Skip to content

Commit

Permalink
Don't crash when WearNTear doesn't have a Piece. Addresses #12
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHimself committed Feb 6, 2023
1 parent 4000bd7 commit d4ca6e3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions XPortal/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ static void Postfix(Piece ___m_piece, ZNetView ___m_nview)
var portalZDO = ___m_nview.GetZDO();
if (portalZDO == null)
{
Jotunn.Logger.LogError("A portal was placed but the ZDO is not available");
return;
}

Expand All @@ -196,11 +197,23 @@ static class WearNTearDestroyPatch
/// <summary>
/// Before destroying a piece, check if it's a portal, and if so, raise event OnPortalDestroyed
/// </summary>
static void Prefix(Piece ___m_piece, ZNetView ___m_nview)
static void Prefix(WearNTear __instance)
{
if (___m_piece.m_name.Equals("$piece_portal") && ___m_piece.CanBeRemoved() && ___m_nview != null)
var piece = __instance.m_piece;
if (piece == null)
{
var portalZDO = ___m_nview.GetZDO();
return;
}

var nview = piece.m_nview;
if (nview == null)
{
return;
}

if (piece.m_name.Equals("$piece_portal") && piece.CanBeRemoved())
{
var portalZDO = nview.GetZDO();
if (portalZDO == null)
{
return;
Expand Down

0 comments on commit d4ca6e3

Please sign in to comment.