rq.ain
since 0.2.0
Reaches into the game's own code (the AIN): call, hook and patch its functions, and read and write its globals.
Names are the game's own, in UTF-8, such as T戦闘前初期化 or T_BattleSelect@select; find them with rq.ain.find. They can change with the game's data, so a mod that patches by number should check the count it gets back.
Functions
| Name | Summary |
|---|---|
rq.ain.patch_float | Replaces float constants in one AIN function. |
rq.ain.patch_int | Replaces integer constants in one AIN function, such as a hard-coded skill number. |
rq.ain.patch_int_after | Replaces the first integer constant from that follows a read of a global. |
rq.ain.set_code_int | Writes a new value into a constant of the game's code that rq.ain.patch_int_after changed. |
rq.ain.code_int | Reads the value a place of rq.ain.patch_int_after holds in the game's code now. |
rq.ain.stack | Returns the names of the game's functions on its call stack now, innermost first. |
rq.ain.call | Calls any AIN function by its name. |
rq.ain.hook | Runs Lua before and after any AIN function. |
rq.ain.method | Calls a method of the game on the object a global reaches. |
rq.ain.global | Reads a game global that holds an int, bool, float or string. |
rq.ain.set_global | Writes a game global, as rq.ain.global reads it: set_global(name, [step, ...,] value). |
rq.ain.global_len | Returns the size of an array global. |
rq.ain.set_global_len | Makes an array global longer or shorter, as the game's own Realloc does. |
rq.ain.skip_msgbox | Removes the game's message boxes whose text contains needle. |
rq.ain.skip_sdl_msgbox | Swallows the engine's own error boxes for the TADA and HTTP network checks (getserverversion). |
rq.ain.find | Writes the AIN functions whose name contains needle to the log. |
rq.ain.patch_float
rq.ain.patch_float(name, from, to, n) -> integersince 0.2.0 changed 1.3.0 changed 2.34.0
Replaces float constants in one AIN function.
| Parameter | Type | Description |
|---|---|---|
name | string | The function's name. |
from | number | The value to find. |
to | number | The new value. |
n (optional) | integer | Which occurrence, from 0. Default: all of them. |
| Returns | Type | Description |
|---|---|---|
count | integer | How many constants were replaced. |
Changed in 1.3.0: Reaches the game's code of a function the loader wraps (such as
T戦闘前初期化); before, it patched only the wrapper and found nothing.
Changed in 2.34.0: Reaches the game's code of a function hooked with
rq.ain.hook(a hook moves the function to a stub); before, a hook made first, as the loader's own onT戦闘前初期化since this version, left nothing to find.
rq.ain.patch_int
rq.ain.patch_int(name, from, to, n) -> integersince 0.17.0 changed 1.3.0 changed 2.34.0
Replaces integer constants in one AIN function, such as a hard-coded skill number.
Occurrences count every constant of that value in the function, so they can differ between versions of the game's AIN; to find one constant by what it follows, use patch_int_after.
| Parameter | Type | Description |
|---|---|---|
name | string | The function's name. |
from | integer | The value to find. |
to | integer | The new value. |
n (optional) | integer | Which occurrence, from 0. Default: all of them. |
| Returns | Type | Description |
|---|---|---|
count | integer | How many constants were replaced. |
Changed in 1.3.0: Reaches the game's code of a function the loader wraps.
Changed in 2.34.0: Reaches the game's code of a function hooked with
rq.ain.hook.
See also: rq.ain.patch_int_after
rq.ain.patch_int_after
rq.ain.patch_int_after(name, global, from, to, nth_ref, window) -> integer, integer[]since 1.3.0 changed 2.22.0 changed 2.34.0
Replaces the first integer constant from that follows a read of a global.
It looks at the window instructions after the read, as for the 2 in if (◆2倍モード == 1) { x = x * 2; }. A variable's index is never taken for the constant.
It also returns the places it changed, for rq.ain.set_code_int: a mod finds a constant once, by what it follows, and writes it again later without searching. Searching again would be wrong once the constant holds a value that also comes before it, as the 1 of == 1 above.
Raises an error for an unknown function or global.
local _, at = rq.ain.patch_int_after("T戦闘前初期化", "◆2倍モード", 2, 3, 0)
rq.ain.set_code_int(at[1], 5) -- later, with no search| Parameter | Type | Description |
|---|---|---|
name | string | The function's name. |
global | string | The global's name. |
from | integer | The value to find. |
to | integer | The new value. |
nth_ref (optional) | integer | Which read of the global in the function, from 0. Default: after every read. |
window (optional) | integer | How many instructions to look at after the read. Default 8. |
| Returns | Type | Description |
|---|---|---|
count | integer | How many constants were replaced. |
places | integer[] | One place for each constant replaced, in code order, for rq.ain.set_code_int and rq.ain.code_int. |
Changed in 2.22.0: Returns the places too.
Changed in 2.34.0: Reaches the game's code of a function hooked with
rq.ain.hook.
See also: rq.ain.set_code_int
rq.ain.set_code_int
rq.ain.set_code_int(place, value) -> booleansince 2.22.0 changed 2.34.0
Writes a new value into a constant of the game's code that rq.ain.patch_int_after changed.
The place is the constant patch_int_after found, written now as it wrote it. The game reads it the next time it runs that code, so a value changed between fights counts from the next fight. When another install wraps the function later, the place is still found: the wrapped code stays where it was, and a body moved and grown is searched for the same constant with the same instructions around it. So is it when the function is hooked later with rq.ain.hook.
Raises an error for a place that patch_int_after did not give.
| Parameter | Type | Description |
|---|---|---|
place | integer | A place from rq.ain.patch_int_after. |
value | integer | The new value. |
| Returns | Type | Description |
|---|---|---|
ok | boolean | false when the place is no longer in the game's code as it was written (it is logged); nothing is written then. |
Changed in 2.34.0: A place in a function hooked with
rq.ain.hookafter the patch is found; before, it returned false.
See also: rq.ain.patch_int_after
rq.ain.code_int
rq.ain.code_int(place) -> integer|nilsince 2.22.0
Reads the value a place of rq.ain.patch_int_after holds in the game's code now.
Raises an error for a place that patch_int_after did not give.
| Parameter | Type | Description |
|---|---|---|
place | integer | A place from rq.ain.patch_int_after. |
| Returns | Type | Description |
|---|---|---|
value | integer|nil | The value, or nil when the place is no longer found. |
rq.ain.stack
rq.ain.stack(max) -> string[]since 2.27.0
Returns the names of the game's functions on its call stack now, innermost first.
A method is named Class@method, as rq.ain.hook takes it. Inside a hook, the stack says who called the hooked function: rq.music reads it to tell a scene, the castle or the town apart. From rq.on_frame it shows the game's frame update (UpdateView, UPDATE) and the screen's loop under it.
rq.ain.hook("音楽", { before = function()
rq.log("music asked by " .. tostring(rq.ain.stack(3)[2]))
end })| Parameter | Type | Description |
|---|---|---|
max (optional) | integer | At most this many names. Default 32. |
| Returns | Type | Description |
|---|---|---|
names | string[] | The function names, innermost first; empty outside the game's code. |
rq.ain.call
rq.ain.call(name, ...) -> anysince 0.18.0 changed 0.26.0 changed 0.27.0
Calls any AIN function by its name.
The arguments must be int, bool, float or string, and all of them are needed. A scene command blocks until it ends, so call it from a callback the game runs, not at the top level of a mod. A function that reaches a save under this call gets the game's own "save failed" message and nothing is written; one that reaches a load closes the game with an error. A bad index passed to a game function is a fatal error in the game, and this call cannot check it.
Raises an error for an unknown name, a wrong number of arguments, a reference or struct argument, a method (Class@method, which needs an object), or SYS_セーブ実行 and SYS_ロード実行.
local name = rq.ain.call("クエスト_名前", 126)| Parameter | Type | Description |
|---|---|---|
name | string | The function's name. |
... | integer|boolean|number|string | The arguments. |
| Returns | Type | Description |
|---|---|---|
result | any | What the function returns; nil for none or a struct. |
Changed in 0.26.0: Refuses
SYS_セーブ実行andSYS_ロード実行.
Changed in 0.27.0: A save under the call fails safely.
rq.ain.hook
rq.ain.hook(name, opts) -> fun()since 0.18.0 changed 0.23.0 changed 2.55.0
Runs Lua before and after any AIN function.
A method is named Class@method. Many hooks may sit on one function. The function does not fire its hooks again while one of its callbacks runs. A table with neither side does nothing.
only keeps the callbacks to the calls a mod wants, checked in C: on a function the game calls thousands of times a frame (a skill check, a stat read), a hook for one skill number costs Lua nothing on the other calls. Every position named must hold one of its values. The after side reads the arguments as the function leaves them. Hooks with a different only on one function each check their own.
Raises an error for an unknown function, an only that is not a table of positions, a position the function has no argument at, an argument that is not an int, more than 4 positions, or a value that is not a whole number or a list of 1 to 16 of them.
rq.ain.hook("message", { before = function(h)
h.args[3] = h.args[3]:gsub("Rance", "Ranse") -- rewrite every line of text
end })
-- Only the game's checks for skill 373: CS番号取得(character, skill, mode).
rq.ain.hook("CS番号取得", { only = { [2] = 373 }, after = function(h)
rq.log("asked for Immature on", h.args[1], "->", h.result)
end })| Parameter | Type | Description |
|---|---|---|
name | string | The function's name. |
opts | rq.AinHookOpts | The callbacks, and only. |
| Returns | Type | Description |
|---|---|---|
remove | fun() | Removes both sides of this hook. |
Changed in 0.23.0: Returns a remover.
Changed in 2.55.0:
only: the callbacks run only for calls with these int arguments.
rq.ain.method
rq.ain.method(path, name, ...) -> anysince 2.16.0
Calls a method of the game on the object a global reaches.
path is a global's name, then indexes and field names as rq.ain.global takes them, and it must end on a struct: {"g_sSystemMenu"}, {"g_sCastle", "m_sList"}. The method's class must be that struct's (T_SystemMenu@createButton on a T_SystemMenu). The arguments are as rq.ain.call's: int, bool, float or string, all of them. The same cautions hold: a method that draws or waits runs inside this call, and a bad value passed to the game can be a fatal error there.
Raises an error for a path that is not a table, does not start with a known global or does not reach a struct, an unknown function, a function that is not a method or not the struct's, a wrong number of arguments, or a reference or struct argument.
local rows = rq.ain.method({ "g_sSystemMenu", "m_sButton" }, "T_ButtonGroup@getButtonCount")| Parameter | Type | Description |
|---|---|---|
path | (string|integer)[] | The global's name, then indexes and field names to the object. |
name | string | The method, Class@method. |
... | integer|boolean|number|string | The arguments. |
| Returns | Type | Description |
|---|---|---|
result | any | What the method returns; nil for none or a struct. |
See also: rq.ain.call
rq.ain.global
rq.ain.global(name, ...) -> integer|boolean|number|stringsince 0.22.0 changed 0.24.0
Reads a game global that holds an int, bool, float or string.
Give the game's own index for an array element, and a field name to go into a struct, mixed as the game does.
Raises an error for an unknown name or field, an index out of range, a step that does not fit the value, a whole array or a struct.
local fa = rq.ain.global("FA", 87) -- FA[87]
local name = rq.ain.global("Q", 126, "名前") -- Q[126].名前| Parameter | Type | Description |
|---|---|---|
name | string | The global's name. |
... | integer|string | Indexes and field names. |
| Returns | Type | Description |
|---|---|---|
value | integer|boolean|number|string | The value. |
Changed in 0.24.0: Field names reach into structs.
rq.ain.set_global
rq.ain.set_global(name, ...)since 0.22.0
Writes a game global, as rq.ain.global reads it: set_global(name, [step, ...,] value).
It is the game's own state and goes into the next save, so restore what a test changes.
Raises an error as rq.ain.global does.
| Parameter | Type | Description |
|---|---|---|
name | string | The global's name. |
... | any | Indexes and field names, then the value. |
rq.ain.global_len
rq.ain.global_len(name, ...) -> integersince 0.22.0
Returns the size of an array global.
Many game arrays start at 1 and leave 0 unused, so the size can be one more than the entries.
| Parameter | Type | Description |
|---|---|---|
name | string | The global's name. |
... | integer|string | Indexes and field names to reach an inner array. |
| Returns | Type | Description |
|---|---|---|
size | integer | The number of elements. |
rq.ain.set_global_len
rq.ain.set_global_len(name, ...)since 2.18.0
Makes an array global longer or shorter, as the game's own Realloc does.
Values that fit are kept; new elements are 0, false, an empty string or an empty struct. Only an array of one dimension. The array is the game's own state and goes into the next save at its new size, and a save made before brings back the old size, so grow it again where it is used (for example in a before hook). It is there only once the game runs, not while init.lua loads.
Raises an error for an unknown name, a value that is not an array, more than one dimension, or a size below 0 or above 65536.
if rq.ain.global_len("取得可能スキル") < 145 then rq.ain.set_global_len("取得可能スキル", 145) end| Parameter | Type | Description |
|---|---|---|
name | string | The global's name. |
... | integer|string | Indexes and field names to reach an inner array, then the new size. |
rq.ain.skip_msgbox
rq.ain.skip_msgbox(needle) -> integersince 0.2.0
Removes the game's message boxes whose text contains needle.
Every system.MsgBox call that shows a string holding needle is taken out of the code.
Raises an error when the AIN is not loaded.
| Parameter | Type | Description |
|---|---|---|
needle | string | Part of the message, in UTF-8. |
| Returns | Type | Description |
|---|---|---|
sites | integer | How many calls were taken out. |
rq.ain.skip_sdl_msgbox
rq.ain.skip_sdl_msgbox()since 1.0.0
Swallows the engine's own error boxes for the TADA and HTTP network checks (getserverversion).
rq.ain.find
rq.ain.find(needle) -> integersince 0.2.0 changed 1.16.1
Writes the AIN functions whose name contains needle to the log.
Each line is find '<needle>' fno=<number> <name>, and the name is what rq.ain.call and rq.ain.hook take (a method as Class@method). The match is on the game's own spelling, so case and full-width letters count. At most 40 are listed; a longer needle narrows the list.
Raises an error when the AIN is not loaded.
rq.ain.find("Encount") -- [rqmod] find 'Encount' fno=... T_Player@checkEncount, ...| Parameter | Type | Description |
|---|---|---|
needle | string | Part of a name, in UTF-8. |
| Returns | Type | Description |
|---|---|---|
count | integer | How many were listed. |
Changed in 1.16.1: Each line also gives the function's name.
