/// <summary> /// Replaces hit objects and timing points with the values in the editor reader /// </summary> /// <param name="beatmap">Beatmap to replace values in</param> /// <param name="reader">Reader that contains the values from memory</param> /// <returns>A list of selected hit objects which originate from the beatmap.</returns> public static List <HitObject> UpdateBeatmap(Beatmap beatmap, EditorReader reader) { beatmap.SetBookmarks(reader.bookmarks.Select <int, double>(o => o).ToList()); beatmap.BeatmapTiming.TimingPoints = reader.controlPoints.Select(o => (TimingPoint)o).ToList(); List <HitObject> selected = new List <HitObject>(); beatmap.HitObjects = reader.hitObjects.Select(o => { var nho = (HitObject)o; if (o.IsSelected) { selected.Add(nho); } return(nho); }).ToList(); beatmap.General["PreviewTime"] = new TValue(reader.PreviewTime.ToString(CultureInfo.InvariantCulture)); beatmap.Difficulty["SliderMultiplier"] = new TValue(reader.SliderMultiplier.ToString(CultureInfo.InvariantCulture)); beatmap.Difficulty["SliderTickRate"] = new TValue(reader.SliderTickRate.ToString(CultureInfo.InvariantCulture)); // Update all the other stuff based on these values beatmap.BeatmapTiming.SliderMultiplier = reader.SliderMultiplier; // Sort the stuff beatmap.HitObjects = beatmap.HitObjects.OrderBy(o => o.Time).ToList(); beatmap.BeatmapTiming.Sort(); beatmap.CalculateHitObjectComboStuff(); beatmap.CalculateSliderEndTimes(); beatmap.GiveObjectsGreenlines(); return(selected); }
/// <summary> /// Gets the path to the beatmap currently open in the <see cref="EditorReader"/> instance. /// </summary> /// <param name="fullReader">Reader object that has already fetched all</param> /// <returns></returns> public static string GetCurrentBeatmap(EditorReader fullReader) { string songs = SettingsManager.GetSongsPath(); string folder = fullReader.ContainingFolder; string filename = fullReader.Filename; return(Path.Combine(songs, folder, filename)); }
public static BeatmapEditor TryGetNewestVersion(EditorReader reader, out List <HitObject> selected) { // Get the path from the beatmap in memory string songs = SettingsManager.GetSongsPath(); string folder = reader.ContainingFolder; string filename = reader.Filename; string memoryPath = Path.Combine(songs, folder, filename); var editor = new BeatmapEditor(memoryPath); // Update the beatmap with memory values selected = SettingsManager.Settings.UseEditorReader ? UpdateBeatmap(editor.Beatmap, reader) : new List <HitObject>(); return(editor); }
private void PeriodicBackupTimerOnTick(object sender, EventArgs e) { try { // Get the newest beatmap, save a temp version, get the hash and compare it to the previous hash, backup temp file var path = IOHelper.GetCurrentBeatmap(); if (string.IsNullOrEmpty(path)) { return; } // Don't make period backup if the editor is not open if (!EditorReaderStuff.IsEditorOpen()) { return; } EditorReader reader = null; try { reader = EditorReaderStuff.GetFullEditorReader(); } catch (Exception ex) { Console.WriteLine(ex.MessageStackTrace()); } var editor = EditorReaderStuff.GetNewestVersionOrNot(path, reader); // Save temp version var tempPath = Path.Combine(MainWindow.AppDataPath, "temp.osu"); Editor.SaveFile(tempPath, editor.Beatmap.GetLines()); // Get MD5 from temp file var currentMapHash = EditorReaderStuff.GetMD5FromPath(tempPath); // Comparing with previously made periodic backup if (currentMapHash == previousPeriodicBackupHash) { return; } // Saving backup of the map BackupManager.SaveMapBackup(tempPath, true, Path.GetFileName(path), "PB"); // PB stands for Periodic Backup previousPeriodicBackupHash = currentMapHash; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Tries to get the newest version if a valid reader is provided. Otherwise returns default save. /// Use this if you don't care about it failing. /// </summary> /// <param name="path"></param> /// <param name="fullReader"></param> /// <param name="selected"></param> /// <param name="exception">Any exception that may occur, null otherwise</param> /// <returns></returns> public static BeatmapEditor GetNewestVersionOrNot(string path, EditorReader fullReader, out List <HitObject> selected, out Exception exception) { exception = null; if (fullReader != null) { try { return(GetNewestVersion(path, fullReader, out selected)); } catch (Exception ex) { exception = ex; } } selected = new List <HitObject>(); return(new BeatmapEditor(path)); }
/// <summary> /// Returns an editor for the beatmap which is currently open in the editor. Returns null if there is no beatmap open in the editor. /// </summary> /// <param name="fullReader">Reader object that has already fetched all</param> /// <param name="selected">List of selected hit objects</param> /// <returns>An editor for the beatmap</returns> /// <exception cref="ArgumentNullException"></exception> public static BeatmapEditor GetBeatmapEditor(EditorReader fullReader, out List <HitObject> selected) { if (fullReader == null) { throw new ArgumentNullException(nameof(fullReader)); } // Get the path from the beatmap in memory string memoryPath = GetCurrentBeatmap(fullReader); // Update the beatmap with memory values var editor = new BeatmapEditor(memoryPath); selected = UpdateBeatmap(editor.Beatmap, fullReader); return(editor); }
/// <summary> /// Tries to get the newest version if editorRead is true otherwise just makes a normal <see cref="BeatmapEditor"/> /// </summary> /// <param name="path"></param> /// <param name="fullReader"></param> /// <param name="readEditor"></param> /// <param name="selected"></param> /// <param name="editorRead">Indicates true if the editor memory was actually read</param> /// <returns></returns> public static BeatmapEditor GetBeatmapEditor(string path, EditorReader fullReader, bool readEditor, out List <HitObject> selected, out bool editorRead) { BeatmapEditor editor; if (readEditor) { editorRead = TryGetNewestVersion(path, out editor, out selected, fullReader); } else { editor = new BeatmapEditor(path); selected = new List <HitObject>(); editorRead = false; } return(editor); }
/// <summary> /// Checks for any insane values in the reader which indicate the editor has been incorrectly read /// </summary> /// <param name="reader">The fully fetched editor reader</param> /// <returns>A boolean whether the reader is valid</returns> private static bool ValidateFullReader(EditorReader reader) { bool result = !reader.hitObjects.Any(readerHitObject => readerHitObject.SegmentCount > 9000 || readerHitObject.Type == 0 || readerHitObject.SampleSet > 1000 || readerHitObject.SampleSetAdditions > 1000 || readerHitObject.SampleVolume > 1000) && reader.numControlPoints > 0 && reader.controlPoints != null && reader.hitObjects != null && reader.numControlPoints == reader.controlPoints.Count && reader.numObjects == reader.hitObjects.Count; if (!result) { // Save error log LogEditorReader(reader); //MessageBox.Show("A problem has been encountered with editor reader. An error log has been saved to editor_reader_error.txt", "Warning"); } return(result); }
private static void LogEditorReader(EditorReader reader) { var path = Path.Combine(MainWindow.AppDataPath, "editor_reader_error.txt"); if (!File.Exists(path)) { File.Create(path).Dispose(); } var lines = new List <string> { @"ContainingFolder: " + reader.ContainingFolder, @"Filename: " + reader.Filename, @"ApproachRate: " + reader.ApproachRate, @"CircleSize: " + reader.CircleSize, @"HPDrainRate: " + reader.HPDrainRate, @"OverallDifficulty: " + reader.OverallDifficulty, @"PreviewTime: " + reader.PreviewTime, @"SliderMultiplier: " + reader.SliderMultiplier, @"SliderTickRate: " + reader.SliderTickRate, @"StackLeniency: " + reader.StackLeniency, @"TimelineZoom: " + reader.TimelineZoom, @"numBookmarks: " + reader.numBookmarks, @"numClipboard: " + reader.numClipboard, @"numControlPoints: " + reader.numControlPoints, @"numObjects: " + reader.numObjects, @"numSelected: " + reader.numSelected, @"EditorTime: " + reader.EditorTime(), @"ProcessTitle: " + reader.ProcessTitle(), @"[HitObjects]", }; // Using .ToList() to prevent possibly modifying the list while being enumerated lines.AddRange(reader.hitObjects.ToList().Select(readerHitObject => readerHitObject.ToString())); lines.Add(@"[TimingPoints]"); lines.AddRange(reader.controlPoints.ToList().Select(readerControlPoint => readerControlPoint.ToString())); File.WriteAllLines(path, lines); }
/// <summary> /// Returns an editor for the beatmap of the specified path. If said beatmap is currently open in the editor it will update the Beatmap object with the latest values. /// </summary> /// <param name="path">Path to the beatmap</param> /// <param name="selected">List of selected hit objects</param> /// <param name="fullReader">Reader object that has already fetched all</param> /// <returns>The editor with the newest version</returns> /// <exception cref="ArgumentNullException"></exception> public static BeatmapEditor GetNewestVersion(string path, EditorReader fullReader, out List <HitObject> selected) { if (fullReader == null) { throw new ArgumentNullException(nameof(fullReader)); } BeatmapEditor editor = new BeatmapEditor(path); selected = new List <HitObject>(); // Get the path from the beatmap in memory string memoryPath = GetCurrentBeatmap(fullReader); // Check whether the beatmap in the editor is the same as the beatmap you want if (memoryPath == path) { // Update the beatmap with memory values selected = UpdateBeatmap(editor.Beatmap, fullReader); } return(editor); }
/// <summary> /// Gets the instance of EditorReader with FetchAll. Throws an exception if the editor is not open. /// </summary> /// <returns></returns> public static bool TryGetFullEditorReader(out EditorReader reader) { reader = editorReader; if (!SettingsManager.Settings.UseEditorReader) { return(false); } try { /*editorReader.FetchEditor(); * editorReader.SetHOM(); * editorReader.ReadHOM(); * editorReader.FetchBeatmap(); * editorReader.FetchControlPoints(); * editorReader.SetObjects(); * Console.WriteLine(editorReader.numObjects); * editorReader.ReadObjects(); * editorReader.FetchBookmarks();*/ editorReader.FetchAll(); var removed = FixFullReader(editorReader); if (removed > 1) { LogEditorReader(editorReader); return(false); } return(ValidateFullReader(editorReader)); } catch { return(false); } }
public static List <HitObject> GetSelectedObjects(BeatmapEditor editor, EditorReader reader) { try { string songs = SettingsManager.GetSongsPath(); string folder = reader.ContainingFolder; string filename = reader.Filename; string memoryPath = Path.Combine(songs, folder, filename); // Check whether the beatmap in the editor is the same as the beatmap you want if (memoryPath != editor.Path) { return(new List <HitObject>()); } reader.FetchSelected(); var convertedSelected = reader.selectedObjects.Select(o => (HitObject)o).ToList(); var selectedHitObjects = new List <HitObject>(convertedSelected.Count()); var comparer = new HitObjectComparer(); // Get all the hit objects that are selected according to the editor reader foreach (var ho in editor.Beatmap.HitObjects) { if (convertedSelected.Contains(ho, comparer)) { selectedHitObjects.Add(ho); } } return(selectedHitObjects); } catch (Exception ex) { MessageBox.Show($"Exception ({ex.Message}) while editor reading."); return(new List <HitObject>()); } }
/// <summary> /// Returns an editor for the beatmap which is currently open in the editor. Returns null if there is no beatmap open in the editor. /// </summary> /// <param name="selected">List of selected hit objects</param> /// <param name="fullReader">Reader object that has already fetched all</param> /// <returns>An editor for the beatmap</returns> public static BeatmapEditor GetBeatmapEditor(out List <HitObject> selected, EditorReader fullReader = null) { selected = new List <HitObject>(); BeatmapEditor editor = null; // Get a reader object that has everything fetched var reader = fullReader; if (reader == null) { if (!TryGetFullEditorReader(out reader)) { return(null); } } // Get the path from the beatmap in memory // This can only crash if the provided fullReader didn't fetch all values try { string songs = SettingsManager.GetSongsPath(); string folder = reader.ContainingFolder; string filename = reader.Filename; string memoryPath = Path.Combine(songs, folder, filename); // Update the beatmap with memory values editor = new BeatmapEditor(memoryPath); selected = UpdateBeatmap(editor.Beatmap, reader); } catch (Exception ex) { MessageBox.Show($"Exception ({ex.Message}) while editor reading."); } return(editor); }
/// <summary> /// Removes all invalid hit objects from the reader object /// </summary> /// <param name="reader">The fully fetched editor reader</param> private static int FixFullReader(EditorReader reader) { return(reader.hitObjects.RemoveAll(readerHitObject => readerHitObject.SegmentCount > 9000 || readerHitObject.Type == 0 || readerHitObject.SampleSet > 1000 || readerHitObject.SampleSetAdditions > 1000 || readerHitObject.SampleVolume > 1000)); }
/// <summary> /// Gets the hit objects out of an editor reader and converts them to better type /// </summary> /// <param name="reader"></param> /// <returns></returns> public static List <HitObject> GetHitObjects(EditorReader reader) { return(reader.hitObjects.Select(o => (HitObject)o).ToList()); }
public static BeatmapEditor GetBeatmapEditor(string path, EditorReader fullReader, bool readEditor) { return(GetBeatmapEditor(path, fullReader, readEditor, out _, out _)); }
public static BeatmapEditor GetBeatmapEditor(string path, EditorReader fullReader, bool readEditor, out List <HitObject> selected) { return(GetBeatmapEditor(path, fullReader, readEditor, out selected, out _)); }
/// <summary> /// Returns an editor for the beatmap of the specified path. If said beatmap is currently open in the editor it will update the Beatmap object with the latest values. /// </summary> /// <param name="path">Path to the beatmap</param> /// <param name="editor">The editor with the newest version</param> /// <param name="fullReader">Reader object that has already fetched all</param> /// <returns>Boolean indicating whether it actually got the newest version</returns> public static bool TryGetNewestVersion(string path, out BeatmapEditor editor, EditorReader fullReader = null) { return(TryGetNewestVersion(path, out editor, out _, fullReader)); }
/// <summary> /// Returns an editor for the beatmap of the specified path. If said beatmap is currently open in the editor it will update the Beatmap object with the latest values. /// </summary> /// <param name="path">Path to the beatmap</param> /// <param name="fullReader">Reader object that has already fetched all</param> /// <returns>The editor with the newest version</returns> /// <exception cref="ArgumentNullException"></exception> public static BeatmapEditor GetNewestVersion(string path, EditorReader fullReader) { return(GetNewestVersion(path, fullReader, out _)); }
/// <summary> /// Returns an editor for the beatmap of the specified path. If said beatmap is currently open in the editor it will update the Beatmap object with the latest values. /// </summary> /// <param name="path">Path to the beatmap</param> /// <param name="newestEditor">The editor with the newest version</param> /// <param name="selected">List of selected hit objects</param> /// <param name="fullReader">Reader object that has already fetched all</param> /// <returns>Boolean indicating whether it actually got the newest version</returns> public static bool TryGetNewestVersion(string path, out BeatmapEditor newestEditor, out List <HitObject> selected, EditorReader fullReader = null) { BeatmapEditor editor = new BeatmapEditor(path); newestEditor = editor; selected = new List <HitObject>(); // Check if Editor Reader is enabled if (!SettingsManager.Settings.UseEditorReader) { return(false); } // Get a reader object that has everything fetched var reader = fullReader; if (reader == null) { if (!TryGetFullEditorReader(out reader)) { return(false); } } // Get the path from the beatmap in memory // This can only crash if the provided fullReader didn't fetch all values try { string songs = SettingsManager.GetSongsPath(); string folder = reader.ContainingFolder; string filename = reader.Filename; string memoryPath = Path.Combine(songs, folder, filename); // Check whether the beatmap in the editor is the same as the beatmap you want if (memoryPath != path) { return(true); } // Update the beatmap with memory values selected = UpdateBeatmap(editor.Beatmap, reader); } catch (Exception ex) { MessageBox.Show($"Exception ({ex.Message}) while editor reading."); return(false); } return(true); }
public static void Main() { EditorReader reader = new EditorReader(); reader.FetchAll(); Console.WriteLine(reader.ContainingFolder); Console.WriteLine(reader.Filename); Console.WriteLine("oR" + reader.objectRadius); Console.WriteLine("sO" + reader.stackOffset); Console.WriteLine("HP" + reader.HPDrainRate); Console.WriteLine("CS" + reader.CircleSize); Console.WriteLine("AR" + reader.ApproachRate); Console.WriteLine("OD" + reader.OverallDifficulty); Console.WriteLine("SV" + reader.SliderMultiplier); Console.WriteLine("TR" + reader.SliderTickRate); Console.WriteLine("CT" + reader.ComposeTool()); Console.WriteLine("GS" + reader.GridSize()); Console.WriteLine("BD" + reader.BeatDivisor()); Console.WriteLine("TZ" + reader.TimelineZoom); Console.WriteLine("DS" + reader.DistanceSpacing()); Console.WriteLine("Current Time:"); Console.WriteLine(reader.EditorTime()); Console.WriteLine("Timing Points:"); for (int i = 0; i < reader.numControlPoints; i++) { Console.WriteLine(reader.controlPoints[i].ToString()); } Console.WriteLine("Bookmarks:"); for (int i = 0; i < reader.numBookmarks; i++) { Console.WriteLine(reader.bookmarks[i]); } Console.WriteLine("Hit Objects (selected):"); for (int i = 0; i < reader.numObjects; i++) { if (reader.hitObjects[i].IsSelected) { Console.WriteLine(reader.hitObjects[i].ToString()); } } while (true) { Console.WriteLine(reader.SnapPosition()); reader.FetchSelected(); Console.WriteLine("Selected Hit Objects:"); for (int i = 0; i < reader.numSelected; i++) { Console.WriteLine(reader.selectedObjects[i].ToString()); } reader.FetchClipboard(); Console.WriteLine("Copied Hit Objects:"); for (int i = 0; i < reader.numClipboard; i++) { Console.WriteLine(reader.clipboardObjects[i].ToString()); } Console.WriteLine("Hovered Hit Object:"); if (reader.FetchHovered()) { Console.WriteLine(reader.hoveredObject.ToString()); } Console.ReadLine(); } }