Skip to content

Instantly share code, notes, and snippets.

@lbmaian
lbmaian / BackstoryDef.cs
Last active August 12, 2019 11:42
Rimworld generic backstory def loading
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;
using UnityEngine;
using Verse;
namespace RimWorld
{
// Allows loading of backstories defined via <BackstoryDef> with optional <defName> (and optional <bodyTypeMale>/<bodyTypeFemale>)
@lbmaian
lbmaian / rimworld_resources_asset_paths.txt
Last active October 12, 2023 14:44
Rimworld Unity Resources Asset Paths
Assets/Font/LiberationSans.ttf
Assets/Material/Font Material.mat
Assets/Material/LiberationSans SDF Material.mat
Assets/Material/TextMeshProSprite.mat
Assets/Resources/backstories/shuffled/ImperialCommon_Adult.bytes
Assets/Resources/backstories/shuffled/ImperialCommon_Child.bytes
Assets/Resources/backstories/shuffled/ImperialFighter_Adult.bytes
Assets/Resources/backstories/shuffled/ImperialFighter_Child.bytes
Assets/Resources/backstories/shuffled/ImperialRoyal_Adult.bytes
Assets/Resources/backstories/shuffled/ImperialRoyal_Child.bytes
@lbmaian
lbmaian / TypeExtensions.cs
Created December 12, 2019 09:41
Helper extension methods for getting lambda/iterator compiler-generated methods
public static class TypeExtensions
{
const BindingFlags lambdaMethodBindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
// Note: In .NET Framework 3.5 and below, type parameter T in IEnumerable<T> is not covariant, i.e.
// an IEnumerable<MethodInfo> is not an IEnumerable<MethodBase>. Since this is used in HarmonyTargetMethods-annotated
// methods, which must have IEnumerable<MethodBase>, we must return IEnumerable<MethodBase> here as well.
public static IEnumerable<MethodBase> FindLambdaMethods(this Type targetType, Func<MethodInfo, bool> methodMatcher)
{
// Lambda code is in compiler-generated non-public instance methods on either the target type (if doesn't need closure)
@lbmaian
lbmaian / TestMod.cs
Created December 16, 2019 06:21
Proof of concept of static constructor patching in RimWorld
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using Harmony;
using Harmony.ILCopying;
using Verse;
// Outputs in order:
@lbmaian
lbmaian / TupleBackport.cs
Created December 27, 2019 13:48
Tuple Backport for .NET 3.5 (might work for earlier .NET versions as well)
// Aggregated and sourced from https://github.com/theraot/Theraot
// Copyright (c) Microsoft. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#pragma warning disable CA1036 // Override methods on comparable types
#pragma warning disable CA1051 // Do not declare visible instance fields
#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
#pragma warning disable CA1815 // Override equals and operator equals on value types
@lbmaian
lbmaian / youtube-livechat-emoji-fixes.user.js
Last active February 12, 2023 12:53
YouTube - Livechat Emoji Fixes
// ==UserScript==
// @name YouTube - Livechat Emoji Fixes
// @namespace https://gist.github.com/lbmaian/e2a60a4aa2c534c1575547a60711613a
// @downloadURL https://gist.github.com/lbmaian/e2a60a4aa2c534c1575547a60711613a/raw/youtube-livechat-emoji-fixes.user.js
// @updateURL https://gist.github.com/lbmaian/e2a60a4aa2c534c1575547a60711613a/raw/youtube-livechat-emoji-fixes.user.js
// @version 0.3
// @description Improves YouTube Livechat emoji performance (and other stuff eventually)
// @author lbmaian
// @match https://www.youtube.com/live_chat*
// @icon https://www.youtube.com/favicon.ico
@lbmaian
lbmaian / youtube-hide-livechat.user.js
Last active April 17, 2024 11:41
YouTube - Hide Live Chat By Default
// ==UserScript==
// @name YouTube - Hide Live Chat By Default
// @namespace https://gist.github.com/lbmaian/94824cef728917a53d3c6e6ea885469c
// @downloadURL https://gist.github.com/lbmaian/94824cef728917a53d3c6e6ea885469c/raw/youtube-hide-livechat.user.js
// @updateURL https://gist.github.com/lbmaian/94824cef728917a53d3c6e6ea885469c/raw/youtube-hide-livechat.user.js
// @version 0.14
// @description Hide live chat by default on live streams
// @author lbmaian
// @match https://www.youtube.com/*
// @exclude https://www.youtube.com/embed/*
@lbmaian
lbmaian / old-reddit-fixes.user.js
Last active April 24, 2022 06:31
old.reddit.com fixes
// ==UserScript==
// @name old.reddit.com fixes
// @namespace https://gist.github.com/lbmaian/c53a9642e15495006e4324d50adce46e
// @version 0.2
// @description old.reddit.com fixes: converts subreddit i.redd.it links to comment links, removes backslashes from links
// @author lbmaian
// @match https://old.reddit.com/r/*
// @match https://old.reddit.com/user/*
// @icon https://www.google.com/s2/favicons?domain=reddit.com
// @grant none
@lbmaian
lbmaian / youtube-redirect-shorts.user.js
Last active March 13, 2024 07:37
YouTube - Redirect Shorts
// ==UserScript==
// @name YouTube - Redirect Shorts
// @namespace https://gist.github.com/lbmaian/c53f48e04a3303d059c042f779a82604
// @downloadURL https://gist.github.com/lbmaian/c53f48e04a3303d059c042f779a82604/raw/youtube-redirect-shorts.user.js
// @updateURL https://gist.github.com/lbmaian/c53f48e04a3303d059c042f779a82604/raw/youtube-redirect-shorts.user.js
// @version 0.2.2
// @description Redirects YouTube shorts URL to watch URL
// @author lbmaian
// @match https://*.youtube.com/*
// @grant window.onurlchange
@lbmaian
lbmaian / holotools-fixes.user.js
Last active May 6, 2023 14:58
HoloTools Fixes and Enhancements
// ==UserScript==
// @name HoloTools Fixes and Enhancements
// @namespace https://gist.github.com/lbmaian/fef815da2628dc6e546ba1f7cd8212a5
// @downloadURL https://gist.github.com/lbmaian/fef815da2628dc6e546ba1f7cd8212a5/raw/holotools-fixes.user.js
// @updateURL https://gist.github.com/lbmaian/fef815da2628dc6e546ba1f7cd8212a5/raw/holotools-fixes.user.js
// @version 0.5
// @description Fixes for HoloTools
// @author lbmaian
// @match https://hololive.jetri.co/
// @match https://holodex.net/login