Skip to content

Commit 660d8e2

Browse files
committed
fix: some fixes
- Fix a few bugs. - Add an option to automatically clear CEO office clutter.
1 parent 3d32838 commit 660d8e2

35 files changed

Lines changed: 804 additions & 273 deletions

SSV2/includes/classes/gta/CPlayerInfo.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959
---@return int64_t
6060
function CPlayerInfo:GetRockstarID()
6161
return self:__safecall(0, function()
62-
return self.m_rl_gamer_info.m_rockstar_id:get_int()
62+
return self.m_rl_gamer_info:GetRockstarID()
6363
end)
6464
end
6565

SSV2/includes/classes/gta/phFragInst.lua

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
--------------------------------------
1111
-- Class: phFragInst
1212
--------------------------------------
13+
-- TODO: research this nonsensical thing or remove it.
1314
---@class phFragInst
1415
---@field protected m_ptr pointer
1516
---@field public m_cache_entry pointer
@@ -18,15 +19,7 @@
1819
---@field public m_obj_matrices pointer<fMatrix44[]> `rage::fMatrix44`
1920
---@field public m_global_matrices pointer<fMatrix44[]> `rage::fMatrix44`
2021
---@overload fun(addr: pointer): phFragInst
21-
local phFragInst = {}
22-
phFragInst.__index = phFragInst
23-
phFragInst.__type = "phFragInst"
24-
---@diagnostic disable-next-line: param-type-mismatch
25-
setmetatable(phFragInst, {
26-
__call = function(cls, ...)
27-
return cls.new(...)
28-
end,
29-
})
22+
local phFragInst = Callable("phFragInst")
3023

3124
---@param ptr pointer
3225
---@return phFragInst|nil

SSV2/includes/classes/gta/rlGamerInfo.lua

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,11 @@ local CStructView = require("includes.classes.gta.CStructView")
1616
---@field private m_decimal uint32_t
1717
---@field private m_packed vec4
1818
---@overload fun(n: uint32_t): IPAddress
19-
local IPAddress <const> = {}
20-
IPAddress.__index = IPAddress
21-
---@diagnostic disable-next-line
22-
setmetatable(IPAddress, {
23-
__call = function(t, ...)
24-
return t.new(...)
25-
end
26-
})
19+
local IPAddress <const> = Callable("IPAddress", { ctor = function(t, n) return t:new(n) end })
2720

2821
---@param n uint32_t
2922
---@return IPAddress
30-
function IPAddress.new(n)
23+
function IPAddress:new(n)
3124
local packed = vec4:zero()
3225
if (n ~= 0) then
3326
packed = vec4:new(
@@ -41,8 +34,7 @@ function IPAddress.new(n)
4134
return setmetatable({
4235
m_decimal = n,
4336
m_packed = packed
44-
---@diagnostic disable-next-line
45-
}, IPAddress)
37+
}, self)
4638
end
4739

4840
---@return string
@@ -60,14 +52,16 @@ end
6052
-- Class: rlGamerInfo
6153
--------------------------------------
6254
---@class rlGamerInfo : CStructBase<rlGamerInfo>
63-
---@field m_peer_id pointer<uint64_t>
64-
---@field m_rockstar_id pointer<int64_t>
65-
---@field m_external_ip pointer<uint32_t>
66-
---@field m_external_port pointer<uint16_t>
67-
---@field m_internal_ip pointer<uint32_t>
68-
---@field m_internal_port pointer<uint16_t>
69-
---@field m_nat_type pointer<uint32_t>
70-
---@field m_player_name pointer<string> // 0x00DC
55+
---@field private m_peer_id pointer<uint64_t>
56+
---@field private m_rockstar_id pointer<int64_t>
57+
---@field private m_external_ip pointer<uint32_t>
58+
---@field private m_external_port pointer<uint16_t>
59+
---@field private m_internal_ip pointer<uint32_t>
60+
---@field private m_internal_port pointer<uint16_t>
61+
---@field private m_nat_type pointer<uint32_t>
62+
---@field private m_player_name pointer<string> // 0x00DC
63+
---@field private m_cached_extern_ipaddr IPAddress
64+
---@field private m_cached_intern_ipaddr IPAddress
7165
---@overload fun(ptr: pointer): rlGamerInfo
7266
local rlGamerInfo = CStructView("rlGamerInfo", 0x0F90)
7367

@@ -88,14 +82,25 @@ function rlGamerInfo.new(ptr)
8882
}, rlGamerInfo)
8983
end
9084

85+
---@return int64_t
86+
function rlGamerInfo:GetRockstarID()
87+
return self.m_rockstar_id:get_int()
88+
end
89+
9190
---@return IPAddress
9291
function rlGamerInfo:GetExternalIP()
93-
return IPAddress(self.m_external_ip:get_dword())
92+
if (not self.m_cached_extern_ipaddr) then
93+
self.m_cached_extern_ipaddr = IPAddress(self.m_external_ip:get_dword())
94+
end
95+
return self.m_cached_extern_ipaddr
9496
end
9597

9698
---@return IPAddress
9799
function rlGamerInfo:GetInternalIP()
98-
return IPAddress(self.m_internal_ip:get_dword())
100+
if (not self.m_cached_intern_ipaddr) then
101+
self.m_cached_intern_ipaddr = IPAddress(self.m_internal_ip:get_dword())
102+
end
103+
return self.m_cached_intern_ipaddr
99104
end
100105

101106
---@return string

SSV2/includes/data/config.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,26 @@ local Config <const> = {
340340
sy_disable_rob_weekly_cd = false,
341341
sy_disable_tow_cd = false,
342342
unsafe_feats_enabled = false,
343+
office_clutter = {
344+
auto_disable = false,
345+
items = {
346+
cash = false,
347+
Swag_Silver = false,
348+
Swag_Pills = false,
349+
Swag_Med = false,
350+
Swag_JewelWatch = false,
351+
Swag_Ivory = false,
352+
Swag_Guns = false,
353+
Swag_Gems = false,
354+
Swag_Furcoats = false,
355+
Swag_electronic = false,
356+
Swag_DrugStatue = false,
357+
Swag_DrugBags = false,
358+
Swag_Counterfeit = false,
359+
Swag_Booze_cigs = false,
360+
Swag_Art = false,
361+
}
362+
}
343363
},
344364
yim_actions = {
345365
auto_close_ped_window = false,

SSV2/includes/features/online/yim_resupplier/YimResupplierV3.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,15 @@ function YRV3:Reset(disable, reason)
144144
end
145145

146146
function YRV3:Reload()
147+
if (self.m_state == Enums.eYRState.RELOADING) then
148+
return
149+
end
150+
151+
self.m_state = Enums.eYRState.RELOADING
147152
ThreadManager:Run(function()
148-
self.m_state = Enums.eYRState.RELOADING
149153
self.m_total_sum = 0
150154
self.m_total_sum_fmt = "$0"
151-
sleep(1500) -- dummy busy wait to give the UI time to refresh
155+
sleep(1500) -- dummy busy wait
152156
self:Reset()
153157
end)
154158
end

SSV2/includes/features/online/yim_resupplier/businesses/BasicBusiness.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
---@field private m_name string
1818
---@field private m_coords vec3
1919
---@field private m_generic_val_get_func fun(): anyval
20-
---@field private m_generic_val_set_func function
20+
---@field private m_generic_val_set_func fun(...: any)
2121
---@field protected m_is_stale boolean
2222
local BasicBusiness = {}
2323
BasicBusiness.__index = BasicBusiness
@@ -52,8 +52,8 @@ function BasicBusiness:GetGenericValue()
5252
return self.m_generic_val_get_func()
5353
end
5454

55-
function BasicBusiness:SetGenericValue()
56-
self.m_generic_val_set_func()
55+
function BasicBusiness:SetGenericValue(...)
56+
self.m_generic_val_set_func(...)
5757
end
5858

5959
return BasicBusiness

SSV2/includes/features/online/yim_resupplier/businesses/BusinessHub.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ BusinessHub.__index = BusinessHub
3636
---@param opts HubOpts
3737
---@return BusinessHub
3838
function BusinessHub.new(opts)
39-
assert(type(opts.max_units) == "number", "Missing argument: max_units<integer>")
4039
local id = opts.id
41-
assert(type(opts.id) == "number" and math.is_inrange(opts.id, 0, 6), "Invalid Business Hub id.")
40+
assert(type(opts.max_units) == "number", "Missing argument: max_units<integer>")
41+
assert(type(id) == "number" and math.is_inrange(id, 0, 6), "Invalid Business Hub id.")
4242

4343
local base = BusinessBase.new(opts)
4444
local instance = setmetatable(base, BusinessHub) ---@cast instance BusinessHub
@@ -100,7 +100,7 @@ end
100100
-- Actually wanted to improve UX with tech names using the return index
101101
--
102102
-- but apparently only Yohan has a name. We should probably return a bool instead
103-
---@return integer TechIndex A number between 0 and 5 or -1 if no one is assigned.
103+
---@return integer techIndex A number between 0 and 5 or -1 if no one is assigned.
104104
function BusinessHub:GetAssignedTechIndex()
105105
for i = 0, 5 do
106106
if (self:IsTechAssignedToThis(i)) then
@@ -192,7 +192,8 @@ end
192192
-- https://www.youtube.com/watch?v=-Gh1lTcwdGY
193193
---@private
194194
function BusinessHub:InstantFillProduction()
195-
self:TriggerProduction(self:GetMaxUnits() - 1)
195+
self:SetProductCount(self:GetMaxUnits() - 1)
196+
self:TriggerProduction()
196197
end
197198

198199
---@return boolean
@@ -207,6 +208,11 @@ end
207208

208209
---@private
209210
function BusinessHub:LoopProduction()
211+
if (self.m_fast_prod_running) then
212+
return
213+
end
214+
215+
self.m_fast_prod_running = true
210216
ThreadManager:Run(function()
211217
while (self:IsValid() and self.fast_prod_enabled and not self:HasFullProduction()) do
212218
self:TriggerProduction()
@@ -230,7 +236,6 @@ function BusinessHub:Update()
230236
return
231237
end
232238

233-
self.m_fast_prod_running = true
234239
self:LoopProduction()
235240
end
236241
end

SSV2/includes/features/online/yim_resupplier/businesses/CarWash.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ CarWash.__index = CarWash
148148
---@param opts BasicBusinessOpts
149149
---@return CarWash
150150
function CarWash.new(opts)
151-
local base = BasicBusiness.new(opts)
152-
local instance = setmetatable(base, CarWash) ---@cast instance CarWash
153-
local cashSafe = CashSafe.new({
151+
local base = BasicBusiness.new(opts)
152+
local instance = setmetatable(base, CarWash) ---@cast instance CarWash
153+
local cashSafe = CashSafe.new({
154154
name = opts.name,
155155
cash_value_stat = "MPX_CWASH_SAFE_CASH_VALUE",
156156
paytime_stat = "MPX_CWASH_PAY_TIME_LEFT",
@@ -159,6 +159,7 @@ function CarWash.new(opts)
159159
get_max_cash = function() return tunables.get_int("TYCOON_CAR_WASH_SAFE_MAX_STORAGE_AMOUNT") end,
160160
})
161161

162+
162163
local sgslObj = SGSL:Get(SGSL.data.car_wash_safe_global)
163164
local pidSize = sgslObj:GetOffset(1)
164165
local entryOffset = sgslObj:GetOffset(2)
@@ -169,16 +170,18 @@ function CarWash.new(opts)
169170
:At(27)
170171
:At(2)
171172

172-
instance.m_safe = cashSafe
173-
instance.m_duffle = CarWashDuffle.new({
173+
174+
instance.m_safe = cashSafe
175+
instance.m_duffle = CarWashDuffle.new({
174176
name = opts.name,
175177
cash_value_stat = "MPX_CAR_WASH_DUFFEL_VALUE",
176178
get_max_cash = function() return tunables.get_int(564305888) end
177179
})
178180

179-
instance.m_subs = {}
181+
182+
local subs = {}
180183
if (stats.get_int("MPX_SB_WEED_SHOP_OWNED") ~= 0) then
181-
table.insert(instance.m_subs, CarWashSubBusiness.new({
184+
table.insert(subs, CarWashSubBusiness.new({
182185
name = Game.GetLabelText("CELL_WSHOP"),
183186
coords = vec3:new(-1162.051147, -1564.757202, 4.410227),
184187
heat_packed_stat = 24925,
@@ -188,7 +191,7 @@ function CarWash.new(opts)
188191
end
189192

190193
if (stats.get_int("MPX_SB_HELI_TOURS_OWNED") ~= 0) then
191-
table.insert(instance.m_subs, CarWashSubBusiness.new({
194+
table.insert(subs, CarWashSubBusiness.new({
192195
name = Game.GetLabelText("CELL_HELIT"),
193196
coords = vec3:new(-753.524841, -1511.244751, 5.015130),
194197
heat_packed_stat = 24926,
@@ -197,6 +200,7 @@ function CarWash.new(opts)
197200
}))
198201
end
199202

203+
instance.m_subs = subs
200204
return instance
201205
end
202206

SSV2/includes/features/online/yim_resupplier/businesses/Factory.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Factory.__index = Factory
4545
---@param opts FactoryOpts
4646
---@return Factory
4747
function Factory.new(opts)
48-
assert(type(opts.max_units) == "number", "Missing argument: max_units<integer>")
4948
local id = opts.id
50-
assert(type(opts.id) == "number" and math.is_inrange(opts.id, 0, 6), "Invalid Biker Business id.")
49+
assert(type(opts.max_units) == "number", "Missing argument: max_units<integer>")
50+
assert(type(id) == "number" and math.is_inrange(id, 0, 6), "Invalid Biker Business id.")
5151

5252
local base = BusinessBase.new(opts)
5353
local instance = setmetatable(base, Factory) ---@cast instance Factory
@@ -75,7 +75,7 @@ function Factory.new(opts)
7575
end
7676

7777
function Factory:Reset()
78-
self.fast_prod_enabled = false
78+
self.fast_prod_enabled = false
7979
self.m_fast_prod_running = false
8080
self:ResetImpl()
8181
end
@@ -176,6 +176,11 @@ end
176176

177177
---@private
178178
function Factory:LoopProduction()
179+
if (self.m_fast_prod_running) then
180+
return
181+
end
182+
183+
self.m_fast_prod_running = true
179184
ThreadManager:Run(function()
180185
while (self:IsValid() and self.fast_prod_enabled and not self:HasFullProduction()) do
181186
if (self:GetSuppliesCount() <= 25) then
@@ -193,16 +198,13 @@ function Factory:LoopProduction()
193198
end
194199

195200
function Factory:Update()
196-
if (not self:IsValid() or not self:IsSetup()) then
201+
if not (self:IsValid() and self:IsSetup()) then
197202
return
198203
end
199204

200205
if (self.fast_prod_enabled and not self.m_fast_prod_running and not self:HasFullProduction()) then
201-
self.m_fast_prod_running = true
202206
self:LoopProduction()
203207
end
204-
205-
-- more stuff later
206208
end
207209

208210
return Factory

0 commit comments

Comments
 (0)