Exemplo n.º 1
0
        public void WriteToFile(string file)
        {
            var output = new BinaryWriterEx(File.OpenWrite(file));

            Write(output);
            output.Close();
        }
Exemplo n.º 2
0
        /*
         * /// <summary>Exports every instrument to a SFZ text file.</summary>
         * /// <param name="fileName">Target file name.</param>
         * public void ToSFZ(string fileName)
         * {
         *  StringBuilder sb = new StringBuilder();
         *
         *  foreach (Instrument ss in longSamples)
         *      sb.Append(ss.ToSFZ(name));
         *
         *  foreach (Instrument ss in shortSamples)
         *      sb.Append(ss.ToSFZ(name));
         *
         *  File.WriteAllText(fileName, sb.ToString());
         * }
         *
         */

        /// <summary>Saves CSEQ file.</summary>
        /// <param name="fileName">Target file name.</param>
        public void Export(string fileName)
        {
            Helpers.CheckFolder(fileName);

            using (BinaryWriterEx bw = new BinaryWriterEx(File.Create(fileName)))
            {
                header.Write(bw);

                foreach (Instrument ls in longSamples)
                {
                    ls.Write(bw);
                }

                foreach (Instrument ss in shortSamples)
                {
                    ss.Write(bw);
                }


                long offsetsarraypos = bw.BaseStream.Position;

                foreach (Sequence seq in sequences)
                {
                    bw.Write((short)0);
                }

                int p = 3;
                if (USdemo)
                {
                    p = 1;
                }

                for (int i = 0; i < p; i++)
                {
                    bw.Write((byte)0);
                }

                List <long> offsets     = new List <long>();
                long        offsetstart = bw.BaseStream.Position;

                foreach (Sequence seq in sequences)
                {
                    offsets.Add(bw.BaseStream.Position - offsetstart);
                    seq.WriteBytes(bw);
                }

                bw.BaseStream.Position = offsetsarraypos;

                foreach (long off in offsets)
                {
                    bw.Write((short)off);
                }

                bw.BaseStream.Position = 0;
                bw.Write((int)bw.BaseStream.Length);

                bw.Close();
            }
        }
Exemplo n.º 3
0
 public void Write(string path, string filename)
 {
     using (BinaryWriterEx bw = new BinaryWriterEx(File.OpenWrite(Path.Combine(path, filename))))
     {
         Write(bw);
         bw.Close();
     }
 }
Exemplo n.º 4
0
        public static bool DecryptLevel(string source, string target)
        {
            if (!File.Exists(source))
            {
                return(false);
            }
            if (File.Exists(target))
            {
                File.Delete(target);
            }
            File.Copy(source, target);

            bool result = false;

            var iStream = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            var oStream = new FileStream(target, FileMode.Open, FileAccess.Write, FileShare.Read);
            var sr      = new BinaryReaderEx(iStream);
            var sw      = new BinaryWriterEx(oStream);

            try
            {
                sw.Seek(3, SeekOrigin.Begin);
                sw.Write((byte)0);

                sr.BaseStream.Seek(14, SeekOrigin.Begin);
                sw.BaseStream.Seek(14, SeekOrigin.Begin);

                uint   size;
                byte[] header = new byte[_keyLength];

                int chunk;
                for (chunk = 0; chunk < 4; ++chunk)
                {
                    size = sr.ReadUInt32();
                    sr.ReadBlockArray(out header, _keyLength);
                    sw.Seek(4, SeekOrigin.Current);
                    sw.WriteBlockArray(Decrypt(header, (int)size >> (chunk + 5) & 0x0F, (int)size >> (chunk + 1) & 0x0F));
                    sw.BaseStream.Seek(size - _keyLength + sizeof(uint), SeekOrigin.Current);
                    sr.BaseStream.Seek(size - _keyLength + sizeof(uint), SeekOrigin.Current);
                }

                result = true;
            }
            finally
            {
                sw.Close();
                sr.Close();
                oStream.Close();
                iStream.Close();
            }

            return(result);
        }
Exemplo n.º 5
0
        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();
            }
        }
Exemplo n.º 6
0
        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());
            }
        }
Exemplo n.º 7
0
        //seralize the Object
        override public void Save(string binFileName)
        {
#if FORMATTER
            FileStream fileStream = new FileStream(binFileName, FileMode.Create);
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(fileStream, this);
            fileStream.Close();
#else //FORMATTER
            BinaryWriterEx binWriterEx = new BinaryWriterEx(binFileName);
            this.Serialize(binWriterEx);
            binWriterEx.Close();
#endif //FORMATTER
        }
Exemplo n.º 8
0
        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.");
        }