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

44 lines
1.3 KiB
C#

using HarmonyLib;
using MIU;
using System.Collections.Generic;
using UnityEngine;
namespace CustomCosmeticLoader.Patches
{
/*
* Hijack the marble of a ghost marble if it's in our custom player list, and apply the custom texture
*/
[HarmonyPatch(typeof(GhostRaceMarbleController), nameof(GhostRaceMarbleController.ApplyCosmetics))]
internal class GhostRaceMarbleControllerApplyCosmeticsPatch
{
static void Postfix(GhostRaceMarbleController __instance)
{
if (!Config.enabled)
return;
string replayName = null;
GamePlayManager.Get().GetCurrentReplays(delegate (List<Replay> replays)
{
if (replays.Count > 0)
replayName = replays[0].Player;
});
Shared.Log("GhostRaceMarbleControllerApplyCosmeticsPatch Replay name: " + replayName);
if (Config.otherPlayers.ContainsKey(replayName) || replayName == Player.Current.Name)
{
MarbleHolder mHolder = __instance.GetComponentInChildren<MarbleHolder>();
if (Config.skinNameToHijack != "*")
mHolder.SetMarble(Shared.SkinToHijack);
Texture2D skin;
if (replayName == Player.Current.Name)
skin = Config.skins[Config.currentSkin];
else
skin = Config.skins[Config.otherPlayers[replayName]];
Shared.ApplyCustomTexture(mHolder.currentMarble, skin);
}
}
}
}