View previous topic :: View next topic |
Author |
Message |
yazigegeda Expert Cheater Reputation: 0
Joined: 22 Jan 2019 Posts: 159
|
Posted: Fri Sep 27, 2019 7:32 am Post subject: How can I use CreateThread? |
|
|
As shown below: How can I use lua to write the same effect as the thread freeze that comes with the cheat engine? I really need a thread to lock the value of an address, but I don't know how to write lua, help me.
Description: |
|
Filesize: |
21.23 KB |
Viewed: |
4733 Time(s) |
|
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Fri Sep 27, 2019 12:37 pm Post subject: |
|
|
Use the createThread function:
Code: |
Thread Class: (Inheritance: Object)
createThread(function(Thread,...), ...) :
Executes the given function in another thread using the systems thread mechanism
The function returns the Thread class object
function declaration: function (Thread, ...) |
Keep in mind Lua is not thread-safe, so you may run into issues doing this. If you need to do any UI calls/updates, you have to use:
Code: |
Methods:
synchronize(function(thread, ...), ...) :
Called from inside the thread. This wil cause the tread to get the main thread to execute the given function and wait for it to finish.
Usually for GUI access
Returns the return value of the given function
|
_________________
- Retired. |
|
Back to top |
|
|
yazigegeda Expert Cheater Reputation: 0
Joined: 22 Jan 2019 Posts: 159
|
Posted: Fri Sep 27, 2019 7:40 pm Post subject: |
|
|
atom0s wrote: | Use the createThread function:
Code: |
Thread Class: (Inheritance: Object)
createThread(function(Thread,...), ...) :
Executes the given function in another thread using the systems thread mechanism
The function returns the Thread class object
function declaration: function (Thread, ...) |
Keep in mind Lua is not thread-safe, so you may run into issues doing this. If you need to do any UI calls/updates, you have to use:
Code: |
Methods:
synchronize(function(thread, ...), ...) :
Called from inside the thread. This wil cause the tread to get the main thread to execute the given function and wait for it to finish.
Usually for GUI access
Returns the return value of the given function
|
|
Can you post the sample code? I don't understand what you say. . . .
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Sat Sep 28, 2019 12:30 am Post subject: |
|
|
Code: |
createThread(function (threadObj)
-- Loop until the thread is terminated..
while (not threadObj.Terminated) do
-- Sleep to prevent excessive CPU usage..
Sleep(10);
-- Do your code here.. (print for example)..
print('Tick..');
end
end);
|
threadObj is a pointer to the Thread instance created.
_________________
- Retired. |
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Sat Sep 28, 2019 12:30 am Post subject: |
|
|
It can be used with the following seen in celua.txt:
Code: |
Thread Class: (Inheritance: Object)
createThread(function(Thread,...), ...) :
Executes the given function in another thread using the systems thread mechanism
The function returns the Thread class object
function declaration: function (Thread, ...)
createThreadSuspended(function(Thread,...), ...) :
Same as createNativeThread but it won't run until resume is called on it
properties
name: string - This name will be shown when the thread terminated abnormally
Finished: boolean - Returns true if the thread has reached the end. Do not rely on this if the thread is freeOnTerminate(true) (which is the default)
Terminated: boolean - Returns true if the Terminate method has been called
methods
freeOnTerminate(state) :
When set to true the thread object will free itself when the function ends (default=true)
Note: Use this only from inside the thread function as the thread might have already terminated and freed itself when called
synchronize(function(thread, ...), ...) :
Called from inside the thread. This wil cause the tread to get the main thread to execute the given function and wait for it to finish.
Usually for GUI access
Returns the return value of the given function
waitfor() :
Waits for the given thread to finish (Not recommended to call this from inside the thread itself)
suspend() :
Suspend the thread's execution
resume() :
Resume the thread's execution
terminate() :
Tells the thread it should terminate. The Terminated property will become true
|
You should call terminate on the thread in some manner when your code does not need to run anymore, or that the trainer/CE is being closed.
_________________
- Retired. |
|
Back to top |
|
|
|