Working with 2-byte
Working with 2-byte
It's a PCSX2 game.
[ecx+4] (2 byte)
[ecx+6] (2 byte, too)
How can I do something like this: [ecx+6] = [ecx+4] * 10, using CE script?
Thank you.
[ecx+4] (2 byte)
[ecx+6] (2 byte, too)
How can I do something like this: [ecx+6] = [ecx+4] * 10, using CE script?
Thank you.
Re: Working with 2-byte
Might help to explain yourself better, I can't seem to see what you are asking to do.
Re: Working with 2-byte
For example, the ecx register is something like this:
Code: Select all
02 1C 42 32 21 00 39 00 ...
multiply 21 00 with 10, result: XX XX
Place result to [ecx+6]
So in the end the ecx should be:
Code: Select all
02 1C 42 32 21 00 XX XX ...
-
- Expert Cheater
- Posts: 293
- Joined: Sat Mar 04, 2017 7:28 am
- Reputation: 236
Re: Working with 2-byte
Assuming 10 is integer value.
Code: Select all
push eax //save eax
xor eax,eax
mov eax,word ptr [ecx+4]
imul eax,a // or imul eax,#10 or imul eax,(int)10
mov word ptr [ecx+6], eax
pop eax //recall eax
Re: Working with 2-byte
^^ #TheByteSize is correct; the "key" thing here is that you use 'word ptr' to collect/manipulate 2 byte info (see also: byte ptr, dword ptr, etc ~ google). for completeness sake, you also might want to work with - in this case - ax...
(seems cleaner, but i always debug it just to make sure )
(seems cleaner, but i always debug it just to make sure )
Re: Working with 2-byte
CE warns me:TheByteSize wrote: ↑Tue Nov 28, 2023 12:53 amAssuming 10 is integer value.Code: Select all
push eax //save eax xor eax,eax mov eax,word ptr [ecx+4] imul eax,a // or imul eax,#10 or imul eax,(int)10 mov word ptr [ecx+6], eax pop eax //recall eax
Code: Select all
Not all code is injectable.
(Error in line 21 (mov eax,word ptr [ecx+4]): This instruction can't be compiled)
Are you sure you want to edit it to this?
Re: Working with 2-byte
Try this:bbufa wrote: ↑Tue Nov 28, 2023 7:37 amCE warns me:Code: Select all
Not all code is injectable. (Error in line 21 (mov eax,word ptr [ecx+4]): This instruction can't be compiled) Are you sure you want to edit it to this?
Code: Select all
push eax //save eax
xor eax,eax
movzx ax,word ptr [ecx+4]
imul ax,#10
mov word ptr [ecx+6], ax
pop eax //recall eax
Re: Working with 2-byte
LineRhark wrote: ↑Tue Nov 28, 2023 7:55 amTry this:bbufa wrote: ↑Tue Nov 28, 2023 7:37 amCE warns me:Code: Select all
Not all code is injectable. (Error in line 21 (mov eax,word ptr [ecx+4]): This instruction can't be compiled) Are you sure you want to edit it to this?
Code: Select all
push eax //save eax xor eax,eax movzx ax,word ptr [ecx+4] imul ax,#10 mov word ptr [ecx+6], ax pop eax //recall eax
Code: Select all
movzx ax,word ptr [ecx+4]
Re: Working with 2-byte
bbufa wrote: ↑Tue Nov 28, 2023 8:04 amLineget the same warning as aboveCode: Select all
movzx ax,word ptr [ecx+4]
Code: Select all
push eax //save eax
xor eax,eax
movzx eax,word ptr [ecx+4]
imul ax,#10
mov [ecx+6], ax
pop eax //recall eax
Re: Working with 2-byte
Rhark wrote: ↑Tue Nov 28, 2023 8:53 ambbufa wrote: ↑Tue Nov 28, 2023 8:04 amLineget the same warning as aboveCode: Select all
movzx ax,word ptr [ecx+4]
Sorry, had a brain fart.Code: Select all
push eax //save eax xor eax,eax movzx eax,word ptr [ecx+4] imul ax,#10 mov [ecx+6], ax pop eax //recall eax
Code: Select all
push eax //save eax (1)
xor eax,eax // (2)
movzx eax,word ptr [ecx+4] // (3)
imul ax,#10 // (4)
mov [ecx+6], ax // (5)
pop eax //recall eax (6)
But line (4) & (5), I think it is eax instead of ax?
Line (5) seems to be problem because: after (2), eax will be cleaned... After (3), except 2 first bytes of eax, the rest are 00 bytes, so eax looks like XX XX 00 00 00 00... In that case, line (5) mov the whole eax to [ecx+6] may replace a lot of bytes in ecx with 00?
Can we use "word ptr" in line (5)?
Re: Working with 2-byte
[Link]
Re: Working with 2-byte
Thank you, after reading many times, I finally understand movzx command
However, the code
Code: Select all
imul ax,#10
I tried creating a new script (which has nothing to do with above codes and has only 1 imul code), just to test imul command:
Code: Select all
newmem:
imul ax,#10
Could you please have a look.
-
- Expert Cheater
- Posts: 293
- Joined: Sat Mar 04, 2017 7:28 am
- Reputation: 236
Re: Working with 2-byte
This should works.
Also remember that you're converting from 4 bytes into 2 bytes so you might get negative number in game.
if that the case, you will need to add number limit to 32767 before storing it back into pointer.
Also remember that you're converting from 4 bytes into 2 bytes so you might get negative number in game.
if that the case, you will need to add number limit to 32767 before storing it back into pointer.
Code: Select all
push eax
xor eax,eax
movzx eax,word ptr [ecx+4]
imul eax,#10
mov word ptr [ecx+6], ax
pop eax
Re: Working with 2-byte
I tested these codes dozen times, so far there is no problem.TheByteSize wrote: ↑Tue Nov 28, 2023 10:31 pmThis should works.
Also remember that you're converting from 4 bytes into 2 bytes so you might get negative number in game.
if that the case, you will need to add number limit to 32767 before storing it back into pointer.Code: Select all
push eax xor eax,eax movzx eax,word ptr [ecx+4] imul eax,#10 mov word ptr [ecx+6], ax pop eax
Just in case bad things happen (negative number), could you please teach me how to fix it?
Thank you so much sirs
-
- Expert Cheater
- Posts: 293
- Joined: Sat Mar 04, 2017 7:28 am
- Reputation: 236
Re: Working with 2-byte
Here you going to see couple push and pop. When you have multiple of these, remember the concept of First In/Last Out or Last In/First Out.
If you mess up the order, your game data could get wrong saved value in long run as worst case scenario. Immediately crash is better in this situation.
Also, we're going to use comparison in this so it's good idea to save the Flag(comparison result) stack and recall it.
If you mess up the order, your game data could get wrong saved value in long run as worst case scenario. Immediately crash is better in this situation.
Also, we're going to use comparison in this so it's good idea to save the Flag(comparison result) stack and recall it.
Code: Select all
pushf //saving flag stack
push eax
push ebx
xor eax,eax
xor ebx,ebx
mov ebx,#9999
movzx eax,word ptr [ecx+4]
imul eax,#10
cmp eax,ebx
cmovg eax,ebx //copy data of ebx to eax if eax is greater than ebx by the comparison line above.
mov word ptr [ecx+6], ax
pop ebx
pop eax
popf //recall flag stack
Who is online
Users browsing this forum: No registered users