With RogueUtilities class you can convert .png or .jpg files into Sprites:
public static Sprite ConvertToSprite(string filePath);
public static Sprite ConvertToSprite(byte[] data);
Sprite sprite = RogueUtilities.ConvertToSprite("D:\Images\MyImage.png");
byte[] data = File.ReadAllBytes("D:\Images\MyImage.png");
Sprite sprite2 = RogueUtilities.ConvertToSprite(data);
And convert .mp3, .ogg, .wav, .aiff files into Audioclips:
public static AudioClip ConvertToAudioClip(string filePath);
AudioClip clip = RogueUtilities.ConvertToAudioClip("D:\Sounds\MySound.ogg");
It is recommended to use .ogg, because other formats might not load properly.
This class allows you to further simplify this code:
// Harmony harmony = new Harmony(pluginGuid);
// MethodInfo original = AccessTools.Method(typeof(SomeClass), "DoSomething");
// MethodInfo patch = AccessTools.Method(typeof(MyPatches), "DoSomething_Patch");
// harmony.Patch(original, patch);
//
// original = AccessTools.Method(typeof(SomeOtherClass), "Start");
// patch = AccessTools.Method(typeof(MyPatches), "Start_Patch");
// harmony.Patch(original, null, patch);
this.PatchPrefix(typeof(SomeClass), "DoSomething", typeof(MyPatches), "DoSomething_Patch");
this.PatchPostfix(typeof(SomeOtherClass), "Start", typeof(MyPatches), "Start_Patch");
To this:
RoguePatcher patcher = new RoguePatcher(this, typeof(MyPatches));
patcher.Prefix(typeof(SomeClass), "DoSomething");
patcher.Postfix(typeof(SomeOtherClass), "Start");
// It will search for a patch method named "<TypeName>_<MethodName>" in class MyPatches.
// For example: Method "DoSomething" in "SomeClass" class will be patched
// by a method "SomeClass_DoSomething" in class "MyPatches".
It uses this.PatchPrefix(..) and this.PatchPostfix(..) methods for patching, so it will catch and log all exceptions that can happen during patching. If the patch was successful, methods return true, otherwise - false.
You can also switch to a different patches class:
RoguePatcher patcher = new RoguePatcher(this, typeof(MyPatches1));
patcher.Patch(..);
patcher.SwitchTo(typeof(MyPatches2));
// OR: patcher.TypeWithPatches = typeof(MyPatches2);
patcher.Patch(..);
This class is probably not very useful, but I think it makes writing code for manual patching a little bit faster.