public static void UpdateDomains()
        {
            try
            {
                PartialSpec gameDone = new PartialSpec("VanguardSpec");
                gameDone[VSPEC.SYSTEM]       = "FileSystem";
                gameDone[VSPEC.GAMENAME]     = FileWatch.currentFileInfo.targetShortName;
                gameDone[VSPEC.SYSTEMPREFIX] = "FileStub";
                gameDone[VSPEC.SYSTEMCORE]   = "FileStub";
                //gameDone[VSPEC.SYNCSETTINGS] = BIZHAWK_GETSET_SYNCSETTINGS;
                gameDone[VSPEC.OPENROMFILENAME] = currentFileInfo.targetFullName;
                gameDone[VSPEC.MEMORYDOMAINS_BLACKLISTEDDOMAINS] = new string[0];
                gameDone[VSPEC.MEMORYDOMAINS_INTERFACES]         = GetInterfaces();
                gameDone[VSPEC.CORE_DISKBASED] = false;
                AllSpec.VanguardSpec.Update(gameDone);

                //This is local. If the domains changed it propgates over netcore
                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_EVENT_DOMAINSUPDATED, true, true);

                //Asks RTC to restrict any features unsupported by the stub
                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_EVENT_RESTRICTFEATURES, true, true);
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Ejemplo n.º 2
0
        public static bool InjectFromStashkey(StashKey sk, bool _loadBeforeOperation = true)
        {
            string saveStateWord = "Savestate";

            object renameSaveStateWord = AllSpec.VanguardSpec[VSPEC.RENAME_SAVESTATE];

            if (renameSaveStateWord != null && renameSaveStateWord is String s)
            {
                saveStateWord = s;
            }


            PreApplyStashkey();

            StashKey psk = CurrentSavestateStashKey;

            if (psk == null)
            {
                MessageBox.Show($"The Glitch Harvester could not perform the INJECT action\n\nEither no {saveStateWord} Box was selected in the {saveStateWord} Manager\nor the {saveStateWord} Box itself is empty.");
                return(false);
            }

            if (psk.SystemCore != sk.SystemCore && !RtcCore.AllowCrossCoreCorruption)
            {
                MessageBox.Show("Merge attempt failed: Core mismatch\n\n" + $"{psk.GameName} -> {psk.SystemName} -> {psk.SystemCore}\n{sk.GameName} -> {sk.SystemName} -> {sk.SystemCore}");
                return(false);
            }

            CurrentStashkey = new StashKey(RtcCore.GetRandomKey(), psk.ParentKey, sk.BlastLayer)
            {
                RomFilename   = psk.RomFilename,
                SystemName    = psk.SystemName,
                SystemCore    = psk.SystemCore,
                GameName      = psk.GameName,
                SyncSettings  = psk.SyncSettings,
                StateLocation = psk.StateLocation
            };

            if (_loadBeforeOperation)
            {
                if (!LoadState(CurrentStashkey))
                {
                    return(false);
                }
            }
            else
            {
                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.APPLYBLASTLAYER, new object[] { CurrentStashkey.BlastLayer, true }, true);
            }

            bool isCorruptionApplied = CurrentStashkey?.BlastLayer?.Layer?.Count > 0;

            if (StashAfterOperation)
            {
                StashHistory.Add(CurrentStashkey);
            }

            PostApplyStashkey();
            return(isCorruptionApplied);
        }
Ejemplo n.º 3
0
        public static bool ApplyStashkey(StashKey sk, bool _loadBeforeOperation = true, bool _clearUnitsBeforeApply = true)
        {
            PreApplyStashkey(_clearUnitsBeforeApply);

            bool isCorruptionApplied = sk?.BlastLayer?.Layer?.Count > 0;

            if (_loadBeforeOperation)
            {
                if (!LoadState(sk))
                {
                    return(isCorruptionApplied);
                }
            }
            else
            {
                bool mergeWithCurrent = !_clearUnitsBeforeApply;

                //APPLYBLASTLAYER
                //Param 0 is BlastLayer
                //Param 1 is storeUncorruptBackup
                //Param 2 is MergeWithCurrent (for fixing blast toggle with inject)
                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.APPLYBLASTLAYER, new object[] { sk?.BlastLayer, true, mergeWithCurrent }, true);
            }

            PostApplyStashkey();
            return(isCorruptionApplied);
        }
Ejemplo n.º 4
0
        private void btnActiveTableAddDump_Click(object sender, EventArgs e)
        {
            if (cbSelectedMemoryDomain == null || MemoryDomains.GetInterface(cbSelectedMemoryDomain.SelectedItem.ToString()).Size.ToString() == null)
            {
                MessageBox.Show("Select a valid domain before continuing!");
                return;
            }
            if (MemoryDumps == null)
            {
                return;
            }

            string key = CorruptCore.RtcCore.GetRandomKey();

            LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_DOMAIN_ACTIVETABLE_MAKEDUMP, new object[] { cbSelectedMemoryDomain.SelectedItem.ToString(), key }, true);

            var keyPath = Path.Combine(RtcCore.workingDir, "MEMORYDUMPS", key + ".dmp");

            MemoryDumps.Add(keyPath);
            lbNbMemoryDumps.Text = "Memory dumps collected: " + MemoryDumps.Count.ToString();

            if (MemoryDumps.Count > 1)
            {
                btnSendToAnalytics.Enabled = true;
            }
        }
Ejemplo n.º 5
0
        //private static void CorruptTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        //{
        //    lock (CorruptLock)
        //    {
        //        if (!VanguardCore.vanguardConnected || AllSpec.CorruptCoreSpec == null || (p?.HasExited ?? true))
        //        {
        //            AutoCorruptTimer.Start();
        //            return;
        //        }

        //        try
        //        {
        //            if (!DontChangeMemoryProtection)
        //            {
        //                foreach (var m in MemoryDomains.MemoryInterfaces?.Values ?? Enumerable.Empty<MemoryDomainProxy>())
        //                {
        //                    if (m.MD is ProcessMemoryDomain pmd)
        //                    {
        //                        pmd.SetMemoryProtection(ProcessExtensions.MemoryProtection.ExecuteReadWrite);
        //                        if (p?.HasExited ?? false)
        //                        {
        //                            Console.WriteLine($"Bad! {pmd.Name}");
        //                        }
        //                    }
        //                }
        //            }

        //            try
        //            {
        //                RtcClock.StepCorrupt(true, true);

        //                if (p?.HasExited ?? false)
        //                {
        //                    Console.WriteLine($"Bad2!");
        //                }
        //            }
        //            catch (Exception ex)
        //            {
        //                Console.WriteLine($"STEP_CORRUPT Error!\n{ex.Message}\n{ex.StackTrace}");
        //            }
        //        }
        //        finally
        //        {
        //            if (!DontChangeMemoryProtection)
        //            {
        //                foreach (var m in MemoryDomains.MemoryInterfaces?.Values ?? Enumerable.Empty<MemoryDomainProxy>())
        //                {
        //                    if (m.MD is ProcessMemoryDomain pmd)
        //                    {
        //                        pmd.ResetMemoryProtection();
        //                        pmd.FlushInstructionCache();
        //                    }

        //                    if (p?.HasExited ?? false)
        //                    {
        //                        Console.WriteLine($"Bad3!");
        //                    }
        //                }
        //            }
        //        }
        //    }

        //    if (p.HasExited)
        //    {
        //        Console.WriteLine($"Bad4!");
        //    }
        //    AutoCorruptTimer.Start();
        //}

        //private static void AutoHookTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        //{
        //    try
        //    {
        //        if (p?.HasExited == false)
        //            return;
        //        SyncObjectSingleton.FormExecute(() => S.GET<StubForm>().lbTargetStatus.Text = "Waiting...");
        //        var procToFind = S.GET<StubForm>().tbClientAddr.Text;
        //        if (string.IsNullOrWhiteSpace(procToFind))
        //            return;

        //        SyncObjectSingleton.FormExecute(() => S.GET<StubForm>().lbTargetStatus.Text = "Hooking...");
        //        var _p = Process.GetProcesses().First(x => x.ProcessName == procToFind);
        //        if (_p != null)
        //        {
        //            Thread.Sleep(2000); //Give the process 2 seconds
        //            SyncObjectSingleton.FormExecute(() =>
        //            {
        //                LoadTarget(_p);

        //                if (!VanguardCore.vanguardConnected)
        //                    VanguardCore.Start();

        //                S.GET<StubForm>().EnableTargetInterface();
        //            });
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine($"AutoHook failed.\n{ex.Message}\n{ex.StackTrace}");
        //    }
        //    AutoHookTimer.Start();
        //}

        //internal static bool LoadTarget(Process _p = null)
        //{
        //    lock (CorruptLock)
        //    {
        //        if (_p == null)
        //        {
        //            using (var f = new HookProcessForm())
        //            {
        //                if (f.ShowDialog() != DialogResult.OK)
        //                    return false;

        //                if (f.RequestedProcess == null || (f.RequestedProcess?.HasExited ?? true))
        //                {
        //                    return false;
        //                }

        //                if (IsProcessBlacklisted(f.RequestedProcess))
        //                {
        //                    MessageBox.Show("Blacklisted process");
        //                    return false;
        //                }

        //                p = f.RequestedProcess;
        //            }
        //        }
        //        else
        //            p = _p;
        //        /*
        //        if (UseExceptionHandler)
        //        {
        //            ProcessExtensions.IsWow64Process(p.Handle, out bool is32BitProcess); //This method is stupid and returns the inverse
        //            string path = is32BitProcess
        //                ? Path.Combine(currentDir, "ExceptionHandler_x86.dll")
        //                : Path.Combine(currentDir, "ExceptionHandler_x64.dll");
        //            if (File.Exists(path))
        //            {
        //                try
        //                {
        //                    using (var i = new Injector(InjectionMethod.CreateThread, p.Id, path))
        //                    {
        //                        if ((ulong) i.InjectDll() != 0)
        //                        {
        //                            Console.WriteLine("Injected exception helper successfully");
        //                        }
        //                    }
        //                }
        //                catch (Exception e)
        //                {
        //                    Console.WriteLine($"Injection failed! {e}");
        //                }
        //            }
        //        }*/

        //        Action<object, EventArgs> action = (ob, ea) =>
        //        {
        //            if (VanguardCore.vanguardConnected)
        //                UpdateDomains();
        //        };

        //        Action<object, EventArgs> postAction = (ob, ea) =>
        //        {
        //            if (p == null)
        //            {
        //                MessageBox.Show("Failed to load target");
        //                S.GET<StubForm>().DisableTargetInterface();
        //                return;
        //            }

        //            S.GET<StubForm>().lbTarget.Text = p.ProcessName;
        //            S.GET<StubForm>().lbTargetStatus.Text = "Hooked!";

        //            //Refresh the UI
        //            //RefreshUIPostLoad();
        //        };
        //        S.GET<StubForm>().RunProgressBar($"Loading target...", 0, action, postAction);
        //    }

        //    return true;
        //}

        //internal static bool CloseTarget(bool updateDomains = true)
        //{
        //    p = null;
        //    if (updateDomains)
        //        UpdateDomains();
        //    return true;
        //}

        public static void UpdateDomains()
        {
            if (!VanguardCore.vanguardConnected)
            {
                return;
            }
            try
            {
                PartialSpec gameDone = new PartialSpec("VanguardSpec");
                gameDone[VSPEC.SYSTEM]          = "Linux";
                gameDone[VSPEC.GAMENAME]        = "IGNORE";
                gameDone[VSPEC.SYSTEMPREFIX]    = "Linux";
                gameDone[VSPEC.SYSTEMCORE]      = "Linux";
                gameDone[VSPEC.OPENROMFILENAME] = "IGNORE";
                gameDone[VSPEC.MEMORYDOMAINS_BLACKLISTEDDOMAINS] = Array.Empty <string>();
                gameDone[VSPEC.MEMORYDOMAINS_INTERFACES]         = GetInterfaces();
                gameDone[VSPEC.CORE_DISKBASED] = false;
                AllSpec.VanguardSpec.Update(gameDone);

                //This is local. If the domains changed it propgates over netcore
                LocalNetCoreRouter.Route(RTCV.NetCore.Endpoints.CorruptCore, RTCV.NetCore.Commands.Remote.EventDomainsUpdated, true, true);

                //Asks RTC to restrict any features unsupported by the stub
                LocalNetCoreRouter.Route(RTCV.NetCore.Endpoints.CorruptCore, RTCV.NetCore.Commands.Remote.EventRestrictFeatures, true, true);
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Ejemplo n.º 6
0
        public static void UpdateDomains()
        {
            try
            {
                PartialSpec gameDone = new PartialSpec("VanguardSpec");
                gameDone[VSPEC.SYSTEM]       = "FileSystem";
                gameDone[VSPEC.GAMENAME]     = FileWatch.currentSession.targetShortName;
                gameDone[VSPEC.SYSTEMPREFIX] = "FileStub";
                gameDone[VSPEC.SYSTEMCORE]   = "FileStub";
                //gameDone[VSPEC.SYNCSETTINGS] = BIZHAWK_GETSET_SYNCSETTINGS;
                gameDone[VSPEC.OPENROMFILENAME] = currentSession.targetFullName;
                gameDone[VSPEC.MEMORYDOMAINS_BLACKLISTEDDOMAINS] = Array.Empty <string>();
                gameDone[VSPEC.MEMORYDOMAINS_INTERFACES]         = GetInterfaces();
                gameDone[VSPEC.CORE_DISKBASED] = false;
                AllSpec.VanguardSpec.Update(gameDone);

                //This is local. If the domains changed it propgates over netcore
                LocalNetCoreRouter.Route(RTCV.NetCore.Endpoints.CorruptCore, RTCV.NetCore.Commands.Remote.EventDomainsUpdated, true, true);

                //Asks RTC to restrict any features unsupported by the stub
                LocalNetCoreRouter.Route(RTCV.NetCore.Endpoints.CorruptCore, RTCV.NetCore.Commands.Remote.EventRestrictFeatures, true, true);
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Ejemplo n.º 7
0
        private static void PreApplyStashkey()
        {
            LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_CLEARSTEPBLASTUNITS, null, true);

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

            LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_PRECORRUPTACTION, null, true);
        }
Ejemplo n.º 8
0
        public static void Start(Form standaloneForm = null)
        {
            S.formRegister.FormRegistered += FormRegister_FormRegistered;
            //registerFormEvents(S.GET<RTC_Core_Form>());
            registerFormEvents(S.GET <UI_CoreForm>());
            registerHotkeyBlacklistControls(S.GET <UI_CoreForm>());

            if (!RtcCore.Attached)
            {
                S.SET((RTC_Standalone_Form)standaloneForm);
            }

            Form   dummy  = new Form();
            IntPtr Handle = dummy.Handle;

            SyncObjectSingleton.SyncObject = dummy;

            UI_VanguardImplementation.StartServer();

            PartialSpec p = new PartialSpec("UISpec");

            p["SELECTEDDOMAINS"] = new string[] { };

            RTCV.NetCore.AllSpec.UISpec              = new FullSpec(p, !CorruptCore.RtcCore.Attached);
            RTCV.NetCore.AllSpec.UISpec.SpecUpdated += (o, e) =>
            {
                PartialSpec partial = e.partialSpec;

                LocalNetCoreRouter.Route(CORRUPTCORE, REMOTE_PUSHUISPECUPDATE, partial, e.syncedUpdate);
            };

            CorruptCore.RtcCore.StartUISide();

            //Loading RTC Params

            S.GET <RTC_SettingsGeneral_Form>().cbDisableEmulatorOSD.Checked       = RTCV.NetCore.Params.IsParamSet(RTCSPEC.CORE_EMULATOROSDDISABLED);
            S.GET <RTC_SettingsGeneral_Form>().cbAllowCrossCoreCorruption.Checked = RTCV.NetCore.Params.IsParamSet("ALLOW_CROSS_CORE_CORRUPTION");
            S.GET <RTC_SettingsGeneral_Form>().cbDontCleanAtQuit.Checked          = RTCV.NetCore.Params.IsParamSet("DONT_CLEAN_SAVESTATES_AT_QUIT");
            S.GET <RTC_SettingsGeneral_Form>().cbUncapIntensity.Checked           = RTCV.NetCore.Params.IsParamSet("UNCAP_INTENSITY");

            //Initialize input code. Poll every 16ms
            Input.Input.Initialize();
            inputCheckTimer           = new System.Timers.Timer();
            inputCheckTimer.Elapsed  += ProcessInputCheck;
            inputCheckTimer.AutoReset = false;
            inputCheckTimer.Interval  = 10;
            inputCheckTimer.Start();

            if (FirstConnect)
            {
                UI_DefaultGrids.connectionStatus.LoadToMain();
            }

            LoadRTCColor();
            S.GET <UI_CoreForm>().Show();
            Initialized.Set();
            LoadRTCColor();
        }
Ejemplo n.º 9
0
 public void btnManualBlast_Click(object sender, EventArgs e)
 {
     if (AllSpec.VanguardSpec[VSPEC.REPLACE_MANUALBLAST_WITH_GHCORRUPT] != null)
     {
         S.GET <RTC_GlitchHarvesterBlast_Form>().btnCorrupt_Click(sender, e);
     }
     else
     {
         LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.MANUALBLAST, true);
     }
 }
Ejemplo n.º 10
0
        public void ResetSession()
        {
            var ui = S.GET <UI_CoreForm>();

            if (ui.AutoCorrupt)
            {
                btnAutoCorrupt_Click(null, null);
            }

            LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_CLEARSTEPBLASTUNITS, null, true);
        }
Ejemplo n.º 11
0
        private static void PostApplyStashkey()
        {
            bool UseSavestates = (bool)AllSpec.VanguardSpec[VSPEC.SUPPORTS_SAVESTATES];
            bool UseRealtime   = (bool)AllSpec.VanguardSpec[VSPEC.SUPPORTS_REALTIME];

            if (Render.RenderAtLoad && UseRealtime)
            {
                Render.StartRender();
            }

            LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_POSTCORRUPTACTION);
        }
        public static bool RefreshDomains(bool updateSpecs = true)
        {
            try
            {
                //Compare the old to the new. If the name and sizes are all the same, don't push that there were changes.
                //We need to compare like this because the domains can change from syncsettings.
                //We only check name and size as those are the only things that can change on the fly
                var  oldInterfaces  = VanguardCore.MemoryInterfacees;
                var  newInterfaces  = GetInterfaces();
                bool domainsChanged = false;

                if (oldInterfaces.Length != newInterfaces.Length)
                {
                    domainsChanged = true;
                }

                for (int i = 0; i < oldInterfaces.Length; i++)
                {
                    if (domainsChanged)
                    {
                        break;
                    }
                    if (oldInterfaces[i].Name != newInterfaces[i].Name)
                    {
                        domainsChanged = true;
                    }
                    if (oldInterfaces[i].Size != newInterfaces[i].Size)
                    {
                        domainsChanged = true;
                    }
                }

                //We gotta push this no matter what since it's new underlying objects
                if (updateSpecs)
                {
                    VanguardCore.VanguardSpec.Update(VSPEC.MEMORYDOMAINS_INTERFACES.ToString(), GetInterfaces());
                    LocalNetCoreRouter.Route(CORRUPTCORE, REMOTE_EVENT_DOMAINSUPDATED, domainsChanged, true);
                }


                return(domainsChanged);
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }

                return(false);
            }
        }
Ejemplo n.º 13
0
        private void btnOpenHexEditor_Click(object sender, EventArgs e)
        {
            bool UseRealtime = (bool?)AllSpec.VanguardSpec[VSPEC.SUPPORTS_REALTIME] ?? false;

            if (UseRealtime)
            {
                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_OPENHEXEDITOR);
            }
            else
            {
                MessageBox.Show("Hex editor only works with real-time systems");
            }
        }
        public static void LOAD_GAME_DONE()
        {
            try
            {
                if (disableRTC)
                {
                    return;
                }


                //Glitch Harvester warning for archives



                //prepare memory domains in advance on bizhawk side
                bool domainsChanged = RefreshDomains(false);

                PartialSpec gameDone = new PartialSpec("VanguardSpec");
                gameDone[VSPEC.SYSTEM]          = EMU_GET_CURRENTLYLOADEDSYSTEMNAME().ToUpper();
                gameDone[VSPEC.GAMENAME]        = EMU_GET_FILESYSTEMGAMENAME();
                gameDone[VSPEC.SYSTEMPREFIX]    = EMU_GET_SAVESTATEPREFIX();
                gameDone[VSPEC.SYSTEMCORE]      = EMU_GET_SYSTEMCORENAME("");
                gameDone[VSPEC.SYNCSETTINGS]    = EMU_GETSET_SYNCSETTINGS;
                gameDone[VSPEC.OPENROMFILENAME] = Program.RomFilename;
                gameDone[VSPEC.MEMORYDOMAINS_BLACKLISTEDDOMAINS] = VanguardCore.GetBlacklistedDomains(EMU_GET_CURRENTLYLOADEDSYSTEMNAME().ToUpper());
                gameDone[VSPEC.MEMORYDOMAINS_INTERFACES]         = GetInterfaces();
                VanguardCore.VanguardSpec.Update(gameDone);

                //This is local. If the domains changed it propgates over netcore
                LocalNetCoreRouter.Route(CORRUPTCORE, REMOTE_EVENT_DOMAINSUPDATED, domainsChanged, true);


                if (VanguardCore.GameName != lastGameName)
                {
                }
                else
                {
                }

                lastGameName = VanguardCore.GameName;
            }
            catch (Exception ex)
            {
                if (VanguardCore.ShowErrorDialog(ex) == DialogResult.Abort)
                {
                    throw new RTCV.NetCore.AbortEverythingException();
                }
            }
        }
Ejemplo n.º 15
0
        private void UI_CoreForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (S.GET <RTC_StockpileManager_Form>().UnsavedEdits&& !UICore.isClosing && MessageBox.Show("You have unsaved edits in the Glitch Harvester Stockpile. \n\n Are you sure you want to close RTC without saving?", "Unsaved edits in Stockpile", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                e.Cancel = true;
                return;
            }

            LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_EVENT_CLOSEEMULATOR);

            //Sleep to make sure the message is sent
            System.Threading.Thread.Sleep(500);

            UICore.CloseAllRtcForms();
        }
Ejemplo n.º 16
0
        private void RTC_Intro_Form_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason != CloseReason.UserClosing)
            {
                return;
            }

            if (selection == IntroAction.EXIT)
            {
                if (UI_VanguardImplementation.connector.netConn.status == NetworkStatus.CONNECTED)
                {
                    LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_EVENT_CLOSEEMULATOR);
                }

                Environment.Exit(0);
            }
        }
Ejemplo n.º 17
0
		public static void CPU_STEP(bool isRewinding, bool isFastForwarding, bool isBeforeStep = false)
		{
			try
			{
				if (disableRTC || Global.Emulator is NullEmulator)
					return;

				bool runBefore = (bool)(AllSpec.CorruptCoreSpec?[RTCSPEC.STEP_RUNBEFORE.ToString()] ?? false);

				//Return out if it's being called from before the step and we're not on frame 0. If we're on frame 0, then we go as normal
				//If we can't get runbefore, just assume we don't want to run before
				if (isBeforeStep && runBefore == false)
					return;
				if (runBefore)
				{
					AllSpec.CorruptCoreSpec.Update(RTCSPEC.STEP_RUNBEFORE.ToString(), false);
				}

				isNormalAdvance = !(isRewinding || isFastForwarding);

				bool isForward = (!isRewinding && !isFastForwarding);

				// Unique step hooks
				if (isForward)
					STEP_FORWARD();
				else if (isRewinding)
					STEP_REWIND();
				else if (isFastForwarding)
					STEP_FASTFORWARD();

				//Any step hook for corruption
				STEP_CORRUPT(isRewinding, isFastForwarding);
				VanguardCore.RTE_API.ON_STEP(isForward, isRewinding, isFastForwarding);
			}
			catch (Exception ex)
			{
				if (VanguardCore.ShowErrorDialog(ex, true) == DialogResult.Abort)
					throw new AbortEverythingException();
				MessageBox.Show("Clearing all step blastunits due to an exception within Core_Step().");
				LocalNetCoreRouter.Route(Endpoints.UI, Basic.ErrorDisableAutoCorrupt, false);
				StepActions.ClearStepBlastUnits();
			}
		}
Ejemplo n.º 18
0
        public static bool LoadRom_NET(StashKey sk)
        {
            if (sk == null)
            {
                return(false);
            }

            StashKey.SetCore(sk);
            LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_LOADROM, sk.RomFilename, true);

            string ss = (string)RTCV.NetCore.AllSpec.VanguardSpec[VSPEC.SYNCSETTINGS];

            //If the syncsettings are different, update them and load it again. Otheriwse, leave as is
            if (sk.SyncSettings != ss && sk.SyncSettings != null)
            {
                LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_KEY_SETSYNCSETTINGS, sk.SyncSettings, true);
                LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_LOADROM, sk.RomFilename, true);
            }
            return(true);
        }
Ejemplo n.º 19
0
 public bool Start(RTCSide side)
 {
     Logging.GlobalLogger.Info($"{Name} v{Version} initializing.");
     if (side == RTCSide.Client)
     {
         connectorEMU = new PluginConnectorEMU();
         S.SET <PluginForm>(new PluginForm());
     }
     else if (side == RTCSide.Server)
     {
         //Uncomment if needed
         //connectorRTC = new PluginConnectorRTC();
         S.GET <RTC_OpenTools_Form>().RegisterTool("Plugin Template", "Open Plugin Template", () => {
             //This is the method you use to route commands between the RTC side and the Emulator side
             LocalNetCoreRouter.Route(Endpoint.EMU_SIDE, Commands.SHOW_WINDOW, true);
         });
     }
     Logging.GlobalLogger.Info($"{Name} v{Version} initialized.");
     CurrentSide = side;
     return(true);
 }
Ejemplo n.º 20
0
        public static bool ApplyStashkey(StashKey sk, bool _loadBeforeOperation = true)
        {
            PreApplyStashkey();

            bool isCorruptionApplied = sk?.BlastLayer?.Layer?.Count > 0;

            if (_loadBeforeOperation)
            {
                if (!LoadState(sk))
                {
                    return(isCorruptionApplied);
                }
            }
            else
            {
                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.APPLYBLASTLAYER, new object[] { sk?.BlastLayer, true }, true);
            }

            PostApplyStashkey();
            return(isCorruptionApplied);
        }
        public void btnBlastToggle_Click(object sender, EventArgs e)
        {
            if (StockpileManager_UISide.CurrentStashkey?.BlastLayer?.Layer == null || StockpileManager_UISide.CurrentStashkey?.BlastLayer?.Layer.Count == 0)
            {
                IsCorruptionApplied = false;
                return;
            }

            if (!IsCorruptionApplied)
            {
                IsCorruptionApplied = true;

                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_SET_APPLYCORRUPTBL, true);
            }
            else
            {
                IsCorruptionApplied = false;

                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_SET_APPLYUNCORRUPTBL, true);
                LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_CLEARSTEPBLASTUNITS, null, true);
            }
        }
Ejemplo n.º 22
0
        private void btnActiveTableAddDump_Click(object sender, EventArgs e)
        {
            if (cbSelectedMemoryDomain == null || MemoryDomains.GetInterface(cbSelectedMemoryDomain.SelectedItem.ToString()).Size.ToString() == null)
            {
                MessageBox.Show("Select a valid domain before continuing!");
                return;
            }
            if (ActiveTableDumps == null)
            {
                return;
            }

            string key = CorruptCore.RtcCore.GetRandomKey();



            LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_DOMAIN_ACTIVETABLE_MAKEDUMP, new object[] { cbSelectedMemoryDomain.SelectedItem.ToString(), key }, true);


            ActiveTableDumps.Add(key);
            lbFreezeEngineNbDumps.Text = "Memory dumps collected: " + ActiveTableDumps.Count.ToString();
        }
Ejemplo n.º 23
0
		public static bool RefreshDomains(bool updateSpecs = true)
		{
			try
			{
				//Compare the old to the new. If the name and sizes are all the same, don't push that there were changes.
				//We need to compare like this because the domains can change from syncsettings.
				//We only check name and size as those are the only things that can change on the fly
				var oldInterfaces = VanguardCore.MemoryInterfacees;
				var newInterfaces = GetInterfaces();
				bool domainsChanged = oldInterfaces.Length != newInterfaces.Length;

				//Bruteforce it since domains can change inconsistently
				for (int i = 0; i < oldInterfaces.Length; i++)
				{
					if (domainsChanged)
						break;
					if (oldInterfaces[i].Name != newInterfaces[i].Name)
						domainsChanged = true;
					if (oldInterfaces[i].Size != newInterfaces[i].Size)
						domainsChanged = true;
				}

				//We gotta push this no matter what since it's new underlying objects
				if (updateSpecs)
				{
					AllSpec.VanguardSpec.Update(VSPEC.MEMORYDOMAINS_INTERFACES, newInterfaces);
					LocalNetCoreRouter.Route(Endpoints.CorruptCore, Remote.EventDomainsUpdated, domainsChanged, true);
				}
				return domainsChanged;
			}
			catch (Exception ex)
			{
				if (VanguardCore.ShowErrorDialog(ex) == DialogResult.Abort)
					throw new AbortEverythingException();

				return false;
			}
		}
Ejemplo n.º 24
0
        private void btnUnloadVMD_Click(object sender, EventArgs e)
        {
            if (lbLoadedVmdList.SelectedIndex == -1)
            {
                return;
            }

            //Clear any active units to prevent bad things due to soon unloaded vmds
            LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_CLEARSTEPBLASTUNITS, null, true);
            foreach (var item in lbLoadedVmdList.SelectedItems)
            {
                string VmdName = item.ToString();
                //Go through the stash history and rasterize
                foreach (StashKey sk in S.GET <RTC_StashHistory_Form>().lbStashHistory.Items)
                {
                    sk.BlastLayer?.RasterizeVMDs(VmdName);
                }
                //CurrentStashKey can be separate
                StockpileManager_UISide.CurrentStashkey?.BlastLayer?.RasterizeVMDs(VmdName);

                MemoryDomains.RemoveVMD(VmdName);
            }
            RefreshVMDs();
        }
 private void BlastRawStash()
 {
     LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.MANUALBLAST, true);
     btnSendRaw_Click(null, null);
 }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
0
 private void btnClearInfiniteUnits_Click(object sender, EventArgs e)
 {
     LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_CLEARSTEPBLASTUNITS, null, true);
 }
Ejemplo n.º 28
0
 private static void Tick(object sender, EventArgs e)
 {
     LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_BACKUPKEY_REQUEST);
 }
 public bool Start(RTCSide side)
 {
     Logging.GlobalLogger.Info(string.Format("{0} v{1} initializing.", (object)this.Name, (object)this.Version));
     if (side == RTCSide.Client)
     {
         connectorEMU = new MemVisConnectorEMU();
         //S.SET<PluginForm>(new PluginForm());
     }
     else if (side == RTCSide.Server)
     {
         if (S.ISNULL <OpenToolsForm>())
         {
             ((Logger)Logging.GlobalLogger).Error(string.Format("{0} v{1} failed to start: Singleton RTC_OpenTools_Form was null.", (object)this.Name, (object)this.Version));
             return(false);
         }
         if (S.ISNULL <CoreForm>())
         {
             ((Logger)Logging.GlobalLogger).Error(string.Format("{0} v{1} failed to start: Singleton UI_CoreForm was null.", (object)this.Name, (object)this.Version));
             return(false);
         }
         S.GET <OpenToolsForm>().RegisterTool("Memory Visualizer", "Open Memory Visualizer", () => { LocalNetCoreRouter.Route(Ep.EMU_SIDE, Commands.SHOW_WINDOW, true); });
     }
     Logging.GlobalLogger.Info(string.Format("{0} v{1} initialized.", (object)this.Name, (object)this.Version));
     CurrentSide = side;
     return(true);
 }
Ejemplo n.º 30
0
 private static void NetCoreSpec_ClientConnected(object sender, EventArgs e)
 {
     LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_PUSHVANGUARDSPEC, RTCV.NetCore.AllSpec.VanguardSpec.GetPartialSpec(), true);
     LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_ALLSPECSSENT, true);
 }