Skip to content

Instantly share code, notes, and snippets.

View pardeike's full-sized avatar
💭
Innovating 🛠

Andreas Pardeike pardeike

💭
Innovating 🛠
View GitHub Profile
@pardeike
pardeike / SearchThroughAllMethodBodies.cs
Last active April 2, 2020 09:47
Search through all methods that exist in all assemblies and run a test on their method bodies
using HarmonyLib;
using MonoMod.Utils;
using System;
using System.Linq;
using System.Reflection;
class Program
{
static void Main()
{
static void RunEvery(int tickInterval, int currentTicks, Action[] actions)
{
var len = actions.Length;
for (var i = 0; i < len; i++)
{
var offset = len > 1 ? i + i * ((tickInterval - len) / len) : 0;
if (offset % tickInterval == currentTicks % tickInterval)
actions[i]();
}
}

You open the game's dll from the filesystem

But once you're there and debug is running, you open the Modules window from Debug -> Windows, and locate your mod's assembly. It won't have the original .dll name

The game loads them in like this:

One of those data-NNNNNNNNN files would be your mod's assembly, double clicking them gives you the assembly name from the DLL

For example:

@pardeike
pardeike / CallingBaseMethodFromPatch.cs
Created April 25, 2020 11:35
Calling a base method from a patch is hard
// run this from LINQPad
// don't forget to add the dependencies to Harmony
void Main()
{
var harmony = new Harmony("test");
harmony.PatchAll();
var bar = new Bar();
Prefix(bar);
@pardeike
pardeike / GizmoRenderingBug.cs
Last active May 8, 2020 18:36
Bug rendering Gizmo's from RimWorld into a rendertexture [https://youtu.be/ZKcFkbCPYts]
// this code works "most of the time"
// sometimes, without any idea why, it generates a transparent image
// as if the drawing calls are not working, leaving the image empty
// Video showing this behaviour: https://youtu.be/ZKcFkbCPYts
public static byte[] GetCommandsMatrix(List<Command> commands)
{
var count = commands.Count;
if (count == 0) return null;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!--<script type="text/babel" src="https://raw.githubusercontent.com/avkonst/hookstate/master/dist/index.js"></script>-->
<script type="text/babel">
@pardeike
pardeike / OffLimits.shader
Last active May 14, 2020 23:46
PychoStripes Unity Shader
Shader "Unlit/OffLimits"
{
Properties {
_Color1 ("Color 1", Color) = (0,0,0,1)
_Color2 ("Color 2", Color) = (1,1,1,1)
_Size ("Size", Float) = 0
_Tiling ("Tiling", Range(0.1, 10)) = 1
_Direction ("Direction", Range(0, 1)) = 0
_WarpScale ("Warp Scale", Range(0, 1)) = 0
_WarpTiling ("Warp Tiling", Range(0.01, 20)) = 1
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il, MethodBase original)
{
// create new local variables
var local = il.DeclareLocal(typeof(TheType));
// create new labels for jumping
var label = il.DefineLabel();
// inspect original methods properties
var args = original.GetParameters();
// This source can be executed directly from the (free) LINQPad (use "Language: C# Program")
public static void Main(String[] args)
{
var harmony = new Harmony("test");
harmony.PatchAll();
Test1.Run();
Test2.Run();
}
// use in LINQPad
delegate string Test1Delegate(int n, ref float f);
void Main()
{
var bar = new Bar();
var baseTest1 = (Test1Delegate)GetBaseMethod(typeof(Foo).GetMethod("Test1"), bar);
var f = 789f;