Skip to content

Commit

Permalink
Merge pull request #603 from FlaminSarge/catalysts
Browse files Browse the repository at this point in the history
Add dummy-catalyst-mapping.json for mapping dummy catalyst items to actual catalyst items
  • Loading branch information
delphiactual authored May 8, 2024
2 parents c42d6c1 + 1cd6ec3 commit 093195f
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 71 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ If your pre-commit hook fails, please run the following `pnpm dlx husky install`
| d2-trials-objectives.json | a mapping containing trials objective hashes and trials passage hashes |
| deprecated-mods.json | an array containing all deprecated mod hashes |
| DestinySymbols.woff2 | woff containing Destiny Glyphs, refer to d2-font-glyphs for enums |
| dummy-catalyst-mapping.json | a mapping from dummy catalyst to actual catalyst hashes for items with the older catalyst socket system (where catalysts auto-apply to the gun once completed) |
| empty-plug-hashes.ts | a set containing a listing of all "empty" plugs (e.g. No Shader, No Mod Inserted) |
| energy-mods-change.json | table for looking up energy capacity mods for Armor 2.0 to change between elements |
| energy-mods.json | table for looking up energy capacity mods for Armor 2.0 staying the same element |
Expand Down
32 changes: 32 additions & 0 deletions output/dummy-catalyst-mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"354293076": 1824496861,
"354293077": 1824496860,
"390807531": 1864989992,
"544137184": 1249968539,
"544137185": 1249968538,
"680163197": 658317088,
"800074992": 3466057365,
"854868710": 769440797,
"1340292993": 2732814938,
"1620506138": 615063267,
"1620506139": 615063266,
"1637046321": 2674202880,
"1678902463": 2409031770,
"1772382457": 1496699324,
"1891148055": 920755188,
"2101754671": 3459475454,
"2142466730": 136852797,
"2282260620": 2085058763,
"2282260621": 2085058762,
"2408641879": 4067652714,
"2626423393": 1733620422,
"2790377728": 1783582993,
"2858348496": 924149235,
"2858348497": 924149234,
"3384861888": 1758592809,
"3804992459": 1149703256,
"3815768596": 484491717,
"3867277431": 1684153732,
"4233905576": 456628589,
"4233905577": 456628588
}
158 changes: 87 additions & 71 deletions src/generate-catalyst-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,75 +37,73 @@ const craftableExotics = getAllDefs('InventoryItem')
// (more interesting than the all-identical icons on catalyst triumphs)
const triumphData: any = { icon: String, source: String };

getDef('PresentationNode', catalystPresentationNodeHash)?.children.presentationNodes.forEach(
(p) =>
getDef('PresentationNode', p.presentationNodeHash)?.children.records.forEach((r) => {
const recordName = getDef('Record', r.recordHash)?.displayProperties.name;
catalystRecordNames.push(recordName ?? '');
}),
getDef('PresentationNode', catalystPresentationNodeHash)?.children.presentationNodes.forEach((p) =>
getDef('PresentationNode', p.presentationNodeHash)?.children.records.forEach((r) => {
const recordName = getDef('Record', r.recordHash)?.displayProperties.name;
catalystRecordNames.push(recordName ?? '');
}),
);

// loop the catalyst section of triumphs
getDef('PresentationNode', catalystPresentationNodeHash)?.children.presentationNodes.forEach(
(p) =>
getDef('PresentationNode', p.presentationNodeHash)?.children.records.forEach((r) => {
const record = getDef('Record', r.recordHash);
const recordName = record?.displayProperties.name;
if (!record || !recordName) {
return;
}

// look for an inventoryItem with the same name, and plugStyle 1 (should find the catalyst for that gun)
let itemWithSameName = inventoryItems.find(
(i) => i.displayProperties.name === recordName && i.plug?.plugStyle === 1,
getDef('PresentationNode', catalystPresentationNodeHash)?.children.presentationNodes.forEach((p) =>
getDef('PresentationNode', p.presentationNodeHash)?.children.records.forEach((r) => {
const record = getDef('Record', r.recordHash);
const recordName = record?.displayProperties.name;
if (!record || !recordName) {
return;
}

// look for an inventoryItem with the same name, and plugStyle 1 (should find the catalyst for that gun)
let itemWithSameName = inventoryItems.find(
(i) => i.displayProperties.name === recordName && i.plug?.plugStyle === 1,
);

// Work around for weirdly named catalysts
if (recordName === 'Two-Tailed Fox Catalyst') {
itemWithSameName = inventoryItems.find(
(i) => i.displayProperties.name === 'Third Tail' && i.plug?.plugStyle === 1,
);
}

// Work around for exotic quest craftables
// still no good icon for osteo striga catalyst
switch (recordName) {
case 'Revision Zero Catalyst':
itemWithSameName = findDummyItemWithSpecificName('4-Timer Refit');
break;
case 'Immovable Refit':
itemWithSameName = findDummyItemWithSpecificName('Immovable Refit');
break;
case 'Wish-Keeper Catalyst':
itemWithSameName = findDummyItemWithSpecificName('Hatchling Refit');
break;
}

const matchingExotic =
(itemWithSameName &&
(findWeaponViaCatalystPlug(itemWithSameName.hash) ??
findWeaponViaCatalystPCH(itemWithSameName.plug?.plugCategoryHash))) ??
craftableExotics.find((i) =>
record.displayProperties.description.includes(i!.displayProperties.name),
);

// Work around for weirdly named catalysts
if (recordName === 'Two-Tailed Fox Catalyst') {
itemWithSameName = inventoryItems.find(
(i) => i.displayProperties.name === 'Third Tail' && i.plug?.plugStyle === 1,
);
}
if (matchingExotic) {
exoticWeaponHashToCatalystRecord[matchingExotic.hash] = r.recordHash;
exoticWeaponHashesWithCatalyst.push(matchingExotic.hash);
}

// Work around for exotic quest craftables
// still no good icon for osteo striga catalyst
switch (recordName) {
case 'Revision Zero Catalyst':
itemWithSameName = findDummyItemWithSpecificName('4-Timer Refit');
break;
case 'Immovable Refit':
itemWithSameName = findDummyItemWithSpecificName('Immovable Refit');
break;
case 'Wish-Keeper Catalyst':
itemWithSameName = findDummyItemWithSpecificName('Hatchling Refit');
break;
}
// and get its icon image
const icon = itemWithSameName?.displayProperties?.icon;

const matchingExotic =
(itemWithSameName &&
(findWeaponViaCatalystPlug(itemWithSameName.hash) ??
findWeaponViaCatalystPCH(itemWithSameName.plug?.plugCategoryHash))) ??
craftableExotics.find((i) =>
record.displayProperties.description.includes(i!.displayProperties.name),
);

if (matchingExotic) {
exoticWeaponHashToCatalystRecord[matchingExotic.hash] = r.recordHash;
exoticWeaponHashesWithCatalyst.push(matchingExotic.hash);
// this "if" check is because of classified data situations
if (icon) {
triumphData[r.recordHash] = icon;
} else {
if (!IGNORED_CATALYSTS_NAMES.some((term) => recordName?.includes(term))) {
console.log(`no catalyst image found for ${r.recordHash} ${recordName}`);
}

// and get its icon image
const icon = itemWithSameName?.displayProperties?.icon;

// this "if" check is because of classified data situations
if (icon) {
triumphData[r.recordHash] = icon;
} else {
if (!IGNORED_CATALYSTS_NAMES.some((term) => recordName?.includes(term))) {
console.log(`no catalyst image found for ${r.recordHash} ${recordName}`);
}
}
}),
}
}),
);

// Generate List of Sorted Exotic Weapons Hashes with Catalysts
Expand All @@ -116,6 +114,18 @@ const pretty = `const exoticWeaponHashesWithCatalyst = new Set<number>([\n${uniq
.join('')}]);\n\nexport default exoticWeaponHashesWithCatalyst;`;
const annotatedExoticHashes = annotate(pretty);

// Get all Dummy Catalyst items, figure out their PCHs, and map them to the reinitializationPossiblePlugHashes items if available
// This will create a mapping of dummy catalyst -> actual catalyst for all guns that 'auto-apply' catalyst when pulled from collections
const dummyCatalystMapping = Object.fromEntries(
getAllDefs('InventoryItem')
.filter((i) => i.itemType === 20 && i.plug?.uiPlugLabel === 'masterwork_interactable')
.filter((i) => i.plug?.plugCategoryHash && i.hash)
.map((i) => [i.hash, findAutoAppliedCatalystForCatalystPCH(i.plug!.plugCategoryHash)])
.filter(([hash, catalyst]) => hash && catalyst)
.map(([hash, catalyst]) => [hash, catalyst!]),
);

writeFile('./output/dummy-catalyst-mapping.json', dummyCatalystMapping);
writeFile('./output/catalyst-triumph-icons.json', triumphData);
writeFile('./output/exotics-with-catalysts.ts', annotatedExoticHashes);
writeFile('./output/exotic-to-catalyst-record.json', exoticWeaponHashToCatalystRecord);
Expand All @@ -130,22 +140,20 @@ function getCatalystPresentationNodeHash(): number | undefined {
}

function findWeaponViaCatalystPlug(catalystPlugHash: number) {
return inventoryItems.find(
(item) =>
item.sockets?.socketEntries.find(
(socket) => socket.reusablePlugItems[0]?.plugItemHash === catalystPlugHash,
),
return inventoryItems.find((item) =>
item.sockets?.socketEntries.find(
(socket) => socket.reusablePlugItems[0]?.plugItemHash === catalystPlugHash,
),
);
}

function findWeaponViaCatalystPCH(catalystPCH: number | undefined) {
const socketTypeHash = allsockets.find(
(sockets) => sockets.plugWhitelist?.find((plug) => plug.categoryHash === catalystPCH),
const socketTypeHash = allsockets.find((sockets) =>
sockets.plugWhitelist?.find((plug) => plug.categoryHash === catalystPCH),
)?.hash;

return inventoryItems.find(
(item) =>
item.sockets?.socketEntries.find((socket) => socket.socketTypeHash === socketTypeHash),
return inventoryItems.find((item) =>
item.sockets?.socketEntries.find((socket) => socket.socketTypeHash === socketTypeHash),
);
}

Expand All @@ -156,3 +164,11 @@ function findDummyItemWithSpecificName(DummyItemName: string) {
i.itemCategoryHashes?.includes(ItemCategoryHashes.Dummies),
);
}

function findAutoAppliedCatalystForCatalystPCH(catalystPCH: number) {
const plug = allsockets
.flatMap((socket) => socket.plugWhitelist || [])
.find((plug) => plug.categoryHash === catalystPCH);

return plug?.reinitializationPossiblePlugHashes?.[0];
}

0 comments on commit 093195f

Please sign in to comment.