diff --git a/NetMFAPatcher/MMFParser/Data/ChunkList.cs b/NetMFAPatcher/MMFParser/Data/ChunkList.cs index 2a186a7..fd52ec4 100644 --- a/NetMFAPatcher/MMFParser/Data/ChunkList.cs +++ b/NetMFAPatcher/MMFParser/Data/ChunkList.cs @@ -23,6 +23,7 @@ namespace NetMFAPatcher.MMFParser.Data while (true) { Chunk chunk = new Chunk(chunks.Count, this); + chunk.verbose = verbose; chunk.Read(exeReader); chunk.loader = LoadChunk(chunk); diff --git a/NetMFAPatcher/MMFParser/Data/MFA.cs b/NetMFAPatcher/MMFParser/Data/MFA.cs index ddf519a..c51a3f4 100644 --- a/NetMFAPatcher/MMFParser/Data/MFA.cs +++ b/NetMFAPatcher/MMFParser/Data/MFA.cs @@ -17,13 +17,25 @@ namespace NetMFAPatcher.mfa { class MFA : DataLoader { + public static readonly string FontBankID = "ATNF"; + public static readonly string ImageBankID = "AGMI"; + public static readonly string MusicBankID = "ASUM"; + public static readonly string SoundBankID = "APMS"; + public int mfaBuild; public int product; public int buildVersion; + public int langID; public string name; public string description; public string path; + + public FontBank fonts; + public SoundBank sounds; + public MusicBank music; + + public string author; public string copyright; public string company; @@ -44,6 +56,35 @@ namespace NetMFAPatcher.mfa //Logger.Log($"MFA Build:{mfaBuild}"); //Logger.Log($"MFA Product:{buildVersion}"); + } + public void Write(ByteWriter writer) + { + + writer.WriteAscii("MFU2"); + writer.WriteInt32(mfaBuild); + writer.WriteInt32(product); + writer.WriteInt32(buildVersion); + writer.WriteInt32(langID); + writer.AutoWriteUnicode(name); + writer.AutoWriteUnicode(description); + writer.AutoWriteUnicode(path); + + writer.WriteUInt32((uint)stamp.Length); + writer.WriteBytes(stamp); + writer.WriteAscii(FontBankID); + fonts.Write(writer); + writer.WriteAscii(SoundBankID); + sounds.Write(writer); + writer.WriteAscii(MusicBankID); + //music.Write();//cum cum cum cum cum cum cum cum + writer.WriteInt32(0);//someone is using musics lol? + + + + + + + } public override void Read() @@ -53,10 +94,11 @@ namespace NetMFAPatcher.mfa product = reader.ReadInt32(); buildVersion = reader.ReadInt32(); Console.WriteLine($"mfaBuild: {mfaBuild}, product: {product}, buildVersion: {buildVersion}"); - var reserved = reader.ReadInt32(); + langID = reader.ReadInt32(); name = Helper.AutoReadUnicode(reader); + description = Helper.AutoReadUnicode(reader); @@ -66,20 +108,21 @@ namespace NetMFAPatcher.mfa Console.WriteLine($"\nMFAName: {name}\nDescription: {description}\nPath: {path}"); stamp = reader.ReadBytes(reader.ReadInt32()); - + if (reader.ReadAscii(4) != "ATNF") { throw new Exception("Invalid Font Bank"); } - var fonts = new FontBank(reader); + fonts = new FontBank(reader); fonts.Read(); + Console.WriteLine("FONTS: " + fonts.numberOfItems); if (reader.ReadAscii(4) != "APMS") { throw new Exception("Invalid Sound Bank"); } - var sounds = new SoundBank(reader); + sounds = new SoundBank(reader); sounds.isCompressed = false; sounds.Read(); @@ -88,9 +131,9 @@ namespace NetMFAPatcher.mfa { throw new Exception("Invalid Music Bank"); } - var music = new MusicBank(reader); + music = new MusicBank(reader); music.Read(); - + if (reader.ReadAscii(4) != "AGMI") { throw new Exception("Invalid Icon Bank"); @@ -142,6 +185,7 @@ namespace NetMFAPatcher.mfa reader.ReadInt32(); var commandLine = Helper.AutoReadUnicode(reader); var aboutbox = Helper.AutoReadUnicode(reader); + Console.WriteLine(aboutbox); reader.ReadInt32(); var binCount = reader.ReadInt32();//wtf i cant put it in loop fuck shit @@ -219,7 +263,9 @@ namespace NetMFAPatcher.mfa } reader.Seek(nextOffset); - + var chunks = new ChunkList(reader); + chunks.Read(); + return; diff --git a/NetMFAPatcher/Program.cs b/NetMFAPatcher/Program.cs index 9fc9f9f..561de33 100644 --- a/NetMFAPatcher/Program.cs +++ b/NetMFAPatcher/Program.cs @@ -117,6 +117,9 @@ namespace NetMFAPatcher ByteIO mfaReader = new ByteIO(path, FileMode.Open); var mfa = new MFA(mfaReader); mfa.Read(); + Console.WriteLine("Writing"); + var MFAWriter = new ByteWriter("out.mfa",FileMode.Create); + mfa.Write(MFAWriter); Console.ReadKey(); } else diff --git a/NetMFAPatcher/Utils/ByteWriter.cs b/NetMFAPatcher/Utils/ByteWriter.cs index 4dd5700..8c4b631 100644 --- a/NetMFAPatcher/Utils/ByteWriter.cs +++ b/NetMFAPatcher/Utils/ByteWriter.cs @@ -57,15 +57,48 @@ namespace NetMFAPatcher.Utils { return BaseStream.Position < BaseStream.Length; } + public void WriteInt8(byte value) => Write(value); + public void WriteInt16(short value)=>Write(value); + public void WriteInt32(int value) => Write(value); + public void WriteInt64(long value) => Write(value); - + public void WriteUInt16(ushort value) => Write(value); + public void WriteUInt32(uint value) => Write(value); + public void WriteUInt64(ulong value) => Write(value); + + public void WriteBytes(byte[] value) => Write(value); + public void WriteAscii(string value) + { + var bytes = Encoding.ASCII.GetBytes(value); + for (int i = 0; i < bytes.Length; i++) + { + WriteInt8(bytes[i]); + } + } + public void WriteUnicode(string value) + { + var bytes = Encoding.Unicode.GetBytes(value); + for (int i = 0; i < bytes.Length; i++) + { + WriteInt8(bytes[i]); + + } + } + + + + + + + + + + - - } } \ No newline at end of file diff --git a/NetMFAPatcher/Utils/Helper.cs b/NetMFAPatcher/Utils/Helper.cs index 61f028e..e068bf3 100644 --- a/NetMFAPatcher/Utils/Helper.cs +++ b/NetMFAPatcher/Utils/Helper.cs @@ -62,6 +62,12 @@ namespace NetMFAPatcher reader.Skip(2); return reader.ReadWideString(len); } + public static void AutoWriteUnicode(this ByteWriter writer,string value) + { + writer.WriteInt16((short)value.Length); + writer.Skip(2); + writer.WriteUnicode(value); + } public static DataLoader LoadParameter(int code, ByteIO reader) { DataLoader item = null; diff --git a/NetMFAPatcher/mmfparser/chunkloaders/banks/FontBank.cs b/NetMFAPatcher/mmfparser/chunkloaders/banks/FontBank.cs index 055db7e..a41811f 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/banks/FontBank.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/banks/FontBank.cs @@ -21,10 +21,11 @@ namespace NetMFAPatcher.chunkloaders public override void Read() { numberOfItems = reader.ReadInt32(); - - - - + } + public void Write(ByteWriter writer) + { + writer.WriteInt32(numberOfItems); + //i am testing with no fonts suck pinus haha } public FontBank(ByteIO reader) : base(reader) diff --git a/NetMFAPatcher/mmfparser/chunkloaders/banks/SoundBank.cs b/NetMFAPatcher/mmfparser/chunkloaders/banks/SoundBank.cs index 8cb1192..ac9d1da 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/banks/SoundBank.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/banks/SoundBank.cs @@ -36,6 +36,14 @@ namespace NetMFAPatcher.chunkloaders items.Add(item); } } + public void Write(ByteWriter writer) + { + writer.WriteInt32(num_of_items); + foreach (var item in items) + { + item.Write(writer); + } + } public SoundBank(ByteIO reader) : base(reader) { @@ -74,6 +82,7 @@ namespace NetMFAPatcher.chunkloaders public bool compressed; public int checksum; public int references; + public int flags; public bool isCompressed = true; public override void Read() @@ -84,7 +93,7 @@ namespace NetMFAPatcher.chunkloaders checksum = reader.ReadInt32(); references = reader.ReadInt32(); var decompressed_size = reader.ReadInt32(); - reader.ReadUInt32(); //flags + flags = (int)reader.ReadUInt32(); //flags var reserved = reader.ReadInt32(); var name_lenght = reader.ReadInt32(); ByteIO SoundData; @@ -114,6 +123,25 @@ namespace NetMFAPatcher.chunkloaders string path = $"{Program.DumpPath}\\SoundBank\\{name}.wav"; File.WriteAllBytes(path, data); + } + public void Write(ByteWriter writer) + { + writer.WriteUInt32((uint)handle); + writer.WriteInt32(checksum); + writer.WriteInt32(references); + writer.WriteInt32(data.Length+name.Length+1); + writer.WriteInt32(flags); + writer.WriteInt32(0); + writer.WriteInt32(name.Length+1); + if (isCompressed) writer.WriteUnicode(name); + else writer.WriteAscii(name); + writer.WriteBytes(data); + + + + + + } public SoundItem(ByteIO reader) : base(reader)