Skip to content

Instantly share code, notes, and snippets.

@pR0Ps
pR0Ps / messenger-seaofstars-fix-checksum
Last active May 12, 2024 21:21
Fix the checksum for the save files of The Messenger and Sea of Stars (Nintendo Switch versions)
#!/bin/bash
# The save files for The Messenger and Sea of Stars on the Nintendo Switch are
# just JSON files with a prefix checksum and (only for The Messenger) some
# padding at the end. The checksum is just the length of the data encoded using
# ULEB128 (https://en.wikipedia.org/wiki/LEB128)
#
# This script takes a save file and adds/updates the checksum. This makes
# editing save files extremely easy. Just open the file in any text editor,
# make the desired changes, save it, then run this script on it to make sure
@pR0Ps
pR0Ps / pybindiff.py
Last active January 8, 2023 16:43
Show binary diff of files while handling inserted/removed data
#!/usr/bin/env python
"""
Shows a binary diff of files. Handles cases where data was inserted/removed
instead of just modified in place to avoid showing that the rest of a file
after a modification was changed.
WARNING: The algorithm used to generate the diff is quadratic in the expected
case and cubic in the worst case. Do not run this on large files unless you
want to wait for a *very* long time. Additionally, because it was only meant to
@pR0Ps
pR0Ps / inline_c.py
Created August 17, 2022 11:57
Use inline C code in Python (using Cython)
#!/usr/bin/env python
import cython
import functools
import inspect
import textwrap
_ARRAY_NAME = "Array_{c_type}"
_MAKE_ARRAY = _ARRAY_NAME + "(&{name}[0], {name}.shape[0])"
@pR0Ps
pR0Ps / 3dstrim.py
Last active November 20, 2022 05:27
Python script to trim and untrim Nintendo 3DS game cart backups
#!/usr/bin/env python
# See https://www.3dbrew.org/wiki/NCSD for details on the file format
import io
import os
import logging
MEDIA_UNIT = 0x200
@pR0Ps
pR0Ps / url_loader_demo.py
Created May 17, 2022 01:01
A demo of importing Python modules directly from URLs
#!/usr/bin/env python
import contextlib
import importlib.abc
import importlib.machinery
import importlib.util
import logging
import sys
import types
from urllib.request import urlopen
@pR0Ps
pR0Ps / switchsplit.sh
Created October 13, 2021 23:44
Split large files into chunks that the Nintendo Switch OS + homebrew can read
#!/bin/bash
# Splits a file into pieces so it can be written to a FAT32 filesystem and read
# by the Nintendo Switch (after setting the archive bit on the folder).
# The original file is not preserved (although it can be easily recovered by
# catting the split files together).
# Will split file like so: file.ext --> file.ext/00, file.ext/01, etc
set -e
@pR0Ps
pR0Ps / plex.conf
Last active July 29, 2021 03:07
Nginx config for running a public, read-only, multi-user, account-less Plex instance
# Goals:
# - Allow access without having to deal with Plex accounts
# - Only allow read-only access (no changing tags, fixing matches, etc)
# - Don't leak information between users (what has been watched, play progress, etc)
# - Prevent users from claiming the server, changing settings, or acessing internal information
# - Allow administration of the server for people with SSH access to it
# Basic setup instructions:
# - Install Nginx on the same server as Plex and load this config file (usually just a matter of
# dropping it into `/etc/nginx/conf.d`)
@pR0Ps
pR0Ps / skyforcestars.py
Created August 17, 2020 03:23
Set the number of stars you have in Sky Force Reloaded
#!/usr/bin/env python
"""
The game Sky Force Reloaded on Android stores how many in-game stars you've
collected in an obfuscated config file. This program was made by
reverse-engineering that obfuscation using a bunch of sample values.
Given the number of stars you want, it will generate a line to add to the
game's config file. Note that the game will treat invalid values as 0 so make a
backup of your config before modifying it.
@pR0Ps
pR0Ps / unifi-update.sh
Last active September 24, 2022 19:10
Update a UniFi Controller installation on Alpine Linux
#!/bin/sh
####################################
# Update a UniFi Controller installation on Alpine Linux
#
# Assumes that the unifi service can be manipulated with "rc-service unifi <start/stop>"
#
# For initial installation see https://wiki.alpinelinux.org/wiki/UniFi_Controller
# Additional steps:
# - apk add --no-cache libc6-compat
@pR0Ps
pR0Ps / make-wg-client.sh
Last active March 28, 2024 10:01
Script to generate wireguard configs for clients to allow them to connect to the local wireguard server
#!/bin/bash
#######
# Setup
#######
### Enable IPv4/6 forwarding:
# # In /etc/sysctl.d/30-ipforward.conf :
# net.ipv4.ip_forward=1
# net.ipv6.conf.default.forwarding=1
# net.ipv6.conf.all.forwarding=1