2023-08-26 17:59:50 -04:00
|
|
|
|
using HarmonyLib;
|
2023-09-09 15:51:47 -04:00
|
|
|
|
using MIU;
|
2023-09-10 16:54:51 -04:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-08-27 02:44:35 -04:00
|
|
|
|
if (!Config.enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-09-03 02:06:53 -04:00
|
|
|
|
if (Config.skinNameToHijack == "*")
|
2023-08-27 02:44:35 -04:00
|
|
|
|
return;
|
|
|
|
|
|
2023-09-03 22:29:29 -04:00
|
|
|
|
// 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
|
2023-09-09 20:09:51 -04:00
|
|
|
|
* 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
|
|
|
|
|
{
|
2023-09-10 16:54:51 -04:00
|
|
|
|
static void Prefix(MarbleController __instance, ref ReplayCosmetics cosmetics)
|
2023-09-09 20:09:51 -04:00
|
|
|
|
{
|
|
|
|
|
// Actually, we can let this one run even if the custom skins are disabled
|
|
|
|
|
//if (!Config.enabled)
|
|
|
|
|
// return;
|
|
|
|
|
|
2023-09-10 16:54:51 -04:00
|
|
|
|
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 == "*")
|
2023-09-09 20:09:51 -04:00
|
|
|
|
return;
|
|
|
|
|
|
2023-09-10 16:54:51 -04:00
|
|
|
|
string replayName = null;
|
2023-09-09 20:09:51 -04:00
|
|
|
|
|
2023-09-10 16:54:51 -04:00
|
|
|
|
GamePlayManager.Get().GetCurrentReplays(delegate (List<Replay> replays)
|
|
|
|
|
{
|
|
|
|
|
if (replays.Count > 0)
|
|
|
|
|
replayName = replays[0].Player;
|
|
|
|
|
});
|
2023-09-09 15:51:47 -04:00
|
|
|
|
|
2023-09-10 16:54:51 -04:00
|
|
|
|
Shared.Log("MarbleControllerApplyCosmeticsPatch Replay name: " + replayName);
|
2023-09-09 15:51:47 -04:00
|
|
|
|
|
2023-09-10 16:54:51 -04:00
|
|
|
|
if (Config.otherPlayers.ContainsKey(replayName) || replayName == Player.Current.Name)
|
|
|
|
|
cosmetics.Skin = Config.skinNameToHijack;
|
2023-09-09 15:51:47 -04:00
|
|
|
|
|
2023-09-10 16:54:51 -04:00
|
|
|
|
// HACK - call this early so that SetMarble is aware of it
|
|
|
|
|
// Normally it would be called right AFTER ApplyCosmetics
|
|
|
|
|
__instance.AddMode(MarbleController.ReplayMode);
|
2023-09-09 15:51:47 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-26 17:59:50 -04:00
|
|
|
|
}
|