thank you for another educating reply.
however, first example cause an error in my compiler:
Code:
error C2400: inline assembler syntax error in 'first operand'; found 'newline'
and second one cause an engine crash at offset 'NewCooldown+46':
Code:
NewCooldown - 83 EC 18 - sub esp,18
NewCooldown+3 - A1 00B00010 - mov eax,[__security_cookie]
NewCooldown+8 - 33 C4 - xor eax,esp
NewCooldown+A - 89 44 24 14 - mov [esp+14],eax
NewCooldown+E - A1 60510010 - mov eax,[`string']
NewCooldown+13 - 8B 0D 64510010 - mov ecx,[`string'+4]
NewCooldown+19 - 8B 15 68510010 - mov edx,[`string'+8]
NewCooldown+1F - 89 04 24 - mov [esp+esp],eax
NewCooldown+22 - A1 6C510010 - mov eax,[`string'+C]
NewCooldown+27 - 89 4C 24 04 - mov [esp+04],ecx
NewCooldown+2B - 8B 0D 70510010 - mov ecx,[`string'+10]
NewCooldown+31 - 89 54 24 08 - mov [esp+08],edx
NewCooldown+35 - 89 44 24 0C - mov [esp+0C],eax
NewCooldown+39 - 89 4C 24 10 - mov [esp+10],ecx
NewCooldown+3D - 8B 44 24 04 - mov eax,[esp+04]
NewCooldown+41 - A3 A0B80010 - mov [dwCooldown],eax
NewCooldown+46 - 89 41 20 - mov [ecx+20],eax // this is the place that cause a crash
NewCooldown+49 - 8B 15 A0B80010 - mov edx,[dwCooldown]
NewCooldown+4F - 52 - push edx
NewCooldown+50 - 8D 44 24 04 - lea eax,[esp+04]
NewCooldown+54 - 50 - push eax
NewCooldown+55 - FF 15 A8500010 - call dword ptr [_imp__printf]
NewCooldown+5B - 8B 4C 24 1C - mov ecx,[esp+1C]
NewCooldown+5F - 83 C4 08 - add esp,08
NewCooldown+62 - 33 CC - xor ecx,esp
NewCooldown+64 - E8 AD300000 - call __security_check_cookie
NewCooldown+69 - 83 C4 18 - add esp,18
NewCooldown+6C - C3 - ret
this asm code looks strange to me and its even more confusing :)
maybe this code is erasing some important registers?
maybe I should tell you few words on how this native function works
Code:
006952E9 - 8B 44 24 04 - mov eax,[esp+04]
006952ED - 89 41 20 - mov [ecx+20],eax
006952F0 - C2 0400 - ret 0004
// eax = 1140735489, 1144036829, and so on.
eax contains something like a timestamp+skill charge+cooldown, so game will know how long the cooldown should last.
these values are different from the one I can get by GetTickCount but every time I use skill value is increased by same amount:
current timestamp + (skill charge time + skill cooldown time)
now, if I patch this function like this:
Code:
006952E9 - C7 41 20 01000000 - mov [ecx+20],00000001
006952F0 - C2 0400 - ret 0004
then it works perfectly and I get no cooldown at all so I can spam teens/houndreds of skills in a second.
The problem is this 'plain stupid patching' method does not satisfy me anymore and I want to learn something more 'sufisticated' ;)
edit:
I have succeded to stop my game from getting a crash by 'PUSHAD/POPAD' - saving and restoring registers, so my code looks like this:
Code:
void Naked NewCooldown()
{
__asm
{
MOV EAX, [ESP+0x04]
MOV [ECX+0x20], EAX
PUSH EAX
MOV EAX, OFFSET info
PUSH EAX
PUSHAD
CALL DWORD PTR [printf]
POPAD
ADD ESP, 0x08
RETN 4
}
}
but something must be wrong because instead of "cooldown value: %d" I get this:
Code:
ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(
~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý
(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~
ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ý(
~ý(~ý(~ý(~ý(~ý(~ý(~ý(~ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}ÉĆ}