master
1987kostya 5 years ago
parent 1db74b1962
commit 0fa315477d

@ -23,6 +23,7 @@ namespace NetMFAPatcher.MMFParser.Data
while (true) while (true)
{ {
Chunk chunk = new Chunk(chunks.Count, this); Chunk chunk = new Chunk(chunks.Count, this);
chunk.verbose = verbose;
chunk.Read(exeReader); chunk.Read(exeReader);
chunk.loader = LoadChunk(chunk); chunk.loader = LoadChunk(chunk);

@ -17,13 +17,25 @@ namespace NetMFAPatcher.mfa
{ {
class MFA : DataLoader 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 mfaBuild;
public int product; public int product;
public int buildVersion; public int buildVersion;
public int langID;
public string name; public string name;
public string description; public string description;
public string path; public string path;
public FontBank fonts;
public SoundBank sounds;
public MusicBank music;
public string author; public string author;
public string copyright; public string copyright;
public string company; public string company;
@ -44,6 +56,35 @@ namespace NetMFAPatcher.mfa
//Logger.Log($"MFA Build:{mfaBuild}"); //Logger.Log($"MFA Build:{mfaBuild}");
//Logger.Log($"MFA Product:{buildVersion}"); //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() public override void Read()
@ -53,10 +94,11 @@ namespace NetMFAPatcher.mfa
product = reader.ReadInt32(); product = reader.ReadInt32();
buildVersion = reader.ReadInt32(); buildVersion = reader.ReadInt32();
Console.WriteLine($"mfaBuild: {mfaBuild}, product: {product}, buildVersion: {buildVersion}"); Console.WriteLine($"mfaBuild: {mfaBuild}, product: {product}, buildVersion: {buildVersion}");
var reserved = reader.ReadInt32(); langID = reader.ReadInt32();
name = Helper.AutoReadUnicode(reader); name = Helper.AutoReadUnicode(reader);
description = Helper.AutoReadUnicode(reader); description = Helper.AutoReadUnicode(reader);
@ -66,20 +108,21 @@ namespace NetMFAPatcher.mfa
Console.WriteLine($"\nMFAName: {name}\nDescription: {description}\nPath: {path}"); Console.WriteLine($"\nMFAName: {name}\nDescription: {description}\nPath: {path}");
stamp = reader.ReadBytes(reader.ReadInt32()); stamp = reader.ReadBytes(reader.ReadInt32());
if (reader.ReadAscii(4) != "ATNF") if (reader.ReadAscii(4) != "ATNF")
{ {
throw new Exception("Invalid Font Bank"); throw new Exception("Invalid Font Bank");
} }
var fonts = new FontBank(reader); fonts = new FontBank(reader);
fonts.Read(); fonts.Read();
Console.WriteLine("FONTS: " + fonts.numberOfItems);
if (reader.ReadAscii(4) != "APMS") if (reader.ReadAscii(4) != "APMS")
{ {
throw new Exception("Invalid Sound Bank"); throw new Exception("Invalid Sound Bank");
} }
var sounds = new SoundBank(reader); sounds = new SoundBank(reader);
sounds.isCompressed = false; sounds.isCompressed = false;
sounds.Read(); sounds.Read();
@ -88,9 +131,9 @@ namespace NetMFAPatcher.mfa
{ {
throw new Exception("Invalid Music Bank"); throw new Exception("Invalid Music Bank");
} }
var music = new MusicBank(reader); music = new MusicBank(reader);
music.Read(); music.Read();
if (reader.ReadAscii(4) != "AGMI") if (reader.ReadAscii(4) != "AGMI")
{ {
throw new Exception("Invalid Icon Bank"); throw new Exception("Invalid Icon Bank");
@ -142,6 +185,7 @@ namespace NetMFAPatcher.mfa
reader.ReadInt32(); reader.ReadInt32();
var commandLine = Helper.AutoReadUnicode(reader); var commandLine = Helper.AutoReadUnicode(reader);
var aboutbox = Helper.AutoReadUnicode(reader); var aboutbox = Helper.AutoReadUnicode(reader);
Console.WriteLine(aboutbox); Console.WriteLine(aboutbox);
reader.ReadInt32(); reader.ReadInt32();
var binCount = reader.ReadInt32();//wtf i cant put it in loop fuck shit var binCount = reader.ReadInt32();//wtf i cant put it in loop fuck shit
@ -219,7 +263,9 @@ namespace NetMFAPatcher.mfa
} }
reader.Seek(nextOffset); reader.Seek(nextOffset);
var chunks = new ChunkList(reader);
chunks.Read();
return;

@ -117,6 +117,9 @@ namespace NetMFAPatcher
ByteIO mfaReader = new ByteIO(path, FileMode.Open); ByteIO mfaReader = new ByteIO(path, FileMode.Open);
var mfa = new MFA(mfaReader); var mfa = new MFA(mfaReader);
mfa.Read(); mfa.Read();
Console.WriteLine("Writing");
var MFAWriter = new ByteWriter("out.mfa",FileMode.Create);
mfa.Write(MFAWriter);
Console.ReadKey(); Console.ReadKey();
} }
else else

@ -57,15 +57,48 @@ namespace NetMFAPatcher.Utils
{ {
return BaseStream.Position < BaseStream.Length; 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]);
}
}
} }
} }

@ -62,6 +62,12 @@ namespace NetMFAPatcher
reader.Skip(2); reader.Skip(2);
return reader.ReadWideString(len); 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) public static DataLoader LoadParameter(int code, ByteIO reader)
{ {
DataLoader item = null; DataLoader item = null;

@ -21,10 +21,11 @@ namespace NetMFAPatcher.chunkloaders
public override void Read() public override void Read()
{ {
numberOfItems = reader.ReadInt32(); 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) public FontBank(ByteIO reader) : base(reader)

@ -36,6 +36,14 @@ namespace NetMFAPatcher.chunkloaders
items.Add(item); 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) public SoundBank(ByteIO reader) : base(reader)
{ {
@ -74,6 +82,7 @@ namespace NetMFAPatcher.chunkloaders
public bool compressed; public bool compressed;
public int checksum; public int checksum;
public int references; public int references;
public int flags;
public bool isCompressed = true; public bool isCompressed = true;
public override void Read() public override void Read()
@ -84,7 +93,7 @@ namespace NetMFAPatcher.chunkloaders
checksum = reader.ReadInt32(); checksum = reader.ReadInt32();
references = reader.ReadInt32(); references = reader.ReadInt32();
var decompressed_size = reader.ReadInt32(); var decompressed_size = reader.ReadInt32();
reader.ReadUInt32(); //flags flags = (int)reader.ReadUInt32(); //flags
var reserved = reader.ReadInt32(); var reserved = reader.ReadInt32();
var name_lenght = reader.ReadInt32(); var name_lenght = reader.ReadInt32();
ByteIO SoundData; ByteIO SoundData;
@ -114,6 +123,25 @@ namespace NetMFAPatcher.chunkloaders
string path = $"{Program.DumpPath}\\SoundBank\\{name}.wav"; string path = $"{Program.DumpPath}\\SoundBank\\{name}.wav";
File.WriteAllBytes(path, data); 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) public SoundItem(ByteIO reader) : base(reader)

Loading…
Cancel
Save