Skip to content
This repository was archived by the owner on Apr 21, 2024. It is now read-only.

Commit 393005d

Browse files
author
BuildTools
committed
merged dev to master
2 parents 5c4a3bc + ccb01b1 commit 393005d

9 files changed

+107
-19
lines changed

Config.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal struct SplotchConfigStruct
1717
public bool splotchEnabled;
1818
public bool consoleEnabled;
1919
public bool verboseLoggingEnabled;
20-
public bool nightly; // I touched it (;
20+
public bool nightly;
2121
}
2222

2323
internal static SplotchConfigStruct LoadedSplotchConfig = new SplotchConfigStruct
@@ -82,7 +82,6 @@ internal struct SplotchConfigCont
8282
}
8383
else
8484
{
85-
8685
try {
8786

8887
using (StreamReader reader = new StreamReader("splotch_config/splotchconfig.yaml"))

Event.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ public static void RegisterEventListener(Type eventListener)
7070
/// </summary>
7171
internal static void PatchEventTypes()
7272
{
73-
// retrieve all types that extend Event
74-
Type[] eventExtensions = AppDomain.CurrentDomain.GetAssemblies()
75-
.SelectMany(domainAssembly => domainAssembly.GetTypes())
76-
.Where(type => type.IsSubclassOf(typeof(Event))
77-
).ToArray();
73+
Logger.Debug("Looking for events...");
74+
75+
IEnumerable<Type> eventExtensions = new List<Type>(); //
76+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) //
77+
if (!assembly.GetName().Name.StartsWith("BepInEx.")) // mm spaghetti
78+
foreach (var type in assembly.ExportedTypes) // it works so don't mess with it
79+
if (type.IsSubclassOf(typeof(Event))) //
80+
eventExtensions.Append(type); //
81+
82+
Logger.Debug($"Found {eventExtensions.Count()} events!");
7883

7984
// run all patches on Event extensions
8085
foreach (Type eventExtension in eventExtensions) {
@@ -93,6 +98,7 @@ internal static void PatchEventTypes()
9398
internal static void Load()
9499
{
95100
PatchEventTypes();
101+
Logger.Debug("Loaded events!");
96102
}
97103
}
98104

GuiModifications.cs

+31-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using TMPro;
33
using System.Reflection;
44
using UnityEngine.UI;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Collections;
58

69
namespace Splotch.Loader
710
{
@@ -40,7 +43,7 @@ internal static void RunMainMenuModifications()
4043
// set the text to the version info
4144
AssemblyName name = Assembly.GetExecutingAssembly().GetName();
4245

43-
textComponent.text = $"{ModManager.GetLoadedModsInfoText()}\n{name.Name} version {VersionChecker.currentVersionString}";
46+
textComponent.text = $"{ModManager.GetLoadedModsInfoText()}\n{GetBepInExInfo()}\n{name.Name} version {VersionChecker.currentVersionString}";
4447

4548
// change settings
4649
textComponent.font = LocalizedText.localizationTable.GetFont(Settings.Get().Language, false);
@@ -60,5 +63,32 @@ internal static void RunMainMenuModifications()
6063
rectTransform.sizeDelta = new Vector2(1200, 0);
6164
rectTransform.anchoredPosition = new Vector2(-10, 30);
6265
}
66+
67+
internal static string GetBepInExInfo()
68+
{
69+
string text = "";
70+
if (Loader.BepInExPresent)
71+
{
72+
Type chainloader = Assembly.LoadFrom(@"BepInEx\core\BepInEx.dll").GetType("BepInEx.Bootstrap.Chainloader");
73+
IEnumerable pluginInfos = (IEnumerable)chainloader.GetProperty("PluginInfos", BindingFlags.Public | BindingFlags.Static).GetValue(null);
74+
foreach ( var pluginInfoKeyValue in pluginInfos )
75+
{
76+
var pluginInfo = pluginInfoKeyValue.GetType().GetProperty("Value").GetValue(pluginInfoKeyValue);
77+
78+
var metadataProperty = pluginInfo.GetType().GetProperty("Metadata");
79+
var pluginMetadata = metadataProperty.GetValue(pluginInfo);
80+
81+
var nameProperty = pluginMetadata.GetType().GetProperty("Name");
82+
var versionProperty = pluginMetadata.GetType().GetProperty("Version");
83+
84+
string name = nameProperty.GetValue(pluginMetadata) as string;
85+
Version version = versionProperty.GetValue(pluginMetadata) as Version;
86+
87+
text += $"{name} version {version} (BepInEx plugin)\n";
88+
}
89+
text += $"BepInEx version {Assembly.LoadFrom(@"BepInEx\core\BepInEx.dll").GetName().Version}";
90+
}
91+
return text;
92+
}
6393
}
6494
}

HarmonyLoader.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ namespace Splotch.Loader
77
/// </summary>
88
internal static class Patcher
99
{
10-
public static Harmony harmony;
10+
public static Harmony harmony = new Harmony("com.codemob.splotch");
1111
/// <summary>
1212
/// Runs all of Splotch's patches.
1313
/// </summary>
1414
public static void DoPatching()
1515
{
16-
harmony = new Harmony("com.codemob.splotch");
1716
harmony.PatchAll(typeof(Patches));
1817
}
1918

Loader.cs

+48-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
using Splotch;
55
using UnityEngine;
66
using System;
7-
using System.Diagnostics;
7+
using System.IO;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using System.Collections;
11+
using HarmonyLib;
12+
using MonoMod.Utils;
813

914
namespace Splotch.Loader
1015
{
@@ -13,6 +18,7 @@ namespace Splotch.Loader
1318
/// </summary>
1419
public static class Loader
1520
{
21+
public static bool BepInExPresent { get { return Directory.Exists(@"BepInEx\core\"); } }
1622

1723
struct SplotchConfigContainer
1824
{
@@ -40,21 +46,50 @@ public static void OnEnterScene(Scene scene, LoadSceneMode loadSceneMode)
4046
EventManager.Load();
4147

4248
GameObject obj = new GameObject("Unloader", new Type[] { typeof(UnLoader) });
49+
Logger.Debug("Finished main menu loading!");
50+
}
51+
52+
public static void LoadBepInEx()
53+
{
54+
string path = @"BepInEx\core\BepInEx.Preloader.dll";
55+
56+
57+
// Trick BepInEx to think it was invoked with doorstop
58+
string actualInvokePath = Environment.GetEnvironmentVariable("DOORSTOP_INVOKE_DLL_PATH");
59+
Environment.SetEnvironmentVariable("DOORSTOP_INVOKE_DLL_PATH", Path.Combine(Directory.GetCurrentDirectory(), path));
60+
61+
62+
Assembly bepInExPreloader = Assembly.LoadFrom(path);
63+
64+
if (bepInExPreloader != null)
65+
{
66+
MethodInfo entrypointMethod = bepInExPreloader.GetType("BepInEx.Preloader.Entrypoint", true)
67+
.GetMethod("Main");
68+
69+
entrypointMethod.Invoke(null, null);
70+
}
71+
72+
Environment.SetEnvironmentVariable("DOORSTOP_INVOKE_DLL_PATH", actualInvokePath);
4373
}
4474

4575
/// <summary>
4676
/// The main entrypoint for Splotch, called by Doorstop.
4777
/// </summary>
4878
public static void Main()
4979
{
80+
if (BepInExPresent)
81+
LoadBepInEx();
82+
5083
Config.CreateConfigAndLoadSplotchConfig();
5184

5285
if (!Config.LoadedSplotchConfig.splotchEnabled)
5386
return;
5487

55-
SceneManager.sceneLoaded += SceneLoaded;
56-
57-
88+
// BepInEx does some shenanigans with assembly loading so by using reflection to run unity
89+
// methods we can avoid loading assemblies before bepinex
90+
typeof(Loader).Assembly.GetType($"Splotch.Loader.BepInExLoader")
91+
.GetMethod(nameof(BepInExLoader.LoadBepInExUnstable))
92+
.Invoke(null, null);
5893
}
5994

6095
internal static void GameExit()
@@ -68,7 +103,7 @@ internal static void GameExit()
68103
/// </summary>
69104
/// <param name="scene">The scene to be loaded</param>
70105
/// <param name="loadSceneMode">The scene mode</param>
71-
private static void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
106+
public static void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
72107
{
73108
// Execute patching after unity has finished it's startup and loaded at least the first game scene
74109
if (!enteredScene)
@@ -98,4 +133,12 @@ public void OnApplicationQuit()
98133
Loader.GameExit();
99134
}
100135
}
136+
137+
class BepInExLoader
138+
{
139+
public static void LoadBepInExUnstable()
140+
{
141+
SceneManager.sceneLoaded += Loader.SceneLoaded;
142+
}
143+
}
101144
}

ModLoader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ internal bool LoadMod(string modFolder)
203203
string dllAbsolutePath = Path.Combine(modFolder, dll);
204204
Logger.Debug($"Loading {dllAbsolutePath}");
205205

206-
assembly = Assembly.Load(File.ReadAllBytes(dllAbsolutePath));
206+
assembly = Assembly.LoadFrom(dllAbsolutePath);
207207

208208
Logger.Debug($"Loaded {assembly}");
209209
Type assemblyEntrypoint = assembly.GetType(className);

Properties/AssemblyInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
// X: major versions
3737
// Y: feature addition/ removal
3838
// Z: small patch/ bugfix
39-
[assembly: AssemblyVersion("0.3.0")]
39+
[assembly: AssemblyVersion("0.4.0")]

Splotch.dll.config

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="Mono.Cecil" publicKeyToken="50cebf1cceb9d05e" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-0.11.4.0" newVersion="0.11.4.0" />
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>

version

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
latest=0.3.0
2-
latestNightly=0.3.0
1+
latest=0.4.0
2+
latestNightly=0.4.0

0 commit comments

Comments
 (0)