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);
}
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 nameMenuItem;
private System.Windows.Forms.ToolStripMenuItem positionMenuItem;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem deleteObjBtn;
private System.Windows.Forms.ScrollableControl scrollableControl1;
#endregion
}

@ -115,7 +115,6 @@
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(180, 281);
this.listBox1.TabIndex = 5;
//
// GameInfo
//
@ -302,7 +301,6 @@
this.showHexBtn.Text = "Show hex";
this.showHexBtn.UseVisualStyleBackColor = false;
this.showHexBtn.Visible = false;
//
// dumpSortedBtn
//
@ -325,7 +323,6 @@
this.ChunkCombo.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.saveChunkBtn, this.viewHexBtn, this.previewFrameBtn});
this.ChunkCombo.Name = "Save";
this.ChunkCombo.Size = new System.Drawing.Size(152, 70);
this.ChunkCombo.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ChunkCombo_ItemSelected);
//
// saveChunkBtn
@ -443,33 +440,30 @@
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.ContextMenuStrip ChunkCombo;
private System.Windows.Forms.Button cryptKeyBtn;
private System.Windows.Forms.Button dumpSortedBtn;
private System.Windows.Forms.Button FolderBTN;
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.ListBox listBox1;
private System.Windows.Forms.Label loadingLabel;
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.Button packDataBtn;
private System.Windows.Forms.ToolStripMenuItem previewFrameBtn;
private System.Windows.Forms.ToolStripMenuItem saveChunkBtn;
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.ToolStripMenuItem viewHexBtn;

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Numerics;
using DotNetCTFDumper.MMFParser.ChunkLoaders;
using DotNetCTFDumper.MMFParser.ChunkLoaders.Banks;
using DotNetCTFDumper.MMFParser.MFALoaders;
@ -27,6 +28,8 @@ namespace DotNetCTFDumper.MMFParser.Data
public string Description;
public string Path;
public List<byte[]> BinaryFiles = new List<byte[]>();
public FontBank Fonts;
public SoundBank Sounds;
public MusicBank Music;
@ -47,6 +50,7 @@ namespace DotNetCTFDumper.MMFParser.Data
public ValueList GlobalValues;
public ValueList GlobalStrings;
public Color BorderColor;
public BitDict DisplayFlags = new BitDict(new string[]
{
"MaximizedOnBoot",
@ -64,8 +68,8 @@ namespace DotNetCTFDumper.MMFParser.Data
"DisableClose",
"HiddenAtStart",
"MDI"
});
public BitDict GraphicFlags = new BitDict(new string[]
{
"MultiSamples",
@ -83,8 +87,10 @@ namespace DotNetCTFDumper.MMFParser.Data
"NoDebugger",
"NoSubappSharing"
});
public string HelpFile;
public int VitalizePreview;
public string unknown_string; //Found in original mfa build 283
public byte[] VitalizePreview;
public int InitialScore;
public int InitialLifes;
public int FrameRate;
@ -95,7 +101,7 @@ namespace DotNetCTFDumper.MMFParser.Data
public uint MenuSize;
public AppMenu Menu;
private int windowMenuIndex;
private int[] menuImages;
private Dictionary<Int32, Int32> menuImages;
private byte[] GlobalEvents;
private int GraphicMode;
private int IcoCount;
@ -107,18 +113,15 @@ namespace DotNetCTFDumper.MMFParser.Data
public List<Frame> Frames;
public override void Print()
{
//Logger.Log($"MFA Product:{product}");
//Logger.Log($"MFA Build:{mfaBuild}");
//Logger.Log($"MFA Product:{buildVersion}");
}
public override void Write(ByteWriter Writer)
{
Writer.WriteAscii("MFU2");
Writer.WriteInt32(MfaBuild);
Writer.WriteInt32(Product);
@ -158,6 +161,10 @@ namespace DotNetCTFDumper.MMFParser.Data
Writer.WriteColor(Color.White);
Writer.WriteInt32((int) DisplayFlags.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) InitialLifes);
Writer.WriteInt32(FrameRate);
@ -165,34 +172,39 @@ namespace DotNetCTFDumper.MMFParser.Data
Writer.AutoWriteUnicode(BuildPath);
Writer.AutoWriteUnicode(CommandLine);
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)
{
byte[] menuData = new byte[1]; //Menu.Generate;
Writer.WriteInt32(menuData.Length);
Writer.WriteBytes(menuData);
using (ByteWriter menuWriter = new ByteWriter(new MemoryStream()))
{
Menu.Write(menuWriter);
Writer.WriteUInt32((uint) menuWriter.BaseStream.Position);
Writer.WriteWriter(menuWriter);
}
}
else
{
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);
}
}
@ -241,7 +253,10 @@ namespace DotNetCTFDumper.MMFParser.Data
DisplayFlags.flag = Reader.ReadUInt32();
GraphicFlags.flag = Reader.ReadUInt32();
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();
InitialLifes = Reader.ReadInt32();
FrameRate = Reader.ReadInt32();
@ -258,8 +273,9 @@ namespace DotNetCTFDumper.MMFParser.Data
for (int i = 0; i < binCount; i++)
{
Reader.ReadBytes(Reader.ReadInt32());//binaryfiles
BinaryFiles.Add(Reader.ReadBytes(Reader.ReadInt32()));
}
Controls = new Controls(Reader);
Controls.Read();
@ -270,24 +286,22 @@ namespace DotNetCTFDumper.MMFParser.Data
Reader.Seek(MenuSize + currentPosition);
windowMenuIndex = Reader.ReadInt32();
menuImages = new int[65535];//govnokod suka
var miCount = Reader.ReadInt32();
menuImages = new Dictionary<Int32, Int32>();
int miCount = Reader.ReadInt32();
for (int i = 0; i < miCount; i++)
{
var id = Reader.ReadInt32();
int id = Reader.ReadInt32();
menuImages[id] = Reader.ReadInt32();
}
GlobalValues = new ValueList(Reader);
GlobalValues.Read();
GlobalStrings = new ValueList(Reader);
GlobalStrings.Read();
GlobalEvents = Reader.ReadBytes(Reader.ReadInt32());
GraphicMode = Reader.ReadInt32();;
GraphicMode = Reader.ReadInt32();
;
IcoCount = Reader.ReadInt32();
@ -305,8 +319,8 @@ namespace DotNetCTFDumper.MMFParser.Data
var name = Reader.ReadAscii(Reader.ReadInt32());
var handle = Reader.ReadInt32();
CustomQuals.Add(new Tuple<string, int>(name, handle));
}
var extCount = Reader.ReadInt32();
Extensions = new List<Tuple<int, string, string, int, byte[]>>();
for (int i = 0; i < extCount; i++) //extensions
@ -319,12 +333,14 @@ namespace DotNetCTFDumper.MMFParser.Data
var tuple = new Tuple<int, string, string, int, byte[]>(handle, filename, name, magic, data);
Extensions.Add(tuple);
}
List<int> frameOffsets = new List<int>();
var offCount = Reader.ReadInt32();
for (int i = 0; i < offCount; i++)
{
frameOffsets.Add(Reader.ReadInt32());
}
var nextOffset = Reader.ReadInt32();
Frames = new List<Frame>();
foreach (var item in frameOffsets)
@ -333,25 +349,18 @@ namespace DotNetCTFDumper.MMFParser.Data
var testframe = new Frame(Reader);
testframe.Read();
Frames.Add(testframe);
}
Reader.Seek(nextOffset);
var chunks = new MFALoaders.ChunkList(Reader);
chunks.Read();
return;
}
}
public MFA(ByteReader reader) : base(reader)
{
}
}
}

@ -6,7 +6,7 @@ namespace DotNetCTFDumper.MMFParser.Decompiling
{
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()
{

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

@ -63,7 +63,7 @@ namespace DotNetCTFDumper.Utils
public void WriteInt64(long 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 WriteSingle(float value) => Write(value);
@ -94,7 +94,7 @@ namespace DotNetCTFDumper.Utils
WriteInt8(color.R);
WriteInt8(color.G);
WriteInt8(color.B);
Skip(1);
WriteInt8(0);
}

@ -40,5 +40,23 @@ namespace DotNetCTFDumper.Utils
Array.Resize<byte>(ref decompressedData, decompSize);
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;
}
}
}

@ -36,6 +36,7 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
$"Number of images: {NumberOfItems}"
};
}
public void Read(bool load, bool save)
{
var cache = Settings.DumpImages;
@ -43,8 +44,8 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
SaveImages = save;
Read();
Settings.DumpImages = cache;
}
public override void Read()
{
if (!Settings.DoMFA) Reader.Seek(0); //Reset the reader to avoid bugs when dumping more than once
@ -228,7 +229,6 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
public void Save(string filename)
{
using (var bmp = new Bitmap(_width, _height, PixelFormat.Format32bppArgb))
{
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0,
@ -243,8 +243,6 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
bmp.UnlockBits(bmpData);
bmp.Save(filename);
}
}
public Bitmap Bitmap
@ -265,50 +263,67 @@ namespace DotNetCTFDumper.MMFParser.ChunkLoaders.Banks
Marshal.Copy(_colorArray, 0, pNative, _colorArray.Length);
_bitmap.UnlockBits(bmpData);
}
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)
{
ByteWriter chunk = new ByteWriter(new MemoryStream());
chunk.WriteInt32(_checksum);
chunk.WriteInt32(_references);
chunk.WriteInt32(_colorArray.Length);
chunk.WriteInt16((short) _width);
chunk.WriteInt16((short) _height);
chunk.WriteInt8((byte) _graphicMode);
if (Flags["Alpha"])
byte[] compressedImg = null;
if (Flags["LZX"])
{
chunk.WriteInt8(16);
compressedImg = Decompressor.compress_block(rawImg);
chunk.WriteUInt32((uint) compressedImg.Length+4);
}
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) YHotspot);
chunk.WriteInt16((short) ActionX);
chunk.WriteInt16((short) ActionY);
chunk.WriteBytes(_transparent);
if (Flags["LZX"])
{
chunk.WriteInt32(rawImg.Length);
chunk.WriteBytes(compressedImg);
}
chunk.WriteBytes(_colorArray);
if(Flags["Alpha"])chunk.WriteBytes(rawAlpha);
writer.WriteInt32(Handle);
else
{
chunk.WriteBytes(rawImg);
}
writer.WriteInt32(Handle + 1);
writer.WriteWriter(chunk);
//MemoryStream ms = (MemoryStream) chunk.BaseStream;
//writer.WriteBytes(ms.GetBuffer());
}

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

Loading…
Cancel
Save