From 663288a9b6f6747ff7a24af87708173c1851c695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 13 Oct 2026 02:05:14 +0300 Subject: [PATCH] Fix IVPhysicsKeyHandler passing parsed data by value --- Game.Server/Physics.cs | 4 ++-- Source.Common/VCollideParse.cs | 4 ++-- Source.Physics/VPhysicsKeyParser.cs | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Game.Server/Physics.cs b/Game.Server/Physics.cs index dd821070d..6cb4d4750 100644 --- a/Game.Server/Physics.cs +++ b/Game.Server/Physics.cs @@ -49,8 +49,8 @@ public static float PhysGetEntityMass(BaseEntity entity) { class SkipKeys : IVPhysicsKeyHandler { - public void ParseKeyValue(T data, ReadOnlySpan key, ReadOnlySpan value) { } - public void SetDefaults(T data) { } + public void ParseKeyValue(ref T data, ReadOnlySpan key, ReadOnlySpan value) { } + public void SetDefaults(ref T data) { } } public static void PhysSolidOverride(ref Solid solid, string? overrideScript) { diff --git a/Source.Common/VCollideParse.cs b/Source.Common/VCollideParse.cs index 473f3c928..985f990c2 100644 --- a/Source.Common/VCollideParse.cs +++ b/Source.Common/VCollideParse.cs @@ -28,8 +28,8 @@ public struct Fluid public interface IVPhysicsKeyHandler { - void ParseKeyValue(T data, ReadOnlySpan pKey, ReadOnlySpan pValue); - void SetDefaults(T data); + void ParseKeyValue(ref T data, ReadOnlySpan pKey, ReadOnlySpan pValue); + void SetDefaults(ref T data); } public interface IVPhysicsKeyParser diff --git a/Source.Physics/VPhysicsKeyParser.cs b/Source.Physics/VPhysicsKeyParser.cs index dfc353077..14b59148e 100644 --- a/Source.Physics/VPhysicsKeyParser.cs +++ b/Source.Physics/VPhysicsKeyParser.cs @@ -107,7 +107,7 @@ static void CopyString(Span dest, ReadOnlySpan src) { } public void ParseSolid(ref Solid solid, IVPhysicsKeyHandler? unknownKeyHandler) { - unknownKeyHandler?.SetDefaults(solid); + unknownKeyHandler?.SetDefaults(ref solid); for (KeyValues? prop = CurrentBlock?.GetFirstSubKey(); prop != null; prop = prop.GetNextKey()) { ReadOnlySpan value = prop.GetString(); @@ -124,7 +124,7 @@ public void ParseSolid(ref Solid solid, IVPhysicsKeyHandler? unknownKeyHandler) case "inertia": solid.Params.Inertia = prop.GetFloat(); break; case "rotinertialimit": solid.Params.RotInertiaLimit = prop.GetFloat(); break; case "volume": solid.Params.Volume = prop.GetFloat(); break; - default: unknownKeyHandler?.ParseKeyValue(solid, prop.Name, value); break; + default: unknownKeyHandler?.ParseKeyValue(ref solid, prop.Name, value); break; } } @@ -133,7 +133,7 @@ public void ParseSolid(ref Solid solid, IVPhysicsKeyHandler? unknownKeyHandler) public void ParseFluid(ref Fluid fluid, IVPhysicsKeyHandler? unknownKeyHandler) { if (unknownKeyHandler != null) - unknownKeyHandler.SetDefaults(fluid); + unknownKeyHandler.SetDefaults(ref fluid); else { fluid = default; CopyString(fluid.SurfaceProp, "water"); @@ -148,7 +148,7 @@ public void ParseFluid(ref Fluid fluid, IVPhysicsKeyHandler? unknownKeyHandler) case "surfaceplane": fluid.Params.SurfacePlane = ParseVector4(value); break; case "currentvelocity": fluid.Params.CurrentVelocity = ParseVector(value); break; case "contents": fluid.Params.Contents = (Contents)prop.GetInt(); break; - default: unknownKeyHandler?.ParseKeyValue(fluid, prop.Name, value); break; + default: unknownKeyHandler?.ParseKeyValue(ref fluid, prop.Name, value); break; } } @@ -157,7 +157,7 @@ public void ParseFluid(ref Fluid fluid, IVPhysicsKeyHandler? unknownKeyHandler) public void ParseRagdollConstraint(ref ConstraintRagdollParams constraint, IVPhysicsKeyHandler? unknownKeyHandler) { if (unknownKeyHandler != null) - unknownKeyHandler.SetDefaults(constraint); + unknownKeyHandler.SetDefaults(ref constraint); else { constraint = default; constraint.ChildIndex = -1; @@ -189,7 +189,7 @@ public void ParseRagdollConstraint(ref ConstraintRagdollParams constraint, IVPhy constraint.Axes[2].Torque = prop.GetFloat(); constraint.Axes[2].AngularVelocity = 0; break; - default: unknownKeyHandler?.ParseKeyValue(constraint, prop.Name, value); break; + default: unknownKeyHandler?.ParseKeyValue(ref constraint, prop.Name, value); break; } } @@ -208,18 +208,18 @@ public void ParseSurfaceTable(Span table, IVPhysicsKeyHandler? unknownKeyH NextBlock(); } - static void ParseCustomRecursive(KeyValues kv, object? custom, IVPhysicsKeyHandler? unknownKeyHandler) { + static void ParseCustomRecursive(KeyValues kv, ref object? custom, IVPhysicsKeyHandler? unknownKeyHandler) { for (KeyValues? prop = kv.GetFirstSubKey(); prop != null; prop = prop.GetNextKey()) { - unknownKeyHandler?.ParseKeyValue(custom, prop.Name, prop.GetString()); - ParseCustomRecursive(prop, custom, unknownKeyHandler); + unknownKeyHandler?.ParseKeyValue(ref custom, prop.Name, prop.GetString()); + ParseCustomRecursive(prop, ref custom, unknownKeyHandler); } } public void ParseCustom(ref object? custom, IVPhysicsKeyHandler? unknownKeyHandler) { - unknownKeyHandler?.SetDefaults(custom); + unknownKeyHandler?.SetDefaults(ref custom); if (CurrentBlock != null) - ParseCustomRecursive(CurrentBlock, custom, unknownKeyHandler); + ParseCustomRecursive(CurrentBlock, ref custom, unknownKeyHandler); NextBlock(); }