public void Register(PublicCommand cmd, PulsarMod mod) { foreach (string alias in cmd.CommandAliases()) { string lowerAlias = alias.ToLower(); if (conflictingPublicAliases.TryGetValue(lowerAlias, out PulsarMod mod2)) { string name = mod != null ? mod.Name : "Pulsar Mod Loader"; string name2 = mod2 != null ? mod2.Name : "Pulsar Mod Loader"; Logger.Info($"Conflicting public alias: {lowerAlias} from {name} and {name2}"); } else { if (publicCommands.TryGetValue(lowerAlias, out Tuple <PublicCommand, PulsarMod> t)) { conflictingPublicAliases.Add(lowerAlias, mod); publicCommands.Remove(lowerAlias); string name = mod != null ? mod.Name : "Pulsar Mod Loader"; string name2 = t.Item2 != null ? t.Item2.Name : "Pulsar Mod Loader"; Logger.Info($"Conflicting public alias: {lowerAlias} from {name} and {name2}"); } else { publicCommands.Add(lowerAlias, new Tuple <PublicCommand, PulsarMod>(cmd, mod)); } } } }
public void Unregister(PulsarMod mod) { List <string> commandsToRemove = new List <string>(); foreach (var command in commands) { if (command.Value.Item2 == mod) { commandsToRemove.Add(command.Key); } } foreach (var command in commandsToRemove) { commands.Remove(command); } commandsToRemove.Clear(); foreach (var command in publicCommands) { if (command.Value.Item2 == mod) { commandsToRemove.Add(command.Key); } } foreach (var command in commandsToRemove) { publicCommands.Remove(command); } }
//Called for every mod loaded public static void RegisterEventHandlers(string name, PulsarMod mod) { Assembly asm = mod.GetType().Assembly; foreach (Type classType in asm.GetTypes()) { foreach (MethodInfo method in classType.GetMethods()) { ParameterInfo[] param = method.GetParameters(); if (method.GetCustomAttributes(typeof(EventHandler), false).Any() && method.ReturnType == typeof(void) && param.Count() == 1 && (param[0].ParameterType.IsSubclassOf(typeof(Event)) || param[0].ParameterType == typeof(Event))) { if (EventHandlers.TryGetValue(param[0].ParameterType, out List <MethodInfo> methods)) { methods.Add(method); } else { methods = new List <MethodInfo> { method }; EventHandlers.Add(param[0].ParameterType, methods); } } } } }
void UpdateOnModLoaded(string modName, PulsarMod mod) { mods.Add(mod); var modsettingstype = typeof(ModSettingsMenu); mod.GetType().Assembly.GetTypes().AsParallel().ForAll((type) => { if (modsettingstype.IsAssignableFrom(type)) { #if DEBUG Utilities.Logger.Info($"Loaded new settings! {type.FullName}"); #endif settings.Add(Activator.CreateInstance(type) as ModSettingsMenu); } }); }
private void LoadCommandsFromAssembly(Assembly asm, PulsarMod mod) { Type ChatCmd = typeof(ChatCommand); Type PublicCmd = typeof(PublicCommand); foreach (Type t in asm.GetTypes()) { if (ChatCmd.IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface) { Register((ChatCommand)Activator.CreateInstance(t), mod); } else if (PublicCmd.IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface) { Register((PublicCommand)Activator.CreateInstance(t), mod); } } }
void UpdateOnModRemoved(PulsarMod mod) { selectedMod = ushort.MaxValue; mods.Remove(mod); List <ModSettingsMenu> settingsToRemove = new List <ModSettingsMenu>(); Assembly asm = mod.GetType().Assembly; settings.AsParallel().ForAll((arg) => { if (arg.GetType().Assembly == asm) { settingsToRemove.Add(arg); } }); for (byte s = 0; s < settingsToRemove.Count; s++) { settings.Remove(settingsToRemove[s]); } settingsToRemove = null; }
public override void Execute(string arguments) { PhotonPlayer player = PLNetworkManager.Instance.LocalPlayer.GetPhotonPlayer(); int page = 1; if (!string.IsNullOrWhiteSpace(arguments)) { if (!int.TryParse(arguments, out page)) { PulsarMod mod = ModManager.Instance.GetMod(arguments); if (mod == null) { foreach (PulsarMod p in ModManager.Instance.GetAllMods()) { if (p.HarmonyIdentifier().ToLower() == arguments.ToLower()) { mod = p; break; } } } if (mod != null) { Messaging.Echo(player, $"[&%~[C4 {mod.Name} ]&%~] - {mod.ShortDescription}"); Messaging.Echo(player, $"Version: {mod.Version}"); if (!string.IsNullOrWhiteSpace(mod.LongDescription)) { Messaging.Echo(player, mod.LongDescription); } } else { Messaging.Echo(player, $"Mod {arguments} not found"); } return; } } int modsPerPage = (PLXMLOptionsIO.Instance.CurrentOptions.GetStringValueAsInt("ChatNumLines") * 5 + 10) - 2; IOrderedEnumerable <PulsarMod> mods = ModManager.Instance.GetAllMods().OrderBy(t => t.Name); int pages = Mathf.CeilToInt(mods.Count() / (float)modsPerPage); page--; //Pages start from 1 if (page < 0) { page = 0; } Messaging.Echo(player, pages == 1 && page == 0 ? "[&%~[C4 Mod List: ]&%~] :" : $"[&%~[C4 Mod List: ]&%~] Page {page + 1} : {pages}"); for (int i = 0; i < modsPerPage; i++) { int index = i + page * modsPerPage; if (i + page * modsPerPage >= mods.Count()) { break; } PulsarMod mod = mods.ElementAt(index); Messaging.Echo(player, $"{mod.Name} - {mod.ShortDescription}"); } Messaging.Echo(player, "Use [&%~[C2 /mod <mod> ]&%~] for details about a specific mod"); }
public void RegisterReaderAndWriter(PulsarMod plugin, Action <BinaryReader> reader, Action <BinaryWriter> writer) { Readers.Add(plugin.Name, reader); Writers.Add(plugin.Name, writer); }
public void RegisterWriter(PulsarMod plugin, Action <BinaryWriter> writer) => Writers.Add(plugin.Name, writer);
public void RegisterReader(PulsarMod plugin, Action <BinaryReader> reader) => Readers.Add(plugin.Name, reader);
public void OnModLoaded(string name, PulsarMod mod) { Assembly asm = mod.GetType().Assembly; LoadCommandsFromAssembly(asm, mod); }
void WindowFunction(int WindowID) { BeginHorizontal(); // TAB Start { if (Button("Mod Info")) { Tab = 0; } if (Button("Mod Settings")) { Tab = 1; } if (Button("About")) { Tab = 2; } } EndHorizontal(); // TAB End switch (Tab) { #region ModList and ModInfo case 0: GUI.skin.label.alignment = PMLConfig.instance.ModInfoTextAnchor; BeginArea(ModListArea); { ModListScroll = BeginScrollView(ModListScroll); { for (ushort p = 0; p < mods.Count; p++) { if (Button(mods[p].Name)) { selectedMod = p; } } } EndScrollView(); } EndArea(); BeginArea(ModInfoArea); { if (selectedMod != ushort.MaxValue) { ModInfoScroll = BeginScrollView(ModInfoScroll); { PulsarMod mod = mods[selectedMod]; BeginHorizontal(); { if (Button("Unload")) { mod.Unload(); } } EndHorizontal(); Label($"Author: {mod.Author}"); Label($"Name: {mod.Name}"); Label($"Version: {mod.Version}"); if (mod.ShortDescription != string.Empty) { Label($"Short Description: {mod.ShortDescription}"); } if (mod.LongDescription != string.Empty) { Label($"Long Description: {mod.LongDescription}"); } Label($"MPFunctionality: {((MPFunction)mod.MPFunctionality).ToString()}"); } EndScrollView(); } } EndArea(); break; #endregion #region ModSettings case 1: GUI.skin.label.alignment = TextAnchor.UpperLeft; BeginArea(ModSettingsArea); { ModSettingsScroll = BeginScrollView(ModSettingsScroll); { if (selectedSettings == ushort.MaxValue) { for (ushort msm = 0; msm < settings.Count; msm++) { if (Button(settings[msm].Name())) { settings[msm].OnOpen(); selectedSettings = msm; break; } } } else { if (Button("Back")) { settings[selectedSettings].OnClose(); selectedSettings = ushort.MaxValue; } else { settings[selectedSettings].Draw(); } } } EndScrollView(); } EndArea(); break; #endregion #region About case 2: GUI.skin.label.alignment = TextAnchor.MiddleCenter; Label($"PulsarModLoader - Unofficial mod loader for PULSAR: Lost Colony."); Label($"Version: {ModManager.Instance.PMLVersionInfo.FileVersion}"); Label($"\n\nDeveloped by Tom Richter"); Label($"Contributors:\nDragonFire47\n18107\nBadRyuner"); BeginHorizontal(); if (Button("Github")) { Process.Start("https://github.com/PULSAR-Modders/pulsar-mod-loader"); } if (Button("Discord")) { Process.Start("https://discord.gg/j3Pydn6"); } EndHorizontal(); break; #endregion } GUI.DragWindow(); }