From dada54506e8ac955d0914941e4f8aab55f914382 Mon Sep 17 00:00:00 2001 From: Jay Malhotra <5047192+SapiensAnatis@users.noreply.github.com> Date: Sun, 6 Oct 2024 20:50:49 +0100 Subject: [PATCH] Sanitize parties for ability crests on export (#1102) --- .../Web/Savefile/SavefileExportTests.cs | 16 +++++++++++++ .../DragaliaAPI/Services/Game/LoadService.cs | 24 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/DragaliaAPI/DragaliaAPI.Integration.Test/Features/Web/Savefile/SavefileExportTests.cs b/DragaliaAPI/DragaliaAPI.Integration.Test/Features/Web/Savefile/SavefileExportTests.cs index da42637b7..a836b0ff6 100644 --- a/DragaliaAPI/DragaliaAPI.Integration.Test/Features/Web/Savefile/SavefileExportTests.cs +++ b/DragaliaAPI/DragaliaAPI.Integration.Test/Features/Web/Savefile/SavefileExportTests.cs @@ -2,6 +2,7 @@ using System.Net.Http.Json; using DragaliaAPI.Database.Entities; using DragaliaAPI.Shared.Serialization; +using Microsoft.EntityFrameworkCore; namespace DragaliaAPI.Integration.Test.Features.Web.Savefile; @@ -45,6 +46,13 @@ await this.AddToDatabase( new DbAbilityCrest() { ViewerId = this.ViewerId, AbilityCrestId = customCrest } ); + this.ApiContext.PlayerPartyUnits.Where(x => x.PartyNo == 1) + .ExecuteUpdate(e => + e.SetProperty(x => x.EquipCrestSlotType1CrestId1, customCrest) + .SetProperty(x => x.EquipCrestSlotType1CrestId2, customCrest) + .SetProperty(x => x.EquipCrestSlotType1CrestId3, customCrest) + ); + HttpResponseMessage resp = await this.Client.GetAsync("/api/savefile/export"); DragaliaResponse? deserialized = await resp.Content.ReadFromJsonAsync< @@ -56,5 +64,13 @@ await this.AddToDatabase( deserialized! .Data.AbilityCrestList.Should() .NotContain(x => x.AbilityCrestId == customCrest); + + PartyList? firstParty = deserialized.Data.PartyList.First(x => x.PartyNo == 1); + + firstParty + .PartySettingList.Should() + .NotContain(x => x.EquipCrestSlotType1CrestId1 == customCrest) + .And.NotContain(x => x.EquipCrestSlotType1CrestId2 == customCrest) + .And.NotContain(x => x.EquipCrestSlotType1CrestId3 == customCrest); } } diff --git a/DragaliaAPI/DragaliaAPI/Services/Game/LoadService.cs b/DragaliaAPI/DragaliaAPI/Services/Game/LoadService.cs index 974e5ed97..cd5dd7152 100644 --- a/DragaliaAPI/DragaliaAPI/Services/Game/LoadService.cs +++ b/DragaliaAPI/DragaliaAPI/Services/Game/LoadService.cs @@ -120,11 +120,33 @@ public async Task BuildIndexData( public LoadIndexResponse SanitizeIndexData(LoadIndexResponse original) { + AbilityCrestId maxVanilllaId = (AbilityCrestId)50000000; + // Remove custom wyrmprints original.AbilityCrestList = original - .AbilityCrestList.Where(x => (int)x.AbilityCrestId < 50000000) + .AbilityCrestList.Where(x => x.AbilityCrestId < maxVanilllaId) .ToList(); + foreach ( + PartySettingList partySettingList in original.PartyList.SelectMany(x => + x.PartySettingList + ) + ) + { + if (partySettingList.EquipCrestSlotType1CrestId1 >= maxVanilllaId) + { + partySettingList.EquipCrestSlotType1CrestId1 = 0; + } + if (partySettingList.EquipCrestSlotType1CrestId2 >= maxVanilllaId) + { + partySettingList.EquipCrestSlotType1CrestId2 = 0; + } + if (partySettingList.EquipCrestSlotType1CrestId3 >= maxVanilllaId) + { + partySettingList.EquipCrestSlotType1CrestId3 = 0; + } + } + return original; } }