4
4
5
5
#include " LuaBase.h"
6
6
#include " SourceCompat.h"
7
+ #include < list>
7
8
8
9
namespace Bootil
9
10
{
@@ -18,10 +19,16 @@ namespace GarrysMod
18
19
{
19
20
namespace Lua
20
21
{
21
- class ILuaThreadedCall ;
22
22
class ILuaGameCallback ;
23
23
class ILuaObject ;
24
24
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
+
25
32
class ILuaInterface : public ILuaBase
26
33
{
27
34
public:
@@ -51,7 +58,7 @@ namespace GarrysMod
51
58
virtual void DestroyObject ( ILuaObject *obj ) = 0;
52
59
virtual ILuaObject *CreateObject ( ) = 0;
53
60
virtual void SetMember ( ILuaObject *table, ILuaObject *key, ILuaObject *value ) = 0;
54
- virtual void GetNewTable ( ) = 0;
61
+ virtual ILuaObject * GetNewTable ( ) = 0;
55
62
virtual void SetMember ( ILuaObject *table, float key ) = 0;
56
63
virtual void SetMember ( ILuaObject *table, float key, ILuaObject *value ) = 0;
57
64
virtual void SetMember ( ILuaObject *table, const char *key ) = 0;
@@ -94,44 +101,97 @@ namespace GarrysMod
94
101
virtual void PreCreateTable ( int arrelems, int nonarrelems ) = 0;
95
102
virtual void PushPooledString ( int index ) = 0;
96
103
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.
98
105
virtual void AppendStackTrace ( char *, unsigned long ) = 0;
99
106
virtual void *CreateConVar ( const char *, const char *, const char *, int ) = 0;
100
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;
109
+ virtual double CheckNumberOpt ( int iStackPos, double def ) = 0;
110
+ virtual void RegisterMetaTable ( const char * name, ILuaObject* tbl ) = 0;
101
111
};
102
112
103
113
class CLuaInterface : public ILuaInterface
104
114
{
105
115
public:
106
116
inline ILuaGameCallback *GetLuaGameCallback ( ) const
107
117
{
108
- return gamecallback ;
118
+ return m_pGameCallback ;
109
119
}
110
120
111
121
inline void SetLuaGameCallback ( ILuaGameCallback *callback )
112
122
{
113
- gamecallback = callback;
123
+ m_pGameCallback = callback;
124
+ }
125
+
126
+ inline ILuaObject *GetStringPool ( ) const
127
+ {
128
+ return m_pStringPool;
114
129
}
115
130
116
131
private:
117
132
// vtable: 1 * sizeof(void **) = 4 (x86) or 8 (x86-64) bytes
118
133
// luabase: 1 * sizeof(LuaBase *) = 4 (x86) or 8 (x86-64) bytes
119
134
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;
124
143
125
144
#ifdef __APPLE__
126
145
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
128
147
129
148
#endif
130
149
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;
135
195
};
136
196
}
137
197
}
0 commit comments