From 565f0b7f8eae1a25ef8ce9447f93d4210e965800 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 15 Oct 2021 21:06:51 +0100 Subject: [PATCH] update patches, use publicized assembly --- .../NPC/Patches/CharacterAnimationPatches.cs | 43 +++--- .../Player/Patches/PlayerAnimationPatches.cs | 37 ++--- QSB/CampfireSync/Patches/CampfirePatches.cs | 12 +- .../Patches/ConversationPatches.cs | 20 +-- QSB/DeathSync/Patches/DeathPatches.cs | 42 ++--- QSB/DeathSync/Patches/MapPatches.cs | 10 +- QSB/DeathSync/Patches/RespawnPatches.cs | 18 ++- QSB/ElevatorSync/Patches/ElevatorPatches.cs | 9 +- QSB/FrequencySync/Patches/FrequencyPatches.cs | 18 +-- QSB/GeyserSync/Patches/GeyserPatches.cs | 9 +- QSB/Inputs/Patches/InputPatches.cs | 9 +- QSB/ItemSync/Patches/ItemPatches.cs | 23 +-- QSB/LogSync/Patches/LogPatches.cs | 8 +- QSB/OrbSync/Patches/OrbPatches.cs | 14 +- QSB/Patches/QSBPatch.cs | 145 ++---------------- QSB/Patches/QSBPatchManager.cs | 25 ++- QSB/Player/Patches/PlayerPatches.cs | 17 +- QSB/Player/PlayerHUDMarker.cs | 2 +- .../CustomNomaiRemoteCameraStreaming.cs | 6 +- QSB/PoolSync/Patches/PoolPatches.cs | 47 ++++-- QSB/QSB.csproj | 43 +++--- QSB/QSBCore.cs | 2 +- .../Patches/ClientQuantumPatches.cs | 14 +- QSB/QuantumSync/Patches/QuantumPatches.cs | 44 ++++-- .../Patches/QuantumVisibilityPatches.cs | 26 ++-- .../Patches/ServerQuantumPatches.cs | 9 +- QSB/RoastingSync/Patches/RoastingPatches.cs | 30 ++-- QSB/SectorSync/FakeSector.cs | 2 +- QSB/ShipSync/Patches/ShipPatches.cs | 101 ++++++++---- QSB/StatueSync/Patches/StatuePatches.cs | 9 +- QSB/TimeSync/Patches/TimePatches.cs | 23 ++- .../Patches/LauncherPatches.cs | 17 +- QSB/TranslationSync/Patches/SpiralPatches.cs | 17 +- QSB/Utility/Extensions.cs | 21 --- QSBTests/PatchTests.cs | 48 +++--- 35 files changed, 456 insertions(+), 464 deletions(-) diff --git a/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs b/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs index 2d797fe0..fffa8883 100644 --- a/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs +++ b/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs @@ -1,4 +1,5 @@ -using OWML.Common; +using HarmonyLib; +using OWML.Common; using QSB.Animation.NPC.WorldObjects; using QSB.ConversationSync; using QSB.Events; @@ -12,22 +13,14 @@ using UnityEngine; namespace QSB.Animation.NPC.Patches { + [HarmonyPatch] public class CharacterAnimationPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(CharacterAnimController_OnAnimatorIK)); - Prefix(nameof(CharacterAnimController_OnZoneEntry)); - Prefix(nameof(CharacterAnimController_OnZoneExit)); - Prefix(nameof(FacePlayerWhenTalking_OnStartConversation)); - Prefix(nameof(CharacterDialogueTree_StartConversation)); - Prefix(nameof(CharacterDialogueTree_EndConversation)); - Prefix(nameof(KidRockController_Update)); - } - - public static bool CharacterAnimController_OnAnimatorIK( + [HarmonyPrefix] + [HarmonyPatch(typeof(CharacterAnimController), nameof(CharacterAnimController.OnAnimatorIK))] + public static bool AnimatorIKReplacement( CharacterAnimController __instance, float ___headTrackingWeight, bool ___lookOnlyWhenTalking, @@ -103,21 +96,27 @@ namespace QSB.Animation.NPC.Patches } - public static bool CharacterAnimController_OnZoneExit(CharacterAnimController __instance) + [HarmonyPrefix] + [HarmonyPatch(typeof(CharacterAnimController), nameof(CharacterAnimController.OnZoneExit))] + public static bool HeadZoneExit(CharacterAnimController __instance) { var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); QSBEventManager.FireEvent(EventNames.QSBExitHeadZone, qsbObj.ObjectId); return false; } - public static bool CharacterAnimController_OnZoneEntry(CharacterAnimController __instance) + [HarmonyPrefix] + [HarmonyPatch(typeof(CharacterAnimController), nameof(CharacterAnimController.OnZoneEntry))] + public static bool HeadZoneEntry(CharacterAnimController __instance) { var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); QSBEventManager.FireEvent(EventNames.QSBEnterHeadZone, qsbObj.ObjectId); return false; } - public static bool FacePlayerWhenTalking_OnStartConversation( + [HarmonyPrefix] + [HarmonyPatch(typeof(FacePlayerWhenTalking), nameof(FacePlayerWhenTalking.OnStartConversation))] + public static bool OnStartConversation( FacePlayerWhenTalking __instance, CharacterDialogueTree ____dialogueTree) { @@ -140,7 +139,9 @@ namespace QSB.Animation.NPC.Patches return false; } - public static bool CharacterDialogueTree_StartConversation(CharacterDialogueTree __instance) + [HarmonyPrefix] + [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.StartConversation))] + public static bool StartConversation(CharacterDialogueTree __instance) { var allNpcAnimControllers = QSBWorldSync.GetWorldObjects(); var ownerOfThis = allNpcAnimControllers.FirstOrDefault(x => x.GetDialogueTree() == __instance); @@ -154,7 +155,9 @@ namespace QSB.Animation.NPC.Patches return true; } - public static bool CharacterDialogueTree_EndConversation(CharacterDialogueTree __instance) + [HarmonyPrefix] + [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.EndConversation))] + public static bool EndConversation(CharacterDialogueTree __instance) { var allNpcAnimControllers = QSBWorldSync.GetWorldObjects(); var ownerOfThis = allNpcAnimControllers.FirstOrDefault(x => x.GetDialogueTree() == __instance); @@ -168,7 +171,9 @@ namespace QSB.Animation.NPC.Patches return true; } - public static bool KidRockController_Update( + [HarmonyPrefix] + [HarmonyPatch(typeof(KidRockController), nameof(KidRockController.Update))] + public static bool UpdateReplacement( KidRockController __instance, bool ____throwingRock, CharacterDialogueTree ____dialogueTree, diff --git a/QSB/Animation/Player/Patches/PlayerAnimationPatches.cs b/QSB/Animation/Player/Patches/PlayerAnimationPatches.cs index 7db275a1..b884c711 100644 --- a/QSB/Animation/Player/Patches/PlayerAnimationPatches.cs +++ b/QSB/Animation/Player/Patches/PlayerAnimationPatches.cs @@ -1,4 +1,5 @@ -using QSB.Events; +using HarmonyLib; +using QSB.Events; using QSB.Patches; using QSB.Player; using QSB.Utility; @@ -6,27 +7,27 @@ using UnityEngine; namespace QSB.Animation.Patches { + [HarmonyPatch] internal class PlayerAnimationPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - => Prefix(nameof(PlayerAnimController_LateUpdate)); - - public static bool PlayerAnimController_LateUpdate( - PlayerAnimController __instance, - PlayerCharacterController ____playerController, - ThrusterModel ____playerJetpack, - ref float ____ungroundedTime, - Animator ____animator, - ref bool ____justBecameGrounded, - ref bool ____justTookFallDamage, - ref bool ____leftFootGrounded, - ref bool ____rightFootGrounded, - ref bool ____rightArmHidden, - GameObject[] ____rightArmObjects, - int ____defaultLayer, - int ____probeOnlyLayer) + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerAnimController), nameof(PlayerAnimController.LateUpdate))] + public static bool LateUpdateReplacement( + PlayerAnimController __instance, + PlayerCharacterController ____playerController, + ThrusterModel ____playerJetpack, + ref float ____ungroundedTime, + Animator ____animator, + ref bool ____justBecameGrounded, + ref bool ____justTookFallDamage, + ref bool ____leftFootGrounded, + ref bool ____rightFootGrounded, + ref bool ____rightArmHidden, + GameObject[] ____rightArmObjects, + int ____defaultLayer, + int ____probeOnlyLayer) { var isGrounded = ____playerController.IsGrounded(); var isAttached = PlayerState.IsAttached(); diff --git a/QSB/CampfireSync/Patches/CampfirePatches.cs b/QSB/CampfireSync/Patches/CampfirePatches.cs index 7914fb5b..5dc7f0e0 100644 --- a/QSB/CampfireSync/Patches/CampfirePatches.cs +++ b/QSB/CampfireSync/Patches/CampfirePatches.cs @@ -1,20 +1,22 @@ -using QSB.CampfireSync.WorldObjects; +using HarmonyLib; +using QSB.CampfireSync.WorldObjects; using QSB.Events; using QSB.Patches; using QSB.WorldSync; namespace QSB.CampfireSync.Patches { + [HarmonyPatch] internal class CampfirePatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() => Prefix(nameof(Campfire_OnPressInteract)); - - public static bool Campfire_OnPressInteract(Campfire __instance, Campfire.State ____state) + [HarmonyPrefix] + [HarmonyPatch(typeof(Campfire), nameof(Campfire.OnPressInteract))] + public static bool LightCampfireEvent(Campfire __instance) { var qsbCampfire = QSBWorldSync.GetWorldFromUnity(__instance); - if (____state == Campfire.State.LIT) + if (__instance._state == Campfire.State.LIT) { qsbCampfire.StartRoasting(); } diff --git a/QSB/ConversationSync/Patches/ConversationPatches.cs b/QSB/ConversationSync/Patches/ConversationPatches.cs index ba948aa2..c674cc15 100644 --- a/QSB/ConversationSync/Patches/ConversationPatches.cs +++ b/QSB/ConversationSync/Patches/ConversationPatches.cs @@ -1,4 +1,5 @@ -using OWML.Common; +using HarmonyLib; +using OWML.Common; using QSB.Patches; using QSB.Player; using QSB.Utility; @@ -7,18 +8,13 @@ using System.Collections.Generic; namespace QSB.ConversationSync.Patches { + [HarmonyPatch] public class ConversationPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Postfix(nameof(DialogueNode_GetNextPage)); - Prefix(nameof(CharacterDialogueTree_InputDialogueOption)); - Prefix(nameof(CharacterDialogueTree_StartConversation)); - Prefix(nameof(CharacterDialogueTree_EndConversation)); - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.StartConversation))] public static void CharacterDialogueTree_StartConversation(CharacterDialogueTree __instance) { var index = QSBWorldSync.OldDialogueTrees.FindIndex(x => x == __instance); @@ -31,6 +27,8 @@ namespace QSB.ConversationSync.Patches ConversationManager.Instance.SendConvState(index, true); } + [HarmonyPrefix] + [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.EndConversation))] public static bool CharacterDialogueTree_EndConversation(CharacterDialogueTree __instance) { if (!__instance.enabled) @@ -51,6 +49,8 @@ namespace QSB.ConversationSync.Patches return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.InputDialogueOption))] public static bool CharacterDialogueTree_InputDialogueOption(int optionIndex, DialogueBoxVer2 ____currentDialogueBox) { if (optionIndex < 0) @@ -65,6 +65,8 @@ namespace QSB.ConversationSync.Patches return true; } + [HarmonyPostfix] + [HarmonyPatch(typeof(DialogueNode), nameof(DialogueNode.GetNextPage))] public static void DialogueNode_GetNextPage(string ____name, List ____listPagesToDisplay, int ____currentPage) { var key = ____name + ____listPagesToDisplay[____currentPage]; diff --git a/QSB/DeathSync/Patches/DeathPatches.cs b/QSB/DeathSync/Patches/DeathPatches.cs index 50d596d9..d012b634 100644 --- a/QSB/DeathSync/Patches/DeathPatches.cs +++ b/QSB/DeathSync/Patches/DeathPatches.cs @@ -11,35 +11,37 @@ using UnityEngine; namespace QSB.DeathSync.Patches { + [HarmonyPatch] public class DeathPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(DeathManager_KillPlayer_Prefix)); - Postfix(nameof(DeathManager_KillPlayer_Postfix)); - Prefix(nameof(ShipDetachableLeg_Detach)); - Prefix(nameof(ShipDetachableModule_Detach)); - Empty("ShipEjectionSystem_OnPressInteract"); - Postfix(nameof(ShipDamageController_Awake)); - Prefix(nameof(DestructionVolume_VanishShip)); - Prefix(nameof(HighSpeedImpactSensor_FixedUpdate)); - Prefix(nameof(PlayerResources_OnImpact)); - } + // TODO : Remove with future functionality. + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipEjectionSystem), nameof(ShipEjectionSystem.OnPressInteract))] + public static bool DisableEjection() + => false; + // TODO : Remove with future functionality. + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipDetachableLeg), nameof(ShipDetachableLeg.Detach))] public static bool ShipDetachableLeg_Detach(ref OWRigidbody __result) { __result = null; return false; } + // TODO : Remove with future functionality. + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipDetachableModule), nameof(ShipDetachableModule.Detach))] public static bool ShipDetachableModule_Detach(ref OWRigidbody __result) { __result = null; return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerResources), nameof(PlayerResources.OnImpact))] public static bool PlayerResources_OnImpact(ImpactData impact, PlayerResources __instance, float ____currentHealth) { if (PlayerState.IsInsideShip()) @@ -65,6 +67,8 @@ namespace QSB.DeathSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(HighSpeedImpactSensor), nameof(HighSpeedImpactSensor.FixedUpdate))] public static bool HighSpeedImpactSensor_FixedUpdate( HighSpeedImpactSensor __instance, bool ____isPlayer, @@ -185,6 +189,8 @@ namespace QSB.DeathSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(DeathManager), nameof(DeathManager.KillPlayer))] public static bool DeathManager_KillPlayer_Prefix(DeathType deathType) { if (RespawnOnDeath.Instance == null) @@ -203,20 +209,20 @@ namespace QSB.DeathSync.Patches return false; } + [HarmonyPostfix] + [HarmonyPatch(typeof(DeathManager), nameof(DeathManager.KillPlayer))] public static void DeathManager_KillPlayer_Postfix(DeathType deathType) { QSBEventManager.FireEvent(EventNames.QSBPlayerDeath, deathType); } + [HarmonyPostfix] + [HarmonyPatch(typeof(ShipDamageController), nameof(ShipDamageController.Awake))] public static void ShipDamageController_Awake(ref bool ____exploded) => ____exploded = true; - public static IEnumerable ReturnNull(IEnumerable instructions) => new List - { - new CodeInstruction(OpCodes.Ldnull), - new CodeInstruction(OpCodes.Ret) - }; - + [HarmonyPrefix] + [HarmonyPatch(typeof(DestructionVolume), nameof(DestructionVolume.VanishShip))] public static bool DestructionVolume_VanishShip(DeathType ____deathType) { if (RespawnOnDeath.Instance == null) diff --git a/QSB/DeathSync/Patches/MapPatches.cs b/QSB/DeathSync/Patches/MapPatches.cs index 7bc11ca2..cf233fd5 100644 --- a/QSB/DeathSync/Patches/MapPatches.cs +++ b/QSB/DeathSync/Patches/MapPatches.cs @@ -7,11 +7,11 @@ namespace QSB.DeathSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.RespawnTime; - public override void DoPatches() - { - Prefix(nameof(MapController_LateUpdate)); - Prefix(nameof(MapController_EnterMapView)); - } + //public override void DoPatches() + //{ + // Prefix(nameof(MapController.LateUpdate), nameof(MapController_LateUpdate)); + // Prefix(nameof(MapController.EnterMapView), nameof(MapController_EnterMapView)); + //} public static bool MapController_EnterMapView( MapController __instance, diff --git a/QSB/DeathSync/Patches/RespawnPatches.cs b/QSB/DeathSync/Patches/RespawnPatches.cs index 9365e6c8..34d96c63 100644 --- a/QSB/DeathSync/Patches/RespawnPatches.cs +++ b/QSB/DeathSync/Patches/RespawnPatches.cs @@ -1,18 +1,22 @@ -using OWML.Utils; +using HarmonyLib; +using OWML.Utils; using QSB.Patches; namespace QSB.DeathSync.Patches { + [HarmonyPatch] internal class RespawnPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(PlayerRecoveryPoint_OnGainFocus)); - Prefix(nameof(PlayerRecoveryPoint_OnPressInteract)); - } + //public override void DoPatches() + //{ + // Prefix(nameof(PlayerRecoveryPoint.OnGainFocus), nameof(PlayerRecoveryPoint_OnGainFocus)); + // Prefix(nameof(PlayerRecoveryPoint.OnPressInteract), nameof(PlayerRecoveryPoint_OnPressInteract)); + //} + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerRecoveryPoint), nameof(PlayerRecoveryPoint.OnGainFocus))] public static bool PlayerRecoveryPoint_OnGainFocus( PlayerResources ____playerResources, bool ____refuelsPlayer, @@ -100,6 +104,8 @@ namespace QSB.DeathSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerRecoveryPoint), nameof(PlayerRecoveryPoint.OnPressInteract))] public static bool PlayerRecoveryPoint_OnPressInteract( PlayerRecoveryPoint __instance, PlayerResources ____playerResources, diff --git a/QSB/ElevatorSync/Patches/ElevatorPatches.cs b/QSB/ElevatorSync/Patches/ElevatorPatches.cs index f1665b1a..2e12063a 100644 --- a/QSB/ElevatorSync/Patches/ElevatorPatches.cs +++ b/QSB/ElevatorSync/Patches/ElevatorPatches.cs @@ -1,4 +1,5 @@ -using OWML.Utils; +using HarmonyLib; +using OWML.Utils; using QSB.ElevatorSync.WorldObjects; using QSB.Events; using QSB.Patches; @@ -6,18 +7,18 @@ using QSB.WorldSync; namespace QSB.ElevatorSync.Patches { + [HarmonyPatch] public class ElevatorPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + [HarmonyPostfix] + [HarmonyPatch(typeof(Elevator), nameof(Elevator.StartLift))] public static void Elevator_StartLift(Elevator __instance) { var isGoingUp = __instance.GetValue("_goingToTheEnd"); var id = QSBWorldSync.GetIdFromUnity(__instance); QSBEventManager.FireEvent(EventNames.QSBStartLift, id, isGoingUp); } - - public override void DoPatches() - => Postfix(nameof(Elevator_StartLift)); } } \ No newline at end of file diff --git a/QSB/FrequencySync/Patches/FrequencyPatches.cs b/QSB/FrequencySync/Patches/FrequencyPatches.cs index 3ad8eb48..a7ad6a5a 100644 --- a/QSB/FrequencySync/Patches/FrequencyPatches.cs +++ b/QSB/FrequencySync/Patches/FrequencyPatches.cs @@ -1,22 +1,22 @@ -using QSB.Events; +using HarmonyLib; +using QSB.Events; using QSB.Patches; namespace QSB.FrequencySync.Patches { + [HarmonyPatch] public class FrequencyPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Postfix(nameof(AudioSignal_IdentifyFrequency)); - Postfix(nameof(AudioSignal_IdentifySignal)); - } - - public static void AudioSignal_IdentifyFrequency(SignalFrequency ____frequency) + [HarmonyPostfix] + [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.IdentifyFrequency))] + static void IdentifyFrequencyEvent(SignalFrequency ____frequency) => QSBEventManager.FireEvent(EventNames.QSBIdentifyFrequency, ____frequency); - public static void AudioSignal_IdentifySignal(SignalName ____name) + [HarmonyPostfix] + [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.IdentifySignal))] + static void IdentifySignalEvent(SignalName ____name) => QSBEventManager.FireEvent(EventNames.QSBIdentifySignal, ____name); } } diff --git a/QSB/GeyserSync/Patches/GeyserPatches.cs b/QSB/GeyserSync/Patches/GeyserPatches.cs index 072eb8c5..b393b6fa 100644 --- a/QSB/GeyserSync/Patches/GeyserPatches.cs +++ b/QSB/GeyserSync/Patches/GeyserPatches.cs @@ -1,11 +1,16 @@ -using QSB.Patches; +using HarmonyLib; +using QSB.Patches; namespace QSB.GeyserSync.Patches { + [HarmonyPatch] internal class GeyserPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect; - public override void DoPatches() => Empty("GeyserController_Update"); + [HarmonyPrefix] + [HarmonyPatch(typeof(GeyserController), nameof(GeyserController.Update))] + public static bool Empty() + => false; } } diff --git a/QSB/Inputs/Patches/InputPatches.cs b/QSB/Inputs/Patches/InputPatches.cs index ff9e0ce1..0b36b7ad 100644 --- a/QSB/Inputs/Patches/InputPatches.cs +++ b/QSB/Inputs/Patches/InputPatches.cs @@ -1,14 +1,15 @@ -using QSB.Patches; +using HarmonyLib; +using QSB.Patches; namespace QSB.Inputs.Patches { + [HarmonyPatch] internal class InputPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - => Prefix(nameof(OWInput_Update)); - + [HarmonyPrefix] + [HarmonyPatch(typeof(OWInput), nameof(OWInput.Update))] public static bool OWInput_Update() => QSBInputManager.Instance.InputsEnabled; } diff --git a/QSB/ItemSync/Patches/ItemPatches.cs b/QSB/ItemSync/Patches/ItemPatches.cs index b47a0826..03667c05 100644 --- a/QSB/ItemSync/Patches/ItemPatches.cs +++ b/QSB/ItemSync/Patches/ItemPatches.cs @@ -1,4 +1,5 @@ -using OWML.Common; +using HarmonyLib; +using OWML.Common; using QSB.Events; using QSB.Patches; using QSB.Utility; @@ -7,19 +8,13 @@ using UnityEngine; namespace QSB.ItemSync.Patches { + [HarmonyPatch] internal class ItemPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(ItemTool_MoveItemToCarrySocket)); - Prefix(nameof(ItemTool_SocketItem)); - Prefix(nameof(ItemTool_StartUnsocketItem)); - Prefix(nameof(ItemTool_CompleteUnsocketItem)); - Prefix(nameof(ItemTool_DropItem)); - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.MoveItemToCarrySocket))] public static bool ItemTool_MoveItemToCarrySocket(OWItem item) { var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(item)); @@ -27,6 +22,8 @@ namespace QSB.ItemSync.Patches return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.SocketItem))] public static bool ItemTool_SocketItem(OWItem ____heldItem, OWItemSocket socket) { var socketId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(socket)); @@ -35,6 +32,8 @@ namespace QSB.ItemSync.Patches return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.StartUnsocketItem))] public static bool ItemTool_StartUnsocketItem(OWItemSocket socket) { var socketId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(socket)); @@ -42,6 +41,8 @@ namespace QSB.ItemSync.Patches return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.CompleteUnsocketItem))] public static bool ItemTool_CompleteUnsocketItem(OWItem ____heldItem) { var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(____heldItem)); @@ -49,6 +50,8 @@ namespace QSB.ItemSync.Patches return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ItemTool), nameof(ItemTool.DropItem))] public static bool ItemTool_DropItem(RaycastHit hit, OWRigidbody targetRigidbody, IItemDropTarget customDropTarget, ref OWItem ____heldItem) { Locator.GetPlayerAudioController().PlayDropItem(____heldItem.GetItemType()); diff --git a/QSB/LogSync/Patches/LogPatches.cs b/QSB/LogSync/Patches/LogPatches.cs index 361b82b0..c619d2fd 100644 --- a/QSB/LogSync/Patches/LogPatches.cs +++ b/QSB/LogSync/Patches/LogPatches.cs @@ -1,12 +1,16 @@ -using QSB.Events; +using HarmonyLib; +using QSB.Events; using QSB.Patches; namespace QSB.LogSync.Patches { + [HarmonyPatch] public class LogPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + [HarmonyPostfix] + [HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.RevealFact))] public static void ShipLogManager_RevealFact(string id, bool saveGame, bool showNotification, bool __result) { if (!__result) @@ -16,7 +20,5 @@ namespace QSB.LogSync.Patches QSBEventManager.FireEvent(EventNames.QSBRevealFact, id, saveGame, showNotification); } - - public override void DoPatches() => Postfix(nameof(ShipLogManager_RevealFact)); } } \ No newline at end of file diff --git a/QSB/OrbSync/Patches/OrbPatches.cs b/QSB/OrbSync/Patches/OrbPatches.cs index 03832dca..360dadcf 100644 --- a/QSB/OrbSync/Patches/OrbPatches.cs +++ b/QSB/OrbSync/Patches/OrbPatches.cs @@ -1,4 +1,5 @@ -using QSB.Events; +using HarmonyLib; +using QSB.Events; using QSB.Patches; using QSB.Utility; using QSB.WorldSync; @@ -6,10 +7,13 @@ using UnityEngine; namespace QSB.OrbSync.Patches { + [HarmonyPatch] public class OrbPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + [HarmonyPostfix] + [HarmonyPatch(typeof(NomaiInterfaceOrb), nameof(NomaiInterfaceOrb.StartDragFromPosition))] public static void NomaiInterfaceOrb_StartDragFromPosition(bool __result, NomaiInterfaceOrb __instance) { if (__result) @@ -18,6 +22,8 @@ namespace QSB.OrbSync.Patches } } + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiInterfaceSlot), nameof(NomaiInterfaceSlot.CheckOrbCollision))] public static bool NomaiInterfaceSlot_CheckOrbCollision(ref bool __result, NomaiInterfaceSlot __instance, NomaiInterfaceOrb orb, bool ____ignoreDraggedOrbs, float ____radius, float ____exitRadius, ref NomaiInterfaceOrb ____occupyingOrb) { @@ -60,11 +66,5 @@ namespace QSB.OrbSync.Patches __result = true; return false; } - - public override void DoPatches() - { - Postfix(nameof(NomaiInterfaceOrb_StartDragFromPosition)); - Prefix(nameof(NomaiInterfaceSlot_CheckOrbCollision)); - } } } \ No newline at end of file diff --git a/QSB/Patches/QSBPatch.cs b/QSB/Patches/QSBPatch.cs index 20844c25..4e3a4098 100644 --- a/QSB/Patches/QSBPatch.cs +++ b/QSB/Patches/QSBPatch.cs @@ -1,147 +1,24 @@ -using OWML.Common; -using QSB.Utility; -using System; -using System.Collections.Generic; +using QSB.Utility; using System.Linq; -using System.Reflection; namespace QSB.Patches { public abstract class QSBPatch { public abstract QSBPatchTypes Type { get; } - public abstract void DoPatches(); + + public virtual void DoPatches() + { + var oldMethods = QSBPatchManager.HarmonyInstance.GetPatchedMethods(); + QSBPatchManager.HarmonyInstance.PatchAll(GetType()); + foreach (var method in QSBPatchManager.HarmonyInstance.GetPatchedMethods().Except(oldMethods)) + { + DebugLog.DebugWrite($"- Patching {method.DeclaringType}.{method.Name}"); + } + } public void DoUnpatches() { - foreach (var item in _patchedMethods) - { - //DebugLog.DebugWrite($"[Unpatch] {item.DeclaringType}.{item.Name}", MessageType.Info); - Unpatch(item); - } - - _patchedMethods.Clear(); - } - - private List _patchedMethods = new List(); - - public void Empty(string patchName) - { - //DebugLog.DebugWrite($"[Empty] {patchName}", MessageType.Success); - var method = GetMethodInfo(patchName); - QSBCore.Helper.HarmonyHelper.EmptyMethod(method); - _patchedMethods.Add(method); - } - - public void Prefix(string patchName, params Type[] args) - => DoPrefixPostfix(true, patchName, args); - - public void Postfix(string patchName, params Type[] args) - => DoPrefixPostfix(false, patchName, args); - - private void DoPrefixPostfix(bool isPrefix, string patchName, params Type[] args) - { - var method = GetMethodInfo(patchName, args); - - if (method != null) - { - if (isPrefix) - { - QSBCore.Helper.HarmonyHelper.AddPrefix(method, GetType(), patchName); - } - else - { - QSBCore.Helper.HarmonyHelper.AddPostfix(method, GetType(), patchName); - } - - _patchedMethods.Add(method); - } - - //DebugLog.DebugWrite($"{(isPrefix ? "[Prefix]" : "[Postfix]")} {patchName}", method == null ? MessageType.Error : MessageType.Success); - } - - private MethodInfo GetMethodInfo(string patchName, params Type[] args) - { - var splitName = patchName.Split('_'); - var typeName = splitName[0]; - var methodName = splitName[1]; - - var type = GetFirstTypeByName(typeName); - if (type == null) - { - DebugLog.ToConsole($"Error - Couldn't find type for patch name {patchName}!", MessageType.Error); - return null; - } - - var allMethodsOfName = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy).Where(x => x.Name == methodName); - - if (allMethodsOfName.Count() == 0) - { - DebugLog.ToConsole($"Error - Could not find method {methodName} in type {typeName}.", MessageType.Error); - return null; - } - - if (allMethodsOfName.Count() == 1) - { - return allMethodsOfName.First(); - } - - DebugLog.DebugWrite($"More than one method found with name {methodName} in type {typeName}"); - - foreach (var method in allMethodsOfName) - { - DebugLog.DebugWrite($"checking {method.Name}"); - var paramList = method.GetParameters().Select(x => x.ParameterType); - if (Enumerable.SequenceEqual(args, paramList)) - { - DebugLog.DebugWrite($"match!"); - return method; - } - } - - DebugLog.DebugWrite($"nothing found"); - - DebugLog.ToConsole($"Error - Could not find method {methodName} in type {typeName} with parameter list of {string.Join(", ", args.Select(x => x.FullName).ToArray())}", MessageType.Error); - foreach (var method in allMethodsOfName) - { - var paramList = method.GetParameters().Select(x => x.ParameterType); - DebugLog.ToConsole($"- Found {method.Name}, but with params {string.Join(", ", paramList.Select(x => x.FullName).ToArray())}", MessageType.Error); - } - - return null; - } - - private Type GetFirstTypeByName(string typeName) - { - var a = typeof(OWRigidbody).Assembly; - var assemblyTypes = a.GetTypes(); - for (var j = 0; j < assemblyTypes.Length; j++) - { - if (assemblyTypes[j].Name == typeName) - { - return assemblyTypes[j]; - } - } - - return null; - } - - private void Unpatch(MethodInfo method) - { - /* - var dictionary = typeof(HarmonySharedState).Invoke>("GetState", new object[0]); - var methodBase = dictionary.Keys.First(m => - m.DeclaringType == method.DeclaringType - && m.Name == method.Name); - - var patchInfo = PatchInfoSerialization.Deserialize(dictionary.GetValueSafe(methodBase)); - patchInfo.RemovePostfix(QSBCore.Helper.Manifest.UniqueName); - patchInfo.RemovePrefix(QSBCore.Helper.Manifest.UniqueName); - patchInfo.RemoveTranspiler(QSBCore.Helper.Manifest.UniqueName); - - PatchFunctions.UpdateWrapper(methodBase, patchInfo, QSBCore.Helper.Manifest.UniqueName); - dictionary[methodBase] = patchInfo.Serialize(); - */ } } } \ No newline at end of file diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 6aa7ad33..8559b627 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -1,4 +1,6 @@ -using OWML.Common; +using HarmonyLib; +using OWML.Common; +using OWML.Utils; using QSB.Animation.NPC.Patches; using QSB.Animation.Patches; using QSB.CampfireSync.Patches; @@ -34,6 +36,8 @@ namespace QSB.Patches private static List _patchList = new List(); + public static Harmony HarmonyInstance; + public static void Init() { _patchList = new List @@ -66,27 +70,36 @@ namespace QSB.Patches new LauncherPatches() }; + HarmonyInstance = QSBCore.Helper.HarmonyHelper.GetValue("_harmony"); + DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success); } public static void DoPatchType(QSBPatchTypes type) { OnPatchType?.SafeInvoke(type); - //DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); + DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); foreach (var patch in _patchList.Where(x => x.Type == type)) { - //DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info); - patch.DoPatches(); + DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info); + try + { + patch.DoPatches(); + } + catch (Exception ex) + { + DebugLog.DebugWrite($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error); + } } } public static void DoUnpatchType(QSBPatchTypes type) { OnUnpatchType?.SafeInvoke(type); - //DebugLog.DebugWrite($"Unpatch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); + DebugLog.DebugWrite($"Unpatch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); foreach (var patch in _patchList.Where(x => x.Type == type)) { - //DebugLog.DebugWrite($" - Unpatching in {patch.GetType().Name}", MessageType.Info); + DebugLog.DebugWrite($" - Unpatching in {patch.GetType().Name}", MessageType.Info); patch.DoUnpatches(); } } diff --git a/QSB/Player/Patches/PlayerPatches.cs b/QSB/Player/Patches/PlayerPatches.cs index 581aef3f..383ebaba 100644 --- a/QSB/Player/Patches/PlayerPatches.cs +++ b/QSB/Player/Patches/PlayerPatches.cs @@ -1,17 +1,15 @@ -using QSB.Patches; +using HarmonyLib; +using QSB.Patches; namespace QSB.Player.Patches { + [HarmonyPatch] internal class PlayerPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(PlayerCrushedController_CrushPlayer)); - Prefix(nameof(PauseMenuManager_OnExitToMainMenu)); - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerCrushedController), nameof(PlayerCrushedController.CrushPlayer))] public static bool PlayerCrushedController_CrushPlayer() { // #CrushIt https://www.twitch.tv/videos/846916781?t=00h03m51s @@ -20,6 +18,9 @@ namespace QSB.Player.Patches return false; } - public static void PauseMenuManager_OnExitToMainMenu() => QSBPlayerManager.LocalPlayer.PlayerStates.IsReady = false; + [HarmonyPrefix] + [HarmonyPatch(typeof(PauseMenuManager), nameof(PauseMenuManager.OnExitToMainMenu))] + public static void PauseMenuManager_OnExitToMainMenu() + => QSBPlayerManager.LocalPlayer.PlayerStates.IsReady = false; } } diff --git a/QSB/Player/PlayerHUDMarker.cs b/QSB/Player/PlayerHUDMarker.cs index 18913139..9fdf8047 100644 --- a/QSB/Player/PlayerHUDMarker.cs +++ b/QSB/Player/PlayerHUDMarker.cs @@ -9,7 +9,7 @@ namespace QSB.Player private bool _needsInitializing; private bool _isReady; - protected override void InitCanvasMarker() + public override void InitCanvasMarker() { _markerRadius = 2f; diff --git a/QSB/PoolSync/CustomNomaiRemoteCameraStreaming.cs b/QSB/PoolSync/CustomNomaiRemoteCameraStreaming.cs index d98f6b80..1178a036 100644 --- a/QSB/PoolSync/CustomNomaiRemoteCameraStreaming.cs +++ b/QSB/PoolSync/CustomNomaiRemoteCameraStreaming.cs @@ -13,7 +13,7 @@ namespace QSB.PoolSync private NomaiRemoteCameraStreaming _oldStreaming; private bool _hasLoadedAssets; - protected override void Awake() + public override void Awake() { base.Awake(); _oldStreaming = GetComponent(); @@ -48,7 +48,7 @@ namespace QSB.PoolSync } } - protected override void OnSectorOccupantAdded(SectorDetector sectorDetector) + public override void OnSectorOccupantAdded(SectorDetector sectorDetector) { if (sectorDetector.GetOccupantType() == DynamicOccupant.Player && StreamingManager.isStreamingEnabled) { @@ -56,7 +56,7 @@ namespace QSB.PoolSync } } - protected override void OnSectorOccupantRemoved(SectorDetector sectorDetector) + public override void OnSectorOccupantRemoved(SectorDetector sectorDetector) { if (sectorDetector.GetOccupantType() == DynamicOccupant.Player) { diff --git a/QSB/PoolSync/Patches/PoolPatches.cs b/QSB/PoolSync/Patches/PoolPatches.cs index 580e9387..41264063 100644 --- a/QSB/PoolSync/Patches/PoolPatches.cs +++ b/QSB/PoolSync/Patches/PoolPatches.cs @@ -1,34 +1,51 @@ -using QSB.Patches; +using HarmonyLib; +using QSB.Patches; namespace QSB.PoolSync.Patches { + [HarmonyPatch] internal class PoolPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(NomaiRemoteCameraPlatform_Awake)); - Prefix(nameof(NomaiRemoteCameraPlatform_Update)); - Prefix(nameof(NomaiRemoteCameraPlatform_OnSocketableRemoved)); - Prefix(nameof(NomaiRemoteCameraPlatform_OnSocketableDonePlacing)); - Prefix(nameof(NomaiRemoteCameraPlatform_OnPedestalContact)); - Prefix(nameof(NomaiRemoteCameraStreaming_FixedUpdate)); - Prefix(nameof(NomaiRemoteCameraStreaming_OnSectorOccupantAdded)); - Prefix(nameof(NomaiRemoteCameraStreaming_OnSectorOccupantRemoved)); - Prefix(nameof(NomaiRemoteCameraStreaming_OnEntry)); - Prefix(nameof(NomaiRemoteCameraStreaming_OnExit)); - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraPlatform), nameof(NomaiRemoteCameraPlatform.Awake))] public static bool NomaiRemoteCameraPlatform_Awake() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraPlatform), nameof(NomaiRemoteCameraPlatform.Update))] public static bool NomaiRemoteCameraPlatform_Update() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraPlatform), nameof(NomaiRemoteCameraPlatform.OnSocketableRemoved))] public static bool NomaiRemoteCameraPlatform_OnSocketableRemoved() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraPlatform), nameof(NomaiRemoteCameraPlatform.OnSocketableDonePlacing))] public static bool NomaiRemoteCameraPlatform_OnSocketableDonePlacing() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraPlatform), nameof(NomaiRemoteCameraPlatform.OnPedestalContact))] public static bool NomaiRemoteCameraPlatform_OnPedestalContact() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraStreaming), nameof(NomaiRemoteCameraStreaming.FixedUpdate))] public static bool NomaiRemoteCameraStreaming_FixedUpdate() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraStreaming), nameof(NomaiRemoteCameraStreaming.OnSectorOccupantAdded))] public static bool NomaiRemoteCameraStreaming_OnSectorOccupantAdded() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraStreaming), nameof(NomaiRemoteCameraStreaming.OnSectorOccupantRemoved))] public static bool NomaiRemoteCameraStreaming_OnSectorOccupantRemoved() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraStreaming), nameof(NomaiRemoteCameraStreaming.OnEntry))] public static bool NomaiRemoteCameraStreaming_OnEntry() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiRemoteCameraStreaming), nameof(NomaiRemoteCameraStreaming.OnExit))] public static bool NomaiRemoteCameraStreaming_OnExit() => false; } } diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 0fdf46cd..756cbd7c 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -22,6 +22,7 @@ DEBUG;TRACE prompt 4 + true pdbonly @@ -339,69 +340,69 @@ - - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\Assembly-CSharp.dll + + $(GameDir)\OuterWilds_Data\Managed\publicized_assemblies\Assembly-CSharp_publicized.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\Assembly-CSharp-firstpass.dll + $(GameDir)\OuterWilds_Data\Managed\Assembly-CSharp-firstpass.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\netstandard.dll + $(GameDir)\OuterWilds_Data\Managed\netstandard.dll ..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll False - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\Unity.InputSystem.dll + $(GameDir)\OuterWilds_Data\Managed\Unity.InputSystem.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.AnimationModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.AnimationModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.AssetBundleModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.AssetBundleModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.AudioModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.AudioModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.CoreModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.CoreModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.IMGUIModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.IMGUIModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.InputLegacyModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.InputLegacyModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.InputModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.InputModule.dll - D:\EpicGames\OuterWilds\OuterWilds_Data\Managed\UnityEngine.Networking.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.Networking.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.ParticleSystemModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.ParticleSystemModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.PhysicsModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.PhysicsModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.TextCoreModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.TextCoreModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.TextRenderingModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.TextRenderingModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.UI.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.UI.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.UIModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.UIModule.dll - D:\SteamLibrary\steamapps\common\Outer Wilds\OuterWilds_Data\Managed\UnityEngine.UNETModule.dll + $(GameDir)\OuterWilds_Data\Managed\UnityEngine.UNETModule.dll diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 8f58c7b2..b210f046 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -69,7 +69,7 @@ namespace QSB public void Awake() { - var instance = TextTranslation.Get().GetValue("m_table"); + var instance = TextTranslation.Get().m_table; instance.theUITable[(int)UITextType.PleaseUseController] = "Quantum Space Buddies is best experienced with friends..."; } diff --git a/QSB/QuantumSync/Patches/ClientQuantumPatches.cs b/QSB/QuantumSync/Patches/ClientQuantumPatches.cs index a25933d4..0a018cc8 100644 --- a/QSB/QuantumSync/Patches/ClientQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/ClientQuantumPatches.cs @@ -1,21 +1,21 @@ -using QSB.Patches; +using HarmonyLib; +using QSB.Patches; using System.Reflection; namespace QSB.QuantumSync.Patches { + [HarmonyPatch] public class ClientQuantumPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect; - public override void DoPatches() - { - Prefix(nameof(QuantumMoon_ChangeQuantumState)); - Postfix(nameof(QuantumMoon_Start)); - } - + [HarmonyPostfix] + [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.Start))] public static void QuantumMoon_Start(QuantumMoon __instance) => __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 }); + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.ChangeQuantumState))] public static bool QuantumMoon_ChangeQuantumState() => false; } diff --git a/QSB/QuantumSync/Patches/QuantumPatches.cs b/QSB/QuantumSync/Patches/QuantumPatches.cs index bfe4e469..ce0aaca5 100644 --- a/QSB/QuantumSync/Patches/QuantumPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumPatches.cs @@ -1,4 +1,5 @@ -using OWML.Common; +using HarmonyLib; +using OWML.Common; using QSB.Events; using QSB.Patches; using QSB.Player; @@ -12,26 +13,13 @@ using UnityEngine; namespace QSB.QuantumSync.Patches { + [HarmonyPatch] public class QuantumPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(SocketedQuantumObject_ChangeQuantumState)); - Postfix(nameof(SocketedQuantumObject_MoveToSocket)); - Prefix(nameof(QuantumShuffleObject_ChangeQuantumState)); - Prefix(nameof(MultiStateQuantumObject_ChangeQuantumState)); - Postfix(nameof(QuantumState_SetVisible)); - Prefix(nameof(QuantumShrine_IsPlayerInDarkness)); - Prefix(nameof(QuantumShrine_ChangeQuantumState)); - Prefix(nameof(QuantumShrine_OnEntry)); - Prefix(nameof(QuantumShrine_OnExit)); - Prefix(nameof(QuantumMoon_CheckPlayerFogProximity)); - Prefix(nameof(QuantumObject_IsLockedByPlayerContact)); - Prefix(nameof(MultiStateQuantumObject_Start)); - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumObject), nameof(QuantumObject.IsLockedByPlayerContact))] public static bool QuantumObject_IsLockedByPlayerContact(ref bool __result, QuantumObject __instance) { var playersEntangled = QuantumManager.GetEntangledPlayers(__instance); @@ -39,6 +27,8 @@ namespace QSB.QuantumSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(SocketedQuantumObject), nameof(SocketedQuantumObject.ChangeQuantumState))] public static bool SocketedQuantumObject_ChangeQuantumState( SocketedQuantumObject __instance, ref bool __result, @@ -149,6 +139,8 @@ namespace QSB.QuantumSync.Patches return false; } + [HarmonyPostfix] + [HarmonyPatch(typeof(SocketedQuantumObject), nameof(SocketedQuantumObject.MoveToSocket))] public static void SocketedQuantumObject_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket) { if (!WorldObjectManager.AllReady) @@ -183,6 +175,8 @@ namespace QSB.QuantumSync.Patches __instance.transform.localRotation); } + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumShuffleObject), nameof(QuantumShuffleObject.ChangeQuantumState))] public static bool QuantumShuffleObject_ChangeQuantumState( QuantumShuffleObject __instance, ref List ____indexList, @@ -227,6 +221,8 @@ namespace QSB.QuantumSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(MultiStateQuantumObject), nameof(MultiStateQuantumObject.Start))] public static bool MultiStateQuantumObject_Start(MultiStateQuantumObject __instance, Sector ____sector, bool ____collapseOnStart) { if (!WorldObjectManager.AllReady) @@ -261,6 +257,8 @@ namespace QSB.QuantumSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(MultiStateQuantumObject), nameof(MultiStateQuantumObject.ChangeQuantumState))] public static bool MultiStateQuantumObject_ChangeQuantumState(MultiStateQuantumObject __instance) { if (!WorldObjectManager.AllReady) @@ -278,6 +276,8 @@ namespace QSB.QuantumSync.Patches return isInControl; } + [HarmonyPostfix] + [HarmonyPatch(typeof(QuantumState), nameof(QuantumState.SetVisible))] public static void QuantumState_SetVisible(QuantumState __instance, bool visible) { if (!WorldObjectManager.AllReady) @@ -305,6 +305,8 @@ namespace QSB.QuantumSync.Patches stateIndex); } + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumShrine), nameof(QuantumShrine.IsPlayerInDarkness))] public static bool QuantumShrine_IsPlayerInDarkness(ref bool __result, Light[] ____lamps, float ____fadeFraction, bool ____isProbeInside, NomaiGateway ____gate) { foreach (var lamp in ____lamps) @@ -351,6 +353,8 @@ namespace QSB.QuantumSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumShrine), nameof(QuantumShrine.ChangeQuantumState))] public static bool QuantumShrine_ChangeQuantumState(QuantumShrine __instance) { var shrineWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); @@ -358,6 +362,8 @@ namespace QSB.QuantumSync.Patches return isInControl; } + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumShrine), nameof(QuantumShrine.OnEntry))] public static bool QuantumShrine_OnEntry( GameObject hitObj, ref bool ____isPlayerInside, @@ -380,6 +386,8 @@ namespace QSB.QuantumSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumShrine), nameof(QuantumShrine.OnExit))] public static bool QuantumShrine_OnExit( GameObject hitObj, ref bool ____isPlayerInside, @@ -402,6 +410,8 @@ namespace QSB.QuantumSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.CheckPlayerFogProximity))] public static bool QuantumMoon_CheckPlayerFogProximity( QuantumMoon __instance, int ____stateIndex, diff --git a/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs b/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs index fafadb80..184b6194 100644 --- a/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs @@ -1,4 +1,5 @@ -using QSB.Patches; +using HarmonyLib; +using QSB.Patches; using QSB.Player; using QSB.Utility; using System.Linq; @@ -7,34 +8,33 @@ using UnityEngine; namespace QSB.QuantumSync.Patches { + [HarmonyPatch] public class QuantumVisibilityPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(ShapeVisibilityTracker_IsVisibleUsingCameraFrustum)); - Prefix(nameof(ShapeVisibilityTracker_IsVisible)); - Prefix(nameof(RendererVisibilityTracker_IsVisibleUsingCameraFrustum)); - Prefix(nameof(VisibilityObject_CheckIllumination)); - Postfix(nameof(Shape_OnEnable)); - Postfix(nameof(Shape_OnDisable)); - } - + [HarmonyPostfix] + [HarmonyPatch(typeof(Shape), nameof(Shape.OnEnable))] public static void Shape_OnEnable(Shape __instance) => __instance.RaiseEvent("OnShapeActivated", __instance); + [HarmonyPostfix] + [HarmonyPatch(typeof(Shape), nameof(Shape.OnDisable))] public static void Shape_OnDisable(Shape __instance) => __instance.RaiseEvent("OnShapeDeactivated", __instance); // ShapeVisibilityTracker patches + [HarmonyPrefix] + [HarmonyPatch(typeof(ShapeVisibilityTracker), nameof(ShapeVisibilityTracker.IsVisibleUsingCameraFrustum))] public static bool ShapeVisibilityTracker_IsVisibleUsingCameraFrustum(ShapeVisibilityTracker __instance, ref bool __result) { __result = QuantumManager.IsVisibleUsingCameraFrustum(__instance, false).Item1; return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ShapeVisibilityTracker), nameof(ShapeVisibilityTracker.IsVisible))] public static bool ShapeVisibilityTracker_IsVisible(ShapeVisibilityTracker __instance, ref bool __result) { __result = QuantumManager.IsVisible(__instance, false); @@ -43,6 +43,8 @@ namespace QSB.QuantumSync.Patches // RendererVisibilityTracker patches - probably not needed as i don't think RendererVisibilityTracker is ever used? + [HarmonyPrefix] + [HarmonyPatch(typeof(RendererVisibilityTracker), nameof(RendererVisibilityTracker.IsVisibleUsingCameraFrustum))] public static bool RendererVisibilityTracker_IsVisibleUsingCameraFrustum(RendererVisibilityTracker __instance, ref bool __result, Renderer ____renderer, bool ____checkFrustumOcclusion) { __result = QSBPlayerManager.GetPlayersWithCameras() @@ -56,6 +58,8 @@ namespace QSB.QuantumSync.Patches // VisibilityObject + [HarmonyPrefix] + [HarmonyPatch(typeof(VisibilityObject), nameof(VisibilityObject.CheckIllumination))] public static bool VisibilityObject_CheckIllumination(VisibilityObject __instance, ref bool __result, bool ____checkIllumination, Vector3 ____localIlluminationOffset, float ____illuminationRadius, Light[] ____lightSources) { if (!____checkIllumination) diff --git a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs index c6572f85..1c664104 100644 --- a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs @@ -1,4 +1,5 @@ -using OWML.Common; +using HarmonyLib; +using OWML.Common; using QSB.Events; using QSB.Patches; using QSB.Player; @@ -9,13 +10,13 @@ using UnityEngine; namespace QSB.QuantumSync.Patches { + [HarmonyPatch] public class ServerQuantumPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect; - public override void DoPatches() - => Prefix(nameof(QuantumMoon_ChangeQuantumState)); - + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumMoon), nameof(QuantumMoon.ChangeQuantumState))] public static bool QuantumMoon_ChangeQuantumState( QuantumMoon __instance, ref bool __result, diff --git a/QSB/RoastingSync/Patches/RoastingPatches.cs b/QSB/RoastingSync/Patches/RoastingPatches.cs index 2fa6da8b..0e85f3d2 100644 --- a/QSB/RoastingSync/Patches/RoastingPatches.cs +++ b/QSB/RoastingSync/Patches/RoastingPatches.cs @@ -1,28 +1,34 @@ -using QSB.Events; +using HarmonyLib; +using QSB.Events; using QSB.Patches; using UnityEngine; namespace QSB.RoastingSync.Patches { + [HarmonyPatch] internal class RoastingPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(RoastingStickController_UpdateMarshmallowInput)); - Prefix(nameof(Marshmallow_Burn)); - Prefix(nameof(Marshmallow_Shrivel)); - Prefix(nameof(Marshmallow_RemoveMallow)); - Prefix(nameof(Marshmallow_SpawnMallow)); - } + //public override void DoPatches() + //{ + // Prefix(nameof(RoastingStickController.UpdateMarshmallowInput), nameof(RoastingStickController_UpdateMarshmallowInput)); + // Prefix(nameof(Marshmallow.Burn), nameof(Marshmallow_Burn)); + // Prefix(nameof(Marshmallow.Shrivel), nameof(Marshmallow_Shrivel)); + // Prefix(nameof(Marshmallow.RemoveMallow), nameof(Marshmallow_RemoveMallow)); + // Prefix(nameof(Marshmallow.SpawnMallow), nameof(Marshmallow_SpawnMallow)); + //} + [HarmonyPrefix] + [HarmonyPatch(typeof(Marshmallow), nameof(Marshmallow.SpawnMallow))] public static bool Marshmallow_SpawnMallow() { QSBEventManager.FireEvent(EventNames.QSBMarshmallowEvent, MarshmallowEventType.Replace); return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(Marshmallow), nameof(Marshmallow.Burn))] public static bool Marshmallow_Burn( ref Marshmallow.MallowState ____mallowState, MeshRenderer ____fireRenderer, @@ -43,6 +49,8 @@ namespace QSB.RoastingSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(Marshmallow), nameof(Marshmallow.Shrivel))] public static bool Marshmallow_Shrivel( ref Marshmallow.MallowState ____mallowState, ref float ____initShrivelTime) @@ -57,6 +65,8 @@ namespace QSB.RoastingSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(Marshmallow), nameof(Marshmallow.RemoveMallow))] public static bool Marshmallow_RemoveMallow( ParticleSystem ____smokeParticles, MeshRenderer ____fireRenderer, @@ -73,6 +83,8 @@ namespace QSB.RoastingSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(RoastingStickController), nameof(RoastingStickController.UpdateMarshmallowInput))] public static bool RoastingStickController_UpdateMarshmallowInput( float ____extendFraction, Marshmallow ____marshmallow, diff --git a/QSB/SectorSync/FakeSector.cs b/QSB/SectorSync/FakeSector.cs index 61c51a90..19144eb5 100644 --- a/QSB/SectorSync/FakeSector.cs +++ b/QSB/SectorSync/FakeSector.cs @@ -4,6 +4,6 @@ { public Sector AttachedSector; - protected override void Awake() { } + public override void Awake() { } } } diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index bfbe87c4..57fbb477 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -1,30 +1,22 @@ -using OWML.Utils; +using HarmonyLib; +using OWML.Utils; using QSB.Events; using QSB.Patches; using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Reflection.Emit; using UnityEngine; namespace QSB.ShipSync.Patches { + [HarmonyPatch] internal class ShipPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(HatchController_OnPressInteract)); - Prefix(nameof(HatchController_OnEntry)); - Prefix(nameof(ShipTractorBeamSwitch_OnTriggerExit)); - Prefix(nameof(InteractZone_UpdateInteractVolume)); - Prefix(nameof(ShipElectricalComponent_OnEnterShip)); - Prefix(nameof(ShipElectricalComponent_OnExitShip)); - Prefix(nameof(ShipComponent_SetDamaged)); - Prefix(nameof(ShipHull_FixedUpdate)); - Prefix(nameof(ShipDamageController_OnImpact)); - Postfix(nameof(ShipComponent_RepairTick)); - Prefix(nameof(ShipHull_RepairTick)); - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(HatchController), nameof(HatchController.OnPressInteract))] public static bool HatchController_OnPressInteract() { if (!PlayerState.IsInsideShip()) @@ -37,6 +29,8 @@ namespace QSB.ShipSync.Patches return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(HatchController), nameof(HatchController.OnEntry))] public static bool HatchController_OnEntry(GameObject hitObj) { if (hitObj.CompareTag("PlayerDetector")) @@ -47,9 +41,11 @@ namespace QSB.ShipSync.Patches return true; } - public static bool ShipTractorBeamSwitch_OnTriggerExit(Collider hitCollider, bool ____isPlayerInShip, bool ____functional) + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipTractorBeamSwitch), nameof(ShipTractorBeamSwitch.OnTriggerExit))] + public static bool ShipTractorBeamSwitch_OnTriggerExit(ShipTractorBeamSwitch __instance, Collider hitCollider) { - if (!____isPlayerInShip && ____functional && hitCollider.CompareTag("PlayerDetector") && !ShipManager.Instance.HatchController.GetValue("_hatchObject").activeSelf) + if (!__instance._isPlayerInShip && __instance._functional && hitCollider.CompareTag("PlayerDetector") && !ShipManager.Instance.HatchController._hatchObject.activeSelf) { ShipManager.Instance.HatchController.Invoke("CloseHatch"); ShipManager.Instance.ShipTractorBeam.DeactivateTractorBeam(); @@ -59,7 +55,16 @@ namespace QSB.ShipSync.Patches return false; } - public static bool InteractZone_UpdateInteractVolume(InteractZone __instance, OWCamera ____playerCam, ref bool ____focused) + [HarmonyReversePatch] + [HarmonyPatch(typeof(SingleInteractionVolume), nameof(SingleInteractionVolume.UpdateInteractVolume))] + public static void SingleInteractionVolume_UpdateInteractVolume_Stub(object instance) + { + throw new NotImplementedException(); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(InteractZone), nameof(InteractZone.UpdateInteractVolume))] + public static bool InteractZone_UpdateInteractVolume(InteractZone __instance) { /* Angle for interaction with the ship hatch * @@ -78,64 +83,86 @@ namespace QSB.ShipSync.Patches return true; } - var angle = 2f * Vector3.Angle(____playerCam.transform.forward, __instance.transform.forward); + var angle = 2f * Vector3.Angle(__instance._playerCam.transform.forward, __instance.transform.forward); - ____focused = PlayerState.IsInsideShip() + __instance._focused = PlayerState.IsInsideShip() ? angle <= 80 : angle >= 280; - __instance.CallBase("UpdateInteractVolume"); + SingleInteractionVolume_UpdateInteractVolume_Stub(__instance as SingleInteractionVolume); return false; } - public static bool ShipElectricalComponent_OnEnterShip(ShipElectricalComponent __instance, bool ____damaged, ElectricalSystem ____electricalSystem) + [HarmonyReversePatch] + [HarmonyPatch(typeof(ShipComponent), nameof(ShipComponent.OnEnterShip))] + public static void ShipComponent_OnEnterShip_Stub(object instance) { - __instance.CallBase("OnEnterShip"); + throw new NotImplementedException(); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipElectricalComponent), nameof(ShipElectricalComponent.OnEnterShip))] + public static bool ShipElectricalComponent_OnEnterShip(ShipElectricalComponent __instance) + { + ShipComponent_OnEnterShip_Stub(__instance as ShipComponent); return false; } - public static bool ShipElectricalComponent_OnExitShip(ShipElectricalComponent __instance, bool ____damaged, ElectricalSystem ____electricalSystem) + [HarmonyReversePatch] + [HarmonyPatch(typeof(ShipComponent), nameof(ShipComponent.OnExitShip))] + public static void ShipComponent_OnExitShip_Stub(object instance) { - __instance.CallBase("OnExitShip"); + throw new NotImplementedException(); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipElectricalComponent), nameof(ShipElectricalComponent.OnExitShip))] + public static bool ShipElectricalComponent_OnExitShip(ShipElectricalComponent __instance) + { + ShipComponent_OnExitShip_Stub(__instance as ShipComponent); return false; } - public static bool ShipComponent_SetDamaged(ShipComponent __instance, bool damaged, ref bool ____damaged, ref float ____repairFraction, DamageEffect ____damageEffect) + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipComponent), nameof(ShipComponent.SetDamaged))] + public static bool ShipComponent_SetDamaged(ShipComponent __instance, bool damaged) { - if (____damaged == damaged) + if (__instance._damaged == damaged) { return false; } if (damaged) { - ____damaged = true; - ____repairFraction = 0f; + __instance._damaged = true; + __instance._repairFraction = 0f; __instance.GetType().GetAnyMethod("OnComponentDamaged").Invoke(__instance, null); __instance.RaiseEvent("OnDamaged", __instance); QSBEventManager.FireEvent(EventNames.QSBComponentDamaged, __instance); } else { - ____damaged = false; - ____repairFraction = 1f; + __instance._damaged = false; + __instance._repairFraction = 1f; __instance.GetType().GetAnyMethod("OnComponentRepaired").Invoke(__instance, null); __instance.RaiseEvent("OnRepaired", __instance); QSBEventManager.FireEvent(EventNames.QSBComponentRepaired, __instance); } __instance.GetType().GetAnyMethod("UpdateColliderState").Invoke(__instance, null); - if (____damageEffect) + if (__instance._damageEffect) { - ____damageEffect.SetEffectBlend(1f - ____repairFraction); + __instance._damageEffect.SetEffectBlend(1f - __instance._repairFraction); } return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipHull), nameof(ShipHull.FixedUpdate))] public static bool ShipHull_FixedUpdate(ShipHull __instance, ref ImpactData ____dominantImpact, ref float ____integrity, ref bool ____damaged, DamageEffect ____damageEffect, ShipComponent[] ____components) { if (____dominantImpact != null) @@ -186,15 +213,21 @@ namespace QSB.ShipSync.Patches return false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipDamageController), nameof(ShipDamageController.OnImpact))] public static bool ShipDamageController_OnImpact() => ShipManager.Instance.HasAuthority; + [HarmonyPostfix] + [HarmonyPatch(typeof(ShipComponent), nameof(ShipComponent.RepairTick))] public static void ShipComponent_RepairTick(ShipComponent __instance, float ____repairFraction) { QSBEventManager.FireEvent(EventNames.QSBComponentRepairTick, __instance, ____repairFraction); return; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipHull), nameof(ShipHull.RepairTick))] public static bool ShipHull_RepairTick(ShipHull __instance, ref float ____integrity, ref bool ____damaged, DamageEffect ____damageEffect, float ____repairTime) { if (!____damaged) diff --git a/QSB/StatueSync/Patches/StatuePatches.cs b/QSB/StatueSync/Patches/StatuePatches.cs index bce3385a..821ae821 100644 --- a/QSB/StatueSync/Patches/StatuePatches.cs +++ b/QSB/StatueSync/Patches/StatuePatches.cs @@ -1,17 +1,18 @@ -using QSB.Events; +using HarmonyLib; +using QSB.Events; using QSB.Patches; using QSB.Player; using UnityEngine; namespace QSB.StatueSync.Patches { + [HarmonyPatch] internal class StatuePatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - => Prefix(nameof(MemoryUplinkTrigger_Update)); - + [HarmonyPrefix] + [HarmonyPatch(typeof(MemoryUplinkTrigger), nameof(MemoryUplinkTrigger.Update))] public static bool MemoryUplinkTrigger_Update(bool ____waitForPlayerGrounded) { if (StatueManager.Instance.HasStartedStatueLocally) diff --git a/QSB/TimeSync/Patches/TimePatches.cs b/QSB/TimeSync/Patches/TimePatches.cs index a0d5f48a..7b43dd11 100644 --- a/QSB/TimeSync/Patches/TimePatches.cs +++ b/QSB/TimeSync/Patches/TimePatches.cs @@ -1,19 +1,26 @@ -using QSB.Patches; +using HarmonyLib; +using QSB.Patches; namespace QSB.TimeSync.Patches { + [HarmonyPatch] internal class TimePatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(PlayerCameraEffectController_OnStartOfTimeLoop)); - Empty("OWTime_Pause"); - Empty("SubmitActionSkipToNextLoop_AdvanceToNextLoop"); // TODO : remove this, remove meditation button instead - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerCameraEffectController), nameof(PlayerCameraEffectController.OnStartOfTimeLoop))] public static bool PlayerCameraEffectController_OnStartOfTimeLoop() => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(OWTime), nameof(OWTime.Pause))] + public static bool StopPausing() + => false; + + [HarmonyPrefix] + [HarmonyPatch(typeof(SubmitActionSkipToNextLoop), nameof(SubmitActionSkipToNextLoop.AdvanceToNewTimeLoop))] + public static bool StopMeditation() + => false; } } diff --git a/QSB/Tools/ProbeLauncherTool/Patches/LauncherPatches.cs b/QSB/Tools/ProbeLauncherTool/Patches/LauncherPatches.cs index 619931a0..f1427d25 100644 --- a/QSB/Tools/ProbeLauncherTool/Patches/LauncherPatches.cs +++ b/QSB/Tools/ProbeLauncherTool/Patches/LauncherPatches.cs @@ -1,4 +1,5 @@ -using QSB.Events; +using HarmonyLib; +using QSB.Events; using QSB.Patches; using QSB.Player; using QSB.Tools.ProbeLauncherTool.WorldObjects; @@ -7,17 +8,13 @@ using UnityEngine; namespace QSB.Tools.ProbeLauncherTool.Patches { + [HarmonyPatch] internal class LauncherPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(ProbeLauncher_RetrieveProbe)); - Postfix(nameof(ProbeLauncherEffects_PlayRetrievalClip)); - Postfix(nameof(ProbeLauncherEffects_PlayLaunchClip)); - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(ProbeLauncher), nameof(ProbeLauncher.RetrieveProbe))] public static bool ProbeLauncher_RetrieveProbe( ProbeLauncher __instance, bool playEffects, @@ -74,8 +71,12 @@ namespace QSB.Tools.ProbeLauncherTool.Patches // TODO : ehhhh idk about this. maybe copy each sound source so we have a 2d version (for local) and a 3d version (for remote)? // this would probably be a whole qsb version on it's own + [HarmonyPostfix] + [HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayRetrievalClip))] public static void ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource) => ____owAudioSource.GetAudioSource().spatialBlend = 1f; + [HarmonyPostfix] + [HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayLaunchClip))] public static void ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource) => ____owAudioSource.GetAudioSource().spatialBlend = 1f; } } diff --git a/QSB/TranslationSync/Patches/SpiralPatches.cs b/QSB/TranslationSync/Patches/SpiralPatches.cs index b608e0e4..788366b0 100644 --- a/QSB/TranslationSync/Patches/SpiralPatches.cs +++ b/QSB/TranslationSync/Patches/SpiralPatches.cs @@ -1,21 +1,18 @@ -using QSB.Events; +using HarmonyLib; +using QSB.Events; using QSB.Patches; using QSB.TranslationSync.WorldObjects; using QSB.WorldSync; namespace QSB.TranslationSync.Patches { + [HarmonyPatch] internal class SpiralPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() - { - Prefix(nameof(NomaiWallText_SetAsTranslated)); - Prefix(nameof(NomaiComputer_SetAsTranslated)); - Prefix(nameof(NomaiVesselComputer_SetAsTranslated)); - } - + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiWallText), nameof(NomaiWallText.SetAsTranslated))] public static bool NomaiWallText_SetAsTranslated(NomaiWallText __instance, int id) { if (__instance.IsTranslated(id)) @@ -31,6 +28,8 @@ namespace QSB.TranslationSync.Patches return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiComputer), nameof(NomaiWallText.SetAsTranslated))] public static bool NomaiComputer_SetAsTranslated(NomaiComputer __instance, int id) { if (__instance.IsTranslated(id)) @@ -46,6 +45,8 @@ namespace QSB.TranslationSync.Patches return true; } + [HarmonyPrefix] + [HarmonyPatch(typeof(NomaiVesselComputer), nameof(NomaiWallText.SetAsTranslated))] public static bool NomaiVesselComputer_SetAsTranslated(NomaiVesselComputer __instance, int id) { if (__instance.IsTranslated(id)) diff --git a/QSB/Utility/Extensions.cs b/QSB/Utility/Extensions.cs index dbba8bd7..b787cc36 100644 --- a/QSB/Utility/Extensions.cs +++ b/QSB/Utility/Extensions.cs @@ -129,27 +129,6 @@ namespace QSB.Utility multiDelegate.GetInvocationList().ToList().ForEach(dl => dl.DynamicInvoke(args)); } - public static void CallBase(this ThisType obj, string methodName) - where ThisType : BaseType - { - var method = typeof(BaseType).GetAnyMethod(methodName); - if (method == null) - { - DebugLog.ToConsole($"Error - Couldn't find method {methodName} in {typeof(BaseType).FullName}!", MessageType.Error); - return; - } - - var functionPointer = method.MethodHandle.GetFunctionPointer(); - if (functionPointer == null) - { - DebugLog.ToConsole($"Error - Function pointer for {methodName} in {typeof(BaseType).FullName} is null!", MessageType.Error); - return; - } - - var methodAction = (Action)Activator.CreateInstance(typeof(Action), obj, functionPointer); - methodAction(); - } - // OW public static Vector3 GetRelativeAngularVelocity(this OWRigidbody baseBody, OWRigidbody relativeBody) diff --git a/QSBTests/PatchTests.cs b/QSBTests/PatchTests.cs index 29d3ebdd..bdbe1b48 100644 --- a/QSBTests/PatchTests.cs +++ b/QSBTests/PatchTests.cs @@ -10,32 +10,32 @@ namespace QSBTests [TestClass] public class PatchTests { - [TestMethod] - public void CheckUnreferencedPatches() - { - var qsbAssembly = Assembly.Load("QSB"); - var allPatchTypes = qsbAssembly - .GetTypes() - .Where(x => typeof(QSBPatch).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); + //[TestMethod] + //public void CheckUnreferencedPatches() + //{ + // var qsbAssembly = Assembly.Load("QSB"); + // var allPatchTypes = qsbAssembly + // .GetTypes() + // .Where(x => typeof(QSBPatch).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); - QSBPatchManager.Init(); - var patchInstances = (List)typeof(QSBPatchManager) - .GetField("_patchList", BindingFlags.NonPublic | BindingFlags.Static) - .GetValue(typeof(QSBPatchManager)); + // QSBPatchManager.Init(); + // var patchInstances = (List)typeof(QSBPatchManager) + // .GetField("_patchList", BindingFlags.NonPublic | BindingFlags.Static) + // .GetValue(typeof(QSBPatchManager)); - var failedTypes = new List(); - foreach (var type in allPatchTypes) - { - if (!patchInstances.Any(x => x.GetType() == type)) - { - failedTypes.Add(type); - } - } + // var failedTypes = new List(); + // foreach (var type in allPatchTypes) + // { + // if (!patchInstances.Any(x => x.GetType() == type)) + // { + // failedTypes.Add(type); + // } + // } - if (failedTypes.Count > 0) - { - Assert.Fail(string.Join(", ", failedTypes.Select(x => x.Name))); - } - } + // if (failedTypes.Count > 0) + // { + // Assert.Fail(string.Join(", ", failedTypes.Select(x => x.Name))); + // } + //} } }