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 


Cheat Engine Forum Index
PostGo back to topic
FreeER
Grandmaster Cheater Supreme
Reputation: 53
Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Mar 23, 2017 2:15 pm    Post subject:

Well if it's a static value you can simply add a memory record for it and then freeze it (set the memory record's Active property to true in lua), the same can be said if the value you set it to is only rarely updated (just update the value of the memory record when the value you care about changes).

Since you want it to be done constantly here's a lua script that creates a timer that does the work, destroying itself (and thus stopping) if the script is disabled

Code:
{$lua}
[ENABLE]
-- if just a syntax check on save/load don't run the following code
if syntaxcheck then return end

local timer = createTimer()
timer.onTimer = function(timer)
  -- check if the script is disabled
  -- note there's probably a way to set a function to be called when the script is disabled but I don't know it off the top of my head lol
  al = getAddressList()
  mr = al.getMemoryRecordByDescription("Lua Auto Write")
  if not mr.Active then timer.destroy() end

  -- otherwise do the work
  --writeInteger("[Tutorial-i386.exe+1FC5D0]+480", 333) -- tutorial test line
  writeInteger("JohnnyMoves", 0x170 + (readInteger"JohnnyMoves+20" or 0))
end
timer.interval = 100 -- 100 milliseconds is 1/10 of a second

[DISABLE]


edit: "better" (?) lua using OnDeactivate event:
Code:
{$lua}
[ENABLE]
if syntaxcheck then return end

local timer = createTimer()
timer.onTimer = function(timer)
  --writeInteger("[Tutorial-i386.exe+1FC5D0]+480", 333) -- tutorial test line
  writeInteger("JohnnyMoves", 0x170 + (readInteger"JohnnyMoves+20" or 0))
end

local al = getAddressList()
local mr = al.getMemoryRecordByID(136)
mr.OnDeactivate = function(mr,before,cs)
  -- if about to change state, return true to let it contine and deactivate
  if before then return true end
  -- otherwise state has changed so stop the timer
  timer.destroy()
end

timer.interval = 100 -- 1/10 of a second

[DISABLE]


If you wanted an asm script then you could use createThread instead and write asm code to load the desired value and write it then sleep for a little while and repeat

Code:
globalalloc(code,1000)
[ENABLE]
label(codeDisable)
label(loop)

code:
  // load desired value
  mov eax, [JohnnyMoves+20] // assumes JohnnyMoves is a registered symbol already
  add eax, 170
  // store desired value
  mov [JohnnyMoves], eax

  cmp byte ptr [codeDisable], 0
  je loop  // loop if script still enabled
  ret // otherwise let the thread die/return

loop:
  // wait 100 milliseconds
  push #100 // note: mov into ecx for x64
  call kernel32.sleep // returns only after time requested has elapsed
  jmp code // loop

// byte to set when disabling script to let thread know it should die
codeDisable:
  db 0

// register codeDisable as a symbol so it can be used in DISABLE section
// (note code needs to be registered for createThread to work but globalalloc does it for us)
registerSymbol(codeDisable)

createThread(code)

[DISABLE]
codeDisable:
  db 1
unregisterSymbol(codeDisable)


Last edited by FreeER on Thu Mar 23, 2017 3:54 pm; edited 2 times in total
Back to top
View user's profile Send private message
Post reviews:   Approve 1
Author Review
++METHOS
Review: Approve
Post reference:
ReviewPosted: Thu Mar 23, 2017 11:47 pm


Back to top
View user's profile Send private message
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites