From 1b0255bb95addc5d658add28e9cc4594d6580018 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Fri, 7 Aug 2020 03:32:46 +0200 Subject: [PATCH] CLI: Fix multi-image suffix was only applied to types.cs --- Il2CppInspector.CLI/Program.cs | 38 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Il2CppInspector.CLI/Program.cs b/Il2CppInspector.CLI/Program.cs index 4cbfffe..8e3507a 100644 --- a/Il2CppInspector.CLI/Program.cs +++ b/Il2CppInspector.CLI/Program.cs @@ -201,9 +201,11 @@ namespace Il2CppInspector.CLI if (il2cppInspectors == null) Environment.Exit(1); - // Write output file - int i = 0; + // Write output files for each binary + int imageIndex = 0; foreach (var il2cpp in il2cppInspectors) { + Console.WriteLine($"Processing image {imageIndex} - {il2cpp.BinaryImage.Arch} / {il2cpp.BinaryImage.Bits}-bit"); + // Create model TypeModel model; using (new Benchmark("Create .NET type model")) @@ -222,13 +224,7 @@ namespace Il2CppInspector.CLI MustCompile = options.MustCompile }; - var imageSuffix = i++ > 0 ? "-" + (i - 1) : ""; - - var csOut = options.CSharpOutPath; - if (csOut.ToLower().EndsWith(".cs")) - csOut = csOut.Insert(csOut.Length - 3, imageSuffix); - else - csOut += imageSuffix; + var csOut = getOutputPath(options.CSharpOutPath, "cs", imageIndex); if (options.CreateSolution) writer.WriteSolution(csOut, unityPath, unityAssembliesPath); @@ -271,25 +267,39 @@ namespace Il2CppInspector.CLI // C++ output using (new Benchmark("Generate C++ code")) { - new CppScaffolding(appModel).Write(options.CppOutPath); + new CppScaffolding(appModel).Write(getOutputPath(options.CppOutPath, "", imageIndex)); } // JSON output using (new Benchmark("Generate JSON metadata")) { - new JSONMetadata(appModel).Write(options.JsonOutPath); + new JSONMetadata(appModel).Write(getOutputPath(options.JsonOutPath, "json", imageIndex)); } // Python script output using (new Benchmark($"Generate {options.ScriptTarget} Python script")) { - new PythonScript(appModel).WriteScriptToFile(options.PythonOutFile, + new PythonScript(appModel).WriteScriptToFile( + getOutputPath(options.PythonOutFile, "py", imageIndex), options.ScriptTarget, - Path.Combine(options.CppOutPath, "appdata/il2cpp-types.h"), - options.JsonOutPath); + Path.Combine(getOutputPath(options.CppOutPath, "", imageIndex), "appdata/il2cpp-types.h"), + getOutputPath(options.JsonOutPath, "json", imageIndex)); } + + imageIndex++; } // Success exit code return 0; } + + private static string getOutputPath(string path, string extension, int suffix) { + if (suffix == 0) + return path; + var imageSuffix = "-" + suffix; + if (extension.Length > 0 && path.ToLower().EndsWith("." + extension)) + path = path.Insert(path.Length - (extension.Length + 1), imageSuffix); + else + path += imageSuffix; + return path; + } } }