Skip to content

Commit 1b992b7

Browse files
authored
Merge pull request YimMenu-Lua#81 from acidlabsdev/main
feat(YRV3): add production triggers
2 parents 4173d30 + d1e400e commit 1b992b7

42 files changed

Lines changed: 1823 additions & 1296 deletions

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 & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -73,50 +73,56 @@ local Backend = {
7373
Backend.__index = Backend
7474

7575
---@param name string
76-
---@param version string
77-
---@param game_build? string
78-
---@param target_version? string
79-
function Backend:init(name, version, game_build, target_version)
80-
self.api_version = self:GetAPIVersion()
76+
---@param script_version string
77+
---@param game_version? GAME_VERSION
78+
function Backend:init(name, script_version, game_version)
79+
local api_ver = self:GetAPIVersion()
80+
self.api_version = api_ver
8181
self.script_name = name
82-
self.__version = version
83-
self.target_build = game_build or "any"
84-
self.target_version = target_version or "any"
85-
86-
require("includes.lib.compat").SetupEnvironment(self.api_version)
82+
self.__version = script_version
83+
self.target_build = game_version and game_version[api_ver].build or "any"
84+
self.target_version = game_version and game_version[api_ver].online or "any"
8785

86+
require("includes.lib.compat").SetupEnv(self.api_version)
8887
return self
8988
end
9089

9190
---@return eAPIVersion
9291
function Backend:GetAPIVersion()
93-
if (not self.api_version) then
94-
if (script and (type(script) == "table")) then
95-
if (menu_event and menu_event.Wndproc) then
96-
if (type(_G["get_game_branch"]) == "function") then
97-
local branch = _G["get_game_branch"]()
98-
if (type(branch) ~= "number" or branch > 1) then
99-
error("Unknown or unsupported game branch.")
100-
end
101-
102-
self.api_version = _G["get_game_branch"]() + 1
103-
else
104-
self.api_version = Enums.eAPIVersion.V1
105-
end
106-
end
92+
if (self.api_version) then
93+
return self.api_version
94+
end
10795

108-
if (type(script["run_in_callback"]) == "function") then
109-
error(
110-
"YmMenu V2 is not supported. If you want to run this script in GTA V Enhanced, download YimLuaAPI.") -- test error; add Github link later
111-
end
112-
---@diagnostic disable-next-line: undefined-global
113-
elseif (util or (menu and menu.root) or SCRIPT_SILENT_START or (_VERSION ~= "Lua 5.4")) then -- should probably place these in a lookup table
96+
if (not script or (type(script) ~= "table")) then
97+
---@diagnostic disable-next-line: undefined-global
98+
if (util or (menu and menu.root) or SCRIPT_SILENT_START or (_VERSION ~= "Lua 5.4")) then
11499
error("Failed to load: Unknown or unsupported Lua environment.")
115-
else
116-
self.api_version = Enums.eAPIVersion.L54
117100
end
101+
102+
self.api_version = Enums.eAPIVersion.L54
103+
return self.api_version
104+
end
105+
106+
if (type(script["run_in_callback"]) == "function") then
107+
error("YmMenu V2 is not supported. If you want to run this script in GTA V Enhanced, download YimLuaAPI.")
108+
end
109+
110+
if (not menu_event or not menu_event.Wndproc) then
111+
error("Unknown or unsupported game branch.")
112+
end
113+
114+
local ylapi_func = _G["get_game_branch"]
115+
if (type(ylapi_func) ~= "function") then
116+
self.api_version = Enums.eAPIVersion.V1
117+
return self.api_version
118+
end
119+
120+
local branch = ylapi_func()
121+
if (type(branch) ~= "number" or branch > 1) then
122+
error("Unknown or unsupported game branch.")
118123
end
119124

125+
self.api_version = branch + 1
120126
return self.api_version
121127
end
122128

@@ -139,18 +145,18 @@ function Backend:debug(data, ...)
139145
log.fdebug(data, ...)
140146
end
141147

142-
function Backend:MatchVersion()
148+
function Backend:MatchGameVersion()
143149
local gv = Game.GetVersion()
144-
return (gv and gv._build
145-
and gv._online
146-
and (self.target_build == gv._build)
147-
and (self.target_version == gv._online)
150+
return (gv and gv.build
151+
and gv.online
152+
and (self.target_build == gv.build)
153+
and (self.target_version == gv.online)
148154
)
149155
end
150156

151157
---@return boolean
152158
function Backend:IsUpToDate()
153-
return (self.target_build == "any") or self:MatchVersion()
159+
return (self.target_build == "any") or self:MatchGameVersion()
154160
end
155161

156162
---@param handle integer

SSV2/includes/data/globals_locals.lua

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,60 @@ return {
7070
capture_group = 1
7171
}
7272
},
73+
biker_trigger_production_global = {
74+
description = "Trigger production for all biker businesses.",
75+
file = "freemode.c",
76+
LEGACY = {
77+
value = 1845250,
78+
pattern = [[(Global_\d{7})\[.*?(.*?)\]\.(f_\d{3}).(f_\d{3})\[.*?/(.*?)\].f_9 = .*?;]],
79+
capture_group = 1,
80+
offsets = {
81+
{
82+
value = 880,
83+
capture_group = 2,
84+
description = "playerID read size."
85+
},
86+
{
87+
value = 260,
88+
capture_group = 3
89+
},
90+
{
91+
value = 205,
92+
capture_group = 4
93+
},
94+
{
95+
value = 13,
96+
capture_group = 5,
97+
description = "business index read size."
98+
},
99+
},
100+
},
101+
ENHANCED = {
102+
value = 1845299,
103+
pattern = [[(Global_\d{7})\[.*?(.*?)\]\.(f_\d{3}).(f_\d{3})\[.*?/(.*?)\].f_9 = .*?;]],
104+
capture_group = 1,
105+
offsets = {
106+
{
107+
value = 883,
108+
capture_group = 2,
109+
description = "playerID read size."
110+
},
111+
{
112+
value = 260,
113+
capture_group = 3
114+
},
115+
{
116+
value = 205,
117+
capture_group = 4
118+
},
119+
{
120+
value = 13,
121+
capture_group = 5,
122+
description = "business index read size."
123+
},
124+
},
125+
}
126+
},
73127
gb_contraband_buy_local_1 = {
74128
description = "Contraband Buy Local 1",
75129
file = "gb_contraband_buy.c",
@@ -245,7 +299,7 @@ return {
245299
}
246300
},
247301
gb_gunrunning_sell_local_2 = {
248-
description = "Bunker Sell Local 2",
302+
description = "Amount delivered.",
249303
file = "gb_gunrunning.c",
250304
LEGACY = {
251305
value = 1266,
@@ -270,6 +324,34 @@ return {
270324
}
271325
}
272326
},
327+
gb_gunrunning_sell_local_3 = {
328+
description = "Remaining delivery vehicles.",
329+
file = "gb_gunrunning.c",
330+
LEGACY = {
331+
value = 1266,
332+
pattern =
333+
[[for \(i = 0; i < func_\w+\(func_\w+\(\), func_\w+\(\),.*?(Local_\d{4})(\.f_\d{3}),.*?Local_\d{4}\.f_\d{3}\); i = i \+ 1\)]],
334+
capture_group = 1,
335+
offsets = {
336+
{
337+
value = 774,
338+
capture_group = 2
339+
}
340+
}
341+
},
342+
ENHANCED = {
343+
value = 1268,
344+
pattern =
345+
[[for \(i = 0; i < func_\w+\(func_\w+\(\), func_\w+\(\),.*?(Local_\d{4})(\.f_\d{3}),.*?Local_\d{4}\.f_\d{3}\); i = i \+ 1\)]],
346+
capture_group = 1,
347+
offsets = {
348+
{
349+
value = 774,
350+
capture_group = 2
351+
}
352+
}
353+
}
354+
},
273355
acid_lab_sell_local = {
274356
description = "Acid Lab Sell Local",
275357
file = "fm_content_acid_lab_sell.c",

SSV2/includes/data/pointers.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PatternScanner = require("includes.services.PatternScanner"):init()
1717
---@field ScriptGlobals pointer
1818
---@field GameState pointer<byte>
1919
---@field GameTime pointer<uint32_t>
20-
---@field GameVersion { _build: string, _online: string }
20+
---@field GameVersion VersionInfo
2121
---@field ScreenResolution vec2
2222
---@field DynamicFuncs DynamicFuncs
2323
local GPointers = {
@@ -26,7 +26,7 @@ local GPointers = {
2626
ScriptGlobals = nullptr,
2727
GameState = nullptr,
2828
GameTime = nullptr,
29-
GameVersion = { _build = "nil", _online = "nil" },
29+
GameVersion = { build = "", online = "" },
3030
ScreenResolution = vec2:zero(),
3131
}
3232

@@ -68,8 +68,8 @@ local mem_batches <const> = {
6868
local pGameBuild = ptr:add(0x24):rip()
6969
local pOnlineVersion = pGameBuild:add(0x20)
7070
GPointers.GameVersion = {
71-
_build = pGameBuild:get_string(),
72-
_online = pOnlineVersion:get_string()
71+
build = pGameBuild:get_string(),
72+
online = pOnlineVersion:get_string()
7373
}
7474
end),
7575
MemoryBatch.new("GameState", "83 3D ? ? ? ? ? 75 17 8B 43 20 25", function(ptr)
@@ -127,8 +127,8 @@ local mem_batches <const> = {
127127
end
128128

129129
GPointers.GameVersion = {
130-
_build = ptr:add(0x3):rip():get_string(),
131-
_online = ptr:add(0x47):add(0x3):rip():get_string()
130+
build = ptr:add(0x3):rip():get_string(),
131+
online = ptr:add(0x47):add(0x3):rip():get_string()
132132
}
133133
end),
134134
MemoryBatch.new("GameState", "83 3D ? ? ? ? ? 0F 85 ? ? ? ? BA ? 00", function(ptr)

0 commit comments

Comments
 (0)