Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Innovating 🛠

Andreas Pardeike pardeike

💭
Innovating 🛠
View GitHub Profile
@pardeike
pardeike / argument-passing-matrix.linq
Last active Dec 22, 2020
Argument passing matrix
View argument-passing-matrix.linq
void Main()
{
var obj = new SomeObject();
var val = new SomeValue { n = 999 };
Original_Object(obj);
Original_Value(val);
Original_Object_Ref(ref obj);
Original_Value_Ref(ref val);
Console.WriteLine(val.n);
}
@pardeike
pardeike / Main.cs
Last active Nov 18, 2020
Complex reverse patching
View Main.cs
/* the following will print
A: val1=123, val2=456
B: val1=123
With C, we also have 456
C: val1=123
B: done
A: done
Press any key to exit
*/
@pardeike
pardeike / EnumeratorMethodShowcase.txt
Last active Sep 30, 2020
How C# enumerator methods look like at IL code level
View EnumeratorMethodShowcase.txt
// The following C# code from LINQPad (free windows app) uses a method (Test) that
// returns an enumeration. Have a look how the IL code that the compiler generates
// looks like:
static IEnumerable<int> Test()
{
yield return 100;
var n = Rand.Range(200, 500);
yield return n;
yield return 600;
@pardeike
pardeike / ListAllOpenFiles.swift
Created Sep 29, 2020
List all open files in iOS
View ListAllOpenFiles.swift
// see https://developer.apple.com/forums/thread/655225
func openFilePaths() -> [String] {
(0..<getdtablesize()).map { fd in
// Return "" for invalid file descriptors.
var flags: CInt = 0
guard fcntl(fd, F_GETFL, &flags) >= 0 else {
return ""
}
// Return "?" for file descriptors not associated with a path, for
// example, a socket.
View ExceptionHandler.cs
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Verse;
using Verse.Sound;
View CustomStatePerPawn.cs
// helper class for scribing ref-deep dicts
public class Scribe_Dictionary<T, S>
{
List<T> tmpKeys;
List<S> tmpVals;
public void Scribe(ref Dictionary<T, S> dict, string name)
{
if (Verse.Scribe.mode == LoadSaveMode.Saving)
{
View CallingBaseMethodWorkaround.cs
// 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;
View PatchBasics.cs
// 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();
}
View TranspilerBasics.cs
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();
@pardeike
pardeike / OffLimits.shader
Last active May 14, 2020
PychoStripes Unity Shader
View OffLimits.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
You can’t perform that action at this time.