forked from akanyan/mu3-mods
71 lines
3.1 KiB
C#
71 lines
3.1 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.IO;
|
||
|
using System.Linq;
|
||
|
|
||
|
namespace MU3.Data;
|
||
|
|
||
|
public class patch_DataManager: DataManager {
|
||
|
private Dictionary<int, FumenAnalysisData> _fumenAnalysisData;
|
||
|
|
||
|
private void InitCache() {
|
||
|
if(File.Exists("data_fumen_analysis_cache.bin")) {
|
||
|
System.Console.WriteLine("Loading FumenAnalysisData cache...");
|
||
|
_fumenAnalysisData = new Dictionary<int, FumenAnalysisData>();
|
||
|
using(FileStream input = File.OpenRead("data_fumen_analysis_cache.bin")) {
|
||
|
using BinaryReader binaryReader = new BinaryReader(input);
|
||
|
while(binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) {
|
||
|
int key = binaryReader.ReadInt32();
|
||
|
bool isExist = binaryReader.ReadBoolean();
|
||
|
int bpm = binaryReader.ReadInt32();
|
||
|
int platinumScoreMax = binaryReader.ReadInt32();
|
||
|
string notesDesignerName = binaryReader.ReadString();
|
||
|
_fumenAnalysisData.Add(key, new FumenAnalysisData {
|
||
|
isExist = isExist,
|
||
|
bpm = bpm,
|
||
|
platinumScoreMax = platinumScoreMax,
|
||
|
notesDesignerName = notesDesignerName
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
System.Console.WriteLine("Success");
|
||
|
} else {
|
||
|
_fumenAnalysisData = new Dictionary<int, FumenAnalysisData>();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void SaveCache() {
|
||
|
System.Console.WriteLine($"Saving FumenAnalysisData cache...{Enumerable.First<KeyValuePair<int, FumenAnalysisData>>((IEnumerable<KeyValuePair<int, FumenAnalysisData>>)_fumenAnalysisData).Key},{Enumerable.First<KeyValuePair<int, FumenAnalysisData>>((IEnumerable<KeyValuePair<int, FumenAnalysisData>>)_fumenAnalysisData).Value.notesDesignerName}");
|
||
|
if(File.Exists("data_fumen_analysis_cache.bin")) {
|
||
|
File.Delete("data_fumen_analysis_cache.bin");
|
||
|
}
|
||
|
using(FileStream fileStream = File.OpenWrite("data_fumen_analysis_cache.bin")) {
|
||
|
using BinaryWriter binaryWriter = new BinaryWriter(fileStream);
|
||
|
foreach(KeyValuePair<int, FumenAnalysisData> fumenAnalysisDatum in _fumenAnalysisData) {
|
||
|
binaryWriter.Write(fumenAnalysisDatum.Key);
|
||
|
binaryWriter.Write(fumenAnalysisDatum.Value.isExist);
|
||
|
binaryWriter.Write(fumenAnalysisDatum.Value.bpm);
|
||
|
binaryWriter.Write(fumenAnalysisDatum.Value.platinumScoreMax);
|
||
|
binaryWriter.Write(fumenAnalysisDatum.Value.notesDesignerName);
|
||
|
}
|
||
|
fileStream.Flush();
|
||
|
}
|
||
|
System.Console.WriteLine("Success");
|
||
|
}
|
||
|
|
||
|
private extern void orig_makeFumenAnalysisDataList();
|
||
|
|
||
|
private void makeFumenAnalysisDataList() {
|
||
|
try {
|
||
|
if(DataStudioManager.needSave || !File.Exists("data_fumen_analysis_cache.bin")) {
|
||
|
orig_makeFumenAnalysisDataList();
|
||
|
SaveCache();
|
||
|
} else {
|
||
|
InitCache();
|
||
|
}
|
||
|
} catch(Exception value) {
|
||
|
System.Console.WriteLine(value);
|
||
|
}
|
||
|
}
|
||
|
}
|