90 lines
3.9 KiB
C#
90 lines
3.9 KiB
C#
using static RebirthManager;
|
|
|
|
namespace Harmony.ConnectionManagerPatches
|
|
{
|
|
[HarmonyPatch(typeof(ConnectionManager))]
|
|
[HarmonyPatch("SendToServer")]
|
|
public class SendToServerPatch
|
|
{
|
|
public static bool Prefix(ConnectionManager __instance, NetPackage _package, bool _flush,
|
|
ref INetConnection[] ___connectionToServer
|
|
)
|
|
{
|
|
int channel = _package.Channel;
|
|
if (___connectionToServer[channel] == null)
|
|
{
|
|
if (__instance.IsConnected)
|
|
{
|
|
Log.Error("Can not queue package for server: NetConnection null");
|
|
Log.Error("Can not queue package for server: Package ID: " + _package.PackageId);
|
|
//Log.Error("Can not queue package for server: Player: " + _package.Sender.playerName);
|
|
}
|
|
return false;
|
|
}
|
|
___connectionToServer[channel].AddToSendQueue(_package);
|
|
if (_flush)
|
|
{
|
|
___connectionToServer[channel].FlushSendQueue();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(ConnectionManager))]
|
|
[HarmonyPatch("DisconnectClient")]
|
|
public class DisconnectClientPatch
|
|
{
|
|
public static bool Prefix(ConnectionManager __instance, ClientInfo _cInfo, bool _bShutdown = false, bool _clientDisconnect = false)
|
|
{
|
|
//Log.Out("ConnectionManagerPatches-DisconnectClient START, _cInfo.entityId: " + _cInfo.entityId);
|
|
RebirthUtilities.removeTileEntityAccess(_cInfo.entityId);
|
|
|
|
RebirthVariables.purgePrefabsLoaded = false;
|
|
|
|
World world = GameManager.Instance.World;
|
|
|
|
foreach (hireInfo hire in playerHires)
|
|
{
|
|
//Log.Out("ConnectionManagerPatches-DisconnectClient hire.playerID: " + hire.playerID);
|
|
//Log.Out("ConnectionManagerPatches-DisconnectClient hire.hireID: " + hire.hireID);
|
|
//Log.Out("ConnectionManagerPatches-DisconnectClient hire.order: " + hire.order);
|
|
|
|
if (hire.playerID == _cInfo.entityId && hire.order == (int)EntityUtilities.Orders.Follow)
|
|
{
|
|
EntityNPCRebirth entity = GameManager.Instance.World.GetEntity(hire.hireID) as EntityNPCRebirth;
|
|
if (entity)
|
|
{
|
|
//Log.Out("ConnectionManagerPatches-DisconnectClient entityPlayer [" + _cInfo.playerName + "] Disconnected, hire [" + entity.EntityName + "] set to STAY");
|
|
//Log.Out("ConnectionManagerPatches-DisconnectClient [" + entityPlayer.EntityName + "] entity.position + entity.GetLookVector(): " + entity.position + entity.GetLookVector());
|
|
|
|
entity.guardPosition = Vector3.zero;
|
|
entity.HideNPC(false);
|
|
entity.Buffs.SetCustomVar("CurrentOrder", (int)EntityUtilities.Orders.TempStay);
|
|
entity.Buffs.SetCustomVar("$Leader", _cInfo.entityId);
|
|
}
|
|
}
|
|
if (hire.playerID == _cInfo.entityId && (hire.order == 1 || hire.order == 2))
|
|
{
|
|
for (int i = 0; i < observers.Count; i++)
|
|
{
|
|
if (observers[i].entityID == hire.hireID)
|
|
{
|
|
//Log.Out("ConnectionManagerPatches-DisconnectClient REMOVED OBSERVER, hire: " + hire.hireID);
|
|
GameManager.Instance.RemoveChunkObserver(observers[i].observerRef);
|
|
observers.RemoveAt(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (hire.playerID == _cInfo.entityId)
|
|
{
|
|
hire.playerSpawned = false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|