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

38 lines
923 B
C#
Raw Permalink Normal View History

using HarmonyLib;
using UnityEngine;
namespace CustomCosmeticLoader.Patches
{
/*
* Since the Setup method already uses the hijacked skin pulled from the marble, we just need to apply the custom
* texture after the fact
*/
[HarmonyPatch(typeof(VoteAvatar), nameof(VoteAvatar.Setup))]
internal class VoteAvatarSetupPatch
{
static void Postfix(VoteAvatar __instance, MarbleController marble)
{
if (!Config.enabled)
return;
// Don't override zombies
if (__instance.widget.cosmeticDisplay.cosmetic.Id == "Zombie")
return;
Texture2D skin = null;
if (marble.isMyClientMarble())
{
skin = Config.skins[Config.currentSkin];
}
else
{
if (Config.otherPlayers.ContainsKey(marble.nickname))
skin = Config.skins[Config.otherPlayers[marble.nickname]];
}
if (skin != null)
Shared.ApplyCustomTexture(__instance.widget.cosmeticDisplay.gameObject, skin);
}
}
}