From 8afebb53feb19bc2e7931abd6de33ce94a780301 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 30 Jan 2022 12:54:15 +0100 Subject: [PATCH] feat(binding): add detour event for pet walk function --- .../Objects/PetManagerBinding.cs | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/Core/NosSmooth.LocalBinding/Objects/PetManagerBinding.cs b/src/Core/NosSmooth.LocalBinding/Objects/PetManagerBinding.cs index e3a435e..3ae74cd 100644 --- a/src/Core/NosSmooth.LocalBinding/Objects/PetManagerBinding.cs +++ b/src/Core/NosSmooth.LocalBinding/Objects/PetManagerBinding.cs @@ -8,6 +8,7 @@ using NosSmooth.LocalBinding.Options; using NosSmooth.LocalBinding.Structs; using Reloaded.Hooks.Definitions; using Reloaded.Hooks.Definitions.X86; +using Reloaded.Memory.Sources; using Remora.Results; namespace NosSmooth.LocalBinding.Objects; @@ -17,6 +18,8 @@ namespace NosSmooth.LocalBinding.Objects; /// public class PetManagerBinding { + private readonly IMemory _memory; + /// /// Create nostale pet manager binding. /// @@ -28,12 +31,13 @@ public class PetManagerBinding (NosBindingManager bindingManager, PetManagerList petManagerList, PetManagerBindingOptions options) { var petManager = new PetManagerBinding(petManagerList); + var petManager = new PetManagerBinding(bindingManager.Memory, petManagerList); var hookResult = bindingManager.CreateHookFromPattern ( "PetManagerBinding.PetWalk", petManager.PetWalkDetour, options.PetWalkPattern, - hook: options.HookPetWalk + enableHook: options.HookPetWalk ); if (!hookResult.IsSuccess) @@ -62,11 +66,20 @@ public class PetManagerBinding private IHook _petWalkHook = null!; - private PetManagerBinding(PetManagerList petManagerList) + private PetManagerBinding(IMemory memory, PetManagerList petManagerList) { + _memory = memory; PetManagerList = petManagerList; } + /// + /// Event that is called when walk was called by NosTale. + /// + /// + /// The walk must be hooked for this event to be called. + /// + public event Func? PetWalkCall; + /// /// Gets the hook of the pet walk function. /// @@ -117,13 +130,19 @@ public class PetManagerBinding int unknown2 = 1 ) { - return _petWalkHook.OriginalFunction - ( - petManagerPtr, - position, - unknown0, - unknown1, - unknown2 - ); + var result = PetWalkCall?.Invoke(new PetManager(_memory, petManagerPtr), (ushort)(position & 0xFFFF), (ushort)((position >> 16) & 0xFFFF)); + if (result ?? true) + { + return _petWalkHook.OriginalFunction + ( + petManagerPtr, + position, + unknown0, + unknown1, + unknown2 + ); + } + + return false; } } \ No newline at end of file -- 2.48.1