private void AddReceiver(LoadedMod parent, Type eventType, MethodInfo receiver, int priority) { List <ReceiverSwitch> list; if (!_receivers.TryGetValue(eventType, out list)) { list = new List <ReceiverSwitch>(); _receivers.Add(eventType, list); } var idx = -1; for (var i = 0; i < list.Count; i++) { if (priority > list[i].Priority) { idx = i; break; } } var @switch = new ReceiverSwitch { Mod = parent, Info = receiver, Priority = priority, Enabled = true }; if (idx == -1) { list.Add(@switch); } else { list.Insert(idx, @switch); } }
public void AddReceiver(LoadedMod mod) { foreach (var sub in mod.AssemblyMods) { foreach (var entry in sub.CallMap) { foreach (var @switch in entry.Value) { AddReceiver(sub.Instance, entry.Key, @switch.Info, @switch.Priority); } } } Mods.Add(mod); }
private void LoadMod(List <LoadedMod> result, string path) { var manifestPath = Path.Combine(path, "manifest.json"); /* I thought about allowing mods without manifests, but it's unnecessary */ /* just include a manifest.json with ur mods gee - Handsome Matt */ if (!File.Exists(manifestPath)) { return; } var manifest = JsonConvert.DeserializeObject <JsonModManifest>(File.ReadAllText(manifestPath)); if (manifest.Properties != null && manifest.Properties.Path == null) { manifest.Properties.Path = path; } var dllPath = string.Empty; if (!string.IsNullOrEmpty(manifest.AssemblyFileName)) { dllPath = Path.Combine(path, manifest.AssemblyFileName); } /* if we have an assembly to load, let's do it */ var assemblyMods = new List <AssemblyMod>(); if (!string.IsNullOrEmpty(dllPath) && File.Exists(dllPath)) { var loaded = LoadModsFromAssembly(Assembly.UnsafeLoadFrom(dllPath)); loaded.ForEach(m => m.LoadDirectory = path); assemblyMods.AddRange(loaded); } var mod = new LoadedMod(manifest, assemblyMods); result.Add(mod); Logging.DebugLogs("[{0}] Loaded mod {1} {3} by {2}", GetType().Name, mod.Name, mod.Author, mod.Version); }
public AssemblyMod(LoadedMod parent, object instance, Dictionary <string, List <MethodInfo> > callMap) { ParentMod = parent; Instance = instance; CallMap = callMap; }
public void RemoveReceiver(LoadedMod mod) { Mods.Remove(mod); }
public void AddReceiver(LoadedMod mod) { Mods.Add(mod); }
public AssemblyMod(LoadedMod parent, object instance, Dictionary <string, List <ReceiverSwitch> > callMap) { ParentMod = parent; Instance = instance; CallMap = callMap; }