Skip to content

Commit

Permalink
added a fix folder for melonloader its a lot cleaner and maintains or…
Browse files Browse the repository at this point in the history
…iginal melonloader file structure
  • Loading branch information
Cursed-Gato committed Oct 15, 2023
1 parent 4107171 commit ad1021f
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 5 deletions.
131 changes: 130 additions & 1 deletion Dependencies/Il2CppAssemblyGenerator/Core.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
Expand All @@ -12,6 +13,7 @@ internal class Core : MelonModule
{
internal static string BasePath = null;
internal static string GameAssemblyPath = null;
internal static string FixFolder = null;
internal static string ManagedPath = null;

internal static HttpClient webClient = null;
Expand Down Expand Up @@ -44,14 +46,16 @@ public override void OnInitialize()
if (MelonUtils.IsMac)
gameAssemblyName += ".dylib";

GameAssemblyPath = Path.Combine(MelonEnvironment.GameRootDirectory, gameAssemblyName);
GameAssemblyPath = Path.Combine(MelonEnvironment.GameRootDirectory, gameAssemblyName);
ManagedPath = MelonEnvironment.MelonManagedDirectory;
FixFolder = Path.Combine(MelonEnvironment.GameRootDirectory, "Fix");

BasePath = Path.GetDirectoryName(Assembly.Location);
}

private static int Run()
{
CopyDataCpp2IL();
Config.Initialize();

if (!MelonLaunchOptions.Il2CppAssemblyGenerator.OfflineMode)
Expand Down Expand Up @@ -157,5 +161,130 @@ private static void OldFiles_LAM()
}
Config.Save();
}

private static void CopyDataCpp2IL()
{
Logger.Msg("Copying files for Assembly Generation");
string sourceDirectory = Path.GetDirectoryName(Core.GameAssemblyPath) + @"\RotMG Exalt_Data\";
string destinationDirectory = Path.GetDirectoryName(Core.FixFolder) + @"\Fix\RotMG Exalt_Data\"; // Replace with the path to your destination folder
string fixedMetadata = Path.GetDirectoryName(Core.FixFolder) + @"\Fix\fixed-global-metadata.dat";
string pathGameAssemblyR = Path.GetDirectoryName(Core.FixFolder) + @"\GameAssembly.dll";

try
{
// Check if GameAssembly exists
if (File.Exists(pathGameAssemblyR))
{
File.Copy(pathGameAssemblyR, Path.GetDirectoryName(Core.FixFolder) + @"\Fix\GameAssembly.dll", true); // The "true" parameter allows overwriting if the file already exists in the destination folder.
Logger.Msg("GameAssembly copied successfully.");
}
else
{
Logger.Msg("GameAssembly.dll does not exist.");
}
}
catch (Exception ex)
{
Logger.Msg($"An error occurred: {ex.Message}");
}

try
{
string pathToExeR = Path.GetDirectoryName(Core.FixFolder) + @"\" + Process.GetCurrentProcess().ProcessName + ".exe";
// Check if the source file exists
if (File.Exists(pathToExeR))
{
File.Copy(pathToExeR, Path.GetDirectoryName(Core.FixFolder) + @"\Fix\" + Process.GetCurrentProcess().ProcessName + ".exe", true); // The "true" parameter allows overwriting if the file already exists in the destination folder.
Logger.Msg(Process.GetCurrentProcess().ProcessName + " copied successfully.");
}
else
{
Logger.Msg(Process.GetCurrentProcess().ProcessName + " does not exist.");
}
}
catch (Exception ex)
{
Logger.Msg($"An error occurred: {ex.Message}");
}


// Check if the source directory exists
if (Directory.Exists(sourceDirectory))
{
// Create the destination directory if it doesn't exist
if (!Directory.Exists(destinationDirectory))
{
Directory.CreateDirectory(destinationDirectory);
}

// Get a list of all files and subdirectories in the source directory
string[] files = Directory.GetFiles(sourceDirectory);
string[] subdirectories = Directory.GetDirectories(sourceDirectory);

// Copy files
foreach (string file in files)
{
string fileName = Path.GetFileName(file);
string destFile = Path.Combine(destinationDirectory, fileName);
File.Copy(file, destFile, true);
}

// Copy subdirectories (recursively)
foreach (string subdir in subdirectories)
{
string subdirName = Path.GetFileName(subdir);
string destSubdir = Path.Combine(destinationDirectory, subdirName);
DirectoryCopy(subdir, destSubdir);
}

Logger.Msg("Folder copied successfully.");
}
else
{
Logger.Msg("Source directory does not exist.");
}

//finnaly copy the fixed-global
try
{
// Check if the source file exists
if (File.Exists(fixedMetadata))
{
File.Copy(fixedMetadata, Path.GetDirectoryName(Core.FixFolder) + @"\Fix\" + Process.GetCurrentProcess().ProcessName + @"_Data\il2cpp_data\Metadata\global-metadata.dat", true); // The "true" parameter allows overwriting if the file already exists in the destination folder.
Logger.Msg("fixed-global-metadata.dat Moved Successfully.");
}
else
{
Logger.Msg("fixed-global-metadata.dat does not exist, if ran already this is fine");
}
}
catch (Exception ex)
{
Logger.Msg($"An error occurred: {ex.Message}");
}

}

// Recursive function to copy subdirectories
public static void DirectoryCopy(string sourceDir, string destDir)
{
Directory.CreateDirectory(destDir);

string[] files = Directory.GetFiles(sourceDir);
foreach (string file in files)
{
string fileName = Path.GetFileName(file);
string destFile = Path.Combine(destDir, fileName);
File.Copy(file, destFile, true);
}

string[] subdirectories = Directory.GetDirectories(sourceDir);
foreach (string subdir in subdirectories)
{
string subdirName = Path.GetFileName(subdir);
string destSubdir = Path.Combine(destDir, subdirName);
DirectoryCopy(subdir, destSubdir);
}
}
}
}
17 changes: 13 additions & 4 deletions Dependencies/Il2CppAssemblyGenerator/Packages/Cpp2IL.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using Il2CppInterop.Generator.Passes;
using Semver;

namespace MelonLoader.Il2CppAssemblyGenerator.Packages
Expand Down Expand Up @@ -41,24 +43,31 @@ internal override bool ShouldSetup()
=> string.IsNullOrEmpty(Config.Values.DumperVersion)
|| !Config.Values.DumperVersion.Equals(Version);

internal override void Cleanup() { }
internal override void Cleanup() {
}

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

internal override bool Execute()
{
//here is where i whould read in the decrypted file into the global-metadata.dat
//at the end replace the original back to run the game properly
if (SemVersion.Parse(Version) <= SemVersion.Parse("2022.0.999"))
return ExecuteOld();
return ExecuteNew();
{
bool returnBool = ExecuteOld();
return returnBool;
}
bool return1Bool = ExecuteNew();
return return1Bool;
}

private bool ExecuteNew()
{
if (Execute(new string[] {
MelonDebug.IsEnabled() ? "--verbose" : string.Empty,
"--game-path",
"\"" + Path.GetDirectoryName(Core.GameAssemblyPath) + "\"",
"\"" + Path.GetDirectoryName(Core.FixFolder) + @"\Fix" + "\"",
"--exe-name",
"\"" + Process.GetCurrentProcess().ProcessName + "\"",
"--use-processor",
Expand Down

0 comments on commit ad1021f

Please sign in to comment.