Skip to content

Commit 5bf3892

Browse files
committed
repo: push local changes(everything is broken)
1 parent 313e1f6 commit 5bf3892

File tree

6 files changed

+187
-65
lines changed

6 files changed

+187
-65
lines changed

source/lua.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ bool Lua::PushHook(const char* hook)
4747
void Lua::Init(GarrysMod::Lua::ILuaInterface* LUA)
4848
{
4949
g_Lua = LUA;
50+
CreateLuaInterfaceData(g_Lua);
5051

5152
g_pModuleManager.LuaInit(false);
5253
}
@@ -68,6 +69,7 @@ void Lua::Shutdown()
6869

6970
void Lua::FinalShutdown()
7071
{
72+
DestroyLuaInterfaceData(g_Lua);
7173
g_Lua = NULL;
7274
}
7375

@@ -150,11 +152,13 @@ GarrysMod::Lua::ILuaInterface* Lua::CreateInterface()
150152
{
151153
GarrysMod::Lua::ILuaInterface* LUA = CreateLuaInterface(true);
152154
LUA->Init(g_LuaCallback, true);
155+
CreateLuaInterfaceData(LUA);
153156

154157
return LUA;
155158
}
156159

157160
void Lua::DestoryInterface(GarrysMod::Lua::ILuaInterface* LUA)
158161
{
159162
CloseLuaInterface(LUA);
163+
DestroyLuaInterfaceData(LUA);
160164
}

source/modules/bitbuf.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Get_LuaClass(bf_write, bf_write_TypeID, "bf_write")
2929

3030
LUA_FUNCTION_STATIC(bf_read__tostring)
3131
{
32-
bf_read* bf = Get_bf_read(1, false);
32+
bf_read* bf = Get_bf_read(LUA, 1, false);
3333
if (!bf)
3434
{
3535
LUA->PushString("bf_read [NULL]");
@@ -48,9 +48,13 @@ LUA_FUNCTION_STATIC(bf_read__index)
4848
return 1;
4949

5050
LUA->Pop(1);
51-
Util::ReferencePush(g_pPushedbf_read[Get_bf_read(1, true)]->iTableReference);
52-
if (!LUA->FindObjectOnTable(-1, 2))
53-
LUA->PushNil();
51+
LuaUserData* pData = GetLuaInterfaceData(LUA)->FindLuaClass(Get_bf_read(LUA, 1, true));
52+
if (pData)
53+
{
54+
pData->Push();
55+
if (!LUA->FindObjectOnTable(-1, 2))
56+
LUA->PushNil();
57+
}
5458

5559
LUA->Remove(-2);
5660

source/modules/cvars.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ LUA_FUNCTION_STATIC(cvars_Unregister)
5959
if (LUA->IsType(1, GarrysMod::Lua::Type::String))
6060
pConVar = g_pCVar->FindCommandBase(LUA->GetString(1));
6161
else
62-
pConVar = Get_ConVar(1, true);
62+
pConVar = Get_ConVar(LUA, 1, true);
6363

6464
if (!pConVar)
6565
LUA->ThrowError("Failed to find ConVar/ConCommand!");

source/modules/physenv.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ LUA_FUNCTION_STATIC(physcollide_CollideIndex)
17481748
LUA_FUNCTION_STATIC(physcollide_CollideSetMassCenter)
17491749
{
17501750
CPhysCollide* pCollide = Get_CPhysCollide(1, true);
1751-
Vector* pMassCenter = Get_Vector(2, true);
1751+
Vector* pMassCenter = Get_Vector(LUA, 2, true);
17521752

17531753
if (!physcollide)
17541754
LUA->ThrowError("Failed to get IPhysicsCollision!");
@@ -1760,7 +1760,7 @@ LUA_FUNCTION_STATIC(physcollide_CollideSetMassCenter)
17601760
LUA_FUNCTION_STATIC(physcollide_CollideSetOrthographicAreas)
17611761
{
17621762
CPhysCollide* pCollide = Get_CPhysCollide(1, true);
1763-
Vector* pArea = Get_Vector(2, true);
1763+
Vector* pArea = Get_Vector(LUA, 2, true);
17641764

17651765
if (!physcollide)
17661766
LUA->ThrowError("Failed to get IPhysicsCollision!");
@@ -1827,7 +1827,7 @@ LUA_FUNCTION_STATIC(physcollide_UnserializeCollide)
18271827
if (!physcollide)
18281828
LUA->ThrowError("Failed to get IPhysicsCollision!");
18291829

1830-
Push_CPhysCollide(physcollide->UnserializeCollide((char*)pData, iSize, index));
1830+
Push_CPhysCollide(LUA, physcollide->UnserializeCollide((char*)pData, iSize, index));
18311831
return 1;
18321832
}
18331833

@@ -1893,7 +1893,7 @@ LUA_FUNCTION_STATIC(physcollide_CreateQueryModel)
18931893
if (!physcollide)
18941894
LUA->ThrowError("Failed to get IPhysicsCollision!");
18951895

1896-
Push_ICollisionQuery(physcollide->CreateQueryModel(pCollide));
1896+
Push_ICollisionQuery(LUA, physcollide->CreateQueryModel(pCollide));
18971897
return 1;
18981898
}
18991899

@@ -1905,7 +1905,7 @@ LUA_FUNCTION_STATIC(physcollide_DestroyQueryModel)
19051905
LUA->ThrowError("Failed to get IPhysicsCollision!");
19061906

19071907
physcollide->DestroyQueryModel(pQuery);
1908-
Delete_ICollisionQuery(pQuery);
1908+
Delete_ICollisionQuery(LUA, pQuery);
19091909
return 0;
19101910
}
19111911

@@ -1917,7 +1917,7 @@ LUA_FUNCTION_STATIC(physcollide_DestroyCollide)
19171917
LUA->ThrowError("Failed to get IPhysicsCollision!");
19181918

19191919
physcollide->DestroyCollide(pCollide);
1920-
Delete_CPhysCollide(pCollide);
1920+
Delete_CPhysCollide(LUA, pCollide);
19211921
return 0;
19221922
}
19231923

source/util.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "player.h"
1010
#include "detours.h"
1111

12+
// Holds all data related to a ILuaInterface in one place.
13+
std::unordered_map<GarrysMod::Lua::ILuaInterface*, LuaInterfaceData*> g_pLuaInterfaceData;
14+
1215
// Try not to use it. We want to move away from it.
1316
// Additionaly, we will add checks in many functions.
1417
GarrysMod::Lua::ILuaInterface* g_Lua;

0 commit comments

Comments
 (0)