From fef58647d3e1e47e9e34075ad269fe1ad1cc6801 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 30 Dec 2024 13:17:42 +0800 Subject: [PATCH] Filter invalid characters. --- .../Dimbreath/FetchModels_GI.swift | 26 ++++++++++++++++--- .../Dimbreath/FetchModels_HSR.swift | 4 +-- .../Components/SupportedGame.swift | 4 +-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Sources/GachaMetaGeneratorModule/Components/FetchModels/Dimbreath/FetchModels_GI.swift b/Sources/GachaMetaGeneratorModule/Components/FetchModels/Dimbreath/FetchModels_GI.swift index 2f26b28..4f746d8 100644 --- a/Sources/GachaMetaGeneratorModule/Components/FetchModels/Dimbreath/FetchModels_GI.swift +++ b/Sources/GachaMetaGeneratorModule/Components/FetchModels/Dimbreath/FetchModels_GI.swift @@ -57,10 +57,18 @@ extension GachaMetaGenerator { let nameTextMapHash: Int var l10nMap: [String: String]? - func isCharacter(for game: SupportedGame) -> Bool { - switch game { - case .genshinImpact: return id > 114514 - case .starRail: return id <= 9999 + var isCharacter: Bool { + id > 114514 + } + + var isValid: Bool { + if isCharacter { + guard id.description.prefix(2) != "11" else { return false } + guard id < 10000900 else { return false } + guard !Self.forbiddenNameTextMapHashes.contains(id) else { return false } + return true + } else { + return true // Temporarily assume that all weapons are vaid. } } @@ -72,5 +80,15 @@ extension GachaMetaGenerator { /// This variable is only useful during decoding process. fileprivate var qualityType: GIQualityType? + + // MARK: Private + + private static let forbiddenNameTextMapHashes: [Int] = [ + 1499745907, 1538092267, 3464027035, 594850707, + 231836963, 3780343147, 1516554699, 977648923, + 2597527627, 500612819, 3532343811, 302691299, + 452043283, 2242027395, 565329475, 1994081075, + 2824690859, 1857915418, 3293134650, 853394138, + ] } } diff --git a/Sources/GachaMetaGeneratorModule/Components/FetchModels/Dimbreath/FetchModels_HSR.swift b/Sources/GachaMetaGeneratorModule/Components/FetchModels/Dimbreath/FetchModels_HSR.swift index 876caa4..44de24d 100644 --- a/Sources/GachaMetaGeneratorModule/Components/FetchModels/Dimbreath/FetchModels_HSR.swift +++ b/Sources/GachaMetaGeneratorModule/Components/FetchModels/Dimbreath/FetchModels_HSR.swift @@ -16,7 +16,7 @@ extension GachaMetaGenerator { } /// Starrail only. - public class AvatarRawItem: Codable, RawItemFetchModelProtocol { + public class HSRAvatarRawItem: Codable, RawItemFetchModelProtocol { // MARK: Lifecycle public required init(from decoder: any Decoder) throws { @@ -64,7 +64,7 @@ extension GachaMetaGenerator { } /// Starrail only. - public class WeaponRawItem: Codable, RawItemFetchModelProtocol { + public class HSRWeaponRawItem: Codable, RawItemFetchModelProtocol { // MARK: Lifecycle public required init(from decoder: any Decoder) throws { diff --git a/Sources/GachaMetaGeneratorModule/Components/SupportedGame.swift b/Sources/GachaMetaGeneratorModule/Components/SupportedGame.swift index e406a21..4860705 100644 --- a/Sources/GachaMetaGeneratorModule/Components/SupportedGame.swift +++ b/Sources/GachaMetaGeneratorModule/Components/SupportedGame.swift @@ -117,11 +117,11 @@ extension GachaMetaGenerator.SupportedGame { return response.map { $0.toGachaItemMeta() } case (.starRail, .weaponData): let (data, _) = try await URLSession.shared.asyncData(from: getExcelConfigDataURL(for: .weaponData)) - let response = try JSONDecoder().decode([GachaMetaGenerator.WeaponRawItem].self, from: data) + let response = try JSONDecoder().decode([GachaMetaGenerator.HSRWeaponRawItem].self, from: data) return response.filter(\.isValid).map { $0.toGachaItemMeta() } case (.starRail, .characterData): let (data, _) = try await URLSession.shared.asyncData(from: getExcelConfigDataURL(for: .characterData)) - let response = try JSONDecoder().decode([GachaMetaGenerator.AvatarRawItem].self, from: data) + let response = try JSONDecoder().decode([GachaMetaGenerator.HSRAvatarRawItem].self, from: data) return response.filter(\.isValid).map { $0.toGachaItemMeta() } } }