Rein-ILHookHelperAPI icon

ILHookHelperAPI

Implements a functional-styled DSL for working with ILHooks inside C# syntax.

Last updated 3 years ago
Total downloads 887
Total rating 3 
Categories Libraries
Dependency string Rein-ILHookHelperAPI-1.0.1
Dependants 1 other package depends on this package

README

Figured I might as well release some of my tooling so others can benefit from it.

Summary

This is a library that adds a functional-style DSL for writing IL hooks.

Wtf is a DSL?

DSL = Domain Specific (programming) Language In this case, its a fancy term for a set of functions that enable a specific style of programming within your C# code.

Wtf does functional-style mean?

Don't worry about it if you don't know.

All you really need to know is that this style makes your IL hooks much, much, much easier to read and write.

Example code

Simple value swap

static void MyILHook(ILContext il) => new ILCursor(il)
    .Goto(x => x.MatchLdcR4(2.65f))
    .Delete()
    .Op_LdConst(3.5f);

Swap add for custom function

static void MyILHook(ILContext il) => new ILCursor(il)
    .Goto(x => x.MatchAdd())
    .Delete()
    .OP_Call<Func<int,int,int>>((lhs, rhs) => lhs * rhs + 14);

Store value from one place, reuse it in another

static void MyILHook(ILContext il) => new ILCursor(il)
    .Goto(MoveType.After, x => x.MatchLdfld<Cheese>(nameof(Cheese.goodLevel)))
    .OP_Dup()
    .AddLocal<int>(out var index)
    .OP_StLocal(index)
    .Goto(MoveType.After, x => x.MatchLdfld<NotCheese>(nameof(NotCheese.badLevel)))
    .OP_LdLocal(index)
    .OP_Sub();

Spam console with useless text to confuse users

private void MyILHook(ILContext il) => new ILCursor(il)
    .Log(base.Logger.LogError)
    .LogContext(base.Logger.LogFatal);

Why?

Initially I told myself I was releasing this to make life easier for some other people but then I spent 2 hours in paint making this horrible icon. Now I actually have no idea why I released this and am instead left with a profound feeling of self-doubt, confusion, and emptiness.

Changelog

1.0.1

-Fixed nullability of a few cursor functions