Skip to content

Commit 3037eb2

Browse files
authored
Merge pull request YimMenu-Lua#129 from YimMenu-Lua/yimactions_ui_refactor
refactor(UI): refactor YimActions UI
2 parents 761a12f + 1588fc6 commit 3037eb2

118 files changed

Lines changed: 3550 additions & 2861 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.

.github/workflows/translations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
git config user.name "github-actions[bot]"
3838
git config user.email "github-actions[bot]@users.noreply.github.com"
3939
git add SSV2/includes/lib/translations/
40-
git diff --cached --quiet || git commit -m "feat(Translations): update translations"
40+
git diff --cached --quiet || git commit -m "chore(Translations): update translations"
4141
git push

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ A full list of available features and their usage [can be found here](docs/Featu
125125

126126
<div>
127127
<a href="https://discord.gg/RHBUxJ5Qhp">
128-
<img height="96" width="192" alt="Discord" src="https://substackcdn.com/image/fetch/$s_!nfCP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a41e45e-aac9-44e5-8b69-55a81058ecbf_875x280.png">
128+
<img height="64" width="192" alt="Discord" src="https://substackcdn.com/image/fetch/$s_!nfCP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a41e45e-aac9-44e5-8b69-55a81058ecbf_875x280.png">
129129
</a>
130130
</div>
131131

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/classes/Mutex.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ function Mutex.new()
2929
return setmetatable({ m_locked = false }, Mutex)
3030
end
3131

32+
---@return boolean
33+
function Mutex:IsLocked()
34+
return self.m_locked
35+
end
36+
3237
function Mutex:Acquire()
3338
while (self.m_locked) do
3439
yield()

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/scenarios.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ return {
104104
scenario = "WORLD_HUMAN_BUM_SLUMPED",
105105
},
106106
{
107-
label = " HOBO Standing",
107+
label = "HOBO Standing",
108108
scenario = "WORLD_HUMAN_BUM_STANDING",
109109
},
110110
{

SSV2/includes/data/actions/types.lua

Lines changed: 3 additions & 2 deletions
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
@@ -96,7 +97,7 @@
9697
---@field strf string?
9798
---@field wanim string
9899

99-
---@alias ActionData AnimData | ScenarioData | SyncedSceneData | MovementClipsetData?
100+
---@alias ActionData AnimData | ScenarioData | SyncedSceneData | MovementClipsetData
100101

101102
---@class ActionCommandData
102103
---@field type eActionType

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)

0 commit comments

Comments
 (0)