forked from raf13lol/OldCharacterReplacer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOldCharacterReplacer.cs
More file actions
57 lines (49 loc) · 2.36 KB
/
Copy pathOldCharacterReplacer.cs
File metadata and controls
57 lines (49 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
#if !BPE5
using BepInEx.Unity.Mono;
#endif
using HarmonyLib;
using System;
using System.IO;
using UnityEngine;
using RDLevelEditor;
using System.Reflection;
namespace OldCharacterReplacer;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInProcess("Rhythm Doctor.exe")]
// i don't know what
#pragma warning disable BepInEx002 // Classes with BepInPlugin attribute must inherit from BaseUnityPlugin
public partial class OldCharacterReplacer : BaseUnityPlugin
#pragma warning restore BepInEx002 // Classes with BepInPlugin attribute must inherit from BaseUnityPlugin
{
public static string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BepInEx", "plugins", "ocrData");
// illegal characters
public static string dictionaryPrefix = @"|?#<OCR>#?|\/";
public static MethodInfo loadTexture2D;
internal static ManualLogSource logger;
private ConfigEntry<bool> charReplacement;
public static ConfigEntry<int> overrideVersion;
private void Awake()
{
logger = Logger;
loadTexture2D = typeof(RDEditorUtils).GetMethod("LoadTextureFileToCache", BindingFlags.Static | BindingFlags.NonPublic);
charReplacement = Config.Bind("General", "ReplaceCharacters", true, "If characters should be replaced with older versions according to the level version.");
overrideVersion = Config.Bind("General", "OverrideVersion", 0, "If the value is not zero, every level (including story levels and the editor) will be treated as being from that version.");
logger.LogMessage($"Old Character Replacer plugin loaded! Will {(charReplacement.Value ? "" : "not ")}replace characters with older versions when appropriate!");
Harmony instance = new("patcher");
if (charReplacement.Value)
{
instance.PatchAll(typeof(CharPatch));
instance.PatchAll(typeof(DialoguePatch));
instance.PatchAll(typeof(HeartPatch));
}
}
public static Texture2D LoadTextureFileToCache(string p, string key, bool isAlpha8)
{
if (scrVfxControl.textureCache.TryGetValue(key, out CachedTexture tex))
return tex.texture;
return (Texture2D)loadTexture2D.Invoke(null, [scrVfxControl.textureCache, Path.Combine(path, p), dictionaryPrefix + key, isAlpha8]);
}
}