fixed image bank writing

created write method for menu
master
REDxEYE 4 years ago
parent 1f58fb0e05
commit fb6948182b

@ -96,14 +96,12 @@ namespace DotNetCTFDumper.GUI
this.ResumeLayout(false); this.ResumeLayout(false);
} }
private System.Windows.Forms.ScrollableControl scrollableControl1; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem deleteObjBtn;
private System.Windows.Forms.ToolStripMenuItem infoMenuItem; private System.Windows.Forms.ToolStripMenuItem infoMenuItem;
private System.Windows.Forms.ToolStripMenuItem nameMenuItem; private System.Windows.Forms.ToolStripMenuItem nameMenuItem;
private System.Windows.Forms.ToolStripMenuItem positionMenuItem; private System.Windows.Forms.ToolStripMenuItem positionMenuItem;
private System.Windows.Forms.ScrollableControl scrollableControl1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem deleteObjBtn;
#endregion #endregion
} }

@ -115,7 +115,6 @@
this.listBox1.Name = "listBox1"; this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(180, 281); this.listBox1.Size = new System.Drawing.Size(180, 281);
this.listBox1.TabIndex = 5; this.listBox1.TabIndex = 5;
// //
// GameInfo // GameInfo
// //
@ -302,7 +301,6 @@
this.showHexBtn.Text = "Show hex"; this.showHexBtn.Text = "Show hex";
this.showHexBtn.UseVisualStyleBackColor = false; this.showHexBtn.UseVisualStyleBackColor = false;
this.showHexBtn.Visible = false; this.showHexBtn.Visible = false;
// //
// dumpSortedBtn // dumpSortedBtn
// //
@ -325,7 +323,6 @@
this.ChunkCombo.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.saveChunkBtn, this.viewHexBtn, this.previewFrameBtn}); this.ChunkCombo.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.saveChunkBtn, this.viewHexBtn, this.previewFrameBtn});
this.ChunkCombo.Name = "Save"; this.ChunkCombo.Name = "Save";
this.ChunkCombo.Size = new System.Drawing.Size(152, 70); this.ChunkCombo.Size = new System.Drawing.Size(152, 70);
this.ChunkCombo.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ChunkCombo_ItemSelected); this.ChunkCombo.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ChunkCombo_ItemSelected);
// //
// saveChunkBtn // saveChunkBtn
@ -443,33 +440,30 @@
this.PerformLayout(); this.PerformLayout();
} }
private System.Windows.Forms.ToolStripMenuItem previewFrameBtn;
private System.Windows.Forms.Button musicsButton;
private System.Windows.Forms.ProgressBar imageBar;
private System.Windows.Forms.Label imageLabel;
private System.Windows.Forms.Button imagesButton;
private System.Windows.Forms.ProgressBar musicBar;
private System.Windows.Forms.Label musicLabel;
private System.Windows.Forms.ProgressBar soundBar;
private System.Windows.Forms.Label soundLabel;
private System.Windows.Forms.Button soundsButton;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private System.Windows.Forms.ContextMenuStrip ChunkCombo; private System.Windows.Forms.ContextMenuStrip ChunkCombo;
private System.Windows.Forms.Button cryptKeyBtn; private System.Windows.Forms.Button cryptKeyBtn;
private System.Windows.Forms.Button dumpSortedBtn; private System.Windows.Forms.Button dumpSortedBtn;
private System.Windows.Forms.Button FolderBTN; private System.Windows.Forms.Button FolderBTN;
private System.Windows.Forms.Label GameInfo; private System.Windows.Forms.Label GameInfo;
private System.Windows.Forms.ProgressBar imageBar;
private System.Windows.Forms.Label imageLabel;
private System.Windows.Forms.Button imagesButton;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label loadingLabel; private System.Windows.Forms.Label loadingLabel;
private System.Windows.Forms.Button MFABtn; private System.Windows.Forms.Button MFABtn;
private System.Windows.Forms.ProgressBar musicBar;
private System.Windows.Forms.Label musicLabel;
private System.Windows.Forms.Button musicsButton;
private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Button packDataBtn; private System.Windows.Forms.Button packDataBtn;
private System.Windows.Forms.ToolStripMenuItem previewFrameBtn;
private System.Windows.Forms.ToolStripMenuItem saveChunkBtn; private System.Windows.Forms.ToolStripMenuItem saveChunkBtn;
private System.Windows.Forms.Button showHexBtn; private System.Windows.Forms.Button showHexBtn;
private System.Windows.Forms.ProgressBar soundBar;
private System.Windows.Forms.Label soundLabel;
private System.Windows.Forms.Button soundsButton;
private System.Windows.Forms.TreeView treeView1; private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.ToolStripMenuItem viewHexBtn; private System.Windows.Forms.ToolStripMenuItem viewHexBtn;

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Numerics;
using DotNetCTFDumper.MMFParser.ChunkLoaders; using DotNetCTFDumper.MMFParser.ChunkLoaders;
using DotNetCTFDumper.MMFParser.ChunkLoaders.Banks; using DotNetCTFDumper.MMFParser.ChunkLoaders.Banks;
using DotNetCTFDumper.MMFParser.MFALoaders; using DotNetCTFDumper.MMFParser.MFALoaders;
@ -27,6 +28,8 @@ namespace DotNetCTFDumper.MMFParser.Data
public string Description; public string Description;
public string Path; public string Path;
public List<byte[]> BinaryFiles = new List<byte[]>();
public FontBank Fonts; public FontBank Fonts;
public SoundBank Sounds; public SoundBank Sounds;
public MusicBank Music; public MusicBank Music;
@ -47,6 +50,7 @@ namespace DotNetCTFDumper.MMFParser.Data
public ValueList GlobalValues; public ValueList GlobalValues;
public ValueList GlobalStrings; public ValueList GlobalStrings;
public Color BorderColor; public Color BorderColor;
public BitDict DisplayFlags = new BitDict(new string[] public BitDict DisplayFlags = new BitDict(new string[]
{ {
"MaximizedOnBoot", "MaximizedOnBoot",
@ -63,9 +67,9 @@ namespace DotNetCTFDumper.MMFParser.Data
"NoCenter", "NoCenter",
"DisableClose", "DisableClose",
"HiddenAtStart", "HiddenAtStart",
"MDI" "MDI"
}); });
public BitDict GraphicFlags = new BitDict(new string[] public BitDict GraphicFlags = new BitDict(new string[]
{ {
"MultiSamples", "MultiSamples",
@ -83,8 +87,10 @@ namespace DotNetCTFDumper.MMFParser.Data
"NoDebugger", "NoDebugger",
"NoSubappSharing" "NoSubappSharing"
}); });
public string HelpFile; public string HelpFile;
public int VitalizePreview; public string unknown_string; //Found in original mfa build 283
public byte[] VitalizePreview;
public int InitialScore; public int InitialScore;
public int InitialLifes; public int InitialLifes;
public int FrameRate; public int FrameRate;
@ -95,7 +101,7 @@ namespace DotNetCTFDumper.MMFParser.Data
public uint MenuSize; public uint MenuSize;
public AppMenu Menu; public AppMenu Menu;
private int windowMenuIndex; private int windowMenuIndex;
private int[] menuImages; private Dictionary<Int32, Int32> menuImages;
private byte[] GlobalEvents; private byte[] GlobalEvents;
private int GraphicMode; private int GraphicMode;
private int IcoCount; private int IcoCount;
@ -107,18 +113,15 @@ namespace DotNetCTFDumper.MMFParser.Data
public List<Frame> Frames; public List<Frame> Frames;
public override void Print() public override void Print()
{ {
//Logger.Log($"MFA Product:{product}"); //Logger.Log($"MFA Product:{product}");
//Logger.Log($"MFA Build:{mfaBuild}"); //Logger.Log($"MFA Build:{mfaBuild}");
//Logger.Log($"MFA Product:{buildVersion}"); //Logger.Log($"MFA Product:{buildVersion}");
} }
public override void Write(ByteWriter Writer) public override void Write(ByteWriter Writer)
{ {
Writer.WriteAscii("MFU2"); Writer.WriteAscii("MFU2");
Writer.WriteInt32(MfaBuild); Writer.WriteInt32(MfaBuild);
Writer.WriteInt32(Product); Writer.WriteInt32(Product);
@ -128,25 +131,25 @@ namespace DotNetCTFDumper.MMFParser.Data
Writer.AutoWriteUnicode(Description); Writer.AutoWriteUnicode(Description);
Writer.AutoWriteUnicode(Path); Writer.AutoWriteUnicode(Path);
Writer.WriteUInt32((uint)Stamp.Length); Writer.WriteUInt32((uint) Stamp.Length);
Writer.WriteBytes(Stamp); Writer.WriteBytes(Stamp);
Writer.WriteAscii(FontBankId); Writer.WriteAscii(FontBankId);
Fonts.Write(Writer); Fonts.Write(Writer);
Writer.WriteAscii(SoundBankId); Writer.WriteAscii(SoundBankId);
Sounds.Write(Writer); Sounds.Write(Writer);
Writer.WriteAscii(MusicBankId); Writer.WriteAscii(MusicBankId);
//music.Write(); // music.Write();
Writer.WriteInt32(0);//someone is using musics lol? Writer.WriteInt32(0); //someone is using musics lol?
//TODO: Do music //TODO: Do music
Writer.WriteAscii(ImageBankId); Writer.WriteAscii(ImageBankId);
Icons.Write(Writer); Icons.Write(Writer);
Writer.WriteAscii(ImageBankId); Writer.WriteAscii(ImageBankId);
Images.Write(Writer); Images.Write(Writer);
Writer.AutoWriteUnicode(Name); Writer.AutoWriteUnicode(Name);
Writer.AutoWriteUnicode(Author); Writer.AutoWriteUnicode(Author);
Writer.AutoWriteUnicode(Description); Writer.AutoWriteUnicode(Description);
@ -158,6 +161,10 @@ namespace DotNetCTFDumper.MMFParser.Data
Writer.WriteColor(Color.White); Writer.WriteColor(Color.White);
Writer.WriteInt32((int) DisplayFlags.flag); Writer.WriteInt32((int) DisplayFlags.flag);
Writer.WriteInt32((int) GraphicFlags.flag); Writer.WriteInt32((int) GraphicFlags.flag);
Writer.AutoWriteUnicode(HelpFile);
Writer.AutoWriteUnicode(unknown_string);
Writer.WriteInt32(VitalizePreview.Length);
Writer.WriteBytes(VitalizePreview);
Writer.WriteUInt32((uint) InitialScore); Writer.WriteUInt32((uint) InitialScore);
Writer.WriteUInt32((uint) InitialLifes); Writer.WriteUInt32((uint) InitialLifes);
Writer.WriteInt32(FrameRate); Writer.WriteInt32(FrameRate);
@ -165,35 +172,40 @@ namespace DotNetCTFDumper.MMFParser.Data
Writer.AutoWriteUnicode(BuildPath); Writer.AutoWriteUnicode(BuildPath);
Writer.AutoWriteUnicode(CommandLine); Writer.AutoWriteUnicode(CommandLine);
Writer.AutoWriteUnicode(Aboutbox); Writer.AutoWriteUnicode(Aboutbox);
Menu = null; //TODO:Menu
Writer.WriteInt32(BinaryFiles.Count);
foreach (byte[] binaryFile in BinaryFiles)
{
Writer.WriteInt32(binaryFile.Length);
Writer.WriteBytes(binaryFile);
}
Controls.Write(Writer);
// Menu = null; //TODO:Menu
if (Menu != null) if (Menu != null)
{ {
byte[] menuData = new byte[1]; //Menu.Generate; using (ByteWriter menuWriter = new ByteWriter(new MemoryStream()))
Writer.WriteInt32(menuData.Length); {
Writer.WriteBytes(menuData); Menu.Write(menuWriter);
Writer.WriteUInt32((uint) menuWriter.BaseStream.Position);
Writer.WriteWriter(menuWriter);
}
} }
else else
{ {
Writer.WriteInt32(0); Writer.WriteInt32(0);
} }
Writer.WriteInt32(windowMenuIndex);
Writer.WriteInt32(menuImages.Count);
foreach (KeyValuePair<int, int> valuePair in menuImages)
{
Writer.WriteInt32(valuePair.Key);
Writer.WriteInt32(valuePair.Value);
}
} }
public override void Read() public override void Read()
@ -216,7 +228,7 @@ namespace DotNetCTFDumper.MMFParser.Data
Sounds = new SoundBank(Reader); Sounds = new SoundBank(Reader);
Sounds.IsCompressed = false; Sounds.IsCompressed = false;
Sounds.Read(); Sounds.Read();
if (Reader.ReadAscii(4) != MusicBankId) throw new Exception("Invalid Music Bank"); if (Reader.ReadAscii(4) != MusicBankId) throw new Exception("Invalid Music Bank");
Music = new MusicBank(Reader); Music = new MusicBank(Reader);
Music.Read(); Music.Read();
@ -229,9 +241,9 @@ namespace DotNetCTFDumper.MMFParser.Data
Images = new AgmiBank(Reader); Images = new AgmiBank(Reader);
Images.Read(); Images.Read();
Helper.CheckPattern(Helper.AutoReadUnicode(Reader),Name); Helper.CheckPattern(Helper.AutoReadUnicode(Reader), Name);
Author = Helper.AutoReadUnicode(Reader); Author = Helper.AutoReadUnicode(Reader);
Helper.CheckPattern(Helper.AutoReadUnicode(Reader),Description); Helper.CheckPattern(Helper.AutoReadUnicode(Reader), Description);
Copyright = Helper.AutoReadUnicode(Reader); Copyright = Helper.AutoReadUnicode(Reader);
Company = Helper.AutoReadUnicode(Reader); Company = Helper.AutoReadUnicode(Reader);
Version = Helper.AutoReadUnicode(Reader); Version = Helper.AutoReadUnicode(Reader);
@ -241,11 +253,14 @@ namespace DotNetCTFDumper.MMFParser.Data
DisplayFlags.flag = Reader.ReadUInt32(); DisplayFlags.flag = Reader.ReadUInt32();
GraphicFlags.flag = Reader.ReadUInt32(); GraphicFlags.flag = Reader.ReadUInt32();
HelpFile = Helper.AutoReadUnicode(Reader); HelpFile = Helper.AutoReadUnicode(Reader);
VitalizePreview = Reader.ReadInt32(); unknown_string = Helper.AutoReadUnicode(Reader);
Int32 vit_size = Reader.ReadInt32();
VitalizePreview = Reader.ReadBytes(vit_size);
InitialScore = Reader.ReadInt32(); InitialScore = Reader.ReadInt32();
InitialLifes = Reader.ReadInt32(); InitialLifes = Reader.ReadInt32();
FrameRate = Reader.ReadInt32(); FrameRate = Reader.ReadInt32();
BuildType = Reader.ReadInt32(); BuildType = Reader.ReadInt32();
BuildPath = Helper.AutoReadUnicode(Reader); BuildPath = Helper.AutoReadUnicode(Reader);
//Console.WriteLine(BuildPath); //Console.WriteLine(BuildPath);
//Helper.CheckPattern(Reader.ReadInt32(),0); //Helper.CheckPattern(Reader.ReadInt32(),0);
@ -253,13 +268,14 @@ namespace DotNetCTFDumper.MMFParser.Data
CommandLine = Helper.AutoReadUnicode(Reader); CommandLine = Helper.AutoReadUnicode(Reader);
Aboutbox = Helper.AutoReadUnicode(Reader); Aboutbox = Helper.AutoReadUnicode(Reader);
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
for (int i = 0; i < binCount; i++) for (int i = 0; i < binCount; i++)
{ {
Reader.ReadBytes(Reader.ReadInt32());//binaryfiles BinaryFiles.Add(Reader.ReadBytes(Reader.ReadInt32()));
} }
Controls = new Controls(Reader); Controls = new Controls(Reader);
Controls.Read(); Controls.Read();
@ -270,24 +286,22 @@ namespace DotNetCTFDumper.MMFParser.Data
Reader.Seek(MenuSize + currentPosition); Reader.Seek(MenuSize + currentPosition);
windowMenuIndex = Reader.ReadInt32(); windowMenuIndex = Reader.ReadInt32();
menuImages = new int[65535];//govnokod suka menuImages = new Dictionary<Int32, Int32>();
var miCount = Reader.ReadInt32(); int miCount = Reader.ReadInt32();
for (int i = 0; i < miCount; i++) for (int i = 0; i < miCount; i++)
{ {
var id = Reader.ReadInt32(); int id = Reader.ReadInt32();
menuImages[id] = Reader.ReadInt32(); menuImages[id] = Reader.ReadInt32();
} }
GlobalValues = new ValueList(Reader); GlobalValues = new ValueList(Reader);
GlobalValues.Read(); GlobalValues.Read();
GlobalStrings = new ValueList(Reader); GlobalStrings = new ValueList(Reader);
GlobalStrings.Read(); GlobalStrings.Read();
GlobalEvents = Reader.ReadBytes(Reader.ReadInt32()); GlobalEvents = Reader.ReadBytes(Reader.ReadInt32());
GraphicMode = Reader.ReadInt32();; GraphicMode = Reader.ReadInt32();
;
IcoCount = Reader.ReadInt32(); IcoCount = Reader.ReadInt32();
@ -296,35 +310,37 @@ namespace DotNetCTFDumper.MMFParser.Data
{ {
IconImages.Add(Reader.ReadInt32()); IconImages.Add(Reader.ReadInt32());
} }
//I STUCK HERE //I STUCK HERE
QualCount = Reader.ReadInt32(); QualCount = Reader.ReadInt32();
CustomQuals = new List<Tuple<string, int>>(); CustomQuals = new List<Tuple<string, int>>();
for (int i = 0; i < QualCount; i++)//qualifiers for (int i = 0; i < QualCount; i++) //qualifiers
{ {
var name = Reader.ReadAscii(Reader.ReadInt32()); var name = Reader.ReadAscii(Reader.ReadInt32());
var handle = Reader.ReadInt32(); var handle = Reader.ReadInt32();
CustomQuals.Add(new Tuple<string,int>(name,handle)); CustomQuals.Add(new Tuple<string, int>(name, handle));
} }
var extCount = Reader.ReadInt32(); var extCount = Reader.ReadInt32();
Extensions = new List<Tuple<int, string, string, int, byte[]>>(); Extensions = new List<Tuple<int, string, string, int, byte[]>>();
for (int i = 0; i < extCount; i++)//extensions for (int i = 0; i < extCount; i++) //extensions
{ {
var handle = Reader.ReadInt32(); var handle = Reader.ReadInt32();
var filename = Helper.AutoReadUnicode(Reader); var filename = Helper.AutoReadUnicode(Reader);
var name = Helper.AutoReadUnicode(Reader); var name = Helper.AutoReadUnicode(Reader);
var magic = Reader.ReadInt32(); var magic = Reader.ReadInt32();
var data = Reader.ReadBytes(Reader.ReadInt32()); var data = Reader.ReadBytes(Reader.ReadInt32());
var tuple = new Tuple<int,string,string,int,byte[]>(handle,filename,name,magic,data); var tuple = new Tuple<int, string, string, int, byte[]>(handle, filename, name, magic, data);
Extensions.Add(tuple); Extensions.Add(tuple);
} }
List<int> frameOffsets = new List<int>(); List<int> frameOffsets = new List<int>();
var offCount = Reader.ReadInt32(); var offCount = Reader.ReadInt32();
for (int i = 0; i < offCount; i++) for (int i = 0; i < offCount; i++)
{ {
frameOffsets.Add(Reader.ReadInt32()); frameOffsets.Add(Reader.ReadInt32());
} }
var nextOffset = Reader.ReadInt32(); var nextOffset = Reader.ReadInt32();
Frames = new List<Frame>(); Frames = new List<Frame>();
foreach (var item in frameOffsets) foreach (var item in frameOffsets)
@ -333,25 +349,18 @@ namespace DotNetCTFDumper.MMFParser.Data
var testframe = new Frame(Reader); var testframe = new Frame(Reader);
testframe.Read(); testframe.Read();
Frames.Add(testframe); Frames.Add(testframe);
} }
Reader.Seek(nextOffset); Reader.Seek(nextOffset);
var chunks = new MFALoaders.ChunkList(Reader); var chunks = new MFALoaders.ChunkList(Reader);
chunks.Read(); chunks.Read();
return; return;
}
}
public MFA(ByteReader reader) : base(reader) public MFA(ByteReader reader) : base(reader)
{ {
} }
} }
} }

@ -6,7 +6,7 @@ namespace DotNetCTFDumper.MMFParser.Decompiling
{ {
public static class MFAGenerator public static class MFAGenerator
{ {
public static readonly string TemplatePath = @"C:\Users\ivani\Desktop\CTFResearch\testNoFrames.mfa"; public static readonly string TemplatePath = @"F:\CPP\DotNetCTFDumper\testNoFrames.mfa";
public static void BuildMFA() public static void BuildMFA()
{ {
@ -16,7 +16,7 @@ namespace DotNetCTFDumper.MMFParser.Decompiling
template.Read(); //Loading template template.Read(); //Loading template
var gameMFA = template;//Pame2Mfa.Translate(template, Exe.LatestInst.GameData); //Translation var gameMFA = template; //Pame2Mfa.Translate(template, Exe.LatestInst.GameData); //Translation
var mfaWriter = var mfaWriter =
new ByteWriter( new ByteWriter(

@ -42,7 +42,7 @@ namespace DotNetCTFDumper.MMFParser.Decompiling
mfa.WindowY = game.Header.WindowHeight; mfa.WindowY = game.Header.WindowHeight;
mfa.BorderColor = game.Header.BorderColor; mfa.BorderColor = game.Header.BorderColor;
mfa.HelpFile = ""; mfa.HelpFile = "";
mfa.VitalizePreview = 0; mfa.VitalizePreview = new byte[]{0x0};
mfa.InitialScore = game.Header.InitialScore; mfa.InitialScore = game.Header.InitialScore;
mfa.InitialLifes = game.Header.InitialLives; mfa.InitialLifes = game.Header.InitialLives;
mfa.FrameRate = game.Header.FrameRate; mfa.FrameRate = game.Header.FrameRate;

@ -61,9 +61,9 @@ namespace DotNetCTFDumper.Utils
public void WriteInt16(short value)=>Write(value); public void WriteInt16(short value)=>Write(value);
public void WriteInt32(int value) => Write(value); public void WriteInt32(int value) => Write(value);
public void WriteInt64(long value) => Write(value); public void WriteInt64(long value) => Write(value);
public void WriteUInt16(ushort value) => Write(value); public void WriteUInt16(ushort value) => Write(value);
public void WriteUInt32(uint value) => Write(value); public void WriteUInt32(UInt32 value) => Write(value);
public void WriteUInt64(ulong value) => Write(value); public void WriteUInt64(ulong value) => Write(value);
public void WriteSingle(float value) => Write(value); public void WriteSingle(float value) => Write(value);
@ -94,7 +94,7 @@ namespace DotNetCTFDumper.Utils
WriteInt8(color.R); WriteInt8(color.R);
WriteInt8(color.G); WriteInt8(color.G);
WriteInt8(color.B); WriteInt8(color.B);
Skip(1); WriteInt8(0);
} }

@ -40,5 +40,23 @@ namespace DotNetCTFDumper.Utils
Array.Resize<byte>(ref decompressedData, decompSize); Array.Resize<byte>(ref decompressedData, decompSize);
return decompressedData; return decompressedData;
} }
public static byte[] compress_block(byte[] data)
{
ZLibCompressOptions compOpts = new ZLibCompressOptions();
compOpts.Level = ZLibCompLevel.Default;
MemoryStream decompressedStream = new MemoryStream(data);
MemoryStream compressedStream = new MemoryStream();
byte[] compressedData = null;
Int32 compressed_size = 0;
ZLibStream zs = new ZLibStream(compressedStream, compOpts);
decompressedStream.CopyTo(zs);
zs.Close();
compressedData = compressedStream.GetBuffer();
Array.Resize<byte>(ref compressedData, (int) zs.TotalOut);
return compressedData;
}
} }
} }

@ -13,7 +13,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
{ {
public class ImageBank : ChunkLoader public class ImageBank : ChunkLoader
{ {
public bool SaveImages=true; public bool SaveImages = true;
public Dictionary<int, ImageItem> Images = new Dictionary<int, ImageItem>(); public Dictionary<int, ImageItem> Images = new Dictionary<int, ImageItem>();
public uint NumberOfItems; public uint NumberOfItems;
@ -36,20 +36,21 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
$"Number of images: {NumberOfItems}" $"Number of images: {NumberOfItems}"
}; };
} }
public void Read(bool load,bool save)
public void Read(bool load, bool save)
{ {
var cache = Settings.DumpImages; var cache = Settings.DumpImages;
Settings.DumpImages = load; Settings.DumpImages = load;
SaveImages = save; SaveImages = save;
Read(); Read();
Settings.DumpImages = cache; Settings.DumpImages = cache;
} }
public override void Read() public override void Read()
{ {
if (!Settings.DoMFA)Reader.Seek(0);//Reset the reader to avoid bugs when dumping more than once if (!Settings.DoMFA) Reader.Seek(0); //Reset the reader to avoid bugs when dumping more than once
Images = new Dictionary<int, ImageItem>(); Images = new Dictionary<int, ImageItem>();
NumberOfItems = Reader.ReadUInt32(); NumberOfItems = Reader.ReadUInt32();
@ -67,11 +68,11 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
var item = new ImageItem(Reader); var item = new ImageItem(Reader);
item.Read(); item.Read();
Images.Add(item.Handle, item); Images.Add(item.Handle, item);
if(SaveImages)item.Save($"{Settings.ImagePath}\\" + item.Handle.ToString() + ".png"); if (SaveImages) item.Save($"{Settings.ImagePath}\\" + item.Handle.ToString() + ".png");
Helper.OnImageSaved(i, (int) NumberOfItems); Helper.OnImageSaved(i, (int) NumberOfItems);
if (Exe.Instance.GameData.ProductBuild >= 284) if (Exe.Instance.GameData.ProductBuild >= 284)
item.Handle -= 1; item.Handle -= 1;
@ -123,7 +124,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
public override void Read() public override void Read()
{ {
Handle = Reader.ReadInt32()-1; Handle = Reader.ReadInt32() - 1;
Position = (int) Reader.Tell(); Position = (int) Reader.Tell();
Load(); Load();
} }
@ -228,23 +229,20 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
public void Save(string filename) public void Save(string filename)
{ {
using (var bmp = new Bitmap(_width, _height, PixelFormat.Format32bppArgb))
using (var bmp = new Bitmap(_width, _height, PixelFormat.Format32bppArgb)) {
{ BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0,
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width,
bmp.Width, bmp.Height),
bmp.Height), ImageLockMode.WriteOnly,
ImageLockMode.WriteOnly, bmp.PixelFormat);
bmp.PixelFormat);
IntPtr pNative = bmpData.Scan0; IntPtr pNative = bmpData.Scan0;
Marshal.Copy(_colorArray, 0, pNative, _colorArray.Length); Marshal.Copy(_colorArray, 0, pNative, _colorArray.Length);
bmp.UnlockBits(bmpData); bmp.UnlockBits(bmpData);
bmp.Save(filename); bmp.Save(filename);
} }
} }
public Bitmap Bitmap public Bitmap Bitmap
@ -265,50 +263,67 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
Marshal.Copy(_colorArray, 0, pNative, _colorArray.Length); Marshal.Copy(_colorArray, 0, pNative, _colorArray.Length);
_bitmap.UnlockBits(bmpData); _bitmap.UnlockBits(bmpData);
} }
return _bitmap; return _bitmap;
} }
}
// private byte[] GenerateImage()
// {
// Int32 pad = ImageHelper.GetPadding(_width, 3);
// byte[] points = new byte[(_width * _height + pad * _height)*3];
// for (UInt32 y = 0; y < _height; y++)
// {
// for (UInt32 x = 0; x < _height; x++)
// {
//
// }
// }
//
// return points;
// }
}
public void Write(ByteWriter writer) public void Write(ByteWriter writer)
{ {
ByteWriter chunk = new ByteWriter(new MemoryStream()); ByteWriter chunk = new ByteWriter(new MemoryStream());
chunk.WriteInt32(_checksum); chunk.WriteInt32(_checksum);
chunk.WriteInt32(_references); chunk.WriteInt32(_references);
chunk.WriteInt32(_colorArray.Length); byte[] compressedImg = null;
chunk.WriteInt16((short) _width); if (Flags["LZX"])
chunk.WriteInt16((short) _height);
chunk.WriteInt8((byte) _graphicMode);
if (Flags["Alpha"])
{ {
chunk.WriteInt8(16); compressedImg = Decompressor.compress_block(rawImg);
chunk.WriteUInt32((uint) compressedImg.Length+4);
} }
else else
{ {
chunk.WriteInt8(0); chunk.WriteUInt32((uint) rawImg.Length);
} }
chunk.Skip(2); chunk.WriteInt16((short) _width);
chunk.WriteInt16((short) _height);
chunk.WriteInt8((byte) _graphicMode);
chunk.WriteInt8((byte) Flags.flag);
chunk.WriteInt16(0);
chunk.WriteInt16((short) XHotspot); chunk.WriteInt16((short) XHotspot);
chunk.WriteInt16((short) YHotspot); chunk.WriteInt16((short) YHotspot);
chunk.WriteInt16((short) ActionX); chunk.WriteInt16((short) ActionX);
chunk.WriteInt16((short) ActionY); chunk.WriteInt16((short) ActionY);
chunk.WriteBytes(_transparent); chunk.WriteBytes(_transparent);
if (Flags["LZX"])
{
chunk.WriteInt32(rawImg.Length);
chunk.WriteBytes(compressedImg);
}
else
{
chunk.WriteBytes(rawImg);
}
chunk.WriteBytes(_colorArray); writer.WriteInt32(Handle + 1);
if(Flags["Alpha"])chunk.WriteBytes(rawAlpha);
writer.WriteInt32(Handle);
writer.WriteWriter(chunk); writer.WriteWriter(chunk);
//MemoryStream ms = (MemoryStream) chunk.BaseStream;
//writer.WriteBytes(ms.GetBuffer());
} }

@ -13,7 +13,7 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders
private int GraphicMode; private int GraphicMode;
private int PaletteVersion; private int PaletteVersion;
private int PaletteEntries; private int PaletteEntries;
public Dictionary<int,ImageItem> Items = new Dictionary<int, ImageItem>(); public Dictionary<int, ImageItem> Items = new Dictionary<int, ImageItem>();
private List<Color> Palette; private List<Color> Palette;
public override void Print() public override void Print()
@ -32,28 +32,25 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders
PaletteEntries = Reader.ReadInt16(); PaletteEntries = Reader.ReadInt16();
Logger.Log($"PaletteEntries:{PaletteEntries}"); Logger.Log($"PaletteEntries:{PaletteEntries}");
Palette = new List<Color>();//Color[256]; Palette = new List<Color>();
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
{ {
Palette.Add(Reader.ReadColor()); Palette.Add(Reader.ReadColor());
} }
var count = Reader.ReadInt32(); var count = Reader.ReadInt32();
Logger.Log($"Number of image items: {count.ToString()}"); Logger.Log($"Number of image items: {count.ToString()}");
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
var item = new ImageItem(Reader); var item = new ImageItem(Reader);
item.Debug = true; item.Debug = true;
item.Read(); item.Read();
//item.Save($"{Settings.ImagePath}\\{i}.png"); //item.Save($"{Settings.ImagePath}\\{i}.png");
Items.Add(item.Handle,item); Items.Add(item.Handle, item);
} }
} }
public override void Write(ByteWriter writer) public override void Write(ByteWriter writer)
{ {
@ -65,12 +62,14 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders
writer.WriteColor(Palette[i]); writer.WriteColor(Palette[i]);
} }
writer.WriteInt32(0);//(Items.Count);
writer.WriteInt32(Items.Count);
foreach (var key in Items.Keys) foreach (var key in Items.Keys)
{ {
//Items[key].Write(writer); Items[key].Write(writer);
} }
} }
public AgmiBank(ByteReader reader) : base(reader) public AgmiBank(ByteReader reader) : base(reader)
{ {
} }
@ -79,4 +78,4 @@ namespace DotNetCTFDumper.MMFParser.MFALoaders
{ {
} }
} }
} }
Loading…
Cancel
Save