Skip to content

Commit 07434bf

Browse files
authored
Merge pull request #142 from YimMenu-Lua/business_stuff
fix: some fixes
2 parents 3d32838 + dba0f06 commit 07434bf

42 files changed

Lines changed: 897 additions & 320 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/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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ local Config <const> = {
185185
subwoofer = false,
186186
horn_beams = false,
187187
fast_vehicles = false,
188+
fast_vehicles_speed = 10,
188189
auto_brake_lights = false,
189190
iv_exit = false,
190191
no_wheel_recenter = false,
@@ -205,6 +206,7 @@ local Config <const> = {
205206
auto_lock_doors = false,
206207
cobra_maneuver = false,
207208
fast_jets = false,
209+
fast_jets_speed = 150.0,
208210
no_jet_stall = false,
209211
no_turbulence = false,
210212
aircraft_mg = {
@@ -340,6 +342,26 @@ local Config <const> = {
340342
sy_disable_rob_weekly_cd = false,
341343
sy_disable_tow_cd = false,
342344
unsafe_feats_enabled = false,
345+
office_clutter = {
346+
auto_disable = false,
347+
items = {
348+
cash = false,
349+
Swag_Silver = false,
350+
Swag_Pills = false,
351+
Swag_Med = false,
352+
Swag_JewelWatch = false,
353+
Swag_Ivory = false,
354+
Swag_Guns = false,
355+
Swag_Gems = false,
356+
Swag_Furcoats = false,
357+
Swag_electronic = false,
358+
Swag_DrugStatue = false,
359+
Swag_DrugBags = false,
360+
Swag_Counterfeit = false,
361+
Swag_Booze_cigs = false,
362+
Swag_Art = false,
363+
}
364+
}
343365
},
344366
yim_actions = {
345367
auto_close_ped_window = false,

SSV2/includes/features/Speedometer.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
local gui_registered = false
1111
local last_engine_state = true
12+
local last_captured_top_spd = 0.0
1213
local RUNTIME_COLORS <const> = {
1314
INDICATOR_RED = Color(1.0, 0.215, 0.215, 1.0):AsU32(),
1415
INDICATOR_GREEN = Color(0.1, 0.91, 0.0, 1.0):AsU32(),
@@ -88,21 +89,25 @@ local Speedometer = {
8889
}; Speedometer.__index = Speedometer
8990

9091
---@public
91-
function Speedometer:UpdateState()
92+
---@param PV PlayerVehicle
93+
function Speedometer:UpdateState(PV)
9294
local state = self._state
93-
local PV = LocalPlayer:GetVehicle()
9495
if not (PV and PV:IsValid()) then
9596
state.should_draw = false
9697
return
9798
end
9899

99-
local speed_modifier = Match(GVars.features.speedometer.speed_unit, UNIT_MULTIPLIERS)
100-
local fast_vehicles = GVars.features.vehicle.fast_vehicles
101-
local IsEngineOn = PV:IsEngineOn()
100+
local speed_modifier = Match(GVars.features.speedometer.speed_unit, UNIT_MULTIPLIERS)
101+
local IsEngineOn = PV:IsEngineOn()
102+
local IsNosActive = PV:IsNOSActive()
103+
if (not IsNosActive) then
104+
last_captured_top_spd = PV:GetMaxSpeed()
105+
end
106+
102107
state.PV = PV
103108
state.speed_modifier = speed_modifier
104109
state.CurrentSpeed = PV:GetSpeed() * speed_modifier
105-
state.MaxSpeed = math.floor((PV:GetDefaultMaxSpeed() * (fast_vehicles and 1.8 or 1)) * speed_modifier)
110+
state.MaxSpeed = math.floor(last_captured_top_spd * speed_modifier)
106111
state.CurrentAltitude = PV:GetHeightAboveGround()
107112
state.Manufacturer = PV:GetManufacturerName()
108113
state.IsEngineOn = IsEngineOn
@@ -111,7 +116,7 @@ function Speedometer:UpdateState()
111116
state.IsABSEngaged = PV:IsABSEngaged()
112117
state.IsESCEngaged = PV:IsESCEngaged()
113118
state.IsESCDisabled = get_is_tc_esc_dsabled(PV)
114-
state.IsNOSActive = PV:IsNOSActive()
119+
state.IsNOSActive = IsNosActive
115120
state.IsAircraft = PV:IsPlane() or PV:IsHeli()
116121
state.IsSports = PV:IsSportsOrSuper()
117122
state.IsShootingFlares = PV.m_is_shooting_flares

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,36 @@ function YRV3:Reset(disable, reason)
130130
self.m_last_autosell_check_time = 0
131131
self.m_last_income_check_time = 0
132132
self.m_last_business_update_time = 0
133-
self.m_businesses = { safes = {} }
134133
self.m_boss_types_avail = { { name = "GB_BOSS" --[[VIP]], id = 0 } }
135134
self.m_sell_script_running = false
136135
self.m_initial_data_done = false
137136
self.m_data_initialized = false
138137
self.m_autosell_state = Enums.eAutoSellState.NONE
139138
self.m_state = disable and Enums.eYRState.ERROR or Enums.eYRState.IDLE
140139

140+
for _, business in self:BusinessIter() do
141+
local reset = business.Reset
142+
if (reset) then
143+
---@diagnostic disable-next-line
144+
reset(business)
145+
end
146+
end; self.m_businesses = { safes = {} }
147+
141148
if (disable) then
142149
self:SetLastError(reason or "Unhandled Exception.")
143150
end
144151
end
145152

146153
function YRV3:Reload()
154+
if (self.m_state == Enums.eYRState.RELOADING) then
155+
return
156+
end
157+
158+
self.m_state = Enums.eYRState.RELOADING
147159
ThreadManager:Run(function()
148-
self.m_state = Enums.eYRState.RELOADING
149160
self.m_total_sum = 0
150161
self.m_total_sum_fmt = "$0"
151-
sleep(1500) -- dummy busy wait to give the UI time to refresh
162+
sleep(1500) -- dummy busy wait
152163
self:Reset()
153164
end)
154165
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

0 commit comments

Comments
 (0)