HelpGetting Lua state after injection

Posts 31–45 of 51 · Page 3 of 4
Firstly you shouldn't really be using the sdk/gmod headers for this.
Styles gave you a very good example on how to do it without the sdk.

Personally, Why not just hook CreateLuaInterface and get a pointer to the client interface when its created?
It's probably been done like this by pretty much everyone, but it works.
Quote Originally Posted by ehex View Post
Firstly you shouldn't really be using the sdk/gmod headers for this.
Styles gave you a very good example on how to do it without the sdk.

Personally, Why not just hook CreateLuaInterface and get a pointer to the client interface when its created?
It's probably been done like this by pretty much everyone, but it works.
I'm using the SDK for other features as well, not just for getting the state.

Quote Originally Posted by MeepDarknessMeep View Post
luaL_dostring is defined like it is on http://pgl.yoyo.org/luai/i/luaL_dostring , right?
if not then luaL_loadstring only loads the string - it doesn't run it
yeah, it's defined correctly and works fine when not done through injection.
Quote Originally Posted by tdsx View Post
yeah, it's defined correctly and works fine when not done through injection.
have you tried using the exact code you just posted but with require? if that works (which if it worked as a gmodule it should work like that) we are overlooking something.
Quote Originally Posted by MeepDarknessMeep View Post
have you tried using the exact code you just posted but with require? if that works (which if it worked as a gmodule it should work like that) we are overlooking something.
it works with only luaL_dostring and none of the interface stuff, but when I call iface->GetLuaState() it crashes with this.

http://i.imgur.com/O3W5mue.png

Crashes
Code:
#include <Windows.h>
#include "Lua/Interface.h"
#include "icvar.h"
#include "ILuaShared.h"
#include "lua_shared.h"

using namespace GarrysMod::Lua;

GMOD_MODULE_OPEN()
{
	ILuaShared* shared;
	CreateInterfaceFn factory = Sys_GetFactory("lua_shared.dll");
	shared = (ILuaShared*)factory(GMOD_LUASHARED_INTERFACE, NULL);
	ILuaInterface* iface = shared->GetLuaInterface(State::SERVER);
	lua_State* istate = iface->GetLuaState(); // Crashes here

	return 0;
}

GMOD_MODULE_CLOSE()
{
	return 0;
}
Doesn't crash, and works
Code:
#include <Windows.h>
#include "Lua/Interface.h"
#include "icvar.h"
#include "ILuaShared.h"
#include "lua_shared.h"

using namespace GarrysMod::Lua;

GMOD_MODULE_OPEN()
{
	luaL_dostring(state, "print(1)");

	return 0;
}

GMOD_MODULE_CLOSE()
{
	return 0;
}
Quote Originally Posted by tdsx View Post
Code:
iface->GetLuaState()
why are you still doing thissssss

Code:
class ILuaInterface
{
public:
 void *vtable;
public:
 lua_State *L;

};
your vtable is probably wrong


also you don't have to make it a gmodule with GMOD_MODULE_OPEN and shit, all you have to do is require it and it should automatically call DllMain
Quote Originally Posted by MeepDarknessMeep View Post
why are you still doing thissssss

Code:
class ILuaInterface
{
public:
 void *vtable;
public:
 lua_State *L;

};
your vtable is probably wrong


also you don't have to make it a gmodule with GMOD_MODULE_OPEN and shit, all you have to do is require it and it should automatically call DllMain
ah, I see now. that fixed it. I remember you telling me something about the state being at a certain index in the interface. I put the stuff in GMOD_MODULE_OPEN because I wanted to show that the normal lua state worked, but whatever, it's okay now.

final code - LuaInterface.h
Code:
namespace GarrysMod
{
	namespace Lua
	{
		class ILuaInterface
		{
		public:
			void *vtable;
		public:
			lua_State* state;
		};
	}
}
main
Code:
#include <Windows.h>
#include "Lua/Interface.h"
#include "icvar.h"
#include "ILuaShared.h"
#include "lua_shared.h"

using namespace GarrysMod::Lua;

void Initialize()
{
	ILuaShared* shared;
	CreateInterfaceFn factory = Sys_GetFactory("lua_shared.dll");
	shared = (ILuaShared*)factory(GMOD_LUASHARED_INTERFACE, NULL);
	lua_State* state = shared->GetLuaInterface(State::SERVER)->state;

	luaL_dostring(state, "print(1)");
}

BOOL APIENTRY DllMain(HANDLE hModule, DWORD Reason, LPVOID lpReserved)
{
	if (Reason == DLL_PROCESS_ATTACH)
	{
		Initialize();

		return TRUE;
	}
}
sorry for being idiot. now I can finally work on other shit in this module.
Quote Originally Posted by MeepDarknessMeep View Post
why are you still doing thissssss

Code:
class ILuaInterface
{
public:
 void *vtable;
public:
 lua_State *L;

};
your vtable is probably wrong


also you don't have to make it a gmodule with GMOD_MODULE_OPEN and shit, all you have to do is require it and it should automatically call DllMain
why are you still posting this holy shit

anyway, why not just dump the lua shared vtable and call GetLuaInterface? Of course you'll have to get it each time you go into a new game.
Quote Originally Posted by ehex View Post
why are you still posting this holy shit

anyway, why not just dump the lua shared vtable and call GetLuaInterface? Of course you'll have to get it each time you go into a new game.
I already tried that but the vtables were wrong and this was already solved anyways using what Meep posted.
Quote Originally Posted by ExiledStyles View Post
maybe because you're counting the constructor, but what i've heard everyone is smarter than meep so you should listen to him
i find it funny you make fun of me yet still can't answer simple questions about c++
Quote Originally Posted by ehex View Post
why are you still posting this holy shit

anyway, why not just dump the lua shared vtable and call GetLuaInterface? Of course you'll have to get it each time you go into a new game.
this isn't the best way - GetLuaInterface is one of the more bad ways to get the CLuaInterface. The best way is to hook it on creation and store it in your own array of CLuaInterface pointers.
how do i get the gary_state* ?????
maybe because you're counting the constructor, but what i've heard everyone is smarter than meep so you should listen to him
Quote Originally Posted by ExiledStyles View Post
maybe because you're counting the constructor, but what i've heard everyone is smarter than meep so you should listen to him
they're not my headers, and I probably won't use them anymore.
that's exactly what he said before, nice job repeating the same thing he said before he gave out an alternative solution
you really are not being helpful
Quote Originally Posted by ExiledStyles View Post
that's exactly what he said before, nice job repeating the same thing he said before he gave out an alternative solution
you really are not being helpful
i still don't see you ever helping anyone or answering basic questions about c++, so i honestly wouldn't talk if i were you.
yeah like i'd answer your kindergarten questions just to make you feel better
dream on nerd
Posts 31–45 of 51 · Page 3 of 4

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us