Skip to content

Commit

Permalink
Update UnityLoader.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
HerpDerpinstine committed Feb 5, 2025
1 parent 79e8904 commit 612ac46
Showing 1 changed file with 55 additions and 50 deletions.
105 changes: 55 additions & 50 deletions Dependencies/Modules/Engines/Unity/Engine.Unity/UnityLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,6 @@ public override bool Validate()
return false;
}

public override void Stage3(string supportModulePath)
{
if (!IsIl2Cpp)
{
// Run Stage3
base.Stage3(supportModulePath);
return;
}

string genBasePath = Path.Combine(LoaderPath, "Il2CppAssemblyGenerator");
if (!Directory.Exists(genBasePath))
Directory.CreateDirectory(genBasePath);

string genOutputPath = Path.Combine(MelonEnvironment.DependenciesDirectory, "Il2CppAssemblies");
if (!Directory.Exists(genOutputPath))
Directory.CreateDirectory(genOutputPath);
MelonAssemblyResolver.AddSearchDirectory(genOutputPath);

// Apply Il2Cpp Fixes
Il2CppInteropFixes.Install(genOutputPath);
Il2CppICallInjector.Install();

// Generate Il2Cpp Wrapper Assemblies
try
{
if (!AssemblyGenerator.Run(genBasePath, GameAssemblyPath, genOutputPath))
{
MelonDebug.Error("Il2Cpp Assembly Generation Failure!");
return;
}

foreach (var file in Directory.GetFiles(genOutputPath, "*.dll"))
{
try
{
AssemblyLoadContext.Default.LoadFromAssemblyPath(file);
}
catch { }
}
}
catch (Exception ex)
{
MelonDebug.Error(ex.ToString());
return;
}

// Run Stage3 after Assembly Generation
base.Stage3(supportModulePath);
}

public override void Initialize()
{
MelonDebug.Msg("Initializing Unity Engine Module...");
Expand All @@ -104,6 +54,11 @@ public override void Initialize()
Il2CppLibrary.Load(GameAssemblyPath);
else
{
// Attempt to find Library

// Load Library
//MonoLibrary.Load(MonoLibPath);

MelonLogger.Error("UNITY MONO SUPPORT NOT IMPLEMENTED!");
}

Expand Down Expand Up @@ -136,5 +91,55 @@ public override void Initialize()
Stage3(null);
}
}

public override void Stage3(string supportModulePath)
{
if (!IsIl2Cpp)
{
// Run Stage3
base.Stage3(supportModulePath);
return;
}

string genBasePath = Path.Combine(LoaderPath, "Il2CppAssemblyGenerator");
if (!Directory.Exists(genBasePath))
Directory.CreateDirectory(genBasePath);

string genOutputPath = Path.Combine(MelonEnvironment.DependenciesDirectory, "Il2CppAssemblies");
if (!Directory.Exists(genOutputPath))
Directory.CreateDirectory(genOutputPath);
MelonAssemblyResolver.AddSearchDirectory(genOutputPath);

// Apply Il2Cpp Fixes
Il2CppInteropFixes.Install(genOutputPath);
Il2CppICallInjector.Install();

// Generate Il2Cpp Wrapper Assemblies
try
{
if (!AssemblyGenerator.Run(genBasePath, GameAssemblyPath, genOutputPath))
{
MelonDebug.Error("Il2Cpp Assembly Generation Failure!");
return;
}

foreach (var file in Directory.GetFiles(genOutputPath, "*.dll"))
{
try
{
AssemblyLoadContext.Default.LoadFromAssemblyPath(file);
}
catch { }
}
}
catch (Exception ex)
{
MelonDebug.Error(ex.ToString());
return;
}

// Run Stage3 after Assembly Generation
base.Stage3(supportModulePath);
}
}
}

0 comments on commit 612ac46

Please sign in to comment.