Skip to content

Instantly share code, notes, and snippets.

View swampservers's full-sized avatar
🎮
Gaming

swampservers

🎮
Gaming
View GitHub Profile
@swampservers
swampservers / net.lua
Created December 9, 2021 02:20
garrysmod - Remove the need for util.AddNetworkString and significantly optimize net.Incoming
-- What this file does:
-- Removes the need to util.AddNetworkString() for net messages
-- It will be added automatically when the server does net.Receive or net.Start with it the first time
-- Optimizes net.Incoming by caching all receivers at the network id
-- The lookup basically changes from Receivers[string.lower(util.NetworkIDToString(id))] to Receivers[id]
local NetworkStringToIDCache = {}
-- Faster than util.NetworkStringToID, returns nil if missing on client, added automatically if missing on server
local function NetworkStringToID(str)
@swampservers
swampservers / materialfix.lua
Last active July 10, 2021 18:56
Garrysmod - Clientside material override patch
-- Mostly-fix for https://github.com/Facepunch/garrysmod-issues/issues/3362 and 4953
-- This won't well if you're trying to set material overrides on the same entity on both the server and client.
-- Also calling SetMaterial() or SetSubMaterial() will reset both materials and submaterials.
-- Put this in lua/autorun/client/materialfix.lua
-- A set of entities which have appeared recently and have clientside material overrides
local watchlist = {}
-- It seems to take about 5 ticks/0.2 sec from when the entity enters PVS to
-- when it reapplies its server material setting (but the time is inconsistent)