-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunsafe_api.lua
More file actions
55 lines (51 loc) · 1.82 KB
/
unsafe_api.lua
File metadata and controls
55 lines (51 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local ffi = require("ffi")
ffi.cdef([[
typedef unsigned short USHORT;
USHORT GetAsyncKeyState(int vKey);
]])
---The unsafe api represents an extension to the main game api that is usable everywhere, but requires direct memory editing to work.
local M
---@class unsafe_api
M = {
---@class addrs
addrs = {
player_body_addr = 0x1401f49a0, -- the player body id global for md5 8bae632057a197aae64f6c1d3a2bfb40
---@class addrs_cell
cell = {
default = 0x1401f2dd8, -- 8bae632057a197aae64f6c1d3a2bfb40
num_cells = 0x1401f4510, -- 8bae632057a197aae64f6c1d3a2bfb40
other_num_cells = 0x140501e20, -- 8bae632057a197aae64f6c1d3a2bfb40
index_array = 0x1404fde20, -- 8bae632057a197aae64f6c1d3a2bfb40
probabilities_array_start = 0x1404ffe20, -- 8bae632057a197aae64f6c1d3a2bfb40
array_start = 0x1401f4508, -- 8bae632057a197aae64f6c1d3a2bfb40
},
},
const = {
cell = {
size = 0xb8, -- 8bae632057a197aae64f6c1d3a2bfb40
},
},
---Throws an error if this function is outdated, currently it requires updating with every game version. If this function doesn't error it worked.
---@param id body_id
set_player_body_id = function(id)
local p_player_body_id = ffi.cast("int *", M.addrs.player_body_addr)
local old_id = get_player_body_id()
if p_player_body_id[0] ~= old_id then
error("Set player body id has an outdated address")
end
p_player_body_id[0] = id
if p_player_body_id[0] ~= get_player_body_id() then
p_player_body_id[0] = old_id
error("Set player body id just corrupted some random memory, attempting to recover")
end
end,
---Returns whether the key is currently pressed, not tied to the framerate.
---@param code key_code
---@return boolean
key_pressed = function(code)
local state = ffi.C.GetAsyncKeyState(code)
local pressed = bit.band(state, bit.lshift(1, 15)) ~= 0
return pressed
end,
}
return M