forked from thepeacockproject/Peacock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contractFiles.test.ts
153 lines (129 loc) · 5.16 KB
/
contractFiles.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* The Peacock Project - a HITMAN server replacement.
* Copyright (C) 2021-2024 The Peacock Project Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { describe, expect, it } from "vitest"
import { glob } from "fast-glob"
import { readFile } from "fs/promises"
import { MissionManifest } from "../../components/types/types"
import { unpack } from "msgpackr"
import { crc32 } from "@aws-crypto/crc32"
const allContractFiles = (
await glob("**/*.json", {
cwd: "../contractdata",
})
).filter((file) => !file.includes("CHALLENGES") && !file.includes("MASTERY"))
type LocWrap = {
$loc: { key: string; data: string | number[] }
}
function parseLocString(locString: string | LocWrap) {
if ((locString as LocWrap)?.$loc?.key) {
return (locString as LocWrap).$loc.key
}
if ((locString as string).includes("$loc")) {
const parts = (locString as string).split(" ")
// i hate this
const double = (locString as string).includes("$loc $loc")
return parts[double ? 2 : 1] ?? ""
}
return locString as string
}
// this is a list of all the crc32s that the game defines for localization
const gameCrcs: number[] = unpack(
await readFile("data/game-defined-locr-crc32s.msgpack"),
)
function getCrc(str: string) {
return crc32(Buffer.from(str))
}
let peacockCrcs: number[]
{
const strings = JSON.parse(
(await readFile("../resources/locale.json")).toString(),
)["english"]
peacockCrcs = Object.keys(strings).map(getCrc)
}
const allCrcs = [...peacockCrcs, ...gameCrcs]
const ignored = [
"UI_CONTRACT_RAT_OBJ_DATACORE_OPTIONAL_TITLE",
"UI_CONTRACT_FOX_ELIMINATE_REMAINING_LESSER_AGENTS_TITLE",
"UI_CONTRACT_FOX_ELIMINATE_REMAINING_LESSER_AGENTS_OBJ",
"UI_CONTRACT_FOX_ELIMINATE_REMAINING_LESSER_AGENTS_DESC",
"$UI_CONTRACT_JACARANDA_OBJECTIVE_SNIPER_NAME",
"UI_CONTRACT_GLORIOSA_OBJ_1_NAME",
"UI_CONTRACT_RAFFLESIA_OBJ_2_NAME",
"UI_CONTRACT_RAFFLESIA_OBJ_3_NAME",
"UI_CONTRACT_TITANUMARUM_OBJ_1_NAME",
"UI_CONTRACT_TITANUMARUM_OBJ_2_NAME",
"UI_CONTRACT_HOLLY_OBJ_3_NAME",
"UI_CONTRACT_HOLLY_OBJ_4_NAME",
"UI_CONTRACT_GORSE_OBJ_1_NAME",
"UI_CONTRACT_GORSE_OBJ_3_NAME",
"UI_CONTRACT_GORSE_OBJ_4_NAME",
"UI_CONTRACT_GORSE_OBJ_5_NAME",
"UI_CONTRACT_GORSE_OBJ_6_NAME",
"UI_CONTRACT_GORSE_OBJ_7_NAME",
"UI_CONTRACT_GORSE_OBJ_2_NAME",
]
describe("contract files", () => {
it("contract objectives have working localization", async () => {
for (const file of allContractFiles) {
const contract: MissionManifest = JSON.parse(
(await readFile(`../contractdata/${file}`)).toString(),
)
if (contract.Metadata.Type === "featured") {
continue
}
for (const objective of contract.Data.Objectives || []) {
if (objective.BriefingText) {
const loc = parseLocString(
objective.BriefingText,
).toUpperCase()
if (!ignored.includes(loc) && !loc.startsWith("$.")) {
const i = getCrc(loc)
expect(
allCrcs,
`${file} objective ${objective.Id} BriefingText (${loc}) in defined strings`,
).toContain(i)
}
}
if (objective.BriefingName) {
const loc = parseLocString(
objective.BriefingName,
).toUpperCase()
if (!ignored.includes(loc) && !loc.startsWith("$.")) {
const i = getCrc(loc)
expect(
allCrcs,
`${file} objective ${objective.Id} BriefingName (${loc}) in defined strings`,
).toContain(i)
}
}
if (objective.HUDTemplate?.display) {
const loc = parseLocString(
objective.HUDTemplate.display,
).toUpperCase()
if (!ignored.includes(loc) && !loc.startsWith("$.")) {
const i = getCrc(loc)
expect(
allCrcs,
`${file} objective ${objective.Id} HUDTemplate.display (${loc}) in defined strings`,
).toContain(i)
}
}
}
}
})
})