Use dictionary for mod lookup

This commit is contained in:
js6pak committed 2021-04-04 22:26:55 +02:00
1 parent eb299fef1d
commit f59e989afc
2 files changed
+18 -2

No files matched your search

+2 -2
View File
@@ -61,7 +61,7 @@ namespace Reactor.Networking
true => AmongUsClient.Instance.StartRpcImmediately(netObject.NetId, CustomRpcManager.CallId, SendOption, targetClientId)
};
var pluginNetId = ModList.Current.Single(x => x.Id == PluginId).NetId;
var pluginNetId = ModList.GetById(PluginId).NetId;
writer.WritePacked(pluginNetId);
writer.WritePacked(Id);
@@ -198,7 +198,7 @@ namespace Reactor.Networking
var pluginNetId = reader.ReadPackedUInt32();
var id = reader.ReadPackedUInt32();
var pluginId = ModList.Current.Single(x => x.NetId == pluginNetId).Id;
var pluginId = ModList.GetByNetId(pluginNetId).Id;
var customRpc = customRpcs.Single(x => x.PluginId == pluginId && x.Id == id);
customRpc.UnsafeHandle(__instance, customRpc.UnsafeRead(reader.ReadMessage()));
+16
View File
@@ -7,8 +7,21 @@ namespace Reactor.Networking
{
public static class ModList
{
private static Dictionary<string, Mod> _mapById;
private static Dictionary<uint, Mod> _mapByNetId;
public static ISet<Mod> Current { get; private set; }
public static Mod GetById(string id)
{
return _mapById[id];
}
public static Mod GetByNetId(uint netId)
{
return _mapByNetId[netId];
}
internal static void Update()
{
var i = (uint) 0;
@@ -22,6 +35,9 @@ namespace Reactor.Networking
plugin.Instance.GetType().GetCustomAttribute<ReactorPluginSideAttribute>()?.Side ?? PluginSide.Both
))
.ToHashSet();
_mapById = Current.ToDictionary(mod => mod.Id, mod => mod);
_mapByNetId = Current.ToDictionary(mod => mod.NetId, mod => mod);
}
}
}