private bool generateActiveTable() { try { if (!ComputeActiveTableActivity()) { return(false); //exit generation if activity computation failed } List <long> newActiveTable = new List <long>(); double computedThreshold = (double)ActiveTableDumps.Count * (ActivityThreshold / 100d) + 1d; bool ExcludeEverchanging = cbActiveTableExclude100percent.Checked; for (int i = 0; i < ActiveTableActivity.Length; i++) { if ((double)ActiveTableActivity[i] >= computedThreshold && (!ExcludeEverchanging || ActiveTableActivity[i] != ((long)ActiveTableDumps.Count - 1))) { newActiveTable.Add(i); } } long[] tempActiveTable = newActiveTable.ToArray(); if (cbActiveTableCapSize.Checked && nmActiveTableCapSize.Value < tempActiveTable.Length) { ActiveTableGenerated = CapActiveTable(tempActiveTable); } else { ActiveTableGenerated = tempActiveTable; } lbActiveTableSize.Text = "Active table size: " + ActiveTableGenerated.Length.ToString(); ActiveTableReady = true; currentFilename = null; return(true); } catch (Exception ex) { string additionalInfo = "Something went wrong in when generating the active table. \n" + "This is an RTC error, so you should probably send this to the RTC devs with instructions on what you did to cause it.\n\n"; var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace); if (CloudDebug.ShowErrorDialog(ex2, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } return(false); } finally { } }
public RTC_Intro_Form() { try { InitializeComponent(); } catch (Exception ex) { if (CloudDebug.ShowErrorDialog(ex, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } } }
public RTC_SanitizeTool_Form() { try { InitializeComponent(); } catch (Exception ex) { string additionalInfo = "An error occurred while opening the SanitizeTool Form\n\n"; var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace); if (CloudDebug.ShowErrorDialog(ex2, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } } }
private void btnLoadStockpile_MouseDown(object sender, MouseEventArgs e) { Point locate = new Point((sender as Control).Location.X + e.Location.X, (sender as Control).Location.Y + e.Location.Y); ContextMenuStrip LoadMenuItems = new ContextMenuStrip(); LoadMenuItems.Items.Add("Load Stockpile", null, new EventHandler((ob, ev) => { try { DontLoadSelectedStockpile = true; string filename = ""; OpenFileDialog ofd = new OpenFileDialog { DefaultExt = "sks", Title = "Open Stockpile File", Filter = "SKS files|*.sks", RestoreDirectory = true }; if (ofd.ShowDialog() == DialogResult.OK) { filename = ofd.FileName; } else { return; } LoadStockpile(filename); } catch (Exception ex) { string additionalInfo = "Loading Failure ->\n\n"; var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace); if (CloudDebug.ShowErrorDialog(ex2, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } } })); LoadMenuItems.Items.Add($"Load {RtcCore.VanguardImplementationName} settings from Stockpile", null, new EventHandler((ob, ev) => { try { AutoKillSwitch.Enabled = false; Stockpile.LoadConfigFromStockpile(); AutoKillSwitch.Enabled = true; } catch (Exception ex) { string additionalInfo = "Loading Settings Failure ->\n\n"; var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace); if (CloudDebug.ShowErrorDialog(ex2, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } } })); LoadMenuItems.Items.Add($"Restore {RtcCore.VanguardImplementationName} config Backup", null, new EventHandler((ob, ev) => { try { AutoKillSwitch.Enabled = false; Stockpile.RestoreEmuConfig(); AutoKillSwitch.Enabled = true; } finally { } })).Enabled = (File.Exists(Path.Combine(CorruptCore.RtcCore.EmuDir, "backup_config.ini"))); LoadMenuItems.Show(this, locate); }
public object OnMessageReceived(object sender, NetCoreEventArgs e) { try { //Use setReturnValue to handle returns var message = e.message; var advancedMessage = message as NetCoreAdvancedMessage; switch (e.message.Type) { case "GETSPECDUMPS": StringBuilder sb = new StringBuilder(); sb.AppendLine("Spec Dump from CorruptCore"); sb.AppendLine(); sb.AppendLine("UISpec"); RTCV.NetCore.AllSpec.UISpec?.GetDump().ForEach(x => sb.AppendLine(x)); sb.AppendLine("CorruptCoreSpec"); RTCV.NetCore.AllSpec.CorruptCoreSpec?.GetDump().ForEach(x => sb.AppendLine(x)); sb.AppendLine("VanguardSpec"); RTCV.NetCore.AllSpec.VanguardSpec?.GetDump().ForEach(x => sb.AppendLine(x)); e.setReturnValue(sb.ToString()); break; //UI sent its spec case REMOTE_PUSHUISPEC: { SyncObjectSingleton.FormExecute(() => { RTCV.NetCore.AllSpec.UISpec = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached); }); break; } //UI sent a spec update case REMOTE_PUSHUISPECUPDATE: SyncObjectSingleton.FormExecute(() => { RTCV.NetCore.AllSpec.UISpec?.Update((PartialSpec)advancedMessage.objectValue); }); break; //Vanguard sent a copy of its spec case REMOTE_PUSHVANGUARDSPEC: SyncObjectSingleton.FormExecute(() => { if (!RtcCore.Attached) { RTCV.NetCore.AllSpec.VanguardSpec = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached); } }); break; //Vanguard sent a spec update case REMOTE_PUSHVANGUARDSPECUPDATE: RTCV.NetCore.AllSpec.VanguardSpec?.Update((PartialSpec)advancedMessage.objectValue, false); break; //UI sent a copy of the CorruptCore spec case REMOTE_PUSHCORRUPTCORESPEC: SyncObjectSingleton.FormExecute(() => { //So here's the deal. The UI doesn't actually have the full memory domains (md isn't sent across) so if we take them from it, it results in them going null //Instead, we stick with what we have, then tell the UI to use that. var temp = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached); //Stick with what we have if it exists to prevent any exceptions if autocorrupt was on or something, then call refresh temp.Update("MEMORYINTERFACES", AllSpec.CorruptCoreSpec?["MEMORYINTERFACES"] ?? new Dictionary <string, MemoryDomainProxy>()); RTCV.NetCore.AllSpec.CorruptCoreSpec = new FullSpec(temp.GetPartialSpec(), !RtcCore.Attached); RTCV.NetCore.AllSpec.CorruptCoreSpec.SpecUpdated += (ob, eas) => { PartialSpec partial = eas.partialSpec; LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_PUSHCORRUPTCORESPECUPDATE, partial, true); }; RTCV.CorruptCore.MemoryDomains.RefreshDomains(); }); e.setReturnValue(true); break; //UI sent an update of the CorruptCore spec case REMOTE_PUSHCORRUPTCORESPECUPDATE: SyncObjectSingleton.FormExecute(() => { RTCV.NetCore.AllSpec.CorruptCoreSpec?.Update((PartialSpec)advancedMessage.objectValue, false); }); break; case REMOTE_EVENT_DOMAINSUPDATED: var domainsChanged = (bool)advancedMessage.objectValue; MemoryDomains.RefreshDomains(domainsChanged); break; case REMOTE_EVENT_RESTRICTFEATURES: { if (!RTCV.NetCore.AllSpec.VanguardSpec?.Get <bool>(VSPEC.SUPPORTS_SAVESTATES) ?? true) { LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_DISABLESAVESTATESUPPORT); } if (!RTCV.NetCore.AllSpec.VanguardSpec?.Get <bool>(VSPEC.SUPPORTS_REALTIME) ?? true) { LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_DISABLEREALTIMESUPPORT); } if (!RTCV.NetCore.AllSpec.VanguardSpec?.Get <bool>(VSPEC.SUPPORTS_KILLSWITCH) ?? true) { LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_DISABLEKILLSWITCHSUPPORT); } if (!RTCV.NetCore.AllSpec.VanguardSpec?.Get <bool>(VSPEC.SUPPORTS_GAMEPROTECTION) ?? true) { LocalNetCoreRouter.Route(NetcoreCommands.UI, NetcoreCommands.REMOTE_DISABLEGAMEPROTECTIONSUPPORT); } break; } case REMOTE_EVENT_SHUTDOWN: { RtcCore.Shutdown(); break; } case REMOTE_OPENHEXEDITOR: { if ((bool?)AllSpec.VanguardSpec[VSPEC.USE_INTEGRATED_HEXEDITOR] ?? false) { LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_OPENHEXEDITOR, true); } else { //Route it to the plugin if loaded if (RtcCore.PluginHost.LoadedPlugins.Any(x => x.Name == "Hex Editor")) { LocalNetCoreRouter.Route("HEXEDITOR", NetcoreCommands.REMOTE_OPENHEXEDITOR, true); } else { MessageBox.Show("The current Vanguard implementation does not include a\n hex editor & the hex editor plugin isn't loaded. Aborting."); } } } break; case EMU_OPEN_HEXEDITOR_ADDRESS: { if ((bool?)AllSpec.VanguardSpec[VSPEC.USE_INTEGRATED_HEXEDITOR] ?? false) { LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.EMU_OPEN_HEXEDITOR_ADDRESS, advancedMessage.objectValue, true); } else { //Route it to the plugin if loaded if (RtcCore.PluginHost.LoadedPlugins.Any(x => x.Name == "Hex Editor")) { LocalNetCoreRouter.Route("HEXEDITOR", NetcoreCommands.EMU_OPEN_HEXEDITOR_ADDRESS, advancedMessage.objectValue, true); } else { MessageBox.Show("The current Vanguard implementation does not include a\n hex editor & the hex editor plugin isn't loaded. Aborting."); } } break; } case MANUALBLAST: { RtcCore.GenerateAndBlast(); } break; case GENERATEBLASTLAYER: { var val = advancedMessage.objectValue as object[]; StashKey sk = val[0] as StashKey; bool loadBeforeCorrupt = (bool)val[1]; bool applyBlastLayer = (bool)val[2]; bool backup = (bool)val[3]; BlastLayer bl = null; bool UseSavestates = (bool)AllSpec.VanguardSpec[VSPEC.SUPPORTS_SAVESTATES]; void a() { lock (loadLock) { //Load the game from the main thread if (UseSavestates && loadBeforeCorrupt) { SyncObjectSingleton.FormExecute(() => { StockpileManager_EmuSide.LoadRom_NET(sk); }); } if (UseSavestates && loadBeforeCorrupt) { StockpileManager_EmuSide.LoadState_NET(sk, false); } //We pull the domains here because if the syncsettings changed, there's a chance the domains changed string[] domains = (string[])AllSpec.UISpec["SELECTEDDOMAINS"]; var cpus = Environment.ProcessorCount; if (cpus == 1 || AllSpec.VanguardSpec[VSPEC.SUPPORTS_MULTITHREAD] == null) { bl = RtcCore.GenerateBlastLayer(domains); } else { //if emulator supports multithreaded access of the domains, disregard the emulation thread and just span threads... long reminder = RtcCore.Intensity % (cpus - 1); long splitintensity = (RtcCore.Intensity - reminder) / (cpus - 1); Task <BlastLayer>[] tasks = new Task <BlastLayer> [cpus]; for (int i = 0; i < cpus; i++) { long requestedIntensity = splitintensity; if (i == 0 && reminder != 0) { requestedIntensity = reminder; } tasks[i] = Task.Factory.StartNew(() => RtcCore.GenerateBlastLayer(domains, requestedIntensity)); } Task.WaitAll(tasks); bl = tasks[0] .Result ?? new BlastLayer(); if (tasks.Length > 1) { for (int i = 1; i < tasks.Length; i++) { if (tasks[i] .Result != null) { bl.Layer.AddRange(tasks[i] .Result.Layer); } } } if (bl.Layer.Count == 0) { bl = null; } } if (applyBlastLayer) { bl?.Apply(backup); } } } //If the emulator uses callbacks, we do everything on the main thread and once we're done, we unpause emulation if ((bool?)AllSpec.VanguardSpec[VSPEC.LOADSTATE_USES_CALLBACKS] ?? false) { SyncObjectSingleton.FormExecute(a); e.setReturnValue(LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_RESUMEEMULATION, true)); } else //We can just do everything on the emulation thread as it'll block { SyncObjectSingleton.EmuThreadExecute(a, true); } if (advancedMessage.requestGuid != null) { e.setReturnValue(bl); } break; } case APPLYBLASTLAYER: { var temp = advancedMessage.objectValue as object[]; BlastLayer bl = (BlastLayer)temp[0]; bool backup = (bool)temp[1]; void a() { bl.Apply(backup, true); } SyncObjectSingleton.EmuThreadExecute(a, true); break; } /* * case STASHKEY: * { * var temp = advancedMessage.objectValue as object[]; * * var sk = temp[0] as StashKey; * var romFilename = temp[1] as String; * var romData = temp[2] as Byte[]; * * if (!File.Exists(CorruptCore.rtcDir + Path.DirectorySeparatorChar + "WORKING" + Path.DirectorySeparatorChar + "SKS" + Path.DirectorySeparatorChar + romFilename)) * File.WriteAllBytes(CorruptCore.rtcDir + Path.DirectorySeparatorChar + "WORKING" + Path.DirectorySeparatorChar + "SKS" + Path.DirectorySeparatorChar + romFilename, romData); * * sk.RomFilename = CorruptCore.rtcDir + Path.DirectorySeparatorChar + "WORKING" + Path.DirectorySeparatorChar + "SKS" + Path.DirectorySeparatorChar + CorruptCore_Extensions.getShortFilenameFromPath(romFilename); * sk.DeployState(); * sk.Run(); * } * break; */ case REMOTE_PUSHRTCSPEC: RTCV.NetCore.AllSpec.CorruptCoreSpec = new FullSpec((PartialSpec)advancedMessage.objectValue, !RtcCore.Attached); e.setReturnValue(true); break; case REMOTE_PUSHRTCSPECUPDATE: RTCV.NetCore.AllSpec.CorruptCoreSpec?.Update((PartialSpec)advancedMessage.objectValue, false); break; case BLASTGENERATOR_BLAST: { List <BlastGeneratorProto> returnList = null; StashKey sk = (StashKey)(advancedMessage.objectValue as object[])[0]; List <BlastGeneratorProto> blastGeneratorProtos = (List <BlastGeneratorProto>)(advancedMessage.objectValue as object[])[1]; bool loadBeforeCorrupt = (bool)(advancedMessage.objectValue as object[])[2]; bool applyAfterCorrupt = (bool)(advancedMessage.objectValue as object[])[3]; bool resumeAfter = (bool)(advancedMessage.objectValue as object[])[4]; void a() { //Load the game from the main thread if (loadBeforeCorrupt) { SyncObjectSingleton.FormExecute(() => { StockpileManager_EmuSide.LoadRom_NET(sk); }); } if (loadBeforeCorrupt) { StockpileManager_EmuSide.LoadState_NET(sk, false); } returnList = BlastTools.GenerateBlastLayersFromBlastGeneratorProtos(blastGeneratorProtos, sk); if (applyAfterCorrupt) { BlastLayer bl = new BlastLayer(); foreach (var p in returnList.Where(x => x != null)) { bl.Layer.AddRange(p.bl.Layer); } bl.Apply(true); } } //If the emulator uses callbacks, we do everything on the main thread and once we're done, we unpause emulation if ((bool?)AllSpec.VanguardSpec[VSPEC.LOADSTATE_USES_CALLBACKS] ?? false) { SyncObjectSingleton.FormExecute(a); if (resumeAfter) { e.setReturnValue(LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_RESUMEEMULATION, true)); } } else { SyncObjectSingleton.EmuThreadExecute(a, false); } e.setReturnValue(returnList); break; } case REMOTE_LOADSTATE: { lock (loadLock) { StashKey sk = (StashKey)(advancedMessage.objectValue as object[])[0]; bool reloadRom = (bool)(advancedMessage.objectValue as object[])[1]; bool runBlastLayer = (bool)(advancedMessage.objectValue as object[])[2]; bool returnValue = false; //Load the game from the main thread if (reloadRom) { SyncObjectSingleton.FormExecute(() => { StockpileManager_EmuSide.LoadRom_NET(sk); }); } void a() { returnValue = StockpileManager_EmuSide.LoadState_NET(sk, runBlastLayer); } //If the emulator uses callbacks, we do everything on the main thread and once we're done, we unpause emulation if ((bool?)AllSpec.VanguardSpec[VSPEC.LOADSTATE_USES_CALLBACKS] ?? false) { SyncObjectSingleton.FormExecute(a); e.setReturnValue(LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_RESUMEEMULATION, true)); } else //We're loading on the emulator thread which'll block { SyncObjectSingleton.EmuThreadExecute(a, false); } e.setReturnValue(returnValue); } } break; case REMOTE_SAVESTATE: { StashKey sk = null; void a() { sk = StockpileManager_EmuSide.SaveState_NET(advancedMessage.objectValue as StashKey); //Has to be nullable cast } SyncObjectSingleton.EmuThreadExecute(a, false); e.setReturnValue(sk); } break; case REMOTE_SAVESTATELESS: { StashKey sk = null; void a() { sk = StockpileManager_EmuSide.SaveStateLess_NET(advancedMessage.objectValue as StashKey); //Has to be nullable cast } SyncObjectSingleton.EmuThreadExecute(a, false); e.setReturnValue(sk); } break; case REMOTE_BACKUPKEY_REQUEST: { //We don't store this in the spec as it'd be horrible to push it to the UI and it doesn't care //if (!LocalNetCoreRouter.QueryRoute<bool>(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_ISNORMALADVANCE)) //break; StashKey sk = null; //We send an unsynced command back SyncObjectSingleton.FormExecute(() => { sk = StockpileManager_EmuSide.SaveState_NET(); }); if (sk != null) { LocalNetCoreRouter.Route(NetcoreCommands.UI, REMOTE_BACKUPKEY_STASH, sk, false); } break; } case REMOTE_DOMAIN_GETDOMAINS: e.setReturnValue(LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_DOMAIN_GETDOMAINS, true)); break; case REMOTE_PUSHVMDPROTOS: MemoryDomains.VmdPool.Clear(); foreach (var proto in (advancedMessage.objectValue as VmdPrototype[])) { MemoryDomains.AddVMD(proto); } break; case REMOTE_DOMAIN_VMD_ADD: MemoryDomains.AddVMD_NET((advancedMessage.objectValue as VmdPrototype)); break; case REMOTE_DOMAIN_VMD_REMOVE: { StepActions.ClearStepBlastUnits(); MemoryDomains.RemoveVMD_NET((advancedMessage.objectValue as string)); } break; case REMOTE_DOMAIN_ACTIVETABLE_MAKEDUMP: { void a() { MemoryDomains.GenerateActiveTableDump((string)(advancedMessage.objectValue as object[])[0], (string)(advancedMessage.objectValue as object[])[1]); } SyncObjectSingleton.EmuThreadExecute(a, false); } break; case REMOTE_BLASTTOOLS_GETAPPLIEDBACKUPLAYER: { var bl = (BlastLayer)(advancedMessage.objectValue as object[])[0]; var sk = (StashKey)(advancedMessage.objectValue as object[])[1]; void a() { e.setReturnValue(BlastTools.GetAppliedBackupLayer(bl, sk)); } SyncObjectSingleton.EmuThreadExecute(a, false); break; } case REMOTE_LONGARRAY_FILTERDOMAIN: { lock (loadLock) { var objValues = (advancedMessage.objectValue as object[]); string domain = (string)objValues[0]; string LimiterListHash = (string)objValues[1]; StashKey sk = objValues[2] as StashKey; //Intentionally nullable void a() { if (sk != null) //If a stashkey was passed in, we want to load then profile { StockpileManager_EmuSide.LoadState_NET(sk, false); } MemoryInterface mi = MemoryDomains.MemoryInterfaces[domain]; List <long> allLegalAdresses = new List <long>(); int listItemSize = Filtering.GetPrecisionFromHash(LimiterListHash); for (long i = 0; i < mi.Size; i += listItemSize) { if (Filtering.LimiterPeekBytes(i, i + listItemSize, mi.Name, LimiterListHash, mi)) { for (int j = 0; j < listItemSize; j++) { allLegalAdresses.Add(i + j); } } } e.setReturnValue(allLegalAdresses.ToArray()); } //If the emulator uses callbacks and we're loading a state, we do everything on the main thread and once we're done, we unpause emulation if (sk != null && ((bool?)AllSpec.VanguardSpec[VSPEC.LOADSTATE_USES_CALLBACKS] ?? false)) { SyncObjectSingleton.FormExecute(a); LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_RESUMEEMULATION, true); } else //We can just do everything on the emulation thread as it'll block { SyncObjectSingleton.EmuThreadExecute(a, true); } } } break; case REMOTE_KEY_GETRAWBLASTLAYER: { void a() { e.setReturnValue(StockpileManager_EmuSide.GetRawBlastlayer()); } SyncObjectSingleton.EmuThreadExecute(a, false); } break; case REMOTE_BL_GETDIFFBLASTLAYER: { string filename = (advancedMessage.objectValue as string); void a() { e.setReturnValue(BlastDiff.GetBlastLayer(filename)); } SyncObjectSingleton.EmuThreadExecute(a, false); } break; case REMOTE_SET_APPLYUNCORRUPTBL: { void a() { if (StockpileManager_EmuSide.UnCorruptBL != null) { StockpileManager_EmuSide.UnCorruptBL.Apply(true); } } SyncObjectSingleton.EmuThreadExecute(a, false); } break; case REMOTE_SET_APPLYCORRUPTBL: { void a() { if (StockpileManager_EmuSide.CorruptBL != null) { StockpileManager_EmuSide.CorruptBL.Apply(false); } } SyncObjectSingleton.EmuThreadExecute(a, false); } break; case REMOTE_CLEARSTEPBLASTUNITS: SyncObjectSingleton.FormExecute(() => { StepActions.ClearStepBlastUnits(); }); break; case REMOTE_LOADPLUGINS: SyncObjectSingleton.FormExecute(() => { string emuPluginDir = ""; try { emuPluginDir = System.IO.Path.Combine(RtcCore.EmuDir, "RTC", "PLUGINS"); } catch (Exception e) { RTCV.Common.Logging.GlobalLogger.Error(e, "Unable to find plugin dir in {dir}", RtcCore.EmuDir + "\\RTC" + "\\PLUGINS"); } RtcCore.LoadPlugins(new[] { RtcCore.pluginDir, emuPluginDir }); }); break; case REMOTE_REMOVEEXCESSINFINITESTEPUNITS: SyncObjectSingleton.FormExecute(() => { StepActions.RemoveExcessInfiniteStepUnits(); }); break; default: new object(); break; } return(e.returnMessage); } catch (Exception ex) { if (CloudDebug.ShowErrorDialog(ex, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } return(e.returnMessage); } }
private void generateVMD() { if (ActiveTableGenerated == null || ActiveTableGenerated.Length == 0) { return; } try { MemoryInterface mi = MemoryDomains.MemoryInterfaces[cbSelectedMemoryDomain.SelectedItem.ToString()]; VirtualMemoryDomain VMD = new VirtualMemoryDomain(); VmdPrototype proto = new VmdPrototype(); int lastaddress = -1; proto.GenDomain = cbSelectedMemoryDomain.SelectedItem.ToString(); proto.VmdName = mi.Name + " " + CorruptCore.RtcCore.GetRandomKey(); proto.BigEndian = mi.BigEndian; proto.WordSize = mi.WordSize; proto.PointerSpacer = 1; if (UseCorePrecision) { foreach (int address in ActiveTableGenerated) { int safeaddress = (address - (address % mi.WordSize)); if (safeaddress != lastaddress) { lastaddress = safeaddress; for (int i = 0; i < mi.WordSize; i++) { proto.AddSingles.Add(safeaddress + i); } //[] _addresses = { safeaddress, safeaddress + mi.WordSize }; // proto.addRanges.Add(_addresses); } } } else { foreach (int address in ActiveTableGenerated) { proto.AddSingles.Add(address); } } VMD = proto.Generate(); if (VMD.Compacted ? VMD.CompactPointerAddresses.Length == 0 : VMD.PointerAddresses.Count == 0) { MessageBox.Show("The resulting VMD had no pointers so the operation got cancelled."); return; } MemoryDomains.AddVMD(VMD); S.GET <RTC_VmdPool_Form>().RefreshVMDs(); return; } catch (Exception ex) { string additionalInfo = "Something went wrong in when generating the VMD table. \n" + "This is an RTC error, so you should probably send this to the RTC devs with instructions on what you did to cause it.\n\n"; var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace); if (CloudDebug.ShowErrorDialog(ex2, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } return; } finally { } }
private static void OnMessageReceived(object sender, NetCoreEventArgs e) { try { var message = e.message; var simpleMessage = message as NetCoreSimpleMessage; var advancedMessage = message as NetCoreAdvancedMessage; switch (message.Type) //Handle received messages here { case REMOTE_PUSHVANGUARDSPEC: { if (!CorruptCore.RtcCore.Attached) { RTCV.NetCore.AllSpec.VanguardSpec = new FullSpec((PartialSpec)advancedMessage.objectValue, !CorruptCore.RtcCore.Attached); } e.setReturnValue(true); //Push the UI and CorruptCore spec (since we're master) LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_PUSHUISPEC, RTCV.NetCore.AllSpec.UISpec.GetPartialSpec(), true); LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_PUSHCORRUPTCORESPEC, RTCV.NetCore.AllSpec.CorruptCoreSpec.GetPartialSpec(), true); SyncObjectSingleton.FormExecute(() => { S.GET <UI_CoreForm>().pnAutoKillSwitch.Visible = true; S.GET <UI_CoreForm>().pnCrashProtection.Visible = true; }); //Specs are all set up so UI is clear. LocalNetCoreRouter.Route(NetcoreCommands.VANGUARD, NetcoreCommands.REMOTE_ALLSPECSSENT, true); } break; case REMOTE_ALLSPECSSENT: if (UICore.FirstConnect) { UICore.Initialized.WaitOne(10000); } SyncObjectSingleton.FormExecute(() => { if (UICore.FirstConnect) { lastVanguardClient = (string)RTCV.NetCore.AllSpec.VanguardSpec?[VSPEC.NAME] ?? "VANGUARD"; UICore.FirstConnect = false; //Load plugins on both sides CorruptCore.RtcCore.LoadPlugins(); LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_LOADPLUGINS, true); //Configure the UI based on the vanguard spec UICore.ConfigureUIFromVanguardSpec(); S.GET <UI_CoreForm>().Show(); //Pull any lists from the vanguard implementation if (RtcCore.EmuDir != null) { UICore.LoadLists(Path.Combine(RtcCore.EmuDir, "LISTS")); } UICore.LoadLists(CorruptCore.RtcCore.listsDir); Panel sidebar = S.GET <UI_CoreForm>().pnSideBar; foreach (Control c in sidebar.Controls) { if (c is Button b) { if (!b.Text.Contains("Test") && !b.Text.Contains("Custom Layout") && b.ForeColor != Color.OrangeRed) { b.Visible = true; } } } string customLayoutPath = Path.Combine(RTCV.CorruptCore.RtcCore.RtcDir, "CustomLayout.txt"); if (File.Exists(customLayoutPath)) { S.GET <UI_CoreForm>().btnOpenCustomLayout.Visible = true; } UI_DefaultGrids.engineConfig.LoadToMain(); UI_DefaultGrids.glitchHarvester.LoadToNewWindow("Glitch Harvester", true); } else { var clientName = (string)RTCV.NetCore.AllSpec.VanguardSpec?[VSPEC.NAME] ?? "VANGUARD"; if (clientName != lastVanguardClient) { MessageBox.Show($"Error: Found {clientName} when previously connected to {lastVanguardClient}.\nPlease restart the RTC to swap clients."); return; } //Push the VMDs since we store them out of spec var vmdProtos = MemoryDomains.VmdPool.Values.Cast <VirtualMemoryDomain>().Select(x => x.Proto).ToArray(); LocalNetCoreRouter.Route(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_PUSHVMDPROTOS, vmdProtos, true); S.GET <UI_CoreForm>().Show(); //Configure the UI based on the vanguard spec UICore.ConfigureUIFromVanguardSpec(); //Unblock the controls in the GH S.GET <RTC_GlitchHarvesterBlast_Form>().SetBlastButtonVisibility(true); //Return to the main form. If the form is null for some reason, default to engineconfig if (S.GET <UI_CoreForm>().previousGrid == null) { S.GET <UI_CoreForm>().previousGrid = UI_DefaultGrids.engineConfig; } UICore.UnlockInterface(); S.GET <UI_CoreForm>().previousGrid.LoadToMain(); } S.GET <UI_CoreForm>().pbAutoKillSwitchTimeout.Value = 0; //remove this once core form is dead if (!CorruptCore.RtcCore.Attached) { AutoKillSwitch.Enabled = true; } //Restart game protection if (S.GET <UI_CoreForm>().cbUseGameProtection.Checked) { if (CorruptCore.StockpileManager_UISide.BackupedState != null) { CorruptCore.StockpileManager_UISide.BackupedState.Run(); } if (CorruptCore.StockpileManager_UISide.BackupedState != null) { S.GET <RTC_MemoryDomains_Form>().RefreshDomainsAndKeepSelected(CorruptCore.StockpileManager_UISide.BackupedState.SelectedDomains.ToArray()); } GameProtection.Start(); if (GameProtection.WasAutoCorruptRunning) { S.GET <UI_CoreForm>().AutoCorrupt = true; } } S.GET <UI_CoreForm>().Show(); if (NetCore.Params.IsParamSet("SIMPLE_MODE")) { bool isSpec = (AllSpec.VanguardSpec[VSPEC.NAME] as string)?.ToUpper().Contains("SPEC") ?? false; if (isSpec) //Simple Mode cannot run on Stubs { MessageBox.Show("Unfortunately, Simple Mode is not compatible with Stubs. RTC will now switch to Normal Mode."); NetCore.Params.RemoveParam("SIMPLE_MODE"); } else { UI_DefaultGrids.simpleMode.LoadToMain(); RTC_SimpleMode_Form smForm = S.GET <RTC_SimpleMode_Form>(); smForm.EnteringSimpleMode(); } } }); break; case REMOTE_PUSHVANGUARDSPECUPDATE: SyncObjectSingleton.FormExecute(() => { RTCV.NetCore.AllSpec.VanguardSpec?.Update((PartialSpec)advancedMessage.objectValue); }); e.setReturnValue(true); break; //CorruptCore pushed its spec. Note the false on propogate (since we don't want a recursive loop) case REMOTE_PUSHCORRUPTCORESPECUPDATE: SyncObjectSingleton.FormExecute(() => { RTCV.NetCore.AllSpec.CorruptCoreSpec?.Update((PartialSpec)advancedMessage.objectValue, false); }); e.setReturnValue(true); break; case REMOTE_GENERATEVMDTEXT: SyncObjectSingleton.FormExecute(() => { object[] objs = (object[])advancedMessage.objectValue; string domain = (string)objs[0]; string text = (string)objs[1]; var vmdgenerator = S.GET <RTC_VmdGen_Form>(); vmdgenerator.btnSelectAll_Click(null, null); var cbitems = vmdgenerator.cbSelectedMemoryDomain.Items; object domainFound = null; for (int i = 0; i < cbitems.Count; i++) { var item = cbitems[i]; if (item.ToString() == domain) { domainFound = item; vmdgenerator.cbSelectedMemoryDomain.SelectedIndex = i; break; } } if (domainFound == null) { throw new Exception($"Domain {domain} could not be selected in the VMD Generator. Aborting procedure."); //return; } vmdgenerator.tbCustomAddresses.Text = text; string value = ""; if (RTCV.UI.UI_Extensions.GetInputBox("VMD Generation", "Enter the new VMD name:", ref value) == DialogResult.OK) { if (!string.IsNullOrWhiteSpace(value)) { vmdgenerator.tbVmdName.Text = value.Trim(); } vmdgenerator.btnGenerateVMD_Click(null, null); } }); e.setReturnValue(true); break; case REMOTE_EVENT_DOMAINSUPDATED: SyncObjectSingleton.FormExecute(() => { S.GET <RTC_MemoryDomains_Form>().RefreshDomains(); S.GET <RTC_MemoryDomains_Form>().SetMemoryDomainsAllButSelectedDomains(RTCV.NetCore.AllSpec.VanguardSpec[VSPEC.MEMORYDOMAINS_BLACKLISTEDDOMAINS] as string[] ?? new string[] { }); }); break; case REMOTE_GETBLASTGENERATOR_LAYER: SyncObjectSingleton.FormExecute(() => { e.setReturnValue(S.GET <RTC_BlastGenerator_Form>().GenerateBlastLayers(true, true, false)); }); break; case ERROR_DISABLE_AUTOCORRUPT: SyncObjectSingleton.FormExecute(() => { S.GET <UI_CoreForm>().AutoCorrupt = false; }); break; case REMOTE_RENDER_DISPLAY: SyncObjectSingleton.FormExecute(() => { S.GET <RTC_GlitchHarvesterBlast_Form>().refreshRenderOutputButton(); }); break; case REMOTE_BACKUPKEY_STASH: if (advancedMessage?.objectValue is StashKey sk) { StockpileManager_UISide.BackupedState = sk; GameProtection.AddBackupState(sk); SyncObjectSingleton.FormExecute(() => { S.GET <UI_CoreForm>().btnGpJumpBack.Visible = true; S.GET <UI_CoreForm>().btnGpJumpNow.Visible = true; }); } break; case KILLSWITCH_PULSE: AutoKillSwitch.Pulse(); break; case RESET_GAME_PROTECTION_IF_RUNNING: if (GameProtection.isRunning) { SyncObjectSingleton.FormExecute(() => { S.GET <UI_CoreForm>().cbUseGameProtection.Checked = false; S.GET <UI_CoreForm>().cbUseGameProtection.Checked = true; }); } break; case REMOTE_DISABLESAVESTATESUPPORT: SyncObjectSingleton.FormExecute(() => { S.GET <RTC_SavestateManager_Form>().DisableFeature(); S.GET <UI_CoreForm>().pnCrashProtection.Visible = false; }); break; case REMOTE_DISABLEGAMEPROTECTIONSUPPORT: SyncObjectSingleton.FormExecute(() => { S.GET <UI_CoreForm>().pnCrashProtection.Visible = false; }); break; case REMOTE_DISABLEREALTIMESUPPORT: SyncObjectSingleton.FormExecute(() => { Button btnManual = S.GET <UI_CoreForm>().btnManualBlast; if (AllSpec.VanguardSpec[VSPEC.REPLACE_MANUALBLAST_WITH_GHCORRUPT] != null) { btnManual.Text = " Corrupt"; } else { btnManual.Visible = false; } S.GET <UI_CoreForm>().btnAutoCorrupt.Enabled = false; S.GET <UI_CoreForm>().btnAutoCorrupt.Visible = false; S.GET <RTC_GeneralParameters_Form>().multiTB_ErrorDelay.Enabled = false; S.GET <RTC_GlitchHarvesterBlast_Form>().btnSendRaw.Enabled = false; S.GET <RTC_GlitchHarvesterBlast_Form>().btnBlastToggle.Enabled = false; S.GET <RTC_CorruptionEngine_Form>().cbSelectedEngine.Items.Remove("Hellgenie Engine"); S.GET <RTC_CorruptionEngine_Form>().cbSelectedEngine.Items.Remove("Distortion Engine"); S.GET <RTC_CorruptionEngine_Form>().cbSelectedEngine.Items.Remove("Pipe Engine"); S.GET <RTC_CorruptionEngine_Form>().cbSelectedEngine.Items.Remove("Freeze Engine"); }); break; case REMOTE_DISABLEKILLSWITCHSUPPORT: SyncObjectSingleton.FormExecute(() => { S.GET <UI_CoreForm>().pnAutoKillSwitch.Visible = false; S.GET <UI_CoreForm>().cbUseAutoKillSwitch.Checked = false; }); break; } } catch (Exception ex) { if (CloudDebug.ShowErrorDialog(ex) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } return; } }
private void loadSSK(bool import, string fileName) { decimal currentProgress = 0; decimal percentPerFile = 0; SaveStateKeys ssk; if (!import) { RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Committing used states to session", currentProgress += 5)); //Commit any used states to the SESSION folder commitUsedStatesToSession(); savestateBindingSource.Clear(); } var extractFolder = import ? "TEMP" : "SSK"; //Extract the ssk RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Extracting the SSK", currentProgress += 50)); if (!Stockpile.Extract(fileName, Path.Combine("WORKING", extractFolder), "keys.json")) { return; } //Read in the ssk try { RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Reading keys.json", currentProgress += 5)); using (FileStream fs = File.Open(Path.Combine(RtcCore.workingDir, extractFolder, "keys.json"), FileMode.OpenOrCreate)) { ssk = CorruptCore.JsonHelper.Deserialize <SaveStateKeys>(fs); fs.Close(); } } catch (Exception ex) { string additionalInfo = "The Savestate Keys file could not be loaded\n\n"; var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace); if (CloudDebug.ShowErrorDialog(ex2, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } return; } if (ssk == null) { MessageBox.Show("The Savestate Keys file was empty (null).\n"); return; } var s = (string)RTCV.NetCore.AllSpec.VanguardSpec?[VSPEC.NAME] ?? "ERROR"; if (!String.IsNullOrEmpty(ssk.VanguardImplementation) && !ssk.VanguardImplementation.Equals(s, StringComparison.OrdinalIgnoreCase) && ssk.VanguardImplementation != "ERROR") { MessageBox.Show($"The ssk you loaded is for a different Vanguard implementation.\nThe ssk reported {ssk.VanguardImplementation} but you're connected to {s}.\nThis is a fatal error. Aborting load."); return; } if (import) { var allCopied = new List <string>(); var files = Directory.GetFiles(Path.Combine(RtcCore.workingDir, "TEMP")); percentPerFile = 20m / (files.Length + 1); //Copy from temp to sks foreach (string file in files) { if (!file.Contains(".ssk")) { RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs($"Copying {Path.GetFileName(file)} to SSK", currentProgress += percentPerFile)); try { string dest = Path.Combine(RtcCore.workingDir, "SSK", Path.GetFileName(file)); //Only copy if a version doesn't exist //This prevents copying over keys if (!File.Exists(dest)) { File.Copy(file, dest); // copy roms/stockpile/whatever to sks folder allCopied.Add(dest); } } catch (Exception ex) { MessageBox.Show("Unable to copy a file from temp to ssk. The culprit is " + file + ".\nCancelling operation.\n " + ex.ToString()); //Attempt to cleanup foreach (var f in allCopied) { File.Delete(f); } return; } } } RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs($"Emptying TEMP", currentProgress += 5)); Stockpile.EmptyFolder(Path.Combine("WORKING", "TEMP")); } percentPerFile = 20m / (ssk.StashKeys.Count + 1); for (var i = 0; i < ssk.StashKeys.Count; i++) { var key = ssk.StashKeys[i]; if (key == null) { continue; } RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs($"Fixing up {key.Alias}", currentProgress += percentPerFile)); //We have to set this first as we then change the other stuff key.StateLocation = StashKeySavestateLocation.SSK; string statefilename = key.GameName + "." + key.ParentKey + ".timejump.State"; // get savestate name string newStatePath = Path.Combine(CorruptCore.RtcCore.workingDir, key.StateLocation.ToString(), statefilename); key.StateFilename = newStatePath; key.StateShortFilename = Path.GetFileName(newStatePath); SyncObjectSingleton.FormExecute(() => savestateBindingSource.Add(new SaveStateKey(key, ssk.Text[i]))); } RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs($"Done", 100)); }
private void saveSSK(string path) { decimal currentProgress = 0; try { SaveStateKeys ssk = new SaveStateKeys(); foreach (SaveStateKey x in savestateBindingSource.List) { ssk.StashKeys.Add(x.StashKey); ssk.Text.Add(x.Text); } RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Prepping TEMP", currentProgress += 5)); //clean temp folder Stockpile.EmptyFolder(Path.Combine("WORKING", "TEMP")); //Commit any states in use RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Committing used states", currentProgress += 5)); commitUsedStatesToSession(); var percentPerFile = 30m / (ssk.StashKeys.Count + 1); foreach (var key in ssk.StashKeys) { RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs($"Copying {key.GameName + "." + key.ParentKey + ".timejump.State"} to TEMP", currentProgress += percentPerFile)); string stateFilename = key.GameName + "." + key.ParentKey + ".timejump.State"; // get savestate name string statePath = Path.Combine(CorruptCore.RtcCore.workingDir, key.StateLocation.ToString(), stateFilename); string tempPath = Path.Combine(CorruptCore.RtcCore.workingDir, "TEMP", stateFilename); if (File.Exists(statePath)) { File.Copy(statePath, tempPath, true); // copy savestates to temp folder } else { MessageBox.Show("Couldn't find savestate " + statePath + "!\n\n. This is savestate index " + ssk.StashKeys.IndexOf(key) + 1 + ".\nAborting save"); Stockpile.EmptyFolder(Path.Combine("WORKING", "TEMP")); return; } } percentPerFile = 10m / (ssk.StashKeys.Count + 1); //Use two separate loops here in case the first one aborts. We don't want to update the StateLocation unless we know we're good foreach (var key in ssk.StashKeys) { RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs($"Updating {key} location", currentProgress += percentPerFile)); if (key == null) { continue; } key.StateLocation = StashKeySavestateLocation.SSK; } //Create keys.json RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Creating keys.json", currentProgress += 10)); using (FileStream fs = File.Open(Path.Combine(CorruptCore.RtcCore.workingDir, "TEMP", "keys.json"), FileMode.OpenOrCreate)) { JsonHelper.Serialize(ssk, fs, Formatting.Indented); fs.Close(); } string tempFilename = path + ".temp"; //If there's already a temp file from a previous failed save, delete it try { if (File.Exists(tempFilename)) { File.Delete(tempFilename); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } string tempFolderPath = Path.Combine(CorruptCore.RtcCore.workingDir, "TEMP"); RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Creating SSK", currentProgress += 20)); System.IO.Compression.ZipFile.CreateFromDirectory(tempFolderPath, tempFilename, System.IO.Compression.CompressionLevel.Fastest, false); if (File.Exists(path)) { File.Delete(path); } RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Moving SSK to destination", currentProgress += 5)); File.Move(tempFilename, path); //Move all the files from temp into SSK RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs("Emptying SSK", currentProgress += 5)); Stockpile.EmptyFolder(Path.Combine("WORKING", "SSK")); var files = Directory.GetFiles(tempFolderPath); percentPerFile = 15m / files.Length; foreach (string file in files) { RtcCore.OnProgressBarUpdate(this, new ProgressBarEventArgs($"Moving {Path.GetFileName(file)} to SSK", currentProgress += percentPerFile)); File.Move(file, Path.Combine(CorruptCore.RtcCore.workingDir, "SSK", Path.GetFileName(file))); } } catch (Exception ex) { string additionalInfo = "The Savestate Keys file could not be saved\n\n"; var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace); if (CloudDebug.ShowErrorDialog(ex2, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } return; } }