Is it possible to write compare script with lua ?

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
Blackrosemmt
Noobzor
Noobzor
Posts: 14
Joined: Wed Jul 17, 2019 8:07 pm
Reputation: 0

Is it possible to write compare script with lua ?

Post by Blackrosemmt »

Hi guys

Is it possible to write compare script with lua ?
I need to add 2 offsets then comparing them to value 0 as the below example.

Code: Select all

newmem:
push edx
mov edx,[esi+ec]     //first offset ec
cmp [edx+11c],0	  //second offset 11c
pop edx

jne originalcode

//mov [esi+28],eax
jg game.exe+1861D6
jmp exit

originalcode:

mov [esi+28],eax
jg game.exe+1861D6

GreenHouse
Expert Cheater
Expert Cheater
Posts: 857
Joined: Fri Oct 12, 2018 10:25 pm
Reputation: 891

Re: Is it possible to write compare script with lua ?

Post by GreenHouse »

Blackrosemmt wrote:
Sat Nov 06, 2021 4:01 pm
Hi guys

Is it possible to write compare script with lua ?
I need to add 2 offsets then comparing them to value 0 as the below example.
Well, yes it is possible to write a compare, but it depends on what you're trying to do. That question is way too broad.
But a compare like that one from ASM to LUA, would be something like this, in a simple way:

Code: Select all

if readInteger(readInteger(Address1)+0x11C) == 0x0
   then print('Something is done here) 
else
   print ('Something else is done here') 
end
But if you're planning to run LUA mid ASM, you can't. LUA will always run first.

User avatar
LeFiXER
LeFixer
LeFixer
Posts: 482
Joined: Wed Mar 24, 2021 9:35 am
Reputation: 243

Re: Is it possible to write compare script with lua ?

Post by LeFiXER »

GreenHouse wrote:
Sat Nov 06, 2021 7:08 pm
...
But if you're planning to run LUA mid ASM, you can't. LUA will always run first.
With the latest version of CE you can now run in-line Lua code via {$LUACODE}.

Code: Select all

newmem:
push edx
mov edx,[esi+ec]	//first offset ec
cmp [edx+11c],0		//second offset 11c
{$luacode r1=esi r2=edx}
printf("esi = %X\nedx = %X\nesi+ec = %X\nedx+11c = %X", r1,r2,r1+0xEC,r2+0x11C)
{$asm}
pop edx

jne originalcode

//mov [esi+28],eax
jg game.exe+1861D6
jmp exit

originalcode:
Not exactly what you need but will give you an idea of how in-line Lua can be used which happens to print the values held in the registers defined at the point of execution, along with some offsets added.

GreenHouse
Expert Cheater
Expert Cheater
Posts: 857
Joined: Fri Oct 12, 2018 10:25 pm
Reputation: 891

Re: Is it possible to write compare script with lua ?

Post by GreenHouse »

LeFiXER wrote:
Sat Nov 06, 2021 11:34 pm
With the latest version of CE you can now run in-line Lua code via {$LUACODE}.
That's nice, I didn't know about that. I'll check that out later to see what can be done with it.

User avatar
LeFiXER
LeFixer
LeFixer
Posts: 482
Joined: Wed Mar 24, 2021 9:35 am
Reputation: 243

Re: Is it possible to write compare script with lua ?

Post by LeFiXER »

Sadly, it's not really documented but yeah it's neat for sure.

Blackrosemmt
Noobzor
Noobzor
Posts: 14
Joined: Wed Jul 17, 2019 8:07 pm
Reputation: 0

Re: Is it possible to write compare script with lua ?

Post by Blackrosemmt »

With the latest version of CE you can now run in-line Lua code via {$LUACODE}.
Thanks @LeFiXER for the reply. I wanted to write all script in Lua because the games sometimes crash using push pop in ASM becasue of invalid pointers, so I need to give it a try in Lua to see if game will still crash or not.
can you please help me writing it in Lua according to these information :

"game.exe"+18610E //Base address
EC // first offset
11C // second offset
then compare 11C to 0

jne originalcode // jump if not equal to originalcode
mov eax,[esi+28] // if equal then make this injection


I saw in another posts that they are writing pointer and offset scripts something like
[[[game.exe+offset0]+offset1]+offset2]
but I didnt find for compare in Lua.

User avatar
LeFiXER
LeFixer
LeFixer
Posts: 482
Joined: Wed Mar 24, 2021 9:35 am
Reputation: 243

Re: Is it possible to write compare script with lua ?

Post by LeFiXER »

Blackrosemmt wrote:
Sun Nov 07, 2021 10:35 am
I saw in another posts that they are writing pointer and offset scripts something like
[[[game.exe+offset0]+offset1]+offset2]
but I didnt find for compare in Lua.
You're welcome, although it's not difficult to use a reputable search engine to answer your query. Nevertheless,

Code: Select all

local base = getAddressSafe('game.exe+18610E')
local pointer = getAddressSafe('[[[' .. base .. ']+EC]+11C')

if readInteger(pointer) == 0 then
  -- The value held in pointer = 0
The function readInteger may differ based on the value type you're reading.

Post Reply

Who is online

Users browsing this forum: No registered users