summaryrefslogtreecommitdiff
path: root/NW4RTools/BrresReader.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--NW4RTools/BrresReader.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/NW4RTools/BrresReader.cs b/NW4RTools/BrresReader.cs
index 20d7739..71dacc3 100644
--- a/NW4RTools/BrresReader.cs
+++ b/NW4RTools/BrresReader.cs
@@ -64,6 +64,9 @@ namespace NW4RTools {
case "3DModels(NW4R)":
File.Add(name, ReadAndConvertDict<Model>(ins, ConvertModelResource));
break;
+ case "Textures(NW4R)":
+ File.Add(name, ReadAndConvertDict<Texture>(ins, ConvertTextureResource));
+ break;
default:
Debug.Send("Not implemented");
return;
@@ -71,6 +74,47 @@ namespace NW4RTools {
}
}
+
+
+ private Texture ConvertTextureResource(string name, InputStream ins) {
+ using (var c = Debug.Push(name)) {
+ Texture tex = new Texture();
+
+ int startPos = ins.Position;
+
+ OffsetMap.Add(startPos, "Texture: " + name);
+
+ byte[] magic = ins.ReadBytes(4);
+ UInt32 size = ins.ReadUInt32();
+ UInt32 version = ins.ReadUInt32();
+
+ Debug.Send("Offset: 0x{0:X}; Size: 0x{1:X}; Version: {2}", startPos, size, version);
+
+ Int32 resFileOffset = ins.ReadInt32();
+ Int32 dataOffset = ins.ReadInt32();
+ Int32 nameOffset = ins.ReadInt32();
+
+ // Flags stores nothing interesting, just "is CI" flag (0x1)
+ UInt32 flags = ins.ReadUInt32();
+
+ Int16 width = ins.ReadInt16();
+ Int16 height = ins.ReadInt16();
+ TextureFormat format = (TextureFormat)ins.ReadUInt32();
+
+ tex.MipMapCount = ins.ReadUInt32();
+ tex.MinLOD = ins.ReadFloat();
+ tex.MaxLOD = ins.ReadFloat();
+
+ ins.Seek(startPos + dataOffset);
+ OffsetMap.Add(ins.Position, String.Format("Texture Data for: {0} [{1}, {2}x{3}]", name, format, width, height));
+ tex.ImportData(ins.ReadBytes(Texture.GetDataSize(width, height, format)), width, height, format);
+
+ return tex;
+ }
+ }
+
+
+
private Model ConvertModelResource(string name, InputStream ins) {
using (var c = Debug.Push(name)) {
Model mdl = new Model();