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 


createD3DHook again

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author 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: Tue Aug 13, 2013 1:42 pm    Post subject: createD3DHook again Reply with quote

I want to create another lua script for me and autorun script for others, both using D3D. Something similar to:

"-- Direct 3D Hook Function --" section,
the one between --TRAINERGENERATORSTART-- and --TRAINERGENERATORSTOP--

But, this script will be for already existing generic trainers (CT, CETRAINER) with Lua script.

I think I just hook those:

- memoryrecordhotkey_onPostHotkey
- memoryrecordhotkey_onHotkey
That way I can collect all memrec objects (memrecHotkey.Owner).

Another function will hook onPostHotkey and onHotkey functions.
That way I will know which cheat is now enabled or disabled

I will add simple notify animation about enabled cheat. (hmm, "graphical beep").
User will place that script in autorun and all D3D game will have that "graphical beep"
(of course I will check if d3d9.dll is loaded, or newer dll)






But there is one little problem. Some people:
- trainer creators, are using AA aobscan - post, second part ("I prefer signatures that do not cover the injection point")

- and then, other people launch CE, enable cheat, close CE. Then after a while they: launch CE, disable cheat, close CE


I know that calling createD3DHook few times (from different CE instances) is not an option. CE or game can crash. Maybe something like D3DWasHooked() and reopenD3DHook() could be handy.

reopenD3DHook() will search for previously created hook, destroy objects (sprites and textures) and then it will return d3dhook object
Code:
if D3DWasHooked() then h=reopenD3DHook() else h=createD3DHook() end



Maybe you can save all needed informations: allocate memory and copy all important pointers and stuff there. And create pointer to that allocated memory, pointer in "processname.exe+500".
Code:
if D3DWasHooked("processname.exe+500") then
  h=reopenD3DHook("processname.exe+500")
else
  h=createD3DHook() end

_________________
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Tue Aug 13, 2013 2:30 pm    Post subject: Reply with quote

createD3DHook actually does what you describe. When it hooks it opens the shared memory, and zero's it out. The problem is that memory also contains memory pointers and handles in the target process so yeah, crash. And because cheat engine doesn't know the exact offset where it allocated that memory it can't be safely de-allocated and the events for frame locking are also owner specific. (shared handle between the owner CE version and the game)


But there is a way to detect if it's loaded:
allocateSharedMemory('CED3D_'+getOpenedProcessID())

If the first byte of this result is 0 (empty path to cheat engine) it's not loaded

So if it's loaded you can tell the user to restart the game

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Tue Aug 13, 2013 3:09 pm    Post subject: Reply with quote

Quote:
And because cheat engine doesn't know the exact offset where it allocated that memory it can't be safely de-allocated

Can we save that "exact offset" somehow? For example in "processname.exe+500" (or other user defined memory location - e.g. "BL2.exe+30" ) ?

Or you meant that CE (the one we used for D3DHook for the first time) can not find that "exact offset"?

_________________
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Tue Aug 13, 2013 4:01 pm    Post subject: Reply with quote

i'll look into it but it's not as straightforward

modulename+offset isn't a reliable solution as some programs might populate that memory block after all and actively use it so best spot is just store it in the shared memory object

The first problem is a small chicken and egg problem (can be solved)
To control access to the command list an Event is used. To obtain a handle to that event a process that owns it needs to call DuplicateHandle with that handle and a pointer to the memory new process. (so also needs to open CE itself, which is most of the time impossible if the game isn't running as admin)




---
Also, the d3d hook is not at all designed to deal with cheat engine closing. There is a part where it sends key presses and mouse clicks in the game's window to ce's lua and waits for a response on how to deal with it

And the most important thing: WHY close cheat engine/the trainer during the game? It won't take up much memory(the working set shrinks as blocks will get paged out), and depending on your script it won't take up much cpu
(It's not because of detection, because the module named "ced3d9hook.dll" is blatantly present inside the game's module list)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Tue Aug 13, 2013 5:02 pm    Post subject: Reply with quote

Dark Byte wrote:
Also, the d3d hook is not at all designed to deal with cheat engine closing. There is a part where it sends key presses and mouse clicks in the game's window to ce's lua and waits for a response on how to deal with it


What you think about this:

1) all D3DHook_RenderObject will get Visible:=false just after CE is closed (or crashed). It must detect that CE process (creator) doesn't exist anymore. And no longer send key presses and mouse clicks to ce's lua.

Can you implement "heartbeat mechanism".
No beat == set visible to false for all objects AND do not send key presses and mouse clicks.




2) We are using D3DHook feature. And we have another instance of CE, executing createD3DHook will hook already existing hook. So, there will be two instances of "command list". ( for now it doesn't work that way, I know)

I don't know how to put this. Maybe Lua example:

Autorun lua file contains:
Code:
if old_bXor==nil then
  old_bXor=bXor
end

function bXor(a,b)
  -- whatever we want
  print('first')  -- first hook

  return old_bXor(a,b)
end



And inside CT file, there is script like this:
Code:
if o_l_d_bXor==nil then
  o_l_d_bXor=bXor
end

function bXor(a,b)
  -- whatever we want
  print('second')  -- second hook

  return o_l_d_bXor(a,b)
end



You know what happens after print(bXor(2,5) ), we get:
second
first
7

print('first') - this is first "command list"
print('second') - this is second "command list"







Can we achieve something like this? It isn't perfect because we don't destroy D3D objects we don't need.

I have a brainstorm.
createD3DHook(textureandcommandlistsize OPTIONAL, hookmessages OPTIONAL, useheartbeat OPTIONAL)

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

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

PostPosted: Wed Aug 14, 2013 7:41 am    Post subject: Reply with quote

Or two AA scripts example:
Hook1:
Code:
[ENABLE]
alloc(newmem,2048)
label(returnhere)
label(copy_hook1)
registersymbol(copy_hook1)

"Tutorial-i386.exe"+15489C:
jmp newmem
returnhere:

newmem:
reassemble("Tutorial-i386.exe"+15489C)
jmp returnhere

copy_hook1:
readmem("Tutorial-i386.exe"+15489C,5)

[DISABLE]
"Tutorial-i386.exe"+15489C:
readmem(copy_hook1,5)

unregistersymbol(copy_hook1)
dealloc(newmem)

Hook2:
Code:
[ENABLE]
alloc(newmem,2048)
label(returnhere)
label(copy_hook2)
registersymbol(copy_hook2)

"Tutorial-i386.exe"+15489C:
jmp newmem
returnhere:

newmem:
reassemble("Tutorial-i386.exe"+15489C)
jmp returnhere

copy_hook2:
readmem("Tutorial-i386.exe"+15489C,5)

[DISABLE]
"Tutorial-i386.exe"+15489C:
readmem(copy_hook2,5)

unregistersymbol(copy_hook2)
dealloc(newmem)

We can enable above scripts. Both use the same hackpoint. Example isn't perfect because order is important: last enabled script is the first to be disabled, otherwise crash. But you don't unhook D3D anyway.

_________________
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Wed Aug 14, 2013 8:16 am    Post subject: Reply with quote

That is another example of why closing the first cheat engine is a bad idea
It will be unable to disable the cheat once ce has been closed since the address to the original unmodified bytes will be gone

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Wed Aug 14, 2013 9:29 am    Post subject: Reply with quote

Personally I use something like this for cheats with aobscan:
Code:
function activateMASTERCHEAT()

  local active = memoryrecord_isActive(memrec0)

  if active==false then

    if readInteger(procname..'+500') == 1
    then
      local address = readInteger(procname..'+508')
      writeBytes(address,0x8B,0x4D,0x00,0x8B,0x44,0x24,0x24)

      address = readInteger(procname..'+50C')
      writeBytes(address,0xC1,0xF8,0x04,0xC3,0xCC)
    end

    memoryrecord_freeze(memrec0)
    active = memoryrecord_isActive(memrec0)

    if active then
      fullAccess(getAddress(procname..'+500'),32)
      writeInteger(procname..'+500',1)
      writeInteger(procname..'+508',getAddress('injectpoint1'))
      writeInteger(procname..'+50C',getAddress('injectpoint2'))
    end

    return active
  else
    return true
  end
end

Or I use aobscan with signature that do not cover the injection point.
I use this trick for my more advanced trainers.





And I can enable already enabled scripts/cheats. And after that, I can disable it.
If my script uses flags (Godmode, InfiniteFuel, 0-disabled 1-enabled, etc. ), all cheats are disabled after enabling master cheat/script. So I don't have to do enable/disable cycle if I want to disable cheat which was enabled in previous CE.

_________________
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 All times are GMT - 6 Hours
Page 1 of 1

 
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