GUI cleanup

master
1987kostya 4 years ago
parent 345e7ce5f6
commit 53c7e45e2e

@ -8,7 +8,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{86D99F9E-98FB-4E50-AB68-F5C115850C33}</ProjectGuid> <ProjectGuid>{86D99F9E-98FB-4E50-AB68-F5C115850C33}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>CTFAK</RootNamespace> <RootNamespace>CTFAK</RootNamespace>
<AssemblyName>CTFAK</AssemblyName> <AssemblyName>CTFAK</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>

@ -752,7 +752,7 @@
this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
this.Location = new System.Drawing.Point(15, 15); this.Location = new System.Drawing.Point(15, 15);
this.Name = "MainForm"; this.Name = "MainForm";
this.Text = "DotNetCTFDumper"; this.Text = "CTFAK";
this.Load += new System.EventHandler(this.MainForm_Load); this.Load += new System.EventHandler(this.MainForm_Load);
this.ChunkCombo.ResumeLayout(false); this.ChunkCombo.ResumeLayout(false);
this.tabControl1.ResumeLayout(false); this.tabControl1.ResumeLayout(false);

@ -17,13 +17,15 @@ using CTFAK.MMFParser.EXE.Loaders.Banks;
using CTFAK.MMFParser.EXE.Loaders.Objects; using CTFAK.MMFParser.EXE.Loaders.Objects;
using CTFAK.MMFParser.Translation; using CTFAK.MMFParser.Translation;
using CTFAK.Utils; using CTFAK.Utils;
using Animation = CTFAK.MMFParser.EXE.Loaders.Objects.Animation;
using AnimationDirection = CTFAK.MMFParser.EXE.Loaders.Objects.AnimationDirection;
namespace CTFAK.GUI namespace CTFAK.GUI
{ {
public partial class MainForm : Form public partial class MainForm : Form
{ {
public delegate void IncrementSortedProgressBar(int all);
public delegate void SaveHandler(int index, int all);
public static bool IsDumpingImages; public static bool IsDumpingImages;
public static bool IsDumpingSounds; public static bool IsDumpingSounds;
public static bool IsDumpingMusics; public static bool IsDumpingMusics;
@ -33,10 +35,12 @@ namespace CTFAK.GUI
public static bool Loaded; public static bool Loaded;
public static Color ColorTheme = Color.FromArgb(223, 114, 38); public static Color ColorTheme = Color.FromArgb(223, 114, 38);
public delegate void SaveHandler(int index, int all); private bool _breakAnim;
private bool _isAnimRunning;
public delegate void IncrementSortedProgressBar(int all);
private bool _isAudioPlaying;
private SoundPlayer _soundPlayer;
public MainForm(Color color) public MainForm(Color color)
@ -52,29 +56,22 @@ namespace CTFAK.GUI
if (item is Button) item.BackColor = Color.FromArgb(30, 30, 30); if (item is Button) item.BackColor = Color.FromArgb(30, 30, 30);
if (item is Label) if (item is Label)
{
//item.BackColor = Color.Transparent; //item.BackColor = Color.Transparent;
item.Refresh(); item.Refresh();
} }
}
foreach (TabPage tabPage in tabControl1.TabPages) foreach (TabPage tabPage in tabControl1.TabPages)
{
foreach (Control item in tabPage.Controls) foreach (Control item in tabPage.Controls)
{ {
item.ForeColor = ColorTheme; item.ForeColor = ColorTheme;
if (!(item is PictureBox) && !(item is TabPage)&&!(item is Label)) item.BackColor = Color.Black; if (!(item is PictureBox) && !(item is TabPage) && !(item is Label)) item.BackColor = Color.Black;
if (item is Button) item.BackColor = Color.FromArgb(30, 30, 30); if (item is Button) item.BackColor = Color.FromArgb(30, 30, 30);
if (item is Label) if (item is Label)
{
//item.BackColor = Color.Transparent; //item.BackColor = Color.Transparent;
item.Refresh(); item.Refresh();
} }
}
}
foreach (var item in ChunkCombo.Items) foreach (var item in ChunkCombo.Items)
{ {
((ToolStripItem) item).ForeColor = ColorTheme; ((ToolStripItem) item).ForeColor = ColorTheme;
@ -87,16 +84,17 @@ namespace CTFAK.GUI
hexBox1.SelectionBackColor = Color.FromArgb(ColorTheme.R / 4, ColorTheme.G / 4, ColorTheme.B / 4); hexBox1.SelectionBackColor = Color.FromArgb(ColorTheme.R / 4, ColorTheme.G / 4, ColorTheme.B / 4);
hexBox1.ShadowSelectionColor = Color.FromArgb(150, ColorTheme.R / 4, ColorTheme.G / 4, ColorTheme.B / 4); hexBox1.ShadowSelectionColor = Color.FromArgb(150, ColorTheme.R / 4, ColorTheme.G / 4, ColorTheme.B / 4);
label1.Text = Settings.DumperVersion; label1.Text = Settings.DumperVersion;
Text = Settings.DumperVersion;
Pame2Mfa.OnMessage += (obj) => Pame2Mfa.OnMessage += obj =>
{ {
var date = DateTime.Now; var date = DateTime.Now;
string msg = (string) obj; var msg = (string) obj;
mfaLogBox.AppendText(msg.Length > 0 mfaLogBox.AppendText(msg.Length > 0
? $"[{date.Hour,2}:{date.Minute,2}:{date.Second,2}:{date.Millisecond,3}] {msg}\r\n" ? $"[{date.Hour,2}:{date.Minute,2}:{date.Second,2}:{date.Millisecond,3}] {msg}\r\n"
: "\r\n"); : "\r\n");
}; };
this.Closing += (a, e) => Closing += (a, e) =>
{ {
var dlg = MessageBox.Show("Are you sure you want to exit?", "Exiting", MessageBoxButtons.YesNo); var dlg = MessageBox.Show("Are you sure you want to exit?", "Exiting", MessageBoxButtons.YesNo);
if (dlg == DialogResult.Yes) Environment.Exit(0); if (dlg == DialogResult.Yes) Environment.Exit(0);
@ -104,39 +102,26 @@ namespace CTFAK.GUI
}; };
KeyPreview = true; KeyPreview = true;
tabControl1.Selecting += tabControl1_Selecting; tabControl1.Selecting += tabControl1_Selecting;
//tabControl1.TabPages.Remove(mfaTab);
} }
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e) private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{ {
if (!Loaded) if (!Loaded)
{
if (e.TabPage != mainTab) if (e.TabPage != mainTab)
e.Cancel = true; e.Cancel = true;
}
//_soundPlayer.Stop(); //_soundPlayer.Stop();
} }
private void openFileDialog1_FileOk(object sender, CancelEventArgs e) private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{ {
var worker = new BackgroundWorker(); var worker = new BackgroundWorker();
worker.DoWork += (workSender, workE) => worker.DoWork += (workSender, workE) =>
{ {
if(File.Exists(openFileDialog1.FileName)) StartReading(); if (File.Exists(openFileDialog1.FileName)) StartReading();
else throw new NotImplementedException("File not found"); else throw new NotImplementedException("File not found");
};
worker.RunWorkerCompleted += (workSender, workE) =>
{
AfterLoad();
}; };
worker.RunWorkerCompleted += (workSender, workE) => { AfterLoad(); };
worker.RunWorkerAsync(); worker.RunWorkerAsync();
} }
@ -151,12 +136,11 @@ namespace CTFAK.GUI
loadingLabel.Visible = false; loadingLabel.Visible = false;
listBox1.Items.Clear(); listBox1.Items.Clear();
var console = new MainConsole(); var console = new MainConsole();
this.Location= new Point(0,0); Location = new Point(0, 0);
this.Size= new Size(this.Size.Width-100,Screen.PrimaryScreen.Bounds.Height-120); Size = new Size(Size.Width - 100, Screen.PrimaryScreen.Bounds.Height - 120);
console.Show(); console.Show();
console.Location = new Point(this.Location.X+this.Size.Width-15,0); console.Location = new Point(Location.X + Size.Width - 15, 0);
console.Size=new Size(console.Size.Width,this.Size.Height); console.Size = new Size(console.Size.Width, Size.Height);
} }
@ -178,24 +162,16 @@ namespace CTFAK.GUI
musicsButton.Visible = false; musicsButton.Visible = false;
dumpSortedBtn.Visible = false; dumpSortedBtn.Visible = false;
Loaded = false; Loaded = false;
} }
private void treeView1_AfterDblClick(object sender, EventArgs e) private void treeView1_AfterDblClick(object sender, EventArgs e)
{ {
ChunkCombo.Show(Cursor.Position); ChunkCombo.Show(Cursor.Position);
} }
private void treeView1_RightClick(object sender, MouseEventArgs e) private void treeView1_RightClick(object sender, MouseEventArgs e)
{ {
if ((e.Button & MouseButtons.Right) != 0) if ((e.Button & MouseButtons.Right) != 0) ChunkCombo.Show(Cursor.Position);
{
ChunkCombo.Show(Cursor.Position);
}
} }
private void ChunkCombo_ItemSelected(object sender, ToolStripItemClickedEventArgs e) private void ChunkCombo_ItemSelected(object sender, ToolStripItemClickedEventArgs e)
@ -204,11 +180,7 @@ namespace CTFAK.GUI
{ {
case "saveChunkBtn": case "saveChunkBtn":
var chunk = ((ChunkNode) treeView1.SelectedNode).chunk; var chunk = ((ChunkNode) treeView1.SelectedNode).chunk;
if (chunk != null) chunk?.Save();
{
chunk.Save();
}
break; break;
case "viewHexBtn": case "viewHexBtn":
ShowHex(); ShowHex();
@ -233,7 +205,6 @@ namespace CTFAK.GUI
listBox1.Items.Clear(); listBox1.Items.Clear();
if (nodeChunk != null) if (nodeChunk != null)
{ {
listBox1.Items.Add($"Name: {nodeChunk.Name}"); listBox1.Items.Add($"Name: {nodeChunk.Name}");
listBox1.Items.Add($"Id: {nodeChunk.Id} - 0x{nodeChunk.Id:X4}"); listBox1.Items.Add($"Id: {nodeChunk.Id} - 0x{nodeChunk.Id:X4}");
listBox1.Items.Add($"Flag: {nodeChunk.Flag}"); listBox1.Items.Add($"Flag: {nodeChunk.Flag}");
@ -265,7 +236,6 @@ namespace CTFAK.GUI
public void AfterLoad() public void AfterLoad()
{ {
Logger.Log("Loading GUI"); Logger.Log("Loading GUI");
//GameData gameData = null; //GameData gameData = null;
var exe = Exe.Instance; var exe = Exe.Instance;
@ -275,13 +245,11 @@ namespace CTFAK.GUI
treeView1.Nodes.Clear(); treeView1.Nodes.Clear();
foreach (var item in gameData.GameChunks.Chunks) foreach (var item in gameData.GameChunks.Chunks)
{ {
var ActualName = item.Name;
string ActualName = item.Name;
if (item.Loader is Frame frm) ActualName = ActualName + " " + frm.Name; if (item.Loader is Frame frm) ActualName = ActualName + " " + frm.Name;
ChunkNode newNode = Helper.GetChunkNode(item, ActualName); var newNode = Helper.GetChunkNode(item, ActualName);
treeView1.Nodes.Add(newNode); treeView1.Nodes.Add(newNode);
if (item.Loader is Frame frame) if (item.Loader is Frame frame)
{
foreach (var frmChunk in frame.Chunks.Chunks) foreach (var frmChunk in frame.Chunks.Chunks)
{ {
var frameNode = Helper.GetChunkNode(frmChunk); var frameNode = Helper.GetChunkNode(frmChunk);
@ -290,7 +258,6 @@ namespace CTFAK.GUI
{ {
var objs = frame.Chunks.GetChunk<ObjectInstances>(); var objs = frame.Chunks.GetChunk<ObjectInstances>();
if (objs != null) if (objs != null)
{
foreach (var frmitem in objs.Items) foreach (var frmitem in objs.Items)
{ {
var objNode = new ChunkNode(frmitem.Name, frmitem); var objNode = new ChunkNode(frmitem.Name, frmitem);
@ -298,18 +265,13 @@ namespace CTFAK.GUI
} }
} }
} }
}
}
else if (item.Loader is FrameItems items) else if (item.Loader is FrameItems items)
{
foreach (var key in items.ItemDict.Keys) foreach (var key in items.ItemDict.Keys)
{ {
var frameItem = items.ItemDict[key]; var frameItem = items.ItemDict[key];
var objNode = new ChunkNode($"{(Constants.ObjectType) frameItem.ObjectType} - {frameItem.Name}", var objNode = new ChunkNode($"{(Constants.ObjectType) frameItem.ObjectType} - {frameItem.Name}",
frameItem); frameItem);
newNode.Nodes.Add(objNode); newNode.Nodes.Add(objNode);
}
} }
} }
@ -378,10 +340,7 @@ namespace CTFAK.GUI
SortedProgressBar.Visible = true; SortedProgressBar.Visible = true;
SortedProgressBar.Maximum = all; SortedProgressBar.Maximum = all;
SortedProgressBar.Value += 1; SortedProgressBar.Value += 1;
if (SortedProgressBar.Value >= SortedProgressBar.Maximum) if (SortedProgressBar.Value >= SortedProgressBar.Maximum) SortedProgressBar.Visible = false;
{
SortedProgressBar.Visible = false;
}
} }
@ -391,7 +350,6 @@ namespace CTFAK.GUI
} }
private void soundsButton_Click(object sender, EventArgs e) private void soundsButton_Click(object sender, EventArgs e)
{ {
if (Exe.Instance.GameData.GameChunks.GetChunk<SoundBank>() == null) return; if (Exe.Instance.GameData.GameChunks.GetChunk<SoundBank>() == null) return;
@ -400,7 +358,6 @@ namespace CTFAK.GUI
SetSoundElements(true); SetSoundElements(true);
IsDumpingSounds = true; IsDumpingSounds = true;
Backend.DumpSounds(this, true, true); Backend.DumpSounds(this, true, true);
} }
else else
{ {
@ -418,8 +375,6 @@ namespace CTFAK.GUI
SetImageElements(true); SetImageElements(true);
IsDumpingImages = true; IsDumpingImages = true;
Backend.DumpImages(this, true, true); Backend.DumpImages(this, true, true);
} }
else else
{ {
@ -444,7 +399,6 @@ namespace CTFAK.GUI
IsDumpingMusics = false; IsDumpingMusics = false;
SetMusicElements(false); SetMusicElements(false);
} }
} }
@ -476,7 +430,7 @@ namespace CTFAK.GUI
{ {
if ((ChunkNode) treeView1.SelectedNode != null) if ((ChunkNode) treeView1.SelectedNode != null)
{ {
var node = ((ChunkNode) treeView1.SelectedNode); var node = (ChunkNode) treeView1.SelectedNode;
HexViewForm hexform = null; HexViewForm hexform = null;
hexform = new HexViewForm(node.chunk.ChunkData, node.chunk.RawData, ColorTheme, hexform = new HexViewForm(node.chunk.ChunkData, node.chunk.RawData, ColorTheme,
@ -484,11 +438,9 @@ namespace CTFAK.GUI
hexform.Show(); hexform.Show();
} }
} }
private void dumpSortedBtn_Click(object sender, EventArgs e) private void dumpSortedBtn_Click(object sender, EventArgs e)
{ {
imageBar.Visible = true; imageBar.Visible = true;
@ -500,7 +452,6 @@ namespace CTFAK.GUI
var bank = Exe.Instance.GameData.GameChunks.GetChunk<ImageBank>(); var bank = Exe.Instance.GameData.GameChunks.GetChunk<ImageBank>();
bank.SaveImages = false; bank.SaveImages = false;
bank.Read(); bank.Read();
}; };
worker.RunWorkerCompleted += (senderA, eA) => worker.RunWorkerCompleted += (senderA, eA) =>
{ {
@ -512,11 +463,6 @@ namespace CTFAK.GUI
} }
private void dumpMFAButton_Click(object sender, EventArgs e) private void dumpMFAButton_Click(object sender, EventArgs e)
{ {
var worker = new BackgroundWorker(); var worker = new BackgroundWorker();
@ -526,17 +472,13 @@ namespace CTFAK.GUI
Logger.Log("MFA Done", true, ConsoleColor.Yellow); Logger.Log("MFA Done", true, ConsoleColor.Yellow);
var res = MessageBox.Show("Dump Extensions?", "Finished", MessageBoxButtons.YesNo); var res = MessageBox.Show("Dump Extensions?", "Finished", MessageBoxButtons.YesNo);
if (res == DialogResult.Yes) if (res == DialogResult.Yes)
{
foreach (var item in Exe.Instance.PackData.Items) foreach (var item in Exe.Instance.PackData.Items)
{ {
item.Dump(); item.Dump();
Pame2Mfa.Message("Dumping " + item.PackFilename); Pame2Mfa.Message("Dumping " + item.PackFilename);
} }
}
Process.Start($"{Settings.DumpPath}"); Process.Start($"{Settings.DumpPath}");
}; };
worker.RunWorkerAsync(); worker.RunWorkerAsync();
@ -561,9 +503,8 @@ namespace CTFAK.GUI
try try
{ {
var previewKey = Decryption.MakeKeyFromComb(rawData, (byte) int.Parse((charBox.Text))); var previewKey = Decryption.MakeKeyFromComb(rawData, (byte) int.Parse(charBox.Text));
hexBox1.ByteProvider = new DynamicByteProvider(previewKey); hexBox1.ByteProvider = new DynamicByteProvider(previewKey);
} }
catch catch
{ {
@ -574,10 +515,7 @@ namespace CTFAK.GUI
public void InitPackDataTab() public void InitPackDataTab()
{ {
packDataListBox.Items.Clear(); packDataListBox.Items.Clear();
foreach (var item in Exe.Instance.PackData.Items) foreach (var item in Exe.Instance.PackData.Items) packDataListBox.Items.Add(item.PackFilename);
{
packDataListBox.Items.Add(item.PackFilename);
}
UpdatePackInfo(0); UpdatePackInfo(0);
} }
@ -603,10 +541,7 @@ namespace CTFAK.GUI
private void dumpAllPackButton_Click(object sender, EventArgs e) private void dumpAllPackButton_Click(object sender, EventArgs e)
{ {
foreach (var item in Exe.Instance.PackData.Items) foreach (var item in Exe.Instance.PackData.Items) item.Dump();
{
item.Dump();
}
} }
private void packDataDialog_FileOk(object sender, CancelEventArgs e) private void packDataDialog_FileOk(object sender, CancelEventArgs e)
@ -615,8 +550,10 @@ namespace CTFAK.GUI
item.Dump(packDataDialog.FileName); item.Dump(packDataDialog.FileName);
} }
private void packDataListBox_SelectedIndexChanged(object sender, EventArgs e) => private void packDataListBox_SelectedIndexChanged(object sender, EventArgs e)
{
UpdatePackInfo(packDataListBox.SelectedIndex); UpdatePackInfo(packDataListBox.SelectedIndex);
}
private void plusCharBtn_Click(object sender, EventArgs e) private void plusCharBtn_Click(object sender, EventArgs e)
{ {
@ -631,9 +568,10 @@ namespace CTFAK.GUI
InitKeyTab(); InitKeyTab();
} }
private void charBox_TextChanged(object sender, EventArgs e) => InitKeyTab(); private void charBox_TextChanged(object sender, EventArgs e)
{
InitKeyTab();
}
public void InitImages() public void InitImages()
@ -642,13 +580,12 @@ namespace CTFAK.GUI
var bank = Exe.Instance.GameData.GameChunks.GetChunk<ImageBank>(); var bank = Exe.Instance.GameData.GameChunks.GetChunk<ImageBank>();
var items = bank.Images.ToList(); var items = bank.Images.ToList();
var filtered = items.OrderBy(x => x.Value.Handle); var filtered = items.OrderBy(x => x.Value.Handle);
foreach (Frame frame in Exe.Instance.GameData.Frames) foreach (var frame in Exe.Instance.GameData.Frames)
{ {
var frameNode = new ChunkNode(frame.Name, frame); var frameNode = new ChunkNode(frame.Name, frame);
imagesTreeView.Nodes.Add(frameNode); imagesTreeView.Nodes.Add(frameNode);
if (frame.Objects != null) if (frame.Objects != null)
{ foreach (var objInst in frame.Objects.Items)
foreach (ObjectInstance objInst in frame.Objects.Items)
{ {
var objInstNode = new ChunkNode(objInst.FrameItem.Name, objInst); var objInstNode = new ChunkNode(objInst.FrameItem.Name, objInst);
frameNode.Nodes.Add(objInstNode); frameNode.Nodes.Add(objInstNode);
@ -656,20 +593,19 @@ namespace CTFAK.GUI
if (loader is ObjectCommon common) if (loader is ObjectCommon common)
{ {
if (common.Animations != null) if (common.Animations != null)
{
foreach (var pair in common.Animations.AnimationDict) foreach (var pair in common.Animations.AnimationDict)
{ {
var animNode = new ChunkNode($"Animation {pair.Key}", pair.Value); var animNode = new ChunkNode($"Animation {pair.Key}", pair.Value);
objInstNode.Nodes.Add(animNode); objInstNode.Nodes.Add(animNode);
foreach (var dir in pair.Value.DirectionDict) foreach (var dir in pair.Value.DirectionDict)
{
if (pair.Value.DirectionDict.Count > 1) if (pair.Value.DirectionDict.Count > 1)
{ {
var dirNode = new ChunkNode($"Direction {pair.Value.DirectionDict.ToList().IndexOf(dir)}",dir.Value); var dirNode = new ChunkNode(
$"Direction {pair.Value.DirectionDict.ToList().IndexOf(dir)}",
dir.Value);
animNode.Nodes.Add(dirNode); animNode.Nodes.Add(dirNode);
for (int a = 0; a < dir.Value.Frames.Count; a++) for (var a = 0; a < dir.Value.Frames.Count; a++)
{ {
var animFrame = dir.Value.Frames[a]; var animFrame = dir.Value.Frames[a];
bank.Images.TryGetValue(animFrame, out var img); bank.Images.TryGetValue(animFrame, out var img);
if (img != null) if (img != null)
@ -677,14 +613,12 @@ namespace CTFAK.GUI
var animFrameNode = new ChunkNode(a.ToString(), img); var animFrameNode = new ChunkNode(a.ToString(), img);
dirNode.Nodes.Add(animFrameNode); dirNode.Nodes.Add(animFrameNode);
} }
} }
} }
else else
{ {
for (int a = 0; a < dir.Value.Frames.Count; a++) for (var a = 0; a < dir.Value.Frames.Count; a++)
{ {
var animFrame = dir.Value.Frames[a]; var animFrame = dir.Value.Frames[a];
bank.Images.TryGetValue(animFrame, out var img); bank.Images.TryGetValue(animFrame, out var img);
if (img != null) if (img != null)
@ -692,17 +626,13 @@ namespace CTFAK.GUI
var animFrameNode = new ChunkNode(a.ToString(), img); var animFrameNode = new ChunkNode(a.ToString(), img);
animNode.Nodes.Add(animFrameNode); animNode.Nodes.Add(animFrameNode);
} }
}
}
} }
} }
} }
} }
else if (loader is Backdrop backdrop) else if (loader is Backdrop backdrop)
{ {
bank.Images.TryGetValue(backdrop.Image,out var img); bank.Images.TryGetValue(backdrop.Image, out var img);
if (img != null) if (img != null)
{ {
var backdropNode = new ChunkNode("Image", img); var backdropNode = new ChunkNode("Image", img);
@ -712,11 +642,6 @@ namespace CTFAK.GUI
} }
} }
} }
}
private bool _breakAnim;
private bool _isAnimRunning;
private SoundPlayer _soundPlayer;
private void advancedPlayAnimation_Click(object sender, EventArgs e) private void advancedPlayAnimation_Click(object sender, EventArgs e)
{ {
@ -730,14 +655,12 @@ namespace CTFAK.GUI
{ {
_isAnimRunning = true; _isAnimRunning = true;
var animThread = new Thread(PlayAnimation); var animThread = new Thread(PlayAnimation);
List<Bitmap> frames = new List<Bitmap>(); var frames = new List<Bitmap>();
foreach (var dir in anim.DirectionDict) foreach (var dir in anim.DirectionDict)
{ {
foreach (var frame in dir.Value.Frames) foreach (var frame in dir.Value.Frames)
{
frames.Add(Exe.Instance.GameData.GameChunks.GetChunk<ImageBank>().Images[frame].Bitmap); frames.Add(Exe.Instance.GameData.GameChunks.GetChunk<ImageBank>().Images[frame].Bitmap);
} animThread.Start(new Tuple<List<Bitmap>, AnimationDirection>(frames, dir.Value));
animThread.Start(new Tuple<List<Bitmap>,AnimationDirection>(frames,dir.Value));
break; break;
} }
} }
@ -752,41 +675,41 @@ namespace CTFAK.GUI
{ {
_isAnimRunning = true; _isAnimRunning = true;
var animThread = new Thread(PlayAnimation); var animThread = new Thread(PlayAnimation);
List<Bitmap> frames = new List<Bitmap>(); var frames = new List<Bitmap>();
foreach (var frame in dir.Frames) foreach (var frame in dir.Frames)
{ {
frames.Add(Exe.Instance.GameData.GameChunks.GetChunk<ImageBank>().Images[frame].Bitmap); frames.Add(Exe.Instance.GameData.GameChunks.GetChunk<ImageBank>().Images[frame].Bitmap);
animThread.Start(new Tuple<List<Bitmap>,AnimationDirection>(frames,dir)); animThread.Start(new Tuple<List<Bitmap>, AnimationDirection>(frames, dir));
break; break;
} }
} }
} }
} }
public void PlayAnimation(object o) public void PlayAnimation(object o)
{ {
var (frames,anim) = (Tuple<List<Bitmap>,AnimationDirection>) o; var (frames, anim) = (Tuple<List<Bitmap>, AnimationDirection>) o;
var fps = (float)anim.MaxSpeed; var fps = (float) anim.MaxSpeed;
float delay = 1f/fps; var delay = 1f / fps;
int i = 0; var i = 0;
if (anim.Repeat > 0&& anim.Frames.Count>1) if (anim.Repeat > 0 && anim.Frames.Count > 1)
{ {
foreach (Bitmap frame in frames) foreach (var frame in frames)
{ {
imageViewPictureBox.Image = frame; imageViewPictureBox.Image = frame;
imageViewerInfo.Text = $"Current frame: {frames.IndexOf(frame)}\nAnimation Speed: {fps}"; imageViewerInfo.Text = $"Current frame: {frames.IndexOf(frame)}\nAnimation Speed: {fps}";
Thread.Sleep((int) (delay*1500)); Thread.Sleep((int) (delay * 1500));
} }
_isAnimRunning = false;
try {Thread.CurrentThread.Abort();}
catch {}
_isAnimRunning = false;
try
{
Thread.CurrentThread.Abort();
}
catch
{
}
} }
else else
{ {
@ -795,25 +718,18 @@ namespace CTFAK.GUI
var frame = frames[i]; var frame = frames[i];
imageViewPictureBox.Image = frame; imageViewPictureBox.Image = frame;
imageViewerInfo.Text = $"Current frame: {i.ToString()}\nAnimation Speed: {fps}"; imageViewerInfo.Text = $"Current frame: {i.ToString()}\nAnimation Speed: {fps}";
Thread.Sleep((int) (delay*1500)); Thread.Sleep((int) (delay * 1500));
i++; i++;
if (i == frames.Count) i = 0; if (i == frames.Count) i = 0;
if (_breakAnim) if (_breakAnim)
{ {
_isAnimRunning = false; _isAnimRunning = false;
_breakAnim = false; _breakAnim = false;
if(Thread.CurrentThread.IsAlive) Thread.CurrentThread.Abort(); if (Thread.CurrentThread.IsAlive) Thread.CurrentThread.Abort();
break; break;
} }
} }
} }
} }
private void advancedTreeView_AfterSelect(object sender, TreeViewEventArgs e) private void advancedTreeView_AfterSelect(object sender, TreeViewEventArgs e)
@ -821,23 +737,16 @@ namespace CTFAK.GUI
var node = e.Node; var node = e.Node;
if (((ChunkNode) node).loader is ImageItem) if (((ChunkNode) node).loader is ImageItem)
{ {
var img = ((ImageItem) ((ChunkNode) node).loader); var img = (ImageItem) ((ChunkNode) node).loader;
imageViewPictureBox.Image = img.Bitmap; imageViewPictureBox.Image = img.Bitmap;
} }
} }
public void InitPlugins() public void InitPlugins()
{ {
PluginAPI.PluginAPI.InitializePlugins(); PluginAPI.PluginAPI.InitializePlugins();
foreach (var plugin in PluginAPI.PluginAPI.Plugins) foreach (var plugin in PluginAPI.PluginAPI.Plugins) pluginsList.Items.Add(plugin.Name);
{
pluginsList.Items.Add(plugin.Name);
}
} }
private void activatePluginBtn_Click(object sender, EventArgs e) private void activatePluginBtn_Click(object sender, EventArgs e)
@ -846,45 +755,37 @@ namespace CTFAK.GUI
} }
public void InitSounds() public void InitSounds()
{ {
var bank = Exe.Instance.GameData.GameChunks.GetChunk<SoundBank>(); var bank = Exe.Instance.GameData.GameChunks.GetChunk<SoundBank>();
if (bank == null) return; if (bank == null) return;
foreach (SoundItem soundItem in bank.Items) foreach (var soundItem in bank.Items) soundList.Nodes.Add(new ChunkNode(soundItem.Name, soundItem));
{ _soundPlayer =
soundList.Nodes.Add(new ChunkNode(soundItem.Name,soundItem)); new SoundPlayer(new MemoryStream(Exe.Instance.GameData.GameChunks.GetChunk<SoundBank>().Items[0].Data));
} }
_soundPlayer = new SoundPlayer(new MemoryStream(Exe.Instance.GameData.GameChunks.GetChunk<SoundBank>().Items[0].Data));
}
private bool _isAudioPlaying;
private void playSoundBtn_Click(object sender, EventArgs e) private void playSoundBtn_Click(object sender, EventArgs e)
{ {
_soundPlayer.Stream = new MemoryStream(Exe.Instance.GameData.GameChunks.GetChunk<SoundBank>().Items[soundList.SelectedNode.Index].Data); _soundPlayer.Stream = new MemoryStream(Exe.Instance.GameData.GameChunks.GetChunk<SoundBank>()
.Items[soundList.SelectedNode.Index].Data);
_soundPlayer.Play(); _soundPlayer.Play();
} }
private void soundList_AfterSelect(object sender, TreeViewEventArgs e) private void soundList_AfterSelect(object sender, TreeViewEventArgs e)
{ {
} }
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
{ {
if (tabControl1.SelectedTab == imgViewerTab) if (tabControl1.SelectedTab == imgViewerTab)
{
if (e.Control) if (e.Control)
{ {
var node = (ChunkNode)imagesTreeView.SelectedNode; var node = (ChunkNode) imagesTreeView.SelectedNode;
var path = $"{Settings.ImagePath}\\{Helper.GetTreePath(imagesTreeView,(ChunkNode) imagesTreeView.SelectedNode)}"; var path =
$"{Settings.ImagePath}\\{Helper.GetTreePath(imagesTreeView, (ChunkNode) imagesTreeView.SelectedNode)}";
if (node == null) return; if (node == null) return;
ImageDumper.SaveFromNode(node); ImageDumper.SaveFromNode(node);
}
} }
} }
@ -894,8 +795,3 @@ namespace CTFAK.GUI
} }
} }
} }

@ -1,70 +1,66 @@
using System; using System;
using System.IO;
using CTFAK.Utils; using CTFAK.Utils;
namespace CTFAK.MMFParser.EXE namespace CTFAK.MMFParser.EXE
{ {
public class Exe public class Exe
{ {
public PackData PackData;
public GameData GameData;
public static Exe Instance; public static Exe Instance;
public GameData GameData;
public PackData PackData;
public void ParseExe(ByteReader exeReader) public void ParseExe(ByteReader exeReader)
{ {
Logger.Log($"Executable: {Settings.GameName}\n", true, ConsoleColor.DarkRed); Logger.Log($"Executable: {Settings.GameName}\n", true, ConsoleColor.DarkRed);
string sig = exeReader.ReadAscii(2); var sig = exeReader.ReadAscii(2);
Logger.Log("EXE Header: " + sig, true, ConsoleColor.Yellow); Logger.Log("EXE Header: " + sig, true, ConsoleColor.Yellow);
if (sig != "MZ") if (sig != "MZ") Logger.Log("Invalid executable signature", true, ConsoleColor.Red);
{
Logger.Log("Invalid executable signature",true,ConsoleColor.Red);
}
exeReader.Seek(60, SeekOrigin.Begin); exeReader.Seek(60);
UInt16 hdrOffset = exeReader.ReadUInt16(); var hdrOffset = exeReader.ReadUInt16();
exeReader.Seek(hdrOffset, SeekOrigin.Begin); exeReader.Seek(hdrOffset);
string peHdr = exeReader.ReadAscii(2); var peHdr = exeReader.ReadAscii(2);
Logger.Log("PE Header: " + peHdr, true, ConsoleColor.Yellow); Logger.Log("PE Header: " + peHdr, true, ConsoleColor.Yellow);
exeReader.Skip(4); exeReader.Skip(4);
UInt16 numOfSections = exeReader.ReadUInt16(); var numOfSections = exeReader.ReadUInt16();
exeReader.Skip(16); exeReader.Skip(16);
int optionalHeader = 28 + 68; var optionalHeader = 28 + 68;
int dataDir = 16 * 8; var dataDir = 16 * 8;
exeReader.Skip(optionalHeader + dataDir); exeReader.Skip(optionalHeader + dataDir);
int possition = 0; var possition = 0;
for (int i = 0; i < numOfSections; i++) for (var i = 0; i < numOfSections; i++)
{ {
long entry = exeReader.Tell(); var entry = exeReader.Tell();
string sectionName = exeReader.ReadAscii(); var sectionName = exeReader.ReadAscii();
if (sectionName == ".extra") if (sectionName == ".extra")
{ {
exeReader.Seek(entry + 20); exeReader.Seek(entry + 20);
possition = (int)exeReader.ReadUInt32(); possition = (int) exeReader.ReadUInt32();
break; break;
} }
if (i >= numOfSections - 1) if (i >= numOfSections - 1)
{ {
exeReader.Seek(entry + 16); exeReader.Seek(entry + 16);
uint size = exeReader.ReadUInt32(); var size = exeReader.ReadUInt32();
uint address = exeReader.ReadUInt32(); var address = exeReader.ReadUInt32();
possition = (int)(address + size); possition = (int) (address + size);
break; break;
} }
exeReader.Seek(entry + 40); exeReader.Seek(entry + 40);
} }
exeReader.Seek((int)possition); exeReader.Seek(possition);
UInt16 firstShort = exeReader.PeekUInt16(); var firstShort = exeReader.PeekUInt16();
Logger.Log("First Short: " + firstShort.ToString("X2"), true, ConsoleColor.Yellow); Logger.Log("First Short: " + firstShort.ToString("X2"), true, ConsoleColor.Yellow);
if (firstShort == 0x7777) Settings.Old = false; if (firstShort == 0x7777) Settings.Old = false;
else Settings.Old = true; else Settings.Old = true;
@ -76,8 +72,6 @@ namespace CTFAK.MMFParser.EXE
GameData = new GameData(); GameData = new GameData();
GameData.Read(exeReader); GameData.Read(exeReader);
Console.ForegroundColor = ConsoleColor.DarkGreen; Console.ForegroundColor = ConsoleColor.DarkGreen;
} }
else else
{ {
@ -88,7 +82,6 @@ namespace CTFAK.MMFParser.EXE
Console.ForegroundColor = ConsoleColor.DarkGreen; Console.ForegroundColor = ConsoleColor.DarkGreen;
Logger.Log("Failed to find PackData header!\n", true, ConsoleColor.Red); Logger.Log("Failed to find PackData header!\n", true, ConsoleColor.Red);
} }
} }
} }
} }

@ -1,32 +1,77 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
namespace CTFAK.Utils namespace CTFAK.Utils
{ {
static class Decryption static class Decryption
{ {
private static byte[] _decryptionKey; private static byte[] _decryptionKey;
public static byte MagicChar = 54; public static byte MagicChar = 0;
public static byte[] FixString(byte[] bytes)
{
List<byte> newBytes = new List<byte>();
foreach (byte b in bytes)
{
if(b!=0) newBytes.Add(b);
}
return bytes; //newBytes.ToArray();
}
public static void MakeKey(string data1, string data2, string data3) public static void MakeKey(string data1, string data2, string data3)
{
var russian = false;
IntPtr keyPtr=new IntPtr();
if (russian)
{
var fixed1 = FixString(Encoding.Unicode.GetBytes(data1));
var data1Ptr = Marshal.AllocHGlobal(fixed1.Length);
Marshal.Copy(fixed1,0,data1Ptr,fixed1.Length);
var fixed2 = FixString(Encoding.Unicode.GetBytes(data2));
var data2Ptr = Marshal.AllocHGlobal(fixed2.Length);
Marshal.Copy(fixed2,0,data2Ptr,fixed2.Length);
var fixed3 = FixString(Encoding.Unicode.GetBytes(data3));
var data3Ptr = Marshal.AllocHGlobal(fixed3.Length);
Marshal.Copy(fixed3,0,data1Ptr,fixed3.Length);
keyPtr = make_key_w(data1Ptr,data2Ptr,data3Ptr,MagicChar);
Marshal.FreeHGlobal(data1Ptr);
Marshal.FreeHGlobal(data2Ptr);
Marshal.FreeHGlobal(data3Ptr);
}
else
{ {
var rawKey = ""; var rawKey = "";
rawKey += data1; rawKey += data1;
rawKey += data2; rawKey += data2;
rawKey += data3; rawKey += data3;
Logger.Log("Combined data " + rawKey, true, ConsoleColor.Yellow); Logger.Log("Combined data " + rawKey, true, ConsoleColor.Yellow);
var rawKeyPtr = Marshal.StringToHGlobalAnsi(rawKey); keyPtr = Marshal.StringToHGlobalAnsi(rawKey);
keyPtr = make_key_combined(keyPtr, MagicChar);
var ptr = Decryption.make_key_combined(rawKeyPtr, MagicChar);
}
byte[] key = new byte[256]; byte[] key = new byte[256];
Marshal.Copy(ptr, key, 0, 256); Marshal.Copy(keyPtr, key, 0, 256);
Marshal.FreeHGlobal(rawKeyPtr); _decryptionKey = key;
_decryptionKey = key;
Logger.Log($"First 16-Bytes of key: {_decryptionKey.GetHex(16)}", true, ConsoleColor.Yellow); Logger.Log($"First 16-Bytes of key: {_decryptionKey.GetHex(16)}", true, ConsoleColor.Yellow);
Logger.Log(Encoding.Unicode.GetString(_decryptionKey));
File.WriteAllBytes($"{Settings.DumpPath}\\key.bin", _decryptionKey); File.WriteAllBytes($"{Settings.DumpPath}\\key.bin", _decryptionKey);
} }
@ -90,6 +135,9 @@ namespace CTFAK.Utils
[DllImport(_dllPath, EntryPoint = "make_key", CharSet = CharSet.Auto)] [DllImport(_dllPath, EntryPoint = "make_key", CharSet = CharSet.Auto)]
public static extern IntPtr make_key(IntPtr cTitle, IntPtr cCopyright, IntPtr cProject, byte magicChar); public static extern IntPtr make_key(IntPtr cTitle, IntPtr cCopyright, IntPtr cProject, byte magicChar);
[DllImport(_dllPath, EntryPoint = "make_key_w", CharSet = CharSet.Unicode)]
public static extern IntPtr make_key_w(IntPtr cTitle, IntPtr cCopyright, IntPtr cProject, byte magicChar);
[DllImport(_dllPath, EntryPoint = "make_key_combined", CharSet = CharSet.Auto)] [DllImport(_dllPath, EntryPoint = "make_key_combined", CharSet = CharSet.Auto)]
public static extern IntPtr make_key_combined(IntPtr data, byte magicChar); public static extern IntPtr make_key_combined(IntPtr data, byte magicChar);

@ -167,6 +167,12 @@ namespace CTFAK.Utils
return colors; return colors;
} }
public static bool ContainsUnicodeCharacter(string input)
{
const int MaxAnsiCode = 255;
return input.Any(c => c > MaxAnsiCode);
}
public static void CheckPattern(object source, object pattern) public static void CheckPattern(object source, object pattern)
{ {

Binary file not shown.
Loading…
Cancel
Save