diff --git a/CTFAK/CTFAK.csproj b/CTFAK/CTFAK.csproj
index 11c7928..0f36bab 100644
--- a/CTFAK/CTFAK.csproj
+++ b/CTFAK/CTFAK.csproj
@@ -168,6 +168,7 @@
+
diff --git a/CTFAK/MMFParser/EXE/ChunkList.cs b/CTFAK/MMFParser/EXE/ChunkList.cs
index 2c15e2f..99caa92 100644
--- a/CTFAK/MMFParser/EXE/ChunkList.cs
+++ b/CTFAK/MMFParser/EXE/ChunkList.cs
@@ -300,8 +300,8 @@ namespace CTFAK.MMFParser.EXE
}
loader?.Read();
- chunk.ChunkData = null;
- chunk.RawData = null;
+ // chunk.ChunkData = null;
+ // chunk.RawData = null;
return loader;
}
diff --git a/CTFAK/MMFParser/EXE/Loaders/Banks/ImageBank.cs b/CTFAK/MMFParser/EXE/Loaders/Banks/ImageBank.cs
index fba08f1..0e89774 100644
--- a/CTFAK/MMFParser/EXE/Loaders/Banks/ImageBank.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/Banks/ImageBank.cs
@@ -75,7 +75,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
if (!Settings.DoMFA) Reader.Seek(0); //Reset the reader to avoid bugs when dumping more than once
var tempImages = new Dictionary();
-
+ // if (!Settings.DoMFA)return;
NumberOfItems = (uint) Reader.ReadInt32();
Logger.Log($"Found {NumberOfItems} images", true, ConsoleColor.Green);
@@ -149,6 +149,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
Handle = Reader.ReadInt32();
if (!Debug)
{
+ if (Settings.Build>288) Handle -= 1;
if (Program.CleanData.ProductVersion != Constants.Products.MMF15&&Settings.Build>=284) Handle -= 1;
}
diff --git a/CTFAK/MMFParser/EXE/Loaders/Banks/MusicBank.cs b/CTFAK/MMFParser/EXE/Loaders/Banks/MusicBank.cs
index 0f7d2a7..0502fab 100644
--- a/CTFAK/MMFParser/EXE/Loaders/Banks/MusicBank.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/Banks/MusicBank.cs
@@ -34,6 +34,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
if (!Settings.DoMFA)Reader.Seek(0);//Reset the reader to avoid bugs when dumping more than once
Items = new List();
+ // if (!Settings.DoMFA)return;
NumOfItems = Reader.ReadInt32();
if (!Settings.DumpMusic) return;
Console.WriteLine(NumOfItems);
diff --git a/CTFAK/MMFParser/EXE/Loaders/Banks/SoundBank.cs b/CTFAK/MMFParser/EXE/Loaders/Banks/SoundBank.cs
index 219b49e..e1abe49 100644
--- a/CTFAK/MMFParser/EXE/Loaders/Banks/SoundBank.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/Banks/SoundBank.cs
@@ -38,6 +38,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
{
if (!Settings.DoMFA)Reader.Seek(0);//Reset the reader to avoid bugs when dumping more than once
Items = new List();
+ // if (!Settings.DoMFA)return;
NumOfItems = Reader.ReadInt32();
Logger.Log("Found " + NumOfItems + " sounds",true,ConsoleColor.Green);
//if (!Settings.DumpSounds) return;
diff --git a/CTFAK/MMFParser/EXE/Loaders/Events/Events.cs b/CTFAK/MMFParser/EXE/Loaders/Events/Events.cs
index 940d575..db3e748 100644
--- a/CTFAK/MMFParser/EXE/Loaders/Events/Events.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/Events/Events.cs
@@ -233,22 +233,44 @@ namespace CTFAK.MMFParser.EXE.Loaders.Events
foreach (Condition condition in Conditions)
{
+ var cond = condition;
+ Fixer.FixConditions(ref cond);
condition.Write(newWriter);
}
foreach (Action action in Actions)
{
- action.Write(newWriter);
+ var act = action;
+ Fixer.FixActions(ref act);
+ act.Write(newWriter);
}
Writer.WriteInt16((short) ((newWriter.Size()+2)*-1));
Writer.WriteWriter(newWriter);
-
+
+ }
+ }
-
-
-
+ public static class Fixer
+ {
+ public static void FixConditions(ref Condition cond)
+ {
+ var num = cond.Num;
+ if (num == -42) num = -27;
+ // if (num == -28||num == -29||num == -30||num == -31||num == -32||num == -33||num == -34||num == -35||num == -36||num == -37||num == -38||num == -39) num = -8;
+ cond.Num = num;
+ }
+ public static void FixActions(ref Action act)
+ {
+ var num = act.Num;
+ // if (num == 27||num == 28||num == 29||num == 30) num = 3;
+ act.Num = num;
}
+
+
}
+
+
+
}
\ No newline at end of file
diff --git a/CTFAK/MMFParser/EXE/Loaders/Events/EventsParts.cs b/CTFAK/MMFParser/EXE/Loaders/Events/EventsParts.cs
index 8f876a7..c559b98 100644
--- a/CTFAK/MMFParser/EXE/Loaders/Events/EventsParts.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/Events/EventsParts.cs
@@ -25,7 +25,6 @@ namespace CTFAK.MMFParser.EXE.Loaders.Events
ByteWriter newWriter = new ByteWriter(new MemoryStream());
// Logger.Log($"{ObjectType}-{Num}-{ObjectInfo}-{ObjectInfoList}-{Flags}-{OtherFlags}-{Items.Count}-{DefType}-{Identifier}");
newWriter.WriteInt16((short) ObjectType);
- if (Num == -42) Num = -27;
newWriter.WriteInt16((short) Num);
newWriter.WriteUInt16((ushort) ObjectInfo);
newWriter.WriteInt16((short) ObjectInfoList);
@@ -187,7 +186,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Events
}
else
{
- throw new Exception("Loader is null");
+ throw new Exception("Loader is null: "+Code);
}
Reader.Seek(currentPosition+size);
diff --git a/CTFAK/MMFParser/EXE/Loaders/Events/Parameters/Extension.cs b/CTFAK/MMFParser/EXE/Loaders/Events/Parameters/Extension.cs
new file mode 100644
index 0000000..c0eff47
--- /dev/null
+++ b/CTFAK/MMFParser/EXE/Loaders/Events/Parameters/Extension.cs
@@ -0,0 +1,33 @@
+using CTFAK.Utils;
+
+namespace CTFAK.MMFParser.EXE.Loaders.Events.Parameters
+{
+ public class Extension:ParameterCommon
+ {
+ public short Size;
+ public short Type;
+ public short Code;
+ public byte[] Data;
+
+ public Extension(ByteReader reader) : base(reader)
+ {
+ }
+
+ public override void Read()
+ {
+ Size = Reader.ReadInt16();
+ Type = Reader.ReadInt16();
+ Code = Reader.ReadInt16();
+ Data = Reader.ReadBytes(Size-20);
+
+ }
+
+ public override void Write(ByteWriter Writer)
+ {
+ Writer.WriteInt16((short) (Data.Length+6));
+ Writer.WriteInt16(Type);
+ Writer.WriteInt16(Code);
+ Writer.WriteBytes(Data);
+ }
+ }
+}
\ No newline at end of file
diff --git a/CTFAK/MMFParser/EXE/Loaders/Frame.cs b/CTFAK/MMFParser/EXE/Loaders/Frame.cs
index 0088ca7..27c9073 100644
--- a/CTFAK/MMFParser/EXE/Loaders/Frame.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/Frame.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
+using System.Linq;
using CTFAK.Utils;
namespace CTFAK.MMFParser.EXE.Loaders
@@ -109,9 +110,9 @@ namespace CTFAK.MMFParser.EXE.Loaders
public string Password => _password.Value;
public Color Background => _header.Background;
public List Objects => _objects?.Items ?? null;
- public List Palette => _palette.Items;
+ public List Palette => _palette?.Items ?? new Color[256].ToList();
public Events.Events Events => _events;
- public List Layers => _layers.Items;
+ public List Layers => _layers?.Items ?? null;
public Frame(ByteReader reader) : base(reader){}
diff --git a/CTFAK/MMFParser/EXE/Loaders/FrameHandles.cs b/CTFAK/MMFParser/EXE/Loaders/FrameHandles.cs
index ab8986a..082c6cc 100644
--- a/CTFAK/MMFParser/EXE/Loaders/FrameHandles.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/FrameHandles.cs
@@ -24,20 +24,13 @@ namespace CTFAK.MMFParser.EXE.Loaders
for (int i = 0; i < len; i++)
{
var handle = Reader.ReadInt16();
- Logger.Log("Frame Handle: "+handle);
Items.Add(i,handle);
}
}
- public override void Print(bool ext)
- {
- throw new System.NotImplementedException();
- }
+ public override void Print(bool ext){}
+ public override string[] GetReadableData() => null;
- public override string[] GetReadableData()
- {
- throw new System.NotImplementedException();
- }
}
}
\ No newline at end of file
diff --git a/CTFAK/MMFParser/EXE/Loaders/ObjectInfo.cs b/CTFAK/MMFParser/EXE/Loaders/ObjectInfo.cs
index 6fadde0..18a0c5f 100644
--- a/CTFAK/MMFParser/EXE/Loaders/ObjectInfo.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/ObjectInfo.cs
@@ -38,7 +38,6 @@ namespace CTFAK.MMFParser.EXE.Loaders
_name = infoChunks.GetChunk();
_properties = infoChunks.GetChunk();
_properties.ReadNew((int) ObjectType,this);
-
}
public int Handle => _header.Handle;
diff --git a/CTFAK/MMFParser/EXE/Loaders/Objects/ObjectCommon.cs b/CTFAK/MMFParser/EXE/Loaders/Objects/ObjectCommon.cs
index 87852aa..674f675 100644
--- a/CTFAK/MMFParser/EXE/Loaders/Objects/ObjectCommon.cs
+++ b/CTFAK/MMFParser/EXE/Loaders/Objects/ObjectCommon.cs
@@ -190,6 +190,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Objects
{
ExtensionData = Reader.ReadBytes(dataSize);
}
+ else ExtensionData=new byte[0];
Logger.Log($"{Parent.Name} - {ExtensionId}");
}
diff --git a/CTFAK/MMFParser/MFA/Loaders/FrameItem.cs b/CTFAK/MMFParser/MFA/Loaders/FrameItem.cs
index 4c43ef0..215072b 100644
--- a/CTFAK/MMFParser/MFA/Loaders/FrameItem.cs
+++ b/CTFAK/MMFParser/MFA/Loaders/FrameItem.cs
@@ -37,7 +37,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
Writer.WriteInt32(IconHandle);
Chunks.Write(Writer);
- Loader.Write(Writer);
+ Loader?.Write(Writer);
diff --git a/CTFAK/MMFParser/MFA/Loaders/mfachunks/ExtensionObject.cs b/CTFAK/MMFParser/MFA/Loaders/mfachunks/ExtensionObject.cs
index 27cb481..7efbed5 100644
--- a/CTFAK/MMFParser/MFA/Loaders/mfachunks/ExtensionObject.cs
+++ b/CTFAK/MMFParser/MFA/Loaders/mfachunks/ExtensionObject.cs
@@ -52,6 +52,8 @@ namespace CTFAK.MMFParser.MFA.Loaders.mfachunks
Writer.WriteUInt32(Magic);
Writer.AutoWriteUnicode(SubType);
}
+
+ // if (ExtensionData == null) ExtensionData = new byte[0];
Writer.WriteInt32(ExtensionData.Length+20);
Writer.WriteInt32(ExtensionData.Length+20);
Writer.WriteInt32(-1);
diff --git a/CTFAK/MMFParser/MFA/MFA.cs b/CTFAK/MMFParser/MFA/MFA.cs
index 8040602..8deb42a 100644
--- a/CTFAK/MMFParser/MFA/MFA.cs
+++ b/CTFAK/MMFParser/MFA/MFA.cs
@@ -98,7 +98,7 @@ namespace CTFAK.MMFParser.MFA
public int InitialLifes;
public int FrameRate;
public int BuildType;
- public string BuildPath;
+ public string BuildPath=" ";
public string CommandLine;
public string Aboutbox;
public uint MenuSize;
@@ -179,7 +179,7 @@ namespace CTFAK.MMFParser.MFA
Writer.WriteUInt32((uint) InitialLifes);
Writer.WriteInt32(FrameRate);
Writer.WriteInt32(BuildType);
- Writer.AutoWriteUnicode(BuildPath);
+ Writer.AutoWriteUnicode(BuildPath ?? "");
Writer.AutoWriteUnicode(unknown_string_2);
Writer.AutoWriteUnicode(CommandLine);
Writer.AutoWriteUnicode(Aboutbox);
diff --git a/CTFAK/MMFParser/Translation/MFAGenerator.cs b/CTFAK/MMFParser/Translation/MFAGenerator.cs
index aeae949..05a4875 100644
--- a/CTFAK/MMFParser/Translation/MFAGenerator.cs
+++ b/CTFAK/MMFParser/Translation/MFAGenerator.cs
@@ -44,7 +44,7 @@ namespace CTFAK.MMFParser.Translation
}
else mfaReader = new ByteReader(TemplatePath, FileMode.Open);
Logger.Log("Loading images");
- Exe.Instance.GameData.GameChunks.GetChunk().PreloadOnly = false;
+ if(Program.CleanData.GameChunks.GetChunk()!=null)Program.CleanData.GameChunks.GetChunk().PreloadOnly = false;
// Exe.Instance.GameData.GameChunks.GetChunk().Read(true,false);
// Exe.Instance.GameData.GameChunks.GetChunk().Read();
@@ -54,11 +54,11 @@ namespace CTFAK.MMFParser.Translation
Pame2Mfa.Message("Loading Template");
template.Read(); //Loading template
Pame2Mfa.Message("Translating...");
- Pame2Mfa.Translate(ref template, Exe.Instance.GameData); //Translation
+ Pame2Mfa.Translate(ref template, Program.CleanData); //Translation
var mfaWriter =
new ByteWriter(
- Settings.GameName.Length > 0 ? $"{Settings.DumpPath}\\{Path.GetFileNameWithoutExtension(Exe.Instance.GameData.GameChunks.GetChunk().Value)}.mfa" : "out.mfa",
+ Program.CleanData.GameChunks.GetChunk().Value.Length > 0 ? $"{Settings.DumpPath}\\{Path.GetFileNameWithoutExtension(Program.CleanData.GameChunks.GetChunk().Value)}.mfa" : "out.mfa",
FileMode.Create); //New writer for new MFA
Pame2Mfa.Message("");
Pame2Mfa.Message("Writing MFA");
diff --git a/CTFAK/MMFParser/Translation/PAME2MFA.cs b/CTFAK/MMFParser/Translation/PAME2MFA.cs
index 1e6d2c4..ea81c49 100644
--- a/CTFAK/MMFParser/Translation/PAME2MFA.cs
+++ b/CTFAK/MMFParser/Translation/PAME2MFA.cs
@@ -17,6 +17,7 @@ using Backdrop = CTFAK.MMFParser.MFA.Loaders.mfachunks.Backdrop;
using ChunkList = CTFAK.MMFParser.MFA.Loaders.ChunkList;
using Counter = CTFAK.MMFParser.MFA.Loaders.mfachunks.Counter;
using Events = CTFAK.MMFParser.MFA.Loaders.Events;
+using Extension = CTFAK.MMFParser.EXE.Loaders.Extension;
using Frame = CTFAK.MMFParser.EXE.Loaders.Frame;
using Layer = CTFAK.MMFParser.MFA.Loaders.Layer;
using Movement = CTFAK.MMFParser.MFA.Loaders.mfachunks.Movement;
@@ -145,10 +146,12 @@ namespace CTFAK.MMFParser.Translation
newFrame.Password = "";
newFrame.LastViewedX = 320;
newFrame.LastViewedY = 240;
+ if (frame.Palette == null) continue;
newFrame.Palette = frame.Palette;
newFrame.StampHandle = 13;
newFrame.ActiveLayer = 0;
//LayerInfo
+ if(frame.Layers==null) continue;
var count = frame.Layers.Count;
Logger.Log($"{newFrame.Name} - {count}");
for (int i=0;i() {(uint) newFrameItem.Handle};
newFrame.Folders.Add(newFolder);
}
-
- if (frame.Events != null)
{
newFrame.Events = new Events((ByteReader) null);
newFrame.Events.Items = new List();
newFrame.Events.Objects = new List();
newFrame.Events._ifMFA = true;
newFrame.Events.Version = 1028;
+ if(frame.Events != null)
{
foreach (var item in newFrame.Items)
{
@@ -234,9 +236,14 @@ namespace CTFAK.MMFParser.Translation
newObject.InstanceHandle = 0xFFFFFFFF;
newFrame.Events.Objects.Add(newObject);
}
- newFrame.Events.Items = frame.Events.Items;
+
+ foreach (EventGroup item in frame.Events.Items)
+ {
+ newFrame.Events.Items.Add(item);
+ }
}
}
+
mfa.Frames.Add(newFrame);
@@ -403,7 +410,7 @@ namespace CTFAK.MMFParser.Translation
{
if (animHeader.AnimationDict.ContainsKey(origAnim.Key))
{
- animation = animHeader.AnimationDict[origAnim.Key];
+ animation = animHeader?.AnimationDict[origAnim.Key];
}
else break;
@@ -456,7 +463,7 @@ namespace CTFAK.MMFParser.Translation
newExt.Movements = newObject.Movements;
newExt.Behaviours = newObject.Behaviours;
}
- var exts = Exe.Instance.GameData.GameChunks.GetChunk();
+ var exts = Program.CleanData.GameChunks.GetChunk();
Extension ext = null;
foreach (var testExt in exts.Items)
{
@@ -492,20 +499,33 @@ namespace CTFAK.MMFParser.Translation
newText.Movements = newObject.Movements;
newText.Behaviours = newObject.Behaviours;
}
- newText.Width = (uint) text.Width;
- newText.Height = (uint) text.Height;
- var paragraph = text.Items[0];
- newText.Font = paragraph.FontHandle;
- newText.Color = paragraph.Color;
- newText.Flags = 0;
- newText.Items = new List();
- foreach (EXE.Loaders.Objects.Paragraph exePar in text.Items)
+ if (text == null)
{
- var newPar = new Paragraph((ByteReader) null);
- newPar.Value = exePar.Value;
- newPar.Flags = exePar.Flags.flag;
- newText.Items.Add(newPar);
+ newText.Width = 10;
+ newText.Height = 10;
+ newText.Font = 0;
+ newText.Color=Color.Black;
+ newText.Flags = 0;
+ newText.Items=new List();
+ }
+ else
+ {
+ newText.Width = (uint) text.Width;
+ newText.Height = (uint) text.Height;
+ var paragraph = text.Items[0];
+ newText.Font = paragraph.FontHandle;
+ newText.Color = paragraph.Color;
+ newText.Flags = 0;
+ newText.Items = new List();
+ foreach (EXE.Loaders.Objects.Paragraph exePar in text.Items)
+ {
+ var newPar = new Paragraph((ByteReader) null);
+ newPar.Value = exePar.Value;
+ newPar.Flags = exePar.Flags.flag;
+ newText.Items.Add(newPar);
+ }
}
+
newItem.Loader = newText;
}
@@ -545,9 +565,20 @@ namespace CTFAK.MMFParser.Translation
newCount.Movements = newObject.Movements;
newCount.Behaviours = newObject.Behaviours;
}
- newCount.Value = itemLoader.Counter.Initial;
- newCount.Maximum = itemLoader.Counter.Maximum;
- newCount.Minimum = itemLoader.Counter.Minimum;
+ if (itemLoader.Counter == null)
+ {
+ newCount.Value = 0;
+ newCount.Minimum = 0;
+ newCount.Maximum = 0;
+
+ }
+ else
+ {
+ newCount.Value = itemLoader.Counter.Initial;
+ newCount.Maximum = itemLoader.Counter.Maximum;
+ newCount.Minimum = itemLoader.Counter.Minimum;
+ }
+
newCount.Images = new List() {0};
var shape = counter?.Shape;
diff --git a/CTFAK/Program.cs b/CTFAK/Program.cs
index 97d65cc..b9d1a7f 100644
--- a/CTFAK/Program.cs
+++ b/CTFAK/Program.cs
@@ -62,6 +62,7 @@ namespace CTFAK
var reader = new ByteReader(new FileStream(args[0],FileMode.Open));
CleanData = new GameData();
CleanData.Read(reader);
+ MFAGenerator.BuildMFA();
}
}
diff --git a/CTFAK/Utils/Helper.cs b/CTFAK/Utils/Helper.cs
index 083a169..0596add 100644
--- a/CTFAK/Utils/Helper.cs
+++ b/CTFAK/Utils/Helper.cs
@@ -164,6 +164,11 @@ namespace CTFAK.Utils
item = new Click(reader);
}
+ if (code == 55)
+ {
+ item = new Extension(reader);
+ }
+
if (code == 38)
{
item = new CTFAK.MMFParser.EXE.Loaders.Events.Parameters.Group(reader);