mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
Use dictionary for mod lookup
This commit is contained in:
1 parent
eb299fef1d
commit
f59e989afc
2 files changed
+18
-2
No files matched your search
@@ -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()));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user