diff --git a/CTFAK/GUI/MainForm.cs b/CTFAK/GUI/MainForm.cs index da1e905..b6100c3 100644 --- a/CTFAK/GUI/MainForm.cs +++ b/CTFAK/GUI/MainForm.cs @@ -640,6 +640,7 @@ namespace DotNetCTFDumper.GUI public void InitImages() { + if (Settings.twofiveplus) return; var bank = Exe.Instance.GameData.GameChunks.GetChunk(); var items = bank.Images.ToList(); var filtered = items.OrderBy(x => x.Value.Handle); @@ -851,6 +852,7 @@ namespace DotNetCTFDumper.GUI public void InitSounds() { var bank = Exe.Instance.GameData.GameChunks.GetChunk(); + if (bank == null) return; foreach (SoundItem soundItem in bank.Items) { soundList.Nodes.Add(new ChunkNode(soundItem.Name,soundItem)); diff --git a/CTFAK/MMFParser/EXE/ChunkList.cs b/CTFAK/MMFParser/EXE/ChunkList.cs index d53646a..ad49176 100644 --- a/CTFAK/MMFParser/EXE/ChunkList.cs +++ b/CTFAK/MMFParser/EXE/ChunkList.cs @@ -25,6 +25,8 @@ namespace DotNetCTFDumper.MMFParser.EXE chunk.Loader = LoadChunk(chunk); Chunks.Add(chunk); if (chunk.Id == 8750) chunk.BuildKey(); + if (chunk.Id == 8788) Settings.twofiveplus = true; + if (reader.Tell() >= reader.Size()) break; if (chunk.Id == 32639) break; //LAST chunkID } diff --git a/CTFAK/MMFParser/EXE/Loaders/Banks/ImageBank.cs b/CTFAK/MMFParser/EXE/Loaders/Banks/ImageBank.cs index af974ce..98da28f 100644 --- a/CTFAK/MMFParser/EXE/Loaders/Banks/ImageBank.cs +++ b/CTFAK/MMFParser/EXE/Loaders/Banks/ImageBank.cs @@ -14,7 +14,7 @@ namespace DotNetCTFDumper.MMFParser.EXE.Loaders.Banks { public class ImageBank : ChunkLoader { - public bool SaveImages = true; + public bool SaveImages = false; public Dictionary Images = new Dictionary(); public uint NumberOfItems; public bool PreloadOnly=false; @@ -155,9 +155,7 @@ namespace DotNetCTFDumper.MMFParser.EXE.Loaders.Banks { Handle = Reader.ReadInt32() - 1; Position = (int) Reader.Tell(); - Logger.Log("ImageFound: "+Handle); if (load) Load(); - else Preload(); } @@ -182,23 +180,14 @@ namespace DotNetCTFDumper.MMFParser.EXE.Loaders.Banks _bitmap = null; Reader.Seek(Position); ByteReader imageReader; - Console.WriteLine("Preloading Image"); - if (Settings.twofiveplus) - { - - //Do 2.5+ decryption - - } - // imageReader = Debug ? Reader : Decompressor.DecompressAsReader(Reader, out var a); - - imageReader = Debug ? Reader : Decompressor.DecompressAsReader(Reader, out var a); - - //Directory.CreateDirectory("DUMP\\DEBUG"); - //File.WriteAllBytes($"DUMP\\DEBUG\\Img-{Handle}.imgb",imageReader.ReadBytes((int) imageReader.Size())); + if (!Settings.twofiveplus) + imageReader = Debug ? Reader : Decompressor.DecompressAsReader(Reader, out var a); + else imageReader = Reader; + long start = imageReader.Tell(); - long start = imageReader.Tell(); - + //return; + if(Settings.twofiveplus) imageReader.Skip(4); _checksum = imageReader.ReadInt32(); _references = imageReader.ReadInt32(); Size = (int) imageReader.ReadUInt32(); @@ -230,7 +219,7 @@ namespace DotNetCTFDumper.MMFParser.EXE.Loaders.Banks _width = imageReader.ReadInt16(); _height = imageReader.ReadInt16(); - _graphicMode = imageReader.ReadByte(); //Graphic mode is always 4 for SL + _graphicMode = imageReader.ReadByte(); Flags.flag = imageReader.ReadByte(); @@ -283,6 +272,13 @@ namespace DotNetCTFDumper.MMFParser.EXE.Loaders.Banks (_colorArray, bytesRead) = ImageHelper.ReadSixteen(imageData, _width, _height); break; } + case 8: + { + //imageReader.Seek(start+Size); + return; + (_colorArray, bytesRead) = ImageHelper.Read32(imageData, _width, _height); + break; + } default: { break; diff --git a/CTFAK/Program.cs b/CTFAK/Program.cs index f3ec3d3..4807ef8 100644 --- a/CTFAK/Program.cs +++ b/CTFAK/Program.cs @@ -30,11 +30,11 @@ namespace DotNetCTFDumper var verbose = false; var dumpImages = true; var dumpSounds = true; - /*AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) => + AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) => { Logger.Log("ERROR: "); Logger.Log(eventArgs.Exception.ToString()); - };*/ + }; Settings.UseGUI = true; @@ -44,7 +44,7 @@ namespace DotNetCTFDumper } if (args.Length > 1) { - ReadFile(args[1],true,true,true); + ReadFile(args[1],true,false,false); } else if(args.Length==0) { diff --git a/CTFAK/Settings.cs b/CTFAK/Settings.cs index 940c80d..d1091b9 100644 --- a/CTFAK/Settings.cs +++ b/CTFAK/Settings.cs @@ -10,7 +10,7 @@ namespace DotNetCTFDumper public static bool SaveChunks; public static bool Verbose; public static bool Old; - public static bool twofiveplus=true; + public static bool twofiveplus = false; public static string GamePath; public static string GameName => Path.GetFileNameWithoutExtension(GamePath); diff --git a/CTFAK/Utils/ImageHelper.cs b/CTFAK/Utils/ImageHelper.cs index 32edb04..a6c1d30 100644 --- a/CTFAK/Utils/ImageHelper.cs +++ b/CTFAK/Utils/ImageHelper.cs @@ -1,4 +1,5 @@ using System; +using System.IO; namespace DotNetCTFDumper.Utils { @@ -56,6 +57,34 @@ namespace DotNetCTFDumper.Utils } return (colorArray, position); + } + public static (byte[], int) Read32(byte[] data, int width, int height) + { + byte[] colorArray = new byte[width * height * 4]; + int stride = width * 4; + int pad = GetPadding(width, 3); + int position = 0; + try + { + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + position += 3; + } + position += pad * 3; + } + } + catch + { + return (Array.Empty(), position); + } + + + return (Array.Empty(), position); + + + } public static (byte[], int) ReadFifteen(byte[] data, int width, int height)