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
5 changes: 4 additions & 1 deletion src/GameLayer/Patches/Networking/CablePositionsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@
}
while (Interlocked.CompareExchange(ref _nextCableId, baseId + 1, current) != current);

MelonLogger.Msg($"[CablePatch] Cable ID counter set to {baseId + 1}");
try { LogMessage(baseId + 1); } catch { }

Check warning on line 70 in src/GameLayer/Patches/Networking/CablePositionsPatch.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/GameLayer/Patches/Networking/CablePositionsPatch.cs#L70

Handle the exception or explain in a comment why it can be ignored.
}

public static int PeekNextId() => _nextCableId;

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static void LogMessage(int id) { MelonLogger.Msg($"[CablePatch] Cable ID counter set to {id}"); }
}
73 changes: 72 additions & 1 deletion src/Infrastructure/Scripting/Lua/Modules/LuaServerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using MoonSharp.Interpreter;
using MelonLoader;
using System.Linq;

namespace gregCore.Infrastructure.Scripting.Lua.Modules;

Expand All @@ -21,9 +22,37 @@ public static void Register(Table greg, Script script, string modId)
{
try
{
var servers = UnityEngine.Object.FindObjectsOfType<Il2Cpp.Server>();
var result = new Table(script);
int i = 1;

var nm = Il2Cpp.NetworkMap.instance;
if (nm != null && nm.servers != null)
{
foreach (var kvp in nm.servers)
{
try
{
var s = kvp.Value;
if (s == null) continue;
var info = new Table(script);
info["id"] = s.ServerID ?? s.GetHashCode().ToString();
info["hash"] = s.GetHashCode();
info["is_on"] = s.isOn;
info["is_broken"] = s.isBroken;
info["server_type"] = (int)s.serverType;
info["size_u"] = s.sizeInU;
var pos = s.transform?.position ?? UnityEngine.Vector3.zero;
info["x"] = (double)pos.x;
info["y"] = (double)pos.y;
info["z"] = (double)pos.z;
result[i++] = info;
}
catch { }
}
return result;
}

var servers = UnityEngine.Object.FindObjectsOfType<Il2Cpp.Server>();
foreach (var s in servers)
{
try
Expand Down Expand Up @@ -80,6 +109,25 @@ public static void Register(Table greg, Script script, string modId)
{
try
{
var nm = Il2Cpp.NetworkMap.instance;
if (nm != null && nm.brokenServers != null)
{
foreach (var kvp in nm.brokenServers)
{
try
{
var s = kvp.Value;
if (s != null && s.GetHashCode() == hash && s.isBroken)
{
s.RepairDevice();
return true;
}
}
catch { }
}
return false;
}

var servers = UnityEngine.Object.FindObjectsOfType<Il2Cpp.Server>();
foreach (var s in servers)
{
Expand All @@ -104,6 +152,29 @@ public static void Register(Table greg, Script script, string modId)
try
{
int repaired = 0;
var nm = Il2Cpp.NetworkMap.instance;
if (nm != null && nm.brokenServers != null)
{
if (nm.brokenServers.Count == 0) return 0;

var brokenList = new System.Collections.Generic.List<Il2Cpp.Server>();
foreach (var kvp in nm.brokenServers) brokenList.Add(kvp.Value);

foreach (var s in brokenList)
{
try
{
if (s != null && s.isBroken)
{
s.RepairDevice();
repaired++;
}
}
catch { }
}
return repaired;
}

var servers = UnityEngine.Object.FindObjectsOfType<Il2Cpp.Server>();
foreach (var s in servers)
{
Expand Down
Loading