Update WAD3 models

This commit is contained in:
Matt Nadareski
2024-11-17 19:56:59 -05:00
parent 385491c67b
commit ea8630ba8c
13 changed files with 247 additions and 76 deletions

View File

@@ -1,27 +0,0 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.WAD
{
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/WADFile.h"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class Lump
{
public uint Offset;
public uint DiskLength;
public uint Length;
public byte Type;
public byte Compression;
public byte Padding0;
public byte Padding1;
/// <remarks>16 bytes</remarks>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string? Name;
}
}

View File

@@ -1,38 +0,0 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.WAD
{
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/WADFile.h"/>
public sealed class LumpInfo
{
/// <summary>
/// Type 0x42 has no name, type 0x43 does
/// </summary>
/// <remarks>16 bytes</remarks>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string? Name;
public uint Width;
public uint Height;
public uint PixelOffset;
/// <summary>
/// Unknown data
/// </summary>
/// <remarks>12 bytes</remarks>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
public byte[]? UnknownData;
/// <remarks>Width * Height bytes located at PixelOffset</remarks>
public byte[]? PixelData { get; set; }
// TODO: Determine what mipmap data looks like
public uint PaletteSize { get; set; }
/// <remarks>PaletteSize * 3 bytes</remarks>
public byte[]? PaletteData { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.WAD3
{
/// <see href="https://twhl.info/wiki/page/Specification:_WAD3"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class CharInfo
{
public ushort StartOffset;
public ushort CharWidth;
}
}

View File

@@ -1,4 +1,4 @@
namespace SabreTools.Models.WAD
namespace SabreTools.Models.WAD3
{
public static class Constants
{

View File

@@ -0,0 +1,48 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.WAD3
{
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/WADFile.h"/>
/// <see href="https://twhl.info/wiki/page/Specification:_WAD3"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class DirEntry
{
/// <summary>
/// Offset from the beginning of the WAD3 data
/// </summary>
public uint Offset;
/// <summary>
/// The entry's size in the archive in bytes
/// </summary>
public uint DiskLength;
/// <summary>
/// The entry's uncompressed size
/// </summary>
public uint Length;
/// <summary>
/// File type of the entry
/// </summary>
public FileType Type;
/// <summary>
/// Whether the file was compressed
/// </summary>
/// <remarks>Actually a boolean value</remarks>
public byte Compression;
/// <summary>
/// Padding
/// </summary>
public ushort Padding;
/// <summary>
/// Null-terminated texture name
/// </summary>
/// <remarks>16 bytes</remarks>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string? Name;
}
}

View File

@@ -0,0 +1,28 @@
namespace SabreTools.Models.WAD3
{
/// <see href="https://twhl.info/wiki/page/Specification:_WAD3"/>
public enum FileType : byte
{
/// <summary>
/// spraydecal (0x40): Same as <see cref="Miptex"/>.
/// Only found in entry LOGO (or {LOGO) in tempdecal.wad
/// </summary>
Spraydecal = 0x40,
/// <summary>
/// qpic (0x42): A simple image of any size.
/// </summary>
Qpic = 0x42,
/// <summary>
/// miptex (0x43): World texture with dimensions that are multiple-of-16
/// and 4 mipmaps. This is the typical entry type.
/// </summary>
Miptex = 0x43,
/// <summary>
/// font (0x46): Fixed-height font for 256 ASCII characters.
/// </summary>
Font = 0x46,
}
}

View File

@@ -1,4 +1,4 @@
namespace SabreTools.Models.WAD
namespace SabreTools.Models.WAD3
{
/// <summary>
/// Half-Life Texture Package File
@@ -12,13 +12,13 @@ namespace SabreTools.Models.WAD
public Header? Header { get; set; }
/// <summary>
/// Deserialized lumps data
/// Deserialized dir entry data
/// </summary>
public Lump?[]? Lumps { get; set; }
public DirEntry?[]? DirEntries { get; set; }
/// <summary>
/// Deserialized lump infos data
/// Deserialized file entry data
/// </summary>
public LumpInfo?[]? LumpInfos { get; set; }
public FileEntry?[]? FileEntries { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace SabreTools.Models.WAD3
{
/// <summary>
/// qlumpy always align entries to the DWORD (=4 bytes) boundary
/// (i.e. next integer multiples of 4 offset from start of file)
/// </summary>
public abstract class FileEntry
{
// No shared fields between types
}
}

View File

@@ -0,0 +1,40 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.WAD3
{
/// <see href="https://twhl.info/wiki/page/Specification:_WAD3"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class Font : FileEntry
{
/// <summary>
/// Dimensions of the texture (must be divisible by 16)
/// </summary>
public uint Width;
/// <summary>
/// Dimensions of the texture (must be divisible by 16)
/// </summary>
public uint Height;
public uint RowCount;
public uint RowHeight;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public CharInfo[] FontInfo = new CharInfo[256];
/// <remarks>[width][height]</remarks>
public byte[,]? Data;
/// <summary>
/// Number of colors used in the palette (always 256 for GoldSrc)
/// </summary>
public ushort ColorsUsed;
/// <summary>
/// The color palette for the mipmaps (always 256 * 3 = 768 for GoldSrc)
/// </summary>
/// <remarks>[ColorsUsed][3]</remarks>
public byte[,]? Palette { get; set; }
}
}

View File

@@ -1,8 +1,9 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.WAD
namespace SabreTools.Models.WAD3
{
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/WADFile.h"/>
/// <see href="https://twhl.info/wiki/page/Specification:_WAD3"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public sealed class Header
{
@@ -14,13 +15,13 @@ namespace SabreTools.Models.WAD
public string? Signature;
/// <summary>
/// Number of lumps in the file
/// Number of Directory entries
/// </summary>
public uint LumpCount;
public uint NumDirs;
/// <summary>
/// Offset where lumps are stored
/// Offset from the WAD3 data's beginning for first Directory entry
/// </summary>
public uint LumpOffset;
public uint DirOffset;
}
}

View File

@@ -0,0 +1,14 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.WAD3
{
/// <see href="https://twhl.info/wiki/page/Specification:_WAD3"/>
public sealed class MipMap
{
/// <summary>
/// Raw image data. Each byte points to an index in the palette
/// </summary>
/// <remarks>[width][height]</remarks>
public byte[,]? Data { get; set; }
}
}

View File

@@ -0,0 +1,48 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.WAD3
{
/// <see href="https://twhl.info/wiki/page/Specification:_WAD3"/>
public sealed class MipTex : FileEntry
{
/// <summary>
/// Null-terminated texture name
/// </summary>
/// <remarks>16 bytes</remarks>
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string? Name;
/// <summary>
/// Dimensions of the texture (must be divisible by 16)
/// </summary>
public uint Width;
/// <summary>
/// Dimensions of the texture (must be divisible by 16)
/// </summary>
public uint Height;
/// <summary>
/// Offset from start of this struct to each mipmap level's image
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public uint[] MipOffsets = new uint[4];
/// <summary>
/// One MipMap for each mipmap level
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public MipMap[] MipImages = new MipMap[4];
/// <summary>
/// Number of colors used in the palette (always 256 for GoldSrc)
/// </summary>
public ushort ColorsUsed;
/// <summary>
/// The color palette for the mipmaps (always 256 * 3 = 768 for GoldSrc)
/// </summary>
/// <remarks>[ColorsUsed][3]</remarks>
public byte[,]? Palette { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
namespace SabreTools.Models.WAD3
{
/// <see href="https://twhl.info/wiki/page/Specification:_WAD3"/>
public sealed class QpicImage : FileEntry
{
/// <summary>
/// Dimensions of the texture (must be divisible by 16)
/// </summary>
public uint Width;
/// <summary>
/// Dimensions of the texture (must be divisible by 16)
/// </summary>
public uint Height;
/// <summary>
/// Raw image data. Each byte points to an index in the palette
/// </summary>
/// <remarks>[height][width]</remarks>
public byte[,]? Data { get; set; }
/// <summary>
/// Number of colors used in the palette (always 256 for GoldSrc)
/// </summary>
public ushort ColorsUsed;
/// <summary>
/// The color palette for the mipmaps (always 256 * 3 = 768 for GoldSrc)
/// </summary>
/// <remarks>[ColorsUsed][3]</remarks>
public byte[,]? Palette { get; set; }
}
}