Git Product home page Git Product logo

geminihook's Introduction

GeminiHook

Wildstar Library - Offers safe Hooking/Unhooking of functions, and methods

GeminiHook-1.0 offers safe Hooking/Unhooking of functions and methods. Using GeminiHook-1.0 is recommended when you need to unhook your hooks again, so the hook chain isn't broken when you manually restore the original function.

GeminiHook-1.0 can be embeded into your addon, either explicitly by calling GeminiHook:Embed(MyAddon) or by specifying it as an embeded library in your GeminiAddon. All functions will be available on your addon object and can be accessed directly, without having to explicitly call GeminiHook itself. It is recommended to embed GeminiHook, otherwise you'll have to specify a custom self on all calls you make into GeminiHook.

##GeminiHook:Hook([object], method, [handler]) Hook a function or a method on an object. The hook created will be a "safe hook", that means that your handler will be called before the hooked function ("Pre-Hook"), and you don't have to call the original function yourself, however you cannot stop the execution of the function, or modify any of the arguments/return values. This type of hook is typically used if you need to know if some function got called, and don't want to modify it.

###Parameters

  • object

    • The object to hook a method from
  • method

    • If object was specified, the name of the method, or the name of the function to hook.
  • handler

    • The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)

###Usage

-- create an addon with GeminiHook embeded
MyAddon = Apollo.GetPackage("Gemini:Addon-1.0").tPackage:NewAddon("HookDemo", false, {}, "Gemini:Hook-1.0")

function MyAddon:OnEnable()
  -- Hook GetCurrentZoneName
  self:Hook("GetCurrentZoneName")
end

function MyAddon:GetCurrentZoneName()
  Print("Showing Zone Name!")
end

##GeminiHook:IsHooked([obj], method) Check if the specific function, method or script is already hooked.

###Parameters

  • obj

    • The object or frame to unhook from
  • method

    • The name of the method, function or script to unhook from.

##GeminiHook:RawHook([object], method, [handler]) RawHook a function or a method on an object. The hook created will be a "raw hook", that means that your handler will completly replace the original function, and your handler has to call the original function (or not, depending on your intentions). The original function will be stored in self.hooks[object][method] or self.hooks[functionName] respectively. This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments or want to control execution of the original function.

###Parameters

  • object

    • The object to hook a method from
  • method

    • If object was specified, the name of the method, or the name of the function to hook.

handler * The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)

###Usage

-- create an addon with GeminiHook embeded
MyAddon = Apollo.GetPackage("Gemini:Addon-1.0").tPackage:NewAddon("HookDemo", false, {}, "Gemini:Hook-1.0")

function MyAddon:OnEnable()
  -- Hook OnGenerateTooltip
  self:RawHook(Apollo.GetAddon("Inventory"),"OnGenerateTooltip")
end

function MyAddon:OnGenerateTooltip(luaCaller, wndControl, wndHandler, tType, item)
  if item ~= nil and item:IsEquippable() then
    Print("Equippable item, no tooltip for you!")
  else
    self.hooks[Apollo.GetAddon("Inventory")].OnGenerateTooltip(luaCaller, wndControl, wndHandler, tType, item)
  end
end

##GeminiHook:PostHook([object], method, [handler]) Post Hook a function or a method on an object. Post Hooks are always called after the original function was called, and you cannot modify the arguments, return values or control the execution. PostHook returns 2 arguments: a table containing the return values of the original function and either nil or the return values of the hook function

###Parameters

  • object

    • The object to hook a method from
  • method

    • If object was specified, the name of the method, or the name of the function to hook.
  • handler

    • The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function)

##GeminiHook:Unhook([obj], method) Unhook from the specified function, method or script.

Parameters

  • obj

    • The object or frame to unhook from
  • method

    • The name of the method, function or script to unhook from.

##GeminiHook:UnhookAll() Unhook all existing hooks for this addon.

geminihook's People

Contributors

sinaloit avatar

Stargazers

Christian Ehrhardt avatar

Watchers

Bryan McLemore avatar David Hedbor avatar  avatar  avatar Rachel Blackman avatar James Cloos avatar Leosky avatar Hans Koch avatar Tamás Varga avatar Scriptorium avatar  avatar Jimmy Van Hecke avatar  avatar

Forkers

nasapunk88

geminihook's Issues

RawHook doesn't pass original parameters?

This maybe me just not understanding how hooking is supposed to work, but I've created a raw hook that's feeding into my version of an existing function in another addon. To do my work, I need the input parameters of that function, but when the hook engages, all the inputs are nil. How to I get the input values that the hooked function would have received?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.