Skip to content

Commit

Permalink
Merged FPP
Browse files Browse the repository at this point in the history
  • Loading branch information
FPtje committed Jun 24, 2019
1 parent 057e66d commit a44cb70
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 197 deletions.
39 changes: 18 additions & 21 deletions gamemode/modules/fpp/pp/server/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ function FPP.Protect.PhysgunPickup(ply, ent)

if type(ent.PhysgunPickup) == "function" then
local val = ent:PhysgunPickup(ply, ent)
if val ~= nil then return val end
-- Do not return the value, the gamemode will do this
if val ~= nil then return end
elseif ent.PhysgunPickup ~= nil then
return ent.PhysgunPickup
end
Expand All @@ -158,7 +159,8 @@ function FPP.Protect.PhysgunReload(weapon, ply)

if type(ent.OnPhysgunReload) == "function" then
local val = ent:OnPhysgunReload(weapon, ply)
if val ~= nil then return val end
-- Do not return the value, the gamemode will do this
if val ~= nil then return end
elseif ent.OnPhysgunReload ~= nil then
return ent.OnPhysgunReload
end
Expand All @@ -174,7 +176,8 @@ hook.Add("OnPhysgunReload", "FPP.Protect.PhysgunReload", FPP.Protect.PhysgunRelo
function FPP.PhysgunFreeze(weapon, phys, ent, ply)
if type(ent.OnPhysgunFreeze) == "function" then
local val = ent:OnPhysgunFreeze(weapon, phys, ent, ply)
if val ~= nil then return val end
-- Do not return the value, the gamemode will do this
if val ~= nil then return end
elseif ent.OnPhysgunFreeze ~= nil then
return ent.OnPhysgunFreeze
end
Expand Down Expand Up @@ -212,6 +215,8 @@ function FPP.Protect.CanGravGunPickup(ply, ent)
if not tobool(FPP.Settings.FPP_GRAVGUN1.toggle) or not IsValid(ent) then return end

if type(ent.GravGunPickup) == "function" then
-- Function name different than gamemode's (GravGunPickup vs GravGunPickupAllowed)
-- Override FPP's behavior when implemented
local val = ent:GravGunPickup(ply, ent)
if val ~= nil then
if val == false then return false end
Expand All @@ -237,8 +242,9 @@ function FPP.Protect.GravGunPunt(ply, ent)
if type(ent.GravGunPunt) == "function" then
local val = ent:GravGunPunt(ply, ent)
if val ~= nil then
-- Gamemode does not drop the ent when entity returns false
if val == false then DropEntityIfHeld(ent) end
return val
return
end
elseif ent.GravGunPunt ~= nil then
if ent.GravGunPunt == false then DropEntityIfHeld(ent) end
Expand All @@ -262,7 +268,8 @@ function FPP.Protect.PlayerUse(ply, ent)

if type(ent.PlayerUse) == "function" then
local val = ent:PlayerUse(ply, ent)
if val ~= nil then return val end
-- Do not return the value, the gamemode will do this
if val ~= nil then return end
elseif ent.PlayerUse ~= nil then
return ent.PlayerUse
end
Expand All @@ -284,7 +291,8 @@ function FPP.Protect.EntityDamage(ent, dmginfo)

if type(ent.EntityDamage) == "function" then
local val = ent:EntityDamage(ent, inflictor, attacker, amount, dmginfo)
if val ~= nil then return val end
-- Do not return the value, the gamemode will do this
if val ~= nil then return end
elseif ent.EntityDamage ~= nil then
return ent.EntityDamage
end
Expand Down Expand Up @@ -464,7 +472,8 @@ function FPP.Protect.CanTool(ply, trace, tool, ENT)

if IsEntity(ent) and type(ent.CanTool) == "function" and ent:GetClass() ~= "gmod_cameraprop" and ent:GetClass() ~= "gmod_rtcameraprop" then
local val = ent:CanTool(ply, trace, tool, ENT)
if val ~= nil then return val end
-- Do not return the value, the gamemode will do this
if val ~= nil then return end
elseif IsEntity(ent) and ent.CanTool ~= nil and ent:GetClass() ~= "gmod_cameraprop" and ent:GetClass() ~= "gmod_rtcameraprop" then
return ent.CanTool
end
Expand Down Expand Up @@ -518,10 +527,9 @@ function FPP.Protect.CanTool(ply, trace, tool, ENT)
end
hook.Add("CanTool", "FPP.Protect.CanTool", FPP.Protect.CanTool)

function FPP.Protect.CanEditVariable(ent, ply, key, val, editTbl)
function FPP.Protect.CanEditVariable(ent, ply, key, varVal, editTbl)
local val = FPP.Protect.CanProperty(ply, "editentity", ent)
if val ~= false and val ~= true then val = true end
return val
if val ~= nil then return val end
end
hook.Add("CanEditVariable", "FPP.Protect.CanEditVariable", FPP.Protect.CanEditVariable)

Expand Down Expand Up @@ -671,17 +679,6 @@ function ENTITY:FireBullets(bullet, ...)
return backup(self, bullet, ...)
end

hook.Add("EntityRemoved","jeepWorkaround",function(ent)
-- Crash workaround, calling IsValid on "Vehicle [DELETED]" will crash the game (gm_mobenix)
if string.find(tostring(ent), "DELETED") then
return
end

if IsValid(ent) and ent:IsVehicle() and ent.GetPassenger and IsValid(ent:GetPassenger(1)) then
ent:GetPassenger(1):ExitVehicle()
end
end)

-- Hydraulic exploit workaround
-- One should not be able to constrain doors to anything
local canConstrain = constraint.CanConstrain
Expand Down
164 changes: 82 additions & 82 deletions gamemode/modules/fpp/pp/sh_cppi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,108 @@ CPPI.CPPI_DEFER = 102112 --\102\112 = fp
CPPI.CPPI_NOTIMPLEMENTED = 7080 --\70\80 = FP

function CPPI:GetName()
return "Falco's prop protection"
return "Falco's prop protection"
end

function CPPI:GetVersion()
return "universal.1"
return "universal.1"
end

function CPPI:GetInterfaceVersion()
return 1.3
return 1.3
end

function CPPI:GetNameFromUID(uid)
return CPPI.CPPI_NOTIMPLEMENTED
return CPPI.CPPI_NOTIMPLEMENTED
end

local PLAYER = FindMetaTable("Player")
function PLAYER:CPPIGetFriends()
if not self.Buddies then return CPPI.CPPI_DEFER end
local FriendsTable = {}
if not self.Buddies then return CPPI.CPPI_DEFER end
local FriendsTable = {}

for k, v in pairs(self.Buddies) do
if not table.HasValue(v, true) then continue end -- not buddies in anything
table.insert(FriendsTable, k)
end
for k, v in pairs(self.Buddies) do
if not table.HasValue(v, true) then continue end -- not buddies in anything
table.insert(FriendsTable, k)
end

return FriendsTable
return FriendsTable
end

local ENTITY = FindMetaTable("Entity")
function ENTITY:CPPIGetOwner()
local Owner = FPP.entGetOwner(self)
if not IsValid(Owner) or not Owner:IsPlayer() then return SERVER and Owner or nil, self.FPPOwnerID end
return Owner, Owner:UniqueID()
local Owner = FPP.entGetOwner(self)
if not IsValid(Owner) or not Owner:IsPlayer() then return SERVER and Owner or nil, self.FPPOwnerID end
return Owner, Owner:UniqueID()
end

if SERVER then
function ENTITY:CPPISetOwner(ply)
if ply == self.FPPOwner then return end

assert(ply == nil or IsEntity(ply), "The owner of an entity must be set to either nil, NULL or a valid entity.")

local valid = IsValid(ply) and ply:IsPlayer()
local steamId = valid and ply:SteamID() or nil
local canSetOwner = hook.Run("CPPIAssignOwnership", ply, self, valid and ply:UniqueID() or ply)

if canSetOwner == false then return false end
ply = canSetOwner ~= nil and canSetOwner ~= true and canSetOwner or ply
self.FPPOwner = ply
self.FPPOwnerID = steamId

self.FPPOwnerChanged = true
FPP.recalculateCanTouch(player.GetAll(), {self})
self.FPPOwnerChanged = nil

return true
end

function ENTITY:CPPISetOwnerUID(UID)
local ply = UID and player.GetByUniqueID(tostring(UID)) or nil
if UID and not IsValid(ply) then return false end
return self:CPPISetOwner(ply)
end

function ENTITY:CPPICanTool(ply, tool)
local Value = FPP.Protect.CanTool(ply, nil, tool, self)
if Value ~= false and Value ~= true then Value = true end
return Value
end

function ENTITY:CPPICanPhysgun(ply)
return FPP.plyCanTouchEnt(ply, self, "Physgun")
end

function ENTITY:CPPICanPickup(ply)
return FPP.plyCanTouchEnt(ply, self, "Gravgun")
end

function ENTITY:CPPICanPunt(ply)
return FPP.plyCanTouchEnt(ply, self, "Gravgun")
end

function ENTITY:CPPICanUse(ply)
return FPP.plyCanTouchEnt(ply, self, "PlayerUse")
end

function ENTITY:CPPICanDamage(ply)
return FPP.plyCanTouchEnt(ply, self, "EntityDamage")
end

function ENTITY:CPPIDrive(ply)
local Value = FPP.Protect.CanDrive(ply, self)
if Value ~= false and Value ~= true then Value = true end
return Value
end

function ENTITY:CPPICanProperty(ply, property)
local Value = FPP.Protect.CanProperty(ply, property, self)
if Value ~= false and Value ~= true then Value = true end
return Value
end

function ENTITY:CPPICanEditVariable(ply, key, val, editTbl)
return self:CPPICanProperty(ply, "editentity")
end
function ENTITY:CPPISetOwner(ply)
if ply == self.FPPOwner then return end

assert(ply == nil or IsEntity(ply), "The owner of an entity must be set to either nil, NULL or a valid entity.")

local valid = IsValid(ply) and ply:IsPlayer()
local steamId = valid and ply:SteamID() or nil
local canSetOwner = hook.Run("CPPIAssignOwnership", ply, self, valid and ply:UniqueID() or ply)

if canSetOwner == false then return false end
ply = canSetOwner ~= nil and canSetOwner ~= true and canSetOwner or ply
self.FPPOwner = ply
self.FPPOwnerID = steamId

self.FPPOwnerChanged = true
FPP.recalculateCanTouch(player.GetAll(), {self})
self.FPPOwnerChanged = nil

return true
end

function ENTITY:CPPISetOwnerUID(UID)
local ply = UID and player.GetByUniqueID(tostring(UID)) or nil
if UID and not IsValid(ply) then return false end
return self:CPPISetOwner(ply)
end

function ENTITY:CPPICanTool(ply, tool)
local Value = FPP.Protect.CanTool(ply, nil, tool, self)
if Value ~= false and Value ~= true then Value = true end
return Value
end

function ENTITY:CPPICanPhysgun(ply)
return FPP.plyCanTouchEnt(ply, self, "Physgun")
end

function ENTITY:CPPICanPickup(ply)
return FPP.plyCanTouchEnt(ply, self, "Gravgun")
end

function ENTITY:CPPICanPunt(ply)
return FPP.plyCanTouchEnt(ply, self, "Gravgun")
end

function ENTITY:CPPICanUse(ply)
return FPP.plyCanTouchEnt(ply, self, "PlayerUse")
end

function ENTITY:CPPICanDamage(ply)
return FPP.plyCanTouchEnt(ply, self, "EntityDamage")
end

function ENTITY:CPPIDrive(ply)
local Value = FPP.Protect.CanDrive(ply, self)
if Value ~= false and Value ~= true then Value = true end
return Value
end

function ENTITY:CPPICanProperty(ply, property)
local Value = FPP.Protect.CanProperty(ply, property, self)
if Value ~= false and Value ~= true then Value = true end
return Value
end

function ENTITY:CPPICanEditVariable(ply, key, val, editTbl)
return self:CPPICanProperty(ply, "editentity")
end
end
Loading

0 comments on commit a44cb70

Please sign in to comment.