November 2, 2013

Mono.Cecil: Change Base Class, Add Field

I wanted to swap out a base class in Terraria with another base class that exists in a different DLL, and wasn't quite sure how to do it, so I created a simple test project for experimenting with Mono.Cecil.

You can download the code for my experiments here.

The sample code has three projects: RewriteMe, InjectMe, and MonoCecilExperiments.  RewriteMe has a class called ReplaceMyBaseClass and I want to swap out its base class with a new base class in InjectMe.  The code should be documented well enough that people should be able to follow along.

Essentially, I want to work at the IL level as little as possible.  If I can inject a call to some C# code, all the better.

No comments: