forked from akanyan/mu3-mods
feat!: rename and reorganize
This commit is contained in:
75
Extras/SortByInternalDifficulty/MU3.User/patch_UserDetail.cs
Normal file
75
Extras/SortByInternalDifficulty/MU3.User/patch_UserDetail.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using MU3.Client;
|
||||
using MU3.DB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MU3.User;
|
||||
|
||||
class patch_UserDetail: UserDetail {
|
||||
public extern void orig_copyTo(UserData userDetail);
|
||||
public new void copyTo(UserData userDetail) {
|
||||
orig_copyTo(userDetail);
|
||||
|
||||
// Attempting to use a profile with InternalLevel sorting enabled
|
||||
// causes unpatched clients to crash thanks to enormous incompetence
|
||||
// of Sxga's interns.
|
||||
// See:
|
||||
// * MusicSelectViewDataList._sort1 set
|
||||
// * UserDetail.copyFrom()
|
||||
if(userDetail.tabSetting == (int)patch_MusicSort1ID.InternalLevel) {
|
||||
userDetail.tabSetting = (int)patch_MusicSort1ID.Level;
|
||||
stashTabSelection(userDetail.userName, true);
|
||||
} else {
|
||||
stashTabSelection(userDetail.userName, false);
|
||||
}
|
||||
}
|
||||
|
||||
public extern void orig_copyFrom(UserData userDetail);
|
||||
public new void copyFrom(UserData userDetail) {
|
||||
orig_copyFrom(userDetail);
|
||||
|
||||
if(userDetail.tabSetting == (int)patch_MusicSort1ID.Level && isStashedTabSelection(userDetail.userName)) {
|
||||
MusicSort1 = (MusicSort1ID)patch_MusicSort1ID.InternalLevel;
|
||||
}
|
||||
}
|
||||
|
||||
private void stashTabSelection(string user, bool value) {
|
||||
var path = getStashPath();
|
||||
List<string> entries;
|
||||
try {
|
||||
entries = File.ReadAllText(path).Split('\n').ToList();
|
||||
entries = entries.Where((val) => val.Length > 0 && val != user).ToList();
|
||||
} catch(Exception) {
|
||||
entries = [];
|
||||
}
|
||||
|
||||
if(value) {
|
||||
entries.Add(user);
|
||||
}
|
||||
|
||||
try {
|
||||
File.WriteAllText(path, entries.Aggregate("", (acc, s) => acc + s + "\n").Trim());
|
||||
} catch(Exception e) {
|
||||
UnityEngine.Debug.Log("Unable to write tab selection: " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool isStashedTabSelection(string user) {
|
||||
try {
|
||||
var entries = File.ReadAllText(getStashPath()).Split('\n').ToList();
|
||||
return entries.Contains(user);
|
||||
} catch(Exception) {
|
||||
// Whatever, this is not mission critical
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private string getStashPath() {
|
||||
using IniFile iniFile = new("mu3.ini");
|
||||
var dir = iniFile.getValue("Extra", "CacheDir", ".");
|
||||
Directory.CreateDirectory(dir);
|
||||
return Path.Combine(dir, "data_tab_cache.txt");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user