-
Notifications
You must be signed in to change notification settings - Fork 5
Hook Overwrite Object Method
Mathieu edited this page Aug 8, 2022
·
10 revisions
To hook or overwrite a global object method there is an utility class now available into the PipeWrench-Utils module.
Import the class into your ts script.
import { hookInto } from "PipeWrench-Utils";The hookInto method takes 2 parameters.
Throws an error if the hook is invalid.
- target The target method fullpath
- hook The hook function to apply to that method
The hook parameter function has a variable amount of parameters but the two first parameters are always the original method and the self object.
- method The original method to call
- self The self object, if the hooked function is static self will be the first parameter of that function.
- varargs Any other params originally passed to the original method
Reloading a script containing a hook will duplicate the effect. Because of the nature of a hook it's preferred to reload the game (back to main menu and load again).
Hooking into a TimedAction:new method:
import { hookInto } from "PipeWrench-Utils";
// Hook into ISTakePillAction:new
hookInto("ISTakePillAction:new", (_new: Function, self: ISTakePillAction, character: IsoPlayer, item: InventoryItem, time: number) => {
const obj = _new(self, character, item, time) as ISTakePillAction
obj.maxTime = 300 // change action properties here
return obj
})Hooking into a TimedAction:perform method:
import { hookInto } from "PipeWrench-Utils";
// Hook into ISTakePillAction:perform
hookInto("ISTakePillAction:perform", (_perform: Function, self: ISTakePillAction) => {
const player = self.character as IsoPlayer
const item = self.item as InventoryItem
player.Say(`I took a ${item.getDisplayName()}!`)
return _perform(self)
})