public void RegisterCommandModule(Type moduleType, ITorchPlugin plugin = null) { if (!moduleType.IsSubclassOf(typeof(CommandModule))) { return; } foreach (var method in moduleType.GetMethods()) { var commandAttrib = method.GetCustomAttribute <CommandAttribute>(); if (commandAttrib == null) { continue; } var command = new Command(plugin, method); var cmdPath = string.Join(".", command.Path); _log.Info($"Registering command '{cmdPath}'"); if (!Commands.AddCommand(command)) { _log.Error($"Command path {cmdPath} is already registered."); } } }
public MultigridProjectorTorchAgent(ITorchSession torchSession) { var pluginManager = torchSession.Managers.GetManager <PluginManager>(); if (!pluginManager.Plugins.TryGetValue(PluginId, out var plugin)) { return; } Api = plugin.GetType().GetProperty("Api")?.GetValue(plugin); if (Api == null) { return; } var apiType = Api.GetType(); Version = (string)apiType.GetProperty("Version")?.GetValue(Api); if (Version == null || !Version.StartsWith(CompatibleMajorVersion)) { return; } _miGetSubgridCount = apiType.GetMethod("GetSubgridCount", BindingFlags.Instance | BindingFlags.Public); _miGetOriginalGridBuilders = apiType.GetMethod("GetOriginalGridBuilders", BindingFlags.Instance | BindingFlags.Public); _miGetPreviewGrid = apiType.GetMethod("GetPreviewGrid", BindingFlags.Instance | BindingFlags.Public); _miGetBuiltGrid = apiType.GetMethod("GetBuiltGrid", BindingFlags.Instance | BindingFlags.Public); _miGetBlockState = apiType.GetMethod("GetBlockState", BindingFlags.Instance | BindingFlags.Public); _miGetBlockStates = apiType.GetMethod("GetBlockStates", BindingFlags.Instance | BindingFlags.Public); _miGetBaseConnections = apiType.GetMethod("GetBaseConnections", BindingFlags.Instance | BindingFlags.Public); _miGetTopConnections = apiType.GetMethod("GetTopConnections", BindingFlags.Instance | BindingFlags.Public); Plugin = plugin; }
private void GridBackupConnection(PluginManager Plugins) { Guid GridBackupGUID = new Guid("75e99032-f0eb-4c0d-8710-999808ed970c"); Plugins.Plugins.TryGetValue(GridBackupGUID, out ITorchPlugin BlockLimiterT); if (BlockLimiterT != null) { Hangar.Debug("Plugin: " + BlockLimiterT.Name + " " + BlockLimiterT.Version + " is installed!"); try { //Grab refrence to TorchPluginBase class in the plugin GridBackup = BlockLimiterT; if (GridBackup != null) { Log.Debug("Successfully attached to GridBackup!"); } //Example Method call //object value = CandAddMethod.Invoke(Class, new object[] { grid }); //Convert to value return type Log.Info("GridBackup Reference added to backup grids upon hangar save!"); } catch (Exception e) { Log.Warn(e, "Could not connect to GridBackup Plugin."); } } }
public CommandContext(ITorchBase torch, ITorchPlugin plugin, IMyPlayer player, string rawArgs = null, List <string> args = null) { Torch = torch; Plugin = plugin; Player = player; RawArgs = rawArgs; Args = args ?? new List <string>(); }
public CommandContext(ITorchBase torch, ITorchPlugin plugin, ulong steamIdSender, string rawArgs = null, List <string> args = null) { Torch = torch; Plugin = plugin; _steamIdSender = steamIdSender; RawArgs = rawArgs; Args = args ?? new List <string>(); }
public void RegisterPluginCommands(ITorchPlugin plugin) { var assembly = plugin.GetType().Assembly; foreach (var type in assembly.ExportedTypes) { RegisterCommandModule(type, plugin); } }
private static void AquireGridBackup(ITorchPlugin Plugin) { Type GridBackupType = DeclareInstalledPlugin(Plugin); BackupGridBuilders = GridBackupType.GetMethod("BackupGridsManuallyWithBuilders", BindingFlags.Public | BindingFlags.Instance, null, new Type[2] { typeof(List <MyObjectBuilder_CubeGrid>), typeof(long) }, null); GridBackupRef = Plugin; BlockLimiterInstalled = true; }
public PluginViewModel(ITorchPlugin plugin) { Plugin = plugin; if (Plugin is IWpfPlugin p) { Control = p.GetControl(); } Name = $"{plugin.Name} ({plugin.Version})"; }
public PluginViewModel(ITorchPlugin plugin) { Plugin = plugin; if (Plugin is IWpfPlugin p) { Control = p.GetControl(); } Name = $"{plugin.Name} ({plugin.Version})"; ThemeControl.UpdateDynamicControls += UpdateResourceDict; UpdateResourceDict(ThemeControl.currentTheme); }
private void Initialize() { _init = true; Instance = this; foreach (var plugin in DamageWavePlugin.Instance.Torch.Managers.GetManager <PluginManager>()) { if (plugin.Id == Guid.Parse("17f44521-b77a-4e85-810f-ee73311cf75d")) //find concealment { concealment = plugin; ReflectMethodRevealAll = plugin.GetType().GetMethod("RevealAll", BindingFlags.Public | BindingFlags.Instance); } } }
private static void AquireNexus(ITorchPlugin Plugin) { Type NexusMain = DeclareInstalledPlugin(Plugin); Type ReflectedServerSideAPI = NexusMain?.Assembly.GetType("Nexus.API.PluginAPISync"); if (ReflectedServerSideAPI == null) { return; } ReflectedServerSideAPI.GetMethod("ApplyPatching", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { typeof(NexusAPI), "QuantumHangar" }); NexusSupport.Init(); NexusInstalled = true; }
public PluginViewModel(ITorchPlugin plugin) { Plugin = plugin; if (Plugin is IWpfPlugin p) { try { Control = p.GetControl(); } catch (Exception ex) { _log.Error(ex, $"Exception loading interface for plugin {Plugin.Name}! Plugin interface will not be available!"); Control = null; } } Name = $"{plugin.Name} ({plugin.Version})"; ThemeControl.UpdateDynamicControls += UpdateResourceDict; UpdateResourceDict(ThemeControl.currentTheme); }
public Command(string name, string description, CommandAction action, ITorchPlugin plugin, MyPromoteLevel?minimumPromoteLevel = null, string helpText = null, int requiredParamCount = 0) { HelpText = helpText; Action = action; Plugin = plugin; MinimumPromoteLevel = minimumPromoteLevel ?? MyPromoteLevel.Admin; var split = name.Split(' '); Name = split.Last(); Description = description; HelpText = helpText ?? description; Path.AddRange(split); var sb = new StringBuilder(); sb.Append($"!{string.Join(" ", Path)} "); _requiredParamCount = requiredParamCount; Log.Debug($"Params: ({_requiredParamCount} required)"); SyntaxHelp = sb.ToString(); }
public PluginViewModel(ITorchPlugin plugin) { Plugin = plugin; Name = $"{plugin.Name} ({plugin.Version})"; }
public Command(ITorchPlugin plugin, MethodInfo commandMethod) { Plugin = plugin; var commandAttribute = commandMethod.GetCustomAttribute <CommandAttribute>(); if (commandAttribute == null) { throw new TypeLoadException($"Method does not have a {nameof(CommandAttribute)}"); } var permissionAttribute = commandMethod.GetCustomAttribute <PermissionAttribute>(); MinimumPromoteLevel = permissionAttribute?.PromoteLevel ?? MyPromoteLevel.None; if (!commandMethod.DeclaringType.IsSubclassOf(typeof(CommandModule))) { throw new TypeLoadException($"Command {commandMethod.Name}'s declaring type {commandMethod.DeclaringType.FullName} is not a subclass of {nameof(CommandModule)}"); } var moduleAttribute = commandMethod.DeclaringType.GetCustomAttribute <CategoryAttribute>(); _method = commandMethod; Module = commandMethod.DeclaringType; if (moduleAttribute != null) { Path.AddRange(moduleAttribute.Path); } Path.AddRange(commandAttribute.Path); Name = commandAttribute.Name; Description = commandAttribute.Description; HelpText = commandAttribute.HelpText; //parameters _parameters = commandMethod.GetParameters(); var sb = new StringBuilder(); sb.Append($"/{string.Join(" ", Path)} "); for (var i = 0; i < _parameters.Length; i++) { var param = _parameters[i]; if (param.HasDefaultValue) { _requiredParamCount = _requiredParamCount ?? i; sb.Append($"[{param.ParameterType.Name} {param.Name}] "); } else { sb.Append($"<{param.ParameterType.Name} {param.Name}> "); } } _requiredParamCount = _requiredParamCount ?? _parameters.Length; LogManager.GetLogger(nameof(Command)).Debug($"Params: {_parameters.Length} ({_requiredParamCount} required)"); SyntaxHelp = sb.ToString(); }
private static void AquireBlockLimiter(ITorchPlugin Plugin) { Type BlockLimiterType = DeclareInstalledPlugin(Plugin); CheckFutureLimits = BlockLimiterType.GetMethod("CheckLimits_future"); }
private static Type DeclareInstalledPlugin(ITorchPlugin Plugin) { Log.Info("Plugin: " + Plugin.Name + " " + Plugin.Version + " is installed!"); return(Plugin.GetType()); }
public void UnregisterPluginCommands(ITorchPlugin plugin) { // TODO }
/// <inheritdoc /> public RconCommandContext(ITorchBase torch, ITorchPlugin plugin, ulong steamIdSender, string rawArgs = null, List <string> args = null) : base(torch, plugin, steamIdSender, rawArgs, args) { }
/// <inheritdoc /> public SEDBCommandHandler(ITorchBase torch, ITorchPlugin plugin, ulong steamIdSender, string rawArgs = null, List <string> args = null) : base(torch, plugin, steamIdSender, rawArgs, args) { }