From 327e17edab4f58303a697840f82fd6e863f0d061 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 15 Aug 2022 12:14:10 -0700 Subject: [PATCH] AnimationSync: simplify send initial state --- QSB/Animation/Player/AnimationSync.cs | 32 ++++--------------- .../TitleScreenManagerPatchesGamepass.cs | 4 +-- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/QSB/Animation/Player/AnimationSync.cs b/QSB/Animation/Player/AnimationSync.cs index 2f44f1e8..025b4ba1 100644 --- a/QSB/Animation/Player/AnimationSync.cs +++ b/QSB/Animation/Player/AnimationSync.cs @@ -8,7 +8,6 @@ using QSB.Player; using QSB.Utility; using QSB.WorldSync; using System; -using System.Reflection; using UnityEngine; namespace QSB.Animation.Player; @@ -39,37 +38,18 @@ public class AnimationSync : PlayerSyncObject protected void OnDestroy() => RequestInitialStatesMessage.SendInitialState -= SendInitialState; - private void SendInitialState(uint to) - { - if (PlayerId == to) - { - return; - } - - /* - * This wipes the NetworkAnimator's "last_X_Parameters" fields, so it assumes the parameters have changed. - * Basically just forces the networkanimator to set all it's dirty flags. - * I tried just manually sending the parameter message myself, but that made the client get very angry and disconnect. - */ - - var parameters = (AnimatorControllerParameter[])NetworkAnimator.GetType().GetField("parameters", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(NetworkAnimator); - var lastIntParams = NetworkAnimator.GetType().GetField("lastIntParameters", BindingFlags.NonPublic | BindingFlags.Instance); - var lastFloatParams = NetworkAnimator.GetType().GetField("lastFloatParameters", BindingFlags.NonPublic | BindingFlags.Instance); - var lastBoolParams = NetworkAnimator.GetType().GetField("lastBoolParameters", BindingFlags.NonPublic | BindingFlags.Instance); - - lastIntParams.SetValue(NetworkAnimator, new int[parameters.Length]); - lastFloatParams.SetValue(NetworkAnimator, new float[parameters.Length]); - lastBoolParams.SetValue(NetworkAnimator, new bool[parameters.Length]); - } + private void SendInitialState(uint to) => + // This wipes the NetworkAnimator's fields, so it assumes the parameters have changed. + // Basically just forces it to set all its dirty flags. + NetworkAnimator.Invoke("Awake"); private void InitCommon(Transform modelRoot) { try { - if (modelRoot == null) { - DebugLog.ToConsole($"Error - Trying to InitCommon with null body!", MessageType.Error); + DebugLog.ToConsole("Error - Trying to InitCommon with null body!", MessageType.Error); return; } @@ -214,4 +194,4 @@ public class AnimationSync : PlayerSyncObject Mirror.RebuildFloatParams(); NetworkAnimator.Invoke("Awake"); } -} \ No newline at end of file +} diff --git a/QSB/SaveSync/Patches/TitleScreenManagerPatchesGamepass.cs b/QSB/SaveSync/Patches/TitleScreenManagerPatchesGamepass.cs index 490ca41f..4f6fbe39 100644 --- a/QSB/SaveSync/Patches/TitleScreenManagerPatchesGamepass.cs +++ b/QSB/SaveSync/Patches/TitleScreenManagerPatchesGamepass.cs @@ -1,6 +1,6 @@ using HarmonyLib; +using OWML.Utils; using QSB.Patches; -using System.Reflection; using UnityEngine.UI; namespace QSB.SaveSync.Patches; @@ -15,7 +15,7 @@ internal class TitleScreenManagerPatchesGamepass : QSBPatch [HarmonyPatch("SetUserAccountDisplayInfo")] public static bool SetUserAccountDisplayInfo(TitleScreenManager __instance) { - var text = (Text)__instance.GetType().GetField("_gamertagDisplay", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance); + var text = __instance.GetValue("_gamertagDisplay"); text.text = ""; // no idea why, mobius be like text.text = QSBMSStoreProfileManager.SharedInstance.userDisplayName; return false;