Skip to content

Commit dd1a6e7

Browse files
committed
Fix some accidental data corruption
1 parent df94f54 commit dd1a6e7

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

api/stately/loadouts-queries.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,17 @@ export function convertLoadoutFromStately(item: StatelyLoadout | StatelyLoadoutS
132132
export function convertLoadoutParametersFromStately(
133133
loParameters: StatelyLoadoutParameters,
134134
): LoadoutParameters {
135-
const { assumeArmorMasterwork, statConstraints, modsByBucket, ...loParametersDefaulted } =
136-
stripTypeName(loParameters);
135+
const {
136+
assumeArmorMasterwork,
137+
statConstraints,
138+
modsByBucket,
139+
artifactUnlocks,
140+
inGameIdentifiers,
141+
...loParametersDefaulted
142+
} = stripTypeName(loParameters);
137143
return {
138144
...stripDefaults(loParametersDefaulted),
139-
exoticArmorHash:
140-
loParameters.exoticArmorHash === 0n ? undefined : Number(loParameters.exoticArmorHash),
145+
exoticArmorHash: exoticArmorHashFromStately(loParameters.exoticArmorHash),
141146
// DIM's AssumArmorMasterwork enum starts at 1
142147
assumeArmorMasterwork: (assumeArmorMasterwork ?? 0) + 1,
143148
statConstraints: statConstraintsFromStately(statConstraints),
@@ -146,14 +151,30 @@ export function convertLoadoutParametersFromStately(
146151
: listToMap('bucketHash', 'modHashes', modsByBucket),
147152
autoStatMods: true,
148153
includeRuntimeStatBenefits: true,
154+
artifactUnlocks: artifactUnlocks ? stripTypeName(artifactUnlocks) : undefined,
155+
inGameIdentifiers: inGameIdentifiers ? stripTypeName(inGameIdentifiers) : undefined,
149156
};
150157
}
151158

159+
function exoticArmorHashFromStately(hash: bigint) {
160+
if (hash === 0n) {
161+
return undefined;
162+
}
163+
// Some hashes got sign-flipped when I was changing data types from uint32 to
164+
// int32 to int64 - the signed versions interpreted larger numbers (> 2^31) as
165+
// signed, and everything got messed up. -1 and -2 are still valid special
166+
// cases.
167+
if (hash < -2) {
168+
hash = 4294967296n + hash; // The constant is 32 set bits, plus one
169+
}
170+
return Number(hash);
171+
}
172+
152173
export function statConstraintsFromStately(statConstraints: StatelyStatConstraint[]) {
153174
if (statConstraints.length === 0) {
154175
return undefined;
155176
}
156-
return statConstraints.map((c) => {
177+
const constraints = statConstraints.map((c) => {
157178
const constraint: StatConstraint = {
158179
statHash: c.statHash,
159180
};
@@ -166,6 +187,14 @@ export function statConstraintsFromStately(statConstraints: StatelyStatConstrain
166187
}
167188
return constraint;
168189
});
190+
191+
// I screwed up the max constraints for some stored items, so we'll fix them here
192+
if (constraints.every((c) => c.maxTier === 0)) {
193+
for (const c of constraints) {
194+
delete c.maxTier;
195+
}
196+
}
197+
return constraints;
169198
}
170199

171200
function convertLoadoutItemFromStately(item: StatelyLoadoutItem): LoadoutItem {

0 commit comments

Comments
 (0)