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
6 changes: 3 additions & 3 deletions .github/workflows/zip-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ jobs:
- name: Bump Version
if: steps.check_changes.outputs.should_proceed == 'true'
run: |
sed -i "s|return \".*\"|return \"${{steps.increment_tag.outputs.no_prefix}}\"|" SSV2/includes/version.lua
sed -i "s|https://img.shields.io/badge/Script%20Version-v[0-9]\+\.[0-9]\+\.[0-9]\+-blue|https://img.shields.io/badge/Script%20Version-${{steps.increment_tag.outputs.version_number}}-blue|g" README.md
sed -i "s|return \".*\"|return \"${{ steps.increment_tag.outputs.no_prefix }}\"|" SSV2/includes/version.lua
sed -i "s|https://img.shields.io/badge/Script%20Version-v[0-9]\+\.[0-9]\+\.[0-9]\+-blue|https://img.shields.io/badge/Script%20Version-${{ steps.increment_tag.outputs.version_number }}-blue|g" README.md
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add SSV2/includes/version.lua README.md
Expand All @@ -173,7 +173,7 @@ jobs:
with:
type: 'zip'
filename: "Samurais_Scripts_${{ steps.increment_tag.outputs.version_number }}.zip"
exclusions: /.git* /scripts* /docs* *.json *.md *.editorconfig *.py *.txt LICENSE
exclusions: /.git* /dev* /docs* **.json **.md **.editorconfig **.py **.txt *.ps1 .gitignore LICENSE

- name: Upload Release
if: steps.check_changes.outputs.should_proceed == 'true'
Expand Down
3 changes: 1 addition & 2 deletions SSV2/includes/classes/Vector2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
---@operator eq(vec2): boolean
---@operator le(vec2): boolean
---@operator lt(vec2): boolean
vec2 = {}
vec2 = { __type = "vec2" }
vec2.__index = vec2
vec2.__type = "vec2"


--------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions SSV2/includes/classes/Vector4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
---@operator eq(vec4): boolean
---@operator le(vec4): boolean
---@operator lt(vec4): boolean
vec4 = {}
vec4 = { __type = "vec4" }
vec4.__index = vec4
vec4.__type = "vec4"


--------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions SSV2/includes/classes/gta/CPlayerInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local rlGamerInfo = require("includes.classes.gta.rlGamerInfo")
---@field m_swim_speed pointer<float>
---@field m_walk_speed pointer<float>
---@field m_game_state pointer<eGameState>
---@field m_ped pointer_ref<CPed>
---@field m_is_wanted pointer<bool>
---@field m_wanted_level pointer<uint32_t>
---@field m_wanted_level_display pointer<uint32_t>
Expand All @@ -40,6 +41,7 @@ function CPlayerInfo.new(ptr)
m_swim_speed = ptr:add(0x01C8),
m_walk_speed = ptr:add(0x01E4),
m_game_state = ptr:add(0x0230),
m_ped = ptr:add(0x0240),
m_is_wanted = ptr:add(0x08E0),
m_wanted_level = ptr:add(0x08E8),
m_wanted_level_display = ptr:add(0x08EC),
Expand Down
10 changes: 7 additions & 3 deletions SSV2/includes/classes/gta/CVehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ local SubHandlingCtorMap <const> = {
---@field public m_car_handling_data pointer<CCarHandlingData>?
---@field public m_model_info_layout pointer<CVehicleModelInfoLayout>
---@field public m_can_boost_jump pointer<byte> `bool`
---@field public m_velocity pointer<vec3>
---@field public m_deform_god pointer<uint8_t>
---@field public m_water_damage pointer<uint32_t>
---@field public m_next_gear pointer<int16_t>
Expand Down Expand Up @@ -107,8 +108,9 @@ function CVehicle:init(vehicle)
instance.m_sub_handling_data = atArray(instance.m_handling_data:add(0x158), CCarHandlingData)
instance.m_model_info_layout = instance.m_model_info:add(0x00B0):deref()
instance.m_physics_fragments = phFragInst(ptr:add(0x0030):deref())
instance.m_draw_data = CVehicleDrawData:init(ptr:add(0x0048):deref())
instance.m_draw_data = CVehicleDrawData(ptr:add(0x0048):deref())
instance.m_can_boost_jump = ptr:add(0x03A4)
instance.m_velocity = ptr:add(0x07D0)
instance.m_deform_god = ptr:add(0x096C)
instance.m_is_targetable = ptr:add(0x0AEE)
instance.m_door_lock_status = ptr:add(0x13D0)
Expand Down Expand Up @@ -185,7 +187,9 @@ end
---@return CCarHandlingData|CBikeHandlingData|CFlyingHandlingData|any
function CVehicle:GetSubHandlingData(handlingType)
return self:__safecall(nil, function()
for _, sub_ptr in self.m_sub_handling_data:Iter() do
local array = self.m_sub_handling_data
for i = 1, array:Size() do
local sub_ptr = array:At(i)
if (sub_ptr:is_valid()) then
-- local base = CBaseSubHandlingData.new(sub_ptr)
-- if (base and base:GetHandlingType() == handlingType) then
Expand Down Expand Up @@ -440,7 +444,7 @@ function CVehicle:GetWheel(index)
return
end

local ptr = self.m_wheels:Get(index)
local ptr = self.m_wheels:At(index)
if (not ptr or ptr:is_null()) then
return
end
Expand Down
12 changes: 7 additions & 5 deletions SSV2/includes/classes/gta/CVehicleDrawData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,19 @@ end
--------------------------------------
-- Class: CVehicleDrawData
--------------------------------------
---@class CVehicleDrawData : fwDrawData
---@class CVehicleDrawData
---@field m_wheel_draw_data pointer_ref<CWheelDrawData>
---@overload fun(ptr: pointer): CVehicleDrawData
local CVehicleDrawData = Class("CVehicleDrawData", { parent = fwDrawData, pointer_ctor = true })
local CVehicleDrawData = Class("CVehicleDrawData", { pointer_ctor = true })

---@param ptr pointer
---@return CVehicleDrawData
function CVehicleDrawData:init(ptr)
self.m_ptr = ptr
self.m_wheel_draw_data = ptr:add(0x370)
return self
return setmetatable({
m_ptr = ptr,
m_wheel_draw_data = ptr:add(0x370)
---@diagnostic disable-next-line: param-type-mismatch
}, CVehicleDrawData)
end

---@return CWheelDrawData
Expand Down
10 changes: 10 additions & 0 deletions SSV2/includes/classes/gta/CWheel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,14 @@ function CWheel:SetConfigFlag(flag, toggle)
end)
end

---@return boolean
function CWheel:IsLeftWheel()
return self:GetConfigFlag(Enums.eWheelConfigFlags.LEFTWHEEL)
end

---@return boolean
function CWheel:IsRearWheel()
return self:GetConfigFlag(Enums.eWheelConfigFlags.REARWHEEL)
end

return CWheel
137 changes: 43 additions & 94 deletions SSV2/includes/classes/gta/atArray.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
---@ignore
---@generic T
---@class atArray<T>
---@field private m_address pointer
---@field protected m_ptr pointer
---@field private m_data_ptr pointer
---@field private m_data array<pointer_ref<T>>
---@field private m_size uint16_t
---@field private m_count uint16_t
---@field private m_data array<pointer>
---@field private m_capacity uint16_t
---@field private m_data_type any
---@field private m_last_update_time TimePoint
---@overload fun(address: pointer, data_type?: any): atArray
local atArray = {
__type = "atArray",
Expand All @@ -35,46 +34,44 @@ setmetatable(atArray, {
})

---@generic T
---@param address pointer
---@param ptr pointer
---@param data_type optional<T>
---@return atArray<T>
function atArray.new(address, data_type)
function atArray.new(ptr, data_type)
local instance = setmetatable({
m_address = nullptr,
m_ptr = ptr,
m_data_ptr = nullptr,
m_size = 0x0,
m_count = 0x0,
m_size = 0,
m_capacity = 0,
m_data = {},
m_data_type = nil
---@diagnostic disable-next-line
---@diagnostic disable-next-line: param-type-mismatch
}, atArray)

if not (IsInstance(address, "pointer") and address:is_valid()) then
if (ptr:is_null()) then
return instance
end

local array_size = address:add(0x8):get_word()
local array_size = ptr:add(0x8):get_word()
if (array_size == 0) then
return instance
end

instance.m_address = address
instance.m_data_ptr = address:deref()
instance.m_size = array_size
instance.m_count = address:add(0xA):get_word()
instance.m_data_type = data_type
instance.m_last_update_time = TimePoint:new()
instance.m_data_ptr = ptr:deref()
instance.m_size = array_size
instance.m_capacity = ptr:add(0x10):get_word()
instance.m_data_type = data_type

for i = 0, array_size - 1 do
instance.m_data[i + 1] = instance.m_data_ptr:add(i * 0x8):deref()
instance.m_data[i + 1] = instance.m_data_ptr:add(i * 0x8)
end

return instance
end

---@return boolean
function atArray:IsValid()
return self.m_address:is_valid() and self.m_data_ptr:is_valid()
return self.m_ptr:is_valid() and self.m_data_ptr:is_valid()
end

---@return boolean
Expand All @@ -84,56 +81,30 @@ end

---@return boolean
function atArray:IsEmpty()
self:Update()
return self.m_size == 0
end

function atArray:Clear()
self.m_address = nullptr
self.m_ptr = nullptr
self.m_data_ptr = nullptr
self.m_size = 0
self.m_capacity = 0
self.m_data = {}
self.m_size = 0x0
self.m_count = 0x0
self.m_data_type = nil
self.m_last_update_time:Reset()
end

function atArray:Update()
if not self:IsValid() then
return
end

if not self.m_last_update_time:HasElapsed(250) then
return
end

self.m_size = self.m_address:add(0x8):get_word()
self.m_count = self.m_address:add(0xA):get_word()
if (self.m_size == 0) then
self.m_data = {}
self.m_last_update_time:Reset()
return
end

for i = 0, self.m_size - 1 do
self.m_data[i + 1] = self.m_data_ptr:add(i * 0x8):deref()
end

self.m_last_update_time:Reset()
end

---@return pointer|nil
function atArray:GetPointer()
if not self:IsValid() then
if (not self:IsValid()) then
return
end

return self.m_address
return self.m_ptr
end

---@return pointer|nil
function atArray:GetDataPointer()
if not self:IsValid() then
if (not self:IsValid()) then
return
end

Expand All @@ -142,94 +113,72 @@ end

---@return uint64_t
function atArray:GetAddress()
return self:IsValid() and self.m_address:get_address() or 0x0
return self:IsValid() and self.m_ptr:get_address() or 0x0
end

---@return uint64_t
function atArray:GetDataAddress()
return self:IsValid() and self.m_data_ptr:get_address() or 0x0
end

---@return uint16_t
function atArray:Size()
self:Update()
return self.m_size
end

---@return uint16_t
function atArray:Count()
self:Update()
return self.m_count
end

---@return uint16_t
function atArray:DataSize()
return SizeOf(self.m_data)
end

---@return string
function atArray:DataType()
function atArray:GetDataType()
local _t = "unknonwn"
if (self.m_data_type and IsInstance(self.m_data_type.__type, "string")) then
if (type(self.m_data_type) == "table" and self.m_data_type.__type) then
_t = self.m_data_type.__type
end

return _F("pointer<%s>", _t)
end

---@param i number
---@return pointer
function atArray:Get(i)
self:Update()
---@param i integer
---@return pointer<T>
function atArray:At(i)
assert(math.is_inrange(i, 1, self.m_size), "[atArray]: Index out of bounds!")
return self.m_data[i]
return self.m_data[i]:deref()
end

---@param i number
---@param v pointer
function atArray:Set(i, v)
self:Update()
assert(math.is_inrange(i, 1, self.m_size), "[atArray]: Index out of bounds!")
assert(IsInstance(v, "pointer"), "[atArray]: Attempt to set array value to non-pointer value!")
---@return uint16_t
function atArray:Size()
return self.m_size
end

self.m_data[i] = v
---@return uint16_t
function atArray:Capacity()
return self.m_capacity
end

---@return fun(): integer, pointer Iterator
-- NOTE: As opposed to the `At` method, you must dereference the pointers returned by this iterator.
---@return fun(): integer, pointer_ref<T> Iterator
function atArray:Iter()
self:Update()
local i = 0

return function()
i = i + 1
if i <= self.m_size then
if (i <= self.m_size) then
return i, self.m_data[i]
---@diagnostic disable-next-line: missing-return
end
end
end

---@return fun(): integer, pointer<T> Iterator
function atArray:__pairs()
log.warning("[atArray]: Use of pairs! Please use atArray:Iter() instead.")
return self:Iter()
end

---@return integer
function atArray:__len()
self:Update()
return self.m_size
end

---@return string
function atArray:__tostring()
self:Update()
local buffer = ""
local data_type = self:DataType()

local __type = self:GetDataType()
for i, data in self:Iter() do
buffer = buffer .. _F("\n[%d] %s @ 0x%X>", i, data_type, data:get_address())
buffer = buffer .. _F("\n[%d] %s* @ 0x%X>", i, __type, data:get_address())
end

return buffer
end

Expand Down
Loading
Loading