Skip to content

Commit

Permalink
more missing swep impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
luttje committed Aug 24, 2024
1 parent d4be1b1 commit 1deb5db
Show file tree
Hide file tree
Showing 30 changed files with 805 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ function math.random(min, max)
return originalMathRandom(min, max)
end

function math.pow(base, exponent)
return base ^ exponent
end

-- Since Lua 5.3 non-integers give an error
local originalRandomSeed = math.randomseed

function math.randomseed(seed)
originalRandomSeed(math.floor(seed))
end

util = Utilities
util.PrecacheModel = _R.Entity.PrecacheModel
util.PrecacheSound = _R.Entity.PrecacheSound
Expand All @@ -69,6 +80,7 @@ util.NetworkStringToID = function() return 0 end -- Not needed for us.
util.TraceLine = Traces.TraceLine
util.TraceHull = Traces.TraceHull
util.TraceEntity = Traces.TraceEntity
util.PointContents = Traces.PointContents

util.JSONToTable = function(json)
return Json.Decode(json)
Expand All @@ -83,6 +95,8 @@ util.CRC = function(unencoded)
return tostring(Serializers.Crc32(unencoded))
end

util.SharedRandom = Randoms.SharedRandomFloat

ents = {
Create = Entities.CreateByName,

Expand Down Expand Up @@ -214,6 +228,8 @@ IsFirstTimePredicted = Predictions.IsFirstTimePredicted
LerpVector = Vectors.Lerp

RecipientFilter = RecipientFilters.Create
EffectData = Effects.Create
util.Effect = Effects.Dispatch

system.AppTime = Systems.GetSecondsSinceAppActive
system.IsOSX = Systems.IsOsx
Expand Down Expand Up @@ -401,6 +417,12 @@ game = {
GetMap = Engines.GetLevelName,
}

local EFFECT_DATA_META = FindMetaTable("EffectData")
EFFECT_DATA_META.GetEntIndex = EFFECT_DATA_META.GetEntityIndex
EFFECT_DATA_META.SetEntIndex = EFFECT_DATA_META.SetEntityIndex
EFFECT_DATA_META.GetAttachment = EFFECT_DATA_META.GetAttachmentIndex
EFFECT_DATA_META.SetAttachment = EFFECT_DATA_META.SetAttachmentIndex

local VECTOR_META = FindMetaTable("Vector")
VECTOR_META.AngleEx = VECTOR_META.AngleWithUp
VECTOR_META.Distance = VECTOR_META.DistanceTo
Expand Down Expand Up @@ -432,6 +454,7 @@ function ANGLE_META:Set(angleToCopy)
end

local ENTITY_META = FindMetaTable("Entity")
ENTITY_META.EntIndex = ENTITY_META.GetEntityIndex
ENTITY_META.Health = ENTITY_META.GetHealth
ENTITY_META.GetPos = ENTITY_META.GetPosition
ENTITY_META.SetPos = ENTITY_META.SetPosition
Expand Down Expand Up @@ -459,6 +482,8 @@ ENTITY_META.GetNumBodyGroups = ENTITY_META.GetBodyGroupsCount
ENTITY_META.WaterLevel = ENTITY_META.GetWaterLevel
ENTITY_META.SetMaterial = ENTITY_META.SetMaterialOverride
ENTITY_META.GetMaterial = ENTITY_META.GetMaterialOverride
ENTITY_META.GetAbsVelocity = ENTITY_META.GetLocalVelocity
ENTITY_META.SetAbsVelocity = ENTITY_META.SetLocalVelocity

function ENTITY_META:GetDTAngle(index)
return self:GetNetworkDataValue(_E.NETWORK_VARIABLE_TYPE.ANGLE, index)
Expand Down Expand Up @@ -611,7 +636,7 @@ WEAPON_META.Ammo1 = WEAPON_META.GetPrimaryAmmoCount
WEAPON_META.Ammo2 = WEAPON_META.GetSecondaryAmmoCount

local PLAYER_META = FindMetaTable("Player")
PLAYER_META.GetShootPos = ENTITY_META.GetEyePosition
PLAYER_META.GetShootPos = ENTITY_META.GetWeaponShootPosition
PLAYER_META.UserID = PLAYER_META.GetUserId
PLAYER_META.AccountID = PLAYER_META.GetAccountId
PLAYER_META.SteamID = PLAYER_META.GetSteamId
Expand Down Expand Up @@ -641,6 +666,14 @@ PLAYER_META.KeyReleased = PLAYER_META.WasKeyReleased
PLAYER_META.GetFOV = PLAYER_META.GetFov
PLAYER_META.SetFOV = PLAYER_META.SetFov

function PLAYER_META:LagCompensation(shouldStart)
if (shouldStart) then
self:StartLagCompensation()
else
self:FinishLagCompensation()
end
end

function PLAYER_META:Crouching()
return self:IsFlagSet(_E.ENGINE_FLAG.DUCKING)
end
Expand Down
2 changes: 1 addition & 1 deletion game/experiment/gamemodes/deathmatch/gamemode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function GM:GiveDefaultItems(client)
local defaultWeaponName = Engines.GetClientConsoleVariableValue(Engines.IndexOfEdict(client), "cl_defaultweapon")
local defaultWeapon = client:OwnsWeaponOfType(defaultWeaponName)

if (ToBaseEntity(defaultWeapon) ~= NULL) then
if (defaultWeapon ~= NULL) then
client:SwitchWeapon(defaultWeapon)
else
client:SwitchWeapon(client:OwnsWeaponOfType("weapon_physcannon"))
Expand Down
2 changes: 1 addition & 1 deletion game/experiment/gamemodes/super/gamemode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function GM:GiveDefaultItems(client)
local defaultWeaponName = Engines.GetClientConsoleVariableValue(Engines.IndexOfEdict(client), "cl_defaultweapon")
local defaultWeapon = client:OwnsWeaponOfType(defaultWeaponName)

if (ToBaseEntity(defaultWeapon) ~= NULL) then
if (defaultWeapon ~= NULL) then
client:SwitchWeapon(defaultWeapon)
else
client:SwitchWeapon(client:OwnsWeaponOfType("weapon_physcannon"))
Expand Down
18 changes: 0 additions & 18 deletions game/experiment/scripts/lua/includes/extensions/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@ if (GAMEUI) then
return
end

local printError = debug.PrintError

function ToBaseEntity(pEntity)
if (not pEntity or type(pEntity) ~= "entity") then
return NULL
end

local success, hEntity = xpcall(_R.Entity.GetBaseEntity, printError, pEntity)
if (not success) then
hEntity = NULL
end
if _DEBUG then
assert(hEntity ~= NULL)
end

return hEntity
end

local ENTITY_META = _R.CBaseAnimating

-- Source has inconsistent naming conventions for these, lets just support both name styles.
Expand Down
2 changes: 1 addition & 1 deletion game/experiment/scripts/lua/includes/extensions/weapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function _R.Weapon.WeaponSound( self, sound_type, soundtime )
-- WeaponSound( self, sound_type, soundtime )
-- else
local shootsound = self:GetShootSound( sound_type )
if ( ToBaseEntity( client ) ~= NULL ) then
if ( client ~= NULL ) then
client:EmitSound( shootsound )
else
self:EmitSound( shootsound )
Expand Down
52 changes: 36 additions & 16 deletions game/experiment/scripts/lua/includes/modules/networks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -711,16 +711,16 @@ end

if (SERVER) then
function MODULE.Send(client)
if (not currentOutgoingMessage) then
error("Networks.Send was called without calling Networks.Start.")
end
if (not currentOutgoingMessage) then
error("Networks.Send was called without calling Networks.Start.")
end

local socketClient = MODULE.ClientToSocketClient(client)
local socketClient = MODULE.ClientToSocketClient(client)

local data = currentOutgoingMessage:GetPackedData()
currentOutgoingMessage = nil
local data = currentOutgoingMessage:GetPackedData()
currentOutgoingMessage = nil

if (not socketClient) then
if (not socketClient) then
debug("Client is not connected yet, queueing message...", client)
MODULE.QueueMessage(client, data)
return
Expand All @@ -729,17 +729,37 @@ if (SERVER) then
socketClient:send(data)
end

function MODULE.Broadcast()
if (not currentOutgoingMessage) then
error("Networks.Broadcast was called without calling Networks.Start.")
end
function MODULE.Broadcast()
if (not currentOutgoingMessage) then
error("Networks.Broadcast was called without calling Networks.Start.")
end

for _, socketClient in ipairs(socketClients) do
MODULE.Send(socketClient.client)
end
for _, socketClient in ipairs(socketClients) do
MODULE.Send(socketClient.client)
end

currentOutgoingMessage = nil
end
currentOutgoingMessage = nil
end

function MODULE.SendOmit(clientOrClientsToExclude)
if (not currentOutgoingMessage) then
error("Networks.SendOmit was called without calling Networks.Start.")
end

local clientsToExclude = type(clientOrClientsToExclude) == "table" and clientOrClientsToExclude or {clientOrClientsToExclude}

for _, socketClient in ipairs(socketClients) do
local client = socketClient.client

if (table.HasValue(clientsToExclude, client)) then
continue
end

MODULE.Send(client)
end

currentOutgoingMessage = nil
end

--- Sends the message to all players that have the entity in their PVS
--- @param entity any
Expand Down
Loading

0 comments on commit 1deb5db

Please sign in to comment.