Skip to content

Commit

Permalink
Reimplemented NetFramework Variant of Cpp2IL as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
HerpDerpinstine committed Sep 26, 2024
1 parent e6f7f3b commit a8033a5
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 56 deletions.
11 changes: 9 additions & 2 deletions Dependencies/Il2CppAssemblyGenerator/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net;
using System.Net.Http;
using MelonLoader.Il2CppAssemblyGenerator.Packages;
using MelonLoader.Il2CppAssemblyGenerator.Packages.Models;
using MelonLoader.Modules;
using MelonLoader.Utils;

Expand All @@ -16,7 +17,7 @@ internal class Core : MelonModule

internal static HttpClient webClient = null;

internal static Cpp2IL cpp2il = null;
internal static ExecutablePackage cpp2il = null;
internal static Cpp2IL_StrippedCodeRegSupport cpp2il_scrs = null;

internal static Packages.Il2CppInterop il2cppinterop = null;
Expand Down Expand Up @@ -59,7 +60,13 @@ private static int Run()
if (!MelonLaunchOptions.Il2CppAssemblyGenerator.OfflineMode)
RemoteAPI.Contact();

cpp2il = new Cpp2IL();
Cpp2IL cpp2IL_netcore = new Cpp2IL();
if (MelonUtils.IsWindows
&& (cpp2IL_netcore.VersionSem < Cpp2IL.NetCoreMinVersion))
cpp2il = new Cpp2IL_NetFramework();
else
cpp2il = cpp2IL_netcore;

//cpp2il_scrs = new Cpp2IL_StrippedCodeRegSupport(cpp2il);

il2cppinterop = new Packages.Il2CppInterop();
Expand Down
60 changes: 6 additions & 54 deletions Dependencies/Il2CppAssemblyGenerator/Packages/Cpp2IL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ namespace MelonLoader.Il2CppAssemblyGenerator.Packages
{
internal class Cpp2IL : Models.ExecutablePackage
{
internal static SemVersion NetCoreMinVersion = SemVersion.Parse("2022.1.0-pre-release.17");
private static SemVersion NewExecutionMinVersion = SemVersion.Parse("2022.0.999");
private SemVersion VersionSem;
internal static SemVersion NetCoreMinVersion = SemVersion.Parse("2022.1.0-pre-release.18");
internal SemVersion VersionSem;
private string BaseFolder;

private static string ReleaseName =>
Expand All @@ -27,10 +26,7 @@ internal Cpp2IL()
VersionSem = SemVersion.Parse(Version);

Name = nameof(Cpp2IL);

string filename = Name;
if (MelonUtils.IsWindows)
filename = $"{Name}.exe";
string filename = $"{Name}.exe";

BaseFolder = Path.Combine(Core.BasePath, Name);
if (!Directory.Exists(BaseFolder))
Expand All @@ -43,15 +39,7 @@ internal Cpp2IL()

OutputFolder = Path.Combine(BaseFolder, "cpp2il_out");

URL = $"https://github.com/SamboyCoding/{Name}/releases/download/{Version}/{Name}-{Version}-{ReleaseName}";

if (MelonUtils.IsWindows)
{
if (VersionSem < NetCoreMinVersion)
URL += "-Netframework472.zip";
else
URL += ".exe";
}
URL = $"https://github.com/SamboyCoding/{Name}/releases/download/{Version}/{Name}-{Version}-{ReleaseName}.exe";
}

internal override bool ShouldSetup()
Expand All @@ -64,15 +52,7 @@ internal override void Save()
=> Save(ref Config.Values.DumperVersion);

internal override bool Execute()
{
if (VersionSem <= NewExecutionMinVersion)
return ExecuteOld();
return ExecuteNew();
}

private bool ExecuteNew()
{
if (Execute([
=> Execute([
MelonDebug.IsEnabled() ? "--verbose" : string.Empty,

"--game-path",
Expand All @@ -95,34 +75,6 @@ private bool ExecuteNew()
], false, new Dictionary<string, string>() {
{"NO_COLOR", "1"},
{"DOTNET_BUNDLE_EXTRACT_BASE_DIR", BaseFolder }
}))
return true;

return false;
}

private bool ExecuteOld()
{
if (Execute([
MelonDebug.IsEnabled() ? "--verbose" : string.Empty,

"--game-path",
"\"" + Path.GetDirectoryName(Core.GameAssemblyPath) + "\"",

"--exe-name",
"\"" + Process.GetCurrentProcess().ProcessName + "\"",

"--skip-analysis",
"--skip-metadata-txts",
"--disable-registration-prompts"

], false, new Dictionary<string, string>() {
{"NO_COLOR", "1"},
{"DOTNET_BUNDLE_EXTRACT_BASE_DIR", BaseFolder }
}))
return true;

return false;
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Semver;

namespace MelonLoader.Il2CppAssemblyGenerator.Packages
{
internal class Cpp2IL_NetFramework : Models.ExecutablePackage
{
private static string ReleaseName => "Windows-Netframework472";
internal Cpp2IL_NetFramework()
{
Version = MelonLaunchOptions.Il2CppAssemblyGenerator.ForceVersion_Dumper;
#if !DEBUG
if (string.IsNullOrEmpty(Version) || Version.Equals("0.0.0.0"))
Version = RemoteAPI.Info.ForceDumperVersion;
#endif
if (string.IsNullOrEmpty(Version) || Version.Equals("0.0.0.0"))
Version = $"2022.1.0-pre-release.15";

Name = nameof(Cpp2IL);
Destination = Path.Combine(Core.BasePath, Name);
OutputFolder = Path.Combine(Destination, "cpp2il_out");

URL = $"https://github.com/SamboyCoding/{Name}/releases/download/{Version}/{Name}-{Version}-{ReleaseName}.zip";
ExeFilePath = Path.Combine(Destination, $"{Name}.exe");
FilePath = Path.Combine(Core.BasePath, $"{Name}_{Version}.zip");
}

internal override bool ShouldSetup()
=> string.IsNullOrEmpty(Config.Values.DumperVersion)
|| !Config.Values.DumperVersion.Equals(Version);

internal override void Cleanup() { }

internal override void Save()
=> Save(ref Config.Values.DumperVersion);

internal override bool Execute()
{
if (SemVersion.Parse(Version) <= SemVersion.Parse("2022.0.999"))
return ExecuteOld();
return ExecuteNew();
}

private bool ExecuteNew()
{
if (Execute([
MelonDebug.IsEnabled() ? "--verbose" : string.Empty,

"--game-path",
"\"" + Path.GetDirectoryName(Core.GameAssemblyPath) + "\"",

"--exe-name",
"\"" + Process.GetCurrentProcess().ProcessName + "\"",

"--output-as",
"dummydll",

"--use-processor",
"attributeanalyzer",
"attributeinjector",
MelonLaunchOptions.Cpp2IL.CallAnalyzer ? "callanalyzer" : string.Empty,
MelonLaunchOptions.Cpp2IL.NativeMethodDetector ? "nativemethoddetector" : string.Empty,
//"deobfmap",
//"stablenamer",

], false, new Dictionary<string, string>() {
{"NO_COLOR", "1"}
}))
return true;

return false;
}

private bool ExecuteOld()
{
if (Execute([
MelonDebug.IsEnabled() ? "--verbose" : string.Empty,

"--game-path",
"\"" + Path.GetDirectoryName(Core.GameAssemblyPath) + "\"",

"--exe-name",
"\"" + Process.GetCurrentProcess().ProcessName + "\"",

"--skip-analysis",
"--skip-metadata-txts",
"--disable-registration-prompts"

], false, new Dictionary<string, string>() {
{"NO_COLOR", "1"}
}))
return true;

return false;
}
}
}

0 comments on commit a8033a5

Please sign in to comment.