From c1d0292fe540b5eefba28ea25910b3774b7b6619 Mon Sep 17 00:00:00 2001 From: SELEKCJONER Date: Sun, 22 Sep 2024 19:05:12 +0200 Subject: [PATCH] Add experimental fix for completestage cmd probably fixes completestage missing some entries like d_main_18af_06 --- EpinelPS/GameData/GameData.cs | 54 ++++++++- EpinelPS/GameData/JsonStaticData.cs | 17 +++ EpinelPS/Program.cs | 165 +++++++++++++++++----------- 3 files changed, 171 insertions(+), 65 deletions(-) diff --git a/EpinelPS/GameData/GameData.cs b/EpinelPS/GameData/GameData.cs index 874769a..338113f 100644 --- a/EpinelPS/GameData/GameData.cs +++ b/EpinelPS/GameData/GameData.cs @@ -46,6 +46,8 @@ namespace EpinelPS.StaticInfo public Dictionary gachaTypes = new Dictionary(); // Fixed initialization public Dictionary eventManagers = new Dictionary(); public Dictionary lwptablemgrs = new Dictionary(); // Fixed initialization + private Dictionary albumResourceRecords = new Dictionary(); + @@ -395,7 +397,13 @@ namespace EpinelPS.StaticInfo foreach (var obj in lwptable.records) { lwptablemgrs.Add(obj.id, obj); // Use obj.id as the key and obj (the LiveWallpaperRecord) as the value - } + } + + var albumResourceTable = await LoadZip("AlbumResourceTable.json", progress); + foreach (var obj in albumResourceTable.records) + { + albumResourceRecords.Add(obj.id, obj); // Now refers to the class-level field + } // Load Jukebox data await LoadJukeboxListData(progress); await LoadJukeboxThemeData(progress); @@ -590,5 +598,49 @@ namespace EpinelPS.StaticInfo jukeboxThemeDataRecords.TryGetValue(id, out var record); return record; } + + public IEnumerable GetScenarioStageIdsForChapter(int chapterNumber) + { + + return albumResourceRecords.Values.Where(record => record.target_chapter == chapterNumber && !string.IsNullOrEmpty(record.scenario_group_id)).Select(record => record.scenario_group_id); + } + public bool IsValidScenarioStage(string scenarioGroupId, int targetChapter, int targetStage) + { + // Example regular stage format: "d_main_26_08" + // Example scenario stage format: "d_main_18af_06" + + var parts = scenarioGroupId.Split('_'); + + if (parts.Length != 4) + { + return false; // If it doesn't have 4 parts, it's not a valid stage + } + + string chapterPart = parts[2]; // This could be "26" or "18af" + string stagePart = parts[3]; // This is the stage part, e.g., "08" or "06" + + // Handle scenario stages (ending in "af") + bool isScenarioStage = chapterPart.EndsWith("af"); + + // Extract chapter number (remove "af" if present) + string chapterNumberStr = isScenarioStage ? chapterPart.Substring(0, chapterPart.Length - 2) : chapterPart; + + // Parse chapter and stage numbers + if (int.TryParse(chapterNumberStr, out int chapter) && int.TryParse(stagePart, out int stage)) + { + // Only accept stages if they are: + // 1. In a chapter less than the target chapter + // 2. OR in the target chapter but with a stage number less than or equal to the target stage + if (chapter < targetChapter || (chapter == targetChapter && stage <= targetStage)) + { + return true; + } + } + + return false; + } + + + } } diff --git a/EpinelPS/GameData/JsonStaticData.cs b/EpinelPS/GameData/JsonStaticData.cs index 52656b0..29bd76a 100644 --- a/EpinelPS/GameData/JsonStaticData.cs +++ b/EpinelPS/GameData/JsonStaticData.cs @@ -283,4 +283,21 @@ { public List records; } + public class AlbumResourceRecord + { + public int id; + public int sub_category_id; + public string scenario_name_localtable = ""; + public string scenario_name_localkey = ""; + public string scenario_group_id = ""; + public int target_chapter; + public bool is_hidden; + public string dialogtype = ""; + } + + public class AlbumResourceTable + { + public List records; + } + } diff --git a/EpinelPS/Program.cs b/EpinelPS/Program.cs index 24618d1..c6ffdf4 100644 --- a/EpinelPS/Program.cs +++ b/EpinelPS/Program.cs @@ -512,8 +512,8 @@ namespace EpinelPS } } - // Save the updated data - JsonDb.Save(); + // Save the updated data + JsonDb.Save(); } else if (input.StartsWith("SetSkillLevel")) { @@ -582,71 +582,108 @@ namespace EpinelPS } } } - else if (input.StartsWith("completestage")) - { - if (selectedUser == 0) - { - Console.WriteLine("No user selected"); - } - else - { - var user = JsonDb.Instance.Users.FirstOrDefault(x => x.ID == selectedUser); - if (user == null) - { - Console.WriteLine("Selected user does not exist"); - selectedUser = 0; - prompt = "# "; - } - else - { - if (args.Length == 2) - { - var input2 = args[1]; - try - { - var chapter = int.TryParse(input2.Split('-')[0], out int chapterNumber); - var stage = int.TryParse(input2.Split('-')[1], out int stageNumber); + else if (input.StartsWith("completestage")) + { + if (selectedUser == 0) + { + Console.WriteLine("No user selected"); + } + else + { + var user = JsonDb.Instance.Users.FirstOrDefault(x => x.ID == selectedUser); + if (user == null) + { + Console.WriteLine("Selected user does not exist"); + selectedUser = 0; + prompt = "# "; + } + else + { + if (args.Length == 2) + { + var input2 = args[1]; + try + { + var chapterParsed = int.TryParse(input2.Split('-')[0], out int chapterNumber); + var stageParsed = int.TryParse(input2.Split('-')[1], out int stageNumber); + + if (chapterParsed && stageParsed) + { + Console.WriteLine($"Chapter number: {chapterNumber}, Stage number: {stageNumber}"); + + // Complete main stages + for (int i = 0; i <= chapterNumber; i++) + { + var stages = GameData.Instance.GetStageIdsForChapter(i, true); + int target = 1; + foreach (var item in stages) + { + if (!user.IsStageCompleted(item, true)) + { + Console.WriteLine("Completing stage " + item); + ClearStage.CompleteStage(user, item, true); + } + + if (i == chapterNumber && target == stageNumber) + { + break; + } + + target++; + } + } + + // Process scenario and regular stages + Console.WriteLine($"Processing stages for chapters 0 to {chapterNumber}"); + + for (int chapter = 0; chapter <= chapterNumber; chapter++) + { + Console.WriteLine($"Processing chapter: {chapter}"); + + var stages = GameData.Instance.GetScenarioStageIdsForChapter(chapter) + .Where(stageId => GameData.Instance.IsValidScenarioStage(stageId, chapterNumber, stageNumber)) + .ToList(); + + Console.WriteLine($"Found {stages.Count} stages for chapter {chapter}"); + + foreach (var stage in stages) + { + if (!user.CompletedScenarios.Contains(stage)) + { + user.CompletedScenarios.Add(stage); + Console.WriteLine($"Added stage {stage} to CompletedScenarios"); + } + else + { + Console.WriteLine($"Stage {stage} is already completed"); + } + } + } + + // Save changes to user data + JsonDb.Save(); + } + else + { + Console.WriteLine("Chapter and stage number must be valid integers"); + } + } + catch (Exception ex) + { + Console.WriteLine("Exception: " + ex.ToString()); + } + } + else + { + Console.WriteLine("Invalid argument length, must be 1"); + } + } + } + } + - if (chapter && stage) - { - for (int i = 0; i < chapterNumber + 1; i++) - { - var stages = GameData.Instance.GetStageIdsForChapter(i, true); - int target = 1; - foreach (var item in stages) - { - if (!user.IsStageCompleted(item, true)) - { - Console.WriteLine("Completing stage " + item); - ClearStage.CompleteStage(user, item, true); - } - if (i == chapterNumber && target == stageNumber) - { - break; - } - target++; - } - } - } - else - { - Console.WriteLine("chapter and stage number must be a 32 bit integer"); - } - } - catch (Exception ex) - { - Console.WriteLine("exception:" + ex.ToString()); - } - } - else - { - Console.WriteLine("invalid argument length, must be 1"); - } - } - } - } else if (input == "exit") { Environment.Exit(0);