Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View 0x1F9F1's full-sized avatar
🧱

Brick 0x1F9F1

🧱
  • Nottingham, United Kingdom
View GitHub Profile
@0x1F9F1
0x1F9F1 / ArchiveReader.cs
Last active November 8, 2017 00:59
Midtown Madness Archive Reader
using System;
using System.Text;
using System.IO;
using System.Linq;
using System.IO.Compression;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
public class MMArchiveHelper
@0x1F9F1
0x1F9F1 / ReadModStatic.cs
Last active January 28, 2018 21:52
ReadModStatic
public static int GfxFVFOffset(int fvfFlags, int a2)
{
int result = 0;
if (a2 != 0x2)
{
result += 12;
if (a2 != 0x10)
{
@0x1F9F1
0x1F9F1 / scoped_seh.h
Last active September 12, 2018 22:45
A raii based SEH to C++ exception translater
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdexcept>
#include <cstdio>
class scoped_seh
{
/*
Copyright 2018 Brick
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
@0x1F9F1
0x1F9F1 / read_bndb_snapshot.py
Created February 14, 2019 16:41
Convert a bndb snapshot to json
import struct
import json
if True:
import lzf # pip install python-lzf
else:
import ctypes
class lzf:
_lzf_dll = ctypes.CDLL('lzf.dll')
import sqlite3
import contextlib
import os
import sys
def clean_binja_snapshots(conn, limit = 1):
with conn as cur:
for section in [ 'snapshot', 'file_data' ]:
cur.execute(f'DELETE FROM {section} WHERE id NOT IN (SELECT id FROM {section} ORDER BY id DESC LIMIT ?)', (limit,))
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <limits>
#include <type_traits>
constexpr std::size_t popcount(std::uint8_t value) noexcept
{
value -= (value >> 1) & 0x55;
value = (value & 0x33) + ((value >> 2) & 0x33);
@0x1F9F1
0x1F9F1 / int_cast.cpp
Last active August 22, 2021 18:25
Safely cast integers
#include <limits>
#include <type_traits>
enum class int_cast_mode
{
lossless,
check_sign,
check_max,
check_trip,
};
@0x1F9F1
0x1F9F1 / sdl_app.cpp
Last active October 3, 2021 13:15
An example of using WM_PAINT and WM_TIMER with SDL2 to allow updates when moving/resizing
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_syswm.h>
#include <Windows.h>
enum class UpdateReason
{
Main,
@0x1F9F1
0x1F9F1 / lcg.cpp
Last active March 27, 2022 12:50
Fun with LCG's
#include <cstdint>
bool PolyMul(uint32_t from, uint32_t to, uint32_t& out_mul)
{
for (; ~from & 1; from >>= 1, to >>= 1) {
if (to & 1)
return false;
}
uint32_t result = 0;