miuu-custom-cosmetic-loader/Patches/MarbleControllerPatches.cs

47 lines
1 KiB
C#

using HarmonyLib;
using System;
using UnityEngine;
namespace CustomCosmeticLoader.Patches
{
[HarmonyPatch(typeof(MarbleController))]
[HarmonyPatch("ApplyMyCosmetics")]
internal class MarbleControllerApplyMyCosmeticsPatch
{
private static Cosmetic hijackSkin = null;
[HarmonyPostfix]
static void Postfix(MarbleController __instance)
{
if (!Config.enabled)
return;
if (Config.skinToHijack == "*")
return;
if (hijackSkin == null)
{
foreach (Cosmetic skin in CosmeticManager.Skins)
{
if (skin.Id == Config.skinToHijack)
{
hijackSkin = skin;
break;
}
}
if (hijackSkin == null)
{
Debug.LogWarning("Couldn't hijack skin " + Config.skinToHijack);
return;
}
}
MarbleHolder mHolder = __instance.MHolder;
string actualSkinId = mHolder.CosmeticSet.skin;
mHolder.SetMarble(hijackSkin);
// Setting the skin id here allows others in multiplayer/replays to see your normal skin
mHolder.CosmeticSet.skin = actualSkinId;
}
}
}