From cff0bbcdf339ec99b9a1311605fb16f6378b3fb4 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sat, 26 Mar 2011 05:14:59 +0100 Subject: the Wii killing bug is hopefully gone for good! also, a few other improvements --- ConsoleApp/Main.cs | 1 + ConsoleApp/ResFileCommands.cs | 28 ++++++++++++++++++++++++++++ NW4RTools.sln | 2 +- NW4RTools.userprefs | 36 +++++++++++++++++++++++++++++------- NW4RTools/BrresReader.cs | 14 ++++++++++++++ NW4RTools/ObjImporter.cs | 39 +++++++++++++++++++++++++-------------- 6 files changed, 98 insertions(+), 22 deletions(-) diff --git a/ConsoleApp/Main.cs b/ConsoleApp/Main.cs index 322d277..9a180f6 100644 --- a/ConsoleApp/Main.cs +++ b/ConsoleApp/Main.cs @@ -10,6 +10,7 @@ namespace ConsoleApp { CommandLookup.Add("init", new InitCommand()); CommandLookup.Add("list", new ListCommand()); + CommandLookup.Add("list-offsets", new ListOffsetsCommand()); CommandLookup.Add("import-obj", new ImportObjCommand()); CommandLookup.Add("export-obj", new ExportObjCommand()); CommandLookup.Add("export-collada", new ExportColladaCommand()); diff --git a/ConsoleApp/ResFileCommands.cs b/ConsoleApp/ResFileCommands.cs index ac734e4..83c28b2 100644 --- a/ConsoleApp/ResFileCommands.cs +++ b/ConsoleApp/ResFileCommands.cs @@ -85,5 +85,33 @@ namespace ConsoleApp { return "syntax: list -- lists the contents of a .brres file"; } } + + + public class ListOffsetsCommand : Command { + // this class also doesn't inherit from ResFileCommand, because I want to + // keep the OffsetMap + + public ListOffsetsCommand() : base("list offsets of data within a .brres file") { + } + + + public override void Execute(string[] args) { + if (args.Length == 0) { + Console.WriteLine("No path entered"); + return; + } + + SortedDictionary offsetMap; + var rf = BrresReader.LoadFile(System.IO.File.ReadAllBytes(args[0]), false, out offsetMap); + + foreach (var e in offsetMap) { + Console.WriteLine("0x{0:X} : {1}", e.Key, e.Value); + } + } + + public override string GetHelp(string[] args) { + return "syntax: init -- creates an empty .brres file"; + } + } } diff --git a/NW4RTools.sln b/NW4RTools.sln index 953e643..15f8760 100644 --- a/NW4RTools.sln +++ b/NW4RTools.sln @@ -27,7 +27,7 @@ Global {A9C9FABD-0A5F-4DAB-979D-9F288F96866F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = TestApp\TestApp.csproj + StartupItem = ConsoleApp\ConsoleApp.csproj Policies = $0 $0.DotNetNamingPolicy = $1 $1.DirectoryNamespaceAssociation = None diff --git a/NW4RTools.userprefs b/NW4RTools.userprefs index 0317cce..9ca70fc 100644 --- a/NW4RTools.userprefs +++ b/NW4RTools.userprefs @@ -1,13 +1,11 @@  - - + + - - - + + - @@ -19,14 +17,38 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs index aa54437..8b9fcb1 100644 --- a/NW4RTools/BrresReader.cs +++ b/NW4RTools/BrresReader.cs @@ -10,10 +10,18 @@ namespace NW4RTools { return LoadFile(data, true); } + public static ResFile LoadFile(byte[] data, out SortedDictionary offsetMap) { + return LoadFile(data, true, out offsetMap); + } + public static ResFile LoadFile(byte[] data, bool debug) { return new BrresReader(debug).Load(new InputStream(data, ByteEndian.BigEndian)); } + public static ResFile LoadFile(byte[] data, bool debug, out SortedDictionary offsetMap) { + return new BrresReader(debug).Load(new InputStream(data, ByteEndian.BigEndian), out offsetMap); + } + private class RawStreamResDict : ResDict { @@ -35,6 +43,11 @@ namespace NW4RTools { } public ResFile Load(InputStream ins) { + SortedDictionary trashThis; + return Load(ins, out trashThis); + } + + public ResFile Load(InputStream ins, out SortedDictionary offsetMap) { File = new ResFile(); // Read BRRES header @@ -63,6 +76,7 @@ namespace NW4RTools { } } + offsetMap = OffsetMap; return File; } diff --git a/NW4RTools/ObjImporter.cs b/NW4RTools/ObjImporter.cs index f00d0f6..93666b1 100755 --- a/NW4RTools/ObjImporter.cs +++ b/NW4RTools/ObjImporter.cs @@ -103,28 +103,32 @@ namespace NW4RTools { // At the end of the .obj parsing, all the shapes will be converted and written. - if (Lightmap != LightmapType.None && !texGroup.ContainsKey(LightmapName1)) { - var lm01 = new Texture(); - var lm02 = new Texture(); + if (Lightmap != LightmapType.None) { + if (!texGroup.ContainsKey(LightmapName1)) { + var lm01 = new Texture(); - lm01.Images = new System.Drawing.Bitmap[1]; - lm01.Images[0] = new System.Drawing.Bitmap(Path.Combine(BasePath, string.Format("images/{0}.png", LightmapName1))); + lm01.Images = new System.Drawing.Bitmap[1]; + lm01.Images[0] = new System.Drawing.Bitmap(Path.Combine(BasePath, string.Format("images/{0}.png", LightmapName1))); - lm01.Format = TextureFormat.I8; + lm01.Format = TextureFormat.I8; + texGroup.Add(LightmapName1, lm01); + } - lm02.Images = new System.Drawing.Bitmap[1]; - lm02.Images[0] = new System.Drawing.Bitmap(Path.Combine(BasePath, string.Format("images/{0}.png", LightmapName2))); + if (!texGroup.ContainsKey(LightmapName2)) { + var lm02 = new Texture(); - lm02.Format = TextureFormat.I8; + lm02.Images = new System.Drawing.Bitmap[1]; + lm02.Images[0] = new System.Drawing.Bitmap(Path.Combine(BasePath, string.Format("images/{0}.png", LightmapName2))); - texGroup.Add(LightmapName1, lm01); - texGroup.Add(LightmapName2, lm02); + lm02.Format = TextureFormat.I8; + texGroup.Add(LightmapName2, lm02); + } } CurrentModel = new Model(); - modelGroup.Add(modelName, CurrentModel); + modelGroup[modelName] = CurrentModel; // Before we start reading the OBJ file, prepare the model CurrentModel.ScaleMode = Model.ScaleModeType.Standard; @@ -780,10 +784,17 @@ namespace NW4RTools { // I might need to create XFMEM_VTXSPECS... // test_lift uses 0x14. According to Dolphin's src, this means: // numcolors = 0, numnormals = 1 (just normal), numtextures = 1. Makes sense. - // If lightmaps, then use: numcolors = 1, numnormals = 1, numtextures = 3 + // If lightmaps, then use: numcolors = 1, numnormals = 1, numtextures = 1 + + // NOTE: Dolphin's source names that as "numtextures" -- but in reality it defines + // the number of texture coords that are sent in the vertex data, NOT textures! + // This little bug was the source of tons of trouble on real consoles, since + // previously I was using 3 (one regular texture; two lightmaps). + // Lightmap texcoords are auto generated, so we now use 1 here. + byte vtxSpecs; if (usingLightmaps) - vtxSpecs = 1 | (1 << 2) | (3 << 4); + vtxSpecs = 1 | (1 << 2) | (1 << 4); else vtxSpecs = 0 | (1 << 2) | (1 << 4); -- cgit v1.2.3