Skip to content

Commit

Permalink
More Mono runtime setup
Browse files Browse the repository at this point in the history
  • Loading branch information
HerpDerpinstine committed Dec 5, 2023
1 parent 8893c90 commit 929689c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>MelonLoader.Mono</RootNamespace>
<RootNamespace>MelonLoader.Bootstrap.Mono</RootNamespace>
<TargetFramework>net6</TargetFramework>
<LangVersion>Latest</LangVersion>
<OutputPath>$(SolutionDir)Output\$(Configuration)\MelonLoader\</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MelonLoader.Bootstrap\MelonLoader.Bootstrap.csproj" Private="false" ExcludeAssets="runtime" />
<ProjectReference Include="..\MelonLoader.Bootstrap\MelonLoader.Bootstrap.csproj" Private="false" ExcludeAssets="runtime" />
<ProjectReference Include="..\MelonLoader.Shared\MelonLoader.Shared.csproj" Private="false" ExcludeAssets="runtime" />
</ItemGroup>
</Project>
12 changes: 6 additions & 6 deletions MelonLoader/MelonLoader.Bootstrap.Mono/MonoLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using MelonLoader.Shared.Utils;
#pragma warning disable 0649

namespace MelonLoader.Mono
namespace MelonLoader.Bootstrap.Mono
{
public unsafe static class MonoLoader
{
Expand All @@ -27,9 +27,9 @@ public unsafe static void Startup(MonoRuntimeInfo runtimeInfo)

// Check if it found any Mono variant library
if (monoRuntimeInfo == null
|| string.IsNullOrEmpty(monoRuntimeInfo.FilePath))
|| string.IsNullOrEmpty(monoRuntimeInfo.LibPath))
{
Assertion.ThrowInternalFailure($"Failed to find {runtimeInfo.Variant} Library!");
Assertion.ThrowInternalFailure($"Failed to find {monoRuntimeInfo.Variant} Library!");
return;
}

Expand All @@ -48,11 +48,11 @@ public unsafe static void Startup(MonoRuntimeInfo runtimeInfo)
}

// Load the Mono variant library
MelonDebug.Msg(monoRuntimeInfo.FilePath);
MelonDebug.Msg(monoRuntimeInfo.LibPath);
MelonDebug.Msg($"Loading {monoRuntimeInfo.Variant} Library...");
if (!MelonNativeLibrary.TryLoad(monoRuntimeInfo.FilePath, out monoLib))
if (!MelonNativeLibrary.TryLoad(monoRuntimeInfo.LibPath, out monoLib))
{
Assertion.ThrowInternalFailure($"Failed to load {monoRuntimeInfo.Variant} Library from {monoRuntimeInfo.FilePath}!");
Assertion.ThrowInternalFailure($"Failed to load {monoRuntimeInfo.Variant} Library from {monoRuntimeInfo.LibPath}!");
return;
}

Expand Down
49 changes: 38 additions & 11 deletions MelonLoader/MelonLoader.Bootstrap.Mono/MonoRuntimeInfo.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
namespace MelonLoader.Mono
namespace MelonLoader.Bootstrap.Mono
{
public class MonoRuntimeInfo
{
public readonly string FilePath;
public readonly string PosixPath;
public readonly string ConfigPath;
public readonly string Variant;
public readonly bool IsOldMono;
#region Public Members

public MonoRuntimeInfo(string filePath, string posixPath, string configPath, string variant, bool isOldMono)
public eMonoRuntimeVariant Variant { get; private set; }
public string LibPath { get; private set; }
public string PosixPath { get; private set; }
public string ConfigPath { get; private set; }

#endregion

#region Constructors

public MonoRuntimeInfo(
eMonoRuntimeVariant variant,
string libPath,
string configPath)
=> SetInfo(variant, libPath, configPath, null);

public MonoRuntimeInfo(
eMonoRuntimeVariant variant,
string libPath,
string configPath,
string posixPath)
=> SetInfo(variant, libPath, configPath, posixPath);

#endregion

#region Private Methods

private void SetInfo(
eMonoRuntimeVariant variant,
string libPath,
string configPath,
string posixPath)
{
FilePath = filePath;
PosixPath = posixPath;
ConfigPath = configPath;
Variant = variant;
IsOldMono = isOldMono;
LibPath = libPath;
ConfigPath = configPath;
PosixPath = posixPath;
}

#endregion
}
}
8 changes: 8 additions & 0 deletions MelonLoader/MelonLoader.Bootstrap.Mono/eMonoRuntimeVariant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace MelonLoader.Bootstrap.Mono
{
public enum eMonoRuntimeVariant
{
MONO = 0,
MONO_BLEEDING_EDGE = 1
}
}
35 changes: 14 additions & 21 deletions MelonLoader/Modules/Unity/Unity.Bootstrap/Bootstrap.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using MelonLoader.Mono;
using System;
using System.IO;
using MelonLoader.Bootstrap.Mono;
using MelonLoader.Shared.Interfaces;
using MelonLoader.Shared.Utils;
using MelonLoader.Unity.Il2Cpp;
Expand Down Expand Up @@ -65,13 +66,6 @@ internal static MonoRuntimeInfo GetMonoRuntimeInfo()
GameDataPath
};

// Variants of Mono folders
string[] monoFolderVariants = new string[]
{
"Mono",
"MonoBleedingEdge"
};

// Get Mono variant library file name
string monoFileNameWithoutExt = "mono";
if (MelonUtils.IsUnix || MelonUtils.IsMac)
Expand All @@ -90,14 +84,17 @@ internal static MonoRuntimeInfo GetMonoRuntimeInfo()
monoFileExt = ".dylib";

// Iterate through Variations in Mono types
bool isOldMono = true;
foreach (var variant in monoFolderVariants)
eMonoRuntimeVariant[] variantTypes = Enum.GetValues<eMonoRuntimeVariant>();
for (int i = 0; i < variantTypes.Length; i++)
{
eMonoRuntimeVariant variant = variantTypes[i];
string variantName = Enum.GetName(variant);

// Iterate through Variations in Mono Directory Positions
foreach (var dir in directoriesToSearch)
{
// Get Directory Path
string dirPath = Path.Combine(dir, variant, "EmbedRuntime");
string dirPath = Path.Combine(dir, variantName, "EmbedRuntime");
if (!Directory.Exists(dirPath))
continue;

Expand All @@ -111,7 +108,7 @@ internal static MonoRuntimeInfo GetMonoRuntimeInfo()
string posixPath = Path.Combine(dirPath, $"{monoPosixFileNameWithoutExt}{monoFileExt}");

// Get Config Directory Path
string configPath = Path.Combine(dir, variant, "etc");
string configPath = Path.Combine(dir, variantName, "etc");

// Iterate through all found Files in EmbedRuntime
foreach (var filePath in foundFiles)
Expand All @@ -123,18 +120,14 @@ internal static MonoRuntimeInfo GetMonoRuntimeInfo()
continue;

// Return Information
return new Mono.MonoRuntimeInfo(
filePath,
posixPath,
configPath,
return new MonoRuntimeInfo(
variant,
isOldMono
filePath,
configPath,
posixPath
);
}
}

// Flip this since Index of 1 is MonoBleedingEdge
isOldMono = false;
}

// Return Nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\MelonLoader.Bootstrap.Mono\MelonLoader.Bootstrap.Mono.csproj" />
<ProjectReference Include="..\..\..\MelonLoader.Bootstrap\MelonLoader.Bootstrap.csproj" Private="false" ExcludeAssets="runtime" />
<ProjectReference Include="..\..\..\MelonLoader.Mono\MelonLoader.Bootstrap.Mono.csproj" />
<ProjectReference Include="..\..\..\MelonLoader.Shared\MelonLoader.Shared.csproj" Private="false" ExcludeAssets="runtime" />
<ProjectReference Include="..\Unity.Il2Cpp\Unity.Il2Cpp.csproj" />
</ItemGroup>
Expand Down

0 comments on commit 929689c

Please sign in to comment.