Skip to content

Commit

Permalink
Merge pull request #604 from misternebula/dev
Browse files Browse the repository at this point in the history
0.26.3
  • Loading branch information
misternebula authored Mar 8, 2023
2 parents 73cdc6a + c5787d9 commit 6a40c9b
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 17 deletions.
66 changes: 66 additions & 0 deletions QSB/Ghostbuster.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Mirror;
using QSB.Player;
using QSB.Utility;
using System.Collections.Generic;
using UnityEngine;

namespace QSB;
internal class Ghostbuster : MonoBehaviour, IAddComponentOnStart
{
private const int UpdateInterval = 60;

private int _updateCount;

public void Update()
{
if (!QSBCore.IsInMultiplayer)
{
return;
}

if (!QSBCore.IsHost)
{
return;
}

if (_updateCount != UpdateInterval)
{
_updateCount++;
return;
}
else
{
_updateCount = 0;
}

var _ghostPlayers = new List<PlayerInfo>();

foreach (var player in QSBPlayerManager.PlayerList)
{
var isGhost = false;

var networkIdentity = player.TransformSync.netIdentity;

if (networkIdentity.connectionToClient == null)
{
isGhost = true;
}
else if (!NetworkServer.connections.ContainsValue(networkIdentity.connectionToClient))
{
isGhost = true;
}

if (isGhost)
{
// WE GOT ONE!!!!!!
_ghostPlayers.Add(player);
}
}

foreach (var item in _ghostPlayers)
{
DebugLog.ToConsole($"Deleting playerId:{item.PlayerId} - It's a ghooOoOoOooost! (hopefully)", OWML.Common.MessageType.Info);
NetworkServer.DestroyPlayerForConnection(item.TransformSync.netIdentity.connectionToClient);
}
}
}
2 changes: 1 addition & 1 deletion QSB/HUD/MultiplayerHUDManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void OnAddPlayer(PlayerInfo player)

private void OnRemovePlayer(PlayerInfo player)
{
Destroy(player.HUDBox.gameObject);
Destroy(player.HUDBox?.gameObject);
}

private PlanetTrigger CreateTrigger(string parentPath, HUDIcon icon)
Expand Down
12 changes: 9 additions & 3 deletions QSB/Player/Patches/VolumePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ public static void OnEffectVolumeEnter(RingRiverFluidVolume __instance, GameObje
public static bool PreventRemotePlayerEnter(object __instance, GameObject hitObj)
{
DebugLog.DebugWrite($"{__instance} funny prevent enter {hitObj}");
// this is a dogshit fix to a bug where this would ApplyShock to remote players,
// which would actually apply the shock affects to the entire planet / sector
//
// TODO: also do this with remote probes
return hitObj.name is not ("REMOTE_PlayerDetector" or "REMOTE_CameraDetector");
}

[HarmonyPrefix]
[HarmonyPatch(typeof(VanishVolume), nameof(VanishVolume.OnTriggerEnter))]
public static bool PreventRemotePlayerEnter(object __instance, Collider hitCollider)
{
DebugLog.DebugWrite($"{__instance} funny prevent enter {hitCollider}");
// TODO: also do this with remote probes
return hitCollider.name is not ("REMOTE_PlayerDetector" or "REMOTE_CameraDetector");
}
}
4 changes: 2 additions & 2 deletions QSB/Player/TransformSync/PlayerTransformSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void OnStartClient()
var player = new PlayerInfo(this);
QSBPlayerManager.PlayerList.SafeAdd(player);
base.OnStartClient();
QSBPlayerManager.OnAddPlayer?.Invoke(Player);
QSBPlayerManager.OnAddPlayer?.SafeInvoke(Player);
DebugLog.DebugWrite($"Create Player : {Player}", MessageType.Info);

JoinLeaveSingularity.Create(Player, true);
Expand All @@ -50,7 +50,7 @@ public override void OnStopClient()

// TODO : Maybe move this to a leave event...? Would ensure everything could finish up before removing the player
QSBPatch.Remote = true;
QSBPlayerManager.OnRemovePlayer?.Invoke(Player);
QSBPlayerManager.OnRemovePlayer?.SafeInvoke(Player);
QSBPatch.Remote = false;
base.OnStopClient();
Player.HudMarker?.Remove();
Expand Down
2 changes: 1 addition & 1 deletion QSB/QSB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</Target>

<Target Name="weave qsb" AfterTargets="PostBuildEvent">
<Exec Command="MirrorWeaver &quot;$(TargetPath)&quot;" WorkingDirectory="..\MirrorWeaver\bin\$(Configuration)\" />
<Exec Command=".\MirrorWeaver &quot;$(TargetPath)&quot;" WorkingDirectory="..\MirrorWeaver\bin\$(Configuration)\" />
</Target>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion QSB/Utility/DebugActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void Update()
{
var player = new PlayerInfo(QSBPlayerManager.LocalPlayer.TransformSync);
QSBPlayerManager.PlayerList.SafeAdd(player);
QSBPlayerManager.OnAddPlayer?.Invoke(player);
QSBPlayerManager.OnAddPlayer?.SafeInvoke(player);
DebugLog.DebugWrite($"CREATING FAKE PLAYER : {player}", MessageType.Info);

JoinLeaveSingularity.Create(player, true);
Expand Down
12 changes: 6 additions & 6 deletions QSB/Utility/DebugGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ private static void DrawGui()
{
WriteLine(1, $" - {item}");
}

WriteLine(1, $"Sectors :");
foreach (var sector in PlayerTransformSync.LocalInstance.SectorDetector.SectorList)
{
WriteLine(1, $"- {sector.Name}");
}
}

#endregion
Expand Down Expand Up @@ -196,12 +202,6 @@ private static void DrawGui()

WriteLine(2, $" - Ref. Sector : {(referenceSector == null ? "NULL" : referenceSector.Name)}", referenceSector == null ? Color.red : Color.white);
WriteLine(2, $" - Ref. Transform : {(referenceTransform == null ? "NULL" : referenceTransform.name)}", referenceTransform == null ? Color.red : Color.white);

WriteLine(2, $"Sectors :");
foreach (var sector in PlayerTransformSync.LocalInstance.SectorDetector.SectorList)
{
WriteLine(2, $"- {sector.Name}");
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions QSB/Utility/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Cysharp.Threading.Tasks;
using Mirror;
using OWML.Common;
using QSB.Player;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -40,10 +41,10 @@ public static GameObject FindChild(this GameObject g, string childPath) =>

public static uint GetPlayerId(this NetworkConnectionToClient conn)
{
if (!conn.identity)
if (conn.identity == null)
{
// wtf
DebugLog.ToConsole($"Error - GetPlayerId on {conn} has no identity\n{Environment.StackTrace}", MessageType.Error);
DebugLog.ToConsole($"Error - GetPlayerId on {conn} has no identity.", MessageType.Error);
return uint.MaxValue;
}

Expand Down
2 changes: 1 addition & 1 deletion QSB/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"body": "- Disable *all* other mods. (Can heavily affect performance)\n- Make sure you are not running any other network-intensive applications."
},
"uniqueName": "Raicuparta.QuantumSpaceBuddies",
"version": "0.26.1",
"version": "0.26.3",
"owmlVersion": "2.9.0",
"dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ],
"pathsToPreserve": [ "debugsettings.json" ],
Expand Down

0 comments on commit 6a40c9b

Please sign in to comment.