private void btnSaveVmd_Click(object sender, EventArgs e) { if (lbLoadedVmdList.SelectedIndex == -1) { return; } string VmdName = lbLoadedVmdList.SelectedItem.ToString(); VirtualMemoryDomain VMD = (VirtualMemoryDomain)RTC_MemoryDomains.VmdPool[VmdName]; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.DefaultExt = "xml"; saveFileDialog1.Title = "Save VMD to File"; saveFileDialog1.Filter = "XML VMD file|*.xml"; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string Filename = saveFileDialog1.FileName; FileStream FS; XmlSerializer xs = new XmlSerializer(typeof(VmdPrototype)); //creater stockpile.xml to temp folder from stockpile object FS = File.Open(Filename, FileMode.OpenOrCreate); xs.Serialize(FS, VMD.proto); FS.Close(); } else { return; } }
public static void RenameVMD(string vmdName) { if (!RTC_MemoryDomains.VmdPool.ContainsKey(vmdName)) { return; } RTC_Core.StopSound(); string Name = ""; string value = ""; if (RTC_Extensions.getInputBox("BlastLayer to VMD", "Enter the new VMD name:", ref value) == DialogResult.OK) { Name = value.Trim(); RTC_Core.StartSound(); } else { RTC_Core.StartSound(); return; } if (string.IsNullOrWhiteSpace(Name)) { Name = RTC_Core.GetRandomKey(); } VirtualMemoryDomain VMD = (VirtualMemoryDomain)RTC_MemoryDomains.VmdPool[vmdName]; RemoveVMD(VMD); VMD.name = Name; VMD.proto.VmdName = Name; AddVMD(VMD); }
public VirtualMemoryDomain Generate() { VirtualMemoryDomain VMD = new VirtualMemoryDomain(); VMD.proto = this; VMD.name = VmdName; VMD.BigEndian = BigEndian; VMD.WordSize = WordSize; if (SuppliedBlastLayer != null) { VMD.AddFromBlastLayer(SuppliedBlastLayer); return(VMD); } int addressCount = 0; foreach (int[] range in addRanges) { int start = range[0]; int end = range[1]; for (int i = start; i < end; i++) { if (!isAddressInRanges(i, removeSingles, removeRanges)) { if (PointerSpacer == 1 || addressCount % PointerSpacer == 0) { //VMD.MemoryPointers.Add(new Tuple<string, long>(Domain, i)); VMD.PointerDomains.Add(GenDomain); VMD.PointerAddresses.Add(i); } } addressCount++; } } foreach (int single in addSingles) { //VMD.MemoryPointers.Add(new Tuple<string, long>(Domain, single)); VMD.PointerDomains.Add(GenDomain); VMD.PointerAddresses.Add(single); addressCount++; } return(VMD); }
public static VirtualMemoryDomain FromData(byte[] data) { using (MemoryStream input = new MemoryStream(data)) using (MemoryStream output = new MemoryStream()) { using (GZipStream zip = new GZipStream(input, CompressionMode.Decompress)) { zip.CopyTo(output); } var binaryFormatter = new BinaryFormatter(); using (MemoryStream serialized = new MemoryStream(output.ToArray())) { VirtualMemoryDomain VMD = (VirtualMemoryDomain)binaryFormatter.Deserialize(serialized); return(VMD); } } }
public byte[] ToData() { VirtualMemoryDomain VMD = this; using (MemoryStream serialized = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(serialized, VMD); using (MemoryStream input = new MemoryStream(serialized.ToArray())) using (MemoryStream output = new MemoryStream()) { using (GZipStream zip = new GZipStream(output, CompressionMode.Compress)) { input.CopyTo(zip); } return(output.ToArray()); } } }
public static void AddVMD(VirtualMemoryDomain VMD) { RTC_MemoryDomains.VmdPool[VMD.ToString()] = VMD; if (RTC_Core.isStandalone) { var token = RTC_NetCore.HugeOperationStart(); RTC_Core.SendCommandToBizhawk(new RTC_Command(CommandType.REMOTE_DOMAIN_VMD_ADD) { objectValue = VMD.proto }, true); RTC_NetCore.HugeOperationEnd(token); } if (!RTC_Hooks.isRemoteRTC) { RTC_Core.ecForm.RefreshDomainsAndKeepSelected(); } }
private bool GenerateVMD() { if (string.IsNullOrWhiteSpace(cbSelectedMemoryDomain.SelectedItem?.ToString()) || !RTC_MemoryDomains.MemoryInterfaces.ContainsKey(cbSelectedMemoryDomain.SelectedItem.ToString())) { cbSelectedMemoryDomain.Items.Clear(); return(false); } if (!string.IsNullOrWhiteSpace(tbVmdName.Text) && RTC_MemoryDomains.VmdPool.ContainsKey($"[V]{tbVmdName.Text}")) { MessageBox.Show("There is already a VMD with this name in the VMD Pool"); return(false); } MemoryInterface mi = RTC_MemoryDomains.MemoryInterfaces[cbSelectedMemoryDomain.SelectedItem.ToString()]; VirtualMemoryDomain VMD = new VirtualMemoryDomain(); VmdPrototype proto = new VmdPrototype(); proto.GenDomain = cbSelectedMemoryDomain.SelectedItem.ToString(); if (string.IsNullOrWhiteSpace(tbVmdName.Text)) { proto.VmdName = RTC_Core.GetRandomKey(); } else { proto.VmdName = tbVmdName.Text; } proto.BigEndian = mi.BigEndian; proto.WordSize = mi.WordSize; if (cbUsePointerSpacer.Checked && nmPointerSpacer.Value > 1) { proto.PointerSpacer = Convert.ToInt32(nmPointerSpacer.Value); } else { proto.PointerSpacer = 1; } foreach (string line in tbCustomAddresses.Lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } string trimmedLine = line.Trim(); bool remove = false; if (trimmedLine[0] == '-') { remove = true; trimmedLine = trimmedLine.Substring(1); } string[] lineParts = trimmedLine.Split('-'); if (lineParts.Length > 1) { int start = SafeStringToInt(lineParts[0]); int end = SafeStringToInt(lineParts[1]); if (end >= currentDomainSize) { end = Convert.ToInt32(currentDomainSize - 1); } if (remove) { proto.removeRanges.Add(new int[] { start, end }); } else { proto.addRanges.Add(new int[] { start, end }); } } else { int address = SafeStringToInt(lineParts[0]); if (address < currentDomainSize) { if (remove) { proto.removeSingles.Add(address); } else { proto.addSingles.Add(address); } } } } if (proto.addRanges.Count == 0 && proto.addSingles.Count == 0) { //No add range was specified, use entire domain proto.addRanges.Add(new int[] { 0, (currentDomainSize > int.MaxValue ? int.MaxValue : Convert.ToInt32(currentDomainSize)) }); } VMD = proto.Generate(); if (VMD.PointerAddresses.Count == 0) { MessageBox.Show("The resulting VMD had no pointers so the operation got cancelled."); return(false); } RTC_MemoryDomains.AddVMD(VMD); tbVmdName.Text = ""; cbSelectedMemoryDomain.SelectedIndex = -1; cbSelectedMemoryDomain.Items.Clear(); currentDomainSize = 0; nmPointerSpacer.Value = 2; cbUsePointerSpacer.Checked = false; tbCustomAddresses.Text = ""; lbDomainSizeValue.Text = "######"; lbEndianTypeValue.Text = "######"; lbWordSizeValue.Text = "######"; //send to vmd pool menu RTC_Core.vmdPoolForm.RefreshVMDs(); RTC_Core.ecForm.cbMemoryDomainTool.SelectedIndex = 1; GC.Collect(); GC.WaitForPendingFinalizers(); return(true); }
public static void RenameVMD(VirtualMemoryDomain VMD) => RenameVMD(VMD.ToString());