Skip to content

Instantly share code, notes, and snippets.

View stravant's full-sized avatar

Mark Langen stravant

  • Roblox
  • Bay Area
View GitHub Profile
@stravant
stravant / FooBar.lua
Last active July 26, 2020 22:18
Lua class template
local FooBar = {}
FooBar.__index = FooBar
function FooBar.new()
local this = {
_privateVariable = 137,
}
return setmetatable(this, FooBar)
end
--==========================================================================================================--
-- Noise generation code ==--
--==========================================================================================================--
--
local perm = {
151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
-- Wait for the things we need to arrive
game:WaitForChild("Workspace")
game.Workspace:WaitForChild("Terrain")
-- Local copy of terrain to call on throughout the script for speed
local terrain = game.Workspace.Terrain
@stravant
stravant / Walkthrough.md
Created November 30, 2020 05:25
BFBBDecom Walkthrough

Reverse Engineering a Function

Name Mangling Translation

The first thing you will have to do when reverse engineering a function is understand what name the function has / what arguments it takes. To do this, you need to understand name mangling.

Functions in C++ can be overloaded, having different variants, each with different argument types. However, there are multiple ways to write a function signature which really means the same thing, for instance:

  • float32 const* foobar(void);
  • const float *foobar();
@stravant
stravant / ripper.py
Last active December 1, 2020 13:24
BFBB Decomp Utility Script
import sys
from pathlib import Path
import re
INCLUDE_INSTRUCTION_BYTES = False
def cpp_get_qualified(text):
if text.startswith("Q"):
# multiple qualified name
count = int(text[1])
@stravant
stravant / convert.py
Created February 28, 2021 04:10
ldraw -> obj converter for Roblox importing
import sys
from pathlib import Path
from math import sqrt
part_name = sys.argv[1]
part_file = part_name + ".dat"
ENTRY_TYPE_COMMENT = '0'
ENTRY_TYPE_SUBMODEL = '1'
ENTRY_TYPE_LINE = '2'
@stravant
stravant / GoodSignal.lua
Last active April 16, 2025 07:18
Good Roblox Signal Implementation
--------------------------------------------------------------------------------
-- Batched Yield-Safe Signal Implementation --
-- This is a Signal class which has effectively identical behavior to a --
-- normal RBXScriptSignal, with the only difference being a couple extra --
-- stack frames at the bottom of the stack trace when an error is thrown. --
-- This implementation caches runner coroutines, so the ability to yield in --
-- the signal handlers comes at minimal extra cost over a naive signal --
-- implementation that either always or never spawns a thread. --
-- --
-- API: --
--------------------------------------------------------------------------------
-- Simple Correct Signal Implementation --
-- This is the most straightforwards possible pure Lua implementation of a --
-- Signal class that correctly implements all of the RBXScriptSignal --
-- behavior (Connect, Disconnect, and Wait) --
--------------------------------------------------------------------------------
local Signal = {}
Signal.__index = Signal
local Connection = {}
--------------------------------------------------------------------------------
-- Simple Correct Signal Implementation --
-- This is the most straightforwards possible pure Lua implementation of a --
-- Signal class that correctly implements all of the RBXScriptSignal --
-- behavior (Connect, Disconnect, and Wait) --
--------------------------------------------------------------------------------
local Signal = {}
Signal.__index = Signal
local Connection = {}
--------------------------------------------------------------------------------
-- Argument By-Reference Signal Wrapper --
-- This is a signal class implemented by wrapping a BindableEvent, which --
-- passes the event arguments by reference instead of by value, and which --
-- still works corectly even with SignalBehavior = deferred. --
--------------------------------------------------------------------------------
local Signal = {}
Signal.__index = Signal