Ejemplo n.º 1
0
        static void STEP_CORRUPT(bool _isRewinding, bool _isFastForwarding, bool _isPaused)
        {
            if (DisableRTC)
            {
                return;
            }

            if (!_isRewinding && !_isPaused)
            {
                if (RTC_PipeEngine.ProcessOnStep)
                {
                    RTC_PipeEngine.ExecutePipes();
                }
            }

            if (_isRewinding || _isFastForwarding || _isPaused)
            {
                return;
            }


            CPU_STEP_Count++;

            if (RTC_Core.AutoCorrupt && CPU_STEP_Count >= RTC_Core.ErrorDelay)
            {
                CPU_STEP_Count = 0;
                BlastLayer bl = RTC_Core.Blast(null, RTC_MemoryDomains.SelectedDomains);
                if (bl != null)
                {
                    bl.Apply();
                }
            }
        }
Ejemplo n.º 2
0
        public VmdPrototype(BlastLayer bl)
        {
            VmdName   = RTC_Core.GetRandomKey();
            GenDomain = "Hybrid";

            BlastUnit bu = bl.Layer[0];
            var       mi = RTC_MemoryDomains.getInterface(bu.Domain);

            BigEndian          = mi.BigEndian;
            WordSize           = mi.WordSize;
            SuppliedBlastLayer = bl;
        }
Ejemplo n.º 3
0
        public BlastLayer GetBackup()
        {
            List <BlastUnit> BackupLayer = new List <BlastUnit>();;

            foreach (BlastUnit bb in Layer)
            {
                BackupLayer.Add(bb.GetBackup());
            }

            BlastLayer Recovery = new BlastLayer(BackupLayer);

            return(Recovery);
        }
Ejemplo n.º 4
0
        public StashKey(String _key, String _parentkey, BlastLayer _blastlayer)
        {
            PathEntry pathEntry = Global.Config.PathEntries[Global.Game.System, "Savestates"] ??
                                  Global.Config.PathEntries[Global.Game.System, "Base"];

            Key        = _key;
            ParentKey  = _parentkey;
            blastlayer = _blastlayer;
            RomFile    = GlobalWin.MainForm.CurrentlyOpenRom;
            GameSystem = RTC_Core.EmuFolderCheck(pathEntry.SystemDisplayName);
            GameName   = PathManager.FilesystemSafeName(Global.Game);

            MemoryZones.AddRange(RTC_MemoryZones.SelectedDomains);
        }
Ejemplo n.º 5
0
        public void AddFromBlastLayer(BlastLayer bl)
        {
            if (bl == null)
            {
                return;
            }

            foreach (BlastUnit bu in bl.Layer)
            {
                //MemoryPointers.Add(new MemoryPointer(bu.Domain, bu.Address));
                //MemoryPointers.Add(new Tuple<string, long>(bu.Domain, bu.Address));
                PointerDomains.Add(bu.Domain);
                PointerAddresses.Add(bu.Address);
            }
        }
Ejemplo n.º 6
0
        public static BlastLayer GetBlastLayer(byte[] Original, byte[] Corrupt)
        {
            BlastLayer bl = new BlastLayer();

            string thisSystem  = Global.Game.System;
            string romFilename = GlobalWin.MainForm.CurrentlyOpenRom;

            var rp = RTC_MemoryDomains.GetRomParts(thisSystem, romFilename);

            if (rp.error != null)
            {
                MessageBox.Show(rp.error);
                return(null);
            }

            if (Original.Length != Corrupt.Length)
            {
                MessageBox.Show("ERROR, ROM SIZE MISMATCH");
                return(null);
            }

            long maxaddress = RTC_MemoryDomains.getInterface(rp.primarydomain).Size;

            for (int i = 0; i < Original.Length; i++)
            {
                if (Original[i] != Corrupt[i] && i >= rp.skipbytes)
                {
                    if (i - rp.skipbytes >= maxaddress)
                    {
                        bl.Layer.Add(new BlastByte(rp.seconddomain, (i - rp.skipbytes) - maxaddress, BlastByteType.SET, new byte[] { Corrupt[i] }, true));
                    }
                    else
                    {
                        bl.Layer.Add(new BlastByte(rp.primarydomain, i - rp.skipbytes, BlastByteType.SET, new byte[] { Corrupt[i] }, true));
                    }
                }
            }


            if (bl.Layer.Count == 0)
            {
                return(null);
            }
            else
            {
                return(bl);
            }
        }
Ejemplo n.º 7
0
        public static string CloudSave(BlastLayer bl)
        {
            FileStream      FS;
            BinaryFormatter bformatter = new BinaryFormatter();

            string tempfile = RTC_Core.rtcDir + "\\CORRUPTCLOUD\\temp.bl";

            GlobalWin.Sound.StopSound();

            if (File.Exists(tempfile))
            {
                File.Delete(tempfile);
            }

            FS = File.Open(tempfile, FileMode.OpenOrCreate);
            bformatter.Serialize(FS, bl);
            FS.Close();


            string remoteUri = CorruptCloudServer + "/post.php?submit=true&action=upload";

            byte[] responseBinary;
            try{
                WebClient client = new WebClient();
                responseBinary = client.UploadFile(remoteUri, "POST", tempfile);
            }
            catch (Exception ex)
            {
                GlobalWin.Sound.StopSound();
                MessageBox.Show("Something went wrong with the upload. Try again. \n\n\n" + ex.ToString());
                GlobalWin.Sound.StartSound();
                return("");
            }

            string response = Encoding.UTF8.GetString(responseBinary);

            GlobalWin.Sound.StartSound();

            if (response == "ERROR")
            {
                return("");
            }
            else
            {
                return(response);
            }
        }
Ejemplo n.º 8
0
        private void btnCorrupt_Click(object sender, EventArgs e)
        {
            BlastLayer bl = new BlastLayer();

            foreach (var item in lbBlastLayer.Items)
            {
                BlastUnit bu = (item as BlastUnit);
                if (bu.IsEnabled)
                {
                    bl.Layer.Add(bu);
                }
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();

            (bl.Clone() as BlastLayer).Apply();
        }
Ejemplo n.º 9
0
        private void btnLoadCorrupt_Click(object sender, EventArgs e)
        {
            BlastLayer bl = new BlastLayer();

            foreach (var item in lbBlastLayer.Items)
            {
                BlastUnit bu = (item as BlastUnit);
                if (bu.IsEnabled)
                {
                    bl.Layer.Add(bu);
                }
            }

            StashKey newSk = (StashKey)sk.Clone();

            newSk.BlastLayer = (BlastLayer)bl.Clone();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            newSk.Run();
        }
Ejemplo n.º 10
0
        public RTC_Command Process_RTCExtensions(RTC_Command cmd)
        {
            RTC_Command cmdBack = null;

            switch (cmd.Type)
            {
            case CommandType.ASYNCBLAST:
            {
                BlastLayer bl = RTC_Core.Blast(null, RTC_MemoryDomains.SelectedDomains);
                if (bl != null)
                {
                    bl.Apply();
                }
            }
            break;

            case CommandType.BLAST:
            {
                BlastLayer bl       = null;
                string[]   _domains = (string[])cmd.objectValue;

                if (_domains == null)
                {
                    _domains = RTC_MemoryDomains.SelectedDomains;
                }

                if (cmd.blastlayer != null)
                {
                    cmd.blastlayer.Apply(cmd.isReplay);
                }
                else
                {
                    bl = RTC_Core.Blast(null, _domains);
                }

                if (cmd.requestGuid != null)
                {
                    cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                    cmdBack.objectValue = bl;
                }
            }

            break;

            case CommandType.STASHKEY:

                if (!File.Exists(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename))
                {
                    File.WriteAllBytes(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename, cmd.romData);
                }

                cmd.stashkey.RomFilename = RTC_Core.rtcDir + "\\TEMP\\" + RTC_Extensions.getShortFilenameFromPath(cmd.romFilename);

                cmd.stashkey.DeployState();

                cmd.stashkey.Run();

                break;

            case CommandType.PULLROM:
                cmdBack             = new RTC_Command(CommandType.PUSHROM);
                cmdBack.romFilename = RTC_Extensions.getShortFilenameFromPath(GlobalWin.MainForm.CurrentlyOpenRom);

                if (!PeerHasRom(cmdBack.romFilename))
                {
                    cmdBack.romData = File.ReadAllBytes(GlobalWin.MainForm.CurrentlyOpenRom);
                }

                break;

            case CommandType.PUSHROM:
                if (cmd.romData != null)
                {
                    cmd.romFilename = RTC_Extensions.getShortFilenameFromPath(cmd.romFilename);
                    if (!File.Exists(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename))
                    {
                        File.WriteAllBytes(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename, cmd.romData);
                    }
                }

                RTC_Core.LoadRom(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename);
                break;

            case CommandType.PULLSTATE:
                cmdBack = new RTC_Command(CommandType.PUSHSTATE);
                StashKey sk_PULLSTATE = RTC_StockpileManager.SaveState(false);
                cmdBack.stashkey = sk_PULLSTATE;
                sk_PULLSTATE.EmbedState();

                break;

            case CommandType.PUSHSTATE:
                cmd.stashkey.DeployState();
                RTC_StockpileManager.LoadState(cmd.stashkey, false);

                if (RTC_Core.multiForm.cbPullStateToGlitchHarvester.Checked)
                {
                    StashKey sk_PUSHSTATE = RTC_StockpileManager.SaveState(true, cmd.stashkey);
                    sk_PUSHSTATE.RomFilename = GlobalWin.MainForm.CurrentlyOpenRom;
                }

                break;

            case CommandType.PULLSWAPSTATE:

                cmdBack             = new RTC_Command(CommandType.PUSHSWAPSTATE);
                cmdBack.romFilename = RTC_Extensions.getShortFilenameFromPath(GlobalWin.MainForm.CurrentlyOpenRom);

                if (!PeerHasRom(cmdBack.romFilename))
                {
                    cmdBack.romData = File.ReadAllBytes(GlobalWin.MainForm.CurrentlyOpenRom);
                }

                StashKey sk_PULLSWAPSTATE = RTC_StockpileManager.SaveState(false);
                cmdBack.stashkey = sk_PULLSWAPSTATE;
                sk_PULLSWAPSTATE.EmbedState();

                cmd.romFilename = RTC_Extensions.getShortFilenameFromPath(cmd.romFilename);

                if (!File.Exists(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename))
                {
                    File.WriteAllBytes(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename, cmd.romData);
                }
                RTC_Core.LoadRom(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename);

                cmd.stashkey.DeployState();
                RTC_StockpileManager.LoadState(cmd.stashkey, false);

                if (RTC_Core.multiForm.GameOfSwapTimer != null)
                {
                    RTC_Core.multiForm.GameOfSwapCounter = 64;
                }

                break;

            case CommandType.PUSHSWAPSTATE:

                cmd.romFilename = RTC_Extensions.getShortFilenameFromPath(cmd.romFilename);

                if (cmd.romData != null)
                {
                    if (!File.Exists(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename))
                    {
                        File.WriteAllBytes(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename, cmd.romData);
                    }
                }

                RTC_Core.LoadRom(RTC_Core.rtcDir + "\\TEMP\\" + cmd.romFilename);

                cmd.stashkey.DeployState();
                RTC_StockpileManager.LoadState(cmd.stashkey, false);

                if (RTC_Core.multiForm.GameOfSwapTimer != null)
                {
                    RTC_Core.multiForm.GameOfSwapCounter = 64;
                }

                break;

            case CommandType.PULLSCREEN:
                cmdBack        = new RTC_Command(CommandType.PUSHSCREEN);
                cmdBack.screen = GlobalWin.MainForm.MakeScreenshotImage().ToSysdrawingBitmap();
                break;

            case CommandType.REQUESTSTREAM:
                RTC_Core.multiForm.cbStreamScreenToPeer.Checked = true;
                break;

            case CommandType.PUSHSCREEN:
                UpdatePeerScreen(cmd.screen);
                break;

            case CommandType.GAMEOFSWAPSTART:
                RTC_Core.multiForm.StartGameOfSwap(false);
                break;

            case CommandType.GAMEOFSWAPSTOP:
                RTC_Core.multiForm.StopGameOfSwap(true);
                break;

            case CommandType.REMOTE_PUSHPARAMS:
                (cmd.objectValue as RTC_Params).Deploy();
                break;

            case CommandType.REMOTE_PUSHVMDS:
                RTC_MemoryDomains.VmdPool.Clear();
                foreach (var proto in (cmd.objectValue as VmdPrototype[]))
                {
                    RTC_MemoryDomains.AddVMD(proto);
                }

                break;

            case CommandType.REMOTE_LOADROM:
                RTC_Core.LoadRom_NET(cmd.romFilename);
                break;

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

                bool returnValue = RTC_StockpileManager.LoadState_NET(sk, reloadRom);

                RTC_MemoryDomains.RefreshDomains(false);

                if (runBlastLayer)
                {
                    RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.BLAST)
                        {
                            blastlayer = sk.BlastLayer, isReplay = true
                        });
                }

                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = returnValue;
            }
            break;

            case CommandType.REMOTE_MERGECONFIG:
                Stockpile.MergeBizhawkConfig_NET();
                break;

            case CommandType.REMOTE_IMPORTKEYBINDS:
                Stockpile.ImportBizhawkKeybinds_NET();
                break;

            case CommandType.REMOTE_SAVESTATE:
            {
                StashKey sk = RTC_StockpileManager.SaveState_NET((bool)(cmd.objectValue as object[])[0], (StashKey)(cmd.objectValue as object[])[1]);
                if (cmd.requestGuid != null)
                {
                    cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                    cmdBack.objectValue = sk;
                }
            }
            break;

            case CommandType.REMOTE_BACKUPKEY_REQUEST:
            {
                if (!RTC_Hooks.isNormalAdvance)
                {
                    break;
                }

                cmdBack = new RTC_Command(CommandType.REMOTE_BACKUPKEY_STASH);

                bool multiThread = false;

                // apparently multithread savestates doesn't work well right now.
                // We can try again in a future version of bizhawk

                /*
                 * if (new string[] {
                 *   "SNES", "GB", "GBC", "GBA",
                 * }.Contains(Global.Game.System.ToString().ToUpper()))
                 *  multiThread = false;
                 */

                cmdBack.objectValue = RTC_StockpileManager.SaveState_NET(false, null, multiThread);
                break;
            }

            case CommandType.REMOTE_BACKUPKEY_STASH:
                RTC_StockpileManager.backupedState = (StashKey)cmd.objectValue;
                RTC_StockpileManager.allBackupStates.Push((StashKey)cmd.objectValue);
                RTC_Core.coreForm.btnGpJumpBack.Visible = true;
                RTC_Core.coreForm.btnGpJumpNow.Visible  = true;
                break;

            case CommandType.REMOTE_DOMAIN_PEEKBYTE:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = RTC_MemoryDomains.getInterface((string)(cmd.objectValue as object[])[0]).PeekByte((long)(cmd.objectValue as object[])[1]);
                break;

            case CommandType.REMOTE_DOMAIN_POKEBYTE:
                RTC_MemoryDomains.getInterface((string)(cmd.objectValue as object[])[0]).PokeByte((long)(cmd.objectValue as object[])[1], (byte)(cmd.objectValue as object[])[2]);
                break;

            case CommandType.REMOTE_DOMAIN_GETDOMAINS:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = RTC_MemoryDomains.getInterfaces();

                break;

            case CommandType.REMOTE_DOMAIN_VMD_ADD:
                RTC_MemoryDomains.AddVMD((cmd.objectValue as VmdPrototype));
                break;

            case CommandType.REMOTE_DOMAIN_VMD_REMOVE:
                RTC_MemoryDomains.RemoveVMD((cmd.objectValue as string));
                break;

            case CommandType.REMOTE_DOMAIN_SETSELECTEDDOMAINS:
                RTC_MemoryDomains.UpdateSelectedDomains((string[])cmd.objectValue);
                break;

            case CommandType.REMOTE_DOMAIN_SYSTEM:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = Global.Game.System.ToString().ToUpper();
                break;

            case CommandType.REMOTE_DOMAIN_SYSTEMPREFIX:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = PathManager.SaveStatePrefix(Global.Game);
                break;

            case CommandType.REMOTE_KEY_PUSHSAVESTATEDICO:
            {
                var key = (string)(cmd.objectValue as object[])[1];
                var sk  = (StashKey)((cmd.objectValue as object[])[0]);
                RTC_StockpileManager.SavestateStashkeyDico[key] = sk;
                RTC_Core.ghForm.refreshSavestateTextboxes();
            }
            break;

            case CommandType.REMOTE_KEY_GETSYSTEMNAME:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = (Global.Config.PathEntries[Global.Game.System, "Savestates"] ?? Global.Config.PathEntries[Global.Game.System, "Base"]).SystemDisplayName;
                break;

            case CommandType.REMOTE_KEY_GETSYSTEMCORE:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = StashKey.getCoreName_NET((string)cmd.objectValue);
                break;

            case CommandType.REMOTE_KEY_GETGAMENAME:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = PathManager.FilesystemSafeName(Global.Game);
                break;

            case CommandType.REMOTE_KEY_GETSYNCSETTINGS:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = StashKey.getSyncSettings_NET((string)cmd.objectValue);
                break;

            case CommandType.REMOTE_KEY_PUTSYNCSETTINGS:
                cmdBack = new RTC_Command(CommandType.RETURNVALUE);
                break;

            case CommandType.REMOTE_KEY_GETOPENROMFILENAME:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = GlobalWin.MainForm.CurrentlyOpenRom;
                break;

            case CommandType.REMOTE_KEY_GETRAWBLASTLAYER:
                cmdBack             = new RTC_Command(CommandType.RETURNVALUE);
                cmdBack.objectValue = RTC_StockpileManager.getRawBlastlayer();
                break;

            case CommandType.BIZHAWK_SET_OSDDISABLED:
                RTC_Core.BizhawkOsdDisabled = (bool)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_SAVESTATEBOX:
                RTC_StockpileManager.currentSavestateKey = (string)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_AUTOCORRUPT:
                RTC_Core.AutoCorrupt = (bool)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_CUSTOMPRECISION:
                RTC_Core.CustomPrecision = (int)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_INTENSITY:
                RTC_Core.Intensity = (int)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_ERRORDELAY:
                RTC_Core.ErrorDelay = (int)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_BLASTRADIUS:
                RTC_Core.Radius = (BlastRadius)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_RESTOREBLASTLAYERBACKUP:
                if (RTC_StockpileManager.lastBlastLayerBackup != null)
                {
                    RTC_StockpileManager.lastBlastLayerBackup.Apply(true);
                }
                break;

            case CommandType.REMOTE_SET_NIGHTMARE_TYPE:
                RTC_NightmareEngine.Algo = (BlastByteAlgo)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_HELLGENIE_MAXCHEATS:
                RTC_HellgenieEngine.MaxCheats = (int)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_HELLGENIE_CHEARCHEATSREWIND:
                RTC_Core.ClearCheatsOnRewind = (bool)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_HELLGENIE_CLEARALLCHEATS:
                if (Global.CheatList != null)
                {
                    Global.CheatList.Clear();
                }
                break;

            case CommandType.REMOTE_SET_HELLGENIE_REMOVEEXCESSCHEATS:
                while (Global.CheatList.Count > RTC_HellgenieEngine.MaxCheats)
                {
                    Global.CheatList.Remove(Global.CheatList[0]);
                }
                break;

            case CommandType.REMOTE_SET_PIPE_MAXPIPES:
                RTC_PipeEngine.MaxPipes = (int)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_PIPE_TILTVALUE:
                RTC_PipeEngine.tiltValue = (int)cmd.objectValue;
                break;


            case CommandType.REMOTE_SET_PIPE_CLEARPIPES:
                RTC_PipeEngine.AllBlastPipes.Clear();
                RTC_PipeEngine.lastDomain = null;
                break;

            case CommandType.REMOTE_SET_PIPE_LOCKPIPES:
                RTC_PipeEngine.LockPipes = (bool)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_PIPE_CHAINEDPIPES:
                RTC_PipeEngine.ChainedPipes = (bool)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_PIPE_PROCESSONSTEP:
                RTC_PipeEngine.ProcessOnStep = (bool)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_PIPE_CLEARPIPESREWIND:
                RTC_Core.ClearPipesOnRewind = (bool)cmd.objectValue;
                break;


            case CommandType.REMOTE_SET_ENGINE:
                RTC_Core.SelectedEngine = (CorruptionEngine)cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_DISTORTION_DELAY:
                RTC_DistortionEngine.MaxAge     = (int)cmd.objectValue;
                RTC_DistortionEngine.CurrentAge = 0;
                RTC_DistortionEngine.AllDistortionBytes.Clear();
                break;

            case CommandType.REMOTE_SET_DISTORTION_RESYNC:
                RTC_DistortionEngine.CurrentAge = 0;
                RTC_DistortionEngine.AllDistortionBytes.Clear();
                break;

            case CommandType.REMOTE_SET_VECTOR_LIMITER:
                RTC_VectorEngine.limiterList = (string[])cmd.objectValue;
                break;

            case CommandType.REMOTE_SET_VECTOR_VALUES:
                RTC_VectorEngine.valueList = (string[])cmd.objectValue;
                break;

            case CommandType.REMOTE_EVENT_LOADGAMEDONE_NEWGAME:

                if (RTC_Core.isStandalone && RTC_GameProtection.isRunning)
                {
                    RTC_GameProtection.Reset();
                }

                RTC_Core.AutoCorrupt = false;
                //RTC_StockpileManager.isCorruptionApplied = false;
                RTC_Core.ecForm.RefreshDomains();
                RTC_Core.ecForm.setMemoryDomainsAllButSelectedDomains(RTC_MemoryDomains.GetBlacklistedDomains());
                RTC_Core.ecForm.lbCoreDefault.Text = $"Core default: { RTC_MemoryDomains.MemoryInterfaces[RTC_MemoryDomains.MainDomain].WordSize * 8}-bit";
                break;

            case CommandType.REMOTE_EVENT_LOADGAMEDONE_SAMEGAME:
                //RTC_StockpileManager.isCorruptionApplied = false;
                RTC_Core.ecForm.RefreshDomainsAndKeepSelected();
                RTC_Core.ecForm.lbCoreDefault.Text = $"Core default: { RTC_MemoryDomains.MemoryInterfaces[RTC_MemoryDomains.MainDomain].WordSize * 8}-bit";
                break;

            case CommandType.REMOTE_EVENT_CLOSEBIZHAWK:
                GlobalWin.MainForm.Close();
                break;

            case CommandType.REMOTE_EVENT_SAVEBIZHAWKCONFIG:
                GlobalWin.MainForm.SaveConfig();
                break;

            case CommandType.REMOTE_EVENT_BIZHAWKSTARTED:

                if (RTC_StockpileManager.backupedState == null)
                {
                    RTC_Core.coreForm.AutoCorrupt = false;
                }

                RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.REMOTE_PUSHPARAMS)
                {
                    objectValue = new RTC_Params()
                }, true, true);

                RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.REMOTE_PUSHVMDS)
                {
                    objectValue = RTC_MemoryDomains.VmdPool.Values.Select(it => (it as VirtualMemoryDomain).proto).ToArray()
                }, true, true);


                Thread.Sleep(100);

                if (RTC_StockpileManager.backupedState != null)
                {
                    RTC_Core.ecForm.RefreshDomainsAndKeepSelected(RTC_StockpileManager.backupedState.SelectedDomains.ToArray());
                }

                if (RTC_Core.coreForm.cbUseGameProtection.Checked)
                {
                    RTC_GameProtection.Start();
                }

                break;


            case CommandType.REMOTE_HOTKEY_MANUALBLAST:
                RTC_Core.coreForm.btnManualBlast_Click(null, null);
                break;

            case CommandType.REMOTE_HOTKEY_AUTOCORRUPTTOGGLE:
                RTC_Core.coreForm.btnAutoCorrupt_Click(null, null);
                break;

            case CommandType.REMOTE_HOTKEY_ERRORDELAYDECREASE:
                if (RTC_Core.ecForm.nmErrorDelay.Value > 1)
                {
                    RTC_Core.ecForm.nmErrorDelay.Value--;
                }
                break;

            case CommandType.REMOTE_HOTKEY_ERRORDELAYINCREASE:
                if (RTC_Core.ecForm.nmErrorDelay.Value < RTC_Core.ecForm.track_ErrorDelay.Maximum)
                {
                    RTC_Core.ecForm.nmErrorDelay.Value++;
                }
                break;

            case CommandType.REMOTE_HOTKEY_INTENSITYDECREASE:
                if (RTC_Core.ecForm.nmIntensity.Value > 1)
                {
                    RTC_Core.ecForm.nmIntensity.Value--;
                }
                break;

            case CommandType.REMOTE_HOTKEY_INTENSITYINCREASE:
                if (RTC_Core.ecForm.nmIntensity.Value < RTC_Core.ecForm.track_Intensity.Maximum)
                {
                    RTC_Core.ecForm.nmIntensity.Value++;
                }
                break;

            case CommandType.REMOTE_HOTKEY_GHLOADCORRUPT:
                if (!RTC_NetCore.NetCoreCommandSynclock)
                {
                    RTC_NetCore.NetCoreCommandSynclock = true;

                    RTC_Core.ghForm.cbAutoLoadState.Checked = true;
                    RTC_Core.ghForm.btnCorrupt_Click(null, null);

                    RTC_NetCore.NetCoreCommandSynclock = false;
                }
                break;

            case CommandType.REMOTE_HOTKEY_GHCORRUPT:
                if (!RTC_NetCore.NetCoreCommandSynclock)
                {
                    RTC_NetCore.NetCoreCommandSynclock = true;

                    bool isload = RTC_Core.ghForm.cbAutoLoadState.Checked;
                    RTC_Core.ghForm.cbAutoLoadState.Checked = false;
                    RTC_Core.ghForm.btnCorrupt_Click(null, null);
                    RTC_Core.ghForm.cbAutoLoadState.Checked = isload;

                    RTC_NetCore.NetCoreCommandSynclock = false;
                }
                break;

            case CommandType.REMOTE_HOTKEY_GHLOAD:
                RTC_Core.ghForm.btnSaveLoad.Text = "LOAD";
                RTC_Core.ghForm.btnSaveLoad_Click(null, null);
                break;

            case CommandType.REMOTE_HOTKEY_GHSAVE:
                RTC_Core.ghForm.btnSaveLoad.Text = "SAVE";
                RTC_Core.ghForm.btnSaveLoad_Click(null, null);
                break;

            case CommandType.REMOTE_HOTKEY_GHSTASHTOSTOCKPILE:
                RTC_Core.ghForm.AddStashToStockpile(false);
                break;

            case CommandType.REMOTE_HOTKEY_SENDRAWSTASH:
                RTC_Core.ghForm.btnSendRaw_Click(null, null);
                break;

            case CommandType.REMOTE_HOTKEY_BLASTRAWSTASH:
                RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.ASYNCBLAST));
                RTC_Core.ghForm.btnSendRaw_Click(null, null);
                break;

            case CommandType.REMOTE_HOTKEY_BLASTLAYERTOGGLE:
                RTC_Core.ghForm.btnBlastToggle_Click(null, null);
                break;

            case CommandType.REMOTE_HOTKEY_BLASTLAYERREBLAST:

                if (RTC_StockpileManager.currentStashkey == null || RTC_StockpileManager.currentStashkey.BlastLayer.Layer.Count == 0)
                {
                    RTC_Core.ghForm.IsCorruptionApplied = false;
                    break;
                }

                RTC_Core.ghForm.IsCorruptionApplied = true;
                RTC_Core.SendCommandToRTC(new RTC_Command(CommandType.BLAST)
                {
                    blastlayer = RTC_StockpileManager.currentStashkey.BlastLayer
                });
                break;

            case CommandType.REMOTE_RENDER_START:
                RTC_Render.StartRender_NET();
                break;

            case CommandType.REMOTE_RENDER_STOP:
                RTC_Render.StopRender_NET();
                break;

            case CommandType.REMOTE_RENDER_SETTYPE:
                RTC_Render.lastType = (RENDERTYPE)cmd.objectValue;
                break;

            case CommandType.REMOTE_RENDER_STARTED:
                RTC_Core.ghForm.btnRender.Text      = "Stop Render";
                RTC_Core.ghForm.btnRender.ForeColor = Color.GreenYellow;
                break;

            case CommandType.REMOTE_RENDER_RENDERATLOAD:
                RTC_StockpileManager.renderAtLoad = (bool)cmd.objectValue;
                break;
            }


            return(cmdBack);
        }
Ejemplo n.º 11
0
        //Generates or applies a blast layer using one of the multiple BlastRadius algorithms
        public static BlastLayer Blast(BlastLayer _layer, string[] _selectedDomains)
        {
            string     Domain        = null;
            long       MaxAddress    = -1;
            long       RandomAddress = -1;
            BlastUnit  bu;
            BlastLayer bl;

            try
            {
                if (_layer != null)
                {
                    _layer.Apply(); //If the BlastLayer was provided, there's no need to generate a new one.

                    return(_layer);
                }
                else if (RTC_Core.SelectedEngine == CorruptionEngine.EXTERNALROM)
                {   //External ROM Plugin: Bypasses domains and uses an alternative algorithm to fetch corruption.
                    //It will query a BlastLayer generated from a differential between an original and corrupted rom.
                    bl = RTC_ExternalRomPlugin.GetBlastLayer();
                    if (bl == null)
                    {
                        return(null);
                    }
                    else
                    {
                        return(bl);
                    }
                }
                else
                {
                    bl = new BlastLayer();

                    if (_selectedDomains == null || _selectedDomains.Count() == 0)
                    {
                        return(null);
                    }

                    // Age distortion BlastBytes
                    if (RTC_Core.SelectedEngine == CorruptionEngine.DISTORTION && RTC_DistortionEngine.CurrentAge < RTC_DistortionEngine.MaxAge)
                    {
                        RTC_DistortionEngine.CurrentAge++;
                    }

                    //Run Pipes on Corrupt Step if required
                    if (RTC_Core.SelectedEngine == CorruptionEngine.PIPE && !RTC_PipeEngine.ProcessOnStep)
                    {
                        RTC_PipeEngine.ExecutePipes();
                    }


                    // Capping intensity at engine-specific maximums

                    int _Intensity = Intensity;                     //general RTC intensity

                    if ((RTC_Core.SelectedEngine == CorruptionEngine.HELLGENIE || RTC_Core.SelectedEngine == CorruptionEngine.FREEZE) && _Intensity > RTC_HellgenieEngine.MaxCheats)
                    {
                        _Intensity = RTC_HellgenieEngine.MaxCheats;                         //Capping for cheat max
                    }
                    if (RTC_Core.SelectedEngine == CorruptionEngine.PIPE && _Intensity > RTC_PipeEngine.MaxPipes)
                    {
                        _Intensity = RTC_PipeEngine.MaxPipes; //Capping for pipe max
                    }
                    switch (Radius)                           //Algorithm branching
                    {
                    case BlastRadius.SPREAD:                  //Randomly spreads all corruption bytes to all selected domains

                        for (int i = 0; i < _Intensity; i++)
                        {
                            Domain = _selectedDomains[RND.Next(_selectedDomains.Length)];

                            MaxAddress    = RTC_MemoryDomains.getInterface(Domain).Size;
                            RandomAddress = RTC_Core.RND.RandomLong(MaxAddress - 1);

                            bu = getBlastUnit(Domain, RandomAddress);
                            if (bu != null)
                            {
                                bl.Layer.Add(bu);
                            }
                        }

                        break;

                    case BlastRadius.CHUNK:     //Randomly spreads the corruption bytes in one randomly selected domain

                        Domain = _selectedDomains[RND.Next(_selectedDomains.Length)];

                        MaxAddress = RTC_MemoryDomains.getInterface(Domain).Size;

                        for (int i = 0; i < _Intensity; i++)
                        {
                            RandomAddress = RTC_Core.RND.RandomLong(MaxAddress - 1);

                            bu = getBlastUnit(Domain, RandomAddress);
                            if (bu != null)
                            {
                                bl.Layer.Add(bu);
                            }
                        }

                        break;

                    case BlastRadius.BURST:                             // 10 shots of 10% chunk

                        for (int j = 0; j < 10; j++)
                        {
                            Domain = _selectedDomains[RND.Next(_selectedDomains.Length)];

                            MaxAddress = RTC_MemoryDomains.getInterface(Domain).Size;

                            for (int i = 0; i < (int)((double)_Intensity / 10); i++)
                            {
                                RandomAddress = RTC_Core.RND.RandomLong(MaxAddress - 1);

                                bu = getBlastUnit(Domain, RandomAddress);
                                if (bu != null)
                                {
                                    bl.Layer.Add(bu);
                                }
                            }
                        }

                        break;

                    case BlastRadius.NORMALIZED:                             // Blasts based on the size of the largest selected domain. Intensity =  Intensity / (domainSize[largestdomain]/domainSize[currentdomain])


                        //Find the smallest domain and base our normalization around it
                        //Domains aren't IComparable so I used keys

                        long[] domainSize = new long [_selectedDomains.Length];
                        for (int i = 0; i < _selectedDomains.Length; i++)
                        {
                            Domain        = _selectedDomains[i];
                            domainSize[i] = RTC_MemoryDomains.getInterface(Domain).Size;
                        }
                        //Sort the arrays
                        Array.Sort(domainSize, _selectedDomains);

                        for (int i = 0; i < _selectedDomains.Length; i++)
                        {
                            Domain = _selectedDomains[i];

                            //Get the intensity divider. The size of the largest domain divided by the size of the current domain
                            long normalized = ((domainSize[_selectedDomains.Length - 1] / (domainSize[i])));

                            for (int j = 0; j < (_Intensity / normalized); j++)
                            {
                                MaxAddress    = RTC_MemoryDomains.getInterface(Domain).Size;
                                RandomAddress = RTC_Core.RND.RandomLong(MaxAddress - 1);

                                bu = getBlastUnit(Domain, RandomAddress);
                                if (bu != null)
                                {
                                    bl.Layer.Add(bu);
                                }
                            }
                        }

                        break;

                    case BlastRadius.PROPORTIONAL:                                                                     //Blasts proportionally based on the total size of all selected domains

                        long totalSize = _selectedDomains.Select(it => RTC_MemoryDomains.getInterface(it).Size).Sum(); //Gets the total size of all selected domains

                        long[] normalizedIntensity = new long[_selectedDomains.Length];                                //matches the index of selectedDomains
                        for (int i = 0; i < _selectedDomains.Length; i++)
                        {                                                                                              //calculates the proportionnal normalized Intensity based on total selected domains size
                            double proportion = (double)RTC_MemoryDomains.getInterface(_selectedDomains[i]).Size / (double)totalSize;
                            normalizedIntensity[i] = Convert.ToInt64((double)_Intensity * proportion);
                        }

                        for (int i = 0; i < _selectedDomains.Length; i++)
                        {
                            Domain = _selectedDomains[i];

                            for (int j = 0; j < normalizedIntensity[i]; j++)
                            {
                                MaxAddress    = RTC_MemoryDomains.getInterface(Domain).Size;
                                RandomAddress = RTC_Core.RND.RandomLong(MaxAddress - 1);

                                bu = getBlastUnit(Domain, RandomAddress);
                                if (bu != null)
                                {
                                    bl.Layer.Add(bu);
                                }
                            }
                        }

                        break;

                    case BlastRadius.EVEN:                             //Evenly distributes the blasts through all selected domains

                        for (int i = 0; i < _selectedDomains.Length; i++)
                        {
                            Domain = _selectedDomains[i];

                            for (int j = 0; j < (_Intensity / _selectedDomains.Length); j++)
                            {
                                MaxAddress    = RTC_MemoryDomains.getInterface(Domain).Size;
                                RandomAddress = RTC_Core.RND.RandomLong(MaxAddress - 1);

                                bu = getBlastUnit(Domain, RandomAddress);
                                if (bu != null)
                                {
                                    bl.Layer.Add(bu);
                                }
                            }
                        }

                        break;

                    case BlastRadius.NONE:                             //Shouldn't ever happen but handled anyway
                        return(null);
                    }


                    if (bl.Layer.Count == 0)
                    {
                        return(null);
                    }
                    else
                    {
                        return(bl);
                    }
                }
            }
            catch (Exception ex)
            {
                DialogResult dr = MessageBox.Show("Something went wrong in the RTC Core. \n" +
                                                  "This is not a BizHawk error so you should probably send a screenshot of this to the devs\n\n" +
                                                  "If you know the steps to reproduce this error it would be greatly appreaciated.\n\n" +
                                                  (RTC_Core.coreForm.AutoCorrupt ? ">> STOP AUTOCORRUPT ?.\n\n" : "") +
                                                  $"domain:{Domain.ToString()} maxaddress:{MaxAddress.ToString()} randomaddress:{RandomAddress.ToString()} \n\n" +
                                                  ex.ToString(), "Error", (RTC_Core.coreForm.AutoCorrupt ? MessageBoxButtons.YesNo : MessageBoxButtons.OK));

                if (dr == DialogResult.Yes || dr == DialogResult.OK)
                {
                    RTC_Core.coreForm.AutoCorrupt = false;
                }

                return(null);
            }
        }
Ejemplo n.º 12
0
        public static bool MergeStashkeys(List <StashKey> sks, bool _stashAfterOperation = true)
        {
            PreApplyStashkey();

            if (sks != null && sks.Count > 1)
            {
                var token = RTC_NetCore.HugeOperationStart();


                StashKey master = sks[0];

                string masterSystemCore  = master.SystemCore;
                bool   allCoresIdentical = true;

                foreach (StashKey item in sks)
                {
                    if (item.SystemCore != master.SystemCore)
                    {
                        allCoresIdentical = false;
                        break;
                    }
                }

                if (!allCoresIdentical && !RTC_Core.AllowCrossCoreCorruption)
                {
                    MessageBox.Show("Merge attempt failed: Core mismatch\n\n" + string.Join("\n", sks.Select(it => $"{it.GameName} -> {it.SystemName} -> {it.SystemCore}")));
                    RTC_NetCore.HugeOperationEnd(token);

                    return(false);
                }

                BlastLayer bl = new BlastLayer();

                foreach (StashKey item in sks)
                {
                    bl.Layer.AddRange(item.BlastLayer.Layer);
                }



                currentStashkey             = new StashKey(RTC_Core.GetRandomKey(), master.ParentKey, bl);
                currentStashkey.RomFilename = master.RomFilename;
                currentStashkey.SystemName  = master.SystemName;
                currentStashkey.SystemCore  = master.SystemCore;
                currentStashkey.GameName    = master.GameName;

                //RTC_NetCore.HugeOperationEnd(token);
                token = RTC_NetCore.HugeOperationStart("LAZY");

                if (loadBeforeOperation)
                {
                    if (!LoadStateAndBlastLayer(currentStashkey))
                    {
                        RTC_NetCore.HugeOperationEnd(token);
                        return(isCorruptionApplied);
                    }
                }
                else
                {
                    RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.BLAST)
                    {
                        blastlayer = currentStashkey.BlastLayer
                    });
                }

                isCorruptionApplied = (currentStashkey.BlastLayer != null && currentStashkey.BlastLayer.Layer.Count > 0);

                if (stashAfterOperation && _stashAfterOperation)
                {
                    StashHistory.Add(currentStashkey);
                    RTC_Core.ghForm.RefreshStashHistory();
                }

                RTC_NetCore.HugeOperationEnd(token);

                PostApplyStashkey();
                return(true);
            }
            else
            {
                MessageBox.Show("You need 2 or more items for Merging");
                return(false);
            }
        }
Ejemplo n.º 13
0
        public void btnSendRaw_Click(object sender, EventArgs e)
        {
            string Key = RTC_Core.GetRandomKey();

            RTC_Core.SaveSave(Key + ".timejump");

            BlastLayer bl = new BlastLayer();

            foreach (var item in Global.CheatList)
            {
                string[] disassembleCheat = item.Name.Split('|');

                if (disassembleCheat[0] == "RTC Cheat")
                {
                    string _domain  = disassembleCheat[1];
                    long   _address = Convert.ToInt64(disassembleCheat[2]);

                    BizHawk.Client.Common.DisplayType _displayType;

                    switch (disassembleCheat[3])
                    {
                    case "Separator":
                        _displayType = BizHawk.Client.Common.DisplayType.Separator;
                        break;

                    case "Signed":
                        _displayType = BizHawk.Client.Common.DisplayType.Signed;
                        break;

                    case "Unsigned":
                        _displayType = BizHawk.Client.Common.DisplayType.Unsigned;
                        break;

                    case "Hex":
                        _displayType = BizHawk.Client.Common.DisplayType.Hex;
                        break;

                    case "Binary":
                        _displayType = BizHawk.Client.Common.DisplayType.Binary;
                        break;

                    case "FixedPoint_12_4":
                        _displayType = BizHawk.Client.Common.DisplayType.FixedPoint_12_4;
                        break;

                    case "FixedPoint_20_12":
                        _displayType = BizHawk.Client.Common.DisplayType.FixedPoint_20_12;
                        break;

                    case "FixedPoint_16_16":
                        _displayType = BizHawk.Client.Common.DisplayType.FixedPoint_16_16;
                        break;

                    case "Float":
                        _displayType = BizHawk.Client.Common.DisplayType.Float;
                        break;

                    default:
                        _displayType = BizHawk.Client.Common.DisplayType.Hex;
                        break;
                    }

                    bool _bigEndian = Convert.ToBoolean(disassembleCheat[4]);
                    int  _value     = Convert.ToInt32(disassembleCheat[5]);
                    bool _isEnabled = Convert.ToBoolean(disassembleCheat[6]);
                    bool _isFreeze  = Convert.ToBoolean(disassembleCheat[7]);

                    bl.Layer.Add(new BlastCheat(_domain, _address, _displayType, _bigEndian, _value, _isEnabled, _isFreeze));
                }
            }

            RTC_Core.currentStashkey = new StashKey(RTC_Core.GetRandomKey(), Key, bl);

            DontLoadSelectedStash = true;
            lbStashHistory.Items.Add(RTC_Core.currentStashkey);
            lbStashHistory.SelectedIndex = lbStashHistory.Items.Count - 1;
            lbStockpile.ClearSelected();

            RTC_Restore.SaveRestore();
        }
Ejemplo n.º 14
0
        private void btnCloudInject_Click(object sender, EventArgs e)
        {
            if (!IsValidCCC())
            {
                GlobalWin.Sound.StopSound();
                MessageBox.Show("The CorruptCloud Code entered below isn't valid");
                GlobalWin.Sound.StartSound();
                return;
            }
            GlobalWin.Sound.StopSound();
            RTC_RPC.SendToKillSwitch("FREEZE");

            BlastLayer bl = RTC_CorruptCloud.CloudLoad(tbCorruptCloudCode.Text);

            if (!bl.CCGD.CheckCompatibility())
            {
                GlobalWin.Sound.StartSound();
                return;
            }

            if (cbAutoLoadState.Checked)
            {
                if (btnParentKeys[Convert.ToInt32(currentSelectedState)] != null)
                {
                    LoadState();
                }
                else
                {
                    GlobalWin.Sound.StopSound();
                    MessageBox.Show("There is no SaveState in the selected box,\nPress 'Switch: Save/Load State' then Press 'SAVE'");
                    GlobalWin.Sound.StartSound();
                    RTC_RPC.SendToKillSwitch("UNFREEZE");
                    return;
                }
            }


            if (bl != null)
            {
                bl.Apply();
            }
            else
            {
                GlobalWin.Sound.StartSound();
                return;
            }

            if (bl != null)
            {
                IsCorruptionApplied = true;
            }


            if (cbStashInjected.Checked)
            {
                RTC_Core.currentStashkey = new StashKey(RTC_Core.GetRandomKey(), btnParentKeys[Convert.ToInt32(currentSelectedState)], bl);


                DontLoadSelectedStash = true;
                lbStashHistory.Items.Add(RTC_Core.currentStashkey);
                lbStashHistory.SelectedIndex = lbStashHistory.Items.Count - 1;
                lbStockpile.ClearSelected();
            }

            if (cbRenderAtCorrupt.Checked)
            {
                StartRender();
            }

            GlobalWin.Sound.StartSound();
            RTC_RPC.SendToKillSwitch("UNFREEZE");
        }
Ejemplo n.º 15
0
        private void btnCloudCorrupt_Click(object sender, EventArgs e)
        {
            if (!IsValidCCC())
            {
                GlobalWin.Sound.StopSound();
                MessageBox.Show("The CorruptCloud Code entered below isn't valid");
                GlobalWin.Sound.StartSound();
                return;
            }



            GlobalWin.Sound.StopSound();
            RTC_RPC.SendToKillSwitch("FREEZE");


            BlastLayer bl = RTC_CorruptCloud.CloudLoad(tbCorruptCloudCode.Text);

            if (!bl.CCGD.CheckCompatibility())
            {
                GlobalWin.Sound.StartSound();
                RTC_RPC.SendToKillSwitch("UNFREEZE");
                return;
            }

            if (cbAutoLoadState.Checked)
            {
                bl.CCGD.PutBackSavestate();
                LoadState(bl.CCGD.originalKey, bl.CCGD.originalGameSystem, bl.CCGD.originalGameName);
            }

            if (bl != null)
            {
                bl.Apply();
            }
            else
            {
                return;
            }


            if (bl != null)
            {
                IsCorruptionApplied = true;
            }

            if (cbStashCorrupted.Checked)
            {
                RTC_Core.currentStashkey = new StashKey(RTC_Core.GetRandomKey(), bl.CCGD.originalKey, bl);

                DontLoadSelectedStash = true;
                lbStashHistory.Items.Add(RTC_Core.currentStashkey);
                lbStashHistory.SelectedIndex = lbStashHistory.Items.Count - 1;
                lbStockpile.ClearSelected();
            }

            if (cbRenderAtCorrupt.Checked)
            {
                StartRender();
            }

            RTC_RPC.SendToKillSwitch("UNFREEZE");
            GlobalWin.Sound.StartSound();
        }
Ejemplo n.º 16
0
        //Generates or queries a blast layer then applies it.
        public static BlastLayer Blast(BlastLayer _layer)
        {
            try
            {
                if (_layer != null)
                {
                    _layer.Apply(); //If the BlastLayer was provided, there's no need to generate a new one.

                    return(_layer);
                }
                else if (RTC_Core.SelectedEngine == CorruptionEngine.EXTERNALROM)
                {
                    BlastLayer romLayer = RTC_ExternalRomPlugin.GetLayer();
                    if (romLayer == null)
                    {
                        return(null);
                    }
                    else
                    {
                        romLayer.Apply();
                        return(romLayer);
                    }
                }
                else
                {
                    BlastLayer bl = new BlastLayer();

                    if (RTC_Core.SelectedEngine != CorruptionEngine.FREEZE && RTC_MemoryZones.SelectedDomains.Count == 0)
                    {
                        return(null);
                    }

                    string    Domain;
                    long      MaxAdress;
                    long      RandomAdress = 0;
                    BlastUnit bu;

                    if (RTC_Core.SelectedEngine == CorruptionEngine.DISTORTION && RTC_DistortionEngine.CurrentAge < RTC_DistortionEngine.MaxAge)
                    {
                        RTC_DistortionEngine.CurrentAge++;
                    }

                    switch (Radius)
                    {
                    case BlastRadius.SPREAD:

                        for (int i = 0; i < Intensity; i++)     //Randomly spreads all corruption bytes to all selected zones
                        {
                            if (RTC_Core.SelectedEngine != CorruptionEngine.FREEZE)
                            {
                                Domain = RTC_MemoryZones.SelectedDomains[RND.Next(RTC_MemoryZones.SelectedDomains.Count)];
                            }
                            else
                            {
                                Domain = RTC_Core.hexeditor._domain.ToString();
                            }

                            MaxAdress    = RTC_MemoryZones.getDomain(Domain).Size;
                            RandomAdress = LongRandom(MaxAdress);

                            bu = getBlastUnit(Domain, RandomAdress);
                            if (bu != null)
                            {
                                bl.Layer.Add(bu);
                            }
                        }

                        break;

                    case BlastRadius.CHUNK:     //Randomly spreads the corruption bytes in one randomly selected zone

                        if (RTC_Core.SelectedEngine != CorruptionEngine.FREEZE)
                        {
                            Domain = RTC_MemoryZones.SelectedDomains[RND.Next(RTC_MemoryZones.SelectedDomains.Count)];
                        }
                        else
                        {
                            Domain = RTC_Core.hexeditor._domain.ToString();
                        }

                        MaxAdress = RTC_MemoryZones.getDomain(Domain).Size;

                        for (int i = 0; i < Intensity; i++)
                        {
                            RandomAdress = LongRandom(MaxAdress);

                            bu = getBlastUnit(Domain, RandomAdress);
                            if (bu != null)
                            {
                                bl.Layer.Add(bu);
                            }
                        }

                        break;

                    case BlastRadius.BURST:

                        for (int j = 0; j < 10; j++)     // 10 shots of 10% chunk
                        {
                            if (RTC_Core.SelectedEngine != CorruptionEngine.FREEZE)
                            {
                                Domain = RTC_MemoryZones.SelectedDomains[RND.Next(RTC_MemoryZones.SelectedDomains.Count)];
                            }
                            else
                            {
                                Domain = RTC_Core.hexeditor._domain.ToString();
                            }

                            MaxAdress = RTC_MemoryZones.getDomain(Domain).Size;

                            for (int i = 0; i < (int)((double)Intensity / 10); i++)
                            {
                                RandomAdress = LongRandom(MaxAdress);

                                bu = getBlastUnit(Domain, RandomAdress);
                                if (bu != null)
                                {
                                    bl.Layer.Add(bu);
                                }
                            }
                        }

                        break;

                    case BlastRadius.NONE:
                        return(null);
                    }

                    bl.Apply();

                    RTC_HellgenieEngine.RemoveExcessCheats();

                    if (bl.Layer.Count == 0)
                    {
                        return(null);
                    }
                    else
                    {
                        return(bl);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong in the RTC Core. \n" +
                                "This is not a BizHawk error so you should probably send a screenshot of this to the devs\n\n" +
                                ex.ToString());
                return(null);
            }
        }
Ejemplo n.º 17
0
        public static StashKey getRawBlastlayer()
        {
            RTC_Core.StopSound();

            StashKey sk = RTC_StockpileManager.SaveState_NET(false);

            BlastLayer bl = new BlastLayer();

            foreach (var item in Global.CheatList)
            {
                string[] disassembleCheat = item.Name.Split('|');

                if (disassembleCheat[0] == "RTC Cheat")
                {
                    string _domain  = disassembleCheat[1];
                    long   _address = Convert.ToInt64(disassembleCheat[2]);

                    BizHawk.Client.Common.DisplayType _displayType = BizHawk.Client.Common.DisplayType.Unsigned;

                    bool   _bigEndian = Convert.ToBoolean(disassembleCheat[4]);
                    byte[] _value     = disassembleCheat[5].Split(',').Select(it => Convert.ToByte(it)).ToArray();
                    bool   _isEnabled = Convert.ToBoolean(disassembleCheat[6]);
                    bool   _isFreeze  = Convert.ToBoolean(disassembleCheat[7]);

                    bl.Layer.Add(new BlastCheat(_domain, _address, _displayType, _bigEndian, _value, _isEnabled, _isFreeze));
                }
            }

            bl.Layer.AddRange(RTC_PipeEngine.AllBlastPipes);

            string thisSystem  = Global.Game.System;
            string romFilename = GlobalWin.MainForm.CurrentlyOpenRom;

            var rp = RTC_MemoryDomains.GetRomParts(thisSystem, romFilename);

            if (rp.error == null)
            {
                if (rp.primarydomain != null)
                {
                    List <byte> addData = new List <byte>();

                    if (rp.skipbytes != 0)
                    {
                        byte[] padding = new byte[rp.skipbytes];
                        for (int i = 0; i < rp.skipbytes; i++)
                        {
                            padding[i] = 0;
                        }

                        addData.AddRange(padding);
                    }

                    addData.AddRange(RTC_MemoryDomains.getDomainData(rp.primarydomain));
                    if (rp.seconddomain != null)
                    {
                        addData.AddRange(RTC_MemoryDomains.getDomainData(rp.seconddomain));
                    }

                    byte[] corrupted = addData.ToArray();
                    byte[] original  = File.ReadAllBytes(GlobalWin.MainForm.CurrentlyOpenRom);

                    if (RTC_MemoryDomains.MemoryInterfaces.ContainsKey("32X FB")) //Flip 16-bit words on 32X rom
                    {
                        original = original.FlipWords(2);
                    }
                    else if (thisSystem.ToUpper() == "N64")
                    {
                        original = BizHawk.Client.Common.RomGame.MutateSwapN64(original);
                    }
                    else if (GlobalWin.MainForm.CurrentlyOpenRom.ToUpper().Contains(".SMD"))
                    {
                        original = BizHawk.Client.Common.RomGame.DeInterleaveSMD(original);
                    }

                    for (int i = 0; i < rp.skipbytes; i++)
                    {
                        original[i] = 0;
                    }

                    BlastLayer romBlast = RTC_ExternalRomPlugin.GetBlastLayer(original, corrupted);

                    if (romBlast != null && romBlast.Layer.Count > 0)
                    {
                        bl.Layer.AddRange(romBlast.Layer);
                    }
                }
            }

            sk.BlastLayer = bl;
            RTC_Core.StartSound();

            return(sk);
        }
        public static BlastLayer GetLayer()
        {
            if (!File.Exists("CorruptedROM.rom"))
            {
                MessageBox.Show("Null Plugin: You must have CorruptedROM.rom in your BizHawk folder");
                return(null);
            }

            CorruptedRom = "CorruptedROM.rom";

            BlastLayer bl = new BlastLayer();

            string thisSystem    = Global.Game.System;
            string _domain       = "";
            string _seconddomain = "";
            int    skipbytes     = 0;

            switch (thisSystem)
            {
            case "NES":
                _domain       = "PRG ROM";
                _seconddomain = "CHR VROM";
                skipbytes     = 16;
                break;

            case "SNES":
                _domain = "CARTROM";
                break;

            case "N64":
                _domain = "ROM";
                break;

            case "GB":
            case "GBC":
                _domain = "ROM";
                break;

            case "SMS":     // Sega Master System
                _domain = "ROM";
                return(null);

            case "GEN":     // Sega Genesis
                _domain = "MD CART";
                break;

            case "PSX":                     // PlayStation
                MessageBox.Show("Unfortunately, Bizhawk doesn't support editing the PSX's ISO while it is running. Maybe in a future version...");
                return(null);

            case "INTV":
            case "SG":
            case "GG":
            case "PCECD":
            case "PCE":
            case "SGX":
            case "TI83":
            case "A26":
            case "A78":
            case "C64":
            case "Coleco":
            case "GBA":
            case "SAT":
            case "DGB":
            default:
                MessageBox.Show("The selected system doesn't appear to have bridge configurations yet. This will not work. You could ask the devs to add it though.");
                break;
            }


            byte[] Original = File.ReadAllBytes(GlobalWin.MainForm.CurrentlyOpenRom);
            byte[] Corrupt  = File.ReadAllBytes("CorruptedROM.rom");

            if (Original.Length != Corrupt.Length)
            {
                MessageBox.Show("Error: The corrupted rom isn't the same size as the original one");
                return(null);
            }

            long maxaddress = RTC_MemoryZones.getDomain(_domain).Size;

            for (int i = 0; i < Original.Length; i++)
            {
                if (Original[i] != Corrupt[i] && i >= skipbytes)
                {
                    if (i - skipbytes >= maxaddress)
                    {
                        bl.Layer.Add(new BlastByte(_seconddomain, (i - skipbytes) - maxaddress, BlastByteType.SET, Convert.ToInt32(Corrupt[i]), true));
                    }
                    else
                    {
                        bl.Layer.Add(new BlastByte(_domain, i - skipbytes, BlastByteType.SET, Convert.ToInt32(Corrupt[i]), true));
                    }
                }
            }

            if (bl.Layer.Count == 0)
            {
                return(null);
            }
            else
            {
                return(bl);
            }
        }
Ejemplo n.º 19
0
        public void btnCorrupt_Click(object sender, EventArgs e)
        {
            if (RTC_Core.coreForm.cbClearCheatsOnRewind.Checked == true)
            {
                RTC_HellgenieEngine.ClearCheats();
            }

            if (cbAutoLoadState.Checked && btnCorrupt.Text.ToUpper() != "MERGE")
            {
                if (btnParentKeys[Convert.ToInt32(currentSelectedState)] != null)
                {
                    if (!LoadState())
                    {
                        return;
                    }
                }
                else
                {
                    GlobalWin.Sound.StopSound();
                    MessageBox.Show("There is no SaveState in the selected box,\nPress 'Switch: Save/Load State' then Press 'SAVE'");
                    GlobalWin.Sound.StartSound();
                    return;
                }
            }


            if (rbCorrupt.Checked)
            {
                BlastLayer bl = RTC_Core.Blast();

                if (bl != null)
                {
                    IsCorruptionApplied = true;
                }

                if (cbStashCorrupted.Checked)
                {
                    if (bl == null)
                    {
                        return;
                    }

                    RTC_Core.currentStashkey = new StashKey(RTC_Core.GetRandomKey(), btnParentKeys[Convert.ToInt32(currentSelectedState)], bl);

                    DontLoadSelectedStash = true;
                    lbStashHistory.Items.Add(RTC_Core.currentStashkey);
                    lbStashHistory.SelectedIndex = lbStashHistory.Items.Count - 1;
                    lbStockpile.ClearSelected();
                }

                if (cbRenderAtCorrupt.Checked)
                {
                    StartRender();
                }
            }
            else if (rbInject.Checked)
            {
                if (lbStashHistory.SelectedIndex == -1 && lbStockpile.SelectedIndex == -1)
                {
                    return;
                }

                if (cbAutoLoadState.Checked)
                {
                    if (btnParentKeys[Convert.ToInt32(currentSelectedState)] != null)
                    {
                        LoadState();
                    }
                    else
                    {
                        GlobalWin.Sound.StopSound();
                        MessageBox.Show("There is no SaveState in the selected box,\nPress 'Switch: Save/Load State' then Press 'SAVE'");
                        GlobalWin.Sound.StartSound();
                        return;
                    }
                }

                if (lbStashHistory.SelectedIndex != -1)
                {
                    RTC_Core.currentStashkey = (lbStashHistory.SelectedItem as StashKey);
                    RTC_Core.currentStashkey.Inject();
                    IsCorruptionApplied = true;
                }

                if (lbStockpile.SelectedIndex != -1)
                {
                    RTC_Core.currentStashkey = (lbStockpile.SelectedItem as StashKey);
                    RTC_Core.currentStashkey.Inject();
                    IsCorruptionApplied = true;
                }

                if (cbStashInjected.Checked)
                {
                    if (lbStashHistory.SelectedIndex != -1)
                    {
                        RTC_Core.currentStashkey = new StashKey(RTC_Core.GetRandomKey(), btnParentKeys[Convert.ToInt32(currentSelectedState)], (lbStashHistory.SelectedItem as StashKey).blastlayer);
                    }

                    if (lbStockpile.SelectedIndex != -1)
                    {
                        RTC_Core.currentStashkey = new StashKey(RTC_Core.GetRandomKey(), btnParentKeys[Convert.ToInt32(currentSelectedState)], (lbStockpile.SelectedItem as StashKey).blastlayer);
                    }

                    DontLoadSelectedStash = true;
                    lbStashHistory.Items.Add(RTC_Core.currentStashkey);
                    lbStashHistory.SelectedIndex = lbStashHistory.Items.Count - 1;
                    lbStockpile.ClearSelected();
                }

                if (cbRenderAtCorrupt.Checked)
                {
                    StartRender();
                }
            }
            else if (rbOriginal.Checked)
            {
                if (lbStashHistory.SelectedIndex == -1 && lbStockpile.SelectedIndex == -1)
                {
                    return;
                }

                if (lbStashHistory.SelectedIndex != -1)
                {
                    RTC_Core.currentStashkey = (lbStashHistory.SelectedItem as StashKey);
                    RTC_Core.currentStashkey.RunOriginal();
                    IsCorruptionApplied = false;
                }

                if (lbStockpile.SelectedIndex != -1)
                {
                    RTC_Core.currentStashkey = (lbStockpile.SelectedItem as StashKey);
                    IsCorruptionApplied      = false;
                }
            }
            else
            {
                if (lbStockpile.SelectedItems.Count > 1)
                {
                    BlastLayer bl = new BlastLayer();

                    foreach (StashKey item in lbStockpile.SelectedItems)
                    {
                        bl.Layer.AddRange(item.blastlayer.Layer);
                    }

                    //bl.Apply();
                    isStockpileSelectMultiple = false;

                    if (cbStashCorrupted.Checked)
                    {
                        if (bl == null)
                        {
                            return;
                        }

                        RTC_Core.currentStashkey = new StashKey(RTC_Core.GetRandomKey(), (lbStockpile.SelectedItem as StashKey).ParentKey, bl);

                        ApplyCurrentStashkey();

                        DontLoadSelectedStash = true;
                        lbStashHistory.Items.Add(RTC_Core.currentStashkey);
                        lbStashHistory.SelectedIndex = lbStashHistory.Items.Count - 1;
                        lbStockpile.ClearSelected();
                        IsCorruptionApplied = true;
                    }

                    if (cbRenderAtCorrupt.Checked)
                    {
                        StartRender();
                    }
                }
                else
                {
                    MessageBox.Show("Select 2 or more items from the Current Stockpile to merge.");
                }
            }

            RTC_Restore.SaveRestore();
        }
Ejemplo n.º 20
0
        public static bool Corrupt(bool _loadBeforeOperation = true)
        {
            PreApplyStashkey();

            var token = RTC_NetCore.HugeOperationStart("LAZY");

            StashKey psk = RTC_StockpileManager.getCurrentSavestateStashkey();

            if (psk == null)
            {
                RTC_Core.StopSound();
                MessageBox.Show("The Glitch Harvester could not perform the CORRUPT action\n\nEither no Savestate Box was selected in the Savestate Manager\nor the Savetate Box itself is empty.");
                RTC_Core.StartSound();
                RTC_NetCore.HugeOperationEnd(token);
                return(false);
            }

            string currentGame = (string)RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.REMOTE_KEY_GETGAMENAME), true);

            if (psk.GameName != currentGame)
            {
                RTC_Core.LoadRom(psk.RomFilename, true);
                RTC_Core.ecForm.RefreshDomains();
                RTC_Core.ecForm.setMemoryDomainsAllButSelectedDomains(RTC_MemoryDomains.GetBlacklistedDomains());
            }



            BlastLayer bl = (BlastLayer)RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.BLAST)
            {
                objectValue = RTC_MemoryDomains.SelectedDomains
            }, true);

            currentStashkey             = new StashKey(RTC_Core.GetRandomKey(), psk.ParentKey, bl);
            currentStashkey.RomFilename = psk.RomFilename;
            currentStashkey.SystemName  = psk.SystemName;
            currentStashkey.SystemCore  = psk.SystemCore;
            currentStashkey.GameName    = psk.GameName;

            if (loadBeforeOperation && _loadBeforeOperation)
            {
                if (!LoadStateAndBlastLayer(currentStashkey))
                {
                    RTC_NetCore.HugeOperationEnd(token);
                    return(isCorruptionApplied);
                }
            }
            else
            {
                RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.BLAST)
                {
                    blastlayer = bl
                });
            }

            isCorruptionApplied = (bl != null);

            if (stashAfterOperation && bl != null)
            {
                StashHistory.Add(currentStashkey);
                RTC_Core.ghForm.RefreshStashHistory();
                RTC_Core.ghForm.dgvStockpile.ClearSelection();
                RTC_Core.ghForm.DontLoadSelectedStash        = true;
                RTC_Core.ghForm.lbStashHistory.SelectedIndex = RTC_Core.ghForm.lbStashHistory.Items.Count - 1;
            }

            RTC_NetCore.HugeOperationEnd(token);

            PostApplyStashkey();
            return(isCorruptionApplied);
        }