From f1c880e7d030fe23dfab8a05700ca3b38b27a07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=AB=E8=B0=B7=E5=89=91=E4=BB=99?= Date: Thu, 21 Oct 2021 19:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E5=93=AA=E9=87=8C=E6=89=BENode?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=E5=91=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/extlist.ts | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ data/index.ts | 5 +++- data/run.bat | 2 +- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 data/extlist.ts diff --git a/data/extlist.ts b/data/extlist.ts new file mode 100644 index 00000000..18dcfd4b --- /dev/null +++ b/data/extlist.ts @@ -0,0 +1,63 @@ +export interface Extlist { + numMons: number; + numCards: number; + checksum: number; + entries: ExtlistEntry[]; +} + +export interface ExtlistEntry { + isCards: boolean; + id: number; + width: number; + height: number; + numFrames: number; + frameRate: number; + checksum: number; + size: number; + lastUpdate: number; + compressedSize: number; + compressedChecksum: number; +} + +export const Extlist = { + load(buf: Buffer): Extlist { + const numMons = buf.readUInt32LE(0); + const numCards = buf.readUInt32LE(4); + const sig = buf.readUInt32LE(8); + const checksum = buf.readUInt32LE(12); + if (sig !== 0x31545845) { // EXT1 + throw new Error('invalid extlist.bin signature'); + } + + const entries: ExtlistEntry[] = []; + const numEntries = numMons + numCards; + const compressedInfoOffset = 0x10 + numEntries * 24; + for (let i = 0; i < numEntries; i++) { + const flags = buf.readUInt16LE(0x10 + i * 24 + 0); + const isCards = (flags & 0x4000) !== 0; + const id = flags & ~0x4000; + if (id === 0) continue; + + entries.push({ + isCards, + id, + width: buf.readUInt16LE(0x10 + i * 24 + 6), + height: buf.readUInt16LE(0x10 + i * 24 + 8), + numFrames: buf.readUInt16LE(0x10 + i * 24 + 10), + frameRate: buf.readUInt16LE(0x10 + i * 24 + 12), + checksum: buf.readUInt16LE(0x10 + i * 24 + 14), + size: buf.readUInt32LE(0x10 + i * 24 + 16), + lastUpdate: buf.readUInt32LE(0x10 + i * 24 + 20), + compressedSize: buf.readUInt32LE(compressedInfoOffset + i * 8 + 0), + compressedChecksum: buf.readUInt32LE(compressedInfoOffset + i * 8 + 4), + }); + } + + return { + numMons, + numCards, + checksum, + entries, + }; + }, +}; diff --git a/data/index.ts b/data/index.ts index 6479ec74..1272b04b 100644 --- a/data/index.ts +++ b/data/index.ts @@ -1,4 +1,5 @@ import { basename } from "https://deno.land/std/path/mod.ts"; +import { Extlist } from './extlist.ts'; const regions = [ {path: 'pad', regionID: 'JA', baseJsonURL: 'https://dl.padsv.gungho.jp/base_adr.json'}, {path: 'padEN', regionID: 'NA', baseJsonURL: 'https://dl-na.padsv.gungho.jp/base-na-adr.json'}, @@ -27,4 +28,6 @@ for (const region of regions) { const extdllistUrl = `${baseJsonData.efl}/extdllist.bin`; console.log(`正在下载 ${extdllistUrl}`); const extdllistResponse = await downloadFile(extdllistUrl, region.path); -} \ No newline at end of file + const extlist = Extlist.load(extlistResponse); + extlist.entries.forEach((item)=>{console.log(item)}); +} \ No newline at end of file diff --git a/data/run.bat b/data/run.bat index f9fac20a..174e8803 100644 --- a/data/run.bat +++ b/data/run.bat @@ -1,2 +1,2 @@ @echo off -deno run --allow-net --allow-read --allow-write --unstable index.js \ No newline at end of file +deno run --allow-net --allow-read --allow-write --unstable index.ts \ No newline at end of file