Skip to content

Commit 9dab543

Browse files
authored
Merge pull request #137 from YimMenu-Lua/misc_fixes
Misc fixes
2 parents e2d85cd + 11c78cf commit 9dab543

67 files changed

Lines changed: 3143 additions & 1206 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SSV2/includes/backend.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ Enums.eEntityType = {
3131
Object = 3
3232
}
3333

34+
3435
-- Global Singleton.
3536
---@class Backend
3637
---@field private m_game_branch eGameBranch
37-
local Backend = {
38+
local Backend = {
3839
__version = "",
3940
target_build = "",
4041
target_version = "",
@@ -71,10 +72,13 @@ local Backend = {
7172
[Enums.eEntityType.Vehicle] = 15,
7273
[Enums.eEntityType.Object] = 35,
7374
},
75+
7476
---@type table<string, fun(handle: handle): any>
75-
FeatureEntityHandlers = {}
76-
}
77-
Backend.__index = Backend
77+
FeatureEntityHandlers = {},
78+
79+
---@type table<int64_t, pointer>
80+
AllocatedPointers = {}
81+
}; Backend.__index = Backend
7882

7983
---@param name string
8084
---@param script_version string
@@ -418,6 +422,10 @@ end
418422
function Backend:Cleanup()
419423
self:EntitySweep()
420424
self:TriggerEventCallbacks(Enums.eBackendEvent.RELOAD_UNLOAD)
425+
426+
for _, ptr in pairs(self.AllocatedPointers) do
427+
free(ptr)
428+
end
421429
end
422430

423431
function Backend:OnSessionSwitch()

SSV2/includes/classes/gta/fVector3.lua

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ local __base_fields__ <const> = {
1313
z = 0x8
1414
}
1515

16+
---@param ptr pointer
17+
local function ptr_to_vec3(ptr)
18+
return vec3:new(
19+
ptr:add(0x0):get_float(),
20+
ptr:add(0x4):get_float(),
21+
ptr:add(0x8):get_float()
22+
)
23+
end
24+
1625
--------------------------------------
1726
-- Class: fVector3
1827
--------------------------------------
@@ -26,7 +35,7 @@ local __base_fields__ <const> = {
2635
---@field public x float
2736
---@field public y float
2837
---@field public z float
29-
---@field public new fun(ptr: pointer): fVector3 -- static
38+
---@field public new fun(ptr: pointer): fVector3 -- static func
3039
---@field public as_vec3 fun(self: fVector3): vec3 -- method
3140
---@overload fun(ptr: pointer): fVector3
3241
local fVector3 <const> = setmetatable({}, {
@@ -46,13 +55,7 @@ function fVector3:__index(key)
4655
end
4756

4857
if (key == "as_vec3") then
49-
return function()
50-
return vec3:new(
51-
ptr:add(0x0):get_float(),
52-
ptr:add(0x4):get_float(),
53-
ptr:add(0x8):get_float()
54-
)
55-
end
58+
return ptr_to_vec3(ptr)
5659
end
5760

5861
---@diagnostic disable-next-line: param-type-mismatch

SSV2/includes/classes/gta/rlGamerInfo.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ end
4747

4848
---@return string
4949
function IPAddress:__tostring()
50+
local packed = self.m_packed
5051
return _F("%d.%d.%d.%d",
51-
self.m_packed.x,
52-
self.m_packed.y,
53-
self.m_packed.z,
54-
self.m_packed.w
52+
packed.x,
53+
packed.y,
54+
packed.z,
55+
packed.w
5556
)
5657
end
5758

SSV2/includes/data/globals_locals.lua

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,60 @@ return {
2222
capture_group = 1
2323
}
2424
},
25+
gpbd_fm_3 = {
26+
description = "GPBD_FM_3",
27+
file = "freemode.c",
28+
LEGACY = {
29+
value = 1892653,
30+
pattern = [[if\s+\(!MISC::IS_STRING_NULL_OR_EMPTY\(\w+\)\)$\n\s+?\{$\n\s+?TEXT_LABEL_ASSIGN_STRING\(&\(Global_(\d{7})\[.*?/\*(\d+)\*/\]\.f_10\.f_343\), \w+, 64\);]],
31+
capture_group = 1,
32+
offsets = {
33+
{
34+
value = 615,
35+
capture_group = 2,
36+
description = "player id size",
37+
},
38+
}
39+
},
40+
ENHANCED = {
41+
value = 1892798,
42+
pattern = [[if\s+\(!MISC::IS_STRING_NULL_OR_EMPTY\(\w+\)\)$\n\s+?\{$\n\s+?TEXT_LABEL_ASSIGN_STRING\(&\(Global_(\d{7})\[.*?/\*(\d+)\*/\]\.f_10\.f_343\), \w+, 64\);]],
43+
capture_group = 1,
44+
offsets = {
45+
{
46+
value = 615,
47+
capture_group = 2,
48+
description = "player id size",
49+
},
50+
}
51+
}
52+
},
53+
freemode_boss_stuff = {
54+
description = "freemode global",
55+
file = "freemode.c",
56+
LEGACY = {
57+
value = 2733002,
58+
pattern = [[if\s+\(!func_\d+\(4\) && !.*?\(Global_(\d{7})\.f_(\d{3}), 4\)\)]],
59+
capture_group = 1,
60+
offsets = {
61+
{
62+
value = 925,
63+
capture_group = 2,
64+
},
65+
}
66+
},
67+
ENHANCED = {
68+
value = 2733138,
69+
pattern = [[if\s+\(!func_\d+\(4\) && !.*?\(Global_(\d{7})\.f_(\d{3}), 4\)\)]],
70+
capture_group = 1,
71+
offsets = {
72+
{
73+
value = 926,
74+
capture_group = 2,
75+
},
76+
}
77+
}
78+
},
2579
freemode_business_global = {
2680
description = "Freemode Business Global",
2781
file = "freemode.c",

SSV2/includes/data/handling_presets.lua

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
-- On the up side, the raw data will be much more readavle.
1616

1717

18-
local CARS_BIT <const> = Enums.eVehicleType.VEHICLE_TYPE_CAR
19-
local BIKES_BIT <const> = Enums.eVehicleType.VEHICLE_TYPE_BIKE
18+
local ALLOW_CARS <const> = 1 << Enums.eVehicleType.VEHICLE_TYPE_CAR
19+
local ALLOW_BIKES <const> = 1 << Enums.eVehicleType.VEHICLE_TYPE_BIKE
20+
local ALLOW_BOTH <const> = ALLOW_CARS | ALLOW_BIKES
2021

2122
---@type array<HandlingPresetData>
2223
return {
@@ -26,39 +27,39 @@ return {
2627
is_translator_name = true,
2728
auto_apply = true,
2829
deltas = { [Enums.eHandlingEditorTypes.TYPE_HF] = { ["FREEWHEEL_NO_GAS"] = true } },
29-
vehicle_bitset = 1 << CARS_BIT | 1 << BIKES_BIT,
30+
vehicle_bitset = ALLOW_BOTH,
3031
},
3132
{
3233
name = "VEH_WHEELIE",
3334
description = "VEH_WHEELIE_TT",
3435
is_translator_name = true,
3536
auto_apply = false,
3637
deltas = { [Enums.eHandlingEditorTypes.TYPE_AF] = { ["CAN_WHEELIE"] = true } },
37-
vehicle_bitset = 1 << CARS_BIT,
38+
vehicle_bitset = ALLOW_CARS,
3839
},
3940
{
4041
name = "VEH_KERS_BOOST",
4142
description = "VEH_KERS_BOOST_TT",
4243
is_translator_name = true,
4344
auto_apply = false,
4445
deltas = { [Enums.eHandlingEditorTypes.TYPE_HF] = { ["HAS_KERS"] = true } },
45-
vehicle_bitset = 1 << CARS_BIT
46+
vehicle_bitset = ALLOW_CARS
4647
},
4748
{
4849
name = "VEH_ROCKET_BOOST",
4950
description = "VEH_ROCKET_BOOST_TT",
5051
is_translator_name = true,
5152
auto_apply = false,
5253
deltas = { [Enums.eHandlingEditorTypes.TYPE_MIF] = { ["HAS_ROCKET_BOOST"] = true } },
53-
vehicle_bitset = 1 << CARS_BIT | 1 << BIKES_BIT
54+
vehicle_bitset = ALLOW_BOTH
5455
},
5556
{
5657
name = "VEH_JUMP",
5758
description = "VEH_JUMP_TT",
5859
is_translator_name = true,
5960
auto_apply = false,
6061
deltas = { [Enums.eHandlingEditorTypes.TYPE_MIF] = { ["JUMPING_CAR"] = true, ["HAS_PARACHUTE"] = true, } },
61-
vehicle_bitset = 1 << CARS_BIT
62+
vehicle_bitset = ALLOW_CARS
6263
},
6364
{
6465
name = "VEH_OFFROAD_ABILITIES",
@@ -83,7 +84,7 @@ return {
8384
},
8485
[Enums.eHandlingEditorTypes.TYPE_MIF] = { ["INCREASE_LOW_SPEED_TORQUE"] = true, },
8586
},
86-
vehicle_bitset = 1 << CARS_BIT
87+
vehicle_bitset = ALLOW_CARS
8788
},
8889
{
8990
name = "VEH_FORCE_NO_TC",
@@ -104,7 +105,7 @@ return {
104105
["DONT_HOLD_LOW_GEARS_WHEN_ENGINE_UNDER_LOAD"] = false,
105106
},
106107
},
107-
vehicle_bitset = 1 << CARS_BIT | 1 << BIKES_BIT
108+
vehicle_bitset = ALLOW_BOTH
108109
},
109110
{
110111
name = "VEH_LOW_SPEED_WHEELIE",
@@ -113,7 +114,7 @@ return {
113114
auto_apply = false,
114115
deltas = {
115116
[Enums.eHandlingEditorTypes.TYPE_HF] = { ["LOW_SPEED_WHEELIES"] = true } },
116-
vehicle_bitset = 1 << BIKES_BIT
117+
vehicle_bitset = ALLOW_BIKES
117118
},
118119
{
119120
name = "VEH_RAMP",
@@ -131,6 +132,6 @@ return {
131132
["RAMP_MOD"] = true,
132133
},
133134
},
134-
vehicle_bitset = 1 << CARS_BIT
135+
vehicle_bitset = ALLOW_CARS
135136
},
136137
}

SSV2/includes/data/pointers.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ local GPointers = {
3737
GameTime = nullptr,
3838
GameVersion = { build = "", online = "" },
3939
ScreenResolution = vec2:zero(),
40+
DynamicFuncs = {}
4041
}
4142

42-
GPointers.DynamicFuncs = {}
43-
4443

4544
---@class MemoryBatch
4645
---@field m_name string

SSV2/includes/data/refs.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,10 @@ return {
457457
"Willard",
458458
"Zirconium",
459459
},
460+
461+
InteriorIDs = {
462+
INTERIOR_ID_OFFICE = 240641,
463+
INTERIOR_ID_CLUBHOUSE = 246273,
464+
INTERIOR_ID_HANGAR = 260353,
465+
},
460466
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- Copyright (C) 2026 SAMURAI (xesdoog) & Contributors.
2+
-- This file is part of Samurai's Scripts.
3+
--
4+
-- Permission is hereby granted to copy, modify, and redistribute
5+
-- this code as long as you respect these conditions:
6+
-- * Credit the owner and contributors.
7+
-- * Provide a copy of or a link to the original license (GPL-3.0 or later); see LICENSE.md or <https://www.gnu.org/licenses/>.
8+
9+
10+
local SGSL = require("includes.services.SGSL")
11+
12+
13+
-- No this is not a typo. Double G's my G!
14+
--
15+
-- Script globals stored and exposed globally. Can be used for caching as well *(though SGSL already does that)*
16+
---@class GGlobals
17+
---@field GPBD_FM_3 ScriptGlobal
18+
---@field MP_BUSINESS_STUFF ScriptGlobal
19+
---@field FREEMODE_GLOBAL ScriptGlobal
20+
local GGlobals = {}
21+
GGlobals.__index = GGlobals
22+
23+
-- Register globals here. Functions will be executed when GGlobals:init is called.
24+
---@type array<function>
25+
local GlobalsRegistry <const> = {
26+
function()
27+
GGlobals.GPBD_FM_3 = SGSL:Get(SGSL.data.gpbd_fm_3):AsGlobal()
28+
end,
29+
function()
30+
GGlobals.MP_BUSINESS_STUFF = SGSL:Get(SGSL.data.mp_business_stuff):AsGlobal()
31+
end,
32+
function()
33+
GGlobals.FREEMODE_GLOBAL = SGSL:Get(SGSL.data.freemode_boss_stuff):AsGlobal()
34+
end,
35+
}
36+
37+
function GGlobals:Init()
38+
for _, func in ipairs(GlobalsRegistry) do
39+
pcall(func)
40+
end
41+
end
42+
43+
return GGlobals

0 commit comments

Comments
 (0)