Skip to content

Instantly share code, notes, and snippets.

View Earu's full-sized avatar

Ryan Earu

View GitHub Profile
@Earu
Earu / gmod_find_vpns.lua
Last active September 27, 2022 16:58
Find IPs that match known VPNs and proxy servers in Garry's Mod.
local BASE_URL = "https://raw.githubusercontent.com/X4BNet/lists_vpn/main/ipv4.txt"
local IP_PATTERN = "(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)"
local IP_RANGE_PATTERN = "(%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?)/(%d+)"
local function str_to_ip(str)
local o1, o2, o3, o4 = str:match(IP_PATTERN)
o1, o2, o3, o4 = tonumber(o1), tonumber(o2), tonumber(o3), tonumber(o4)
return bit.bor(
o1 * 2 ^ 24,
@Earu
Earu / chatsounds_parser.lua
Last active June 11, 2022 12:23
Generic asynchronous chatsounds lua parser
module("chatsounds_parser", package.seeall)
function is_gmod_env()
return _G.VERSION and _G.VERSIONSTR and _G.BRANCH and _G.vector_origin -- these should be unique enough to determine that we're in gmod
end
lookup = {}
-- abstract away these methods are they are environement specific and we don't want to be constrained to gmod
function build_lookup()
@Earu
Earu / [hackerrank]Tree_huffman_decoding.cpp
Last active May 19, 2022 21:18
Tree: Huffman decoding challenge on hackerrank.com
#include <stack>
string get_sequence(vector<int> source)
{
string ret;
for (int i = 0; i < source.size(); i++)
{
ret.push_back(to_string(source[i])[0]);
}
@Earu
Earu / [hackerrank]_Tree_Preorder_Traversal.cpp
Last active May 19, 2022 19:47
Tree: Preorder Traversal challenge on hackerrank.com
#include <bits/stdc++.h>
#include <stack>
using namespace std;
class Node {
public:
int data;
Node *left;
Node *right;
@Earu
Earu / [hackerrank]_Simple_Text_Editor.cs
Last active May 17, 2022 22:48
Code for the "Simple Text Editor" challenge on hackerrank.com
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
class Operation
{
protected readonly Stack<Operation> operationStack;
protected readonly string context;
@Earu
Earu / advanced_server_search_query.lua
Last active April 16, 2022 14:08
An advanced Garry's Mod server search query processor.
local function parse_host_name_tags(host_name)
local tags = {}
local function add_tag(tag)
tag = tag:Trim()
if #tag > 1 and #tag < 15 then
table.insert(tags, tag)
end
end
local start_index, _ = host_name:find("[%|%,%-]")
@Earu
Earu / fs_hider.lua
Last active January 23, 2022 12:55
Naughty script that allows you to hide files in Garry's Mod. Lua replacement for gm_fshook.
-- if you don't trust the hook library at this point you might wanna
-- replace this with a local callback of sorts
hook.Add("ShouldHideFile", "", function(_, path)
if path:match("custom_file.lua") then return true end
end)
-- hide our detours
local debug_info_cache = {}
local old_debug_getinfo = debug.getinfo
function debug.getinfo(fn, ...)
@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.
@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 / 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