Skip to content

Commit f9e5512

Browse files
RaphaelIT7danielga
andauthored
Added/Updated some things (#115)
* Added all pooled strings. * Updated lua_typename * Allow one to directly use the ILuaInterface instead of the ILuaBase * Update some GarrysMod files * Update some args in GarrysMod files * Also update this file * Fix a typo * Update the Windows symbol * Requested changes + Updated some things * Misc changes Update VS version compatibility --------- Co-authored-by: Daniel <[email protected]>
1 parent 8a94dbe commit f9e5512

File tree

11 files changed

+729
-89
lines changed

11 files changed

+729
-89
lines changed

helpers_extended/source/Symbols.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ namespace Symbols
166166

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

172172
const std::vector<Symbol> CNetChan_IsValidFileForTransfer = {

include/GarrysMod/Lua/Interface.h

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
#ifndef GARRYSMOD_LUA_INTERFACE_H
22
#define GARRYSMOD_LUA_INTERFACE_H
33

4+
#ifdef GMOD_USE_ILUAINTERFACE
5+
#include "LuaInterface.h"
6+
7+
namespace GarrysMod::Lua
8+
{
9+
typedef ILuaInterface ILua;
10+
}
11+
#else
412
#include "LuaBase.h"
513

14+
namespace GarrysMod::Lua
15+
{
16+
typedef ILuaBase ILua;
17+
}
18+
#endif
19+
620
struct lua_State
721
{
822
#if ( defined( _WIN32 ) || defined( __linux__ ) || defined( __APPLE__ ) ) && \
@@ -17,7 +31,7 @@ struct lua_State
1731
#error Unsupported platform
1832
#endif
1933

20-
GarrysMod::Lua::ILuaBase* luabase;
34+
GarrysMod::Lua::ILua *luabase;
2135
};
2236

2337
#ifndef GMOD
@@ -38,40 +52,40 @@ struct lua_State
3852
#define LUA_FUNCTION_STATIC( name ) static LUA_FUNCTION( name )
3953
#else
4054
#define GMOD_MODULE_OPEN() \
41-
int gmod13_open__Imp( GarrysMod::Lua::ILuaBase* LUA ); \
55+
int gmod13_open__Imp( GarrysMod::Lua::ILua *LUA ); \
4256
GMOD_DLL_EXPORT int gmod13_open( lua_State* L ) \
4357
{ \
4458
return gmod13_open__Imp( L->luabase ); \
4559
} \
46-
int gmod13_open__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
60+
int gmod13_open__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )
4761

4862
#define GMOD_MODULE_CLOSE() \
49-
int gmod13_close__Imp( GarrysMod::Lua::ILuaBase* LUA ); \
63+
int gmod13_close__Imp( GarrysMod::Lua::ILua *LUA ); \
5064
GMOD_DLL_EXPORT int gmod13_close( lua_State* L ) \
5165
{ \
5266
return gmod13_close__Imp( L->luabase ); \
5367
} \
54-
int gmod13_close__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
68+
int gmod13_close__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )
5569

5670
#define LUA_FUNCTION( FUNC ) \
57-
int FUNC##__Imp( GarrysMod::Lua::ILuaBase* LUA ); \
71+
int FUNC##__Imp( GarrysMod::Lua::ILua *LUA ); \
5872
int FUNC( lua_State* L ) \
5973
{ \
60-
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \
74+
GarrysMod::Lua::ILua *LUA = L->luabase; \
6175
LUA->SetState(L); \
6276
return FUNC##__Imp( LUA ); \
6377
} \
64-
int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
78+
int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )
6579

6680
#define LUA_FUNCTION_STATIC( FUNC ) \
67-
static int FUNC##__Imp( GarrysMod::Lua::ILuaBase* LUA ); \
81+
static int FUNC##__Imp( GarrysMod::Lua::ILua *LUA ); \
6882
static int FUNC( lua_State* L ) \
6983
{ \
70-
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \
84+
GarrysMod::Lua::ILua *LUA = L->luabase; \
7185
LUA->SetState(L); \
7286
return FUNC##__Imp( LUA ); \
7387
} \
74-
static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
88+
static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )
7589

7690
#define LUA_FUNCTION_DECLARE( FUNC ) \
7791
int FUNC( lua_State *L )
@@ -81,25 +95,25 @@ struct lua_State
8195

8296
#define LUA_FUNCTION_IMPLEMENT( FUNC ) \
8397
[[deprecated("Use LUA_FUNCTION_STATIC_MEMBER instead of LUA_FUNCTION_IMPLEMENT.")]] \
84-
static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILuaBase* LUA )
98+
static int FUNC##__Imp( [[maybe_unused]] GarrysMod::Lua::ILua *LUA )
8599

86100
#define LUA_FUNCTION_WRAP( FUNC ) \
87101
[[deprecated("Use LUA_FUNCTION_STATIC_MEMBER instead of LUA_FUNCTION_WRAP.")]] \
88102
static int FUNC( lua_State *L ) \
89103
{ \
90-
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \
104+
GarrysMod::Lua::ILua *LUA = L->luabase; \
91105
LUA->SetState(L); \
92106
return FUNC##__Imp( LUA ); \
93107
}
94108

95109
#define LUA_FUNCTION_STATIC_MEMBER( FUNC ) \
96110
static int FUNC( lua_State* L ) \
97111
{ \
98-
GarrysMod::Lua::ILuaBase* LUA = L->luabase; \
112+
GarrysMod::Lua::ILua *LUA = L->luabase; \
99113
LUA->SetState(L); \
100114
return FUNC##__Imp( LUA ); \
101115
} \
102-
static int FUNC##__Imp( GarrysMod::Lua::ILuaBase* LUA )
116+
static int FUNC##__Imp( GarrysMod::Lua::ILua *LUA )
103117
#endif
104118
#endif
105119

include/GarrysMod/Lua/LuaConVars.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class ConVar;
66
class CCommand;
7+
class ConCommand;
78

89
namespace GarrysMod
910
{
@@ -14,11 +15,12 @@ namespace GarrysMod
1415
public:
1516
virtual ~ILuaConVars( ) = 0;
1617
virtual void Init( ) = 0;
17-
virtual ConVar *CreateConVar( const char *, const char *, const char *, int ) = 0;
18-
virtual ConCommand *CreateConCommand( const char *, const char *, int, void ( * )( const CCommand & ), int ( * )( const char *, char ( * )[128] ) ) = 0;
18+
virtual ConVar *CreateConVar( const char *name, const char *defaultValue, const char *helpString, int flags ) = 0;
19+
virtual ConCommand *CreateConCommand( const char *name, const char *helpString, int flags, void ( *callback )( const CCommand & ), int ( *completionFunc )( const char *, char ( * )[128] ) ) = 0;
1920
virtual void DestroyManaged( ) = 0;
20-
virtual void Cache( const char *, const char * ) = 0;
21+
virtual void Cache( const char *key, const char *value ) = 0;
2122
virtual void ClearCache( ) = 0;
23+
virtual void SaveManaged( ) = 0;
2224
};
2325
}
2426
}

include/GarrysMod/Lua/LuaInterface.h

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Bootil
1414
struct lua_Debug;
1515
class CCommand;
1616
class Color;
17+
class ConVar;
18+
class ConCommand;
1719

1820
namespace GarrysMod
1921
{
@@ -83,31 +85,33 @@ namespace GarrysMod
8385
virtual void PopPath( ) = 0;
8486
virtual const char *GetPath( ) = 0;
8587
virtual int GetColor( int index ) = 0;
86-
virtual void PushColor( Color color ) = 0;
88+
virtual void *PushColor( Color color ) = 0; // ToDo: This seems to return something, but it hasn't been figured out what yet.
8789
virtual int GetStack( int level, lua_Debug *dbg ) = 0;
8890
virtual int GetInfo( const char *what, lua_Debug *dbg ) = 0;
8991
virtual const char *GetLocal( lua_Debug *dbg, int n ) = 0;
9092
virtual const char *GetUpvalue( int funcIndex, int n ) = 0;
9193
virtual bool RunStringEx( const char *filename, const char *path, const char *stringToRun, bool run, bool printErrors, bool dontPushErrors, bool noReturns ) = 0;
9294
virtual size_t GetDataString( int index, const char **str ) = 0;
9395
virtual void ErrorFromLua( const char *fmt, ... ) = 0;
96+
// Returns "<nowhere>" if nothing was found.
9497
virtual const char *GetCurrentLocation( ) = 0;
9598
virtual void MsgColour( const Color &col, const char *fmt, ... ) = 0;
99+
// outStr is set to "!UNKNOWN" if it couldn't be found.
96100
virtual void GetCurrentFile( std::string &outStr ) = 0;
97-
virtual void CompileString( Bootil::Buffer &dumper, const std::string &stringToCompile ) = 0;
101+
virtual bool CompileString( Bootil::Buffer &dumper, const std::string &stringToCompile ) = 0;
98102
virtual bool CallFunctionProtected( int, int, bool ) = 0;
99103
virtual void Require( const char *name ) = 0;
100104
virtual const char *GetActualTypeName( int type ) = 0;
101105
virtual void PreCreateTable( int arrelems, int nonarrelems ) = 0;
102106
virtual void PushPooledString( int index ) = 0;
103107
virtual const char *GetPooledString( int index ) = 0;
104-
virtual int AddThreadedCall( ILuaThreadedCall * ) = 0; // NOTE: Returns the amount off queried threaded calls.
105-
virtual void AppendStackTrace( char *, unsigned long ) = 0;
106-
virtual void *CreateConVar( const char *, const char *, const char *, int ) = 0;
107-
virtual void *CreateConCommand( const char *, const char *, int, void ( * )( const CCommand & ), int ( * )( const char *, char ( * )[128] ) ) = 0;
108-
virtual const char* CheckStringOpt( int iStackPos, const char* def ) = 0;
108+
virtual int AddThreadedCall( ILuaThreadedCall *call ) = 0; // NOTE: Returns the number of queried threaded calls.
109+
virtual void AppendStackTrace( char *, unsigned int ) = 0;
110+
virtual ConVar *CreateConVar( const char *name, const char *defaultValue, const char *helpString, int flags ) = 0;
111+
virtual ConCommand *CreateConCommand( const char *name, const char *helpString, int flags, void ( *callback )( const CCommand & ), int ( *completionFunc )( const char *, char ( * )[128] ) ) = 0;
112+
virtual const char *CheckStringOpt( int iStackPos, const char *def ) = 0;
109113
virtual double CheckNumberOpt( int iStackPos, double def ) = 0;
110-
virtual void RegisterMetaTable( const char* name, ILuaObject* tbl ) = 0;
114+
virtual int RegisterMetaTable( const char *name, ILuaObject *tbl ) = 0;
111115
};
112116

113117
class CLuaInterface : public ILuaInterface
@@ -134,11 +138,11 @@ namespace GarrysMod
134138

135139
// The purpose of all members that start with _ are unknown
136140
int _1; // Always 1?
137-
const char* m_sCurrentPath;
141+
const char *m_sCurrentPath;
138142
int _2; // Always 16?
139143
int _3; // Always 0?
140144
int m_iPushedPaths;
141-
const char* m_sLastPath;
145+
const char *m_sLastPath;
142146
std::list<ILuaThreadedCall*> m_pThreadedCalls;
143147

144148
#ifdef __APPLE__
@@ -147,51 +151,17 @@ namespace GarrysMod
147151

148152
#endif
149153

150-
ILuaObject* m_pProtectedFunctionReturns[4];
151-
ILuaObject* m_pTempObjects[32];
154+
ILuaObject *m_pProtectedFunctionReturns[4];
155+
ILuaObject *m_pTempObjects[32];
152156
unsigned char m_iRealm; // CLIENT = 0, SERVER = 1, MENU = 2
153-
ILuaGameCallback* m_pGameCallback;
157+
ILuaGameCallback *m_pGameCallback;
154158
char m_sPathID[32]; // lsv, lsc or LuaMenu
155159
int m_iCurrentTempObject;
156-
ILuaObject* m_pGlobal;
157-
ILuaObject* m_pStringPool;
158-
// 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.
159-
char _5[40];
160-
ILuaObject* m_pWeaponMeta;
161-
ILuaObject* m_pVectorMeta;
162-
ILuaObject* m_pAngleMeta;
163-
ILuaObject* m_pPhysObjMeta;
164-
ILuaObject* m_pISaveMeta;
165-
ILuaObject* m_pIRestoreMeta;
166-
ILuaObject* m_pCTakeDamageInfoMeta;
167-
ILuaObject* m_pCEffectDataMeta;
168-
ILuaObject* m_pCMoveDataMeta;
169-
ILuaObject* m_pCRecipientFilterMeta;
170-
ILuaObject* m_pCUserCmd;
171-
ILuaObject* _6; // Unknown.
172-
ILuaObject* m_pIMaterialMeta;
173-
ILuaObject* m_pPanelMeta;
174-
ILuaObject* m_pCLuaParticleMeta;
175-
char _7[3];
176-
ILuaObject* m_pITextureMeta;
177-
ILuaObject* m_pBf_readMeta;
178-
ILuaObject* m_pConVarMeta;
179-
ILuaObject* m_pIMeshMeta;
180-
ILuaObject* m_pVMatrixMeta;
181-
ILuaObject* m_pCSoundPatchMeta;
182-
ILuaObject* m_pPixelvis_handle_tMeta;
183-
ILuaObject* m_pDlight_tMeta;
184-
ILuaObject* m_pIVideoWriterMeta;
185-
ILuaObject* m_pFileMeta;
186-
ILuaObject* m_pCLuaLocomotionMeta;
187-
ILuaObject* m_pPathFollowerMeta;
188-
ILuaObject* m_pCNavAreaMeta;
189-
ILuaObject* m_pIGModAudioChannelMeta;
190-
ILuaObject* m_pCNavLadderMeta;
191-
ILuaObject* m_pCNewParticleEffectMeta;
192-
ILuaObject* m_pProjectedTextureMeta;
193-
ILuaObject* m_pPhysCollideMeta;
194-
ILuaObject* m_pSurfaceInfoMeta;
160+
ILuaObject *m_pGlobal;
161+
ILuaObject *m_pStringPool;
162+
unsigned char m_iMetaTableIDCounter;
163+
// 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.
164+
GarrysMod::Lua::ILuaObject *m_pMetaTables[255];
195165
};
196166
}
197167
}

include/GarrysMod/Lua/LuaObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ namespace GarrysMod
150150
virtual void SetMemberMatrix( int, VMatrix const * ) = 0;
151151

152152
virtual void SetMemberPhysObject( const char *, IPhysicsObject * ) = 0;
153+
virtual double GetMemberDouble( float, double ) = 0;
153154
};
154155

155156
class CLuaObject : public ILuaObject

include/GarrysMod/Lua/LuaShared.h

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,58 @@ namespace GarrysMod
4343
};
4444
}
4545

46-
struct File
46+
struct LuaFile
4747
{
48+
~LuaFile();
4849
int time;
50+
#ifdef WIN32
4951
std::string name;
5052
std::string source;
5153
std::string contents;
54+
#else
55+
const char *name;
56+
const char *source;
57+
const char *contents;
58+
#endif
5259
Bootil::AutoBuffer compressed;
60+
#ifndef WIN32
61+
int random; // Unknown thing
62+
#endif
5363
unsigned int timesloadedserver;
5464
unsigned int timesloadedclient;
5565
};
5666

67+
struct LuaFindResult
68+
{
69+
std::string fileName;
70+
bool isFolder;
71+
};
72+
5773
class ILuaShared
5874
{
5975
public:
6076
virtual ~ILuaShared( ) = 0;
61-
virtual void Init( void *( * )( const char *, int * ), bool, CSteamAPIContext *, IGet * ) = 0;
77+
// NOTE: magicBool - could maybe be bIsDedicated? true if its a dedicated server?
78+
virtual void Init( void *( *interfaceFactory )( const char *, int * ), bool magicBool, CSteamAPIContext *context, IGet *pGet ) = 0;
6279
virtual void Shutdown( ) = 0;
6380
virtual void DumpStats( ) = 0;
64-
virtual ILuaInterface *CreateLuaInterface( unsigned char, bool ) = 0;
65-
virtual void CloseLuaInterface( ILuaInterface * ) = 0;
66-
virtual ILuaInterface *GetLuaInterface( unsigned char ) = 0;
67-
virtual File *LoadFile( const std::string &path, const std::string &pathId, bool fromDatatable, bool fromFile ) = 0;
68-
virtual File *GetCache( const std::string & );
69-
virtual void MountLua( const char * ) = 0;
70-
virtual void MountLuaAdd( const char *, const char * ) = 0;
71-
virtual void UnMountLua( const char * ) = 0;
72-
virtual void SetFileContents( const char *, const char * ) = 0;
73-
virtual void SetLuaFindHook( LuaClientDatatableHook * ) = 0;
74-
virtual void FindScripts( const std::string &, const std::string &, std::vector<std::string> & ) = 0;
81+
virtual ILuaInterface *CreateLuaInterface( unsigned char realm, bool unknown ) = 0;
82+
virtual void CloseLuaInterface( ILuaInterface *luaInterface ) = 0;
83+
virtual ILuaInterface *GetLuaInterface( unsigned char realm ) = 0;
84+
virtual LuaFile *LoadFile( const std::string &path, const std::string &pathId, bool fromDatatable, bool fromFile ) = 0;
85+
virtual LuaFile *GetCache( const std::string &fileName );
86+
virtual void MountLua( const char *pathID ) = 0;
87+
virtual void MountLuaAdd( const char *file, const char *pathID ) = 0;
88+
virtual void UnMountLua( const char *pathID ) = 0;
89+
// Probably: unknown1 = fileName | unknown2 = pathID
90+
virtual void SetFileContents( const char *unknown1, const char *unknown2 ) = 0;
91+
virtual void SetLuaFindHook( LuaClientDatatableHook *hook ) = 0;
92+
virtual void FindScripts( const std::string &path, const std::string &pathID, std::vector<LuaFindResult> &outPut ) = 0;
7593
virtual const char *GetStackTraces( ) = 0;
76-
virtual void InvalidateCache( const std::string & ) = 0;
94+
// probably unknown = fileName?
95+
virtual void InvalidateCache( const std::string &unknown ) = 0;
7796
virtual void EmptyCache( ) = 0;
97+
virtual bool ScriptExists( const std::string &file, const std::string &path, bool unknown ) = 0;
7898
};
7999
}
80100
}

0 commit comments

Comments
 (0)