Hook templates¶
A manipulation is a JavaScript function that runs in the game after every hooked write. It receives a ctx object and returns the value to store; undefined or null keeps the game's value. Integer results are truncated and limited to the range of the type.
function (ctx) {
const { factor, direction } = ctx.params;
if (direction === 'increase' && ctx.delta <= 0)
return undefined;
if (direction === 'decrease' && ctx.delta >= 0)
return undefined;
return ctx.old + ctx.delta * factor;
}
The fields of ctx are listed in the hook context reference.
Managing templates¶
Manipulations are stored in the database as hook templates and managed under View → Hook templates …. At first start Grembyte creates the examples Multiplier, Fixed value and Clamp; they can be changed or deleted like templates of your own. Their texts are English whatever the language of the interface, since templates are data that exports share.
A template consists of a name, an optional description, the JavaScript function and parameters. Each parameter has
- a name –
ctx.params.<name>in the script, - a label shown in the hook dialog,
- a type: Number, Choice or Code for multi-line text,
- a default, and whether it is optional.
Choice values are written as value=Label; value=Label. The hook dialog builds its form from the parameters. A template with the number parameter threshold that only lets large gains through:
Testing without a game¶
Test runs the function without a game process: enter the value type, the old value (ctx.old) and the value written by the game (ctx.new) and run it. It shows the stored value, the output of ctx.log/console.log, and errors. ctx.state is kept between test runs until it is reset.
Note
The test runs in Qt's JavaScript engine rather than in Frida, so Frida APIs such as ptr() or Memory are not available there.
Templates and existing hooks¶
A hook stores a copy of the template it was created from, so later changes to the template do not affect existing hooks. In the hook's Edit dialog Grembyte points out a changed template and offers Use changed template. If the template is deleted, the hook keeps working with its copy.