public static Stream EnsurePacked(Stream s) { s.Position = 0; StructReader reader = new StructReader(s); MemoryStream ms = new MemoryStream(); StructWriter writer = new StructWriter(ms, System.Text.Encoding.ASCII, true); var header = reader.ReadStruct <FTS_IO_UNIQUE_HEADER>(); writer.WriteStruct(header); for (int i = 0; i < header.count; i++) { writer.WriteStruct(reader.ReadStruct <FTS_IO_UNIQUE_HEADER2>()); } byte[] restOfFile = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); byte[] packed = ArxIO.Pack(restOfFile); ms.Write(packed, 0, packed.Length); ms.Position = 0; s.Dispose(); return(ms); }
public void WriteTo(StructWriter writer) { writer.WriteStruct(header); for (int i = 0; i < paths.Length; i++) { writer.WriteStruct(paths[i]); } }
public static void Repack(File[] Files, Stream Output, bool CloseStreams = true) { if ((from x in Files where x.FileName == HeaderInfo select x).Count() != 1) { throw new Exception("Header Info Not Found"); } byte[] HInfo = new byte[0x7F8]; File tmp = (from x in Files where x.FileName == HeaderInfo select x).First(); tmp.Content.Read(HInfo, 0, HInfo.Length); tmp.Content.Close(); Files = (from x in Files where x.FileName != HeaderInfo select x).ToArray(); StructWriter Writer = new StructWriter(Output, Encoding: Encoding.ASCII); PACHeader Header = new PACHeader() { Signature = "PAC ", FileCount = (uint)Files.Length, Dummy = HInfo }; Writer.WriteStruct(ref Header); uint TotalHeaderLen = (uint)((Tools.GetStructLength(new File()) * Files.Length) + Tools.GetStructLength(Header)); for (uint i = 0, x = 0; i < Files.Length; i++) { tmp = new File() { FileName = Files[i].FileName, Length = (uint)Files[i].Content.Length, Offset = x + TotalHeaderLen }; Writer.WriteStruct(ref tmp); x += tmp.Length; } for (uint i = 0; i < Files.Length; i++) { Files[i].Content.CopyTo(Writer.BaseStream); if (CloseStreams) { Files[i].Content.Close(); } } Writer.Flush(); if (CloseStreams) { Writer.Close(); } }
static public void Export(File[] Files, Stream Output, bool CloseStreams = true) { StructWriter Writer = new StructWriter(Output, Encoding: Encoding.Unicode); uint DataInfoLen = 0; foreach (File f in Files) { DataInfoLen += (uint)Tools.GetStructLength(f, Encoding.Unicode); } ArcHeader Header = new ArcHeader() { Count = (uint)Files.LongLength, BaseOffset = DataInfoLen }; Writer.WriteStruct(ref Header); uint Ptr = 0; for (uint i = 0; i < Files.LongLength; i++) { Files[i].Offset = Ptr; Files[i].Length = (uint)Files[i].Content.Length; Ptr += Files[i].Length; Writer.WriteStruct(ref Files[i]); } for (uint i = 0; i < Files.LongLength; i++) { int Readed = 0; uint TotalLen = 0; byte[] Buffer = new byte[1024 * 1024]; do { Readed = Files[i].Content.Read(Buffer, 0, Buffer.Length); Output.Write(Buffer, 0, Readed); TotalLen += (uint)Readed; } while (Readed > 0); Output.Flush(); //System.Diagnostics.Debug.Assert(TotalLen == Files[i].Length); if (CloseStreams) { Files[i].Content.Close(); } } if (CloseStreams) { Writer.Close(); } }
public void WriteTo(StructWriter writer) { writer.WriteStruct(sceneInfo); for (int i = 0; i < polygons.Length; i++) { writer.WriteStruct(polygons[i]); } for (int i = 0; i < anchors.Length; i++) { writer.Write(anchors[i]); } }
public void WriteTo(StructWriter writer) { writer.WriteStruct(data); for (int i = 0; i < portals.Length; i++) { writer.Write(portals[i]); } for (int i = 0; i < polygons.Length; i++) { writer.WriteStruct(polygons[i]); } }
public static void SaveCache() { if (!CacheReady) { return; } try { TLBCache Cache = new TLBCache() { Signature = "TLBC", Original = Program.Cache.Keys.OfType <string>().ToArray(), Translations = Program.Cache.Values.OfType <string>().ToArray(), ManualString = ForceDialogues.Keys.OfType <string>().ToArray(), ManualChecked = ForceDialogues.Values.OfType <bool>().ToArray() }; if (File.Exists(CachePath)) { File.Delete(CachePath); } using (StructWriter Writer = new StructWriter(CachePath)) { Writer.WriteStruct(ref Cache); Writer.Close(); } } catch { } SaveTask(); }
public byte[] Export(string[] Content) { using (var Strm = new MemoryStream()) using (StructWriter Writer = new StructWriter(Strm, Encoding: Encoding)) { var File = new TextDataFormat(); File.Content = Content; File.Count = Content.Length; File.Offsets = new TextDataEntryOffset[File.Count]; var Offset = 16 + (16 * File.Count); for (int i = 0; i < Content.Length; i++) { File.Offsets[i] = new TextDataEntryOffset() { Offset = Offset }; Offset += Encoding.GetByteCount(Content[i] + '\x0'); } Writer.WriteStruct(ref File); Writer.Flush(); foreach (var String in Content) { Writer.WriteString(String, StringStyle.CString); } return(Strm.ToArray()); } }
public static byte[] DoImplode(byte[] bytes) { MemoryStream output = new MemoryStream(); var header = new ImplodeHeader(); header.literalSize = ImplodeLiteralSize.Fixed; header.dictSize = ImplodeDictSize.Size1024; using (var sw = new StructWriter(output, Encoding.UTF8, true)) { sw.WriteStruct(header); } BitStream bits = new BitStream(); for (int i = 0; i < bytes.Length; i++) { bits.WriteFixedLiteral(bytes[i]); } bits.WriteEOS(); while (bits.ByteReady()) { output.WriteByte(bits.GetByte()); } output.WriteByte(bits.GetBytePadded()); return(output.ToArray()); }
public static Stream EnsureUnpacked(Stream s) { var reader = new StructReader(s, System.Text.Encoding.ASCII, true); var streamStart = s.Position; var version = reader.ReadSingle(); //read just version s.Position = streamStart; //back to start for further processing if (version >= 1.44f) { var header = reader.ReadStruct <DLF_IO_HEADER>(); //read full header MemoryStream ms = new MemoryStream(); StructWriter writer = new StructWriter(ms, System.Text.Encoding.ASCII, true); writer.WriteStruct(header); //write header byte[] restOfFile = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); byte[] unpacked = ArxIO.Unpack(restOfFile); writer.Write(unpacked); //write unpacked rest s.Dispose(); //close old stream ms.Position = 0; return(ms); } return(s); //no need to unpack, return input stream }
public byte[] Export(string[] Content) { var NewHeader = new HeaderFooter(); Tools.CopyStruct(Header, ref NewHeader); using (MemoryStream OriScript = new MemoryStream(Script)) using (MemoryStream Stream = new MemoryStream()) using (StructWriter Writer = new StructWriter(Stream, Header.Endian == 'B', Encoding)) { NewHeader.StructOffset = 0; OriScript.Position = Header.StructOffset; byte[] StructData = new byte[Align(Header.StructCount * Header.StructSize)]; OriScript.Read(StructData, 0, StructData.Length); NewHeader.TypesOffset = (uint)StructData.Length; OriScript.Position = Header.TypesOffset; byte[] TypeData = new byte[Align(Header.TypesCount * Tools.GetStructLength(new TypeDescriptor()))]; OriScript.Read(TypeData, 0, TypeData.Length); NewHeader.StringOffset = (uint)(NewHeader.TypesOffset + TypeData.Length); byte[] StrData; using (MemoryStream StrStream = new MemoryStream()) using (StructWriter StrWriter = new StructWriter(StrStream, Writer.BigEndian, Encoding)) { Dictionary <string, uint> OffsetMap = new Dictionary <string, uint>(); for (int i = 0; i < Content.Length; i++) { if (OffsetMap.ContainsKey(Content[i])) { var Offset = OffsetMap[Content[i]]; BitConverter.GetBytes(Offset).CopyTo(StructData, OffsetPos[i]); } else { BitConverter.GetBytes((uint)StrWriter.Position).CopyTo(StructData, OffsetPos[i]); OffsetMap[Content[i]] = (uint)StrWriter.Position; StrWriter.Write(Content[i], StringStyle.CString); } } StrWriter.Flush(); StrData = new byte[Align(StrStream.Length)]; StrStream.ToArray().CopyTo(StrData, 0); } Writer.Write(StructData); Writer.Write(TypeData); Writer.Write(StrData); Writer.WriteStruct(ref NewHeader); Writer.Flush(); return(Stream.ToArray()); } }
public void WriteTo(Stream s) { var writer = new StructWriter(s); writer.WriteStruct(header); for (int i = 0; i < lights.Length; i++) { writer.WriteStruct(lights[i]); } writer.WriteStruct(lightingHeader); for (int i = 0; i < lightColors.Length; i++) { writer.Write(lightColors[i]); } }
public void WriteTo(StructWriter writer) { writer.WriteStruct(data); for (int i = 0; i < linkedAnchors.Length; i++) { writer.Write(linkedAnchors[i]); } }
public void WriteTo(StructWriter writer) { writer.WriteStruct(header); for (int i = 0; i < vertexList.Length; i++) { writer.WriteStruct(vertexList[i]); } for (int i = 0; i < faceList.Length; i++) { writer.WriteStruct(faceList[i]); } for (int i = 0; i < textureContainers.Length; i++) { writer.WriteStruct(textureContainers[i]); } }
public static byte[] BuildStruct <T>(ref T Struct, bool BigEndian = false, Encoding Encoding = null) { MemoryStream Stream = new MemoryStream(); StructWriter Writer = new StructWriter(Stream, BigEndian, Encoding); Writer.WriteStruct(ref Struct); byte[] Result = Stream.ToArray(); Writer.Close(); Stream?.Close(); return(Result); }
public static Stream BuildEntries(NPK3Entry[] Entries) { Stream Output = new MemoryStream(); StructWriter Writer = new StructWriter(Output, Encoding: Encoding); for (int i = 0; i < Entries.Length; i++) { var Entry = Entries[i]; Writer.WriteStruct(ref Entry); } Output.Position = 0; return(Output); }
public static void Repack(Stream Output, FileEntry[] Files, bool CloseStreams = true) { StructWriter Writer = new StructWriter(Output, false, Encoding.GetEncoding(932)); IntHeader Header = new IntHeader() { Signature = "KIF\x0", FileCount = (uint)Files.LongLength }; Writer.WriteStruct(ref Header); uint Len = 0; for (uint i = 0; i < Files.Length; i++) { FileEntry Entry = new FileEntry() { FileName = Files[i].FileName, Postion = (0x48 * (uint)Files.LongLength) + 0x8 + Len, Length = (uint)Files[i].Content.Length }; Writer.WriteStruct(ref Entry); Len += Entry.Length; } for (uint i = 0; i < Files.Length; i++) { Tools.CopyStream(Files[i].Content, Writer.BaseStream); if (CloseStreams) { Files[i].Content.Close(); } } if (CloseStreams) { Output.Close(); } }
private void SaveSettings() { Settings.Signature = Signature; Settings.Version = SettingsVersion; Settings.Blacklist = Settings.Blacklist.Distinct().ToArray(); using (Stream WriterStream = new StreamWriter(SettingsPath).BaseStream) using (StructWriter Writer = new StructWriter(WriterStream)) { Writer.WriteStruct(ref Settings); Writer.Close(); } }
public void WriteTo(Stream s) { StructWriter writer = new StructWriter(s, Encoding.ASCII, true); writer.WriteStruct(header); var secondaryHeaderPosition = s.Position; writer.WriteStruct(secondaryHeader); //write header with old values for now if (dataTill3Ddata != null) { writer.Write(dataTill3Ddata); } if (has3DDataSection) { secondaryHeader.offset_3Ddata = (int)s.Position; writer.WriteStruct(_3DDataSection); } else { secondaryHeader.offset_3Ddata = -1; } if (dataTillFileEnd != null) { writer.Write(dataTillFileEnd); } var end = s.Position; s.Position = secondaryHeaderPosition; writer.WriteStruct(secondaryHeader); //update offsets s.Position = end; //go back to end, in case user wants to do more with the stream }
public byte[] Export(StringEntry[] Strings) { ScriptHeader NewHeader = new ScriptHeader(); Tools.CopyStruct(Header, ref NewHeader); MemoryStream UnkData = new MemoryStream(); MemoryStream OffsetData = new MemoryStream(); MemoryStream StringData = new MemoryStream(); MemoryStream Reader = new MemoryStream(Script); Reader.Seek(0x10, SeekOrigin.Begin); Algo.CopyStream(Reader, UnkData, NewHeader.UnkCount * 8); Reader.Close(); StructWriter OffsetWriter = new StructWriter(OffsetData, false, Encoding); StructWriter StringWriter = new StructWriter(StringData, false, Encoding); for (uint i = 0; i < EntryCount; i++) { OffsetWriter.Write((uint)StringWriter.BaseStream.Length); StringWriter.WriteStruct(ref Strings[i]); } OffsetWriter.Seek(0, SeekOrigin.Begin); StringWriter.Seek(0, SeekOrigin.Begin); NewHeader.ScriptLength = (uint)(OffsetWriter.BaseStream.Length + StringWriter.BaseStream.Length + UnkData.Length); NewHeader.OffsetTable = (uint)UnkData.Length; NewHeader.StringTable = (uint)(UnkData.Length + OffsetData.Length); byte[] Output = new byte[0x10 + UnkData.Length + OffsetData.Length + StringData.Length]; Tools.BuildStruct(ref NewHeader, false, Encoding).CopyTo(Output, 0); UnkData.ToArray().CopyTo(Output, 0x10); OffsetData.ToArray().CopyTo(Output, 0x10 + UnkData.Length); StringData.ToArray().CopyTo(Output, 0x10 + UnkData.Length + OffsetData.Length); UnkData.Close(); StringWriter.Close(); OffsetWriter.Close(); return(Compress(Output)); }
private void BuildStringData(string[] Strings, out byte[] StringTable, out int[] Offsets) { Offsets = new int[StrCount]; MemoryStream StrData = new MemoryStream(); StructWriter Writer = new StructWriter(StrData); for (int i = 0; i < StrCount; i++) { Offsets[i] = (int)Writer.BaseStream.Length; StrEntry Entry = new StrEntry(); Entry.Content = Strings[i]; Writer.WriteStruct(ref Entry); } StringTable = StrData.ToArray(); Writer.Close(); StrData?.Close(); }
internal static void SaveTask() { try { if (File.Exists(TaskPath)) { File.Delete(TaskPath); } if (TaskInfo.LastTaskPos > 0) { using (StructWriter Writer = new StructWriter(TaskPath)) { Writer.WriteStruct(ref TaskInfo); Writer.Close(); } } } catch { } }
public byte[] Export(string[] Strings) { if (Resource.Localizations.Length != Strings.Length) { throw new Exception("You can't add/remove strings from a locres file"); } for (int i = 0; i < Resource.Localizations.Length; i++) { Resource.Localizations[i].Content = Strings[i]; } using (var Stream = new MemoryStream()) using (var Writer = new StructWriter(Stream, Encoding: Encoding.Unicode)) { Writer.WriteStruct(ref Resource); Writer.Flush(); return(Stream.ToArray()); } }
public void WriteTo(Stream s) { StructWriter writer = new StructWriter(s); writer.WriteStruct(header); for (int i = 0; i < uniqueHeaders.Length; i++) { writer.WriteStruct(uniqueHeaders[i]); } writer.WriteStruct(sceneHeader); for (int i = 0; i < textureContainers.Length; i++) { writer.WriteStruct(textureContainers[i]); } for (int z = 0; z < sceneHeader.sizez; z++) { for (int x = 0; x < sceneHeader.sizex; x++) { int index = z * sceneHeader.sizex + x; cells[index].WriteTo(writer); } } for (int i = 0; i < anchors.Length; i++) { anchors[i].WriteTo(writer); } for (int i = 0; i < portals.Length; i++) { writer.WriteStruct(portals[i]); } for (int i = 0; i < rooms.Length; i++) { rooms[i].WriteTo(writer); } for (int i = 0, index = 0; i < rooms.Length; i++) { for (int j = 0; j < rooms.Length; j++, index++) { writer.WriteStruct(roomDistances[index]); } } }
public byte[] Export(string[] Strings) { using (MemoryStream Data = new MemoryStream()) using (StructWriter Builder = new StructWriter(Data, Encoding: Encoding)) { #if !BRUTE if (Struct is BINv1Struct) { Struct.Strings = Strings; Builder.WriteStruct(ref Struct); return(Data.ToArray()); } else { return(V2Engine.Export(Strings)); } #else return(BruteEngine.Export(Strings)); #endif } }
public byte[] Export(string[] Content) { if (Content.Length != Data.Count) { throw new Exception("You Can't Modify The Count of Strings."); } using (MemoryStream Buffer = new MemoryStream()) using (StructWriter Writer = new StructWriter(Buffer, Encoding: Encoding)) { for (int i = 0; i < Content.Length; i++) { Entry Entry = Data[i]; Entry.Content = Content[i]; Writer.WriteStruct(ref Entry); } Writer.Flush(); return(Encrypt(Buffer.ToArray())); } }
public byte[] Export(string[] Strings) { MemoryStream Output = new MemoryStream(); Script.Seek(0, SeekOrigin.Begin); CopyStream(Script.BaseStream, Output, OffsetTablePos); MemoryStream StrBuffer = new MemoryStream(); StructWriter StrWorker = new StructWriter(StrBuffer, false, Encoding.Unicode); MemoryStream OffBuffer = new MemoryStream(); StructWriter OffWorker = new StructWriter(OffBuffer, false, Encoding.Unicode); OffWorker.Write((uint)Strings.LongLength); for (uint i = 0; i < Strings.LongLength; i++) { StrEntry Entry = new StrEntry() { Offset = (uint)StrBuffer.Length, Length = (uint)Strings[i].Length * 2 }; OffWorker.WriteStruct(ref Entry); StrWorker.Write(Strings[i], StringStyle.UCString); } OffWorker.Write((uint)StrBuffer.Length); StrBuffer.Position = 0; OffBuffer.Position = 0; CopyStream(OffBuffer, Output, OffBuffer.Length); CopyStream(StrBuffer, Output, StrBuffer.Length); StrWorker.Close(); OffWorker.Close(); return(Output.ToArray()); }
public byte[] Export(string[] Text) { MemoryStream Script = new MemoryStream(Data); long StrIndex = 0; long LastPos = 0; byte[] Buffer = new byte[0]; using (MemoryStream Output = new MemoryStream()) using (StructReader Reader = new StructReader(Script, Encoding: Encoding)) using (StructWriter Writer = new StructWriter(Output, Encoding: Encoding)) { foreach (long BasePos in BlockPos) { Buffer = new byte[BasePos - LastPos]; Reader.Read(Buffer, 0, Buffer.Length); Writer.Write(Buffer, 0, Buffer.Length); BINv2Struct Struct = new BINv2Struct(); Reader.ReadStruct(ref Struct); LastPos = Reader.BaseStream.Position; for (uint i = 0; i < Struct.Strings.LongLength; i++) { Struct.Strings[i] = Text[i + StrIndex]; } StrIndex += Struct.Strings.LongLength; Writer.WriteStruct(ref Struct); } if (Reader.BaseStream.Position != Reader.BaseStream.Length) { Reader.BaseStream.CopyTo(Writer.BaseStream); } Writer.Flush(); return(Output.ToArray()); } }
public void WriteTo(Stream s) { using (StructWriter writer = new StructWriter(s, System.Text.Encoding.ASCII, true)) { writer.WriteStruct(header); for (int i = 0; i < scenes.Length; i++) { writer.WriteStruct(scenes[i]); } for (int i = 0; i < inters.Length; i++) { writer.WriteStruct(inters[i]); } if (header.lighting != 0) { writer.WriteStruct(lightingHeader); for (int i = 0; i < lightColors.Length; i++) { writer.Write(lightColors[i]); } } for (int i = 0; i < lights.Length; i++) { writer.WriteStruct(lights[i]); } for (int i = 0; i < fogs.Length; i++) { writer.WriteStruct(fogs[i]); } //write back nodes data writer.Write(nodesData); for (int i = 0; i < paths.Length; i++) { paths[i].WriteTo(writer); } } }
public byte[] Export(string[] Content) { MemoryStream Output = new MemoryStream(); StructWriter Writer = new StructWriter(Output, false, Encoding.UTF8); Writer.WriteStruct(ref Header); WriteNum(Writer, Langs.Length); foreach (string Lang in Langs) { WriteString(Writer, Lang); } WriteNum(Writer, (Content.Length / 2) / Langs.Length); foreach (string str in Content) { WriteString(Writer, str); } byte[] Result = Output.ToArray(); Writer.Close(); return(Result); }