silphscope 1.2.10 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "silphscope",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "description": "A firered/leafgreen ROM asset extractor for use in web applications",
5
5
  "main": "main.js",
6
6
  "exports": {
@@ -6,6 +6,9 @@ export const firered = {
6
6
  monFrontSprites: 0x2350AC,
7
7
  monBackSprites: 0x23654C,
8
8
  monPalettes: 0x23730C,
9
- monShinyPalettes: 0x2380CC
9
+ monShinyPalettes: 0x2380CC,
10
+ monIconTable: 0x3D37A0,
11
+ monIconPaletteIndices: 0x3D3E80,
12
+ monIconPaletteTable: 0x3D4038,
10
13
  } // if this works out... well hehe... :D
11
14
  }
@@ -5,6 +5,8 @@ import { extract } from "../extract.js";
5
5
  import { PNG } from "pngjs";
6
6
  import fs from "fs";
7
7
  import { render4bppImage } from "../render-4bpp-image.js";
8
+ import { resolveMonIcon } from "./resolvers/mon-icon-resolver.js";
9
+ import { resolveMonIconPalette } from "./resolvers/mon-icon-palette-resolver.js";
8
10
 
9
11
  const streamToBuffer = (stream) => new Promise((resolve, reject) => {
10
12
  const chunks = [];
@@ -13,7 +15,7 @@ const streamToBuffer = (stream) => new Promise((resolve, reject) => {
13
15
  stream.on("error", reject);
14
16
  });
15
17
 
16
- export async function renderMonIcon(monName, mons, assets, iconPalettes, rom, options = {}) {
18
+ export async function renderMonIcon(monName, mons, reader, rom, options = {}) {
17
19
  const { outputDir = null } = options;
18
20
 
19
21
  if (!rom || !(rom instanceof Uint8Array || Buffer.isBuffer(rom))) {
@@ -25,13 +27,12 @@ export async function renderMonIcon(monName, mons, assets, iconPalettes, rom, op
25
27
  throw new Error(`Missing mon entry for ${monName}`);
26
28
  }
27
29
 
28
- const iconAsset = assets.find(a => a.name === mon.Icon);
29
- if (!iconAsset) throw new Error(`Missing icon asset for ${monName}`);
30
+ const iconAsset = resolveMonIcon(mon, reader);
31
+ const iconPalette = resolveMonIconPalette(mon, reader);
32
+ if (!iconAsset || !iconPalette) throw new Error(`Missing icon asset for ${monName}`);
30
33
 
31
34
  const iconData = extract(iconAsset, rom);
32
- const palIndex = Number(mon.iconPalIndex);
33
- const palSize = 32;
34
- const rawIconPalData = extract(iconPalettes, rom);
35
+ const rawIconPalData = extract(iconPalette, rom);
35
36
  const width = 32;
36
37
  const height = 64;
37
38
 
@@ -40,8 +41,6 @@ export async function renderMonIcon(monName, mons, assets, iconPalettes, rom, op
40
41
  paletteData: rawIconPalData.data,
41
42
  width,
42
43
  height,
43
- paletteOffset: palIndex * palSize,
44
- paletteSize: palSize
45
44
  });
46
45
 
47
46
  const frameHeight = 32;
@@ -31,9 +31,7 @@ export async function renderMon(monName, mons, assets, reader, rom, options = {}
31
31
  }
32
32
 
33
33
  if (icon === true) {
34
- const comboPal = assets.find(a => a.name === "gMonIconPalettes");
35
- if (!comboPal) throw new Error("Missing gMonIconPalettes asset");
36
- await renderMonIcon(monName, mons, assets, comboPal, rom, { outputDir });
34
+ await renderMonIcon(monName, mons, reader, rom, { outputDir });
37
35
  }
38
36
  if (footprint === true) {
39
37
  await renderMonFoot(monName, mons, assets, rom, { outputDir });
@@ -0,0 +1,9 @@
1
+ export function resolveMonIconPalette(mon, reader) { // I kinda think this might be wrong... but erm who knows :o maybe I got it right first try lol
2
+ const indexTable = reader.getTable("monIconPaletteIndices");
3
+ const paletteIndex = reader.readU8(indexTable + mon.index);
4
+ const paletteTable = reader.getTable("monIconPaletteTable");
5
+ const palettePtr = reader.readPointer(paletteTable + paletteIndex * 4);
6
+ return {
7
+ offset: palettePtr
8
+ };
9
+ }
@@ -0,0 +1,8 @@
1
+ export function resolveMonIcon(mon, reader) {
2
+ const table = reader.getTable("monIconTable");
3
+ const entryOffset = table + mon.index * 4;
4
+ const ptr = reader.readPointer(entryOffset);
5
+ return {
6
+ offset: ptr
7
+ };
8
+ }