public static void StartRender_NET() { if (Render.RenderType == Render.RENDERTYPE.NONE) { return; } string Key = "RENDER_" + (RtcCore.GetRandomKey()); switch (Render.RenderType) { case Render.RENDERTYPE.WAV: Hooks.BIZHAWK_STARTRECORDAV("wave", Path.Combine(RtcCore.RtcDir, "RENDEROUTPUT", Key + ".wav"), true); break; case Render.RENDERTYPE.AVI: try { Hooks.BIZHAWK_STARTRECORDAV("vfwavi", Path.Combine(RtcCore.RtcDir, "RENDEROUTPUT", Key + ".avi"), true); } catch (Exception ex) { throw new Exception("Rendering AVI Failed. \nIf you haven't already, you need to set a codec in bizhawk before starting an AVI Render. \nThe menu for config is at: File -> AVI/WAV -> Config.\n\n" + ex.ToString()); } break; case Render.RENDERTYPE.MPEG: Hooks.BIZHAWK_STARTRECORDAV("ffmpeg", Path.Combine(RtcCore.RtcDir, "RENDEROUTPUT", Key + ".mpg"), true); break; } }
public static BlastUnit GenerateUnit(string domain, long address, int precision, int alignment) { // Randomly selects a memory operation according to the selected algorithm if (domain == null) { return(null); } BlastTarget pipeStart = RtcCore.GetBlastTarget(); MemoryInterface mi = MemoryDomains.GetInterface(domain); MemoryInterface startmi = MemoryDomains.GetInterface(pipeStart.Domain); long safeAddress = address - (address % precision) + alignment; long safePipeStartAddress = pipeStart.Address - (pipeStart.Address % precision) + alignment; if (safeAddress > mi.Size - precision && mi.Size > precision) { safeAddress = mi.Size - (2 * precision) + alignment; //If we're out of range, hit the last aligned address } if (safePipeStartAddress > startmi.Size - precision && startmi.Size > precision) { safePipeStartAddress = startmi.Size - (2 * precision) + alignment; //If we're out of range, hit the last aligned address } return(new BlastUnit(StoreType.CONTINUOUS, StoreTime.PREEXECUTE, domain, safeAddress, pipeStart.Domain, safePipeStartAddress, precision, mi.BigEndian, 0, 0)); }
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(); SyncObjectSingleton.FormExecute(() => 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") is { Failed : true })
public static void STEP_CORRUPT(bool executeActions, bool performStep) { if (executeActions) { StepActions.Execute(); } if (performStep) { CPU_STEP_Count++; bool autoCorrupt = RtcCore.AutoCorrupt; long errorDelay = RtcCore.ErrorDelay; if (autoCorrupt && CPU_STEP_Count >= errorDelay) { CPU_STEP_Count = 0; BlastLayer bl = RtcCore.GenerateBlastLayer((string[])AllSpec.UISpec["SELECTEDDOMAINS"]); if (bl != null) { bl.Apply(false, false); } } } }
public static void CLOSE_GAME(bool loadDefault = false) { try { if (disableRTC) return; if (CLOSE_GAME_loop_flag) return; CLOSE_GAME_loop_flag = true; //RTC_Core.AutoCorrupt = false; StepActions.ClearStepBlastUnits(); MemoryDomains.Clear(); VanguardCore.OpenRomFilename = null; if (loadDefault) VanguardCore.LoadDefaultRom(); //RTC_RPC.SendToKillSwitch("UNFREEZE"); CLOSE_GAME_loop_flag = false; RtcCore.InvokeGameClosed(); VanguardCore.RTE_API.GAME_CLOSED(); } catch (Exception ex) { if (VanguardCore.ShowErrorDialog(ex) == DialogResult.Abort) throw new AbortEverythingException(); } }
public void WebRtcCtr_ReceivedMessage(string description, string message) { // Debug.Log("WebRtcMsgExchanger, " + description + ", " + message); // WebRtcCtr.ReceivedMessage(description, message); RtcCore.ReceivedMessage(description, message); }
public static void LOAD_GAME_DONE() { try { if (disableRTC) return; if (AllSpec.UISpec == null) { CLOSE_GAME(); GlobalWin.MainForm.CloseRom(); MessageBox.Show("It appears you haven't connected to StandaloneRTC. Please make sure that the RTC is running and not just Bizhawk.\nIf you have an antivirus, it might be blocking the RTC from launching.\n\nIf you keep getting this message, poke the RTC devs for help (Discord is in the launcher).", "RTC Not Connected"); return; } //Glitch Harvester warning for archives string uppercaseFilename = GlobalWin.MainForm.CurrentlyOpenRom.ToUpper(); if (uppercaseFilename.Contains(".ZIP") || uppercaseFilename.Contains(".7Z")) { MessageBox.Show($"The selected file {Path.GetFileName(uppercaseFilename.Split('|')[0])} is an archive.\nThe RTC does not support archived rom files. Please extract the file then try again."); CLOSE_GAME(true); return; } //Load Game vars into RTC_Core PathEntry pathEntry = Global.Config.PathEntries[Global.Game.System, "Savestates"] ?? Global.Config.PathEntries[Global.Game.System, "Base"]; //prepare memory domains in advance on bizhawk side bool domainsChanged = RefreshDomains(false); PartialSpec gameDone = new PartialSpec("VanguardSpec"); gameDone[VSPEC.SYSTEM] = BIZHAWK_GET_CURRENTLYLOADEDSYSTEMNAME().ToUpper(); gameDone[VSPEC.GAMENAME] = BIZHAWK_GET_FILESYSTEMGAMENAME(); gameDone[VSPEC.SYSTEMPREFIX] = BIZHAWK_GET_SAVESTATEPREFIX(); gameDone[VSPEC.SYSTEMCORE] = BIZHAWK_GET_SYSTEMCORENAME(Global.Game.System); gameDone[VSPEC.SYNCSETTINGS] = BIZHAWK_GETSET_SYNCSETTINGS; gameDone[VSPEC.OPENROMFILENAME] = GlobalWin.MainForm.CurrentlyOpenRom; gameDone[VSPEC.MEMORYDOMAINS_BLACKLISTEDDOMAINS] = VanguardCore.GetBlacklistedDomains(BIZHAWK_GET_CURRENTLYLOADEDSYSTEMNAME().ToUpper()); gameDone[VSPEC.MEMORYDOMAINS_INTERFACES] = GetInterfaces(); gameDone[VSPEC.CORE_DISKBASED] = isCurrentCoreDiskBased(); AllSpec.VanguardSpec.Update(gameDone); //This is local. If the domains changed it propgates over netcore LocalNetCoreRouter.Route(Endpoints.CorruptCore, Remote.EventDomainsUpdated, domainsChanged, true); if (VanguardCore.GameName != lastGameName) { LocalNetCoreRouter.Route(Endpoints.UI, Basic.ResetGameProtectionIfRunning, true); } lastGameName = VanguardCore.GameName; RtcCore.InvokeLoadGameDone(); VanguardCore.RTE_API.LOAD_GAME(); } catch (Exception ex) { if (VanguardCore.ShowErrorDialog(ex) == DialogResult.Abort) throw new AbortEverythingException(); } }
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; } }