Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Getting scren resolution
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
k4sh
Cheater
Reputation: 0

Joined: 01 Mar 2016
Posts: 28

PostPosted: Thu Mar 17, 2016 4:02 pm    Post subject: Getting scren resolution Reply with quote

Hello there,

i wonder if it's possible in the [ENABLE] section of a cheat table to retrieve the screen width and height.

Any way to do this ?
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Thu Mar 17, 2016 4:58 pm    Post subject: Reply with quote

In lua, not sure it is reliable,
return 4 numbers, 1st 2 numbers is width, height of full screen, next 2 numbers is client width/height ie. without taskbar, usually a smaller y with horizontal taskbar.
Code:
function getScreenSize()
  local param = cheatEngineIs64Bit() and 'mov rcx,' or 'push '
  local r = {string.format([[
//  info : https://msdn.microsoft.com/en-us/library/windows/desktop/ms724385(v=vs.85).aspx
globalalloc(_screenapi,$100)
_screenapi:
dd 0
_screenapi+10:
push rcx
push rax
%s1   // SM_CYSCREEN : The height of the screen of the primary display monitor
call GetSystemMetrics
mov [_screenapi+04],eax
%s10  // SM_CXFULLSCREEN : The width of the client area for a full-screen window on the primary display monitor
call GetSystemMetrics
mov [_screenapi+08],eax
%s11  // SM_CYFULLSCREEN : The height of the client area for a full-screen window on the primary display monitor
call GetSystemMetrics
mov [_screenapi+0c],eax
%s0   // SM_CXSCREEN : The width of the screen of the primary display monitor
call GetSystemMetrics
mov [_screenapi+00],eax
pop rax
pop rcx
ret
]],param,param,param,param),"createThread(_screenapi+10)",[[

]]}
  local w = {}
  if autoAssemble(r[1],true) then
    if autoAssemble(r[2],true) then
      for i=1,100 do
        if readIntegerLocal('_screenapi') ~= 0 then break end
        sleep(10) -- needed for the thread actually done and finished
      end
      local fmt = "_screenapi+%x"
      for i=1,4 do w[i] = readIntegerLocal(fmt:format((i-1)*4))  end

    end
    autoAssemble(r[3],true)-- dummy
  end
  return unpack(w) -- screen x,y with taskbar & x,y w/o taskbar
end

print(">>>",getScreenSize()) -- CXSCREEN, CYSCREEN,CXFULLSCREEN,CYFULLSCREEN


There should be other efficient methods. eg. @main.lua ?
Code:
D3DHOOK class:
...
properties
  Width: Integer : The width of the screen (readonly)
  Height: integer: The height of the screen (readonly)

_________________
- Retarded.
Back to top
View user's profile Send private message
k4sh
Cheater
Reputation: 0

Joined: 01 Mar 2016
Posts: 28

PostPosted: Fri Mar 18, 2016 1:27 pm    Post subject: Reply with quote

I copied the whole block in my enable section and it crashes Cheat engine.
If i remove the print line (last one), it doesn't crash but obviously the getscreensize function is never used.

I tried the d3dhook but i have no idea how to retrieve the width properties and i read that hooking many times is no good.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Fri Mar 18, 2016 3:30 pm    Post subject: Reply with quote

What's your ce version?
Older version may not support local execution (ie. on ce itself) of autoAssemble script, or globalalloc aa command, so may be the error~
The pic is from ce 6.4 vanilla @ winxp/vitualbox, with or without attaching a process.

btw, if AA script assembler (in target process?) is need, may try these instead of Lua function:
Code:
//32bit
push 0 //   for other value, check the msdn page, or comment inside the lua function
call GetSystemMetrics
... // result value in eax

//64bit
mov  rcx,0
call GetSystemMetrics
... // result value in eax



cescxy.jpg
 Description:
 Filesize:  8.02 KB
 Viewed:  15626 Time(s)

cescxy.jpg



_________________
- Retarded.


Last edited by panraven on Fri Mar 18, 2016 3:36 pm; edited 1 time in total
Back to top
View user's profile Send private message
k4sh
Cheater
Reputation: 0

Joined: 01 Mar 2016
Posts: 28

PostPosted: Fri Mar 18, 2016 3:34 pm    Post subject: Reply with quote

Latest version.
i wrote that code into [ENABLE] section in {$lua} and {$asm}.
Never it worked.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Fri Mar 18, 2016 3:47 pm    Post subject: Reply with quote

k4sh wrote:
Latest version.
i wrote that code into [ENABLE] section in {$lua} and {$asm}.
Never it worked.


I tested in my ce 6.5.0.4591 with admin right, inside [ENABLE] section, no problem to print the result, no idea for the difference.

Sorry for my noob, I probably misunderstood the problem. It may be more make sense that ' the screen width and height' you mean is the size of target process window, eg. in a windowed game of 1366x768 at a 1920x1080 desktop, you may want the windowed 'screen'?

_________________
- Retarded.
Back to top
View user's profile Send private message
k4sh
Cheater
Reputation: 0

Joined: 01 Mar 2016
Posts: 28

PostPosted: Fri Mar 18, 2016 6:05 pm    Post subject: Reply with quote

Maybe you could share your working cheat table with me ?
Would be so lovely.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Sat Mar 19, 2016 1:07 am    Post subject: Reply with quote

eh... it is just copy and paste~


getScreenSizeTest.CT
 Description:

Download
 Filename:  getScreenSizeTest.CT
 Filesize:  1.94 KB
 Downloaded:  619 Time(s)


_________________
- Retarded.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Mar 19, 2016 7:46 am    Post subject: Reply with quote

Because we are in Lua forum section:

Lua code
Code:
local cever,offset=getCEVersion(),0
if cheatEngineIs64Bit()
  then if cever==6.4 then offset=0xE98
   elseif cever==6.5 then offset=0xEC0 end
  else if cever==6.4 then offset=0x808
   elseif cever==6.5 then offset=0x81C end
  end

local screenSizeAddress = userDataToInteger(getMainForm())+offset
local screenWidth = readIntegerLocal(screenSizeAddress)
local screenHeight = readIntegerLocal(screenSizeAddress+4)


print(screenWidth,screenHeight)





Lua code inside AA script
Code:
{$lua}
local cever=getCEVersion()
if cheatEngineIs64Bit()
  then if cever==6.4 then offset=0xE98
   elseif cever==6.5 then offset=0xEC0 end
  else if cever==6.4 then offset=0x808
   elseif cever==6.5 then offset=0x81C end
  end

local screenSizeAddress = userDataToInteger(getMainForm())+offset
local screenWidth = readIntegerLocal(screenSizeAddress)
local screenHeight = readIntegerLocal(screenSizeAddress+4)

return 'define(screenWidth,#'..screenWidth..')\r\ndefine(screenHeight,#'..screenHeight..')'
{$asm}

[ENABLE]
400500:
mov eax,screenWidth
mov ebx,screenHeight

[DISABLE]






@panraven, your code crashes on some systems.
Add sub rsp,20 and add rsp,20 to fix this problem.

Code:
_screenapi+10:
push rcx
push rax
sub rsp,20
...
...
add rsp,20
pop rax
pop rcx
ret

_________________
Back to top
View user's profile Send private message MSN Messenger
k4sh
Cheater
Reputation: 0

Joined: 01 Mar 2016
Posts: 28

PostPosted: Sat Mar 19, 2016 9:51 am    Post subject: Reply with quote

Thank you mgr.inz.Player.

It's working fine.

Is there a way to detect the resolution used by a process ?
i mean a game may be using lower resolution or bezel compensation like what i'm using now with an eyefinity setup.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Mar 19, 2016 2:37 pm    Post subject: Reply with quote

What you can try:

1)
- set game to window mode, borderless, set resolution to smallest possible, e.g. it will be 640 x 480
- do fist scan, grouped, with this command:
BS:256 OOO:A 4:640 4:480

- set resolution to next, e.g. it will be 800 x 600
- do next scan, with this command:
BS:256 OOO:A 4:800 4:600


and so on. Maybe you will find some static address with width and height.



2)
- full screen, set resolution to smallest possible, e.g. it will be 640 x 480
- alttab, do fist scan, grouped, with this command:
BS:256 OOO:A 4:640 4:480

- alttab, set resolution to next, e.g. it will be 800 x 600
- alttab, do next scan, with this command:
BS:256 OOO:A 4:800 4:600


and so on...






There's a chance that those addresses will still keep the correct value while using eyefinity.

_________________
Back to top
View user's profile Send private message MSN Messenger
k4sh
Cheater
Reputation: 0

Joined: 01 Mar 2016
Posts: 28

PostPosted: Sat Mar 19, 2016 3:39 pm    Post subject: Reply with quote

Again thank you for your great help that is really appreciated.
I found one address that should be located in the process.
It changes through resolution changes.

However, i'm not sure it will stay the same through updates.
I have tried to see what accesses that address and while in game it gives nothing.
Finding what writes to this address gives results but it occurs only while changing resolution.

I know these resolution values are used in the game but maybe copies of these addesses i found.

I'm little bit stuck now on how to make it update proof.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Mar 19, 2016 4:02 pm    Post subject: Reply with quote

Are those static (entry has green color in foundaddress list)?


PS:
"Finding what writes" - writes
"Finding what accesses" - writes and reads


PPS:
Do "Finding what accesses" on that address and change resolution. You should get at least one entry (you wrote you got one). We will each entry.


Highlight the first one
open in disassembler (click "show disassembler")
be sure that right opcode is highlighted,
press CTRL+A (tools->autoassemble)
from template choose "full injection", press OK
select all, copy and paste to notepad
close window

Highlight the second one (in "following opcode ..." window)
open in disassembler (click "show disassembler")
be sure that right opcode is highlighted,
press CTRL+A (tools->autoassemble)
from template choose "full injection", press OK
select all, copy and paste(append) to notepad
close window



copy from notepad and paste it here.

_________________
Back to top
View user's profile Send private message MSN Messenger
k4sh
Cheater
Reputation: 0

Joined: 01 Mar 2016
Posts: 28

PostPosted: Sat Mar 19, 2016 5:41 pm    Post subject: Reply with quote

So yes the address given by the grouped search is written in green.

And here is the following codes that accesses the width address
Code:

{ Game   : mgsvtpp.exe
  Version:
  Date   : 2016-03-19
  Author : K4sh

  This script does blah blah blah
}

define(address,"mgsvtpp.exe"+303747F)
define(bytes,48 89 47 40 48 8B 46 30)

[ENABLE]

assert(address,bytes)
alloc(newmem,$1000,"mgsvtpp.exe"+303747F)

label(code)
label(return)

newmem:

code:
  mov [rdi+40],rax
  mov rax,[rsi+30]
  jmp return

address:
  jmp code
  nop
  nop
  nop
return:

[DISABLE]

address:
  db bytes
  // mov [rdi+40],rax
  // mov rax,[rsi+30]

dealloc(newmem)

{
// ORIGINAL CODE - INJECTION POINT: "mgsvtpp.exe"+303747F

"mgsvtpp.exe"+3037457: 48 89 47 18                 -  mov [rdi+18],rax
"mgsvtpp.exe"+303745B: 48 8B 46 08                 -  mov rax,[rsi+08]
"mgsvtpp.exe"+303745F: 48 89 47 20                 -  mov [rdi+20],rax
"mgsvtpp.exe"+3037463: 48 8B 46 10                 -  mov rax,[rsi+10]
"mgsvtpp.exe"+3037467: 48 89 47 28                 -  mov [rdi+28],rax
"mgsvtpp.exe"+303746B: 48 8B 46 18                 -  mov rax,[rsi+18]
"mgsvtpp.exe"+303746F: 48 89 47 30                 -  mov [rdi+30],rax
"mgsvtpp.exe"+3037473: 48 8B 46 20                 -  mov rax,[rsi+20]
"mgsvtpp.exe"+3037477: 48 89 47 38                 -  mov [rdi+38],rax
"mgsvtpp.exe"+303747B: 48 8B 46 28                 -  mov rax,[rsi+28]
// ---------- INJECTING HERE ----------
"mgsvtpp.exe"+303747F: 48 89 47 40                 -  mov [rdi+40],rax
"mgsvtpp.exe"+3037483: 48 8B 46 30                 -  mov rax,[rsi+30]
// ---------- DONE INJECTING  ----------
"mgsvtpp.exe"+3037487: 48 89 47 48                 -  mov [rdi+48],rax
"mgsvtpp.exe"+303748B: E8 20 E2 F6 FF              -  call mgsvtpp.exe+2FA56B0
"mgsvtpp.exe"+3037490: B8 0F A2 C3 90              -  mov eax,90C3A20F
"mgsvtpp.exe"+3037495: 8D 80 F2 5D 3C 6F           -  lea eax,[rax+6F3C5DF2]
"mgsvtpp.exe"+303749B: 48 8B 5C 24 30              -  mov rbx,[rsp+30]
"mgsvtpp.exe"+30374A0: 48 8B 6C 24 38              -  mov rbp,[rsp+38]
"mgsvtpp.exe"+30374A5: 48 8B 74 24 40              -  mov rsi,[rsp+40]
"mgsvtpp.exe"+30374AA: 48 83 C4 20                 -  add rsp,20
"mgsvtpp.exe"+30374AE: 5F                          -  pop rdi
"mgsvtpp.exe"+30374AF: C3                          -  ret
}



{ Game   : mgsvtpp.exe
  Version:
  Date   : 2016-03-19
  Author : K4sh

  This script does blah blah blah
}

define(address,"mgsvtpp.exe"+303D7AD)
define(bytes,48 8B 42 28 48 89 45 EF)

[ENABLE]

assert(address,bytes)
alloc(newmem,$1000,"mgsvtpp.exe"+303D7AD)

label(code)
label(return)

newmem:

code:
  mov rax,[rdx+28]
  mov [rbp-11],rax
  jmp return

address:
  jmp code
  nop
  nop
  nop
return:

[DISABLE]

address:
  db bytes
  // mov rax,[rdx+28]
  // mov [rbp-11],rax

dealloc(newmem)

{
// ORIGINAL CODE - INJECTION POINT: "mgsvtpp.exe"+303D7AD

"mgsvtpp.exe"+303D78A: 31 F6                                   -  xor esi,esi
"mgsvtpp.exe"+303D78C: 41 89 F4                                -  mov r12d,esi
"mgsvtpp.exe"+303D78F: 41 89 F5                                -  mov r13d,esi
"mgsvtpp.exe"+303D792: 48 8B 3A                                -  mov rdi,[rdx]
"mgsvtpp.exe"+303D795: 4C 8B 7A 08                             -  mov r15,[rdx+08]
"mgsvtpp.exe"+303D799: 48 8B 5A 10                             -  mov rbx,[rdx+10]
"mgsvtpp.exe"+303D79D: 48 8B 42 18                             -  mov rax,[rdx+18]
"mgsvtpp.exe"+303D7A1: 48 89 45 FF                             -  mov [rbp-01],rax
"mgsvtpp.exe"+303D7A5: 48 8B 42 20                             -  mov rax,[rdx+20]
"mgsvtpp.exe"+303D7A9: 48 89 45 07                             -  mov [rbp+07],rax
// ---------- INJECTING HERE ----------
"mgsvtpp.exe"+303D7AD: 48 8B 42 28                             -  mov rax,[rdx+28]
"mgsvtpp.exe"+303D7B1: 48 89 45 EF                             -  mov [rbp-11],rax
// ---------- DONE INJECTING  ----------
"mgsvtpp.exe"+303D7B5: 48 8B 42 30                             -  mov rax,[rdx+30]
"mgsvtpp.exe"+303D7B9: 48 89 45 0F                             -  mov [rbp+0F],rax
"mgsvtpp.exe"+303D7BD: 48 89 75 8F                             -  mov [rbp-71],rsi
"mgsvtpp.exe"+303D7C1: 48 89 75 97                             -  mov [rbp-69],rsi
"mgsvtpp.exe"+303D7C5: 48 8D 45 97                             -  lea rax,[rbp-69]
"mgsvtpp.exe"+303D7C9: 48 89 45 9F                             -  mov [rbp-61],rax
"mgsvtpp.exe"+303D7CD: 48 8D 45 8F                             -  lea rax,[rbp-71]
"mgsvtpp.exe"+303D7D1: 48 89 45 A7                             -  mov [rbp-59],rax
"mgsvtpp.exe"+303D7D5: 48 8D 45 93                             -  lea rax,[rbp-6D]
"mgsvtpp.exe"+303D7D9: 48 89 45 AF                             -  mov [rbp-51],rax
}
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Mar 19, 2016 7:40 pm    Post subject: Reply with quote

OK.

Could you rightclick on "mgsvtpp.exe"+303747F (in memory viewer) and choose "find out what addresses ...".

That way we can check how many addresses that instruction access. If only one (go back to game and play the game for a while), we can use that without problems. If more than one, we have to use some filtering.



Also try it on "mgsvtpp.exe"+303D7AD

_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites