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 


anything below call rand is not working

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
linhlan981
How do I cheat?
Reputation: 0

Joined: 30 Aug 2022
Posts: 6
Location: Ha Noi

PostPosted: Tue Aug 30, 2022 5:40 am    Post subject: anything below call rand is not working Reply with quote

Hello, i try to make a random critical damage script, and come up with this.


originalcode:
call rand
and eax,#7
cmp eax,0
jne normal

imul esi,#5
sub ecx,esi
mov [rsp+30],ecx
jmp returnhere

normal:
sub ecx,esi
mov [rsp+30],ecx
jmp returnhere

i want to have 12.5% change to deal 500% damage, but any codes below the call rand is not working, but when i remove the call rand, i have 100% chance to crit 500%. Please help me, thank you.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Tue Aug 30, 2022 5:56 am    Post subject: Reply with quote

Try adding a sub rsp,20 before call rand, and add rsp,20 after.

or
Code:

{$ccode r=eax}
r=rand();
{asm}

_________________
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
linhlan981
How do I cheat?
Reputation: 0

Joined: 30 Aug 2022
Posts: 6
Location: Ha Noi

PostPosted: Tue Aug 30, 2022 6:33 am    Post subject: Reply with quote

Dark Byte wrote:
Try adding a sub rsp,20 before call rand, and add rsp,20 after.

or
Code:

{$ccode r=eax}
r=rand();
{asm}


thanks for your reply. I changed it to


originalcode:
sub rsp,20
call rand
add rsp,20
and eax,#7
cmp eax,0
jne normal
imul esi,#5
sub ecx,esi
mov [rsp+30],ecx
jmp returnhere


normal:
sub ecx,esi
mov [rsp+30],ecx
jmp returnhere

but its still the same, when i test with cheat engine tutorial game its work but with real game its not work.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Tue Aug 30, 2022 6:37 am    Post subject: Reply with quote

you may want to save all registers before calling rand

These registers may have changed by calling rand:
RAX, RCX, RDX, R8,R9,R10, R11
( according to https://docs.microsoft.com/en-us/cpp/build/x64-software-conventions?view=msvc-170 )

and of course,
Code:

{$ccode r=rax}
r=rand();
{asm}

is still an option

_________________
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
linhlan981
How do I cheat?
Reputation: 0

Joined: 30 Aug 2022
Posts: 6
Location: Ha Noi

PostPosted: Tue Aug 30, 2022 6:53 am    Post subject: Reply with quote

Dark Byte wrote:
you may want to save all registers before calling rand

These registers may have changed by calling rand:
RAX, RCX, RDX, R8,R9,R10, R11

and of course,
Code:

{$ccode r=rax}
r=rand();
{asm}

is still an option


im so sorry, i dont understand that at all, where do i put those code in, if you have link for document, would be great, im new and noob. Thank you.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Tue Aug 30, 2022 7:42 am    Post subject: Reply with quote

the ccode block you can just put in place of call rand (if you're on ce 7.4)

e.g:
Code:

originalcode:
{$ccode r=rax}
r=rand();
{$asm}

and eax,#7
cmp eax,0
jne normal

imul esi,#5
sub ecx,esi
mov [rsp+30],ecx
jmp returnhere

normal:
sub ecx,esi
mov [rsp+30],ecx
jmp returnhere




as for doing it manually and saving and restoring the registers you'll have to sub rsp with some more (8*registercount), and then use that to store the old registers. But make sure to keep the stack aligned. (and make sure not to use rsp to rsp+20 as those may get changed when you call rand)

check out
https://docs.microsoft.com/en-us/cpp/build/x64-software-conventions?view=msvc-170

_________________
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
linhlan981
How do I cheat?
Reputation: 0

Joined: 30 Aug 2022
Posts: 6
Location: Ha Noi

PostPosted: Tue Aug 30, 2022 1:07 pm    Post subject: Reply with quote

Dark Byte wrote:
the ccode block you can just put in place of call rand (if you're on ce 7.4)

e.g:
Code:

originalcode:
{$ccode r=rax}
r=rand();
{$asm}

and eax,#7
cmp eax,0
jne normal

imul esi,#5
sub ecx,esi
mov [rsp+30],ecx
jmp returnhere

normal:
sub ecx,esi
mov [rsp+30],ecx
jmp returnhere




as for doing it manually and saving and restoring the registers you'll have to sub rsp with some more (8*registercount), and then use that to store the old registers. But make sure to keep the stack aligned. (and make sure not to use rsp to rsp+20 as those may get changed when you call rand)




Thank you so much, sir. Its works like black magic now. Im gonna show the enemies my crit now haha.
Just one more question, what is {$ccode and {$asm}. Im never see it before, sorry, im new.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Tue Aug 30, 2022 2:59 pm    Post subject: Reply with quote

{$ccode}/{$asm} and {$luacode}/{$asm} are blocks that pretty much do all the setup of the stack and parameters for you.
Then inside the blocks you can write c code($ccode), or luacode($luacode) and reference the optional registers as variables you've provided

The difference between luacode and ccode, (besides the language used) is that luacode runs inside CE's context and waits till it returns from CE, and ccode runs inside the target itself with no wait

_________________
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
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