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 


String StartsWith with auto assembler

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

Joined: 17 Dec 2014
Posts: 2

PostPosted: Wed Dec 17, 2014 1:18 am    Post subject: String StartsWith with auto assembler Reply with quote

I've been searching through the forums and found a way to compare string, but it is not exactly what I need as this has to be a string ending in "0". In my case I need to make sure that a string starts with a particular text.
As background, I'm doing an auto assembler code for Final Fantasy XIII-2 where I check what kind of item I'm looking at to decide whether to set the amount or leave as is. Currently this is an extract of my working script:

Code:

newmem:
cmp [eax+10],0 //if no item, do nothing
je originalcode
isitem:
cmp word [eax]      ,'it'
jne ismaterial
cmp byte [eax+2]    ,'_'
je setitemmax
ismaterial:
cmp dword [eax]      ,'mate'
jne isgysahl
cmp dword [eax+4]      ,'rial'
je setitemmax
isgysahl:
cmp dword [eax]      ,'cc_g'
jne originalcode
cmp dword [eax+4]      ,'ysah'
jne originalcode
setitemmax:
mov [eax+10],#99


As you can see, the max length I can compare at once are 4 bytes and need to work with different data type sizes to compare different length of strings.
Basically what I need to do is: if the string at [eax] starts with either "it_", "material_" or "cc_gysah", set item amount to 99, else, do normal execution.
Is there a better and simpler way of doing this? I'd like to keep it simple and be able to add other checks easily and without worrying about the length of the string I'm comparing against.

Thanks!
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Wed Dec 17, 2014 3:53 am    Post subject: Reply with quote

I've only tested one case.

Code:


//  --- original code, snip for no  space and don't want to spam another similar post


The addressing used for EDX should make the assembler ok both for 32-bit and 64-bit target.


UPDATE:

hope this work:
Code:
[ENABLE]
alloc(newmem,4096)
label(returnhere)
label(originalcode)
label(exit)

label(_target)
label(_next)
label(_allFail)
label(_found)

newmem:
cmp [eax+10],0 //if no item, do nothing
je originalcode

//back up registers

// ====== change start
pushad      // save all register
push eax    // save EAX 1 more time for later decision braching
mov   esi,eax
// ====== change end

mov   edi,_target     // address of list of strings of startwith at assembler end, alloc enough memory

//start registers as zero

xor   eax,eax
xor   ebx,ebx
xor   ecx,ecx

//loop start
_next:
inc   ecx             // testing i-th string, return 0 if not found after all test
add   edi,ebx         // update target to next
mov   al,[edi]
test  eax,eax
je    _allFail
xor   ebx,ebx
@@:
  mov   edx,ebx
  add   edx,edi 
  mov   al,[edx]
  test  eax,eax
  je    _found          // end of all match for current target (startwith), match found
  mov   edx,ebx
  // add edx,edx        // for double byte source string
  add   edx,esi
  inc   ebx
  cmp   al,[edx]
je    @B
xor   eax,eax
@@:
  mov   edx,edi         //  adjust ebx to next target
  add   edx,ebx
  inc   ebx
  cmp   al,[edx]
jne   @B
jmp   _next           // not match this target, check next
_allFail:             // all fail, rest ecx to zero
xor      ecx,ecx
_found:
// ====== change start

//ecx contain the result, 0 for not found, otherwise the 1-base index of which target startWith string matched
pop eax // restore original eax
test ecx,ecx
je  @F
  mov [eax+10],#99
@@:
popad     // res=tore all register


// ====== change end

originalcode:
mov eax,[eax+10]
mov [ecx+10],eax

exit:

jmp returnhere

_target:
db 'it_',0
db 'material_',0
db 'cc_gysahl',0
db 0 //   mark for no more to test
//key       key item
//opt       optional key item?
//0000      weapon/acc

"ffxiii2img.exe"+57BFA1:
jmp newmem
nop
returnhere:


[DISABLE]
//code from here till the end of the code will be used to disable the cheat
dealloc(newmem)
"ffxiii2img.exe"+57BFA1:
mov eax,[eax+10]
mov [ecx+10],eax
//Alt: db 8B 40 10 89 41 10 


Last edited by panraven on Tue Dec 30, 2014 6:20 am; edited 4 times in total
Back to top
View user's profile Send private message
nicolaspdlt
How do I cheat?
Reputation: 0

Joined: 17 Dec 2014
Posts: 2

PostPosted: Sun Dec 21, 2014 12:30 am    Post subject: Reply with quote

Thank you very much! I didn't fully understand some parts of your code but I managed to merge that with what I had.
I'll post the full code here for anyone interested. It's for Final Fantasy XIII-2 and it sets to 99 the amount of items which are items, components, monster materials and gysahl greens.
Thanks to you, new items or item types can easily be added, but at the moment those set are the ones I need

Code:

[ENABLE]
alloc(newmem,4096)
label(returnhere)
label(originalcode)
label(exit)

label(_target)
label(_next)
label(_allFail)
label(_found)

newmem:
cmp [eax+10],0 //if no item, do nothing
je originalcode

//back up registers
push eax
push ebx
push ecx
push edx
push edi

mov   edi,_target     // address of list of strings of startwith at assembler end, alloc enough memory

//start registers as zero
xor   eax,eax
xor   ebx,ebx
xor   ecx,ecx

//loop start
_next:
inc   ecx             // testing i-th string, return 0 if not found after all test
add   edi,ebx         // update target to next
mov   al,[edi]
test  eax,eax
je    _allFail
xor   ebx,ebx
@@:
mov   edx,ebx
add   edx,edi
mov   al,[edx]
test  eax,eax
je    _found          // end of all match for current target (startwith), match found
mov   edx,ebx
// add edx,edx        // for double byte source string
add   edx,esi
inc   ebx
cmp   al,[edx]
je    @B
xor   eax,eax
@@:
mov   edx,edi         //  adjust ebx to next target
add   edx,ebx
inc   ebx
cmp   al,[edx]
jne   @B
jmp   _next           // not match this target, check next
_allFail:             // all fail, rest ecx to zero
xor      ecx,ecx
_found:
//ecx contain the result, 0 for not found, otherwise the 1-base index of which target startWith string matched
cmp ecx,0
//restore registers
pop edi
pop edx
pop ecx
pop ebx
pop eax
je originalcode    //if not found, do original code

mov [eax+10],#99   //if found, set item amount to 99

originalcode:
mov eax,[eax+10]
mov [ecx+10],eax

exit:

jmp returnhere

_target:
db 'it_',0
db 'material_',0
db 'cc_gysahl',0
db 0 //   mark for no more to test
//key       key item
//opt       optional key item?
//0000      weapon/acc

"ffxiii2img.exe"+57BFA1:
jmp newmem
nop
returnhere:


[DISABLE]
//code from here till the end of the code will be used to disable the cheat
dealloc(newmem)
"ffxiii2img.exe"+57BFA1:
mov eax,[eax+10]
mov [ecx+10],eax
//Alt: db 8B 40 10 89 41 10
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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