You are not logged in.
Pages: 1
[center][size=3]Fixed create_thread For CLEO Scripts[/size][/center]
My function to create threads within a CLEO Script worked well, but for one flaw.
It's actually a problem with Sanny Builder not expecting a new thread within a CLEO Script. The label pointers are relative to the file and not to the new thread like they are supposed to be. I'm able to fix this by patching the base IP of the new thread to match the one that created it, so that jumps are processed relative to the file and not the thread.
This doesn't affect the thread which created it at all. I've found out that [opcode]0A93[/opcode] simply does nothing when used in this thread (still use end_thread to end this thread). I was hoping that CLEO would end the whole script, providing a pretty useful feature, but I guess it might work by patching the thread name.
Anyway, all end_custom_thread will do is return the script to the game, like [opcode]003D[/opcode] or any other invalid opcode does, as I explained in another post.
So here's the fixed version, where you can actually jump to labels properly.
{$CLEO} 0000: while true wait 0 if 0ADC: test_cheat "NEWTHREAD" then 0AB1: call_scm_func @CreateThread 3 @MyNewThread 1 6 end end :MyNewThread wait 0 0ACD: show_text_highpriority "I'm running continuously! I'm tired." time 1 jump @MyNewThread // before, this would have jumped to code below - now it jumps correctly :CreateThread 0A9F: 32@ = current_thread_pointer 000A: 32@ += 0x10 0A8D: 32@ = read_memory 32@ size 4 virtual_protect 0 0062: 32@ -= 0@ 0AA7: call_function 0x464C20 num_params 1 pop 1 32@ 33@ 005A: 32@ += 0@ 000A: 33@ += 0x10 0A8C: write_memory 33@ size 4 value 32@ virtual_protect 0 000A: 33@ += 0x2C for 32@ = 0 to 30 0A8C: write_memory 33@ size 4 value 1@(32@,30i) virtual_protect 0 000A: 33@ += 4 end 0AB2: ret 0
The new code:
005A: 32@ += 0@ // just restores the thread pointer, because we changed it before. 000A: 33@ += 0x10 // go to the thread base IP 0A8C: write_memory 33@ size 4 value 32@ virtual_protect 0 // write the base IP of the current thread to the new thread
Hope you like. I was lazy and copy'n'pasted.
Offline
Not sure if it's really useful but anyway you deserve some cookies for the efforts.
ps
dunno if SCM funcs uses this space too, I believe so
no they use its own stacks, at least in CLEO 3
Offline
Hmm.. that would unfortunately mean it wouldn't be easy to determine which thread created the SCM Function to create more advanced capabilities for SCM Functions.
The idea behind create thread links to my plan of doing "callback" style scripting. Interesting to see how well it works in CLEO and if it makes creating advanced stuff any easier.
Pretty soon I'll try to have Windows 7 ported to San Andreas
Offline
Pages: 1