Friendly hooking and unhooking of functions "BlacksmithHookManager" - v0.2.1

Saelorable

Villager
Member
Joined
Feb 22, 2019
Messages
9
Reaction score
15
First Language
English
Primarily Uses
RMMV

Introduction
Blacksmith Plugin Manager part of the Blacksmith suite of plugin development tools.
Blacksmith Hook Manager allows plugin developers to hook system functions in a compatible away, allowing multiple plugins to hook the same functions without risking clash.

Features
  • Smart hooking and unhooking: Provides helpers for hooking and unhooking system functions without clashing with other tools that also use the Hook Manager.

How to Use

End users:
Unless included alongside another plugin, you shouldn't need to use this, as it should be included automatically.

Plugin developers: This plugin depends upon BlacksmithPluginManager, set up your Plugin as directed in that thread and list this plugin as a dependency, in the following format:
Code:
new PluginManager.Plugin({
        id: "examplePluginID", //required - this should match the filename
        dependencies: [{url:"https://pastebin.com/raw/v8aPTvE2", name:"BlacksmithHookManager"}],
        initializer: function (callback) { //required - all your code should go in here
   
            /* your code here */

            callback()
        }
});
Once included, any code within the initializer function has access to the following functions:
  • PluginManager.registerHook - hooks a function, returning an unhook function.
    • params
      1. hook: string - the dot-separated variable name. (I.e. "Scene_Title.prototype.commandNewGame" to hook the new game function.)
      2. handler: function - the handler function. your code should go in here. called with the same arguments as the overloaded function.
        • should return either:
          • an iteratable object (i.e. an array[]) containing the arguments to call the function with, if intended to run before the hooked function
          • OR a replacement return value for the function if run after.
            • if undefined is returned (i.e. nothing) nothing will happen, to explicitly exclude return value, return null
      3. order: optional number - a number controlling when the function should be run. negative values run before the function, positive values run after. the further from zero, the earlier/later the function will be called. Range [-10...+10] Out of range values will be accepted, but will cause lag. DEFAULT: 0
      4. hookID: optional string - a string to refer to the function later for removal.
    • returns:
      • detatch: function - When called this will remove your hook.
  • PluginManager.registerAsyncHook
    • params
      1. hook: see PluginManager.registerHook
      2. handler: similar to PluginManager.registerHook except called with additional arguments, the first arguments match the original function followed by an array of the arguments for mutation, and finally the callback arguments of the previous run of the function (only guaranteed if running after the base function)
      3. callbackIndex: number - the 0 based index of the callback. Defaults to the first attribute
      4. order: see PluginManager.registerHook
      5. hookID: see PluginManager.registerHook
    • returns
      • detatch: see PluginManager.registerHook
  • PluginManager.unregisterHook unregister a hooked function. useful when the return value of one of the previous functions is unavailable for some reason, as it can be accessed anywhere.
    • params
      1. hookID: should match the ID set in the hook function.



Script

Github Link: https://github.com/Connor-Macleod/blacksmith-plugin-suite/blob/master/BlacksmithHookManager.js

FAQ


Licencing
Copyright (c) 2019 Connor "Saelorable" Macleod

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish and/or distribute copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  • That no additional charge is ascribed to the inclusion of the software.
  • That attribution is included with any use of the software such that it is visible to end users, either within any bundled software or on any related download pages.
  • That no bundled items intentionally promote hate speech or discrimination of protected minorities.
Additionally, permission to sublicense, and/or sell copies of the Software may be obtained by contacting the copyright holder. This permission may come with additional and/or more specific costs and/or conditions.

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author's Notes
All feedback is greatly appreciated!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

buinguyenhoangtho wrote on fizzly's profile.
Hello @fizzly, i would like to use your asset/ resource for my project ( is maybe commercial ). May i have your permission? Thanks you !
Working on breaking the limits of RPGMaker! :cool:
I have 470+ hours on RMMV but have only made a demo game, is this normal? :kaoswt: (I lose motivation a lot plus I use a 32gb laptop, so..)
I like Iron Maiden.
Benku wrote on Magnus0808's profile.
Hey man you helped me out a long time ago with a plugin i was wondering if you can help me out one more time since its literally the last thing i need help with if not is cool but id figured id ask you one more soild.

Forum statistics

Threads
95,427
Messages
929,082
Members
125,659
Latest member
AphoticAmaranth
Top