Skip to content

Commit 7c6943f

Browse files
authored
Merge pull request YimMenu-Lua#86 from acidlabsdev/main
refactor(YRV3): refactor businesses into objects
2 parents 508c560 + c369617 commit 7c6943f

199 files changed

Lines changed: 4231 additions & 1459 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: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
---@diagnostic disable: lowercase-global
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+
29

310
local PreviewService = require("includes.services.PreviewService")
411
local function ClearPreview()
@@ -35,36 +42,38 @@ Enums.eEntityType = {
3542
---@class Backend
3643
---@field private api_version eAPIVersion
3744
local Backend = {
38-
__version = "",
39-
target_build = "",
40-
target_version = "",
41-
disable_input = false, -- Never serialize this runtime variable!
45+
__version = "",
46+
target_build = "",
47+
target_version = "",
48+
disable_input = false, -- Never serialize this runtime variable!
49+
is_in_session_transition = false,
50+
is_in_player_transition = false,
4251

4352
---@type table<integer, integer>
44-
ControlsToDisable = {},
53+
ControlsToDisable = {},
4554

4655
---@type table<integer, BlipData>
47-
CreatedBlips = {},
56+
CreatedBlips = {},
4857

4958
---@type array<handle>
50-
AttachedEntities = {},
59+
AttachedEntities = {},
5160

5261
---@type table<eBackendEvent, array<function>>
53-
EventCallbacks = {
62+
EventCallbacks = {
5463
[Enums.eBackendEvent.RELOAD_UNLOAD] = { ClearPreview },
5564
[Enums.eBackendEvent.SESSION_SWITCH] = { ClearPreview },
5665
[Enums.eBackendEvent.PLAYER_SWITCH] = { ClearPreview }
5766
},
5867

5968
---@type table<eEntityType, table<handle, handle>>
60-
SpawnedEntities = {
69+
SpawnedEntities = {
6170
[Enums.eEntityType.Ped] = {},
6271
[Enums.eEntityType.Vehicle] = {},
6372
[Enums.eEntityType.Object] = {},
6473
},
6574

6675
---@type table<eEntityType, integer>
67-
MaxAllowedEntities = {
76+
MaxAllowedEntities = {
6877
[Enums.eEntityType.Ped] = 50,
6978
[Enums.eEntityType.Vehicle] = 25,
7079
[Enums.eEntityType.Object] = 75,
@@ -411,29 +420,47 @@ function Backend:Cleanup()
411420
end
412421

413422
function Backend:OnSessionSwitch()
423+
if (self.is_in_session_transition) then
424+
return
425+
end
426+
414427
if (not script.is_active("maintransition")) then
415428
return
416429
end
417430

418-
self:TriggerEventCallbacks(Enums.eBackendEvent.SESSION_SWITCH)
431+
self.is_in_session_transition = true
432+
ThreadManager:Run(function()
433+
self:TriggerEventCallbacks(Enums.eBackendEvent.SESSION_SWITCH)
419434

420-
repeat
421-
sleep(100)
422-
until not script.is_active("maintransition")
423-
sleep(1000)
435+
while (script.is_active("maintransition")) do
436+
yield()
437+
end
438+
439+
sleep(1000)
440+
self.is_in_session_transition = false
441+
end)
424442
end
425443

426444
function Backend:OnPlayerSwitch()
445+
if (self.is_in_player_transition) then
446+
return
447+
end
448+
427449
if (not self:IsPlayerSwitchInProgress()) then
428450
return
429451
end
430452

431-
self:TriggerEventCallbacks(Enums.eBackendEvent.PLAYER_SWITCH)
453+
self.is_in_player_transition = true
454+
455+
ThreadManager:Run(function()
456+
self:TriggerEventCallbacks(Enums.eBackendEvent.PLAYER_SWITCH)
432457

433-
repeat
434-
sleep(100)
435-
until not self:IsPlayerSwitchInProgress()
436-
sleep(1000)
458+
while (self:IsPlayerSwitchInProgress()) do
459+
yield()
460+
end
461+
462+
self.is_in_player_transition = false
463+
end)
437464
end
438465

439466
function Backend:RegisterHandlers()

SSV2/includes/classes/Mutex.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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+
110
--------------------------------------
211
-- Class: Mutex
312
--------------------------------------

SSV2/includes/classes/Pair.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
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+
--------------------------------------
11+
-- Class: Pair
12+
--------------------------------------
113
---@class Pair<K, V> : { first: K, second: V }
214
Pair = {}
315
Pair.__index = Pair

SSV2/includes/classes/Range.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
---@diagnostic disable: param-type-mismatch
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+
29

310
--------------------------------------
411
-- Class: Range
@@ -12,6 +19,7 @@
1219
---@overload fun(from: number, to: number, step?: number): Range
1320
Range = {}
1421
Range.__index = Range
22+
---@diagnostic disable-next-line
1523
setmetatable(Range, {
1624
__call = function(_, from, to, step)
1725
return Range.new(from, to, step)
@@ -31,17 +39,14 @@ function Range.new(from, to, step)
3139
m_min = from,
3240
m_max = to,
3341
m_step = step,
42+
---@diagnostic disable-next-line
3443
}, Range)
3544
end
3645

3746
---@param value number
3847
---@return boolean
3948
function Range:Contains(value)
40-
if (self.m_step > 0) then
41-
return value >= self.m_min and value <= self.m_max -- or math.inrange(value, self.m_min, self.m_max)
42-
else
43-
return value <= self.m_min and value >= self.m_max
44-
end
49+
return value >= self.m_min and value <= self.m_max -- or math.isinrange(value, self.m_min, self.m_max)
4550
end
4651

4752
---@return fun(): number Iterator

SSV2/includes/classes/Rect.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
---@diagnostic disable: param-type-mismatch
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/>.
28

9+
10+
--------------------------------------
11+
-- Class: Rect
12+
--------------------------------------
313
---@class Rect
414
---@field min vec2
515
---@field max vec2
616
---@overload fun(min: vec2, max: vec2) : Rect
717
Rect = {}
818
Rect.__index = Rect
19+
---@diagnostic disable-next-line
920
setmetatable(Rect, {
1021
__call = function(_, ...)
1122
return Rect.new(...)
@@ -16,6 +27,7 @@ setmetatable(Rect, {
1627
---@param max vec2
1728
---@return Rect
1829
function Rect.new(min, max)
30+
---@diagnostic disable-next-line
1931
return setmetatable({ min = min, max = max }, Rect)
2032
end
2133

SSV2/includes/classes/Set.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
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+
--------------------------------------
11+
-- Class: Set
12+
--------------------------------------
113
---@generic T
214
---@class Set<T> : { [T]: true }
315
---@field protected m_data table<anyval, true>

SSV2/includes/classes/Vector2.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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+
110
---@diagnostic disable: unknown-operator
211

312
--------------------------------------

SSV2/includes/classes/Vector3.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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+
110
---@diagnostic disable: unknown-operator
211

312
--------------------------------------

SSV2/includes/classes/Vector4.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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+
110
---@diagnostic disable: unknown-operator
211

312
--------------------------------------

SSV2/includes/classes/gta/CBaseSubHandlingData.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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+
110
---@class CBaseSubHandlingData
211
---@field protected m_ptr pointer
312
---@field protected m_handling_type pointer<int32_t> -- 0x00C8

0 commit comments

Comments
 (0)