Skip to content

Instantly share code, notes, and snippets.

View Earu's full-sized avatar

Ryan Earu

View GitHub Profile
@Earu
Earu / easychat_nametags.lua
Last active April 18, 2020 01:03
An EasyChat nametags module using markup.
surface.CreateFont("NameTagFont", {
font = "Tahoma",
extended = true,
size = 100,
weight = 880,
additive = false,
})
surface.CreateFont("NameTagShadowFont", {
font = "Tahoma",
@Earu
Earu / easychat_targetid.lua
Last active January 20, 2020 15:44
Garry's Mod HUDDrawTargetID with EasyChat markup.
AddCSLuaFile()
if SERVER then return end
local default_color = Color(68, 112, 146, 255)
local black_color = Color(0, 0, 0, 255)
local function default_trace()
local eye_pos = EyePos()
return util.TraceLine({
@Earu
Earu / gmod_wiki_style_fix.css
Last active February 7, 2020 14:55
A CSS fix for the new gmod wiki, so it looks like it used to.
html {
background-image: none !important;
}
body {
margin: 0px !important;
max-width: 100% !important;
}
.body {
@Earu
Earu / gmod_image_networking.lua
Created February 5, 2020 01:07
Garry's Mod image networking (proof of concept)
local NET_SEND_OWN_IMG = "IMG_SEND_OWN_IMG"
local NET_TRANSFER_IMG = "IMG_TRANSFER_IMG"
local NET_REQ_CHECKSUM = "IMG_REQ_CHECKSUM"
local CHUNK_SIZE = 60000
local THROTTLE_DELAY = 0.05 -- in seconds
if CLIENT then
local CACHE_DIRECTORY = "img_cache"
if not file.Exists(CACHE_DIRECTORY, "DATA") then
file.CreateDir(CACHE_DIRECTORY)
@Earu
Earu / websocket.lua
Last active September 27, 2020 11:13
Garry's Mod client-side websockets.
local function init_listener_type(obj, browser, name)
local listeners_key = ("%sListeners"):format(name)
local callback_key = ("On%s"):format(name)
local add_listener_key = ("Add%sListener"):format(name)
obj[listeners_key] = {}
obj[callback_key] = function(...)
for _, listener in ipairs(obj[listeners_key]) do
listener(...)
end
@Earu
Earu / easychat_local_tab.lua
Last active April 18, 2020 01:05
A simple EasyChat tab module that allows you to outsource your local Garry's Mod chat.
local tag = "local_tab"
local EC_LEGACY_ENTRY = GetConVar("easychat_legacy_entry")
local EC_LEGACY_TEXT = GetConVar("easychat_legacy_text")
local HAS_CHROMIUM = jit.arch == "x64"
local use_new_text_entry = (EC_LEGACY_ENTRY and not EC_LEGACY_ENTRY:GetBool()) or not EC_LEGACY_ENTRY
local use_new_richtext = (EC_LEGACY_TEXT and not EC_LEGACY_TEXT:GetBool()) or not EC_LEGACY_TEXT
local tab = vgui.Create("DPanel")
@Earu
Earu / easychat_os_mentions.lua
Last active September 4, 2020 22:31
EasyChat mentions sent directly to you via your os notifications.
require("win_toast") -- you need https://github.com/Earu/gm_win_toast
local base_dir = "windows_mentions"
local function get_avatar(id64, success_callback, err_callback)
http.Fetch("http://steamcommunity.com/profiles/" .. id64 .. "?xml=1", function(content, size)
local ret = content:match("<avatarIcon><!%[CDATA%[(.-)%]%]></avatarIcon>")
success_callback(ret)
end, err_callback)
end
@Earu
Earu / easychat_native_playersay_calls.lua
Created July 25, 2021 13:33
POC for detecting native PlayerSay calls and fowarding them to EasyChat's own networking (only works in sandbox derived gamemodes).
--[[
---------------------------------------------------------------------
THIS ONLY WORKS IN SANDBOX, DARKRP DOES WEIRD STUFF WITH ITS
GAMEMODE PLAYERSAY HOOK SO IT WONT WORK (SAME WITH MURDER)
---------------------------------------------------------------------
--]]
hook.Add("PostGamemodeLoaded", TAG, function()
local existing_callbacks = hook.GetTable().PlayerSay or {}
for identifier, callback in pairs(existing_callbacks) do
@Earu
Earu / server_screenshot.lua
Last active August 22, 2021 09:39
POC for taking a screenshot of a client's playermodel from a random angle from the server.
local TAG = "SCREENSHOT_SV"
if SERVER then
util.AddNetworkString(TAG)
local token_base = "1234567890_@#$abcdefghijklmnopqrstuvwxyz"
local function generate_token()
local ret = ""
for _ = 1, math.random(10, 32) do
local char = token_base[math.random(#token_base)]
@Earu
Earu / hook_async.lua
Last active August 22, 2021 10:34
POC for a Garry's Mod asynchronous event library.
--[[
MAIN DIFFERENCES WITH THE SYNCHRONOUS HOOK LIBRARY
- You cannot add a hook callback to an event that is being executed
example:
hook.Add("Think", "example", function()
hook.Add("Think", "example2", function() end)
end)
In this case the hook would be added from the next call of the Think event
and not in the callback.