Ejemplo n.º 1
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));
            }
        }
Ejemplo n.º 2
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);
        }
        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);
            }
        }
Ejemplo n.º 4
0
        public static StashKey SaveState_NET(StashKey _sk = null, bool threadSave = false)
        {
            string Key;
            string statePath;

            StashKey sk;

            if (_sk == null)
            {
                Key       = RtcCore.GetRandomKey();
                statePath = LocalNetCoreRouter.QueryRoute <string>(NetcoreCommands.VANGUARD, NetcoreCommands.SAVESAVESTATE, Key, true);

                if (statePath == null)
                {
                    return(null);
                }

                sk = new StashKey(Key, Key, null);
            }
            else
            {
                Key       = _sk.Key;
                statePath = _sk.StateFilename;
                sk        = _sk;
            }

            if (string.IsNullOrEmpty(statePath))
            {
                return(null);
            }

            //sk.StateShortFilename = statePath.Substring(statePath.LastIndexOf(Path.DirectorySeparatorChar) + 1, statePath.Length - (statePath.LastIndexOf(Path.DirectorySeparatorChar) + 1));
            sk.StateShortFilename = Path.GetFileName(statePath);
            sk.StateFilename      = statePath;

            return(sk);
        }
Ejemplo n.º 5
0
        private bool GenerateVMD()
        {
            if (string.IsNullOrWhiteSpace(cbSelectedMemoryDomain.SelectedItem?.ToString()) || !MemoryDomains.MemoryInterfaces.ContainsKey(cbSelectedMemoryDomain.SelectedItem.ToString()))
            {
                cbSelectedMemoryDomain.Items.Clear();
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(tbVmdName.Text) && MemoryDomains.VmdPool.ContainsKey($"[V]{tbVmdName.Text}"))
            {
                MessageBox.Show("There is already a VMD with this name in the VMD Pool");
                return(false);
            }

            MemoryInterface     mi    = MemoryDomains.MemoryInterfaces[cbSelectedMemoryDomain.SelectedItem.ToString()];
            VirtualMemoryDomain VMD   = new VirtualMemoryDomain();
            VmdPrototype        proto = new VmdPrototype
            {
                GenDomain = cbSelectedMemoryDomain.SelectedItem.ToString()
            };

            if (string.IsNullOrWhiteSpace(tbVmdName.Text))
            {
                proto.VmdName = CorruptCore.RtcCore.GetRandomKey();
            }
            else
            {
                proto.VmdName = tbVmdName.Text;
            }

            proto.BigEndian = mi.BigEndian;
            proto.WordSize  = mi.WordSize;
            proto.Padding   = 0;

            var sk = S.GET <RTC_SavestateManager_Form>().CurrentSaveStateStashKey;

            if (sk == null && cbLoadBeforeGenerate.Checked && (AllSpec.VanguardSpec[VSPEC.SUPPORTS_SAVESTATES] as bool? ?? false))
            {
                MessageBox.Show("Load before generate is checked but no Savestate is selected in the Glitch Harvester!");
                return(false);
            }
            var legalAdresses = LocalNetCoreRouter.QueryRoute <long[]>(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_LONGARRAY_FILTERDOMAIN, new object[] { mi.Name, LimiterListHash, cbLoadBeforeGenerate.Checked ? sk : null });

            if (legalAdresses == null)
            {
                return(false);
            }

            proto.AddSingles.AddRange(legalAdresses);

            if (proto.AddRanges.Count == 0 && proto.AddSingles.Count == 0)
            {
                //No add range was specified, use entire domain
                proto.AddRanges.Add(new long[] { 0, (currentDomainSize > long.MaxValue ? long.MaxValue : Convert.ToInt64(currentDomainSize)) });
            }

            //Precalc the size of the vmd
            //Ignore the fact that addranges and subtractranges can overlap. Only account for add
            long size = 0;

            foreach (var v in proto.AddSingles)
            {
                size++;
            }

            foreach (var v in proto.AddRanges)
            {
                long x = v[1] - v[0];
                size += x;
            }
            //If the size is still 0 and we have removals, we're gonna use the entire range then sub from it so size is now the size of the domain
            if (size == 0 &&
                (proto.RemoveSingles.Count > 0 || proto.RemoveRanges.Count > 0) ||
                (proto.RemoveSingles.Count == 0 && proto.RemoveRanges.Count == 0 && size == 0))
            {
                size = currentDomainSize;
            }

            foreach (var v in proto.RemoveSingles)
            {
                size--;
            }

            foreach (var v in proto.RemoveRanges)
            {
                long x = v[1] - v[0];
                size -= x;
            }

            //Verify they want to continue if the domain is larger than 32MB and they didn't manually set ranges
            if (size > 0x2000000)
            {
                DialogResult result = MessageBox.Show("The VMD you're trying to generate is larger than 32MB\n The VMD size is " + ((size / 1024 / 1024) + 1) + " MB (" + size / 1024f / 1024f / 1024f + " GB).\n Are you sure you want to continue?", "VMD Detected", MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return(false);
                }
            }

            VMD = proto.Generate();

            if (VMD.Size == 0)
            {
                MessageBox.Show("The resulting VMD had no pointers so the operation got cancelled.");
                return(false);
            }

            MemoryDomains.AddVMD(VMD);

            tbVmdName.Text = "";
            cbSelectedMemoryDomain.SelectedIndex = -1;
            cbSelectedMemoryDomain.Items.Clear();

            currentDomainSize = 0;

            lbDomainSizeValue.Text = "######";
            lbEndianTypeValue.Text = "######";
            lbWordSizeValue.Text   = "######";

            //send to vmd pool menu
            S.GET <RTC_VmdPool_Form>().RefreshVMDs();

            //Selects back the VMD Pool menu
            foreach (var item in UICore.mtForm.cbSelectBox.Items)
            {
                if (((dynamic)item).value is RTC_VmdPool_Form)
                {
                    UICore.mtForm.cbSelectBox.SelectedItem = item;
                    break;
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        public static bool Corrupt(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;

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

            if (!UseSavestates)
            {
                psk = SaveState();
            }

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

            string currentGame = (string)RTCV.NetCore.AllSpec.VanguardSpec[VSPEC.GAMENAME];
            string currentCore = (string)RTCV.NetCore.AllSpec.VanguardSpec[VSPEC.SYSTEMCORE];

            if (UseSavestates && (currentGame == null || psk.GameName != currentGame || psk.SystemCore != currentCore))
            {
                LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_LOADROM, psk.RomFilename, true);
            }

            //We make it without the blastlayer so we can send it across and use the cached version without needing a prototype
            CurrentStashkey = new StashKey(RtcCore.GetRandomKey(), psk.ParentKey, null)
            {
                RomFilename   = psk.RomFilename,
                SystemName    = psk.SystemName,
                SystemCore    = psk.SystemCore,
                GameName      = psk.GameName,
                SyncSettings  = psk.SyncSettings,
                StateLocation = psk.StateLocation
            };


            BlastLayer bl = LocalNetCoreRouter.QueryRoute <BlastLayer>(NetcoreCommands.CORRUPTCORE, NetcoreCommands.GENERATEBLASTLAYER,
                                                                       new object[]
            {
                CurrentStashkey,
                _loadBeforeOperation,
                true,
                true
            }, true);
            bool isCorruptionApplied = bl?.Layer?.Count > 0;

            CurrentStashkey.BlastLayer = bl;

            if (StashAfterOperation && bl != null)
            {
                StashHistory.Add(CurrentStashkey);
            }

            PostApplyStashkey();
            return(isCorruptionApplied);
        }
Ejemplo n.º 7
0
        public static bool LoadState(StashKey sk, bool reloadRom = true, bool applyBlastLayer = true)
        {
            bool success = LocalNetCoreRouter.QueryRoute <bool>(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_LOADSTATE, new object[] { sk, true, applyBlastLayer }, true);

            return(success);
        }