2023-08-26 17:59:50 -04:00
|
|
|
|
using HarmonyLib;
|
2023-09-10 16:54:51 -04:00
|
|
|
|
using MIU;
|
|
|
|
|
using System.Collections.Generic;
|
2023-09-03 22:29:29 -04:00
|
|
|
|
using System.Reflection;
|
2023-08-26 17:59:50 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace CustomCosmeticLoader.Patches
|
|
|
|
|
{
|
2024-01-02 01:22:31 -05:00
|
|
|
|
/*
|
|
|
|
|
* Private fields/values for MarbleHolder to be used in the patches
|
|
|
|
|
*/
|
2023-09-04 02:30:54 -04:00
|
|
|
|
internal static class MarbleHolderValues
|
|
|
|
|
{
|
2024-01-02 01:22:31 -05:00
|
|
|
|
internal static FieldInfo mbcField = typeof(MarbleHolder).GetField("mbc", BindingFlags.NonPublic | BindingFlags.Instance);
|
2023-09-04 02:30:54 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-08 00:24:00 -04:00
|
|
|
|
/*
|
2024-01-02 01:22:31 -05:00
|
|
|
|
* In multiplayer and Replays, hijack the current marble and set it to be the marble we're hijacking, then apply the skin
|
2023-09-08 00:24:00 -04:00
|
|
|
|
*/
|
2024-01-02 01:22:31 -05:00
|
|
|
|
[HarmonyPatch(typeof(MarbleHolder), nameof(MarbleHolder.CheckSet))]
|
|
|
|
|
internal class MarbleHolderCheckSetPatch
|
2023-08-26 17:59:50 -04:00
|
|
|
|
{
|
2024-01-02 01:22:31 -05:00
|
|
|
|
static void Postfix(MarbleHolder __instance, Cosmetic.Set cs)
|
2023-08-26 17:59:50 -04:00
|
|
|
|
{
|
2023-08-27 02:44:35 -04:00
|
|
|
|
if (!Config.enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-02 01:22:31 -05:00
|
|
|
|
if (!NetworkManager.IsMultiplayer && !MarbleManager.Replaying)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Don't hijack the soccer ball or zombie skins
|
|
|
|
|
if (cs.skin == "SoccerBall_V4" || cs.skin == "Zombie")
|
2023-08-27 02:44:35 -04:00
|
|
|
|
return;
|
2023-09-03 00:21:15 -04:00
|
|
|
|
|
2024-01-02 01:22:31 -05:00
|
|
|
|
MarbleController controller = MarbleHolderValues.mbcField.GetValue(__instance) as MarbleController;
|
|
|
|
|
|
2023-09-10 16:54:51 -04:00
|
|
|
|
if (controller == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-09-04 02:30:54 -04:00
|
|
|
|
Texture2D skin = null;
|
|
|
|
|
|
2023-09-03 22:29:29 -04:00
|
|
|
|
if (NetworkManager.IsMultiplayer)
|
|
|
|
|
{
|
2023-09-10 16:54:51 -04:00
|
|
|
|
if (controller.isMyClientMarble())
|
|
|
|
|
{
|
|
|
|
|
skin = Config.skins[Config.currentSkin];
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-09-04 02:30:54 -04:00
|
|
|
|
{
|
2024-01-02 01:22:31 -05:00
|
|
|
|
if (Config.otherPlayers.ContainsKey(controller.nickname))
|
|
|
|
|
skin = Config.skins[Config.otherPlayers[controller.nickname]];
|
2023-09-04 02:30:54 -04:00
|
|
|
|
}
|
2023-10-06 20:23:48 -04:00
|
|
|
|
}
|
2024-01-02 01:22:31 -05:00
|
|
|
|
else if (MarbleManager.Replaying) // Should always be true
|
2023-09-10 16:54:51 -04:00
|
|
|
|
{
|
2024-01-02 01:22:31 -05:00
|
|
|
|
string replayName = null;
|
2023-09-03 22:29:29 -04:00
|
|
|
|
|
2024-01-02 01:22:31 -05:00
|
|
|
|
GamePlayManager.Get().GetCurrentReplays(delegate (List<Replay> replays)
|
|
|
|
|
{
|
|
|
|
|
if (replays.Count > 0)
|
|
|
|
|
replayName = replays[0].Player;
|
|
|
|
|
});
|
2023-09-10 16:54:51 -04:00
|
|
|
|
|
2024-01-02 01:22:31 -05:00
|
|
|
|
Shared.Log("MarbleHolderCheckSetPatch Replay name: " + replayName);
|
|
|
|
|
if (replayName == Player.Current.Name)
|
|
|
|
|
{
|
|
|
|
|
skin = Config.skins[Config.currentSkin];
|
2023-09-10 16:54:51 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-01-02 01:22:31 -05:00
|
|
|
|
if (Config.otherPlayers.ContainsKey(replayName))
|
|
|
|
|
skin = Config.skins[Config.otherPlayers[replayName]];
|
2023-09-10 16:54:51 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 22:29:29 -04:00
|
|
|
|
|
2024-01-02 01:22:31 -05:00
|
|
|
|
if (skin == null)
|
2023-09-03 22:29:29 -04:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__instance.SetMarble(Shared.SkinToHijack);
|
2024-01-02 01:22:31 -05:00
|
|
|
|
Shared.ApplyCustomTexture(__instance.currentMarble, skin);
|
|
|
|
|
// Reset this to what it should be incase it's used later
|
2023-09-03 22:29:29 -04:00
|
|
|
|
__instance.CosmeticSet.skin = cs.skin;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-26 17:59:50 -04:00
|
|
|
|
}
|