Skip to content

Instantly share code, notes, and snippets.

@ManuelBlanc
ManuelBlanc / div0.c
Last active May 26, 2024 04:52
Recover from div by 0
/* div0.c -- Recover from a division by zero.
** References:
** https://learn.microsoft.com/en-us/cpp/cpp/writing-an-exception-filter
** http://ref.x86asm.net/coder64.html
** https://www.felixcloutier.com/x86/idiv
** AMD64 Architecture Programmer's Manual Volume 3
** Intel Architectures Software Developer's Manual Volume 2
** https://web.archive.org/web/20110304144303/http://www.microsoft.com/msj/0898/bugslayer0898.aspx
*/
##
## Generate a list of 256 cryptographically random u64 numbers, arranged in a 64x4 grid.
##
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$bytes = new-object byte[] 8
1..64 |% { $n = (1..4) |% { $rng.GetBytes($b); "0x{0:X16}ull," -f [BitConverter]::ToUint64($b,0) }; $n -join "" }
@ManuelBlanc
ManuelBlanc / prd_constant_calculator.hs
Last active April 30, 2023 00:39
PRD algorithm constant calculator (Haskell)
--
-- Pseudo-random distribution constant calculator.
--
-- The constants are calculated by numerically approximating the roots of
-- the function f(p) = p - p(c) via Newton-Raphson / bisection.
-- Calculating p(c) is easy: evaluate a polynomial and invert it.
--
-- For an explanation and visualization of the PRD algorithm, please see
-- https://observablehq.com/@manuelblanc/pseudo-random-distribution
--
@ManuelBlanc
ManuelBlanc / league_of_legends_unequip_challenge_tokens.ps1
Created April 19, 2023 17:56
League of Legends - Unequip challenge tokens
##
## PowerShell script to remove all equipped challenge tokens.
## (2023-04-19) Donated to the public domain
## Method credit: https://www.reddit.com/r/leagueoflegends/comments/w91xqk/comment/iip126n/
##
# Obtain the port & auth code of the LCU local server.
$command_line = (Get-WmiObject Win32_Process -Filter "name = 'LeagueClientUx.exe'").CommandLine
$command_line -match '--remoting-auth-token=(\w+)'
$LOL_AUTH = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("riot:$($matches[1])"))
@ManuelBlanc
ManuelBlanc / lj_trap.patch
Last active February 27, 2023 06:24
BP Test
commit 8f3872a422beafcc9fc4c4d36e7518be58fb6a8b
Author: ManuelBlanc <manuel.blanc@estudiante.uam.es>
Date: Mon Feb 27 06:59:29 2023 +0100
Implement BC_TRAP and jit.util.setbreakpoint
diff --git a/src/lib_debug.c b/src/lib_debug.c
index 3af7a353..e02070f1 100644
--- a/src/lib_debug.c
+++ b/src/lib_debug.c
@ManuelBlanc
ManuelBlanc / ubmark.lua
Last active February 10, 2021 16:04
ubmark.lua -- A collection of Lua microbenchmarks.
--
-- ubmark.lua -- A collection of Lua microbenchmarks
-- Targeted at LuaJIT 2.1.0-beta3.
--
-- References:
-- https://cr.yp.to/talks/2015.04.16/slides-djb-20150416-a4.pdf
-- https://github.com/google/caliper/wiki/JavaMicrobenchmarks
-- http://www.ellipticgroup.com/html/benchmarkingArticle.html
-- http://hugoduncan.org/criterium/
-- http://www.serpentine.com/criterion/
-- [SERVER] The attack generation.
local _attack_gen = 0
-- [SERVER] When the attack animation is initiated, also request an attack ACK.
mod:hook_safe(BTAttackAction, "enter", function(self, unit, bb, t)
if bb.action.unblockable then return end
local mob_id = Managers.state.unit_storage:go_id(unit)
local atk_id = _attack_gen
mod:network_send("request_attack_ack", mob_id, atk_id)
bb._csb_needs_ack, bb._csb_mob_id, bb._csb_atk_id = true, mob_id, atk_id
@ManuelBlanc
ManuelBlanc / vt1_steam_rich_presence.txt
Last active September 25, 2019 10:52
Localization file for Steam rich presennce in VT1. Exact same format (including indentation) as in example.
"lang"
{
"english"
{
"tokens"
{
"#State_Loading" "Loading..."
"#State_Inn" "Waiting at the Red Moon Inn"
"#State_Tutorial" "Playing the tutorial"
"#State_Menus" "In the menus"
local type, next, tostring = type, next, tostring
local byte, find, format, gsub, concat = string.byte, string.find, string.format, string.gsub, table.concat
local function ctlsub(c)
if c == "\t" then return "\\t"
elseif c == "\n" then return "\\n"
elseif c == "\r" then return "\\r"
else return byte(c) end
end
local function serialize_push(b, v, q)
local t = type(v)
@ManuelBlanc
ManuelBlanc / murmurhash64.lua
Created June 16, 2019 17:54
MurmurHash2A in Lua
--[[
MurmurHash2, 64-bit versions, by Austin Appleby and placed in the public domain.
The same caveats as 32-bit MurmurHash2 apply here - beware of alignment
and endian-ness issues if used across multiple platforms.
Ported to Lua by ManuelBlanc (https://github.com/manuelblanc/).
Requires a 64-bit bitwise operations library. Eg, https://github.com/ManuelBlanc/lua-bit64
--]]
local ffi = require("ffi")