public void AddTile(VTMapTile tile) { if (Tiles.Count <= tile.Row) { for (int x = Tiles.Count; x <= tile.Row; x++) { Tiles.Add(new List<VTMapTile>()); } } if (Tiles[tile.Row].Count <= tile.Column) { for (int x = Tiles[tile.Row].Count; x <= tile.Column; x++) { Tiles[tile.Row].Add(null); } } if (Tiles[tile.Row][tile.Column] == null) { Tiles[tile.Row].Insert(tile.Column, tile); } else { //Logger.LogToFile("Tile already exists at [{0}, {1}] in Tiles Page #{2} \"{3}\" ( other tile: {4})", tile.Row, tile.Column, PageNumber, tile.TileNameString, Tiles[tile.Row][tile.Column].TileNameString); } if (tile.Row > MaxTilesY) MaxTilesY = tile.Row; if (tile.Column > MaxTilesX) MaxTilesX = tile.Column; }
public VirtualTextureDef LoadVT(string inputFolder) { var zadFiles = Directory.EnumerateFiles(inputFolder, "*.zad"); //bool firstZad = true; ZAD EnvironmentsZAD = ZAD.Load(Path.Combine(inputFolder, "Environments.zad")); TDX DiffuseTDX = null; TDX SpecularTDX = null; TDX NormalTDX = null; //Console.WriteLine("Loading dictionary TDX files..."); foreach (ZADEntry entry in EnvironmentsZAD.Contents) { //Console.WriteLine(entry.Name); switch (Path.GetFileName(entry.Name).ToLower()) { case "diffuse_d.tdx": DiffuseTDX = LoadTDXFromZADEntry(entry, EnvironmentsZAD); break; case "specular_s.tdx": SpecularTDX = LoadTDXFromZADEntry(entry, EnvironmentsZAD); break; case "normal_n.tdx": NormalTDX = LoadTDXFromZADEntry(entry, EnvironmentsZAD); break; } } VirtualTextureDef vtDef = new VirtualTextureDef { DiffuseMap = (VTMap)DiffuseTDX.ExtraData, SpecularMap = (VTMap)SpecularTDX.ExtraData, NormalMap = (VTMap)NormalTDX.ExtraData, DiffusePages = new List <VTPage>() }; for (int i = 0; i < vtDef.DiffuseMap.PageCount + 1; i++) { int pageWidth = vtDef.DiffuseMap.GetWidth(i); int pageHeight = vtDef.DiffuseMap.GetHeight(i); vtDef.DiffusePages.Add(new VTPage(pageWidth, pageHeight, i, vtDef.DiffuseMap)); //Console.WriteLine("\tDiffuse Page {0} created", i); } vtDef.SpecularPages = new List <VTPage>(); for (int i = 0; i < vtDef.SpecularMap.PageCount + 1; i++) { int pageWidth = vtDef.SpecularMap.GetWidth(i); int pageHeight = vtDef.SpecularMap.GetHeight(i); vtDef.SpecularPages.Add(new VTPage(pageWidth, pageHeight, i, vtDef.SpecularMap)); //Console.WriteLine("\tSpecular Page {0} created", i); } vtDef.NormalPages = new List <VTPage>(); for (int i = 0; i < vtDef.NormalMap.PageCount + 1; i++) { int pageWidth = vtDef.NormalMap.GetWidth(i); int pageHeight = vtDef.NormalMap.GetHeight(i); vtDef.NormalPages.Add(new VTPage(pageWidth, pageHeight, i, vtDef.NormalMap)); //Console.WriteLine("\tNormal Page {0} created", i); } foreach (string zadFile in zadFiles) { if (Path.GetFileNameWithoutExtension(zadFile).ToLower() == "environments") { continue; } //Console.Write("Loading ZAD: " + zadFile); /*if(Path.GetFileNameWithoutExtension(zadFile).ToLower() == "pages_5") * { * Console.WriteLine("This is page 5"); * }*/ ZAD currentZAD = ZAD.Load(zadFile); foreach (ZADEntry entry in currentZAD.Contents) { if (entry.CompressionMethod != CompressionMethods.LZ4) { //Console.WriteLine("This entry isnt compressed using lz4! wtf? {0}", entry.Name); } string tdxName = Path.GetFileNameWithoutExtension(entry.Name).ToLower(); string tileName = tdxName.Split(new Char[] { '_' })[0].ToUpper(); /*if (tileName == "E4C7607E") * { * Console.WriteLine("This is E4C7607E"); * }*/ if (vtDef.DiffuseMap.TilesByName.ContainsKey(tileName)) { VTMapTileTDX tileTDX = vtDef.DiffuseMap.TilesByName[tileName]; //tileTDX.Texture = LoadTDXFromZADEntry(entry, currentZAD); tileTDX.ZADFile = zadFile; tileTDX.ZADEntryLocation = entry.Name; for (int i = 0; i < tileTDX.Coords.Count; i++) { VTMapTile tile = tileTDX.Coords[i]; tile.TDXTile = tileTDX; //if (tile.Row < diffusePages[tile.Page].maxTilesToStitch && tile.Column < diffusePages[tile.Page].maxTilesToStitch) { vtDef.DiffusePages[tile.Page].Tiles[tile.Row][tile.Column] = tileTDX;// LoadTDXFromZADEntry(entry, currentZAD); } } } if (vtDef.SpecularMap.TilesByName.ContainsKey(tileName)) { VTMapTileTDX tileTDX = vtDef.SpecularMap.TilesByName[tileName]; //tileTDX.Texture = LoadTDXFromZADEntry(entry, currentZAD); tileTDX.ZADFile = zadFile; tileTDX.ZADEntryLocation = entry.Name; for (int i = 0; i < tileTDX.Coords.Count; i++) { VTMapTile tile = tileTDX.Coords[i]; tile.TDXTile = tileTDX; if (tile.Row < vtDef.SpecularPages[tile.Page].maxTilesToStitch && tile.Column < vtDef.SpecularPages[tile.Page].maxTilesToStitch) { vtDef.SpecularPages[tile.Page].Tiles[tile.Row][tile.Column] = tileTDX;// LoadTDXFromZADEntry(entry, currentZAD); } } } if (vtDef.NormalMap.TilesByName.ContainsKey(tileName)) { //currentZAD.Extract(entry, Path.Combine(outputFolder, "Normal", "TDX")+"/"); VTMapTileTDX tileTDX = vtDef.NormalMap.TilesByName[tileName]; //tileTDX.Texture = LoadTDXFromZADEntry(entry, currentZAD); tileTDX.ZADFile = zadFile; tileTDX.ZADEntryLocation = entry.Name; for (int i = 0; i < tileTDX.Coords.Count; i++) { VTMapTile tile = tileTDX.Coords[i]; tile.TDXTile = tileTDX; if (tile.Row < vtDef.NormalPages[tile.Page].maxTilesToStitch && tile.Column < vtDef.NormalPages[tile.Page].maxTilesToStitch) { vtDef.NormalPages[tile.Page].Tiles[tile.Row][tile.Column] = tileTDX;// LoadTDXFromZADEntry(entry, currentZAD); } } } } continue; foreach (ZADEntry entry in currentZAD.Contents) { if (entry.CompressionMethod != CompressionMethods.LZ4) { //Console.WriteLine("This entry isnt compressed using lz4! wtf? {0}", entry.Name); } string tdxName = Path.GetFileNameWithoutExtension(entry.Name).ToLower(); string tileName = tdxName.Split(new Char[] { '_' })[0].ToUpper(); /*if (tileName == "E4C7607E") * { * Console.WriteLine("This is E4C7607E"); * }*/ if (vtDef.DiffuseMap.TilesByName.ContainsKey(tileName)) { VTMapTileTDX tileTDX = vtDef.DiffuseMap.TilesByName[tileName]; //tileTDX.Texture = LoadTDXFromZADEntry(entry, currentZAD); tileTDX.ZADFile = zadFile; tileTDX.ZADEntryLocation = entry.Name; for (int i = 0; i < tileTDX.Coords.Count; i++) { VTMapTile tile = tileTDX.Coords[i]; tile.TDXTile = tileTDX; //if (tile.Row < diffusePages[tile.Page].maxTilesToStitch && tile.Column < diffusePages[tile.Page].maxTilesToStitch) { vtDef.DiffusePages[tile.Page].Tiles[tile.Row][tile.Column] = tileTDX; // LoadTDXFromZADEntry(entry, currentZAD); } } } if (vtDef.SpecularMap.TilesByName.ContainsKey(tileName)) { VTMapTileTDX tileTDX = vtDef.SpecularMap.TilesByName[tileName]; //tileTDX.Texture = LoadTDXFromZADEntry(entry, currentZAD); tileTDX.ZADFile = zadFile; tileTDX.ZADEntryLocation = entry.Name; for (int i = 0; i < tileTDX.Coords.Count; i++) { VTMapTile tile = tileTDX.Coords[i]; tile.TDXTile = tileTDX; if (tile.Row < vtDef.SpecularPages[tile.Page].maxTilesToStitch && tile.Column < vtDef.SpecularPages[tile.Page].maxTilesToStitch) { vtDef.SpecularPages[tile.Page].Tiles[tile.Row][tile.Column] = tileTDX; // LoadTDXFromZADEntry(entry, currentZAD); } } } if (vtDef.NormalMap.TilesByName.ContainsKey(tileName)) { //currentZAD.Extract(entry, Path.Combine(outputFolder, "Normal", "TDX")+"/"); VTMapTileTDX tileTDX = vtDef.NormalMap.TilesByName[tileName]; //tileTDX.Texture = LoadTDXFromZADEntry(entry, currentZAD); tileTDX.ZADFile = zadFile; tileTDX.ZADEntryLocation = entry.Name; for (int i = 0; i < tileTDX.Coords.Count; i++) { VTMapTile tile = tileTDX.Coords[i]; tile.TDXTile = tileTDX; if (tile.Row < vtDef.NormalPages[tile.Page].maxTilesToStitch && tile.Column < vtDef.NormalPages[tile.Page].maxTilesToStitch) { vtDef.NormalPages[tile.Page].Tiles[tile.Row][tile.Column] = tileTDX; // LoadTDXFromZADEntry(entry, currentZAD); } } } } } return(vtDef); }
public VTMap(byte[] buff) { using (MemoryStream ms = new MemoryStream(buff)) using (BinaryReader br = new BinaryReader(ms)) { type = (VTMapType)br.ReadInt16(); if (!IsDeadBeef(br)) { Logger.LogToFile(Logger.LogLevel.Error, "OH F**K IT'S NOT DEADBEEF #1!\nPosition: {0:x2}", br.BaseStream.Position); return; } width = br.ReadInt32(); height = br.ReadInt32(); pageCount = br.ReadInt32(); tileSize = br.ReadInt32(); tilePadding = br.ReadInt32(); if (!IsDeadBeef(br)) { Logger.LogToFile(Logger.LogLevel.Error, "OH F**K IT'S NOT DEADBEEF #2!\nPosition: {0:x2}", br.BaseStream.Position); return; } textureCount = br.ReadInt32(); for (int i = 0; i < textureCount; i++) { VTMapEntry entry = new VTMapEntry(); entry.Row = br.ReadInt32(); entry.Column = br.ReadInt32(); entry.Width = br.ReadInt32(); entry.Height = br.ReadInt32(); entry.FileName = br.ReadNullTerminatedString(); br.ReadByte(); entries.Add(entry); } if (!IsDeadBeef(br)) { Logger.LogToFile(Logger.LogLevel.Error, "OH F**K IT'S NOT DEADBEEF #3!\nPosition: {0:x2}", br.BaseStream.Position); return; } numberOfTiles = br.ReadInt32(); int j = 0; for (int i = 0; i < numberOfTiles; i++) { VTMapTile tile = new VTMapTile(); tile.Column = br.ReadInt32(); tile.Row = br.ReadInt32(); tile.Page = br.ReadInt32(); tile.Hash = br.ReadUInt32(); tile.TileName = string.Format("{0:x8}", tile.Hash); tile.ZadTileName = string.Format("{0}/{1}_{2}.tdx", tile.TileName.Substring(0, 2), tile.TileName, type.ToString().Substring(0, 1)); //Logger.LogToFile("\tTile {0}\n\t\t FileName: {1}\n\t\tUnknown1: {2}\n\t\tUnknown2: {3}\n\t\tUnknown3: {4}", j, BitConverter.ToString( tile.TileName), tile.Unknown1, tile.Unknown2, tile.Unknown3); j++; if (!TilesByName.ContainsKey(tile.TileName)) { VTMapTileTDX tileTDX = new VTMapTileTDX(); tileTDX.TileName = tile.TileName; tileTDX.Coords.Add(tile); TilesByName.Add(tile.TileName, tileTDX); } else { //Logger.LogToFile("Tile #{0} \"{1}\" already in TilesByName", i, tile.TileNameString); TilesByName[tile.TileName].Coords.Add(tile); } if (tile.Page >= TilesPages.Count) { for (int x = TilesPages.Count; x <= tile.Page; x++) { TilesPages.Add(new VTMapPage() { PageNumber = tile.Page }); } } TilesPages[tile.Page].AddTile(tile); } if (!IsDeadBeef(br)) { Logger.LogToFile(Logger.LogLevel.Error, "OH F**K IT'S NOT DEADBEEF #4!\nPosition: {0}", br.BaseStream.Position); return; } int anotherTextureCount = br.ReadInt32(); List<int> unknownValues = new List<int>(); for (int i = 0; i < anotherTextureCount; i++) { string fileName = br.ReadNullTerminatedString(); if (entries[i].FileName == fileName) { entries[i].TimeStamp = br.ReadInt32(); entries[i].Unknown2 = br.ReadInt32(); if (!unknownValues.Contains(entries[i].TimeStamp)) unknownValues.Add(entries[i].TimeStamp); } else { for (int k = 0; k < entries.Count; k++) { if (entries[k].FileName == fileName) { entries[k].TimeStamp = br.ReadInt32(); entries[k].Unknown2 = br.ReadInt32(); if (!unknownValues.Contains(entries[k].TimeStamp)) unknownValues.Add(entries[k].TimeStamp); break; } } } } } }