mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
In-game mods (GameBanana browser, search and installs, with the Mask Salesman), code-patch and cheat mods, the devs' test18 to test45 work (full performance overlay, frame pacing on, steady frame rate, save export and import, bug capture, new options rows, Setup's Mods page and Add to Steam), occlusion queries and new defaults, Auto resolution that scales, replay helper threads and robust buffers off by default, the options in sections.
22 lines
1.1 KiB
C
22 lines
1.1 KiB
C
/* (Triforce) Bounds checks on what the game passes in that cannot overflow. A check written as `first + n > cap` wraps
|
|
around when the game's offset or count is huge (in 32 bits for ints, in 64 for addresses) and lets the range through;
|
|
these compare by subtraction, in 64 bits, so a range that does not fit is refused whatever its size.
|
|
Plain functions: tests/test_guest_bounds.py compiles and runs them against the old expressions. */
|
|
#pragma once
|
|
#include <stdint.h>
|
|
|
|
/* [first, first + n) lies in [0, cap): a start and a count as the game gave them (ints widened, a negative one refused) */
|
|
static inline int hos_span_ok(int64_t first, int64_t n, int64_t cap) {
|
|
return first >= 0 && n >= 0 && first <= cap && n <= cap - first;
|
|
}
|
|
|
|
/* [at, at + n) lies in [0, end): addresses and sizes, unsigned */
|
|
static inline int hos_range_ok(uint64_t at, uint64_t n, uint64_t end) {
|
|
return at <= end && n <= end - at;
|
|
}
|
|
|
|
/* how many of the n units from x lie in a cap-wide row: n, or what is left after x (0 from cap on) */
|
|
static inline uint32_t hos_span_clip(uint32_t x, uint32_t n, uint32_t cap) {
|
|
return x >= cap ? 0 : (uint64_t)x + n <= cap ? n : cap - x;
|
|
}
|