From 4371b20c87f70ee285b5182d86a3324d75e6e324 Mon Sep 17 00:00:00 2001 From: Terry Hearst Date: Sat, 9 Sep 2023 03:38:28 -0400 Subject: [PATCH] Apply skin to the vote avatar in multiplayer --- Patches/VoteAvatarPatches.cs | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Patches/VoteAvatarPatches.cs diff --git a/Patches/VoteAvatarPatches.cs b/Patches/VoteAvatarPatches.cs new file mode 100644 index 0000000..27f5230 --- /dev/null +++ b/Patches/VoteAvatarPatches.cs @@ -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); + } + } +}