Skip to content

Commit 5c138aa

Browse files
committed
fix: multiple fixes
- Big features are no longer global. - Organize big features and related classes/subclasses into their own subfolders. - Fix GUI not calling a function to draw requested windows. - Rename API version enum to eGameBranch since we're no longer basing compatibility on the version of YimMenu.
1 parent 291ba39 commit 5c138aa

99 files changed

Lines changed: 1412 additions & 1153 deletions

File tree

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: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@
88

99

1010
local PreviewService = require("includes.services.PreviewService")
11-
local function ClearPreview()
12-
PreviewService:Clear()
13-
end
11+
local ClearPreview = function() PreviewService:Clear() end
12+
1413

1514
---@class BlipData
1615
---@field handle integer
1716
---@field owner integer
1817
---@field alpha integer
1918

20-
---@enum eAPIVersion
21-
Enums.eAPIVersion = {
22-
V1 = 1, -- YimMenu V1 (Lua54)
23-
V2 = 2, -- YimLuaAPI (Lua 54)
24-
L54 = 99, -- Mock environment (Lua54)
19+
---@enum eGameBranch
20+
Enums.eGameBranch = {
21+
LAGECY = 1,
22+
ENHANCED = 2,
23+
MOCK = 99,
2524
}
2625

2726
---@enum eBackendEvent
@@ -32,7 +31,7 @@ Enums.eBackendEvent = {
3231
}
3332

3433
---@enum eEntityType
35-
Enums.eEntityType = {
34+
Enums.eEntityType = {
3635
Invalid = -1,
3736
Ped = 1,
3837
Vehicle = 2,
@@ -41,8 +40,8 @@ Enums.eEntityType = {
4140

4241
-- Global Singleton.
4342
---@class Backend
44-
---@field private api_version eAPIVersion
45-
local Backend = {
43+
---@field private m_game_branch eGameBranch
44+
local Backend = {
4645
__version = "",
4746
target_build = "",
4847
target_version = "",
@@ -79,28 +78,30 @@ local Backend = {
7978
[Enums.eEntityType.Vehicle] = 15,
8079
[Enums.eEntityType.Object] = 35,
8180
},
81+
---@type table<string, fun(handle: handle): any>
82+
FeatureEntityHandlers = {}
8283
}
83-
Backend.__index = Backend
84+
Backend.__index = Backend
8485

8586
---@param name string
8687
---@param script_version string
8788
---@param game_version? GAME_VERSION
8889
function Backend:init(name, script_version, game_version)
89-
local api_ver = self:GetAPIVersion()
90-
self.api_version = api_ver
90+
local branch = self:GetGameBranch()
91+
self.m_game_branch = branch
9192
self.script_name = name
9293
self.__version = script_version
93-
self.target_build = game_version and game_version[api_ver].build or "any"
94-
self.target_version = game_version and game_version[api_ver].online or "any"
94+
self.target_build = game_version and game_version[branch].build or "any"
95+
self.target_version = game_version and game_version[branch].online or "any"
9596

96-
require("includes.lib.compat").SetupEnv(self.api_version)
97+
require("includes.lib.compat").SetupEnv(self.m_game_branch)
9798
return self
9899
end
99100

100-
---@return eAPIVersion
101-
function Backend:GetAPIVersion()
102-
if (self.api_version) then
103-
return self.api_version
101+
---@return eGameBranch
102+
function Backend:GetGameBranch()
103+
if (self.m_game_branch) then
104+
return self.m_game_branch
104105
end
105106

106107
if (not script or (type(script) ~= "table")) then
@@ -109,36 +110,37 @@ function Backend:GetAPIVersion()
109110
error("Failed to load: Unknown or unsupported Lua environment.")
110111
end
111112

112-
self.api_version = Enums.eAPIVersion.L54
113-
return self.api_version
113+
self.m_game_branch = Enums.eGameBranch.MOCK
114+
return self.m_game_branch
114115
end
115116

116117
if (type(script["run_in_callback"]) == "function") then
117118
error("YimMenuV2 is not supported. If you want to run this script in GTA V Enhanced, download YimLuaAPI.")
118119
end
119120

120121
if (not menu_event or not menu_event.Wndproc) then
121-
error("Unknown or unsupported game branch.")
122+
error("Unknown or unsupported API.")
122123
end
123124

124-
local ylapi_func = _G["get_game_branch"]
125-
if (type(ylapi_func) ~= "function") then
126-
self.api_version = Enums.eAPIVersion.V1
127-
return self.api_version
125+
---@type (fun(): integer)?
126+
local get_game_branch = _G["get_game_branch"]
127+
if (type(get_game_branch) ~= "function") then
128+
self.m_game_branch = Enums.eGameBranch.LAGECY
129+
return self.m_game_branch
128130
end
129131

130-
local branch = ylapi_func()
132+
local branch = get_game_branch()
131133
if (type(branch) ~= "number" or branch > 1) then
132134
error("Failed to load: Unknown or unsupported game branch.")
133135
end
134136

135-
self.api_version = branch + 1
136-
return self.api_version
137+
self.m_game_branch = branch + 1 -- Our own eGameBranch starts at 1 to make it compatible with Lua table indices. YimLuaAPI's naturally starts at 0
138+
return self.m_game_branch
137139
end
138140

139141
---@return boolean
140142
function Backend:IsMockEnv()
141-
return self:GetAPIVersion() == Enums.eAPIVersion.L54
143+
return self:GetGameBranch() == Enums.eGameBranch.MOCK
142144
end
143145

144146
---@return boolean
@@ -274,18 +276,18 @@ function Backend:RemoveBlip(owner)
274276
self.CreatedBlips[owner] = nil
275277
end
276278

279+
---@param name string
280+
---@param callback fun(handle: handle): any
281+
function Backend:RegisterFeatureEntityHandler(name, callback)
282+
self.FeatureEntityHandlers[name] = callback
283+
end
284+
277285
---@param handle integer
278286
function Backend:CheckFeatureEntities(handle)
279-
if Decorator:ExistsOn(handle, "EntityForge") then
280-
EntityForge:RemoveEntityByHandle(handle)
281-
end
282-
283-
if Decorator:ExistsOn(handle, "BillionaireServices") then
284-
BillionaireServices:RemoveEntityByHandle(handle)
285-
end
286-
287-
if Decorator:ExistsOn(handle, "YimActions") then
288-
YimActions.CompanionManager:RemoveCompanionByHandle(handle)
287+
for featName, callback in pairs(self.FeatureEntityHandlers) do
288+
if (Decorator:ExistsOn(handle, featName)) then
289+
callback(handle)
290+
end
289291
end
290292
end
291293

SSV2/includes/data/actions/animations.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,7 +3018,7 @@ return {
30183018
label = "Ride Dick In Car",
30193019
dict = "mini@prostitutes@sexlow_veh",
30203020
name = "low_car_sex_loop_female",
3021-
category = "NSFW",
3021+
category = "In-Vehicle",
30223022
playbackRate = 1.0,
30233023
blendInSpeed = 4.0,
30243024
blendOutSpeed = -4.0,
@@ -3033,7 +3033,7 @@ return {
30333033
label = "Give Head In Car",
30343034
dict = "anim@mini@prostitutes@sex@veh_vstr@",
30353035
name = "bj_loop_prostitute",
3036-
category = "NSFW",
3036+
category = "In-Vehicle",
30373037
playbackRate = 1.0,
30383038
blendInSpeed = 4.0,
30393039
blendOutSpeed = -4.0,
@@ -3048,7 +3048,7 @@ return {
30483048
label = "Receive Head In Car",
30493049
dict = "anim@mini@prostitutes@sex@veh_vstr@",
30503050
name = "bj_loop_male",
3051-
category = "NSFW",
3051+
category = "In-Vehicle",
30523052
playbackRate = 1.0,
30533053
blendInSpeed = 4.0,
30543054
blendOutSpeed = -4.0,

SSV2/includes/data/actions/types.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
---@field rot vec3
2323
---@field pos vec3
2424
---@field delay float
25-
---@field scale float
25+
---@field scale? float
26+
---@field bone? integer
2627

2728
---@class AnimSFX
2829
---@field speechName string

SSV2/includes/data/pointers.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ function MemoryBatch.new(name, ida_sig, callback)
5959
}
6060
end
6161

62-
---@type table<eAPIVersion, array<MemoryBatch>>
62+
---@type table<eGameBranch, array<MemoryBatch>>
6363
local mem_batches <const> = {
64-
[Enums.eAPIVersion.V1] = {
64+
[Enums.eGameBranch.LAGECY] = {
6565
MemoryBatch.new("ScriptGlobals", "48 8D 15 ? ? ? ? 4C 8B C0 E8 ? ? ? ? 48 85 FF 48 89 1D", function(ptr)
6666
GPointers.ScriptGlobals = ptr:add(0x3):rip()
6767
end),
@@ -94,7 +94,7 @@ local mem_batches <const> = {
9494
-- GPointers.DynamicFuncs.BreakOffVehicleWheel = _G[func_name]
9595
-- end),
9696
},
97-
[Enums.eAPIVersion.V2] = {
97+
[Enums.eGameBranch.ENHANCED] = {
9898
MemoryBatch.new("ScriptGlobals", "48 8B 8E B8 00 00 00 48 8D 15 ? ? ? ? 49 89 D8", function(ptr)
9999
GPointers.ScriptGlobals = ptr:add(0x7):add(0x3):rip()
100100
end),
@@ -110,10 +110,10 @@ local mem_batches <const> = {
110110
GPointers.ScreenResolution.y = ptr:add(0x1E):add(0x4):rip():get_word()
111111
end),
112112
},
113-
[Enums.eAPIVersion.L54] = { --[[dummy]] },
113+
[Enums.eGameBranch.MOCK] = { --[[dummy]] },
114114
}
115115

116-
local API_VERSON <const> = Backend:GetAPIVersion()
116+
local API_VERSON <const> = Backend:GetGameBranch()
117117
local batches = mem_batches[API_VERSON]
118118
for _, batch in ipairs(batches) do
119119
PatternScanner:Add(batch.m_name, batch.m_pattern, batch.m_callback)

SSV2/includes/features/BillionaireServicesV2.lua renamed to SSV2/includes/features/extra/billionaire_services/BillionaireServicesV2.lua

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
-- * Credit the owner and contributors.
77
-- * 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/>.
88

9+
10+
local Bodyguard = require("Bodyguard")
11+
local EscortGroup = require("EscortGroup")
12+
local PrivateHeli = require("PrivateHeli")
13+
local PrivateJet = require("PrivateJet")
14+
local PrivateLimo = require("PrivateLimo")
15+
916
local BSV2Data = require("includes.data.bsv2_data")
1017
local GroupManager = require("includes.services.GroupManager")
1118
local RandomPedNames = require("includes.data.ped_names")
12-
local Bodyguard = require("includes.modules.BSV2.Bodyguard")
13-
local EscortGroup = require("includes.modules.BSV2.EscortGroup")
14-
local PrivateHeli = require("includes.modules.BSV2.PrivateHeli")
15-
local PrivateJet = require("includes.modules.BSV2.PrivateJet")
16-
local PrivateLimo = require("includes.modules.BSV2.PrivateLimo")
1719

1820
---@alias ServiceType integer
1921
---| -1 # ALL
@@ -64,24 +66,23 @@ local PrivateLimo = require("includes.modules.BSV2.PrivateLimo")
6466
---@field Bodyguards table<integer, Bodyguard>
6567
---@field EscortGroups table<string, EscortGroup>
6668
---@field EscortVehicles table<integer, EscortVehicle>
67-
local BillionaireServices = {}
68-
BillionaireServices.__index = BillionaireServices
69-
BillionaireServices.Bodyguards = {}
70-
BillionaireServices.EscortGroups = {}
71-
BillionaireServices.EscortVehicles = {}
72-
BillionaireServices.groups_file_name = "escort_groups.json"
73-
BillionaireServices.GroupManager = GroupManager
74-
BillionaireServices.GroupManager.globalTick = GroupManager.globalTick or 0
75-
BillionaireServices.EscortGroupsData = BSV2Data.DefaultEscortGroups
76-
BillionaireServices.SERVICE_TYPE = {
69+
---@field protected m_initialized boolean
70+
local BillionaireServices = {}
71+
BillionaireServices.__index = BillionaireServices
72+
BillionaireServices.Bodyguards = {}
73+
BillionaireServices.EscortGroups = {}
74+
BillionaireServices.EscortVehicles = {}
75+
BillionaireServices.groups_file_name = "escort_groups.json"
76+
BillionaireServices.EscortGroupsData = BSV2Data.DefaultEscortGroups
77+
BillionaireServices.SERVICE_TYPE = {
7778
ALL = -1,
7879
BODYGUARD = 0,
7980
ESCORT = 1,
8081
LIMO = 2,
8182
HELI = 3,
8283
JET = 4,
8384
}
84-
BillionaireServices.ActiveServices = {
85+
BillionaireServices.ActiveServices = {
8586
---@type PrivateLimo
8687
limo = nil,
8788
---@type PrivateHeli
@@ -90,7 +91,7 @@ BillionaireServices.ActiveServices = {
9091
jet = nil,
9192
}
9293

93-
BillionaireServices.VehicleTaskToString = {
94+
BillionaireServices.VehicleTaskToString = {
9495
[Enums.eVehicleTask.NONE] = "Idle.",
9596
[Enums.eVehicleTask.GOTO] = "Going to destination.",
9697
[Enums.eVehicleTask.WANDER] = "Cruising around.",
@@ -100,9 +101,20 @@ BillionaireServices.VehicleTaskToString = {
100101
[Enums.eVehicleTask.GO_HOME] = "Going home.",
101102
}
102103

104+
---@return BillionaireServices
103105
function BillionaireServices:init()
104-
self:ParseEscortGroups()
105-
Backend:RegisterEventCallbackAll(function() self:ForceCleanup() end)
106+
if (not self.m_initialized) then
107+
self:ParseEscortGroups()
108+
self.GroupManager = GroupManager:init(BillionaireServices)
109+
self.GroupManager.globalTick = GroupManager.globalTick or 0
110+
self.m_initialized = true
111+
112+
Backend:RegisterEventCallbackAll(function() self:ForceCleanup() end)
113+
Backend:RegisterFeatureEntityHandler("BillionaireServices", function(handle)
114+
self:RemoveEntityByHandle(handle)
115+
end)
116+
end
117+
106118
return self
107119
end
108120

@@ -243,6 +255,7 @@ function BillionaireServices:SpawnBodyguard(modelHash, name, spawnPos, weapon, g
243255
end
244256

245257
local ok, guard = pcall(Bodyguard.new,
258+
self,
246259
modelHash,
247260
name,
248261
spawnPos,
@@ -358,6 +371,7 @@ function BillionaireServices:SpawnEscortGroup(t_Data, godMode, noRagdoll, spawnP
358371

359372
local ok, group = pcall(EscortGroup.Spawn,
360373
EscortGroup,
374+
self,
361375
t_Data,
362376
godMode,
363377
noRagdoll,
@@ -478,7 +492,7 @@ function BillionaireServices:CallPrivateLimo(t_Data, spawnPos)
478492
return
479493
end
480494

481-
local ok, limo = pcall(PrivateLimo.Spawn, PrivateLimo, t_Data, spawnPos)
495+
local ok, limo = pcall(PrivateLimo.Spawn, PrivateLimo, self, t_Data, spawnPos)
482496
if (not ok or not limo) then
483497
Notifier:ShowWarning("Billionaire Services", _T("GENERIC_ENTITY_SPAWN_FAIL"))
484498
return
@@ -532,7 +546,7 @@ function BillionaireServices:CallPrivateHeli(model, godmode)
532546

533547
local isInWater = LocalPlayer:IsOnFoot() and LocalPlayer:IsInWater() or LocalPlayer:GetVehicle():IsBoat()
534548
local spawnPos = LocalPlayer:GetOffsetInWorldCoords(0.0, 30.0, 50.0)
535-
local ok, heli = pcall(PrivateHeli.spawn, model, spawnPos, godmode)
549+
local ok, heli = pcall(PrivateHeli.spawn, self, model, spawnPos, godmode)
536550

537551
if (not ok or not heli) then
538552
Notifier:ShowWarning("Billionaire Services", _T("GENERIC_ENTITY_SPAWN_FAIL"))
@@ -620,7 +634,7 @@ function BillionaireServices:CallPrivateJet(model, airportData)
620634
return
621635
end
622636

623-
local ok, jet = pcall(PrivateJet.spawn, model, airportData)
637+
local ok, jet = pcall(PrivateJet.spawn, self, model, airportData)
624638
if (not ok or not jet) then
625639
Notifier:ShowWarning("Billionaire Services", _T("GENERIC_ENTITY_SPAWN_FAIL"))
626640
return
@@ -822,4 +836,4 @@ function BillionaireServices:ForceCleanup()
822836
self.EscortVehicles = {}
823837
end
824838

825-
return BillionaireServices
839+
return BillionaireServices:init()

0 commit comments

Comments
 (0)