Skip to content

Added/Updated some things #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helpers_extended/source/Symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace Symbols

const std::vector<Symbol> GModDataPack_SendFileToClient = {
Symbol::FromName( "?SendFileToClient@GModDataPack@@QAEXHH@Z" ),
Symbol::FromSignature( "\x55\x8B\xEC\x83\xEC\x50\x53\x8B\x5D\x0C\x56\x8B\xF1\x89\x75\xF8" )
Symbol::FromSignature( "\x55\x8B\xEC\x83\xEC\x2A\x53\x8B\x5D\x0C\x56\x8B\xF1\x89\x75\xF8" )
};

const std::vector<Symbol> CNetChan_IsValidFileForTransfer = {
Expand Down
44 changes: 29 additions & 15 deletions include/GarrysMod/Lua/Interface.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
#ifndef GARRYSMOD_LUA_INTERFACE_H
#define GARRYSMOD_LUA_INTERFACE_H

#ifdef GMOD_USE_ILUAINTERFACE
#include "LuaInterface.h"

namespace GarrysMod::Lua
{
typedef ILuaInterface ILua;
}
#else
#include "LuaBase.h"

namespace GarrysMod::Lua
{
typedef ILuaBase ILua;
}
#endif

struct lua_State
{
#if ( defined( _WIN32 ) || defined( __linux__ ) || defined( __APPLE__ ) ) && \
Expand All @@ -17,7 +31,7 @@ struct lua_State
#error Unsupported platform
#endif

GarrysMod::Lua::ILuaBase* luabase;
GarrysMod::Lua::ILua *luabase;
};

#ifndef GMOD
Expand All @@ -38,40 +52,40 @@ struct lua_State
#define LUA_FUNCTION_STATIC( name ) static LUA_FUNCTION( name )
#else
#define GMOD_MODULE_OPEN() \
int gmod13_open__Imp( GarrysMod::Lua::ILuaBase* LUA ); \
int gmod13_open__Imp( GarrysMod::Lua::ILua *LUA ); \
GMOD_DLL_EXPORT int gmod13_open( lua_State* L ) \
{ \
return gmod13_open__Imp( L->luabase ); \
} \
int gmod13_open__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
int gmod13_open__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )

#define GMOD_MODULE_CLOSE() \
int gmod13_close__Imp( GarrysMod::Lua::ILuaBase* LUA ); \
int gmod13_close__Imp( GarrysMod::Lua::ILua *LUA ); \
GMOD_DLL_EXPORT int gmod13_close( lua_State* L ) \
{ \
return gmod13_close__Imp( L->luabase ); \
} \
int gmod13_close__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
int gmod13_close__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )

#define LUA_FUNCTION( FUNC ) \
int FUNC##__Imp( GarrysMod::Lua::ILuaBase* LUA ); \
int FUNC##__Imp( GarrysMod::Lua::ILua *LUA ); \
int FUNC( lua_State* L ) \
{ \
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \
GarrysMod::Lua::ILua *LUA = L->luabase; \
LUA->SetState(L); \
return FUNC##__Imp( LUA ); \
} \
int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )

#define LUA_FUNCTION_STATIC( FUNC ) \
static int FUNC##__Imp( GarrysMod::Lua::ILuaBase* LUA ); \
static int FUNC##__Imp( GarrysMod::Lua::ILua *LUA ); \
static int FUNC( lua_State* L ) \
{ \
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \
GarrysMod::Lua::ILua *LUA = L->luabase; \
LUA->SetState(L); \
return FUNC##__Imp( LUA ); \
} \
static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )

#define LUA_FUNCTION_DECLARE( FUNC ) \
int FUNC( lua_State *L )
Expand All @@ -81,25 +95,25 @@ struct lua_State

#define LUA_FUNCTION_IMPLEMENT( FUNC ) \
[[deprecated("Use LUA_FUNCTION_STATIC_MEMBER instead of LUA_FUNCTION_IMPLEMENT.")]] \
static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )

#define LUA_FUNCTION_WRAP( FUNC ) \
[[deprecated("Use LUA_FUNCTION_STATIC_MEMBER instead of LUA_FUNCTION_WRAP.")]] \
static int FUNC( lua_State *L ) \
{ \
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \
GarrysMod::Lua::ILua *LUA = L->luabase; \
LUA->SetState(L); \
return FUNC##__Imp( LUA ); \
}

#define LUA_FUNCTION_STATIC_MEMBER( FUNC ) \
static int FUNC( lua_State* L ) \
{ \
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \
GarrysMod::Lua::ILua *LUA = L->luabase; \
LUA->SetState(L); \
return FUNC##__Imp( LUA ); \
} \
static int FUNC##__Imp( GarrysMod::Lua::ILuaBase* LUA )
static int FUNC##__Imp( GarrysMod::Lua::ILua *LUA )
#endif
#endif

Expand Down
8 changes: 5 additions & 3 deletions include/GarrysMod/Lua/LuaConVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class ConVar;
class CCommand;
class ConCommand;

namespace GarrysMod
{
Expand All @@ -14,11 +15,12 @@ namespace GarrysMod
public:
virtual ~ILuaConVars( ) = 0;
virtual void Init( ) = 0;
virtual ConVar *CreateConVar( const char *, const char *, const char *, int ) = 0;
virtual ConCommand *CreateConCommand( const char *, const char *, int, void ( * )( const CCommand & ), int ( * )( const char *, char ( * )[128] ) ) = 0;
virtual ConVar *CreateConVar( const char *name, const char *defaultValue, const char *helpString, int flags ) = 0;
virtual ConCommand *CreateConCommand( const char *name, const char *helpString, int flags, void ( *callback )( const CCommand & ), int ( *completionFunc )( const char *, char ( * )[128] ) ) = 0;
virtual void DestroyManaged( ) = 0;
virtual void Cache( const char *, const char * ) = 0;
virtual void Cache( const char *key, const char *value ) = 0;
virtual void ClearCache( ) = 0;
virtual void SaveManaged( ) = 0;
};
}
}
74 changes: 22 additions & 52 deletions include/GarrysMod/Lua/LuaInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Bootil
struct lua_Debug;
class CCommand;
class Color;
class ConVar;
class ConCommand;

namespace GarrysMod
{
Expand Down Expand Up @@ -83,31 +85,33 @@ namespace GarrysMod
virtual void PopPath( ) = 0;
virtual const char *GetPath( ) = 0;
virtual int GetColor( int index ) = 0;
virtual void PushColor( Color color ) = 0;
virtual void *PushColor( Color color ) = 0; // ToDo: This seems to return something, but it hasn't been figured out what yet.
virtual int GetStack( int level, lua_Debug *dbg ) = 0;
virtual int GetInfo( const char *what, lua_Debug *dbg ) = 0;
virtual const char *GetLocal( lua_Debug *dbg, int n ) = 0;
virtual const char *GetUpvalue( int funcIndex, int n ) = 0;
virtual bool RunStringEx( const char *filename, const char *path, const char *stringToRun, bool run, bool printErrors, bool dontPushErrors, bool noReturns ) = 0;
virtual size_t GetDataString( int index, const char **str ) = 0;
virtual void ErrorFromLua( const char *fmt, ... ) = 0;
// Returns "<nowhere>" if nothing was found.
virtual const char *GetCurrentLocation( ) = 0;
virtual void MsgColour( const Color &col, const char *fmt, ... ) = 0;
// outStr is set to "!UNKNOWN" if it couldn't be found.
virtual void GetCurrentFile( std::string &outStr ) = 0;
virtual void CompileString( Bootil::Buffer &dumper, const std::string &stringToCompile ) = 0;
virtual bool CompileString( Bootil::Buffer &dumper, const std::string &stringToCompile ) = 0;
virtual bool CallFunctionProtected( int, int, bool ) = 0;
virtual void Require( const char *name ) = 0;
virtual const char *GetActualTypeName( int type ) = 0;
virtual void PreCreateTable( int arrelems, int nonarrelems ) = 0;
virtual void PushPooledString( int index ) = 0;
virtual const char *GetPooledString( int index ) = 0;
virtual int AddThreadedCall( ILuaThreadedCall * ) = 0; // NOTE: Returns the amount off queried threaded calls.
virtual void AppendStackTrace( char *, unsigned long ) = 0;
virtual void *CreateConVar( const char *, const char *, const char *, int ) = 0;
virtual void *CreateConCommand( const char *, const char *, int, void ( * )( const CCommand & ), int ( * )( const char *, char ( * )[128] ) ) = 0;
virtual const char* CheckStringOpt( int iStackPos, const char* def ) = 0;
virtual int AddThreadedCall( ILuaThreadedCall *call ) = 0; // NOTE: Returns the number of queried threaded calls.
virtual void AppendStackTrace( char *, unsigned int ) = 0;
virtual ConVar *CreateConVar( const char *name, const char *defaultValue, const char *helpString, int flags ) = 0;
virtual ConCommand *CreateConCommand( const char *name, const char *helpString, int flags, void ( *callback )( const CCommand & ), int ( *completionFunc )( const char *, char ( * )[128] ) ) = 0;
virtual const char *CheckStringOpt( int iStackPos, const char *def ) = 0;
virtual double CheckNumberOpt( int iStackPos, double def ) = 0;
virtual void RegisterMetaTable( const char* name, ILuaObject* tbl ) = 0;
virtual int RegisterMetaTable( const char *name, ILuaObject *tbl ) = 0;
};

class CLuaInterface : public ILuaInterface
Expand All @@ -134,11 +138,11 @@ namespace GarrysMod

// The purpose of all members that start with _ are unknown
int _1; // Always 1?
const char* m_sCurrentPath;
const char *m_sCurrentPath;
int _2; // Always 16?
int _3; // Always 0?
int m_iPushedPaths;
const char* m_sLastPath;
const char *m_sLastPath;
std::list<ILuaThreadedCall*> m_pThreadedCalls;

#ifdef __APPLE__
Expand All @@ -147,51 +151,17 @@ namespace GarrysMod

#endif

ILuaObject* m_pProtectedFunctionReturns[4];
ILuaObject* m_pTempObjects[32];
ILuaObject *m_pProtectedFunctionReturns[4];
ILuaObject *m_pTempObjects[32];
unsigned char m_iRealm; // CLIENT = 0, SERVER = 1, MENU = 2
ILuaGameCallback* m_pGameCallback;
ILuaGameCallback *m_pGameCallback;
char m_sPathID[32]; // lsv, lsc or LuaMenu
int m_iCurrentTempObject;
ILuaObject* m_pGlobal;
ILuaObject* m_pStringPool;
// But wait, there's more. In the next fields the metatables objects are saved, but idk if it just has a field for each metatable or if it uses a map.
char _5[40];
ILuaObject* m_pWeaponMeta;
ILuaObject* m_pVectorMeta;
ILuaObject* m_pAngleMeta;
ILuaObject* m_pPhysObjMeta;
ILuaObject* m_pISaveMeta;
ILuaObject* m_pIRestoreMeta;
ILuaObject* m_pCTakeDamageInfoMeta;
ILuaObject* m_pCEffectDataMeta;
ILuaObject* m_pCMoveDataMeta;
ILuaObject* m_pCRecipientFilterMeta;
ILuaObject* m_pCUserCmd;
ILuaObject* _6; // Unknown.
ILuaObject* m_pIMaterialMeta;
ILuaObject* m_pPanelMeta;
ILuaObject* m_pCLuaParticleMeta;
char _7[3];
ILuaObject* m_pITextureMeta;
ILuaObject* m_pBf_readMeta;
ILuaObject* m_pConVarMeta;
ILuaObject* m_pIMeshMeta;
ILuaObject* m_pVMatrixMeta;
ILuaObject* m_pCSoundPatchMeta;
ILuaObject* m_pPixelvis_handle_tMeta;
ILuaObject* m_pDlight_tMeta;
ILuaObject* m_pIVideoWriterMeta;
ILuaObject* m_pFileMeta;
ILuaObject* m_pCLuaLocomotionMeta;
ILuaObject* m_pPathFollowerMeta;
ILuaObject* m_pCNavAreaMeta;
ILuaObject* m_pIGModAudioChannelMeta;
ILuaObject* m_pCNavLadderMeta;
ILuaObject* m_pCNewParticleEffectMeta;
ILuaObject* m_pProjectedTextureMeta;
ILuaObject* m_pPhysCollideMeta;
ILuaObject* m_pSurfaceInfoMeta;
ILuaObject *m_pGlobal;
ILuaObject *m_pStringPool;
unsigned char m_iMetaTableIDCounter;
// Their index is based off their type. means m_MetaTables[Type::Entity] returns the Entity metatable though they can be NULL as its only filled by CreateMetaTableType.
GarrysMod::Lua::ILuaObject *m_pMetaTables[255];
};
}
}
1 change: 1 addition & 0 deletions include/GarrysMod/Lua/LuaObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ namespace GarrysMod
virtual void SetMemberMatrix( int, VMatrix const * ) = 0;

virtual void SetMemberPhysObject( const char *, IPhysicsObject * ) = 0;
virtual double GetMemberDouble( float, double ) = 0;
};

class CLuaObject : public ILuaObject
Expand Down
48 changes: 34 additions & 14 deletions include/GarrysMod/Lua/LuaShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,58 @@ namespace GarrysMod
};
}

struct File
struct LuaFile
{
~LuaFile();
int time;
#ifdef WIN32
std::string name;
std::string source;
std::string contents;
#else
const char *name;
const char *source;
const char *contents;
#endif
Bootil::AutoBuffer compressed;
#ifndef WIN32
int random; // Unknown thing
#endif
unsigned int timesloadedserver;
unsigned int timesloadedclient;
};

struct LuaFindResult
{
std::string fileName;
bool isFolder;
};

class ILuaShared
{
public:
virtual ~ILuaShared( ) = 0;
virtual void Init( void *( * )( const char *, int * ), bool, CSteamAPIContext *, IGet * ) = 0;
// NOTE: magicBool - could maybe be bIsDedicated? true if its a dedicated server?
virtual void Init( void *( *interfaceFactory )( const char *, int * ), bool magicBool, CSteamAPIContext *context, IGet *pGet ) = 0;
virtual void Shutdown( ) = 0;
virtual void DumpStats( ) = 0;
virtual ILuaInterface *CreateLuaInterface( unsigned char, bool ) = 0;
virtual void CloseLuaInterface( ILuaInterface * ) = 0;
virtual ILuaInterface *GetLuaInterface( unsigned char ) = 0;
virtual File *LoadFile( const std::string &path, const std::string &pathId, bool fromDatatable, bool fromFile ) = 0;
virtual File *GetCache( const std::string & );
virtual void MountLua( const char * ) = 0;
virtual void MountLuaAdd( const char *, const char * ) = 0;
virtual void UnMountLua( const char * ) = 0;
virtual void SetFileContents( const char *, const char * ) = 0;
virtual void SetLuaFindHook( LuaClientDatatableHook * ) = 0;
virtual void FindScripts( const std::string &, const std::string &, std::vector<std::string> & ) = 0;
virtual ILuaInterface *CreateLuaInterface( unsigned char realm, bool unknown ) = 0;
virtual void CloseLuaInterface( ILuaInterface *luaInterface ) = 0;
virtual ILuaInterface *GetLuaInterface( unsigned char realm ) = 0;
virtual LuaFile *LoadFile( const std::string &path, const std::string &pathId, bool fromDatatable, bool fromFile ) = 0;
virtual LuaFile *GetCache( const std::string &fileName );
virtual void MountLua( const char *pathID ) = 0;
virtual void MountLuaAdd( const char *file, const char *pathID ) = 0;
virtual void UnMountLua( const char *pathID ) = 0;
// Probably: unknown1 = fileName | unknown2 = pathID
virtual void SetFileContents( const char *unknown1, const char *unknown2 ) = 0;
virtual void SetLuaFindHook( LuaClientDatatableHook *hook ) = 0;
virtual void FindScripts( const std::string &path, const std::string &pathID, std::vector<LuaFindResult> &outPut ) = 0;
virtual const char *GetStackTraces( ) = 0;
virtual void InvalidateCache( const std::string & ) = 0;
// probably unknown = fileName?
virtual void InvalidateCache( const std::string &unknown ) = 0;
virtual void EmptyCache( ) = 0;
virtual bool ScriptExists( const std::string &file, const std::string &path, bool unknown ) = 0;
};
}
}
Loading