From caa16fe0c493d1895090727a6656f9f68419aa50 Mon Sep 17 00:00:00 2001 From: Denneisk Date: Sat, 3 Jun 2023 01:56:09 -0400 Subject: [PATCH 1/4] Multiple fixes. Fixes using on certain entities. Fixes damage on props not applying when they should. Networks grabbing so frozen props are not grabbed. --- lua/autorun/server/g64_networkstrings.lua | 3 +- lua/autorun/server/g64_sv_init.lua | 64 +++++++++++++++++++---- lua/entities/g64_mario.lua | 62 ++++++++++++---------- 3 files changed, 91 insertions(+), 38 deletions(-) diff --git a/lua/autorun/server/g64_networkstrings.lua b/lua/autorun/server/g64_networkstrings.lua index 12d0c20..02cac90 100644 --- a/lua/autorun/server/g64_networkstrings.lua +++ b/lua/autorun/server/g64_networkstrings.lua @@ -25,4 +25,5 @@ util.AddNetworkString("G64_COLLECTED1UP") util.AddNetworkString("G64_COLLECTEDCOIN") util.AddNetworkString("G64_SPAWNNEWPLAYER") util.AddNetworkString("G64_UPDATEHELDOBJECT") -util.AddNetworkString("G64_TELEPORTMARIO") \ No newline at end of file +util.AddNetworkString("G64_TELEPORTMARIO") +util.AddNetworkString("G64_GRABREQUEST") \ No newline at end of file diff --git a/lua/autorun/server/g64_sv_init.lua b/lua/autorun/server/g64_sv_init.lua index bf50f8a..7423b13 100644 --- a/lua/autorun/server/g64_sv_init.lua +++ b/lua/autorun/server/g64_sv_init.lua @@ -352,14 +352,9 @@ net.Receive("G64_UPLOADCOLORS", function(len, ply) end end) -net.Receive("G64_DAMAGEENTITY", function(len, ply) - local mario = net.ReadEntity() - local victim = net.ReadEntity() - local forceVec = net.ReadVector() - local hitPos = net.ReadVector() - local minDmg = net.ReadUInt(8) - - if not IsValid(victim) or !IsValid(mario) then return end +local function damageEntity(mario, victim, forceVec, hitPos, minDmg, ply) + --print(mario, victim, forceVec, hitpos, minDmg, ply) + if not IsValid(victim) or not IsValid(mario) then return end local victimHealth = victim:Health() if victim:IsNPC() or victim:IsPlayer() or victimHealth > 0 then local d = DamageInfo() @@ -394,11 +389,34 @@ net.Receive("G64_DAMAGEENTITY", function(len, ply) local phys = victim:GetPhysicsObject() phys:ApplyForceOffset(forceVec * 7800, hitPos) + + -- Allow damage taking for things like damage detectors + if victim.TakeDamageInfo ~= nil then + local d = DamageInfo() + local damage = math.random(minDmg, minDmg+10) + d:SetDamage(damage) + d:SetAttacker(mario) + d:SetInflictor(mario) + d:SetDamageType(DMG_GENERIC) + d:SetDamageForce(forceVec * 15000) + d:SetDamagePosition(hitPos) + + victim:TakeDamageInfo(d) + end end if ply:GetUseEntity() ~= NULL then - ply:GetUseEntity():Use(mario, mario, USE_ON) + ply:GetUseEntity():Use(ply, mario, USE_ON) end +end + +net.Receive("G64_DAMAGEENTITY", function(len, ply) + local mario = net.ReadEntity() + local victim = net.ReadEntity() + local forceVec = net.ReadVector() + local hitPos = net.ReadVector() + local minDmg = net.ReadUInt(8) + damageEntity(mario, victim, forceVec, hitPos, minDmg, ply) end) net.Receive("G64_REMOVEINVALIDMARIO", function(len, ply) @@ -477,6 +495,34 @@ net.Receive("G64_UPDATEHELDOBJECT", function(len, ply) end end) +local function GrabRequestReply(_, ply) + local mario = ply.MarioEnt + local entity = net.ReadEntity() + local forceVec = net.ReadVector() + local hitPos = net.ReadVector() + local volume = 1000000 + local phys = entity:GetPhysicsObject() + + if phys:IsValid() and phys:IsMotionEnabled() and phys:IsMoveable() then -- if not frozen + volume = phys:GetVolume() + end + + if volume < 65000 then + net.Start("G64_GRABREQUEST") + net.WriteBool(true) + net.WriteEntity(entity) + net.Send(ply) + else + print("Failed grab, damaging") + damageEntity(mario, entity, forceVec, hitPos, 15, ply) + net.Start("G64_GRABREQUEST", true) + net.WriteBool(false) + net.WriteEntity(entity) + net.Send(ply) + end +end +net.Receive("G64_GRABREQUEST", GrabRequestReply) + local meta = FindMetaTable("Player") meta.DefaultGodEnable = meta.DefaultGodEnable or meta.GodEnable diff --git a/lua/entities/g64_mario.lua b/lua/entities/g64_mario.lua index 181d609..d450f4c 100644 --- a/lua/entities/g64_mario.lua +++ b/lua/entities/g64_mario.lua @@ -807,6 +807,25 @@ if CLIENT then local pickUpWhitelist = { prop_physics = true } + + local function GrabRequestReply() + if net.ReadBool() then + local entity = net.ReadEntity() + -- If somehow these important things changed in between net messages + if pickUpWhitelist[entity:GetClass()] and self.holdingObject == false and IsValid(self.heldObject) == false then + libsm64.SetMarioAction(self.MarioId, g64types.SM64MarioAction.ACT_PICKING_UP) + self.heldObject = entity + self.waitForHold = true + end + else + net.ReadEntity().HitStunTimer = 0.25 + local soundArg = GetSoundArg(g64types.SM64SoundTable.SOUND_ACTION_HIT) + libsm64.PlaySoundGlobal(soundArg) + end + self.pickupMode = false + end + net.Receive("G64_GRABREQUEST", GrabRequestReply) + local function PerformGroundAttacks() if self:MarioIsAttacking() then local tr = util.TraceHull({ @@ -838,35 +857,21 @@ if CLIENT then net.WriteUInt(dmg, 8) net.SendToServer() end - else - local volume = 1000000 - if self.pickupMode == true and pickUpWhitelist[tr.Entity:GetClass()] and - g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_KICKING) == false and - g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_TRIPPING) == false and - self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK and - self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK_SLIDE then - tr.Entity:PhysicsInit(6) - local phys = tr.Entity:GetPhysicsObject() - if phys:IsValid() == false then - tr.Entity:PhysicsDestroy() - else - volume = phys:GetVolume() - end - tr.Entity:PhysicsDestroy() - self.pickupMode = false - end - - --print(volume) - if volume < 65000 then - if self.holdingObject == false and IsValid(self.heldObject) == false then - libsm64.SetMarioAction(self.MarioId, g64types.SM64MarioAction.ACT_PICKING_UP) - self.heldObject = tr.Entity - self.waitForHold = true - end + -- Need this here because we need the check for the else case + elseif self.pickupMode == true then + -- Doing this full check here + if pickUpWhitelist[tr.Entity:GetClass()] and + g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_KICKING) == false and + g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_TRIPPING) == false and + self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK and + self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK_SLIDE and + self.holdingObject == false and IsValid(self.heldObject) == false then + net.Start("G64_GRABREQUEST", true) + net.WriteEntity(tr.Entity) + net.WriteVector(self.marioForward) + net.WriteVector(tr.HitPos) + net.SendToServer() else - tr.Entity.HitStunTimer = 0.25 - local soundArg = GetSoundArg(g64types.SM64SoundTable.SOUND_ACTION_HIT) - libsm64.PlaySoundGlobal(soundArg) net.Start("G64_DAMAGEENTITY") net.WriteEntity(self) net.WriteEntity(tr.Entity) @@ -875,6 +880,7 @@ if CLIENT then net.WriteUInt(15, 8) net.SendToServer() end + self.pickupMode = false end end end From 6860b466252147d559750929db171b9d9e1a9f4f Mon Sep 17 00:00:00 2001 From: Denneisk Date: Sat, 3 Jun 2023 02:01:24 -0400 Subject: [PATCH 2/4] Removed debug --- lua/autorun/server/g64_sv_init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/autorun/server/g64_sv_init.lua b/lua/autorun/server/g64_sv_init.lua index 7423b13..3bf5e28 100644 --- a/lua/autorun/server/g64_sv_init.lua +++ b/lua/autorun/server/g64_sv_init.lua @@ -513,7 +513,6 @@ local function GrabRequestReply(_, ply) net.WriteEntity(entity) net.Send(ply) else - print("Failed grab, damaging") damageEntity(mario, entity, forceVec, hitPos, 15, ply) net.Start("G64_GRABREQUEST", true) net.WriteBool(false) From 5bffd7b435c437e8253704e037437099f42b8956 Mon Sep 17 00:00:00 2001 From: Denneisk Date: Sat, 3 Jun 2023 08:40:48 -0400 Subject: [PATCH 3/4] Fixed improper handling of punches for damage --- lua/entities/g64_mario.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lua/entities/g64_mario.lua b/lua/entities/g64_mario.lua index d450f4c..c5fc734 100644 --- a/lua/entities/g64_mario.lua +++ b/lua/entities/g64_mario.lua @@ -858,9 +858,7 @@ if CLIENT then net.SendToServer() end -- Need this here because we need the check for the else case - elseif self.pickupMode == true then - -- Doing this full check here - if pickUpWhitelist[tr.Entity:GetClass()] and + elseif self.pickupMode == true and pickUpWhitelist[tr.Entity:GetClass()] and g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_KICKING) == false and g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_TRIPPING) == false and self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK and @@ -871,16 +869,18 @@ if CLIENT then net.WriteVector(self.marioForward) net.WriteVector(tr.HitPos) net.SendToServer() - else - net.Start("G64_DAMAGEENTITY") - net.WriteEntity(self) - net.WriteEntity(tr.Entity) - net.WriteVector(self.marioForward) - net.WriteVector(tr.HitPos) - net.WriteUInt(15, 8) - net.SendToServer() - end self.pickupMode = false + else + tr.Entity.HitStunTimer = 0.25 + local soundArg = GetSoundArg(g64types.SM64SoundTable.SOUND_ACTION_HIT) + libsm64.PlaySoundGlobal(soundArg) + net.Start("G64_DAMAGEENTITY") + net.WriteEntity(self) + net.WriteEntity(tr.Entity) + net.WriteVector(self.marioForward) + net.WriteVector(tr.HitPos) + net.WriteUInt(15, 8) + net.SendToServer() end end end From 1b1659fc853155a71b59a2a52b0b9108adfa614f Mon Sep 17 00:00:00 2001 From: Denneisk Date: Wed, 7 Jun 2023 22:31:51 -0400 Subject: [PATCH 4/4] Restored vanish cap functionality --- lua/autorun/client/g64_cl_init.lua | 5 +++-- lua/weapons/gmod_tool/stools/g64surfacechanger.lua | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/autorun/client/g64_cl_init.lua b/lua/autorun/client/g64_cl_init.lua index 4b9ce0b..5417961 100644 --- a/lua/autorun/client/g64_cl_init.lua +++ b/lua/autorun/client/g64_cl_init.lua @@ -283,15 +283,16 @@ hook.Add("G64Initialized", "G64_ENTITY_GEO", function() end local mario = LocalPlayer().MarioEnt + local marioIsValid = IsValid(mario) for j,surfaceId in pairs(surfaceIds[k]) do --if v:GetSolidFlags() ~= 256 then print(v, v:GetSolidFlags()) end if v:GetCollisionGroup() == COLLISION_GROUP_WORLD or v.DontCollideWithMario == true or v == LocalPlayer():GetVehicle() or - (IsValid(mario) and mario.hasVanishCap == true) or + (marioIsValid and v.G64SurfaceType == 123 and mario.hasVanishCap) or v:IsSolid() == false or v:GetNWInt("Solidity") == 0 or - (IsValid(mario) and mario.heldObj == v) then + (marioIsValid and mario.heldObj == v) then libsm64.SurfaceObjectMove(surfaceId, noCollidePos, v:GetAngles()) else diff --git a/lua/weapons/gmod_tool/stools/g64surfacechanger.lua b/lua/weapons/gmod_tool/stools/g64surfacechanger.lua index bece415..677f145 100644 --- a/lua/weapons/gmod_tool/stools/g64surfacechanger.lua +++ b/lua/weapons/gmod_tool/stools/g64surfacechanger.lua @@ -77,4 +77,4 @@ list.Set( "SurfaceTypes", "#tool.g64surfacechanger.hard_not_slippery", { g64surf list.Set( "SurfaceTypes", "#tool.g64surfacechanger.vertical_wind", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_VERTICAL_WIND } ) list.Set( "SurfaceTypes", "#tool.g64surfacechanger.horizontal_wind", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_HORIZONTAL_WIND } ) list.Set( "SurfaceTypes", "#tool.g64surfacechanger.noise_default", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_NOISE_DEFAULT } ) ---list.Set( "SurfaceTypes", "#tool.g64surfacechanger.vanish_cap_walls", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_VANISH_CAP_WALLS } ) \ No newline at end of file +list.Set( "SurfaceTypes", "#tool.g64surfacechanger.vanish_cap_walls", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_VANISH_CAP_WALLS } ) \ No newline at end of file