Skip to content

Commit

Permalink
Sanitize parties for ability crests on export (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
SapiensAnatis authored Oct 6, 2024
1 parent 5b31507 commit dada545
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<LoadIndexResponse>? deserialized = await resp.Content.ReadFromJsonAsync<
Expand All @@ -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);
}
}
24 changes: 23 additions & 1 deletion DragaliaAPI/DragaliaAPI/Services/Game/LoadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,33 @@ public async Task<LoadIndexResponse> 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;
}
}
Expand Down

0 comments on commit dada545

Please sign in to comment.