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

60 lines
1.6 KiB
C#
Raw Normal View History

2023-08-26 17:59:50 -04:00
using HarmonyLib;
using System;
using System.Reflection;
2023-08-26 17:59:50 -04:00
using UnityEngine;
namespace CustomCosmeticLoader.Patches
{
2023-09-02 23:19:35 -04:00
[HarmonyPatch(typeof(MarbleHolder), nameof(MarbleHolder.SetMarble))]
2023-08-26 17:59:50 -04:00
internal class MarbleHolderSetMarblePatch
{
static void Postfix(MarbleHolder __instance, Cosmetic marbleObject)
{
if (!Config.enabled)
return;
2023-09-03 02:06:53 -04:00
if (marbleObject.Id != Config.skinNameToHijack && Config.skinNameToHijack != "*")
return;
if (!Config.inCosmeticMenu && __instance == CosmeticPanel.cosmHolder)
return;
// If this is a networked game, ONLY apply to my marble and not anyone else happening to use our SkinToHijack
if (NetworkManager.IsMultiplayer)
{
MarbleController controller = __instance.GetComponentInParent<MarbleController>();
if (!controller.isMyClientMarble())
return;
}
2023-09-03 02:06:53 -04:00
Shared.ApplyCustomTexture(__instance.currentMarble);
2023-08-26 17:59:50 -04:00
}
}
[HarmonyPatch(typeof(MarbleHolder), nameof(MarbleHolder.CheckSet))]
internal class MarbleHolderCheckSetPatch
{
static void Postfix(MarbleHolder __instance, Cosmetic.Set cs)
{
if (!Config.enabled)
return;
if (!NetworkManager.IsMultiplayer)
return;
FieldInfo mbcField = typeof(MarbleHolder).GetField("mbc", BindingFlags.NonPublic | BindingFlags.Instance);
MarbleController controller = mbcField.GetValue(__instance) as MarbleController;
if (controller == null)
return;
// Don't hijack the soccer ball or zombie skins
if (cs.skin == "SoccerBall_V4" || cs.skin == "Zombie")
return;
__instance.SetMarble(Shared.SkinToHijack);
__instance.CosmeticSet.skin = cs.skin;
}
}
2023-08-26 17:59:50 -04:00
}