Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions SSV2/includes/backend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ function Backend:OnPlayerSwitch()
end

self.is_in_player_transition = true

ThreadManager:Run(function()
self:TriggerEventCallbacks(Enums.eBackendEvent.PLAYER_SWITCH)

Expand All @@ -469,36 +468,38 @@ function Backend:OnPlayerSwitch()
end

function Backend:RegisterHandlers()
self.debug_mode = self:IsMockEnv() or GVars.backend.debug_mode or false
local mockEnv = self:IsMockEnv()
self.debug_mode = mockEnv or GVars.backend.debug_mode or false

if (self:IsMockEnv()) then
return
end
if (mockEnv) then return end

ThreadManager:RegisterLooped("SS_CTRLS", function()
if (self.disable_input) then
PAD.DISABLE_ALL_CONTROL_ACTIONS(0)
end

if ((gui.is_open() or GUI:IsOpen()) and not self.disable_input) then
self:DisableAttackInput()
end
else
if ((gui.is_open() or GUI:IsOpen())) then
self:DisableAttackInput()
end

for _, control in pairs(self.ControlsToDisable) do
PAD.DISABLE_CONTROL_ACTION(0, control, true)
for _, control in pairs(self.ControlsToDisable) do
PAD.DISABLE_CONTROL_ACTION(0, control, true)
end
end
end)

ThreadManager:RegisterLooped("SS_BACKEND", function()
self:OnPlayerSwitch()
self:OnSessionSwitch()

PreviewService:Update()
Decorator:CollectGarbage()

yield()
end)

ThreadManager:RegisterLooped("SS_POOLMGR", function()
self:PoolMgr()
yield()
end)

event.register_handler(menu_event.MenuUnloaded, function() self:Cleanup() end)
Expand Down
7 changes: 4 additions & 3 deletions SSV2/includes/classes/Mutex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
--------------------------------------
-- Class: Mutex
--------------------------------------
-- Simple mutual exclusion.
-- Simple mutual exclusivity.
---@class Mutex
---@field protected m_locked boolean
---@overload fun(): Mutex
Expand Down Expand Up @@ -42,9 +42,10 @@ function Mutex:Release()
end

-- Scoped lock.
---@param func function
---@generic R1, R2, R3, R4, R5
---@param func fun(...?: any): R1?, R2?, R3?, R4?, R5?, ...?
---@param ... any
---@return ...
---@return boolean success, R1?, R2?, R3?, R4?, R5?, ...?
function Mutex:WithLock(func, ...)
self:Acquire()
local ret = { xpcall(func, function(msg)
Expand Down
8 changes: 4 additions & 4 deletions SSV2/includes/classes/gta/CPed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local CPlayerInfo = require("includes.classes.gta.CPlayerInfo")
---@field m_ped_weapon_mgr pointer_ref<CPedWeaponManager>
---@field m_player_info CPlayerInfo
---@field m_velocity pointer<vec3>
---@field m_ped_type pointer<uint8_t>
---@field m_ped_type pointer<uint32_t>
---@field m_ped_task_flag pointer<uint8_t>
---@field m_seatbelt pointer<uint8_t>
---@field m_armor pointer<float>
Expand Down Expand Up @@ -64,14 +64,14 @@ end
---@return boolean
function CPed:CanRagdoll()
return self:__safecall(false, function()
return (self.m_ped_type & 0x20) ~= 0
return (self.m_ped_type:get_dword() & 0x20) ~= 0
end)
end

---@return boolean
function CPed:HasSeatbelt()
return self:__safecall(false, function()
return (self.m_seatbelt & 0x3) ~= 0
return (self.m_seatbelt:get_byte() & 0x3) ~= 0
end)
end

Expand All @@ -85,7 +85,7 @@ end
---@return ePedType
function CPed:GetPedType()
return self:__safecall(-1, function()
return (self.m_ped_type:get_word() << 11 >> 25)
return (self.m_ped_type:get_dword() << 11 >> 25)
end)
end

Expand Down
3 changes: 2 additions & 1 deletion SSV2/includes/data/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ local Config <const> = {
auto_cleanup_entities = false,
language_index = 1,
language_code = "en-US",
language_name = "English"
language_name = "English",
use_game_language = false
},
ui = {
disable_tooltips = false,
Expand Down
29 changes: 15 additions & 14 deletions SSV2/includes/data/enums/__init__.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@


local Enums <const> = {
eActionType = require("includes.data.enums.action_type"),
eAnimFlags = require("includes.data.enums.anim_flags"),
eDrivingFlags = require("includes.data.enums.driving_flags"),
eGameState = require("includes.data.enums.game_state"),
eModelType = require("includes.data.enums.model_type"),
eRagdollBlockingFlags = require("includes.data.enums.ragdoll_blocking_flags"),
eVehicleClasses = require("includes.data.enums.vehicle_classes"),
eGameLanguage = require("includes.data.enums.game_language"),
eHandlingType = require("includes.data.enums.handling_type"),
eDrivingFlags = require("includes.data.enums.driving_flags"),
eVehicleHandlingFlags = require("includes.data.enums.handling_flags"),
eVehicleModelFlags = require("includes.data.enums.vehicle_model_flags"),
eVehicleModelInfoFlags = require("includes.data.enums.vehicle_model_info_flags"),
eVehicleAdvancedFlags = require("includes.data.enums.vehicle_advanced_flags"),
ePedType = require("includes.data.enums.ped_type"),
ePedGender = require("includes.data.enums.ped_gender"),
eLandingGearState = require("includes.data.enums.landing_gear_state"),
eModelType = require("includes.data.enums.model_type"),
ePedCombatAttributes = require("includes.data.enums.ped_combat_attributes"),
ePedComponents = require("includes.data.enums.ped_components"),
ePedConfigFlags = require("includes.data.enums.ped_config_flags"),
ePedGender = require("includes.data.enums.ped_gender"),
ePedResetFlags = require("includes.data.enums.ped_reset_flags"),
ePedCombatAttributes = require("includes.data.enums.ped_combat_attributes"),
ePedTaskIndex = require("includes.data.enums.ped_task_index"),
eAnimFlags = require("includes.data.enums.anim_flags"),
eActionType = require("includes.data.enums.action_type"),
ePedType = require("includes.data.enums.ped_type"),
eRagdollBlockingFlags = require("includes.data.enums.ragdoll_blocking_flags"),
eVehicleAdvancedFlags = require("includes.data.enums.vehicle_advanced_flags"),
eVehicleClasses = require("includes.data.enums.vehicle_classes"),
eVehicleHandlingFlags = require("includes.data.enums.vehicle_handling_flags"),
eVehicleModelFlags = require("includes.data.enums.vehicle_model_flags"),
eVehicleModelInfoFlags = require("includes.data.enums.vehicle_model_info_flags"),
eVehicleTask = require("includes.data.enums.vehicle_task"),
eLandingGearState = require("includes.data.enums.landing_gear_state"),
}

return Enums
27 changes: 27 additions & 0 deletions SSV2/includes/data/enums/game_language.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Copyright (C) 2026 SAMURAI (xesdoog) & Contributors.
-- This file is part of Samurai's Scripts.
--
-- Permission is hereby granted to copy, modify, and redistribute
-- this code as long as you respect these conditions:
-- * Credit the owner and contributors.
-- * 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/>.


---@enum eGameLanguage
local eGameLanguage <const> = {
ENGLISH = 0,
FRENCH = 1,
GERMAN = 2,
ITALIAN = 3,
SPANISH = 4,
PORTUGUESE_BRASIL = 5,
POLISH = 6,
RUSSIAN = 7,
KOREAN = 8,
CHINESE_TRADITIONAL = 9,
JAPANESE = 10,
SPANISH_MEXICAN = 11,
CHINESE_SIMPLIFIED = 12,
}

return eGameLanguage
5 changes: 3 additions & 2 deletions SSV2/includes/features/vehicle/flappy_doors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
-- * 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/>.


local FeatureBase = require("includes.modules.FeatureBase")
local FeatureBase = require("includes.modules.FeatureBase")
local StateMachine = require("includes.structs.StateMachine")


---@class FlappyDoors : FeatureBase
---@field private m_entity PlayerVehicle
---@field private m_is_active boolean
---@field private m_state_machine StateMachine
local FlappyDoors = setmetatable({}, FeatureBase)
local FlappyDoors = setmetatable({}, FeatureBase)
FlappyDoors.__index = FlappyDoors

---@param pv PlayerVehicle
Expand Down
2 changes: 1 addition & 1 deletion SSV2/includes/features/vehicle/misc_vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function MiscVehicle:UpdateMachineGuns()
return
end

if (not LocalPlayer:IsUsingAirctaftMG()) then
if (not LocalPlayer:IsUsingAircraftMG()) then
return
end

Expand Down
7 changes: 2 additions & 5 deletions SSV2/includes/frontend/self/self_ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ local playerAbilitiesWindow = {

local function CheckIfRagdollBlocked()
ThreadManager:Run(function()
if (LocalPlayer:IsOnFoot() and not PED.CAN_PED_RAGDOLL(LocalPlayer:GetHandle())) then
Notifier:ShowWarning(
"Samurais Scripts",
_T("SELF_RAGDOLL_BLOCK_INFO")
)
if (LocalPlayer:IsOnFoot() and not LocalPlayer:IsRagdoll() and not LocalPlayer:CanRagdoll()) then
Notifier:ShowWarning("Samurais Scripts", _T("SELF_RAGDOLL_BLOCK_INFO"))
end
end)
end
Expand Down
7 changes: 4 additions & 3 deletions SSV2/includes/frontend/settings/debug_ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ local function DrawThreads()
end
elseif (thread_state == eThreadState.DEAD) then
if GUI:Button("Start", { size = side_button_size }) then
ThreadManager:StartThread(thread_name)
---@diagnostic disable-next-line: invisible
ThreadManager:RestartThread(thread_name)
end
end
end
Expand Down Expand Up @@ -546,8 +547,8 @@ local function DrawMiscTests()
return
end

local cweaponinfo = cpedweaponmgr.m_weapon_info
if (not cweaponinfo) then
local cweaponinfo = cpedweaponmgr:GetWeaponInfo()
if not (cweaponinfo and cweaponinfo:IsValid()) then
print("CWeaponInfo: invalid pointer.")
return
end
Expand Down
70 changes: 41 additions & 29 deletions SSV2/includes/frontend/settings/settings_ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
-- * 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/>.


local ThemeManager = require("includes.services.ThemeManager")
local selectedTheme = ThemeManager:GetCurrentTheme()
local newThemeBuff = selectedTheme:Copy()
local cfgReset = {
local ThemeManager = require("includes.services.ThemeManager")
local selectedTheme
local newThemeBuff

local cfgReset = {
---@type Set<string>
exceptions = Set.new("backend.debug_mode"),
excToggles = {
Expand All @@ -23,14 +24,13 @@ local cfgReset = {
},
open = false,
}
local themeEditor = {
local themeEditor = {
shouldDraw = false,
liveEdit = false,
shouldFocusName = false,
valid = true,
errors = {}
}
newThemeBuff.Name = ""

local function onConfigReset()
for _, v in pairs(cfgReset.excToggles) do
Expand All @@ -44,29 +44,38 @@ local function drawGeneralSettings()
GVars.backend.auto_cleanup_entities = GUI:CustomToggle(_T("SETTINGS_ENTITY_REPLACE"),
GVars.backend.auto_cleanup_entities
)
GUI:Tooltip(_T("SETTINGS_ENTITY_REPLACE_TT"))
GUI:HelpMarker(_T("SETTINGS_ENTITY_REPLACE_TT"))

ImGui.Spacing()
ImGui.BulletText(_F("%s: %s (%s)", _T("SETTINGS_LANGUAGE"), GVars.backend.language_name, GVars.backend.language_code))
ImGui.Spacing()
if (Translator and Translator:IsReady()) then
GUI:HeaderText(_T("SETTINGS_LANGUAGE"), { separator = true, spacing = true })

if ImGui.BeginCombo("##langs", _F("%s (%s)",
Translator.locales[GVars.backend.language_index].name,
Translator.locales[GVars.backend.language_index].iso
)) then
for i, lang in ipairs(Translator.locales) do
local is_selected = (i == GVars.backend.language_index)
if (ImGui.Selectable(_F("%s (%s)", lang.name, lang.iso), is_selected)) then
GVars.backend.language_index = i
GVars.backend.language_name = lang.name
GVars.backend.language_code = lang.iso
GVars.backend.use_game_language = GUI:CustomToggle(_T("SETTINGS_GAME_LANGUAGE"),
GVars.backend.use_game_language,
{ onClick = function() Translator:Reload() end, }
)
GUI:HelpMarker(_T("SETTINGS_GAME_LANGUAGE_TT"))

ImGui.Spacing()
ImGui.BeginDisabled(GVars.backend.use_game_language)
if ImGui.BeginCombo("##langs", _F("%s (%s)",
Translator.locales[GVars.backend.language_index].name,
Translator.locales[GVars.backend.language_index].iso
)) then
for i, lang in ipairs(Translator.locales) do
local is_selected = (i == GVars.backend.language_index)
if (ImGui.Selectable(_F("%s (%s)", lang.name, lang.iso), is_selected)) then
GVars.backend.language_index = i
GVars.backend.language_name = lang.name
GVars.backend.language_code = lang.iso
end
end
ImGui.EndCombo()
end
ImGui.EndCombo()
ImGui.EndDisabled()
end

ImGui.Spacing()

ImGui.Separator()
if ImGui.Button(_T("SETTINGS_CFG_RESET")) then
cfgReset.open = true
end
Expand Down Expand Up @@ -105,11 +114,10 @@ local function drawGeneralSettings()
end, function()
cfgReset.exceptions:Clear()
onConfigReset()
end)
end, true)
ImGui.End()
end
end
ImGui.Dummy(1, 10)
end

local function drawThemeSettings()
Expand All @@ -119,7 +127,6 @@ local function drawThemeSettings()

if (ImGui.Begin("##new_theme",
ImGuiWindowFlags.NoTitleBar
| ImGuiWindowFlags.NoMove
| ImGuiWindowFlags.NoResize
| ImGuiWindowFlags.AlwaysAutoResize
)) then
Expand Down Expand Up @@ -306,7 +313,8 @@ local function drawGuiSettings()
ImGui.PopStyleVar()
GUI:ShowWindowHeightLimit()
end,
ImGui.CloseCurrentPopup
ImGui.CloseCurrentPopup,
true
)
ImGui.EndPopup()
end
Expand Down Expand Up @@ -346,14 +354,18 @@ local function drawGuiSettings()
end

ImGui.BeginDisabled()
GVars.ui.window_pos.x, _ = ImGui.SliderFloat(_T("SETTINGS_WINDOW_POS_X"), GVars.ui.window_pos.x, 0, resolution.x)
GUI:Tooltip(_T("SETTINGS_WINDOW_POS_TT"))
GVars.ui.window_pos.y, _ = ImGui.SliderFloat(_T("SETTINGS_WINDOW_POS_Y"), GVars.ui.window_pos.y, 0, resolution.y)
GVars.ui.window_pos.x = ImGui.SliderFloat(_T("SETTINGS_WINDOW_POS_X"), GVars.ui.window_pos.x, 0, resolution.x)
ImGui.EndDisabled()
GUI:Tooltip(_T("SETTINGS_WINDOW_POS_TT"))

ImGui.BeginDisabled()
GVars.ui.window_pos.y = ImGui.SliderFloat(_T("SETTINGS_WINDOW_POS_Y"), GVars.ui.window_pos.y, 0, resolution.y)
ImGui.EndDisabled()
GUI:Tooltip(_T("SETTINGS_WINDOW_POS_TT"))

ImGui.Spacing()
GUI:HeaderText(_T("SETTINGS_WINDOW_STYLE"), { separator = true })
selectedTheme = selectedTheme or ThemeManager:GetCurrentTheme()

GVars.ui.style.bg_alpha, _ = ImGui.SliderFloat(_T("SETTINGS_WINDOW_ALPHA"), GVars.ui.style.bg_alpha, 0.01, 1.0)
ImGui.SameLine()
Expand Down
Loading