2023-07-29 00:26:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-08-03 21:55:21 +00:00
|
|
|
|
using OWML.Common;
|
2023-07-29 00:26:12 +00:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
|
|
|
|
|
namespace QSB.API;
|
|
|
|
|
|
|
|
|
|
public static class AddonDataManager
|
|
|
|
|
{
|
2023-08-03 21:55:21 +00:00
|
|
|
|
private static readonly Dictionary<int, Action<uint, object>> _handlers = new();
|
2023-07-29 00:26:12 +00:00
|
|
|
|
|
2023-08-03 21:55:21 +00:00
|
|
|
|
public static void OnReceiveDataMessage(int hash, object data, uint from)
|
2023-07-29 00:26:12 +00:00
|
|
|
|
{
|
2023-08-03 21:55:21 +00:00
|
|
|
|
if (!_handlers.TryGetValue(hash, out var handler))
|
2023-07-29 00:26:12 +00:00
|
|
|
|
{
|
2023-08-03 21:55:21 +00:00
|
|
|
|
DebugLog.DebugWrite($"unknown addon message type with hash {hash}", MessageType.Error);
|
2023-08-23 23:03:51 +00:00
|
|
|
|
return;
|
2023-07-29 00:26:12 +00:00
|
|
|
|
}
|
2023-07-30 10:23:11 +00:00
|
|
|
|
handler(from, data);
|
2023-07-29 00:26:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 21:55:21 +00:00
|
|
|
|
public static void RegisterHandler<T>(int hash, Action<uint, T> handler)
|
2023-07-29 00:26:12 +00:00
|
|
|
|
{
|
2023-08-03 21:55:21 +00:00
|
|
|
|
_handlers.Add(hash, (from, data) => handler(from, (T)data));
|
2023-07-29 00:26:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|