Skip to content

Commit

Permalink
All patchers are now executed after SML
Browse files Browse the repository at this point in the history
  • Loading branch information
Metious committed Aug 20, 2023
1 parent 6423e77 commit 295cb40
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 19 deletions.
1 change: 1 addition & 0 deletions Nautilus/Patchers/ConsoleCommandsPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Nautilus.Patchers;

[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static class ConsoleCommandsPatcher
{
private static Dictionary<string, ConsoleCommand> ConsoleCommands = new();
Expand Down
1 change: 1 addition & 0 deletions Nautilus/Patchers/CraftDataPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Nautilus.Patchers;

[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal partial class CraftDataPatcher
{
#region Internal Fields
Expand Down
1 change: 1 addition & 0 deletions Nautilus/Patchers/CraftTreePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Nautilus.Patchers;

[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal class CraftTreePatcher
{
#region Internal Fields
Expand Down
1 change: 1 addition & 0 deletions Nautilus/Patchers/CustomSoundPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Nautilus.Patchers;

[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal class CustomSoundPatcher
{
internal static readonly SelfCheckingDictionary<string, Sound> CustomSounds = new("CustomSounds");
Expand Down
1 change: 1 addition & 0 deletions Nautilus/Patchers/EnumPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Nautilus.Patchers;

[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static class EnumPatcher
{
internal static void Patch(Harmony harmony)
Expand Down
6 changes: 3 additions & 3 deletions Nautilus/Patchers/ItemActionPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ internal static void Patch(Harmony harmony)
// See README.md for details.

harmony.Patch(AccessTools.Method(typeof(uGUI_InventoryTab), nameof(uGUI_InventoryTab.OnPointerClick)),
prefix: new HarmonyMethod(AccessTools.Method(typeof(ItemActionPatcher), nameof(ItemActionPatcher.OnPointerClick_Prefix))));
prefix: new HarmonyMethod(AccessTools.Method(typeof(ItemActionPatcher), nameof(OnPointerClick_Prefix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

harmony.Patch(AccessTools.Method(typeof(Inventory), nameof(Inventory.ExecuteItemAction),new Type[] { typeof(ItemAction), typeof(InventoryItem) }),
prefix: new HarmonyMethod(AccessTools.Method(typeof(ItemActionPatcher), nameof(ItemActionPatcher.ExecuteItemAction_Prefix))));
prefix: new HarmonyMethod(AccessTools.Method(typeof(ItemActionPatcher), nameof(ExecuteItemAction_Prefix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

harmony.Patch(AccessTools.Method(typeof(TooltipFactory), nameof(TooltipFactory.ItemActions)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemActionPatcher), nameof(ItemActionPatcher.ItemActions_Postfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemActionPatcher), nameof(ItemActions_Postfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

if (MiddleClickActions.Count > 0 && LeftClickActions.Count > 0)
{
Expand Down
10 changes: 5 additions & 5 deletions Nautilus/Patchers/ItemsContainerPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ internal static class ItemsContainerPatcher
internal static void Patch(Harmony harmony)
{
harmony.Patch(AccessTools.Method(typeof(ItemsContainer), nameof(ItemsContainer.HasRoomFor), new Type[] { typeof(int), typeof(int) }),
prefix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(ItemsContainerPatcher.HasRoomFor_XY_Prefix))),
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(ItemsContainerPatcher.HasRoomFor_Postfix))));
prefix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(HasRoomFor_XY_Prefix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}),
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(HasRoomFor_Postfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

harmony.Patch(AccessTools.Method(typeof(ItemsContainer), nameof(ItemsContainer.NotifyAddItem)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(ItemsContainerPatcher.NotifyChangeItem_Postfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(NotifyChangeItem_Postfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

harmony.Patch(AccessTools.Method(typeof(ItemsContainer), nameof(ItemsContainer.NotifyRemoveItem)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(ItemsContainerPatcher.NotifyChangeItem_Postfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(NotifyChangeItem_Postfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

harmony.Patch(AccessTools.Method(typeof(ItemsContainer), nameof(ItemsContainer.NotifyResize)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(ItemsContainerPatcher.NotifyChangeItem_Postfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(ItemsContainerPatcher), nameof(NotifyChangeItem_Postfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

InternalLogger.Log($"ItemsContainerPatcher is done.", LogLevel.Debug);
}
Expand Down
6 changes: 3 additions & 3 deletions Nautilus/Patchers/LanguagePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ private static void LoadLanguageFilePrefix(string language)

internal static void Patch(Harmony harmony)
{
HarmonyMethod repatchCheckMethod = new(AccessTools.Method(typeof(LanguagePatcher), nameof(RepatchCheck)));
HarmonyMethod insertLinesMethod = new(AccessTools.Method(typeof(LanguagePatcher), nameof(InsertCustomLines)));
HarmonyMethod loadLanguagesMethod = new(AccessTools.Method(typeof(LanguagePatcher), nameof(LoadLanguageFilePrefix)));
HarmonyMethod repatchCheckMethod = new(AccessTools.Method(typeof(LanguagePatcher), nameof(RepatchCheck)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance});
HarmonyMethod insertLinesMethod = new(AccessTools.Method(typeof(LanguagePatcher), nameof(InsertCustomLines)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance});
HarmonyMethod loadLanguagesMethod = new(AccessTools.Method(typeof(LanguagePatcher), nameof(LoadLanguageFilePrefix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance});

harmony.Patch(AccessTools.Method(typeof(Language), nameof(Language.ParseMetaData)), prefix: insertLinesMethod);
harmony.Patch(AccessTools.Method(typeof(Language), nameof(Language.GetKeysFor)), prefix: insertLinesMethod);
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Patchers/LargeWorldStreamerPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class LargeWorldStreamerPatcher
internal static void Patch(Harmony harmony)
{
System.Reflection.MethodInfo initializeOrig = AccessTools.Method(typeof(LargeWorldStreamer), nameof(LargeWorldStreamer.Initialize));
HarmonyMethod initPostfix = new(AccessTools.Method(typeof(LargeWorldStreamerPatcher), nameof(InitializePostfix)));
HarmonyMethod initPostfix = new(AccessTools.Method(typeof(LargeWorldStreamerPatcher), nameof(InitializePostfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance});
harmony.Patch(initializeOrig, postfix: initPostfix);
}

Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Patchers/LootDistributionPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class LootDistributionPatcher
internal static void Patch(Harmony harmony)
{
harmony.Patch(AccessTools.Method(typeof(LootDistributionData), nameof(LootDistributionData.Initialize)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(LootDistributionPatcher), nameof(LootDistributionPatcher.InitializePostfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(LootDistributionPatcher), nameof(InitializePostfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

InternalLogger.Log("LootDistributionPatcher is done.", LogLevel.Debug);
}
Expand Down
3 changes: 3 additions & 0 deletions Nautilus/Patchers/OptionsPanelPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal static void Patch(Harmony harmony)
// 'Mods' tab also added in QModManager, so we can't rely on 'modsTab' in AddTabs_Postfix
[HarmonyPostfix]
[HarmonyPatch(typeof(uGUI_TabbedControlsPanel), nameof(uGUI_TabbedControlsPanel.AddTab))]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static void AddTab_Postfix(uGUI_TabbedControlsPanel __instance, string label, int __result)
{
if(__instance is not uGUI_OptionsPanel)
Expand All @@ -47,6 +48,7 @@ internal static void AddTab_Postfix(uGUI_TabbedControlsPanel __instance, string

[HarmonyPrefix]
[HarmonyPatch(typeof(uGUI_Binding), nameof(uGUI_Binding.RefreshValue))]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static bool RefreshValue_Prefix(uGUI_Binding __instance)
{
if (__instance.gameObject.GetComponent<ModBindingTag>() is null)
Expand All @@ -61,6 +63,7 @@ internal static bool RefreshValue_Prefix(uGUI_Binding __instance)

[HarmonyPostfix]
[HarmonyPatch(typeof(uGUI_OptionsPanel), nameof(uGUI_OptionsPanel.AddTabs))]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static void AddTabs_Postfix(uGUI_OptionsPanel __instance)
{
uGUI_OptionsPanel optionsPanel = __instance;
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Patchers/PDAEncyclopediaPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class PDAEncyclopediaPatcher
internal static void Patch(Harmony harmony)
{
harmony.Patch(AccessTools.Method(typeof(PDAEncyclopedia), nameof(PDAEncyclopedia.Initialize)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(PDAEncyclopediaPatcher), nameof(PDAEncyclopediaPatcher.InitializePostfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(PDAEncyclopediaPatcher), nameof(InitializePostfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));
}

internal static void InitializePostfix()
Expand Down
1 change: 1 addition & 0 deletions Nautilus/Patchers/PDAEncyclopediaTabPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal static void Patch(Harmony harmony)
}
[HarmonyPatch(typeof(uGUI_EncyclopediaTab))]
[HarmonyPatch(nameof(uGUI_EncyclopediaTab.Awake))]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
[HarmonyPostfix]
internal static void EncyTabAwakePostfix(uGUI_EncyclopediaTab __instance)
{
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Patchers/PDALogPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class PDALogPatcher
internal static void Patch(Harmony harmony)
{
harmony.Patch(AccessTools.Method(typeof(PDALog), nameof(PDALog.Initialize)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(PDALogPatcher), nameof(InitializePostfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(PDALogPatcher), nameof(InitializePostfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));
}

internal static void InitializePostfix()
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Patchers/PdaPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class PDAPatcher
internal static void Patch(Harmony harmony)
{
harmony.Patch(AccessTools.Method(typeof(PDAScanner), nameof(PDAScanner.Initialize)),
postfix: new HarmonyMethod(AccessTools.Method(typeof(PDAPatcher), nameof(PDAPatcher.InitializePostfix))));
postfix: new HarmonyMethod(AccessTools.Method(typeof(PDAPatcher), nameof(PDAPatcher.InitializePostfix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));

InternalLogger.Log($"PDAPatcher is done.", LogLevel.Debug);
}
Expand Down
5 changes: 5 additions & 0 deletions Nautilus/Patchers/PrefabDatabasePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private static class PostPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(PrefabDatabase), nameof(PrefabDatabase.LoadPrefabDatabase))]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static void LoadPrefabDatabase_Postfix()
{
foreach (var prefab in PrefabHandler.Prefabs)
Expand All @@ -28,6 +29,7 @@ internal static void LoadPrefabDatabase_Postfix()

[HarmonyPrefix]
[HarmonyPatch(typeof(PrefabDatabase), nameof(PrefabDatabase.TryGetPrefabFilename))]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static bool TryGetPrefabFilename_Prefix(string classId, ref string filename, ref bool __result)
{
if (!PrefabHandler.Prefabs.TryGetInfoForClassId(classId, out PrefabInfo prefabInfo))
Expand All @@ -42,6 +44,7 @@ internal static bool TryGetPrefabFilename_Prefix(string classId, ref string file

[HarmonyPrefix]
[HarmonyPatch(typeof(DeferredSpawner.AddressablesTask), nameof(DeferredSpawner.AddressablesTask.SpawnAsync))]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static bool DeferredSpawner_AddressablesTask_Spawn_Prefix(DeferredSpawner.AddressablesTask __instance, ref IEnumerator __result)
{
if (!PrefabHandler.Prefabs.TryGetInfoForFileName(__instance.key, out PrefabInfo prefabInfo))
Expand Down Expand Up @@ -90,6 +93,7 @@ private static IPrefabRequest GetModPrefabAsync(string classId)

[HarmonyPrefix]
[HarmonyPatch(typeof(PrefabDatabase), nameof(PrefabDatabase.GetPrefabAsync))]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static bool GetPrefabAsync_Prefix(ref IPrefabRequest __result, string classId)
{
__result ??= GetModPrefabAsync(classId);
Expand All @@ -101,6 +105,7 @@ internal static bool GetPrefabAsync_Prefix(ref IPrefabRequest __result, string c
{
typeof(string), typeof(IOut<GameObject>), typeof(Transform), typeof(Vector3), typeof(Quaternion), typeof(bool)
})]
[HarmonyAfter(SMLHelperCompatibilityPatcher.SMLHarmonyInstance)]
internal static bool InstantiateAsync_Prefix(ref IEnumerator __result,string key, IOut<GameObject> result, Transform parent, Vector3 position, Quaternion rotation, bool awake)
{
if (!PrefabHandler.Prefabs.TryGetInfoForFileName(key, out var prefabInfo) && !PrefabHandler.Prefabs.TryGetInfoForClassId(key, out prefabInfo))
Expand Down
4 changes: 2 additions & 2 deletions Nautilus/Patchers/SpritePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ internal static void Patch(Harmony harmony)
#endif
MethodInfo spriteManagerGetBackground = AccessTools.Method(typeof(SpriteManager), nameof(SpriteManager.GetBackground), new Type[] { typeof(CraftData.BackgroundType) });

HarmonyMethod patchCheck = new(AccessTools.Method(typeof(SpritePatcher), nameof(SpritePatcher.PatchCheck)));
HarmonyMethod patchBackgrounds = new(AccessTools.Method(typeof(SpritePatcher), nameof(PatchBackgrounds)));
HarmonyMethod patchCheck = new(AccessTools.Method(typeof(SpritePatcher), nameof(SpritePatcher.PatchCheck)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance});
HarmonyMethod patchBackgrounds = new(AccessTools.Method(typeof(SpritePatcher), nameof(PatchBackgrounds)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance});
harmony.Patch(spriteManagerGet, prefix: patchCheck);
harmony.Patch(spriteManagerGetBackground, prefix: patchBackgrounds);
}
Expand Down
2 changes: 1 addition & 1 deletion Nautilus/Patchers/WorldEntityDatabasePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class WorldEntityDatabasePatcher
internal static void Patch(Harmony harmony)
{
harmony.Patch(AccessTools.Method(typeof(WorldEntityDatabase), nameof(WorldEntityDatabase.TryGetInfo)),
prefix: new HarmonyMethod(AccessTools.Method(typeof(WorldEntityDatabasePatcher), nameof(WorldEntityDatabasePatcher.Prefix))));
prefix: new HarmonyMethod(AccessTools.Method(typeof(WorldEntityDatabasePatcher), nameof(WorldEntityDatabasePatcher.Prefix)), after: new []{SMLHelperCompatibilityPatcher.SMLHarmonyInstance}));
}

private static bool Prefix(string classId, ref WorldEntityInfo info, ref bool __result)
Expand Down

0 comments on commit 295cb40

Please sign in to comment.