Skip to content

Instantly share code, notes, and snippets.

@mcu8
Created August 10, 2021 16:09
Show Gist options
  • Save mcu8/10981b57c63112e35a9ee35e951ad27f to your computer and use it in GitHub Desktop.
Save mcu8/10981b57c63112e35a9ee35e951ad27f to your computer and use it in GitHub Desktop.
Example mod for Here Comes Niko!
using UnityModManagerNet;
using HarmonyLib;
using System;
using System.Reflection;
namespace NikoOwO
{
static class Main
{
public static bool IsEnabled;
static bool Load(UnityModManager.ModEntry modEntry)
{
var harmony = new Harmony(modEntry.Info.Id);
harmony.PatchAll(Assembly.GetExecutingAssembly());
modEntry.OnToggle = OnToggle;
return true;
}
static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
{
IsEnabled = value;
return true;
}
[HarmonyPatch(typeof(LocalizationManager), "GetLocalizedValue", new System.Type[] { typeof(string) })]
static class LocalizationManager_GetLocalizedValue_Patch
{
static void Postfix(string key, ref string __result)
{
if (!IsEnabled)
return;
__result = Owoize(__result);
}
}
[HarmonyPatch(typeof(LocalizationManager), "GetLocalizedValueOrEmpty", new System.Type[] { typeof(string) })]
static class LocalizationManager_GetLocalizedValueOrEmpty_Patch
{
static void Postfix(ref string __result)
{
if (!IsEnabled)
return;
__result = Owoize(__result);
}
}
public static string Owoize(string v)
{
var x = v.Replace(";", "; @!@ ").Split(' ');
for (int i = 0; i < x.Length; i++)
{
if (x[i].StartsWith("##") || x[i].EndsWith(";")) continue;
x[i] = OwoizeInt(x[i]);
}
return string.Join(" ", x).Replace("; @!@ ", ";");
}
public static string OwoizeInt(string v)
{
return v.Replace("r", "w")
.Replace("R", "W")
.Replace("l", "w")
.Replace("L", "W")
.Replace("na", "nya")
.Replace("ne", "nye")
.Replace("ni", "nyi")
.Replace("no", "nyo")
.Replace("nu", "nyu")
.Replace("Na", "Nya")
.Replace("Ne", "Nye")
.Replace("Ni", "Nyi")
.Replace("No", "Nyo")
.Replace("Nu", "Nyu")
.Replace("NA", "NYA")
.Replace("NE", "NYE")
.Replace("NI", "NYI")
.Replace("NO", "NYO")
.Replace("NU", "NYU")
.Replace("ove", "uv");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment