Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 51
  1. #31
    ehex's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    150
    Reputation
    22
    Thanks
    555
    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.

  2. #32
    tdsx's Avatar
    Join Date
    Apr 2014
    Gender
    male
    Posts
    255
    Reputation
    10
    Thanks
    1,004
    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 https://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.

  3. #33
    MeepDarknessMeep's Avatar
    Join Date
    Aug 2012
    Gender
    female
    Posts
    725
    Reputation
    22
    Thanks
    922
    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.

  4. #34
    tdsx's Avatar
    Join Date
    Apr 2014
    Gender
    male
    Posts
    255
    Reputation
    10
    Thanks
    1,004
    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.

    https://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;
    }
    Last edited by tdsx; 01-14-2015 at 09:58 PM.

  5. #35
    MeepDarknessMeep's Avatar
    Join Date
    Aug 2012
    Gender
    female
    Posts
    725
    Reputation
    22
    Thanks
    922
    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

  6. #36
    tdsx's Avatar
    Join Date
    Apr 2014
    Gender
    male
    Posts
    255
    Reputation
    10
    Thanks
    1,004
    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.

  7. #37
    kingboy111's Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    129
    Reputation
    10
    Thanks
    103
    My Mood
    Sneaky
    how do i get the gary_state* ?????

  8. #38
    ehex's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    150
    Reputation
    22
    Thanks
    555
    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.

  9. #39
    tdsx's Avatar
    Join Date
    Apr 2014
    Gender
    male
    Posts
    255
    Reputation
    10
    Thanks
    1,004
    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.

  10. #40
    ExiledStyles's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Posts
    104
    Reputation
    10
    Thanks
    66
    maybe because you're counting the constructor, but what i've heard everyone is smarter than meep so you should listen to him

  11. #41
    tdsx's Avatar
    Join Date
    Apr 2014
    Gender
    male
    Posts
    255
    Reputation
    10
    Thanks
    1,004
    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.

  12. #42
    MeepDarknessMeep's Avatar
    Join Date
    Aug 2012
    Gender
    female
    Posts
    725
    Reputation
    22
    Thanks
    922
    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.

  13. #43
    ExiledStyles's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Posts
    104
    Reputation
    10
    Thanks
    66
    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

  14. #44
    MeepDarknessMeep's Avatar
    Join Date
    Aug 2012
    Gender
    female
    Posts
    725
    Reputation
    22
    Thanks
    922
    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.

  15. #45
    ExiledStyles's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Posts
    104
    Reputation
    10
    Thanks
    66
    yeah like i'd answer your kindergarten questions just to make you feel better
    dream on nerd

Page 3 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. [Help Request] Getting lua state in the new api
    By kasperbjerby in forum Garry's Mod Discussions & Help
    Replies: 36
    Last Post: 07-20-2014, 01:14 PM
  2. [Help Request] Getting values from game after injection
    By univex in forum C# Programming
    Replies: 9
    Last Post: 10-07-2013, 03:12 PM
  3. Means of grabbing Lua State from Injection
    By Dessix in forum Garry's Mod Discussions & Help
    Replies: 15
    Last Post: 06-11-2013, 04:06 AM
  4. So I keep getting kicked after injecting using the VA.
    By WhamBamm in forum DayZ Discussion
    Replies: 5
    Last Post: 01-31-2013, 03:42 AM
  5. Warrock closes after injection. Injector is not detected.
    By jacky5354 in forum WarRock Discussions
    Replies: 11
    Last Post: 11-29-2009, 09:36 AM