From b0729424bfa62df0afc29a7db5c42986df8cdd2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:50:22 +0200 Subject: [PATCH 01/13] Port lua bindings for global state access --- Game.Shared/GarrysMod/LuaGame.cs | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Game.Shared/GarrysMod/LuaGame.cs b/Game.Shared/GarrysMod/LuaGame.cs index 5d6aedcb..8ebdb17f 100644 --- a/Game.Shared/GarrysMod/LuaGame.cs +++ b/Game.Shared/GarrysMod/LuaGame.cs @@ -98,6 +98,47 @@ static int SetSkillLevel(ILuaInterface lua) { rules.SkillLevel = (int)g_Lua!.CheckNumber(1); return 0; } + + [LuaFunction] + static int GetGlobalState(ILuaInterface lua) { + int index = GlobalEntity.GetIndex(g_Lua!.CheckString(1)); + g_Lua.PushNumber(index < 0 ? (int)GlobalEState.Dead : (int)GlobalEntity.GetState(index)); + return 1; + } + + [LuaFunction] + static int SetGlobalState(ILuaInterface lua) { + string name = g_Lua!.CheckString(1); + int index = GlobalEntity.GetIndex(name); + GlobalEState state = (GlobalEState)Math.Clamp((int)g_Lua.CheckNumber(2), (int)GlobalEState.Off, (int)GlobalEState.Dead); + if (index < 0) { + GlobalEntity.Add(name, gpGlobals.MapName ?? "", state); + GlobalEntity.SetCounter(GlobalEntity.GetIndex(name), 0); + } + else + GlobalEntity.SetState(index, state); + return 0; + } + + [LuaFunction] + static int GetGlobalCounter(ILuaInterface lua) { + int index = GlobalEntity.GetIndex(g_Lua!.CheckString(1)); + g_Lua.PushNumber(index < 0 ? 0 : GlobalEntity.GetCounter(index)); + return 1; + } + + [LuaFunction] + static int SetGlobalCounter(ILuaInterface lua) { + string name = g_Lua!.CheckString(1); + int index = GlobalEntity.GetIndex(name); + int counter = (int)g_Lua.CheckNumber(2); + if (index < 0) { + GlobalEntity.Add(name, gpGlobals.MapName ?? "", GlobalEState.Off); + index = GlobalEntity.GetIndex(name); + } + GlobalEntity.SetCounter(index, counter); + return 0; + } #endif [LuaFunction] From 835d231f69b0ae2b69c70e46241f1e18f024707d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:50:56 +0200 Subject: [PATCH 02/13] Add gmod_suit, does nothing currently but addons might read it --- Game.Shared/GarrysMod/GarrysMod.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Game.Shared/GarrysMod/GarrysMod.cs b/Game.Shared/GarrysMod/GarrysMod.cs index 1522af42..12e1f88b 100644 --- a/Game.Shared/GarrysMod/GarrysMod.cs +++ b/Game.Shared/GarrysMod/GarrysMod.cs @@ -43,6 +43,7 @@ public class GarrysMod : IGarrysMod { public static readonly ConVar lua_strict = new("lua_strict", "0", FCvar.Replicated | FCvar.Notify, "Enable extra checks for Lua API, such as argument type checking, errors that normally would be silent, etc. Useful to catch bugs in code when developing addons."); public static readonly ConVar sv_allowcslua = new("sv_allowcslua", "0", FCvar.Archive | FCvar.Notify | FCvar.Replicated, "Allow clients to run clientside addons. This will override any gamemode setting!"); + public static readonly ConVar gmod_suit = new("gmod_suit", "0", FCvar.Replicated, "Set to non zero to enable Half-Life 2 aux suit power stuff."); public void DLLInit(IServiceCollection services) { #if CLIENT_DLL From e73d42d8429ce67ea5a82bae40c9665b52fdb754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:53:07 +0200 Subject: [PATCH 03/13] Add g_debug_transitions convar, does nothing at the moment --- Game.Server/Triggers.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Game.Server/Triggers.cs b/Game.Server/Triggers.cs index cac765f4..ad059e2b 100644 --- a/Game.Server/Triggers.cs +++ b/Game.Server/Triggers.cs @@ -15,6 +15,7 @@ namespace Game.Server; public static class TriggerGlobals { public static readonly ConVar showtriggers = new("showtriggers", "0", FCvar.Cheat, "Shows trigger brushes"); + public static readonly ConVar g_debug_transitions = new("g_debug_transitions", "0", FCvar.None, "Set to 1 and restart the map to be warned if the map has no trigger_transition volumes. Set to 2 to see a dump of all entities & associated results during a transition."); // Global list of triggers that care about weapon fire // Doesn't need saving, the triggers re-add themselves on restore. From 00a7c271c35c67db4c702b3ce3a3b7fc09a7726c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:56:23 +0200 Subject: [PATCH 04/13] Share BaseEntity.StopSound(soundname) with the client --- Game.Shared/SoundEmitterSystem.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Game.Shared/SoundEmitterSystem.cs b/Game.Shared/SoundEmitterSystem.cs index 4c32e546..a3406722 100644 --- a/Game.Shared/SoundEmitterSystem.cs +++ b/Game.Shared/SoundEmitterSystem.cs @@ -403,9 +403,15 @@ public partial class { public static void StopSound(int entIndex, int channel, ReadOnlySpan sample) => g_SoundEmitterSystem.StopSound(entIndex, channel, sample); public static void StopSound(int entIndex, ReadOnlySpan soundname) => g_SoundEmitterSystem.StopSound(entIndex, soundname); -#if GAME_DLL - public void StopSound(ReadOnlySpan soundname) => StopSound(EntIndex(), soundname); + public void StopSound(ReadOnlySpan soundname) { +#if CLIENT_DLL + if (EntIndex() == -1) { + StopSound(GetSoundSourceIndex(), soundname); + return; + } #endif + StopSound(EntIndex(), soundname); + } public static SoundLevel LookupSoundLevel(ReadOnlySpan soundname) { return soundemitterbase.LookupSoundLevel(soundname); From b99cec037024a5d38224f74165b2b7fc484d0fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:58:41 +0200 Subject: [PATCH 05/13] Port Entity:StopSound --- Game.Shared/GarrysMod/LuaEntity.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Game.Shared/GarrysMod/LuaEntity.cs b/Game.Shared/GarrysMod/LuaEntity.cs index 8f51101e..e3178acb 100644 --- a/Game.Shared/GarrysMod/LuaEntity.cs +++ b/Game.Shared/GarrysMod/LuaEntity.cs @@ -2094,6 +2094,25 @@ static int Entity__EmitSound(ILuaInterface lua) { return 0; } + [LuaMethod] + static int Entity__StopSound(ILuaInterface lua) { + BaseEntity ent = Get_Entity(1, false)!; + string soundName = lua.CheckString(2); + + if (ent.IsBaseCombatWeapon() && ent is BaseCombatWeapon weapon && weapon.GetOwner() is BaseEntity owner) { + BaseEntity.StopSound(owner.EntIndex(), (int)SoundEntityChannel.Weapon, soundName); + return 0; + } + + if (!stristr(soundName, ".wav").IsEmpty || !stristr(soundName, ".mp3").IsEmpty || !stristr(soundName, ".ogg").IsEmpty || soundName.StartsWith('!')) { + for (SoundEntityChannel channel = SoundEntityChannel.Replace; channel <= SoundEntityChannel.Voice2; channel++) + BaseEntity.StopSound(ent.EntIndex(), (int)channel, soundName); + } + else + ent.StopSound(soundName); + return 0; + } + [LuaMethod] static int Entity__ViewModelIndex(ILuaInterface lua) { BaseEntity ent = Get_Entity(1, false)!; From d0bd81338d59e6a75d43758a0e125ff0cd0490d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:03:42 +0200 Subject: [PATCH 06/13] Port Entity:AddFlags and Entity:RemoveFlags --- Game.Shared/GarrysMod/LuaEntity.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Game.Shared/GarrysMod/LuaEntity.cs b/Game.Shared/GarrysMod/LuaEntity.cs index e3178acb..5b5dd0b9 100644 --- a/Game.Shared/GarrysMod/LuaEntity.cs +++ b/Game.Shared/GarrysMod/LuaEntity.cs @@ -1815,6 +1815,24 @@ static int Entity__IsFlagSet(ILuaInterface lua) { return 1; } + [LuaMethod] + static int Entity__AddFlags(ILuaInterface lua) { + BaseEntity ent = Get_Entity(1, false)!; + if (IsQueuedForRemoval(ent) || ent.IsEFlagSet(EFL.KillMe)) + return 0; + ent.AddFlag((EntityFlags)(int)lua.CheckNumber(2)); + return 0; + } + + [LuaMethod] + static int Entity__RemoveFlags(ILuaInterface lua) { + BaseEntity ent = Get_Entity(1, false)!; + if (IsQueuedForRemoval(ent) || ent.IsEFlagSet(EFL.KillMe)) + return 0; + ent.RemoveFlag((EntityFlags)(int)lua.CheckNumber(2)); + return 0; + } + [LuaMethod] static int Entity__GetParent(ILuaInterface lua) { BaseEntity ent = Get_Entity(1, false)!; From f6900a32495a26680cef03b10dc24141df0f2545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:10:26 +0200 Subject: [PATCH 07/13] Port Entity:SetLagCompensated and Entity:IsLagCompensated --- Game.Shared/GarrysMod/LuaEntity.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Game.Shared/GarrysMod/LuaEntity.cs b/Game.Shared/GarrysMod/LuaEntity.cs index 5b5dd0b9..733bef78 100644 --- a/Game.Shared/GarrysMod/LuaEntity.cs +++ b/Game.Shared/GarrysMod/LuaEntity.cs @@ -3107,6 +3107,29 @@ static int Entity__SetCollisionGroup(ILuaInterface lua) { } #if GAME_DLL + [LuaMethod] + static int Entity__SetLagCompensated(ILuaInterface lua) { + BaseEntity ent = Get_Entity(1, false)!; + if (ent.GetBaseAnimating() == null || ent.IsPlayer()) + return 0; + if (lua.GetBool(2)) + lagcompensation.AddAdditionalEntity(ent); + else + lagcompensation.RemoveAdditionalEntity(ent); + return 0; + } + + [LuaMethod] + static int Entity__IsLagCompensated(ILuaInterface lua) { + BaseEntity ent = Get_Entity(1, false)!; + if (ent.GetBaseAnimating() == null) { + lua.PushBool(false); + return 1; + } + lua.PushBool(ent.IsPlayer() || lagcompensation.IsAdditionalEntity(ent)); + return 1; + } + [LuaMethod] static int Entity__HasBoneManipulations(ILuaInterface lua) { BaseEntity ent = Get_Entity(1, false)!; From 46c0098206fd764ec44b9c829763fec28fccebf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:19:37 +0200 Subject: [PATCH 08/13] Port GMOD_Player.KillSilent --- Game.Server/GarrysMod/GMOD_Player.cs | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Game.Server/GarrysMod/GMOD_Player.cs b/Game.Server/GarrysMod/GMOD_Player.cs index 14e695c7..4032d3b9 100644 --- a/Game.Server/GarrysMod/GMOD_Player.cs +++ b/Game.Server/GarrysMod/GMOD_Player.cs @@ -73,6 +73,43 @@ public void Kill() { Event_Dying(new TakeDamageInfo(this, this, 0, DamageType.NeverGib)); } + public void KillSilent() { + if (gGM != null && gGM.CallWithArgs((int)LUA_POOLEDSTRING.PlayerSilentDeath)) { + LuaEntity.Push_Entity(this); + gGM.CallFinish(1); + } + + // todo: LeaveVehicle(); + // todo: SetDriving(null); + Health = 0; + ClearUseEntity(); + // todo: DetonateTripmines(); + + GetActiveWeapon()?.Holster(); + + SetViewOffset(VEC_DEAD_VIEWHEIGHT_SCALED(this)); + LifeState = (int)Source.LifeState.Dying; + pl.DeadFlag = true; + AddSolidFlags(SolidFlags.NotSolid); + SetMoveType(Source.MoveType.None); + SetGroundEntity(null); + SetSuitUpdate(null, false, 0); + SetFOV(this, 0); + DeathTime = gpGlobals.CurTime; + FlashlightTurnOff(); + LifeState = (int)Source.LifeState.Dead; + RemoveEffects(EntityEffects.NoDraw); + StopZooming(); + RemoveAllItems(true); + UnforceButtons((InButtons)0x3FFFFFF); + EnableButtons((InButtons)0x3FFFFFF); + + if (gGM != null && gGM.CallWithArgs((int)LUA_POOLEDSTRING.PostPlayerDeath)) { + LuaEntity.Push_Entity(this); + gGM.CallFinish(1); + } + } + public ReadOnlySpan GetUniqueID() { if (gpGlobals.MaxClients == 1) { if (NeedsUniqueID) { From 18bb9ce699658ecd6cddce29a1665f8dc2e1ac86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:23:12 +0200 Subject: [PATCH 09/13] Port Player:KillSilent --- Game.Shared/GarrysMod/LuaPlayer.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Game.Shared/GarrysMod/LuaPlayer.cs b/Game.Shared/GarrysMod/LuaPlayer.cs index 9a599b55..f018cf4b 100644 --- a/Game.Shared/GarrysMod/LuaPlayer.cs +++ b/Game.Shared/GarrysMod/LuaPlayer.cs @@ -152,6 +152,13 @@ static int Player__Kill(ILuaInterface lua) { player.Kill(); return 0; } + + [LuaMethod] + static int Player__KillSilent(ILuaInterface lua) { + GMOD_Player player = (GMOD_Player)Get_Player(1, false)!; + player.KillSilent(); + return 0; + } #endif [LuaMethod] From 30e91dcf0d0c8ca883704feb4efd55ca1298f49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:30:25 +0200 Subject: [PATCH 10/13] Port the hidehud convar --- Game.Client/HUD/Hud.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Game.Client/HUD/Hud.cs b/Game.Client/HUD/Hud.cs index f142e37c..4d4ae685 100644 --- a/Game.Client/HUD/Hud.cs +++ b/Game.Client/HUD/Hud.cs @@ -7,6 +7,7 @@ using Game.Shared; using Source; +using Source.Common.Commands; using Source.Common.Filesystem; using Source.Common.Formats.Keyvalues; using Source.Common.GUI; @@ -154,6 +155,8 @@ public enum ProgressBarType [EngineComponent] public class Hud(HudElementHelper HudElementHelper) { + static readonly ConVar hidehud = new("hidehud", "0", FCvar.Cheat); + readonly HudTextureDict Icons = []; public readonly List HudList = []; internal InButtons KeyBits; @@ -267,7 +270,8 @@ internal bool IsHidden(HideHudBits hudFlags) { return true; HideHudBits hideHud = (HideHudBits)player.Local.HideHUD; - // todo: hidehud convar + if (hidehud.GetInt() != 0) + hideHud = (HideHudBits)hidehud.GetInt(); if ((hideHud & HideHudBits.All) != 0) return true; From 6144ff0837cdba6725ad0a5e385f2b4b45c6a6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:37:01 +0200 Subject: [PATCH 11/13] Port NPC:SetCurrentWeaponProficiency and GetCurrentWeaponProficiency --- Game.Server/GarrysMod/LuaNPC.cs | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Game.Server/GarrysMod/LuaNPC.cs diff --git a/Game.Server/GarrysMod/LuaNPC.cs b/Game.Server/GarrysMod/LuaNPC.cs new file mode 100644 index 00000000..075bc9a3 --- /dev/null +++ b/Game.Server/GarrysMod/LuaNPC.cs @@ -0,0 +1,42 @@ +using Game.Shared; + +using Source.Common.GarrysMod.Lua; + +namespace Game.Server.GarrysMod; + +public static partial class LuaNPC +{ + [LuaClass] + static readonly LuaEntityClass LC_NPC = LuaEntity.LC_NPC; + + public static AI_BaseNPC? Get_NPC(int stackPos, bool allowNull) { + BaseEntity? ent = LuaEntity.Get_Entity(stackPos, allowNull); + if (ent == null) + return null; + + AI_BaseNPC? npc = ent.MyNPCPointer(); + if (npc == null && !allowNull) + g_Lua!.Error("Tried to use a NULL NPC!"); + return npc; + } + + [LuaMethod] + static int NPC__SetCurrentWeaponProficiency(ILuaInterface lua) { + AI_BaseNPC? npc = Get_NPC(1, false); + if (npc == null) + return 0; + + npc.SetCurrentWeaponProficiency((WeaponProficiency)Math.Clamp((int)lua.CheckNumber(2), (int)WeaponProficiency.Poor, (int)WeaponProficiency.Perfect)); + return 0; + } + + [LuaMethod] + static int NPC__GetCurrentWeaponProficiency(ILuaInterface lua) { + AI_BaseNPC? npc = Get_NPC(1, false); + if (npc == null) + return 0; + + lua.PushNumber((int)npc.GetCurrentWeaponProficiency()); + return 1; + } +} From f9fd8029c69a44a2e209d73fc7bcf53a51cce6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:46:52 +0200 Subject: [PATCH 12/13] Fix server GetModel never reloading the world model --- Source.Engine/Server/GameServer.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source.Engine/Server/GameServer.cs b/Source.Engine/Server/GameServer.cs index 59a92860..f0cf7c97 100644 --- a/Source.Engine/Server/GameServer.cs +++ b/Source.Engine/Server/GameServer.cs @@ -247,9 +247,6 @@ public int PrecacheModel(ReadOnlySpan name, Res flags, Model? model = null if (model != null) return model; - if (index == 1) - return null; - ReadOnlySpan name = ModelPrecacheTable.GetString(index); if (name.IsEmpty) return null; From cb70440b1bf65da8b0357856112c7cbe3f70bcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:51:17 +0200 Subject: [PATCH 13/13] Raise the model precache limit to GMod's 8192 --- Source.Engine/Precache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source.Engine/Precache.cs b/Source.Engine/Precache.cs index 553b72a4..004ee108 100644 --- a/Source.Engine/Precache.cs +++ b/Source.Engine/Precache.cs @@ -23,7 +23,7 @@ public class PrecacheItem public const int PRECACHE_USER_DATA_NUMBITS = 2; - public const int MAX_MODEL_INDEX_BITS = 12; + public const int MAX_MODEL_INDEX_BITS = 13; public const int MAX_MODELS = (1 << MAX_MODEL_INDEX_BITS); public const int MAX_GENERIC_INDEX_BITS = 9;