Skip to content

Commit 9bef125

Browse files
committed
chore(Serializer): make use of the new os.rename
- With this, configs should no longer get corrupted and even if they do, a backup is always available. > [!Note] > For YimLuaAPI compatibility, this relies on TupoyeMenu/YimLuaAPI#3
1 parent 47cb5ee commit 9bef125

17 files changed

Lines changed: 478 additions & 353 deletions

File tree

SSV2/includes/backend.lua

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ function Backend:OnPlayerSwitch()
456456
end
457457

458458
self.is_in_player_transition = true
459-
460459
ThreadManager:Run(function()
461460
self:TriggerEventCallbacks(Enums.eBackendEvent.PLAYER_SWITCH)
462461

@@ -469,36 +468,38 @@ function Backend:OnPlayerSwitch()
469468
end
470469

471470
function Backend:RegisterHandlers()
472-
self.debug_mode = self:IsMockEnv() or GVars.backend.debug_mode or false
471+
local mockEnv = self:IsMockEnv()
472+
self.debug_mode = mockEnv or GVars.backend.debug_mode or false
473473

474-
if (self:IsMockEnv()) then
475-
return
476-
end
474+
if (mockEnv) then return end
477475

478476
ThreadManager:RegisterLooped("SS_CTRLS", function()
479477
if (self.disable_input) then
480478
PAD.DISABLE_ALL_CONTROL_ACTIONS(0)
481-
end
482-
483-
if ((gui.is_open() or GUI:IsOpen()) and not self.disable_input) then
484-
self:DisableAttackInput()
485-
end
479+
else
480+
if ((gui.is_open() or GUI:IsOpen())) then
481+
self:DisableAttackInput()
482+
end
486483

487-
for _, control in pairs(self.ControlsToDisable) do
488-
PAD.DISABLE_CONTROL_ACTION(0, control, true)
484+
for _, control in pairs(self.ControlsToDisable) do
485+
PAD.DISABLE_CONTROL_ACTION(0, control, true)
486+
end
489487
end
490488
end)
491489

492490
ThreadManager:RegisterLooped("SS_BACKEND", function()
493491
self:OnPlayerSwitch()
494492
self:OnSessionSwitch()
493+
495494
PreviewService:Update()
496495
Decorator:CollectGarbage()
496+
497497
yield()
498498
end)
499499

500500
ThreadManager:RegisterLooped("SS_POOLMGR", function()
501501
self:PoolMgr()
502+
yield()
502503
end)
503504

504505
event.register_handler(menu_event.MenuUnloaded, function() self:Cleanup() end)

SSV2/includes/classes/Mutex.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
--------------------------------------
1111
-- Class: Mutex
1212
--------------------------------------
13-
-- Simple mutual exclusion.
13+
-- Simple mutual exclusivity.
1414
---@class Mutex
1515
---@field protected m_locked boolean
1616
---@overload fun(): Mutex
@@ -42,9 +42,10 @@ function Mutex:Release()
4242
end
4343

4444
-- Scoped lock.
45-
---@param func function
45+
---@generic R1, R2, R3, R4, R5
46+
---@param func fun(...?: any): R1?, R2?, R3?, R4?, R5?, ...?
4647
---@param ... any
47-
---@return ...
48+
---@return boolean success, R1?, R2?, R3?, R4?, R5?, ...?
4849
function Mutex:WithLock(func, ...)
4950
self:Acquire()
5051
local ret = { xpcall(func, function(msg)

SSV2/includes/features/vehicle/flappy_doors.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
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

99

10-
local FeatureBase = require("includes.modules.FeatureBase")
10+
local FeatureBase = require("includes.modules.FeatureBase")
1111
local StateMachine = require("includes.structs.StateMachine")
1212

13+
1314
---@class FlappyDoors : FeatureBase
1415
---@field private m_entity PlayerVehicle
1516
---@field private m_is_active boolean
1617
---@field private m_state_machine StateMachine
17-
local FlappyDoors = setmetatable({}, FeatureBase)
18+
local FlappyDoors = setmetatable({}, FeatureBase)
1819
FlappyDoors.__index = FlappyDoors
1920

2021
---@param pv PlayerVehicle

SSV2/includes/frontend/settings/debug_ui.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ local function DrawThreads()
181181
end
182182
elseif (thread_state == eThreadState.DEAD) then
183183
if GUI:Button("Start", { size = side_button_size }) then
184-
ThreadManager:StartThread(thread_name)
184+
---@diagnostic disable-next-line: invisible
185+
ThreadManager:RestartThread(thread_name)
185186
end
186187
end
187188
end

SSV2/includes/init.lua

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ local SCRIPT_NAME <const> = "Samurai's Scripts"
2424
local SCRIPT_VERSION <const> = require("includes.version")
2525
local DEFAULT_CONFIG <const> = require("includes.data.config")
2626

27+
2728
---@type GAME_VERSION
28-
local GAME_VERSION <const> = {
29-
{ build = "3788.0", online = "1.72" },
30-
{ build = "1013.29", online = "1.72" },
29+
local GAME_VERSION <const> = {
30+
[1] = { build = "3788.0", online = "1.72" },
31+
[2] = { build = "1013.29", online = "1.72" },
32+
[99] = { build = "any", online = "any" },
3133
}
3234

35+
3336
-- ### Enums Namespace.
3437
--
3538
-- All enums are stored here to avoid polluting the global namespace.
36-
Enums = require("includes.data.enums.__init__")
39+
Enums = require("includes.data.enums.__init__")
40+
3741

3842
-- ### Backend Module
3943
--
@@ -42,7 +46,8 @@ Enums = require("includes.data.enums.__init__")
4246
-- It handles API/environment detection, cleanup logic, entity and blip tracking, etc.
4347
--
4448
-- This is the core system that ensures safe, predictable behavior when switching sessions, reloading scripts, or shutting down.
45-
Backend = require("includes.backend"):init(SCRIPT_NAME, SCRIPT_VERSION, GAME_VERSION)
49+
Backend = require("includes.backend"):init(SCRIPT_NAME, SCRIPT_VERSION, GAME_VERSION)
50+
4651

4752
require("includes.lib.types")
4853
require("includes.lib.utils")
@@ -63,13 +68,15 @@ require("includes.modules.Accessor")
6368
--
6469
-- For temporary or internal state that should not be saved, use `_G` directly.
6570
---@class GVars : Config
66-
GVars = {}
71+
GVars = {}
72+
6773

6874
----------------------------------------------------------------------------------------------------
6975
-- These services must be loaded before any class that registers with/uses them -------------------
7076
ThreadManager = require("includes.services.ThreadManager"):init()
7177
Serializer = require("includes.services.Serializer"):init("ssv2", DEFAULT_CONFIG, GVars)
7278

79+
7380
-- These may look out of place, but they register themselves with Serializer for seamless
7481
--
7582
-- object serialization and deserialization. They are also needed in the next batch of
@@ -80,27 +87,27 @@ require("includes.classes.Vector3")
8087
require("includes.classes.Vector4")
8188
require("includes.modules.Color")
8289

83-
GPointers = require("includes.data.pointers")
84-
Memory = require("includes.modules.Memory")
85-
KeyManager = require("includes.services.KeyManager"):init()
86-
GUI = require("includes.services.GUI")
87-
Notifier = require("includes.services.ToastNotifier").new()
88-
CommandExecutor = require("includes.services.CommandExecutor"):init()
90+
91+
GPointers = require("includes.data.pointers")
92+
Memory = require("includes.modules.Memory")
93+
KeyManager = require("includes.services.KeyManager"):init()
94+
GUI = require("includes.services.GUI")
95+
Notifier = require("includes.services.ToastNotifier").new()
96+
CommandExecutor = require("includes.services.CommandExecutor"):init()
8997
----------------------------------------------------------------------------------------------------
9098

99+
91100
----------------- Big Features (for smaller features, refer to includes/features) ------------------
92101
BillionaireServices = require("includes.features.BillionaireServicesV2"):init()
93102
EntityForge = require("includes.features.EntityForge"):init()
94103
YimActions = require("includes.features.YimActionsV3"):init()
95104
YRV3 = require("includes.features.YimResupplierV3"):init()
96105
----------------------------------------------------------------------------------------------------
97106

98-
local base_path = "includes"
99-
local packages = {
100-
"data.refs",
101-
"data.weapons",
102107

103-
"structs.StateMachine",
108+
local base_path = "includes"
109+
local packages = {
110+
"data.refs",
104111

105112
"modules.Audio",
106113
"modules.Decorator",

SSV2/includes/lib/compat.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Compat.__index = Compat
1515
---@param version eAPIVersion
1616
function Compat.SetupEnv(version)
1717
if (version == Enums.eAPIVersion.L54) then
18-
require("includes.lib.mock_env")
18+
require("includes.lib.mock_env").Setup(version)
1919
else
2020
print = function(...)
2121
local out = {}

0 commit comments

Comments
 (0)