Skip to content

Commit

Permalink
Finished nuking using namespace GarrysMod::Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Apr 5, 2024
1 parent e72bca3 commit 6c5c673
Show file tree
Hide file tree
Showing 20 changed files with 171 additions and 175 deletions.
28 changes: 14 additions & 14 deletions source/class_angle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static const char metaname[] = "Angle";
static const char invalid_error[] = "invalid Angle";
static const char table_name[] = "Angle_object";

void Push_Angle(ILuaBase* LUA, int pitch, int yaw, int roll)
void Push_Angle(GarrysMod::Lua::ILuaBase* LUA, int pitch, int yaw, int roll)
{
LUA_Angle* udata = (LUA_Angle*)LUA->NewUserdata(sizeof(LUA_Angle));
udata->x = pitch;
Expand All @@ -16,24 +16,24 @@ void Push_Angle(ILuaBase* LUA, int pitch, int yaw, int roll)
LUA->SetMetaTable(-2);
}

void Push_Angle(ILuaBase* LUA, QAngle ang)
void Push_Angle(GarrysMod::Lua::ILuaBase* LUA, QAngle ang)
{
Push_Angle(LUA, ang.x, ang.y, ang.z);
}

void Angle_CheckType(ILuaBase* LUA, int index)
void Angle_CheckType(GarrysMod::Lua::ILuaBase* LUA, int index)
{
if(!LUA->IsType(index, Type::UserData))
if(!LUA->IsType(index, GarrysMod::Lua::Type::UserData))
luaL_typerror(LUA->GetState(), index, metaname);
}

bool IsAngle(ILuaBase* LUA, int index)
bool IsAngle(GarrysMod::Lua::ILuaBase* LUA, int index)
{
if (LUA->IsType(index, Type::UserData))
if (LUA->IsType(index, GarrysMod::Lua::Type::UserData))
{
LUA->GetMetaTable(index);
LUA->GetField(-1, "MetaName");
if (LUA->IsType(-1, Type::String))
if (LUA->IsType(-1, GarrysMod::Lua::Type::String))
{
if (strcmp(LUA->GetString(-1), metaname))
{
Expand All @@ -50,12 +50,12 @@ bool IsAngle(ILuaBase* LUA, int index)
return false;
}

LUA_Angle* Angle_GetUserdata(ILuaBase *LUA, int index)
LUA_Angle* Angle_GetUserdata(GarrysMod::Lua::ILuaBase *LUA, int index)
{
return (LUA_Angle*)LUA->GetUserdata(index);
}

LUA_Angle* Angle_Get(ILuaBase* LUA, int index)
LUA_Angle* Angle_Get(GarrysMod::Lua::ILuaBase* LUA, int index)
{
Angle_CheckType(LUA, index);

Expand All @@ -64,11 +64,11 @@ LUA_Angle* Angle_Get(ILuaBase* LUA, int index)
return ang;
}

void Angle_Destroy(ILuaBase *LUA, int index)
void Angle_Destroy(GarrysMod::Lua::ILuaBase *LUA, int index)
{
LUA_Angle* ang = Angle_GetUserdata(LUA, index);

LUA->GetField(INDEX_REGISTRY, table_name);
LUA->GetField(GarrysMod::Lua::INDEX_REGISTRY, table_name);
LUA->PushUserdata(ang);
LUA->PushNil();
LUA->SetTable(-3);
Expand Down Expand Up @@ -398,8 +398,8 @@ LUA_FUNCTION(Angle_Random)
{
Angle_CheckType(LUA, 1);
LUA_Angle* ang = Angle_Get(LUA, 1);
int min = LUA->IsType(2, Type::Number) ? LUA->GetNumber(2) : -360;
int max = LUA->IsType(3, Type::Number) ? LUA->GetNumber(3) : 360;
int min = LUA->IsType(2, GarrysMod::Lua::Type::Number) ? LUA->GetNumber(2) : -360;
int max = LUA->IsType(3, GarrysMod::Lua::Type::Number) ? LUA->GetNumber(3) : 360;

ang->x = std::rand() % max + min;
ang->y = std::rand() % max + min;
Expand Down Expand Up @@ -462,7 +462,7 @@ LUA_FUNCTION(Global_LerpAngle)
return 1;
}

void InitAngleClass(ILuaInterface* LUA)
void InitAngleClass(GarrysMod::Lua::ILuaInterface* LUA)
{
LUA->CreateTable();
LUA->SetField(GarrysMod::Lua::INDEX_REGISTRY, table_name);
Expand Down
24 changes: 12 additions & 12 deletions source/class_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ static const char metaname[] = "File";
static const char invalid_error[] = "invalid File";
static const char table_name[] = "File_object";

void Push_File(ILuaBase* LUA, const char* filename, const char* fileMode, const char* path)
void Push_File(GarrysMod::Lua::ILuaBase* LUA, const char* filename, const char* fileMode, const char* path)
{
LUA_File* udata = (LUA_File*)LUA->NewUserdata(sizeof(LUA_File));
udata->filename = filename;
udata->handle = gpFileSystem->Open(filename, fileMode, path);

ILuaInterface* ILUA = (ILuaInterface*)LUA;
GarrysMod::Lua::ILuaInterface* ILUA = (GarrysMod::Lua::ILuaInterface*)LUA;
ILUA->SetType(metatype);

LUA->CreateMetaTableType(metaname, metatype);
LUA->SetMetaTable(-2);
}

bool IsFile(ILuaBase* LUA, int index)
bool IsFile(GarrysMod::Lua::ILuaBase* LUA, int index)
{
if (LUA->IsType(index, Type::UserData))
if (LUA->IsType(index, GarrysMod::Lua::Type::UserData))
{
LUA->GetMetaTable(index);
LUA->GetField(-1, "MetaName");
if (LUA->IsType(-1, Type::String))
if (LUA->IsType(-1, GarrysMod::Lua::Type::String))
{
if (strcmp(LUA->GetString(-1), metaname))
{
Expand All @@ -41,18 +41,18 @@ bool IsFile(ILuaBase* LUA, int index)
return false;
}

void File_CheckType(ILuaBase* LUA, int index)
void File_CheckType(GarrysMod::Lua::ILuaBase* LUA, int index)
{
if(!LUA->IsType(index, Type::UserData)) // ToDo: Make a better check.
if(!LUA->IsType(index, GarrysMod::Lua::Type::UserData)) // ToDo: Make a better check.
luaL_typerror(LUA->GetState(), index, metaname);
}

LUA_File* File_GetUserdata(ILuaBase *LUA, int index)
LUA_File* File_GetUserdata(GarrysMod::Lua::ILuaBase *LUA, int index)
{
return (LUA_File*)LUA->GetUserdata(index);
}

LUA_File* File_Get(ILuaBase* LUA, int index, bool error)
LUA_File* File_Get(GarrysMod::Lua::ILuaBase* LUA, int index, bool error)
{
File_CheckType(LUA, index);

Expand All @@ -66,11 +66,11 @@ LUA_File* File_Get(ILuaBase* LUA, int index, bool error)
return file;
}

void File_Destroy(ILuaBase *LUA, int index)
void File_Destroy(GarrysMod::Lua::ILuaBase *LUA, int index)
{
LUA_File* file = File_GetUserdata(LUA, index);

LUA->GetField(INDEX_REGISTRY, table_name);
LUA->GetField(GarrysMod::Lua::INDEX_REGISTRY, table_name);
LUA->PushUserdata(file);
LUA->PushNil();
LUA->SetTable(-3);
Expand Down Expand Up @@ -413,7 +413,7 @@ LUA_FUNCTION(File_WriteUShort)
return 0;
}

void InitFileClass(ILuaInterface* LUA)
void InitFileClass(GarrysMod::Lua::ILuaInterface* LUA)
{
LUA->CreateTable();
LUA->SetField(GarrysMod::Lua::INDEX_REGISTRY, table_name);
Expand Down
38 changes: 18 additions & 20 deletions source/class_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ static const char metaname[] = "Vector";
static const char invalid_error[] = "invalid Vector";
static const char table_name[] = "Vector_object";

void Push_Vector(ILuaBase* LUA, float x, float y, float z)
void Push_Vector(GarrysMod::Lua::ILuaBase* LUA, float x, float y, float z)
{
LUA_Vector* udata = (LUA_Vector*)LUA->NewUserdata(sizeof(LUA_Vector));
udata->x = x;
udata->y = y;
udata->z = z;

ILuaInterface* ILUA = (ILuaInterface*)LUA;
ILUA->SetType(Type::Vector);
GarrysMod::Lua::ILuaInterface* ILUA = (GarrysMod::Lua::ILuaInterface*)LUA;
ILUA->SetType(GarrysMod::Lua::Type::Vector);

LUA->CreateMetaTableType(metaname, metatype);
LUA->SetMetaTable(-2);
Expand All @@ -34,24 +34,24 @@ void Push_Vector(ILuaBase* LUA, float x, float y, float z)
obj->Push();*/
}

void Push_Vector(ILuaBase* LUA, Vector vec)
void Push_Vector(GarrysMod::Lua::ILuaBase* LUA, Vector vec)
{
Push_Vector(LUA, vec.x, vec.y, vec.z);
}

void Vector_CheckType(ILuaBase* LUA, int index)
void Vector_CheckType(GarrysMod::Lua::ILuaBase* LUA, int index)
{
if(!LUA->IsType(index, Type::UserData))
if(!LUA->IsType(index, GarrysMod::Lua::Type::UserData))
luaL_typerror(LUA->GetState(), index, metaname);
}

bool IsVector(ILuaBase* LUA, int index)
bool IsVector(GarrysMod::Lua::ILuaBase* LUA, int index)
{
if (LUA->IsType(index, Type::UserData))
if (LUA->IsType(index, GarrysMod::Lua::Type::UserData))
{
LUA->GetMetaTable(index);
LUA->GetField(-1, "MetaName");
if (LUA->IsType(-1, Type::String))
if (LUA->IsType(-1, GarrysMod::Lua::Type::String))
{
if (strcmp(LUA->GetString(-1), metaname))
{
Expand All @@ -68,12 +68,12 @@ bool IsVector(ILuaBase* LUA, int index)
return false;
}

LUA_Vector* Vector_GetUserdata(ILuaBase *LUA, int index)
LUA_Vector* Vector_GetUserdata(GarrysMod::Lua::ILuaBase *LUA, int index)
{
return (LUA_Vector*)LUA->GetUserdata(index);
}

LUA_Vector* Vector_Get(ILuaBase* LUA, int index)
LUA_Vector* Vector_Get(GarrysMod::Lua::ILuaBase* LUA, int index)
{
Vector_CheckType(LUA, index);

Expand All @@ -84,11 +84,11 @@ LUA_Vector* Vector_Get(ILuaBase* LUA, int index)
return vec;
}

void Vector_Destroy(ILuaBase *LUA, int index)
void Vector_Destroy(GarrysMod::Lua::ILuaBase *LUA, int index)
{
LUA_Vector* vec = Vector_GetUserdata(LUA, index);

LUA->GetField(INDEX_REGISTRY, table_name);
LUA->GetField(GarrysMod::Lua::INDEX_REGISTRY, table_name);
LUA->PushUserdata(vec);
LUA->PushNil();
LUA->SetTable(-3);
Expand Down Expand Up @@ -213,7 +213,7 @@ LUA_FUNCTION_STATIC(Vector__mul)
Vector_CheckType(LUA, 1);
LUA_Vector* vec1 = Vector_Get(LUA, 1);

if (LUA->IsType(2, Type::Number)) {
if (LUA->IsType(2, GarrysMod::Lua::Type::Number)) {
int num = LUA->GetNumber(2);

Push_Vector(LUA, vec1->x * num, vec1->y * num, vec1->z * num);
Expand All @@ -232,7 +232,7 @@ LUA_FUNCTION_STATIC(Vector__div)
Vector_CheckType(LUA, 1);
LUA_Vector* vec1 = Vector_Get(LUA, 1);

if (LUA->IsType(2, Type::Number)) {
if (LUA->IsType(2, GarrysMod::Lua::Type::Number)) {
int num = LUA->GetNumber(2);

Push_Vector(LUA, vec1->x / num, vec1->y / num, vec1->z / num);
Expand Down Expand Up @@ -289,7 +289,7 @@ LUA_FUNCTION(Vector_Mul) // Undocumented: Second arg can be a Vector?
Vector_CheckType(LUA, 1);
LUA_Vector* vec1 = Vector_Get(LUA, 1);

if (LUA->IsType(2, Type::Number)) {
if (LUA->IsType(2, GarrysMod::Lua::Type::Number)) {
int num = LUA->GetNumber(2);

vec1->x *= num;
Expand All @@ -312,7 +312,7 @@ LUA_FUNCTION(Vector_Div) // Undocumented: Second arg can be a Vector?
Vector_CheckType(LUA, 1);
LUA_Vector* vec1 = Vector_Get(LUA, 1);

if (LUA->IsType(2, Type::Number)) {
if (LUA->IsType(2, GarrysMod::Lua::Type::Number)) {
int num = LUA->GetNumber(2);

vec1->x /= num;
Expand Down Expand Up @@ -681,13 +681,11 @@ LUA_FUNCTION(Global_OrderVectors)
return 0;
}

void InitVectorClass(ILuaInterface* LUA)
void InitVectorClass(GarrysMod::Lua::ILuaInterface* LUA)
{
LUA->CreateTable();
LUA->SetField(GarrysMod::Lua::INDEX_REGISTRY, table_name);



LUA->CreateMetaTableType(metaname, metatype);
Add_Func(LUA, Vector__gc, "__gc"); // Gmod doesn't have __gc
Add_Func(LUA, Vector__index, "__index");
Expand Down
20 changes: 9 additions & 11 deletions source/detours.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
#include <filesystem.h>
#include <vector>

using namespace GarrysMod::Lua;

/*
lua_shared Symbols
*/
typedef ILuaInterface* (*CreateLuaInterface)(bool);
typedef GarrysMod::Lua::ILuaInterface* (*CreateLuaInterface)(bool);
extern CreateLuaInterface func_CreateLuaInterface;
const std::vector<Symbol> CreateLuaInterfaceSym = {
Symbol::FromName("_Z18CreateLuaInterfaceb"),
Expand All @@ -21,7 +19,7 @@ const std::vector<Symbol> CreateLuaInterfaceSym = {
#endif
};

typedef void (*CloseLuaInterface)(ILuaInterface*);
typedef void (*CloseLuaInterface)(GarrysMod::Lua::ILuaInterface*);
extern CloseLuaInterface func_CloseLuaInterface;
const std::vector<Symbol> CloseLuaInterfaceSym = {
Symbol::FromName("_Z17CloseLuaInterfaceP13ILuaInterface"),
Expand All @@ -35,7 +33,7 @@ typedef int (*TLuaPanic)(lua_State*);
extern TLuaPanic func_LuaPanic;
const Symbol LuaPanicSym = Symbol::FromName("_ZL8LuaPanicP9lua_State");

typedef void (*Tlua_atpanic)(lua_State*, CFunc);
typedef void (*Tlua_atpanic)(lua_State*, GarrysMod::Lua::CFunc);
extern Tlua_atpanic func_lua_atpanic;
const Symbol lua_atpanicSym = Symbol::FromName("lua_atpanic");

Expand Down Expand Up @@ -82,22 +80,22 @@ const Symbol AdvancedLuaErrorReporterSym = Symbol::FromName("_Z24AdvancedLuaErro
/*
server_srv stuff
*/
typedef void (*TInitLuaLibraries)(ILuaInterface*);
typedef void (*TInitLuaLibraries)(GarrysMod::Lua::ILuaInterface*);
extern TInitLuaLibraries func_InitLuaLibraries;
const Symbol InitLuaLibrariesSym = Symbol::FromName("_Z16InitLuaLibrariesP13ILuaInterface");

typedef void (*InitLuaClasses)(ILuaInterface*);
typedef void (*InitLuaClasses)(GarrysMod::Lua::ILuaInterface*);
extern InitLuaClasses func_InitLuaClasses;
const Symbol InitLuaClassesSym = Symbol::FromName("_Z14InitLuaClassesP13ILuaInterface");

extern void* g_pGlobalLuaLibraryFactory;
const Symbol g_pGlobalLuaLibraryFactorySym = Symbol::FromName("_ZL26g_pGlobalLuaLibraryFactory");

typedef void (*CLuaGlobalLibrary_InitLibraries)(void*, ILuaInterface*);
typedef void (*CLuaGlobalLibrary_InitLibraries)(void*, GarrysMod::Lua::ILuaInterface*);
extern CLuaGlobalLibrary_InitLibraries func_CLuaGlobalLibrary_InitLibraries;
const Symbol CLuaGlobalLibrary_InitLibrariesSym = Symbol::FromName("_ZN17CLuaGlobalLibrary13InitLibrariesEP13ILuaInterface");

typedef void (*CLuaGameEnums_InitLibraries)(void*, ILuaInterface*);
typedef void (*CLuaGameEnums_InitLibraries)(void*, GarrysMod::Lua::ILuaInterface*);
extern CLuaGameEnums_InitLibraries func_CLuaGameEnums_InitLibraries;
const Symbol CLuaGameEnums_InitLibrariesSym = Symbol::FromName("_ZN13CLuaGameEnums13InitLibrariesEP13ILuaInterface");

Expand All @@ -118,7 +116,7 @@ const std::vector<Symbol> Editor_SendCommandSym = {
/*
CLuaGameCallback stuff
*/
typedef ILuaObject* (*CLuaGameCallback_CreateLuaObject)(void*);
typedef GarrysMod::Lua::ILuaObject* (*CLuaGameCallback_CreateLuaObject)(void*);
extern CLuaGameCallback_CreateLuaObject func_CLuaGameCallback_CreateLuaObject;
const std::vector<Symbol> CLuaGameCallback_CreateLuaObjectSym = {
Symbol::FromName("_ZN16CLuaGameCallback15CreateLuaObjectEv"),
Expand All @@ -128,7 +126,7 @@ const std::vector<Symbol> CLuaGameCallback_CreateLuaObjectSym = {
#endif
};

typedef void (*CLuaGameCallback_DestroyLuaObject)(void*, ILuaObject*);
typedef void (*CLuaGameCallback_DestroyLuaObject)(void*, GarrysMod::Lua::ILuaObject*);
extern CLuaGameCallback_DestroyLuaObject func_CLuaGameCallback_DestroyLuaObject;
const std::vector<Symbol> CLuaGameCallback_DestroyLuaObjectSym = {
Symbol::FromName("_ZN16CLuaGameCallback16DestroyLuaObjectEP10ILuaObject"),
Expand Down
Loading

0 comments on commit 6c5c673

Please sign in to comment.