Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Latest commit

 

History

History
73 lines (59 loc) · 2.88 KB

Extras.md

File metadata and controls

73 lines (59 loc) · 2.88 KB
  1. Main page
  2. RogueLibs
  3. Mutators
  4. CustomNames
  5. Extras
  6. RogueLibs Changelog

RogueUtilities

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.

RoguePatcher

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.