private void WriteLevelTr3() { // Now begin to compile the geometry block in a MemoryStream using (var writer = new BinaryWriterEx(new FileStream(_dest, FileMode.Create, FileAccess.Write, FileShare.None))) { ReportProgress(80, "Writing geometry data to memory buffer"); // Write version writer.WriteBlockArray(new byte[] { 0x38, 0x00, 0x18, 0xFF }); /*using (var readerPalette = new BinaryReader(new FileStream("Editor\\Misc\\Palette.Tr3.bin", FileMode.Open, FileAccess.Write, FileShare.None))) * { * var palette = readerPalette.ReadBytes(1792); * // Write palette * writer.Write(palette); * }*/ // TODO: for now I write fake palette, they should be needed only for 8 bit textures for (var i = 0; i < 768; i++) { writer.Write((byte)0x00); } for (var i = 0; i < 1024; i++) { writer.Write((byte)0x00); } // Write textures int numTextureTiles = _texture32Data.GetLength(0) / (256 * 256 * 4); writer.Write(numTextureTiles); // TODO 8 bit textures (altough who uses 8 bit textures in 2018?) var fakeTextures = new byte[256 * 256 * numTextureTiles]; writer.Write(fakeTextures); // 16 bit textures byte[] texture16Data = PackTextureMap32To16Bit(_texture32Data, _level.Settings); writer.Write(texture16Data); const int filler = 0; writer.Write(filler); var numRooms = (ushort)_level.Rooms.Count(r => r != null); writer.Write(numRooms); long offset; long offset2; foreach (var r in _level.Rooms.Where(r => r != null)) { _tempRooms[r].WriteTr3(writer); } // Write floordata var numFloorData = (uint)_floorData.Count; writer.Write(numFloorData); writer.WriteBlockArray(_floorData); // Write meshes offset = writer.BaseStream.Position; const int numMeshData = 0; writer.Write(numMeshData); var totalMeshSize = 0; for (var i = 0; i < _meshes.Count; i++) { var meshSize = _meshes[i].WriteTr3(writer); totalMeshSize += (int)meshSize; } offset2 = writer.BaseStream.Position; uint meshDataSize = (uint)((offset2 - offset - 4) / 2); // Save the size of the meshes writer.BaseStream.Seek(offset, SeekOrigin.Begin); writer.Write(meshDataSize); writer.BaseStream.Seek(offset2, SeekOrigin.Begin); // Write mesh pointers writer.Write((uint)_meshPointers.Count); writer.WriteBlockArray(_meshPointers); // Write animations' data writer.Write((uint)_animations.Count); foreach (var anim in _animations) { anim.Write(writer, _level); } writer.Write((uint)_stateChanges.Count); writer.WriteBlockArray(_stateChanges); writer.Write((uint)_animDispatches.Count); writer.WriteBlockArray(_animDispatches); writer.Write((uint)_animCommands.Count); writer.WriteBlockArray(_animCommands); writer.Write((uint)_meshTrees.Count); writer.WriteBlockArray(_meshTrees); writer.Write((uint)_frames.Count); writer.WriteBlockArray(_frames); writer.Write((uint)_moveables.Count); writer.WriteBlockArray(_moveables); writer.Write((uint)_staticMeshes.Count); writer.WriteBlockArray(_staticMeshes); // Sprites writer.Write((uint)_spriteTextures.Count); writer.WriteBlockArray(_spriteTextures); writer.Write((uint)_spriteSequences.Count); writer.WriteBlockArray(_spriteSequences); // Write camera, sound sources writer.Write((uint)_cameras.Count); writer.WriteBlockArray(_cameras); writer.Write((uint)_soundSources.Count); writer.WriteBlockArray(_soundSources); // Write pathfinding data writer.Write((uint)_boxes.Length); writer.WriteBlockArray(_boxes); writer.Write((uint)_overlaps.Length); writer.WriteBlockArray(_overlaps); for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].GroundZone1_Normal); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].GroundZone2_Normal); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].GroundZone3_Normal); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].GroundZone4_Normal); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].FlyZone_Normal); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].GroundZone1_Alternate); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].GroundZone2_Alternate); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].GroundZone3_Alternate); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].GroundZone4_Alternate); } for (var i = 0; i < _boxes.Length; i++) { writer.Write(_zones[i].FlyZone_Alternate); } // Write animated textures _textureInfoManager.WriteAnimatedTextures(writer); // Write object textures _textureInfoManager.WriteTextureInfos(writer, _level); // Write items and AI objects writer.Write((uint)_items.Count); writer.WriteBlockArray(_items); // TODO Figure out light map var lightmap = new byte[8192]; writer.Write(lightmap); const ushort numDemo = 0; const ushort numCinematicFrames = 0; writer.Write(numDemo); writer.Write(numCinematicFrames); // Write sound meta data PrepareSoundsData(); WriteSoundMetadata(writer); writer.Flush(); } }
public TestLevel(string fileName, string outFileName = "") { this.fileName = fileName; FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); BinaryReaderEx reader = new BinaryReaderEx(fileStream); byte[] buffer; reader.ReadBlock(out Version); reader.ReadBlock(out NumRoomTextureTiles); reader.ReadBlock(out NumObjectTextureTiles); reader.ReadBlock(out NumBumpTextureTiles); reader.ReadBlock(out Texture32UncompressedSize); reader.ReadBlock(out Texture32CompressedSize); Texture32 = new byte[Texture32CompressedSize]; reader.ReadBlockArray(out Texture32, Texture32CompressedSize); Texture32 = ZLib.DecompressData(Texture32); ImageC img = ImageC.FromByteArray(Texture32, 256, (int)Texture32UncompressedSize / 262144 * 256); //img.Save("H:\\karnak.png"); BinaryWriterEx wrttext = new BinaryWriterEx(new FileStream("textures.raw", FileMode.Create, FileAccess.Write, FileShare.None)); wrttext.WriteBlockArray(Texture32); wrttext.Flush(); wrttext.Close(); reader.ReadBlock(out Texture16UncompressedSize); reader.ReadBlock(out Texture16CompressedSize); Texture16 = new byte[Texture16CompressedSize]; reader.ReadBlockArray(out Texture16, Texture16CompressedSize); Texture16 = ZLib.DecompressData(Texture16); reader.ReadBlock(out MiscTextureUncompressedSize); reader.ReadBlock(out MiscTextureCompressedSize); MiscTexture = new byte[MiscTextureCompressedSize]; reader.ReadBlockArray(out MiscTexture, MiscTextureCompressedSize); MiscTexture = ZLib.DecompressData(MiscTexture); reader.ReadBlock(out LevelUncompressedSize); reader.ReadBlock(out LevelCompressedSize); buffer = new byte[LevelCompressedSize]; reader.ReadBlockArray(out buffer, LevelCompressedSize); buffer = ZLib.DecompressData(buffer); var stream = new MemoryStream(); stream.Write(buffer, 0, (int)LevelUncompressedSize); stream.Seek(0, SeekOrigin.Begin); BinaryWriterEx wrt = new BinaryWriterEx(new FileStream("coastal.bin", FileMode.Create, FileAccess.Write, FileShare.None)); wrt.Write(buffer, 0, (int)LevelUncompressedSize); wrt.Flush(); wrt.Close(); BinaryWriterEx wrs = new BinaryWriterEx(new FileStream("samples." + outFileName + ".bin", FileMode.Create, FileAccess.Write, FileShare.None)); byte[] samples = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); wrs.Write(samples); wrs.Flush(); wrs.Close(); reader.Close(); reader = new BinaryReaderEx(stream); reader.ReadBlock(out Unused); reader.ReadBlock(out NumRooms); int max = 0; StreamWriter wp = new StreamWriter(new FileStream("portals" + outFileName + ".txt", FileMode.Create, FileAccess.Write, FileShare.None)); Rooms = new tr_room[NumRooms]; for (int i = 0; i < NumRooms; i++) { wp.WriteLine("====================================================================="); wp.WriteLine("ROOM #" + i); wp.WriteLine("====================================================================="); reader.ReadBlock(out Rooms[i].Info); reader.ReadBlock(out Rooms[i].NumDataWords); reader.ReadBlock(out Rooms[i].NumVertices); // Rooms[i].Vertices = new tr_room_vertex[Rooms[i].NumVertices]; reader.ReadBlockArray(out Rooms[i].Vertices, Rooms[i].NumVertices); if (Rooms[i].NumVertices > max) { max = Rooms[i].NumVertices; } reader.ReadBlock(out Rooms[i].NumRectangles); Rooms[i].Rectangles = new tr_face4[Rooms[i].NumRectangles]; for (int j = 0; j < Rooms[i].NumRectangles; j++) { // Rooms[i].Rectangles[j].Vertices = new ushort[4]; reader.ReadBlockArray(out Rooms[i].Rectangles[j].Vertices, 4); reader.ReadBlock(out Rooms[i].Rectangles[j].Texture); } reader.ReadBlock(out Rooms[i].NumTriangles); Rooms[i].Triangles = new tr_face3[Rooms[i].NumTriangles]; for (int j = 0; j < Rooms[i].NumTriangles; j++) { // Rooms[i].Triangles[j].Vertices = new ushort[3]; reader.ReadBlockArray(out Rooms[i].Triangles[j].Vertices, 3); reader.ReadBlock(out Rooms[i].Triangles[j].Texture); } reader.ReadBlock(out Rooms[i].NumSprites); reader.ReadBlock(out Rooms[i].NumPortals); //Rooms[i].Portals = new tr_room_portal[Rooms[i].NumPortals]; reader.ReadBlockArray(out Rooms[i].Portals, Rooms[i].NumPortals); for (int nn = 0; nn < Rooms[i].Portals.Length; nn++) { tr_room_portal pt = Rooms[i].Portals[nn]; wp.WriteLine(nn + ": "); wp.WriteLine("Room: " + pt.AdjoiningRoom); for (int vv = 0; vv < 4; vv++) { wp.Write("V" + vv + " = " + pt.Vertices[vv].X + ", " + pt.Vertices[vv].Y + ", " + pt.Vertices[vv].Z); wp.WriteLine(""); } wp.WriteLine(""); } reader.ReadBlock(out Rooms[i].NumZSectors); reader.ReadBlock(out Rooms[i].NumXSectors); //Rooms[i].Sectors = new tr_room_sector[Rooms[i].NumZSectors * Rooms[i].NumXSectors]; reader.ReadBlockArray(out Rooms[i].Sectors, (uint)Rooms[i].NumZSectors * Rooms[i].NumXSectors); reader.ReadBlock(out Rooms[i].AmbientIntensity1); reader.ReadBlock(out Rooms[i].AmbientIntensity2); reader.ReadBlock(out Rooms[i].NumLights); reader.ReadBlockArray(out Rooms[i].Lights, Rooms[i].NumLights); reader.ReadBlock(out Rooms[i].NumStaticMeshes); reader.ReadBlockArray(out Rooms[i].StaticMeshes, Rooms[i].NumStaticMeshes); reader.ReadBlock(out Rooms[i].AlternateRoom); reader.ReadBlock(out Rooms[i].Flags); reader.ReadBlock(out Rooms[i].Param1); reader.ReadBlock(out Rooms[i].Unknown1); reader.ReadBlock(out Rooms[i].Unknown2); } wp.Flush(); wp.Close(); //return; reader.ReadBlock(out NumFloorData); reader.ReadBlockArray(out FloorData, NumFloorData); reader.ReadBlock(out NumMeshData); /*for (int i = 0; i < NumFloorData; i++) * Console.WriteLine(FloorData[i].ToString("X2"));*/ int numBytes = 0; int totalBytes = 0; int l = 0; short temp = 0; Meshes = new tr_mesh[2048]; while (totalBytes < NumMeshData * 2) { long offset1 = reader.BaseStream.Position; reader.ReadBlock(out Meshes[l].Center); reader.ReadBlock(out Meshes[l].Radius); numBytes += 10; reader.ReadBlock(out Meshes[l].NumVertices); reader.ReadBlockArray(out Meshes[l].Vertices, Meshes[l].NumVertices); numBytes += 2 + 6 * Meshes[l].NumVertices; reader.ReadBlock(out Meshes[l].NumNormals); if (Meshes[l].NumNormals > 0) { reader.ReadBlockArray(out Meshes[l].Normals, Meshes[l].NumNormals); numBytes += 2 + 6 * Meshes[l].NumNormals; } else { reader.ReadBlockArray(out Meshes[l].Lights, -Meshes[l].NumNormals); numBytes += 2 - 2 * Meshes[l].NumNormals; } reader.ReadBlock(out Meshes[l].NumTexturedRectangles); reader.ReadBlockArray(out Meshes[l].TexturedRectangles, Meshes[l].NumTexturedRectangles); numBytes += 2 + 12 * Meshes[l].NumTexturedRectangles; reader.ReadBlock(out Meshes[l].NumTexturedTriangles); reader.ReadBlockArray(out Meshes[l].TexturedTriangles, Meshes[l].NumTexturedTriangles); numBytes += 2 + 10 * Meshes[l].NumTexturedTriangles; long offset2 = reader.BaseStream.Position; int diff = (int)(offset2 - offset1); if (diff % 4 != 0) { reader.ReadBlock(out temp); diff += 2; } Meshes[l].MeshSize = numBytes; Meshes[l].MeshPointer = totalBytes; if (l == 209) { BinaryWriterEx tmpwriter = new BinaryWriterEx(new FileStream("cleopal.msh", FileMode.Create, FileAccess.Write, FileShare.None)); tmpwriter.WriteBlock(Meshes[l].Center); tmpwriter.WriteBlock(Meshes[l].Radius); tmpwriter.WriteBlock(Meshes[l].NumVertices); tmpwriter.WriteBlockArray(Meshes[l].Vertices); tmpwriter.WriteBlock(Meshes[l].NumNormals); if (Meshes[l].NumNormals > 0) { tmpwriter.WriteBlockArray(Meshes[l].Normals); } else { tmpwriter.WriteBlockArray(Meshes[l].Lights); } tmpwriter.WriteBlock(Meshes[l].NumTexturedRectangles); tmpwriter.WriteBlockArray(Meshes[l].TexturedRectangles); tmpwriter.WriteBlock(Meshes[l].NumTexturedTriangles); tmpwriter.WriteBlockArray(Meshes[l].TexturedTriangles); tmpwriter.Flush(); tmpwriter.Close(); } totalBytes += diff;// numBytes; numBytes = 0; l++; } Array.Resize(ref Meshes, l); NumMeshes = (uint)Meshes.Length; reader.ReadBlock(out NumMeshPointers); reader.ReadBlockArray(out MeshPointers, NumMeshPointers); reader.ReadBlock(out NumAnimations); reader.ReadBlockArray(out Animations, NumAnimations); reader.ReadBlock(out NumStateChanges); reader.ReadBlockArray(out StateChanges, NumStateChanges); reader.ReadBlock(out NumAnimDispatches); reader.ReadBlockArray(out AnimDispatches, NumAnimDispatches); reader.ReadBlock(out NumAnimCommands); reader.ReadBlockArray(out AnimCommands, NumAnimCommands); reader.ReadBlock(out NumMeshTrees); reader.ReadBlockArray(out MeshTrees, NumMeshTrees); logger.Debug(reader.BaseStream.Position.ToString()); reader.ReadBlock(out NumFrames); reader.ReadBlockArray(out Frames, NumFrames); reader.ReadBlock(out NumMoveables); reader.ReadBlockArray(out Moveables, NumMoveables); reader.ReadBlock(out NumStaticMeshes); reader.ReadBlockArray(out StaticMeshes, NumStaticMeshes); reader.ReadBlockArray(out SPR, 3); reader.ReadBlock(out NumSpriteTextures); reader.ReadBlockArray(out SpriteTextures, NumSpriteTextures); reader.ReadBlock(out NumSpriteSequences); reader.ReadBlockArray(out SpriteSequences, NumSpriteSequences); reader.ReadBlock(out NumCameras); reader.ReadBlockArray(out Cameras, NumCameras); reader.ReadBlock(out NumFlyByCameras); reader.ReadBlockArray(out FlyByCameras, NumFlyByCameras * 40); reader.ReadBlock(out NumSoundSources); reader.ReadBlockArray(out SoundSources, NumSoundSources); reader.ReadBlock(out NumBoxes); reader.ReadBlockArray(out Boxes, NumBoxes); reader.ReadBlock(out NumOverlaps); reader.ReadBlockArray(out Overlaps, NumOverlaps); // reader.ReadBlockArray(out Zones, NumBoxes * 10); Zones = new short[NumBoxes * 10]; for (int n = 0; n < NumBoxes * 10; n++) { Zones[n] = reader.ReadInt16(); } reader.ReadBlock(out NumAnimatedTextures); short[] animTextures; reader.ReadBlockArray(out animTextures, NumAnimatedTextures); string fn = Path.GetFileNameWithoutExtension(fileName); if (File.Exists("pathfinding." + fn + "." + outFileName + ".txt")) { File.Delete("pathfinding." + fn + "." + outFileName + ".txt"); } StreamWriter writer = new StreamWriter(new FileStream("pathfinding." + fn + "." + outFileName + ".txt", FileMode.Create, FileAccess.Write, FileShare.None)); writer.WriteLine("BOXES"); for (int n = 0; n < Boxes.Length; n++) { writer.WriteLine("[" + n + "] " + "Xmin: " + Boxes[n].Xmin + ", " + "Xmax: " + Boxes[n].Xmax + ", " + "Zmin: " + Boxes[n].Zmin + ", " + "Zmax: " + Boxes[n].Zmax + ", " + "Floor: " + Boxes[n].TrueFloor + ", Overlap Index: " + Boxes[n].OverlapIndex); } writer.WriteLine(" "); writer.WriteLine("OVERLAPS"); for (int n = 0; n < Overlaps.Length; n++) { writer.WriteLine("[" + n + "] " + (Overlaps[n] & 0x7fff)); if ((Overlaps[n] & 0x8000) != 0) { writer.WriteLine("--- END OF LIST ---"); } } writer.WriteLine(" "); writer.WriteLine("ZONES"); for (int n = 0; n < Boxes.Length; n++) { /*writer.WriteLine("[" + n + "] " + "Ground1: " + Zones[n * 10 + 0] + ", " + "Ground2: " + Zones[n * 10 + 1] + ", " + * "Ground3: " + Zones[n * 10 + 2] + ", " + "Ground4: " + Zones[n * 10 + 3] + ", " + * "Fly: " + Zones[n * 10 + 4] + ", A_Ground1: " + Zones[n * 10 + 5] + ", " + "A_Ground2: " + Zones[n * 10 + 6] + ", " + * "A_Ground3: " + Zones[n * 10 + 7] + ", " + "A_Ground4: " + Zones[n * 10 + 8] + ", " + * "A_Fly: " + Zones[n * 10 + 9]);*/ writer.WriteLine("[" + n + "] " + "Ground1: " + Zones[n] + ", " + "Ground2: " + Zones[1 * NumBoxes + n] + ", " + "Ground3: " + Zones[2 * NumBoxes + n] + ", " + "Ground4: " + Zones[3 * NumBoxes + n] + ", " + "Fly: " + Zones[4 * NumBoxes + n] + ", A_Ground1: " + Zones[5 * NumBoxes + n] + ", " + "A_Ground2: " + Zones[6 * NumBoxes + n] + ", " + "A_Ground3: " + Zones[7 * NumBoxes + n] + ", " + "A_Ground4: " + Zones[8 * NumBoxes + n] + ", " + "A_Fly: " + Zones[9 * NumBoxes + n]); } writer.Flush(); writer.Close(); reader.ReadBlockArray(out TEX, 4); reader.ReadBlock(out NumObjectTextures); reader.ReadBlockArray(out ObjectTextures, NumObjectTextures); if (File.Exists("textures." + fn + "." + outFileName + ".txt")) { File.Delete("textures." + fn + "." + outFileName + ".txt"); } writer = new StreamWriter(new FileStream("textures." + fn + "." + outFileName + ".txt", FileMode.Create, FileAccess.Write, FileShare.None)); for (int ii = 0; ii < NumObjectTextures; ii++) { writer.WriteLine("TEXTURE #" + ii); writer.WriteLine(" TileAndFlags: " + (ObjectTextures[ii].Tile).ToString()); writer.WriteLine(" NewFlags: " + (ObjectTextures[ii].Flags).ToString()); writer.WriteLine(" Tile: " + (ObjectTextures[ii].Tile & 0xFF).ToString()); for (int jj = 0; jj < 4; jj++) { writer.WriteLine(" " + jj + " X: " + ((ushort)(ObjectTextures[ii].Vertices[jj].Xpixel << 8 + ObjectTextures[ii].Vertices[jj].Xcoordinate)).ToString() + " Y: " + ((ushort)(ObjectTextures[ii].Vertices[jj].Ypixel << 8 + ObjectTextures[ii].Vertices[jj].Ycoordinate)).ToString() + " (" + ObjectTextures[ii].Vertices[jj].Xpixel + ", " + ObjectTextures[ii].Vertices[jj].Ypixel + ")"); } /* BinaryWriterEx tmpwriter2 = new BinaryWriterEx(new FileStream("test\\cleopal_" + ii + ".text", FileMode.Create, FileAccess.Write, FileShare.None)); * tmpwriter2.WriteBlock(ObjectTextures[ii]); * tmpwriter2.Flush(); * tmpwriter2.Close();*/ } writer.Flush(); writer.Close(); reader.ReadBlock(out NumItems); reader.ReadBlockArray(out Items, NumItems); reader.ReadBlock(out NumAiItems); reader.ReadBlockArray(out AiItems, NumAiItems); StreamWriter aiw = new StreamWriter(new FileStream("AI" + outFileName + ".txt", FileMode.Create, FileAccess.Write, FileShare.None)); for (int n = 0; n < NumAiItems; n++) { aiw.WriteLine("[" + n + "]"); aiw.WriteLine(" ObjectID: " + AiItems[n].ObjectID); aiw.WriteLine(" X: " + AiItems[n].X); aiw.WriteLine(" Y: " + AiItems[n].Y); aiw.WriteLine(" Z: " + AiItems[n].Z); aiw.WriteLine(" Room: " + AiItems[n].Room); aiw.WriteLine(" Angle: " + AiItems[n].Angle); } aiw.Flush(); aiw.Close(); BinaryWriterEx bwex = new BinaryWriterEx(new FileStream("sounds" + outFileName + ".sfx", FileMode.Create, FileAccess.Write, FileShare.None)); var numDemo = reader.ReadInt16(); byte[] soundmap = reader.ReadBytes((numDemo != 0 ? numDemo * 2 : 740)); int numSoundDetails = reader.ReadInt32(); byte[] details = reader.ReadBytes(8 * numSoundDetails); int numIndices = reader.ReadInt32(); byte[] indices = reader.ReadBytes(4 * numIndices); bwex.Write(soundmap); bwex.Write(numSoundDetails); bwex.Write(details); bwex.Write(numIndices); bwex.Write(indices); bwex.Flush(); bwex.Close(); List <byte> bytes = new List <byte>(); while (reader.BaseStream.Position < reader.BaseStream.Length) { bytes.Add(reader.ReadByte()); } }
public void Write() { using (FileStream fs = new FileStream(LevSavePath, FileMode.Create, FileAccess.Write)) { using (BinaryWriterEx bw = new BinaryWriterEx(fs)) { bw.Flush(); bw.Seek((int)0, SeekOrigin.Begin); bw.Write(fileSize); header.Write(bw); bw.Seek((int)header.ptrMeshInfo + 4, SeekOrigin.Begin); meshinfo.Write(bw); bw.Seek((int)meshinfo.ptrVertexArray + 4, SeekOrigin.Begin); foreach (Vertex vert in verts) { vert.Write(bw); } bw.Seek((int)header.ptrRestartPts + 4, SeekOrigin.Begin); foreach (var restartPoint in restartPts) { restartPoint.Write(bw); } bw.Seek((int)meshinfo.ptrVisDataArray + 4, SeekOrigin.Begin); foreach (var visdat in visdata) { visdat.Write(bw); } bw.Seek((int)meshinfo.ptrQuadBlockArray + 4, SeekOrigin.Begin); foreach (var quad in quads) { quad.Write(bw); } /* * if (header.ptrSkybox != 0) { * bw.Seek((int) header.ptrSkybox + 4, SeekOrigin.Begin); * skybox.Write(bw); * }*/ if (header.ptrVcolAnim != 0) { bw.Seek((int)header.ptrVcolAnim + 4, SeekOrigin.Begin); foreach (var vertanim in vertanims) { vertanim.Write(bw); } } if (header.ptrAiNav != 0) { bw.Seek((int)header.ptrAiNav + 4, SeekOrigin.Begin); nav.Write(bw); } if (header.ptrTrialData != 0) { bw.Seek((int)header.ptrTrialData + 4, SeekOrigin.Begin); trial.Write(bw); } if (header.cntSpawnPts != 0) { bw.Seek((int)header.ptrSpawnPts + 4, SeekOrigin.Begin); unkadv.Write(bw); } bw.Seek((int)posu1_ptr + 4, SeekOrigin.Begin); for (int i = 0; i < posu1_cnt; i++) { posu1[i].Write(bw); } //write pickup models //starts out right, but anims ruin it bw.Seek((int)(header.ptrModelsPtr + 4), SeekOrigin.Begin); for (int i = 0; i < header.numModels; i++) { bw.Seek((int)pickUpModelDataLocation[i * 2 + 0] + 4, SeekOrigin.Begin); bw.Write(pickUpModelDataLocation[i * 2 + 1]); bw.Seek((int)pickUpModelDataLocation[i * 2 + 1] + 4, SeekOrigin.Begin); //dynamics[i].Write(bw); } bw.Close(); } fs.Close(); } }
private void actionPack_Click(object sender, EventArgs e) { if (!File.Exists(pathFile.Text)) { MessageBox.Show($"File doesn't exist!\r\n{pathFile.Text}"); return; } using (Scene scn = Scene.FromFile(pathFile.Text)) { Tim ctr = scn.ctrvram; //dumping vram before the change if (optionDebugVram.Checked) { //only dump if file doesn't exist (to compare to earliest version of vram) if (!File.Exists(Path.Combine(pathFileParent, "test_old.bmp"))) { ctr.SaveBMP(Path.Combine(pathFileParent, "test_old.bmp"), BMPHeader.GrayScalePalette(16)); } } Dictionary <string, TextureLayout> list = scn.GetTexturesList(); foreach (string s in Directory.GetFiles(pathFolder.Text, "*.png")) { string tag = Path.GetFileNameWithoutExtension(s); Console.Write($"replacing {tag}... "); if (!list.ContainsKey(tag)) { Helpers.Panic(ctr, "unknown texture entry"); continue; } Tim newtex = ctr.GetTimTexture(list[tag]); newtex.LoadDataFromBitmap(s); ctr.DrawTim(newtex); Console.WriteLine("done."); } if (optionDebugVram.Checked) { ctr.SaveBMP(Path.Combine(pathFileParent, "test_new.bmp"), BMPHeader.GrayScalePalette(16)); } List <Tim> tims = new List <Tim>(); foreach (var r in CtrVrm.frames) { tims.Add(ctr.GetTrueColorTexture(r)); } string tempFile = Path.Combine(pathFileParent, "temp.tim"); string vramFile = Path.ChangeExtension(pathFile.Text, ".vrm"); Helpers.BackupFile(vramFile); File.Delete(vramFile); using (BinaryWriterEx bw = new BinaryWriterEx(File.Create(vramFile))) { bw.Write((int)0x20); foreach (Tim tim in tims) { tim.Write(tempFile); byte[] x = File.ReadAllBytes(tempFile); bw.Write(x.Length); bw.Write(x); } bw.Write((int)0); bw.Flush(); bw.Close(); } File.Delete(tempFile); //ctr.GetTrueColorTexture(512, 0, 384, 256).Write(Path.Combine(Path.GetDirectoryName(pathFolder.Text), "x01.tim")); //ctr.GetTrueColorTexture(512, 256, 512, 256).Write(Path.Combine(Path.GetDirectoryName(pathFolder.Text), "x02.tim")); } GC.Collect(); MessageBox.Show("Done."); }