From 72a3334f4c2581104805eebbd55e33b389913053 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 4 Dec 2021 06:21:11 -0800 Subject: [PATCH 01/52] non-tornado stuff (todo: prefab) --- QSB/Patches/QSBPatchManager.cs | 4 +- QSB/QSB.csproj | 3 + QSB/QSBCore.cs | 2 + QSB/QSBNetworkManager.cs | 4 + QSB/TornadoSync/Patches/TornadoPatches.cs | 11 ++ QSB/TornadoSync/TornadoManager.cs | 46 ++++++ .../TransformSync/OccasionalTransformSync.cs | 145 ++++++++++++++++++ QSB/TornadoSync/WorldObjects/QSBTornado.cs | 13 ++ 8 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 QSB/TornadoSync/Patches/TornadoPatches.cs create mode 100644 QSB/TornadoSync/TornadoManager.cs create mode 100644 QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs create mode 100644 QSB/TornadoSync/WorldObjects/QSBTornado.cs diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 9712fdb5..e0a29310 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -29,6 +29,7 @@ using QSB.TimeSync.Patches; using QSB.Tools.ProbeLauncherTool.Patches; using QSB.Tools.SignalscopeTool.FrequencySync.Patches; using QSB.Tools.TranslatorTool.TranslationSync.Patches; +using QSB.TornadoSync.Patches; using QSB.Utility; using QSB.ZeroGCaveSync.Patches; @@ -81,7 +82,8 @@ namespace QSB.Patches new MeteorServerPatches(), new JellyfishPatches(), new TravelerControllerPatches(), - new ZeroGCavePatches() + new ZeroGCavePatches(), + new TornadoPatches() }; TypeToInstance = new Dictionary diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index a11b5377..9a084961 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -78,4 +78,7 @@ copy /y "$(OwmlDir)\OWML.Abstractions.dll" "$(UnityAssetsDir)" Always + + + diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 746cddda..8b09e458 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -29,6 +29,7 @@ using QSB.StatueSync; using QSB.TimeSync; using QSB.Tools.ProbeLauncherTool; using QSB.Tools.TranslatorTool.TranslationSync; +using QSB.TornadoSync; using QSB.Utility; using QSB.WorldSync; using QSB.ZeroGCaveSync; @@ -143,6 +144,7 @@ namespace QSB gameObject.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); + gameObject.AddComponent(); DebugBoxManager.Init(); diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 6abaab80..f70ceeaf 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -36,6 +36,7 @@ namespace QSB public GameObject ShipPrefab { get; private set; } public GameObject AnglerPrefab { get; private set; } public GameObject JellyfishPrefab { get; private set; } + public GameObject OccasionalPrefab { get; private set; } public string PlayerName { get; private set; } private const int MaxConnections = 128; @@ -70,6 +71,9 @@ namespace QSB JellyfishPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkjellyfish.prefab"); spawnPrefabs.Add(JellyfishPrefab); + OccasionalPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkoccasional.prefab"); + spawnPrefabs.Add(OccasionalPrefab); + ConfigureNetworkManager(); } diff --git a/QSB/TornadoSync/Patches/TornadoPatches.cs b/QSB/TornadoSync/Patches/TornadoPatches.cs new file mode 100644 index 00000000..d037e165 --- /dev/null +++ b/QSB/TornadoSync/Patches/TornadoPatches.cs @@ -0,0 +1,11 @@ +using QSB.Patches; + +namespace QSB.TornadoSync.Patches +{ + public class TornadoPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + + } +} diff --git a/QSB/TornadoSync/TornadoManager.cs b/QSB/TornadoSync/TornadoManager.cs new file mode 100644 index 00000000..0a38cdcb --- /dev/null +++ b/QSB/TornadoSync/TornadoManager.cs @@ -0,0 +1,46 @@ +using QSB.TornadoSync.TransformSync; +using QSB.TornadoSync.WorldObjects; +using QSB.Utility; +using QSB.WorldSync; +using QuantumUNET; +using UnityEngine; + +namespace QSB.TornadoSync +{ + public class TornadoManager : WorldObjectManager + { + protected override void RebuildWorldObjects(OWScene scene) + { + QSBWorldSync.Init(); + + foreach (var transformSync in QSBWorldSync.GetWorldObjects()) + { + QNetworkServer.Destroy(transformSync.gameObject); + } + + // islands + foreach (var islandController in QSBWorldSync.GetWorldObjects()) + { + var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); + transformSync.InitBodyIndexes(islandController._islandBody, Locator._giantsDeep.GetOWRigidbody()); + transformSync.gameObject.SpawnWithServerAuthority(); + } + + // cannon parts + foreach (var partName in new[] + { + "OrbitalProbeCannon_Body", + "CannonBarrel_Body", + "CannonMuzzle_Body", + "Debris_Body (1)", + "Debris_Body (2)" + }) + { + var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); + transformSync.InitBodyIndexes(GameObject.Find(partName).GetAttachedOWRigidbody(), + Locator._giantsDeep.GetOWRigidbody()); + transformSync.gameObject.SpawnWithServerAuthority(); + } + } + } +} diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs new file mode 100644 index 00000000..508af12e --- /dev/null +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -0,0 +1,145 @@ +using QSB.Syncs; +using QSB.Syncs.Unsectored.Rigidbodies; +using QSB.Utility; +using QSB.WorldSync; +using QuantumUNET.Transport; +using UnityEngine; + +namespace QSB.TornadoSync.TransformSync +{ + public class OccasionalTransformSync : UnsectoredRigidbodySync + { + public override bool IsReady => WorldObjectManager.AllObjectsReady; + public override bool UseInterpolation => false; + + protected override OWRigidbody GetRigidbody() => CenterOfTheUniverse.s_rigidbodies[_bodyIndex]; + + private int _bodyIndex = -1; + private int _refBodyIndex = -1; + + public void InitBodyIndexes(OWRigidbody body, OWRigidbody refBody) + { + _bodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(body); + _bodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(refBody); + } + + public override float GetNetworkSendInterval() => 1; + + protected override void Init() + { + base.Init(); + SetReferenceTransform(CenterOfTheUniverse.s_rigidbodies[_refBodyIndex].transform); + + // to prevent change in vel/angvel + if (AttachedObject.TryGetComponent(out var align) && !HasAuthority) + { + align.enabled = false; + } + } + + public override void SerializeTransform(QNetworkWriter writer, bool initialState) + { + base.SerializeTransform(writer, initialState); + + if (initialState) + { + writer.Write(_bodyIndex); + writer.Write(_refBodyIndex); + } + } + + private bool _shouldUpdate; + + public override void DeserializeTransform(QNetworkReader reader, bool initialState) + { + base.DeserializeTransform(reader, initialState); + + if (!WorldObjectManager.AllObjectsReady || HasAuthority) + { + return; + } + + if (initialState) + { + _bodyIndex = reader.ReadInt32(); + _refBodyIndex = reader.ReadInt32(); + } + + _shouldUpdate = true; + } + + /// replacement that handles KinematicRigidbody + protected override bool UpdateTransform() + { + if (HasAuthority) + { + SetValuesToSync(); + return true; + } + + if (!_shouldUpdate) + { + return false; + } + + _shouldUpdate = false; + + var targetPos = ReferenceTransform.DecodePos(transform.position); + var targetRot = ReferenceTransform.DecodeRot(transform.rotation); + + if (targetPos == Vector3.zero || transform.position == Vector3.zero) + { + return false; + } + + var positionToSet = targetPos; + var rotationToSet = targetRot; + + if (UseInterpolation) + { + positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos); + rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); + } + + var hasMoved = CustomHasMoved( + transform.position, + _localPrevPosition, + transform.rotation, + _localPrevRotation, + _relativeVelocity, + _localPrevVelocity, + _relativeAngularVelocity, + _localPrevAngularVelocity); + + _localPrevPosition = transform.position; + _localPrevRotation = transform.rotation; + _localPrevVelocity = _relativeVelocity; + _localPrevAngularVelocity = _relativeAngularVelocity; + + if (!hasMoved) + { + return true; + } + + if (((OWRigidbody)AttachedObject).RunningKinematicSimulation()) + { + ((OWRigidbody)AttachedObject).SetPosition(positionToSet); + ((OWRigidbody)AttachedObject).SetRotation(rotationToSet); + } + else + { + // does nothing for KinematicRigidbody + ((OWRigidbody)AttachedObject).MoveToPosition(positionToSet); + ((OWRigidbody)AttachedObject).MoveToRotation(rotationToSet); + } + + var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); + var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); + + ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); + ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); + + return true; + } + } +} diff --git a/QSB/TornadoSync/WorldObjects/QSBTornado.cs b/QSB/TornadoSync/WorldObjects/QSBTornado.cs new file mode 100644 index 00000000..b29ed573 --- /dev/null +++ b/QSB/TornadoSync/WorldObjects/QSBTornado.cs @@ -0,0 +1,13 @@ +using QSB.WorldSync; + +namespace QSB.TornadoSync.WorldObjects +{ + public class QSBTornado : WorldObject + { + public override void Init(TornadoController attachedObject, int id) + { + ObjectId = id; + AttachedObject = attachedObject; + } + } +} From 8da9a62b3844017729d091c3d5ddc7218bd47c95 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 4 Dec 2021 23:24:26 +0000 Subject: [PATCH 02/52] yes --- QSB/Menus/IMenuAPI.cs | 6 +-- QSB/Menus/MenuManager.cs | 110 ++++++++++++++++++++++++++++++--------- 2 files changed, 88 insertions(+), 28 deletions(-) diff --git a/QSB/Menus/IMenuAPI.cs b/QSB/Menus/IMenuAPI.cs index c30510f0..1d308537 100644 --- a/QSB/Menus/IMenuAPI.cs +++ b/QSB/Menus/IMenuAPI.cs @@ -6,9 +6,9 @@ namespace QSB.Menus public interface IMenuAPI { // Title screen - GameObject TitleScreen_MakeMenuOpenButton(string name, Menu menuToOpen); - GameObject TitleScreen_MakeSceneLoadButton(string name, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null); - Button TitleScreen_MakeSimpleButton(string name); + GameObject TitleScreen_MakeMenuOpenButton(string name, int index, Menu menuToOpen); + GameObject TitleScreen_MakeSceneLoadButton(string name, int index, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null); + Button TitleScreen_MakeSimpleButton(string name, int index); // Pause menu GameObject PauseMenu_MakeMenuOpenButton(string name, Menu menuToOpen, Menu customMenu = null); GameObject PauseMenu_MakeSceneLoadButton(string name, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null, Menu customMenu = null); diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 7ac927ca..729f744c 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -1,4 +1,5 @@ using QSB.Player; +using QSB.Utility; using System.Linq; using UnityEngine; using UnityEngine.Networking; @@ -12,11 +13,21 @@ namespace QSB.Menus private IMenuAPI MenuApi => QSBCore.MenuApi; private PopupMenu PopupMenu; + private PopupMenu InfoPopup; + private bool _addedPauseLock; + private Button HostButton; private GameObject ClientButton; private Button DisconnectButton; - private PopupMenu InfoPopup; - private bool _addedPauseLock; + private Button JoinMultiplayerGame; + + private GameObject ResumeGameButton; + private GameObject NewGameButton; + + private const int _JoinGameIndex = 1; + private const int _HostButtonIndex = 2; + private const int _ClientButtonIndex = 3; + private const int _DisconnectIndex = 2; public void Start() { @@ -81,6 +92,16 @@ namespace QSB.Menus InfoPopup.OnDeactivateMenu += OnCloseInfoPopup; } + private void SetButtonActive(Button button, bool active) + => SetButtonActive(button.gameObject, active); + + private void SetButtonActive(GameObject button, bool active) + { + DebugLog.DebugWrite($"Set {button.name} to {active}"); + button.SetActive(active); + button.GetComponent().alpha = active ? 1 : 0; + } + private void InitPauseMenus() { CreateCommonPopups(); @@ -97,13 +118,11 @@ namespace QSB.Menus { ClientButton.SetActive(false); HostButton.gameObject.SetActive(false); - DisconnectButton.gameObject.SetActive(true); - DisconnectButton.GetComponent().alpha = 1f; + SetButtonActive(DisconnectButton, true); } else { - DisconnectButton.gameObject.SetActive(false); - DisconnectButton.GetComponent().alpha = 1f; + SetButtonActive(DisconnectButton, false); } OnConnected(); @@ -113,25 +132,45 @@ namespace QSB.Menus { CreateCommonPopups(); - HostButton = MenuApi.TitleScreen_MakeSimpleButton("MULTIPLAYER (HOST)"); + HostButton = MenuApi.TitleScreen_MakeSimpleButton("MULTIPLAYER (HOST)", _HostButtonIndex); HostButton.onClick.AddListener(Host); - ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("MULTIPLAYER (CONNECT)", PopupMenu); + ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("MULTIPLAYER (CONNECT)", _ClientButtonIndex, PopupMenu); - DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT"); + DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT", _DisconnectIndex); DisconnectButton.onClick.AddListener(Disconnect); + JoinMultiplayerGame = MenuApi.TitleScreen_MakeSimpleButton("JOIN MULTIPLAYER GAME", _JoinGameIndex); + JoinMultiplayerGame.onClick.AddListener(Join); + + ResumeGameButton = GameObject.Find("MainMenuLayoutGroup/Button-ResumeGame"); + NewGameButton = GameObject.Find("MainMenuLayoutGroup/Button-NewGame"); + if (QSBCore.IsInMultiplayer) { ClientButton.SetActive(false); HostButton.gameObject.SetActive(false); - DisconnectButton.gameObject.SetActive(true); - DisconnectButton.GetComponent().alpha = 1f; + SetButtonActive(DisconnectButton, true); + + if (QSBCore.IsHost) + { + SetButtonActive(JoinMultiplayerGame, false); + SetButtonActive(ResumeGameButton, true); + SetButtonActive(NewGameButton, true); + } + else + { + SetButtonActive(JoinMultiplayerGame, true); + SetButtonActive(ResumeGameButton, false); + SetButtonActive(NewGameButton, false); + } } else { - DisconnectButton.gameObject.SetActive(false); - DisconnectButton.GetComponent().alpha = 1f; + SetButtonActive(DisconnectButton, false); + SetButtonActive(JoinMultiplayerGame, false); + SetButtonActive(ResumeGameButton, true); + SetButtonActive(NewGameButton, true); } OnConnected(); @@ -156,21 +195,35 @@ namespace QSB.Menus } } + private void Join() + { + DebugLog.DebugWrite($"Join"); + } + private void Disconnect() { QSBNetworkManager.Instance.StopHost(); - DisconnectButton.gameObject.SetActive(false); - ClientButton.SetActive(true); - HostButton.gameObject.SetActive(true); + SetButtonActive(DisconnectButton.gameObject, false); + SetButtonActive(JoinMultiplayerGame, false); + SetButtonActive(ClientButton, true); + SetButtonActive(HostButton, true); } private void Host() { - QSBNetworkManager.Instance.StartHost(); - DisconnectButton.gameObject.SetActive(true); - DisconnectButton.GetComponent().alpha = 1f; - ClientButton.SetActive(false); - HostButton.gameObject.SetActive(false); + DebugLog.DebugWrite($"Host"); + + if (QSBNetworkManager.Instance.StartHost() != null) + { + SetButtonActive(DisconnectButton, true); + SetButtonActive(JoinMultiplayerGame, false); + SetButtonActive(ClientButton, false); + SetButtonActive(HostButton, false); + } + else + { + OpenInfoPopup($"Failed to start server.", "OK"); + } } private void Connect() @@ -178,10 +231,17 @@ namespace QSB.Menus QSBNetworkManager.Instance.networkAddress = string.Concat((PopupMenu as PopupInputMenu).GetInputText().Where(c => !char.IsWhiteSpace(c))); QSBNetworkManager.Instance.StartClient(); DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent().text = "CONNECTING... (STOP)"; - DisconnectButton.gameObject.SetActive(true); - DisconnectButton.GetComponent().alpha = 1f; - ClientButton.SetActive(false); - HostButton.gameObject.SetActive(false); + + SetButtonActive(DisconnectButton, true); + SetButtonActive(JoinMultiplayerGame, true); + SetButtonActive(ClientButton, false); + SetButtonActive(HostButton, false); + + if (QSBSceneManager.CurrentScene == OWScene.TitleScreen) + { + SetButtonActive(ResumeGameButton, false); + SetButtonActive(NewGameButton, false); + } } private void OnConnected() From 41af623ded06f14ed08122f42fe95389425b0476 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 4 Dec 2021 17:44:21 -0800 Subject: [PATCH 03/52] use prefab template to make network objects --- QSB/AssetBundles/network | Bin 3948 -> 3213 bytes QSB/AssetBundles/network.manifest | 22 ++++------------- QSB/QSBCore.cs | 2 +- QSB/QSBNetworkManager.cs | 38 +++++++++++++++++++++++------- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/QSB/AssetBundles/network b/QSB/AssetBundles/network index dfbd89d660febf2a184c618b419aab16cf3476d0..e1bab2b2b0d5cb22f764b5bce02ae68c1cebc088 100644 GIT binary patch delta 3123 zcmV-349xTF9*r50BmxYLktQMrJ@^0s3=EM@JAb=~3^){=QIs#w4S?#G#*NWy&z;7x zQdlC$(7y7qS0`rD8CBzu)g}io6i1AaY1JqHs@p2gTf_I*&5;`UH|=~>(0#18aNfuh zGzl!LLRY)n0Pj0B|MsJ{*Px7X{Wxq>Qu)gYql$ed)s(#yA%XJj$CBw^Go4~s;^q|= z?|%lez<_kkzkqt(zDd3VJ+wlw#S&%b>ST=-6h0XtcrMMMT9olxpYP^zNHk9knS%SL z5SrEmGShz7K0nV=UbsBB?eAqp5di9aXl+r?^)O53tbsruK9hpZK(Vb9Q>Q7j1!c8~ z^J=bRCt1V$<%%^VgHw#PR#V46$vjLQaer6Nxl-~`vrJ?%c~ZHwzX=H_Y~QufdZAqc z6+SA?7^3P_VrI6)1DbvoG29eK+Z?I(fD!lCMD8`BfA0uhh;hbyT}^+q4^37QFa@&{ zA6>HJlNXO#+_EIFdD1sPz76*M3Hnj84d-}q|GxHfpaFU3k;SMC1H|TUzprE3@PBcq zeecG3?88awAvHov;lMrw%{%4~@av=R52ABF1A9*6t>2S2(O5gL!gB$`x#jfKM-RX7 zwxuxm(Iruy0=EGC>87AL`sQp||0iW=Q3JlkRN%ejo)=od zeJSFHeBSB~fCV>0ZrG*&KE^@<_|=8OSKc=tqV&=#eD94`QXMGw(A?(RRR`kh5% z%YB`{R_}o{xxR(Pe;4jFy$Dh&)knX98WD_HqRAad#nvy3{nan#u&@%N+J6wBlW`gL z>OQV-(&n!h6#0p*lybp|mM;W-}%{VtyaURfX%ALUEiIe7A z+2iA6eu~57AP&>aDH`1~zj@n*9-E@!qk(dMDGYK)%nVW^U>>xA~fU02N$B zSGb=wI9a?P%V|$q>KBY@lo|3#LR_-!h;!dsX$x*S5>1$xVA&Z1?SF&dj;+i64T5$Zt$1RvO4`mUPB}+@wfQ@3OZQZCl6;ti-#_fA5rr* z1H-|r&Jmr^5&z&#jj#VW!qr&;%kV*M<#uS1sT`FR3Z2i*$V|0&gvf`|hj@8}+gU;Pf7L;y+8ah-Q8iDcn8!4X|ISg(ty+h7h??|;whA%sjIC+cQM)|Ud?0P`kJ&`+(gXo-I9i3-E@FH-$_uZbQvAynfdR}@|< zh({8DqoV5Ov8$V1#qA^nm;>N+LW(ol)grCx;4D@{n6q33?2!k;2J#ecGzTBJo6>g7E;EZtfn(WmUl54*9 z{ev`-Ek!`Nkc|R2xKbs8ChBlsHHUrMla18)kk6uEm46r0RK5Rk|7MynwZ8}fSof*g zU=r0j=aN~~&c)3>v$o-q6?~CQ-Z)f>_~cpFPv?M!A1DocH41pk+OI+1ATA>Y-Eg@3 zUhe3|f5z9?pI;^eV56Nzv#A;d9T7TrUw&V6QyiqArRWU%^y4M@?%{z`6+ev)UU9{oqek;_Ab7~a!rFFS5GAA{` z9ak)F*YKlFn&5XD3Wzq@=9rSL0()d4A$f^msBMBF+~9n3@C1Vy2mCPd=G(xyT%IC} zRx?aMuJUY8QhsFFugfz1Fw@t(XG6p@pp}^ZIe%{xuLgK$$~@J$C-4+nYi~ONzSlTT zNc1@z_fLaS!`})G@~W+g)`5#?0-la_5 zW7dp`_c{ezO`{ajZoN91g}yd2l9&L%^?z-`OA+@aI+GENm{3=>WZUb<86YFj&>N=n z+zP>tK9a8#zH84UOKjz8d;S}m@~86!jftYBW!}=+uLd$OR&hr=p<`utR_15oxtLwI~?Wz~&P z)DtaG7!`S(jz=OYrqL6qys#KT#nBD3QPpw9Zc-W^gxN!|2w>I;JV?Vw=vnrvdd!Q$ z0!nfHK}QFUH?x6JBRc%bP0H6@Ie+R^aED-H!0-X6LRf*30T%?g77eOFvVPzm{QD*9--@qDn!8MUDx<9;V7M-kifG+W2Y5 zbNw$XKEpVh-;rHK8Mq_)Q~J1d+yZNB{PR-i?;Kva&V9>oj6mg{27~`A1E^K({hI9yMTI+)JyDhgqXc#J(J!`6;T)-)iaQ_|Xcg9i<%{w|iDp-JWt^`BS0mq1i3kjc{o zZ-?Pw_m+AmF=6xZ_$}Y?Q-3pF8TP63KshQ)i5Lz<$aUIda$F;~a9%7lG#XDP(;_{ke8Rlb&EGvt0#sPT;+DMmwYBbr`tm~h?7oK@Xc2RRdK`?z* z8f+3YX}0j}e%N@q?tTRKri&*n?b|pq9sT222%|jLQ=ryu-Z!CUNPq6vB&qg$Vn|l* z%TLE0R?Ry8=Kok{{XnxyOXw`1(+V)n`#8HN5-6Ox#RgON+{I6a1`8@88;vqe;g$)UJlTt#qyr@OO{s>OnM zkim0mRTpVHc>41FDk&YOg z2>wGbeO8}tn(9#da_XgwD>?%?>EkB#)v+FJ)SH@6_X%}OrGN9m`9H>yJU0rD+5wK3 zpE_@;B~6`cB&0YuV>spy$;8Yl5hjvWbBO(d=!W1KlYx)k#F{AgpQ5PGulhuyEf&%K z+Fv1oY^?#;%QWF}0oR-DDBw!TH11qGLkm_*I^w!M^7=@BhI<+9NmYl{fTQM)n6jA? zb()9tk!h>q2!GyDgVbwiyw^JXqqTV z?5NVWA?IqC*Vc=RE3wQB>Wm5P6yzu- z>PVos()okn$m`gQqL9!1x_%kaRR3NkI1AT2!TFs_tQnL&SVs0RF N9Nh({O^W-k5hrG*|+f{|~5EpMJuO%C;FLv)A z)2&%_ac|L^Hd;karq6!P=#sMRDDrK`rb_)M#}V^JjglcE+HIn)?t?wMhTwiYrUXb) z$A5=vcoK+Zbe!E%1!zK=FlE^e8$Px+D*pQuFQ42dN$)Wn6;Ss}s;05?0a^=dgq5t@ zKXdiB%5xbnEs7TFwE;C4&{?etCuDPZ5JIN*!POW{>C?vAl^r>&PbU0vj1TzSqLIn`;Xb;eD-naSFtUzmi-d(X*i({v=Lw^o; z6}QWdY(#zfp{G6+e2$+xrPvG^q`$3|8SdqxT8sOk1Jw`Gbqt zHh_Ps$mTz$7nmA8(q3#I`^Hh^xkqxbFs!R(k|#lP7Z__r>UccYVKB0ni=okN4VYMQ zgzGD_xMppY$@IR$fnLLhpI#&t=YsWMYQTIj=|WNVo>Pb2n%%f0z<;epb6Fa3{cJVJ zy>*DN@5fN2U^)@ijbt2{IE$& zB6OqbEoecx5=_d?xPKJs1_G7JAdcRo#MPJx$}R5+Yr1blOsk*Y9{Cn&ie z7Jc*uJG!t{P5l8Tx4)>liL0XDpr-LOUaP)gh4mU#_=7DEfa}ybZ&Ru zUW|BALv%}yzB)*8e}esa-xVzyRNaX}{5DeO$aB`5yezxz?P`9VeMaj;e4l4(5v7{$ z#3L}6-i{!oeScm;PZJ{ysu)sInwpa^f@r3P;@?@bSUwqRe5;Y6Yhb>VaC4w4Gs5<`BIZN6Cq0&#BeC+vEmI)D2(ypnwXyWabC3C25rvXt!_ zVQ<1gE#7%{V1JLL6RqmJJ1w4ggoPUC*FGLW&!?H7{+Vxk17tghdl+kZ{D1rW4fQ^1 zM>Y7rVRw4vl`%`~QJL5#47=vQm@$r&g_JI17k`l{9t&Pt&W6c-@=n_rxtRAD&7C*F@v3*g2t9qlMm{^8WVAD9n3>LK zyb(UhgSy`|jNM;;>MYD`^nhm)K%bXg_!?lLWG<4*gDhYi(*usmaa;7@B-1 zD?uu}uy&Kgd+Yo&-m=khWqSJkPS6r?htFBCw;UGJ{)-1*{b*^yE2~cY8~Njl-gBY@ zQ-9BEs9QiFY8bcZ32%)I#>gzLv}4b?}?@aM&+y8twru_yr@Lm3|iVwA0e|;jObujYa+HK zWx5vqQ?EUN>~MiFQE%WXhsld@B5k;pT9|GgD<-(NU+iP*9qJ*lOb$Pr3eEZCnt#V< zF`*m9x8R!vEydr;2v?ACs}-i7h`sDJi5GdDRkrKs@+KPBOaFele^(C5{_K_5KLan4 zEFE7Hdo@h;z_5&i;ax#K(;oo!-ak8!k13aSLp4g1`$l(BgUjUs!F?4V?2Xkvj6E7{ zdl#6;xPQdVm`i28rF>f^4O+y4C4Y}-xrdd=HlB(C5ixzNsxPhe-j;C`j#d*ArvFL| zb(ZTYoilX!Ud33;)dvI+=GL-tfehl;WgvwtgU`yP&v3(xM8X9x_cF@^#+7@t53%KF zf52qFoTa~#E~Sczfx=*j$ETk_LREx_ipY;3%QD;_i8_nfT=s(~CAWob9)Cw85a^!^ zRj=@^LVxH+JYz@pcz>Lz0*{=H(b(WGOj}!u$-q+j>Bo?<8SUbXzmu5*}B^^`#q7!H* z1k2J&%H$IZE|f_z`^sA2%&yGiXV1XEij8Cwa+u9V`oA2)wGU*vsegY7e?czM)sC3? ziMLM?!ioMYf&OmAMv&C`7`pU^5O2{Klh_aq?W{==TaBoyNSqKIoxz{1GWAEuu^PbAMpJn}}b@jQf&;<4=N1?VLL-1p%Q@0JN$!RoO=(hRh(O_>5}m z!O$gW%PLO{Qj+Z$U9?OopQC0*s93@b%@t4^eJU~sw8I6lT}%uQN7D50>*VGv8AO!rUZ1$+hbQE8dD& z+lZfJV%T0~{c(OMzxNl*d%m~gCgwiwIexq!gji%xJ-0+J?KPk^b2UA;$|-g`kG<7a z!jQlS!l597cVzi@%mBHvJqM_oezAfHe&5A} z*f0-}d7+yoF;6S45qh~hzP7;d$+TQULRj?F(vV!H?`2LE_{x;pkCEDd3h zkd>J3JL!g5VCUGi4u#(rf@NHU-kE-C9;(Gs8Gq=SCHyfg1x9uAy7G6nrKr6R`?M&6 zt7b2e!(V?!PhYji0(JfgPG!?bfbmqyNi3PqSN2hZUDJb$dNGY4L6-~AcY-^KeU^DX zm`K0T4T68m>cHynAiGjJ)U+>nuic3=LO4jq1qG+_!_n7#KPD`k%Nr$1gPYB~%H5QJ zAb+epGFq95b&h1M2`VD+3lhYUu%)Kz>4=wB`U(WBFIt_74E5mr_h!2>f21ZxpiE-{d$V(7 z^I?UL2}SvtJpcRvz-sXLc(x$!7&wXWU-IO2|wKcE&vs zs@Wi596_<@jJ15CD@5ZUG!hp3Z9A3yO-VX$spQbEBLBs^tDT|cml02KB5+=Y>bn#03opzxdez#f{GWRT(6Rox_O?wxY^;NKuVq!-vCT1vd90zmpuBe;^!6kjko z!-3|rwrTSpaGWMBGKa{Qc&D?q!7wrh7&k@;Mp~TUvdMiE-Vm?DvMEn DebugMode && DebugSettings.ShowQuantumDebugBoxes; public static bool AvoidTimeSync => DebugMode && DebugSettings.AvoidTimeSync; public static bool SkipTitleScreen => DebugMode && DebugSettings.SkipTitleScreen; - public static AssetBundle NetworkAssetBundle { get; private set; } + public static AssetBundle NetworkAssetBundle { get; internal set; } public static AssetBundle InstrumentAssetBundle { get; private set; } public static AssetBundle ConversationAssetBundle { get; private set; } public static AssetBundle DebugAssetBundle { get; private set; } diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index f70ceeaf..92f557cc 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -2,10 +2,12 @@ using System.Linq; using OWML.Common; using OWML.Utils; +using QSB.Anglerfish.TransformSync; using QSB.AuthoritySync; using QSB.ClientServerStateSync; using QSB.DeathSync; using QSB.Events; +using QSB.JellyfishSync.TransformSync; using QSB.OrbSync.TransformSync; using QSB.Patches; using QSB.Player; @@ -13,6 +15,8 @@ using QSB.Player.TransformSync; using QSB.PoolSync; using QSB.ShipSync.TransformSync; using QSB.TimeSync; +using QSB.Tools.ProbeTool.TransformSync; +using QSB.TornadoSync.TransformSync; using QSB.Utility; using QSB.WorldSync; using QuantumUNET; @@ -42,7 +46,6 @@ namespace QSB private const int MaxConnections = 128; private const int MaxBufferedPackets = 64; - private AssetBundle _assetBundle; private GameObject _probePrefab; private bool _everConnected; @@ -52,26 +55,25 @@ namespace QSB Instance = this; PlayerName = GetPlayerName(); - _assetBundle = QSBCore.NetworkAssetBundle; - playerPrefab = _assetBundle.LoadAsset("Assets/Prefabs/NETWORK_Player_Body.prefab"); + playerPrefab = QSBCore.NetworkAssetBundle.LoadAsset("Assets/Prefabs/NETWORK_Player_Body.prefab"); - ShipPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkship.prefab"); + ShipPrefab = MakeNewNetworkObject(2, "NetworkShip", typeof(ShipTransformSync)); spawnPrefabs.Add(ShipPrefab); - _probePrefab = _assetBundle.LoadAsset("assets/Prefabs/networkprobe.prefab"); + _probePrefab = MakeNewNetworkObject(3, "NetworkProbe", typeof(PlayerProbeSync)); spawnPrefabs.Add(_probePrefab); - OrbPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkorb.prefab"); + OrbPrefab = MakeNewNetworkObject(4, "NetworkOrb", typeof(NomaiOrbTransformSync)); spawnPrefabs.Add(OrbPrefab); - AnglerPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkangler.prefab"); + AnglerPrefab = MakeNewNetworkObject(5, "NetworkAngler", typeof(AnglerTransformSync)); spawnPrefabs.Add(AnglerPrefab); - JellyfishPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkjellyfish.prefab"); + JellyfishPrefab = MakeNewNetworkObject(6, "NetworkJellyfish", typeof(JellyfishTransformSync)); spawnPrefabs.Add(JellyfishPrefab); - OccasionalPrefab = _assetBundle.LoadAsset("assets/Prefabs/networkoccasional.prefab"); + OccasionalPrefab = MakeNewNetworkObject(7, "NetworkOccasional", typeof(OccasionalTransformSync)); spawnPrefabs.Add(OccasionalPrefab); ConfigureNetworkManager(); @@ -94,6 +96,24 @@ namespace QSB } } + /// create a new network prefab from the network object prefab template. + /// this works by calling Unload(false) and then reloading the AssetBundle, + /// which makes LoadAsset give you a new resource. + /// see https://docs.unity3d.com/Manual/AssetBundles-Native.html. + private static GameObject MakeNewNetworkObject(int assetId, string name, Type transformSyncType) + { + QSBCore.NetworkAssetBundle.Unload(false); + QSBCore.NetworkAssetBundle = QSBCore.Helper.Assets.LoadBundle("AssetBundles/network"); + + var template = QSBCore.NetworkAssetBundle.LoadAsset("Assets/Prefabs/NetworkObject.prefab"); + DebugLog.DebugWrite($"MakeNewNetworkObject - prefab id {template.GetInstanceID()} " + + $"for {assetId} {name} {transformSyncType.Name}"); + template.name = name; + template.GetRequiredComponent().SetValue("m_AssetId", assetId); + template.AddComponent(transformSyncType); + return template; + } + private void ConfigureNetworkManager() { networkAddress = QSBCore.DefaultServerIP; From e69c74ae66f3ab18ed4a3e7054f23715b61f5dac Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 4 Dec 2021 18:33:43 -0800 Subject: [PATCH 04/52] make body indexes actually work --- .../TransformSync/OccasionalTransformSync.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index 508af12e..d9be430f 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -20,7 +20,7 @@ namespace QSB.TornadoSync.TransformSync public void InitBodyIndexes(OWRigidbody body, OWRigidbody refBody) { _bodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(body); - _bodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(refBody); + _refBodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(refBody); } public override float GetNetworkSendInterval() => 1; @@ -30,8 +30,8 @@ namespace QSB.TornadoSync.TransformSync base.Init(); SetReferenceTransform(CenterOfTheUniverse.s_rigidbodies[_refBodyIndex].transform); - // to prevent change in vel/angvel - if (AttachedObject.TryGetComponent(out var align) && !HasAuthority) + // to prevent change in rotation/angvel + if (!HasAuthority && AttachedObject.TryGetComponent(out var align)) { align.enabled = false; } @@ -54,17 +54,17 @@ namespace QSB.TornadoSync.TransformSync { base.DeserializeTransform(reader, initialState); - if (!WorldObjectManager.AllObjectsReady || HasAuthority) - { - return; - } - if (initialState) { _bodyIndex = reader.ReadInt32(); _refBodyIndex = reader.ReadInt32(); } + if (!WorldObjectManager.AllObjectsReady || HasAuthority) + { + return; + } + _shouldUpdate = true; } From b16710d92324c687f05e95aa270646a1947e6b5c Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 4 Dec 2021 18:34:00 -0800 Subject: [PATCH 05/52] le funny islands werent showing up for some reason --- QSB/TornadoSync/TornadoManager.cs | 40 +++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/QSB/TornadoSync/TornadoManager.cs b/QSB/TornadoSync/TornadoManager.cs index 0a38cdcb..2beebff2 100644 --- a/QSB/TornadoSync/TornadoManager.cs +++ b/QSB/TornadoSync/TornadoManager.cs @@ -1,4 +1,5 @@ -using QSB.TornadoSync.TransformSync; +using System.Linq; +using QSB.TornadoSync.TransformSync; using QSB.TornadoSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; @@ -13,32 +14,51 @@ namespace QSB.TornadoSync { QSBWorldSync.Init(); + if (!QSBCore.IsHost) + { + return; + } + foreach (var transformSync in QSBWorldSync.GetWorldObjects()) { QNetworkServer.Destroy(transformSync.gameObject); } - // islands - foreach (var islandController in QSBWorldSync.GetWorldObjects()) + // cannon parts + var mainCannonPart = GameObject.Find("OrbitalProbeCannon_Body").GetAttachedOWRigidbody(); { var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); - transformSync.InitBodyIndexes(islandController._islandBody, Locator._giantsDeep.GetOWRigidbody()); + transformSync.InitBodyIndexes(mainCannonPart, Locator._giantsDeep.GetOWRigidbody()); transformSync.gameObject.SpawnWithServerAuthority(); } - - // cannon parts - foreach (var partName in new[] + foreach (var cannonPartNames in new[] { - "OrbitalProbeCannon_Body", "CannonBarrel_Body", "CannonMuzzle_Body", "Debris_Body (1)", "Debris_Body (2)" }) { + var cannonPart = GameObject.Find(cannonPartNames).GetAttachedOWRigidbody(); var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); - transformSync.InitBodyIndexes(GameObject.Find(partName).GetAttachedOWRigidbody(), - Locator._giantsDeep.GetOWRigidbody()); + transformSync.InitBodyIndexes(cannonPart, mainCannonPart); + transformSync.gameObject.SpawnWithServerAuthority(); + } + + // islands + var islandControllers = QSBWorldSync.GetWorldObjects().ToArray(); + DebugLog.DebugWrite($"there are {islandControllers.Length} islandControllers"); + foreach (var islandNames in new[] + { + "GabbroIsland_Body", + "StatueIsland_Body", + "ConstructionYardIsland_Body", + "BrambleIsland_Body" + }) + { + var island = GameObject.Find(islandNames).GetAttachedOWRigidbody(); + var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); + transformSync.InitBodyIndexes(island, Locator._giantsDeep.GetOWRigidbody()); transformSync.gameObject.SpawnWithServerAuthority(); } } From 369f8078bfd52f87155f7d5d320799a8c92476fa Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 4 Dec 2021 18:56:25 -0800 Subject: [PATCH 06/52] the j --- QSB/TornadoSync/TornadoManager.cs | 15 +++------------ .../TransformSync/OccasionalTransformSync.cs | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/QSB/TornadoSync/TornadoManager.cs b/QSB/TornadoSync/TornadoManager.cs index 2beebff2..695b12e3 100644 --- a/QSB/TornadoSync/TornadoManager.cs +++ b/QSB/TornadoSync/TornadoManager.cs @@ -25,29 +25,20 @@ namespace QSB.TornadoSync } // cannon parts - var mainCannonPart = GameObject.Find("OrbitalProbeCannon_Body").GetAttachedOWRigidbody(); - { - var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); - transformSync.InitBodyIndexes(mainCannonPart, Locator._giantsDeep.GetOWRigidbody()); - transformSync.gameObject.SpawnWithServerAuthority(); - } foreach (var cannonPartNames in new[] { + "OrbitalProbeCannon_Body", "CannonBarrel_Body", - "CannonMuzzle_Body", - "Debris_Body (1)", - "Debris_Body (2)" + "CannonMuzzle_Body" }) { var cannonPart = GameObject.Find(cannonPartNames).GetAttachedOWRigidbody(); var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); - transformSync.InitBodyIndexes(cannonPart, mainCannonPart); + transformSync.InitBodyIndexes(cannonPart, Locator._giantsDeep.GetOWRigidbody()); transformSync.gameObject.SpawnWithServerAuthority(); } // islands - var islandControllers = QSBWorldSync.GetWorldObjects().ToArray(); - DebugLog.DebugWrite($"there are {islandControllers.Length} islandControllers"); foreach (var islandNames in new[] { "GabbroIsland_Body", diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index d9be430f..830fda6a 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -23,7 +23,7 @@ namespace QSB.TornadoSync.TransformSync _refBodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(refBody); } - public override float GetNetworkSendInterval() => 1; + // public override float GetNetworkSendInterval() => 1; protected override void Init() { From 253e778f0c46d973953dc48bd74e87d25b35910f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 4 Dec 2021 19:40:57 -0800 Subject: [PATCH 07/52] move player if we need to --- .../TransformSync/JellyfishTransformSync.cs | 5 --- QSB/TornadoSync/TornadoManager.cs | 3 +- .../TransformSync/OccasionalTransformSync.cs | 45 ++++++++++++++++--- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs index d343fea2..b97492c8 100644 --- a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs +++ b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs @@ -93,11 +93,6 @@ namespace QSB.JellyfishSync.TransformSync var targetPos = ReferenceTransform.DecodePos(transform.position); var targetRot = ReferenceTransform.DecodeRot(transform.rotation); - if (targetPos == Vector3.zero || transform.position == Vector3.zero) - { - return false; - } - var positionToSet = targetPos; var rotationToSet = targetRot; diff --git a/QSB/TornadoSync/TornadoManager.cs b/QSB/TornadoSync/TornadoManager.cs index 695b12e3..5d4eae86 100644 --- a/QSB/TornadoSync/TornadoManager.cs +++ b/QSB/TornadoSync/TornadoManager.cs @@ -1,5 +1,4 @@ -using System.Linq; -using QSB.TornadoSync.TransformSync; +using QSB.TornadoSync.TransformSync; using QSB.TornadoSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index 830fda6a..3d79e602 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -1,4 +1,5 @@ -using QSB.Syncs; +using QSB.Player; +using QSB.Syncs; using QSB.Syncs.Unsectored.Rigidbodies; using QSB.Utility; using QSB.WorldSync; @@ -15,6 +16,7 @@ namespace QSB.TornadoSync.TransformSync protected override OWRigidbody GetRigidbody() => CenterOfTheUniverse.s_rigidbodies[_bodyIndex]; private int _bodyIndex = -1; + private Sector _sector; private int _refBodyIndex = -1; public void InitBodyIndexes(OWRigidbody body, OWRigidbody refBody) @@ -23,12 +25,13 @@ namespace QSB.TornadoSync.TransformSync _refBodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(refBody); } - // public override float GetNetworkSendInterval() => 1; + public override float GetNetworkSendInterval() => 1; protected override void Init() { base.Init(); SetReferenceTransform(CenterOfTheUniverse.s_rigidbodies[_refBodyIndex].transform); + _sector = ((OWRigidbody)AttachedObject).GetComponentInChildren(); // to prevent change in rotation/angvel if (!HasAuthority && AttachedObject.TryGetComponent(out var align)) @@ -87,11 +90,6 @@ namespace QSB.TornadoSync.TransformSync var targetPos = ReferenceTransform.DecodePos(transform.position); var targetRot = ReferenceTransform.DecodeRot(transform.rotation); - if (targetPos == Vector3.zero || transform.position == Vector3.zero) - { - return false; - } - var positionToSet = targetPos; var rotationToSet = targetRot; @@ -121,6 +119,27 @@ namespace QSB.TornadoSync.TransformSync return true; } + // todo? also do this with the ship? + string playerSector = null!; + string thisSector = null!; + Vector3 playerPos = default; + Quaternion playerRot = default; + Vector3 playerVel = default; + Vector3 playerAngVel = default; + if (_sector != null) + { + playerSector = QSBPlayerManager.LocalPlayer.TransformSync.ReferenceSector.Name; + thisSector = _sector.name; + if (playerSector == thisSector) + { + var pos = Locator.GetPlayerBody().GetPosition(); + playerPos = ((OWRigidbody)AttachedObject).transform.EncodePos(pos); + playerRot = ((OWRigidbody)AttachedObject).transform.EncodeRot(Locator.GetPlayerBody().GetRotation()); + playerVel = ((OWRigidbody)AttachedObject).EncodeVel(Locator.GetPlayerBody().GetVelocity(), pos); + playerAngVel = ((OWRigidbody)AttachedObject).EncodeAngVel(Locator.GetPlayerBody().GetAngularVelocity()); + } + } + if (((OWRigidbody)AttachedObject).RunningKinematicSimulation()) { ((OWRigidbody)AttachedObject).SetPosition(positionToSet); @@ -139,6 +158,18 @@ namespace QSB.TornadoSync.TransformSync ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); + if (_sector != null) + { + if (playerSector == thisSector) + { + var pos = ((OWRigidbody)AttachedObject).transform.DecodePos(playerPos); + Locator.GetPlayerBody().SetPosition(pos); + Locator.GetPlayerBody().SetRotation(((OWRigidbody)AttachedObject).transform.DecodeRot(playerRot)); + Locator.GetPlayerBody().SetVelocity(((OWRigidbody)AttachedObject).DecodeVel(playerVel, pos)); + Locator.GetPlayerBody().SetAngularVelocity(((OWRigidbody)AttachedObject).DecodeAngVel(playerAngVel)); + } + } + return true; } } From e02d70d7b113c425dc2d1cb1c1b1df8dcd19c7f0 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 4 Dec 2021 19:48:41 -0800 Subject: [PATCH 08/52] multiple child sectors oops --- .../TransformSync/OccasionalTransformSync.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index 3d79e602..ee577087 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -1,4 +1,6 @@ -using QSB.Player; +using System.Collections.Generic; +using System.Linq; +using QSB.Player; using QSB.Syncs; using QSB.Syncs.Unsectored.Rigidbodies; using QSB.Utility; @@ -16,7 +18,7 @@ namespace QSB.TornadoSync.TransformSync protected override OWRigidbody GetRigidbody() => CenterOfTheUniverse.s_rigidbodies[_bodyIndex]; private int _bodyIndex = -1; - private Sector _sector; + private string[] _sectors; private int _refBodyIndex = -1; public void InitBodyIndexes(OWRigidbody body, OWRigidbody refBody) @@ -31,7 +33,8 @@ namespace QSB.TornadoSync.TransformSync { base.Init(); SetReferenceTransform(CenterOfTheUniverse.s_rigidbodies[_refBodyIndex].transform); - _sector = ((OWRigidbody)AttachedObject).GetComponentInChildren(); + _sectors = ((OWRigidbody)AttachedObject).GetComponentsInChildren() + .Select(x => x.name).ToArray(); // to prevent change in rotation/angvel if (!HasAuthority && AttachedObject.TryGetComponent(out var align)) @@ -119,18 +122,16 @@ namespace QSB.TornadoSync.TransformSync return true; } - // todo? also do this with the ship? - string playerSector = null!; - string thisSector = null!; + // todo also do this with the ship/probe. oh and orbs. yeah this really sucks + string playerSector = null; Vector3 playerPos = default; Quaternion playerRot = default; Vector3 playerVel = default; Vector3 playerAngVel = default; - if (_sector != null) + if (_sectors != null) { playerSector = QSBPlayerManager.LocalPlayer.TransformSync.ReferenceSector.Name; - thisSector = _sector.name; - if (playerSector == thisSector) + if (_sectors.Contains(playerSector)) { var pos = Locator.GetPlayerBody().GetPosition(); playerPos = ((OWRigidbody)AttachedObject).transform.EncodePos(pos); @@ -158,9 +159,9 @@ namespace QSB.TornadoSync.TransformSync ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); - if (_sector != null) + if (_sectors != null) { - if (playerSector == thisSector) + if (_sectors.Contains(playerSector)) { var pos = ((OWRigidbody)AttachedObject).transform.DecodePos(playerPos); Locator.GetPlayerBody().SetPosition(pos); From 906c5448d22e1f9af8f2322d71a8839dd0092234 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 4 Dec 2021 20:09:29 -0800 Subject: [PATCH 09/52] make this actually occasional. it's jank for now. oh well --- QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index ee577087..5b96aea9 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -27,7 +27,7 @@ namespace QSB.TornadoSync.TransformSync _refBodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(refBody); } - public override float GetNetworkSendInterval() => 1; + public override float GetNetworkSendInterval() => 20; protected override void Init() { @@ -128,7 +128,7 @@ namespace QSB.TornadoSync.TransformSync Quaternion playerRot = default; Vector3 playerVel = default; Vector3 playerAngVel = default; - if (_sectors != null) + if (_sectors.Length != 0) { playerSector = QSBPlayerManager.LocalPlayer.TransformSync.ReferenceSector.Name; if (_sectors.Contains(playerSector)) @@ -159,7 +159,7 @@ namespace QSB.TornadoSync.TransformSync ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); - if (_sectors != null) + if (_sectors.Length != 0) { if (_sectors.Contains(playerSector)) { From 7bbe2953f911e9f2a6127cc8ce6dd88842076119 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 10:23:36 +0000 Subject: [PATCH 10/52] Update IMenuAPI.cs --- QSB/Menus/IMenuAPI.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/QSB/Menus/IMenuAPI.cs b/QSB/Menus/IMenuAPI.cs index 1d308537..edb0a932 100644 --- a/QSB/Menus/IMenuAPI.cs +++ b/QSB/Menus/IMenuAPI.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; using UnityEngine.UI; namespace QSB.Menus @@ -6,6 +7,13 @@ namespace QSB.Menus public interface IMenuAPI { // Title screen + [Obsolete] + GameObject TitleScreen_MakeMenuOpenButton(string name, Menu menuToOpen); + [Obsolete] + GameObject TitleScreen_MakeSceneLoadButton(string name, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null); + [Obsolete] + Button TitleScreen_MakeSimpleButton(string name); + GameObject TitleScreen_MakeMenuOpenButton(string name, int index, Menu menuToOpen); GameObject TitleScreen_MakeSceneLoadButton(string name, int index, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null); Button TitleScreen_MakeSimpleButton(string name, int index); From 078ac3b863f05a1f91dc6552a34da3a367020b6f Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 5 Dec 2021 02:26:58 -0800 Subject: [PATCH 11/52] SectoredRigidbodySync: set transform.position to Vector3.zero if ReferenceTransform is null, like in SectoredTransformSync --- .../Rigidbodies/SectoredRigidbodySync.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs index 460bcf1e..4a547b9d 100644 --- a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs +++ b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs @@ -94,10 +94,20 @@ namespace QSB.Syncs.Sectored.Rigidbodies protected void SetValuesToSync() { - transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); - transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); - _relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeVel(((OWRigidbody)AttachedObject).GetVelocity(), AttachedObject.transform.position); - _relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeAngVel(((OWRigidbody)AttachedObject).GetAngularVelocity()); + if (ReferenceTransform != null) + { + transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); + _relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeVel(((OWRigidbody)AttachedObject).GetVelocity(), AttachedObject.transform.position); + _relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeAngVel(((OWRigidbody)AttachedObject).GetAngularVelocity()); + } + else + { + transform.position = Vector3.zero; + transform.rotation = Quaternion.identity; + _relativeVelocity = Vector3.zero; + _relativeAngularVelocity = Vector3.zero; + } } protected override bool UpdateTransform() From 1849fdec9486e42e350365908ce4a36faef7b19a Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 5 Dec 2021 02:30:43 -0800 Subject: [PATCH 12/52] the j --- QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index 5b96aea9..1d0e3c41 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using QSB.Player; using QSB.Syncs; using QSB.Syncs.Unsectored.Rigidbodies; From 857d99eca759da2aa18a356b7b0583a410c54d99 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 5 Dec 2021 02:48:01 -0800 Subject: [PATCH 13/52] boinky --- QSB/QSB.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 9a084961..a11b5377 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -78,7 +78,4 @@ copy /y "$(OwmlDir)\OWML.Abstractions.dll" "$(UnityAssetsDir)" Always - - - From b52abafe241af8d102bbbba4c4c14ad391e19348 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 11:00:18 +0000 Subject: [PATCH 14/52] pain --- QSB/Menus/MenuManager.cs | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 729f744c..4326caad 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -19,15 +19,12 @@ namespace QSB.Menus private Button HostButton; private GameObject ClientButton; private Button DisconnectButton; - private Button JoinMultiplayerGame; private GameObject ResumeGameButton; private GameObject NewGameButton; - private const int _JoinGameIndex = 1; - private const int _HostButtonIndex = 2; - private const int _ClientButtonIndex = 3; - private const int _DisconnectIndex = 2; + private const int _ClientButtonIndex = 2; + private const int _DisconnectIndex = 3; public void Start() { @@ -97,6 +94,11 @@ namespace QSB.Menus private void SetButtonActive(GameObject button, bool active) { + if (button == null) + { + return; + } + DebugLog.DebugWrite($"Set {button.name} to {active}"); button.SetActive(active); button.GetComponent().alpha = active ? 1 : 0; @@ -109,8 +111,6 @@ namespace QSB.Menus HostButton = MenuApi.PauseMenu_MakeSimpleButton("MULTIPLAYER (HOST)"); HostButton.onClick.AddListener(Host); - ClientButton = MenuApi.PauseMenu_MakeMenuOpenButton("MULTIPLAYER (CONNECT)", PopupMenu); - DisconnectButton = MenuApi.PauseMenu_MakeSimpleButton("DISCONNECT"); DisconnectButton.onClick.AddListener(Disconnect); @@ -132,35 +132,26 @@ namespace QSB.Menus { CreateCommonPopups(); - HostButton = MenuApi.TitleScreen_MakeSimpleButton("MULTIPLAYER (HOST)", _HostButtonIndex); - HostButton.onClick.AddListener(Host); - ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("MULTIPLAYER (CONNECT)", _ClientButtonIndex, PopupMenu); DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT", _DisconnectIndex); DisconnectButton.onClick.AddListener(Disconnect); - JoinMultiplayerGame = MenuApi.TitleScreen_MakeSimpleButton("JOIN MULTIPLAYER GAME", _JoinGameIndex); - JoinMultiplayerGame.onClick.AddListener(Join); - ResumeGameButton = GameObject.Find("MainMenuLayoutGroup/Button-ResumeGame"); NewGameButton = GameObject.Find("MainMenuLayoutGroup/Button-NewGame"); if (QSBCore.IsInMultiplayer) { ClientButton.SetActive(false); - HostButton.gameObject.SetActive(false); SetButtonActive(DisconnectButton, true); if (QSBCore.IsHost) { - SetButtonActive(JoinMultiplayerGame, false); SetButtonActive(ResumeGameButton, true); SetButtonActive(NewGameButton, true); } else { - SetButtonActive(JoinMultiplayerGame, true); SetButtonActive(ResumeGameButton, false); SetButtonActive(NewGameButton, false); } @@ -168,7 +159,6 @@ namespace QSB.Menus else { SetButtonActive(DisconnectButton, false); - SetButtonActive(JoinMultiplayerGame, false); SetButtonActive(ResumeGameButton, true); SetButtonActive(NewGameButton, true); } @@ -204,7 +194,6 @@ namespace QSB.Menus { QSBNetworkManager.Instance.StopHost(); SetButtonActive(DisconnectButton.gameObject, false); - SetButtonActive(JoinMultiplayerGame, false); SetButtonActive(ClientButton, true); SetButtonActive(HostButton, true); } @@ -216,7 +205,6 @@ namespace QSB.Menus if (QSBNetworkManager.Instance.StartHost() != null) { SetButtonActive(DisconnectButton, true); - SetButtonActive(JoinMultiplayerGame, false); SetButtonActive(ClientButton, false); SetButtonActive(HostButton, false); } @@ -233,9 +221,7 @@ namespace QSB.Menus DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent().text = "CONNECTING... (STOP)"; SetButtonActive(DisconnectButton, true); - SetButtonActive(JoinMultiplayerGame, true); SetButtonActive(ClientButton, false); - SetButtonActive(HostButton, false); if (QSBSceneManager.CurrentScene == OWScene.TitleScreen) { @@ -266,7 +252,7 @@ namespace QSB.Menus DisconnectButton.gameObject.SetActive(false); ClientButton.SetActive(true); - HostButton.gameObject.SetActive(true); + HostButton?.gameObject.SetActive(true); } private void OnDisconnected(NetworkError error) @@ -285,7 +271,7 @@ namespace QSB.Menus DisconnectButton.gameObject.SetActive(false); ClientButton.SetActive(true); - HostButton.gameObject.SetActive(true); + HostButton?.gameObject.SetActive(true); } private void OnClientError(NetworkError error) @@ -303,7 +289,7 @@ namespace QSB.Menus text = "Internal QNet client error!\r\nDNS Faliure. Address was invalid or could not be resolved."; DisconnectButton.gameObject.SetActive(false); ClientButton.SetActive(true); - HostButton.gameObject.SetActive(true); + HostButton?.gameObject.SetActive(true); break; default: text = $"Internal QNet client error!\n\nNetworkError:{error}"; From 85ef88769891f561c5bd32c4aa8f5f05b4d42c91 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 5 Dec 2021 03:41:07 -0800 Subject: [PATCH 15/52] form collapse event --- QSB/Events/EventNames.cs | 1 + QSB/Events/QSBEventManager.cs | 2 + .../Events/TornadoFormCollapseEvent.cs | 32 ++++++++++ QSB/TornadoSync/Patches/TornadoPatches.cs | 64 ++++++++++++++++++- QSB/TornadoSync/TornadoManager.cs | 1 + QSB/TornadoSync/WorldObjects/QSBTornado.cs | 17 ++++- 6 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index b37d2b4e..dbf91074 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -102,5 +102,6 @@ public const string QSBSatelliteRepaired = nameof(QSBSatelliteRepairTick); public const string QSBAuthorityQueue = nameof(QSBAuthorityQueue); public const string QSBJellyfishRising = nameof(QSBJellyfishRising); + public const string QSBTornadoFormCollapse = nameof(QSBTornadoFormCollapse); } } diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index 7a8cfe40..536186d3 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -32,6 +32,7 @@ using QSB.Tools.SignalscopeTool.Events; using QSB.Tools.SignalscopeTool.FrequencySync.Events; using QSB.Tools.TranslatorTool.Events; using QSB.Tools.TranslatorTool.TranslationSync.Events; +using QSB.TornadoSync.Events; using QSB.Utility; using QSB.Utility.Events; using QSB.ZeroGCaveSync.Events; @@ -106,6 +107,7 @@ namespace QSB.Events new FragmentDamageEvent(), new FragmentResyncEvent(), new JellyfishRisingEvent(), + new TornadoFormCollapseEvent(), // Conversation/dialogue/exploration new ConversationEvent(), new ConversationStartEndEvent(), diff --git a/QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs b/QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs new file mode 100644 index 00000000..c5b16d81 --- /dev/null +++ b/QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs @@ -0,0 +1,32 @@ +using QSB.Events; +using QSB.TornadoSync.WorldObjects; +using QSB.WorldSync; +using QSB.WorldSync.Events; + +namespace QSB.TornadoSync.Events +{ + public class TornadoFormCollapseEvent : QSBEvent + { + public override bool RequireWorldObjectsReady => true; + + public override void SetupListener() + => GlobalMessenger.AddListener(EventNames.QSBJellyfishRising, Handler); + + public override void CloseListener() + => GlobalMessenger.RemoveListener(EventNames.QSBJellyfishRising, Handler); + + private void Handler(QSBTornado qsbTornado, bool formCollapse) => SendEvent(CreateMessage(qsbTornado, formCollapse)); + + private BoolWorldObjectMessage CreateMessage(QSBTornado qsbTornado, bool formCollapse) => new() + { + ObjectId = qsbTornado.ObjectId, + State = formCollapse + }; + + public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message) + { + var qsbTornado = QSBWorldSync.GetWorldFromId(message.ObjectId); + qsbTornado.FormCollapse(message.State); + } + } +} diff --git a/QSB/TornadoSync/Patches/TornadoPatches.cs b/QSB/TornadoSync/Patches/TornadoPatches.cs index d037e165..c2d2e514 100644 --- a/QSB/TornadoSync/Patches/TornadoPatches.cs +++ b/QSB/TornadoSync/Patches/TornadoPatches.cs @@ -1,4 +1,11 @@ -using QSB.Patches; +using HarmonyLib; +using QSB.AuthoritySync; +using QSB.Events; +using QSB.JellyfishSync.WorldObjects; +using QSB.Patches; +using QSB.TornadoSync.WorldObjects; +using QSB.WorldSync; +using UnityEngine; namespace QSB.TornadoSync.Patches { @@ -6,6 +13,61 @@ namespace QSB.TornadoSync.Patches { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + [HarmonyPrefix] + [HarmonyPatch(typeof(TornadoController), nameof(TornadoController.FixedUpdate))] + public static bool FixedUpdate(TornadoController __instance) + { + if (QSBCore.IsHost && __instance._secondsUntilFormation > 0f) + { + __instance._secondsUntilFormation -= Time.fixedDeltaTime; + if (__instance._secondsUntilFormation < 0f) + { + __instance.StartFormation(); + var qsbTornado = QSBWorldSync.GetWorldFromUnity(__instance); + QSBEventManager.FireEvent(EventNames.QSBTornadoFormCollapse, qsbTornado, true); + return false; + } + } + else + { + if (__instance._tornadoCollapsing) + { + __instance.UpdateCollapse(); + } + else if (__instance._tornadoForming) + { + __instance.UpdateFormation(); + } + if (__instance._isSectorOccupied) + { + __instance.UpdateAnimation(); + if (__instance._wander) + { + var num = Mathf.PerlinNoise(Time.time * __instance._wanderRate, 0f) * 2f - 1f; + var num2 = Mathf.PerlinNoise(Time.time * __instance._wanderRate, 5f) * 2f - 1f; + var localEulerAngles = new Vector3(num * __instance._wanderDegreesX, 0f, num2 * __instance._wanderDegreesZ); + __instance.transform.localEulerAngles = localEulerAngles; + } + } + } + return false; + } + + + [HarmonyPrefix] + [HarmonyPatch(typeof(TornadoController), nameof(TornadoController.OnEnterCollapseTrigger))] + public static bool OnEnterCollapseTrigger(TornadoController __instance, + GameObject hitObject) + { + if (QSBCore.IsHost && hitObject.GetComponentInParent().GetMass() > 50f) + { + __instance.StartCollapse(); + var qsbTornado = QSBWorldSync.GetWorldFromUnity(__instance); + QSBEventManager.FireEvent(EventNames.QSBTornadoFormCollapse, qsbTornado, false); + } + + return false; + } } } diff --git a/QSB/TornadoSync/TornadoManager.cs b/QSB/TornadoSync/TornadoManager.cs index 5d4eae86..9181beb5 100644 --- a/QSB/TornadoSync/TornadoManager.cs +++ b/QSB/TornadoSync/TornadoManager.cs @@ -13,6 +13,7 @@ namespace QSB.TornadoSync { QSBWorldSync.Init(); + return; if (!QSBCore.IsHost) { return; diff --git a/QSB/TornadoSync/WorldObjects/QSBTornado.cs b/QSB/TornadoSync/WorldObjects/QSBTornado.cs index b29ed573..83293199 100644 --- a/QSB/TornadoSync/WorldObjects/QSBTornado.cs +++ b/QSB/TornadoSync/WorldObjects/QSBTornado.cs @@ -1,4 +1,5 @@ -using QSB.WorldSync; +using QSB.Utility; +using QSB.WorldSync; namespace QSB.TornadoSync.WorldObjects { @@ -9,5 +10,19 @@ namespace QSB.TornadoSync.WorldObjects ObjectId = id; AttachedObject = attachedObject; } + + public void FormCollapse(bool formCollapse) + { + if (formCollapse) + { + AttachedObject.StartFormation(); + DebugLog.DebugWrite($"{LogName} form"); + } + else + { + AttachedObject.StartCollapse(); + DebugLog.DebugWrite($"{LogName} collapse"); + } + } } } From 8a571e37e5063024589b4d442bf447fa5f8b5183 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 14:06:15 +0000 Subject: [PATCH 16/52] fix errors in statue and respawn managers --- QSB/RespawnSync/RespawnManager.cs | 6 ++++++ QSB/StatueSync/StatueManager.cs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/QSB/RespawnSync/RespawnManager.cs b/QSB/RespawnSync/RespawnManager.cs index 917b681d..a2f26748 100644 --- a/QSB/RespawnSync/RespawnManager.cs +++ b/QSB/RespawnSync/RespawnManager.cs @@ -56,6 +56,12 @@ namespace QSB.RespawnSync return; } + if (PlayerTransformSync.LocalInstance == null) + { + DebugLog.ToConsole($"Error - Tried to init when PlayerTransformSync.LocalInstance was null!", OWML.Common.MessageType.Error); + return; + } + QSBPlayerManager.ShowAllPlayers(); QSBPlayerManager.LocalPlayer.UpdateStatesFromObjects(); QSBPlayerManager.PlayerList.ForEach(x => x.IsDead = false); diff --git a/QSB/StatueSync/StatueManager.cs b/QSB/StatueSync/StatueManager.cs index 6ee6ebee..62ed255c 100644 --- a/QSB/StatueSync/StatueManager.cs +++ b/QSB/StatueSync/StatueManager.cs @@ -1,4 +1,6 @@ using QSB.Player; +using QSB.Player.TransformSync; +using QSB.Utility; using System.Collections; using UnityEngine; @@ -25,6 +27,12 @@ namespace QSB.StatueSync return; } + if (PlayerTransformSync.LocalInstance == null) + { + DebugLog.ToConsole($"Error - Tried to run OnUniverseSceneLoaded when PlayerTransformSync.LocalInstance was null!", OWML.Common.MessageType.Error); + return; + } + QSBPlayerManager.ShowAllPlayers(); QSBPlayerManager.LocalPlayer.UpdateStatesFromObjects(); } From d75136bbc38f9ca0fcf88c68f262da06e6c600b5 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 14:06:43 +0000 Subject: [PATCH 17/52] sync loop count and frequencies --- QSB/Events/EventNames.cs | 2 + QSB/Events/QSBEventManager.cs | 3 + QSB/Menus/MenuManager.cs | 98 ++++++++++++++++---- QSB/SaveSync/Events/GameStateEvent.cs | 50 ++++++++++ QSB/SaveSync/Events/GameStateMessage.cs | 58 ++++++++++++ QSB/SaveSync/Events/RequestGameStateEvent.cs | 32 +++++++ 6 files changed, 225 insertions(+), 18 deletions(-) create mode 100644 QSB/SaveSync/Events/GameStateEvent.cs create mode 100644 QSB/SaveSync/Events/GameStateMessage.cs create mode 100644 QSB/SaveSync/Events/RequestGameStateEvent.cs diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index b37d2b4e..c19be58f 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -102,5 +102,7 @@ public const string QSBSatelliteRepaired = nameof(QSBSatelliteRepairTick); public const string QSBAuthorityQueue = nameof(QSBAuthorityQueue); public const string QSBJellyfishRising = nameof(QSBJellyfishRising); + public const string QSBRequestGameDetails = nameof(QSBRequestGameDetails); + public const string QSBGameDetails = nameof(QSBGameDetails); } } diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index 7a8cfe40..05c134e8 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -20,6 +20,7 @@ using QSB.QuantumSync.Events; using QSB.RespawnSync.Events; using QSB.RoastingSync.Events; using QSB.SatelliteSync.Events; +using QSB.SaveSync.Events; using QSB.ShipSync.Events; using QSB.ShipSync.Events.Component; using QSB.ShipSync.Events.Hull; @@ -82,6 +83,8 @@ namespace QSB.Events new SatelliteProjectorEvent(), new SatelliteProjectorSnapshotEvent(), new LaunchCodesEvent(), + new RequestGameStateEvent(), + new GameStateEvent(), // World Objects new ElevatorEvent(), new GeyserEvent(), diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 4326caad..18646a82 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -1,6 +1,9 @@ -using QSB.Player; +using QSB.Events; +using QSB.Player; +using QSB.Player.TransformSync; using QSB.Utility; using System.Linq; +using System.Text; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; @@ -15,6 +18,8 @@ namespace QSB.Menus private PopupMenu PopupMenu; private PopupMenu InfoPopup; private bool _addedPauseLock; + private StringBuilder _nowLoadingSB; + protected Text _loadingText; private Button HostButton; private GameObject ClientButton; @@ -50,6 +55,50 @@ namespace QSB.Menus } } + private void ResetStringBuilder() + { + if (_nowLoadingSB == null) + { + _nowLoadingSB = new StringBuilder(); + return; + } + _nowLoadingSB.Length = 0; + } + + private void Update() + { + if ((LoadManager.GetLoadingScene() == OWScene.SolarSystem || LoadManager.GetLoadingScene() == OWScene.EyeOfTheUniverse) && _loadingText != null) + { + var num = LoadManager.GetAsyncLoadProgress(); + num = num < 0.1f + ? Mathf.InverseLerp(0f, 0.1f, num) * 0.9f + : 0.9f + (Mathf.InverseLerp(0.1f, 1f, num) * 0.1f); + ResetStringBuilder(); + _nowLoadingSB.Append(UITextLibrary.GetString(UITextType.LoadingMessage)); + _nowLoadingSB.Append(num.ToString("P0")); + _loadingText.text = _nowLoadingSB.ToString(); + } + } + + public void JoinGame(bool inEye, bool inSolarSystem) + { + DebugLog.DebugWrite($"Join game ineye:{inEye} inSolarSystem:{inSolarSystem}"); + if (inEye) + { + LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, true, LoadManager.FadeType.ToBlack, 1f, false); + Locator.GetMenuInputModule().DisableInputs(); + } + else if (inSolarSystem) + { + LoadManager.LoadSceneAsync(OWScene.SolarSystem, true, LoadManager.FadeType.ToBlack, 1f, false); + Locator.GetMenuInputModule().DisableInputs(); + } + else + { + DebugLog.DebugWrite("tried to join game that wasnt in solar system or eye??"); + } + } + private void OpenInfoPopup(string message, string buttonText) { InfoPopup.SetUpPopup(message, InputLibrary.menuConfirm, InputLibrary.cancel, new ScreenPrompt(buttonText), null, true, false); @@ -90,7 +139,7 @@ namespace QSB.Menus } private void SetButtonActive(Button button, bool active) - => SetButtonActive(button.gameObject, active); + => SetButtonActive(button?.gameObject, active); private void SetButtonActive(GameObject button, bool active) { @@ -99,7 +148,6 @@ namespace QSB.Menus return; } - DebugLog.DebugWrite($"Set {button.name} to {active}"); button.SetActive(active); button.GetComponent().alpha = active ? 1 : 0; } @@ -116,12 +164,12 @@ namespace QSB.Menus if (QSBCore.IsInMultiplayer) { - ClientButton.SetActive(false); - HostButton.gameObject.SetActive(false); + SetButtonActive(HostButton, false); SetButtonActive(DisconnectButton, true); } else { + SetButtonActive(HostButton, true); SetButtonActive(DisconnectButton, false); } @@ -136,6 +184,7 @@ namespace QSB.Menus DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT", _DisconnectIndex); DisconnectButton.onClick.AddListener(Disconnect); + _loadingText = DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent(); ResumeGameButton = GameObject.Find("MainMenuLayoutGroup/Button-ResumeGame"); NewGameButton = GameObject.Find("MainMenuLayoutGroup/Button-NewGame"); @@ -147,7 +196,7 @@ namespace QSB.Menus if (QSBCore.IsHost) { - SetButtonActive(ResumeGameButton, true); + SetButtonActive(ResumeGameButton, StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount > 1); SetButtonActive(NewGameButton, true); } else @@ -159,7 +208,7 @@ namespace QSB.Menus else { SetButtonActive(DisconnectButton, false); - SetButtonActive(ResumeGameButton, true); + SetButtonActive(ResumeGameButton, StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount > 1); SetButtonActive(NewGameButton, true); } @@ -185,11 +234,6 @@ namespace QSB.Menus } } - private void Join() - { - DebugLog.DebugWrite($"Join"); - } - private void Disconnect() { QSBNetworkManager.Instance.StopHost(); @@ -232,10 +276,23 @@ namespace QSB.Menus private void OnConnected() { + DebugLog.DebugWrite($"ON CONNECTED"); + var text = QSBCore.IsHost ? "STOP HOSTING" : "DISCONNECT"; DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent().text = text; + + if (QSBCore.IsHost || !QSBCore.IsInMultiplayer) + { + return; + } + + QSBCore.UnityEvents.RunWhen(() => QSBEventManager.Ready && PlayerTransformSync.LocalInstance != null, () => + { + DebugLog.DebugWrite($"requesting game details"); + QSBEventManager.FireEvent(EventNames.QSBRequestGameDetails); + }); } public void OnKicked(KickReason reason) @@ -269,9 +326,11 @@ namespace QSB.Menus }; OpenInfoPopup(text, "OK"); - DisconnectButton.gameObject.SetActive(false); - ClientButton.SetActive(true); - HostButton?.gameObject.SetActive(true); + SetButtonActive(DisconnectButton, false); + SetButtonActive(ClientButton, true); + SetButtonActive(HostButton, true); + SetButtonActive(ResumeGameButton, StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount > 1); + SetButtonActive(NewGameButton, true); } private void OnClientError(NetworkError error) @@ -287,9 +346,12 @@ namespace QSB.Menus { case NetworkError.DNSFailure: text = "Internal QNet client error!\r\nDNS Faliure. Address was invalid or could not be resolved."; - DisconnectButton.gameObject.SetActive(false); - ClientButton.SetActive(true); - HostButton?.gameObject.SetActive(true); + DebugLog.DebugWrite($"dns failure"); + SetButtonActive(DisconnectButton, false); + SetButtonActive(ClientButton, true); + SetButtonActive(HostButton, true); + SetButtonActive(ResumeGameButton, StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount > 1); + SetButtonActive(NewGameButton, true); break; default: text = $"Internal QNet client error!\n\nNetworkError:{error}"; diff --git a/QSB/SaveSync/Events/GameStateEvent.cs b/QSB/SaveSync/Events/GameStateEvent.cs new file mode 100644 index 00000000..93087989 --- /dev/null +++ b/QSB/SaveSync/Events/GameStateEvent.cs @@ -0,0 +1,50 @@ +using QSB.Events; +using QSB.Menus; +using QSB.Utility; +using System; +using System.Linq; + +namespace QSB.SaveSync.Events +{ + // only to be sent from host + internal class GameStateEvent : QSBEvent + { + public override bool RequireWorldObjectsReady => false; + + public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBGameDetails, Handler); + public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBGameDetails, Handler); + + private void Handler() => SendEvent(CreateMessage()); + + private GameStateMessage CreateMessage() => new() + { + AboutId = LocalPlayerId, + InSolarSystem = QSBSceneManager.CurrentScene == OWScene.SolarSystem, + InEye = QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse, + LoopCount = StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount, + KnownFrequencies = StandaloneProfileManager.SharedInstance.currentProfileGameSave.knownFrequencies + }; + + public override void OnReceiveRemote(bool isHost, GameStateMessage message) + { + var gameSave = StandaloneProfileManager.SharedInstance.currentProfileGameSave; + DebugLog.DebugWrite($"loopcount:{message.LoopCount}"); + gameSave.loopCount = message.LoopCount; + for (var i = 0; i < message.KnownFrequencies.Length; i++) + { + DebugLog.DebugWrite($"knowsFrequency{i}:{message.KnownFrequencies[i]}"); + } + gameSave.knownFrequencies = message.KnownFrequencies; + + PlayerData.SaveCurrentGame(); + + DebugLog.DebugWrite($"inEye:{message.InEye}"); + DebugLog.DebugWrite($"inSolarSystem:{message.InSolarSystem}"); + if (message.InEye != (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) + || message.InSolarSystem != (QSBSceneManager.CurrentScene == OWScene.SolarSystem)) + { + MenuManager.Instance.JoinGame(message.InEye, message.InSolarSystem); + } + } + } +} diff --git a/QSB/SaveSync/Events/GameStateMessage.cs b/QSB/SaveSync/Events/GameStateMessage.cs new file mode 100644 index 00000000..030f9339 --- /dev/null +++ b/QSB/SaveSync/Events/GameStateMessage.cs @@ -0,0 +1,58 @@ +using QSB.Messaging; +using QSB.Utility; +using QuantumUNET.Transport; +using System; + +namespace QSB.SaveSync.Events +{ + internal class GameStateMessage : PlayerMessage + { + public bool InSolarSystem { get; set; } + public bool InEye { get; set; } + public int LoopCount { get; set; } + public bool[] KnownFrequencies { get; set; } + + public override void Deserialize(QNetworkReader reader) + { + base.Deserialize(reader); + // in solarsystem + InSolarSystem = reader.ReadBoolean(); + + // in eye + InEye = reader.ReadBoolean(); + + // Loop count + LoopCount = reader.ReadInt32(); + + // Known Frequencies + var frequenciesLength = reader.ReadInt32(); + var knownFrequencies = KnownFrequencies; + Array.Resize(ref knownFrequencies, frequenciesLength); + KnownFrequencies = knownFrequencies; + for (var i = 0; i < frequenciesLength; i++) + { + KnownFrequencies[i] = reader.ReadBoolean(); + } + } + + public override void Serialize(QNetworkWriter writer) + { + base.Serialize(writer); + // in solarsystem + writer.Write(InSolarSystem); + + // in eye + writer.Write(InEye); + + // Loop count + writer.Write(LoopCount); + + // Known frequencies + writer.Write(KnownFrequencies.Length); + foreach (var item in KnownFrequencies) + { + writer.Write(item); + } + } + } +} diff --git a/QSB/SaveSync/Events/RequestGameStateEvent.cs b/QSB/SaveSync/Events/RequestGameStateEvent.cs new file mode 100644 index 00000000..930768a4 --- /dev/null +++ b/QSB/SaveSync/Events/RequestGameStateEvent.cs @@ -0,0 +1,32 @@ +using QSB.Events; +using QSB.Messaging; +using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QSB.SaveSync.Events +{ + internal class RequestGameStateEvent : QSBEvent + { + public override bool RequireWorldObjectsReady => false; + + public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBRequestGameDetails, Handler); + public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBRequestGameDetails, Handler); + + private void Handler() => SendEvent(CreateMessage()); + + private PlayerMessage CreateMessage() => new() + { + AboutId = LocalPlayerId, + OnlySendToHost = true + }; + + public override void OnReceiveRemote(bool isHost, PlayerMessage message) + { + QSBEventManager.FireEvent(EventNames.QSBGameDetails); + } + } +} From c17ea7607f8889e67c53515d19ba50edd8f036cf Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 23:32:01 +0000 Subject: [PATCH 18/52] add error catch to serialize --- QuantumUNET/QNetworkServer.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/QuantumUNET/QNetworkServer.cs b/QuantumUNET/QNetworkServer.cs index 13551272..3e436b9c 100644 --- a/QuantumUNET/QNetworkServer.cs +++ b/QuantumUNET/QNetworkServer.cs @@ -1257,7 +1257,16 @@ namespace QuantumUNET if (handlers.ContainsKey(msgType) && m_LocalConnection != null) { var writer = new QNetworkWriter(); - msg.Serialize(writer); + try + { + msg.Serialize(writer); + } + catch (Exception ex) + { + QLog.Error($"Error serializing msgId:{msgType} - {ex}"); + return false; + } + var reader = new QNetworkReader(writer); m_LocalConnection.InvokeHandler(msgType, reader, channelId); result = true; From 73b83d22f6282a82104e3165e2a904dd72a277a2 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 23:32:19 +0000 Subject: [PATCH 19/52] add timeloop debug gui --- QSB/Utility/DebugGUI.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index e124ecec..525c6df5 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -112,6 +112,12 @@ namespace QSB.Utility WriteLine(1, $"Timescale : {OWTime.GetTimeScale()}"); WriteLine(1, $"Time Remaining : {Mathf.Floor(TimeLoop.GetSecondsRemaining() / 60f)}:{Mathf.Round(TimeLoop.GetSecondsRemaining() % 60f * 100f / 100f)}"); WriteLine(1, $"Loop Count : {TimeLoop.GetLoopCount()}"); + WriteLine(1, $"TimeLoop Initialized : {TimeLoop._initialized}"); + if (TimeLoop._initialized) + { + WriteLine(1, $"TimeLoop IsTimeFlowing : {TimeLoop.IsTimeFlowing()}"); + WriteLine(1, $"TimeLoop IsTimeLoopEnabled : {TimeLoop.IsTimeLoopEnabled()}"); + } } #endregion From 81e1f113a99ca8104d5038527074c0dac494469b Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 23:33:24 +0000 Subject: [PATCH 20/52] dont draw lines --- QSB/debugsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/debugsettings.json b/QSB/debugsettings.json index c125ec65..c6d0afb9 100644 --- a/QSB/debugsettings.json +++ b/QSB/debugsettings.json @@ -1,6 +1,6 @@ { "debugMode": true, - "drawLines": true, + "drawLines": false, "showQuantumVisibilityObjects": false, "showQuantumDebugBoxes": false, "avoidTimeSync": false, From bcec680235e5b9eb823a94228bfb22c604d32183 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 23:34:06 +0000 Subject: [PATCH 21/52] add ToId and SendToSpecific --- QSB/Events/QSBEvent.cs | 5 +++++ QSB/Messaging/PlayerMessage.cs | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/QSB/Events/QSBEvent.cs b/QSB/Events/QSBEvent.cs index 5194bf7c..93aed4ce 100644 --- a/QSB/Events/QSBEvent.cs +++ b/QSB/Events/QSBEvent.cs @@ -75,6 +75,11 @@ namespace QSB.Events return; } + if (message.SendToSpecific && message.ToId != LocalPlayerId) + { + return; + } + if (PlayerTransformSync.LocalInstance == null || PlayerTransformSync.LocalInstance.GetComponent() == null) { DebugLog.ToConsole($"Warning - Tried to handle message of type <{GetType().Name}> before localplayer was established.", MessageType.Warning); diff --git a/QSB/Messaging/PlayerMessage.cs b/QSB/Messaging/PlayerMessage.cs index dc22a948..e3262711 100644 --- a/QSB/Messaging/PlayerMessage.cs +++ b/QSB/Messaging/PlayerMessage.cs @@ -15,6 +15,17 @@ namespace QSB.Messaging /// public uint AboutId { get; set; } + /// + /// The Player ID that this message is for + /// (only used if SendToSpecific is set) + /// + public uint ToId { get; set; } + + /// + /// when this message is only being sent to ToId + /// + public bool SendToSpecific { get; set; } + /// /// If true, only send this message to the host of the current session /// (OnReceiveLocal/Remote is not called on any other client) @@ -26,6 +37,11 @@ namespace QSB.Messaging FromId = reader.ReadUInt32(); AboutId = reader.ReadUInt32(); OnlySendToHost = reader.ReadBoolean(); + SendToSpecific = reader.ReadBoolean(); + if (SendToSpecific) + { + ToId = reader.ReadUInt32(); + } } public override void Serialize(QNetworkWriter writer) @@ -33,6 +49,11 @@ namespace QSB.Messaging writer.Write(FromId); writer.Write(AboutId); writer.Write(OnlySendToHost); + writer.Write(SendToSpecific); + if (SendToSpecific) + { + writer.Write(ToId); + } } } } \ No newline at end of file From 5b15d26bea7b2bc871c31a7eb0c7025b40091788 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 23:34:49 +0000 Subject: [PATCH 22/52] cleanup requestgamestateevent --- QSB/SaveSync/Events/RequestGameStateEvent.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/QSB/SaveSync/Events/RequestGameStateEvent.cs b/QSB/SaveSync/Events/RequestGameStateEvent.cs index 930768a4..d732f96d 100644 --- a/QSB/SaveSync/Events/RequestGameStateEvent.cs +++ b/QSB/SaveSync/Events/RequestGameStateEvent.cs @@ -24,9 +24,6 @@ namespace QSB.SaveSync.Events OnlySendToHost = true }; - public override void OnReceiveRemote(bool isHost, PlayerMessage message) - { - QSBEventManager.FireEvent(EventNames.QSBGameDetails); - } + public override void OnReceiveRemote(bool isHost, PlayerMessage message) => QSBEventManager.FireEvent(EventNames.QSBGameDetails, message.FromId); } } From 61e43cec21f5bac7948c9ec5ad8be430ab505bb7 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 5 Dec 2021 23:35:33 +0000 Subject: [PATCH 23/52] add KnownSignals --- QSB/SaveSync/Events/GameStateEvent.cs | 22 +++++++++++++++------- QSB/SaveSync/Events/GameStateMessage.cs | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/QSB/SaveSync/Events/GameStateEvent.cs b/QSB/SaveSync/Events/GameStateEvent.cs index 93087989..98ce0427 100644 --- a/QSB/SaveSync/Events/GameStateEvent.cs +++ b/QSB/SaveSync/Events/GameStateEvent.cs @@ -1,8 +1,6 @@ using QSB.Events; using QSB.Menus; using QSB.Utility; -using System; -using System.Linq; namespace QSB.SaveSync.Events { @@ -11,18 +9,20 @@ namespace QSB.SaveSync.Events { public override bool RequireWorldObjectsReady => false; - public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBGameDetails, Handler); - public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBGameDetails, Handler); + public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBGameDetails, Handler); + public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBGameDetails, Handler); - private void Handler() => SendEvent(CreateMessage()); + private void Handler(uint toId) => SendEvent(CreateMessage(toId)); - private GameStateMessage CreateMessage() => new() + private GameStateMessage CreateMessage(uint toId) => new() { AboutId = LocalPlayerId, + ToId = toId, InSolarSystem = QSBSceneManager.CurrentScene == OWScene.SolarSystem, InEye = QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse, LoopCount = StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount, - KnownFrequencies = StandaloneProfileManager.SharedInstance.currentProfileGameSave.knownFrequencies + KnownFrequencies = StandaloneProfileManager.SharedInstance.currentProfileGameSave.knownFrequencies, + KnownSignals = StandaloneProfileManager.SharedInstance.currentProfileGameSave.knownSignals }; public override void OnReceiveRemote(bool isHost, GameStateMessage message) @@ -34,8 +34,16 @@ namespace QSB.SaveSync.Events { DebugLog.DebugWrite($"knowsFrequency{i}:{message.KnownFrequencies[i]}"); } + gameSave.knownFrequencies = message.KnownFrequencies; + foreach (var item in message.KnownSignals) + { + DebugLog.DebugWrite($"knowsSignal {item.Key}:{item.Value}"); + } + + gameSave.knownSignals = message.KnownSignals; + PlayerData.SaveCurrentGame(); DebugLog.DebugWrite($"inEye:{message.InEye}"); diff --git a/QSB/SaveSync/Events/GameStateMessage.cs b/QSB/SaveSync/Events/GameStateMessage.cs index 030f9339..bb986919 100644 --- a/QSB/SaveSync/Events/GameStateMessage.cs +++ b/QSB/SaveSync/Events/GameStateMessage.cs @@ -2,6 +2,7 @@ using QSB.Utility; using QuantumUNET.Transport; using System; +using System.Collections.Generic; namespace QSB.SaveSync.Events { @@ -11,6 +12,7 @@ namespace QSB.SaveSync.Events public bool InEye { get; set; } public int LoopCount { get; set; } public bool[] KnownFrequencies { get; set; } + public Dictionary KnownSignals { get; set; } = new(); public override void Deserialize(QNetworkReader reader) { @@ -33,6 +35,16 @@ namespace QSB.SaveSync.Events { KnownFrequencies[i] = reader.ReadBoolean(); } + + // Known signals + var signalsLength = reader.ReadInt32(); + KnownSignals.Clear(); + for (var i = 0; i < signalsLength; i++) + { + var key = reader.ReadInt32(); + var value = reader.ReadBoolean(); + KnownSignals.Add(key, value); + } } public override void Serialize(QNetworkWriter writer) @@ -53,6 +65,14 @@ namespace QSB.SaveSync.Events { writer.Write(item); } + + // Known signals + writer.Write(KnownSignals.Count); + foreach (var item in KnownSignals) + { + writer.Write(item.Key); + writer.Write(item.Value); + } } } } From 543e2d57d5859d84a4218069d44177370e6d0f25 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 5 Dec 2021 20:09:54 -0800 Subject: [PATCH 24/52] form state for real --- QSB/Events/EventNames.cs | 2 +- QSB/Events/QSBEventManager.cs | 2 +- QSB/Player/Events/RequestStateResyncEvent.cs | 8 +++-- ...lapseEvent.cs => TornadoFormStateEvent.cs} | 14 ++++----- QSB/TornadoSync/Patches/TornadoPatches.cs | 6 ++-- QSB/TornadoSync/WorldObjects/QSBTornado.cs | 30 +++++++++++++------ 6 files changed, 38 insertions(+), 24 deletions(-) rename QSB/TornadoSync/Events/{TornadoFormCollapseEvent.cs => TornadoFormStateEvent.cs} (54%) diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index dbf91074..fca3dd4a 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -102,6 +102,6 @@ public const string QSBSatelliteRepaired = nameof(QSBSatelliteRepairTick); public const string QSBAuthorityQueue = nameof(QSBAuthorityQueue); public const string QSBJellyfishRising = nameof(QSBJellyfishRising); - public const string QSBTornadoFormCollapse = nameof(QSBTornadoFormCollapse); + public const string QSBTornadoFormState = nameof(QSBTornadoFormState); } } diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index 536186d3..f751f11e 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -107,7 +107,7 @@ namespace QSB.Events new FragmentDamageEvent(), new FragmentResyncEvent(), new JellyfishRisingEvent(), - new TornadoFormCollapseEvent(), + new TornadoFormStateEvent(), // Conversation/dialogue/exploration new ConversationEvent(), new ConversationStartEndEvent(), diff --git a/QSB/Player/Events/RequestStateResyncEvent.cs b/QSB/Player/Events/RequestStateResyncEvent.cs index ab1f32f1..d0948b84 100644 --- a/QSB/Player/Events/RequestStateResyncEvent.cs +++ b/QSB/Player/Events/RequestStateResyncEvent.cs @@ -1,4 +1,5 @@ -using OWML.Utils; +using System.Linq; +using OWML.Utils; using QSB.CampfireSync.WorldObjects; using QSB.ClientServerStateSync; using QSB.Events; @@ -7,9 +8,9 @@ using QSB.MeteorSync.WorldObjects; using QSB.QuantumSync; using QSB.Tools.TranslatorTool.TranslationSync; using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects; +using QSB.TornadoSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; -using System.Linq; namespace QSB.Player.Events { @@ -83,6 +84,9 @@ namespace QSB.Player.Events QSBWorldSync.GetWorldObjects().ForEach(fragment => QSBEventManager.FireEvent(EventNames.QSBFragmentResync, fragment)); + + QSBWorldSync.GetWorldObjects().ForEach(tornado + => QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado)); } } } diff --git a/QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs b/QSB/TornadoSync/Events/TornadoFormStateEvent.cs similarity index 54% rename from QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs rename to QSB/TornadoSync/Events/TornadoFormStateEvent.cs index c5b16d81..6e5c9c21 100644 --- a/QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs +++ b/QSB/TornadoSync/Events/TornadoFormStateEvent.cs @@ -5,28 +5,28 @@ using QSB.WorldSync.Events; namespace QSB.TornadoSync.Events { - public class TornadoFormCollapseEvent : QSBEvent + public class TornadoFormStateEvent : QSBEvent { public override bool RequireWorldObjectsReady => true; public override void SetupListener() - => GlobalMessenger.AddListener(EventNames.QSBJellyfishRising, Handler); + => GlobalMessenger.AddListener(EventNames.QSBTornadoFormState, Handler); public override void CloseListener() - => GlobalMessenger.RemoveListener(EventNames.QSBJellyfishRising, Handler); + => GlobalMessenger.RemoveListener(EventNames.QSBTornadoFormState, Handler); - private void Handler(QSBTornado qsbTornado, bool formCollapse) => SendEvent(CreateMessage(qsbTornado, formCollapse)); + private void Handler(QSBTornado qsbTornado) => SendEvent(CreateMessage(qsbTornado)); - private BoolWorldObjectMessage CreateMessage(QSBTornado qsbTornado, bool formCollapse) => new() + private BoolWorldObjectMessage CreateMessage(QSBTornado qsbTornado) => new() { ObjectId = qsbTornado.ObjectId, - State = formCollapse + State = qsbTornado.FormState }; public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message) { var qsbTornado = QSBWorldSync.GetWorldFromId(message.ObjectId); - qsbTornado.FormCollapse(message.State); + qsbTornado.FormState = message.State; } } } diff --git a/QSB/TornadoSync/Patches/TornadoPatches.cs b/QSB/TornadoSync/Patches/TornadoPatches.cs index c2d2e514..ca6ad2f1 100644 --- a/QSB/TornadoSync/Patches/TornadoPatches.cs +++ b/QSB/TornadoSync/Patches/TornadoPatches.cs @@ -1,7 +1,5 @@ using HarmonyLib; -using QSB.AuthoritySync; using QSB.Events; -using QSB.JellyfishSync.WorldObjects; using QSB.Patches; using QSB.TornadoSync.WorldObjects; using QSB.WorldSync; @@ -24,7 +22,7 @@ namespace QSB.TornadoSync.Patches { __instance.StartFormation(); var qsbTornado = QSBWorldSync.GetWorldFromUnity(__instance); - QSBEventManager.FireEvent(EventNames.QSBTornadoFormCollapse, qsbTornado, true); + QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, qsbTornado); return false; } } @@ -64,7 +62,7 @@ namespace QSB.TornadoSync.Patches { __instance.StartCollapse(); var qsbTornado = QSBWorldSync.GetWorldFromUnity(__instance); - QSBEventManager.FireEvent(EventNames.QSBTornadoFormCollapse, qsbTornado, false); + QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, qsbTornado); } return false; diff --git a/QSB/TornadoSync/WorldObjects/QSBTornado.cs b/QSB/TornadoSync/WorldObjects/QSBTornado.cs index 83293199..d51edf72 100644 --- a/QSB/TornadoSync/WorldObjects/QSBTornado.cs +++ b/QSB/TornadoSync/WorldObjects/QSBTornado.cs @@ -11,17 +11,29 @@ namespace QSB.TornadoSync.WorldObjects AttachedObject = attachedObject; } - public void FormCollapse(bool formCollapse) + public bool FormState { - if (formCollapse) + get => AttachedObject._tornadoRoot.activeSelf // forming or formed or collapsing + && !AttachedObject._tornadoCollapsing; // and not collapsing + set { - AttachedObject.StartFormation(); - DebugLog.DebugWrite($"{LogName} form"); - } - else - { - AttachedObject.StartCollapse(); - DebugLog.DebugWrite($"{LogName} collapse"); + if (FormState == value) + { + return; + } + + if (value) + { + AttachedObject._tornadoCollapsing = false; + AttachedObject.StartFormation(); + DebugLog.DebugWrite($"{LogName} form"); + } + else + { + AttachedObject._secondsUntilFormation = 0; + AttachedObject.StartCollapse(); + DebugLog.DebugWrite($"{LogName} collapse"); + } } } } From fbb88b57756622d6748ec5ef6887155c52695085 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 5 Dec 2021 21:30:04 -0800 Subject: [PATCH 25/52] body resyncing --- QSB/Events/EventNames.cs | 1 + QSB/Events/QSBEventManager.cs | 1 + QSB/Player/Events/RequestStateResyncEvent.cs | 5 +- QSB/TornadoSync/Events/BodyResyncEvent.cs | 43 ++++++++++++++++ QSB/TornadoSync/Events/BodyResyncMessage.cs | 38 ++++++++++++++ QSB/TornadoSync/TornadoManager.cs | 53 ++++++-------------- 6 files changed, 101 insertions(+), 40 deletions(-) create mode 100644 QSB/TornadoSync/Events/BodyResyncEvent.cs create mode 100644 QSB/TornadoSync/Events/BodyResyncMessage.cs diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index fca3dd4a..cead5200 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -103,5 +103,6 @@ public const string QSBAuthorityQueue = nameof(QSBAuthorityQueue); public const string QSBJellyfishRising = nameof(QSBJellyfishRising); public const string QSBTornadoFormState = nameof(QSBTornadoFormState); + public const string QSBBodyResync = nameof(QSBBodyResync); } } diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index f751f11e..ac9c2cbf 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -108,6 +108,7 @@ namespace QSB.Events new FragmentResyncEvent(), new JellyfishRisingEvent(), new TornadoFormStateEvent(), + new BodyResyncEvent(), // Conversation/dialogue/exploration new ConversationEvent(), new ConversationStartEndEvent(), diff --git a/QSB/Player/Events/RequestStateResyncEvent.cs b/QSB/Player/Events/RequestStateResyncEvent.cs index d0948b84..e58900d9 100644 --- a/QSB/Player/Events/RequestStateResyncEvent.cs +++ b/QSB/Player/Events/RequestStateResyncEvent.cs @@ -8,7 +8,7 @@ using QSB.MeteorSync.WorldObjects; using QSB.QuantumSync; using QSB.Tools.TranslatorTool.TranslationSync; using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects; -using QSB.TornadoSync.WorldObjects; +using QSB.TornadoSync; using QSB.Utility; using QSB.WorldSync; @@ -85,8 +85,7 @@ namespace QSB.Player.Events QSBWorldSync.GetWorldObjects().ForEach(fragment => QSBEventManager.FireEvent(EventNames.QSBFragmentResync, fragment)); - QSBWorldSync.GetWorldObjects().ForEach(tornado - => QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado)); + TornadoManager.FireResync(); } } } diff --git a/QSB/TornadoSync/Events/BodyResyncEvent.cs b/QSB/TornadoSync/Events/BodyResyncEvent.cs new file mode 100644 index 00000000..4530f708 --- /dev/null +++ b/QSB/TornadoSync/Events/BodyResyncEvent.cs @@ -0,0 +1,43 @@ +using QSB.Events; +using QSB.Syncs; + +namespace QSB.TornadoSync.Events +{ + public class BodyResyncEvent : QSBEvent + { + public override bool RequireWorldObjectsReady => true; + + public override void SetupListener() + => GlobalMessenger.AddListener(EventNames.QSBBodyResync, Handler); + + public override void CloseListener() + => GlobalMessenger.RemoveListener(EventNames.QSBBodyResync, Handler); + + private void Handler(OWRigidbody body, OWRigidbody refBody) => SendEvent(CreateMessage(body, refBody)); + + private BodyResyncMessage CreateMessage(OWRigidbody body, OWRigidbody refBody) + { + var pos = body.GetPosition(); + return new BodyResyncMessage + { + BodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(body), + RefBodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(refBody), + Pos = refBody.transform.EncodePos(pos), + Rot = refBody.transform.EncodeRot(body.GetRotation()), + Vel = refBody.EncodeVel(body.GetVelocity(), pos), + AngVel = refBody.EncodeAngVel(body.GetAngularVelocity()) + }; + } + + public override void OnReceiveRemote(bool isHost, BodyResyncMessage message) + { + var body = CenterOfTheUniverse.s_rigidbodies[message.BodyIndex]; + var refBody = CenterOfTheUniverse.s_rigidbodies[message.RefBodyIndex]; + var pos = refBody.transform.DecodePos(message.Pos); + body.SetPosition(pos); + body.SetRotation(refBody.transform.DecodeRot(message.Rot)); + body.SetVelocity(refBody.DecodeVel(message.Vel, pos)); + body.SetAngularVelocity(refBody.DecodeAngVel(message.AngVel)); + } + } +} diff --git a/QSB/TornadoSync/Events/BodyResyncMessage.cs b/QSB/TornadoSync/Events/BodyResyncMessage.cs new file mode 100644 index 00000000..1789017c --- /dev/null +++ b/QSB/TornadoSync/Events/BodyResyncMessage.cs @@ -0,0 +1,38 @@ +using QSB.Messaging; +using QuantumUNET.Transport; +using UnityEngine; + +namespace QSB.TornadoSync.Events +{ + public class BodyResyncMessage : PlayerMessage + { + public int BodyIndex; + public int RefBodyIndex; + public Vector3 Pos; + public Quaternion Rot; + public Vector3 Vel; + public Vector3 AngVel; + + public override void Deserialize(QNetworkReader reader) + { + base.Deserialize(reader); + BodyIndex = reader.ReadInt32(); + RefBodyIndex = reader.ReadInt32(); + Pos = reader.ReadVector3(); + Rot = reader.ReadQuaternion(); + Vel = reader.ReadVector3(); + AngVel = reader.ReadVector3(); + } + + public override void Serialize(QNetworkWriter writer) + { + base.Serialize(writer); + writer.Write(BodyIndex); + writer.Write(RefBodyIndex); + writer.Write(Pos); + writer.Write(Rot); + writer.Write(Vel); + writer.Write(AngVel); + } + } +} diff --git a/QSB/TornadoSync/TornadoManager.cs b/QSB/TornadoSync/TornadoManager.cs index 9181beb5..65ee69ea 100644 --- a/QSB/TornadoSync/TornadoManager.cs +++ b/QSB/TornadoSync/TornadoManager.cs @@ -1,56 +1,35 @@ -using QSB.TornadoSync.TransformSync; +using QSB.Events; using QSB.TornadoSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; -using QuantumUNET; -using UnityEngine; namespace QSB.TornadoSync { public class TornadoManager : WorldObjectManager { - protected override void RebuildWorldObjects(OWScene scene) - { + protected override void RebuildWorldObjects(OWScene scene) => QSBWorldSync.Init(); - return; - if (!QSBCore.IsHost) - { - return; - } + public static void FireResync() + { + QSBWorldSync.GetWorldObjects().ForEach(tornado + => QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado)); - foreach (var transformSync in QSBWorldSync.GetWorldObjects()) + // cannon + var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); + var gdBody = Locator._giantsDeep.GetOWRigidbody(); + QSBEventManager.FireEvent(EventNames.QSBBodyResync, cannon.GetAttachedOWRigidbody(), gdBody); + foreach (var proxy in cannon._realDebrisSectorProxies) { - QNetworkServer.Destroy(transformSync.gameObject); - } - - // cannon parts - foreach (var cannonPartNames in new[] - { - "OrbitalProbeCannon_Body", - "CannonBarrel_Body", - "CannonMuzzle_Body" - }) - { - var cannonPart = GameObject.Find(cannonPartNames).GetAttachedOWRigidbody(); - var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); - transformSync.InitBodyIndexes(cannonPart, Locator._giantsDeep.GetOWRigidbody()); - transformSync.gameObject.SpawnWithServerAuthority(); + QSBEventManager.FireEvent(EventNames.QSBBodyResync, + proxy.transform.root.GetAttachedOWRigidbody(), gdBody); } + QSBEventManager.FireEvent(EventNames.QSBBodyResync, cannon._probeBody, gdBody); // islands - foreach (var islandNames in new[] + foreach (var island in QSBWorldSync.GetUnityObjects()) { - "GabbroIsland_Body", - "StatueIsland_Body", - "ConstructionYardIsland_Body", - "BrambleIsland_Body" - }) - { - var island = GameObject.Find(islandNames).GetAttachedOWRigidbody(); - var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetComponent(); - transformSync.InitBodyIndexes(island, Locator._giantsDeep.GetOWRigidbody()); - transformSync.gameObject.SpawnWithServerAuthority(); + QSBEventManager.FireEvent(EventNames.QSBBodyResync, island._islandBody, gdBody); } } } From 8c7d0a98af6f5b559edd920373b09e64e0a5ed91 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 5 Dec 2021 23:09:08 -0800 Subject: [PATCH 26/52] sync _fakeDebrisBodies as well, why not --- QSB/TornadoSync/TornadoManager.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/QSB/TornadoSync/TornadoManager.cs b/QSB/TornadoSync/TornadoManager.cs index 65ee69ea..fc620e54 100644 --- a/QSB/TornadoSync/TornadoManager.cs +++ b/QSB/TornadoSync/TornadoManager.cs @@ -15,14 +15,22 @@ namespace QSB.TornadoSync QSBWorldSync.GetWorldObjects().ForEach(tornado => QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado)); + var gdBody = Locator._giantsDeep.GetOWRigidbody(); // cannon var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); - var gdBody = Locator._giantsDeep.GetOWRigidbody(); QSBEventManager.FireEvent(EventNames.QSBBodyResync, cannon.GetAttachedOWRigidbody(), gdBody); - foreach (var proxy in cannon._realDebrisSectorProxies) + foreach (var fake in cannon._fakeDebrisBodies) + { + if (fake) + { + QSBEventManager.FireEvent(EventNames.QSBBodyResync, + fake.GetAttachedOWRigidbody(), gdBody); + } + } + foreach (var real in cannon._realDebrisSectorProxies) { QSBEventManager.FireEvent(EventNames.QSBBodyResync, - proxy.transform.root.GetAttachedOWRigidbody(), gdBody); + real.transform.root.GetAttachedOWRigidbody(), gdBody); } QSBEventManager.FireEvent(EventNames.QSBBodyResync, cannon._probeBody, gdBody); From 3bae78b24a000764db9bb178ad34fd802ecec2ac Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 6 Dec 2021 01:53:06 -0800 Subject: [PATCH 27/52] log-o remove-o --- QSB/TornadoSync/WorldObjects/QSBTornado.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/QSB/TornadoSync/WorldObjects/QSBTornado.cs b/QSB/TornadoSync/WorldObjects/QSBTornado.cs index d51edf72..4295be74 100644 --- a/QSB/TornadoSync/WorldObjects/QSBTornado.cs +++ b/QSB/TornadoSync/WorldObjects/QSBTornado.cs @@ -1,5 +1,4 @@ -using QSB.Utility; -using QSB.WorldSync; +using QSB.WorldSync; namespace QSB.TornadoSync.WorldObjects { @@ -26,13 +25,11 @@ namespace QSB.TornadoSync.WorldObjects { AttachedObject._tornadoCollapsing = false; AttachedObject.StartFormation(); - DebugLog.DebugWrite($"{LogName} form"); } else { AttachedObject._secondsUntilFormation = 0; AttachedObject.StartCollapse(); - DebugLog.DebugWrite($"{LogName} collapse"); } } } From 4978ece2ffe15490d4d62986788f36d4b23b08b9 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 6 Dec 2021 03:09:23 -0800 Subject: [PATCH 28/52] go back to using transform syncs. it just gets too desynced without it --- QSB/Events/EventNames.cs | 1 - QSB/Events/QSBEventManager.cs | 1 - QSB/Player/Events/RequestStateResyncEvent.cs | 4 +- QSB/TornadoSync/Events/BodyResyncEvent.cs | 43 ------------------ QSB/TornadoSync/Events/BodyResyncMessage.cs | 38 ---------------- QSB/TornadoSync/TornadoManager.cs | 45 ++++++++++--------- .../TransformSync/OccasionalTransformSync.cs | 20 +-------- 7 files changed, 30 insertions(+), 122 deletions(-) delete mode 100644 QSB/TornadoSync/Events/BodyResyncEvent.cs delete mode 100644 QSB/TornadoSync/Events/BodyResyncMessage.cs diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index cead5200..fca3dd4a 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -103,6 +103,5 @@ public const string QSBAuthorityQueue = nameof(QSBAuthorityQueue); public const string QSBJellyfishRising = nameof(QSBJellyfishRising); public const string QSBTornadoFormState = nameof(QSBTornadoFormState); - public const string QSBBodyResync = nameof(QSBBodyResync); } } diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index 92fd5133..39485157 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -108,7 +108,6 @@ namespace QSB.Events new FragmentResyncEvent(), new JellyfishRisingEvent(), new TornadoFormStateEvent(), - new BodyResyncEvent(), // Conversation/dialogue/exploration new ConversationEvent(), new ConversationStartEndEvent(), diff --git a/QSB/Player/Events/RequestStateResyncEvent.cs b/QSB/Player/Events/RequestStateResyncEvent.cs index 88e7adba..5b7eced6 100644 --- a/QSB/Player/Events/RequestStateResyncEvent.cs +++ b/QSB/Player/Events/RequestStateResyncEvent.cs @@ -9,6 +9,7 @@ using QSB.QuantumSync; using QSB.Tools.TranslatorTool.TranslationSync; using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects; using QSB.TornadoSync; +using QSB.TornadoSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; @@ -96,7 +97,8 @@ namespace QSB.Player.Events QSBWorldSync.GetWorldObjects().ForEach(fragment => QSBEventManager.FireEvent(EventNames.QSBFragmentResync, fragment)); - TornadoManager.FireResync(); + QSBWorldSync.GetWorldObjects().ForEach(tornado + => QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado)); } } } diff --git a/QSB/TornadoSync/Events/BodyResyncEvent.cs b/QSB/TornadoSync/Events/BodyResyncEvent.cs deleted file mode 100644 index 4530f708..00000000 --- a/QSB/TornadoSync/Events/BodyResyncEvent.cs +++ /dev/null @@ -1,43 +0,0 @@ -using QSB.Events; -using QSB.Syncs; - -namespace QSB.TornadoSync.Events -{ - public class BodyResyncEvent : QSBEvent - { - public override bool RequireWorldObjectsReady => true; - - public override void SetupListener() - => GlobalMessenger.AddListener(EventNames.QSBBodyResync, Handler); - - public override void CloseListener() - => GlobalMessenger.RemoveListener(EventNames.QSBBodyResync, Handler); - - private void Handler(OWRigidbody body, OWRigidbody refBody) => SendEvent(CreateMessage(body, refBody)); - - private BodyResyncMessage CreateMessage(OWRigidbody body, OWRigidbody refBody) - { - var pos = body.GetPosition(); - return new BodyResyncMessage - { - BodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(body), - RefBodyIndex = CenterOfTheUniverse.s_rigidbodies.IndexOf(refBody), - Pos = refBody.transform.EncodePos(pos), - Rot = refBody.transform.EncodeRot(body.GetRotation()), - Vel = refBody.EncodeVel(body.GetVelocity(), pos), - AngVel = refBody.EncodeAngVel(body.GetAngularVelocity()) - }; - } - - public override void OnReceiveRemote(bool isHost, BodyResyncMessage message) - { - var body = CenterOfTheUniverse.s_rigidbodies[message.BodyIndex]; - var refBody = CenterOfTheUniverse.s_rigidbodies[message.RefBodyIndex]; - var pos = refBody.transform.DecodePos(message.Pos); - body.SetPosition(pos); - body.SetRotation(refBody.transform.DecodeRot(message.Rot)); - body.SetVelocity(refBody.DecodeVel(message.Vel, pos)); - body.SetAngularVelocity(refBody.DecodeAngVel(message.AngVel)); - } - } -} diff --git a/QSB/TornadoSync/Events/BodyResyncMessage.cs b/QSB/TornadoSync/Events/BodyResyncMessage.cs deleted file mode 100644 index 1789017c..00000000 --- a/QSB/TornadoSync/Events/BodyResyncMessage.cs +++ /dev/null @@ -1,38 +0,0 @@ -using QSB.Messaging; -using QuantumUNET.Transport; -using UnityEngine; - -namespace QSB.TornadoSync.Events -{ - public class BodyResyncMessage : PlayerMessage - { - public int BodyIndex; - public int RefBodyIndex; - public Vector3 Pos; - public Quaternion Rot; - public Vector3 Vel; - public Vector3 AngVel; - - public override void Deserialize(QNetworkReader reader) - { - base.Deserialize(reader); - BodyIndex = reader.ReadInt32(); - RefBodyIndex = reader.ReadInt32(); - Pos = reader.ReadVector3(); - Rot = reader.ReadQuaternion(); - Vel = reader.ReadVector3(); - AngVel = reader.ReadVector3(); - } - - public override void Serialize(QNetworkWriter writer) - { - base.Serialize(writer); - writer.Write(BodyIndex); - writer.Write(RefBodyIndex); - writer.Write(Pos); - writer.Write(Rot); - writer.Write(Vel); - writer.Write(AngVel); - } - } -} diff --git a/QSB/TornadoSync/TornadoManager.cs b/QSB/TornadoSync/TornadoManager.cs index fc620e54..e07ec13d 100644 --- a/QSB/TornadoSync/TornadoManager.cs +++ b/QSB/TornadoSync/TornadoManager.cs @@ -1,44 +1,49 @@ -using QSB.Events; +using QSB.TornadoSync.TransformSync; using QSB.TornadoSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; +using QuantumUNET; namespace QSB.TornadoSync { public class TornadoManager : WorldObjectManager { - protected override void RebuildWorldObjects(OWScene scene) => + protected override void RebuildWorldObjects(OWScene scene) + { QSBWorldSync.Init(); - public static void FireResync() - { - QSBWorldSync.GetWorldObjects().ForEach(tornado - => QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado)); + if (!QSBCore.IsHost) + { + return; + } + + foreach (var transformSync in QSBWorldSync.GetUnityObjects()) + { + QNetworkServer.Destroy(transformSync.gameObject); + } var gdBody = Locator._giantsDeep.GetOWRigidbody(); // cannon var cannon = Locator._orbitalProbeCannon.GetRequiredComponent(); - QSBEventManager.FireEvent(EventNames.QSBBodyResync, cannon.GetAttachedOWRigidbody(), gdBody); - foreach (var fake in cannon._fakeDebrisBodies) + SpawnOccasional(cannon.GetAttachedOWRigidbody(), gdBody); + foreach (var proxy in cannon._realDebrisSectorProxies) { - if (fake) - { - QSBEventManager.FireEvent(EventNames.QSBBodyResync, - fake.GetAttachedOWRigidbody(), gdBody); - } + SpawnOccasional(proxy.transform.root.GetAttachedOWRigidbody(), gdBody); } - foreach (var real in cannon._realDebrisSectorProxies) - { - QSBEventManager.FireEvent(EventNames.QSBBodyResync, - real.transform.root.GetAttachedOWRigidbody(), gdBody); - } - QSBEventManager.FireEvent(EventNames.QSBBodyResync, cannon._probeBody, gdBody); + SpawnOccasional(cannon._probeBody, gdBody); // islands foreach (var island in QSBWorldSync.GetUnityObjects()) { - QSBEventManager.FireEvent(EventNames.QSBBodyResync, island._islandBody, gdBody); + SpawnOccasional(island._islandBody, gdBody); } } + + private static void SpawnOccasional(OWRigidbody body, OWRigidbody refBody) + { + var transformSync = Instantiate(QSBNetworkManager.Instance.OccasionalPrefab).GetRequiredComponent(); + transformSync.InitBodyIndexes(body, refBody); + transformSync.gameObject.SpawnWithServerAuthority(); + } } } diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index 1d0e3c41..bcb7364b 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -34,12 +34,6 @@ namespace QSB.TornadoSync.TransformSync SetReferenceTransform(CenterOfTheUniverse.s_rigidbodies[_refBodyIndex].transform); _sectors = ((OWRigidbody)AttachedObject).GetComponentsInChildren() .Select(x => x.name).ToArray(); - - // to prevent change in rotation/angvel - if (!HasAuthority && AttachedObject.TryGetComponent(out var align)) - { - align.enabled = false; - } } public override void SerializeTransform(QNetworkWriter writer, bool initialState) @@ -73,7 +67,6 @@ namespace QSB.TornadoSync.TransformSync _shouldUpdate = true; } - /// replacement that handles KinematicRigidbody protected override bool UpdateTransform() { if (HasAuthority) @@ -140,17 +133,8 @@ namespace QSB.TornadoSync.TransformSync } } - if (((OWRigidbody)AttachedObject).RunningKinematicSimulation()) - { - ((OWRigidbody)AttachedObject).SetPosition(positionToSet); - ((OWRigidbody)AttachedObject).SetRotation(rotationToSet); - } - else - { - // does nothing for KinematicRigidbody - ((OWRigidbody)AttachedObject).MoveToPosition(positionToSet); - ((OWRigidbody)AttachedObject).MoveToRotation(rotationToSet); - } + ((OWRigidbody)AttachedObject).SetPosition(positionToSet); + ((OWRigidbody)AttachedObject).SetRotation(rotationToSet); var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); From b638d1cb0d5ce7e326d41f498bf4b7d719e983bc Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Tue, 7 Dec 2021 03:31:53 -0800 Subject: [PATCH 29/52] much more robust moving moving of "children" when resync happens --- .../TransformSync/OccasionalTransformSync.cs | 130 +++++++++++------- 1 file changed, 77 insertions(+), 53 deletions(-) diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index bcb7364b..7a7226c7 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -1,8 +1,10 @@ -using System.Linq; -using QSB.Player; +using System.Collections.Generic; +using System.Linq; +using QSB.Player.TransformSync; +using QSB.ShipSync.TransformSync; using QSB.Syncs; using QSB.Syncs.Unsectored.Rigidbodies; -using QSB.Utility; +using QSB.Tools.ProbeTool.TransformSync; using QSB.WorldSync; using QuantumUNET.Transport; using UnityEngine; @@ -17,8 +19,9 @@ namespace QSB.TornadoSync.TransformSync protected override OWRigidbody GetRigidbody() => CenterOfTheUniverse.s_rigidbodies[_bodyIndex]; private int _bodyIndex = -1; - private string[] _sectors; private int _refBodyIndex = -1; + private Sector[] _sectors; + private OWRigidbody[] _orbs; public void InitBodyIndexes(OWRigidbody body, OWRigidbody refBody) { @@ -32,8 +35,12 @@ namespace QSB.TornadoSync.TransformSync { base.Init(); SetReferenceTransform(CenterOfTheUniverse.s_rigidbodies[_refBodyIndex].transform); - _sectors = ((OWRigidbody)AttachedObject).GetComponentsInChildren() - .Select(x => x.name).ToArray(); + + _sectors = SectorManager.s_sectors + .Where(x => x._attachedOWRigidbody == AttachedObject).ToArray(); + _orbs = QSBWorldSync.OldOrbList + .Where(x => _sectors.Contains(x._sector)) + .Select(x => x._orbBody).ToArray(); } public override void SerializeTransform(QNetworkWriter writer, bool initialState) @@ -82,18 +89,6 @@ namespace QSB.TornadoSync.TransformSync _shouldUpdate = false; - var targetPos = ReferenceTransform.DecodePos(transform.position); - var targetRot = ReferenceTransform.DecodeRot(transform.rotation); - - var positionToSet = targetPos; - var rotationToSet = targetRot; - - if (UseInterpolation) - { - positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos); - rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); - } - var hasMoved = CustomHasMoved( transform.position, _localPrevPosition, @@ -114,47 +109,76 @@ namespace QSB.TornadoSync.TransformSync return true; } - // todo also do this with the ship/probe. oh and orbs. yeah this really sucks - string playerSector = null; - Vector3 playerPos = default; - Quaternion playerRot = default; - Vector3 playerVel = default; - Vector3 playerAngVel = default; - if (_sectors.Length != 0) + if (_sectors.Contains(PlayerTransformSync.LocalInstance?.ReferenceSector?.AttachedObject)) { - playerSector = QSBPlayerManager.LocalPlayer.TransformSync.ReferenceSector.Name; - if (_sectors.Contains(playerSector)) - { - var pos = Locator.GetPlayerBody().GetPosition(); - playerPos = ((OWRigidbody)AttachedObject).transform.EncodePos(pos); - playerRot = ((OWRigidbody)AttachedObject).transform.EncodeRot(Locator.GetPlayerBody().GetRotation()); - playerVel = ((OWRigidbody)AttachedObject).EncodeVel(Locator.GetPlayerBody().GetVelocity(), pos); - playerAngVel = ((OWRigidbody)AttachedObject).EncodeAngVel(Locator.GetPlayerBody().GetAngularVelocity()); - } + QueueMove(Locator._playerBody); + } + if (_sectors.Contains(ShipTransformSync.LocalInstance?.ReferenceSector?.AttachedObject)) + { + QueueMove(Locator._shipBody); + } + if (_sectors.Contains(PlayerProbeSync.LocalInstance?.ReferenceSector?.AttachedObject)) + { + QueueMove(Locator._probe._owRigidbody); + } + foreach (var orb in _orbs) + { + QueueMove(orb); } - ((OWRigidbody)AttachedObject).SetPosition(positionToSet); - ((OWRigidbody)AttachedObject).SetRotation(rotationToSet); + var pos = ReferenceTransform.DecodePos(transform.position); + ((OWRigidbody)AttachedObject).SetPosition(pos); + ((OWRigidbody)AttachedObject).SetRotation(ReferenceTransform.DecodeRot(transform.rotation)); + ((OWRigidbody)AttachedObject).SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, pos)); + ((OWRigidbody)AttachedObject).SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity)); - var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); - var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); - - ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); - ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); - - if (_sectors.Length != 0) - { - if (_sectors.Contains(playerSector)) - { - var pos = ((OWRigidbody)AttachedObject).transform.DecodePos(playerPos); - Locator.GetPlayerBody().SetPosition(pos); - Locator.GetPlayerBody().SetRotation(((OWRigidbody)AttachedObject).transform.DecodeRot(playerRot)); - Locator.GetPlayerBody().SetVelocity(((OWRigidbody)AttachedObject).DecodeVel(playerVel, pos)); - Locator.GetPlayerBody().SetAngularVelocity(((OWRigidbody)AttachedObject).DecodeAngVel(playerAngVel)); - } - } + Move(); return true; } + + + private readonly List _toMove = new(); + + private struct MoveData + { + public OWRigidbody Child; + public Vector3 RelPos; + public Quaternion RelRot; + public Vector3 RelVel; + public Vector3 RelAngVel; + } + + private void QueueMove(OWRigidbody child) + { + if (child.transform.parent != null) + { + // it's parented to AttachedObject or one of its children + return; + } + + var pos = child.GetPosition(); + _toMove.Add(new MoveData + { + Child = child, + RelPos = ((OWRigidbody)AttachedObject).transform.EncodePos(pos), + RelRot = ((OWRigidbody)AttachedObject).transform.EncodeRot(child.GetRotation()), + RelVel = ((OWRigidbody)AttachedObject).EncodeVel(child.GetVelocity(), pos), + RelAngVel = ((OWRigidbody)AttachedObject).EncodeAngVel(child.GetAngularVelocity()) + }); + } + + private void Move() + { + foreach (var data in _toMove) + { + var pos = ((OWRigidbody)AttachedObject).transform.DecodePos(data.RelPos); + data.Child.SetPosition(pos); + data.Child.SetRotation(((OWRigidbody)AttachedObject).transform.DecodeRot(data.RelRot)); + data.Child.SetVelocity(((OWRigidbody)AttachedObject).DecodeVel(data.RelVel, pos)); + data.Child.SetAngularVelocity(((OWRigidbody)AttachedObject).DecodeAngVel(data.RelAngVel)); + } + _toMove.Clear(); + } } } From 4a7cc859fbf8394e205a3c5173381acce0e19764 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 7 Dec 2021 13:35:03 +0000 Subject: [PATCH 30/52] add dlc install check --- QSB/Menus/MenuManager.cs | 5 +++-- QSB/Player/Events/PlayerJoinEvent.cs | 14 ++++++++++++-- QSB/Player/Events/PlayerJoinMessage.cs | 3 +++ QSB/Player/KickReason.cs | 3 ++- QSB/QSBCore.cs | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 18646a82..9ef1054f 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -156,7 +156,7 @@ namespace QSB.Menus { CreateCommonPopups(); - HostButton = MenuApi.PauseMenu_MakeSimpleButton("MULTIPLAYER (HOST)"); + HostButton = MenuApi.PauseMenu_MakeSimpleButton("OPEN TO MULTIPLAYER"); HostButton.onClick.AddListener(Host); DisconnectButton = MenuApi.PauseMenu_MakeSimpleButton("DISCONNECT"); @@ -180,7 +180,7 @@ namespace QSB.Menus { CreateCommonPopups(); - ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("MULTIPLAYER (CONNECT)", _ClientButtonIndex, PopupMenu); + ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("CONNECT TO MULTIPLAYER", _ClientButtonIndex, PopupMenu); DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT", _DisconnectIndex); DisconnectButton.onClick.AddListener(Disconnect); @@ -302,6 +302,7 @@ namespace QSB.Menus KickReason.QSBVersionNotMatching => "Server refused connection as QSB version does not match.", KickReason.GameVersionNotMatching => "Server refused connection as Outer Wilds version does not match.", KickReason.GamePlatformNotMatching => "Server refused connection as Outer Wilds platform does not match. (Steam/Epic)", + KickReason.DLCNotMatching => "Server refused connection as DLC installation state does not match.", KickReason.None => "Kicked from server. No reason given.", _ => $"Kicked from server. KickReason:{reason}", }; diff --git a/QSB/Player/Events/PlayerJoinEvent.cs b/QSB/Player/Events/PlayerJoinEvent.cs index f6f3b239..d0177a15 100644 --- a/QSB/Player/Events/PlayerJoinEvent.cs +++ b/QSB/Player/Events/PlayerJoinEvent.cs @@ -19,7 +19,8 @@ namespace QSB.Player.Events PlayerName = name, QSBVersion = QSBCore.QSBVersion, GameVersion = QSBCore.GameVersion, - Platform = QSBCore.Platform + Platform = QSBCore.Platform, + DlcInstalled = QSBCore.DLCInstalled }; public override void OnReceiveRemote(bool server, PlayerJoinMessage message) @@ -51,6 +52,15 @@ namespace QSB.Player.Events if (server) { DebugLog.ToConsole($"Error - Client {message.PlayerName} connecting with wrong game platform. (Client:{message.Platform}, Server:{QSBCore.Platform})", MessageType.Error); + QSBEventManager.FireEvent(EventNames.QSBPlayerKick, message.AboutId, KickReason.DLCNotMatching); + } + } + + if (message.DlcInstalled != QSBCore.DLCInstalled) + { + if (server) + { + DebugLog.ToConsole($"Error - Client {message.PlayerName} connecting with wrong DLC installation state. (Client:{message.DlcInstalled}, Server:{QSBCore.DLCInstalled})", MessageType.Error); QSBEventManager.FireEvent(EventNames.QSBPlayerKick, message.AboutId, KickReason.GamePlatformNotMatching); } } @@ -58,7 +68,7 @@ namespace QSB.Player.Events var player = QSBPlayerManager.GetPlayer(message.AboutId); player.Name = message.PlayerName; DebugLog.ToAll($"{player.Name} joined!", MessageType.Info); - DebugLog.DebugWrite($"{player.Name} joined. id:{player.PlayerId}, qsbVersion:{message.QSBVersion}, gameVersion:{message.GameVersion}, platform:{message.Platform}", MessageType.Info); + DebugLog.DebugWrite($"{player.Name} joined. id:{player.PlayerId}, qsbVersion:{message.QSBVersion}, gameVersion:{message.GameVersion}, platform:{message.Platform}. dlcInstalled:{message.DlcInstalled}", MessageType.Info); } public override void OnReceiveLocal(bool server, PlayerJoinMessage message) diff --git a/QSB/Player/Events/PlayerJoinMessage.cs b/QSB/Player/Events/PlayerJoinMessage.cs index a07f5f4d..a965cf20 100644 --- a/QSB/Player/Events/PlayerJoinMessage.cs +++ b/QSB/Player/Events/PlayerJoinMessage.cs @@ -9,6 +9,7 @@ namespace QSB.Player.Events public string QSBVersion { get; set; } public string GameVersion { get; set; } public GamePlatform Platform { get; set; } + public bool DlcInstalled { get; set; } public override void Deserialize(QNetworkReader reader) { @@ -17,6 +18,7 @@ namespace QSB.Player.Events QSBVersion = reader.ReadString(); GameVersion = reader.ReadString(); Platform = (GamePlatform)reader.ReadInt32(); + DlcInstalled = reader.ReadBoolean(); } public override void Serialize(QNetworkWriter writer) @@ -26,6 +28,7 @@ namespace QSB.Player.Events writer.Write(QSBVersion); writer.Write(GameVersion); writer.Write((int)Platform); + writer.Write(DlcInstalled); } } } \ No newline at end of file diff --git a/QSB/Player/KickReason.cs b/QSB/Player/KickReason.cs index d02b4159..5b44b066 100644 --- a/QSB/Player/KickReason.cs +++ b/QSB/Player/KickReason.cs @@ -5,6 +5,7 @@ None, QSBVersionNotMatching, GameVersionNotMatching, - GamePlatformNotMatching + GamePlatformNotMatching, + DLCNotMatching } } diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 746cddda..1de470f5 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -79,6 +79,7 @@ namespace QSB public static GamePlatform Platform => typeof(Achievements).Assembly.GetTypes().Any(x => x.Name == "EpicEntitlementRetriever") ? GamePlatform.Epic : GamePlatform.Steam; + public static bool DLCInstalled => EntitlementsManager.IsDlcOwned() == EntitlementsManager.AsyncOwnershipStatus.Owned; public static IMenuAPI MenuApi { get; private set; } private static DebugSettings DebugSettings { get; set; } = new DebugSettings(); From 5600bd0d2f19520bdd56f1ea5ae912f86ce4bab4 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 7 Dec 2021 15:47:46 +0000 Subject: [PATCH 31/52] update for dev changes --- QSB/Events/QSBEvent.cs | 5 ----- QSB/SaveSync/Events/GameStateEvent.cs | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/QSB/Events/QSBEvent.cs b/QSB/Events/QSBEvent.cs index d593bdbb..c2df5ffa 100644 --- a/QSB/Events/QSBEvent.cs +++ b/QSB/Events/QSBEvent.cs @@ -85,11 +85,6 @@ namespace QSB.Events return; } - if (message.SendToSpecific && message.ToId != LocalPlayerId) - { - return; - } - if (PlayerTransformSync.LocalInstance == null || PlayerTransformSync.LocalInstance.GetComponent() == null) { DebugLog.ToConsole($"Warning - Tried to handle message of type <{GetType().Name}> before localplayer was established.", MessageType.Warning); diff --git a/QSB/SaveSync/Events/GameStateEvent.cs b/QSB/SaveSync/Events/GameStateEvent.cs index 98ce0427..9b2b1990 100644 --- a/QSB/SaveSync/Events/GameStateEvent.cs +++ b/QSB/SaveSync/Events/GameStateEvent.cs @@ -17,7 +17,7 @@ namespace QSB.SaveSync.Events private GameStateMessage CreateMessage(uint toId) => new() { AboutId = LocalPlayerId, - ToId = toId, + ForId = toId, InSolarSystem = QSBSceneManager.CurrentScene == OWScene.SolarSystem, InEye = QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse, LoopCount = StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount, From 554c2bb2dd40776f34433f50e6073bff0b0b1651 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 7 Dec 2021 15:56:08 +0000 Subject: [PATCH 32/52] cleanup --- QSB/Anglerfish/Patches/AnglerPatches.cs | 78 +++++++++---------- QSB/Animation/Player/CrouchSync.cs | 4 +- .../Player/Events/AnimationTriggerEvent.cs | 1 - .../Player/Events/ChangeAnimTypeEvent.cs | 1 - .../Player/Events/PlayerSuitEvent.cs | 1 - QSB/AuthoritySync/AuthorityManager.cs | 8 +- QSB/AuthoritySync/AuthorityQueueEvent.cs | 1 - QSB/ElevatorSync/WorldObjects/QSBElevator.cs | 2 +- QSB/Events/QSBEvent.cs | 4 +- QSB/Events/QSBEventManager.cs | 4 +- .../TransformSync/JellyfishTransformSync.cs | 4 +- QSB/Messaging/MessageHandler.cs | 2 +- QSB/Messaging/PlayerMessage.cs | 2 +- QSB/OrbSync/Events/OrbUserEvent.cs | 4 +- QSB/Patches/QSBPatchManager.cs | 8 +- QSB/QSBCore.cs | 6 +- QSB/QSBNetworkManager.cs | 6 +- .../Events/MoonStateChangeEvent.cs | 1 - .../QSBMultiStateQuantumObject.cs | 6 +- .../WorldObjects/QSBQuantumObject.cs | 2 +- QSB/SaveSync/Events/GameStateMessage.cs | 1 - QSB/SaveSync/Events/RequestGameStateEvent.cs | 6 -- QSB/ShipSync/Patches/ShipPatches.cs | 2 +- .../Transforms/UnsectoredTransformSync.cs | 3 +- QSB/Utility/DebugGUI.cs | 3 - QSB/Utility/VariableSync/VariableReference.cs | 2 +- QSB/WorldSync/QSBWorldSync.cs | 8 +- QSB/WorldSync/WorldObjectManager.cs | 6 +- QuantumUNET/QNetworkScene.cs | 2 +- 29 files changed, 79 insertions(+), 99 deletions(-) diff --git a/QSB/Anglerfish/Patches/AnglerPatches.cs b/QSB/Anglerfish/Patches/AnglerPatches.cs index 205acec2..df477667 100644 --- a/QSB/Anglerfish/Patches/AnglerPatches.cs +++ b/QSB/Anglerfish/Patches/AnglerPatches.cs @@ -189,54 +189,54 @@ namespace QSB.Anglerfish.Patches __instance.ApplyDrag(1f); return false; case AnglerfishController.AnglerState.Investigating: - { - var targetPos = __instance._brambleBody.transform.TransformPoint(__instance._localDisturbancePos); - __instance.RotateTowardsTarget(targetPos, __instance._turnSpeed, __instance._turnSpeed); - if (!__instance._turningInPlace) { - __instance.MoveTowardsTarget(targetPos, __instance._investigateSpeed, __instance._acceleration); - return false; + var targetPos = __instance._brambleBody.transform.TransformPoint(__instance._localDisturbancePos); + __instance.RotateTowardsTarget(targetPos, __instance._turnSpeed, __instance._turnSpeed); + if (!__instance._turningInPlace) + { + __instance.MoveTowardsTarget(targetPos, __instance._investigateSpeed, __instance._acceleration); + return false; + } + break; } - break; - } case AnglerfishController.AnglerState.Chasing: - { - var velocity = qsbAngler.TargetVelocity; - var normalized = velocity.normalized; - var from = __instance._anglerBody.GetPosition() + __instance.transform.TransformDirection(__instance._mouthOffset) - qsbAngler.TargetTransform.position; - var magnitude = velocity.magnitude; - var num = Vector3.Angle(from, normalized); - var num2 = magnitude * 2f; - var d = num2; - if (num < 90f) { - var magnitude2 = from.magnitude; - var num3 = magnitude2 * Mathf.Sin(num * 0.017453292f); - var num4 = magnitude2 * Mathf.Cos(num * 0.017453292f); - var magnitude3 = __instance._anglerBody.GetVelocity().magnitude; - var num5 = num4 / Mathf.Max(magnitude, 0.0001f); - var num6 = num3 / Mathf.Max(magnitude3, 0.0001f); - var num7 = num5 / num6; - if (num7 <= 1f) + var velocity = qsbAngler.TargetVelocity; + var normalized = velocity.normalized; + var from = __instance._anglerBody.GetPosition() + __instance.transform.TransformDirection(__instance._mouthOffset) - qsbAngler.TargetTransform.position; + var magnitude = velocity.magnitude; + var num = Vector3.Angle(from, normalized); + var num2 = magnitude * 2f; + var d = num2; + if (num < 90f) { - var t = Mathf.Clamp01(num7); - d = Mathf.Lerp(num2, num4, t); + var magnitude2 = from.magnitude; + var num3 = magnitude2 * Mathf.Sin(num * 0.017453292f); + var num4 = magnitude2 * Mathf.Cos(num * 0.017453292f); + var magnitude3 = __instance._anglerBody.GetVelocity().magnitude; + var num5 = num4 / Mathf.Max(magnitude, 0.0001f); + var num6 = num3 / Mathf.Max(magnitude3, 0.0001f); + var num7 = num5 / num6; + if (num7 <= 1f) + { + var t = Mathf.Clamp01(num7); + d = Mathf.Lerp(num2, num4, t); + } + else + { + var num8 = Mathf.InverseLerp(1f, 4f, num7); + d = Mathf.Lerp(num4, 0f, num8 * num8); + } } - else + __instance._targetPos = qsbAngler.TargetTransform.position + normalized * d; + __instance.RotateTowardsTarget(__instance._targetPos, __instance._turnSpeed, __instance._quickTurnSpeed); + if (!__instance._turningInPlace) { - var num8 = Mathf.InverseLerp(1f, 4f, num7); - d = Mathf.Lerp(num4, 0f, num8 * num8); + __instance.MoveTowardsTarget(__instance._targetPos, __instance._chaseSpeed, __instance._acceleration); + return false; } + break; } - __instance._targetPos = qsbAngler.TargetTransform.position + normalized * d; - __instance.RotateTowardsTarget(__instance._targetPos, __instance._turnSpeed, __instance._quickTurnSpeed); - if (!__instance._turningInPlace) - { - __instance.MoveTowardsTarget(__instance._targetPos, __instance._chaseSpeed, __instance._acceleration); - return false; - } - break; - } case AnglerfishController.AnglerState.Consuming: __instance.ApplyDrag(1f); return false; diff --git a/QSB/Animation/Player/CrouchSync.cs b/QSB/Animation/Player/CrouchSync.cs index dabcf039..faee97d3 100644 --- a/QSB/Animation/Player/CrouchSync.cs +++ b/QSB/Animation/Player/CrouchSync.cs @@ -1,8 +1,6 @@ -using QSB.Utility; -using QSB.Utility.VariableSync; +using QSB.Utility.VariableSync; using QuantumUNET; using UnityEngine; -using UnityEngine.Networking; namespace QSB.Animation.Player { diff --git a/QSB/Animation/Player/Events/AnimationTriggerEvent.cs b/QSB/Animation/Player/Events/AnimationTriggerEvent.cs index ddc85992..951311ba 100644 --- a/QSB/Animation/Player/Events/AnimationTriggerEvent.cs +++ b/QSB/Animation/Player/Events/AnimationTriggerEvent.cs @@ -1,6 +1,5 @@ using QSB.Events; using QSB.Player; -using QSB.WorldSync; namespace QSB.Animation.Player.Events { diff --git a/QSB/Animation/Player/Events/ChangeAnimTypeEvent.cs b/QSB/Animation/Player/Events/ChangeAnimTypeEvent.cs index d20ae6df..3fbf03fe 100644 --- a/QSB/Animation/Player/Events/ChangeAnimTypeEvent.cs +++ b/QSB/Animation/Player/Events/ChangeAnimTypeEvent.cs @@ -2,7 +2,6 @@ using QSB.Instruments; using QSB.Messaging; using QSB.Player; -using QSB.WorldSync; namespace QSB.Animation.Player.Events { diff --git a/QSB/Animation/Player/Events/PlayerSuitEvent.cs b/QSB/Animation/Player/Events/PlayerSuitEvent.cs index 1c67c151..329adb0a 100644 --- a/QSB/Animation/Player/Events/PlayerSuitEvent.cs +++ b/QSB/Animation/Player/Events/PlayerSuitEvent.cs @@ -1,7 +1,6 @@ using QSB.Events; using QSB.Messaging; using QSB.Player; -using QSB.WorldSync; namespace QSB.Animation.Player.Events { diff --git a/QSB/AuthoritySync/AuthorityManager.cs b/QSB/AuthoritySync/AuthorityManager.cs index 1b93fbde..b2b3ce25 100644 --- a/QSB/AuthoritySync/AuthorityManager.cs +++ b/QSB/AuthoritySync/AuthorityManager.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using System.Linq; -using QSB.Events; +using QSB.Events; using QSB.Utility; using QuantumUNET; using QuantumUNET.Components; +using System.Collections.Generic; +using System.Linq; namespace QSB.AuthoritySync { @@ -72,7 +72,7 @@ namespace QSB.AuthoritySync } // DebugLog.DebugWrite($"{identity.NetId}:{identity.gameObject.name} - " - // + $"set authority to {id}"); + // + $"set authority to {id}"); } #endregion diff --git a/QSB/AuthoritySync/AuthorityQueueEvent.cs b/QSB/AuthoritySync/AuthorityQueueEvent.cs index d949dc6f..5d51bbaf 100644 --- a/QSB/AuthoritySync/AuthorityQueueEvent.cs +++ b/QSB/AuthoritySync/AuthorityQueueEvent.cs @@ -1,5 +1,4 @@ using QSB.Events; -using QSB.WorldSync; using QuantumUNET.Components; namespace QSB.AuthoritySync diff --git a/QSB/ElevatorSync/WorldObjects/QSBElevator.cs b/QSB/ElevatorSync/WorldObjects/QSBElevator.cs index f322af7a..e62e73dc 100644 --- a/QSB/ElevatorSync/WorldObjects/QSBElevator.cs +++ b/QSB/ElevatorSync/WorldObjects/QSBElevator.cs @@ -40,7 +40,7 @@ namespace QSB.ElevatorSync.WorldObjects if (_elevatorTrigger.IsTrackingObject(Locator.GetPlayerDetector())) { SetDirection(isGoingUp); - + AttachedObject._attachPoint.AttachPlayer(); if (Locator.GetPlayerSuit().IsWearingSuit(true) && Locator.GetPlayerSuit().IsTrainingSuit()) diff --git a/QSB/Events/QSBEvent.cs b/QSB/Events/QSBEvent.cs index c2df5ffa..8a59d500 100644 --- a/QSB/Events/QSBEvent.cs +++ b/QSB/Events/QSBEvent.cs @@ -1,5 +1,4 @@ -using System; -using OWML.Common; +using OWML.Common; using QSB.ClientServerStateSync; using QSB.Messaging; using QSB.Player; @@ -8,6 +7,7 @@ using QSB.Player.TransformSync; using QSB.Utility; using QSB.WorldSync; using QuantumUNET.Components; +using System; namespace QSB.Events { diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index 75fc5b78..17b2cf47 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using OWML.Common; +using OWML.Common; using QSB.Anglerfish.Events; using QSB.Animation.NPC.Events; using QSB.Animation.Player.Events; @@ -36,6 +35,7 @@ using QSB.Tools.TranslatorTool.TranslationSync.Events; using QSB.Utility; using QSB.Utility.Events; using QSB.ZeroGCaveSync.Events; +using System.Collections.Generic; namespace QSB.Events { diff --git a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs index d343fea2..f14aa1cd 100644 --- a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs +++ b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; -using QSB.JellyfishSync.WorldObjects; +using QSB.JellyfishSync.WorldObjects; using QSB.Syncs; using QSB.Syncs.Unsectored.Rigidbodies; using QSB.Utility; using QSB.WorldSync; using QuantumUNET.Transport; +using System.Collections.Generic; using UnityEngine; namespace QSB.JellyfishSync.TransformSync diff --git a/QSB/Messaging/MessageHandler.cs b/QSB/Messaging/MessageHandler.cs index 545f6607..496a8f16 100644 --- a/QSB/Messaging/MessageHandler.cs +++ b/QSB/Messaging/MessageHandler.cs @@ -16,7 +16,7 @@ namespace QSB.Messaging public MessageHandler(int msgType) { - + _eventType = (short)(msgType + QMsgType.Highest + 1); if (_eventType >= short.MaxValue) { diff --git a/QSB/Messaging/PlayerMessage.cs b/QSB/Messaging/PlayerMessage.cs index 4c7e595f..b14eb553 100644 --- a/QSB/Messaging/PlayerMessage.cs +++ b/QSB/Messaging/PlayerMessage.cs @@ -17,7 +17,7 @@ namespace QSB.Messaging /// /// If true, only send this message to the host of the current session - /// /// (OnReceiveLocal/Remote is not called on any other client) + /// (OnReceiveLocal/Remote is not called on any other client) /// public bool OnlySendToHost { get; set; } diff --git a/QSB/OrbSync/Events/OrbUserEvent.cs b/QSB/OrbSync/Events/OrbUserEvent.cs index 5770d85f..3d7ea18a 100644 --- a/QSB/OrbSync/Events/OrbUserEvent.cs +++ b/QSB/OrbSync/Events/OrbUserEvent.cs @@ -1,11 +1,11 @@ -using System.Linq; -using OWML.Common; +using OWML.Common; using QSB.AuthoritySync; using QSB.Events; using QSB.OrbSync.TransformSync; using QSB.Utility; using QSB.WorldSync; using QSB.WorldSync.Events; +using System.Linq; namespace QSB.OrbSync.Events { diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 9712fdb5..f336f6c9 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using HarmonyLib; +using HarmonyLib; using OWML.Common; using QSB.Anglerfish.Patches; using QSB.Animation.NPC.Patches; @@ -31,6 +28,9 @@ using QSB.Tools.SignalscopeTool.FrequencySync.Patches; using QSB.Tools.TranslatorTool.TranslationSync.Patches; using QSB.Utility; using QSB.ZeroGCaveSync.Patches; +using System; +using System.Collections.Generic; +using System.Linq; namespace QSB.Patches { diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 1de470f5..4a7e70f8 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -1,5 +1,4 @@ -using System.Linq; -using OWML.Common; +using OWML.Common; using OWML.ModHelper; using OWML.ModHelper.Input; using QSB.Anglerfish; @@ -18,7 +17,6 @@ using QSB.MeteorSync; using QSB.OrbSync; using QSB.Patches; using QSB.Player; -using QSB.Player.TransformSync; using QSB.PoolSync; using QSB.QuantumSync; using QSB.RespawnSync; @@ -30,10 +28,10 @@ using QSB.TimeSync; using QSB.Tools.ProbeLauncherTool; using QSB.Tools.TranslatorTool.TranslationSync; using QSB.Utility; -using QSB.WorldSync; using QSB.ZeroGCaveSync; using QuantumUNET; using QuantumUNET.Components; +using System.Linq; using UnityEngine; /* diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 6abaab80..22650e78 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using OWML.Common; +using OWML.Common; using OWML.Utils; using QSB.AuthoritySync; using QSB.ClientServerStateSync; @@ -17,6 +15,8 @@ using QSB.Utility; using QSB.WorldSync; using QuantumUNET; using QuantumUNET.Components; +using System; +using System.Linq; using UnityEngine; using UnityEngine.Networking; diff --git a/QSB/QuantumSync/Events/MoonStateChangeEvent.cs b/QSB/QuantumSync/Events/MoonStateChangeEvent.cs index b4332b6b..6f2c82a3 100644 --- a/QSB/QuantumSync/Events/MoonStateChangeEvent.cs +++ b/QSB/QuantumSync/Events/MoonStateChangeEvent.cs @@ -2,7 +2,6 @@ using QSB.Events; using System.Linq; using System.Reflection; -using QSB.WorldSync; using UnityEngine; namespace QSB.QuantumSync.Events diff --git a/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs index a35c019c..5bb22d7e 100644 --- a/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBMultiStateQuantumObject.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using System.Linq; -using QSB.Utility; +using QSB.Utility; using QSB.WorldSync; +using System.Collections.Generic; +using System.Linq; using UnityEngine.UI; namespace QSB.QuantumSync.WorldObjects diff --git a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs index 8005135a..87c42343 100644 --- a/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs +++ b/QSB/QuantumSync/WorldObjects/QSBQuantumObject.cs @@ -112,7 +112,7 @@ namespace QSB.QuantumSync.WorldObjects } } - public List GetVisibilityTrackers() + public List GetVisibilityTrackers() => AttachedObject?._visibilityTrackers == null ? new() : AttachedObject._visibilityTrackers.Select(x => (ShapeVisibilityTracker)x).ToList(); diff --git a/QSB/SaveSync/Events/GameStateMessage.cs b/QSB/SaveSync/Events/GameStateMessage.cs index bb986919..1315df1d 100644 --- a/QSB/SaveSync/Events/GameStateMessage.cs +++ b/QSB/SaveSync/Events/GameStateMessage.cs @@ -1,5 +1,4 @@ using QSB.Messaging; -using QSB.Utility; using QuantumUNET.Transport; using System; using System.Collections.Generic; diff --git a/QSB/SaveSync/Events/RequestGameStateEvent.cs b/QSB/SaveSync/Events/RequestGameStateEvent.cs index d732f96d..94f78312 100644 --- a/QSB/SaveSync/Events/RequestGameStateEvent.cs +++ b/QSB/SaveSync/Events/RequestGameStateEvent.cs @@ -1,11 +1,5 @@ using QSB.Events; using QSB.Messaging; -using QSB.Utility; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace QSB.SaveSync.Events { diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index 9d786168..663dc505 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -3,8 +3,8 @@ using OWML.Utils; using QSB.Events; using QSB.Patches; using QSB.Utility; -using System; using QSB.WorldSync; +using System; using UnityEngine; namespace QSB.ShipSync.Patches diff --git a/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs b/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs index 867952c9..36709e64 100644 --- a/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs +++ b/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs @@ -1,5 +1,4 @@ -using OWML.Common; -using QSB.Utility; +using QSB.Utility; using QSB.WorldSync; using QuantumUNET.Transport; using UnityEngine; diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index 525c6df5..16cb8656 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -1,9 +1,7 @@ using QSB.ClientServerStateSync; using QSB.OrbSync.TransformSync; -using QSB.OrbSync.WorldObjects; using QSB.Player; using QSB.QuantumSync; -using QSB.QuantumSync.WorldObjects; using QSB.ShipSync; using QSB.ShipSync.TransformSync; using QSB.ShipSync.WorldObjects; @@ -11,7 +9,6 @@ using QSB.TimeSync; using QSB.WorldSync; using System.Linq; using UnityEngine; -using UnityEngine.Assertions.Must; namespace QSB.Utility { diff --git a/QSB/Utility/VariableSync/VariableReference.cs b/QSB/Utility/VariableSync/VariableReference.cs index f2343bb5..d57f8fbc 100644 --- a/QSB/Utility/VariableSync/VariableReference.cs +++ b/QSB/Utility/VariableSync/VariableReference.cs @@ -26,7 +26,7 @@ namespace QSB.Utility.VariableSync { DebugLog.ToConsole($"Warning - Getter is null!", OWML.Common.MessageType.Warning); } - + return default; } } diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 5342543f..13348a41 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OWML.Common; +using OWML.Common; using QSB.OrbSync.TransformSync; using QSB.OrbSync.WorldObjects; using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; using UnityEngine; namespace QSB.WorldSync diff --git a/QSB/WorldSync/WorldObjectManager.cs b/QSB/WorldSync/WorldObjectManager.cs index e5c081b7..2c0d1f99 100644 --- a/QSB/WorldSync/WorldObjectManager.cs +++ b/QSB/WorldSync/WorldObjectManager.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using OWML.Common; +using OWML.Common; using QSB.Player; using QSB.Utility; +using System; +using System.Collections.Generic; using UnityEngine; namespace QSB.WorldSync diff --git a/QuantumUNET/QNetworkScene.cs b/QuantumUNET/QNetworkScene.cs index 102eed16..032bf292 100644 --- a/QuantumUNET/QNetworkScene.cs +++ b/QuantumUNET/QNetworkScene.cs @@ -1,6 +1,6 @@ using QuantumUNET.Components; -using System.Collections.Generic; using QuantumUNET.Messages; +using System.Collections.Generic; using UnityEngine; namespace QuantumUNET From 757af4a998f5fc17077919113e2aa47c967ab58c Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Tue, 7 Dec 2021 13:19:58 -0800 Subject: [PATCH 33/52] whoops --- QSB/Anglerfish/Patches/AnglerPatches.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/QSB/Anglerfish/Patches/AnglerPatches.cs b/QSB/Anglerfish/Patches/AnglerPatches.cs index 205acec2..756ae566 100644 --- a/QSB/Anglerfish/Patches/AnglerPatches.cs +++ b/QSB/Anglerfish/Patches/AnglerPatches.cs @@ -22,6 +22,7 @@ namespace QSB.Anglerfish.Patches if (qsbAngler.TargetTransform != null) { __result = qsbAngler.TargetTransform.position; + return false; } __result = __instance._brambleBody.transform.TransformPoint(__instance._localDisturbancePos); From 478628bdb8a4f5f1ebe37f2fa429b7453215446f Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 8 Dec 2021 10:48:11 +0000 Subject: [PATCH 34/52] pain. pain. pain. --- QSB/Menus/MenuManager.cs | 93 ++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 9ef1054f..96aa24a7 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -15,18 +15,23 @@ namespace QSB.Menus public static MenuManager Instance; private IMenuAPI MenuApi => QSBCore.MenuApi; - private PopupMenu PopupMenu; + + private PopupMenu IPPopup; private PopupMenu InfoPopup; private bool _addedPauseLock; + + // Pause menu only + private Button HostButton; + private GameObject QuitButton; + private GameObject DisconnectButton; + private PopupMenu DisconnectPopup; private StringBuilder _nowLoadingSB; protected Text _loadingText; - private Button HostButton; - private GameObject ClientButton; - private Button DisconnectButton; - + // title screen only private GameObject ResumeGameButton; private GameObject NewGameButton; + private GameObject ClientButton; private const int _ClientButtonIndex = 2; private const int _DisconnectIndex = 3; @@ -67,7 +72,9 @@ namespace QSB.Menus private void Update() { - if ((LoadManager.GetLoadingScene() == OWScene.SolarSystem || LoadManager.GetLoadingScene() == OWScene.EyeOfTheUniverse) && _loadingText != null) + if (QSBCore.IsInMultiplayer + && (LoadManager.GetLoadingScene() == OWScene.SolarSystem || LoadManager.GetLoadingScene() == OWScene.EyeOfTheUniverse) + && _loadingText != null) { var num = LoadManager.GetAsyncLoadProgress(); num = num < 0.1f @@ -82,7 +89,6 @@ namespace QSB.Menus public void JoinGame(bool inEye, bool inSolarSystem) { - DebugLog.DebugWrite($"Join game ineye:{inEye} inSolarSystem:{inSolarSystem}"); if (inEye) { LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, true, LoadManager.FadeType.ToBlack, 1f, false); @@ -131,8 +137,8 @@ namespace QSB.Menus private void CreateCommonPopups() { - PopupMenu = MenuApi.MakeInputFieldPopup("IP Address", "IP Address", "Connect", "Cancel"); - PopupMenu.OnPopupConfirm += Connect; + IPPopup = MenuApi.MakeInputFieldPopup("IP Address", "IP Address", "Connect", "Cancel"); + IPPopup.OnPopupConfirm += Connect; InfoPopup = MenuApi.MakeInfoPopup("", ""); InfoPopup.OnDeactivateMenu += OnCloseInfoPopup; @@ -145,6 +151,7 @@ namespace QSB.Menus { if (button == null) { + DebugLog.DebugWrite($"Warning - Tried to set button to {active}, but it was null.", OWML.Common.MessageType.Warning); return; } @@ -159,40 +166,51 @@ namespace QSB.Menus HostButton = MenuApi.PauseMenu_MakeSimpleButton("OPEN TO MULTIPLAYER"); HostButton.onClick.AddListener(Host); - DisconnectButton = MenuApi.PauseMenu_MakeSimpleButton("DISCONNECT"); - DisconnectButton.onClick.AddListener(Disconnect); + DisconnectPopup = MenuApi.MakeTwoChoicePopup("Are you sure you want to disconnect?\r\nThis will send you back to the main menu.", "YES", "NO"); + DisconnectPopup.OnPopupConfirm += Disconnect; + + DisconnectButton = MenuApi.PauseMenu_MakeMenuOpenButton("DISCONNECT", DisconnectPopup); + + QuitButton = Resources.FindObjectsOfTypeAll().First(x => x.name == "Button-ExitToMainMenu").gameObject; if (QSBCore.IsInMultiplayer) { SetButtonActive(HostButton, false); SetButtonActive(DisconnectButton, true); + SetButtonActive(QuitButton, false); } else { SetButtonActive(HostButton, true); SetButtonActive(DisconnectButton, false); + SetButtonActive(QuitButton, true); } - OnConnected(); + var text = QSBCore.IsHost + ? "STOP HOSTING" + : "DISCONNECT"; + DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent().text = text; + + var popupText = QSBCore.IsHost + ? "Are you sure you want to stop hosting?\r\nThis will disconnect all clients and send everyone back to the main menu." + : "Are you sure you want to disconnect?\r\nThis will send you back to the main menu."; + DisconnectPopup._labelText.text = popupText; } private void MakeTitleMenus() { CreateCommonPopups(); - ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("CONNECT TO MULTIPLAYER", _ClientButtonIndex, PopupMenu); + ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("CONNECT TO MULTIPLAYER", _ClientButtonIndex, IPPopup); - DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT", _DisconnectIndex); - DisconnectButton.onClick.AddListener(Disconnect); - _loadingText = DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent(); + _loadingText = ClientButton.transform.GetChild(0).GetChild(1).GetComponent(); ResumeGameButton = GameObject.Find("MainMenuLayoutGroup/Button-ResumeGame"); NewGameButton = GameObject.Find("MainMenuLayoutGroup/Button-NewGame"); if (QSBCore.IsInMultiplayer) { - ClientButton.SetActive(false); - SetButtonActive(DisconnectButton, true); + SetButtonActive(ClientButton, false); if (QSBCore.IsHost) { @@ -207,13 +225,11 @@ namespace QSB.Menus } else { - SetButtonActive(DisconnectButton, false); + SetButtonActive(ClientButton, true); SetButtonActive(ResumeGameButton, StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount > 1); SetButtonActive(NewGameButton, true); } - OnConnected(); - if (QSBCore.SkipTitleScreen) { Application.runInBackground = true; @@ -238,34 +254,42 @@ namespace QSB.Menus { QSBNetworkManager.Instance.StopHost(); SetButtonActive(DisconnectButton.gameObject, false); - SetButtonActive(ClientButton, true); - SetButtonActive(HostButton, true); + + Locator.GetSceneMenuManager().pauseMenu._pauseMenu.EnableMenu(false); + Locator.GetSceneMenuManager().pauseMenu._isPaused = false; + + OWInput.RestorePreviousInputs(); + + LoadManager.LoadScene(OWScene.TitleScreen, LoadManager.FadeType.ToBlack, 2f, true); } private void Host() { - DebugLog.DebugWrite($"Host"); - if (QSBNetworkManager.Instance.StartHost() != null) { SetButtonActive(DisconnectButton, true); - SetButtonActive(ClientButton, false); SetButtonActive(HostButton, false); } else { OpenInfoPopup($"Failed to start server.", "OK"); } + + var text = QSBCore.IsHost + ? "STOP HOSTING" + : "DISCONNECT"; + DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent().text = text; + + var popupText = QSBCore.IsHost + ? "Are you sure you want to stop hosting?\r\nThis will disconnect all clients and send everyone back to the main menu." + : "Are you sure you want to disconnect?\r\nThis will send you back to the main menu."; + DisconnectPopup._labelText.text = popupText; } private void Connect() { - QSBNetworkManager.Instance.networkAddress = string.Concat((PopupMenu as PopupInputMenu).GetInputText().Where(c => !char.IsWhiteSpace(c))); + QSBNetworkManager.Instance.networkAddress = string.Concat((IPPopup as PopupInputMenu).GetInputText().Where(c => !char.IsWhiteSpace(c))); QSBNetworkManager.Instance.StartClient(); - DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent().text = "CONNECTING... (STOP)"; - - SetButtonActive(DisconnectButton, true); - SetButtonActive(ClientButton, false); if (QSBSceneManager.CurrentScene == OWScene.TitleScreen) { @@ -276,13 +300,6 @@ namespace QSB.Menus private void OnConnected() { - DebugLog.DebugWrite($"ON CONNECTED"); - - var text = QSBCore.IsHost - ? "STOP HOSTING" - : "DISCONNECT"; - DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent().text = text; - if (QSBCore.IsHost || !QSBCore.IsInMultiplayer) { return; From 557941399f41ebcd2fed4e56662c101cf1e958a0 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 8 Dec 2021 10:57:00 +0000 Subject: [PATCH 35/52] quit back to main menu on error/disconnect/kick --- QSB/Menus/MenuManager.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 96aa24a7..73308e3d 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -133,6 +133,11 @@ namespace QSB.Menus OWTime.Unpause(OWTime.PauseType.System); OWInput.RestorePreviousInputs(); + + if (QSBSceneManager.IsInUniverse) + { + LoadManager.LoadScene(OWScene.TitleScreen, LoadManager.FadeType.ToBlack, 2f, true); + } } private void CreateCommonPopups() @@ -307,7 +312,6 @@ namespace QSB.Menus QSBCore.UnityEvents.RunWhen(() => QSBEventManager.Ready && PlayerTransformSync.LocalInstance != null, () => { - DebugLog.DebugWrite($"requesting game details"); QSBEventManager.FireEvent(EventNames.QSBRequestGameDetails); }); } From 849bea21ce83abceb4eaf634ad0667555aa30ea7 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 8 Dec 2021 10:59:36 +0000 Subject: [PATCH 36/52] hide quit button --- QSB/Menus/MenuManager.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 73308e3d..b34e525a 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -301,6 +301,11 @@ namespace QSB.Menus SetButtonActive(ResumeGameButton, false); SetButtonActive(NewGameButton, false); } + + if (QSBSceneManager.IsInUniverse) + { + SetButtonActive(QuitButton, false); + } } private void OnConnected() @@ -329,9 +334,10 @@ namespace QSB.Menus }; OpenInfoPopup(text, "OK"); - DisconnectButton.gameObject.SetActive(false); - ClientButton.SetActive(true); - HostButton?.gameObject.SetActive(true); + SetButtonActive(DisconnectButton, false); + SetButtonActive(ClientButton, true); + SetButtonActive(HostButton, true); + SetButtonActive(QuitButton, true); } private void OnDisconnected(NetworkError error) @@ -350,6 +356,7 @@ namespace QSB.Menus SetButtonActive(DisconnectButton, false); SetButtonActive(ClientButton, true); + SetButtonActive(QuitButton, true); SetButtonActive(HostButton, true); SetButtonActive(ResumeGameButton, StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount > 1); SetButtonActive(NewGameButton, true); @@ -374,6 +381,7 @@ namespace QSB.Menus SetButtonActive(HostButton, true); SetButtonActive(ResumeGameButton, StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount > 1); SetButtonActive(NewGameButton, true); + SetButtonActive(QuitButton, true); break; default: text = $"Internal QNet client error!\n\nNetworkError:{error}"; From 0e0c51e37100ee53e7a85be91999632f7f3773b3 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 8 Dec 2021 11:01:47 +0000 Subject: [PATCH 37/52] remove logs --- QSB/SaveSync/Events/GameStateEvent.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/QSB/SaveSync/Events/GameStateEvent.cs b/QSB/SaveSync/Events/GameStateEvent.cs index 9b2b1990..903da031 100644 --- a/QSB/SaveSync/Events/GameStateEvent.cs +++ b/QSB/SaveSync/Events/GameStateEvent.cs @@ -28,26 +28,12 @@ namespace QSB.SaveSync.Events public override void OnReceiveRemote(bool isHost, GameStateMessage message) { var gameSave = StandaloneProfileManager.SharedInstance.currentProfileGameSave; - DebugLog.DebugWrite($"loopcount:{message.LoopCount}"); gameSave.loopCount = message.LoopCount; - for (var i = 0; i < message.KnownFrequencies.Length; i++) - { - DebugLog.DebugWrite($"knowsFrequency{i}:{message.KnownFrequencies[i]}"); - } - gameSave.knownFrequencies = message.KnownFrequencies; - - foreach (var item in message.KnownSignals) - { - DebugLog.DebugWrite($"knowsSignal {item.Key}:{item.Value}"); - } - gameSave.knownSignals = message.KnownSignals; PlayerData.SaveCurrentGame(); - DebugLog.DebugWrite($"inEye:{message.InEye}"); - DebugLog.DebugWrite($"inSolarSystem:{message.InSolarSystem}"); if (message.InEye != (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) || message.InSolarSystem != (QSBSceneManager.CurrentScene == OWScene.SolarSystem)) { From e163a2a69f529a993afa74b2e344758bce865d17 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 10 Dec 2021 14:54:51 +0000 Subject: [PATCH 38/52] some error catchers --- QSB/Animation/Player/AnimationSync.cs | 43 ++++++++++++++++++++------- QSB/Player/PlayerInfo.cs | 27 +++++++++++++++-- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/QSB/Animation/Player/AnimationSync.cs b/QSB/Animation/Player/AnimationSync.cs index d6ef7908..abd85265 100644 --- a/QSB/Animation/Player/AnimationSync.cs +++ b/QSB/Animation/Player/AnimationSync.cs @@ -223,25 +223,48 @@ namespace QSB.Animation.Player break; } - InvisibleAnimator.runtimeAnimatorController = controller; - VisibleAnimator.runtimeAnimatorController = controller; + if (InvisibleAnimator == null) + { + DebugLog.ToConsole($"Error - InvisibleAnimator is null. ({PlayerId})", MessageType.Error); + } + else + { + InvisibleAnimator.runtimeAnimatorController = controller; + } + + if (VisibleAnimator == null) + { + DebugLog.ToConsole($"Error - VisibleAnimator is null. ({PlayerId})", MessageType.Error); + } + else + { + VisibleAnimator.runtimeAnimatorController = controller; + } + if (type is not AnimationType.PlayerSuited and not AnimationType.PlayerUnsuited) { - VisibleAnimator.SetTrigger("Playing"); - InvisibleAnimator.SetTrigger("Playing"); + VisibleAnimator?.SetTrigger("Playing"); + InvisibleAnimator?.SetTrigger("Playing"); } else { // Avoids "jumping" when exiting instrument and putting on suit - VisibleAnimator.SetTrigger("Grounded"); - InvisibleAnimator.SetTrigger("Grounded"); + VisibleAnimator?.SetTrigger("Grounded"); + InvisibleAnimator?.SetTrigger("Grounded"); } - NetworkAnimator.animator = InvisibleAnimator; // Probably not needed. - Mirror.RebuildFloatParams(); - for (var i = 0; i < InvisibleAnimator.parameterCount; i++) + if (NetworkAnimator == null) { - NetworkAnimator.SetParameterAutoSend(i, true); + DebugLog.ToConsole($"Error - NetworkAnimator is null. ({PlayerId})", MessageType.Error); + } + else + { + NetworkAnimator.animator = InvisibleAnimator; // Probably not needed. + Mirror.RebuildFloatParams(); + for (var i = 0; i < InvisibleAnimator?.parameterCount; i++) + { + NetworkAnimator.SetParameterAutoSend(i, true); + } } } } diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 1b51d7a8..9507350d 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -225,7 +225,30 @@ namespace QSB.Player QSBEventManager.FireEvent(EventNames.QSBPlayerInformation); } - private QSBTool GetToolByType(ToolType type) => CameraBody?.GetComponentsInChildren() - .FirstOrDefault(x => x.Type == type); + private QSBTool GetToolByType(ToolType type) + { + if (CameraBody == null) + { + DebugLog.ToConsole($"Warning - Tried to GetToolByType({type}) on player {PlayerId}, but CameraBody was null.", MessageType.Warning); + return null; + } + + var tools = CameraBody.GetComponentsInChildren(); + + if (tools == null || tools.Length == 0) + { + DebugLog.ToConsole($"Warning - Couldn't find any QSBTools for player {PlayerId}.", MessageType.Warning); + return null; + } + + var tool = tools.FirstOrDefault(x => x.Type == type); + + if (tool == null) + { + DebugLog.ToConsole($"Warning - No tool found on player {PlayerId} matching ToolType {type}.", MessageType.Warning); + } + + return tool; + } } } \ No newline at end of file From 2ab553069e4b17a276575aa0002ef389c35a980b Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 10 Dec 2021 21:12:01 +0000 Subject: [PATCH 39/52] idk what this breaks????? --- QSB/Syncs/SyncBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 1a25d7d8..8b7a4aee 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -73,7 +73,7 @@ namespace QSB.Syncs public PlayerInfo Player => QSBPlayerManager.GetPlayer(PlayerId); private bool _baseIsReady => QSBPlayerManager.PlayerExists(PlayerId) && Player != null - // && Player.IsReady + && Player.IsReady && NetId.Value != uint.MaxValue && NetId.Value != 0U && WorldObjectManager.AllObjectsAdded; From f6114f1f4f51507b13bf80423e4af56ccc5d8815 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 10 Dec 2021 21:12:11 +0000 Subject: [PATCH 40/52] remove sector sync error log --- QSB/SectorSync/SectorSync.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/QSB/SectorSync/SectorSync.cs b/QSB/SectorSync/SectorSync.cs index ed1f9895..09ca9ec9 100644 --- a/QSB/SectorSync/SectorSync.cs +++ b/QSB/SectorSync/SectorSync.cs @@ -127,7 +127,6 @@ namespace QSB.SectorSync if (_sectorDetector == null || _attachedOWRigidbody == null || _targetType == TargetType.None) { IsReady = false; - DebugLog.ToConsole($"Error - SectorSync is no longer ready. Detector Null : {_sectorDetector == null}, OWRigidbody Null : {_attachedOWRigidbody == null}, None TargetType : {_targetType == TargetType.None}", MessageType.Error); return null; } From f502e4ee73a235bd843c4fa7c6437c63708d7e80 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 10 Dec 2021 21:12:27 +0000 Subject: [PATCH 41/52] dont update objects from states if player is not ready --- QSB/Player/QSBPlayerManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 35fb95fb..542deca6 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -89,7 +89,7 @@ namespace QSB.Player player.SignalscopeEquipped = message.SignalscopeEquipped; player.TranslatorEquipped = message.TranslatorEquipped; player.ProbeActive = message.ProbeActive; - if (LocalPlayer.IsReady) + if (LocalPlayer.IsReady && player.IsReady) { player.UpdateObjectsFromStates(); } From 916056c6057e0771b93257299ae42e1a498286ba Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 10 Dec 2021 22:13:39 +0000 Subject: [PATCH 42/52] aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --- .../TransformSync/AnglerTransformSync.cs | 1 + QSB/Animation/Player/AnimationSync.cs | 42 ++++++++++++++++--- .../Player/Events/AnimationTriggerEvent.cs | 5 +++ .../TransformSync/JellyfishTransformSync.cs | 1 + .../TransformSync/NomaiOrbTransformSync.cs | 2 + QSB/Player/Events/PlayerJoinEvent.cs | 1 + QSB/Player/Events/PlayerReadyEvent.cs | 4 +- QSB/Player/PlayerInfo.cs | 6 +-- QSB/Player/QSBPlayerManager.cs | 1 + .../TransformSync/PlayerTransformSync.cs | 23 ++++++++-- .../TransformSync/ShipTransformSync.cs | 2 + QSB/Syncs/SyncBase.cs | 26 +++++++++--- QSB/TimeSync/WakeUpSync.cs | 6 +++ .../TransformSync/PlayerProbeSync.cs | 1 + 14 files changed, 100 insertions(+), 21 deletions(-) diff --git a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs index 3df7db00..01d874e0 100644 --- a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs +++ b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs @@ -11,6 +11,7 @@ namespace QSB.Anglerfish.TransformSync { public override bool IsReady => WorldObjectManager.AllObjectsAdded; public override bool UseInterpolation => false; + public override bool IsPlayerObject => false; private QSBAngler _qsbAngler; private static readonly List _instances = new(); diff --git a/QSB/Animation/Player/AnimationSync.cs b/QSB/Animation/Player/AnimationSync.cs index abd85265..fd12e7b9 100644 --- a/QSB/Animation/Player/AnimationSync.cs +++ b/QSB/Animation/Player/AnimationSync.cs @@ -187,19 +187,45 @@ namespace QSB.Animation.Player DebugLog.ToConsole($"Error - Suited controller is null. ({PlayerId})", MessageType.Error); } + if (_unsuitedGraphics == null) + { + DebugLog.ToConsole($"Warning - _unsuitedGraphics is null! ({PlayerId})", MessageType.Warning); + } + + if (_suitedGraphics == null) + { + DebugLog.ToConsole($"Warning - _suitedGraphics is null! ({PlayerId})", MessageType.Warning); + } + RuntimeAnimatorController controller = default; switch (type) { case AnimationType.PlayerSuited: controller = _suitedAnimController; - _unsuitedGraphics?.SetActive(false); - _suitedGraphics?.SetActive(true); + if (_unsuitedGraphics != null) + { + _unsuitedGraphics?.SetActive(false); + } + + if (_suitedGraphics != null) + { + _suitedGraphics?.SetActive(true); + } + break; case AnimationType.PlayerUnsuited: controller = _unsuitedAnimController; - _unsuitedGraphics?.SetActive(true); - _suitedGraphics?.SetActive(false); + if (_unsuitedGraphics != null) + { + _unsuitedGraphics?.SetActive(true); + } + + if (_suitedGraphics != null) + { + _suitedGraphics?.SetActive(false); + } + break; case AnimationType.Chert: @@ -257,11 +283,15 @@ namespace QSB.Animation.Player { DebugLog.ToConsole($"Error - NetworkAnimator is null. ({PlayerId})", MessageType.Error); } - else + else if (Mirror == null) + { + DebugLog.ToConsole($"Error - Mirror is null. ({PlayerId})", MessageType.Error); + } + else if (InvisibleAnimator != null) { NetworkAnimator.animator = InvisibleAnimator; // Probably not needed. Mirror.RebuildFloatParams(); - for (var i = 0; i < InvisibleAnimator?.parameterCount; i++) + for (var i = 0; i < InvisibleAnimator.parameterCount; i++) { NetworkAnimator.SetParameterAutoSend(i, true); } diff --git a/QSB/Animation/Player/Events/AnimationTriggerEvent.cs b/QSB/Animation/Player/Events/AnimationTriggerEvent.cs index 951311ba..4aac7220 100644 --- a/QSB/Animation/Player/Events/AnimationTriggerEvent.cs +++ b/QSB/Animation/Player/Events/AnimationTriggerEvent.cs @@ -27,6 +27,11 @@ namespace QSB.Animation.Player.Events return; } + if (animationSync.VisibleAnimator == null) + { + return; + } + animationSync.VisibleAnimator.SetTrigger(message.Name); } } diff --git a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs index f14aa1cd..ca493cee 100644 --- a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs +++ b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs @@ -13,6 +13,7 @@ namespace QSB.JellyfishSync.TransformSync { public override bool IsReady => WorldObjectManager.AllObjectsAdded; public override bool UseInterpolation => false; + public override bool IsPlayerObject => false; private QSBJellyfish _qsbJellyfish; private static readonly List _instances = new(); diff --git a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs index aacb5eb8..600e6a8c 100644 --- a/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs +++ b/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs @@ -11,6 +11,8 @@ namespace QSB.OrbSync.TransformSync { public static List OrbTransformSyncs = new(); + public override bool IsPlayerObject => false; + private int _index => OrbTransformSyncs.IndexOf(this); public override void OnStartClient() => OrbTransformSyncs.Add(this); diff --git a/QSB/Player/Events/PlayerJoinEvent.cs b/QSB/Player/Events/PlayerJoinEvent.cs index d0177a15..56d68060 100644 --- a/QSB/Player/Events/PlayerJoinEvent.cs +++ b/QSB/Player/Events/PlayerJoinEvent.cs @@ -80,6 +80,7 @@ namespace QSB.Player.Events if (QSBSceneManager.IsInUniverse) { + DebugLog.DebugWrite($"Joined! SENDING READY = TRUE"); QSBPlayerManager.LocalPlayer.IsReady = true; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, true); } diff --git a/QSB/Player/Events/PlayerReadyEvent.cs b/QSB/Player/Events/PlayerReadyEvent.cs index 8da97c2c..9cbfc962 100644 --- a/QSB/Player/Events/PlayerReadyEvent.cs +++ b/QSB/Player/Events/PlayerReadyEvent.cs @@ -34,14 +34,14 @@ namespace QSB.Player.Events private static void HandleServer(ToggleMessage message) { - DebugLog.DebugWrite($"[SERVER] Get ready event from {message.FromId}", MessageType.Success); + DebugLog.DebugWrite($"[SERVER] Get ready event from {message.FromId} (ready = {message.ToggleValue})", MessageType.Success); QSBPlayerManager.GetPlayer(message.AboutId).IsReady = message.ToggleValue; QSBEventManager.FireEvent(EventNames.QSBPlayerInformation); } private void HandleClient(ToggleMessage message) { - DebugLog.DebugWrite($"[CLIENT] Get ready event from {message.FromId}", MessageType.Success); + DebugLog.DebugWrite($"[CLIENT] Get ready event from {message.FromId} (ready = {message.ToggleValue})", MessageType.Success); if (!QSBPlayerManager.PlayerExists(message.FromId)) { DebugLog.ToConsole( diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 9507350d..b37444f4 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -142,7 +142,7 @@ namespace QSB.Player return null; } - return CameraBody.transform.Find("ProbeLauncher").GetComponent(); + return CameraBody?.transform.Find("ProbeLauncher").GetComponent(); } } @@ -170,7 +170,7 @@ namespace QSB.Player return null; } - return CameraBody.transform.Find("Signalscope").GetComponent(); + return CameraBody?.transform.Find("Signalscope").GetComponent(); } } @@ -184,7 +184,7 @@ namespace QSB.Player return null; } - return CameraBody.transform.Find("NomaiTranslatorProp").GetComponent(); + return CameraBody?.transform.Find("NomaiTranslatorProp").GetComponent(); } } diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 542deca6..c34272e9 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -91,6 +91,7 @@ namespace QSB.Player player.ProbeActive = message.ProbeActive; if (LocalPlayer.IsReady && player.IsReady) { + DebugLog.DebugWrite($"{player.PlayerId} UpdateObjectsFromStates player.IsReady:{player.IsReady}, camerabody null :{player.CameraBody == null}"); player.UpdateObjectsFromStates(); } diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index e82cfac7..6f670f44 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -17,6 +17,8 @@ namespace QSB.Player.TransformSync { static PlayerTransformSync() => AnimControllerPatch.Init(); + public override bool IsPlayerObject => true; + private Transform _visibleCameraRoot; private Transform _networkCameraRoot => gameObject.transform.GetChild(0); @@ -58,13 +60,16 @@ namespace QSB.Player.TransformSync base.OnSceneLoaded(oldScene, newScene, isInUniverse); } - if (isInUniverse) + if (isInUniverse && !_isInitialized) { - Player.IsReady = true; - QSBEventManager.FireEvent(EventNames.QSBPlayerReady, true); + DebugLog.DebugWrite($"Is in universe, but is not initialized! SENDING READY = FALSE"); + Player.IsReady = false; + QSBEventManager.FireEvent(EventNames.QSBPlayerReady, false); } - else + + if (!isInUniverse) { + DebugLog.DebugWrite($"Is not in universe! SENDING READY = FALSE"); Player.IsReady = false; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, false); } @@ -72,6 +77,16 @@ namespace QSB.Player.TransformSync base.OnSceneLoaded(oldScene, newScene, isInUniverse); } + protected override void Init() + { + base.Init(); + + DebugLog.DebugWrite($"Init! SENDING READY = TRUE"); + + Player.IsReady = true; + QSBEventManager.FireEvent(EventNames.QSBPlayerReady, true); + } + protected override void OnDestroy() { // TODO : Maybe move this to a leave event...? Would ensure everything could finish up before removing the player diff --git a/QSB/ShipSync/TransformSync/ShipTransformSync.cs b/QSB/ShipSync/TransformSync/ShipTransformSync.cs index d5f910ed..9921365d 100644 --- a/QSB/ShipSync/TransformSync/ShipTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipTransformSync.cs @@ -10,6 +10,8 @@ namespace QSB.ShipSync.TransformSync { public static ShipTransformSync LocalInstance { get; private set; } + public override bool IsPlayerObject => false; + private const int ForcePositionAfterUpdates = 50; private int _updateCount; diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 8b7a4aee..291651b0 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -58,6 +58,11 @@ namespace QSB.Syncs { get { + if (!IsPlayerObject) + { + return uint.MaxValue; + } + if (NetIdentity == null) { DebugLog.ToConsole($"Error - Trying to get PlayerId with null NetIdentity! Type:{GetType().Name} GrandType:{GetType().GetType().Name}", MessageType.Error); @@ -71,9 +76,10 @@ namespace QSB.Syncs } public PlayerInfo Player => QSBPlayerManager.GetPlayer(PlayerId); - private bool _baseIsReady => QSBPlayerManager.PlayerExists(PlayerId) - && Player != null - && Player.IsReady + private bool _baseIsReady + => (!IsPlayerObject || QSBPlayerManager.PlayerExists(PlayerId)) + && (!IsPlayerObject || Player != null) + && (!IsPlayerObject || Player.IsReady) && NetId.Value != uint.MaxValue && NetId.Value != 0U && WorldObjectManager.AllObjectsAdded; @@ -82,6 +88,7 @@ namespace QSB.Syncs public abstract bool IgnoreDisabledAttachedObject { get; } public abstract bool IgnoreNullReferenceTransform { get; } public abstract bool ShouldReparentAttachedObject { get; } + public abstract bool IsPlayerObject { get; } public Component AttachedObject { get; set; } public Transform ReferenceTransform { get; set; } @@ -99,16 +106,23 @@ namespace QSB.Syncs public virtual void Start() { - var lowestBound = QSBWorldSync.GetUnityObjects() + if (IsPlayerObject) + { + var lowestBound = QSBWorldSync.GetUnityObjects() .Where(x => x.NetId.Value <= NetId.Value).OrderBy(x => x.NetId.Value).Last(); - NetIdentity.SetRootIdentity(lowestBound.NetIdentity); + NetIdentity.SetRootIdentity(lowestBound.NetIdentity); + } DontDestroyOnLoad(gameObject); QSBSceneManager.OnSceneLoaded += OnSceneLoaded; if (Player == null) { - DebugLog.ToConsole($"Error - Player in start of {LogName} was null!", MessageType.Error); + if (IsPlayerObject) + { + DebugLog.ToConsole($"Error - Player in start of {LogName} was null!", MessageType.Error); + } + return; } diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index c3ff6069..db66dc42 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -153,6 +153,12 @@ namespace QSB.TimeSync var myTime = Time.timeSinceLevelLoad; var diff = myTime - _serverTime; + if (ServerStateManager.Instance.GetServerState() is not ServerState.InSolarSystem and not ServerState.InEye) + { + DebugLog.ToConsole($"nah serverstate:{ServerStateManager.Instance.GetServerState()} (Target:{_serverTime} Current:{Time.timeSinceLevelLoad})"); + return; + } + if (diff > PauseOrFastForwardThreshold) { StartPausing(PauseReason.TooFarAhead); diff --git a/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs b/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs index 7eb63bd3..d2ea936b 100644 --- a/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs +++ b/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs @@ -15,6 +15,7 @@ namespace QSB.Tools.ProbeTool.TransformSync protected override float DistanceLeeway => 10f; public override bool UseInterpolation => true; public override bool IgnoreDisabledAttachedObject => true; + public override bool IsPlayerObject => true; public static PlayerProbeSync LocalInstance { get; private set; } From 7c1f9ac3a60e0ecc045846f571f4310e5b632765 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 11 Dec 2021 10:50:17 +0000 Subject: [PATCH 43/52] me me stupid --- QSB/Player/QSBPlayerManager.cs | 2 +- QSB/Syncs/SyncBase.cs | 93 ++++++++++++----------------- QSB/WorldSync/WorldObjectManager.cs | 12 +--- 3 files changed, 41 insertions(+), 66 deletions(-) diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index c34272e9..927804f8 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -179,7 +179,7 @@ namespace QSB.Player return null; } - return playerList.Where(x => x.IsReady).OrderBy(x => Vector3.Distance(x.Body.transform.position, worldPoint)).FirstOrDefault(); + return playerList.Where(x => x.IsReady && x.Body != null).OrderBy(x => Vector3.Distance(x.Body.transform.position, worldPoint)).FirstOrDefault(); } public static IEnumerable> GetPlayerCarryItems() diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 291651b0..5409c977 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -18,28 +18,6 @@ namespace QSB.Syncs public abstract class SyncBase : QNetworkTransform { - private static readonly Dictionary> _storedTransformSyncs = new(); - - public static T GetPlayers(PlayerInfo player) - where T : SyncBase - { - var dictOfOwnedSyncs = _storedTransformSyncs[player.PlayerId]; - var wantedSync = dictOfOwnedSyncs[typeof(T)]; - if (wantedSync == default) - { - DebugLog.ToConsole($"Error - _storedTransformSyncs does not contain type:{typeof(T)} under player {player.PlayerId}. Attempting to find manually...", MessageType.Error); - var allSyncs = QSBWorldSync.GetUnityObjects(); - wantedSync = allSyncs.First(x => x.Player == player); - if (wantedSync == default) - { - DebugLog.ToConsole($"Error - Could not find type:{typeof(T)} for player {player.PlayerId} manually!", MessageType.Error); - return default; - } - } - - return (T)wantedSync; - } - public uint AttachedNetId { get @@ -76,13 +54,43 @@ namespace QSB.Syncs } public PlayerInfo Player => QSBPlayerManager.GetPlayer(PlayerId); - private bool _baseIsReady - => (!IsPlayerObject || QSBPlayerManager.PlayerExists(PlayerId)) - && (!IsPlayerObject || Player != null) - && (!IsPlayerObject || Player.IsReady) - && NetId.Value != uint.MaxValue - && NetId.Value != 0U - && WorldObjectManager.AllObjectsAdded; + + private bool _baseIsReady + { + get + { + if (NetId.Value is uint.MaxValue or 0U) + { + return false; + } + + if (!WorldObjectManager.AllObjectsAdded) + { + return false; + } + + if (IsPlayerObject) + { + if (!QSBPlayerManager.PlayerExists(PlayerId)) + { + return false; + } + + if (Player == null) + { + return false; + } + + if (!Player.IsReady && !IsLocalPlayer) + { + return false; + } + } + + return true; + } + } + public abstract bool IsReady { get; } public abstract bool UseInterpolation { get; } public abstract bool IgnoreDisabledAttachedObject { get; } @@ -115,24 +123,6 @@ namespace QSB.Syncs DontDestroyOnLoad(gameObject); QSBSceneManager.OnSceneLoaded += OnSceneLoaded; - - if (Player == null) - { - if (IsPlayerObject) - { - DebugLog.ToConsole($"Error - Player in start of {LogName} was null!", MessageType.Error); - } - - return; - } - - if (!_storedTransformSyncs.ContainsKey(PlayerId)) - { - _storedTransformSyncs.Add(PlayerId, new Dictionary()); - } - - var playerDict = _storedTransformSyncs[PlayerId]; - playerDict[GetType()] = this; } protected virtual void OnDestroy() @@ -146,14 +136,6 @@ namespace QSB.Syncs } QSBSceneManager.OnSceneLoaded -= OnSceneLoaded; - - if (!QSBPlayerManager.PlayerExists(PlayerId)) - { - return; - } - - var playerDict = _storedTransformSyncs[PlayerId]; - playerDict.Remove(GetType()); } protected virtual void Init() @@ -182,7 +164,6 @@ namespace QSB.Syncs { if (!_isInitialized && IsReady && _baseIsReady) { - try { Init(); diff --git a/QSB/WorldSync/WorldObjectManager.cs b/QSB/WorldSync/WorldObjectManager.cs index 2c0d1f99..76394646 100644 --- a/QSB/WorldSync/WorldObjectManager.cs +++ b/QSB/WorldSync/WorldObjectManager.cs @@ -49,25 +49,19 @@ namespace QSB.WorldSync { if (!QSBNetworkManager.Instance.IsReady) { - DebugLog.ToConsole($"Warning - Tried to rebuild WorldObjects when Network Manager not ready!", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to rebuild WorldObjects when Network Manager not ready! Building when ready...", MessageType.Warning); QSBCore.UnityEvents.RunWhen(() => QSBNetworkManager.Instance.IsReady, () => Rebuild(scene)); return; } if (QSBPlayerManager.LocalPlayerId == uint.MaxValue) { - DebugLog.ToConsole($"Warning - Tried to rebuild WorldObjects when LocalPlayer is not ready!", OWML.Common.MessageType.Warning); + DebugLog.ToConsole($"Warning - Tried to rebuild WorldObjects when LocalPlayer is not ready! Building when ready...", MessageType.Warning); QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayerId != uint.MaxValue, () => Rebuild(scene)); return; } - if (QSBPlayerManager.LocalPlayer.IsReady) - { - DoRebuild(scene); - return; - } - - QSBCore.UnityEvents.RunWhen(() => QSBPlayerManager.LocalPlayer.IsReady, () => DoRebuild(scene)); + DoRebuild(scene); } private static void DoRebuild(OWScene scene) From 72938b4c7cbd78775273f16719320932b8c08caa Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 11 Dec 2021 11:47:07 +0000 Subject: [PATCH 44/52] removed logs --- QSB/Inputs/QSBInputManager.cs | 1 - QSB/Player/Events/PlayerJoinEvent.cs | 1 - QSB/Player/PlayerHUDMarker.cs | 1 - QSB/Player/QSBPlayerManager.cs | 1 - QSB/Player/TransformSync/PlayerTransformSync.cs | 4 ---- QSB/StatueSync/Events/StartStatueEvent.cs | 10 +++++++--- QSB/TimeSync/WakeUpSync.cs | 9 --------- 7 files changed, 7 insertions(+), 20 deletions(-) diff --git a/QSB/Inputs/QSBInputManager.cs b/QSB/Inputs/QSBInputManager.cs index 840ffeb0..dcf06a1b 100644 --- a/QSB/Inputs/QSBInputManager.cs +++ b/QSB/Inputs/QSBInputManager.cs @@ -58,7 +58,6 @@ namespace QSB.Inputs public void SetInputsEnabled(bool enabled) { - DebugLog.DebugWrite($"INPUTS ENABLED? : {enabled}"); InputsEnabled = enabled; } } diff --git a/QSB/Player/Events/PlayerJoinEvent.cs b/QSB/Player/Events/PlayerJoinEvent.cs index 56d68060..d0177a15 100644 --- a/QSB/Player/Events/PlayerJoinEvent.cs +++ b/QSB/Player/Events/PlayerJoinEvent.cs @@ -80,7 +80,6 @@ namespace QSB.Player.Events if (QSBSceneManager.IsInUniverse) { - DebugLog.DebugWrite($"Joined! SENDING READY = TRUE"); QSBPlayerManager.LocalPlayer.IsReady = true; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, true); } diff --git a/QSB/Player/PlayerHUDMarker.cs b/QSB/Player/PlayerHUDMarker.cs index 30f4d5a1..0e411f5f 100644 --- a/QSB/Player/PlayerHUDMarker.cs +++ b/QSB/Player/PlayerHUDMarker.cs @@ -21,7 +21,6 @@ namespace QSB.Player public void Init(PlayerInfo player) { - DebugLog.DebugWrite($"Init {player.PlayerId} name:{player.Name}"); _player = player; _player.HudMarker = this; _needsInitializing = true; diff --git a/QSB/Player/QSBPlayerManager.cs b/QSB/Player/QSBPlayerManager.cs index 927804f8..6895a1da 100644 --- a/QSB/Player/QSBPlayerManager.cs +++ b/QSB/Player/QSBPlayerManager.cs @@ -91,7 +91,6 @@ namespace QSB.Player player.ProbeActive = message.ProbeActive; if (LocalPlayer.IsReady && player.IsReady) { - DebugLog.DebugWrite($"{player.PlayerId} UpdateObjectsFromStates player.IsReady:{player.IsReady}, camerabody null :{player.CameraBody == null}"); player.UpdateObjectsFromStates(); } diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index 6f670f44..8c90ead7 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -62,14 +62,12 @@ namespace QSB.Player.TransformSync if (isInUniverse && !_isInitialized) { - DebugLog.DebugWrite($"Is in universe, but is not initialized! SENDING READY = FALSE"); Player.IsReady = false; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, false); } if (!isInUniverse) { - DebugLog.DebugWrite($"Is not in universe! SENDING READY = FALSE"); Player.IsReady = false; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, false); } @@ -81,8 +79,6 @@ namespace QSB.Player.TransformSync { base.Init(); - DebugLog.DebugWrite($"Init! SENDING READY = TRUE"); - Player.IsReady = true; QSBEventManager.FireEvent(EventNames.QSBPlayerReady, true); } diff --git a/QSB/StatueSync/Events/StartStatueEvent.cs b/QSB/StatueSync/Events/StartStatueEvent.cs index f9e95ecc..c0df8d01 100644 --- a/QSB/StatueSync/Events/StartStatueEvent.cs +++ b/QSB/StatueSync/Events/StartStatueEvent.cs @@ -28,8 +28,6 @@ namespace QSB.StatueSync.Events public override void OnReceiveLocal(bool server, StartStatueMessage message) { - DebugLog.DebugWrite($"OnReceiveLocal StartStatueEvent"); - if (!QSBCore.IsHost) { return; @@ -40,8 +38,14 @@ namespace QSB.StatueSync.Events public override void OnReceiveRemote(bool server, StartStatueMessage message) { - DebugLog.DebugWrite($"OnReceiveRemote StartStatueEvent"); StatueManager.Instance.BeginSequence(message.PlayerPosition, message.PlayerRotation, message.CameraDegrees); + + if (!QSBCore.IsHost) + { + return; + } + + QSBEventManager.FireEvent(EventNames.QSBServerState, ServerState.InStatueCutscene); } } } diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index db66dc42..bac9d9d9 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -278,7 +278,6 @@ namespace QSB.TimeSync { if (CurrentState != State.Pausing) { - DebugLog.DebugWrite($"Wait for other clients to be ready"); StartPausing(PauseReason.WaitingForAllPlayersToBeReady); } } @@ -287,7 +286,6 @@ namespace QSB.TimeSync { if (clientState == ClientState.AliveInSolarSystem && serverState == ServerState.InSolarSystem) { - DebugLog.DebugWrite($"start of new loop!"); ResetTimeScale(); } } @@ -352,13 +350,11 @@ namespace QSB.TimeSync if (serverState == ServerState.NotLoaded && CurrentState != State.Pausing && QSBSceneManager.IsInUniverse) { - DebugLog.DebugWrite($"Server Not Loaded"); StartPausing(PauseReason.ServerNotStarted); } if (serverState == ServerState.WaitingForAllPlayersToReady && CurrentState != State.Pausing && clientState == ClientState.WaitingForOthersToReadyInSolarSystem) { - DebugLog.DebugWrite($"Awaiting Play Confirmation"); StartPausing(PauseReason.WaitingForAllPlayersToBeReady); } @@ -369,7 +365,6 @@ namespace QSB.TimeSync if (serverState == ServerState.WaitingForAllPlayersToDie && clientState == ClientState.WaitingForOthersToReadyInSolarSystem) { - DebugLog.DebugWrite($"Wait for others to load new scene"); StartPausing(PauseReason.WaitingForAllPlayersToBeReady); } @@ -379,7 +374,6 @@ namespace QSB.TimeSync { if (serverState != ServerState.NotLoaded) { - DebugLog.DebugWrite($"Server started!"); ResetTimeScale(); } } @@ -388,7 +382,6 @@ namespace QSB.TimeSync { if (clientState == ClientState.AliveInSolarSystem && serverState == ServerState.InSolarSystem) { - DebugLog.DebugWrite($"start of new loop!"); ResetTimeScale(); } } @@ -397,7 +390,6 @@ namespace QSB.TimeSync { if (Time.timeSinceLevelLoad <= _serverTime) { - DebugLog.DebugWrite($"Done pausing to match time!"); ResetTimeScale(); } } @@ -406,7 +398,6 @@ namespace QSB.TimeSync { if (Time.timeSinceLevelLoad >= _serverTime) { - DebugLog.DebugWrite($"Done fast-forwarding to match time!"); ResetTimeScale(); } } From accef60619708fbdc1ad8a62837ed45ebd31ff3b Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 11 Dec 2021 11:47:21 +0000 Subject: [PATCH 45/52] add _waitingForEvent --- QSB/Player/Events/PlayerInformationEvent.cs | 2 +- QSB/Player/Events/RequestStateResyncEvent.cs | 25 +++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/QSB/Player/Events/PlayerInformationEvent.cs b/QSB/Player/Events/PlayerInformationEvent.cs index 3ba248fb..5dda07bc 100644 --- a/QSB/Player/Events/PlayerInformationEvent.cs +++ b/QSB/Player/Events/PlayerInformationEvent.cs @@ -29,7 +29,7 @@ namespace QSB.Player.Events public override void OnReceiveRemote(bool server, PlayerInformationMessage message) { - DebugLog.DebugWrite($"Received playerstate of player ID {message.AboutId}", MessageType.Info); + RequestStateResyncEvent._waitingForEvent = false; if (QSBPlayerManager.PlayerExists(message.AboutId)) { QSBPlayerManager.HandleFullStateMessage(message); diff --git a/QSB/Player/Events/RequestStateResyncEvent.cs b/QSB/Player/Events/RequestStateResyncEvent.cs index fabfa614..f7b7e654 100644 --- a/QSB/Player/Events/RequestStateResyncEvent.cs +++ b/QSB/Player/Events/RequestStateResyncEvent.cs @@ -16,18 +16,41 @@ namespace QSB.Player.Events // Can be sent by any client (including host) to signal they want latest worldobject, player, and server infomation public class RequestStateResyncEvent : QSBEvent { + public static bool _waitingForEvent; + public override bool RequireWorldObjectsReady => false; public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBRequestStateResync, Handler); public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBRequestStateResync, Handler); - private void Handler() => SendEvent(CreateMessage()); + private void Handler() + { + if (_waitingForEvent) + { + return; + } + + _waitingForEvent = true; + SendEvent(CreateMessage()); + } private PlayerMessage CreateMessage() => new() { AboutId = LocalPlayerId }; + public override void OnReceiveLocal(bool isHost, PlayerMessage message) + { + QSBCore.UnityEvents.FireInNUpdates(() => + { + if (_waitingForEvent) + { + DebugLog.ToConsole($"Did not receive PlayerInformationEvent in time. Setting _waitingForEvent to false.", OWML.Common.MessageType.Info); + _waitingForEvent = false; + } + }, 60); + } + public override void OnReceiveRemote(bool isHost, PlayerMessage message) { // send response only to the requesting client From 65ec923e33a12099eadc79e7530708829545b472 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 11 Dec 2021 11:47:37 +0000 Subject: [PATCH 46/52] fix check for messages recieved from not ready player --- QSB/Events/QSBEvent.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/Events/QSBEvent.cs b/QSB/Events/QSBEvent.cs index 8a59d500..dde34852 100644 --- a/QSB/Events/QSBEvent.cs +++ b/QSB/Events/QSBEvent.cs @@ -98,9 +98,9 @@ namespace QSB.Events if (!player.IsReady && player.PlayerId != LocalPlayerId && player.State is ClientState.AliveInSolarSystem or ClientState.AliveInEye or ClientState.DeadInSolarSystem - && this is not PlayerInformationEvent or PlayerReadyEvent) + && this is not PlayerInformationEvent and not PlayerReadyEvent and not RequestStateResyncEvent) { - DebugLog.ToConsole($"Warning - Got message from player {message.FromId}, but they were not ready. Asking for state resync, just in case.", MessageType.Warning); + DebugLog.ToConsole($"Warning - Got message (type:{GetType().Name}) from player {message.FromId}, but they were not ready. Asking for state resync, just in case.", MessageType.Warning); QSBEventManager.FireEvent(EventNames.QSBRequestStateResync); } } From d9e250d19161f8f7c0ed8b74dff2cce64c042470 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 11 Dec 2021 20:06:02 +0000 Subject: [PATCH 47/52] help --- QSB/Animation/Player/AnimationSync.cs | 22 ++++++++++++++++++---- QSB/Events/QSBEvent.cs | 6 +++++- QSB/Player/PlayerInfo.cs | 6 ++++++ QSB/TimeSync/WakeUpSync.cs | 6 ------ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/QSB/Animation/Player/AnimationSync.cs b/QSB/Animation/Player/AnimationSync.cs index fd12e7b9..806b80df 100644 --- a/QSB/Animation/Player/AnimationSync.cs +++ b/QSB/Animation/Player/AnimationSync.cs @@ -269,14 +269,28 @@ namespace QSB.Animation.Player if (type is not AnimationType.PlayerSuited and not AnimationType.PlayerUnsuited) { - VisibleAnimator?.SetTrigger("Playing"); - InvisibleAnimator?.SetTrigger("Playing"); + if (VisibleAnimator != null) + { + VisibleAnimator.SetTrigger("Playing"); + } + + if (InvisibleAnimator != null) + { + InvisibleAnimator.SetTrigger("Playing"); + } } else { // Avoids "jumping" when exiting instrument and putting on suit - VisibleAnimator?.SetTrigger("Grounded"); - InvisibleAnimator?.SetTrigger("Grounded"); + if (VisibleAnimator != null) + { + VisibleAnimator.SetTrigger("Grounded"); + } + + if (InvisibleAnimator != null) + { + InvisibleAnimator.SetTrigger("Grounded"); + } } if (NetworkAnimator == null) diff --git a/QSB/Events/QSBEvent.cs b/QSB/Events/QSBEvent.cs index dde34852..8352f616 100644 --- a/QSB/Events/QSBEvent.cs +++ b/QSB/Events/QSBEvent.cs @@ -1,5 +1,6 @@ using OWML.Common; using QSB.ClientServerStateSync; +using QSB.ClientServerStateSync.Events; using QSB.Messaging; using QSB.Player; using QSB.Player.Events; @@ -98,7 +99,10 @@ namespace QSB.Events if (!player.IsReady && player.PlayerId != LocalPlayerId && player.State is ClientState.AliveInSolarSystem or ClientState.AliveInEye or ClientState.DeadInSolarSystem - && this is not PlayerInformationEvent and not PlayerReadyEvent and not RequestStateResyncEvent) + && this is not PlayerInformationEvent + and not PlayerReadyEvent + and not RequestStateResyncEvent + and not ServerStateEvent) { DebugLog.ToConsole($"Warning - Got message (type:{GetType().Name}) from player {message.FromId}, but they were not ready. Asking for state resync, just in case.", MessageType.Warning); QSBEventManager.FireEvent(EventNames.QSBRequestStateResync); diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index b37444f4..da426922 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -197,6 +197,12 @@ namespace QSB.Player public void UpdateObjectsFromStates() { if (OWInput.GetInputMode() == InputMode.None) + { + // ? why is this here lmao + return; + } + + if (CameraBody == null) { return; } diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index bac9d9d9..4cc99d05 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -155,7 +155,6 @@ namespace QSB.TimeSync if (ServerStateManager.Instance.GetServerState() is not ServerState.InSolarSystem and not ServerState.InEye) { - DebugLog.ToConsole($"nah serverstate:{ServerStateManager.Instance.GetServerState()} (Target:{_serverTime} Current:{Time.timeSinceLevelLoad})"); return; } @@ -358,11 +357,6 @@ namespace QSB.TimeSync StartPausing(PauseReason.WaitingForAllPlayersToBeReady); } - if (serverState == ServerState.InSolarSystem && (clientState == ClientState.WaitingForOthersToReadyInSolarSystem || clientState == ClientState.WaitingForOthersToDieInSolarSystem)) - { - DebugLog.DebugWrite($"Server is still running game normally, but this player has died from an accepted death!", MessageType.Warning); - } - if (serverState == ServerState.WaitingForAllPlayersToDie && clientState == ClientState.WaitingForOthersToReadyInSolarSystem) { StartPausing(PauseReason.WaitingForAllPlayersToBeReady); From 1aa99df228e97388d326ad720f1f887d3616f15e Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 12 Dec 2021 00:00:24 +0000 Subject: [PATCH 48/52] fix ready event lol --- QSB/Player/Events/PlayerReadyEvent.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/QSB/Player/Events/PlayerReadyEvent.cs b/QSB/Player/Events/PlayerReadyEvent.cs index 9cbfc962..2bc21ad5 100644 --- a/QSB/Player/Events/PlayerReadyEvent.cs +++ b/QSB/Player/Events/PlayerReadyEvent.cs @@ -49,6 +49,8 @@ namespace QSB.Player.Events MessageType.Error); return; } + + QSBPlayerManager.GetPlayer(message.AboutId).IsReady = message.ToggleValue; } } } \ No newline at end of file From 6f5a8d75313ae682e9bc4fdb4244f21f28a1ff13 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 12 Dec 2021 00:00:46 +0000 Subject: [PATCH 49/52] add launchcodesgiven sync --- QSB/SaveSync/Events/GameStateEvent.cs | 3 +++ QSB/SaveSync/Events/GameStateMessage.cs | 17 +++-------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/QSB/SaveSync/Events/GameStateEvent.cs b/QSB/SaveSync/Events/GameStateEvent.cs index 903da031..b8b257fc 100644 --- a/QSB/SaveSync/Events/GameStateEvent.cs +++ b/QSB/SaveSync/Events/GameStateEvent.cs @@ -20,6 +20,7 @@ namespace QSB.SaveSync.Events ForId = toId, InSolarSystem = QSBSceneManager.CurrentScene == OWScene.SolarSystem, InEye = QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse, + LaunchCodesGiven = PlayerData.KnowsLaunchCodes(), LoopCount = StandaloneProfileManager.SharedInstance.currentProfileGameSave.loopCount, KnownFrequencies = StandaloneProfileManager.SharedInstance.currentProfileGameSave.knownFrequencies, KnownSignals = StandaloneProfileManager.SharedInstance.currentProfileGameSave.knownSignals @@ -32,6 +33,8 @@ namespace QSB.SaveSync.Events gameSave.knownFrequencies = message.KnownFrequencies; gameSave.knownSignals = message.KnownSignals; + PlayerData.SetPersistentCondition("LAUNCH_CODES_GIVEN", message.LaunchCodesGiven); + PlayerData.SaveCurrentGame(); if (message.InEye != (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) diff --git a/QSB/SaveSync/Events/GameStateMessage.cs b/QSB/SaveSync/Events/GameStateMessage.cs index 1315df1d..74755a57 100644 --- a/QSB/SaveSync/Events/GameStateMessage.cs +++ b/QSB/SaveSync/Events/GameStateMessage.cs @@ -9,6 +9,7 @@ namespace QSB.SaveSync.Events { public bool InSolarSystem { get; set; } public bool InEye { get; set; } + public bool LaunchCodesGiven { get; set; } public int LoopCount { get; set; } public bool[] KnownFrequencies { get; set; } public Dictionary KnownSignals { get; set; } = new(); @@ -16,16 +17,11 @@ namespace QSB.SaveSync.Events public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); - // in solarsystem InSolarSystem = reader.ReadBoolean(); - - // in eye InEye = reader.ReadBoolean(); - - // Loop count + LaunchCodesGiven = reader.ReadBoolean(); LoopCount = reader.ReadInt32(); - // Known Frequencies var frequenciesLength = reader.ReadInt32(); var knownFrequencies = KnownFrequencies; Array.Resize(ref knownFrequencies, frequenciesLength); @@ -35,7 +31,6 @@ namespace QSB.SaveSync.Events KnownFrequencies[i] = reader.ReadBoolean(); } - // Known signals var signalsLength = reader.ReadInt32(); KnownSignals.Clear(); for (var i = 0; i < signalsLength; i++) @@ -49,23 +44,17 @@ namespace QSB.SaveSync.Events public override void Serialize(QNetworkWriter writer) { base.Serialize(writer); - // in solarsystem writer.Write(InSolarSystem); - - // in eye writer.Write(InEye); - - // Loop count + writer.Write(LaunchCodesGiven); writer.Write(LoopCount); - // Known frequencies writer.Write(KnownFrequencies.Length); foreach (var item in KnownFrequencies) { writer.Write(item); } - // Known signals writer.Write(KnownSignals.Count); foreach (var item in KnownSignals) { From 632a706cd0c1ed0cca72e1456d745439ade40086 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 16:19:59 -0800 Subject: [PATCH 50/52] le fix --- QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index 7a7226c7..bf844bfc 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -15,6 +15,7 @@ namespace QSB.TornadoSync.TransformSync { public override bool IsReady => WorldObjectManager.AllObjectsReady; public override bool UseInterpolation => false; + public override bool IsPlayerObject => false; protected override OWRigidbody GetRigidbody() => CenterOfTheUniverse.s_rigidbodies[_bodyIndex]; From a90677bfd58a6590f083b82b8691f2172988df45 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 12 Dec 2021 00:32:56 +0000 Subject: [PATCH 51/52] im stupid --- QSB/Menus/MenuManager.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index b34e525a..15b9e5a6 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -274,6 +274,7 @@ namespace QSB.Menus { SetButtonActive(DisconnectButton, true); SetButtonActive(HostButton, false); + SetButtonActive(QuitButton, false); } else { From 76171103abf7d4f0462decc77736737528572bcc Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sat, 11 Dec 2021 17:36:44 -0800 Subject: [PATCH 52/52] fixed quit button being wrong --- QSB/Menus/MenuManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 15b9e5a6..647dfddd 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -176,7 +176,7 @@ namespace QSB.Menus DisconnectButton = MenuApi.PauseMenu_MakeMenuOpenButton("DISCONNECT", DisconnectPopup); - QuitButton = Resources.FindObjectsOfTypeAll().First(x => x.name == "Button-ExitToMainMenu").gameObject; + QuitButton = FindObjectOfType()._exitToMainMenuAction.gameObject; if (QSBCore.IsInMultiplayer) {