Beispiel #1
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();
                }
            }
        }
        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;
            }
        }
Beispiel #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);
        }
Beispiel #4
0
        public VanguardConnector(NetCoreReceiver _receiver)
        {
            receiver = _receiver;

            LocalNetCoreRouter.registerEndpoint(this, NetcoreCommands.VANGUARD);
            corruptConn = new CorruptCoreConnector();
            LocalNetCoreRouter.registerEndpoint(corruptConn, NetcoreCommands.CORRUPTCORE);

            if (receiver.Attached)//attached mode
            {
                CorruptCore.RtcCore.Attached = true;
                RTCV.UI.UICore.Start(null);
                return;
            }

            var netCoreSpec = new NetCoreSpec
            {
                Side = NetworkSide.CLIENT
            };

            netCoreSpec.MessageReceived += OnMessageReceivedProxy;
            netCoreSpec.ClientConnected += NetCoreSpec_ClientConnected;
            netConn = new NetCoreConnector(netCoreSpec);

            //netConn = LocalNetCoreRouter.registerEndpoint(new NetCoreConnector(netCoreSpec), "WGH");
            LocalNetCoreRouter.registerEndpoint(netConn, NetcoreCommands.DEFAULT); //Will send mesages to netcore if can't find the destination
        }
        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);
        }
Beispiel #6
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();
                }
            }
        }
        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();
                }
            }
        }
Beispiel #8
0
        public UIConnector(NetCoreReceiver _receiver)
        {
            receiver = _receiver;

            LocalNetCoreRouter.registerEndpoint(this, NetcoreCommands.UI);

            if (receiver.Attached)
            {
                return;
            }

            var netCoreSpec = new NetCore.NetCoreSpec();

            netCoreSpec.Side                  = NetCore.NetworkSide.SERVER;
            netCoreSpec.Attached              = receiver.Attached;
            netCoreSpec.Loopback              = true;
            netCoreSpec.MessageReceived      += OnMessageReceivedProxy;
            netCoreSpec.ServerConnected      += Spec_ServerConnected;
            netCoreSpec.ServerConnectionLost += NetCoreSpec_ServerConnectionLost;
            netCoreSpec.ServerDisconnected   += NetCoreSpec_ServerConnectionLost;

            netConn = new NetCoreConnector(netCoreSpec);
            LocalNetCoreRouter.registerEndpoint(netConn, NetcoreCommands.VANGUARD);
            LocalNetCoreRouter.registerEndpoint(netConn, NetcoreCommands.DEFAULT);             //Will send mesages to netcore if can't find the destination
        }
        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);
        }
Beispiel #10
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();
        }
Beispiel #11
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);
     }
 }
Beispiel #12
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);
        }
Beispiel #13
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);
            }
        }
Beispiel #15
0
        public static StashKey SaveState(StashKey sk = null, bool threadSave = false)
        {
            bool UseSavestates = (bool)AllSpec.VanguardSpec[VSPEC.SUPPORTS_SAVESTATES];

            if (UseSavestates)
            {
                return(LocalNetCoreRouter.QueryRoute <StashKey>(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_SAVESTATE, sk, true));
            }
            else
            {
                return(LocalNetCoreRouter.QueryRoute <StashKey>(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_SAVESTATELESS, sk, true));
            }
        }
Beispiel #16
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();
                }
            }
        }
Beispiel #18
0
        public VanguardConnector(TargetSpec _spec)
        {
            spec = _spec;

            LocalNetCoreRouter.registerEndpoint(this, "VANGUARD");
            corruptConn = LocalNetCoreRouter.registerEndpoint(new CorruptCoreConnector(), "CORRUPTCORE");

            var netCoreSpec = new NetCoreSpec();

            netCoreSpec.Side             = NetworkSide.CLIENT;
            netCoreSpec.MessageReceived += OnMessageReceivedProxy;

            netConn = LocalNetCoreRouter.registerEndpoint(new NetCoreConnector(netCoreSpec), "RTCV");
            //LocalNetCoreRouter.registerEndpoint(netConn, "WGH"); //We can make an alias for WGH
        }
Beispiel #19
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();
        }
Beispiel #20
0
        public bool Start(RTCSide side)
        {
            RTCV.Common.Logging.GlobalLogger.Info($"{Name} v{Version} initializing.");


            if (side == RTCSide.Client)
            {
                var conn = new HexEditorConnector();
                LocalNetCoreRouter.registerEndpoint(conn, "HEXEDITOR");
            }

            RTCV.Common.Logging.GlobalLogger.Info($"{Name} v{Version} initialized.");

            return(true);
        }
Beispiel #21
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);
            }
        }
Beispiel #22
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();
			}
		}
Beispiel #23
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);
        }
Beispiel #24
0
        public static bool LoadState_NET(StashKey sk, bool applyBlastLayer = true)
        {
            if (sk == null)
            {
                return(false);
            }

            bool useStates = (AllSpec.VanguardSpec[VSPEC.SUPPORTS_SAVESTATES] as bool? ?? false);

            if (useStates)
            {
                StashKey.SetCore(sk);
                string gameSystem = sk.SystemName;
                string gameName   = CorruptCore_Extensions.MakeSafeFilename(sk.GameName, '-');
                string key        = sk.ParentKey;
                StashKeySavestateLocation stateLocation = sk.StateLocation;

                string theoreticalSaveStateFilename = Path.Combine(RtcCore.workingDir, stateLocation.ToString(), gameName + "." + key + ".timejump.State");

                if (File.Exists(theoreticalSaveStateFilename))
                {
                    if (!LocalNetCoreRouter.QueryRoute <bool>(NetcoreCommands.VANGUARD, NetcoreCommands.LOADSAVESTATE, new object[] { theoreticalSaveStateFilename, stateLocation }, true))
                    {
                        MessageBox.Show($"Error loading savestate : An internal error has occurred.\n Are you sure your savestate matches the game, your syncsettings match, and the savestate is supported by this version of {RtcCore.VanguardImplementationName}?");
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show($"Error loading savestate : (File {theoreticalSaveStateFilename} not found)");
                    return(false);
                }
            }

            if (applyBlastLayer && sk?.BlastLayer?.Layer?.Count > 0)
            {
                CorruptBL = sk.BlastLayer;
                sk.BlastLayer.Apply(true);
            }
            return(true);
        }
Beispiel #25
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);
 }
        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);
            }
        }
Beispiel #28
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();
        }
        public void btnSendRaw_Click(object sender, EventArgs e)
        {
            if (!btnSendRaw.Visible)
            {
                return;
            }
            try
            {
                SetBlastButtonVisibility(false);

                string romFilename = (string)RTCV.NetCore.AllSpec.VanguardSpec[VSPEC.OPENROMFILENAME];
                if (romFilename == null)
                {
                    return;
                }
                if (romFilename.Contains("|"))
                {
                    MessageBox.Show($"The Glitch Harvester attempted to corrupt a game bound to the following file:\n{romFilename}\n\nIt cannot be processed because the rom seems to be inside a Zip Archive\n(Bizhawk returned a filename with the chracter | in it)");
                    return;
                }

                StashKey sk = LocalNetCoreRouter.QueryRoute <StashKey>(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_KEY_GETRAWBLASTLAYER, true);

                StockpileManager_UISide.CurrentStashkey = sk;
                StockpileManager_UISide.StashHistory.Add(StockpileManager_UISide.CurrentStashkey);


                S.GET <RTC_StashHistory_Form>().DontLoadSelectedStash = true;
                S.GET <RTC_StashHistory_Form>().RefreshStashHistorySelectLast();
                S.GET <RTC_StashHistory_Form>().DontLoadSelectedStash = true;
                S.GET <RTC_StockpileManager_Form>().dgvStockpile.ClearSelection();
                S.GET <RTC_StashHistory_Form>().DontLoadSelectedStash = false;
            }
            finally
            {
                SetBlastButtonVisibility(true);
            }
        }
Beispiel #30
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;
			}
		}