From 3ae6528922e9f5e032bdf2de7af4d0df8dc952e3 Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Wed, 21 Sep 2022 21:42:53 +0800 Subject: [PATCH] Add support for more songs, but disabled by default as that causes issues with the game --- TaikoLocalServer/Common/Constants.cs | 12 ++--------- .../Controllers/AmAuth/PowerOnController.cs | 4 ++-- .../Controllers/AmUpdater/MuchaController.cs | 4 ++-- .../Controllers/Game/CrownsDataController.cs | 20 +++++++++++++------ .../Game/GetScoreRankController.cs | 19 ++++++++++++------ .../Game/InitialDataCheckController.cs | 13 +++++++++--- .../Controllers/Game/UserDataController.cs | 13 +++++++++--- TaikoLocalServer/Program.cs | 9 ++++++++- .../{UrlSettings.cs => ServerSettings.cs} | 4 +++- TaikoLocalServer/appsettings.json | 5 +++-- 10 files changed, 67 insertions(+), 36 deletions(-) rename TaikoLocalServer/Settings/{UrlSettings.cs => ServerSettings.cs} (67%) diff --git a/TaikoLocalServer/Common/Constants.cs b/TaikoLocalServer/Common/Constants.cs index 15cf172..45863cb 100644 --- a/TaikoLocalServer/Common/Constants.cs +++ b/TaikoLocalServer/Common/Constants.cs @@ -4,17 +4,9 @@ public static class Constants { public const string DATE_TIME_FORMAT = "yyyyMMddHHmmss"; - public const int MUSIC_ID_MAX = 9000; + public const int MUSIC_ID_MAX = 1599; - public const int CROWN_FLAG_ARRAY_SIZE = MUSIC_ID_MAX + 1; - - public const int DONDAFUL_CROWN_FLAG_ARRAY_SIZE = MUSIC_ID_MAX + 1; - - public const int KIWAMI_SCORE_RANK_ARRAY_SIZE = MUSIC_ID_MAX + 1; - - public const int IKI_CORE_RANK_ARRAY_SIZE = MUSIC_ID_MAX + 1; - - public const int MIYABI_CORE_RANK_ARRAY_SIZE = MUSIC_ID_MAX + 1; + public const int MUSIC_ID_MAX_EXPANDED = 9000; public const string DEFAULT_DB_NAME = "taiko.db3"; diff --git a/TaikoLocalServer/Controllers/AmAuth/PowerOnController.cs b/TaikoLocalServer/Controllers/AmAuth/PowerOnController.cs index 2730518..06c203a 100644 --- a/TaikoLocalServer/Controllers/AmAuth/PowerOnController.cs +++ b/TaikoLocalServer/Controllers/AmAuth/PowerOnController.cs @@ -7,9 +7,9 @@ namespace TaikoLocalServer.Controllers.AmAuth; [Route("/sys/servlet/PowerOn")] public class PowerOnController : BaseController { - private readonly UrlSettings settings; + private readonly ServerSettings settings; - public PowerOnController(IOptions settings) + public PowerOnController(IOptions settings) { this.settings = settings.Value; } diff --git a/TaikoLocalServer/Controllers/AmUpdater/MuchaController.cs b/TaikoLocalServer/Controllers/AmUpdater/MuchaController.cs index 38125d2..22b8895 100644 --- a/TaikoLocalServer/Controllers/AmUpdater/MuchaController.cs +++ b/TaikoLocalServer/Controllers/AmUpdater/MuchaController.cs @@ -5,9 +5,9 @@ namespace TaikoLocalServer.Controllers.AmUpdater; public class MuchaController : BaseController { - private readonly UrlSettings settings; + private readonly ServerSettings settings; - public MuchaController(IOptions settings) + public MuchaController(IOptions settings) { this.settings = settings.Value; } diff --git a/TaikoLocalServer/Controllers/Game/CrownsDataController.cs b/TaikoLocalServer/Controllers/Game/CrownsDataController.cs index 5d9f654..6956011 100644 --- a/TaikoLocalServer/Controllers/Game/CrownsDataController.cs +++ b/TaikoLocalServer/Controllers/Game/CrownsDataController.cs @@ -1,4 +1,8 @@ -namespace TaikoLocalServer.Controllers.Game; +using System.Runtime.InteropServices; +using Microsoft.Extensions.Options; +using TaikoLocalServer.Settings; + +namespace TaikoLocalServer.Controllers.Game; [Route("/v12r03/chassis/crownsdata.php")] [ApiController] @@ -6,9 +10,12 @@ public class CrownsDataController : BaseController { private readonly ISongBestDatumService songBestDatumService; - public CrownsDataController(ISongBestDatumService songBestDatumService) + private readonly ServerSettings settings; + + public CrownsDataController(ISongBestDatumService songBestDatumService, IOptions settings) { this.songBestDatumService = songBestDatumService; + this.settings = settings.Value; } [HttpPost] @@ -19,10 +26,11 @@ public class CrownsDataController : BaseController var songBestData = await songBestDatumService.GetAllSongBestData(request.Baid); - var crown = new ushort[Constants.CROWN_FLAG_ARRAY_SIZE]; - var dondafulCrown = new byte[Constants.DONDAFUL_CROWN_FLAG_ARRAY_SIZE]; + var songIdMax = settings.EnableMoreSongs ? Constants.MUSIC_ID_MAX_EXPANDED : Constants.MUSIC_ID_MAX; + var crown = new ushort[songIdMax + 1]; + var dondafulCrown = new byte[songIdMax + 1]; - for (var songId = 0; songId < Constants.MUSIC_ID_MAX; songId++) + for (var songId = 0; songId < songIdMax; songId++) { var id = songId; dondafulCrown[songId] = songBestData @@ -39,7 +47,7 @@ public class CrownsDataController : BaseController // Calculate flag according to difficulty .Aggregate((ushort)0, (flag, datum) => FlagCalculator.ComputeCrownFlag(flag, datum.BestCrown, datum.Difficulty)); } - + var response = new CrownsDataResponse { Result = 1, diff --git a/TaikoLocalServer/Controllers/Game/GetScoreRankController.cs b/TaikoLocalServer/Controllers/Game/GetScoreRankController.cs index cf41eb0..2ffc6fc 100644 --- a/TaikoLocalServer/Controllers/Game/GetScoreRankController.cs +++ b/TaikoLocalServer/Controllers/Game/GetScoreRankController.cs @@ -1,14 +1,20 @@ -namespace TaikoLocalServer.Controllers.Game; +using Microsoft.Extensions.Options; +using TaikoLocalServer.Settings; + +namespace TaikoLocalServer.Controllers.Game; [Route("/v12r03/chassis/getscorerank.php")] [ApiController] public class GetScoreRankController : BaseController { private readonly ISongBestDatumService songBestDatumService; + + private readonly ServerSettings settings; - public GetScoreRankController(ISongBestDatumService songBestDatumService) + public GetScoreRankController(ISongBestDatumService songBestDatumService, IOptions settings) { this.songBestDatumService = songBestDatumService; + this.settings = settings.Value; } [HttpPost] @@ -16,12 +22,13 @@ public class GetScoreRankController : BaseController public async Task GetScoreRank([FromBody] GetScoreRankRequest request) { Logger.LogInformation("GetScoreRank request : {Request}", request.Stringify()); - var kiwamiScores = new byte[Constants.KIWAMI_SCORE_RANK_ARRAY_SIZE]; - var miyabiScores = new ushort[Constants.MIYABI_CORE_RANK_ARRAY_SIZE]; - var ikiScores = new ushort[Constants.IKI_CORE_RANK_ARRAY_SIZE]; + var songIdMax = settings.EnableMoreSongs ? Constants.MUSIC_ID_MAX_EXPANDED : Constants.MUSIC_ID_MAX; + var kiwamiScores = new byte[songIdMax + 1]; + var miyabiScores = new ushort[songIdMax + 1]; + var ikiScores = new ushort[songIdMax + 1]; var songBestData = await songBestDatumService.GetAllSongBestData(request.Baid); - for (var songId = 0; songId < Constants.MUSIC_ID_MAX; songId++) + for (var songId = 0; songId < songIdMax; songId++) { var id = songId; kiwamiScores[songId] = songBestData diff --git a/TaikoLocalServer/Controllers/Game/InitialDataCheckController.cs b/TaikoLocalServer/Controllers/Game/InitialDataCheckController.cs index e8f9909..af13f10 100644 --- a/TaikoLocalServer/Controllers/Game/InitialDataCheckController.cs +++ b/TaikoLocalServer/Controllers/Game/InitialDataCheckController.cs @@ -1,4 +1,7 @@ -namespace TaikoLocalServer.Controllers.Game; +using Microsoft.Extensions.Options; +using TaikoLocalServer.Settings; + +namespace TaikoLocalServer.Controllers.Game; [ApiController] [Route("/v12r03/chassis/initialdatacheck.php")] @@ -6,9 +9,12 @@ public class InitialDataCheckController : BaseController settings) { this.gameDataService = gameDataService; + this.settings = settings.Value; } [HttpPost] @@ -17,8 +23,9 @@ public class InitialDataCheckController : BaseController(); for (var danId = Constants.MIN_DAN_ID; danId <= Constants.MAX_DAN_ID; danId++) diff --git a/TaikoLocalServer/Controllers/Game/UserDataController.cs b/TaikoLocalServer/Controllers/Game/UserDataController.cs index cbf5d15..edae329 100644 --- a/TaikoLocalServer/Controllers/Game/UserDataController.cs +++ b/TaikoLocalServer/Controllers/Game/UserDataController.cs @@ -1,5 +1,7 @@ using System.Buffers.Binary; using System.Text.Json; +using Microsoft.Extensions.Options; +using TaikoLocalServer.Settings; using Throw; namespace TaikoLocalServer.Controllers.Game; @@ -13,12 +15,16 @@ public class UserDataController : BaseController private readonly ISongPlayDatumService songPlayDatumService; private readonly IGameDataService gameDataService; + + private readonly ServerSettings settings; - public UserDataController(IUserDatumService userDatumService, ISongPlayDatumService songPlayDatumService, IGameDataService gameDataService) + public UserDataController(IUserDatumService userDatumService, ISongPlayDatumService songPlayDatumService, + IGameDataService gameDataService, IOptions settings) { this.userDatumService = userDatumService; this.songPlayDatumService = songPlayDatumService; this.gameDataService = gameDataService; + this.settings = settings.Value; } [HttpPost] @@ -27,11 +33,12 @@ public class UserDataController : BaseController { Logger.LogInformation("UserData request : {Request}", request.Stringify()); + var songIdMax = settings.EnableMoreSongs ? Constants.MUSIC_ID_MAX_EXPANDED : Constants.MUSIC_ID_MAX; var releaseSongArray = - FlagCalculator.GetBitArrayFromIds(gameDataService.GetMusicList(), Constants.MUSIC_ID_MAX, Logger); + FlagCalculator.GetBitArrayFromIds(gameDataService.GetMusicList(), songIdMax, Logger); var uraSongArray = - FlagCalculator.GetBitArrayFromIds(gameDataService.GetMusicWithUraList(), Constants.MUSIC_ID_MAX, Logger); + FlagCalculator.GetBitArrayFromIds(gameDataService.GetMusicWithUraList(), songIdMax, Logger); var userData = await userDatumService.GetFirstUserDatumOrDefault(request.Baid); diff --git a/TaikoLocalServer/Program.cs b/TaikoLocalServer/Program.cs index 1a4b16c..e8bfad7 100644 --- a/TaikoLocalServer/Program.cs +++ b/TaikoLocalServer/Program.cs @@ -35,10 +35,17 @@ try configuration.WriteTo.Console().ReadFrom.Configuration(context.Configuration); }); + if (builder.Configuration.GetValue("ServerSettings:EnableMoreSongs")) + { + Log.Warning("Song limit expanded! Currently the game has issue loading crown/score rank and " + + "probably more server related data for songs with id > 1599. " + + "Also, the game can have random crashes because of that! Use at your own risk!"); + } + // Add services to the container. builder.Services.AddOptions(); builder.Services.AddSingleton(); - builder.Services.Configure(builder.Configuration.GetSection(nameof(UrlSettings))); + builder.Services.Configure(builder.Configuration.GetSection(nameof(ServerSettings))); builder.Services.AddControllers().AddProtoBufNet(); builder.Services.AddDbContext(option => { diff --git a/TaikoLocalServer/Settings/UrlSettings.cs b/TaikoLocalServer/Settings/ServerSettings.cs similarity index 67% rename from TaikoLocalServer/Settings/UrlSettings.cs rename to TaikoLocalServer/Settings/ServerSettings.cs index d024cda..3dd9136 100644 --- a/TaikoLocalServer/Settings/UrlSettings.cs +++ b/TaikoLocalServer/Settings/ServerSettings.cs @@ -1,8 +1,10 @@ namespace TaikoLocalServer.Settings; -public class UrlSettings +public class ServerSettings { public string MuchaUrl { get; set; } = string.Empty; public string GameUrl { get; set; } = string.Empty; + + public bool EnableMoreSongs { get; set; } } \ No newline at end of file diff --git a/TaikoLocalServer/appsettings.json b/TaikoLocalServer/appsettings.json index 5553448..13b11b2 100644 --- a/TaikoLocalServer/appsettings.json +++ b/TaikoLocalServer/appsettings.json @@ -1,7 +1,8 @@ { - "UrlSettings": { + "ServerSettings": { "MuchaUrl": "https://v402-front.mucha-prd.nbgi-amnet.jp:10122", - "GameUrl": "vsapi.taiko-p.jp" + "GameUrl": "vsapi.taiko-p.jp", + "EnableMoreSongs": false }, "DbFileName" : "taiko.db3",