| View previous topic :: View next topic |
| Author |
Message |
Icesythe7 How do I cheat?
Reputation: 0
Joined: 17 Jan 2016 Posts: 7
|
Posted: Tue Mar 01, 2022 10:51 pm Post subject: Plugin - New Thread |
|
|
| I'm trying to create a plugin which works fine however if I create a new thread with a while loop it just closes CE, how might one create a new thread in a plugin? (Can't obviously use while loop in plugin thread or will lock up CE until while is done) (C++)
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 473
Joined: 09 May 2003 Posts: 25909 Location: The netherlands
|
Posted: Wed Mar 02, 2022 6:19 am Post subject: |
|
|
it depends on what your thread does. You are aware that the dll runs inside the context of CE and not the target process?
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Icesythe7 How do I cheat?
Reputation: 0
Joined: 17 Jan 2016 Posts: 7
|
Posted: Wed Mar 02, 2022 2:28 pm Post subject: |
|
|
| Dark Byte wrote: | | it depends on what your thread does. You are aware that the dll runs inside the context of CE and not the target process? |
Yes I'm aware so it's not possible to have a while loop in a plugin outside of CE's thread?
As far as what it did it didn't do anything just a naked while true for a test and it just closes cheat engine
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 473
Joined: 09 May 2003 Posts: 25909 Location: The netherlands
|
Posted: Wed Mar 02, 2022 4:52 pm Post subject: |
|
|
if it is a thread then it should be fine. But what kind of thread are you talking about and how do you create it ? And are you waiting for the thread to finish before continuing ?
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Icesythe7 How do I cheat?
Reputation: 0
Joined: 17 Jan 2016 Posts: 7
|
Posted: Wed Mar 02, 2022 10:55 pm Post subject: |
|
|
| Dark Byte wrote: | | if it is a thread then it should be fine. But what kind of thread are you talking about and how do you create it ? And are you waiting for the thread to finish before continuing ? |
just an std::thread and not waiting for it to finish I need it to just run forever basically because I plan on creating an overlay window with dxd9 but can't get a thread to stay alive yet xd.
| Code: | BOOL CEPlugin_InitializePlugin(PExportedFunctions ef, int pluginid)
{
self_plugin_id = pluginid;
exported = *ef;
if (exported.sizeofExportedFunctions != sizeof exported)
return false;
std::thread t1(NewThread);
... |
| Code: | [[noreturn]] void NewThread()
{
while (true)
{
printf("test\n");
}
} | this was the test I did
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 473
Joined: 09 May 2003 Posts: 25909 Location: The netherlands
|
Posted: Wed Mar 02, 2022 11:07 pm Post subject: |
|
|
remove that printf and see how that goes (there is no console)
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Icesythe7 How do I cheat?
Reputation: 0
Joined: 17 Jan 2016 Posts: 7
|
Posted: Wed Mar 02, 2022 11:10 pm Post subject: |
|
|
| Dark Byte wrote: | | remove that printf and see how that goes (there is no console) |
Still closes CE like 3 seconds after plugin loads, I have a message box at the end of the Init plugin function that is displayed saying the function returns successfully then CE just closes itself.
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 154
Joined: 06 Jul 2014 Posts: 4754
|
Posted: Wed Mar 02, 2022 11:10 pm Post subject: |
|
|
What comes after the ellipses is important. If you don't explicitly join or detach it, the destructor will call std::terminate, which is probably bad.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Icesythe7 How do I cheat?
Reputation: 0
Joined: 17 Jan 2016 Posts: 7
|
Posted: Wed Mar 02, 2022 11:14 pm Post subject: |
|
|
| ParkourPenguin wrote: | | What comes after the ellipses is important. If you don't explicitly join or detach it, the destructor will call std::terminate, which is probably bad. |
nothing thread related was under the impression if I call thread join then i freeze CE's thread again waiting for it, hence I need a new thread so the dll has its own thread to do stuff in without ce waiting for it
| Code: | BOOL CEPlugin_InitializePlugin(PExportedFunctions ef, int pluginid)
{
self_plugin_id = pluginid;
exported = *ef;
if (exported.sizeofExportedFunctions != sizeof exported)
return false;
std::thread t1(NewThread);
lua_game_state = std::make_unique<sol::state_view>(ef->GetLuaState());
auto& lua = *lua_game_state;
lua["testFunc"] = [](const uint64_t num1, const uint64_t num2)
{
return (num1 + num2) / 2;
};
lua.new_usertype<Vector3>("Vector3",
sol::constructors<Vector3(float, float, float)>(),
"x", &Vector3::x,
"y", &Vector3::y,
"z", &Vector3::z);
lua.new_usertype<Example>("ExampleClass", sol::no_constructor,
"health", &Example::health,
"maxHealth", &Example::max_health,
"pos", &Example::pos,
"getHealthPercent", &Example::getHealthPercent);
lua.set("Player", Example());
exported.ShowMessage(const_cast<char*>("Lua Test Plugin enabled!")); //this is printed
return true; //returns fine
} |
edit yep you were right destructor was being called automatically setting it globally fixed the issue xd
| Code: |
std::thread window_thread;
BOOL CEPlugin_InitializePlugin(PExportedFunctions ef, int pluginid)
{
self_plugin_id = pluginid;
exported = *ef;
if (exported.sizeofExportedFunctions != sizeof exported)
return false;
window_thread = std::thread(NewThread);
... |
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 154
Joined: 06 Jul 2014 Posts: 4754
|
|
| Back to top |
|
 |
Icesythe7 How do I cheat?
Reputation: 0
Joined: 17 Jan 2016 Posts: 7
|
Posted: Wed Mar 02, 2022 11:49 pm Post subject: |
|
|
| ParkourPenguin wrote: | You can also call detach.
snip cant post urls |
Yes but I need to kill the thread in disable plugin it kinda works but my console locks up instead of closing even tho I join and wait for the thread to close.
edit: fixed console issue
| Code: |
void NewThread()
{
if (AllocConsole())
{
console_window = GetConsoleWindow();
SetConsoleTitle("CE Plugin Debug Console");
FILE* stream;
freopen_s(&stream, "CONOUT$", "w", stdout);
}
static uint64_t num = 0;
while (!shutdown)
{
printf("Test %llu\n", num);
num++;
Sleep(1);
}
FreeConsole();
} |
| Code: |
BOOL CEPlugin_DisablePlugin()
{
shutdown = true;
window_thread.join();
if (console_window)
{
FreeConsole();
PostMessage(console_window, WM_CLOSE, 0, 0);
}
MessageBoxA(nullptr, "Disabled plugin", "Lua Test Plugin", MB_OK);
return true;
} |
seems to be working as expected now I appreciate the help!
|
|
| Back to top |
|
 |
|