/// <summary> /// Get the instance of region graph, nodes in it are regions and edges /// are pathways linking the regions. /// </summary> public Graph <Region, string> GetRegiongraph() { Graph <Region, string> regionGraph = new Graph <Region, string>(); foreach (Region region in Regions) { regionGraph.AddNode(region); } foreach (Edge edge in Edges) { Region sourceRegion = Regions.First(region => region.Waypoints.Any(waypoint => waypoint.ID.Equals(edge.SourceWaypointUUID))); Region targetRegion = Regions.First(region => region.Waypoints.Any(waypoint => waypoint.ID.Equals(edge.TargetWaypointUUID))); uint sourceKey = regionGraph .Where(region => region.Item.Waypoints .Equals(sourceRegion.Waypoints)) .Select(c => c.Key).First(); uint targetKey = regionGraph .Where(region => region.Item.Waypoints .Equals(targetRegion.Waypoints)) .Select(c => c.Key).First(); regionGraph.Connect(sourceKey, targetKey, (int)edge.Distance, string.Empty); } return(regionGraph); }
public virtual void Validate() { if (!Regions.Any() || string.IsNullOrWhiteSpace(Regions.First())) { throw new ArgumentNullException("config.Regions", "Cannot have a blank entry for config.Regions"); } }
public MainViewModel() { ConnectCommand = new RelayCommand(() => Connect()); OnViewLoaded = new RelayCommand(() => AfterViewLoaded()); Regions = Constants.Server.RegionNames.Values.ToList(); SelectedRegionName = Regions.First(); App.Client.StateChanged += _client_StateChanged; App.Client.Disconnected += (o, p) => this.Cleanup(); LoadSettings(); }
public virtual void Validate() { if (!Regions.Any() || string.IsNullOrWhiteSpace(Regions.First())) { throw new ArgumentNullException("config.Regions", "Cannot have a blank entry for config.Regions"); } var duplicateRegion = Regions.GroupBy(x => x).FirstOrDefault(y => y.Count() > 1); if (duplicateRegion != null) { throw new ArgumentException(string.Format("Region {0} was added multiple times", duplicateRegion.Key)); } }
private bool updateRegionName(string pNew, string pOld) { if (regionAlreadyExists(pNew)) { return(false); } updateExistingRoomRegions(pNew, pOld); Regions.First(p => p.RegionName == m_RegionListing.Items[itemSelected].ToString()).RegionName = pNew; m_RegionListing.Items[itemSelected] = pNew; return(true); }
public void OnSelectRegion(int rid) { Region region = Regions.First(r => r.RID == rid); if (CurrentMode.GetType() == typeof(SelectOrigin)) { OnOrigin(region); } else if (CurrentMode.GetType() == typeof(SelectDestination)) { OnDestination(region); } else if (CurrentMode.GetType() == typeof(SelectVillage)) { OnVillage(region); } }
/// <summary> /// Called after all the scenes have been added. Performs calculations that require /// knowledge of all the scenes. /// </summary> public void CalcSceneLocations() { if (Regions.Count == 0) { return; } // Find the bounding rectangle uint firstY = Regions.First().Key; uint lastY = Regions.Last().Key; uint?firstX = null; uint?lastX = null; foreach (SortedDictionary <uint, Scene> row in Regions.Values) { uint curFirstX = row.First().Key; uint curLastX = row.Last().Key; firstX = (firstX == null) ? curFirstX : (firstX < curFirstX) ? firstX : curFirstX; lastX = (lastX == null) ? curLastX : (lastX > curLastX) ? lastX : curLastX; } Rect = new Rectangle((int)firstX, (int)firstY, (int)(lastY - firstY + 1), (int)(lastX - firstX + 1)); // Calculate the subdirectory in which each region will be stored in the archive m_regionDirs.Clear(); ForEachScene(delegate(Scene scene) { // We add the region's coordinates to ensure uniqueness even if multiple regions have the same name string path = string.Format("{0}_{1}_{2}", scene.RegionInfo.RegionLocX - Rect.X + 1, scene.RegionInfo.RegionLocY - Rect.Y + 1, scene.RegionInfo.RegionName.Replace(' ', '_')); m_regionDirs[scene.RegionInfo.RegionID] = path; }); }
protected async Task InternalCreateIRD(string savePath, CancellationToken cancellation, string isoPath = null) { byte[] buffer = new byte[Utilities.SectorSize]; List <FileHash> fileList = new List <FileHash>(); try { // First, get the partition table of this iso using (Stream fs = Open()) { if (fs == null) { return; } PS3CDReader reader = new PS3CDReader(fs); List <DirectoryMemberInformation> files = reader.Members.Where(d => d.IsFile).Distinct().ToList(); StartOfDataSector = files.First().StartSector; EndOfDataSector = files.Last().StartSector + files.Last().TotalSectors; var updateFile = files.FirstOrDefault( d => d.Path.Equals("/PS3_UPDATE/PS3UPDAT.PUP", StringComparison.OrdinalIgnoreCase)); long updateOffset = updateFile != null ? updateFile.StartSector * Utilities.SectorSize : 0; fileList.AddRange(files.Select(d => new FileHash(d.StartSector, d.Length))); if (cancellation.IsCancellationRequested) { return; } IrdFile irdFile = IrdFile.New(); using (Stream s = reader.OpenFile("PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read)) { ParamSfo sfo = ParamSfo.Load(s); irdFile.AppVersion = sfo.GetStringValue("APP_VER"); irdFile.GameVersion = sfo.GetStringValue("VERSION"); irdFile.GameID = sfo.GetStringValue("TITLE_ID"); irdFile.GameName = sfo.GetStringValue("TITLE"); } Interaction.Instance.ReportMessage("Processing " + (string.IsNullOrEmpty(irdFile.GameName) ? irdFile.GameID : irdFile.GameName)); irdFile.UpdateVersion = Utilities.FindUpdateVersion(fs, updateOffset); using (FileStream isoStream = string.IsNullOrEmpty(isoPath) ? null : new FileStream(isoPath, FileMode.Create, FileAccess.Write)) { if (isoStream != null) { isoStream.SetLength(TotalSectors * Utilities.SectorSize); } using (IOStream ioStream = new IOStream(fs, isoStream)) { ioStream.Seek(0, SeekOrigin.Begin); // Read the header, until StartOfDataSector (in sectors) irdFile.Header = new MemoryStream(); for (int i = 0; i < StartOfDataSector; i++) { int bytesRead = ioStream.Read(buffer, 0, buffer.Length); irdFile.Header.Write(buffer, 0, bytesRead); Interaction.Instance.ReportProgress(i); if (cancellation.IsCancellationRequested) { return; } } irdFile.ExtractAuthData(); // Fix the regions for the actual interesting data Regions.First().Start = (uint)StartOfDataSector; Regions.First().Length -= (uint)StartOfDataSector; Regions.Last().Length = (uint)EndOfDataSector - Regions.Last().Start; // Now, we should calculate the md5 sums of all regions Interaction.Instance.ReportMessage("Calculating hashes for " + Regions.Length + " regions."); for (int i = 0; i < Regions.Length; i++) { // Calculate the hash Interaction.Instance.ReportMessage( "Calculate hash for region " + i + " (" + Regions[i].Start.ToString("X2") + "-" + Regions[i].End.ToString("X2") + ")"); ioStream.Seek(Regions[i].Start * Utilities.SectorSize, SeekOrigin.Begin); using (FileHashStream fhs = new FileHashStream(fileList, Regions[i].Start)) { await Regions[i].CopyRegion(cancellation, ioStream, fhs); if (cancellation.IsCancellationRequested) { return; } irdFile.RegionHashes.Add(Regions[i].SourceHash); Interaction.Instance.ReportMessage("Region " + i + " hash: " + Regions[i].SourceHash.AsString()); } } ioStream.Seek(EndOfDataSector * Utilities.SectorSize, SeekOrigin.Begin); irdFile.Footer = new MemoryStream(); for (long i = EndOfDataSector; i < TotalSectors; i++) { int bytesRead = ioStream.Read(buffer, 0, buffer.Length); irdFile.Footer.Write(buffer, 0, bytesRead); Interaction.Instance.ReportProgress((int)(ioStream.Position / Utilities.SectorSize)); if (cancellation.IsCancellationRequested) { return; } } } } irdFile.FileHashes = fileList.ToDictionary(t => t.StartSector, t => t.Hash); irdFile.Save(savePath); Interaction.Instance.ReportMessage("All done, IRD file saved to " + savePath); } } catch (BadReadException e) { Interaction.Instance.ReportMessage(e.Message, ReportType.Fail); } catch (AuthenticationException e) { Interaction.Instance.ReportMessage(e.Message, ReportType.Fail); } }
public Region Region(int RegionId) { return(Regions.First(r => r.ID == RegionId)); }
public Region CurrentRegion(int tick) => Regions.First((r) => r.Tick <= tick && tick < r.Tick + r.Length);