Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions SellDoor/Helpers/BarricadeHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SDG.Unturned;
using Steamworks;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -20,12 +21,19 @@ public static BarricadeDrop FindBarricadeDrop(Guid assetGuid, Vector3 point)

foreach (Transform result in results)
{
BarricadeDrop barricadeDrop = BarricadeManager.FindBarricadeByRootTransform(result);
BarricadeData barricadeData = barricadeDrop.GetServersideData();

if (barricadeData.point == point && barricadeDrop.asset.GUID == assetGuid)
NetId netId = NetIdRegistry.GetTransformNetId(result);
if (netId == NetId.INVALID)
return null;
netId.id--;
BarricadeDrop drop = NetIdRegistry.Get<BarricadeDrop>(netId);


BarricadeData barricadeData = drop.GetServersideData();

if (barricadeData.point == point && drop.asset.GUID == assetGuid)
{
return barricadeDrop;
return drop;
}
}

Expand All @@ -41,7 +49,14 @@ public static BarricadeDrop ForceDropBarricade(ItemBarricadeAsset asset, Vector3

Transform transform = BarricadeManager.dropNonPlantedBarricade(barricade, point, rotation, owner, group);

return BarricadeManager.FindBarricadeByRootTransform(transform);

NetId netId = NetIdRegistry.GetTransformNetId(transform);
if (netId == NetId.INVALID)
return null;
netId.id--;
BarricadeDrop drop = NetIdRegistry.Get<BarricadeDrop>(netId);

return drop;
}
}
}
29 changes: 25 additions & 4 deletions SellDoor/Helpers/RaycastHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SDG.Unturned;
using Steamworks;
using System.Collections.Generic;
using UnityEngine;

Expand All @@ -22,7 +23,12 @@ public static Transform GetBarricadeTransform(Player player, out BarricadeData b
transform = door.transform;
}

drop = BarricadeManager.FindBarricadeByRootTransform(transform);
NetId netId = NetIdRegistry.GetTransformNetId(transform);
if (netId == NetId.INVALID)
return null;
netId.id--;
drop = NetIdRegistry.Get<BarricadeDrop>(netId);

if (drop != null)
{
barricadeData = drop.GetServersideData();
Expand All @@ -40,7 +46,11 @@ public static Transform GetStructureTransform(Player player, out StructureData s
Ray ray = new Ray(player.look.aim.position, player.look.aim.forward);
if (Physics.Raycast(ray, out hit, 3, RayMasks.STRUCTURE_INTERACT))
{
StructureDrop drop = StructureManager.FindStructureByRootTransform(hit.transform);
NetId netId = NetIdRegistry.GetTransformNetId(hit.transform);
if (netId == NetId.INVALID)
return null;
netId.id--;
StructureDrop drop = NetIdRegistry.Get<StructureDrop>(netId);
if (drop != null)
{
structureData = drop.GetServersideData();
Expand All @@ -62,7 +72,13 @@ public static Transform GetBarricadeTransform(Vector3 position)
{
if (transform.position == position)
{
return BarricadeManager.FindBarricadeByRootTransform(transform)?.model ?? null;

NetId netId = NetIdRegistry.GetTransformNetId(transform);
if (netId == NetId.INVALID)
return null;
netId.id--;
BarricadeDrop drop = NetIdRegistry.Get<BarricadeDrop>(netId);
return drop?.model ?? null;
}
}
return null;
Expand All @@ -79,7 +95,12 @@ public static Transform GetStructureTransform(Vector3 position)
{
if (transform.position == position)
{
return StructureManager.FindStructureByRootTransform(transform)?.model ?? null;
NetId netId = NetIdRegistry.GetTransformNetId(transform);
if (netId == NetId.INVALID)
return null;
netId.id--;
StructureDrop drop = NetIdRegistry.Get<StructureDrop>(netId);
return drop?.model ?? null;
}
}

Expand Down
26 changes: 20 additions & 6 deletions SellDoor/Helpers/StructureHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace RestoreMonarchy.SellDoor.Helpers
{
public class StructureHelper
{
/*
public static StructureDrop FindStructureDropByPosition(Guid assetGuid, Vector3 point)
{

List<RegionCoordinate> regions = new();
Regions.getRegionsInRadius(point, 0.1f, regions);

Expand All @@ -17,17 +19,25 @@ public static StructureDrop FindStructureDropByPosition(Guid assetGuid, Vector3

foreach (Transform result in results)
{
StructureDrop structureDrop = StructureManager.FindStructureByRootTransform(result);
StructureData structureData = structureDrop.GetServersideData();

if (structureData.point == point && structureDrop.asset.GUID == assetGuid)
NetId netId = NetIdRegistry.GetTransformNetId(result);
if (netId == NetId.INVALID)
return null;
netId.id--;
StructureDrop drop = NetIdRegistry.Get<StructureDrop>(netId);
StructureData structureData = drop.GetServersideData();

if (structureData.point == point && drop.asset.GUID == assetGuid)
{
return structureDrop;
return drop;
}
}




return null;
}
*/

public static StructureDrop ForceDropStructure(ItemStructureAsset asset, Vector3 point, Vector3 angle, ulong owner, ulong group)
{
Expand All @@ -36,7 +46,11 @@ public static StructureDrop ForceDropStructure(ItemStructureAsset asset, Vector3

StructureManager.dropReplicatedStructure(structure, point, rotation, owner, group);

return FindStructureDropByPosition(asset.GUID, point);
NetId dropNetId = new NetId(NetIdRegistry.counter - 2);

StructureDrop drop = NetIdRegistry.Get<StructureDrop>(dropNetId);

return drop;
}
}
}
6 changes: 5 additions & 1 deletion SellDoor/Models/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public bool TryGetDoorOwners(out CSteamID steamID, out CSteamID groupID)
{
steamID = CSteamID.Nil;
groupID = CSteamID.Nil;
BarricadeDrop drop = BarricadeManager.FindBarricadeByRootTransform(Transform);
NetId netId = NetIdRegistry.GetTransformNetId(Transform);
if (netId == NetId.INVALID)
return false;
netId.id--;
BarricadeDrop drop = NetIdRegistry.Get<BarricadeDrop>(netId);
if (drop == null)
{
return false;
Expand Down
7 changes: 6 additions & 1 deletion SellDoor/Models/DoorItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SDG.Unturned;
using Steamworks;
using UnityEngine;

namespace RestoreMonarchy.SellDoor.Models
{
Expand Down Expand Up @@ -29,7 +30,11 @@ public void UpdateSign(string text)
return;
}

BarricadeDrop drop = BarricadeManager.FindBarricadeByRootTransform(Transform);
NetId netId = NetIdRegistry.GetTransformNetId(Transform);
if (netId == NetId.INVALID)
return;
netId.id--;
BarricadeDrop drop = NetIdRegistry.Get<BarricadeDrop>(netId);
if (drop == null)
{
return;
Expand Down
18 changes: 15 additions & 3 deletions SellDoor/Models/TransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,28 @@ public void UpdatePosition()

if (AssetId == null)
{
BarricadeDrop drop = BarricadeManager.FindBarricadeByRootTransform(Transform);
BarricadeDrop drop = null;
NetId netId = NetIdRegistry.GetTransformNetId(Transform);
if (netId != NetId.INVALID)
{
netId.id--;
drop = NetIdRegistry.Get<BarricadeDrop>(netId);
}
if (drop != null)
{
AssetId = drop.asset.GUID;
AssetName = drop.asset.itemName;
}
else
{
StructureDrop structureDrop = StructureManager.FindStructureByRootTransform(Transform);
if (drop != null)
StructureDrop structureDrop = null;
NetId structureNetId = NetIdRegistry.GetTransformNetId(Transform);
if (structureNetId != NetId.INVALID)
{
structureNetId.id--;
structureDrop = NetIdRegistry.Get<StructureDrop>(structureNetId);
}
if (structureDrop != null)
{
AssetId = structureDrop.asset.GUID;
AssetName = structureDrop.asset.itemName;
Expand Down
5 changes: 5 additions & 0 deletions SellDoor/SellDoor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Krafs.Publicizer" Version="2.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Lib.Harmony" Version="2.3.3" />
<PackageReference Include="RestoreMonarchy.RocketRedist" Version="3.24.6" ExcludeAssets="runtime" />
<Publicize Include="Assembly-CSharp:SDG.Unturned.NetIdRegistry.counter"/>
</ItemGroup>

<ItemGroup>
Expand Down