Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How can I use CreateThread?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
yazigegeda
Expert Cheater
Reputation: 0

Joined: 22 Jan 2019
Posts: 159

PostPosted: Fri Sep 27, 2019 7:32 am    Post subject: How can I use CreateThread? Reply with quote

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.


1.png
 Description:
 Filesize:  21.23 KB
 Viewed:  4725 Time(s)

1.png


Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Fri Sep 27, 2019 12:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
yazigegeda
Expert Cheater
Reputation: 0

Joined: 22 Jan 2019
Posts: 159

PostPosted: Fri Sep 27, 2019 7:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sat Sep 28, 2019 12:30 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sat Sep 28, 2019 12:30 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites