 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Wed Feb 17, 2016 5:24 pm Post subject: Lua script in AA script. Please help! :( |
|
|
Hey there, first of all, sorry for my English and I'm a noob to programming.
Anyway, what I want to achieve is to create a randomizer in my AA script. I tried to use Lua but with no success. I want to make the following happen:
1. I have a variable "a", which is a randomized number;
2. compare "a" to 50.
3. if "a" is bigger than 50, then make some actions, for example add 50 health;
4. if "a" is smaller than 50, then make other actions, for example add 20 health.
My problem that I have been working on for 10 hours is: I cannot create the randomizer! I tried the following script, which must have some major issues, so please don't laugh too hard. Thanks in advance.
BTW, most part of the code comes from the template, and there is one line that cannot be compiled when I try to compare two stuffs. I marked that line in the code below.
| Code: | [ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
{$lua}
function myFunction() --try to create a randomizer
math.randomseed( os.time() )
return math.random(100)
end
print(myFunction())
{$asm}
loadlibrary(luaclient-i386.dll)
luacall(openLuaServer('CELUASERVER'))
globalalloc(luainit, 128)
globalalloc(LuaFunctionCall, 128)
label(luainit_exit)
globalalloc(luaserverinitialized, 4)
globalalloc(luaservername, 12)
luaservername:
db 'CELUASERVER',0
luainit:
cmp [luaserverinitialized],0
jne luainit_exit
push luaservername
call CELUA_Initialize //this function is defined in the luaclient dll
mov [luaserverinitialized],eax
luainit_exit:
ret
LuaFunctionCall:
push ebp
mov ebp,esp
call luainit
push [ebp+c]
push [ebp+8]
call CELUA_ExecuteFunction
pop ebp
ret 8
//luacall call example:
//push integervariableyouwishtopasstolua
//push addresstostringwithfunction //(The lua function will have access to the variable passed by name "parameter")
//call LuaFunctionCall
//When done EAX will contain the result of the lua function
alloc(newmen,128)
alloc(myLuaScript,2048)
label(returnhere)
label(originalcode)
label(exit)
myLuaScript:
db 'myFunction',0
newmem:
push eax
push ebx
push myLuaScript
call LuaFunctionCall
cmp myFunction,1 <-------[color=red]this line cannot be compiled, I cannot fix it. :([/color]
jg originalcode
jmp exit
originalcode:
mov [ebx+esi+1D],cl
lea ecx,[edx+edi]
jmp exit
exit:
jmp returnhere
"XXXX.exe"+XXXX:
jmp newmem
nop
nop
returnhere:
[DISABLE]
//code from here till the end of the code will be used to disable the cheat
dealloc(newmem)
dealloc(myLuaScript)
"XXXX.exe"+XXXX:
mov [ebx+esi+1D],cl
lea ecx,[edx+edi] |
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25839 Location: The netherlands
|
Posted: Wed Feb 17, 2016 5:38 pm Post subject: |
|
|
You didn't mention what the issue is. No random? Crash? (I assume crash)
you could probably just do a
| Code: |
pushad
call rand
and eax,1
cmp eax,0
popad
je add50
add20:
...
jmp exit
add50:
...
jmp exit
|
and if eax=0 do one thing, if not, so something else
Anyhow, for the luacall method
try this lua section:
| Code: |
{$lua}
math.randomseed( os.time() )
function myFunction() --try to create a randomizer
local r=math.random(100)
print("r="..r)
return r
end
{$asm}
|
this way you'll know when it's called (and when you know it works, remove the print)
As for the ASM part,
your "call LuaFunctionCall" is preceded by 3 pushes, but LuaFunctionCall only takes 2 parameters.
And you're also not saving/restoring the original registers before and after the call
Also, "cmp myFunction,1" won't work. the result of the call is stored in EAX, so use "cmp eax,1"
And not sure about the 1, you may want to use #50 (cmp eax,#50) to comply with your case
_________________
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
Last edited by Dark Byte on Fri Feb 19, 2016 11:28 am; edited 1 time in total |
|
| Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Wed Feb 17, 2016 6:00 pm Post subject: |
|
|
Thanks a lot for the reply, Dark Byte. I will try to fix it with your methods.
Update:
Hey Dark Byte, I have tried your first solution, but it always returns the same result, like also return option one.
Update again:
It worked after I changed "or eax, 1" to "and eax,1".Thanks a lot.
|
|
| Back to top |
|
 |
|
|
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
|
|