From 0a6c46ef465f595a1115bf424801e89e2c9b217a Mon Sep 17 00:00:00 2001 From: techbot Date: Fri, 22 Dec 2023 00:15:53 +0100 Subject: [PATCH] use pac hooks when possible should help prevent showing stuff when pac is disabled --- lua/autorun/pac_restart.lua | 7 +- lua/pac3/core/client/ear_grab_animation.lua | 2 +- lua/pac3/core/client/init.lua | 13 ++-- lua/pac3/core/client/integration_tools.lua | 18 ++--- lua/pac3/core/client/part_pool.lua | 4 +- lua/pac3/core/client/parts/damage_zone.lua | 16 ++-- lua/pac3/core/client/parts/legacy/model.lua | 10 +-- lua/pac3/core/client/parts/model.lua | 2 +- lua/pac3/core/client/test.lua | 14 ++-- lua/pac3/core/client/util.lua | 25 ++++-- lua/pac3/core/server/in_skybox.lua | 2 +- lua/pac3/core/server/init.lua | 6 +- lua/pac3/core/server/util.lua | 2 +- lua/pac3/core/shared/entity_mutator.lua | 12 +-- lua/pac3/core/shared/footsteps_fix.lua | 14 ++-- lua/pac3/editor/client/init.lua | 4 +- lua/pac3/editor/client/panels/tree.lua | 1 - lua/pac3/editor/client/parts.lua | 76 +++++++++---------- lua/pac3/editor/client/saved_parts.lua | 4 +- lua/pac3/editor/client/settings.lua | 4 +- lua/pac3/editor/client/show_outfit_on_use.lua | 8 +- lua/pac3/editor/client/wear.lua | 14 ++-- lua/pac3/editor/server/util.lua | 2 +- lua/pac3/editor/server/wear.lua | 10 +-- lua/pac3/extra/shared/init.lua | 2 +- 25 files changed, 141 insertions(+), 131 deletions(-) diff --git a/lua/autorun/pac_restart.lua b/lua/autorun/pac_restart.lua index 8c7e527b1..40eba4f1c 100644 --- a/lua/autorun/pac_restart.lua +++ b/lua/autorun/pac_restart.lua @@ -4,7 +4,7 @@ if SERVER then return end -local sv_allowcslua = GetConVar('sv_allowcslua') +local sv_allowcslua = GetConVar("sv_allowcslua") local prefer_local_version = CreateClientConVar("pac_restart_prefer_local_version", "0") function _G.pac_ReloadParts() @@ -92,7 +92,7 @@ function _G.pac_Restart() if pac and pac.Disable then pacLocal.Message("removing all traces of pac3 from lua") - pac.Disable() + pac.Disable(true) pac.Panic() if pace and pace.Editor then @@ -110,7 +110,8 @@ function _G.pac_Restart() for hook_name, hooks in pairs(hook.GetTable()) do for id, func in pairs(hooks) do - if isstring(id) and (id:StartWith("pace_") or id:StartWith("pac_") or id:StartWith("pac3_") or id:StartWith("pacx_")) then + local lower = isstring(id) and string.lower(id) + if lower and (lower:StartWith("pace_") or lower:StartWith("pac_") or lower:StartWith("pac3_") or lower:StartWith("pacx_")) then hook.Remove(hook_name, id) end end diff --git a/lua/pac3/core/client/ear_grab_animation.lua b/lua/pac3/core/client/ear_grab_animation.lua index 95c651c62..511def904 100644 --- a/lua/pac3/core/client/ear_grab_animation.lua +++ b/lua/pac3/core/client/ear_grab_animation.lua @@ -1,5 +1,5 @@ -- see https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/animations.lua#L235 -hook.Add("PostGamemodeLoaded", "pac_ear_grab_animation",function() +pac.AddHook("PostGamemodeLoaded", "ear_grab_animation", function() if GAMEMODE.GrabEarAnimation then -- only add it if it exists local original_ear_grab_animation = GAMEMODE.GrabEarAnimation GAMEMODE.GrabEarAnimation = function(_, ply) diff --git a/lua/pac3/core/client/init.lua b/lua/pac3/core/client/init.lua index c96b0d63f..92faf69bc 100644 --- a/lua/pac3/core/client/init.lua +++ b/lua/pac3/core/client/init.lua @@ -27,14 +27,15 @@ do pac_enable:SetBool(true) end - function pac.Disable() + function pac.Disable(temp) pac.EnableDrawnEntities(false) pac.DisableAddedHooks() pac.CallHook("Disable") - pac_enable:SetBool(false) + if not temp then + pac_enable:SetBool(false) + end end end - include("util.lua") include("class.lua") @@ -58,7 +59,7 @@ include("ear_grab_animation.lua") pac.LoadParts() -hook.Add("OnEntityCreated", "pac_init", function(ent) +pac.AddHook("OnEntityCreated", "init", function(ent) local ply = LocalPlayer() if not ply:IsValid() then return end @@ -67,8 +68,8 @@ hook.Add("OnEntityCreated", "pac_init", function(ent) pac.LocalHands = pac.LocalPlayer:GetHands() pac.in_initialize = true - hook.Run("pac_Initialized") + pac.CallHook("Initialized") pac.in_initialize = nil - hook.Remove("OnEntityCreated", "pac_init") + pac.RemoveHook("OnEntityCreated", "init") end) diff --git a/lua/pac3/core/client/integration_tools.lua b/lua/pac3/core/client/integration_tools.lua index caa033c4e..380266e15 100644 --- a/lua/pac3/core/client/integration_tools.lua +++ b/lua/pac3/core/client/integration_tools.lua @@ -25,7 +25,7 @@ end do local force_draw_localplayer = false - hook.Add("ShouldDrawLocalPlayer", "pac_draw_2d_entity", function() + pac.AddHook("ShouldDrawLocalPlayer", "draw_2d_entity", function() if force_draw_localplayer == true then return true end @@ -244,7 +244,7 @@ function pac.AddEntityClassListener(class, session, check_func, draw_dist) draw_dist = 0 check_func = check_func or function(ent) return ent:GetClass() == class end - local id = "pac_auto_attach_" .. class + local id = "auto_attach_" .. class local weapons = {} local function weapon_think() @@ -282,7 +282,7 @@ function pac.AddEntityClassListener(class, session, check_func, draw_dist) if ent:IsValid() and check_func(ent) then if ent:IsWeapon() then weapons[ent:EntIndex()] = ent - hook.Add("Think", id, weapon_think) + pac.AddHook("Think", id, weapon_think) else pac.SetupENT(ent) ent:AttachPACSession(session) @@ -302,8 +302,8 @@ function pac.AddEntityClassListener(class, session, check_func, draw_dist) created(ent) end - hook.Add("EntityRemoved", id, removed) - hook.Add("OnEntityCreated", id, created) + pac.AddHook("EntityRemoved", id, removed) + pac.AddHook("OnEntityCreated", id, created) end function pac.RemoveEntityClassListener(class, session, check_func) @@ -319,11 +319,11 @@ function pac.RemoveEntityClassListener(class, session, check_func) end end - local id = "pac_auto_attach_" .. class + local id = "auto_attach_" .. class - hook.Remove("Think", id) - hook.Remove("EntityRemoved", id) - hook.Remove("OnEntityCreated", id) + pac.RemoveHook("Think", id) + pac.RemoveHook("EntityRemoved", id) + pac.RemoveHook("OnEntityCreated", id) end timer.Simple(0, function() diff --git a/lua/pac3/core/client/part_pool.lua b/lua/pac3/core/client/part_pool.lua index a601ff395..40a701e3d 100644 --- a/lua/pac3/core/client/part_pool.lua +++ b/lua/pac3/core/client/part_pool.lua @@ -349,8 +349,8 @@ pac.AddHook("Think", "events", function() lamp:SetAngles( pac.LocalPlayer:EyeAngles() ) lamp:Update() - hook.Add("PostRender", "pac_flashlight_stuck_fix", function() - hook.Remove("PostRender", "pac_flashlight_stuck_fix") + pac.AddHook("PostRender", "flashlight_stuck_fix", function() + pac.RemoveHook("PostRender", "flashlight_stuck_fix") lamp:Remove() end) diff --git a/lua/pac3/core/client/parts/damage_zone.lua b/lua/pac3/core/client/parts/damage_zone.lua index bd5f82c4f..d09294530 100644 --- a/lua/pac3/core/client/parts/damage_zone.lua +++ b/lua/pac3/core/client/parts/damage_zone.lua @@ -719,16 +719,16 @@ end) function PART:OnHide() - hook.Remove(self.RenderingHook, "pace_draw_hitbox"..self.UniqueID) + pac.RemoveHook(self.RenderingHook, "pace_draw_hitbox"..self.UniqueID) for _,v in pairs(renderhooks) do - hook.Remove(v, "pace_draw_hitbox"..self.UniqueID) + pac.RemoveHook(v, "pace_draw_hitbox"..self.UniqueID) end end function PART:OnRemove() - hook.Remove(self.RenderingHook, "pace_draw_hitbox") + pac.RemoveHook(self.RenderingHook, "pace_draw_hitbox") for _,v in pairs(renderhooks) do - hook.Remove(v, "pace_draw_hitbox") + pac.RemoveHook(v, "pace_draw_hitbox") end end @@ -738,16 +738,16 @@ function PART:PreviewHitbox() if previousRenderingHook ~= self.RenderingHook then for _,v in pairs(renderhooks) do - hook.Remove(v, "pace_draw_hitbox"..self.UniqueID) + pac.RemoveHook(v, "pace_draw_hitbox"..self.UniqueID) end previousRenderingHook = self.RenderingHook end if not self.Preview then return end - hook.Add(self.RenderingHook, "pace_draw_hitbox"..self.UniqueID, function() - if not self.Preview then hook.Remove(self.RenderingHook, "pace_draw_hitbox"..self.UniqueID) end - if not IsValid(self) then hook.Remove(self.RenderingHook, "pace_draw_hitbox"..self.UniqueID) end + pac.AddHook(self.RenderingHook, "pace_draw_hitbox"..self.UniqueID, function() + if not self.Preview then pac.RemoveHook(self.RenderingHook, "pace_draw_hitbox"..self.UniqueID) end + if not IsValid(self) then pac.RemoveHook(self.RenderingHook, "pace_draw_hitbox"..self.UniqueID) end self:GetWorldPosition() if self.HitboxMode == "Box" then local mins = Vector(-self.Radius, -self.Radius, -self.Length) diff --git a/lua/pac3/core/client/parts/legacy/model.lua b/lua/pac3/core/client/parts/legacy/model.lua index 97a34dd91..505ac48d1 100644 --- a/lua/pac3/core/client/parts/legacy/model.lua +++ b/lua/pac3/core/client/parts/legacy/model.lua @@ -662,13 +662,13 @@ do self.Mesh = nil local real_model = modelPath - local ret = hook.Run("pac_model:SetModel", self, modelPath, self.ModelFallback) + local ret = pac.CallHook("model:SetModel", self, modelPath, self.ModelFallback) if ret == nil then - real_model = pac.FilterInvalidModel(real_model,self.ModelFallback) + real_model = pac.FilterInvalidModel(real_model, self.ModelFallback) else modelPath = ret or modelPath real_model = modelPath - real_model = pac.FilterInvalidModel(real_model,self.ModelFallback) + real_model = pac.FilterInvalidModel(real_model, self.ModelFallback) end self.Model = modelPath @@ -682,7 +682,7 @@ do end end -local NORMAL = Vector(1,1,1) +local NORMAL = Vector(1, 1, 1) function PART:CheckScale() -- RenderMultiply doesn't work with this.. @@ -704,7 +704,7 @@ function PART:SetAlternativeScaling(b) end function PART:SetScale(var) - var = var or Vector(1,1,1) + var = var or Vector(1, 1, 1) self.Scale = var diff --git a/lua/pac3/core/client/parts/model.lua b/lua/pac3/core/client/parts/model.lua index d8fe5de4a..ad647adba 100644 --- a/lua/pac3/core/client/parts/model.lua +++ b/lua/pac3/core/client/parts/model.lua @@ -669,7 +669,7 @@ function PART:ProcessModelChange() end ) else - local status, reason = hook.Run('PAC3AllowMDLDownload', self:GetPlayerOwner(), self, path) + local status, reason = hook.Run("PAC3AllowMDLDownload", self:GetPlayerOwner(), self, path) if ALLOW_TO_MDL:GetBool() and status ~= false then self.loading = "downloading mdl zip" diff --git a/lua/pac3/core/client/test.lua b/lua/pac3/core/client/test.lua index 200f82616..b88b7d587 100644 --- a/lua/pac3/core/client/test.lua +++ b/lua/pac3/core/client/test.lua @@ -79,17 +79,17 @@ local function start_test(name, done) end function test.Setup() - hook.Add("ShouldDrawLocalPlayer", "pac_test", function() return true end) + pac.AddHook("ShouldDrawLocalPlayer", "test", function() return true end) end function test.Teardown() - hook.Remove("ShouldDrawLocalPlayer", "pac_test") + pac.RemoveHook("ShouldDrawLocalPlayer", "test") end function test.Run(done) error("test.Run is not defined") end function test.Remove() - hook.Remove("ShouldDrawLocalPlayer", "pac_test") - hook.Remove("Think", "pac_test_coroutine") + pac.RemoveHook("ShouldDrawLocalPlayer", "test") + pac.RemoveHook("Think", "test_coroutine") if test.done then return end @@ -172,7 +172,7 @@ local function start_test(name, done) test.Remove() end - hook.Add("Think", "pac_test_coroutine", function() + pac.AddHook("Think", "test_coroutine", function() if not test.co then return end local ok, err = coroutine.resume(test.co) @@ -213,7 +213,7 @@ concommand.Add("pac_test", function(ply, _, args) local current_test = nil - hook.Add("Think", "pac_tests", function() + pac.AddHook("Think", "tests", function() if current_test then if current_test.time < os.clock() then msg_error("test ", current_test.name, " timed out") @@ -232,7 +232,7 @@ concommand.Add("pac_test", function(ply, _, args) local name = table.remove(tests, 1) if not name then msg("finished testing") - hook.Remove("Think", "pac_tests") + pac.RemoveHook("Think", "tests") return end diff --git a/lua/pac3/core/client/util.lua b/lua/pac3/core/client/util.lua index 996eea451..a405e3ce7 100644 --- a/lua/pac3/core/client/util.lua +++ b/lua/pac3/core/client/util.lua @@ -364,28 +364,29 @@ do -- hook helpers pac.added_hooks = pac.added_hooks or {} function pac.AddHook(event_name, id, func, priority) - id = "pac_" .. id + id = isstring(id) and "pac_" .. id or id if not DLib and not ULib then priority = nil end - if pac.IsEnabled() then + print("adding", event_name, id) hook.Add(event_name, id, func, priority) + print("adding hooks", event_name .. tostring(id)) + pac.added_hooks[event_name .. tostring(id)] = {event_name = event_name, id = id, func = func, priority = priority} end - - pac.added_hooks[event_name .. id] = {event_name = event_name, id = id, func = func, priority = priority} end function pac.RemoveHook(event_name, id) - id = "pac_" .. id + id = "pac_" .. tostring(id) local data = pac.added_hooks[event_name .. id] if data then hook.Remove(data.event_name, data.id) - + print("removing", data.event_name, data.id) pac.added_hooks[event_name .. id] = nil + print("removing hooks", event_name .. id) end end @@ -395,13 +396,21 @@ do -- hook helpers function pac.EnableAddedHooks() for _, data in pairs(pac.added_hooks) do - hook.Add(data.event_name, data.id, data.func, data.priority) + if ispanel(data.id) and not IsValid(data.id) then -- Panels can be NULL and are (probably) already removed + pac.added_hooks[data.event_name .. tostring(data.id)] = nil + else + hook.Add(data.event_name, data.id, data.func, data.priority) + end end end function pac.DisableAddedHooks() for _, data in pairs(pac.added_hooks) do - hook.Remove(data.event_name, data.id) + if ispanel(data.id) and not IsValid(data.id) then -- Panels can be NULL and are already removed + pac.added_hooks[data.event_name .. tostring(data.id)] = nil + else + hook.Remove(data.event_name, data.id) + end end end end diff --git a/lua/pac3/core/server/in_skybox.lua b/lua/pac3/core/server/in_skybox.lua index 35d4c54a3..01f214272 100644 --- a/lua/pac3/core/server/in_skybox.lua +++ b/lua/pac3/core/server/in_skybox.lua @@ -1,4 +1,4 @@ -hook.Add("InitPostEntity","pac_get_sky_camera",function() +pac.AddHook("InitPostEntity", "get_sky_camera", function() local sky_camera = ents.FindByClass("sky_camera")[1] if sky_camera then local nwVarName = "pac_in_skybox" diff --git a/lua/pac3/core/server/init.lua b/lua/pac3/core/server/init.lua index 4e60b8688..eac2c9fda 100644 --- a/lua/pac3/core/server/init.lua +++ b/lua/pac3/core/server/init.lua @@ -7,8 +7,8 @@ pac.resource = include("pac3/libraries/resource.lua") CreateConVar("has_pac3", "1", {FCVAR_NOTIFY}) CreateConVar("pac_allow_blood_color", "1", {FCVAR_NOTIFY}, "Allow to use custom blood color") -CreateConVar('pac_allow_mdl', '1', CLIENT and {FCVAR_REPLICATED} or {FCVAR_ARCHIVE, FCVAR_REPLICATED}, 'Allow to use custom MDLs') -CreateConVar('pac_allow_mdl_entity', '1', CLIENT and {FCVAR_REPLICATED} or {FCVAR_ARCHIVE, FCVAR_REPLICATED}, 'Allow to use custom MDLs as Entity') +CreateConVar("pac_allow_mdl", "1", CLIENT and {FCVAR_REPLICATED} or {FCVAR_ARCHIVE, FCVAR_REPLICATED}, "Allow to use custom MDLs") +CreateConVar("pac_allow_mdl_entity", "1", CLIENT and {FCVAR_REPLICATED} or {FCVAR_ARCHIVE, FCVAR_REPLICATED}, "Allow to use custom MDLs as Entity") include("util.lua") @@ -20,4 +20,4 @@ include("net_messages.lua") include("test_suite_backdoor.lua") include("in_skybox.lua") -hook.Run("pac_Initialized") +pac.CallHook("Initialized") diff --git a/lua/pac3/core/server/util.lua b/lua/pac3/core/server/util.lua index 4e8918a62..923f340e4 100644 --- a/lua/pac3/core/server/util.lua +++ b/lua/pac3/core/server/util.lua @@ -32,7 +32,7 @@ function pac.AddHook(str, id, func, priority) local status, a, b, c, d, e, f, g = pcall(func, ...) if not status then - pac.Message('Error on hook ' .. str .. ' (' .. id .. ')! ', a) + pac.Message("Error on hook " .. str .. " (" .. id .. ")! ", a) return end diff --git a/lua/pac3/core/shared/entity_mutator.lua b/lua/pac3/core/shared/entity_mutator.lua index 77f20e4b3..6b03d57f6 100644 --- a/lua/pac3/core/shared/entity_mutator.lua +++ b/lua/pac3/core/shared/entity_mutator.lua @@ -301,15 +301,15 @@ if SERVER then end end - hook.Add("PlayerInitialSpawn", "pac_entity_mutators_spawn", function(ply) - local id = "pac_entity_mutators_spawn" .. ply:UniqueID() - hook.Add( "SetupMove", id, function(movingPly, _, cmd) + pac.AddHook("PlayerInitialSpawn", "entity_mutators_spawn", function(ply) + local id = "entity_mutators_spawn" .. ply:UniqueID() + pac.AddHook( "SetupMove", id, function(movingPly, _, cmd) if not ply:IsValid() then - hook.Remove("SetupMove", id) + pac.RemoveHook("SetupMove", id) elseif movingPly == ply and not cmd:IsForced() then emut.ReplicateMutatorsForPlayer(ply) - hook.Remove("SetupMove", id) + pac.RemoveHook("SetupMove", id) end end) end) @@ -323,7 +323,7 @@ function emut.RemoveMutationsForPlayer(ply) end end -hook.Add("EntityRemoved", "pac_entity_mutators_left", function(ent) +pac.AddHook("EntityRemoved", "entity_mutators_left", function(ent) if not IsValid(ent) then return end if ent:IsPlayer() then if Player(ent:UserID()) == NULL then diff --git a/lua/pac3/core/shared/footsteps_fix.lua b/lua/pac3/core/shared/footsteps_fix.lua index 8440073a2..c38ac2382 100644 --- a/lua/pac3/core/shared/footsteps_fix.lua +++ b/lua/pac3/core/shared/footsteps_fix.lua @@ -1,11 +1,11 @@ if game.SinglePlayer() then if SERVER then - util.AddNetworkString('pac_footstep') - util.AddNetworkString('pac_footstep_request_state_update') - util.AddNetworkString('pac_signal_mute_footstep') + util.AddNetworkString("pac_footstep") + util.AddNetworkString("pac_footstep_request_state_update") + util.AddNetworkString("pac_signal_mute_footstep") - hook.Add("PlayerFootstep", "footstep_fix", function(ply, pos, _, snd, vol) + pac.AddHook("PlayerFootstep", "footstep_fix", function(ply, pos, _, snd, vol) net.Start("pac_footstep_request_state_update") net.Send(ply) @@ -17,14 +17,14 @@ if game.SinglePlayer() then net.Broadcast() end) - net.Receive("pac_signal_mute_footstep", function(len,ply) + net.Receive("pac_signal_mute_footstep", function(len, ply) local b = net.ReadBool() ply.pac_mute_footsteps = b if ply.pac_mute_footsteps then - hook.Add("PlayerFootstep", "pac_footstep_silence", function() + pac.AddHook("PlayerFootstep", "footstep_silence", function() return b end) - else hook.Remove("PlayerFootstep", "pac_footstep_silence") end + else pac.RemoveHook("PlayerFootstep", "footstep_silence") end end) diff --git a/lua/pac3/editor/client/init.lua b/lua/pac3/editor/client/init.lua index b4811d6f0..8980714a4 100644 --- a/lua/pac3/editor/client/init.lua +++ b/lua/pac3/editor/client/init.lua @@ -221,7 +221,7 @@ function pace.Panic() if ent:IsValid() then ent.pac_onuse_only = nil ent.pac_onuse_only_check = nil - hook.Remove('pace_OnUseOnlyUpdates', ent) + pac.RemoveHook("pace_OnUseOnlyUpdates", ent) end end end @@ -313,7 +313,7 @@ do local up = Vector(0,0,10000) - hook.Add("HUDPaint", "pac_in_editor", function() + pac.AddHook("HUDPaint", "in_editor", function() for _, ply in ipairs(player.GetAll()) do if ply ~= pac.LocalPlayer and ply:GetNW2Bool("pac_in_editor") then diff --git a/lua/pac3/editor/client/panels/tree.lua b/lua/pac3/editor/client/panels/tree.lua index 83a6745b5..8f479046a 100644 --- a/lua/pac3/editor/client/panels/tree.lua +++ b/lua/pac3/editor/client/panels/tree.lua @@ -619,7 +619,6 @@ end pac.AddHook("pac_OnPartRemove", "pace_remove_tree_nodes", remove_node) - local last_refresh = 0 local function refresh(part) if last_refresh > SysTime() then return end diff --git a/lua/pac3/editor/client/parts.lua b/lua/pac3/editor/client/parts.lua index 37c6e5322..eb77a71c1 100644 --- a/lua/pac3/editor/client/parts.lua +++ b/lua/pac3/editor/client/parts.lua @@ -12,7 +12,7 @@ pace.operations_default = {"help_part_info", "wear", "copy", "paste", "cut", "pa pace.operations_legacy = {"wear", "copy", "paste", "cut", "paste_properties", "clone", "spacer", "registered_parts", "spacer", "save", "load", "spacer", "remove"} pace.operations_experimental = {"help_part_info", "wear", "copy", "paste", "cut", "paste_properties", "clone", "bulk_select", "spacer", "registered_parts", "spacer", "bulk_apply_properties", "partsize_info", "copy_uid", "spacer", "save", "load", "spacer", "remove"} -pace.operations_bulk_poweruser = {"bulk_select","clone", "registered_parts", "spacer", "copy", "paste", "cut", "spacer", "wear", "save", "load", "partsize_info"} +pace.operations_bulk_poweruser = {"bulk_select", "clone", "registered_parts", "spacer", "copy", "paste", "cut", "spacer", "wear", "save", "load", "partsize_info"} if not file.Exists("pac3_config/pac_editor_partmenu_layouts.txt", "DATA") then pace.operations_order = pace.operations_default @@ -130,7 +130,7 @@ end local function DrawHaloHighlight(tbl) if (type(tbl) ~= "table") then return end if not pace.Active then - hook.Remove('PreDrawHalos', "BulkSelectHighlights") + pac.RemoveHook("PreDrawHalos", "BulkSelectHighlights") end --Find out the color and apply the halo @@ -174,7 +174,7 @@ end local function ThinkBulkHighlight() if table.IsEmpty(pace.BulkSelectList) or last_bulk_select_tbl == nil or table.IsEmpty(pac.GetLocalParts()) or (#pac.GetLocalParts() == 1) then - hook.Remove('PreDrawHalos', "BulkSelectHighlights") + pac.RemoveHook("PreDrawHalos", "BulkSelectHighlights") return end DrawHaloHighlight(last_bulk_select_tbl) @@ -474,9 +474,9 @@ end function pace.OnVariableChanged(obj, key, val, not_from_editor) local valType = type(val) - if valType == 'Vector' then + if valType == "Vector" then val = Vector(val) - elseif valType == 'Angle' then + elseif valType == "Angle" then val = Angle(val) end @@ -580,14 +580,14 @@ do -- menu local trap if not pace.Active or refresh_halo_hook then - hook.Remove('PreDrawHalos', "BulkSelectHighlights") + pac.RemoveHook("PreDrawHalos", "BulkSelectHighlights") end //@note registered parts function pace.AddRegisteredPartsToMenu(menu, parent) local partsToShow = {} local clicked = false - hook.Add('Think', menu, function() + pac.AddHook("Think", menu, function() local ctrl = input.IsControlDown() if clicked and not ctrl then @@ -600,7 +600,7 @@ do -- menu menu:SetDeleteSelf(not ctrl) end) - hook.Add('CloseDermaMenus', menu, function() + pac.AddHook("CloseDermaMenus", menu, function() clicked = true if input.IsControlDown() then menu:SetVisible(true) @@ -609,7 +609,7 @@ do -- menu end) local function add_part(menu, part) - local newMenuEntry = menu:AddOption(L(part.FriendlyName or part.ClassName:Replace('_', ' ')), function() + local newMenuEntry = menu:AddOption(L(part.FriendlyName or part.ClassName:Replace("_", " ")), function() pace.RecordUndoHistory() pace.Call("CreatePart", part.ClassName, nil, nil, parent) pace.RecordUndoHistory() @@ -706,7 +706,7 @@ do -- menu add_part(sub, part) end - hook.Add('Think', sub, function() + pac.AddHook("Think", sub, function() local ctrl = input.IsControlDown() if clicked and not ctrl then @@ -719,7 +719,7 @@ do -- menu sub:SetDeleteSelf(not ctrl) end) - hook.Add('CloseDermaMenus', sub, function() + pac.AddHook("CloseDermaMenus", sub, function() if input.IsControlDown() and trap then trap = false sub:SetVisible(true) @@ -796,7 +796,7 @@ do -- menu end for class_name, part in pairs(partsToShow) do - local newMenuEntry = menu:AddOption(L((part.FriendlyName or part.ClassName):Replace('_', ' ')), function() + local newMenuEntry = menu:AddOption(L((part.FriendlyName or part.ClassName):Replace("_", " ")), function() pace.RecordUndoHistory() pace.Call("CreatePart", class_name, nil, nil, parent) pace.RecordUndoHistory() @@ -1062,7 +1062,7 @@ do -- menu local label = line:Add("DLabel") label:SetTextColor(label:GetSkin().Colours.Category.Line.Text) - label:SetText(L((part.FriendlyName or part.ClassName):Replace('_', ' '))) + label:SetText(L((part.FriendlyName or part.ClassName):Replace("_", " "))) label:SizeToContents() label:MoveRightOf(btn, 4) label:SetMouseInputEnabled(false) @@ -1411,17 +1411,17 @@ do -- menu RebuildBulkHighlight() if not silent then if selected_part_added then - surface.PlaySound('buttons/button1.wav') + surface.PlaySound("buttons/button1.wav") - else surface.PlaySound('buttons/button16.wav') end + else surface.PlaySound("buttons/button16.wav") end end if table.IsEmpty(pace.BulkSelectList) then --remove halo hook - hook.Remove('PreDrawHalos', "BulkSelectHighlights") + pac.RemoveHook("PreDrawHalos", "BulkSelectHighlights") else --start halo hook - hook.Add('PreDrawHalos', "BulkSelectHighlights", function() + pac.AddHook("PreDrawHalos", "BulkSelectHighlights", function() local mode = GetConVar("pac_bulk_select_halo_mode"):GetInt() if mode == 0 then return elseif mode == 1 then ThinkBulkHighlight() @@ -2212,7 +2212,7 @@ function pace.addPartMenuComponent(menu, obj, option_name) elseif option_name == "paste" and obj then menu:AddOption(L"paste", function() pace.Paste(obj) end):SetImage(pace.MiscIcons.paste) elseif option_name == "cut" and obj then - menu:AddOption(L"cut", function() pace.Cut(obj) end):SetImage('icon16/cut.png') + menu:AddOption(L"cut", function() pace.Cut(obj) end):SetImage("icon16/cut.png") elseif option_name == "paste_properties" and obj then menu:AddOption(L"paste properties", function() pace.PasteProperties(obj) end):SetImage(pace.MiscIcons.replace) elseif option_name == "clone" and obj then @@ -2247,7 +2247,7 @@ function pace.addPartMenuComponent(menu, obj, option_name) end end) - psi_icon:SetImage('icon16/drive.png') + psi_icon:SetImage("icon16/drive.png") part_size_info:AddOption(L"from bulk select", function() local cumulative_bytes = 0 for _,v in pairs(pace.BulkSelectList) do @@ -2267,12 +2267,12 @@ function pace.addPartMenuComponent(menu, obj, option_name) end) elseif option_name == "bulk_apply_properties" then local bulk_apply_properties,bap_icon = menu:AddSubMenu(L"bulk change properties", function() pace.BulkApplyProperties(obj, "harsh") end) - bap_icon:SetImage('icon16/application_form.png') + bap_icon:SetImage("icon16/application_form.png") bulk_apply_properties:AddOption("Policy: harsh filtering", function() pace.BulkApplyProperties(obj, "harsh") end) bulk_apply_properties:AddOption("Policy: lenient filtering", function() pace.BulkApplyProperties(obj, "lenient") end) elseif option_name == "bulk_select" then bulk_menu, bs_icon = menu:AddSubMenu(L"bulk select ("..#pace.BulkSelectList..")", function() pace.DoBulkSelect(obj) end) - bs_icon:SetImage('icon16/table_multiple.png') + bs_icon:SetImage("icon16/table_multiple.png") bulk_menu.GetDeleteSelf = function() return false end local mode = GetConVar("pac_bulk_select_halo_mode"):GetInt() @@ -2319,16 +2319,16 @@ function pace.addPartMenuComponent(menu, obj, option_name) bulk_menu:AddOption(L"Insert (Move / Cut + Paste)", function() pace.BulkCutPaste(obj) - end):SetImage('icon16/arrow_join.png') + end):SetImage("icon16/arrow_join.png") if not pace.ordered_operation_readystate then bulk_menu:AddOption(L"prepare Ordered Insert (please select parts in order beforehand)", function() pace.BulkCutPasteOrdered() - end):SetImage('icon16/text_list_numbers.png') + end):SetImage("icon16/text_list_numbers.png") else bulk_menu:AddOption(L"do Ordered Insert (select destinations in order)", function() pace.BulkCutPasteOrdered() - end):SetImage('icon16/arrow_switch.png') + end):SetImage("icon16/arrow_switch.png") end @@ -2341,20 +2341,20 @@ function pace.addPartMenuComponent(menu, obj, option_name) --bulk paste modes bulk_menu:AddOption(L"Bulk Paste (bulk select -> into this part)", function() pace.BulkPasteFromBulkSelectToSinglePart(obj) - end):SetImage('icon16/arrow_join.png') + end):SetImage("icon16/arrow_join.png") bulk_menu:AddOption(L"Bulk Paste (clipboard or this part -> into bulk selection)", function() if not pace.Clipboard then pace.Copy(obj) end pace.BulkPasteFromSingleClipboard() - end):SetImage('icon16/arrow_divide.png') + end):SetImage("icon16/arrow_divide.png") bulk_menu:AddOption(L"Bulk Paste (Single paste from bulk clipboard -> into this part)", function() pace.BulkPasteFromBulkClipboard(obj) - end):SetImage('icon16/arrow_join.png') + end):SetImage("icon16/arrow_join.png") bulk_menu:AddOption(L"Bulk Paste (Multi-paste from bulk clipboard -> into bulk selection)", function() pace.BulkPasteFromBulkClipboardToBulkSelect() - end):SetImage('icon16/arrow_divide.png') + end):SetImage("icon16/arrow_divide.png") bulk_menu:AddSpacer() @@ -2381,14 +2381,14 @@ function pace.addPartMenuComponent(menu, obj, option_name) part.Arguments = str..i.."@@0@@0" end end) - end):SetImage('icon16/clock.png') + end):SetImage("icon16/clock.png") bulk_menu:AddOption(L"Pack into a new root group", function() root = pac.CreatePart("group") for i,v in ipairs(pace.BulkSelectList) do v:SetParent(root) end - end):SetImage('icon16/world.png') + end):SetImage("icon16/world.png") bulk_menu:AddSpacer() @@ -2398,21 +2398,21 @@ function pace.addPartMenuComponent(menu, obj, option_name) bulk_menu:AddOption(L"Clear Bulk List", function() pace.ClearBulkList() - end):SetImage('icon16/table_delete.png') + end):SetImage("icon16/table_delete.png") elseif option_name == "spacer" then menu:AddSpacer() elseif option_name == "registered_parts" then pace.AddRegisteredPartsToMenu(menu, not obj) elseif option_name == "hide_editor" then - menu:AddOption(L"hide editor / toggle focus", function() pace.Call("ToggleFocus") end):SetImage('icon16/zoom.png') + menu:AddOption(L"hide editor / toggle focus", function() pace.Call("ToggleFocus") end):SetImage("icon16/zoom.png") elseif option_name == "expand_all" and obj then menu:AddOption(L"expand all", function() - obj:CallRecursive('SetEditorExpand', true) - pace.RefreshTree(true) end):SetImage('icon16/arrow_down.png') + obj:CallRecursive("SetEditorExpand", true) + pace.RefreshTree(true) end):SetImage("icon16/arrow_down.png") elseif option_name == "collapse_all" and obj then menu:AddOption(L"collapse all", function() - obj:CallRecursive('SetEditorExpand', false) - pace.RefreshTree(true) end):SetImage('icon16/arrow_in.png') + obj:CallRecursive("SetEditorExpand", false) + pace.RefreshTree(true) end):SetImage("icon16/arrow_in.png") elseif option_name == "copy_uid" and obj then local menu2, pnl = menu:AddSubMenu(L"Copy part UniqueID", function() pace.CopyUID(obj) end) pnl:SetIcon(pace.MiscIcons.uniqueid) @@ -2422,11 +2422,11 @@ function pace.addPartMenuComponent(menu, obj, option_name) hoverfunc = "open", pac_part = pace.current_part, panel_exp_width = 900, panel_exp_height = 400 - }) end):SetImage('icon16/information.png') + }) end):SetImage("icon16/information.png") elseif option_name == "reorder_movables" and obj then if (obj.Position and obj.Angles and obj.PositionOffset) then local substitute, pnl = menu:AddSubMenu("Reorder / replace base movable") - pnl:SetImage('icon16/application_double.png') + pnl:SetImage("icon16/application_double.png") substitute:AddOption("Create a parent for position substitution", function() pace.SubstituteBaseMovable(obj, "create_parent") end) if obj.Parent then if obj.Parent.Position and obj.Parent.Angles then diff --git a/lua/pac3/editor/client/saved_parts.lua b/lua/pac3/editor/client/saved_parts.lua index 45a2a61ba..981867692 100644 --- a/lua/pac3/editor/client/saved_parts.lua +++ b/lua/pac3/editor/client/saved_parts.lua @@ -58,7 +58,7 @@ function pace.SaveParts(name, prompt_name, override_part, overrideAsUsual) end end - data = hook.Run("pac_pace.SaveParts", data) or data + data = pac.CallHook("pace.SaveParts", data) or data if not override_part and #file.Find("pac3/sessions/*", "DATA") > 0 and not name:find("/") then pace.luadata.WriteFile("pac3/sessions/" .. name .. ".txt", data) @@ -146,7 +146,7 @@ end local latestprop local latest_uid if game.SinglePlayer() then - hook.Add("OnEntityCreated", "PAC_queue_proppacs", function( ent ) + pac.AddHook("OnEntityCreated", "queue_proppacs", function( ent ) if ( ent:GetClass() == "prop_physics" or ent:IsNPC()) and not ent:CreatedByMap() and LocalPlayer().pac_propload_queuedparts then if not table.IsEmpty(LocalPlayer().pac_propload_queuedparts) then ent:EmitSound( "buttons/button4.wav" ) diff --git a/lua/pac3/editor/client/settings.lua b/lua/pac3/editor/client/settings.lua index f70df4cbb..b1c3b3928 100644 --- a/lua/pac3/editor/client/settings.lua +++ b/lua/pac3/editor/client/settings.lua @@ -1661,7 +1661,7 @@ function pace.FillEditorSettings(pnl) local previous_inputs_str = "" pace.FlashNotification("Recording input... Release one key when you're done") - hook.Add("Tick", "pace_buttoncapture_countdown", function() + pac.AddHook("Tick", "pace_buttoncapture_countdown", function() pace.delayshortcuts = RealTime() + 5 local inputs_tbl = {} inputs_str = "" @@ -1692,7 +1692,7 @@ function pace.FillEditorSettings(pnl) --pace.PACActionShortcut[shortcutaction_choices:GetValue()][shortcutaction_index:GetValue()] = tbl pace.delayshortcuts = RealTime() + 5 pace.bindcapturelabel_text = "Recorded input:\n" .. previous_inputs_str - hook.Remove("Tick", "pace_buttoncapture_countdown") + pac.RemoveHook("Tick", "pace_buttoncapture_countdown") end end previous_inputs_str = inputs_str diff --git a/lua/pac3/editor/client/show_outfit_on_use.lua b/lua/pac3/editor/client/show_outfit_on_use.lua index 9346e52eb..56eee8f57 100644 --- a/lua/pac3/editor/client/show_outfit_on_use.lua +++ b/lua/pac3/editor/client/show_outfit_on_use.lua @@ -17,7 +17,7 @@ end local pac_IsPacOnUseOnly = pac.IsPacOnUseOnly -hook.Add("PlayerBindPress", "pac_onuse_only", function(ply, bind, isPressed) +pac.AddHook("PlayerBindPress", "onuse_only", function(ply, bind, isPressed) if bind ~= "use" and bind ~= "+use" then return end if bind ~= "+use" and isPressed then return end if not pac_IsPacOnUseOnly() then return end @@ -47,7 +47,7 @@ do weight = 600, }) - hook.Add("HUDPaint", "pac_onuse_only", function() + pac.AddHook("HUDPaint", "onuse_only", function() if not pac_IsPacOnUseOnly() then return end local ply = pac.LocalPlayer local eyes, aim = ply:EyePos(), ply:GetAimVector() @@ -72,7 +72,7 @@ do end function pace.OnUseOnlyUpdates(cvar, ...) - hook.Call('pace_OnUseOnlyUpdates', nil, ...) + pace.Call("OnUseOnlyUpdates", ...) end cvars.AddChangeCallback("pac_onuse_only", pace.OnUseOnlyUpdates, "PAC3") @@ -122,7 +122,7 @@ function pace.HandleOnUseReceivedData(data) -- behaviour of this (if one of entities on this hook becomes invalid) -- is undefined if DLib is not installed, but anyway - hook.Add('pace_OnUseOnlyUpdates', data.owner, function() + pac.AddHook('pace_OnUseOnlyUpdates', data.owner, function() if pac_IsPacOnUseOnly() then pac.ToggleIgnoreEntity(data.owner, data.owner.pac_onuse_only_check, 'pac_onuse_only') else diff --git a/lua/pac3/editor/client/wear.lua b/lua/pac3/editor/client/wear.lua index a81c91e7e..97f6fbbe8 100644 --- a/lua/pac3/editor/client/wear.lua +++ b/lua/pac3/editor/client/wear.lua @@ -354,7 +354,7 @@ do end end - pac.RemoveHook("Think", "pac_request_outfits") + pac.RemoveHook("Think", "request_outfits") pac.Message("Requesting outfits in 8 seconds...") timer.Simple(8, function() @@ -364,14 +364,14 @@ do end local function Initialize() - pac.RemoveHook("KeyRelease", "pac_request_outfits") + pac.RemoveHook("KeyRelease", "request_outfits") if not pac.LocalPlayer:IsValid() then return end if not pac.IsEnabled() then - pac.RemoveHook("Think", "pac_request_outfits") + pac.RemoveHook("Think", "request_outfits") pace.NeverLoaded = true return end @@ -379,7 +379,7 @@ do LoadUpDefault() end - hook.Add("pac_Enable", "pac_LoadUpDefault", function() + pac.AddHook("pac_Enable", "LoadUpDefault", function() if not pace.NeverLoaded then return end pace.NeverLoaded = nil LoadUpDefault() @@ -387,7 +387,7 @@ do local frames = 0 - pac.AddHook("Think", "pac_request_outfits", function() + pac.AddHook("Think", "request_outfits", function() if RealFrameTime() > 0.2 then -- lag? return end @@ -396,13 +396,13 @@ do if frames > 400 then if not xpcall(Initialize, ErrorNoHalt) then - pac.RemoveHook("Think", "pac_request_outfits") + pac.RemoveHook("Think", "request_outfits") pace.NeverLoaded = true end end end) - pac.AddHook("KeyRelease", "pac_request_outfits", function() + pac.AddHook("KeyRelease", "request_outfits", function() local me = pac.LocalPlayer if me:IsValid() and me:GetVelocity():Length() > 50 then diff --git a/lua/pac3/editor/server/util.lua b/lua/pac3/editor/server/util.lua index c59e607c2..d1a608070 100644 --- a/lua/pac3/editor/server/util.lua +++ b/lua/pac3/editor/server/util.lua @@ -15,7 +15,7 @@ end function pace.CallHook(str, ...) - return hook.Call("pac_" .. str, GAMEMODE, ...) + return hook.Call("pace_" .. str, GAMEMODE, ...) end diff --git a/lua/pac3/editor/server/wear.lua b/lua/pac3/editor/server/wear.lua index f4472fb69..a003a5ab4 100644 --- a/lua/pac3/editor/server/wear.lua +++ b/lua/pac3/editor/server/wear.lua @@ -269,17 +269,17 @@ function pace.SubmitPartNow(data, filter) if not players or istable(players) and not next(players) then return true end -- Alternative transmission system - local ret = hook.Run("pac_SendData", players, data) + local ret = pac.CallHook("SendData", players, data) if ret == nil then net.Start("pac_submit") local bytes, err = net_write_table(data) if not bytes then local errStr = tostring(err) - ErrorNoHalt("[PAC3] Outfit broadcast failed for " .. tostring(owner) .. ": " .. errStr .. '\n') + ErrorNoHalt("[PAC3] Outfit broadcast failed for " .. tostring(owner) .. ": " .. errStr .. "\n") if owner and owner:IsValid() then - owner:ChatPrint('[PAC3] ERROR: Could not broadcast your outfit: ' .. errStr) + owner:ChatPrint("[PAC3] ERROR: Could not broadcast your outfit: " .. errStr) end else net.Send(players) @@ -378,8 +378,8 @@ end util.AddNetworkString("pac_submit") -local pac_submit_spam = CreateConVar('pac_submit_spam', '1', {FCVAR_NOTIFY, FCVAR_ARCHIVE}, 'Prevent users from spamming pac_submit') -local pac_submit_limit = CreateConVar('pac_submit_limit', '30', {FCVAR_NOTIFY, FCVAR_ARCHIVE}, 'pac_submit spam limit') +local pac_submit_spam = CreateConVar("pac_submit_spam", "1", {FCVAR_NOTIFY, FCVAR_ARCHIVE}, "Prevent users from spamming pac_submit") +local pac_submit_limit = CreateConVar("pac_submit_limit", "30", {FCVAR_NOTIFY, FCVAR_ARCHIVE}, "pac_submit spam limit") pace.PCallNetReceive(net.Receive, "pac_submit", function(len, ply) if len < 64 then return end diff --git a/lua/pac3/extra/shared/init.lua b/lua/pac3/extra/shared/init.lua index 4728c341f..5381081a1 100644 --- a/lua/pac3/extra/shared/init.lua +++ b/lua/pac3/extra/shared/init.lua @@ -7,7 +7,7 @@ include("net_combat.lua") local cvar = CreateConVar("pac_restrictions", "0", FCVAR_REPLICATED) if CLIENT then - pac.AddHook("pac_EditorCalcView", "pac_restrictions", function() + pac.AddHook("pac_EditorCalcView", "restrictions", function() if cvar:GetInt() > 0 and not pac.LocalPlayer:IsAdmin() then local ent = pace.GetViewEntity() local dir = pace.ViewPos - ent:EyePos()