Show custom skins when watching replays
This commit is contained in:
parent
8d5de1a6c1
commit
7c35b2e5da
3 changed files with 84 additions and 26 deletions
|
@ -1,6 +1,7 @@
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MIU;
|
using MIU;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace CustomCosmeticLoader.Patches
|
namespace CustomCosmeticLoader.Patches
|
||||||
|
@ -41,37 +42,40 @@ namespace CustomCosmeticLoader.Patches
|
||||||
[HarmonyPatch(typeof(MarbleController), nameof(MarbleController.ApplyCosmetics))]
|
[HarmonyPatch(typeof(MarbleController), nameof(MarbleController.ApplyCosmetics))]
|
||||||
internal class MarbleControllerApplyCosmeticsPatch
|
internal class MarbleControllerApplyCosmeticsPatch
|
||||||
{
|
{
|
||||||
static void Prefix(ref ReplayCosmetics cosmetics)
|
static void Prefix(MarbleController __instance, ref ReplayCosmetics cosmetics)
|
||||||
{
|
{
|
||||||
// Actually, we can let this one run even if the custom skins are disabled
|
// Actually, we can let this one run even if the custom skins are disabled
|
||||||
//if (!Config.enabled)
|
//if (!Config.enabled)
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
if (!Config.overrideReplayCosmetics)
|
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;
|
return;
|
||||||
|
|
||||||
cosmetics.Skin = CosmeticManager.MySkin.Id;
|
string replayName = null;
|
||||||
cosmetics.Trail = CosmeticManager.MyTrail.Id;
|
|
||||||
cosmetics.Respawn = CosmeticManager.MyRespawn.Id;
|
|
||||||
cosmetics.Hat = CosmeticManager.MyHat.Id;
|
|
||||||
cosmetics.Blast = CosmeticManager.MyBlast.Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Postfix(MarbleController __instance, ReplayCosmetics cosmetics)
|
GamePlayManager.Get().GetCurrentReplays(delegate (List<Replay> replays)
|
||||||
{
|
{
|
||||||
if (!Config.enabled)
|
if (replays.Count > 0)
|
||||||
return;
|
replayName = replays[0].Player;
|
||||||
|
});
|
||||||
|
|
||||||
if (Config.skinNameToHijack == "*")
|
Shared.Log("MarbleControllerApplyCosmeticsPatch Replay name: " + replayName);
|
||||||
return;
|
|
||||||
|
|
||||||
if (!Config.inAllReplays)
|
if (Config.otherPlayers.ContainsKey(replayName) || replayName == Player.Current.Name)
|
||||||
return;
|
cosmetics.Skin = Config.skinNameToHijack;
|
||||||
|
|
||||||
MarbleHolder mHolder = __instance.GetComponentInChildren<MarbleHolder>();
|
// HACK - call this early so that SetMarble is aware of it
|
||||||
string actualSkinId = mHolder.CosmeticSet.skin;
|
// Normally it would be called right AFTER ApplyCosmetics
|
||||||
mHolder.SetMarble(Shared.SkinToHijack);
|
__instance.AddMode(MarbleController.ReplayMode);
|
||||||
mHolder.CosmeticSet.skin = actualSkinId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using MIU;
|
||||||
using Parse.Common.Internal;
|
using Parse.Common.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
@ -36,22 +38,60 @@ namespace CustomCosmeticLoader.Patches
|
||||||
if (!Config.inCosmeticMenu && __instance == CosmeticPanel.cosmHolder)
|
if (!Config.inCosmeticMenu && __instance == CosmeticPanel.cosmHolder)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
MarbleController controller = MarbleHolderValues.MbcField.GetValue(__instance) as MarbleController;
|
||||||
|
if (controller == null)
|
||||||
|
return;
|
||||||
|
|
||||||
Texture2D skin = null;
|
Texture2D skin = null;
|
||||||
|
|
||||||
if (NetworkManager.IsMultiplayer)
|
if (NetworkManager.IsMultiplayer)
|
||||||
{
|
{
|
||||||
MarbleController controller = MarbleHolderValues.MbcField.GetValue(__instance) as MarbleController;
|
if (controller.isMyClientMarble())
|
||||||
if (controller == null)
|
{
|
||||||
return;
|
skin = Config.skins[Config.currentSkin];
|
||||||
if (!controller.isMyClientMarble())
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (!Config.otherPlayers.ContainsKey(controller.nickname))
|
if (!Config.otherPlayers.ContainsKey(controller.nickname))
|
||||||
return;
|
return;
|
||||||
skin = Config.skins[Config.otherPlayers[controller.nickname]];
|
skin = Config.skins[Config.otherPlayers[controller.nickname]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (controller.InGhostMode ||
|
||||||
|
controller.InMode(MarbleController.ReplayMode) ||
|
||||||
|
controller.name.StartsWith("Marble Ghost"))
|
||||||
|
{
|
||||||
|
string replayName = null;
|
||||||
|
|
||||||
Shared.ApplyCustomTexture(__instance.currentMarble, skin);
|
GamePlayManager.Get().GetCurrentReplays(delegate (List<Replay> replays)
|
||||||
|
{
|
||||||
|
if (replays.Count > 0)
|
||||||
|
replayName = replays[0].Player;
|
||||||
|
});
|
||||||
|
|
||||||
|
Shared.Log("MarbleHolderSetMarblePatch Replay name: " + replayName);
|
||||||
|
if (replayName == Player.Current.Name)
|
||||||
|
{
|
||||||
|
skin = Config.skins[Config.currentSkin];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Config.otherPlayers.ContainsKey(replayName))
|
||||||
|
skin = Config.skins[Config.otherPlayers[replayName]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
skin = Config.skins[Config.currentSkin];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skin != null)
|
||||||
|
{
|
||||||
|
Shared.ApplyCustomTexture(__instance.currentMarble, skin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
Shared.cs
16
Shared.cs
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.Remoting.Messaging;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace CustomCosmeticLoader
|
namespace CustomCosmeticLoader
|
||||||
|
@ -42,6 +43,12 @@ namespace CustomCosmeticLoader
|
||||||
|
|
||||||
public static void ApplyCustomTexture(GameObject marbleObject, Texture2D skin = null)
|
public static void ApplyCustomTexture(GameObject marbleObject, Texture2D skin = null)
|
||||||
{
|
{
|
||||||
|
if (marbleObject == null)
|
||||||
|
{
|
||||||
|
Shared.Log("ApplyCustomTexture - marbleObject is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (skin == null)
|
if (skin == null)
|
||||||
skin = Config.skins[Config.currentSkin];
|
skin = Config.skins[Config.currentSkin];
|
||||||
|
|
||||||
|
@ -49,8 +56,15 @@ namespace CustomCosmeticLoader
|
||||||
for (int i = 0; i < componentsInChildren.Length; i++)
|
for (int i = 0; i < componentsInChildren.Length; i++)
|
||||||
{
|
{
|
||||||
Material[] materials = componentsInChildren[i].materials;
|
Material[] materials = componentsInChildren[i].materials;
|
||||||
|
if (materials == null)
|
||||||
|
continue;
|
||||||
foreach (Material material in materials)
|
foreach (Material material in materials)
|
||||||
material.mainTexture = skin;
|
{
|
||||||
|
if (material == null)
|
||||||
|
continue;
|
||||||
|
if (material.mainTexture != null)
|
||||||
|
material.mainTexture = skin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue