Browse Source

Improve NetClientListener debugging

tags/v0.0.2
NGnius (Graham) 3 years ago
parent
commit
5dd67a88f4
3 changed files with 63 additions and 23 deletions
  1. +55
    -1
      CLre/API/Tools/NetClientListener.cs
  2. +3
    -0
      CLre/CLre.cs
  3. +5
    -22
      CLre/Fixes/CooldownCrossSlotSync.cs

+ 55
- 1
CLre/API/Tools/NetClientListener.cs View File

@@ -1,6 +1,9 @@
using System.Reflection;
using System.Text;
using GameNetworkLayer.Shared;
using HarmonyLib;
using Svelto.DataStructures;
using Svelto.DataStructures.Experimental;

namespace CLre.API.Tools
{
@@ -8,6 +11,10 @@ namespace CLre.API.Tools
{
internal static bool isEnabled = false;

private static FasterDictionary<short, FasterList<NetReceiveMessageCallback>> callbacks = new FasterDictionary<short,FasterList<NetReceiveMessageCallback>>();

public delegate void NetReceiveMessageCallback(NetworkDispatcherCode code, byte[] data, int playerId);

public static void Enable()
{
isEnabled = true;
@@ -17,6 +24,52 @@ namespace CLre.API.Tools
{
isEnabled = false;
}

public static void DebugReceiveMessage(NetworkDispatcherCode code, NetReceiveMessageCallback callback)
{
short key = (short)code;
if (callbacks.TryGetValue(key, out FasterList<NetReceiveMessageCallback> handlers))
{
handlers.Add(callback);
}
else
{
FasterList<NetReceiveMessageCallback> newHandlers = new FasterList<NetReceiveMessageCallback>(new [] {callback});
callbacks.Add(key, newHandlers);
}
}

internal static bool RunDebugCallbacks(NetworkDispatcherCode code, byte[] data, int playerId)
{
short key = (short)code;
if (callbacks.TryGetValue(key, out FasterList<NetReceiveMessageCallback> handlers))
{
foreach (NetReceiveMessageCallback callback in handlers)
{
callback(code, data, playerId);
}

return true;
}
else
{
return false;
}
}

public static void Log(NetworkDispatcherCode code, byte[] data, int playerId)
{
StringBuilder sb = new StringBuilder("Received ");
sb.Append(code.ToString());
sb.Append(" for player #");
sb.Append(playerId);
sb.Append(": 0x");
foreach (byte b in data)
{
sb.Append(b.ToString("X"));
}
Utility.Logging.Log(sb.ToString());
}
}

[HarmonyPatch]
@@ -35,7 +88,8 @@ namespace CLre.API.Tools
Utility.Logging.LogWarning("Network message data was deserialized as null");
return;
}
Utility.Logging.Log($"Received network message for player {playerId} (code: {code.ToString()}, len: {data.Length})");
bool isHandled = NetClientListener.RunDebugCallbacks(code, data, playerId);
if (!isHandled) Utility.Logging.Log($"Received network message for player {playerId} (code: {code.ToString()}, len: {data.Length})");
}
[HarmonyTargetMethod]


+ 3
- 0
CLre/CLre.cs View File

@@ -62,6 +62,9 @@ namespace CLre
NetClientSender.GetLogMethod(netData));
API.Utility.Logging.MetaLog("Patched SendMessage<Shared.Inventory.HandheldEquipmentRequest>");
NetClientListener.DebugReceiveMessage(NetworkDispatcherCode.EACMessageServerToClient,
NetClientListener.Log);
// API debug and testing
API.App.Client.InitComplete += (_, __) =>
{


+ 5
- 22
CLre/Fixes/CooldownCrossSlotSync.cs View File

@@ -78,11 +78,7 @@ namespace CLre.Fixes
return;
}

object wcevOriginal = queryWCEV(toolId, baseGroup);
float cooldownLeft =
Traverse.Create(wcevOriginal).Field("weaponCooldownComponent").Property<float>("cooldownLeft").Value;
bool isInCooldown =
Traverse.Create(wcevOriginal).Field("weaponCooldownComponent").Property<bool>("isInCooldown").Value;
//object wcevOriginal = queryWCEV(toolId, baseGroup);
//API.Utility.Logging.MetaLog($"Cooling down? {isInCooldown} for {cooldownLeft}s");
// build functions for querying all Game.Handhelds.WeaponCooldownEntityView objects
Type protoRaw =
@@ -109,23 +105,6 @@ namespace CLre.Fixes
isRunningTick = true;
cooldownTickEverything(characterId, cwcevExists, queryCWCEV, queryWCEV, queryAllWCEV, indexer, baseGroup).Run();
}
/*object[] indexParams = {0};
for (int index = 0; index < count; index++)
{
#if DEBUG
API.Utility.Logging.MetaLog("Syncing cooldown with another weapon");
#endif
indexParams[0] = index;
object wcev = indexer.GetValue(collectionStruct, indexParams);
Traverse.Create(wcev)
.Field("weaponCooldownComponent")
.Property<float>("cooldownLeft")
.Value = cooldownLeft;
Traverse.Create(wcev)
.Field("weaponCooldownComponent")
.Property<bool>("isInCooldown").Value = isInCooldown;
}*/
}

[HarmonyTargetMethod]
@@ -156,7 +135,9 @@ namespace CLre.Fixes
Traverse.Create(wcevOriginal).Field("weaponCooldownComponent").Property<bool>("isInCooldown").Value;
object[] indexParams = {0};
// iterate over other handhelds and sync their cooldowns to the held item
#if DEBUG
API.Utility.Logging.MetaDebugLog($"Syncing {count} weapon cooldowns with the held item {toolId}");
#endif
for (int index = 0; index < count; index++)
{
indexParams[0] = index;
@@ -175,7 +156,9 @@ namespace CLre.Fixes
yield return null;
}
// cleanup
#if DEBUG
API.Utility.Logging.MetaDebugLog("Custom cooldown ticks complete");
#endif
isRunningTick = false;
yield return null;
}


Loading…
Cancel
Save