I am trying to centre the description texts in the menus (at the moment they all have fixed X position). I have created some code to do this job (and a function already exists to count the width of all letters in a string). So the original code is this:
Push 2D [X Position of the description text string. This is the value the new code will change]
call 006F5B03
add esp,14
and the new is this:
call 00914237 [Jump to a blank area that I can add my own code to
The 2 instructions below (call 006F5B03 and add esp,14 ) are now nopped]
and at 00914237:
push ebp
mov ebp,esp
mov eax,009A7FF0
push eax [Push string address]
call 006F54A2 [Adds all character widths in string]
add esp,04
cdq
sub eax,edx
sar eax,1
mov edx,00000140
sub edx,eax
push edx [pushes new X position of the string]
call 006F5B03 [and now we are back to the original code]
add esp,14
mov esp,ebp
pop ebp
ret
This simply doesn't work (because I lack knowledge on how the stack works), so I am doing something very wrong. It returns to the completely wrong address.
Questions:
1. When making a call, do you always need to use push ebp mov ebp,esp / mov esp,ebp pop ebp ?
2. Is there a better way of doing the above
3. How do I ensure this call will jump back to the correct address?