Exemplo n.º 1
0
        public static T LoadConfiguration <T>(string?configFile = null, IPluginHostDelegates hostDelegates = null) where T : class, new()
        {
            if (configFile == null)
            {
                configFile = GetConfigFile(typeof(T).Assembly);
            }

            try
            {
                if (File.Exists(configFile))
                {
                    using (FileStream fs = new FileStream(configFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
                        return(JsonSerializer.DeserializeAsync <T>(fs, JSO).Result);
                }
                else
                {
                    return(new T()); // File did not exist, just return a new instance.
                }
            }
            catch (Exception ex)
            {
                if (hostDelegates != null)
                {
                    try { hostDelegates.ExceptionMessage.Invoke(ex); }
                    catch { }
                }
                return(new T()); // An exception occurred when reading the file, return a new instance.
            }
        }
Exemplo n.º 2
0
 public int Startup(IPluginHostDelegates hostDelegates)
 {
     _hostDelegates = hostDelegates;
     _memoryScanner = new GameMemoryMGUScanner(GetProcess());
     _stopwatch     = new Stopwatch();
     _stopwatch.Start();
     return(0);
 }
 public int Startup(IPluginHostDelegates hostDelegates)
 {
     this.hostDelegates = hostDelegates;
     processId          = GetProcessId();
     gameMemoryScanner  = new GameMemoryRE7Scanner(processId);
     stopwatch          = new Stopwatch();
     stopwatch.Start();
     return(0);
 }
Exemplo n.º 4
0
 public int Startup(IPluginHostDelegates hostDelegates)
 {
     this.hostDelegates = hostDelegates;
     processId          = Process.GetProcessesByName("re7")?.FirstOrDefault()?.Id;
     gameMemoryScanner  = new GameMemoryRE7Scanner(processId);
     stopwatch          = new Stopwatch();
     stopwatch.Start();
     return(0);
 }
        public int Startup(IPluginHostDelegates hostDelegates)
        {
            SRTPluginUIJSON.hostDelegates = hostDelegates;

            // Start the JSON server for listening for new reqeusts.
            cancellationTokenSource = new CancellationTokenSource();
            jsonServer     = new JSONServer();
            jsonServerTask = jsonServer?.Start(cancellationTokenSource.Token);

            // Return success.
            return(0);
        }
        public int Startup(IPluginHostDelegates hostDelegates)
        {
            this.hostDelegates = hostDelegates;

            Program.Main(new string[0]);

            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            applicationContext = new ApplicationContext(new MainUI());
            applicationTask    = Task.Run(() => Application.Run(applicationContext));

            return(0);
        }
Exemplo n.º 7
0
        public override int Startup(IPluginHostDelegates hostDelegates)
        {
            _hostDelegates = hostDelegates;
            Config         = LoadConfiguration <PluginConfig>();

            try
            {
                GenerateClipping();
                InitializeOverlay();
            }
            catch (Exception ex)
            {
                _hostDelegates.ExceptionMessage(ex);
                _characterToImageTranslation = null;

                _graphics?.Dispose();
                _graphics = null;
                _window?.Dispose();
                _window = null;

                _isOverlayInitialized = false;
                _isOverlayReady       = false;

                return(1);
            }

            try
            {
                Thread t = new Thread(new ThreadStart(() =>
                {
                    _windowEventDispatcher = Dispatcher.CurrentDispatcher;
                    Dispatcher.Run();
                }));

                t.IsBackground = true;
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
            }
            catch (Exception ex)
            {
                _hostDelegates.ExceptionMessage(ex);
                _windowEventDispatcher = null;
            }

            return(0);
        }
Exemplo n.º 8
0
        public override int Startup(IPluginHostDelegates hostDelegates)
        {
            this.hostDelegates = hostDelegates;
            Program.config     = LoadConfiguration <PluginConfiguration>();

            if (!oneTimeInit)
            {
                // Must be before any rendering happens, including creation of ContextMenuStrip in Program class.
                Application.SetHighDpiMode(HighDpiMode.DpiUnaware);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                oneTimeInit = true;
            }

            // Context menu.
            contextMenuStrip = new ContextMenuStrip();
            contextMenuStrip.Items.Add(new ToolStripMenuItem("Options", null, (object sender, EventArgs e) =>
            {
                using (OptionsUI optionsForm = new OptionsUI())
                    optionsForm.ShowDialog();
            }));
            contextMenuStrip.Items.Add(new ToolStripSeparator());
            contextMenuStrip.Items.Add(new ToolStripMenuItem("Exit", null, (object sender, EventArgs e) =>
            {
                // Call Application.Exit() within the context of the Form.
                applicationContext?.MainForm?.Invoke(new Action(() => Application.Exit()));
            }));

            // Call the legacy code initialization.
            Program.Main(new string[0]);

            // Create and start the form.
            applicationContext = new ApplicationContext(new MainUI());
            applicationTask    = Task.Run(() =>
            {
                Application.Run(applicationContext);
            }).ContinueWith((Task t) =>
            {
                Shutdown();
            });

            return(0);
        }
 public int Startup(IPluginHostDelegates hostDelegates)
 {
     try
     {
         _hostDelegates = hostDelegates;
         _memoryScanner = new GameMemoryRECVXScanner(GetEmulator());
         _stopwatch     = new Stopwatch[2];
         _stopwatch[0]  = new Stopwatch();
         _stopwatch[0].Start();
         _stopwatch[1] = new Stopwatch();
         _stopwatch[1].Start();
         return(0);
     }
     catch (Exception ex)
     {
         _hostDelegates.ExceptionMessage(ex);
         return(1);
     }
 }
Exemplo n.º 10
0
 public override int Startup(IPluginHostDelegates hostDelegates)
 {
     HostDelegates = hostDelegates;
     return(Plugin.Initialize(this));
 }
Exemplo n.º 11
0
 public abstract int Startup(IPluginHostDelegates hostDelegates);
Exemplo n.º 12
0
 public virtual T LoadConfiguration <T>(IPluginHostDelegates hostDelegates = null) where T : class, new() => Extensions.LoadConfiguration <T>(null, hostDelegates);
Exemplo n.º 13
0
        public static void SaveConfiguration <T>(this T configuration, string?configFile = null, IPluginHostDelegates hostDelegates = null) where T : class, new()
        {
            if (configFile == null)
            {
                configFile = GetConfigFile(typeof(T).Assembly);
            }

            if (configuration != null) // Only save if configuration is not null.
            {
                try
                {
                    using (FileStream fs = new FileStream(configFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite | FileShare.Delete))
                        JsonSerializer.SerializeAsync <T>(fs, configuration, JSO).Wait();
                }
                catch (Exception ex)
                {
                    if (hostDelegates != null)
                    {
                        try { hostDelegates.ExceptionMessage.Invoke(ex); }
                        catch { }
                    }
                }
            }
        }
Exemplo n.º 14
0
 public static void SaveConfiguration <T>(this T configuration, IPluginHostDelegates hostDelegates = null) where T : class, new() => SaveConfiguration <T>(configuration, null, hostDelegates);
Exemplo n.º 15
0
 public T LoadConfiguration <T>(string?configFile = null, IPluginHostDelegates hostDelegates = null) where T : class, new() => Extensions.LoadConfiguration <T>(configFile, hostDelegates);
Exemplo n.º 16
0
 public static T LoadConfiguration <T>(IPluginHostDelegates hostDelegates = null) where T : class, new() => LoadConfiguration <T>(null, hostDelegates);
Exemplo n.º 17
0
 public void SaveConfiguration <T>(T configuration, string?configFile = null, IPluginHostDelegates hostDelegates = null) where T : class, new() => configuration.SaveConfiguration(configFile, hostDelegates);
Exemplo n.º 18
0
 public virtual void SaveConfiguration <T>(T configuration, IPluginHostDelegates hostDelegates = null) where T : class, new() => configuration.SaveConfiguration(null, hostDelegates);