MFA Writing is almost finished, fix extensions

master
1987kostya
parent a226652837
commit 938bc54838

@ -8,7 +8,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{86D99F9E-98FB-4E50-AB68-F5C115850C33}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<RootNamespace>CTFAK</RootNamespace>
<AssemblyName>CTFAK</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
@ -54,7 +54,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>DEBUG;TRACE;WIN64</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
@ -161,8 +161,13 @@
<Compile Include="GUI\MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="MMFParser\EXE\Loaders\Extensions.cs" />
<Compile Include="MMFParser\EXE\Loaders\Objects\Movements.cs" />
<Compile Include="MMFParser\EXE\Loaders\Objects\Text.cs" />
<Compile Include="MMFParser\MFA\Loaders\mfachunks\Backdrop.cs" />
<Compile Include="MMFParser\MFA\Loaders\mfachunks\Counter.cs" />
<Compile Include="MMFParser\MFA\Loaders\mfachunks\ExtensionObject.cs" />
<Compile Include="MMFParser\MFA\Loaders\mfachunks\Text.cs" />
<Compile Include="MMFParser\Translation\MFAGenerator.cs" />
<Compile Include="MMFParser\Translation\PAME2MFA.cs" />
<Compile Include="MMFParser\EXE\ChunkList.cs" />

@ -145,22 +145,22 @@ namespace CTFAK.GUI
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
var worker = new BackgroundWorker();
worker.DoWork += (workSender, workE) =>
if (File.Exists(openFileDialog1.FileName))
{
if (File.Exists(openFileDialog1.FileName))
{
objTreeView.Nodes.Clear();
StartReading();
}
else throw new NotImplementedException("File not found");
};
worker.RunWorkerCompleted += (workSender, workE) => { AfterLoad(); };
objTreeView.Nodes.Clear();
Loaded = false;
loadingLabel.Visible = true;
var worker = new BackgroundWorker();
worker.DoWork += (workSender, workE) => { StartReading(); };
worker.RunWorkerCompleted += (workSender, workE) => { AfterLoad(); };
worker.RunWorkerAsync();
worker.RunWorkerAsync();
}
else throw new NotImplementedException("File not found");
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
@ -185,8 +185,7 @@ namespace CTFAK.GUI
private void StartReading()
{
var path = openFileDialog1.FileName;
Loaded = false;
loadingLabel.Visible = true;
Program.ReadFile(path, Settings.Verbose, Settings.DumpImages, Settings.DumpSounds);
imageBar.Value = 0;

@ -97,7 +97,7 @@ namespace CTFAK.MMFParser.EXE
ChunkData = exeReader.ReadBytes(Size);
break;
}
Save();
//Save();
}
@ -193,6 +193,9 @@ namespace CTFAK.MMFParser.EXE
case 8752:
loader = new AppDoc(chunk);
break;
case 8756:
loader = new Extensions(chunk);
break;
case 8745:
loader = new FrameItems(chunk);
break;

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
@ -16,7 +17,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
public bool SaveImages = false;
public Dictionary<int, ImageItem> Images = new Dictionary<int, ImageItem>();
public uint NumberOfItems;
public bool PreloadOnly=true;
public bool PreloadOnly=false;
public ImageBank(ByteReader reader) : base(reader)
{
@ -95,7 +96,6 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
item.Read(!PreloadOnly);
tempImages.Add(item.Handle, item);
if (SaveImages) item.Save($"{Settings.ImagePath}\\" + item.Handle.ToString() + ".png");
OnImageSaved?.Invoke(i,(int) NumberOfItems);
@ -156,7 +156,11 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
public void Read(bool load)
{
Handle = Reader.ReadInt32();
if (Exe.Instance.GameData.ProductVersion != Constants.Products.MMF15&&Settings.Build>=284) Handle -= 1;
if (!Debug)
{
if (Exe.Instance.GameData.ProductVersion != Constants.Products.MMF15&&Settings.Build>=284) Handle -= 1;
}
Position = (int) Reader.Tell();
if (load) Load();
else Preload();
@ -165,7 +169,11 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
public override void Read()
{
Handle = Reader.ReadInt32();
if (Exe.Instance.GameData.ProductVersion != Constants.Products.MMF15&&Settings.Build>=284) Handle -= 1;
if (!Debug)
{
if (Exe.Instance.GameData.ProductVersion != Constants.Products.MMF15&&Settings.Build>=284) Handle -= 1;
}
Position = (int) Reader.Tell();
Load();
}
@ -442,7 +450,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Banks
chunk.WriteBytes(rawImg);
}
writer.WriteInt32(Handle + 1);
writer.WriteInt32(Handle);
writer.WriteWriter(chunk);
}

@ -0,0 +1,92 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CTFAK.Utils;
namespace CTFAK.MMFParser.EXE.Loaders
{
public class Extensions:ChunkLoader
{
internal ushort PreloadExtensions;
public List<Extension> Items;
public Extensions(ByteReader reader) : base(reader)
{
}
public Extensions(ChunkList.Chunk chunk) : base(chunk)
{
}
public override void Read()
{
var count = Reader.ReadUInt16();
PreloadExtensions = Reader.ReadUInt16();
Items = new List<Extension>();
for (int i = 0; i < count; i++)
{
var ext = new Extension(Reader);
ext.Read();
Items.Add(ext);
}
}
public override void Print(bool ext)
{
throw new System.NotImplementedException();
}
public override string[] GetReadableData()
{
throw new System.NotImplementedException();
}
}
public class Extension:ChunkLoader
{
public short Handle;
public int MagicNumber;
public int VersionLs;
public int VersionMs;
public string Name;
public string Ext;
public string SubType;
public Extension(ByteReader reader) : base(reader)
{
}
public Extension(ChunkList.Chunk chunk) : base(chunk)
{
}
public override void Read()
{
var currentPosition = Reader.Tell();
var size = Reader.ReadInt16();
if (size < 0)
{
size = (short) (size*-1);
}
Handle = Reader.ReadInt16();
MagicNumber = Reader.ReadInt32();
VersionLs = Reader.ReadInt32();
VersionMs = Reader.ReadInt32();
var arr = Reader.ReadWideString().Split('.');
Name = arr[0];
Logger.Log("Found Extension: "+Name+" with id "+Handle);
Ext = arr[1];
SubType = Reader.ReadWideString();
Reader.Seek(currentPosition+size);
}
public override void Print(bool ext)
{
throw new System.NotImplementedException();
}
public override string[] GetReadableData()
{
throw new System.NotImplementedException();
}
}
}

@ -59,6 +59,9 @@ namespace CTFAK.MMFParser.EXE.Loaders.Objects
public ushort Font;
public bool Inverse;
public bool AddNulls;
public ushort DisplayType;
public ushort Flags;
public ushort Player;
public Counters(ByteReader reader) : base(reader)
{
@ -74,21 +77,21 @@ namespace CTFAK.MMFParser.EXE.Loaders.Objects
var size = Reader.ReadUInt32();
Width = Reader.ReadUInt32();
Height = Reader.ReadUInt32();
var player = Reader.ReadUInt16();
var displayType = Reader.ReadUInt16();
var flags = Reader.ReadUInt16();
Player = Reader.ReadUInt16();
DisplayType = Reader.ReadUInt16();
Flags = Reader.ReadUInt16();
IntegerDigits = flags & _intDigitsMask;
FormatFloat = (flags & _formatFloat) != 0;
FloatDigits = (flags & _floatDigitsMask) >> _floatDigitsShift + 1;
UseDecimals = (flags & _useDecimals) != 0;
Decimals = (flags & _floatDecimalsMask) >> _floatDecimalsShift;
AddNulls = (flags & _floatPad) != 0;
IntegerDigits = Flags & _intDigitsMask;
FormatFloat = (Flags & _formatFloat) != 0;
FloatDigits = (Flags & _floatDigitsMask) >> _floatDigitsShift + 1;
UseDecimals = (Flags & _useDecimals) != 0;
Decimals = (Flags & _floatDecimalsMask) >> _floatDecimalsShift;
AddNulls = (Flags & _floatPad) != 0;
Inverse = ByteFlag.GetFlag(flags, 8);
Inverse = ByteFlag.GetFlag(Flags, 8);
Font = Reader.ReadUInt16();
if (displayType == 0) return;
else if (displayType == 1 || displayType == 4|| displayType==50)
if (DisplayType == 0) return;
else if (DisplayType == 1 || DisplayType == 4|| DisplayType==50)
{
Frames = new List<int>();
@ -98,7 +101,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Objects
Frames.Add(Reader.ReadUInt16());
}
}
else if (displayType == 2 || displayType == 3 || displayType == 5)
else if (DisplayType == 2 || DisplayType == 3 || DisplayType == 5)
{
//TODO: Shapes
Logger.Log("Ignoring unsupported counter type");

@ -88,6 +88,7 @@ namespace CTFAK.MMFParser.EXE.Loaders.Objects
public Movements Movements;
private ushort _zeroUnk;
public Text Text;
public Counter Counter;
public ObjectCommon(ByteReader reader) : base(reader)
@ -192,6 +193,13 @@ namespace CTFAK.MMFParser.EXE.Loaders.Objects
}
}
if (_counterOffset > 0)
{
Reader.Seek(currentPosition+_counterOffset);
Counter = new Counter(Reader);
Counter.Read();
}
// Logger.Log("anims: "+_animationsOffset);
// Logger.Log("fadeIn: "+_fadeinOffset);
// Logger.Log("fadeOut: "+_fadeoutOffset);

@ -72,7 +72,7 @@ namespace CTFAK.MMFParser.EXE
_bingo = exeReader.ReadInt32();
Data = exeReader.ReadBytes(exeReader.ReadInt32());
//Dump();
Dump();
}
public void Dump(string path = "[DEFAULT-PATH]")
{

@ -183,6 +183,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
public override void Write(ByteWriter Writer)
{
Writer.WriteUInt16(Version);
Writer.WriteUInt16(FrameType);
@ -362,6 +363,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
else if (ObjectType == 2)//ShortcutItemType
{
Code = Reader.ReadAscii(4);
Logger.Log("Code: "+Code);
if (Code == "OIC2")//IconBufferCode
{
IconBuffer = Reader.AutoReadUnicode();
@ -389,11 +391,11 @@ namespace CTFAK.MMFParser.MFA.Loaders
}
else if (ObjectType == 2)
{
Writer.WriteAscii(Code);
if (Code == "OIC2")
{
Writer.AutoWriteUnicode(IconBuffer);
}
// Writer.WriteAscii(Code);
// if (Code == "OIC2")
// {
// Writer.AutoWriteUnicode(IconBuffer);
// }
}
if (ObjectType == 3)
{

@ -101,14 +101,13 @@ namespace CTFAK.MMFParser.MFA.Loaders
var bytes = new byte[] {0x01,0x01,0x00,0x00, 0x00,0x00,0x00,0x00, 0x80,0x01,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x32,0x00, 0x00,0x00,0x32,0x00, 0x00,0x00,0x01,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00};
}
Writer.WriteInt32(Folders.Count);
foreach (var item in Folders)
{
item.Write(Writer);
}
// Writer.WriteAscii("AA");
Writer.WriteInt32(Instances.Count);
foreach (var item in Instances)
{

@ -19,11 +19,11 @@ namespace CTFAK.MMFParser.MFA.Loaders
public int IconType;
public int IconHandle;
public ChunkList Chunks;
public Active Loader;
public DataLoader Loader;
public override void Write(ByteWriter Writer)
{
Debug.Assert(ObjectType==2);
//Debug.Assert(ObjectType==2);
Writer.WriteInt32(this.ObjectType);
Writer.WriteInt32(Handle);
Writer.AutoWriteUnicode(Name);
@ -36,6 +36,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
Writer.WriteInt32(IconHandle);
Chunks.Write(Writer);
Logger.Log("Writing "+this.ObjectType);
Loader.Write(Writer);
@ -65,6 +66,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
if(IconType==1)
{
IconHandle = Reader.ReadInt32();
Logger.Log("IconHandle: "+IconHandle);
}
else
{

@ -9,7 +9,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
public List<uint> Items;
public string Name;
public uint UnkHeader;
public uint NonFolder;
public bool isRetard;
public ItemFolder(ByteReader reader) : base(reader)
{
@ -24,6 +24,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
UnkHeader = Reader.ReadUInt32();
if (UnkHeader == 0x70000004)
{
isRetard = false;
Name = Reader.AutoReadUnicode();
Items = new List<uint>();
var count = Reader.ReadUInt32();
@ -34,6 +35,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
}
else
{
isRetard = true;
Name = null;
Items = new List<uint>();
Items.Add(Reader.ReadUInt32());
@ -42,14 +44,15 @@ namespace CTFAK.MMFParser.MFA.Loaders
public override void Write(ByteWriter Writer)
{
if (Name == null)
if(isRetard)
{
Writer.WriteInt32(0x70000005);
Writer.WriteInt32(3);
Writer.WriteInt32((int) Items[0]);
}
else
{
Writer.WriteInt32(0x70000004);
if (Name == null) Name = "";
Writer.AutoWriteUnicode(Name);
Writer.WriteInt32(Items.Count);
foreach (var item in Items)

@ -26,7 +26,7 @@ namespace CTFAK.MMFParser.MFA.Loaders
public override void Write(ByteWriter Writer)
{
Writer.AutoWriteUnicode("");
Writer.AutoWriteUnicode(Name);
Writer.WriteInt32((int) Flags.flag);
Writer.WriteSingle(XCoefficient);
Writer.WriteSingle(YCoefficient);

@ -7,7 +7,7 @@ namespace CTFAK.MMFParser.MFA.Loaders.mfachunks
{
public class AnimationObject:ObjectLoader
{
public List<Animation> Items = new List<Animation>();
public Dictionary<int,Animation> Items = new Dictionary<int,Animation>();
public override void Read()
{
base.Read();
@ -19,7 +19,7 @@ namespace CTFAK.MMFParser.MFA.Loaders.mfachunks
{
var item = new Animation(Reader);
item.Read();
Items.Add(item);
Items.Add(i,item);
}
}
}
@ -29,7 +29,7 @@ namespace CTFAK.MMFParser.MFA.Loaders.mfachunks
base.Write(Writer);
Writer.WriteInt8(1);
Writer.WriteUInt32((uint) Items.Count);
foreach (Animation animation in Items)
foreach (Animation animation in Items.Values)
{
animation.Write(Writer);
}

@ -0,0 +1,61 @@
using CTFAK.MMFParser.EXE;
using CTFAK.Utils;
namespace CTFAK.MMFParser.MFA.Loaders.mfachunks
{
public class Backdrop:BackgroundLoader
{
public int Handle;
public Backdrop(ByteReader reader) : base(reader)
{
}
public Backdrop(EXE.ChunkList.Chunk chunk) : base(chunk)
{
}
public override void Read()
{
base.Read();
Handle = Reader.ReadInt32();
}
public override void Write(ByteWriter Writer)
{
base.Write(Writer);
Writer.WriteInt32(Handle);
}
}
public class BackgroundLoader : DataLoader
{
public uint ObstacleType;
public uint CollisionType;
public BackgroundLoader(ByteReader reader) : base(reader)
{
}
public BackgroundLoader(EXE.ChunkList.Chunk chunk) : base(chunk)
{
}
public override void Read()
{
ObstacleType = Reader.ReadUInt32();
CollisionType = Reader.ReadUInt32();
}
public override void Write(ByteWriter Writer)
{
Writer.WriteUInt32(ObstacleType);
Writer.WriteUInt32(CollisionType);
}
public override void Print()
{
throw new System.NotImplementedException();
}
}
}

@ -0,0 +1,75 @@
using System.Collections.Generic;
using System.Drawing;
using CTFAK.MMFParser.EXE.Loaders.Banks;
using CTFAK.Utils;
namespace CTFAK.MMFParser.MFA.Loaders.mfachunks
{
public class Counter:ObjectLoader
{
public int Value;
public int Minimum;
public int Maximum;
public uint DisplayType;
public uint Flags;
public Color Color1;
public uint VerticalGradient;
public Color Color2;
public int CountType;
public int Width;
public int Height;
public List<int> Images;
public uint Font;
public Counter(ByteReader reader) : base(reader)
{
}
public override void Read()
{
base.Read();
Value = Reader.ReadInt32();
Minimum = Reader.ReadInt32();
Maximum = Reader.ReadInt32();
DisplayType = Reader.ReadUInt32();
Flags = Reader.ReadUInt32();
Color1 = Reader.ReadColor();
Color2 = Reader.ReadColor();
VerticalGradient = Reader.ReadUInt32();
CountType = Reader.ReadInt32();
Width = Reader.ReadInt32();
Height = Reader.ReadInt32();
Images = new List<int>();
var imageCount = Reader.ReadUInt32();
for (int i = 0; i < imageCount; i++)
{
Images.Add((int) Reader.ReadUInt32());
}
Font = Reader.ReadUInt32();
}
public override void Write(ByteWriter Writer)
{
base.Write(Writer);
Writer.WriteInt32(Value);
Writer.WriteInt32(Minimum);
Writer.WriteInt32(Maximum);
Writer.WriteUInt32(DisplayType);
Writer.WriteUInt32(Flags);
Writer.WriteColor(Color1);;
Writer.WriteColor(Color2);;
Writer.WriteUInt32(VerticalGradient);
Writer.WriteInt32(CountType);
Writer.WriteInt32(Width);
Writer.WriteInt32(Height);
Writer.WriteInt32(Images.Count);
foreach (var item in Images)
{
Writer.WriteUInt32((uint) item);
}
Writer.WriteUInt32(Font);
}
}
}

@ -0,0 +1,64 @@
using CTFAK.Utils;
namespace CTFAK.MMFParser.MFA.Loaders.mfachunks
{
public class ExtensionObject:AnimationObject
{
public string ExtensionName;
public int ExtensionType;
public string Filename;
public uint Magic;
public string SubType;
public int ExtensionVersion;
public int ExtensionId;
public int ExtensionPrivate;
public byte[] ExtensionData;
public ExtensionObject(ByteReader reader) : base(reader)
{
}
public override void Read()
{
base.Read();
ExtensionType = Reader.ReadInt32();
if (ExtensionType == -1)
{
ExtensionName = Reader.AutoReadUnicode();
Filename = Reader.AutoReadUnicode();
Magic = Reader.ReadUInt32();
SubType = Reader.AutoReadUnicode();
}
var newReader = new ByteReader(Reader.ReadBytes((int) Reader.ReadUInt32()));
var dataSize = newReader.ReadInt32() - 20;
newReader.Skip(4);
ExtensionVersion = newReader.ReadInt32();
ExtensionId = newReader.ReadInt32();
ExtensionPrivate = newReader.ReadInt32();
ExtensionData = newReader.ReadBytes(dataSize);
}
public override void Write(ByteWriter Writer)
{
base.Write(Writer);
if (ExtensionType == -1)
{
Writer.AutoWriteUnicode(ExtensionName);
Writer.AutoWriteUnicode(Filename);
Writer.WriteUInt32(Magic);
Writer.AutoWriteUnicode(SubType);
}
Writer.WriteInt32(ExtensionData.Length+20);
Writer.WriteInt32(ExtensionData.Length+20);
Writer.WriteInt32(0);
Writer.WriteInt32(ExtensionVersion);
Writer.WriteInt32(ExtensionId);
Writer.WriteInt32(ExtensionPrivate);
Writer.WriteBytes(ExtensionData);
}
}
}

@ -0,0 +1,90 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using CTFAK.MMFParser.EXE;
using CTFAK.Utils;
namespace CTFAK.MMFParser.MFA.Loaders.mfachunks
{
public class Text:ObjectLoader
{
public List<Paragraph> Items;
public uint Width;
public uint Height;
public uint Font;
public Color Color;
public uint Flags;
public Text(ByteReader reader) : base(reader)
{
}
public override void Read()
{
base.Read();
Width = Reader.ReadUInt32();
Height = Reader.ReadUInt32();
Font = Reader.ReadUInt32();
Color = Reader.ReadColor();
Flags = Reader.ReadUInt32();
Debug.Assert(Reader.ReadUInt32()==0);
Items = new List<Paragraph>();
var parCount = Reader.ReadUInt32();
for (int i = 0; i < parCount; i++)
{
var par = new Paragraph(Reader);
par.Read();
Items.Add(par);
}
}
public override void Write(ByteWriter Writer)
{
base.Write(Writer);
Writer.WriteUInt32(Width);
Writer.WriteUInt32(Height);
Writer.WriteUInt32(Font);
Writer.WriteColor(Color);
Writer.WriteUInt32(Flags);
Writer.WriteInt32(0);
Writer.WriteUInt32((uint) Items.Count);
foreach (Paragraph paragraph in Items)
{
paragraph.Write(Writer);
}
}
}
public class Paragraph : DataLoader
{
public string Value;
public uint Flags;
public Paragraph(ByteReader reader) : base(reader)
{
}
public Paragraph(EXE.ChunkList.Chunk chunk) : base(chunk)
{
}
public override void Read()
{
Value = Reader.AutoReadUnicode();
Flags = Reader.ReadUInt32();
}
public override void Write(ByteWriter Writer)
{
Writer.AutoWriteUnicode(Value);
Writer.WriteUInt32(Flags);
}
public override void Print()
{
throw new System.NotImplementedException();
}
}
}

@ -59,8 +59,8 @@ namespace CTFAK.MMFParser.Translation
public static void ReadTestMFA()
{
var outputPath = Path.Combine(Path.GetDirectoryName(TemplatePath), "decompiled.mfa");
var mfaReader = new ByteReader(TemplatePath, FileMode.Open);
var outputPath = Path.Combine(Path.GetDirectoryName(@"C:\Users\ivani\Desktop\CTFResearch\284final.mfa"), "decompiled.mfa");
var mfaReader = new ByteReader(@"C:\Users\ivani\Desktop\CTFResearch\284final.mfa", FileMode.Open);
var template = new MFA.MFA(mfaReader);
Settings.DoMFA = true;
template.Read();

@ -3,16 +3,21 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using CTFAK.MMFParser.EXE;
using CTFAK.MMFParser.EXE.Loaders;
using CTFAK.MMFParser.EXE.Loaders.Objects;
using CTFAK.MMFParser.MFA.Loaders;
using CTFAK.MMFParser.MFA.Loaders.mfachunks;
using CTFAK.Utils;
using Animation = CTFAK.MMFParser.MFA.Loaders.mfachunks.Animation;
using AnimationDirection = CTFAK.MMFParser.MFA.Loaders.mfachunks.AnimationDirection;
using Backdrop = CTFAK.MMFParser.MFA.Loaders.mfachunks.Backdrop;
using ChunkList = CTFAK.MMFParser.MFA.Loaders.ChunkList;
using Counter = CTFAK.MMFParser.MFA.Loaders.mfachunks.Counter;
using Frame = CTFAK.MMFParser.EXE.Loaders.Frame;
using Layer = CTFAK.MMFParser.MFA.Loaders.Layer;
using Movement = CTFAK.MMFParser.MFA.Loaders.mfachunks.Movement;
using Paragraph = CTFAK.MMFParser.MFA.Loaders.mfachunks.Paragraph;
using Text = CTFAK.MMFParser.MFA.Loaders.mfachunks.Text;
namespace CTFAK.MMFParser.Translation
{
@ -20,11 +25,11 @@ namespace CTFAK.MMFParser.Translation
{
public static Dictionary<int, FrameItem> FrameItems;
public static event Program.DumperEvent OnMessage;
public static void Translate(ref MFA.MFA mfa, GameData game)
{
Message("Running Pame2MFA");
Message("Original MFA Build: "+mfa.BuildVersion);
Message("Original MFA Build: " + mfa.BuildVersion);
Message("");
// mfa.MfaBuild = 4;
// mfa.Product = (int) game.ProductVersion;
@ -33,10 +38,10 @@ namespace CTFAK.MMFParser.Translation
mfa.LangId = 8192;
mfa.Description = "";
mfa.Path = game.EditorFilename;
//mfa.Stamp = wtf;
//if (game.Fonts != null) mfa.Fonts = game.Fonts;
//mfa.Sounds = game.Sounds;
//foreach (var item in mfa.Sounds.Items)
//{
@ -50,7 +55,7 @@ namespace CTFAK.MMFParser.Translation
}
mfa.Author = game.Author ?? "";
mfa.Copyright = game.Copyright ??"";
mfa.Copyright = game.Copyright ?? "";
mfa.Company = "";
mfa.Version = "";
//TODO:Binary Files
@ -63,7 +68,7 @@ namespace CTFAK.MMFParser.Translation
mfa.WindowY = game.Header.WindowHeight;
mfa.BorderColor = game.Header.BorderColor;
mfa.HelpFile = "";
mfa.VitalizePreview = new byte[]{0x0};
mfa.VitalizePreview = new byte[] {0x0};
mfa.InitialScore = game.Header.InitialScore;
mfa.InitialLifes = game.Header.InitialLives;
mfa.FrameRate = game.Header.FrameRate;
@ -74,107 +79,243 @@ namespace CTFAK.MMFParser.Translation
? game?.AboutText
: "";
//TODO: Controls
//Object Section
FrameItems = new Dictionary<int,FrameItem>();
FrameItems = new Dictionary<int, FrameItem>();
for (int i = 0; i < game.Frameitems.ItemDict.Keys.Count; i++)
{
var key = game.Frameitems.ItemDict.Keys.ToArray()[i];
var item = game.Frameitems.ItemDict[key];
if (item.ObjectType != 2) continue;
//if (item.ObjectType != 2 && item.ObjectType != 1 && item.ObjectType != 3) break;
var newItem = new FrameItem(null);
newItem.Name = item.Name;
newItem.ObjectType = 2;//item.ObjectType;
newItem.ObjectType = item.ObjectType;
newItem.Handle = item.Handle;
newItem.Transparent = item.Transparent ? 1:0;
newItem.Transparent = item.Transparent ? 1 : 0;
newItem.InkEffect = item.InkEffect;
newItem.InkEffectParameter = item.InkEffectValue;
newItem.AntiAliasing = item.Antialias ? 1 : 0;
newItem.Flags = (int) item.Flags; //32 TODO:Fix this
newItem.IconHandle = 10;
newItem.IconHandle = 12;
newItem.Chunks = new ChunkList(null);
var itemLoader = (ObjectCommon)item.Properties.Loader;
//Only actives
//TODO:Other types of objects
var newLoader = new Active(null);
newLoader.ObjectFlags = (int) itemLoader.Flags.flag;//820
newLoader.NewObjectFlags = (int) itemLoader.NewFlags.flag;//8
newLoader.BackgroundColor = Color.FromArgb(0x0, 0xff, 0xff, 0xff);
//newLoader.Qualifiers;
newLoader.Strings = ConvertStrings(itemLoader.Strings);
newLoader.Values = ConvertValue(itemLoader.Values);
newLoader.Movements=new MFA.Loaders.mfachunks.Movements(null);
for (int j = 0; j < itemLoader.Movements.Items.Count; j++)
if (item.ObjectType == 1)
{
var mov = itemLoader.Movements.Items[j];
var newMov = new Movement(null);
newMov.Name = $"Movement #{j}";
newMov.Extension = "";
newMov.Identifier = (uint) mov.Type;
newMov.Player = mov.Player;
newMov.MovingAtStart = mov.MovingAtStart;
newMov.DirectionAtStart = mov.DirectionAtStart;
newLoader.Movements.Items.Add(newMov);
var backdropLoader = (EXE.Loaders.Objects.Backdrop) item.Properties.Loader;
var backdrop = new Backdrop((ByteReader) null);
backdrop.ObstacleType = (uint) backdropLoader.ObstacleType;
backdrop.CollisionType = (uint) backdropLoader.CollisionType;
backdrop.Handle = backdropLoader.Image;
//TODO:Implement QuickBackdrops
newItem.Loader = backdrop;
}
newLoader.Behaviours=new Behaviours(null);
//TODO: Transitions
if (itemLoader.Animations != null)
else
{
var animHeader = itemLoader.Animations;
for (int j = 0; j < animHeader.AnimationDict.Count; j++)
var itemLoader = (ObjectCommon) item.Properties.Loader;
//CommonSection
var newObject = new ObjectLoader(null);
newObject.ObjectFlags = (int) itemLoader.Flags.flag;
newObject.NewObjectFlags =(int) itemLoader.NewFlags.flag;
newObject.BackgroundColor = Color.FromArgb(0x0, 0xff, 0xff, 0xff);
//newLoader.Qualifiers;
newObject.Strings = ConvertStrings(itemLoader.Strings);
newObject.Values = ConvertValue(itemLoader.Values);
newObject.Movements = new MFA.Loaders.mfachunks.Movements(null);
for (int j = 0; j < itemLoader.Movements.Items.Count; j++)
{
var mov = itemLoader.Movements.Items[j];
var newMov = new Movement(null);
newMov.Name = $"Movement #{j}";
newMov.Extension = "";
newMov.Identifier = (uint) mov.Type;
newMov.Player = mov.Player;
newMov.MovingAtStart = mov.MovingAtStart;
newMov.DirectionAtStart = mov.DirectionAtStart;
newObject.Movements.Items.Add(newMov);
}
var newAnimation = new Animation(null);
var newDirections = new List<AnimationDirection>();
EXE.Loaders.Objects.Animation animation = null;
try
{
if (animHeader.AnimationDict.ContainsKey(j)) animation = animHeader.AnimationDict[j];
else break;
}
catch (Exception e)
newObject.Behaviours = new Behaviours(null);
if (item.ObjectType == 2)
{
var active = new Active(null);
//Shit Section
{
Console.WriteLine(e);
//throw;
active.ObjectFlags = newObject.ObjectFlags;
active.NewObjectFlags = newObject.NewObjectFlags;
active.BackgroundColor = newObject.BackgroundColor;
active.Strings = newObject.Strings;
active.Values = newObject.Values;
active.Movements = newObject.Movements;
active.Behaviours = newObject.Behaviours;
}
if (animation != null)
//TODO: Transitions
if (itemLoader.Animations != null)
{
for (int n = 0; n < 1; n++)
var animHeader = itemLoader.Animations;
for (int j = 0; j < animHeader.AnimationDict.Count; j++)
{
var direction = animation.DirectionDict.ToArray()[n].Value;
var newDirection = new AnimationDirection(null);
newDirection.MinSpeed = direction.MinSpeed;
newDirection.MaxSpeed = direction.MaxSpeed;
newDirection.Index = n;
newDirection.Repeat = direction.Repeat;
newDirection.BackTo = direction.BackTo;
newDirection.Frames = direction.Frames;
newDirections.Add(newDirection);
}
var origAnim = animHeader.AnimationDict.ToArray()[j];
var newAnimation = new Animation(null);
var newDirections = new List<AnimationDirection>();
EXE.Loaders.Objects.Animation animation = null;
try
{
if (animHeader.AnimationDict.ContainsKey(origAnim.Key))
{
animation = animHeader.AnimationDict[origAnim.Key];
}
else break;
newAnimation.Directions = newDirections;
}
catch
{
}
}
if (animation != null)
{
for (int n = 0; n < animation.DirectionDict.Count; n++)
{
var direction = animation.DirectionDict.ToArray()[n].Value;
var newDirection = new AnimationDirection(null);
newDirection.MinSpeed = direction.MinSpeed;
newDirection.MaxSpeed = direction.MaxSpeed;
newDirection.Index = n;
newDirection.Repeat = direction.Repeat;
newDirection.BackTo = direction.BackTo;
newDirection.Frames = direction.Frames;
newDirections.Add(newDirection);
}
newAnimation.Directions = newDirections;
}
newLoader.Items.Add(newAnimation);
active.Items.Add(j, newAnimation);
}
}
newItem.Loader = active;
}
}
newItem.Loader = newLoader;
FrameItems.Add(newItem.Handle,newItem);
if (item.ObjectType >= 32)
{
var newExt = new ExtensionObject(null);
{
newExt.ObjectFlags = newObject.ObjectFlags;
newExt.NewObjectFlags = newObject.NewObjectFlags;
newExt.BackgroundColor = newObject.BackgroundColor;
newExt.Strings = newObject.Strings;
newExt.Values = newObject.Values;
newExt.Movements = newObject.Movements;
newExt.Behaviours = newObject.Behaviours;
}
var exts = Exe.Instance.GameData.GameChunks.GetChunk<Extensions>();
Extension ext = null;
foreach (var testExt in exts.Items)
{
if (testExt.Handle == 1) ext = testExt;
}
newExt.ExtensionType = -1;
newExt.ExtensionName = ext.Name;
newExt.Filename = $"{ext.Name}.mfx";
newExt.Magic = (uint) ext.MagicNumber;
newExt.SubType = ext.SubType;
newExt.ExtensionVersion = itemLoader.ExtensionVersion;
newExt.ExtensionId = itemLoader.ExtensionId;
newExt.ExtensionPrivate = itemLoader.ExtensionPrivate;
newExt.ExtensionData = itemLoader.ExtensionData;
newItem.Loader = newExt;
// var tuple = new Tuple<int, string, string, int, byte[]>(ext.Handle, ext.Name, "",
// ext.MagicNumber, ext.SubType);
// mfa.Extensions.Add();
}
else if (item.ObjectType == 3)
{
var text = itemLoader.Text;
var newText = new Text(null);
//Shit Section
{
newText.ObjectFlags = newObject.ObjectFlags;
newText.NewObjectFlags = newObject.NewObjectFlags;
newText.BackgroundColor = newObject.BackgroundColor;
newText.Strings = newObject.Strings;
newText.Values = newObject.Values;
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<Paragraph>();
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;
}
else if (item.ObjectType == 7)
{
var counter = itemLoader.Counters;
var newCount = new Counter(null);
{
newCount.ObjectFlags = newObject.ObjectFlags;
newCount.NewObjectFlags = newObject.NewObjectFlags;
newCount.BackgroundColor = newObject.BackgroundColor;
newCount.Strings = newObject.Strings;
newCount.Values = newObject.Values;
newCount.Movements = newObject.Movements;
newCount.Behaviours = newObject.Behaviours;
}
newCount.Value = itemLoader.Counter.Initial;
newCount.Maximum = itemLoader.Counter.Maximum;
newCount.Minimum = itemLoader.Counter.Minimum;
if (counter == null)
{
newCount.DisplayType = 0;
newCount.CountType = 0;
newCount.Width = 0;
newCount.Height = 0;
newCount.Images=new List<int>(){0};
newCount.Font = 0;
}
else
{
newCount.DisplayType = counter.DisplayType;
newCount.CountType = counter.Inverse ? 1:0;
newCount.Width = (int) counter.Width;
newCount.Height = (int) counter.Height;
newCount.Images = counter.Frames;
newCount.Font = counter.Font;
}
newCount.Color1=Color.White;
newCount.Color2=Color.White;
newCount.Flags = 0;
newCount.VerticalGradient = 0;
newItem.Loader = newCount;
}
}
// if(newItem.Loader==null) throw new NotImplementedException("Unsupported Object");
FrameItems.Add(newItem.Handle, newItem);
}
mfa.Frames.Clear();
foreach (Frame frame in game.Frames)
{
//if(frame.Name!="what day")continue;
if (frame.Name != "title") continue;
var newFrame = new MFA.Loaders.Frame(null);
//FrameInfo
newFrame.Handle = game.Frames.IndexOf(frame);
@ -182,11 +323,11 @@ namespace CTFAK.MMFParser.Translation
newFrame.SizeX = frame.Width;
newFrame.SizeY = frame.Height;
newFrame.Background = frame.Background;
newFrame.FadeIn = frame.FadeIn!=null? ConvertTransition(frame.FadeIn):null;
newFrame.FadeOut = frame.FadeOut!=null? ConvertTransition(frame.FadeOut):null;
newFrame.FadeIn = frame.FadeIn != null ? ConvertTransition(frame.FadeIn) : null;
newFrame.FadeOut = frame.FadeOut != null ? ConvertTransition(frame.FadeOut) : null;
var mfaFlags = newFrame.Flags;
var originalFlags = frame.Flags;
mfaFlags["GrabDesktop"] = originalFlags["GrabDesktop"];
mfaFlags["KeepDisplay"] = originalFlags["KeepDisplay"];
mfaFlags["BackgroundCollisions"] = originalFlags["TotalCollisionMask"];
@ -204,7 +345,7 @@ namespace CTFAK.MMFParser.Translation
newFrame.StampHandle = 13;
newFrame.ActiveLayer = 0;
//LayerInfo
newFrame.Layers=new List<Layer>();
newFrame.Layers = new List<Layer>();
foreach (EXE.Loaders.Layer layer in frame.Layers.Items)
{
var newLayer = new Layer(null);
@ -219,7 +360,8 @@ namespace CTFAK.MMFParser.Translation
newLayer.YCoefficient = layer.YCoeff;
newFrame.Layers.Add(newLayer);
}
Message("Translating frame: "+newFrame.Name);
Message("Translating frame: " + newFrame.Name);
var newFrameItems = new List<FrameItem>();
var newInstances = new List<FrameInstance>();
if (frame.Objects != null)
@ -234,35 +376,40 @@ namespace CTFAK.MMFParser.Translation
if (FrameItems.ContainsKey(instance.ObjectInfo))
{
frameItem = FrameItems[instance.ObjectInfo];
newFrameItems.Add(frameItem);
var newInstance = new FrameInstance((ByteReader) null);
newInstance.X = instance.X;
newInstance.Y = instance.Y;
newInstance.Handle = i;
newInstance.Flags = 1;
newInstance.ParentType = (uint) instance.ParentType;
newInstance.ItemHandle = (uint) (instance.ObjectInfo + 3);
newInstance.ParentHandle = (uint) instance.ParentHandle; //0xffffffff;
newInstance.Layer = (uint) instance.Layer;
newInstances.Add(newInstance);
newFrameItems.Add(frameItem);
var newInstance = new FrameInstance((ByteReader) null);
newInstance.X = instance.X;
newInstance.Y = instance.Y;
newInstance.Handle = instance.Handle;
newInstance.Flags = instance.FrameItem.Flags;
newInstance.ParentType = (uint) instance.ParentType;
newInstance.ItemHandle = (uint) (instance.ObjectInfo);
newInstance.ParentHandle = 0xffffffff;
newInstance.Layer = (uint) instance.Layer;
newInstances.Add(newInstance);
// if(i==34) break;
}
}
}
newFrame.Items = newFrameItems;
newFrame.Instances = newInstances;
newFrame.Folders=new List<ItemFolder>();
newFrame.Folders = new List<ItemFolder>();
foreach (FrameItem newFrameItem in newFrame.Items)
{
var newFolder = new ItemFolder((ByteReader) null);
newFolder.Items=new List<uint>() {(uint) newFrameItem.Handle};
newFolder.isRetard = true;
newFolder.Items = new List<uint>() {(uint) newFrameItem.Handle};
newFrame.Folders.Add(newFolder);
}
//EventInfo
newFrame.Events = MFA.MFA.emptyEvents;
@ -270,26 +417,24 @@ namespace CTFAK.MMFParser.Translation
foreach (var item in newFrame.Items)
{
var newObject = new EventObject((ByteReader) null);
newObject.Handle = (uint) item.Handle;
newObject.Name = item.Name ??"";
newObject.Name = item.Name ?? "";
newObject.TypeName = "";
newObject.ItemType = (ushort) item.ObjectType;
newObject.ObjectType = 2;
newObject.ObjectType = (ushort) item.ObjectType;
newObject.Flags = 0;
newObject.ItemHandle = (uint) item.Handle;
newObject.InstanceHandle = 0xFFFFFFFF;
// newFrame.Events.Objects.Add(newObject);
//newFrame.Events.Objects.Add(newObject);
}
newFrame.Chunks = new ChunkList(null);
mfa.Frames.Add(newFrame);
}
}
public static MFA.Loaders.Transition ConvertTransition(EXE.Loaders.Transition gameTrans)
@ -321,6 +466,10 @@ namespace CTFAK.MMFParser.Translation
alterables.Items.Add(newValue);
}
}
else
{
return alterables;
}
return alterables;
}
@ -338,6 +487,10 @@ namespace CTFAK.MMFParser.Translation
alterables.Items.Add(newValue);
}
}
else
{
return alterables;
}
return alterables;
}
@ -353,4 +506,4 @@ namespace CTFAK.MMFParser.Translation
}
}
}

@ -9,6 +9,7 @@ using System.Web.Caching;
using System.Windows.Forms;
using CTFAK.GUI;
using CTFAK.MMFParser.EXE;
using CTFAK.MMFParser.Translation;
using CTFAK.Utils;
using Joveler.Compression.ZLib;
@ -52,6 +53,8 @@ namespace CTFAK
if (args.Length > 1)
{
ReadFile(args[1],true,false,false);
MFAGenerator.BuildMFA();
Environment.Exit(0);
}
else if(args.Length==0)
{

@ -32,7 +32,7 @@ namespace CTFAK.Utils
Console.WriteLine(Helper.GetCurrentTime()+text);
Console.ForegroundColor = ConsoleColor.White;
}
if(logToConsole) MainConsole.Message(text);
//if(logToConsole) MainConsole.Message(text);

Loading…
Cancel
Save