Apply skin to the vote avatar in multiplayer

This commit is contained in:
Terry Hearst 2023-09-09 03:38:28 -04:00
parent a145e22fce
commit 4371b20c87

View file

@ -0,0 +1,38 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
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);
}
}
}