mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
LuaNetworkVariables: idk
This commit is contained in:
parent
db07d53971
commit
fe768029eb
19 changed files with 1680 additions and 0 deletions
|
@ -0,0 +1,57 @@
|
|||
using ABI_RC.Core.Savior;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.LuaNetVars;
|
||||
|
||||
public partial class LuaNetVarController
|
||||
{
|
||||
private bool TryGetUniqueNetworkID(out int hash)
|
||||
{
|
||||
string path = GetGameObjectPath(transform);
|
||||
hash = path.GetHashCode();
|
||||
|
||||
// Check if it already exists (this **should** only matter in worlds)
|
||||
if (_hashes.Contains(hash))
|
||||
{
|
||||
LuaNetVarsMod.Logger.Warning($"Duplicate RelativeSyncMarker found at path {path}");
|
||||
if (!FindAvailableHash(ref hash)) // Super lazy fix idfc
|
||||
{
|
||||
LuaNetVarsMod.Logger.Error($"Failed to find available hash for RelativeSyncMarker after 16 tries! {path}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_hashes.Add(hash);
|
||||
|
||||
return true;
|
||||
|
||||
static bool FindAvailableHash(ref int hash)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
hash += 1;
|
||||
if (!_hashes.Contains(hash)) return true;
|
||||
}
|
||||
return false; // Failed to find a hash in 16 tries
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetGameObjectPath(Transform transform)
|
||||
{
|
||||
string path = transform.name;
|
||||
while (transform.parent != null)
|
||||
{
|
||||
transform = transform.parent;
|
||||
|
||||
// Only true at root of local player object
|
||||
if (transform.CompareTag("Player"))
|
||||
{
|
||||
path = MetaPort.Instance.ownerId + "/" + path;
|
||||
break;
|
||||
}
|
||||
|
||||
path = transform.name + "/" + path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue