Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve BepInEx plugins being destroyed #240

Merged
merged 14 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Dependencies/BZ.EXP/BepInEx.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Preloader.Entrypoint]

## The local filename of the assembly to target.
# Setting type: String
# Default value: UnityEngine.CoreModule.dll
Assembly = Assembly-CSharp.dll

## The name of the type in the entrypoint assembly to search for the entrypoint method.
# Setting type: String
# Default value: Application
Type = PreStartScreen

## The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from.
# Setting type: String
# Default value: .cctor
Method = Start
16 changes: 16 additions & 0 deletions Dependencies/BZ.STABLE/BepInEx.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Preloader.Entrypoint]

## The local filename of the assembly to target.
# Setting type: String
# Default value: UnityEngine.CoreModule.dll
Assembly = Assembly-CSharp.dll

## The name of the type in the entrypoint assembly to search for the entrypoint method.
# Setting type: String
# Default value: Application
Type = PreStartScreen

## The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from.
# Setting type: String
# Default value: .cctor
Method = Start
16 changes: 16 additions & 0 deletions Dependencies/SN.EXP/BepInEx.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Preloader.Entrypoint]

## The local filename of the assembly to target.
# Setting type: String
# Default value: UnityEngine.CoreModule.dll
Assembly = Assembly-CSharp.dll

## The name of the type in the entrypoint assembly to search for the entrypoint method.
# Setting type: String
# Default value: Application
Type = PreStartScreen

## The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from.
# Setting type: String
# Default value: .cctor
Method = Start
16 changes: 16 additions & 0 deletions Dependencies/SN.STABLE/BepInEx.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Preloader.Entrypoint]

## The local filename of the assembly to target.
# Setting type: String
# Default value: UnityEngine.CoreModule.dll
Assembly = Assembly-CSharp.dll

## The name of the type in the entrypoint assembly to search for the entrypoint method.
# Setting type: String
# Default value: Application
Type = SystemsSpawner

## The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from.
# Setting type: String
# Default value: .cctor
Method = Awake
1 change: 1 addition & 0 deletions Installer/BZ.EXP.iss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Source: "QModManager.UnityAudioFixer.xml"; DestDir: "{app}\BepInEx\patchers\QMod

; BepInEx
Source: "..\..\Dependencies\BepInEx\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs replacesameversion sharedfile uninsnosharedfileprompt;
Source: "..\..\Dependencies\BZ.EXP\BepInEx.cfg"; DestDir: "{app}\BepInEx\config"; Flags: ignoreversion sharedfile uninsnosharedfileprompt;

[Dirs]
Name: "{app}\QMods"
Expand Down
1 change: 1 addition & 0 deletions Installer/BZ.STABLE.iss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Source: "QModManager.UnityAudioFixer.xml"; DestDir: "{app}\BepInEx\patchers\QMod

; BepInEx
Source: "..\..\Dependencies\BepInEx\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs replacesameversion sharedfile uninsnosharedfileprompt;
Source: "..\..\Dependencies\BZ.STABLE\BepInEx.cfg"; DestDir: "{app}\BepInEx\config"; Flags: ignoreversion sharedfile uninsnosharedfileprompt;

[Dirs]
Name: "{app}\QMods"
Expand Down
1 change: 1 addition & 0 deletions Installer/SN.EXP.iss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Source: "QModManager.UnityAudioFixer.xml"; DestDir: "{app}\BepInEx\patchers\QMod

; BepInEx
Source: "..\..\Dependencies\BepInEx\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs replacesameversion sharedfile uninsnosharedfileprompt;
Source: "..\..\Dependencies\SN.EXP\BepInEx.cfg"; DestDir: "{app}\BepInEx\config"; Flags: ignoreversion sharedfile uninsnosharedfileprompt;

[Dirs]
Name: "{app}\QMods"
Expand Down
1 change: 1 addition & 0 deletions Installer/SN.STABLE.iss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Source: "QModManager.UnityAudioFixer.xml"; DestDir: "{app}\BepInEx\patchers\QMod

; BepInEx
Source: "..\..\Dependencies\BepInEx\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs replacesameversion sharedfile uninsnosharedfileprompt;
Source: "..\..\Dependencies\SN.STABLE\BepInEx.cfg"; DestDir: "{app}\BepInEx\config"; Flags: ignoreversion sharedfile uninsnosharedfileprompt;

[Dirs]
Name: "{app}\QMods"
Expand Down
92 changes: 91 additions & 1 deletion QModManager/BepInex/Plugins/QMMLoader.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
using BepInEx;
using System;
#if !SUBNAUTICA_STABLE
using HarmonyLib;
#if !BELOWZERO
using System.Collections;
#endif
#endif
using System.Collections.Generic;
using UnityEngine;

namespace QModInstaller.BepInEx.Plugins
{
using QModManager.API.ModLoading;
using QModManager.Patching;
using QModManager.Utility;

/// <summary>
/// QMMLoader - simply fires up the QModManager entry point.
/// </summary>
Expand All @@ -15,6 +25,9 @@ public class QMMLoader : BaseUnityPlugin
internal const string PluginName = "QMMLoader";
internal const string PluginVersion = "4.1.4";

internal static List<QMod> QModsToLoad;
private static Initializer Initializer;

/// <summary>
/// Prevents a default instance of the <see cref="QMMLoader"/> class from being created
/// Also ensures the root bepinex object does not get destroyed if the game reloads for steam.
Expand All @@ -24,10 +37,87 @@ private void Awake()
GameObject obj = gameObject;

while (obj.transform.parent?.gameObject != null)
{
obj = obj.transform.parent.gameObject;
}

obj.EnsureComponent<SceneCleanerPreserve>();
DontDestroyOnLoad(obj);

PreInitializeQMods();
}

private void PreInitializeQMods()
{
Patcher.Patch(); // Run QModManager patch

if (QModsToLoad is null)
{
Logger.LogWarning("QModsToLoad is null!");
return;
}

Initializer = new Initializer(Patcher.CurrentlyRunningGame);
Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPreInitialize);
Initializer.InitializeMods(QModsToLoad, PatchingOrder.PreInitialize);

#if SUBNAUTICA_STABLE
Initializer.InitializeMods(QModsToLoad, PatchingOrder.NormalInitialize);
Initializer.InitializeMods(QModsToLoad, PatchingOrder.PostInitialize);
Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPostInitialize);

SummaryLogger.ReportIssues(QModsToLoad);
SummaryLogger.LogSummaries(QModsToLoad);
foreach (Dialog dialog in Patcher.Dialogs)
{
dialog.Show();
}
#else
var harmony = new Harmony(PluginGuid);
harmony.Patch(
AccessTools.Method(
#if SUBNAUTICA
typeof(PlatformUtils), nameof(PlatformUtils.PlatformInitAsync)
#elif BELOWZERO
typeof(SpriteManager), nameof(SpriteManager.OnLoadedSpriteAtlases)
#endif
),
postfix: new HarmonyMethod(AccessTools.Method(typeof(QMMLoader), nameof(QMMLoader.InitializeQMods)))
);
#endif
}

#if SUBNAUTICA_EXP
private static IEnumerator InitializeQMods(IEnumerator result)
{
yield return result;

Initializer.InitializeMods(QModsToLoad, PatchingOrder.NormalInitialize);
Initializer.InitializeMods(QModsToLoad, PatchingOrder.PostInitialize);
Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPostInitialize);

SummaryLogger.ReportIssues(QModsToLoad);
SummaryLogger.LogSummaries(QModsToLoad);
foreach (Dialog dialog in Patcher.Dialogs)
{
dialog.Show();
}
}
#elif BELOWZERO
private static void InitializeQMods()
{
Initializer.InitializeMods(QModsToLoad, PatchingOrder.NormalInitialize);
Initializer.InitializeMods(QModsToLoad, PatchingOrder.PostInitialize);
Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPostInitialize);

SummaryLogger.ReportIssues(QModsToLoad);
SummaryLogger.LogSummaries(QModsToLoad);

foreach (Dialog dialog in Patcher.Dialogs)
{
dialog.Show();
}
}
#endif
}
}
10 changes: 6 additions & 4 deletions QModManager/QModManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@
<HintPath>..\Dependencies\$(Configuration)\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sentry">
<HintPath>..\Dependencies\$(Configuration)\Sentry.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine">
<HintPath>..\Dependencies\$(Configuration)\UnityEngine.dll</HintPath>
Expand Down Expand Up @@ -112,6 +108,12 @@
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'BZ.EXP'">
<Reference Include="Sentry">
<HintPath>..\Dependencies\$(Configuration)\Sentry.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="API\IQMod.cs" />
<Compile Include="API\IQModAPI.cs" />
Expand Down
4 changes: 3 additions & 1 deletion QModPluginEmulator/QModManager.QModPluginGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
<PropertyGroup>
<PostBuildEvent>rmdir "$(SolutionDir)VortexBuild\$(Configuration)" /q /s
xcopy "$(SolutionDir)Dependencies\BepInEx" "$(SolutionDir)VortexBuild\$(Configuration)" /E /H /I /Q /Y
xcopy "$(SolutionDir)Dependencies\$(Configuration)\BepInEx.cfg" "$(SolutionDir)VortexBuild\$(Configuration)\BepInEx\config\" /I /Q /Y
mkdir "$(SolutionDir)VortexBuild\$(Configuration)\QMods"
xcopy "$(SolutionDir)Dependencies\cldb.dat" "$(SolutionDir)VortexBuild\$(Configuration)\BepInEx\patchers\QModManager\" /I /Q /Y
xcopy "$(SolutionDir)packages\AssetsTools.NET.2.0.3\lib\net35\AssetsTools.NET.dll" "$(SolutionDir)VortexBuild\$(Configuration)\BepInEx\patchers\QModManager\" /I /Q /Y
xcopy "$(TargetDir)QModManager.exe" "$(SolutionDir)VortexBuild\$(Configuration)\BepInEx\patchers\QModManager\" /I /Q /Y
Expand All @@ -105,7 +107,7 @@ xcopy "$(TargetDir)QModManager.OculusNewtonsoftRedirect.dll" "$(SolutionDir)Vort
xcopy "$(TargetDir)QModInstaller.dll" "$(SolutionDir)VortexBuild\$(Configuration)\BepInEx\plugins\QModManager\" /I /Q /Y
xcopy "$(TargetDir)QModInstaller.xml" "$(SolutionDir)VortexBuild\$(Configuration)\BepInEx\plugins\QModManager\" /I /Q /Y

powershell Compress-Archive -Path '$(SolutionDir)VortexBuild\$(Configuration)\Bepinex' -DestinationPath '$(SolutionDir)VortexBuild\QModManager_$(Configuration).zip' -Force
powershell Compress-Archive -Path '$(SolutionDir)VortexBuild\$(Configuration)\BepInEx' -DestinationPath '$(SolutionDir)VortexBuild\QModManager_$(Configuration).zip' -Force
powershell Compress-Archive -LiteralPath '$(SolutionDir)VortexBuild\$(Configuration)\doorstop_config.ini', '$(SolutionDir)VortexBuild\$(Configuration)\winhttp.dll' -DestinationPath '$(SolutionDir)VortexBuild\QModManager_$(Configuration).zip' -Update

echo F|xcopy /S /Q /Y /F "$(SolutionDir)Installer\$(Configuration).iss" "$(TargetDir)\QModsInstallerScript.iss"
Expand Down
Loading