# Kirby Air Riders hook sites for main (update 1.3.3). ASCII only.
#
# Job-system diagnostics (xc2_boot.cpp, KAR_JOB_TRACE=1): where the job queue reads a waiting job's counter pointer, and where
# a job's wait condition is set.

midhook 7100e8e3d4   # job pop: x19 = job, x11 = *(job+0xa8) (address of the waiter's counter pointer)
midhook 7100e8f298   # job wait set: x19 = current job, x24 = address of the counter pointer (a slot on the waiter's stack)

# Output resolution experiments (docked 1920x1080 / handheld 1280x720 picks): the movz immediates are read from guest
# memory, so the runtime can write another size into these instructions at boot ([kar] resolution).
dynimm 7102d5cf38   # mov w9, #1920 -> +0x110 (docked; csel with 1280)
dynimm 7102d5cf4c   # mov w9, #1080 -> +0x114
dynimm 7102d60ac4   # mov w8, #1920 -> +0xe4 (size above 1280x720)
dynimm 7102d60ad4   # mov w9, #1080 -> +0xe8
dynimm 7102d699c0   # mov w24, #1920 (mode buffer)
dynimm 7102d699c4   # mov w23, #1080
dynimm 7102ecb820   # mov w1, #1920 -> f_7101093270(obj, w, h)
dynimm 7102ecb824   # mov w2, #1080
dynimm 7102ecbd08   # mov w1, #1920 -> f_7101093270(obj, w, h)
dynimm 7102ecbd10   # mov w2, #1080
dynimm 7103ae0c50   # mov w1, #1920
dynimm 7103ae0c54   # mov w2, #1080

# The size the game hands its DLSS setup (main+0x5ae2190: w8/w9 = object +0x210/+0x214, 1920x1080 docked): an inline hook
# before they are stored can give another output size. The DLSS layer clamps its inputs to 2048x1152 (main+0x5b64860..):
# those compares and limits read their immediates from guest memory so the limit can follow.
inline 7105ae21b0   # stp w8, w9, [sp, #0x8]: w8 = width, w9 = height of the DLSS output
dynimm 7105b64860   # cmp w16, #0x800
dynimm 7105b64864   # mov w17, #0x800
dynimm 7105b64868   # mov w18, #0x480
dynimm 7105b64870   # cmp w15, #0x480
dynimm 7105b64878   # cmp w8, #0x800
dynimm 7105b64880   # cmp w9, #0x480
dynimm 7105b64888   # cmp w14, #0x800
dynimm 7105b64890   # cmp w13, #0x480

# The same 2048x1152 input limit in the DLSS layer's other set-up paths (the menu's 3D used one of them: 80% of a 4K frame),
# each also guarded by a pixel-count compare against 0x240000 (2048 * 1152).
dynimm 7105b64b48
dynimm 7105b64b50
dynimm 7105b64b60
dynimm 7105b64b68
dynimm 7105b64d14
dynimm 7105b64f08
dynimm 7105b64f10
dynimm 7105b64f14
dynimm 7105b64f1c
dynimm 7105b64f20
dynimm 7105b64ff4
dynimm 7105b64ffc
dynimm 7105b65000
dynimm 7105b65008
dynimm 7105b6500c
dynimm 7105b651c0
dynimm 7105b651c8
dynimm 7105b651cc
dynimm 7105b651d4
dynimm 7105b651d8

# The docked output size also lives in code as a packed constant (mov x8, #2560; movk x8, #1440, lsl #32): the final picture's
# target (main+0x5b6284c) and two copies of the preset table the DLSS layer builds in .bss (main+0x93b7420, +0x93b7440).
# Inline hooks after the movk let the runtime give them the rodata table's first entry (main+0x5f5bbe8).
inline 7105b62858   # x8 = 2560 | 1440 << 32 -> stur x8, [sp, #0x3c]
inline 7105b64758   # stp x8, x9, [x10] (x8 = docked, x9 = 1920x1080)
inline 7105b647e8   # stp x8, x9, [x10]

# The DLSS layer's 27 render-target kinds get their size from main+0x5b74840(kind) (a switch; many kinds are hard-coded to
# the 1440p output). Entry: x0 = kind; common exit main+0x5b7540c: x0 = width | height << 32. The final picture is one of them.
inline 7105b7484c   # mov w8, w0 (x0 = kind)
inline 7105b7540c   # ldp x29, x30 (x0 = the size)

# The engine's display buffers (the frame the game presents): sized from a screen-info record a global object returns
# (main+0xf344a0, blr; x0 = record, +0x10 width, +0x14 height = 2560x1440 docked).
inline 7100f344a4   # ldr w8, [x0, #0x10]

# Engine window size (monitor-matched output work): after the window object x20 took min(requested w24 x w23, its maximum at
# +0x3d8/+0x3dc) into +0x28; xc2_boot.cpp logs it and KAR_WIN_WH overrides it.
inline 7104c3e10c   # adrp x8 (w24 x w23 = the window size)
inline 7104c3de00   # ldp w9, w8, [x29, #0x18]: the window maximum (+0x18 height, +0x1c width) after the MaxWindow settings
# More copies of the packed docked output 2560 | 1440 << 32 (native-output work): the register is replaced by the rodata entry.
inline 7105b60ad8   # stp x9, x8, [x29, #-0xb0] (x9; the DLSS layer's input textures, main+0x5b60a80)
inline 7105b6790c   # str x20, [x8]
inline 7105b742a8   # stp x9, x8, [sp, #0x28]

# The game's frame limiter (f_7100fb22fc) reads its target rate here: ldr d8, [x8] (x21 = the settings object). An inline hook puts
# the F1 frame rate ([kar] fps > 60) there, since the game writes 60 back every frame.
inline 7100fb2350   # ldr d8, [x8]: target rate of the frame limiter
