Skip to content

Commit 91fa594

Browse files
authored
Added CLuaObject + Updated CLuaInterface (#109)
* Added CLuaObject + Extented CLuaInterface * Fixed 64x CLuaInterface offset * Added new functions to ILuaInterface. * Fixed two issues * Updated ILuaInterface::GetNewTable * Updated ILuaInterface again + Added ILuaThreadedCall * Woops * Added a note to the ILuaObject. * Fixed it Forgot to change it and to include <list> * Added a missing space Hopefully the last commit xd * Update from latest release
1 parent 2b19668 commit 91fa594

File tree

2 files changed

+106
-15
lines changed

2 files changed

+106
-15
lines changed

include/GarrysMod/Lua/LuaInterface.h

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

55
#include "LuaBase.h"
66
#include "SourceCompat.h"
7+
#include <list>
78

89
namespace Bootil
910
{
@@ -18,10 +19,16 @@ namespace GarrysMod
1819
{
1920
namespace Lua
2021
{
21-
class ILuaThreadedCall;
2222
class ILuaGameCallback;
2323
class ILuaObject;
2424

25+
class ILuaThreadedCall
26+
{
27+
public:
28+
virtual void Init( ) = 0; // NOTE: Always called on the main thread, so if you need to prepare something there, you can do it in here.
29+
virtual void Run( ILuaBase* ) = 0; // NOTE: After the call was executed, it won't be deleted! So call `delete this;` or reuse it.
30+
};
31+
2532
class ILuaInterface : public ILuaBase
2633
{
2734
public:
@@ -51,7 +58,7 @@ namespace GarrysMod
5158
virtual void DestroyObject( ILuaObject *obj ) = 0;
5259
virtual ILuaObject *CreateObject( ) = 0;
5360
virtual void SetMember( ILuaObject *table, ILuaObject *key, ILuaObject *value ) = 0;
54-
virtual void GetNewTable( ) = 0;
61+
virtual ILuaObject *GetNewTable( ) = 0;
5562
virtual void SetMember( ILuaObject *table, float key ) = 0;
5663
virtual void SetMember( ILuaObject *table, float key, ILuaObject *value ) = 0;
5764
virtual void SetMember( ILuaObject *table, const char *key ) = 0;
@@ -94,44 +101,97 @@ namespace GarrysMod
94101
virtual void PreCreateTable( int arrelems, int nonarrelems ) = 0;
95102
virtual void PushPooledString( int index ) = 0;
96103
virtual const char *GetPooledString( int index ) = 0;
97-
virtual void *AddThreadedCall( ILuaThreadedCall * ) = 0;
104+
virtual int AddThreadedCall( ILuaThreadedCall * ) = 0; // NOTE: Returns the amount off queried threaded calls.
98105
virtual void AppendStackTrace( char *, unsigned long ) = 0;
99106
virtual void *CreateConVar( const char *, const char *, const char *, int ) = 0;
100107
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;
109+
virtual double CheckNumberOpt( int iStackPos, double def ) = 0;
110+
virtual void RegisterMetaTable( const char* name, ILuaObject* tbl ) = 0;
101111
};
102112

103113
class CLuaInterface : public ILuaInterface
104114
{
105115
public:
106116
inline ILuaGameCallback *GetLuaGameCallback( ) const
107117
{
108-
return gamecallback;
118+
return m_pGameCallback;
109119
}
110120

111121
inline void SetLuaGameCallback( ILuaGameCallback *callback )
112122
{
113-
gamecallback = callback;
123+
m_pGameCallback = callback;
124+
}
125+
126+
inline ILuaObject *GetStringPool( ) const
127+
{
128+
return m_pStringPool;
114129
}
115130

116131
private:
117132
// vtable: 1 * sizeof(void **) = 4 (x86) or 8 (x86-64) bytes
118133
// luabase: 1 * sizeof(LuaBase *) = 4 (x86) or 8 (x86-64) bytes
119134

120-
// These members represent nothing in particular
121-
// They've been selected to fill the required space between the vtable and the callback object
122-
uint64_t _1; // 8 bytes
123-
size_t _2[43]; // 43 * sizeof(size_t) = 172 (x86) or 344 (x86-64) bytes
135+
// The purpose of all members that start with _ are unknown
136+
int _1; // Always 1?
137+
const char* m_sCurrentPath;
138+
int _2; // Always 16?
139+
int _3; // Always 0?
140+
int m_iPushedPaths;
141+
const char* m_sLastPath;
142+
std::list<ILuaThreadedCall*> m_pThreadedCalls;
124143

125144
#ifdef __APPLE__
126145

127-
size_t _3; // 1 * sizeof(size_t) = 4 (x86) or 8 (x86-64) bytes
146+
size_t _4; // 1 * sizeof(size_t) = 4 (x86) or 8 (x86-64) bytes
128147

129148
#endif
130149

131-
// x86: offset of 188 bytes
132-
// x86-64: offset of 368 bytes
133-
// macOS adds an offset of 4 bytes (total 192) on x86 and 8 bytes (total 376) on x86-64
134-
ILuaGameCallback *gamecallback;
150+
ILuaObject* m_pProtectedFunctionReturns[4];
151+
ILuaObject* m_pTempObjects[32];
152+
unsigned char m_iRealm; // CLIENT = 0, SERVER = 1, MENU = 2
153+
ILuaGameCallback* m_pGameCallback;
154+
char m_sPathID[32]; // lsv, lsc or LuaMenu
155+
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;
135195
};
136196
}
137197
}

include/GarrysMod/Lua/LuaObject.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ namespace GarrysMod
121121

122122
virtual void SetMemberDouble( float, double ) = 0;
123123
virtual double GetMemberDouble( const char *, double ) = 0;
124+
// NOTE: All members below do NOT exist in ILuaObjects returned from the menusystem!
124125

125126
virtual BaseEntity *GetMemberEntity( const char *, BaseEntity * ) = 0;
126127
virtual void SetMemberEntity( float, BaseEntity * ) = 0;
@@ -150,5 +151,35 @@ namespace GarrysMod
150151

151152
virtual void SetMemberPhysObject( const char *, IPhysicsObject * ) = 0;
152153
};
154+
155+
class CLuaObject : public ILuaObject
156+
{
157+
public:
158+
inline ILuaBase *GetLua( ) const
159+
{
160+
return m_pLua;
161+
}
162+
163+
inline void SetLua( ILuaBase *Lua )
164+
{
165+
m_pLua = Lua;
166+
}
167+
168+
inline int GetReference( ) const
169+
{
170+
return m_iReference;
171+
}
172+
173+
inline int GetInternalType( ) const
174+
{
175+
return m_iType;
176+
}
177+
178+
private:
179+
bool m_bUserData;
180+
int m_iType;
181+
int m_iReference;
182+
ILuaBase* m_pLua;
183+
};
153184
}
154-
}
185+
}

0 commit comments

Comments
 (0)