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 / Dilute.cs
Created April 19, 2024 14:58
Expanding an image with a brush
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.PixelFormats;
using Image = SixLabors.ImageSharp.Image;
using SixLabors.ImageSharp.Formats.Png;
class Program
{
static readonly PngEncoder encoder = new()
{
@pardeike
pardeike / TwoTranspilersDoingTheSame.cs
Created April 7, 2024 22:29
How infixes will be better than transpilers
public static readonly StringBuilder buffer = new StringBuilder();
void Main()
{
// first mod adds transpiler
Console.WriteLine("// APPLYING PATCH 1");
var h1 = new Harmony("test1");
h1.CreateClassProcessor(typeof(Patch1)).Patch();
// second mod adds transpiler
@pardeike
pardeike / LINQPad_Harmony2.3.3.cs
Created March 29, 2024 14:15
Changes in Harmony 2.3.3
void Main()
{
Test.Run();
var harmony = new Harmony("test");
harmony.PatchCategory("category1");
Test.Run();
harmony.PatchCategory("category2");
Test.Run();
@pardeike
pardeike / finalizers.cs
Created March 26, 2024 22:41
Multiple Finalizers seems broken
void Main()
{
var harmony = new Harmony("test");
Harmony.DEBUG = true;
harmony.PatchAll();
Class.Test();
}
[HarmonyPriority(Priority.High)]
[HarmonyPatch(typeof(Class), nameof(Class.Test))]
@pardeike
pardeike / innerfix.cs
Last active February 4, 2024 23:45
Harmony: A draft of how to patch inner methods with so called infixes
static void Main(string[] args)
{
var test = new Test();
Console.WriteLine($"--> OriginalMethod={test.OriginalMethod(0, "foobartest")}");
Console.WriteLine("");
Console.WriteLine($"--> OriginalMethod={test.OriginalMethod(123, "foobartest")}");
Console.WriteLine("");
// patching would happen here
@pardeike
pardeike / FilterBlockTest.cs
Created January 14, 2024 23:33
Creating a filter clause in Cecil
/*
The following code creates this class:
using System;
public static void Method1()
{
try
{
Console.WriteLine("code");
}
@pardeike
pardeike / RimWorld_1.0_to_1.1.md
Last active January 1, 2024 09:49
How to update your Mod from RimWorld from 1.0 to 1.1 and Harmony 1.2.0.1 to 2.0

Updating RimWorld from 1.0 to 1.1

Introduction

My name is Andreas Pardeike, aka Brrainz, or the creator of Harmony. This guide is my personal attempt to help everyone through the journey of upgrading their mods. I am not affiliated with LUDEON studios or with developing RimWorld. It's just a personal thank you from me to the community.

Scope

This guide will help modders to update their C# mod to RimWorld 1.1. I will tell you how you upgrade to Harmony 2 and why. It will also serve as a guide to common changes that I encountered while I upgraded my own Camera+ mod. During the guide, I will use Visual Studio 2019. It's community edition is free. If you use a different IDE, please adapt your changes.

@pardeike
pardeike / DynamicWorkTypes.cs
Last active October 2, 2023 18:37
Some helper for RimWorld mods to add and remove work types at runtime
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace Brrainz
{
[StaticConstructorOnStartup]
void Main()
{
var harmony = new Harmony("test");
harmony.PatchAll();
var group = new StatusItemGroup();
var items = new List<StatusItemGroup.Entry>() { StatusItemGroup.Entry.Make("A"), StatusItemGroup.Entry.Make("B") };
Traverse.Create(group).Field("items").SetValue(items);
var enumerator = group.GetEnumerator();
@pardeike
pardeike / InstallMod.bat
Created August 16, 2023 19:26
Mod build and install script
REM ################ Mod build and install script (c) Andreas Pardeike 2020 ################
REM
REM Call this script from Visual Studio's Build Events post-build event command line box:
REM "$(ProjectDir)Install.bat" $(ConfigurationName) "$(ProjectDir)" "$(ProjectName)" "About Assemblies Languages Textures v1.1" "LoadFolders.xml"
REM
REM The project structure should look like this:
REM
REM Modname
REM +- .git
REM +- .vs