Getting lua state in C++

Hello, so i’ve been working with C++ and I wanted to use the lua C api when making an injected module. But one thing that I cannot do is get the lua state. This is the code that I am using

#include "Interface.h"
#include "Windows.h" 
#include "LuaBase.h"
#include "Methods.h"

using namespace Methods;
using namespace Methods::table;
using namespace GarrysMod::Lua;
HMODULE lua_shared = GetModuleHandle( "lua_shared.dll" );
typedef int (*lua_CFunction) (lua_State *L);
typedef void (*pushvalue) ( lua_State* L, int index );
typedef void (*pushstring) ( lua_State *L, const char *S );
typedef void (*pushcfunction) ( lua_State *L, lua_CFunction F );
typedef void (*settable) ( lua_State *L, int index );
typedef void (*pop) ( lua_State *L, int n );
typedef void (*call) (lua_State *L, int nargs, int nresults);
typedef void (*getfield) (lua_State *L, int index, const char *k);

getfield lua_getfield = (getfield)GetProcAddress( lua_shared, "lua_getfield" );
call lua_call = (call)GetProcAddress( lua_shared, "lua_call" );
pushvalue lua_pushvalue = (pushvalue)GetProcAddress( lua_shared, "lua_pushvalue" );
pushstring lua_pushstring = (pushstring)GetProcAddress( lua_shared, "lua_pushstring" );
pushcfunction lua_pushcfunction = (pushcfunction)GetProcAddress( lua_shared, "lua_pushcfunction" );
settable lua_settable = (settable)GetProcAddress( lua_shared, "lua_settable" );
pop lua_pop = (pop)GetProcAddress( lua_shared, "lua_pop" );

int test( lua_State *state )
	lua_pushvalue( state, -10002 );
	lua_getfield( state, -1, "print" );
	lua_pushstring( state, "test" );
	lua_call( state, 1, 0 );
	lua_pop( state, -1 );
	return 0;

int gmod13_open( lua_State* state )
	lua_pushvalue( state, -10002 );
	lua_pushstring( state, "shitfunction" );
	lua_pushcfunction( state, test );
	lua_settable( state, -1 );
	lua_pop( state, -1 );
	return 0;

and the code I am using for getting the lua state is

lua_State* L;
lua_State* ILuaBase::GetLuaState()
return L;

This does nothing, it is supposed to print “test” in console when the function is called on.
I think I know what how to fix 1 of the problems, but the other I have no clue.
I’m still learning C++ but I know mostly how the lua C api works.

You should really use the interfaces if you don’t know what you are doing.

I see zero use for getting the Lua state(s) without using the gmod13_open function other than cheating. Even if you do have a legitimate use for this, posting a solution here is just going to make cheating easier for people.

Do not help this guy at all. He just wants to make a cheat. He also posts on MPGH.

HAC log (GMod U140419) @ [17.05.14 05:34:50PM] for -pg- wisezombieking (STEAM_0:0:51826775)

[00:12] data/nyaaaa_cheaters.txt-1869404167 (cheat)
[00:12] data/anxition/aimbot/button.txt-1837073529 (anxition)
[00:12] data/anxition/detection/toggle.txt-4261170317 (anxition)
[00:12] data/anxition/esp/Entitys.txt-NoFO (anxition)
[00:12] data/anxition/esp/Finder.txt-NoFO (anxition)
[00:12] data/anxition/esp/Printers.txt-NoFO (anxition)
[00:12] data/anxition/logger/ID.txt-NoFO (anxition)
[00:12] data/anxition/logger/Models.txt-NoFO (anxition)
[00:12] data/anxition/playlist/Name.txt-NoFO (anxition)
[00:12] data/anxition/playlist/URL.txt-NoFO (anxition)
[00:12] data/nh/default.txt-622687871 (/nh/)
[00:12] Bind=[["b" "mapex_wall"]] (mapex)
[00:12] Bind=[["g" "+mapex_speed"]] (+)
[00:12] Bind=[["i" "Ahack_Menu"]] (hack)
[00:12] Bind=[["m" "mapex_ent"]] (mapex)
[00:12] Bind=[["n" "mapex_esp"]] (mapex)
[00:12] Bind=[["o" "+darkness_menu"]] (+)
[00:12] Bind=[["PGUP" "lua_openscript_cl autorun/client/mapex_hud.lua; lua_openscript_cl autorun/client/mapex.lua"]] (mapex)
[00:12] Bind=[["MOUSE3" "+mapex_aim"]] (+)
[00:12] Datafile=data/Hera/log.txt-2013274 (*.txt) [[Log started 03_22_14 13_1]]
[00:32] lua/includes/extensions/Aimbot.lua-4179879415 (bot)
[00:32] lua/Aimbot.txt-2324325218 (bot)

More of his binds from another log @ [09.06.14 03:58:46PM]:

"MOUSE3" "bluebot_aimbot_toggle"
"p" "bluebot_menu"

All he is asking for is help. Don’t be an asshole. As long as he isn’t ruining servers and ddosing people there’s nothing wrong.


I’m almost feeling hypocritical right now

Cheating ruins the game for others on the server. Also your SteamID doesn’t look too good either, trollaux.

Hacking in single player =/= hacking online
This is a sandbox game, why not have fun messing around with your friends in a private server. Ruining something someone has worked on and invested capital into is a different story.

[editline]4th July 2014[/editline]

Hurr durr omfg you found me!
Good thing I don’t hack in multiplayer. You realize most of my bans for hacking are because people mistake my aim for aimbot correct? Do some research before you point fingers. You didn’t even accept my friend request on Steam when I only wanted to ask you a simple question. Stop being an ignorant narcissist who thinks what he thinks is the moral standards for everyone else.

Dude, you have code on your anti-cheat that destroys people’s gmods and try to over-write people’s C:/windows directory if they log your code.

Why do you even think you have the moral upper hand here. Wtf?

As I’ve said on my profile, I don’t accept friend requests from cheaters or people who would send another DoS/booter to my come connection. I’ve had it happen too often. You could always post on my Steam profile or PM me here.

…Which you only know becuase you yourself have stolen my clientside code (and leaked it on hackforums if I remember correctly).
Nothing I can do with Lua alone can destroy people’s GMods or PCs. It’s the hacks/file stealers they have running that do that if they join. For example using cvar3 to rebind all their keys if they have it.
I’m releasing HAC in 6 weeks when I close down my server, you can all have the code then.

I didn’t have cvar3 and it still rebinded my keys.

I’m not an asshole and I don’t send DoS attacks of any kind, and I am not a cheater. I enjoy playing all of my steam games legitimately without any sort of clientside modifications to give myself an advantage in multiplayer. Using a lua script in singleplayer that effects no one doesn’t make a difference to how I play otherwise. Inb4you quote anything I say on mpgh because you believe it all.

I would like to see what you mean as my steamid doesn’t look too good. Banned for what?

Any skid (god i hate using that word) can decrypt the lua cache and leak your anticheat. Its already been done a ton to everyone. Your fault for not using any type of encryption. (My apologies if you do, never been on your excuse for a server.)
>now hex looks in logs for a connection from my steam account wasting his time yet again