From dcef3115b82fce7c253990de274b21cf86ff3975 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 4 Nov 2022 09:56:06 -0700 Subject: [PATCH] Add NE resource table --- BurnOutSharp.Models/NewExecutable/Enums.cs | 19 ++++++++ .../NewExecutable/Executable.cs | 5 ++- .../NewExecutable/ResourceTable.cs | 35 +++++++++++++++ .../ResourceTypeAndNameString.cs | 26 +++++++++++ .../ResourceTypeInformationEntry.cs | 37 ++++++++++++++++ .../ResourceTypeResourceEntry.cs | 44 +++++++++++++++++++ 6 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 BurnOutSharp.Models/NewExecutable/ResourceTable.cs create mode 100644 BurnOutSharp.Models/NewExecutable/ResourceTypeAndNameString.cs create mode 100644 BurnOutSharp.Models/NewExecutable/ResourceTypeInformationEntry.cs create mode 100644 BurnOutSharp.Models/NewExecutable/ResourceTypeResourceEntry.cs diff --git a/BurnOutSharp.Models/NewExecutable/Enums.cs b/BurnOutSharp.Models/NewExecutable/Enums.cs index a1c71bda..2b406925 100644 --- a/BurnOutSharp.Models/NewExecutable/Enums.cs +++ b/BurnOutSharp.Models/NewExecutable/Enums.cs @@ -150,6 +150,25 @@ namespace BurnOutSharp.Models.NewExecutable Unknown = 0xF0, } + [Flags] + public enum ResourceTypeResourceFlag : ushort + { + /// + /// Resource is not fixed. + /// + MOVEABLE = 0x0010, + + /// + /// Resource can be shared. + /// + PURE = 0x0020, + + /// + /// Resource is preloaded. + /// + PRELOAD = 0x0040, + } + [Flags] public enum SegmentTableEntryFlag : ushort { diff --git a/BurnOutSharp.Models/NewExecutable/Executable.cs b/BurnOutSharp.Models/NewExecutable/Executable.cs index 52001660..adcb60ee 100644 --- a/BurnOutSharp.Models/NewExecutable/Executable.cs +++ b/BurnOutSharp.Models/NewExecutable/Executable.cs @@ -26,7 +26,10 @@ namespace BurnOutSharp.Models.NewExecutable /// public SegmentTableEntry[] SegmentTable { get; set; } - // TODO: NE Resource Table + /// + /// Resource table + /// + public ResourceTable ResourceTable { get; set; } /// /// Resident-Name table diff --git a/BurnOutSharp.Models/NewExecutable/ResourceTable.cs b/BurnOutSharp.Models/NewExecutable/ResourceTable.cs new file mode 100644 index 00000000..f4da8fe7 --- /dev/null +++ b/BurnOutSharp.Models/NewExecutable/ResourceTable.cs @@ -0,0 +1,35 @@ +using System.Runtime.InteropServices; + +namespace BurnOutSharp.Models.NewExecutable +{ + /// + /// The resource table follows the segment table and contains entries for + /// each resource in the executable file. The resource table consists of + /// an alignment shift count, followed by a table of resource records. The + /// resource records define the type ID for a set of resources. Each + /// resource record contains a table of resource entries of the defined + /// type. The resource entry defines the resource ID or name ID for the + /// resource. It also defines the location and size of the resource. The + /// following describes the contents of each of these structures: + /// + /// + [StructLayout(LayoutKind.Sequential)] + public class ResourceTable + { + /// + /// Alignment shift count for resource data. + /// + public ushort AlignmentShiftCount; + + /// + /// A table of resource type information blocks follows. + /// + public ResourceTypeInformationEntry[] ResourceTypes; + + /// + /// Resource type and name strings are stored at the end of the + /// resource table. + /// + public ResourceTypeAndNameString[] TypeAndNameStrings; + } +} diff --git a/BurnOutSharp.Models/NewExecutable/ResourceTypeAndNameString.cs b/BurnOutSharp.Models/NewExecutable/ResourceTypeAndNameString.cs new file mode 100644 index 00000000..52f82f9e --- /dev/null +++ b/BurnOutSharp.Models/NewExecutable/ResourceTypeAndNameString.cs @@ -0,0 +1,26 @@ +using System.Runtime.InteropServices; + +namespace BurnOutSharp.Models.NewExecutable +{ + /// + /// Resource type and name strings are stored at the end of the + /// resource table. Note that these strings are NOT null terminated and + /// are case sensitive. + /// + /// + [StructLayout(LayoutKind.Sequential)] + public class ResourceTypeAndNameString + { + /// + /// Length of the type or name string that follows. A zero value + /// indicates the end of the resource type and name string, also + /// the end of the resource table. + /// + public byte Length; + + /// + /// ASCII text of the type or name string. + /// + public byte[] Text; + } +} diff --git a/BurnOutSharp.Models/NewExecutable/ResourceTypeInformationEntry.cs b/BurnOutSharp.Models/NewExecutable/ResourceTypeInformationEntry.cs new file mode 100644 index 00000000..53ed3249 --- /dev/null +++ b/BurnOutSharp.Models/NewExecutable/ResourceTypeInformationEntry.cs @@ -0,0 +1,37 @@ +using System.Runtime.InteropServices; + +namespace BurnOutSharp.Models.NewExecutable +{ + /// + /// A table of resource type information blocks follows. The following + /// is the format of each type information block: + /// + /// + [StructLayout(LayoutKind.Sequential)] + public class ResourceTypeInformationEntry + { + /// + /// Type ID. This is an integer type if the high-order bit is + /// set (8000h); otherwise, it is an offset to the type string, + /// the offset is relative to the beginning of the resource + /// table. A zero type ID marks the end of the resource type + /// information blocks. + /// + public ushort TypeID; + + /// + /// Number of resources for this type. + /// + public ushort ResourceCount; + + /// + /// Reserved. + /// + public uint Reserved; + + /// + /// A table of resources for this type follows. + /// + public ResourceTypeResourceEntry[] Resources; + } +} diff --git a/BurnOutSharp.Models/NewExecutable/ResourceTypeResourceEntry.cs b/BurnOutSharp.Models/NewExecutable/ResourceTypeResourceEntry.cs new file mode 100644 index 00000000..8103dd10 --- /dev/null +++ b/BurnOutSharp.Models/NewExecutable/ResourceTypeResourceEntry.cs @@ -0,0 +1,44 @@ +using System.Runtime.InteropServices; + +namespace BurnOutSharp.Models.NewExecutable +{ + /// + /// A table of resources for this type follows. The following is + /// the format of each resource (8 bytes each): + /// + /// + [StructLayout(LayoutKind.Sequential)] + public class ResourceTypeResourceEntry + { + /// + /// File offset to the contents of the resource data, + /// relative to beginning of file. The offset is in terms + /// of the alignment shift count value specified at + /// beginning of the resource table. + /// + public ushort Offset; + + /// + /// Length of the resource in the file (in bytes). + /// + public ushort Length; + + /// + /// Flag word. + /// + public ResourceTypeResourceFlag FlagWord; + + /// + /// Resource ID. This is an integer type if the high-order + /// bit is set (8000h), otherwise it is the offset to the + /// resource string, the offset is relative to the + /// beginning of the resource table. + /// + public ushort ResourceID; + + /// + /// Reserved. + /// + public uint Reserved; + } +}