From e6b0ca101b2b7ba5c83eeb7649c368362c52422e Mon Sep 17 00:00:00 2001 From: phacoxcll <36426650+phacoxcll@users.noreply.github.com> Date: Thu, 11 Jul 2019 18:18:53 -0500 Subject: [PATCH] Creates a log file. By default it creates a log file (both in CMD mode and in GUI mode) with the messages of the injection process of the command line. --- 64Inject/64Inject.csproj | 2 +- 64Inject/64InjectCMD.cs | 323 ++++++++++++++-------------- 64Inject/64InjectGUI.cs | 22 ++ 64Inject/64Injector.cs | 79 +++++-- 64Inject/Log.cs | 73 ++----- 64Inject/Properties/AssemblyInfo.cs | 4 +- 64Inject/RomN64.cs | 14 +- 7 files changed, 277 insertions(+), 240 deletions(-) diff --git a/64Inject/64Inject.csproj b/64Inject/64Inject.csproj index ac70033..1e77c90 100644 --- a/64Inject/64Inject.csproj +++ b/64Inject/64Inject.csproj @@ -263,6 +263,6 @@ --> - "C:\Users\Alberto\Documents\Visual Studio 2008\Projects\64Inject\64Inject\CllAssemblyVersion.exe" assemblyInfo "$(ProjectDir)Properties\AssemblyInfo.cs" projectPath "$(ProjectPath)" config "$(ConfigurationName)" platform "$(PlatformName)" title "$(SolutionName)" format "major.minor.build.revision" replaceIn "$(ProjectDir)64Injector.cs" + "C:\Users\Alberto\source\repos\64Inject\64Inject\CllAssemblyVersion.exe" assemblyInfo "$(ProjectDir)Properties\AssemblyInfo.cs" projectPath "$(ProjectPath)" config "$(ConfigurationName)" platform "$(PlatformName)" title "$(SolutionName)" format "major.minor.build.revision" replaceIn "$(ProjectDir)64Injector.cs" \ No newline at end of file diff --git a/64Inject/64InjectCMD.cs b/64Inject/64InjectCMD.cs index f10ae18..4b3e7e5 100644 --- a/64Inject/64InjectCMD.cs +++ b/64Inject/64InjectCMD.cs @@ -9,46 +9,50 @@ public class _64InjectCMD public _64InjectCMD() { + Cll.Log.SaveIn("64Inject_log.txt"); + Cll.Log.WriteLine(DateTime.UtcNow.ToString()); + Cll.Log.WriteLine("64Inject open in CMD mode."); + injector = new _64Injector(); } public void Run(string[] args) { - injector.Log.WriteLine("64Inject " + _64Injector.Release + " - by phacox.cll"); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("64Inject " + _64Injector.Release + " - by phacox.cll"); + Cll.Log.WriteLine(""); if (NusContent.GetJavaVersion() == null) { - injector.Log.WriteLine("Warning! Apparently the system does not have Java installed!"); - injector.Log.WriteLine("Java is needed to NUSPacker (encrypt) and JNUSTool (decrypt)."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("Warning! Apparently the system does not have Java installed!"); + Cll.Log.WriteLine("Java is needed to NUSPacker (encrypt) and JNUSTool (decrypt)."); + Cll.Log.WriteLine(""); } else { if (!File.Exists("resources\\nuspacker\\NUSPacker.jar")) { - injector.Log.WriteLine("Warning! \"resources\\nuspacker\\NUSPacker.jar\" not found!"); - injector.Log.WriteLine("NUSPacker allows you to encrypt the result for WUPInstaller."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("Warning! \"resources\\nuspacker\\NUSPacker.jar\" not found!"); + Cll.Log.WriteLine("NUSPacker allows you to encrypt the result for WUPInstaller."); + Cll.Log.WriteLine(""); } if (!File.Exists("resources\\jnustool\\JNUSTool.jar")) { - injector.Log.WriteLine("Warning! \"resources\\jnustool\\JNUSTool.jar\" not found!"); - injector.Log.WriteLine("JNUSTool allows you to decrypt Wii U VC games to use as a base."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("Warning! \"resources\\jnustool\\JNUSTool.jar\" not found!"); + Cll.Log.WriteLine("JNUSTool allows you to decrypt Wii U VC games to use as a base."); + Cll.Log.WriteLine(""); } } if (NusContent.CheckCommonKeyFiles()) - injector.Log.WriteLine("Common Key found successfully."); + Cll.Log.WriteLine("Common Key found successfully."); else - injector.Log.WriteLine("Common Key not found. Use load-key option."); + Cll.Log.WriteLine("Common Key not found. Use load-key option."); if (injector.BaseIsLoaded) - injector.Log.WriteLine("Base loaded: " + injector.LoadedBase); + Cll.Log.WriteLine("Base loaded: " + injector.LoadedBase); else - injector.Log.WriteLine("Base not found. Use load-base option or specify one using the -base option."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("Base not found. Use load-base option or specify one using the -base option."); + Cll.Log.WriteLine(""); if (args.Length == 0) { @@ -60,36 +64,36 @@ public void Run(string[] args) } else if (args.Length == 2 && args[0] == "load-key") { - injector.Log.WriteLine("load-key: " + args[1]); + Cll.Log.WriteLine("load-key: " + args[1]); if (NusContent.LoadKey(args[1])) - injector.Log.WriteLine("Common Key loaded successfully."); + Cll.Log.WriteLine("Common Key loaded successfully."); else - injector.Log.WriteLine("The load of the key failed. Is a valid Common Key?"); + Cll.Log.WriteLine("The load of the key failed. Is a valid Common Key?"); } else if (args.Length == 2 && args[0] == "load-base") { - injector.Log.WriteLine("load-base: " + args[1]); - injector.Log.WriteLine("Loading base, please wait..."); + Cll.Log.WriteLine("load-base: " + args[1]); + Cll.Log.WriteLine("Loading base, please wait..."); if (injector.LoadBase(args[1])) - injector.Log.WriteLine("Base loaded: " + injector.LoadedBase); + Cll.Log.WriteLine("Base loaded: " + injector.LoadedBase); else - injector.Log.WriteLine("The base was not loaded correctly."); + Cll.Log.WriteLine("The base was not loaded correctly."); } else if (args.Length >= 1 && args[0] == "create-image") { if (CreateImage(args)) - injector.Log.WriteLine("Image created."); + Cll.Log.WriteLine("Image created."); else - injector.Log.WriteLine("Image not created."); + Cll.Log.WriteLine("Image not created."); } else if (args.Length >= 1 && args[0] == "create-icon") { if (CreateIcon(args)) - injector.Log.WriteLine("Icon created."); + Cll.Log.WriteLine("Icon created."); else - injector.Log.WriteLine("Icon not created."); + Cll.Log.WriteLine("Icon not created."); } else if ((args.Length == 3 || args.Length == 5) && (args[0] == "pack" || args[0] == "unpack")) @@ -104,14 +108,15 @@ public void Run(string[] args) _continue = ValidArgs(); if (_continue) - _continue = Inject(); + Inject(); } - //Console.ReadLine(); + Cll.Log.WriteLine("Close."); + Cll.Log.WriteLine("----------------------------------------------------------------"); } private void ConsoleHelp() { - injector.Log.WriteText(global::_64Inject.Properties.Resources.Help, 80, 0, Cll.Log.TabMode.All); + Cll.Log.WriteText(global::_64Inject.Properties.Resources.Help, 80, 0, Cll.Log.TabMode.All); } private bool CreateImage(string[] args) @@ -137,7 +142,7 @@ private bool CreateImage(string[] args) } else { - injector.Log.WriteLine("Error in the \"-frame\" option."); + Cll.Log.WriteLine("Error in the \"-frame\" option."); return false; } case "-title": @@ -148,7 +153,7 @@ private bool CreateImage(string[] args) } else { - injector.Log.WriteLine("Error in the \"-title\" option."); + Cll.Log.WriteLine("Error in the \"-title\" option."); return false; } case "-name": @@ -161,7 +166,7 @@ private bool CreateImage(string[] args) } else { - injector.Log.WriteLine("Error in the \"-name\" option."); + Cll.Log.WriteLine("Error in the \"-name\" option."); return false; } case "-longname": @@ -174,7 +179,7 @@ private bool CreateImage(string[] args) } else { - injector.Log.WriteLine("Error in the \"-longname\" option."); + Cll.Log.WriteLine("Error in the \"-longname\" option."); return false; } case "-r": @@ -185,7 +190,7 @@ private bool CreateImage(string[] args) } else { - injector.Log.WriteLine("Error in the \"-r\" option."); + Cll.Log.WriteLine("Error in the \"-r\" option."); return false; } case "-p": @@ -196,7 +201,7 @@ private bool CreateImage(string[] args) } else { - injector.Log.WriteLine("Error in the \"-p\" option."); + Cll.Log.WriteLine("Error in the \"-p\" option."); return false; } case "-out": @@ -207,23 +212,23 @@ private bool CreateImage(string[] args) } else { - injector.Log.WriteLine("Error in the \"-out\" option."); + Cll.Log.WriteLine("Error in the \"-out\" option."); return false; } default: - injector.Log.WriteLine("Invalid option \"" + args[i] + "\"."); + Cll.Log.WriteLine("Invalid option \"" + args[i] + "\"."); return false; } } if (framePath != null && !File.Exists(framePath)) { - injector.Log.WriteLine("The frame image \"" + framePath + "\" not exists."); + Cll.Log.WriteLine("The frame image \"" + framePath + "\" not exists."); return false; } if (titlePath != null && !File.Exists(titlePath)) { - injector.Log.WriteLine("The title screen \"" + titlePath + "\" not exists."); + Cll.Log.WriteLine("The title screen \"" + titlePath + "\" not exists."); return false; } if (released != null) @@ -233,13 +238,13 @@ private bool CreateImage(string[] args) bootImg.Released = Convert.ToInt32(released); if (bootImg.Released < 1996) { - injector.Log.WriteLine("The year of release is less than 1996."); + Cll.Log.WriteLine("The year of release is less than 1996."); return false; } } catch { - injector.Log.WriteLine("The year of release is not an integer."); + Cll.Log.WriteLine("The year of release is not an integer."); return false; } } @@ -250,13 +255,13 @@ private bool CreateImage(string[] args) bootImg.Players = Convert.ToInt32(players); if (bootImg.Players < 1 || bootImg.Players > 4) { - injector.Log.WriteLine("The number of players must be between 1 and 4."); + Cll.Log.WriteLine("The number of players must be between 1 and 4."); return false; } } catch { - injector.Log.WriteLine("The number of players is not an integer."); + Cll.Log.WriteLine("The number of players is not an integer."); return false; } } @@ -264,7 +269,7 @@ private bool CreateImage(string[] args) { if (!Directory.Exists(outPath)) { - injector.Log.WriteLine("The \"" + outPath + "\" folder not exist."); + Cll.Log.WriteLine("The \"" + outPath + "\" folder not exist."); return false; } } @@ -272,17 +277,17 @@ private bool CreateImage(string[] args) outPath = Environment.CurrentDirectory; outPath += "\\image.png"; - injector.Log.WriteLine("Creating image ----------------------------------------------------------------"); - if (titlePath != null) injector.Log.WriteLine("title: " + titlePath); - if (framePath != null) injector.Log.WriteLine("frame: " + framePath); + Cll.Log.WriteLine("Creating image ----------------------------------------------------------------"); + if (titlePath != null) Cll.Log.WriteLine("title: " + titlePath); + if (framePath != null) Cll.Log.WriteLine("frame: " + framePath); if (bootImg.NameLine1 != "") { - if (bootImg.NameLine2 == "") injector.Log.WriteLine("name: " + bootImg.NameLine1); - else injector.Log.WriteLine("longname:\n" + bootImg.NameLine1 + "\n" + bootImg.NameLine2); + if (bootImg.NameLine2 == "") Cll.Log.WriteLine("name: " + bootImg.NameLine1); + else Cll.Log.WriteLine("longname:\n" + bootImg.NameLine1 + "\n" + bootImg.NameLine2); } - if (released != null) injector.Log.WriteLine("released: " + released); - if (players != null) injector.Log.WriteLine("players: " + players); - if (outPath != null) injector.Log.WriteLine("out: " + outPath); + if (released != null) Cll.Log.WriteLine("released: " + released); + if (players != null) Cll.Log.WriteLine("players: " + players); + if (outPath != null) Cll.Log.WriteLine("out: " + outPath); System.Drawing.Bitmap image = null; try @@ -329,7 +334,7 @@ private bool CreateIcon(string[] args) } else { - injector.Log.WriteLine("Error in the \"-frame\" option."); + Cll.Log.WriteLine("Error in the \"-frame\" option."); return false; } case "-title": @@ -340,7 +345,7 @@ private bool CreateIcon(string[] args) } else { - injector.Log.WriteLine("Error in the \"-title\" option."); + Cll.Log.WriteLine("Error in the \"-title\" option."); return false; } case "-out": @@ -351,30 +356,30 @@ private bool CreateIcon(string[] args) } else { - injector.Log.WriteLine("Error in the \"-out\" option."); + Cll.Log.WriteLine("Error in the \"-out\" option."); return false; } default: - injector.Log.WriteLine("Invalid option \"" + args[i] + "\"."); + Cll.Log.WriteLine("Invalid option \"" + args[i] + "\"."); return false; } } if (framePath != null && !File.Exists(framePath)) { - injector.Log.WriteLine("The frame image \"" + framePath + "\" not exists."); + Cll.Log.WriteLine("The frame image \"" + framePath + "\" not exists."); return false; } if (titlePath != null && !File.Exists(titlePath)) { - injector.Log.WriteLine("The title screen \"" + titlePath + "\" not exists."); + Cll.Log.WriteLine("The title screen \"" + titlePath + "\" not exists."); return false; } if (outPath != null) { if (!Directory.Exists(outPath)) { - injector.Log.WriteLine("The \"" + outPath + "\" folder not exist."); + Cll.Log.WriteLine("The \"" + outPath + "\" folder not exist."); return false; } } @@ -382,10 +387,10 @@ private bool CreateIcon(string[] args) outPath = Environment.CurrentDirectory; outPath += "\\icon.png"; - injector.Log.WriteLine("Creating icon -----------------------------------------------------------------"); - if (titlePath != null) injector.Log.WriteLine("title: " + titlePath); - if (framePath != null) injector.Log.WriteLine("frame: " + framePath); - if (outPath != null) injector.Log.WriteLine("out: " + outPath); + Cll.Log.WriteLine("Creating icon -----------------------------------------------------------------"); + if (titlePath != null) Cll.Log.WriteLine("title: " + titlePath); + if (framePath != null) Cll.Log.WriteLine("frame: " + framePath); + if (outPath != null) Cll.Log.WriteLine("out: " + outPath); System.Drawing.Bitmap icon = null; try @@ -430,8 +435,8 @@ private void PackUnpack(string[] args) } else { - injector.Log.WriteLine("Incorrect " + args[0] + " syntax."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("Incorrect " + args[0] + " syntax."); + Cll.Log.WriteLine(""); _continue = false; } @@ -439,16 +444,16 @@ private void PackUnpack(string[] args) { if (!Directory.Exists(injector.InPath) || !Path.IsPathRooted(injector.InPath)) { - injector.Log.WriteLine("The input folder \"" + injector.InPath + "\" not exist."); - injector.Log.WriteLine("Do not use relative paths."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("The input folder \"" + injector.InPath + "\" not exist."); + Cll.Log.WriteLine("Do not use relative paths."); + Cll.Log.WriteLine(""); _continue = false; } if (!Directory.Exists(injector.OutPath) || !Path.IsPathRooted(injector.OutPath)) { - injector.Log.WriteLine("The output folder \"" + injector.OutPath + "\" not exist."); - injector.Log.WriteLine("Do not use relative paths."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("The output folder \"" + injector.OutPath + "\" not exist."); + Cll.Log.WriteLine("Do not use relative paths."); + Cll.Log.WriteLine(""); _continue = false; } } @@ -457,53 +462,53 @@ private void PackUnpack(string[] args) if (Directory.GetDirectories(injector.OutPath).Length != 0 || Directory.GetFiles(injector.OutPath).Length != 0) { - injector.Log.WriteLine("The \"" + injector.OutPath + "\" folder exist and not empty."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("The \"" + injector.OutPath + "\" folder exist and not empty."); + Cll.Log.WriteLine(""); _continue = false; } if (_continue) { - injector.Log.WriteLine("in: " + injector.InPath); - injector.Log.WriteLine("out: " + injector.OutPath); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("in: " + injector.InPath); + Cll.Log.WriteLine("out: " + injector.OutPath); + Cll.Log.WriteLine(""); if (args[0] == "pack") { if (NusContent.Encrypt(injector.InPath, injector.OutPath)) - injector.Log.WriteLine("The encryption was successful."); + Cll.Log.WriteLine("The encryption was successful."); else - injector.Log.WriteLine("The encryption failed."); + Cll.Log.WriteLine("The encryption failed."); } else if (args[0] == "unpack") { if (NusContent.Decrypt(injector.InPath, injector.OutPath)) - injector.Log.WriteLine("The decryption was successful."); + Cll.Log.WriteLine("The decryption was successful."); else - injector.Log.WriteLine("The decryption failed."); + Cll.Log.WriteLine("The decryption failed."); } } else if (args[0] == "pack") - injector.Log.WriteLine("The encryption failed."); + Cll.Log.WriteLine("The encryption failed."); else - injector.Log.WriteLine("The decryption failed."); + Cll.Log.WriteLine("The decryption failed."); } private bool Inject() { - injector.Log.WriteLine("Injecting ---------------------------------------------------------------------"); - if (injector.BasePath != null) injector.Log.WriteLine("base: " + injector.BasePath); - if (injector.ShortName != null) injector.Log.WriteLine("name: " + injector.ShortName); - if (injector.LongName != null) injector.Log.WriteLine("longname:\n" + injector.LongName); - if (injector.InPath != null) injector.Log.WriteLine("in: " + injector.InPath); - if (injector.RomPath != null) injector.Log.WriteLine("rom: " + injector.RomPath); - if (injector.IniPath != null) injector.Log.WriteLine("ini: " + injector.IniPath); - if (injector.BootTvPath != null) injector.Log.WriteLine("tv: " + injector.BootTvPath); - if (injector.BootDrcPath != null) injector.Log.WriteLine("drc: " + injector.BootDrcPath); - if (injector.IconPath != null) injector.Log.WriteLine("icon: " + injector.IconPath); - if (injector.OutPath != null) injector.Log.WriteLine("out: " + injector.OutPath); - injector.Log.WriteLine("encrypt: " + injector.Encrypt.ToString()); - injector.Log.WriteLine("Please wait..."); + Cll.Log.WriteLine("Injecting - - - - - - - - - - - - - - - - - - - - - - - - - - - "); + if (injector.BasePath != null) Cll.Log.WriteLine("base: " + injector.BasePath); + if (injector.ShortName != null) Cll.Log.WriteLine("name: " + injector.ShortName); + if (injector.LongName != null) Cll.Log.WriteLine("longname:\n" + injector.LongName); + if (injector.InPath != null) Cll.Log.WriteLine("in: " + injector.InPath); + if (injector.RomPath != null) Cll.Log.WriteLine("rom: " + injector.RomPath); + if (injector.IniPath != null) Cll.Log.WriteLine("ini: " + injector.IniPath); + if (injector.BootTvPath != null) Cll.Log.WriteLine("tv: " + injector.BootTvPath); + if (injector.BootDrcPath != null) Cll.Log.WriteLine("drc: " + injector.BootDrcPath); + if (injector.IconPath != null) Cll.Log.WriteLine("icon: " + injector.IconPath); + if (injector.OutPath != null) Cll.Log.WriteLine("out: " + injector.OutPath); + Cll.Log.WriteLine("encrypt: " + injector.Encrypt.ToString()); + Cll.Log.WriteLine("Please wait..."); return injector.Inject(); } @@ -522,7 +527,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-base\" option."); + Cll.Log.WriteLine("Error in the \"-base\" option."); return false; } case "-name": @@ -533,7 +538,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-name\" option."); + Cll.Log.WriteLine("Error in the \"-name\" option."); return false; } case "-longname": @@ -544,7 +549,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-longname\" option."); + Cll.Log.WriteLine("Error in the \"-longname\" option."); return false; } case "no-darkfilter": @@ -561,7 +566,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-zoom\" option."); + Cll.Log.WriteLine("Error in the \"-zoom\" option."); return false; } case "-in": @@ -572,7 +577,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-in\" option."); + Cll.Log.WriteLine("Error in the \"-in\" option."); return false; } case "-rom": @@ -583,7 +588,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-rom\" option."); + Cll.Log.WriteLine("Error in the \"-rom\" option."); return false; } case "-ini": @@ -594,7 +599,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-ini\" option."); + Cll.Log.WriteLine("Error in the \"-ini\" option."); return false; } case "-icon": @@ -605,7 +610,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-icon\" option."); + Cll.Log.WriteLine("Error in the \"-icon\" option."); return false; } case "-tv": @@ -616,7 +621,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-tv\" option."); + Cll.Log.WriteLine("Error in the \"-tv\" option."); return false; } case "-drc": @@ -627,7 +632,7 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-drc\" option."); + Cll.Log.WriteLine("Error in the \"-drc\" option."); return false; } case "-out": @@ -638,14 +643,14 @@ private bool LoadArgs(string[] args) } else { - injector.Log.WriteLine("Error in the \"-out\" option."); + Cll.Log.WriteLine("Error in the \"-out\" option."); return false; } case "not-encrypt": injector.Encrypt = false; break; default: - injector.Log.WriteLine("Invalid option \"" + args[i] + "\"."); + Cll.Log.WriteLine("Invalid option \"" + args[i] + "\"."); return false; } } @@ -696,24 +701,24 @@ private bool ValidBasePath() { if (injector.BasePath != null) { - injector.Log.WriteLine("Loading base, please wait..."); + Cll.Log.WriteLine("Loading base, please wait..."); if (injector.LoadBase(injector.BasePath)) { - injector.Log.WriteLine("Base loaded: " + injector.LoadedBase); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("Base loaded: " + injector.LoadedBase); + Cll.Log.WriteLine(""); } else { - injector.Log.WriteLine("The base was not loaded correctly."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("The base was not loaded correctly."); + Cll.Log.WriteLine(""); return false; } } else if (!injector.BaseIsLoaded) { - injector.Log.WriteLine("There is not a loaded base."); - injector.Log.WriteLine(""); + Cll.Log.WriteLine("There is not a loaded base."); + Cll.Log.WriteLine(""); return false; } return true; @@ -725,12 +730,12 @@ private bool ValidShortName() { if (injector.ShortName.Length == 0) { - injector.Log.WriteLine("The name of the game is empty."); + Cll.Log.WriteLine("The name of the game is empty."); return false; } else if (injector.ShortName.Length > 256) { - injector.Log.WriteLine("The name is not valid, it has more than 256 characters."); + Cll.Log.WriteLine("The name is not valid, it has more than 256 characters."); return false; } } @@ -747,12 +752,12 @@ private bool ValidLongName() { if (injector.ShortName.Length == 0) { - injector.Log.WriteLine("The long name of the game is empty."); + Cll.Log.WriteLine("The long name of the game is empty."); return false; } else if (injector.LongName.Length > 512) { - injector.Log.WriteLine("The long name is not valid, it has more than 512 characters."); + Cll.Log.WriteLine("The long name is not valid, it has more than 512 characters."); return false; } } @@ -772,24 +777,24 @@ private bool ValidZoom() injector.Scale = Convert.ToSingle(injector.Zoom); if (injector.Scale < 50.0F || injector.Scale > 200.0F) { - injector.Log.WriteLine("The zoom value must be between 50 and 200."); + Cll.Log.WriteLine("The zoom value must be between 50 and 200."); return false; } } catch { - injector.Log.WriteLine("The zoom value is not a number."); + Cll.Log.WriteLine("The zoom value is not a number."); return false; } if (injector.ShortName.Length == 0) { - injector.Log.WriteLine("The name of the game is empty."); + Cll.Log.WriteLine("The name of the game is empty."); return false; } else if (injector.ShortName.Length > 256) { - injector.Log.WriteLine("The name is not valid, it has more than 256 characters."); + Cll.Log.WriteLine("The name is not valid, it has more than 256 characters."); return false; } } @@ -806,12 +811,12 @@ private bool ValidInPath() { if (!Directory.Exists(injector.InPath)) { - injector.Log.WriteLine("The input folder \"" + injector.InPath + "\" not exists."); + Cll.Log.WriteLine("The input folder \"" + injector.InPath + "\" not exists."); return false; } } else - injector.Log.WriteLine("The input folder was not specified."); + Cll.Log.WriteLine("The input folder was not specified."); return true; } @@ -824,13 +829,13 @@ private bool ValidRomPath() injector.Rom = new RomN64(injector.RomPath); if (!injector.Rom.IsValid) { - injector.Log.WriteLine("The ROM file is not valid."); + Cll.Log.WriteLine("The ROM file is not valid."); return false; } } else { - injector.Log.WriteLine("The ROM file \"" + injector.RomPath + "\" not exists."); + Cll.Log.WriteLine("The ROM file \"" + injector.RomPath + "\" not exists."); return false; } } @@ -844,20 +849,20 @@ private bool ValidRomPath() injector.Rom = new RomN64(injector.RomPath); if (!injector.Rom.IsValid) { - injector.Log.WriteLine("The ROM file is not valid."); + Cll.Log.WriteLine("The ROM file is not valid."); return false; } } else { - injector.Log.WriteLine("The ROM file \"" + injector.RomPath + "\" not exists."); + Cll.Log.WriteLine("The ROM file \"" + injector.RomPath + "\" not exists."); return false; } } else { - //injector.Log.WriteLine("The input folder was not specified."); - injector.Log.WriteLine("ROM not found."); + //Cll.Log.WriteLine("The input folder was not specified."); + Cll.Log.WriteLine("ROM not found."); return false; } } @@ -872,13 +877,13 @@ private bool ValidIniPath() { if (!injector.LoadIni(injector.IniPath)) { - injector.Log.WriteLine("The INI file is not valid."); + Cll.Log.WriteLine("The INI file is not valid."); return false; } } else { - injector.Log.WriteLine("The INI file \"" + injector.IniPath + "\" not exists."); + Cll.Log.WriteLine("The INI file \"" + injector.IniPath + "\" not exists."); return false; } } @@ -891,21 +896,21 @@ private bool ValidIniPath() { if (!injector.LoadIni(injector.IniPath)) { - injector.Log.WriteLine("The INI file is not valid."); + Cll.Log.WriteLine("The INI file is not valid."); return false; } } else { injector.IniPath = null; - injector.Log.WriteLine("The INI file \"" + injector.IniPath + "\" not exists."); - injector.Log.WriteLine("An empty INI file will be used."); + Cll.Log.WriteLine("The INI file \"" + injector.IniPath + "\" not exists."); + Cll.Log.WriteLine("An empty INI file will be used."); } } else { - //injector.Log.WriteLine("The input folder was not specified."); - injector.Log.WriteLine("An empty INI file will be used."); + //Cll.Log.WriteLine("The input folder was not specified."); + Cll.Log.WriteLine("An empty INI file will be used."); } } return true; @@ -917,7 +922,7 @@ private bool ValidBootTvPath() { if (!File.Exists(injector.BootTvPath)) { - injector.Log.WriteLine("The boot tv image file \"" + injector.BootTvPath + "\" not exists."); + Cll.Log.WriteLine("The boot tv image file \"" + injector.BootTvPath + "\" not exists."); return false; } else @@ -930,24 +935,24 @@ private bool ValidBootTvPath() injector.BootTvPath = injector.InPath + "\\tv.png"; if (!File.Exists(injector.BootTvPath)) { - injector.Log.WriteLine("The boot tv image file \"" + injector.BootTvPath + "\" not exists."); + Cll.Log.WriteLine("The boot tv image file \"" + injector.BootTvPath + "\" not exists."); if (File.Exists("resources\\boot.png")) injector.BootTvPath = "resources\\boot.png"; else injector.BootTvPath = null; - injector.Log.WriteLine("A default image will be used as boot tv."); + Cll.Log.WriteLine("A default image will be used as boot tv."); } else injector.BootTvImg.IsDefault = false; } else { - //injector.Log.WriteLine("The input folder was not specified."); + //Cll.Log.WriteLine("The input folder was not specified."); if (File.Exists("resources\\boot.png")) injector.BootTvPath = "resources\\boot.png"; else injector.BootTvPath = null; - injector.Log.WriteLine("A default image will be used as boot tv."); + Cll.Log.WriteLine("A default image will be used as boot tv."); } } return true; @@ -959,7 +964,7 @@ private bool ValidBootDrcPath() { if (!File.Exists(injector.BootDrcPath)) { - injector.Log.WriteLine("The boot drc image file \"" + injector.BootDrcPath + "\" not exists."); + Cll.Log.WriteLine("The boot drc image file \"" + injector.BootDrcPath + "\" not exists."); return false; } else @@ -972,7 +977,7 @@ private bool ValidBootDrcPath() injector.BootDrcPath = injector.InPath + "\\drc.png"; if (!File.Exists(injector.BootDrcPath)) { - injector.Log.WriteLine("The boot drc image file \"" + injector.BootDrcPath + "\" not exists."); + Cll.Log.WriteLine("The boot drc image file \"" + injector.BootDrcPath + "\" not exists."); injector.BootDrcPath = injector.BootTvPath; if (!File.Exists(injector.BootDrcPath)) { @@ -980,17 +985,17 @@ private bool ValidBootDrcPath() injector.BootDrcPath = "resources\\boot.png"; else injector.BootDrcPath = null; - injector.Log.WriteLine("A default image will be used as boot drc."); + Cll.Log.WriteLine("A default image will be used as boot drc."); } else - injector.Log.WriteLine("The boot tv image will be used as boot drc."); + Cll.Log.WriteLine("The boot tv image will be used as boot drc."); } else injector.BootDrcImg.IsDefault = false; } else { - //injector.Log.WriteLine("The input folder was not specified."); + //Cll.Log.WriteLine("The input folder was not specified."); injector.BootDrcPath = injector.BootTvPath; if (!File.Exists(injector.BootDrcPath)) { @@ -998,10 +1003,10 @@ private bool ValidBootDrcPath() injector.BootDrcPath = "resources\\boot.png"; else injector.BootDrcPath = null; - injector.Log.WriteLine("A default image will be used as boot drc."); + Cll.Log.WriteLine("A default image will be used as boot drc."); } else - injector.Log.WriteLine("The boot tv image will be used as boot drc."); + Cll.Log.WriteLine("The boot tv image will be used as boot drc."); } } return true; @@ -1013,7 +1018,7 @@ private bool ValidIconPath() { if (!File.Exists(injector.IconPath)) { - injector.Log.WriteLine("The icon file \"" + injector.IconPath + "\" not exists."); + Cll.Log.WriteLine("The icon file \"" + injector.IconPath + "\" not exists."); return false; } else @@ -1026,24 +1031,24 @@ private bool ValidIconPath() injector.IconPath = injector.InPath + "\\icon.png"; if (!File.Exists(injector.IconPath)) { - injector.Log.WriteLine("The icon file \"" + injector.IconPath + "\" not exists."); + Cll.Log.WriteLine("The icon file \"" + injector.IconPath + "\" not exists."); if (File.Exists("resources\\icon.png")) injector.IconPath = "resources\\icon.png"; else injector.IconPath = null; - injector.Log.WriteLine("A default image will be used as icon."); + Cll.Log.WriteLine("A default image will be used as icon."); } else injector.IconImg.IsDefault = false; } else { - //injector.Log.WriteLine("The input folder was not specified."); + //Cll.Log.WriteLine("The input folder was not specified."); if (File.Exists("resources\\icon.png")) injector.IconPath = "resources\\icon.png"; else injector.IconPath = null; - injector.Log.WriteLine("A default image will be used as icon."); + Cll.Log.WriteLine("A default image will be used as icon."); } } return true; @@ -1055,15 +1060,15 @@ private bool ValidOutPath() { if (!Directory.Exists(injector.OutPath)) { - injector.Log.WriteLine("The \"" + injector.OutPath + "\" folder not exist."); + Cll.Log.WriteLine("The \"" + injector.OutPath + "\" folder not exist."); return false; } } else { - injector.Log.WriteLine("The output folder was not specified."); + Cll.Log.WriteLine("The output folder was not specified."); injector.OutPath = Environment.CurrentDirectory; - injector.Log.WriteLine("The root folder of 64Inject will be used as the output folder."); + Cll.Log.WriteLine("The root folder of 64Inject will be used as the output folder."); } injector.OutPath += "\\" + injector.ShortNameASCII + " [" + injector.TitleId + "]"; @@ -1072,7 +1077,7 @@ private bool ValidOutPath() if (Directory.GetDirectories(injector.OutPath).Length != 0 || Directory.GetFiles(injector.OutPath).Length != 0) { - injector.Log.WriteLine("The \"" + injector.OutPath + "\" folder exist and not empty."); + Cll.Log.WriteLine("The \"" + injector.OutPath + "\" folder exist and not empty."); return false; } diff --git a/64Inject/64InjectGUI.cs b/64Inject/64InjectGUI.cs index 2e7369b..dd249b6 100644 --- a/64Inject/64InjectGUI.cs +++ b/64Inject/64InjectGUI.cs @@ -18,6 +18,10 @@ public partial class _64InjectGUI : Form public _64InjectGUI() { + Cll.Log.SaveIn("64Inject_log.txt"); + Cll.Log.WriteLine(DateTime.UtcNow.ToString()); + Cll.Log.WriteLine("64Inject open in GUI mode."); + injector = new _64Injector(); InitializeComponent(); @@ -100,6 +104,8 @@ public _64InjectGUI() private void _64InjectGUI_FormClosing(object sender, FormClosingEventArgs e) { SaveXmlConfig(); + Cll.Log.WriteLine("Close."); + Cll.Log.WriteLine("----------------------------------------------------------------"); } #region Config @@ -660,6 +666,20 @@ private void buttonInject_Click(object sender, EventArgs e) if (_continue) { + Cll.Log.WriteLine("Injecting - - - - - - - - - - - - - - - - - - - - - - - - - - - "); + if (injector.BasePath != null) Cll.Log.WriteLine("base: " + injector.BasePath); + if (injector.ShortName != null) Cll.Log.WriteLine("name: " + injector.ShortName); + if (injector.LongName != null) Cll.Log.WriteLine("longname:\n" + injector.LongName); + if (injector.InPath != null) Cll.Log.WriteLine("in: " + injector.InPath); + if (injector.RomPath != null) Cll.Log.WriteLine("rom: " + injector.RomPath); + if (injector.IniPath != null) Cll.Log.WriteLine("ini: " + injector.IniPath); + if (injector.BootTvPath != null) Cll.Log.WriteLine("tv: " + injector.BootTvPath); + if (injector.BootDrcPath != null) Cll.Log.WriteLine("drc: " + injector.BootDrcPath); + if (injector.IconPath != null) Cll.Log.WriteLine("icon: " + injector.IconPath); + if (injector.OutPath != null) Cll.Log.WriteLine("out: " + injector.OutPath); + Cll.Log.WriteLine("encrypt: " + injector.Encrypt.ToString()); + Cll.Log.WriteLine("Please wait..."); + if (injector.Inject()) MessageBox.Show("Injection completed successfully!", "64Inject", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -839,10 +859,12 @@ private bool AskBase() textBoxBaseFrom.Text = folderBrowserDialog.SelectedPath; + Cll.Log.WriteLine("Loading base."); if (injector.LoadBase(textBoxBaseFrom.Text)) { labelLoadedBase.Text = "Base loaded: " + injector.LoadedBase; panelLoadedBase.BackgroundImage = global::_64Inject.Properties.Resources.checkmark_16; + Cll.Log.WriteLine("Base loaded: " + injector.LoadedBase); return true; } else diff --git a/64Inject/64Injector.cs b/64Inject/64Injector.cs index 32af48f..169b365 100644 --- a/64Inject/64Injector.cs +++ b/64Inject/64Injector.cs @@ -10,9 +10,7 @@ namespace _64Inject { public class _64Injector { - public const string Release = "1.2 debug"; //CllVersionReplace "major.minor stability" - - public Cll.Log Log; + public const string Release = "1.3 debug"; //CllVersionReplace "major.minor stability" public string BasePath; public string ShortName; @@ -35,8 +33,7 @@ public class _64Injector public float Scale; public BootImage BootTvImg; public BootImage BootDrcImg; - public IconImage IconImg; - + public IconImage IconImg; public bool BaseIsLoaded { @@ -125,8 +122,6 @@ public string TitleId public _64Injector() { - Log = new Cll.Log(); - BasePath = null; ShortName = null; LongName = null; @@ -155,7 +150,7 @@ public bool Inject() { _base = GetLoadedBase(); bool _continue = BaseIsLoaded; - Log.WriteLine("The base is ready: " + _continue.ToString()); + Cll.Log.WriteLine("The base is ready: " + _continue.ToString()); if (_continue) _continue = InjectGameLayout(); @@ -173,21 +168,21 @@ public bool Inject() { if (Encrypt) { - Log.WriteLine("Creating encrypted output."); + Cll.Log.WriteLine("Creating encrypted output."); string inPath = Environment.CurrentDirectory + "\\base"; _continue = NusContent.Encrypt(inPath, OutPath); } else { - Log.WriteLine("Creating unencrypted output."); + Cll.Log.WriteLine("Creating unencrypted output."); _continue = Useful.DirectoryCopy("base", OutPath, true); } } if (_continue) - Log.WriteLine("Injection completed successfully!"); + Cll.Log.WriteLine("Injection completed successfully!"); else - Log.WriteLine("The injection failed."); + Cll.Log.WriteLine("The injection failed."); return _continue; } @@ -197,6 +192,8 @@ private bool InjectGameLayout() FileStream fs = null; try { + Cll.Log.WriteLine("Editing \"FrameLayout.arc\" file."); + byte darkFilterB = (byte)(DarkFilter ? 1 : 0); byte[] widescreenB = Widescreen ? new byte[] { 0x44, 0xF0, 0, 0 } : @@ -290,6 +287,7 @@ private bool InjectGameLayout() } else if (name == "power_save_bg") { + Cll.Log.WriteLine("\"FrameLayout.arc\" file editing successfully."); return true; } @@ -309,7 +307,7 @@ private bool InjectGameLayout() } fs.Close(); } - catch { Log.WriteLine("Error editing the \"FrameLayout.arc\"."); } + catch { Cll.Log.WriteLine("Error editing \"FrameLayout.arc\"."); } finally { if (fs != null) fs.Close(); } return false; @@ -326,6 +324,8 @@ private bool InjectImages() try { + Cll.Log.WriteLine("Creating bitmaps."); + if (BootTvPath != null) tmp = new Bitmap(BootTvPath); else @@ -355,19 +355,32 @@ private bool InjectImages() g.DrawImage(tmp, new Rectangle(0, 0, 128, 128)); g.Dispose(); tmp.Dispose(); + + Cll.Log.WriteLine("Bitmaps created."); } catch { - Log.WriteLine("Error creating images."); + Cll.Log.WriteLine("Error creating bitmaps."); return false; } if (!NusContent.ConvertToTGA(bootTvImg, currentDir + "\\base\\meta\\bootTvTex.tga")) + { + Cll.Log.WriteLine("Error creating \"bootTvTex.tga\" file."); return false; + } if (!NusContent.ConvertToTGA(bootDrcImg, currentDir + "\\base\\meta\\bootDrcTex.tga")) + { + Cll.Log.WriteLine("Error creating \"bootDrcTex.tga\" file."); return false; + } if (!NusContent.ConvertToTGA(iconImg, currentDir + "\\base\\meta\\iconTex.tga")) + { + Cll.Log.WriteLine("Error creating \"iconTex.tga\" file."); return false; + } + + Cll.Log.WriteLine("Injected TGA files."); return true; } @@ -391,6 +404,8 @@ private bool InjectMeta() try { + Cll.Log.WriteLine("Editing \"app.xml\" and \"meta.xml\" files."); + xmlApp.Load("base\\code\\app.xml"); xmlMeta.Load("base\\meta\\meta.xml"); @@ -421,11 +436,13 @@ private bool InjectMeta() app.Close(); meta.Close(); + Cll.Log.WriteLine("\"app.xml\" and \"meta.xml\" files editing successfully."); + return true; } catch { - Log.WriteLine("Error editing the \"meta.xml\"."); + Cll.Log.WriteLine("Error editing \"app.xml\" and \"meta.xml\" files."); } return false; @@ -437,27 +454,42 @@ private bool InjectRom() try { + Cll.Log.WriteLine("Empty \"base\\content\\config\" folder."); Directory.Delete("base\\content\\config", true); Directory.CreateDirectory("base\\content\\config"); + Cll.Log.WriteLine("Injecting INI data."); if (IniIsLoaded) { FileStream fs = File.Open("base\\content\\config\\U" + Rom.ProductCodeVersion + ".z64.ini", FileMode.Create); fs.Write(_ini, 0, _ini.Length); fs.Close(); + Cll.Log.WriteLine("INI injected."); } else + { File.Create("base\\content\\config\\U" + Rom.ProductCodeVersion + ".z64.ini").Close(); + Cll.Log.WriteLine("An empty INI injected."); + } + Cll.Log.WriteLine("Empty \"base\\content\\rom\" folder."); Directory.Delete("base\\content\\rom", true); Directory.CreateDirectory("base\\content\\rom"); - if (!RomN64.ToBigEndian(RomPath, "base\\content\\rom\\U" + Rom.ProductCodeVersion + ".z64")) + Cll.Log.WriteLine("Injecting ROM."); + if (RomN64.ToBigEndian(RomPath, "base\\content\\rom\\U" + Rom.ProductCodeVersion + ".z64")) + { + Cll.Log.WriteLine("Injected ROM."); + } + else + { + Cll.Log.WriteLine("ROM not injected, \"ToBigEndian\" failed."); injected = false; + } } catch { - Log.WriteLine("Error injecting ROM."); + Cll.Log.WriteLine("Error injecting ROM."); injected = false; } @@ -470,16 +502,23 @@ private bool InjectRom() public bool LoadBase(string path) { if (Directory.Exists("base")) + { Directory.Delete("base", true); + Cll.Log.WriteLine("Previous base deleted."); + } if (IsValidBase(path)) + { + Cll.Log.WriteLine("The \"" + path + "\" folder contains a valid base."); Useful.DirectoryCopy(path, "base", true); - + } else if (IsValidEncryptedBase(path)) + { + Cll.Log.WriteLine("The \"" + path + "\" folder contains a valid encrypted base."); NusContent.Decrypt(path, "base"); - + } else - Console.WriteLine("The \"" + path + "\" folder not contain a valid base."); + Cll.Log.WriteLine("The \"" + path + "\" folder not contains a valid base."); _base = GetLoadedBase(); diff --git a/64Inject/Log.cs b/64Inject/Log.cs index 427dba7..cce1a5e 100644 --- a/64Inject/Log.cs +++ b/64Inject/Log.cs @@ -4,7 +4,7 @@ namespace Cll { - public class Log : IDisposable + public static class Log { public enum TabMode { @@ -14,77 +14,36 @@ public enum TabMode All } - private bool disposed = false; - private StreamWriter _log; - - public Log() - { - _log = null; - } - - public Log(string filename) + private static String _filename; + public static void SaveIn(String filename, bool clear = true) { if (filename != null && filename.Length > 0) { - try - { - _log = File.CreateText(filename); - } - catch - { - _log = null; - } + _filename = filename; + if (clear) + File.Delete(filename); } else - _log = null; - } - - ~Log() - { - Dispose(false); - } - - public void Close() - { - Dispose(); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!this.disposed) - { - if (disposing) - { - if (_log != null) - _log.Dispose(); - } - disposed = true; - } + _filename = null; } - public void Write(string value) + public static void Write(string value) { Debug.Write(value); Console.Write(value); - if (_log != null) - _log.Write(value); + if (_filename != null) + File.AppendAllText(_filename, value); } - public void WriteLine(string value) + public static void WriteLine(string value) { Debug.WriteLine(value); Console.WriteLine(value); - if (_log != null) - _log.WriteLine(value); + if (_filename != null) + File.AppendAllText(_filename, value + "\r\n"); } - public void WriteLine(string value, int width, int tab, TabMode mode) + public static void WriteLine(string value, int width, int tab, TabMode mode) { int tabLength = GetTabLength(value); string t = tab > 0 ? new string(' ', tab) : value.Substring(0, tabLength); @@ -140,7 +99,7 @@ public void WriteLine(string value, int width, int tab, TabMode mode) WriteLine(mode == TabMode.All || mode == TabMode.OnlyFirst ? t : ""); } - public void WriteText(string text, int width, int tab, TabMode mode) + public static void WriteText(string text, int width, int tab, TabMode mode) { text = text.Replace("\r", ""); string[] lines = text.Split(new char[] { '\n' }); @@ -149,7 +108,7 @@ public void WriteText(string text, int width, int tab, TabMode mode) WriteLine(line, width, tab, mode); } - private int GetTabLength(string line) + private static int GetTabLength(string line) { int i; diff --git a/64Inject/Properties/AssemblyInfo.cs b/64Inject/Properties/AssemblyInfo.cs index cdf9c2a..9f5353e 100644 --- a/64Inject/Properties/AssemblyInfo.cs +++ b/64Inject/Properties/AssemblyInfo.cs @@ -5,7 +5,7 @@ // La información general sobre un ensamblado se controla mediante el siguiente // conjunto de atributos. Cambie estos atributos para modificar la información // asociada con un ensamblado. -[assembly: AssemblyTitle("64Inject debug")] +[assembly: AssemblyTitle("64Inject beta")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] @@ -32,5 +32,5 @@ // Puede especificar todos los valores o establecer como predeterminados los números de versión de compilación y de revisión // mediante el asterisco ('*'), como se muestra a continuación: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.25.0")] +[assembly: AssemblyVersion("1.3.64.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/64Inject/RomN64.cs b/64Inject/RomN64.cs index b585f9c..5bb84ee 100644 --- a/64Inject/RomN64.cs +++ b/64Inject/RomN64.cs @@ -53,6 +53,8 @@ public RomN64(string filename) try { + Cll.Log.WriteLine("Validating ROM."); + byte[] header = new byte[0x40]; FileStream fs = File.Open(filename, FileMode.Open); Size = (int)fs.Length; @@ -107,12 +109,22 @@ public RomN64(string filename) fs = File.Open(filename, FileMode.Open); HashCRC32 = Cll.Security.ComputeCRC32(fs); fs.Close(); + + Cll.Log.WriteLine("The ROM is valid and its metadata has been loaded."); } + else + Cll.Log.WriteLine("It was not possible to determine the ROM format."); } else + { Size = 0; + Cll.Log.WriteLine("The ROM is too small to be valid."); + } + } + catch + { + Cll.Log.WriteLine("Error reading ROM."); } - catch { } } ~RomN64()