public LauncherWindow() { try { this.InitializeComponent(); Common.Initialize(); this.args = (String[])Application.Current.Resources["args"]; if (args == null) { throw new InvalidOperationException("The Application was launched improperly. Resources('args') are missing."); } this.Title = this.args.Aggregate(this.Title, (a, b) => a + " " + b); } catch (Exception e) { MessageBox.Show(e.ToString(), e.GetType().Name); } }
private static void StartDirect(String[] args) { try { Common.Initialize(); switch (args.First()) { case "-game": Common.StartGame(args.Skip(1).ToArray()); break; case "-editor": Common.StartEditor(args.Skip(1).ToArray()); break; default: throw new ArgumentException(@"Invalid start argument: """ + args[0] + @""", valid arguments are ""-game"" or ""-editor"""); } } catch (Exception e) { MessageBox.Show(e.ToString(), e.GetType().Name); } }
public static void StartGame(String[] args) { if (!Common.IsInitialized) { Common.Initialize(); } if (!File.Exists(Common.GamePath)) { throw new FileNotFoundException("Could not find war3.exe!" + Environment.NewLine + "You may need to verify your registry settings are correct.", "war3.exe"); } if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "SharpCraft.dll"))) { throw new FileNotFoundException("Could not find SharpCraft.dll!" + Environment.NewLine + "You may need to redownload SharpCraft.", "SharpCraft.dll"); } Boolean kill = false; Boolean debug = false; Boolean valid = true; while (valid && args.Length > 0) { switch (args[0]) { case "-kill": kill = true; args = args.Skip(1).ToArray(); break; case "-debug": debug = true; args = args.Skip(1).ToArray(); break; default: valid = false; break; } } var war3s = Process.GetProcessesByName("war3"); if (war3s.Count() > 0) { if (kill) { foreach (var war3 in war3s) { war3.Kill(); } } else { throw new InvalidOperationException("Warcraft III is already running!" + Environment.NewLine + "You may need to check Task Manager for \"war3.exe\", and kill it."); } } Console.Write("Creating and injecting into Warcraft III . . . "); var cmd = '"' + Common.GamePath + '"'; if (args.Length > 0) { cmd += ' ' + args.Aggregate((a, b) => a + ' ' + b); } Int32 processId; RemoteHooking.CreateAndInject(Common.GamePath, cmd, 0, "SharpCraft.dll", "SharpCraft.dll", out processId, PluginContext.Game, debug, Environment.CurrentDirectory, Common.InstallPath); Console.WriteLine("Done!"); }
public static void StartEditor(string[] args) { if (!Common.Initialize()) { return; } if (!File.Exists(Common.EditorPath)) { throw new FileNotFoundException("Could not find worldedit.exe!" + Environment.NewLine + "You may need to verify your registry settings are correct.", "worldedit.exe"); } if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "SharpCraft.dll"))) { throw new FileNotFoundException("Could not find SharpCraft.dll!" + Environment.NewLine + "You may need to redownload SharpCraft.", "SharpCraft.dll"); } bool kill = false; bool debug = false; bool valid = true; while (valid && args.Length > 0) { switch (args[0]) { case "-kill": kill = true; args = args.Skip(1).ToArray(); break; case "-debug": debug = true; args = args.Skip(1).ToArray(); break; default: valid = false; break; } } var worldedits = Process.GetProcessesByName("worldedit"); if (worldedits.Count() > 0) { if (kill) { foreach (var worldedit in worldedits) { worldedit.Kill(); } } else { throw new InvalidOperationException("World Editor is already running!" + Environment.NewLine + "You may need to check Task Manager for \"worldedit.exe\", and kill it."); } } Console.Write("Creating and injecting into World Editor . . . "); string cmd = String.Empty; if (args.Length > 0) { cmd = args.Aggregate((a, b) => a + ' ' + b); } int processId; RemoteHooking.CreateAndInject(Common.EditorPath, cmd, 0, "SharpCraft.dll", "SharpCraft.dll", out processId, PluginContext.Editor, debug, Environment.CurrentDirectory, Common.InstallPath); Console.WriteLine("Done!"); }