Esempio n. 1
0
        private static void OpenGUI()
        {
            var appstate = new Application("org.AmongUsCapture.AmongUsCaptureUtil", GLib.ApplicationFlags.None);

            appstate.Register(GLib.Cancellable.Current);
            Application.Init();
            window = new UserForm(socket);
            appstate.AddWindow(window);
            Settings.form         = window;
            Settings.conInterface = new FormConsole(window);

            window.DeleteEvent += (object o, DeleteEventArgs e) =>
            {
                // Make sure that the IPC adapter has a chance to clean up after itself.
                IPCadapter.getInstance().Cancel().Wait();
                Application.Quit();
            };

            window.ShowAll();

            Application.Run();
            IPCadapter.getInstance().Cancel().Wait();

            Environment.Exit(0);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (Settings.PersistentSettings.debugConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }

            URIStartResult uriRes = HandleURIStart(args);

            if (uriRes == URIStartResult.CLOSE)
            {
                return;
            }

            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClientSocket socket = new ClientSocket();

            form                  = new UserForm(socket);
            Settings.form         = form;
            Settings.conInterface = new FormConsole(form);                                                                  //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Init()).Wait();                                                              // run socket in background. Important to wait for init to have actually finished before continuing
            Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop());                                             // run loop in background
            Task.Factory.StartNew(() => IPCadapter.getInstance().RunLoop(uriRes == URIStartResult.PARSE ? args[0] : null)); // Run listener for tokens

            //AllocConsole();
            Application.Run(form);

            //test
        }
Esempio n. 3
0
        /// <summary>
        ///     The main entry point for the application.
        /// </summary>
        public static void Main()
        {
            //Create the Form Console interface.
            var socketTask = Task.Factory.StartNew(() => socket.Init());        // run socket in background. Important to wait for init to have actually finished before continuing

            Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background
            socketTask.Wait();
            IPCadapter.getInstance().RegisterMinion();
        }
Esempio n. 4
0
        private static void Main(string[] args)
        {
            if (Settings.PersistentSettings.debugConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }
            var uriRes = IPCadapter.getInstance().HandleURIStart(args);

            switch (uriRes)
            {
            case URIStartResult.CLOSE:
                Environment.Exit(0);
                break;

            case URIStartResult.PARSE:
                Console.WriteLine($"Starting with args : {args[0]}");
                break;

            case URIStartResult.CONTINUE:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }



            var socket = new ClientSocket();

            //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Init()).Wait(); // run socket in background. Important to wait for init to have actually finished before continuing
            var thread = new Thread(OpenGUI);

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            while (Settings.conInterface is null)
            {
                Thread.Sleep(250);
            }
            //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Init())
            .Wait();     // run socket in background. Important to wait for init to have actually finished before continuing
            IPCadapter.getInstance().RegisterMinion();
            window.Loaded += (sender, eventArgs) =>
            {
                Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background
                if (uriRes == URIStartResult.PARSE)
                {
                    IPCadapter.getInstance().SendToken(args[0]);
                }
            };
            thread.Join();
        }
Esempio n. 5
0
        public void Init()
        {
            // Initialize a socket.io connection.
            socket = new SocketIO();

            // Handle tokens from protocol links.
            IPCadapter.getInstance().OnToken += OnTokenHandler;

            // Register handlers for game-state change events.
            GameMemReader.getInstance().GameStateChanged += GameStateChangedHandler;
            GameMemReader.getInstance().PlayerChanged    += PlayerChangedHandler;
            GameMemReader.getInstance().JoinedLobby      += JoinedLobbyHandler;

            // Handle socket connection events.
            socket.OnConnected += (sender, e) =>
            {
                // Report the connection
                //Settings.form.setConnectionStatus(true);
                Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, "Connected successfully!");


                // Alert any listeners that the connection has occurred.
                OnConnected?.Invoke(this, new ConnectedEventArgs()
                {
                    Uri = socket.ServerUri.ToString()
                });

                // On each (re)connection, send the connect code and then force-update everything.
                socket.EmitAsync("connectCode", ConnectCode).ContinueWith((_) =>
                {
                    Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan,
                                                                 $"Connection code ({Color.Red.ToTextColor()}{ConnectCode}{MainWindow.NormalTextColor.ToTextColor()}) sent to server.");
                    GameMemReader.getInstance().ForceUpdatePlayers();
                    GameMemReader.getInstance().ForceTransmitState();
                    GameMemReader.getInstance().ForceTransmitLobby();
                });
            };

            // Handle socket disconnection events.
            socket.OnDisconnected += (sender, e) =>
            {
                //Settings.form.setConnectionStatus(false);
                //Settings.conInterface.WriteTextFormatted($"[§bClientSocket§f] Lost connection!");
                Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan,
                                                             $"{Color.Red.ToTextColor()}Connection lost!");

                // Alert any listeners that the disconnection has occured.
                OnDisconnected?.Invoke(this, EventArgs.Empty);
            };
        }
Esempio n. 6
0
        public static IPCadapter getInstance()
        {
            if (instance == null)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // Use the RPC Buffer for Windows.
                    instance = new IPCadapterRpcBuffer();
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    // Use DBus for Linux.
                    instance = new IPCadapterDBus();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return(instance);
        }
Esempio n. 7
0
        private void _primaryWindowInstallLinkWindow_Dialog(object o, EventArgs e)
        {
            Gtk.Application.Invoke((sender, args) =>
            {
                var xdg_path = System.IO.Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                   "applications");
                var xdg_file = System.IO.Path.Join(xdg_path, "aucapture-opener.desktop");
                string info  = String.Empty;

                var InstallLinkDialogBox = new MessageDialog(this,
                                                             DialogFlags.Modal,
                                                             MessageType.Question,
                                                             ButtonsType.None,
                                                             false,
                                                             String.Empty);

                if (!File.Exists(xdg_file) && !Settings.PersistentSettings.skipHandlerInstall)
                {
                    info +=
                        "Would you like to enable support for AutoMuteUs one-click connection?" +
                        "This will allow you to use the links provided by AutoMuteUs to connect the capture to the bot automatically.\n\n" +
                        "The following operations will be performed:\n\n" +
                        $"- The following .desktop file will be installed: {xdg_file}\n\n" +
                        "- The following command will be run to link the 'aucapture:' URI to the program:\n\n \'xdg-mime default aucapture-opener.desktop x-scheme-handler/aucapture\'" +
                        "\n\nIf you decline, Discord connection links will not be functional." +
                        "\n\nYou can install or manage One-Click support by using the \"One-Click Connection Management\" link in the File menu.";

                    InstallLinkDialogBox.Text  = info;
                    InstallLinkDialogBox.Title = "Enable One-Click Connection?";
                    InstallLinkDialogBox.AddButton("Cancel", ResponseType.Reject);
                    InstallLinkDialogBox.AddButton("Install", ResponseType.Accept);

                    InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
                    {
                        if (responseArgs.ResponseId == ResponseType.Reject)
                        {
                            // Make sure we have the setting to ignore the dialog box set.
                            Settings.PersistentSettings.skipHandlerInstall = true;
                        }

                        if (responseArgs.ResponseId == ResponseType.Accept)
                        {
                            IPCadapter.getInstance().InstallHandler();
                        }
                    };
                }
                else
                {
                    info += "This menu manages the One-Click Connection link system.\n\n";

                    info += "One-Click Connection Status: ";
                    if (File.Exists(xdg_file))
                    {
                        info += "Enabled\n\n";
                    }
                    else
                    {
                        info += "Disabled\n\n";
                    }

                    info += $"Runner (.desktop) Installation Path: ";
                    if (File.Exists(xdg_file))
                    {
                        info += xdg_file;
                    }
                    else
                    {
                        info += "Not Found";
                    }

                    InstallLinkDialogBox.Text += info;
                    InstallLinkDialogBox.Title = "Manage One-Click Connection";
                    InstallLinkDialogBox.AddButton("Cancel", ResponseType.Close);
                    InstallLinkDialogBox.AddButton("Uninstall", ResponseType.Reject);
                    InstallLinkDialogBox.AddButton("Reinstall", ResponseType.Accept);

                    InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
                    {
                        if (responseArgs.ResponseId == ResponseType.Reject)
                        {
                            // Make sure we have the setting to ignore the dialog box set.
                            IPCadapter.getInstance().RemoveHandler();
                        }

                        if (responseArgs.ResponseId == ResponseType.Accept)
                        {
                            IPCadapter.getInstance().InstallHandler();
                        }
                    };
                }

                InstallLinkDialogBox.ShowAll();
                InstallLinkDialogBox.Run();
                InstallLinkDialogBox.Dispose();
            });
        }
Esempio n. 8
0
        private static void Main(string[] args)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Settings.PersistentSettings.debugConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }
            if (!Directory.Exists(Settings.StorageLocation))
            {
                // Create Settings directory if it doesn't exist, as we need to stick our pidfile there.
                Directory.CreateDirectory(Settings.StorageLocation);
            }

            URIStartResult uriRes = URIStartResult.CLOSE;

            uriRes = IPCadapter.getInstance().HandleURIStart(args);
            switch (uriRes)
            {
            case URIStartResult.CLOSE:
                Environment.Exit(0);
                break;

            case URIStartResult.PARSE:
                Console.WriteLine($"Starting with args : {args[0]}");
                break;

            case URIStartResult.CONTINUE:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            socket = new ClientSocket();

            //Create the Form Console interface.
            var thread = new Thread(OpenGUI);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                thread.SetApartmentState(ApartmentState.STA);
            }
            thread.Start();
            while (Settings.conInterface is null)
            {
                Thread.Sleep(250);
            }
            Task.Factory.StartNew(() => socket.Init())
            .Wait();     // run socket in background. Important to wait for init to have actually finished before continuing
            Task.Factory.StartNew(() => IPCadapter.getInstance().RegisterMinion()).Wait();

            // Add a GLib Idle handler to fix the issue here.
            Idle.Add(delegate
            {
                Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background
                if (uriRes == URIStartResult.PARSE)
                {
                    IPCadapter.getInstance().SendToken(args[0]);
                }
                return(false);
            });

            thread.Join();
        }