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
23 changes: 17 additions & 6 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,18 @@ 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)
continue;
netId.id--;
BarricadeDrop drop = NetIdRegistry.Get<BarricadeDrop>(netId);
if (drop == null)
continue;

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

Expand All @@ -41,7 +48,11 @@ 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--;
return NetIdRegistry.Get<BarricadeDrop>(netId);
}
}
}
30 changes: 26 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)
continue;
netId.id--;
BarricadeDrop drop = NetIdRegistry.Get<BarricadeDrop>(netId);
if (drop != null)
return drop.model;
}
}
return null;
Expand All @@ -79,7 +95,13 @@ 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)
continue;
netId.id--;
StructureDrop drop = NetIdRegistry.Get<StructureDrop>(netId);
if (drop != null)
return drop.model;
}
}

Expand Down
30 changes: 4 additions & 26 deletions SellDoor/Helpers/StructureHelper.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
using SDG.Unturned;
using System;
using System.Collections.Generic;
using SDG.Unturned;
using UnityEngine;

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);

List<Transform> results = new();
StructureManager.getStructuresInRadius(point, 0.1f, regions, results);

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

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

return null;
}

public static StructureDrop ForceDropStructure(ItemStructureAsset asset, Vector3 point, Vector3 angle, ulong owner, ulong group)
{
Structure structure = new(asset, asset.health);
Quaternion rotation = Quaternion.Euler(angle.x, angle.y, angle.z);

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

return FindStructureDropByPosition(asset.GUID, point);
// dropReplicatedStructure goes through ClaimBlock(2u): drop is at counter-1, transform at counter.
NetId dropNetId = new NetId(NetIdRegistry.counter - 1);
return NetIdRegistry.Get<StructureDrop>(dropNetId);
}
}
}
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
25 changes: 15 additions & 10 deletions SellDoor/Models/TransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@ public void UpdatePosition()

if (AssetId == null)
{
BarricadeDrop drop = BarricadeManager.FindBarricadeByRootTransform(Transform);
if (drop != null)
NetId netId = NetIdRegistry.GetTransformNetId(Transform);
if (netId != NetId.INVALID)
{
AssetId = drop.asset.GUID;
AssetName = drop.asset.itemName;
}
else
{
StructureDrop structureDrop = StructureManager.FindStructureByRootTransform(Transform);
netId.id--;
BarricadeDrop drop = NetIdRegistry.Get<BarricadeDrop>(netId);
if (drop != null)
{
AssetId = structureDrop.asset.GUID;
AssetName = structureDrop.asset.itemName;
AssetId = drop.asset.GUID;
AssetName = drop.asset.itemName;
}
else
{
StructureDrop structureDrop = NetIdRegistry.Get<StructureDrop>(netId);
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