From 67799b965b4acb200ad74c0bf906a221cdef3c8e Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 15 Nov 2015 15:43:17 -0800 Subject: [PATCH 1/2] Wad: support loading WAD2 (Quake) texture wads. WAD2 is the same as WAD3 except that the miptex entries don't have a palette after the pixel data, the palette needs to be supplied externally. --- Sledge.DataStructures/GameData/Palette.cs | 12 +++++++++ .../Sledge.DataStructures.csproj | 1 + Sledge.Editor/Documents/Document.cs | 21 +++++++++++++++- Sledge.Editor/Extensions/ModelExtensions.cs | 2 +- Sledge.Packages/Sledge.Packages.csproj | 7 +++++- Sledge.Packages/Wad/WadEntryType.cs | 2 +- Sledge.Packages/Wad/WadImageStream.cs | 13 ++++++++-- Sledge.Packages/Wad/WadPackage.cs | 25 ++++++++++++++----- Sledge.Providers/Model/MdlProvider.cs | 10 ++++---- Sledge.Providers/Model/ModelProvider.cs | 10 ++++---- Sledge.Providers/Texture/SprProvider.cs | 5 ++-- Sledge.Providers/Texture/TexturePackage.cs | 5 +++- Sledge.Providers/Texture/TextureProvider.cs | 7 +++--- Sledge.Providers/Texture/VmtProvider.cs | 5 ++-- Sledge.Providers/Texture/WadProvider.cs | 15 +++++------ Sledge.Tests/Vtf/VtfTest.cs | 2 +- 16 files changed, 104 insertions(+), 38 deletions(-) create mode 100644 Sledge.DataStructures/GameData/Palette.cs diff --git a/Sledge.DataStructures/GameData/Palette.cs b/Sledge.DataStructures/GameData/Palette.cs new file mode 100644 index 000000000..2eed3798e --- /dev/null +++ b/Sledge.DataStructures/GameData/Palette.cs @@ -0,0 +1,12 @@ +namespace Sledge.DataStructures.GameData +{ + public class Palette + { + public byte[] ByteArray { get; private set; } + + public Palette(byte[] pal) + { + ByteArray = pal; + } + } +} diff --git a/Sledge.DataStructures/Sledge.DataStructures.csproj b/Sledge.DataStructures/Sledge.DataStructures.csproj index 47e19582e..7ee826f3f 100644 --- a/Sledge.DataStructures/Sledge.DataStructures.csproj +++ b/Sledge.DataStructures/Sledge.DataStructures.csproj @@ -47,6 +47,7 @@ + diff --git a/Sledge.Editor/Documents/Document.cs b/Sledge.Editor/Documents/Document.cs index b9a70e5e6..3ca9ed192 100644 --- a/Sledge.Editor/Documents/Document.cs +++ b/Sledge.Editor/Documents/Document.cs @@ -44,6 +44,7 @@ public class Document public Game Game { get; set; } public GameEnvironment Environment { get; private set; } public GameData GameData { get; set; } + public Palette Palette { get; set; } public Pointfile Pointfile { get; set; } @@ -107,7 +108,25 @@ public Document(string mapFile, Map map, Game game) GameData.MapSizeHigh = game.OverrideMapSizeHigh; } - TextureCollection = TextureProvider.CreateCollection(Environment.GetGameDirectories(), Game.AdditionalPackages, Game.GetTextureBlacklist(), Game.GetTextureWhitelist()); + // Set up Quake 1/Hexen 2 palette + var palpath = Environment.Root.TraversePath("gfx/palette.lmp"); + var paldata = new byte[768]; + if (palpath != null) + { + try + { + using (var br = new BinaryReader(palpath.Open())) + { + paldata = br.ReadBytes(768); + } + } + catch (Exception) + { + } + } + Palette = new Palette(paldata); + + TextureCollection = TextureProvider.CreateCollection(Environment.GetGameDirectories(), Game.AdditionalPackages, Game.GetTextureBlacklist(), Game.GetTextureWhitelist(), Palette); /* .Union(GameData.MaterialExclusions) */ // todo material exclusions var texList = Map.GetAllTextures(); diff --git a/Sledge.Editor/Extensions/ModelExtensions.cs b/Sledge.Editor/Extensions/ModelExtensions.cs index 3ff087974..bdd2a9200 100644 --- a/Sledge.Editor/Extensions/ModelExtensions.cs +++ b/Sledge.Editor/Extensions/ModelExtensions.cs @@ -83,7 +83,7 @@ private static bool UpdateModels(Document document, MapObject mo, Dictionary - + + + {26a974c9-e495-4fa3-8e87-1e00019d04f5} + Sledge.DataStructures + +