Пример #1
0
 private void Singularity_ConsoleWritten(object sender, NetCoreEventArgs e)
 {
     if (cbDisplayConsole.Checked)
     {
         tbNetCoreOutput.AppendText(e.message.Type + "\n");
     }
 }
        public object OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            NetCoreAdvancedMessage message = e.message as NetCoreAdvancedMessage;

            switch (message.Type)
            {
            case Commands.SHOW_WINDOW:
                try
                {
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        if (S.GET <PluginForm>() == null || S.GET <PluginForm>().IsDisposed)
                        {
                            S.SET <PluginForm>(new PluginForm());
                        }
                        var form = S.GET <PluginForm>();
                        form.Show();
                        form.Activate();
                    });
                    break;
                }
                catch
                {
                    Logging.GlobalLogger.Error($"Template command {Commands.SHOW_WINDOW} failed. Reason:\r\n" + e.ToString());
                    break;
                }
            }
            return(e.returnMessage);
        }
Пример #3
0
        private static void FormRegister_FormRegistered(object sender, NetCoreEventArgs e)
        {
            Form newForm = ((e.message as NetCoreAdvancedMessage)?.objectValue as Form);

            if (newForm != null)
            {
                registerFormEvents(newForm);
                registerHotkeyBlacklistControls(newForm);
            }
        }
        public object OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            NetCoreAdvancedMessage message = e.message as NetCoreAdvancedMessage;

            switch (message.Type)
            {
            default:
                break;
            }
            return(e.returnMessage);
        }
Пример #5
0
        public object OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            //Use setReturnValue to handle returns
            var message         = e.message;
            var advancedMessage = message as NetCoreAdvancedMessage;

            switch (e.message.Type)
            {
            case NetcoreCommands.REMOTE_OPENHEXEDITOR:
            {
                SyncObjectSingleton.FormExecute(() =>
                    {
                        if (S.GET <HexEditor>().IsDisposed)
                        {
                            S.SET(new HexEditor());
                        }
                        S.GET <HexEditor>().Restart();
                        S.GET <HexEditor>().Show();
                    });
            }
            break;

            case NetcoreCommands.EMU_OPEN_HEXEDITOR_ADDRESS:
            {
                var    temp    = advancedMessage.objectValue as object[];
                string domain  = (string)temp[0];
                long   address = (long)temp[1];

                MemoryInterface mi = MemoryDomains.GetInterface(domain);
                if (mi == null)
                {
                    break;
                }

                SyncObjectSingleton.FormExecute(() =>
                    {
                        if (S.GET <HexEditor>().IsDisposed)
                        {
                            S.SET(new HexEditor());
                        }
                        S.GET <HexEditor>().Restart();
                        S.GET <HexEditor>().Show();
                        S.GET <HexEditor>().SetDomain(mi);
                        S.GET <HexEditor>().GoToAddress(address);
                    });
            }
            break;
            }
            return(e.returnMessage);
        }
Пример #6
0
        public object OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            //Use setReturnValue to handle returns

            switch (e.message.Type)
            {
            //HANDLE MESSAGES HERE
            default:
                new object();
                break;
            }

            return(e.returnMessage);
        }
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            // This is where you implement interaction
            // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

            var message         = e.message;
            var simpleMessage   = message as NetCoreSimpleMessage;
            var advancedMessage = message as NetCoreAdvancedMessage;

            switch (message.Type) //Handle received messages here
            {
            default:
                ConsoleEx.WriteLine($"Received unassigned {(message is NetCoreAdvancedMessage ? "advanced " : "")}message \"{message.Type}\"");
                break;
            }
        }
Пример #8
0
        public object OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            NetCoreAdvancedMessage message = e.message as NetCoreAdvancedMessage;

            switch (e.message.Type)
            {
            case Commands.SHOW_WINDOW:
                try
                {
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        if (((Control)S.GET <MemoryVisualizer>()).IsDisposed)
                        {
                            Loader.PluginForm = new MemoryVisualizer();
                            S.SET <MemoryVisualizer>(Loader.PluginForm);
                        }
                        ((Control)S.GET <MemoryVisualizer>()).Show();
                        ((Form)S.GET <MemoryVisualizer>()).Activate();
                    });
                    break;
                }
                catch
                {
                    Logging.GlobalLogger.Error("MemVisConnectorEMU: SHOW_WINDOW failed Reason:\r\n" + e.ToString());
                    break;
                }
                //case Commands.BYTESGET:
                //    try
                //    {
                //        Tuple<long, long, string> objectValue = (Tuple<long, long, string>)message.objectValue;
                //        e.setReturnValue((object)this.GetByteArr(objectValue.Item1, objectValue.Item2, objectValue.Item3));
                //        break;
                //    }
                //    catch (Exception ex)
                //    {
                //        if (!(ex is ArgumentNullException))
                //        {
                //            NullReferenceException referenceException = ex as NullReferenceException;
                //            break;
                //        }
                //        break;
                //    }
            }
            return(e.returnMessage);
        }
Пример #9
0
        public object OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            //No implementation here, we simply route and return

            if (e.message.Type.Contains('|'))
            {               //This needs to be routed
                var    msgParts = e.message.Type.Split('|');
                string endpoint = msgParts[0];
                e.message.Type = msgParts[1];                 //remove endpoint from type

                return(NetCore.LocalNetCoreRouter.Route(endpoint, e));
            }
            else
            {               //This is for the Vanguard Implementation
                receiver.OnMessageReceived(e);
                return(e.returnMessage);
            }
        }
Пример #10
0
        private void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            // This is where you implement interaction.
            // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

            var message         = e.message;
            var simpleMessage   = message as NetCoreSimpleMessage;
            var advancedMessage = message as NetCoreAdvancedMessage;

            switch (message.Type)         //Handle received messages here
            {
            case "{EVENT_NETWORKSTATUS}": //status update broadcast (string)
                lbNetCoreStatus.Text = $"Status : {(advancedMessage.objectValue as string)?.ToString()}";
                break;



            default:
                ConsoleEx.WriteLine($"Received unassigned {(message is NetCoreAdvancedMessage ? "advanced " : "")}message \"{message.Type}\"");
                break;
            }
        }
Пример #11
0
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            // This is where you implement interaction.
            // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

            var message         = e.message;
            var simpleMessage   = message as NetCoreSimpleMessage;
            var advancedMessage = message as NetCoreAdvancedMessage;

            switch (message.Type) //Handle received messages here
            {
            case "JUST A MESSAGE":
                //do something
                break;

            case "ADVANCED MESSAGE THAT CONTAINS A VALUE":
                object value = advancedMessage.objectValue;     //This is how you get the value from a message
                break;

            case "#!RETURNTEST":     //ADVANCED MESSAGE (SYNCED) WANTS A RETURN VALUE
                e.setReturnValue(new Random(666));
                break;

            case "#!WAIT":
                ConsoleEx.WriteLine("Simulating 20 sec of workload");
                Thread.Sleep(20000);
                break;

            case "#!HANG":
                ConsoleEx.WriteLine("Hanging forever");
                Thread.Sleep(int.MaxValue);
                break;

            default:
                ConsoleEx.WriteLine($"Received unassigned {(message is NetCoreAdvancedMessage ? "advanced " : "")}message \"{message.Type}\"");
                break;
            }
        }
        public object OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            var message         = e.message;
            var advancedMessage = message as NetCoreAdvancedMessage;

            switch (e.message.Type)
            {
            //case Commands.SPECUPDATE:
            //    SyncObjectSingleton.FormExecute(() =>
            //    {
            //        Spec.VisualizerSpec?.Update((PartialSpec)advancedMessage.objectValue, false);
            //    });
            //    break;

            //case Commands.SPECPUSH:
            //    SyncObjectSingleton.FormExecute(() =>
            //    {
            //        var temp = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached);

            //        Spec.VisualizerSpec = new FullSpec(temp.GetPartialSpec(), !RtcCore.Attached);
            //        Spec.VisualizerSpec.SpecUpdated += (ob, eas) =>
            //        {
            //            PartialSpec partial = eas.partialSpec;
            //            LocalNetCoreRouter.Route(Ep.EMU_SIDE, Commands.SPECPUSH, partial, true);
            //        };
            //        RTCV.CorruptCore.MemoryDomains.RefreshDomains();
            //    });
            //    e.setReturnValue(true);
            //    break;
            //case Commands.

            default:
                break;
            }



            //switch (e.message.Type)
            //{
            //    case NetcoreCommands.REMOTE_OPENHEXEDITOR:
            //        {
            //            SyncObjectSingleton.FormExecute(() =>
            //            {
            //                if (S.GET<HexEditor>().IsDisposed)
            //                {
            //                    S.SET(new HexEditor());
            //                }
            //                S.GET<HexEditor>().Restart();
            //                S.GET<HexEditor>().Show();
            //            });
            //        }
            //        break;

            //    case NetcoreCommands.EMU_OPEN_HEXEDITOR_ADDRESS:
            //        {
            //            var temp = advancedMessage.objectValue as object[];
            //            string domain = (string)temp[0];
            //            long address = (long)temp[1];

            //            MemoryInterface mi = MemoryDomains.GetInterface(domain);
            //            if (mi == null)
            //                break;

            //            SyncObjectSingleton.FormExecute(() =>
            //            {
            //                if (S.GET<HexEditor>().IsDisposed)
            //                {
            //                    S.SET(new HexEditor());
            //                }
            //                S.GET<HexEditor>().Restart();
            //                S.GET<HexEditor>().Show();
            //                S.GET<HexEditor>().SetDomain(mi);
            //                S.GET<HexEditor>().GoToAddress(address);
            //            });
            //        }
            //        break;
            //}
            return(e.returnMessage);
        }
Пример #13
0
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                // This is where you implement interaction.
                // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                ConsoleEx.WriteLine(message.Type);
                switch (message.Type) //Handle received messages here
                {
                case RTCV.NetCore.Commands.Remote.AllSpecSent:
                {
                    //We still need to set the emulator's path
                    AllSpec.VanguardSpec.Update(VSPEC.EMUDIR, UnityWatch.currentDir);
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            UnityWatch.UpdateDomains();
                        });
                }
                break;

                case RTCV.NetCore.Commands.Basic.SaveSavestate:
                    e.setReturnValue("");
                    break;

                case RTCV.NetCore.Commands.Basic.LoadSavestate:
                    e.setReturnValue(true);
                    break;

                case RTCV.NetCore.Commands.Remote.PreCorruptAction:
                    if (UnityWatch.currentFileInfo.TerminateBeforeExecution)
                    {
                        UnityWatch.KillProcess();
                    }
                    UnityWatch.currentFileInfo.targetInterface.CloseStream();
                    UnityWatch.RestoreTarget();
                    break;

                case RTCV.NetCore.Commands.Remote.PostCorruptAction:
                    //var fileName = advancedMessage.objectValue as String;
                    UnityWatch.currentFileInfo.targetInterface.CloseStream();
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Executor.Execute();
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.CloseGame:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        UnityWatch.KillProcess();
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.DomainGetDomains:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(UnityWatch.GetInterfaces());
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.EventEmuMainFormClose:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Environment.Exit(0);
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.IsNormalAdvance:
                    e.setReturnValue(true);
                    break;

                case RTCV.NetCore.Commands.Remote.EventCloseEmulator:
                    Environment.Exit(-1);
                    break;
                }
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Пример #14
0
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                // This is where you implement interaction.
                // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                ConsoleEx.WriteLine(message.Type);
                switch (message.Type) //Handle received messages here
                {
                case REMOTE_ALLSPECSSENT:
                {
                    //We still need to set the emulator's path
                    AllSpec.VanguardSpec.Update(VSPEC.EMUDIR, CemuWatch.currentGameInfo.cemuExeFile.Directory.FullName);
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            CemuWatch.UpdateDomains();
                        });
                }
                break;

                case SAVESAVESTATE:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(VanguardCore.SaveSavestate_NET(advancedMessage.objectValue as string));
                        //e.setReturnValue("");
                    });
                    break;

                case LOADSAVESTATE:
                {
                    var cmd      = advancedMessage.objectValue as object[];
                    var path     = cmd[0] as string;
                    var location = (StashKeySavestateLocation)cmd[1];
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            e.setReturnValue(VanguardCore.LoadSavestate_NET(path, location));
                        });


                    e.setReturnValue(true);
                    break;
                }

                case REMOTE_PRECORRUPTACTION:
                    CemuWatch.KillCemuProcess(false);
                    CemuWatch.RestoreBackup();
                    break;

                case REMOTE_POSTCORRUPTACTION:
                {
                    //var fileName = advancedMessage.objectValue as String;
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            CemuWatch.StartRpx();
                        });
                }
                break;

                case REMOTE_CLOSEGAME:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        CemuWatch.KillCemuProcess(false);
                    });

                    break;

                case REMOTE_DOMAIN_GETDOMAINS:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(CemuWatch.GetInterfaces());
                    });
                    break;

                case REMOTE_EVENT_EMU_MAINFORM_CLOSE:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Environment.Exit(0);
                    });
                    break;

                case REMOTE_ISNORMALADVANCE:
                    e.setReturnValue(true);
                    //e.setReturnValue(Hooks.isNormalAdvance);
                    break;

                case REMOTE_EVENT_CLOSEEMULATOR:
                    Environment.Exit(-1);
                    break;
                }
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Пример #15
0
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                // This is where you implement interaction.
                // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                ConsoleEx.WriteLine(message.Type);
                switch (message.Type) //Handle received messages here
                {
                case RTCV.NetCore.Commands.Remote.AllSpecSent:
                {
                    //We still need to set the emulator's path
                    AllSpec.VanguardSpec.Update(VSPEC.EMUDIR, Hook.currentDir);
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            Hook.UpdateDomains();
                        });
                }
                break;

                case RTCV.NetCore.Commands.Basic.SaveSavestate:
                    e.setReturnValue("");
                    break;

                case RTCV.NetCore.Commands.Basic.LoadSavestate:
                    e.setReturnValue(true);
                    break;

                case RTCV.NetCore.Commands.Remote.PreCorruptAction:

                    //SyncObjectSingleton.FormExecute(() =>
                    //{
                    //    lock (Hook.CorruptLock)
                    //    {
                    //        if (Hook.SuspendProcess)
                    //        {
                    //            if (!Hook.p?.Suspend() ?? true && !suspendWarned)
                    //            {
                    //                suspendWarned = (MessageBox.Show("Failed to suspend a thread!\nWould you like to continue to receive warnings?", "Failed to suspend thread", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes);
                    //            }
                    //        }

                    //        Hook.DontChangeMemoryProtection = true;
                    //        var count = 0;
                    //        foreach (var m in MemoryDomains.MemoryInterfaces.Values)
                    //        {
                    //            if (m.MD is ProcessMemoryDomain pmd)
                    //            {
                    //                if (!pmd.SetMemoryProtection(ProcessExtensions.MemoryProtection.ExecuteReadWrite))
                    //                    count++;
                    //            }
                    //        }

                    //        Console.WriteLine($"PreCorrupt\n" +
                    //                          $"Total domains: {MemoryDomains.MemoryInterfaces.Values.Count}\n" +
                    //                          $"Errors: {count}");
                    //    }
                    //});

                    break;

                case RTCV.NetCore.Commands.Remote.PostCorruptAction:
                    //SyncObjectSingleton.FormExecute(() =>
                    //{
                    //    lock (Hook.CorruptLock)
                    //    {
                    //        foreach (var m in MemoryDomains.MemoryInterfaces.Values)
                    //        {
                    //            if (m.MD is ProcessMemoryDomain pmd)
                    //            {
                    //                pmd.ResetMemoryProtection();
                    //                pmd.FlushInstructionCache();
                    //            }
                    //        }
                    //        Hook.DontChangeMemoryProtection = false;
                    //        if (Hook.SuspendProcess)
                    //        {
                    //            if (!Hook.p?.Resume() ?? true && !suspendWarned)
                    //            {
                    //                suspendWarned = (MessageBox.Show("Failed to resume a thread!\nWould you like to continue to receive warnings?", "Failed to resume thread", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes);
                    //            }
                    //        }
                    //    }
                    //});
                    break;

                case RTCV.NetCore.Commands.Remote.CloseGame:
                    break;

                case RTCV.NetCore.Commands.Remote.DomainGetDomains:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(Hook.GetInterfaces());
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.DomainRefreshDomains:
                    SyncObjectSingleton.FormExecute(() => { Hook.UpdateDomains(); });
                    break;

                case RTCV.NetCore.Commands.Remote.EventEmuMainFormClose:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Environment.Exit(0);
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.IsNormalAdvance:
                    e.setReturnValue(true);
                    break;

                case RTCV.NetCore.Commands.Remote.EventCloseEmulator:
                    Environment.Exit(-1);
                    break;
                }
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
                {
                    throw new AbortEverythingException();
                }
            }
        }
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                // This is where you implement interaction.
                // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                ConsoleEx.WriteLine(message.Type);
                switch (message.Type)                 //Handle received messages here
                {
                case "INFINITELOOP":
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        while (true)
                        {
                            Thread.Sleep(10);
                        }
                    });
                    break;


                case REMOTE_ALLSPECSSENT:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        VanguardCore.LoadDefaultRom();
                        Program.SpecsSent = true;
                    });
                    break;

                case SAVESAVESTATE:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        e.setReturnValue(VanguardCore.SaveSavestate_NET(advancedMessage.objectValue as string));
                    });
                    break;

                case LOADSAVESTATE:
                {
                    var cmd      = advancedMessage.objectValue as object[];
                    var path     = cmd[0] as string;
                    var location = (StashKeySavestateLocation)cmd[1];
                    SyncObjectSingleton.FormExecute((o, ea) =>
                        {
                            e.setReturnValue(VanguardCore.LoadSavestate_NET(path, location));
                        });
                    break;
                }

                case REMOTE_LOADROM:
                {
                    var fileName = advancedMessage.objectValue as String;
                    SyncObjectSingleton.FormExecute((o, ea) =>
                        {
                            VanguardCore.LoadRom_NET(fileName);
                        });
                }
                break;

                case REMOTE_DOMAIN_GETDOMAINS:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        e.setReturnValue(Hooks.GetInterfaces());
                    });
                    break;

                case REMOTE_KEY_SETSYNCSETTINGS:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        Hooks.EMU_GETSET_SYNCSETTINGS = (string)advancedMessage.objectValue;
                    });
                    break;

                case REMOTE_KEY_SETSYSTEMCORE:
                {
                    var cmd        = advancedMessage.objectValue as object[];
                    var systemName = (string)cmd[0];
                    var systemCore = (string)cmd[1];
                    SyncObjectSingleton.FormExecute((o, ea) =>
                        {
                            Hooks.EMU_SET_SYSTEMCORE(systemName, systemCore);
                        });
                }
                break;

                case EMU_OPEN_HEXEDITOR_ADDRESS:
                {
                    var    temp    = advancedMessage.objectValue as object[];
                    string domain  = (string)temp[0];
                    long   address = (long)temp[1];

                    MemoryDomainProxy mdp = MemoryDomains.GetProxy(domain, address);
                    long realAddress      = MemoryDomains.GetRealAddress(domain, address);

                    SyncObjectSingleton.FormExecute((o, ea) =>
                        {
                            Hooks.EMU_OPEN_HEXEDITOR_ADDRESS(mdp, realAddress);
                        });

                    break;
                }

                case REMOTE_EVENT_EMU_MAINFORM_CLOSE:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        Hooks.EMU_MAINFORM_CLOSE();
                    });
                    break;

                case REMOTE_EVENT_SAVEBIZHAWKCONFIG:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        Hooks.EMU_MAINFORM_SAVECONFIG();
                    });
                    break;


                case REMOTE_IMPORTKEYBINDS:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        Hooks.EMU_IMPORTCONFIGINI(CorruptCore.bizhawkDir + Path.DirectorySeparatorChar + "import_config.ini", CorruptCore.bizhawkDir + Path.DirectorySeparatorChar + "stockpile_config.ini");
                    });
                    break;

                case REMOTE_MERGECONFIG:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        Hooks.EMU_MERGECONFIGINI(CorruptCore.bizhawkDir + Path.DirectorySeparatorChar + "backup_config.ini", CorruptCore.bizhawkDir + Path.DirectorySeparatorChar + "stockpile_config.ini");
                    });
                    break;

                case REMOTE_RESTOREBIZHAWKCONFIG:
                    SyncObjectSingleton.FormExecute((o, ea) =>
                    {
                        Process.Start(CorruptCore.bizhawkDir + Path.DirectorySeparatorChar + $"RestoreConfigDETACHED.bat");
                    });
                    break;

                case REMOTE_ISNORMALADVANCE:
                    e.setReturnValue(Hooks.isNormalAdvance);
                    break;
                }
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Пример #17
0
 public virtual void OnMessageReceived(NetCoreEventArgs e) => MessageReceived?.Invoke(this, e);
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                // This is where you implement interaction.
                // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                ConsoleEx.WriteLine(message.Type);
                switch (message.Type) //Handle received messages here
                {
                case RTCV.NetCore.Commands.Remote.AllSpecSent:
                {
                    //We still need to set the emulator's path
                    AllSpec.VanguardSpec.Update(VSPEC.EMUDIR, FileWatch.currentDir);
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            FileWatch.UpdateDomains();
                        });
                }
                break;

                case RTCV.NetCore.Commands.Basic.SaveSavestate:

                    string key = (advancedMessage.objectValue as string);

                    //TODO: Sync states with keys

                    SyncObjectSingleton.FormExecute(() =>
                    {
                        S.GET <StubForm>().btnRamSaveState_Click(null, null);
                        string returnKey = VanguardCore.SaveSavestate_NET(key);
                        e.setReturnValue(returnKey);
                    });

                    break;

                case RTCV.NetCore.Commands.Basic.LoadSavestate:

                    var cmd      = advancedMessage.objectValue as object[];
                    var path     = cmd[0] as string;
                    var location = (StashKeySavestateLocation)cmd[1];

                    SyncObjectSingleton.FormExecute(() =>
                    {
                        //e.setReturnValue(VanguardCore.LoadSavestate_NET(path, location));
                        VanguardCore.LoadSavestate_NET(path, location);
                        S.GET <StubForm>().RepackState(false);
                    });

                    e.setReturnValue(true);

                    break;

                case RTCV.NetCore.Commands.Remote.PreCorruptAction:
                    FileWatch.KillProcess();
                    FileWatch.currentFileInfo.targetInterface.CloseStream();
                    FileWatch.RestoreTarget();
                    break;

                case RTCV.NetCore.Commands.Remote.PostCorruptAction:
                    //var fileName = advancedMessage.objectValue as String;
                    FileWatch.currentFileInfo.targetInterface?.CloseStream();
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Executor.Execute();
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.CloseGame:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        FileWatch.KillProcess();
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.DomainGetDomains:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(FileWatch.GetInterfaces());
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.EventEmuMainFormClose:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Environment.Exit(0);
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.IsNormalAdvance:
                    e.setReturnValue(true);
                    break;

                case RTCV.NetCore.Commands.Remote.EventCloseEmulator:
                    Environment.Exit(-1);
                    break;
                }
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Пример #19
0
        public object OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            { //Use setReturnValue to handle returns
                var message         = e.message;
                var advancedMessage = message as NetCoreAdvancedMessage;

                switch (e.message.Type)
                {
                case "GETSPECDUMPS":
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Spec Dump from CorruptCore");
                    sb.AppendLine();
                    sb.AppendLine("UISpec");
                    RTCV.NetCore.AllSpec.UISpec?.GetDump().ForEach(x => sb.AppendLine(x));
                    sb.AppendLine("CorruptCoreSpec");
                    RTCV.NetCore.AllSpec.CorruptCoreSpec?.GetDump().ForEach(x => sb.AppendLine(x));
                    sb.AppendLine("VanguardSpec");
                    RTCV.NetCore.AllSpec.VanguardSpec?.GetDump().ForEach(x => sb.AppendLine(x));
                    e.setReturnValue(sb.ToString());
                    break;

                //UI sent its spec
                case REMOTE_PUSHUISPEC:
                {
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            RTCV.NetCore.AllSpec.UISpec = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached);
                        });
                    break;
                }

                //UI sent a spec update
                case REMOTE_PUSHUISPECUPDATE:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        RTCV.NetCore.AllSpec.UISpec?.Update((PartialSpec)advancedMessage.objectValue);
                    });
                    break;

                //Vanguard sent a copy of its spec
                case REMOTE_PUSHVANGUARDSPEC:

                    SyncObjectSingleton.FormExecute(() =>
                    {
                        if (!RtcCore.Attached)
                        {
                            RTCV.NetCore.AllSpec.VanguardSpec = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached);
                        }
                    });
                    break;

                //Vanguard sent a spec update
                case REMOTE_PUSHVANGUARDSPECUPDATE:
                    RTCV.NetCore.AllSpec.VanguardSpec?.Update((PartialSpec)advancedMessage.objectValue, false);
                    break;

                //UI sent a copy of the CorruptCore spec
                case REMOTE_PUSHCORRUPTCORESPEC:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        //So here's the deal. The UI doesn't actually have the full memory domains (md isn't sent across) so if we take them from it, it results in them going null
                        //Instead, we stick with what we have, then tell the UI to use that.

                        var temp = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached);

                        //Stick with what we have if it exists to prevent any exceptions if autocorrupt was on or something, then call refresh
                        temp.Update("MEMORYINTERFACES", AllSpec.CorruptCoreSpec?["MEMORYINTERFACES"] ?? new Dictionary <string, MemoryDomainProxy>());

                        RTCV.NetCore.AllSpec.CorruptCoreSpec              = new FullSpec(temp.GetPartialSpec(), !RtcCore.Attached);
                        RTCV.NetCore.AllSpec.CorruptCoreSpec.SpecUpdated += (ob, eas) =>
                        {
                            PartialSpec partial = eas.partialSpec;
                            LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_PUSHCORRUPTCORESPECUPDATE, partial, true);
                        };
                        RTCV.CorruptCore.MemoryDomains.RefreshDomains();
                    });
                    e.setReturnValue(true);
                    break;

                //UI sent an update of the CorruptCore spec
                case REMOTE_PUSHCORRUPTCORESPECUPDATE:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        RTCV.NetCore.AllSpec.CorruptCoreSpec?.Update((PartialSpec)advancedMessage.objectValue, false);
                    });
                    break;

                case REMOTE_EVENT_DOMAINSUPDATED:
                    var domainsChanged = (bool)advancedMessage.objectValue;
                    MemoryDomains.RefreshDomains(domainsChanged);
                    break;

                case REMOTE_EVENT_RESTRICTFEATURES:
                {
                    if (!RTCV.NetCore.AllSpec.VanguardSpec?.Get <bool>(VSPEC.SUPPORTS_SAVESTATES) ?? true)
                    {
                        LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_DISABLESAVESTATESUPPORT);
                    }

                    if (!RTCV.NetCore.AllSpec.VanguardSpec?.Get <bool>(VSPEC.SUPPORTS_REALTIME) ?? true)
                    {
                        LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_DISABLEREALTIMESUPPORT);
                    }

                    if (!RTCV.NetCore.AllSpec.VanguardSpec?.Get <bool>(VSPEC.SUPPORTS_KILLSWITCH) ?? true)
                    {
                        LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_DISABLEKILLSWITCHSUPPORT);
                    }

                    if (!RTCV.NetCore.AllSpec.VanguardSpec?.Get <bool>(VSPEC.SUPPORTS_GAMEPROTECTION) ?? true)
                    {
                        LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_DISABLEGAMEPROTECTIONSUPPORT);
                    }

                    break;
                }

                case REMOTE_EVENT_SHUTDOWN:
                {
                    RtcCore.Shutdown();
                    break;
                }

                case REMOTE_OPENHEXEDITOR:
                {
                    if ((bool?)AllSpec.VanguardSpec[VSPEC.USE_INTEGRATED_HEXEDITOR] ?? false)
                    {
                        LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_OPENHEXEDITOR, true);
                    }
                    else
                    {
                        //Route it to the plugin if loaded
                        if (RtcCore.PluginHost.LoadedPlugins.Any(x => x.Name == "Hex Editor"))
                        {
                            LocalNetCoreRouter.Route("HEXEDITOR", NetcoreCommands.REMOTE_OPENHEXEDITOR, true);
                        }
                        else
                        {
                            MessageBox.Show("The current Vanguard implementation does not include a\n hex editor & the hex editor plugin isn't loaded. Aborting.");
                        }
                    }
                }
                break;

                case EMU_OPEN_HEXEDITOR_ADDRESS:
                {
                    if ((bool?)AllSpec.VanguardSpec[VSPEC.USE_INTEGRATED_HEXEDITOR] ?? false)
                    {
                        LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.EMU_OPEN_HEXEDITOR_ADDRESS, advancedMessage.objectValue, true);
                    }
                    else
                    {
                        //Route it to the plugin if loaded
                        if (RtcCore.PluginHost.LoadedPlugins.Any(x => x.Name == "Hex Editor"))
                        {
                            LocalNetCoreRouter.Route("HEXEDITOR", NetcoreCommands.EMU_OPEN_HEXEDITOR_ADDRESS, advancedMessage.objectValue, true);
                        }
                        else
                        {
                            MessageBox.Show("The current Vanguard implementation does not include a\n hex editor & the hex editor plugin isn't loaded. Aborting.");
                        }
                    }
                    break;
                }

                case MANUALBLAST:
                {
                    RtcCore.GenerateAndBlast();
                }
                break;

                case GENERATEBLASTLAYER:
                {
                    var      val = advancedMessage.objectValue as object[];
                    StashKey sk  = val[0] as StashKey;
                    bool     loadBeforeCorrupt = (bool)val[1];
                    bool     applyBlastLayer   = (bool)val[2];
                    bool     backup            = (bool)val[3];

                    BlastLayer bl = null;

                    bool UseSavestates = (bool)AllSpec.VanguardSpec[VSPEC.SUPPORTS_SAVESTATES];

                    void a()
                    {
                        lock (loadLock)
                        {
                            //Load the game from the main thread
                            if (UseSavestates && loadBeforeCorrupt)
                            {
                                SyncObjectSingleton.FormExecute(() =>
                                    {
                                        StockpileManager_EmuSide.LoadRom_NET(sk);
                                    });
                            }

                            if (UseSavestates && loadBeforeCorrupt)
                            {
                                StockpileManager_EmuSide.LoadState_NET(sk, false);
                            }

                            //We pull the domains here because if the syncsettings changed, there's a chance the domains changed
                            string[] domains = (string[])AllSpec.UISpec["SELECTEDDOMAINS"];

                            var cpus = Environment.ProcessorCount;

                            if (cpus == 1 || AllSpec.VanguardSpec[VSPEC.SUPPORTS_MULTITHREAD] == null)
                            {
                                bl = RtcCore.GenerateBlastLayer(domains);
                            }
                            else
                            {
                                //if emulator supports multithreaded access of the domains, disregard the emulation thread and just span threads...

                                long reminder = RtcCore.Intensity % (cpus - 1);

                                long splitintensity = (RtcCore.Intensity - reminder) / (cpus - 1);

                                Task <BlastLayer>[] tasks = new Task <BlastLayer> [cpus];
                                for (int i = 0; i < cpus; i++)
                                {
                                    long requestedIntensity = splitintensity;

                                    if (i == 0 && reminder != 0)
                                    {
                                        requestedIntensity = reminder;
                                    }

                                    tasks[i] = Task.Factory.StartNew(() =>
                                                                     RtcCore.GenerateBlastLayer(domains, requestedIntensity));
                                }

                                Task.WaitAll(tasks);

                                bl = tasks[0]
                                     .Result ?? new BlastLayer();

                                if (tasks.Length > 1)
                                {
                                    for (int i = 1; i < tasks.Length; i++)
                                    {
                                        if (tasks[i]
                                            .Result != null)
                                        {
                                            bl.Layer.AddRange(tasks[i]
                                                              .Result.Layer);
                                        }
                                    }
                                }

                                if (bl.Layer.Count == 0)
                                {
                                    bl = null;
                                }
                            }

                            if (applyBlastLayer)
                            {
                                bl?.Apply(backup);
                            }
                        }
                    }
                    //If the emulator uses callbacks, we do everything on the main thread and once we're done, we unpause emulation
                    if ((bool?)AllSpec.VanguardSpec[VSPEC.LOADSTATE_USES_CALLBACKS] ?? false)
                    {
                        SyncObjectSingleton.FormExecute(a);
                        e.setReturnValue(LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_RESUMEEMULATION, true));
                    }
                    else         //We can just do everything on the emulation thread as it'll block
                    {
                        SyncObjectSingleton.EmuThreadExecute(a, true);
                    }

                    if (advancedMessage.requestGuid != null)
                    {
                        e.setReturnValue(bl);
                    }
                    break;
                }

                case APPLYBLASTLAYER:
                {
                    var        temp   = advancedMessage.objectValue as object[];
                    BlastLayer bl     = (BlastLayer)temp[0];
                    bool       backup = (bool)temp[1];

                    void a()
                    {
                        bl.Apply(backup, true);
                    }

                    SyncObjectSingleton.EmuThreadExecute(a, true);
                    break;
                }

                /*
                 * case STASHKEY:
                 *  {
                 *      var temp = advancedMessage.objectValue as object[];
                 *
                 *      var sk = temp[0] as StashKey;
                 *      var romFilename = temp[1] as String;
                 *      var romData = temp[2] as Byte[];
                 *
                 *      if (!File.Exists(CorruptCore.rtcDir + Path.DirectorySeparatorChar + "WORKING" + Path.DirectorySeparatorChar + "SKS" + Path.DirectorySeparatorChar + romFilename))
                 *          File.WriteAllBytes(CorruptCore.rtcDir + Path.DirectorySeparatorChar + "WORKING" + Path.DirectorySeparatorChar + "SKS" + Path.DirectorySeparatorChar + romFilename, romData);
                 *
                 *      sk.RomFilename = CorruptCore.rtcDir + Path.DirectorySeparatorChar + "WORKING" + Path.DirectorySeparatorChar + "SKS" + Path.DirectorySeparatorChar + CorruptCore_Extensions.getShortFilenameFromPath(romFilename);
                 *      sk.DeployState();
                 *      sk.Run();
                 *  }
                 *  break;
                 */

                case REMOTE_PUSHRTCSPEC:
                    RTCV.NetCore.AllSpec.CorruptCoreSpec = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached);
                    e.setReturnValue(true);
                    break;

                case REMOTE_PUSHRTCSPECUPDATE:
                    RTCV.NetCore.AllSpec.CorruptCoreSpec?.Update((PartialSpec)advancedMessage.objectValue, false);
                    break;

                case BLASTGENERATOR_BLAST:
                {
                    List <BlastGeneratorProto> returnList = null;
                    StashKey sk = (StashKey)(advancedMessage.objectValue as object[])[0];
                    List <BlastGeneratorProto> blastGeneratorProtos = (List <BlastGeneratorProto>)(advancedMessage.objectValue as object[])[1];
                    bool loadBeforeCorrupt = (bool)(advancedMessage.objectValue as object[])[2];
                    bool applyAfterCorrupt = (bool)(advancedMessage.objectValue as object[])[3];
                    bool resumeAfter       = (bool)(advancedMessage.objectValue as object[])[4];
                    void a()
                    {
                        //Load the game from the main thread
                        if (loadBeforeCorrupt)
                        {
                            SyncObjectSingleton.FormExecute(() =>
                                {
                                    StockpileManager_EmuSide.LoadRom_NET(sk);
                                });
                        }

                        if (loadBeforeCorrupt)
                        {
                            StockpileManager_EmuSide.LoadState_NET(sk, false);
                        }

                        returnList = BlastTools.GenerateBlastLayersFromBlastGeneratorProtos(blastGeneratorProtos, sk);
                        if (applyAfterCorrupt)
                        {
                            BlastLayer bl = new BlastLayer();
                            foreach (var p in returnList.Where(x => x != null))
                            {
                                bl.Layer.AddRange(p.bl.Layer);
                            }
                            bl.Apply(true);
                        }
                    }
                    //If the emulator uses callbacks, we do everything on the main thread and once we're done, we unpause emulation
                    if ((bool?)AllSpec.VanguardSpec[VSPEC.LOADSTATE_USES_CALLBACKS] ?? false)
                    {
                        SyncObjectSingleton.FormExecute(a);
                        if (resumeAfter)
                        {
                            e.setReturnValue(LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_RESUMEEMULATION, true));
                        }
                    }
                    else
                    {
                        SyncObjectSingleton.EmuThreadExecute(a, false);
                    }

                    e.setReturnValue(returnList);

                    break;
                }

                case REMOTE_LOADSTATE:
                {
                    lock (loadLock)
                    {
                        StashKey sk            = (StashKey)(advancedMessage.objectValue as object[])[0];
                        bool     reloadRom     = (bool)(advancedMessage.objectValue as object[])[1];
                        bool     runBlastLayer = (bool)(advancedMessage.objectValue as object[])[2];

                        bool returnValue = false;

                        //Load the game from the main thread
                        if (reloadRom)
                        {
                            SyncObjectSingleton.FormExecute(() =>
                                {
                                    StockpileManager_EmuSide.LoadRom_NET(sk);
                                });
                        }
                        void a()
                        {
                            returnValue = StockpileManager_EmuSide.LoadState_NET(sk, runBlastLayer);
                        }
                        //If the emulator uses callbacks, we do everything on the main thread and once we're done, we unpause emulation
                        if ((bool?)AllSpec.VanguardSpec[VSPEC.LOADSTATE_USES_CALLBACKS] ?? false)
                        {
                            SyncObjectSingleton.FormExecute(a);
                            e.setReturnValue(LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_RESUMEEMULATION, true));
                        }
                        else         //We're loading on the emulator thread which'll block
                        {
                            SyncObjectSingleton.EmuThreadExecute(a, false);
                        }
                        e.setReturnValue(returnValue);
                    }
                }
                break;

                case REMOTE_SAVESTATE:
                {
                    StashKey sk = null;
                    void a()
                    {
                        sk = StockpileManager_EmuSide.SaveState_NET(advancedMessage.objectValue as StashKey);         //Has to be nullable cast
                    }
                    SyncObjectSingleton.EmuThreadExecute(a, false);
                    e.setReturnValue(sk);
                }
                break;

                case REMOTE_SAVESTATELESS:
                {
                    StashKey sk = null;
                    void a()
                    {
                        sk = StockpileManager_EmuSide.SaveStateLess_NET(advancedMessage.objectValue as StashKey);         //Has to be nullable cast
                    }
                    SyncObjectSingleton.EmuThreadExecute(a, false);
                    e.setReturnValue(sk);
                }
                break;

                case REMOTE_BACKUPKEY_REQUEST:
                {
                    //We don't store this in the spec as it'd be horrible to push it to the UI and it doesn't care
                    //if (!LocalNetCoreRouter.QueryRoute<bool>(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_ISNORMALADVANCE))
                    //break;

                    StashKey sk = null;
                    //We send an unsynced command back
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            sk = StockpileManager_EmuSide.SaveState_NET();
                        });

                    if (sk != null)
                    {
                        LocalNetCoreRouter.Route(NetcoreCommands.UI, REMOTE_BACKUPKEY_STASH, sk, false);
                    }

                    break;
                }

                case REMOTE_DOMAIN_GETDOMAINS:
                    e.setReturnValue(LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_DOMAIN_GETDOMAINS, true));
                    break;

                case REMOTE_PUSHVMDPROTOS:
                    MemoryDomains.VmdPool.Clear();
                    foreach (var proto in (advancedMessage.objectValue as VmdPrototype[]))
                    {
                        MemoryDomains.AddVMD(proto);
                    }

                    break;

                case REMOTE_DOMAIN_VMD_ADD:
                    MemoryDomains.AddVMD_NET((advancedMessage.objectValue as VmdPrototype));
                    break;

                case REMOTE_DOMAIN_VMD_REMOVE:
                {
                    StepActions.ClearStepBlastUnits();
                    MemoryDomains.RemoveVMD_NET((advancedMessage.objectValue as string));
                }
                break;

                case REMOTE_DOMAIN_ACTIVETABLE_MAKEDUMP:
                {
                    void a()
                    {
                        MemoryDomains.GenerateActiveTableDump((string)(advancedMessage.objectValue as object[])[0],
                                                              (string)(advancedMessage.objectValue as object[])[1]);
                    }

                    SyncObjectSingleton.EmuThreadExecute(a, false);
                }
                break;

                case REMOTE_BLASTTOOLS_GETAPPLIEDBACKUPLAYER:
                {
                    var bl = (BlastLayer)(advancedMessage.objectValue as object[])[0];
                    var sk = (StashKey)(advancedMessage.objectValue as object[])[1];

                    void a()
                    {
                        e.setReturnValue(BlastTools.GetAppliedBackupLayer(bl, sk));
                    }

                    SyncObjectSingleton.EmuThreadExecute(a, false);
                    break;
                }

                case REMOTE_LONGARRAY_FILTERDOMAIN:
                {
                    lock (loadLock)
                    {
                        var      objValues       = (advancedMessage.objectValue as object[]);
                        string   domain          = (string)objValues[0];
                        string   LimiterListHash = (string)objValues[1];
                        StashKey sk = objValues[2] as StashKey;         //Intentionally nullable

                        void a()
                        {
                            if (sk != null)         //If a stashkey was passed in, we want to load then profile
                            {
                                StockpileManager_EmuSide.LoadState_NET(sk, false);
                            }

                            MemoryInterface mi = MemoryDomains.MemoryInterfaces[domain];
                            List <long>     allLegalAdresses = new List <long>();

                            int listItemSize = Filtering.GetPrecisionFromHash(LimiterListHash);

                            for (long i = 0; i < mi.Size; i += listItemSize)
                            {
                                if (Filtering.LimiterPeekBytes(i, i + listItemSize, mi.Name, LimiterListHash, mi))
                                {
                                    for (int j = 0; j < listItemSize; j++)
                                    {
                                        allLegalAdresses.Add(i + j);
                                    }
                                }
                            }

                            e.setReturnValue(allLegalAdresses.ToArray());
                        }

                        //If the emulator uses callbacks and we're loading a state, we do everything on the main thread and once we're done, we unpause emulation
                        if (sk != null && ((bool?)AllSpec.VanguardSpec[VSPEC.LOADSTATE_USES_CALLBACKS] ?? false))
                        {
                            SyncObjectSingleton.FormExecute(a);
                            LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_RESUMEEMULATION, true);
                        }
                        else         //We can just do everything on the emulation thread as it'll block
                        {
                            SyncObjectSingleton.EmuThreadExecute(a, true);
                        }
                    }
                }
                break;

                case REMOTE_KEY_GETRAWBLASTLAYER:
                {
                    void a()
                    {
                        e.setReturnValue(StockpileManager_EmuSide.GetRawBlastlayer());
                    }
                    SyncObjectSingleton.EmuThreadExecute(a, false);
                }
                break;

                case REMOTE_BL_GETDIFFBLASTLAYER:
                {
                    string filename = (advancedMessage.objectValue as string);
                    void a()
                    {
                        e.setReturnValue(BlastDiff.GetBlastLayer(filename));
                    }
                    SyncObjectSingleton.EmuThreadExecute(a, false);
                }
                break;

                case REMOTE_SET_APPLYUNCORRUPTBL:
                {
                    void a()
                    {
                        if (StockpileManager_EmuSide.UnCorruptBL != null)
                        {
                            StockpileManager_EmuSide.UnCorruptBL.Apply(true);
                        }
                    }
                    SyncObjectSingleton.EmuThreadExecute(a, false);
                }
                break;

                case REMOTE_SET_APPLYCORRUPTBL:
                {
                    void a()
                    {
                        if (StockpileManager_EmuSide.CorruptBL != null)
                        {
                            StockpileManager_EmuSide.CorruptBL.Apply(false);
                        }
                    }
                    SyncObjectSingleton.EmuThreadExecute(a, false);
                }
                break;

                case REMOTE_CLEARSTEPBLASTUNITS:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        StepActions.ClearStepBlastUnits();
                    });
                    break;

                case REMOTE_LOADPLUGINS:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        string emuPluginDir = "";
                        try
                        {
                            emuPluginDir = System.IO.Path.Combine(RtcCore.EmuDir, "RTC", "PLUGINS");
                        }
                        catch (Exception e)
                        {
                            RTCV.Common.Logging.GlobalLogger.Error(e, "Unable to find plugin dir in {dir}", RtcCore.EmuDir + "\\RTC" + "\\PLUGINS");
                        }
                        RtcCore.LoadPlugins(new[] { RtcCore.pluginDir, emuPluginDir });
                    });

                    break;

                case REMOTE_REMOVEEXCESSINFINITESTEPUNITS:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        StepActions.RemoveExcessInfiniteStepUnits();
                    });
                    break;

                default:
                    new object();
                    break;
                }

                return(e.returnMessage);
            }
            catch (Exception ex)
            {
                if (CloudDebug.ShowErrorDialog(ex, true) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }

                return(e.returnMessage);
            }
        }
Пример #20
0
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                // This is where you implement interaction.
                // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                ConsoleEx.WriteLine(message.Type);
                switch (message.Type) //Handle received messages here
                {
                case REMOTE_ALLSPECSSENT:
                {
                    //We still need to set the emulator's path
                    AllSpec.VanguardSpec.Update(VSPEC.EMUDIR, FileWatch.currentDir);
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            FileWatch.UpdateDomains();
                        });
                }
                break;

                case SAVESAVESTATE:
                    e.setReturnValue("");
                    break;

                case LOADSAVESTATE:
                    e.setReturnValue(true);
                    break;

                case REMOTE_PRECORRUPTACTION:
                    FileWatch.KillProcess();
                    FileWatch.currentFileInfo.targetInterface.CloseStream();
                    FileWatch.RestoreTarget();
                    break;

                case REMOTE_POSTCORRUPTACTION:
                    //var fileName = advancedMessage.objectValue as String;
                    FileWatch.currentFileInfo.targetInterface.CloseStream();
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Executor.Execute();
                    });
                    break;

                case REMOTE_CLOSEGAME:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        FileWatch.KillProcess();
                    });
                    break;

                case REMOTE_DOMAIN_GETDOMAINS:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(FileWatch.GetInterfaces());
                    });
                    break;

                case REMOTE_EVENT_EMU_MAINFORM_CLOSE:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Environment.Exit(0);
                    });
                    break;

                case REMOTE_ISNORMALADVANCE:
                    e.setReturnValue(true);
                    break;

                case REMOTE_EVENT_CLOSEEMULATOR:
                    Environment.Exit(-1);
                    break;
                }
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Пример #21
0
 private void Singularity_ConsoleWritten(object sender, NetCoreEventArgs e)
 {
     lbNetCoreConsole.Items.Add(e.message.Type + "\n");
     lbNetCoreConsole.SelectedIndex = lbNetCoreConsole.Items.Count - 1;
 }
Пример #22
0
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                switch (message.Type) //Handle received messages here
                {
                case REMOTE_PUSHVANGUARDSPEC:
                {
                    if (!CorruptCore.RtcCore.Attached)
                    {
                        RTCV.NetCore.AllSpec.VanguardSpec = new FullSpec((PartialSpec)advancedMessage.objectValue, !CorruptCore.RtcCore.Attached);
                    }

                    e.setReturnValue(true);

                    //Push the UI and CorruptCore spec (since we're master)
                    LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_PUSHUISPEC, RTCV.NetCore.AllSpec.UISpec.GetPartialSpec(), true);
                    LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_PUSHCORRUPTCORESPEC, RTCV.NetCore.AllSpec.CorruptCoreSpec.GetPartialSpec(), true);

                    SyncObjectSingleton.FormExecute(() =>
                        {
                            S.GET <UI_CoreForm>().pnAutoKillSwitch.Visible  = true;
                            S.GET <UI_CoreForm>().pnCrashProtection.Visible = true;
                        });
                    //Specs are all set up so UI is clear.
                    LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_ALLSPECSSENT, true);
                }
                break;

                case REMOTE_ALLSPECSSENT:
                    if (UICore.FirstConnect)
                    {
                        UICore.Initialized.WaitOne(10000);
                    }

                    SyncObjectSingleton.FormExecute(() =>
                    {
                        if (UICore.FirstConnect)
                        {
                            lastVanguardClient  = (string)RTCV.NetCore.AllSpec.VanguardSpec?[VSPEC.NAME] ?? "VANGUARD";
                            UICore.FirstConnect = false;

                            //Load plugins on both sides
                            CorruptCore.RtcCore.LoadPlugins();
                            LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_LOADPLUGINS, true);

                            //Configure the UI based on the vanguard spec
                            UICore.ConfigureUIFromVanguardSpec();

                            S.GET <UI_CoreForm>().Show();

                            //Pull any lists from the vanguard implementation
                            if (RtcCore.EmuDir != null)
                            {
                                UICore.LoadLists(Path.Combine(RtcCore.EmuDir, "LISTS"));
                            }

                            UICore.LoadLists(CorruptCore.RtcCore.listsDir);

                            Panel sidebar = S.GET <UI_CoreForm>().pnSideBar;
                            foreach (Control c in sidebar.Controls)
                            {
                                if (c is Button b)
                                {
                                    if (!b.Text.Contains("Test") && !b.Text.Contains("Custom Layout") && b.ForeColor != Color.OrangeRed)
                                    {
                                        b.Visible = true;
                                    }
                                }
                            }

                            string customLayoutPath = Path.Combine(RTCV.CorruptCore.RtcCore.RtcDir, "CustomLayout.txt");
                            if (File.Exists(customLayoutPath))
                            {
                                S.GET <UI_CoreForm>().btnOpenCustomLayout.Visible = true;
                            }

                            UI_DefaultGrids.engineConfig.LoadToMain();

                            UI_DefaultGrids.glitchHarvester.LoadToNewWindow("Glitch Harvester", true);
                        }
                        else
                        {
                            var clientName = (string)RTCV.NetCore.AllSpec.VanguardSpec?[VSPEC.NAME] ?? "VANGUARD";
                            if (clientName != lastVanguardClient)
                            {
                                MessageBox.Show($"Error: Found {clientName} when previously connected to {lastVanguardClient}.\nPlease restart the RTC to swap clients.");
                                return;
                            }

                            //Push the VMDs since we store them out of spec
                            var vmdProtos = MemoryDomains.VmdPool.Values.Cast <VirtualMemoryDomain>().Select(x => x.Proto).ToArray();
                            LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_PUSHVMDPROTOS, vmdProtos, true);

                            S.GET <UI_CoreForm>().Show();

                            //Configure the UI based on the vanguard spec
                            UICore.ConfigureUIFromVanguardSpec();

                            //Unblock the controls in the GH
                            S.GET <RTC_GlitchHarvesterBlast_Form>().SetBlastButtonVisibility(true);

                            //Return to the main form. If the form is null for some reason, default to engineconfig
                            if (S.GET <UI_CoreForm>().previousGrid == null)
                            {
                                S.GET <UI_CoreForm>().previousGrid = UI_DefaultGrids.engineConfig;
                            }

                            UICore.UnlockInterface();
                            S.GET <UI_CoreForm>().previousGrid.LoadToMain();
                        }

                        S.GET <UI_CoreForm>().pbAutoKillSwitchTimeout.Value = 0;   //remove this once core form is dead

                        if (!CorruptCore.RtcCore.Attached)
                        {
                            AutoKillSwitch.Enabled = true;
                        }

                        //Restart game protection
                        if (S.GET <UI_CoreForm>().cbUseGameProtection.Checked)
                        {
                            if (CorruptCore.StockpileManager_UISide.BackupedState != null)
                            {
                                CorruptCore.StockpileManager_UISide.BackupedState.Run();
                            }

                            if (CorruptCore.StockpileManager_UISide.BackupedState != null)
                            {
                                S.GET <RTC_MemoryDomains_Form>().RefreshDomainsAndKeepSelected(CorruptCore.StockpileManager_UISide.BackupedState.SelectedDomains.ToArray());
                            }

                            GameProtection.Start();
                            if (GameProtection.WasAutoCorruptRunning)
                            {
                                S.GET <UI_CoreForm>().AutoCorrupt = true;
                            }
                        }

                        S.GET <UI_CoreForm>().Show();

                        if (NetCore.Params.IsParamSet("SIMPLE_MODE"))
                        {
                            bool isSpec = (AllSpec.VanguardSpec[VSPEC.NAME] as string)?.ToUpper().Contains("SPEC") ?? false;

                            if (isSpec)     //Simple Mode cannot run on Stubs
                            {
                                MessageBox.Show("Unfortunately, Simple Mode is not compatible with Stubs. RTC will now switch to Normal Mode.");
                                NetCore.Params.RemoveParam("SIMPLE_MODE");
                            }
                            else
                            {
                                UI_DefaultGrids.simpleMode.LoadToMain();
                                RTC_SimpleMode_Form smForm = S.GET <RTC_SimpleMode_Form>();
                                smForm.EnteringSimpleMode();
                            }
                        }
                    });
                    break;

                case REMOTE_PUSHVANGUARDSPECUPDATE:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        RTCV.NetCore.AllSpec.VanguardSpec?.Update((PartialSpec)advancedMessage.objectValue);
                    });
                    e.setReturnValue(true);
                    break;

                //CorruptCore pushed its spec. Note the false on propogate (since we don't want a recursive loop)
                case REMOTE_PUSHCORRUPTCORESPECUPDATE:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        RTCV.NetCore.AllSpec.CorruptCoreSpec?.Update((PartialSpec)advancedMessage.objectValue, false);
                    });
                    e.setReturnValue(true);
                    break;

                case REMOTE_GENERATEVMDTEXT:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        object[] objs = (object[])advancedMessage.objectValue;
                        string domain = (string)objs[0];
                        string text   = (string)objs[1];

                        var vmdgenerator = S.GET <RTC_VmdGen_Form>();

                        vmdgenerator.btnSelectAll_Click(null, null);

                        var cbitems        = vmdgenerator.cbSelectedMemoryDomain.Items;
                        object domainFound = null;
                        for (int i = 0; i < cbitems.Count; i++)
                        {
                            var item = cbitems[i];

                            if (item.ToString() == domain)
                            {
                                domainFound = item;
                                vmdgenerator.cbSelectedMemoryDomain.SelectedIndex = i;
                                break;
                            }
                        }

                        if (domainFound == null)
                        {
                            throw new Exception($"Domain {domain} could not be selected in the VMD Generator. Aborting procedure.");
                            //return;
                        }

                        vmdgenerator.tbCustomAddresses.Text = text;

                        string value = "";

                        if (RTCV.UI.UI_Extensions.GetInputBox("VMD Generation", "Enter the new VMD name:", ref value) == DialogResult.OK)
                        {
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                vmdgenerator.tbVmdName.Text = value.Trim();
                            }
                            vmdgenerator.btnGenerateVMD_Click(null, null);
                        }
                    });
                    e.setReturnValue(true);
                    break;

                case REMOTE_EVENT_DOMAINSUPDATED:

                    SyncObjectSingleton.FormExecute(() =>
                    {
                        S.GET <RTC_MemoryDomains_Form>().RefreshDomains();
                        S.GET <RTC_MemoryDomains_Form>().SetMemoryDomainsAllButSelectedDomains(RTCV.NetCore.AllSpec.VanguardSpec[VSPEC.MEMORYDOMAINS_BLACKLISTEDDOMAINS] as string[] ?? new string[] { });
                    });
                    break;

                case REMOTE_GETBLASTGENERATOR_LAYER:

                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(S.GET <RTC_BlastGenerator_Form>().GenerateBlastLayers(true, true, false));
                    });
                    break;

                case ERROR_DISABLE_AUTOCORRUPT:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        S.GET <UI_CoreForm>().AutoCorrupt = false;
                    });
                    break;

                case REMOTE_RENDER_DISPLAY:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        S.GET <RTC_GlitchHarvesterBlast_Form>().refreshRenderOutputButton();
                    });
                    break;

                case REMOTE_BACKUPKEY_STASH:
                    if (advancedMessage?.objectValue is StashKey sk)
                    {
                        StockpileManager_UISide.BackupedState = sk;
                        GameProtection.AddBackupState(sk);
                        SyncObjectSingleton.FormExecute(() =>
                        {
                            S.GET <UI_CoreForm>().btnGpJumpBack.Visible = true;
                            S.GET <UI_CoreForm>().btnGpJumpNow.Visible  = true;
                        });
                    }
                    break;

                case KILLSWITCH_PULSE:
                    AutoKillSwitch.Pulse();
                    break;

                case RESET_GAME_PROTECTION_IF_RUNNING:
                    if (GameProtection.isRunning)
                    {
                        SyncObjectSingleton.FormExecute(() =>
                        {
                            S.GET <UI_CoreForm>().cbUseGameProtection.Checked = false;
                            S.GET <UI_CoreForm>().cbUseGameProtection.Checked = true;
                        });
                    }
                    break;

                case REMOTE_DISABLESAVESTATESUPPORT:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        S.GET <RTC_SavestateManager_Form>().DisableFeature();
                        S.GET <UI_CoreForm>().pnCrashProtection.Visible = false;
                    });
                    break;

                case REMOTE_DISABLEGAMEPROTECTIONSUPPORT:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        S.GET <UI_CoreForm>().pnCrashProtection.Visible = false;
                    });
                    break;

                case REMOTE_DISABLEREALTIMESUPPORT:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Button btnManual = S.GET <UI_CoreForm>().btnManualBlast;
                        if (AllSpec.VanguardSpec[VSPEC.REPLACE_MANUALBLAST_WITH_GHCORRUPT] != null)
                        {
                            btnManual.Text = "  Corrupt";
                        }
                        else
                        {
                            btnManual.Visible = false;
                        }

                        S.GET <UI_CoreForm>().btnAutoCorrupt.Enabled = false;
                        S.GET <UI_CoreForm>().btnAutoCorrupt.Visible = false;
                        S.GET <RTC_GeneralParameters_Form>().multiTB_ErrorDelay.Enabled = false;
                        S.GET <RTC_GlitchHarvesterBlast_Form>().btnSendRaw.Enabled      = false;
                        S.GET <RTC_GlitchHarvesterBlast_Form>().btnBlastToggle.Enabled  = false;

                        S.GET <RTC_CorruptionEngine_Form>().cbSelectedEngine.Items.Remove("Hellgenie Engine");
                        S.GET <RTC_CorruptionEngine_Form>().cbSelectedEngine.Items.Remove("Distortion Engine");
                        S.GET <RTC_CorruptionEngine_Form>().cbSelectedEngine.Items.Remove("Pipe Engine");
                        S.GET <RTC_CorruptionEngine_Form>().cbSelectedEngine.Items.Remove("Freeze Engine");
                    });
                    break;

                case REMOTE_DISABLEKILLSWITCHSUPPORT:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        S.GET <UI_CoreForm>().pnAutoKillSwitch.Visible    = false;
                        S.GET <UI_CoreForm>().cbUseAutoKillSwitch.Checked = false;
                    });
                    break;
                }
            }
            catch (Exception ex)
            {
                if (CloudDebug.ShowErrorDialog(ex) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }

                return;
            }
        }
Пример #23
0
 public void OnMessageReceivedProxy(object sender, NetCoreEventArgs e) => OnMessageReceived(sender, e);
Пример #24
0
 public virtual void OnFormRegistered(NetCoreEventArgs e) => FormRegistered?.Invoke(this, e);
Пример #25
0
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                // This is where you implement interaction.
                // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                ConsoleEx.WriteLine(message.Type);
                switch (message.Type)                 //Handle received messages here
                {
                case RTCV.NetCore.Commands.Remote.AllSpecSent:
                {
                    if (VanguardCore.FirstConnect)
                    {
                        SyncObjectSingleton.FormExecute(() =>
                            {
                                VanguardCore.LoadDefaultAndShowBizhawkForm();
                            });
                        VanguardCore.FirstConnect = false;
                    }
                }
                break;

                case RTCV.NetCore.Commands.Basic.SaveSavestate:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(VanguardCore.SaveSavestate_NET(advancedMessage.objectValue as string));
                    });
                    break;

                case RTCV.NetCore.Commands.Basic.LoadSavestate:
                {
                    var cmd      = advancedMessage.objectValue as object[];
                    var path     = cmd[0] as string;
                    var location = (StashKeySavestateLocation)cmd[1];
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            e.setReturnValue(VanguardCore.LoadSavestate_NET(path, location));
                        });
                    break;
                }

                case RTCV.NetCore.Commands.Remote.LoadROM:
                {
                    var fileName = advancedMessage.objectValue as String;
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            VanguardCore.LoadRom_NET(fileName);
                        });
                }
                break;

                case RTCV.NetCore.Commands.Remote.CloseGame:
                {
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            Hooks.CLOSE_GAME(true);
                        });
                }
                break;

                case RTCV.NetCore.Commands.Remote.DomainGetDomains:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(Hooks.GetInterfaces());
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.KeySetSyncSettings:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Hooks.BIZHAWK_GETSET_SYNCSETTINGS = (string)advancedMessage.objectValue;
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.KeySetSystemCore:
                {
                    var cmd        = advancedMessage.objectValue as object[];
                    var systemName = (string)cmd[0];
                    var systemCore = (string)cmd[1];
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            Hooks.BIZHAWK_SET_SYSTEMCORE(systemName, systemCore);
                        });
                }
                break;

                case RTCV.NetCore.Commands.Remote.OpenHexEditor:
                    SyncObjectSingleton.FormExecute(() => Hooks.BIZHAWK_OPEN_HEXEDITOR());
                    break;

                case RTCV.NetCore.Commands.Emulator.GetRealtimeAPI:
                    e.setReturnValue(VanguardCore.RTE_API);
                    break;

                case RTCV.NetCore.Commands.Emulator.GetScreenshot:
                    e.setReturnValue(Hooks.BIZHAWK_GET_SCREENSHOT());
                    break;

                case RTCV.NetCore.Commands.Emulator.OpenHexEditorAddress:
                {
                    var    temp    = advancedMessage.objectValue as object[];
                    string domain  = (string)temp[0];
                    long   address = (long)temp[1];

                    MemoryDomainProxy mdp = MemoryDomains.GetProxy(domain, address);
                    long realAddress      = MemoryDomains.GetRealAddress(domain, address);

                    SyncObjectSingleton.FormExecute(() =>
                        {
                            Hooks.BIZHAWK_OPEN_HEXEDITOR_ADDRESS(mdp, realAddress);
                        });

                    break;
                }

                case RTCV.NetCore.Commands.Remote.EventEmuMainFormClose:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Hooks.BIZHAWK_MAINFORM_CLOSE();
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.RenderStart:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        BizhawkRender.StartRender_NET();
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.RenderStop:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        BizhawkRender.StopRender_NET();
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.EventEmuStarted:
                    //if (RTC_StockpileManager.BackupedState == null)
                    //S.GET<RTC_Core_Form>().AutoCorrupt = false;


                    //Todo
                    //RTC_NetcoreImplementation.SendCommandToBizhawk(new RTC_Command("REMOTE_PUSHVMDS) { objectValue = MemoryDomains.VmdPool.Values.Select(it => (it as VirtualMemoryDomain).Proto).ToArray() }, true, true);

                    //Thread.Sleep(100);

                    //		if (RTC_StockpileManager.BackupedState != null)
                    //			S.GET<RTC_MemoryDomains_Form>().RefreshDomainsAndKeepSelected(RTC_StockpileManager.BackupedState.SelectedDomains.ToArray());

                    //		if (S.GET<RTC_Core_Form>().cbUseGameProtection.Checked)
                    //			RTC_GameProtection.Start();

                    break;

                case RTCV.NetCore.Commands.Remote.IsNormalAdvance:
                    e.setReturnValue(Hooks.isNormalAdvance);
                    break;

                case RTCV.NetCore.Commands.Remote.EventCloseEmulator:
                    Environment.Exit(-1);
                    break;
                }
            }
            catch (Exception ex)
            {
                VanguardCore.ShowErrorDialog(ex, true);
            }
        }
Пример #26
0
        private static void OnMessageReceived(object sender, NetCoreEventArgs e)
        {
            try
            {
                // This is where you implement interaction.
                // Warning: Any error thrown in here will be caught by NetCore and handled by being displayed in the console.

                var message         = e.message;
                var simpleMessage   = message as NetCoreSimpleMessage;
                var advancedMessage = message as NetCoreAdvancedMessage;

                ConsoleEx.WriteLine(message.Type);
                switch (message.Type) //Handle received messages here
                {
                case RTCV.NetCore.Commands.Remote.AllSpecSent:
                {
                    //We still need to set the emulator's path
                    AllSpec.VanguardSpec.Update(VSPEC.EMUDIR, CemuWatch.currentGameInfo.cemuExeFile.Directory.FullName);
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            CemuWatch.UpdateDomains();
                        });
                }
                break;

                case RTCV.NetCore.Commands.Basic.SaveSavestate:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(VanguardCore.SaveSavestate_NET(advancedMessage.objectValue as string));
                        //e.setReturnValue("");
                    });
                    break;

                case RTCV.NetCore.Commands.Basic.LoadSavestate:
                {
                    var cmd      = advancedMessage.objectValue as object[];
                    var path     = cmd[0] as string;
                    var location = (StashKeySavestateLocation)cmd[1];
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            e.setReturnValue(VanguardCore.LoadSavestate_NET(path, location));
                        });


                    e.setReturnValue(true);
                    break;
                }

                case RTCV.NetCore.Commands.Remote.PreCorruptAction:
                    CemuWatch.KillCemuProcess(false);
                    CemuWatch.RestoreBackup();
                    break;

                case RTCV.NetCore.Commands.Remote.PostCorruptAction:
                {
                    //var fileName = advancedMessage.objectValue as String;
                    SyncObjectSingleton.FormExecute(() =>
                        {
                            CemuWatch.StartRpx();
                        });
                }
                break;

                case RTCV.NetCore.Commands.Remote.CloseGame:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        CemuWatch.KillCemuProcess(false);
                    });

                    break;

                case RTCV.NetCore.Commands.Remote.DomainGetDomains:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        e.setReturnValue(CemuWatch.GetInterfaces());
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.EventEmuMainFormClose:
                    SyncObjectSingleton.FormExecute(() =>
                    {
                        Environment.Exit(0);
                    });
                    break;

                case RTCV.NetCore.Commands.Remote.IsNormalAdvance:
                    e.setReturnValue(true);
                    //e.setReturnValue(Hooks.isNormalAdvance);
                    break;

                case RTCV.NetCore.Commands.Remote.EventCloseEmulator:
                    Environment.Exit(-1);
                    break;
                }
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }