private void Decompress() { CatHeader CompHeader = new CatHeader(); StructReader Reader = new StructReader(new MemoryStream(Script), false, Encoding); Reader.ReadStruct(ref CompHeader); if (CompHeader.Singnature != "CatScene") { throw new Exception("This isn't a valid CatSystem2 Script"); } MemoryStream Decompressed = new MemoryStream(); Algo.DecompressData(Reader.BaseStream, Decompressed); if (CompHeader.DecompressedSize != Decompressed.Length) { throw new Exception("Corrupted Script"); } Reader.Close(); Script = Decompressed.ToArray(); Decompressed.Close(); this.Decompressed = true; }
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 byte[] Compress(byte[] Input) { byte[] Compressed; Algo.CompressData(Input, out Compressed); CatHeader Header = new CatHeader() { Singnature = "CatScene", CompressedSize = (uint)Compressed.LongLength, DecompressedSize = (uint)Input.LongLength }; byte[] Output = new byte[0x10 + Header.CompressedSize]; Tools.BuildStruct(ref Header, false, Encoding).CopyTo(Output, 0); Compressed.CopyTo(Output, 0x10); Input = new byte[0]; Compressed = new byte[0]; return(Output); }