From d8872e71e19ec8abf33144343efee01948938a37 Mon Sep 17 00:00:00 2001 From: 1987kostya Date: Fri, 11 Dec 2020 18:45:40 +0600 Subject: [PATCH] Started working on events --- NetMFAPatcher/DotNetCTFDumper.csproj | 1 + NetMFAPatcher/GUI/HexViewForm.cs | 9 +- NetMFAPatcher/GUI/MainForm.Designer.cs | 2 +- NetMFAPatcher/GUI/MainForm.cs | 107 ++--- .../MMFParser/ChunkLoaders/Events/Events.cs | 6 +- NetMFAPatcher/MMFParser/Data/MFA.cs | 16 +- .../MMFParser/Decompiling/MFAGenerator.cs | 16 +- .../MMFParser/Decompiling/PAME2MFA.cs | 25 +- NetMFAPatcher/MMFParser/mfaloaders/Events.cs | 384 ++++++++++++++++++ NetMFAPatcher/Utils/Helper.cs | 16 +- .../mmfparser/chunkloaders/AppMenu.cs | 23 +- .../mmfparser/chunkloaders/banks/ImageBank.cs | 11 +- .../mmfparser/chunkloaders/banks/MusicBank.cs | 4 +- .../mmfparser/chunkloaders/banks/SoundBank.cs | 5 +- .../mmfparser/mfaloaders/Controls.cs | 34 +- NetMFAPatcher/mmfparser/mfaloaders/Frame.cs | 11 +- 16 files changed, 554 insertions(+), 116 deletions(-) create mode 100644 NetMFAPatcher/MMFParser/mfaloaders/Events.cs diff --git a/NetMFAPatcher/DotNetCTFDumper.csproj b/NetMFAPatcher/DotNetCTFDumper.csproj index d772aa4..dff2630 100644 --- a/NetMFAPatcher/DotNetCTFDumper.csproj +++ b/NetMFAPatcher/DotNetCTFDumper.csproj @@ -189,6 +189,7 @@ + diff --git a/NetMFAPatcher/GUI/HexViewForm.cs b/NetMFAPatcher/GUI/HexViewForm.cs index bbada4f..eae2daf 100644 --- a/NetMFAPatcher/GUI/HexViewForm.cs +++ b/NetMFAPatcher/GUI/HexViewForm.cs @@ -16,10 +16,11 @@ namespace DotNetCTFDumper.GUI public HexViewForm(byte[] parsedData, byte[] rawData,Color color) { - InitializeComponent(); - sizeLabel.ForeColor = color; - rawBox.ForeColor = color; - hexBox1.ForeColor = color; + InitializeComponent(); + foreach (Control item in Controls) + { + item.ForeColor = color; + } hexBox1.InfoForeColor = Color.FromArgb(color.R/2, color.G/2, color.B/2); hexBox1.SelectionForeColor=Color.FromArgb(color.R, color.G, color.B); hexBox1.SelectionBackColor=Color.FromArgb(color.R/4, color.G/4, color.B/4); diff --git a/NetMFAPatcher/GUI/MainForm.Designer.cs b/NetMFAPatcher/GUI/MainForm.Designer.cs index 615941c..9458590 100644 --- a/NetMFAPatcher/GUI/MainForm.Designer.cs +++ b/NetMFAPatcher/GUI/MainForm.Designer.cs @@ -119,6 +119,7 @@ // GameInfo // this.GameInfo.AutoSize = true; + this.GameInfo.BackColor = System.Drawing.Color.Transparent; this.GameInfo.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (204))); this.GameInfo.ForeColor = System.Drawing.Color.FromArgb(((int) (((byte) (255)))), ((int) (((byte) (128)))), ((int) (((byte) (0))))); this.GameInfo.Location = new System.Drawing.Point(9, 55); @@ -216,7 +217,6 @@ // this.MFABtn.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.MFABtn.BackColor = System.Drawing.Color.FromArgb(((int) (((byte) (64)))), ((int) (((byte) (64)))), ((int) (((byte) (64))))); - this.MFABtn.Enabled = false; this.MFABtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.MFABtn.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (204))); this.MFABtn.ForeColor = System.Drawing.Color.FromArgb(((int) (((byte) (255)))), ((int) (((byte) (128)))), ((int) (((byte) (0))))); diff --git a/NetMFAPatcher/GUI/MainForm.cs b/NetMFAPatcher/GUI/MainForm.cs index 7427ffa..8379b9c 100644 --- a/NetMFAPatcher/GUI/MainForm.cs +++ b/NetMFAPatcher/GUI/MainForm.cs @@ -24,39 +24,33 @@ namespace DotNetCTFDumper.GUI public Color ColorTheme = Color.FromArgb(223,114,38); public PackDataForm PackForm; - + public delegate void SaveHandler(int index, int all); public MainForm() { //Buttons InitializeComponent(); - cryptKeyBtn.ForeColor = ColorTheme; - dumpSortedBtn.ForeColor = ColorTheme; - showHexBtn.ForeColor = ColorTheme; - FolderBTN.ForeColor = ColorTheme; - MFABtn.ForeColor = ColorTheme; - imagesButton.ForeColor = ColorTheme; - soundsButton.ForeColor = ColorTheme; - packDataBtn.ForeColor = ColorTheme; - //Menu - saveChunkBtn.ForeColor = ColorTheme; - saveChunkBtn.BackColor=Color.Black; - viewHexBtn.ForeColor = ColorTheme; - viewHexBtn.BackColor=Color.Black; - previewFrameBtn.ForeColor = ColorTheme; - previewFrameBtn.BackColor=Color.Black; - //Labels - label1.ForeColor = ColorTheme; + foreach (Control item in Controls) + { + item.ForeColor = ColorTheme; + item.BackColor=Color.Black; + if(item is Button) item.BackColor=Color.FromArgb(30,30,30); + + if (item is Label) + { + item.BackColor = Color.Transparent; + item.Refresh(); + } + + } + + foreach (var item in ChunkCombo.Items) + { + ((ToolStripItem)item).ForeColor = ColorTheme; + ((ToolStripItem)item).BackColor=Color.Black; + } + label1.Text = Settings.DumperVersion; - button1.ForeColor = ColorTheme; - GameInfo.ForeColor = ColorTheme; - loadingLabel.ForeColor = ColorTheme; - imageLabel.ForeColor = ColorTheme; - soundLabel.ForeColor=ColorTheme; - //Other - treeView1.ForeColor = ColorTheme; - listBox1.ForeColor = ColorTheme; - imageBar.ForeColor = ColorTheme; - soundBar.ForeColor = ColorTheme; + @@ -187,6 +181,9 @@ namespace DotNetCTFDumper.GUI } } } + GameInfo.BackColor=Color.Transparent; + + GameInfo.Refresh(); } public void AfterLoad() @@ -253,12 +250,13 @@ namespace DotNetCTFDumper.GUI toLog += $"Unique FrameItems: {Exe.Instance.GameData.Frameitems.NumberOfItems}\n"; toLog += $"Frame Count: {Exe.Instance.GameData.Frames.Count}\n"; toLog += $"Chunks Count: {Exe.Instance.GameData.GameChunks.Chunks.Count}\n"; + if (Exe.Instance.GameData.GameChunks.GetChunk() != null) + Exe.Instance.GameData.GameChunks.GetChunk().OnImageSaved += UpdateImageBar; + if (Exe.Instance.GameData.GameChunks.GetChunk() != null) + Exe.Instance.GameData.GameChunks.GetChunk().OnSoundSaved += UpdateSoundBar; + if (Exe.Instance.GameData.GameChunks.GetChunk() != null) + Exe.Instance.GameData.GameChunks.GetChunk().OnMusicSaved += UpdateMusicBar; - - - - //toLog += $"Runtime Subversion: {Exe.LatestInst.GameData.RuntimeSubversion}\n"; - GameInfo.Text = toLog; } @@ -301,6 +299,7 @@ namespace DotNetCTFDumper.GUI if (!IsDumpingSounds) { SetSoundElements(true); + IsDumpingSounds = true; Backend.DumpSounds(this,true,true); } @@ -316,6 +315,7 @@ namespace DotNetCTFDumper.GUI if (!IsDumpingImages) { SetImageElements(true); + IsDumpingImages = true; Backend.DumpImages(this,true,true); } @@ -326,6 +326,23 @@ namespace DotNetCTFDumper.GUI SetImageElements(false); } } + private void musicsButton_Click(object sender, EventArgs e) + { + + if (!IsDumpingMusics) + { + SetMusicElements(true); + IsDumpingMusics = true; + Backend.DumpMusics(this,true,true); + } + else + { + BreakMusics = true; + IsDumpingMusics = false; + SetMusicElements(false); + } + + } public void SetSoundElements(bool state) @@ -430,21 +447,19 @@ namespace DotNetCTFDumper.GUI PackForm.Show(); } - private void musicsButton_Click(object sender, EventArgs e) + + + private void button2_Click(object sender, EventArgs e) { + var myPic = new PictureBox(); + var img = Exe.Instance.GameData.GameChunks.GetChunk().Images[65].Bitmap; + myPic.SizeMode = PictureBoxSizeMode.StretchImage; - if (!IsDumpingMusics) - { - Backend.DumpMusics(this,true,true); - } - else - { - BreakMusics = true; - IsDumpingMusics = false; - SetMusicElements(false); - } - - } + myPic.Image = img; + myPic.Width = img.Width / 2; + myPic.Height = img.Height / 2; + Controls.Add(myPic); + } } } \ No newline at end of file diff --git a/NetMFAPatcher/MMFParser/ChunkLoaders/Events/Events.cs b/NetMFAPatcher/MMFParser/ChunkLoaders/Events/Events.cs index 74cf39d..83aa1d9 100644 --- a/NetMFAPatcher/MMFParser/ChunkLoaders/Events/Events.cs +++ b/NetMFAPatcher/MMFParser/ChunkLoaders/Events/Events.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; using DotNetCTFDumper.Utils; using static DotNetCTFDumper.MMFParser.Data.ChunkList; @@ -170,8 +171,11 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Events } + } - + public void Write(ByteWriter Writer) + { + } } diff --git a/NetMFAPatcher/MMFParser/Data/MFA.cs b/NetMFAPatcher/MMFParser/Data/MFA.cs index ece1cd8..f0eb5aa 100644 --- a/NetMFAPatcher/MMFParser/Data/MFA.cs +++ b/NetMFAPatcher/MMFParser/Data/MFA.cs @@ -123,6 +123,7 @@ namespace DotNetCTFDumper.MMFParser.Data public override void Write(ByteWriter Writer) { + Writer.WriteAscii("MFU2"); Writer.WriteInt32(MfaBuild); Writer.WriteInt32(Product); @@ -189,7 +190,7 @@ namespace DotNetCTFDumper.MMFParser.Data using (ByteWriter menuWriter = new ByteWriter(new MemoryStream())) { Menu.Write(menuWriter); - + Writer.WriteUInt32((uint) menuWriter.BaseStream.Position); Writer.WriteWriter(menuWriter); } @@ -198,7 +199,7 @@ namespace DotNetCTFDumper.MMFParser.Data { Writer.WriteInt32(0); } - + Writer.WriteInt32(windowMenuIndex); Writer.WriteInt32(menuImages.Count); foreach (KeyValuePair valuePair in menuImages) @@ -218,7 +219,16 @@ namespace DotNetCTFDumper.MMFParser.Data } Writer.WriteInt32(0);//custom qualifiers Writer.WriteInt32(0); //extensions - Writer.WriteInt32(0); //frame + Writer.WriteInt32(Frames.Count); //frame + var startPos = Reader.Tell() + 4 * Frames.Count + 4; + ByteWriter newWriter = new ByteWriter(new MemoryStream()); + foreach (Frame frame in Frames) + { + Writer.WriteUInt32((uint) (startPos+newWriter.Tell()+4)); + frame.Write(newWriter); + } + Writer.WriteUInt32((uint) (startPos+newWriter.Tell()+4)); + Writer.WriteWriter(newWriter); diff --git a/NetMFAPatcher/MMFParser/Decompiling/MFAGenerator.cs b/NetMFAPatcher/MMFParser/Decompiling/MFAGenerator.cs index f0d2df8..892436c 100644 --- a/NetMFAPatcher/MMFParser/Decompiling/MFAGenerator.cs +++ b/NetMFAPatcher/MMFParser/Decompiling/MFAGenerator.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using DotNetCTFDumper.MMFParser.Data; using DotNetCTFDumper.Utils; @@ -6,8 +7,8 @@ namespace DotNetCTFDumper.MMFParser.Decompiling { public static class MFAGenerator { - public static readonly string TemplatePath = @"C:\Users\MED45\Downloads\testNoFrames.mfa"; - // public static readonly string TemplatePath = @"C:\Users\ivani\Desktop\CTFResearch\testNoFrames.mfa"; + //public static readonly string TemplatePath = @"C:\Users\MED45\Downloads\testNoFrames.mfa"; + public static readonly string TemplatePath = @"C:\Users\ivani\Desktop\CTFResearch\testNoFrames.mfa"; public static void BuildMFA() { @@ -17,13 +18,15 @@ namespace DotNetCTFDumper.MMFParser.Decompiling template.Read(); //Loading template - var gameMFA = template; //Pame2Mfa.Translate(template, Exe.LatestInst.GameData); //Translation + Pame2Mfa.Translate(ref template, Exe.Instance.GameData); //Translation var mfaWriter = new ByteWriter( Settings.GameName.Length > 0 ? $"{Settings.DumpPath}\\{Exe.Instance.GameData.Name}.mfa" : "out.mfa", FileMode.Create); //New writer for new MFA - gameMFA.Write(mfaWriter); //Writing new MFA + template.Write(mfaWriter); //Writing new MFA + mfaWriter.Dispose(); + Logger.Log("MFA Done",true,ConsoleColor.Yellow); } public static void ReadTestMFA() @@ -32,6 +35,9 @@ namespace DotNetCTFDumper.MMFParser.Decompiling var template = new MFA(mfaReader); Settings.DoMFA = true; template.Read(); + + //Add modifications + var mfaWriter = new ByteWriter("outTest.mfa", FileMode.Create); template.Write(mfaWriter); } diff --git a/NetMFAPatcher/MMFParser/Decompiling/PAME2MFA.cs b/NetMFAPatcher/MMFParser/Decompiling/PAME2MFA.cs index 4355c95..97624e9 100644 --- a/NetMFAPatcher/MMFParser/Decompiling/PAME2MFA.cs +++ b/NetMFAPatcher/MMFParser/Decompiling/PAME2MFA.cs @@ -5,17 +5,19 @@ namespace DotNetCTFDumper.MMFParser.Decompiling { public static class Pame2Mfa { - public static MFA Translate(MFA template, GameData game) + public static void Translate(ref MFA mfa, GameData game) { - MFA mfa = template; - mfa.MfaBuild = 4; - mfa.Product = (int) game.ProductVersion; + + //mfa.MfaBuild = 4; + //mfa.Product = (int) game.ProductVersion; mfa.BuildVersion = 283; mfa.Name = game.Name; mfa.Description = $"Decompiled with {Settings.DumperVersion}"; mfa.Path = game.EditorFilename; + return; //mfa.Stamp = wtf; - mfa.Fonts = game.Fonts; + if (game.Fonts != null) mfa.Fonts = game.Fonts; + mfa.Sounds = game.Sounds; foreach (var item in mfa.Sounds.Items) { @@ -49,20 +51,11 @@ namespace DotNetCTFDumper.MMFParser.Decompiling mfa.BuildType = 0; mfa.BuildPath = game.TargetFilename; mfa.CommandLine = ""; - mfa.Aboutbox = game.AboutText.Length > 0 - ? game.AboutText + mfa.Aboutbox = game.AboutText?.Length > 0 + ? game?.AboutText : "This game was decompiled with " + Settings.DumperVersion; - - - - - - - - - return mfa; } } } \ No newline at end of file diff --git a/NetMFAPatcher/MMFParser/mfaloaders/Events.cs b/NetMFAPatcher/MMFParser/mfaloaders/Events.cs new file mode 100644 index 0000000..53bc5cb --- /dev/null +++ b/NetMFAPatcher/MMFParser/mfaloaders/Events.cs @@ -0,0 +1,384 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Runtime.InteropServices; +using DotNetCTFDumper.MMFParser.ChunkLoaders.Events; +using DotNetCTFDumper.MMFParser.Data; +using DotNetCTFDumper.Utils; + +namespace DotNetCTFDumper.MMFParser.MFALoaders +{ + public class Events:DataLoader + { + public readonly string EventData = "Evts"; + public readonly string CommentData = "Rems"; + public readonly string ObjectData = "EvOb"; + public readonly string EventEditorData = "EvCs"; + public readonly string ObjectListData = "EvEd"; + public readonly string TimeListData = "EvEd"; + public readonly string EditorPositionData = "EvTs"; + public readonly string EditorLineData = "EvLs"; + public readonly string EventEnd ="!DNE"; + public List Items; + public ushort Version; + public ushort FrameType; + public List Comments; + public List Objects; + public ushort ConditionWidth; + public ushort ObjectHeight; + public List ObjectTypes; + public List ObjectHandles; + public List ObjectFlags; + public List Folders; + public uint X; + public uint Y; + public uint CaretType; + public uint CaretX; + public uint CaretY; + public uint LineY; + public uint LineItemType; + public uint EventLine; + public uint EventLineY; + + public Events(ByteReader reader) : base(reader) + { + } + + public Events(Data.ChunkList.Chunk chunk) : base(chunk) + { + } + + public override void Read() + { + Version = Reader.ReadUInt16(); + FrameType = Reader.ReadUInt16(); + Items = new List(); + + while (true) + { + + string name = Reader.ReadAscii(4); + if (name == EventData) + { + uint size = Reader.ReadUInt32(); + uint end = (uint) (Reader.Tell() + size); + while (true) + { + EventGroup evGrp = new EventGroup(Reader); + evGrp.Read(); + Items.Add(evGrp); + if (Reader.Tell() >= end) break; + } + } + else if (name == CommentData) + { + try + { + uint len = Reader.ReadUInt32(); + Comments = new List(); + Comment comment = new Comment(Reader); + comment.Read(); + Comments.Add(comment); + } + catch + { + //What the fuck? + + /* + import code + code.interact(local = locals()) + */ + } + } + else if (name == ObjectData) + { + Objects = new List(); + uint len = Reader.ReadUInt32(); + for (int i = 0; i < len; i++) + { + EventObject eventObject = new EventObject(Reader); + eventObject.Read(); + Objects.Add(eventObject); + + } + } + else if (name == EventEditorData) + { + Reader.Skip(4); + ConditionWidth = Reader.ReadUInt16(); + ObjectHeight = Reader.ReadUInt16(); + Reader.Skip(12); + } + else if (name == ObjectListData) + { + short count = Reader.ReadInt16(); + short realCount = count; + if (count == -1) + { + realCount = Reader.ReadInt16(); + } + + ObjectTypes = new List(); + for (int i = 0; i < realCount; i++) + { + ObjectTypes.Add(Reader.ReadUInt16()); + } + ObjectHandles = new List(); + for (int i = 0; i < realCount; i++) + { + ObjectHandles.Add(Reader.ReadUInt16()); + } + ObjectFlags = new List(); + for (int i = 0; i < realCount; i++) + { + ObjectFlags.Add(Reader.ReadUInt16()); + } + + if (count == -1) + { + Folders = new List(); + var folderCount = Reader.ReadUInt16(); + for (int i = 0; i < folderCount; i++) + { + Folders.Add( Reader.AutoReadUnicode()); + } + } + } + else if (name == TimeListData) + { + throw new NotImplementedException("I don't like no timelist"); + } + else if (name == EditorPositionData) + { + if(Reader.ReadUInt16()!=1) throw new NotImplementedException("Invalid chunkversion"); + X = Reader.ReadUInt32(); + Y = Reader.ReadUInt32(); + CaretType = Reader.ReadUInt32(); + CaretX = Reader.ReadUInt32(); + CaretY = Reader.ReadUInt32(); + } + else if (name == EditorLineData) + { + if(Reader.ReadUInt16()!=1) throw new NotImplementedException("Invalid chunkversion"); + LineY = Reader.ReadUInt32(); + LineItemType = Reader.ReadUInt32(); + EventLine = Reader.ReadUInt32(); + EventLineY = Reader.ReadUInt32(); + } + else if (name == EventEnd) break; + //else throw new NotImplementedException("Fuck Something Broken"); + + } + } + + public override void Write(ByteWriter Writer) + { + Writer.WriteUInt16(Version); + Writer.WriteInt16((short) FrameType); + if (Items != null) + { + Writer.WriteAscii(EventData); + ByteWriter newWriter = new ByteWriter(new MemoryStream()); + foreach (EventGroup eventGroup in Items) + { + eventGroup.Write(newWriter); + } + Writer.WriteWriter(newWriter); + } + + if (Comments != null) + { + Writer.WriteAscii(CommentData); + foreach (Comment comment in Comments) + { + comment.Write(Writer); + } + } + + if (Objects != null) + { + Writer.WriteAscii(ObjectData); + Writer.WriteUInt32((uint) Objects.Count); + foreach (EventObject eventObject in Objects) + { + eventObject.Write(Writer); + } + } + Writer.WriteAscii(EventEditorData); + Writer.Skip(4+2*2+4*3); + if (ObjectTypes != null) + { + Writer.WriteAscii(ObjectListData); + Writer.WriteInt16(-1); + Writer.WriteInt16((short) ObjectTypes.Count); + foreach (ushort objectType in ObjectTypes) + { + Writer.WriteUInt16(objectType); + } + foreach (ushort objectHandle in ObjectHandles) + { + Writer.WriteUInt16(objectHandle); + } + foreach (ushort objectFlag in ObjectFlags) + { + Writer.WriteUInt16(objectFlag); + } + Writer.WriteUInt16((ushort) Folders.Count); + foreach (string folder in Folders) + { + Writer.AutoWriteUnicode(folder); + } + + } + + if (X != 0) + { + Writer.WriteAscii(EditorPositionData); + Writer.WriteInt16(1); + Writer.WriteInt32((int) X); + Writer.WriteInt32((int) Y); + Writer.WriteUInt32(CaretType); + Writer.WriteUInt32(CaretX); + Writer.WriteUInt32(CaretY); + } + + if (LineY != 0) + { + Writer.WriteAscii(EditorLineData); + Writer.WriteInt16(1); + Writer.WriteUInt32(LineY); + Writer.WriteUInt32(LineItemType); + Writer.WriteUInt32(EventLine); + Writer.WriteUInt32(EventLineY); + } + Writer.WriteAscii(EventEnd); + + + + + + } + + public override void Print() + { + throw new System.NotImplementedException(); + } + } + + public class Comment:DataLoader + { + public uint Handle; + public string Value; + + public Comment(ByteReader reader) : base(reader) + { + } + + public Comment(Data.ChunkList.Chunk chunk) : base(chunk) + { + } + + public override void Read() + { + Handle = Reader.ReadUInt32(); + Value = Helper.AutoReadUnicode(Reader); + } + + public override void Write(ByteWriter Writer) + { + Writer.WriteUInt32(Handle); + Writer.AutoWriteUnicode(Value); + } + + public override void Print() + { + throw new System.NotImplementedException(); + } + } + + public class EventObject : DataLoader + { + public uint Handle; + public ushort ObjectType; + public ushort ItemType; + public string Name; + public string TypeName; + public ushort Flags; + public uint ItemHandle; + public uint InstanceHandle; + public string Code; + public string IconBuffer; + public ushort SystemQualifier; + + public EventObject(ByteReader reader) : base(reader) + { + } + + public EventObject(Data.ChunkList.Chunk chunk) : base(chunk) + { + } + + public override void Read() + { + Handle = Reader.ReadUInt32(); + ObjectType = Reader.ReadUInt16(); + ItemType = Reader.ReadUInt16(); + Name = Reader.AutoReadUnicode();//Not Sure + TypeName = Reader.AutoReadUnicode();//Not Sure + Flags = Reader.ReadUInt16(); + if (ObjectType == 1)//FrameItemType + { + ItemHandle = Reader.ReadUInt32(); + InstanceHandle = Reader.ReadUInt32(); + } + else if (ObjectType == 2)//ShortcutItemType + { + Code = Reader.ReadAscii(4); + if (Code == "OIC2")//IconBufferCode + { + IconBuffer = Reader.AutoReadUnicode(); + } + } + if (ObjectType == 3) //SystemItemType + { + SystemQualifier = Reader.ReadUInt16(); + } + + } + + public override void Write(ByteWriter Writer) + { + Writer.WriteUInt32(Handle); + Writer.WriteUInt16(ObjectType); + Writer.WriteUInt16(ItemType); + Writer.AutoWriteUnicode(Name);//Not Sure + Writer.AutoWriteUnicode(TypeName);//Not Sure + Writer.WriteUInt16(Flags); + if (ObjectType == 1) + { + Writer.WriteUInt32(ItemHandle); + Writer.WriteUInt32(InstanceHandle); + } + else if (ObjectType == 2) + { + Writer.WriteAscii(Code); + if (Code == "OIC2") + { + Writer.AutoWriteUnicode(IconBuffer); + } + } + if (ObjectType == 3) + { + Writer.WriteUInt16(SystemQualifier); + } + + + } + + public override void Print() + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/NetMFAPatcher/Utils/Helper.cs b/NetMFAPatcher/Utils/Helper.cs index 083f732..9e2927b 100644 --- a/NetMFAPatcher/Utils/Helper.cs +++ b/NetMFAPatcher/Utils/Helper.cs @@ -53,7 +53,7 @@ namespace DotNetCTFDumper.Utils return temp; } - public static string AutoReadUnicode(ByteReader reader) + public static string AutoReadUnicode(this ByteReader reader) { var len = reader.ReadInt16(); reader.Skip(2); @@ -180,19 +180,7 @@ namespace DotNetCTFDumper.Utils } } - public static void OnImageSaved(int index, int all) - { - Program.MyForm.UpdateImageBar(index, all); - } - - public static void OnSoundSaved(int index, int all) - { - Program.MyForm.UpdateSoundBar(index, all); - } - public static void OnMusicSaved(int index, int all) - { - Program.MyForm.UpdateSoundBar(index, all); - } + private const long OneKb = 1024; private const long OneMb = OneKb * 1024; diff --git a/NetMFAPatcher/mmfparser/chunkloaders/AppMenu.cs b/NetMFAPatcher/mmfparser/chunkloaders/AppMenu.cs index 06fc2c5..d8e0588 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/AppMenu.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/AppMenu.cs @@ -33,6 +33,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders public override void Read() { + long currentPosition = Reader.Tell(); uint headerSize = Reader.ReadUInt32(); int menuOffset = Reader.ReadInt32(); @@ -46,14 +47,14 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders Load(Reader); Reader.Seek(currentPosition + accelOffset); - + AccelShift = new List(); + AccelKey = new List(); + AccelId = new List(); for (int i = 0; i < accelSize / 8; i++) { - AccelShift = new List(); - AccelKey = new List(); - AccelId = new List(); + AccelShift.Add(Reader.ReadByte()); - ; + Reader.Skip(1); AccelKey.Add(Reader.ReadInt16()); AccelId.Add(Reader.ReadInt16()); @@ -65,7 +66,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders { writer.WriteInt32(20); writer.WriteInt32(20); - writer.WriteInt32(0); + writer.WriteInt32(458); ByteWriter menuDataWriter = new ByteWriter(new MemoryStream()); @@ -74,7 +75,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders item.Write(menuDataWriter); } - writer.WriteUInt32((uint) (24 + menuDataWriter.BaseStream.Position)); + writer.WriteUInt32((uint) ( menuDataWriter.BaseStream.Position)+62);//shit writer.WriteInt32(AccelKey.Count * 8); writer.WriteInt32(0); writer.WriteWriter(menuDataWriter); @@ -152,7 +153,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders Mnemonic = Name[i + 1].ToString().ToUpper(); } - Name = Name.Replace("&", ""); + //Name = Name.Replace("&", ""); } Console.WriteLine(Name); @@ -171,12 +172,12 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders } String MName = Name; - if (Mnemonic != null) + if (Mnemonic!=null) { - MName = MName.Replace(Mnemonic, "&" + Mnemonic); + //MName = MName.Replace(Mnemonic, "&" + Mnemonic); } - writer.AutoWriteUnicode(MName); + writer.WriteUnicode(MName); } } } \ No newline at end of file diff --git a/NetMFAPatcher/mmfparser/chunkloaders/banks/ImageBank.cs b/NetMFAPatcher/mmfparser/chunkloaders/banks/ImageBank.cs index aaac63f..55c8b82 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/banks/ImageBank.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/banks/ImageBank.cs @@ -46,6 +46,13 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks Settings.DumpImages = cache; } + + + public event MainForm.SaveHandler OnImageSaved; + + + + public override void Read() { if (!Settings.DoMFA) Reader.Seek(0); //Reset the reader to avoid bugs when dumping more than once @@ -70,11 +77,11 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks Images.Add(item.Handle, item); if (SaveImages) item.Save($"{Settings.ImagePath}\\" + item.Handle.ToString() + ".png"); + OnImageSaved?.Invoke(i,(int) NumberOfItems); - Helper.OnImageSaved(i, (int) NumberOfItems); - if (Exe.Instance.GameData.ProductBuild >= 284) + if (Settings.Build >= 284) item.Handle -= 1; //images[item.handle] = item; diff --git a/NetMFAPatcher/mmfparser/chunkloaders/banks/MusicBank.cs b/NetMFAPatcher/mmfparser/chunkloaders/banks/MusicBank.cs index 5745d36..4933ccf 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/banks/MusicBank.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/banks/MusicBank.cs @@ -30,7 +30,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks Read(); Settings.DumpMusic = cache; } - + public event MainForm.SaveHandler OnMusicSaved; public override void Read() { //Someone is using this lol? @@ -45,7 +45,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks if (MainForm.BreakMusics) break; var item = new MusicFile(Reader); item.Read(); - Helper.OnMusicSaved(i,NumOfItems); + OnMusicSaved?.Invoke(i,(int) NumOfItems); Items.Add(item); } } diff --git a/NetMFAPatcher/mmfparser/chunkloaders/banks/SoundBank.cs b/NetMFAPatcher/mmfparser/chunkloaders/banks/SoundBank.cs index 0b1e892..72abf54 100644 --- a/NetMFAPatcher/mmfparser/chunkloaders/banks/SoundBank.cs +++ b/NetMFAPatcher/mmfparser/chunkloaders/banks/SoundBank.cs @@ -33,7 +33,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks Settings.DumpSounds = cache; } - + public event MainForm.SaveHandler OnSoundSaved; public override void Read() { //Implementing for standalone-only because of my lazyness @@ -58,7 +58,8 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks var item = new SoundItem(Reader); item.IsCompressed = IsCompressed; item.Read(); - Helper.OnSoundSaved(i, NumOfItems); + + OnSoundSaved?.Invoke(i,(int) NumOfItems); Items.Add(item); diff --git a/NetMFAPatcher/mmfparser/mfaloaders/Controls.cs b/NetMFAPatcher/mmfparser/mfaloaders/Controls.cs index a872f9b..1303f37 100644 --- a/NetMFAPatcher/mmfparser/mfaloaders/Controls.cs +++ b/NetMFAPatcher/mmfparser/mfaloaders/Controls.cs @@ -54,6 +54,14 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders public int Button2; public int Button3; public int Button4; + public int Unk1; + public int Unk2; + public int Unk3; + public int Unk4; + public int Unk5; + public int Unk6; + public int Unk7; + public int Unk8; public PlayerControl(ByteReader reader) : base(reader) @@ -79,10 +87,15 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders Button2 = Reader.ReadInt32(); Button3 = Reader.ReadInt32(); Button4 = Reader.ReadInt32(); - for (int i = 0; i < 8; i++) - { - Reader.ReadInt32(); - } + Unk1 = Reader.ReadInt32(); + Unk2 = Reader.ReadInt32(); + Unk3 = Reader.ReadInt32(); + Unk4 = Reader.ReadInt32(); + Unk5 = Reader.ReadInt32(); + Unk6 = Reader.ReadInt32(); + Unk7 = Reader.ReadInt32(); + Unk8 = Reader.ReadInt32(); + } public override void Write(ByteWriter writer) @@ -97,10 +110,15 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders writer.WriteInt32(Button2); writer.WriteInt32(Button3); writer.WriteInt32(Button4); - for (int i = 0; i < 8; i++) - { - writer.WriteInt32(0); - } + writer.WriteInt32(Unk1); + writer.WriteInt32(Unk2); + writer.WriteInt32(Unk3); + writer.WriteInt32(Unk4); + writer.WriteInt32(Unk5); + writer.WriteInt32(Unk6); + writer.WriteInt32(Unk7); + writer.WriteInt32(Unk8); + } diff --git a/NetMFAPatcher/mmfparser/mfaloaders/Frame.cs b/NetMFAPatcher/mmfparser/mfaloaders/Frame.cs index 49967d5..0cc9566 100644 --- a/NetMFAPatcher/mmfparser/mfaloaders/Frame.cs +++ b/NetMFAPatcher/mmfparser/mfaloaders/Frame.cs @@ -25,6 +25,7 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders public int StampHandle; public int ActiveLayer; public List Layers; + public Events Events; public Frame(ByteReader reader) : base(reader) { @@ -58,19 +59,25 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders } //TODO: Do transitions Writer.WriteInt8(0); + Writer.WriteInt8(0); + + Writer.WriteInt32(Items.Count); foreach (var item in Items) { item.Write(Writer); } + Writer.WriteInt32(Folders.Count); foreach (var item in Folders) { item.Write(Writer); } + Writer.WriteInt32(Instances.Count); foreach (var item in Instances) { item.Write(Writer); } - + Events.Write(Writer); + @@ -145,6 +152,8 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders //inst.Read(); Instances.Add(inst); } + Events = new Events(Reader); + Events.Read();