Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #gm_runlua.cpp(main)
- #define _RETAIL
- #define GAME_DLL
- //hey let's just include everything possible
- #include "GMLuaModule.h"
- #include "windows.h"
- #include <convar.h>
- #include <public/icvar.h>
- #include <tier1/tier1.h>
- #include <tier2/tier2.h>
- #include <tier3/tier3.h>
- #include <eiface.h>
- #include <interface.h>
- #include <detours.h>
- #include <vfnhook.h>
- GMOD_MODULE( Init, Shutdown );
- ILuaInterface *gLua = NULL;
- ICvar *g_pCVar = NULL;
- //(ICvar*)interfaceFactory(CVAR_INTERFACE_VERSION, NULL);
- //ICvar *icvar = NULL;
- DEFVFUNC(LuaInterfaceInit, bool, (ILuaInterface* pInterface, NULL));
- bool VFUNC luaInit(ILuaInterface* pInterface, NULL) {
- gLua->Msg("Hook called!");
- return LuaInterfaceInit(pInterface);
- }
- const char *runString;
- const char *filePath;
- bool doRun;
- bool showErrors;
- void runscript( const char *p, bool dor=true, bool showerr=true ) {
- gLua->FindAndRunScript(p, dor, showerr);
- }
- void runscript_concmd( const CCommand &args ) {
- gLua->Msg("Args 0-3: %s, %s, %s, %s",args.Arg(0), args.Arg(1), args.Arg(2), args.Arg(3));
- const char *p = args.Arg(1);
- bool dor = true;
- bool showerr = true;
- gLua->FindAndRunScript(p, dor, showerr);
- }
- void runstring_concmd( const CCommand &args ) {
- const char *strtorun = args.Arg(1);
- gLua->RunString("tempstrcontainerconcmd.txt", "./", strtorun, true, true);
- }
- LUA_FUNCTION ( runFile ) {
- gLua->CheckType( 1, GLua::TYPE_STRING );
- gLua->CheckType( 2, GLua::TYPE_BOOL );
- gLua->CheckType( 3, GLua::TYPE_BOOL );
- filePath = gLua->GetString(1);
- doRun = gLua->GetBool(1);
- showErrors = gLua->GetBool(2);
- runscript(filePath, doRun, showErrors);
- return 0;
- }
- LUA_FUNCTION ( runLua ) {
- gLua->CheckType( 1, GLua::TYPE_STRING );
- runString = gLua->GetString(1);
- gLua->RunString("tempstrcontainer.txt", "./", runString, true, true);
- return 0;
- }
- class CBase : public IConCommandBaseAccessor
- {
- public:
- bool RegisterConCommandBase(ConCommandBase *pVar)
- {
- gLua->Msg( "RegisterConCommandBase called for: %s.\n", pVar->GetName() );
- g_pCVar->RegisterConCommand(pVar);
- return 0;
- }
- } s_CBase;
- /*
- CON_COMMAND(runfile, "Runs a file.") {
- gLua->FindAndRunScript("cockfishing.lua", true, true);
- }
- */
- static ConCommand runfile_command( "runfile", runscript_concmd, "Runs a given lua file." );
- static ConCommand runstring_command( "runlua", runstring_concmd, "Runs a given lua string." );
- int Init( lua_State *L ) {
- gLua = Lua();
- //Extract g_pCVar
- CreateInterfaceFn vstdFactory = Sys_GetFactory("vstdlib.dll");
- if(!vstdFactory) {
- gLua->Msg("yeah sys_getfactory did not work");
- return 0;
- }
- g_pCVar = (ICvar*)vstdFactory(CVAR_INTERFACE_VERSION, NULL);
- // ConCommandBase* CMD = g_pCVar->GetCommands();
- gLua->Msg( "gmcl_runlua loaded.\n" );
- gLua->SetGlobal( "runLua", runLua );
- gLua->SetGlobal( "runFile", runFile );
- // ConVar_Register(0, &fuckfuckfuck);
- // ConCommand *runfile = new ConCommand( "runfile", runscript_concmd, "runs a script", 0, 0);
- ConVar_Register(0, &s_CBase);
- HOOKVFUNC(gLua, 2, LuaInterfaceInit, luaInit);
- return 0;
- }
- int Shutdown( lua_State *L ) {
- ConVar_Unregister();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement