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 / chess.js
Created December 23, 2016 12:23
Chess I 1024 bytes, no html needed
for(B=i=y=u=b=i=5-5,x=10,I=[],l=[];l[B]="ECDFBDCEAAAAAAAAIIIIIIIIMKLNJLKM@G@TSb~?A6J57IKJT576,+-48HLSUmgukgg OJNMLK IDHGFE".charCodeAt(B)-64,B++<120;I[B-1]=B%x?B/x%x<2|B%x<2?7:B/x&4?0:l[i++]:7);function X(c,h,e,s){c^=8;for(var o,S,C,A,R,T,G,d=e&&X(c,0)>1e4,n,N=-1e8,O=20;++O<99;)if((o=I[T=O])&&(G=o^c)<7){A=G--&2?8:4;C=o-9?l[61+G]:49;do if(!(R=I[T+=l[C]])&&!!G|A<3||(R+1^c)>9&&G|A>2){if(!(R-2&7))return 78-h<<x;n=G|(c?T>29:T<91)?o:6^c;S=(R&&l[R&7|32]*2-h-G)+(G?0:n-o?110:(A<2)+1);if(e>h||1<e&e==h&&S>2|d){I[T]=n;I[O]=0;S-=X(c,h+1,e,S-N);if(!(h||e-1|B-O|T-b|S<-1e4))return W(),c&&setTimeout("X(8,0,2),X(8,0,1)",50);I[O]=o;I[T]=R}if(S>N||!h&S==N&&Math.random()<.5)if(N=S,e>1)if(h?s-S<0:(B=O,b=T,0))return N}while(!R&G>2||(T=O,(G||A>2|(c?O>78:O<41)&!R)&&++C*--A))}return N}function W(){i="<table>";for(u=18;u<98;document.body.innerHTML=i+=++u%x-9?"<th width=60 height=60 onclick='I[b="+u+"]>8?W():X(0,0,1)'style='font-size:50px'bgcolor=#"+(u-B?u*.9&1||9:"d")+"0f0e0>&#"+(I[u]?9808+l[67+I[u]]:160)+";":u++&&"<tr>")B=b}W()
The following is a log created by Harmony when running two mods in RimWorld together:
CameraPlus and SameSpot. Both are here on GitHub under my name and the Harmony commit 81a27ed
is used with both mods: https://github.com/pardeike/Harmony/commit/81a27edb2d917c8be0fe25f2eae52b17ea9b529f
PC used: Windows 10, version 1607 14393.693
Intel i7-3770 16GB ram, 64bit x64 system
Debugging was done on offline RimWorld with replaced debug mono.ddl
The log shows SameSpot loading first (both have the same Harmony.dll and thus ony SameSpot gets
@pardeike
pardeike / HarmonyMainTemplate.cs
Created April 17, 2017 13:19
A basic starter for a Rimworld Mod using Harmony
using Harmony;
using System;
using System.Linq;
using System.Reflection;
using Verse;
namespace Namespace
{
[StaticConstructorOnStartup]
static class YourMod
@pardeike
pardeike / ReadModIDs.cs
Created May 29, 2017 12:49
Read-Write mod ids
public static List<string> ReadModIDs(string filepath) {
Scribe.loader.InitLoadingMetaHeaderOnly(filepath);
ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
Scribe.loader.FinalizeLoading();
return ScribeMetaHeaderUtility.loadedModIdsList;
}
public static void Test() {
List<string> modIDs = ReadModIDs(file);
ModsConfig.Reset();
@pardeike
pardeike / SimpleHarmonyTranspilerTutorial.md
Last active May 22, 2023 04:43
Simple Harmony Transpiler Tutorial

About
A hopefully easy tutorial on how to make a Transpiler with Harmony
Based on patching a method in the game RimWorld

Introduction

Writing transpilers is like writing a book about how to rewrite a cookbook to make it work for the age of microwave even if that cookbook was written before microwave ovens were invented. It requires good knowledge about the language the cookbook is written in and the topics and information models the cookbook author uses.

As such, writing a transpiler is way more complex and low level than writing a simple method that prefixes, postfixes or replaces an existing method. It is required to have good understanding in general C# programming and how to manipulate abstract data structures with respect to references and relative positioning. It also requires to know the language, in this case CIL, so you can manipulate the instructions without it to get into an illegal state.

@pardeike
pardeike / Dynamic-AssemblyInfo-Part.csproj
Last active July 22, 2017 16:18
AssemblyInfo.cs template with automatic version number calculation
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- add this to the end of the Project -->
<Target Name="TransformOnBuild" BeforeTargets="BeforeBuild">
<PropertyGroup>
<!-- CHANGE TO YOUR CORRECT PATH, THIS IS FOR VISUAL STUDIO 2017 COMMUNITY EDITION -->
<_TransformExe>$(MSBuildExtensionsPath)\..\Common7\IDE\TextTransform.exe</_TransformExe>
<_TextTransform>$(ProjectDir)Properties\AssemblyInfo.tt</_TextTransform>
<_TextTransformResult>$(ProjectDir)Properties\AssemblyInfo.cs</_TextTransformResult>
@pardeike
pardeike / Install.bat
Last active October 22, 2018 03:21
Build script for Rimworld Mods
REM ################ Mod build and install script (c) Andreas Pardeike 2018 ################
REM
REM Call this script from Visual Studio's Build Events post-build event command line box:
REM "$(ProjectDir)Install.bat" $(ConfigurationName) "$(SolutionDir)..\" "$(TargetFileName)"
REM
REM The project structure should look like this:
REM
REM ProjectFolder
REM +- About
REM +- Assemblies
@pardeike
pardeike / CodeMatcher.cs
Last active August 12, 2018 11:36
CodeMatcher draft
using Harmony.ILCopying;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
namespace Harmony
{
public class CodeMatch
{
@pardeike
pardeike / MultiVersionModFix.cs
Last active October 6, 2018 20:43
Add this class to your mod to make it 0.9 and 1.0 compatible and put 1.0 into the About.xml
using Harmony;
using RimWorld;
using Steamworks;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using Verse;
using Verse.Steam;
@pardeike
pardeike / MultiVersionModFix.cs
Last active October 14, 2018 18:09
Handling multiple version of the RimWorld API
using Harmony;
using RimWorld;
using System;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;
using Verse;
namespace YourNameSpace