Skip to content
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
30 changes: 2 additions & 28 deletions QModManager/Checks/NitroxCheck.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System;

namespace QModManager.Checks
{
internal static class NitroxCheck
{
internal static bool IsRunning { get; set; } = false;


[HarmonyPatch(typeof(GameInput), nameof(GameInput.Awake))]
internal static class AwakePatch
{
internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode == OpCodes.Call)
{
MethodInfo method = (MethodInfo)instruction.operand;

if (method.DeclaringType.Name == "Main" && method.Name == "Execute")
{
IsRunning = true;
}
}
}

return instructions;
}
}
internal static bool IsRunning => Environment.GetEnvironmentVariable("NITROX_LAUNCHER_PATH") is not null;
}
}
12 changes: 1 addition & 11 deletions QModManager/Patching/Initializer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using QModManager.Checks;

namespace QModManager.API.ModLoading
namespace QModManager.API.ModLoading
{
using QModManager.Patching;
using QModManager.Utility;
Expand Down Expand Up @@ -32,14 +30,6 @@ internal void InitializeMods(List<QMod> modsToInitialize, PatchingOrder order)
continue;
}


if(!mod.NitroxCompat && NitroxCheck.IsRunning)
{
mod.PatchMethods.Clear(); // Do not attempt any other patch methods
mod.Status = ModStatus.NitroxIncompatible;
continue;
}

if (!mod.PatchMethods.TryGetValue(order, out QModPatchMethod patchMethod))
continue; // Nothing to patch at this stage

Expand Down
11 changes: 8 additions & 3 deletions QModManager/Patching/ManifestValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using QModManager.API;
using QModManager.API.ModLoading;
using QModManager.Checks;
using QModManager.Utility;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -63,10 +64,14 @@ public void ValidateBasicManifest(QMod mod)
mod.SupportedGame = QModGame.Subnautica;
break;
default:
{
mod.Status = ModStatus.FailedIdentifyingGame;
return;
}
}

if (!mod.NitroxCompat && NitroxCheck.IsRunning)
{
mod.Status = ModStatus.NitroxIncompatible;
return;
}

try
Expand Down Expand Up @@ -241,7 +246,7 @@ public void FindPatchMethods(QMod qMod)
}
catch (ReflectionTypeLoadException rtle)
{
Logger.Debug($"Unable to load types for '{qMod.Id}': \nInnerException: \n" + rtle.InnerException + "\n LoaderExceptions:\n" +string.Join("/n", rtle.LoaderExceptions.ToList()));
Logger.Debug($"Unable to load types for '{qMod.Id}': \nInnerException: \n" + rtle.InnerException + "\n LoaderExceptions:\n" + string.Join("/n", rtle.LoaderExceptions.ToList()));
qMod.Status = ModStatus.MissingDependency;
}

Expand Down
8 changes: 3 additions & 5 deletions QModManager/Utility/SummaryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ private static void LogStatus(List<QMod> mods, ModStatus statusToReport, string
switch (statusToReport)
{
case ModStatus.MissingDependency:
{
if (mod.HasDependencies)
{
Console.WriteLine($"- {mod.DisplayName} ({mod.Id}) is missing these dependencies:");
foreach (RequiredQMod dependency in mod.RequiredMods)
{
if (!QModServices.Main.ModPresent(dependency.Id))
if (QModServices.Main.GetMod(mod.Id) is not IQMod requiredMod || !requiredMod.IsLoaded || !requiredMod.Enable)
Console.WriteLine($" - {dependency.Id}{(dependency.RequiresMinimumVersion ? $" at version {dependency.MinimumVersion} or newer" : string.Empty)}");
}
}
Expand All @@ -65,7 +64,6 @@ private static void LogStatus(List<QMod> mods, ModStatus statusToReport, string
Console.WriteLine($"- {mod.DisplayName} ({mod.Id}) is missing a dependency but none are listed in mod.json, Please check Nexusmods for list of Dependencies.");
}
break;
}

case ModStatus.OutOfDateDependency:
Console.WriteLine($"- {mod.DisplayName} ({mod.Id}) requires a newer version of these dependencies:");
Expand All @@ -75,8 +73,8 @@ private static void LogStatus(List<QMod> mods, ModStatus statusToReport, string
{
IQMod dependencyDetails = QModServices.Main.FindModById(dependency.Id);

if (dependencyDetails == null || dependencyDetails.ParsedVersion < dependency.MinimumVersion)
Console.WriteLine($" - {dependency.Id} at version {dependency.MinimumVersion} or newer");
if (dependencyDetails == null || dependencyDetails.ParsedVersion < dependency.MinimumVersion)
Console.WriteLine($" - {dependency.Id} at version {dependency.MinimumVersion} or newer");
}
}
break;
Expand Down