| View previous topic :: View next topic |
| Author |
Message |
Kyokyonos Newbie cheater
Reputation: 0
Joined: 14 Apr 2009 Posts: 19
|
Posted: Sun Dec 22, 2013 8:21 pm Post subject: Proper way to end/disable createthread() |
|
|
So...
I recently noticed this "createthread()" function which seems way more efficient as opposed to 'hijacking' some ingame functionality to make a jump to a potentially long and time consuming (2-4 second) AA script.
I saw the 2009 thread on "createthread understanding", but still not sure how to 'safely' undo createthread().
I've made some simple AA scripts using createthread() that do some math, change values, check some conditions, or store values from addresses into some allocated addresses and it seems to work fine when I just put 'ret' at the end to return to the calling function that supposedly terminates the created thread. When I have longer scripts that involve searching/looping and a few of jumps... I try making a conditional jump to a label with 'ret' (and have tried having the conditional jump point to the main content of the script instead), but it seems to crash more often then not when the debugger gets to 'ret'. As a way around the crashing, I sometime make it loop through a long (10hr+) sleep cycle when it's done and lately have been omitting 'ret' entirely. But the concern arises if I need to re-enable the script... I assume multiple threads are created.
Is 'ret' necessary for createthread() to terminate itself? Perhaps this has something to do with my understanding of assembly ]:
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25830 Location: The netherlands
|
Posted: Sun Dec 22, 2013 9:17 pm Post subject: |
|
|
When a thread starts [esp] contains the address of ExitThread. So when the thread executes ret with a proper stack, it will call ExitThread and exit
The reason you crash is most likely a broken stack (e.g wrong parameter count when calling a function, or the wrong calling convention (cdecl requires the caller to undo the parameter pushes)
You could of course call ExitThread yourself, but this indicates that there's something wrong in your code
_________________
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 |
|
 |
Kyokyonos Newbie cheater
Reputation: 0
Joined: 14 Apr 2009 Posts: 19
|
Posted: Sun Dec 22, 2013 10:19 pm Post subject: |
|
|
You were right! After closer inspection, there were a few inconsistencies with a few registers being pushed/popped on the stack in the code. Oops! No more crashes. Thanks!
Now I know how important the state of registers are before and after calling subroutines.
|
|
| Back to top |
|
 |
|