// Reads every map icon the game's own script can place (data/main.scm) and writes online/mapicons.json, // so the online map shows all locations although missions do not run. Usage: bun tools/map-icons.ts import { readFileSync, writeFileSync } from "node:fs"; const dir = process.argv[2]; if (!dir) throw new Error("usage: bun tools/map-icons.ts "); const d = readFileSync(`${dir}/data/main.scm`); const OPS = new Set([0x02a7, 0x02a8, 0x04ce, 0x0570]); const seen = new Map(); for (let i = 0; i + 24 < d.length; i++) { if (!OPS.has(d.readUInt16LE(i))) continue; if (d[i + 2] !== 6 || d[i + 7] !== 6 || d[i + 12] !== 6) continue; const t = d[i + 17]; const sprite = t === 4 ? d.readInt8(i + 18) : t === 5 ? d.readInt16LE(i + 18) : t === 1 ? d.readInt32LE(i + 18) : -1; if (sprite <= 0 || sprite > 60) continue; const [x, y, z] = [d.readFloatLE(i + 3), d.readFloatLE(i + 8), d.readFloatLE(i + 13)]; if (Math.abs(x) > 3000 || Math.abs(y) > 3000) continue; seen.set(`${sprite}:${Math.round(x)}:${Math.round(y)}`, { sprite, x: +x.toFixed(1), y: +y.toFixed(1), z: +z.toFixed(1) }); } const icons = [...seen.values()].sort((a, b) => a.sprite - b.sprite); writeFileSync(`${dir}/online/mapicons.json`, JSON.stringify({ icons })); const count: Record = {}; for (const c of icons) count[c.sprite] = (count[c.sprite] || 0) + 1; console.log(icons.length, JSON.stringify(count));