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

82 lines
2.5 KiB
C#
Raw Normal View History

2023-08-26 17:59:50 -04:00
using HarmonyLib;
2023-09-09 15:51:47 -04:00
using MIU;
using System.Collections.Generic;
2023-08-26 17:59:50 -04:00
namespace CustomCosmeticLoader.Patches
{
2023-09-08 00:24:00 -04:00
/*
* 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.
*/
2023-09-02 23:19:35 -04:00
[HarmonyPatch(typeof(MarbleController), nameof(MarbleController.ApplyMyCosmetics))]
2023-08-26 17:59:50 -04:00
internal class MarbleControllerApplyMyCosmeticsPatch
{
[HarmonyPostfix]
static void Postfix(MarbleController __instance)
{
if (!Config.enabled)
return;
2023-09-03 02:06:53 -04:00
if (Config.skinNameToHijack == "*")
return;
// Shouldn't happen I don't think but we do this elsewhere in mp
if (NetworkManager.IsMultiplayer)
2023-09-03 02:06:53 -04:00
return;
2023-08-26 17:59:50 -04:00
MarbleHolder mHolder = __instance.MHolder;
string actualSkinId = mHolder.CosmeticSet.skin;
2023-09-03 02:06:53 -04:00
mHolder.SetMarble(Shared.SkinToHijack);
2023-08-26 17:59:50 -04:00
// Setting the skin id here allows others in multiplayer/replays to see your normal skin
mHolder.CosmeticSet.skin = actualSkinId;
}
}
2023-09-09 15:51:47 -04:00
/*
* 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.
2023-09-09 15:51:47 -04:00
*/
[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;
2023-10-06 20:54:57 -04:00
if (Config.inAllReplays)
{
cosmetics.Skin = Config.skinNameToHijack;
return;
}
string replayName = null;
GamePlayManager.Get().GetCurrentReplays(delegate (List<Replay> replays)
{
if (replays.Count > 0)
replayName = replays[0].Player;
});
2023-09-09 15:51:47 -04:00
Shared.Log("MarbleControllerApplyCosmeticsPatch Replay name: " + replayName);
2023-09-09 15:51:47 -04:00
if (Config.otherPlayers.ContainsKey(replayName) || replayName == Player.Current.Name)
cosmetics.Skin = Config.skinNameToHijack;
2023-09-09 15:51:47 -04:00
}
}
2023-08-26 17:59:50 -04:00
}