diff --git a/Game.Server/BaseEntity.cs b/Game.Server/BaseEntity.cs index e2259f9e..77b3a71b 100644 --- a/Game.Server/BaseEntity.cs +++ b/Game.Server/BaseEntity.cs @@ -1307,7 +1307,7 @@ public void SetParent(BaseEntity? parentEntity, int attachment = -1) { if (attachment == -1) attachment = ParentAttachment; - if (!IsPlayer() && Game.Client.GarrysMod.GarrysMod.IsSacredEntity(Classname ?? "")) { + if (!IsPlayer() && Game.Server.GarrysMod.GarrysMod.IsSacredEntity(Classname ?? "")) { Warning($"Refusing to set parent on {Classname}!\n"); return; } diff --git a/Game.Server/Util.cs b/Game.Server/Util.cs index a4d12f7d..3fb277ee 100644 --- a/Game.Server/Util.cs +++ b/Game.Server/Util.cs @@ -74,11 +74,11 @@ public class CEntityFactoryDictionary : IEntityFactoryDictionary className = className.SliceNullTerminatedString(); IEntityFactory? factory = FindFactory(className); #if GMOD_DLL - if (Game.Client.GarrysMod.GarrysMod.g_LuaManager != null) { + if (Game.Server.GarrysMod.GarrysMod.g_LuaManager != null) { Span lowered = stackalloc char[512]; strcpy(lowered, className); strlower(lowered); - IServerNetworkable? luaEnt = Game.Client.GarrysMod.GarrysMod.g_LuaManager.CreateEntity(((ReadOnlySpan)lowered).SliceNullTerminatedString(), factory != null); + IServerNetworkable? luaEnt = Game.Server.GarrysMod.GarrysMod.g_LuaManager.CreateEntity(((ReadOnlySpan)lowered).SliceNullTerminatedString(), factory != null); if (luaEnt != null) return luaEnt; } @@ -523,8 +523,8 @@ public static void TransmitShakeEvent(BasePlayer player, float localAmplitude, f public static void PrecacheOther(ReadOnlySpan className, ReadOnlySpan modelName = default) { bool precaching = s_RemoveImmediateSemaphore == 0; if (precaching) - Game.Client.GarrysMod.GarrysMod.g_GModPrecaching++; - if (Game.Client.GarrysMod.GarrysMod.g_GModPrecaching > 0x20) + Game.Server.GarrysMod.GarrysMod.g_GModPrecaching++; + if (Game.Server.GarrysMod.GarrysMod.g_GModPrecaching > 0x20) Error("Something seems to have gone wroong"); BaseEntity? entity = CreateEntityByName(className); @@ -540,7 +540,7 @@ public static void PrecacheOther(ReadOnlySpan className, ReadOnlySpan(scoped in Filter filter, HudPrint dest, ReadOnlySpan msgName, ReadOnlySpan param1 = default, ReadOnlySpan param2 = default, ReadOnlySpan param3 = default, ReadOnlySpan param4 = default) where Filter : IRecipientFilter { @@ -711,7 +711,7 @@ public static int DispatchSpawn(BaseEntity? entity) { public static void RemoveSafe(BaseEntity? entity) { if (entity == null) return; - if (Game.Client.GarrysMod.GarrysMod.IsSacredEntity(entity.Classname ?? "")) { + if (Game.Server.GarrysMod.GarrysMod.IsSacredEntity(entity.Classname ?? "")) { Warning($"Refusing to delete entity '{entity.Classname ?? ""}'!\n"); return; } diff --git a/Game.Shared/GarrysMod/GarrysMod.cs b/Game.Shared/GarrysMod/GarrysMod.cs index 2d1d820d..3b4f7e80 100644 --- a/Game.Shared/GarrysMod/GarrysMod.cs +++ b/Game.Shared/GarrysMod/GarrysMod.cs @@ -1,10 +1,11 @@ #if CLIENT_DLL || GAME_DLL +#if CLIENT_DLL global using static Game.Client.GarrysMod.GarrysModSingletons; +#else +global using static Game.Server.GarrysMod.GarrysModSingletons; +#endif using Game.Shared; -#if GAME_DLL -using Game.Server.GarrysMod; -#endif using Microsoft.Extensions.DependencyInjection; @@ -27,7 +28,11 @@ using System.Collections.Generic; using System.Text; +#if CLIENT_DLL namespace Game.Client.GarrysMod; +#else +namespace Game.Server.GarrysMod; +#endif public static class GarrysModSingletons { @@ -230,11 +235,7 @@ public static bool Kill() { g_LuaManager = null; } gGM?.Dispose(); -#if CLIENT_DLL LuaTimer.Shutdown(); -#else - Game.Server.GarrysMod.LuaTimer.Shutdown(); -#endif return true; } @@ -263,7 +264,7 @@ public static bool Create() { g_LuaManager.Startup(); #if GAME_DLL gGM.LoadCurrentlyActiveGamemode(); - Game.Server.GarrysMod.GModDataPack.DataPack().BuildSearchPaths(); + GModDataPack.DataPack().BuildSearchPaths(); #endif return true; } @@ -370,15 +371,9 @@ public void Startup() { Msg("Clientside Lua startup!\n"); enginevgui.UpdateCustomProgressBar(0.95f, "Starting Lua..."); #endif -#if CLIENT_DLL if (LuaNetworkedVars.g_LuaNetworkedVars != null) Error("g_LuaNetworkedVars"); LuaNetworkedVars.g_LuaNetworkedVars = new LuaNetworkedVars(); -#else - if (Game.Server.GarrysMod.LuaNetworkedVars.g_LuaNetworkedVars != null) - Error("g_LuaNetworkedVars"); - Game.Server.GarrysMod.LuaNetworkedVars.g_LuaNetworkedVars = new Game.Server.GarrysMod.LuaNetworkedVars(); -#endif if (g_Lua != null) Error("CLuaManager::Startup Lua already exsits?\n"); @@ -400,7 +395,7 @@ public void Startup() { g_Lua.SetType(0); #else g_Lua = get.LuaShared()!.CreateLuaInterface(Realm.Server, false); - g_Lua.Init(Game.Server.GarrysMod.LuaGameCallback.g_LuaCallback, Singleton().CheckParm("-withjit")); + g_Lua.Init(LuaGameCallback.g_LuaCallback, Singleton().CheckParm("-withjit")); g_Lua.SetPathID(LuaPathID); g_Lua.SetType(1); #endif @@ -408,15 +403,10 @@ public void Startup() { g_Lua.Global().SetMember("VERSIONSTR", get.VersionStr()); g_Lua.Global().SetMember("BRANCH", get.Branch()); #if GAME_DLL - Game.Server.GarrysMod.FileServ.Add("lua/send.txt"); + FileServ.Add("lua/send.txt"); #endif -#if CLIENT_DLL LuaUser.InitLuaLibraries(g_Lua); LuaClass.InitLuaClasses(g_Lua); -#else - Game.Server.GarrysMod.LuaUser.InitLuaLibraries(g_Lua); - Game.Server.GarrysMod.LuaClass.InitLuaClasses(g_Lua); -#endif #if CLIENT_DLL g_Lua.Global().SetMember("SERVER", false); g_Lua.Global().SetMember("CLIENT", true); @@ -424,11 +414,7 @@ public void Startup() { g_Lua.Global().SetMember("SERVER", true); g_Lua.Global().SetMember("CLIENT", false); #endif -#if CLIENT_DLL LuaEntity.MakeLuaNULLEntity(); -#else - Game.Server.GarrysMod.LuaEntity.MakeLuaNULLEntity(); -#endif g_Lua.FindAndRunScript("includes/init.lua", true, true, "!UNKNOWN", true); #if CLIENT_DLL if (gGM == null) @@ -469,7 +455,7 @@ public void SendScriptsInFolder(ReadOnlySpan folder, ReadOnlySpan so List files = []; get.LuaShared()!.FindScripts($"{folder}/*.lua", "lsv", files); foreach (LuaFindResult file in files) - Game.Server.GarrysMod.FileServ.AddCSLuaFile($"{folder}/{file.FileName}", new string(source)); + FileServ.AddCSLuaFile($"{folder}/{file.FileName}", new string(source)); } #endif @@ -492,22 +478,12 @@ public void Shutdown() { GModBase.Shutdown(); #endif g_LuaID++; -#if CLIENT_DLL LuaClass.ShutdownLuaClasses(g_Lua!); -#else - Game.Server.GarrysMod.LuaClass.ShutdownLuaClasses(g_Lua!); -#endif get.LuaShared()!.CloseLuaInterface(g_Lua!); g_Lua = null; -#if CLIENT_DLL if (LuaNetworkedVars.g_LuaNetworkedVars == null) Error("!g_LuaNetworkedVars"); LuaNetworkedVars.g_LuaNetworkedVars = null; -#else - if (Game.Server.GarrysMod.LuaNetworkedVars.g_LuaNetworkedVars == null) - Error("!g_LuaNetworkedVars"); - Game.Server.GarrysMod.LuaNetworkedVars.g_LuaNetworkedVars = null; -#endif } } @@ -613,11 +589,7 @@ public void EntityCreated(BaseEntity? ent) { if (gGM == null || !gGM.CallWithArgs((int)LUA_POOLEDSTRING.OnEntityCreated)) return; -#if CLIENT_DLL LuaEntity.Push_Entity(ent); -#else - Game.Server.GarrysMod.LuaEntity.Push_Entity(ent); -#endif gGM.CallNoReturns(1); } @@ -671,21 +643,13 @@ public bool RenderScene(in ViewSetup view) { #endif public void EntityRemoved(BaseEntity ent, bool fullUpdate) { -#if CLIENT_DLL LuaEntity.RemoveFromRemoveList(ent); -#else - Game.Server.GarrysMod.LuaEntity.RemoveFromRemoveList(ent); -#endif SoundEnvelopeController.GetController().ShutdownSoundsForEntity(ent.EntIndex()); if (g_Lua == null || gGM == null) return; if (gGM.CallWithArgs((int)LUA_POOLEDSTRING.EntityRemoved)) { -#if CLIENT_DLL LuaEntity.Push_Entity(ent); -#else - Game.Server.GarrysMod.LuaEntity.Push_Entity(ent); -#endif g_Lua.PushBool(fullUpdate); gGM.CallNoReturns(2); } @@ -695,7 +659,7 @@ public void EntityRemoved(BaseEntity ent, bool fullUpdate) { ent.GetLuaTable()?.UnReference(); ent.GetLuaEntity()?.UnReference(); } - Game.Server.GarrysMod.LuaNetworkedVars.g_LuaNetworkedVars?.ClearEntity(ent.GetRefEHandle().Index); + LuaNetworkedVars.g_LuaNetworkedVars?.ClearEntity(ent.GetRefEHandle().Index); #endif } @@ -708,9 +672,9 @@ public void Think() { LuaFileLibrary.AsyncCycle(); UGCDownloadManager.Think(); #else - Game.Server.GarrysMod.LuaNetworkedVars.g_LuaNetworkedVars?.Cycle(); - Game.Server.GarrysMod.LuaTimer.Cycle(); - Game.Server.GarrysMod.LuaFileLibrary.AsyncCycle(); + LuaNetworkedVars.g_LuaNetworkedVars?.Cycle(); + LuaTimer.Cycle(); + LuaFileLibrary.AsyncCycle(); #endif // HTTP.Cycle(); // ErrorReporter.RunQueue(); diff --git a/Game.Shared/GarrysMod/LuaDump.cs b/Game.Shared/GarrysMod/LuaDump.cs index 2482a442..c4d90630 100644 --- a/Game.Shared/GarrysMod/LuaDump.cs +++ b/Game.Shared/GarrysMod/LuaDump.cs @@ -7,7 +7,13 @@ using System.Text; using System.Text.RegularExpressions; +#if CLIENT_DLL namespace Game.Client.GarrysMod; +#elif MENU_DLL +namespace Game.MenuSystem.GarrysMod; +#else +namespace Game.Server.GarrysMod; +#endif public static class LuaDump { diff --git a/Game.Shared/GarrysMod/LuaFileLibrary.cs b/Game.Shared/GarrysMod/LuaFileLibrary.cs index be69a65d..b05ea17c 100644 --- a/Game.Shared/GarrysMod/LuaFileLibrary.cs +++ b/Game.Shared/GarrysMod/LuaFileLibrary.cs @@ -256,7 +256,7 @@ static int File__Read(ILuaInterface lua) { toRead = length; else { #if !MENU_DLL - if (Game.Client.GarrysMod.GarrysMod.lua_strict.GetInt() != 0) { + if (GarrysMod.lua_strict.GetInt() != 0) { lua.ErrorFromLua($"File:Read() - Invalid requested size {(int)length}\n"); return 0; } @@ -310,7 +310,7 @@ static int File__Write(ILuaInterface lua) { } #if !MENU_DLL - if (Game.Client.GarrysMod.GarrysMod.lua_strict.GetInt() != 0) + if (GarrysMod.lua_strict.GetInt() != 0) #endif lua.ErrorFromLua($"File:Write() - Invalid write size {data.Length}\n"); return 0; diff --git a/Game.Shared/GarrysMod/LuaGamemode.cs b/Game.Shared/GarrysMod/LuaGamemode.cs index 176d0227..104c28d6 100644 --- a/Game.Shared/GarrysMod/LuaGamemode.cs +++ b/Game.Shared/GarrysMod/LuaGamemode.cs @@ -37,7 +37,7 @@ public void Dispose() { } public void LoadGamemode(string name, bool reload) { - if (Game.Client.GarrysMod.GarrysMod.g_LuaManager == null) + if (GarrysMod.g_LuaManager == null) Error("Tried to LoadGamemode with NULL g_LuaManager"); if (g_Lua == null) Error("Tried to LoadGamemode with NULL g_Lua"); @@ -59,16 +59,16 @@ public void LoadGamemode(string name, bool reload) { foreach (ILegacyAddons.Information addon in filesystem.LegacyAddons().GetList()) { string path = addon.GamemodesPath + "/" + folder + "/entities"; if (!string.IsNullOrEmpty(addon.GamemodesPath) && filesystem.IsDirectory(path, "MOD")) - get.LuaShared()!.MountLuaAdd(path, Game.Client.GarrysMod.GarrysMod.LuaPathID); + get.LuaShared()!.MountLuaAdd(path, GarrysMod.LuaPathID); } - get.LuaShared()!.MountLuaAdd("workshop/" + folder + "/entities", Game.Client.GarrysMod.GarrysMod.LuaPathID); + get.LuaShared()!.MountLuaAdd("workshop/" + folder + "/entities", GarrysMod.LuaPathID); get.LuaShared()!.MountLuaAdd(folder + "/entities", g_Lua.GetPathID()); } LuaTable GM = new("GM", 0); GM.SetMember("Folder", folder); GM.SetMember("FolderName", name); - if (!Game.Client.GarrysMod.GarrysMod.g_LuaManager.RunScript(init, Game.Client.GarrysMod.GarrysMod.LuaPathID, true, "!GM")) + if (!GarrysMod.g_LuaManager.RunScript(init, GarrysMod.LuaPathID, true, "!GM")) g_Lua.ErrorFromLua($"Couldn't Load Init Script: '{init}'\n"); string derived = GM.GetMemberStr("DerivedFrom", "base") ?? ""; @@ -104,7 +104,7 @@ public void LoadGamemode(string name, bool reload) { public bool IsValidGamemode(string name) { string init = name + "/gamemode/" + "init.lua"; - return Game.Client.GarrysMod.GarrysMod.g_LuaManager!.ScriptExists(init, Game.Client.GarrysMod.GarrysMod.LuaPathID); + return GarrysMod.g_LuaManager!.ScriptExists(init, GarrysMod.LuaPathID); } public void DeriveGamemode(string name) { diff --git a/Game.Shared/GarrysMod/LuaNet.cs b/Game.Shared/GarrysMod/LuaNet.cs index 2f84d2b4..9e4b5091 100644 --- a/Game.Shared/GarrysMod/LuaNet.cs +++ b/Game.Shared/GarrysMod/LuaNet.cs @@ -458,7 +458,7 @@ static void ValidateDataSize(ILuaInterface lua, int bits) { if (g_NetIncoming == null) return; - if (Game.Client.GarrysMod.GarrysMod.lua_strict.GetInt() != 0 && bits > g_NetIncoming.BitsLeft) + if (GarrysMod.lua_strict.GetInt() != 0 && bits > g_NetIncoming.BitsLeft) lua.ErrorFromLua($"Trying to read more data ({bits} bit) than the net message has left ({g_NetIncoming.BitsLeft} bits)!\n"); } diff --git a/Game.Shared/GarrysMod/LuaPlayer.cs b/Game.Shared/GarrysMod/LuaPlayer.cs index 1aedb660..cd639c52 100644 --- a/Game.Shared/GarrysMod/LuaPlayer.cs +++ b/Game.Shared/GarrysMod/LuaPlayer.cs @@ -806,7 +806,7 @@ static int Player__SendLua(ILuaInterface lua) { if (stristr(code, "while true do end").IsEmpty) { Game.Server.RecipientFilter filter = new Game.Server.SingleUserRecipientFilter(player); filter.MakeReliable(); - Game.Client.GarrysMod.GarrysMod.BroadcastLua(filter, code); + GarrysMod.BroadcastLua(filter, code); } return 0; } diff --git a/Game.Shared/GarrysMod/LuaSENTManager.cs b/Game.Shared/GarrysMod/LuaSENTManager.cs index b8d44117..ce57dcbb 100644 --- a/Game.Shared/GarrysMod/LuaSENTManager.cs +++ b/Game.Shared/GarrysMod/LuaSENTManager.cs @@ -4,7 +4,11 @@ using Source.Common.GarrysMod; using Source.Common.GarrysMod.Lua; +#if CLIENT_DLL using static Game.Client.GarrysMod.GarrysMod; +#else +using static Game.Server.GarrysMod.GarrysMod; +#endif #if CLIENT_DLL namespace Game.Client.GarrysMod; diff --git a/Game.Shared/GarrysMod/LuaSWEPManager.cs b/Game.Shared/GarrysMod/LuaSWEPManager.cs index 0b193adf..f12152cd 100644 --- a/Game.Shared/GarrysMod/LuaSWEPManager.cs +++ b/Game.Shared/GarrysMod/LuaSWEPManager.cs @@ -4,7 +4,11 @@ using Source.Common.GarrysMod; using Source.Common.GarrysMod.Lua; +#if CLIENT_DLL using static Game.Client.GarrysMod.GarrysMod; +#else +using static Game.Server.GarrysMod.GarrysMod; +#endif #if CLIENT_DLL namespace Game.Client.GarrysMod; diff --git a/Game.Shared/GarrysMod/LuaTimer.cs b/Game.Shared/GarrysMod/LuaTimer.cs index b18f58ee..86ca4b93 100644 --- a/Game.Shared/GarrysMod/LuaTimer.cs +++ b/Game.Shared/GarrysMod/LuaTimer.cs @@ -65,7 +65,7 @@ public static partial class LuaTimer [LuaFunction] static int Check(ILuaInterface lua) { #if !MENU_DLL - if (Game.Client.GarrysMod.GarrysMod.lua_strict.GetInt() != 0) + if (GarrysMod.lua_strict.GetInt() != 0) lua.ErrorFromLua("timer.Check is deprecated and does nothing. Do not use it."); #endif return 0; diff --git a/Game.Shared/GarrysMod/ScriptedEntity.cs b/Game.Shared/GarrysMod/ScriptedEntity.cs index c5a03c02..653b774d 100644 --- a/Game.Shared/GarrysMod/ScriptedEntity.cs +++ b/Game.Shared/GarrysMod/ScriptedEntity.cs @@ -3,7 +3,11 @@ using Source.Common; using Source.Common.GarrysMod.Lua; +#if CLIENT_DLL using static Game.Client.GarrysMod.GarrysMod; +#else +using static Game.Server.GarrysMod.GarrysMod; +#endif #if CLIENT_DLL namespace Game.Client.GarrysMod; diff --git a/Game.Shared/PrecacheRegister.cs b/Game.Shared/PrecacheRegister.cs index 1ec2a80b..7b4fa0f0 100644 --- a/Game.Shared/PrecacheRegister.cs +++ b/Game.Shared/PrecacheRegister.cs @@ -4,6 +4,12 @@ using System.Collections.Generic; using System.Text; +#if CLIENT_DLL +using static Game.Client.GarrysMod.GarrysMod; +#elif GAME_DLL +using static Game.Server.GarrysMod.GarrysMod; +#endif + namespace Game.Shared; @@ -37,13 +43,13 @@ public PrecacheRegister(PrecacheFn fn, object? userdata) { public static void Precache() { #if GAME_DLL || CLIENT_DLL - if (++Game.Client.GarrysMod.GarrysMod.g_GModPrecaching > 0x20) + if (++g_GModPrecaching > 0x20) Error("Something seems to have gone wrong"); #endif for (PrecacheRegister? cur = PrecacheRegisters; cur != null; cur = cur.Next) cur.Fn(cur.User); #if GAME_DLL || CLIENT_DLL - Game.Client.GarrysMod.GarrysMod.g_GModPrecaching--; + g_GModPrecaching--; #endif }