So I recently created a Module, cuz I wanted to do something in C++ and saw that modules are a thing and thought that was awesome so I started my Module and in the Headers I found the Method "RunString" and tried that out.
When I do this:
LUA->RunString("", "", "local TestFrame = vgui.Create(\"DHTML\")", true, true);
My game just instantly crashes, why is that? (And I also tested it with other stuff and that works fine)
This is the interface you should be using. https://github.com/Facepunch/gmod-module-base/blob/master/include/GarrysMod/Lua/LuaBase.h
It doesn't contain the method RunString as that is an internal method that can change "position" at anytime. There is a way to invoke it but it requires a bit of reverse engineering knowledge or using a different interface (guessing the one you are using is outdated) and may break when Garry's Mod updates.
If you really want to go down the rabbit hole check links.
https://en.wikipedia.org/wiki/Virtual_method_table
https://stackoverflow.com/questions/3972548/virtual-dispatch-implementation-details
https://www.unknowncheats.me/forum/source-engine/119285-dump-vtable-css-gmod-tf2-etc.html - Downloading dylibs from steamcmd might not work anymore but, the rest is useful
https://github.com/SteamRE/DepotDownloader - This is how I have been getting dylibs for steam games
https://steamdb.info/app/4000/
https://www.hex-rays.com/products/ida/ - 10/10 disassembler
Okay, well so still if I use that header,
aswell as this code:
LUA->PushSpecial(SPECIAL_GLOB);
LUA->GetField(-1, "CompileString");
LUA->PushString("local TestFrame = vgui.Create(\"DHTML\")
");
LUA->PushString("");
LUA->PushBool(true);
LUA->Call(3, 1);
LUA->Push(2);
LUA->Call(0, 0);
LUA->Pop(2);
It still crashes (still print or similar work fine)
If you're trying to use this to bypass CAC, it doesn't work anymore.
Im not trying to do anything with anticheats ? I just wanted to convert an old gui of mine to a module for fun and then found out DHTML is crashing the game when called through C++ and was curious about why that happens
At first glance I see you are only allowing lua to return 1 result from CompileString thus when calling LUA->Push(2) you are attempting to push a value from stack that does not exist. Additionally return #2 is a string according to CompileString.
This might work for you.
LUA->PushSpecial(SPECIAL_GLOB);
LUA->GetField(-1, "CompileString");
LUA->PushString("local TestFrame = vgui.Create(\"DHTML\")");
LUA->PushString("");
LUA->PushBool(true);
// virtual void Call( int iArgs, int iResults ) = 0;
LUA->Call(3, 2); // Changed iResults from 1 to 2.
LUA->Push(1); // 1 now contains function
// 2 now contains error string
LUA->Call(0, 0);
LUA->Pop();
LUA->Pop();
The lua stack interface was difficult for me to understand (honestly I still don't fully understand it) however, I found that the following links / examples helped me and may help you debug issues going forward.
https://stackoverflow.com/questions/6137684/iterate-through-lua-table
https://stackoverflow.com/questions/18445022/lua-c-api-whats-the-difference-between-lua-gettop-and-1
It could be that it crashes because it the module loaded on start up (to early for DHTML maybe). Does it crash if you require it on the client side while the game is running? I can also think of a lua error being thrown inside CompileString calls inside binaries that causes the game to freak out an crash especially doing on startup. You need to know that lua errors caused by binary modules can do nasty things. Such errors are not try-catch able nor checkable and stops the execution of your binary code, because they actually a jump operation that goes into the error rotine inside the Lua core. It stops everything in side your functions from being called/run that comes afterwards. It even prevents any calling of destructors of objects that are instanced by pointer or even by value (which would get theirs called automatically).
Sorry, you need to Log In to post a reply to this thread.