feat: various enhancements

* AttractVideoPlayer,LoadBoost: allow setting a cache directory
* AttractVideoPlayer: color leds
* BetterGiveUp: prevent multiple restarts in a row
* use GetTriggerOn in general where applicable
This commit is contained in:
あかニャン 2024-07-23 01:45:36 +09:00
parent 8cbc7e8b86
commit 4ad595f6c3
10 changed files with 109 additions and 76 deletions

View File

@ -5,18 +5,22 @@ using System.IO;
namespace MU3.Operation;
class patch_OperationManager: OperationManager {
private static readonly string _fname = "data_advert_cache.txt";
private ReadOnlyCollection<MovieData> _movieDataList;
private int _movieIndex;
private string _fileName;
~patch_OperationManager() {
try {
File.WriteAllText(_fname, _movieIndex.ToString());
} catch(Exception) {}
File.WriteAllText(_fileName, MovieIndex.ToString());
} catch(Exception) { }
}
public int MovieIndex {
set {
_movieIndex = (value + _movieDataList.Count) % _movieDataList.Count;
if(_movieDataList.Count > 0) {
_movieIndex = (value + _movieDataList.Count) % _movieDataList.Count;
} else {
_movieIndex = 0;
}
}
get {
return _movieIndex;
@ -25,7 +29,7 @@ class patch_OperationManager: OperationManager {
public new MovieData movieData {
get {
if(_movieDataList.Count > 0) {
return _movieDataList[_movieIndex];
return _movieDataList[MovieIndex];
}
return null;
}
@ -35,8 +39,12 @@ class patch_OperationManager: OperationManager {
public new void initialize() {
orig_initialize();
using IniFile iniFile = new("mu3.ini");
_fileName = Path.Combine(iniFile.getValue("Extra", "CacheDir", "."), "data_advert_cache.txt");
try {
_movieIndex = Math.Max(0, int.Parse(File.ReadAllText(_fname)));
_movieIndex = Math.Max(0, int.Parse(File.ReadAllText(_fileName)));
} catch(Exception) {
_movieIndex = 0;
}

View File

@ -32,4 +32,22 @@ class patch_AdvManager: AdvManager {
initMovie();
}
public extern bool orig_initMovie();
public new bool initMovie() {
UIInput instance = Singleton<UIInput>.instance;
instance.setLedColor(UIInput.Key.L2, new Color(0f, 0.7f, 0f));
instance.setLedColor(UIInput.Key.L3, new Color(0f, 0.7f, 0f));
return orig_initMovie();
}
public extern void orig_exitMovie();
public new void exitMovie() {
orig_exitMovie();
UIInput instance = Singleton<UIInput>.instance;
instance.setLedColor(UIInput.Key.L2, Color.black);
instance.setLedColor(UIInput.Key.L3, Color.black);
}
}

View File

@ -13,6 +13,7 @@ class patch_PlayMusic: PlayMusic {
public static bool QuickSkip = false;
private GameEngine _gameEngine;
private SessionInfo _sessionInfo;
private bool _pressedYellow;
private bool _isRolling;
private float _totalRollingFrame;
private DateTime _rollingStartTime;
@ -30,11 +31,13 @@ class patch_PlayMusic: PlayMusic {
return min + (max - min) * Math.Pow(progress, 2.0);
}
private static bool IsHolding() {
return Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuLeft) ^ Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuRight);
private bool IsHolding() {
return Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuLeft)
^ (_pressedYellow && Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuRight));
}
private void StartRolling() {
_pressedYellow = false;
_isRolling = true;
_totalRollingFrame = ntMgr.getCurrentFrame();
_rollingStartTime = CustomDateTime.Now;
@ -60,6 +63,9 @@ class patch_PlayMusic: PlayMusic {
}
private void Execute_Play() {
if(Singleton<UIInput>.instance.getTriggerOn(UIInput.Key.MenuRight)) {
_pressedYellow = true;
}
if(_isRolling) {
TimeSpan timeSpan = CustomDateTime.Now - _rollingStartTime;
if(timeSpan <= ROLL_DURATION) {

View File

@ -7,61 +7,62 @@ namespace MU3.Data;
public class patch_DataManager: DataManager {
private Dictionary<int, FumenAnalysisData> _fumenAnalysisData;
private string _fileName;
private void InitCache() {
if(File.Exists("data_fumen_analysis_cache.bin")) {
System.Console.WriteLine("Loading FumenAnalysisData cache...");
private void initCache() {
if(File.Exists(_fileName)) {
System.Console.WriteLine("Loading chart analysis 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
});
}
using FileStream input = File.OpenRead(_fileName);
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");
private void saveCache() {
System.Console.WriteLine($"Saving chart analysis cache...{Enumerable.First(_fumenAnalysisData).Key},{Enumerable.First(_fumenAnalysisData).Value.notesDesignerName}");
if(File.Exists(_fileName)) {
File.Delete(_fileName);
}
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();
using FileStream fileStream = File.OpenWrite(_fileName);
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);
}
System.Console.WriteLine("Success");
fileStream.Flush();
}
private extern void orig_makeFumenAnalysisDataList();
private void makeFumenAnalysisDataList() {
using IniFile iniFile = new("mu3.ini");
_fileName = Path.Combine(iniFile.getValue("Extra", "CacheDir", "."), "data_fumen_analysis_cache.bin");
try {
if(DataStudioManager.needSave || !File.Exists("data_fumen_analysis_cache.bin")) {
if(patch_DataStudioManager.needSave || !File.Exists(_fileName)) {
orig_makeFumenAnalysisDataList();
SaveCache();
saveCache();
} else {
InitCache();
initCache();
}
} catch(Exception value) {
System.Console.WriteLine(value);

View File

@ -4,40 +4,46 @@ using System.Runtime.Serialization.Formatters.Binary;
namespace MU3.Data;
public class DataStudioManager {
public class patch_DataStudioManager: DataStudioManager {
public static bool needSave;
private static string _fileName;
private static Dictionary<string, object> _dataCache;
private static extern bool orig_Deserialize<T>(string filePath, out T dsr) where T : new();
private static void InitCache() {
if(File.Exists("data_cache.bin")) {
System.Console.WriteLine("Loading cache...");
using FileStream serializationStream = File.OpenRead("data_cache.bin");
private static void initCache() {
using IniFile iniFile = new("mu3.ini");
_fileName = Path.Combine(iniFile.getValue("Extra", "CacheDir", "."), "data_cache.bin");
if(File.Exists(_fileName)) {
System.Console.WriteLine("Loading data cache...");
using FileStream serializationStream = File.OpenRead(_fileName);
_dataCache = (Dictionary<string, object>)new BinaryFormatter().Deserialize(serializationStream);
return;
}
_dataCache = new Dictionary<string, object>();
_dataCache = new();
}
private static void SaveCache() {
if(File.Exists("data_cache.bin")) {
File.Delete("data_cache.bin");
private static void saveCache() {
if(_fileName == "") {
return;
}
using FileStream serializationStream = File.OpenWrite("data_cache.bin");
if(File.Exists(_fileName)) {
File.Delete(_fileName);
}
using FileStream serializationStream = File.OpenWrite(_fileName);
new BinaryFormatter().Serialize(serializationStream, _dataCache);
}
private static bool Deserialize<T>(string filePath, out T dsr) where T : new() {
if(_dataCache == null) {
InitCache();
initCache();
}
if(_dataCache.ContainsKey(filePath)) {
dsr = (T)_dataCache[filePath];
return true;
}
if(orig_Deserialize<T>(filePath, out dsr)) {
if(orig_Deserialize(filePath, out dsr)) {
needSave = true;
_dataCache.Add(filePath, dsr);
return true;
@ -47,11 +53,11 @@ public class DataStudioManager {
public extern bool orig_IsLoaded();
public bool IsLoaded() {
public new bool IsLoaded() {
if(orig_IsLoaded()) {
if(needSave) {
System.Console.WriteLine("Saving cache...");
SaveCache();
System.Console.WriteLine("Saving data cache...");
saveCache();
}
return true;
}

View File

@ -22,7 +22,7 @@ class patch_PlayMusic: PlayMusic {
}
public override bool updateState(float deltaTime = -1f) {
pauseTimer += deltaTime;
if(Singleton<UIInput>.instance.getStateOn(UIInput.Key.Service) && !Singleton<UIInput>.instance.getStateOn(UIInput.Key.Test)) {
if(Singleton<UIInput>.instance.getTriggerOn(UIInput.Key.Service) && !Singleton<UIInput>.instance.getStateOn(UIInput.Key.Test)) {
if((!Paused && pauseTimer >= PAUSE_CD) || (Paused && pauseTimer >= UNPAUSE_CD)) {
Paused = !Paused;
pgm.pause(Paused);

View File

@ -4,10 +4,4 @@
<Description>Platinum early/late</Description>
</PropertyGroup>
<Import Project="..\Mu3Mods.csproj" />
<ItemGroup>
<None Remove="MU3\patch_UIResultTechScore.experiment" />
</ItemGroup>
<ItemGroup>
<Compile Include="MU3\patch_UIResultTechScore.experiment" />
</ItemGroup>
</Project>

View File

@ -16,7 +16,7 @@ class patch_Scene_30_NoticeReward: Scene_30_NoticeReward {
SingletonMonoBehaviour<SystemUI>.instance.Panel.pushState(0, show: true);
}
private void Update() {
if(_mode.get() < (int)State.FadeOut && Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuLeft)) {
if(_mode.get() < (int)State.FadeOut && Singleton<UIInput>.instance.getTriggerOn(UIInput.Key.MenuLeft)) {
Skipped = true;
_mode.set(State.FadeOut);
} else {

View File

@ -11,7 +11,7 @@ class patch_PlayMusic: PlayMusic {
private void Execute_StartCutscene() {
orig_Execute_StartCutscene();
ForceSkipped = false;
if(Singleton<Sys.System>.instance.config.isQuickStart || Singleton<UIInput>.instance.getStateOn(UIInput.Key.MenuLeft)) {
if(Singleton<Sys.System>.instance.config.isQuickStart || Singleton<UIInput>.instance.getTriggerOn(UIInput.Key.MenuLeft)) {
ForceSkipped = true;
_gameEngine.skipStartCutscene();
setNextState(EState.Countdown);