From c48522e6c02d4fe1621b2a5124347033716408bd Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 28 Dec 2022 15:22:16 -0800 Subject: [PATCH] Add and use VBSP constants --- BurnOutSharp.Builders/VBSP.cs | 22 ++-------------------- BurnOutSharp.Models/VBSP/Constants.cs | 26 ++++++++++++++++++++++++++ BurnOutSharp.Wrappers/VBSP.cs | 10 +++++----- 3 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 BurnOutSharp.Models/VBSP/Constants.cs diff --git a/BurnOutSharp.Builders/VBSP.cs b/BurnOutSharp.Builders/VBSP.cs index d65276a8..dc062046 100644 --- a/BurnOutSharp.Builders/VBSP.cs +++ b/BurnOutSharp.Builders/VBSP.cs @@ -2,30 +2,12 @@ using System.IO; using System.Text; using BurnOutSharp.Models.VBSP; using BurnOutSharp.Utilities; +using static BurnOutSharp.Models.VBSP.Constants; namespace BurnOutSharp.Builders { public static class VBSP { - #region Constants - - /// - /// Total number of lumps in the package - /// - public const int HL_VBSP_LUMP_COUNT = 64; - - /// - /// Index for the entities lump - /// - public const int HL_VBSP_LUMP_ENTITIES = 0; - - /// - /// Index for the pakfile lump - /// - public const int HL_VBSP_LUMP_PAKFILE = 40; - - #endregion - #region Byte Data /// @@ -101,7 +83,7 @@ namespace BurnOutSharp.Builders byte[] signature = data.ReadBytes(4); header.Signature = Encoding.ASCII.GetString(signature); - if (header.Signature != "VBSP") + if (header.Signature != SignatureString) return null; header.Version = data.ReadInt32(); diff --git a/BurnOutSharp.Models/VBSP/Constants.cs b/BurnOutSharp.Models/VBSP/Constants.cs new file mode 100644 index 00000000..7ae8cfa9 --- /dev/null +++ b/BurnOutSharp.Models/VBSP/Constants.cs @@ -0,0 +1,26 @@ +namespace BurnOutSharp.Models.VBSP +{ + public static class Constants + { + public static readonly byte[] SignatureBytes = new byte[] { 0x56, 0x42, 0x53, 0x50 }; + + public const string SignatureString = "VBSP"; + + public const uint SignatureUInt32 = 0x50534256; + + /// + /// Total number of lumps in the package + /// + public const int HL_VBSP_LUMP_COUNT = 64; + + /// + /// Index for the entities lump + /// + public const int HL_VBSP_LUMP_ENTITIES = 0; + + /// + /// Index for the pakfile lump + /// + public const int HL_VBSP_LUMP_PAKFILE = 40; + } +} \ No newline at end of file diff --git a/BurnOutSharp.Wrappers/VBSP.cs b/BurnOutSharp.Wrappers/VBSP.cs index 8516a680..fae30829 100644 --- a/BurnOutSharp.Wrappers/VBSP.cs +++ b/BurnOutSharp.Wrappers/VBSP.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; +using static BurnOutSharp.Models.VBSP.Constants; namespace BurnOutSharp.Wrappers { @@ -138,10 +138,10 @@ namespace BurnOutSharp.Wrappers string specialLumpName = string.Empty; switch (i) { - case Builders.VBSP.HL_VBSP_LUMP_ENTITIES: + case HL_VBSP_LUMP_ENTITIES: specialLumpName = " (entities)"; break; - case Builders.VBSP.HL_VBSP_LUMP_PAKFILE: + case HL_VBSP_LUMP_PAKFILE: specialLumpName = " (pakfile)"; break; } @@ -211,10 +211,10 @@ namespace BurnOutSharp.Wrappers string filename = $"lump_{index}.bin"; switch (index) { - case Builders.VBSP.HL_VBSP_LUMP_ENTITIES: + case HL_VBSP_LUMP_ENTITIES: filename = "entities.ent"; break; - case Builders.VBSP.HL_VBSP_LUMP_PAKFILE: + case HL_VBSP_LUMP_PAKFILE: filename = "pakfile.zip"; break; }