From cccaebcf126bccc36b2e0ae66646d13887b2d325 Mon Sep 17 00:00:00 2001 From: James King Date: Sun, 10 Mar 2019 19:05:47 +0000 Subject: [PATCH] Workaround for #63 --- SourceUtils/ValveBsp/GameLump.cs | 7 ++++ SourceUtils/ValveBsp/StaticProps.cs | 62 ++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/SourceUtils/ValveBsp/GameLump.cs b/SourceUtils/ValveBsp/GameLump.cs index 3e36426d..72ad2888 100644 --- a/SourceUtils/ValveBsp/GameLump.cs +++ b/SourceUtils/ValveBsp/GameLump.cs @@ -45,6 +45,13 @@ private string GetIdString( int id ) return str; } + public ushort GetItemFlags( string id ) + { + EnsureLoaded(); + + return _items[id].Flags; + } + public ushort GetItemVersion( string id ) { EnsureLoaded(); diff --git a/SourceUtils/ValveBsp/StaticProps.cs b/SourceUtils/ValveBsp/StaticProps.cs index b1d3cef4..3792088d 100644 --- a/SourceUtils/ValveBsp/StaticProps.cs +++ b/SourceUtils/ValveBsp/StaticProps.cs @@ -111,7 +111,50 @@ public struct StaticPropV6 : IStaticProp } [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 72)] - public struct StaticPropV10 : IStaticProp + public struct StaticPropV10Bsp20 : IStaticProp + { + public readonly Vector3 Origin; + public readonly Vector3 Angles; + public readonly ushort PropType; + public readonly ushort FirstLeaf; + public readonly ushort LeafCount; + [MarshalAs(UnmanagedType.U1)] + public readonly bool Solid; + public readonly StaticPropFlags Flags; + public readonly int Skin; + public readonly float FadeMinDist; + public readonly float FadeMaxDist; + public readonly Vector3 LightingOrigin; + + public readonly float ForcedFadeScale; + + public readonly byte MinCpuLevel; + public readonly byte MaxCpuLevel; + public readonly byte MinGpuLevel; + public readonly byte MaxGpuLevel; + + public readonly uint ColorModulation; + [MarshalAs(UnmanagedType.U1)] + public readonly bool DisableX360; + + Vector3 IStaticProp.Origin => Origin; + Vector3 IStaticProp.Angles => Angles; + ushort IStaticProp.PropType => PropType; + int IStaticProp.Skin => Skin; + ushort IStaticProp.FirstLeaf => FirstLeaf; + ushort IStaticProp.LeafCount => LeafCount; + StaticPropFlags IStaticProp.Flags => Flags; + bool IStaticProp.Solid => Solid; + uint IStaticProp.ColorModulation => ColorModulation; + float IStaticProp.FadeMinDist => FadeMinDist; + float IStaticProp.FadeMaxDist => FadeMaxDist; + float IStaticProp.ForcedFadeScale => ForcedFadeScale; + Vector3 IStaticProp.LightingOrigin => LightingOrigin; + float IStaticProp.Scale => 1f; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 76)] + public struct StaticPropV10Bsp21 : IStaticProp { public readonly Vector3 Origin; public readonly Vector3 Angles; @@ -322,8 +365,6 @@ private void EnsureLoaded() return; } - Console.WriteLine($"Static prop version: v{version}"); - switch ( version ) { case 5: @@ -337,9 +378,18 @@ private void EnsureLoaded() .ToArray(); break; case 10: - _props = LumpReader.ReadLumpFromStream( reader.BaseStream, propCount ) - .Cast() - .ToArray(); + if (_bspFile.Version <= 20) + { + _props = LumpReader.ReadLumpFromStream(reader.BaseStream, propCount) + .Cast() + .ToArray(); + } + else + { + _props = LumpReader.ReadLumpFromStream(reader.BaseStream, propCount) + .Cast() + .ToArray(); + } break; case 11: _props = LumpReader.ReadLumpFromStream(reader.BaseStream, propCount)