Patcher Api
Methods
Section titled “Methods”after()
Section titled “after()”after<
O,K>(object,method,callback): () =>void
Runs a callback after a function on an object has been run
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
O extends object |
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
object | O |
method | K |
callback | (thisVal, args, returnVal) => any |
Returns
Section titled “Returns”Function
A function to remove the patch
Returns
Section titled “Returns”void
Example
Section titled “Example”const object = { method: () => 100 };api.patcher.after(object, "method", (thisVal, args, returnVal) => { console.log("Came after:", returnVal);});
object.method(); // Logs "Came after: 100"before()
Section titled “before()”before<
O,K>(object,method,callback): () =>void
Runs a callback before a function on an object has been run. Return true from the callback to prevent the function from running
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
O extends object |
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
object | O |
method | K |
callback | (thisVal, args) => boolean | void |
Returns
Section titled “Returns”Function
A function to remove the patch
Returns
Section titled “Returns”void
Example
Section titled “Example”const object = { method: (arg1, arg2) => 100 };api.patcher.before(object, "method", (thisVal, args) => { console.log("Came before:", args);});
object.method(5, 6); // Logs "Came before: [5, 6]"instead()
Section titled “instead()”instead<
O,K>(object,method,callback): () =>void
Runs a function instead of a function on an object
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
O extends object |
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
object | O |
method | K |
callback | (thisVal, args) => any |
Returns
Section titled “Returns”Function
A function to remove the patch
Returns
Section titled “Returns”void
Example
Section titled “Example”const object = { method: (arg1, arg2) => 100 };api.patcher.instead(object, "method", (thisVal, args) => { return args[0] + args[1];});
console.log(object.method(5, 6)); // Logs "11" instead of "100"swap()
Section titled “swap()”swap<
O,K>(object,method,callback): () =>void
Replaces a function on an object with another function
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
O extends object |
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
object | O |
method | K |
callback | (…args) => any |
Returns
Section titled “Returns”Function
A function to remove the patch
Returns
Section titled “Returns”void
Example
Section titled “Example”const object = { method: (arg1, arg2) => 100 };api.patcher.swap(object, "method", (arg1, arg2) => { return arg1 + arg2;});
console.log(object.method(5, 6)); // Logs "11" instead of "100"