Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Game.Client/HUD/Hud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IHudElement> HudList = [];
internal InButtons KeyBits;
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions Game.Server/GarrysMod/GMOD_Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> GetUniqueID() {
if (gpGlobals.MaxClients == 1) {
if (NeedsUniqueID) {
Expand Down
42 changes: 42 additions & 0 deletions Game.Server/GarrysMod/LuaNPC.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions Game.Server/Triggers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Game.Shared/GarrysMod/GarrysMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions Game.Shared/GarrysMod/LuaEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)!;
Expand Down Expand Up @@ -2094,6 +2112,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)!;
Expand Down Expand Up @@ -3070,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)!;
Expand Down
41 changes: 41 additions & 0 deletions Game.Shared/GarrysMod/LuaGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions Game.Shared/GarrysMod/LuaPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 8 additions & 2 deletions Game.Shared/SoundEmitterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,15 @@ public partial class
{
public static void StopSound(int entIndex, int channel, ReadOnlySpan<char> sample) => g_SoundEmitterSystem.StopSound(entIndex, channel, sample);
public static void StopSound(int entIndex, ReadOnlySpan<char> soundname) => g_SoundEmitterSystem.StopSound(entIndex, soundname);
#if GAME_DLL
public void StopSound(ReadOnlySpan<char> soundname) => StopSound(EntIndex(), soundname);
public void StopSound(ReadOnlySpan<char> soundname) {
#if CLIENT_DLL
if (EntIndex() == -1) {
StopSound(GetSoundSourceIndex(), soundname);
return;
}
#endif
StopSound(EntIndex(), soundname);
}

public static SoundLevel LookupSoundLevel(ReadOnlySpan<char> soundname) {
return soundemitterbase.LookupSoundLevel(soundname);
Expand Down
2 changes: 1 addition & 1 deletion Source.Engine/Precache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions Source.Engine/Server/GameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,6 @@ public int PrecacheModel(ReadOnlySpan<char> name, Res flags, Model? model = null
if (model != null)
return model;

if (index == 1)
return null;

ReadOnlySpan<char> name = ModelPrecacheTable.GetString(index);
if (name.IsEmpty)
return null;
Expand Down
Loading