summaryrefslogtreecommitdiff
path: root/TestApp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-09-23 17:43:33 +0200
committerTreeki <treeki@gmail.com>2012-09-23 17:43:33 +0200
commitc9bfbf84244c8aa4e26ece994ef6b93386c708e3 (patch)
treed267d5732bed21c666750263d2ca62dcdfa9e44f /TestApp
parent31380b4bb93d1fb65faff8f71753de80fb0a8c9d (diff)
downloadnw4rtools-c9bfbf84244c8aa4e26ece994ef6b93386c708e3.tar.gz
nw4rtools-c9bfbf84244c8aa4e26ece994ef6b93386c708e3.zip
tons of junk I'll clean up eventually
Diffstat (limited to '')
-rwxr-xr-xTestApp/Main.cs312
1 files changed, 300 insertions, 12 deletions
diff --git a/TestApp/Main.cs b/TestApp/Main.cs
index a61577f..76329b7 100755
--- a/TestApp/Main.cs
+++ b/TestApp/Main.cs
@@ -2,6 +2,8 @@ using System;
using System.IO;
using System.Collections.Generic;
using NW4RTools;
+using NW4RTools.Models;
+using NW4RTools.Models.Animation;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
@@ -9,6 +11,21 @@ using OpenTK.Graphics.OpenGL;
namespace TestApp {
class MainClass {
public static void Main(string[] args) {
+ ResFile shits = BrresReader.LoadFile(File.ReadAllBytes("Z:/stuff/Games/Newer/bros.brres"));
+ ColladaExporter.WriteModel(File.OpenWrite("Z:/stuff/Games/Newer/bros.dae"), shits, "bros");
+ //ResFile shits = BrresReader.LoadFile(File.ReadAllBytes("/home/me/Games/Newer/bros.brres"));
+ //ColladaExporter.WriteModel(File.OpenWrite("/home/me/Games/Newer/bros.dae"), shits, "bros");
+ return;
+
+ striphammer();
+ return;
+
+ fuckskawo();
+ return;
+
+ ewater();
+ return;
+
blah(args);
return;
@@ -23,13 +40,13 @@ namespace TestApp {
//string filename = "crapmap", resmdlname = "CrapMap";
/*string filename = "SMGoldwood";
- ResFile rf = new ResFile();
+ ResFile rf = new ResFile();
- ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "GoldwoodBase.obj"), rf, "GoldwoodBase", ObjImporter.LightmapType.Map);
- ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "BrownTree.obj"), rf, "BrownTree", ObjImporter.LightmapType.MapObj);
- ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "RedTree.obj"), rf, "RedTree", ObjImporter.LightmapType.MapObj);
+ ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "GoldwoodBase.obj"), rf, "GoldwoodBase", ObjImporter.LightmapType.Map);
+ ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "BrownTree.obj"), rf, "BrownTree", ObjImporter.LightmapType.MapObj);
+ ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "RedTree.obj"), rf, "RedTree", ObjImporter.LightmapType.MapObj);
- File.WriteAllBytes(mdlPath + "SMGoldwood.brres", BrresWriter.WriteFile(rf));*/
+ File.WriteAllBytes(mdlPath + "SMGoldwood.brres", BrresWriter.WriteFile(rf));*/
string filename = "DemoMap";
@@ -58,7 +75,7 @@ namespace TestApp {
/*var texs = rf.GetGroup<Texture>("Textures(NW4R)");
// wtf C#?!
foreach (var kv in (IEnumerable<KeyValuePair<string,Texture>>)texs) {
- kv.Value.BaseImage.Save(mdlPath + "images/" + kv.Key + ".png");
+ kv.Value.BaseImage.Save(mdlPath + "images/" + kv.Key + ".png");
}
//var objFile = File.Open(mdlPath + mdlName + ".obj", FileMode.OpenOrCreate);
@@ -69,6 +86,38 @@ namespace TestApp {
objFile.Close();*/
}
+ private static void striphammer() {
+ string mdlPath = "/home/me/Games/Newer/ISO/files/Object/hammerM/g3d/";
+
+ ResFile rf = BrresReader.LoadFile(File.ReadAllBytes(mdlPath + "bros.brres"));
+
+ var mgrp = rf.GetModelGroup();
+ var mremove = new List<string>();
+ foreach (var k in mgrp.Keys)
+ if (k != "bros_hammer")
+ mremove.Add(k);
+ foreach (var k in mremove)
+ mgrp.Remove(k);
+
+ var tgrp = rf.GetTextureGroup();
+ var texremove = new List<string>();
+ var texkeep = new Dictionary<string, bool>();
+ texkeep.Add("bros_hammer", true);
+ texkeep.Add("bros_hammer_env", true);
+ texkeep.Add("bros_hammer_handle", true);
+ texkeep.Add("lm_01e", true);
+ texkeep.Add("lm_02e", true);
+ foreach (var k in tgrp.Keys)
+ if (!texkeep.ContainsKey(k))
+ texremove.Add(k);
+ foreach (var k in texremove)
+ tgrp.Remove(k);
+
+ rf.Remove("AnmChr(NW4R)");
+
+ File.WriteAllBytes(mdlPath + "hammer.brres", BrresWriter.WriteFile(rf));
+
+ }
private static void skawo() {
string mdlPath = "/home/me/Games/Newer/ModelRev/";
@@ -113,7 +162,7 @@ namespace TestApp {
/*var texs = rf.GetGroup<Texture>("Textures(NW4R)");
// wtf C#?!
foreach (var kv in (IEnumerable<KeyValuePair<string,Texture>>)texs) {
- kv.Value.Images[0].Save(mdlPath + "images/" + kv.Key + ".png");
+ kv.Value.Images[0].Save(mdlPath + "images/" + kv.Key + ".png");
}*/
//var objFile = File.Open(mdlPath + "lift_han_wood_M.dae", FileMode.OpenOrCreate);
@@ -123,11 +172,7 @@ namespace TestApp {
private static void blah(string[] args) {
- string mdlPath;
- if (Directory.Exists("/home/me"))
- mdlPath = "/home/me/Games/Newer/WaterL/";
- else
- mdlPath = "Z:/stuff/Games/Newer/WaterL/";
+ string mdlPath = getPath();
ResFile rf = BrresReader.LoadFile(File.ReadAllBytes(mdlPath + "CS_W4.brres"));
File.WriteAllBytes(mdlPath + "CS_W4a.brres", BrresWriter.WriteFile(rf));
@@ -143,6 +188,249 @@ namespace TestApp {
File.WriteAllBytes(mdlPath + "CS_W4e.brres", BrresWriter.WriteFile(rf5));
}
}
+
+ private static void ewater() {
+ string mdlPath = getPath();
+
+ ResFile rf = BrresReader.LoadFile(File.ReadAllBytes(mdlPath + "CS_W4.brres"));
+ Model m = rf.GetModelGroup()["CS_W4"];
+
+ foreach (var kv in m.Shapes) {
+ var s = kv.Value;
+ Console.WriteLine("{0} : {1}",
+ kv.Key,
+ m.VtxPosData.GetKeyForValue(s.PosData));
+ }
+
+ var tgrp = rf.GetTextureGroup();
+ var texremove = new List<string>();
+ var texkeep = new Dictionary<string, bool>();
+ texkeep.Add("W3a_water01", true);
+ texkeep.Add("water_wave1mm", true);
+ texkeep.Add("water01", true);
+ texkeep.Add("texMask", true);
+ foreach (var k in tgrp.Keys)
+ if (!texkeep.ContainsKey(k))
+ texremove.Add(k);
+ foreach (var k in texremove)
+ tgrp.Remove(k);
+
+ rf.Remove("AnmClr(NW4R)");
+ rf.Remove("AnmChr(NW4R)");
+
+ var tsanmg = rf.GetGroup<TextureSRTAnim>("AnmTexSrt(NW4R)");
+ var tsanm = tsanmg["CS_W4"];
+ tsanmg.RemoveAt(0);
+ tsanmg.Add("KpBG", tsanm);
+
+ tsanm.Nodes.Remove("mtCloudA");
+ tsanm.Nodes.Remove("mtCloudB");
+ tsanm.Nodes.Remove("mtWater_nami");
+
+ rf.GetModelGroup().RemoveAt(0);
+ rf.GetModelGroup()["KpBG"] = m;
+
+ // Make bytecode
+ m.MatrixIDtoNodeID = new int[1];
+ m.MatrixIDtoNodeID[0] = 0;
+
+ // Now put together the NodeTree
+ var nodeTreeInsn = new ByteCode.AssignNodeToParentMtxInstruction();
+ nodeTreeInsn.NodeID = 0;
+ nodeTreeInsn.ParentMatrixID = 0;
+
+ var done = new ByteCode.DoneInstruction();
+
+ var nodeTree = new ByteCode();
+ nodeTree.Instructions.Add(nodeTreeInsn);
+ nodeTree.Instructions.Add(done);
+
+ m.Bytecode["NodeTree"] = nodeTree;
+
+ // Also, DrawOpa
+ var drawOpa = new ByteCode();
+ var shapeInsn = new ByteCode.DrawShapeInstruction();
+ shapeInsn.ShapeID = 0;
+ shapeInsn.NodeID = 0;
+ shapeInsn.MaterialID = 0;
+ drawOpa.Instructions.Add(shapeInsn);
+ drawOpa.Instructions.Add(done);
+ m.Bytecode["DrawOpa"] = drawOpa;
+
+ var drawXlu = new ByteCode();
+ drawXlu.Instructions.Add(done);
+ m.Bytecode["DrawXlu"] = drawXlu;
+
+
+ // Clean up other shit
+ var seashape = m.Shapes["polygon106"];
+ var posd = seashape.PosData;
+ var nrmd = seashape.NrmData;
+ var clrd = seashape.ClrData;
+ var tcd = seashape.TexCoordData;
+
+ var nnod = new ResDict<Node>();
+ var nshp = new ResDict<Shape>();
+ var nshd = new ResDict<Shader>();
+ var nmat = new ResDict<Material>();
+ var npos = new ResDict<VertexPosData>();
+ var nnrm = new ResDict<VertexNrmData>();
+ var nclr = new ResDict<VertexClrData>();
+ var ntc = new ResDict<VertexTexCoordData>();
+
+ Node rn = m.Nodes["CS_W4"];
+ rn.FirstChild = null;
+ nnod["RootNode"] = rn;
+ nshp["waterpoly"] = seashape;
+ nshd["mtWater"] = m.Shaders["mtWater"];
+ nmat["mtWater"] = m.Materials["mtWater"];
+
+ if (posd != null) {
+ npos[m.VtxPosData.GetKeyForValue(posd)] = posd;
+ }
+
+ if (nrmd != null) {
+ nnrm[m.VtxNrmData.GetKeyForValue(nrmd)] = nrmd;
+ }
+
+ foreach (var t in clrd) {
+ if (t != null) {
+ nclr[m.VtxClrData.GetKeyForValue(t)] = t;
+ }
+ }
+
+ foreach (var t in tcd) {
+ if (t != null) {
+ ntc[m.VtxTexCoordData.GetKeyForValue(t)] = t;
+ }
+ }
+
+ m.Nodes = nnod;
+ m.Shapes = nshp;
+ m.Shaders = nshd;
+ m.Materials = nmat;
+ m.VtxPosData = npos;
+ m.VtxNrmData = nnrm;
+ m.VtxClrData = nclr;
+ m.VtxTexCoordData = ntc;
+
+ m.PairingLookupByTexture = new ResDict<List<TexMatPairing>>();
+ m.PairingLookupByPalette = new ResDict<List<TexMatPairing>>();
+
+ // NEW
+ var dl = new DisplayListWriter();
+ dl.BeginPrimitives(PrimitiveType.Quads, 0, 4);
+ dl.WriteByte(0);
+ dl.WriteByte(0);
+ dl.WriteByte(1);
+ dl.WriteByte(1);
+ dl.WriteByte(2);
+ dl.WriteByte(2);
+ dl.WriteByte(3);
+ dl.WriteByte(3);
+ dl.End();
+ seashape.DisplayList2 = dl.GetBuffer();
+ seashape.DLBufferSize2 = (uint)seashape.DisplayList2.Length;
+ var shape = seashape;
+
+ float w = 200000, h = 100000;
+ float sw = 600, sh = 600;
+ float ow = -480, oh = 480;
+
+ posd.EntryCount = 4;
+ posd.Data = new float[][] {
+ new float[] { ow, (-h) + oh, -40 },
+ new float[] { ow, oh, -40 },
+ new float[] { ow + w, oh, -40 },
+ new float[] { ow + w, (-h) + oh, -40 }
+ };
+ posd.EntrySize = 12;
+ posd.Fraction = 0;
+ posd.ComponentType = VertexSettings.CompType.Float32;
+ posd.Save();
+
+ tcd[0].EntryCount = 4;
+ tcd[0].Fraction = 0;
+ tcd[0].Data = new float[][] {
+ new float[] { 0, 0 },
+ new float[] { sw, 0 },
+ new float[] { sw, sh },
+ new float[] { 0, sh }
+ };
+ tcd[0].Save();
+ /* posd.Data = new float[][] {
+ new float[] { 0, -40, h },
+ new float[] { 0, -40, 0 },
+ new float[] { w, -40, 0 },
+ new float[] { w, -40, h }
+ };*/
+
+ var vs = new VertexSettings();
+ vs.PositionDesc = VertexSettings.DescType.Index8;
+ vs.PositionFormat = VertexSettings.CompType.Float32;
+ vs.PositionCount = VertexSettings.CompCount.Position3;
+
+ vs.TexCoordDesc[0] = VertexSettings.DescType.Index8;
+ vs.TexCoordFormat[0] = VertexSettings.CompType.Int16;
+ vs.TexCoordCount[0] = VertexSettings.CompCount.TexCoord2;
+ vs.TexCoordFrac[0] = 0;
+
+ uint vd1, vd2, vat1, vat2, vat3;
+ vs.GetDesc(out vd1, out vd2);
+ vs.GetAttrFmt(out vat1, out vat2, out vat3);
+
+ byte vtxSpecs = 1 << 4;
+ // setting up Unk in the hopes it will work, I think this is what it's for..
+ var unkStream = new OutputStream();
+ unkStream.WriteUInt32(vd1);
+ unkStream.WriteUInt32(vd2);
+ unkStream.WriteUInt32(vtxSpecs);
+ shape.Unk = unkStream.GetBuffer();
+
+ // now make the display list
+ var dl1 = new DisplayListWriter();
+ dl1.AddPadding(10);
+ dl1.LoadCPReg(0x50, vd1);
+ dl1.LoadCPReg(0x60, vd2);
+ dl1.LoadXFReg(0x1008, new byte[] { 0x00, 0x00, 0x00, vtxSpecs });
+ dl1.Nop();
+ dl1.LoadCPReg(0x70, vat1);
+ dl1.LoadCPReg(0x80, vat2);
+ dl1.LoadCPReg(0x90, vat3);
+
+ // extend it
+ // should it be bigger if more texcoords are used? maybe...
+ dl1.PadToSize(0x80);
+ dl1.End();
+
+ shape.DLBufferSize1 = 0xE0;
+ shape.DisplayList1 = dl1.GetBuffer();
+
+
+
+ var texmask = tgrp["texMask"].Images[0];
+ var g = System.Drawing.Graphics.FromImage(texmask);
+ g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.White), 0, 0, texmask.Width, texmask.Height);
+ g.Dispose();
+
+
+ // END NEW
+
+ File.WriteAllBytes(mdlPath + "Water.brres", BrresWriter.WriteFile(rf));
+ }
+
+
+ private static string getPath() {
+ if (Directory.Exists("/home/me"))
+ return "/home/me/Games/Newer/WaterL/";
+ else
+ return "Z:/stuff/Games/Newer/WaterL/";
+ }
+
+ private static void fuckskawo() {
+ var rf = BrresReader.LoadFile(File.ReadAllBytes("/home/me/Games/Newer/Pakku/pakkun/g3d/pakkun.brres"));
+ File.WriteAllBytes("/home/me/Games/Newer/Pakku/pakkun/g3d/pakkuRewrite.brres", BrresWriter.WriteFile(rf));
+ }
}
}