using HarmonyLib; using MIU; using System.Collections.Generic; namespace CustomCosmeticLoader.Patches { /* * Hijack the cosmetic of the marble in single player. This doesn't apply the custom texture, just swaps out the * marble with the designated marble to hijack. */ [HarmonyPatch(typeof(MarbleController), nameof(MarbleController.ApplyMyCosmetics))] internal class MarbleControllerApplyMyCosmeticsPatch { [HarmonyPostfix] static void Postfix(MarbleController __instance) { if (!Config.enabled) return; if (Config.skinNameToHijack == "*") return; // Shouldn't happen I don't think but we do this elsewhere in mp if (NetworkManager.IsMultiplayer) return; MarbleHolder mHolder = __instance.MHolder; string actualSkinId = mHolder.CosmeticSet.skin; mHolder.SetMarble(Shared.SkinToHijack); // Setting the skin id here allows others in multiplayer/replays to see your normal skin mHolder.CosmeticSet.skin = actualSkinId; } } /* * Hijack the cosmetic of the marble when watching Replays. This doesn't apply the custom texture, just swaps out * the marble with the designated marble to hijack. If overrideReplayCosmetics is enabled, we swap out all cosmetics * to match our current configuration to view the replay that way. */ [HarmonyPatch(typeof(MarbleController), nameof(MarbleController.ApplyCosmetics))] internal class MarbleControllerApplyCosmeticsPatch { static void Prefix(MarbleController __instance, ref ReplayCosmetics cosmetics) { // Actually, we can let this one run even if the custom skins are disabled //if (!Config.enabled) // return; if (Config.overrideReplayCosmetics) { cosmetics.Skin = CosmeticManager.MySkin.Id; cosmetics.Trail = CosmeticManager.MyTrail.Id; cosmetics.Respawn = CosmeticManager.MyRespawn.Id; cosmetics.Hat = CosmeticManager.MyHat.Id; cosmetics.Blast = CosmeticManager.MyBlast.Id; } if (!Config.enabled || Config.skinNameToHijack == "*") return; if (Config.inAllReplays) { cosmetics.Skin = Config.skinNameToHijack; return; } string replayName = null; GamePlayManager.Get().GetCurrentReplays(delegate (List replays) { if (replays.Count > 0) replayName = replays[0].Player; }); Shared.Log("MarbleControllerApplyCosmeticsPatch Replay name: " + replayName); if (Config.otherPlayers.ContainsKey(replayName) || replayName == Player.Current.Name) cosmetics.Skin = Config.skinNameToHijack; } } }