From 5c7abe164a16632b290b79a032e6da33091cb307 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 18 Jun 2021 21:54:32 +0100 Subject: [PATCH] rework patches --- QSB.editorconfig | 217 ++++++++++++++++++ .../NPC/Patches/CharacterAnimationPatches.cs | 31 +-- .../Player/Patches/PlayerAnimationPatches.cs | 4 +- QSB/CampfireSync/Patches/CampfirePatches.cs | 3 +- .../Patches/ConversationPatches.cs | 24 +- QSB/DeathSync/Patches/DeathPatches.cs | 42 ++-- QSB/ElevatorSync/Patches/ElevatorPatches.cs | 7 +- QSB/FrequencySync/Patches/FrequencyPatches.cs | 14 +- QSB/GeyserSync/Patches/GeyserPatches.cs | 3 +- QSB/Inputs/Patches/InputPatches.cs | 5 +- QSB/ItemSync/Patches/ItemPatches.cs | 19 +- QSB/LogSync/Patches/LogPatches.cs | 6 +- QSB/OrbSync/Patches/OrbPatches.cs | 14 +- QSB/Patches/QSBPatch.cs | 95 +++++++- QSB/Player/Patches/PlayerPatches.cs | 10 +- QSB/PoolSync/Patches/PoolPatches.cs | 45 ++-- QSB/QSBCore.cs | 27 ++- .../Patches/ClientQuantumPatches.cs | 15 +- QSB/QuantumSync/Patches/QuantumPatches.cs | 61 ++--- .../Patches/QuantumVisibilityPatches.cs | 30 +-- .../Patches/ServerQuantumPatches.cs | 7 +- QSB/RoastingSync/Patches/RoastingPatches.cs | 15 +- QSB/ShipSync/Patches/ShipPatches.cs | 16 +- QSB/StatueSync/Patches/StatuePatches.cs | 7 +- QSB/TimeSync/Patches/TimePatches.cs | 5 +- QSB/TranslationSync/Patches/SpiralPatches.cs | 19 +- 26 files changed, 477 insertions(+), 264 deletions(-) create mode 100644 QSB.editorconfig diff --git a/QSB.editorconfig b/QSB.editorconfig new file mode 100644 index 00000000..cc6b1d02 --- /dev/null +++ b/QSB.editorconfig @@ -0,0 +1,217 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories +root = true + +# C# files +[*.cs] + +#### Core EditorConfig Options #### + +# Indentation and spacing +indent_size = 4 +indent_style = tab +tab_width = 4 + +# New line preferences +end_of_line = crlf +insert_final_newline = false + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = false +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members + +# Expression-level preferences +dotnet_style_coalesce_expression = true +dotnet_style_collection_initializer = true +dotnet_style_explicit_tuple_names = true +dotnet_style_namespace_match_folder = true +dotnet_style_null_propagation = true +dotnet_style_object_initializer = true +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_compound_assignment = true +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true +dotnet_style_prefer_inferred_tuple_names = true +dotnet_style_prefer_is_null_check_over_reference_equality_method = true +dotnet_style_prefer_simplified_boolean_expressions = true +dotnet_style_prefer_simplified_interpolation = true + +# Field preferences +dotnet_style_readonly_field = true + +# Parameter preferences +dotnet_code_quality_unused_parameters = all + +# Suppression preferences +dotnet_remove_unnecessary_suppression_exclusions = none + +# New line preferences +dotnet_style_allow_multiple_blank_lines_experimental = false:warning +dotnet_style_allow_statement_immediately_after_block_experimental = false:warning + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = true:suggestion +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true +csharp_style_expression_bodied_constructors = false +csharp_style_expression_bodied_indexers = true +csharp_style_expression_bodied_lambdas = when_on_single_line:suggestion +csharp_style_expression_bodied_local_functions = when_on_single_line:suggestion +csharp_style_expression_bodied_methods = when_on_single_line:suggestion +csharp_style_expression_bodied_operators = false +csharp_style_expression_bodied_properties = true + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true +csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_prefer_not_pattern = true +csharp_style_prefer_pattern_matching = true:suggestion +csharp_style_prefer_switch_expression = true + +# Null-checking preferences +csharp_style_conditional_delegate_call = true + +# Modifier preferences +csharp_prefer_static_local_function = true +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async + +# Code-block preferences +csharp_prefer_braces = true:suggestion +csharp_prefer_simple_using_statement = false + +# Expression-level preferences +csharp_prefer_simple_default_expression = true +csharp_style_deconstructed_variable_declaration = true +csharp_style_implicit_object_creation_when_type_is_apparent = true +csharp_style_inlined_variable_declaration = true +csharp_style_pattern_local_over_anonymous_function = true +csharp_style_prefer_index_operator = true +csharp_style_prefer_range_operator = true +csharp_style_throw_expression = true +csharp_style_unused_value_assignment_preference = discard_variable +csharp_style_unused_value_expression_statement_preference = discard_variable + +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace + +# New line preferences +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:warning +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:warning +csharp_style_allow_embedded_statements_on_same_line_experimental = false:warning + +#### C# Formatting Rules #### + +# New line preferences +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case diff --git a/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs b/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs index 2e4c0acc..4f293159 100644 --- a/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs +++ b/QSB/Animation/NPC/Patches/CharacterAnimationPatches.cs @@ -18,27 +18,16 @@ namespace QSB.Animation.NPC.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("OnAnimatorIK", typeof(CharacterAnimationPatches), nameof(AnimController_OnAnimatorIK)); - QSBCore.HarmonyHelper.AddPrefix("OnZoneEntry", typeof(CharacterAnimationPatches), nameof(AnimController_OnZoneEntry)); - QSBCore.HarmonyHelper.AddPrefix("OnZoneExit", typeof(CharacterAnimationPatches), nameof(AnimController_OnZoneExit)); - QSBCore.HarmonyHelper.AddPrefix("OnStartConversation", typeof(CharacterAnimationPatches), nameof(FacePlayerWhenTalking_OnStartConversation)); - QSBCore.HarmonyHelper.AddPrefix("StartConversation", typeof(CharacterAnimationPatches), nameof(CharacterDialogueTree_StartConversation)); - QSBCore.HarmonyHelper.AddPrefix("EndConversation", typeof(CharacterAnimationPatches), nameof(CharacterDialogueTree_EndConversation)); - QSBCore.HarmonyHelper.AddPrefix("Update", typeof(CharacterAnimationPatches), nameof(KidRockController_Update)); + 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 override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("OnAnimatorIK"); - QSBCore.HarmonyHelper.Unpatch("OnZoneEntry"); - QSBCore.HarmonyHelper.Unpatch("OnZoneExit"); - QSBCore.HarmonyHelper.Unpatch("OnStartConversation"); - QSBCore.HarmonyHelper.Unpatch("StartConversation"); - QSBCore.HarmonyHelper.Unpatch("EndConversation"); - QSBCore.HarmonyHelper.Unpatch("Update"); - } - - public static bool AnimController_OnAnimatorIK( + public static bool CharacterAnimController_OnAnimatorIK( CharacterAnimController __instance, float ___headTrackingWeight, bool ___lookOnlyWhenTalking, @@ -114,14 +103,14 @@ namespace QSB.Animation.NPC.Patches } - public static bool AnimController_OnZoneExit(CharacterAnimController __instance) + public static bool CharacterAnimController_OnZoneExit(CharacterAnimController __instance) { var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); QSBEventManager.FireEvent(EventNames.QSBExitHeadZone, qsbObj.ObjectId); return false; } - public static bool AnimController_OnZoneEntry(CharacterAnimController __instance) + public static bool CharacterAnimController_OnZoneEntry(CharacterAnimController __instance) { var qsbObj = QSBWorldSync.GetWorldFromUnity(__instance); QSBEventManager.FireEvent(EventNames.QSBEnterHeadZone, qsbObj.ObjectId); diff --git a/QSB/Animation/Player/Patches/PlayerAnimationPatches.cs b/QSB/Animation/Player/Patches/PlayerAnimationPatches.cs index d35b5b6c..5178d6c4 100644 --- a/QSB/Animation/Player/Patches/PlayerAnimationPatches.cs +++ b/QSB/Animation/Player/Patches/PlayerAnimationPatches.cs @@ -10,8 +10,8 @@ namespace QSB.Animation.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() => QSBCore.HarmonyHelper.AddPrefix("LateUpdate", typeof(PlayerAnimationPatches), nameof(PlayerAnimController_LateUpdate)); - public override void DoUnpatches() => QSBCore.HarmonyHelper.Unpatch("LateUpdate"); + public override void DoPatches() + => Prefix(nameof(PlayerAnimController_LateUpdate)); public static bool PlayerAnimController_LateUpdate( PlayerAnimController __instance, diff --git a/QSB/CampfireSync/Patches/CampfirePatches.cs b/QSB/CampfireSync/Patches/CampfirePatches.cs index dad60ff0..bbe11459 100644 --- a/QSB/CampfireSync/Patches/CampfirePatches.cs +++ b/QSB/CampfireSync/Patches/CampfirePatches.cs @@ -9,8 +9,7 @@ namespace QSB.CampfireSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public override void DoPatches() => QSBCore.HarmonyHelper.AddPrefix("OnPressInteract", typeof(CampfirePatches), nameof(Campfire_OnPressInteract)); - public override void DoUnpatches() => QSBCore.HarmonyHelper.Unpatch("OnPressInteract"); + public override void DoPatches() => Prefix(nameof(Campfire_OnPressInteract)); public static bool Campfire_OnPressInteract(Campfire __instance, Campfire.State ____state) { diff --git a/QSB/ConversationSync/Patches/ConversationPatches.cs b/QSB/ConversationSync/Patches/ConversationPatches.cs index 47ecee4b..10349b5e 100644 --- a/QSB/ConversationSync/Patches/ConversationPatches.cs +++ b/QSB/ConversationSync/Patches/ConversationPatches.cs @@ -13,21 +13,13 @@ namespace QSB.ConversationSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPostfix("GetNextPage", typeof(ConversationPatches), nameof(Node_GetNextPage)); - QSBCore.HarmonyHelper.AddPrefix("InputDialogueOption", typeof(ConversationPatches), nameof(Tree_InputDialogueOption)); - QSBCore.HarmonyHelper.AddPrefix("StartConversation", typeof(ConversationPatches), nameof(Tree_StartConversation)); - QSBCore.HarmonyHelper.AddPrefix("EndConversation", typeof(ConversationPatches), nameof(Tree_EndConversation)); + Postfix(nameof(DialogueNode_GetNextPage)); + Prefix(nameof(CharacterDialogueTree_InputDialogueOption)); + Prefix(nameof(CharacterDialogueTree_StartConversation)); + Prefix(nameof(CharacterDialogueTree_EndConversation)); } - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("GetNextPage"); - QSBCore.HarmonyHelper.Unpatch("InputDialogueOption"); - QSBCore.HarmonyHelper.Unpatch("StartConversation"); - QSBCore.HarmonyHelper.Unpatch("EndConversation"); - } - - public static void Tree_StartConversation(CharacterDialogueTree __instance) + public static void CharacterDialogueTree_StartConversation(CharacterDialogueTree __instance) { var index = QSBWorldSync.OldDialogueTrees.FindIndex(x => x == __instance); if (index == -1) @@ -38,7 +30,7 @@ namespace QSB.ConversationSync.Patches ConversationManager.Instance.SendConvState(index, true); } - public static bool Tree_EndConversation(CharacterDialogueTree __instance) + public static bool CharacterDialogueTree_EndConversation(CharacterDialogueTree __instance) { if (!__instance.enabled) { @@ -56,7 +48,7 @@ namespace QSB.ConversationSync.Patches return true; } - public static bool Tree_InputDialogueOption(int optionIndex, DialogueBoxVer2 ____currentDialogueBox) + public static bool CharacterDialogueTree_InputDialogueOption(int optionIndex, DialogueBoxVer2 ____currentDialogueBox) { if (optionIndex < 0) { @@ -70,7 +62,7 @@ namespace QSB.ConversationSync.Patches return true; } - public static void Node_GetNextPage(string ____name, List ____listPagesToDisplay, int ____currentPage) + public static void DialogueNode_GetNextPage(string ____name, List ____listPagesToDisplay, int ____currentPage) { var key = ____name + ____listPagesToDisplay[____currentPage]; // Sending key so translation can be done on client side - should make different language-d clients compatible diff --git a/QSB/DeathSync/Patches/DeathPatches.cs b/QSB/DeathSync/Patches/DeathPatches.cs index e7ff15fa..4b753c03 100644 --- a/QSB/DeathSync/Patches/DeathPatches.cs +++ b/QSB/DeathSync/Patches/DeathPatches.cs @@ -16,27 +16,27 @@ namespace QSB.DeathSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("KillPlayer", typeof(DeathPatches), nameof(PreFinishDeathSequence)); - QSBCore.HarmonyHelper.AddPostfix("KillPlayer", typeof(DeathPatches), nameof(BroadcastDeath)); - QSBCore.HarmonyHelper.Transpile("Detach", typeof(DeathPatches), nameof(ReturnNull)); - QSBCore.HarmonyHelper.Transpile("Detach", typeof(DeathPatches), nameof(ReturnNull)); - QSBCore.HarmonyHelper.EmptyMethod("OnPressInteract"); - QSBCore.HarmonyHelper.AddPostfix("Awake", typeof(DeathPatches), nameof(DamageController_Exploded)); - QSBCore.HarmonyHelper.AddPrefix("VanishShip", typeof(DeathPatches), nameof(DestructionVolume_VanishShip)); - QSBCore.HarmonyHelper.AddPrefix("FixedUpdate", typeof(DeathPatches), nameof(HighSpeedImpactSensor_FixedUpdate)); - QSBCore.HarmonyHelper.AddPrefix("OnImpact", typeof(DeathPatches), nameof(PlayerResources_OnImpact)); + 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)); } - public override void DoUnpatches() + public static bool ShipDetachableLeg_Detach(ref OWRigidbody __result) { - QSBCore.HarmonyHelper.Unpatch("KillPlayer"); - QSBCore.HarmonyHelper.Unpatch("Detach"); - QSBCore.HarmonyHelper.Unpatch("Detach"); - QSBCore.HarmonyHelper.Unpatch("OnPressInteract"); - QSBCore.HarmonyHelper.Unpatch("Awake"); - QSBCore.HarmonyHelper.Unpatch("VanishShip"); - QSBCore.HarmonyHelper.Unpatch("FixedUpdate"); - QSBCore.HarmonyHelper.Unpatch("OnImpact"); + __result = null; + return false; + } + + public static bool ShipDetachableModule_Detach(ref OWRigidbody __result) + { + __result = null; + return false; } public static bool PlayerResources_OnImpact(ImpactData impact, PlayerResources __instance, float ____currentHealth) @@ -181,7 +181,7 @@ namespace QSB.DeathSync.Patches return false; } - public static bool PreFinishDeathSequence(DeathType deathType) + public static bool DeathManager_KillPlayer_Prefix(DeathType deathType) { if (RespawnOnDeath.Instance == null) { @@ -204,10 +204,10 @@ namespace QSB.DeathSync.Patches return false; } - public static void BroadcastDeath(DeathType deathType) + public static void DeathManager_KillPlayer_Postfix(DeathType deathType) => QSBEventManager.FireEvent(EventNames.QSBPlayerDeath, deathType); - public static void DamageController_Exploded(ref bool ____exploded) + public static void ShipDamageController_Awake(ref bool ____exploded) => ____exploded = true; public static IEnumerable ReturnNull(IEnumerable instructions) diff --git a/QSB/ElevatorSync/Patches/ElevatorPatches.cs b/QSB/ElevatorSync/Patches/ElevatorPatches.cs index bb204e3b..8ce5a270 100644 --- a/QSB/ElevatorSync/Patches/ElevatorPatches.cs +++ b/QSB/ElevatorSync/Patches/ElevatorPatches.cs @@ -10,15 +10,14 @@ namespace QSB.ElevatorSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public static void StartLift(Elevator __instance) + 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() => QSBCore.HarmonyHelper.AddPostfix("StartLift", typeof(ElevatorPatches), nameof(StartLift)); - - public override void DoUnpatches() => QSBCore.HarmonyHelper.Unpatch("StartLift"); + 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 b3d0c612..3ad8eb48 100644 --- a/QSB/FrequencySync/Patches/FrequencyPatches.cs +++ b/QSB/FrequencySync/Patches/FrequencyPatches.cs @@ -9,20 +9,14 @@ namespace QSB.FrequencySync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPostfix("IdentifyFrequency", typeof(FrequencyPatches), nameof(IdentifyFrequency)); - QSBCore.HarmonyHelper.AddPostfix("IdentifySignal", typeof(FrequencyPatches), nameof(IdentifySignal)); + Postfix(nameof(AudioSignal_IdentifyFrequency)); + Postfix(nameof(AudioSignal_IdentifySignal)); } - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("IdentifyFrequency"); - QSBCore.HarmonyHelper.Unpatch("IdentifySignal"); - } - - public static void IdentifyFrequency(SignalFrequency ____frequency) + public static void AudioSignal_IdentifyFrequency(SignalFrequency ____frequency) => QSBEventManager.FireEvent(EventNames.QSBIdentifyFrequency, ____frequency); - public static void IdentifySignal(SignalName ____name) + public static void AudioSignal_IdentifySignal(SignalName ____name) => QSBEventManager.FireEvent(EventNames.QSBIdentifySignal, ____name); } } diff --git a/QSB/GeyserSync/Patches/GeyserPatches.cs b/QSB/GeyserSync/Patches/GeyserPatches.cs index 804b5e91..072eb8c5 100644 --- a/QSB/GeyserSync/Patches/GeyserPatches.cs +++ b/QSB/GeyserSync/Patches/GeyserPatches.cs @@ -6,7 +6,6 @@ namespace QSB.GeyserSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect; - public override void DoPatches() => QSBCore.HarmonyHelper.EmptyMethod("Update"); - public override void DoUnpatches() => QSBCore.HarmonyHelper.Unpatch("Update"); + public override void DoPatches() => Empty("GeyserController_Update"); } } diff --git a/QSB/Inputs/Patches/InputPatches.cs b/QSB/Inputs/Patches/InputPatches.cs index c44dfb2e..b9398aac 100644 --- a/QSB/Inputs/Patches/InputPatches.cs +++ b/QSB/Inputs/Patches/InputPatches.cs @@ -7,10 +7,7 @@ namespace QSB.Inputs.Patches public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; public override void DoPatches() - => QSBCore.HarmonyHelper.AddPrefix("Update", typeof(InputPatches), nameof(OWInput_Update)); - - public override void DoUnpatches() - => QSBCore.HarmonyHelper.Unpatch("Update"); + => Prefix(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 8a06c754..fece3228 100644 --- a/QSB/ItemSync/Patches/ItemPatches.cs +++ b/QSB/ItemSync/Patches/ItemPatches.cs @@ -13,20 +13,11 @@ namespace QSB.ItemSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("MoveItemToCarrySocket", typeof(ItemPatches), nameof(ItemTool_MoveItemToCarrySocket)); - QSBCore.HarmonyHelper.AddPrefix("SocketItem", typeof(ItemPatches), nameof(ItemTool_SocketItem)); - QSBCore.HarmonyHelper.AddPrefix("StartUnsocketItem", typeof(ItemPatches), nameof(ItemTool_StartUnsocketItem)); - QSBCore.HarmonyHelper.AddPrefix("CompleteUnsocketItem", typeof(ItemPatches), nameof(ItemTool_CompleteUnsocketItem)); - QSBCore.HarmonyHelper.AddPrefix("DropItem", typeof(ItemPatches), nameof(ItemTool_DropItem)); - } - - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("MoveItemToCarrySocket"); - QSBCore.HarmonyHelper.Unpatch("SocketItem"); - QSBCore.HarmonyHelper.Unpatch("StartUnsocketItem"); - QSBCore.HarmonyHelper.Unpatch("CompleteUnsocketItem"); - QSBCore.HarmonyHelper.Unpatch("DropItem"); + Prefix(nameof(ItemTool_MoveItemToCarrySocket)); + Prefix(nameof(ItemTool_SocketItem)); + Prefix(nameof(ItemTool_StartUnsocketItem)); + Prefix(nameof(ItemTool_CompleteUnsocketItem)); + Prefix(nameof(ItemTool_DropItem)); } public static bool ItemTool_MoveItemToCarrySocket(OWItem item) diff --git a/QSB/LogSync/Patches/LogPatches.cs b/QSB/LogSync/Patches/LogPatches.cs index d19e702e..5661af83 100644 --- a/QSB/LogSync/Patches/LogPatches.cs +++ b/QSB/LogSync/Patches/LogPatches.cs @@ -7,7 +7,7 @@ namespace QSB.LogSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public static void RevealFact(string id, bool saveGame, bool showNotification, bool __result) + public static void ShipLogManager_RevealFact(string id, bool saveGame, bool showNotification, bool __result) { if (!__result) { @@ -16,8 +16,6 @@ namespace QSB.LogSync.Patches QSBEventManager.FireEvent(EventNames.QSBRevealFact, id, saveGame, showNotification); } - public override void DoPatches() => QSBCore.HarmonyHelper.AddPostfix("RevealFact", typeof(LogPatches), nameof(RevealFact)); - - public override void DoUnpatches() => QSBCore.HarmonyHelper.Unpatch("RevealFact"); + 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 fd7d546c..04765147 100644 --- a/QSB/OrbSync/Patches/OrbPatches.cs +++ b/QSB/OrbSync/Patches/OrbPatches.cs @@ -9,7 +9,7 @@ namespace QSB.OrbSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; - public static void StartDragCallEvent(bool __result, NomaiInterfaceOrb __instance) + public static void NomaiInterfaceOrb_StartDragFromPosition(bool __result, NomaiInterfaceOrb __instance) { if (__result) { @@ -17,7 +17,7 @@ namespace QSB.OrbSync.Patches } } - public static bool CheckOrbCollision(ref bool __result, NomaiInterfaceSlot __instance, NomaiInterfaceOrb orb, + public static bool NomaiInterfaceSlot_CheckOrbCollision(ref bool __result, NomaiInterfaceSlot __instance, NomaiInterfaceOrb orb, bool ____ignoreDraggedOrbs, float ____radius, float ____exitRadius, ref NomaiInterfaceOrb ____occupyingOrb) { if (____ignoreDraggedOrbs && orb.IsBeingDragged()) @@ -57,14 +57,8 @@ namespace QSB.OrbSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPostfix("StartDragFromPosition", typeof(OrbPatches), nameof(StartDragCallEvent)); - QSBCore.HarmonyHelper.AddPrefix("CheckOrbCollision", typeof(OrbPatches), nameof(CheckOrbCollision)); - } - - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("StartDragFromPosition"); - QSBCore.HarmonyHelper.Unpatch("CheckOrbCollision"); + 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 bd9a93e0..4f0108dc 100644 --- a/QSB/Patches/QSBPatch.cs +++ b/QSB/Patches/QSBPatch.cs @@ -1,9 +1,100 @@ -namespace QSB.Patches +using Harmony; +using OWML.Common; +using OWML.Utils; +using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace QSB.Patches { public abstract class QSBPatch { public abstract QSBPatchTypes Type { get; } public abstract void DoPatches(); - public abstract void DoUnpatches(); + + public void DoUnpatches() + { + var instance = QSBCore.Helper.HarmonyHelper.GetValue("_harmony"); + foreach (var item in _patchedMethods) + { + DebugLog.DebugWrite($"[Unpatch] {item.DeclaringType}.{item.Name}", MessageType.Info); + instance.Unpatch(item, HarmonyPatchType.All); + } + _patchedMethods.Clear(); + } + + private List _patchedMethods = new List(); + + public void Empty(string patchName) + { + DebugLog.DebugWrite($"[Empty] {patchName}", MessageType.Info); + var method = GetMethodInfo(patchName); + QSBCore.Helper.HarmonyHelper.EmptyMethod(method); + } + + public void Prefix(string patchName) + => DoPrefixPostfix(true, patchName); + + public void Postfix(string patchName) + => DoPrefixPostfix(false, patchName); + + private void DoPrefixPostfix(bool isPrefix, string patchName) + { + var method = GetMethodInfo(patchName); + + 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) + { + var splitName = patchName.Split('_'); + var typeName = splitName[0]; + var methodName = splitName[1]; + + var type = GetFirstTypeByName(typeName); + if (type == null) + { + DebugLog.DebugWrite($"Error - Couldn't find type for patch name {patchName}!", MessageType.Error); + return null; + } + + var method = type.GetAnyMethod(methodName); + if (method == null) + { + DebugLog.DebugWrite($"Error - Couldn't find method for patch name {patchName}!", MessageType.Error); + return null; + } + + return method; + } + + private Type GetFirstTypeByName(string typeName) + { + var a = typeof(OWRigidbody).Assembly; + var assemblyTypes = a.GetTypes(); + for (int j = 0; j < assemblyTypes.Length; j++) + { + if (assemblyTypes[j].Name == typeName) + { + return assemblyTypes[j]; + } + } + return null; + } } } \ No newline at end of file diff --git a/QSB/Player/Patches/PlayerPatches.cs b/QSB/Player/Patches/PlayerPatches.cs index 5eeab2a7..581aef3f 100644 --- a/QSB/Player/Patches/PlayerPatches.cs +++ b/QSB/Player/Patches/PlayerPatches.cs @@ -8,14 +8,8 @@ namespace QSB.Player.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("CrushPlayer", typeof(PlayerPatches), nameof(PlayerCrushedController_CrushPlayer)); - QSBCore.HarmonyHelper.AddPrefix("OnExitToMainMenu", typeof(PlayerPatches), nameof(PauseMenuManager_OnExitToMainMenu)); - } - - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("CrushPlayer"); - QSBCore.HarmonyHelper.Unpatch("OnExitToMainMenu"); + Prefix(nameof(PlayerCrushedController_CrushPlayer)); + Prefix(nameof(PauseMenuManager_OnExitToMainMenu)); } public static bool PlayerCrushedController_CrushPlayer() diff --git a/QSB/PoolSync/Patches/PoolPatches.cs b/QSB/PoolSync/Patches/PoolPatches.cs index f717ebfe..580e9387 100644 --- a/QSB/PoolSync/Patches/PoolPatches.cs +++ b/QSB/PoolSync/Patches/PoolPatches.cs @@ -8,32 +8,27 @@ namespace QSB.PoolSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("Awake", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("Update", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnSocketableRemoved", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnSocketableDonePlacing", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnPedestalContact", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("FixedUpdate", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnSectorOccupantAdded", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnSectorOccupantRemoved", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnEntry", typeof(PoolPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnExit", typeof(PoolPatches), nameof(ReturnFalse)); + 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)); } - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("Awake"); - QSBCore.HarmonyHelper.Unpatch("Update"); - QSBCore.HarmonyHelper.Unpatch("OnSocketableRemoved"); - QSBCore.HarmonyHelper.Unpatch("OnSocketableDonePlacing"); - QSBCore.HarmonyHelper.Unpatch("OnPedestalContact"); - QSBCore.HarmonyHelper.Unpatch("FixedUpdate"); - QSBCore.HarmonyHelper.Unpatch("OnSectorOccupantAdded"); - QSBCore.HarmonyHelper.Unpatch("OnSectorOccupantRemoved"); - QSBCore.HarmonyHelper.Unpatch("OnEntry"); - QSBCore.HarmonyHelper.Unpatch("OnExit"); - } - - public static bool ReturnFalse() => false; + public static bool NomaiRemoteCameraPlatform_Awake() => false; + public static bool NomaiRemoteCameraPlatform_Update() => false; + public static bool NomaiRemoteCameraPlatform_OnSocketableRemoved() => false; + public static bool NomaiRemoteCameraPlatform_OnSocketableDonePlacing() => false; + public static bool NomaiRemoteCameraPlatform_OnPedestalContact() => false; + public static bool NomaiRemoteCameraStreaming_FixedUpdate() => false; + public static bool NomaiRemoteCameraStreaming_OnSectorOccupantAdded() => false; + public static bool NomaiRemoteCameraStreaming_OnSectorOccupantRemoved() => false; + public static bool NomaiRemoteCameraStreaming_OnEntry() => false; + public static bool NomaiRemoteCameraStreaming_OnExit() => false; } } diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index c11c3d01..abcd24df 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -55,7 +55,6 @@ namespace QSB public class QSBCore : ModBehaviour { public static IModHelper Helper { get; private set; } - public static IHarmonyHelper HarmonyHelper => Helper.HarmonyHelper; public static IModUnityEvents UnityEvents => Helper.Events.Unity; public static string DefaultServerIP { get; private set; } public static int Port { get; private set; } @@ -246,4 +245,28 @@ namespace QSB ShowLinesInDebug = config.GetSettingsValue("showLinesInDebug"); } } -} \ No newline at end of file +} + +/* + * _nebula's music thanks + * I listen to music constantly while programming/working - here's my thanks to them for keeping me entertained :P + * + * Wintergatan + * HOME + * C418 + * Lupus Nocte + * Max Cooper + * Darren Korb + * Harry Callaghan + * Toby Fox + * Andrew Prahlow + * Valve (Mike Morasky, Kelly Bailey) + * Joel Nielsen + * Vulfpeck + * Detektivbyrån + * Ben Prunty + * ConcernedApe + * Jake Chudnow + * Murray Gold + * Teleskärm + */ \ No newline at end of file diff --git a/QSB/QuantumSync/Patches/ClientQuantumPatches.cs b/QSB/QuantumSync/Patches/ClientQuantumPatches.cs index 78f82809..a510704e 100644 --- a/QSB/QuantumSync/Patches/ClientQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/ClientQuantumPatches.cs @@ -9,19 +9,14 @@ namespace QSB.QuantumSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ClientQuantumPatches), nameof(ReturnFalsePatch)); - QSBCore.HarmonyHelper.AddPostfix("Start", typeof(ClientQuantumPatches), nameof(Moon_CollapseOnStart)); + Prefix(nameof(QuantumMoon_ChangeQuantumState)); + Postfix(nameof(QuantumMoon_Start)); } - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("ChangeQuantumState"); - QSBCore.HarmonyHelper.Unpatch("Start"); - } - - public static void Moon_CollapseOnStart(QuantumMoon __instance) + public static void QuantumMoon_Start(QuantumMoon __instance) => __instance.GetType().GetMethod("SetSurfaceState", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { -1 }); - public static bool ReturnFalsePatch() => false; + public static bool QuantumMoon_ChangeQuantumState() + => false; } } \ No newline at end of file diff --git a/QSB/QuantumSync/Patches/QuantumPatches.cs b/QSB/QuantumSync/Patches/QuantumPatches.cs index 58a561f6..7e70cee3 100644 --- a/QSB/QuantumSync/Patches/QuantumPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumPatches.cs @@ -18,43 +18,28 @@ namespace QSB.QuantumSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(Socketed_ChangeQuantumState)); - QSBCore.HarmonyHelper.AddPostfix("MoveToSocket", typeof(QuantumPatches), nameof(Socketed_MoveToSocket)); - QSBCore.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(Shuffle_ChangeQuantumState)); - QSBCore.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(MultiState_ChangeQuantumState)); - QSBCore.HarmonyHelper.AddPostfix("SetVisible", typeof(QuantumPatches), nameof(QuantumState_SetVisible)); - QSBCore.HarmonyHelper.AddPrefix("IsPlayerInDarkness", typeof(QuantumPatches), nameof(Shrine_IsPlayerInDarkness)); - QSBCore.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(QuantumPatches), nameof(Shrine_ChangeQuantumState)); - QSBCore.HarmonyHelper.AddPrefix("OnEntry", typeof(QuantumPatches), nameof(Shrine_OnEntry)); - QSBCore.HarmonyHelper.AddPrefix("OnExit", typeof(QuantumPatches), nameof(Shrine_OnExit)); - QSBCore.HarmonyHelper.AddPrefix("CheckPlayerFogProximity", typeof(QuantumPatches), nameof(Moon_CheckPlayerFogProximity)); - QSBCore.HarmonyHelper.AddPrefix("IsLockedByPlayerContact", typeof(QuantumPatches), nameof(Object_IsLockedByPlayerContact)); - QSBCore.HarmonyHelper.AddPrefix("Start", typeof(QuantumPatches), nameof(MultiState_Start)); + 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)); } - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("ChangeQuantumState"); - QSBCore.HarmonyHelper.Unpatch("MoveToSocket"); - QSBCore.HarmonyHelper.Unpatch("ChangeQuantumState"); - QSBCore.HarmonyHelper.Unpatch("ChangeQuantumState"); - QSBCore.HarmonyHelper.Unpatch("SetVisible"); - QSBCore.HarmonyHelper.Unpatch("IsPlayerInDarkness"); - QSBCore.HarmonyHelper.Unpatch("ChangeQuantumState"); - QSBCore.HarmonyHelper.Unpatch("OnEntry"); - QSBCore.HarmonyHelper.Unpatch("OnExit"); - QSBCore.HarmonyHelper.Unpatch("CheckPlayerFogProximity"); - QSBCore.HarmonyHelper.Unpatch("IsLockedByPlayerContact"); - } - - public static bool Object_IsLockedByPlayerContact(ref bool __result, QuantumObject __instance) + public static bool QuantumObject_IsLockedByPlayerContact(ref bool __result, QuantumObject __instance) { var playersEntangled = QuantumManager.GetEntangledPlayers(__instance); __result = playersEntangled.Count() != 0 && __instance.IsIlluminated(); return false; } - public static bool Socketed_ChangeQuantumState( + public static bool SocketedQuantumObject_ChangeQuantumState( SocketedQuantumObject __instance, ref bool __result, bool skipInstantVisibilityCheck, @@ -161,7 +146,7 @@ namespace QSB.QuantumSync.Patches return false; } - public static void Socketed_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket) + public static void SocketedQuantumObject_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket) { if (!WorldObjectManager.AllReady) { @@ -194,7 +179,7 @@ namespace QSB.QuantumSync.Patches __instance.transform.localRotation); } - public static bool Shuffle_ChangeQuantumState( + public static bool QuantumShuffleObject_ChangeQuantumState( QuantumShuffleObject __instance, ref List ____indexList, ref Vector3[] ____localPositions, @@ -239,7 +224,7 @@ namespace QSB.QuantumSync.Patches return false; } - public static bool MultiState_Start(MultiStateQuantumObject __instance, Sector ____sector, bool ____collapseOnStart) + public static bool MultiStateQuantumObject_Start(MultiStateQuantumObject __instance, Sector ____sector, bool ____collapseOnStart) { if (!WorldObjectManager.AllReady) { @@ -272,7 +257,7 @@ namespace QSB.QuantumSync.Patches return false; } - public static bool MultiState_ChangeQuantumState(MultiStateQuantumObject __instance) + public static bool MultiStateQuantumObject_ChangeQuantumState(MultiStateQuantumObject __instance) { if (!WorldObjectManager.AllReady) { @@ -313,7 +298,7 @@ namespace QSB.QuantumSync.Patches stateIndex); } - public static bool Shrine_IsPlayerInDarkness(ref bool __result, Light[] ____lamps, float ____fadeFraction, bool ____isProbeInside, NomaiGateway ____gate) + public static bool QuantumShrine_IsPlayerInDarkness(ref bool __result, Light[] ____lamps, float ____fadeFraction, bool ____isProbeInside, NomaiGateway ____gate) { foreach (var lamp in ____lamps) { @@ -359,14 +344,14 @@ namespace QSB.QuantumSync.Patches return false; } - public static bool Shrine_ChangeQuantumState(QuantumShrine __instance) + public static bool QuantumShrine_ChangeQuantumState(QuantumShrine __instance) { var shrineWorldObject = QSBWorldSync.GetWorldFromUnity(__instance); var isInControl = shrineWorldObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId; return isInControl; } - public static bool Shrine_OnEntry( + public static bool QuantumShrine_OnEntry( GameObject hitObj, ref bool ____isPlayerInside, ref bool ____fading, @@ -387,7 +372,7 @@ namespace QSB.QuantumSync.Patches return false; } - public static bool Shrine_OnExit( + public static bool QuantumShrine_OnExit( GameObject hitObj, ref bool ____isPlayerInside, ref bool ____fading, @@ -408,7 +393,7 @@ namespace QSB.QuantumSync.Patches return false; } - public static bool Moon_CheckPlayerFogProximity( + public static bool QuantumMoon_CheckPlayerFogProximity( QuantumMoon __instance, int ____stateIndex, float ____eyeStateFogOffset, diff --git a/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs b/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs index cd5f9b24..3b85247b 100644 --- a/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs +++ b/QSB/QuantumSync/Patches/QuantumVisibilityPatches.cs @@ -13,22 +13,12 @@ namespace QSB.QuantumSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("IsVisibleUsingCameraFrustum", typeof(QuantumVisibilityPatches), nameof(ShapeIsVisibleUsingCameraFrustum)); - QSBCore.HarmonyHelper.AddPrefix("IsVisible", typeof(QuantumVisibilityPatches), nameof(ShapeIsVisible)); - QSBCore.HarmonyHelper.AddPrefix("IsVisibleUsingCameraFrustum", typeof(QuantumVisibilityPatches), nameof(RenderIsVisibleUsingCameraFrustum)); - QSBCore.HarmonyHelper.AddPrefix("CheckIllumination", typeof(QuantumVisibilityPatches), nameof(CheckIllumination)); - QSBCore.HarmonyHelper.AddPostfix("OnEnable", typeof(QuantumVisibilityPatches), nameof(Shape_OnEnable)); - QSBCore.HarmonyHelper.AddPostfix("OnDisable", typeof(QuantumVisibilityPatches), nameof(Shape_OnDisable)); - } - - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("IsVisibleUsingCameraFrustum"); - QSBCore.HarmonyHelper.Unpatch("IsVisible"); - QSBCore.HarmonyHelper.Unpatch("IsVisibleUsingCameraFrustum"); - QSBCore.HarmonyHelper.Unpatch("CheckIllumination"); - QSBCore.HarmonyHelper.Unpatch("OnEnable"); - QSBCore.HarmonyHelper.Unpatch("OnDisable"); + Prefix(nameof(ShapeVisibilityTracker_IsVisibleUsingCameraFrustum)); + Prefix(nameof(ShapeVisibilityTracker_IsVisible)); + Prefix(nameof(RendererVisibilityTracker_IsVisibleUsingCameraFrustum)); + Prefix(nameof(VisibilityObject_CheckIllumination)); + Postfix(nameof(Shape_OnEnable)); + Postfix(nameof(Shape_OnDisable)); } public static void Shape_OnEnable(Shape __instance) @@ -39,13 +29,13 @@ namespace QSB.QuantumSync.Patches // ShapeVisibilityTracker patches - public static bool ShapeIsVisibleUsingCameraFrustum(ShapeVisibilityTracker __instance, ref bool __result) + public static bool ShapeVisibilityTracker_IsVisibleUsingCameraFrustum(ShapeVisibilityTracker __instance, ref bool __result) { __result = QuantumManager.IsVisibleUsingCameraFrustum(__instance, false).First; return false; } - public static bool ShapeIsVisible(ShapeVisibilityTracker __instance, ref bool __result) + public static bool ShapeVisibilityTracker_IsVisible(ShapeVisibilityTracker __instance, ref bool __result) { __result = QuantumManager.IsVisible(__instance, false); return false; @@ -53,7 +43,7 @@ namespace QSB.QuantumSync.Patches // RendererVisibilityTracker patches - probably not needed as i don't think RendererVisibilityTracker is ever used? - public static bool RenderIsVisibleUsingCameraFrustum(RendererVisibilityTracker __instance, ref bool __result, Renderer ____renderer, bool ____checkFrustumOcclusion) + public static bool RendererVisibilityTracker_IsVisibleUsingCameraFrustum(RendererVisibilityTracker __instance, ref bool __result, Renderer ____renderer, bool ____checkFrustumOcclusion) { __result = QSBPlayerManager.GetPlayersWithCameras() .Any(x => GeometryUtility.TestPlanesAABB(x.Camera.GetFrustumPlanes(), ____renderer.bounds)) @@ -66,7 +56,7 @@ namespace QSB.QuantumSync.Patches // VisibilityObject - public static bool CheckIllumination(VisibilityObject __instance, ref bool __result, bool ____checkIllumination, Vector3 ____localIlluminationOffset, float ____illuminationRadius, Light[] ____lightSources) + 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 eb2bb374..77cd8548 100644 --- a/QSB/QuantumSync/Patches/ServerQuantumPatches.cs +++ b/QSB/QuantumSync/Patches/ServerQuantumPatches.cs @@ -14,12 +14,9 @@ namespace QSB.QuantumSync.Patches public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect; public override void DoPatches() - => QSBCore.HarmonyHelper.AddPrefix("ChangeQuantumState", typeof(ServerQuantumPatches), nameof(Moon_ChangeQuantumState)); + => Prefix(nameof(QuantumMoon_ChangeQuantumState)); - public override void DoUnpatches() - => QSBCore.HarmonyHelper.Unpatch("ChangeQuantumState"); - - public static bool Moon_ChangeQuantumState( + public static bool QuantumMoon_ChangeQuantumState( QuantumMoon __instance, ref bool __result, bool skipInstantVisibilityCheck, diff --git a/QSB/RoastingSync/Patches/RoastingPatches.cs b/QSB/RoastingSync/Patches/RoastingPatches.cs index 3e9dce13..5f12fe8c 100644 --- a/QSB/RoastingSync/Patches/RoastingPatches.cs +++ b/QSB/RoastingSync/Patches/RoastingPatches.cs @@ -10,16 +10,11 @@ namespace QSB.RoastingSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("UpdateMarshmallowInput", typeof(RoastingPatches), nameof(RoastingStickController_UpdateMarshmallowInput)); - QSBCore.HarmonyHelper.AddPrefix("Burn", typeof(RoastingPatches), nameof(Marshmallow_Burn)); - QSBCore.HarmonyHelper.AddPrefix("Shrivel", typeof(RoastingPatches), nameof(Marshmallow_Shrivel)); - QSBCore.HarmonyHelper.AddPrefix("RemoveMallow", typeof(RoastingPatches), nameof(Marshmallow_RemoveMallow)); - QSBCore.HarmonyHelper.AddPrefix("SpawnMallow", typeof(RoastingPatches), nameof(Marshmallow_SpawnMallow)); - } - - public override void DoUnpatches() - { - // TODO : add unpatches + Prefix(nameof(RoastingStickController_UpdateMarshmallowInput)); + Prefix(nameof(Marshmallow_Burn)); + Prefix(nameof(Marshmallow_Shrivel)); + Prefix(nameof(Marshmallow_RemoveMallow)); + Prefix(nameof(Marshmallow_SpawnMallow)); } public static bool Marshmallow_SpawnMallow() diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index 7029aea5..675f7056 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -12,18 +12,10 @@ namespace QSB.ShipSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("OnPressInteract", typeof(ShipPatches), nameof(HatchController_OnPressInteract)); - QSBCore.HarmonyHelper.AddPrefix("OnEntry", typeof(ShipPatches), nameof(HatchController_OnEntry)); - QSBCore.HarmonyHelper.AddPrefix("OnTriggerExit", typeof(ShipPatches), nameof(ShipTractorBeamSwitch_OnTriggerExit)); - QSBCore.HarmonyHelper.AddPrefix("UpdateInteractVolume", typeof(ShipPatches), nameof(InteractZone_UpdateInteractVolume)); - } - - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("OnPressInteract"); - QSBCore.HarmonyHelper.Unpatch("OnEntry"); - QSBCore.HarmonyHelper.Unpatch("OnTriggerExit"); - QSBCore.HarmonyHelper.Unpatch("UpdateInteractVolume"); + Prefix(nameof(HatchController_OnPressInteract)); + Prefix(nameof(HatchController_OnEntry)); + Prefix(nameof(ShipTractorBeamSwitch_OnTriggerExit)); + Prefix(nameof(InteractZone_UpdateInteractVolume)); } public static bool HatchController_OnPressInteract() diff --git a/QSB/StatueSync/Patches/StatuePatches.cs b/QSB/StatueSync/Patches/StatuePatches.cs index 928bd806..f485eb5f 100644 --- a/QSB/StatueSync/Patches/StatuePatches.cs +++ b/QSB/StatueSync/Patches/StatuePatches.cs @@ -10,12 +10,9 @@ namespace QSB.StatueSync.Patches public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; public override void DoPatches() - => QSBCore.HarmonyHelper.AddPrefix("Update", typeof(StatuePatches), nameof(Statue_Update)); + => Prefix(nameof(MemoryUplinkTrigger_Update)); - public override void DoUnpatches() - => QSBCore.HarmonyHelper.Unpatch("Update"); - - public static bool Statue_Update(bool ____waitForPlayerGrounded) + 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 a46f5020..26725dce 100644 --- a/QSB/TimeSync/Patches/TimePatches.cs +++ b/QSB/TimeSync/Patches/TimePatches.cs @@ -7,10 +7,7 @@ namespace QSB.TimeSync.Patches public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; public override void DoPatches() - => QSBCore.HarmonyHelper.AddPrefix("OnStartOfTimeLoop", typeof(TimePatches), nameof(PlayerCameraEffectController_OnStartOfTimeLoop)); - - public override void DoUnpatches() - => QSBCore.HarmonyHelper.Unpatch("OnStartOfTimeLoop"); + => Prefix(nameof(PlayerCameraEffectController_OnStartOfTimeLoop)); public static bool PlayerCameraEffectController_OnStartOfTimeLoop() => false; diff --git a/QSB/TranslationSync/Patches/SpiralPatches.cs b/QSB/TranslationSync/Patches/SpiralPatches.cs index cf2a6f54..91348b9b 100644 --- a/QSB/TranslationSync/Patches/SpiralPatches.cs +++ b/QSB/TranslationSync/Patches/SpiralPatches.cs @@ -11,19 +11,12 @@ namespace QSB.TranslationSync.Patches public override void DoPatches() { - QSBCore.HarmonyHelper.AddPrefix("SetAsTranslated", typeof(SpiralPatches), nameof(Wall_SetAsTranslated)); - QSBCore.HarmonyHelper.AddPrefix("SetAsTranslated", typeof(SpiralPatches), nameof(Computer_SetAsTranslated)); - QSBCore.HarmonyHelper.AddPrefix("SetAsTranslated", typeof(SpiralPatches), nameof(VesselComputer_SetAsTranslated)); + Prefix(nameof(NomaiWallText_SetAsTranslated)); + Prefix(nameof(NomaiComputer_SetAsTranslated)); + Prefix(nameof(NomaiVesselComputer_SetAsTranslated)); } - public override void DoUnpatches() - { - QSBCore.HarmonyHelper.Unpatch("SetAsTranslated"); - QSBCore.HarmonyHelper.Unpatch("SetAsTranslated"); - QSBCore.HarmonyHelper.Unpatch("SetAsTranslated"); - } - - public static bool Wall_SetAsTranslated(NomaiWallText __instance, int id) + public static bool NomaiWallText_SetAsTranslated(NomaiWallText __instance, int id) { if (__instance.IsTranslated(id)) { @@ -37,7 +30,7 @@ namespace QSB.TranslationSync.Patches return true; } - public static bool Computer_SetAsTranslated(NomaiComputer __instance, int id) + public static bool NomaiComputer_SetAsTranslated(NomaiComputer __instance, int id) { if (__instance.IsTranslated(id)) { @@ -51,7 +44,7 @@ namespace QSB.TranslationSync.Patches return true; } - public static bool VesselComputer_SetAsTranslated(NomaiVesselComputer __instance, int id) + public static bool NomaiVesselComputer_SetAsTranslated(NomaiVesselComputer __instance, int id) { if (__instance.IsTranslated(id)) {