Improve NetClientListener debugging
This commit is contained in:
parent
00589d1c28
commit
5dd67a88f4
3 changed files with 63 additions and 23 deletions
|
@ -1,6 +1,9 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
using GameNetworkLayer.Shared;
|
using GameNetworkLayer.Shared;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using Svelto.DataStructures;
|
||||||
|
using Svelto.DataStructures.Experimental;
|
||||||
|
|
||||||
namespace CLre.API.Tools
|
namespace CLre.API.Tools
|
||||||
{
|
{
|
||||||
|
@ -8,6 +11,10 @@ namespace CLre.API.Tools
|
||||||
{
|
{
|
||||||
internal static bool isEnabled = false;
|
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()
|
public static void Enable()
|
||||||
{
|
{
|
||||||
isEnabled = true;
|
isEnabled = true;
|
||||||
|
@ -17,6 +24,52 @@ namespace CLre.API.Tools
|
||||||
{
|
{
|
||||||
isEnabled = false;
|
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]
|
[HarmonyPatch]
|
||||||
|
@ -35,7 +88,8 @@ namespace CLre.API.Tools
|
||||||
Utility.Logging.LogWarning("Network message data was deserialized as null");
|
Utility.Logging.LogWarning("Network message data was deserialized as null");
|
||||||
return;
|
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]
|
[HarmonyTargetMethod]
|
||||||
|
|
|
@ -62,6 +62,9 @@ namespace CLre
|
||||||
NetClientSender.GetLogMethod(netData));
|
NetClientSender.GetLogMethod(netData));
|
||||||
API.Utility.Logging.MetaLog("Patched SendMessage<Shared.Inventory.HandheldEquipmentRequest>");
|
API.Utility.Logging.MetaLog("Patched SendMessage<Shared.Inventory.HandheldEquipmentRequest>");
|
||||||
|
|
||||||
|
NetClientListener.DebugReceiveMessage(NetworkDispatcherCode.EACMessageServerToClient,
|
||||||
|
NetClientListener.Log);
|
||||||
|
|
||||||
// API debug and testing
|
// API debug and testing
|
||||||
API.App.Client.InitComplete += (_, __) =>
|
API.App.Client.InitComplete += (_, __) =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,11 +78,7 @@ namespace CLre.Fixes
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
object wcevOriginal = queryWCEV(toolId, baseGroup);
|
//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;
|
|
||||||
//API.Utility.Logging.MetaLog($"Cooling down? {isInCooldown} for {cooldownLeft}s");
|
//API.Utility.Logging.MetaLog($"Cooling down? {isInCooldown} for {cooldownLeft}s");
|
||||||
// build functions for querying all Game.Handhelds.WeaponCooldownEntityView objects
|
// build functions for querying all Game.Handhelds.WeaponCooldownEntityView objects
|
||||||
Type protoRaw =
|
Type protoRaw =
|
||||||
|
@ -109,23 +105,6 @@ namespace CLre.Fixes
|
||||||
isRunningTick = true;
|
isRunningTick = true;
|
||||||
cooldownTickEverything(characterId, cwcevExists, queryCWCEV, queryWCEV, queryAllWCEV, indexer, baseGroup).Run();
|
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]
|
[HarmonyTargetMethod]
|
||||||
|
@ -156,7 +135,9 @@ namespace CLre.Fixes
|
||||||
Traverse.Create(wcevOriginal).Field("weaponCooldownComponent").Property<bool>("isInCooldown").Value;
|
Traverse.Create(wcevOriginal).Field("weaponCooldownComponent").Property<bool>("isInCooldown").Value;
|
||||||
object[] indexParams = {0};
|
object[] indexParams = {0};
|
||||||
// iterate over other handhelds and sync their cooldowns to the held item
|
// 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}");
|
API.Utility.Logging.MetaDebugLog($"Syncing {count} weapon cooldowns with the held item {toolId}");
|
||||||
|
#endif
|
||||||
for (int index = 0; index < count; index++)
|
for (int index = 0; index < count; index++)
|
||||||
{
|
{
|
||||||
indexParams[0] = index;
|
indexParams[0] = index;
|
||||||
|
@ -175,7 +156,9 @@ namespace CLre.Fixes
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
// cleanup
|
// cleanup
|
||||||
|
#if DEBUG
|
||||||
API.Utility.Logging.MetaDebugLog("Custom cooldown ticks complete");
|
API.Utility.Logging.MetaDebugLog("Custom cooldown ticks complete");
|
||||||
|
#endif
|
||||||
isRunningTick = false;
|
isRunningTick = false;
|
||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue