Skip to content

Commit

Permalink
添加 导出玩家存档功能
Browse files Browse the repository at this point in the history
  • Loading branch information
WYH2004-MC committed Oct 3, 2024
1 parent 067448f commit 6fba1e6
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
4 changes: 2 additions & 2 deletions BuildInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SinmaiAssist {
public static partial class BuildInfo {
public const string CommitHash = "c5f1801";
public const string BuildDate = "2024-09-30T21:29:26.2579972+08:00";
public const string CommitHash = "067448f";
public const string BuildDate = "2024-10-04T03:01:50.9338622+08:00";
}
}
6 changes: 6 additions & 0 deletions GUI/DebugPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using MAI2.Util;
using Manager;
using SinmaiAssist.Utils;
using UnityEngine;
Expand Down Expand Up @@ -33,6 +34,11 @@ public static void OnGUI()
if (GUILayout.Button("Save P1 Option To DefaultOption")) Common.ChangeDefaultOption.SaveOptionFile(0L);
if (GUILayout.Button("Save P2 Option To DefaultOption")) Common.ChangeDefaultOption.SaveOptionFile(1L);
if (GUILayout.Button("↑ ↓ ↑ ↓")) SoundManager.PlaySE(Mai2.Mai2Cue.Cue.SE_ENTRY_AIME_ERROR, 1);
if (GUILayout.Button("Export Backup Data"))
{
User.ExportBackupData(0);
User.ExportBackupData(1);
}
GUILayout.Label($"GUI Toggle", MiddleStyle);
if (GUILayout.Button("Toggle Show Info")) SinmaiAssist.config.ModSetting.ShowInfo = !SinmaiAssist.config.ModSetting.ShowInfo;
if (GUILayout.Button("Toggle Show FPS")) SinmaiAssist.config.Common.ShowFPS = !SinmaiAssist.config.Common.ShowFPS;
Expand Down
4 changes: 2 additions & 2 deletions GUI/MainGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private enum Toolbar
Debug
}

private const float PanelWidth = 320f;
private const float PanelWidth = 300f;
private const int ButtonsPerRow = 3;

private Rect _panelWindow;
Expand Down Expand Up @@ -58,7 +58,7 @@ private void MainPanel(int id)
GUILayout.BeginVertical($"{BuildInfo.Name} {BuildInfo.Version} ({BuildInfo.CommitHash??"NOT SET"})", GUILayout.Height(20f));
ToolBarPanel();
GUILayout.EndVertical();
GUILayout.BeginVertical(GUILayout.Width(PanelWidth), GUILayout.Height(300f));
GUILayout.BeginVertical(GUILayout.Width(PanelWidth), GUILayout.Height(330f));
if (_toolbar == Toolbar.AutoPlay && SinmaiAssist.config.Cheat.AutoPlay) AutoPlayPanel.OnGUI();
else if (_toolbar == Toolbar.FastSkip && SinmaiAssist.config.Cheat.FastSkip) FastSkipPanel.OnGUI();
else if (_toolbar == Toolbar.ChartTimer && SinmaiAssist.config.Cheat.ChartTimer) ChartTimerPanel.OnGUI();
Expand Down
1 change: 1 addition & 0 deletions Sinmai-Assist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@
<Compile Include="Utils\GetUserId.cs" />
<Compile Include="Utils\Keyboard.cs" />
<Compile Include="Utils\Server.cs" />
<Compile Include="Utils\User.cs" />
<Compile Include="Utils\UserLogout.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
91 changes: 91 additions & 0 deletions Utils/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.IO;
using System.Linq;
using MAI2.Util;
using Manager;
using MelonLoader.TinyJSON;
using Net.VO.Mai2;

namespace SinmaiAssist.Utils;

public class User
{
public static void ExportBackupData(long index)
{
UserData userData = Singleton<UserDataManager>.Instance.GetUserData(index);
if (userData.IsGuest())
{
GameMessageManager.SendGameMessage("Guest Account\nUnable to export backup", (int)index);
return;
}
string path = $"{BuildInfo.Name}/UserBackup";
string userDataJson = "{";
userDataJson += $"\"accessCode\": \"{userData.Detail.AccessCode}\",";
userDataJson += $"\"userId\": {userData.Detail.UserID},";
userDataJson += $"\"userName\": \"{userData.Detail.UserName}\",";
userDataJson += $"\"rating\": {userData.Detail.Rating}";

userDataJson += ",\"userFavoriteList\": " + GetFavoriteList(userData);
userDataJson += ",\"userCharacterList\": " + GetCharacterList(userData);
userDataJson += ",\"userMusicDetailList\": " + GetMusicDetailList(userData);
//userDataJson += ",\"userChargeList\": " + GetChargeList(userData);
//userDataJson += ",\"userCourseList\": " + GetCourseList(userData);

userDataJson += "}";

string timestamp = DateTime.Now.ToString("yyMMddHHmmss");
if (!Directory.Exists(Path.Combine(path)))
{
Directory.CreateDirectory(path);
}
File.WriteAllText(Path.Combine(path, $"User{userData.Detail.UserID}-{timestamp}.json"), userDataJson);
GameMessageManager.SendGameMessage($"Export Backup Data:\nUser{userData.Detail.UserID}-{timestamp}.json", (int)index);
}

public static string GetCharacterList(UserData userData)
{
return JSON.Dump(userData.CharaList.Export(), EncodeOptions.NoTypeHints);
}

public static string GetChargeList(UserData userData)
{
return JSON.Dump(userData.ChargeList, EncodeOptions.NoTypeHints);
}

public static string GetCourseList(UserData userData)
{
return JSON.Dump(userData.CourseList.Export(), EncodeOptions.NoTypeHints);
}

public static string GetMusicDetailList(UserData userData)
{
string list = "[";
UserMusicDetail[] userMusicDetail = userData.ExportScoreDetailList();
list += string.Join(", ", userMusicDetail.Select(detail =>
$"{{\"musicId\": {detail.musicId}, " +
$"\"level\": {(int)detail.level}, " +
$"\"playCount\": {detail.playCount}, " +
$"\"achievement\": {detail.achievement}, " +
$"\"comboStatus\": {(int)detail.comboStatus}, " +
$"\"syncStatus\": {(int)detail.syncStatus}, " +
$"\"deluxscoreMax\": {detail.deluxscoreMax}, " +
$"\"scoreRank\": {(int)detail.scoreRank}, " +
$"\"extNum1\": {detail.extNum1}}}"
));
list += "]";
return list;
}

public static string GetFavoriteList(UserData userData)
{
string list = "[{";
list += "\"iconList\": [" + string.Join(", ", userData.IconList.Select(item => item.itemId)) + "]";
list += ",\"plateList\": [" + string.Join(", ", userData.PlateList.Select(item => item.itemId)) + "]";
list += ",\"titleList\": [" + string.Join(", ", userData.TitleList.Select(item => item.itemId)) + "]";
list += ",\"frameList\": [" + string.Join(", ", userData.FrameList.Select(item => item.itemId)) + "]";
list += "}]";
return list;
}


}

0 comments on commit 6fba1e6

Please sign in to comment.