|
| 1 | +-- Copyright (C) 2026 SAMURAI (xesdoog) & Contributors. |
| 2 | +-- This file is part of Samurai's Scripts. |
| 3 | +-- |
| 4 | +-- Permission is hereby granted to copy, modify, and redistribute |
| 5 | +-- this code as long as you respect these conditions: |
| 6 | +-- * Credit the owner and contributors. |
| 7 | +-- * Provide a copy of or a link to the original license (GPL-3.0 or later); see LICENSE.md or <https://www.gnu.org/licenses/>. |
| 8 | + |
| 9 | + |
| 10 | +local CStructView = require("includes.classes.gta.CStructView") |
| 11 | + |
| 12 | +---@class IPAddress |
| 13 | +---@field private m_decimal uint32_t |
| 14 | +---@field private m_packed vec4 |
| 15 | +---@overload fun(n: uint32_t): IPAddress |
| 16 | +local IPAddress <const> = {} |
| 17 | +IPAddress.__index = IPAddress |
| 18 | +---@diagnostic disable-next-line |
| 19 | +setmetatable(IPAddress, { |
| 20 | + __call = function(t, ...) |
| 21 | + return t.new(...) |
| 22 | + end |
| 23 | +}) |
| 24 | + |
| 25 | +---@param n uint32_t |
| 26 | +---@return IPAddress |
| 27 | +function IPAddress.new(n) |
| 28 | + local packed = vec4:zero() |
| 29 | + if (n ~= 0) then |
| 30 | + packed = vec4:new( |
| 31 | + math.floor(n / 16777216), |
| 32 | + math.floor(n / 65536) % 256, |
| 33 | + math.floor(n / 256) % 256, |
| 34 | + n % 256 |
| 35 | + ) |
| 36 | + end |
| 37 | + |
| 38 | + return setmetatable({ |
| 39 | + m_decimal = n, |
| 40 | + m_packed = packed |
| 41 | + ---@diagnostic disable-next-line |
| 42 | + }, IPAddress) |
| 43 | +end |
| 44 | + |
| 45 | +---@return string |
| 46 | +function IPAddress:__tostring() |
| 47 | + return _F("%d.%d.%d.%d", |
| 48 | + self.m_packed.x, |
| 49 | + self.m_packed.y, |
| 50 | + self.m_packed.z, |
| 51 | + self.m_packed.w |
| 52 | + ) |
| 53 | +end |
| 54 | + |
| 55 | +-------------------------------------- |
| 56 | +-- Class: rlGamerInfo |
| 57 | +-------------------------------------- |
| 58 | +---@class rlGamerInfo : CStructBase<rlGamerInfo> |
| 59 | +---@field m_peer_id pointer<uint64_t> |
| 60 | +---@field m_rockstar_id pointer<int64_t> |
| 61 | +---@field m_external_ip pointer<uint32_t> |
| 62 | +---@field m_external_port pointer<uint16_t> |
| 63 | +---@field m_internal_ip pointer<uint32_t> |
| 64 | +---@field m_internal_port pointer<uint16_t> |
| 65 | +---@field m_nat_type pointer<uint32_t> |
| 66 | +---@field m_player_name pointer<string> // 0x00DC |
| 67 | +---@overload fun(ptr: pointer): rlGamerInfo |
| 68 | +local rlGamerInfo = CStructView("rlGamerInfo", 0x0F90) |
| 69 | + |
| 70 | +---@param ptr pointer |
| 71 | +---@return rlGamerInfo |
| 72 | +function rlGamerInfo.new(ptr) |
| 73 | + return setmetatable({ |
| 74 | + m_ptr = ptr, |
| 75 | + m_peer_id = ptr:add(0x0008), |
| 76 | + m_rockstar_id = ptr:add(0x0010), |
| 77 | + m_external_ip = ptr:add(0x00A8), |
| 78 | + m_external_port = ptr:add(0x00AC), |
| 79 | + m_internal_ip = ptr:add(0x00B0), |
| 80 | + m_internal_port = ptr:add(0x00B4), |
| 81 | + m_nat_type = ptr:add(0x00B8), |
| 82 | + m_player_name = ptr:add(0x00DC), |
| 83 | + ---@diagnostic disable-next-line: param-type-mismatch |
| 84 | + }, rlGamerInfo) |
| 85 | +end |
| 86 | + |
| 87 | +---@return IPAddress |
| 88 | +function rlGamerInfo:GetExternalIP() |
| 89 | + return IPAddress(self.m_external_ip:get_dword()) |
| 90 | +end |
| 91 | + |
| 92 | +---@return IPAddress |
| 93 | +function rlGamerInfo:GetInternalIP() |
| 94 | + return IPAddress(self.m_internal_ip:get_dword()) |
| 95 | +end |
| 96 | + |
| 97 | +---@return string |
| 98 | +function rlGamerInfo:GetPlayerName() |
| 99 | + return self.m_player_name:get_string() |
| 100 | +end |
| 101 | + |
| 102 | +return rlGamerInfo |
0 commit comments