From d915af2f3f48a16c2b71c809b90ea6db5ca5d2b0 Mon Sep 17 00:00:00 2001 From: Skillbert Date: Sat, 4 Mar 2023 18:03:52 +0100 Subject: [PATCH] <2013 cache investigation --- generated/cacheindex.d.ts | 2 +- generated/proctexture.d.ts | 8 ++++++ src/cache/openrs2loader.ts | 11 ++++---- src/opcodes/cacheindex.json | 4 +-- src/opcodes/proctexture.jsonc | 6 +++++ src/opdecoder.ts | 3 ++- src/scripts/extractfiles.ts | 4 ++- src/scripts/openrs2ids.ts | 47 ++++++++++++++++++++++------------- 8 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 generated/proctexture.d.ts create mode 100644 src/opcodes/proctexture.jsonc diff --git a/generated/cacheindex.d.ts b/generated/cacheindex.d.ts index 4f1be7b..a8febc6 100644 --- a/generated/cacheindex.d.ts +++ b/generated/cacheindex.d.ts @@ -4,7 +4,7 @@ export type cacheindex = { format: number, - timestamp: number, + timestamp: (number|0), flags: number, indices: { minor: number, diff --git a/generated/proctexture.d.ts b/generated/proctexture.d.ts new file mode 100644 index 0000000..fc7b85e --- /dev/null +++ b/generated/proctexture.d.ts @@ -0,0 +1,8 @@ +// GENERATED DO NOT EDIT +// This source data is located at '..\src\opcodes\proctexture.jsonc' +// run `npm run filetypes` to rebuild + +export type proctexture = { + op: number, + args: (Uint8Array), +}[]; diff --git a/src/cache/openrs2loader.ts b/src/cache/openrs2loader.ts index 5f4bedf..f521499 100644 --- a/src/cache/openrs2loader.ts +++ b/src/cache/openrs2loader.ts @@ -31,20 +31,21 @@ var cachelist: Promise | null = null; export function validOpenrs2Caches() { if (!cachelist) { cachelist = (async () => { - const openrs2Blacklist = [ - 423,//osrs cache wrongly labeled as rs3 + const openrs2Blacklist: number[] = [ + //some of these might actually be fine + 423,//osrs cache wrongly labeled as rs3? 623,//seems to have different builds in it 693,//wrong timestamp? - 621,619,618,620,617,//wrong timestamp/osrs? + 621, 619, 618, 620, 617,//wrong timestamp/osrs? 840,//multiple builds 734, 736, 733,//don't have items index 20, 19, 17, 13, 10, 9, 8, 7, 6, 5,//don't have items index ]; - let allcaches = await fetch(`${endpoint}/caches.json`).then(q => q.json()); + let allcaches: Openrs2CacheMeta[] = await fetch(`${endpoint}/caches.json`).then(q => q.json()); let checkedcaches = allcaches.filter(q => q.language == "en" && q.environment == "live" && !openrs2Blacklist.includes(q.id) && q.game == "runescape" && q.timestamp && q.builds.length != 0 - ).sort((a, b) => +new Date(b.timestamp!) - +new Date(a.timestamp!)); + ).sort((a, b) => b.builds[0].major - a.builds[0].major || (b.builds[0].minor ?? 0) - (a.builds[0].minor ?? 0) || +new Date(b.timestamp!) - +new Date(a.timestamp!)); return checkedcaches; })(); diff --git a/src/opcodes/cacheindex.json b/src/opcodes/cacheindex.json index 7cd8fcb..d93f2f0 100644 --- a/src/opcodes/cacheindex.json +++ b/src/opcodes/cacheindex.json @@ -1,9 +1,9 @@ ["struct", ["format","unsigned byte"], - ["timestamp","unsigned int"], + ["timestamp",["match",["ref","format"],{">=6":"uint","other":0}]], ["flags","unsigned byte"], ["$minorindex","0"], - ["indices",["chunkedarray","variable unsigned int", + ["indices",["chunkedarray",["match",["ref","format"],{">=7":"varuint","other":"ushort"}], [ ["minor",["accum","$minorindex","unsigned short"]] ], diff --git a/src/opcodes/proctexture.jsonc b/src/opcodes/proctexture.jsonc new file mode 100644 index 0000000..c421c2b --- /dev/null +++ b/src/opcodes/proctexture.jsonc @@ -0,0 +1,6 @@ +["nullarray",["struct", + ["op",["ref","$opcode"]], + ["args",["match",["ref","$opcode"],{ + "0x01":["buffer",8,"hex"] + }]] +]] \ No newline at end of file diff --git a/src/opdecoder.ts b/src/opdecoder.ts index 84d343b..ea7ba3d 100644 --- a/src/opdecoder.ts +++ b/src/opdecoder.ts @@ -115,6 +115,7 @@ function allParsers() { params: FileParser.fromJson(require("./opcodes/params.jsonc")), particles_0: FileParser.fromJson(require("./opcodes/particles_0.jsonc")), particles_1: FileParser.fromJson(require("./opcodes/particles_1.jsonc")), - audio: FileParser.fromJson(require("./opcodes/audio.jsonc")) + audio: FileParser.fromJson(require("./opcodes/audio.jsonc")), + proctexture: FileParser.fromJson(require("./opcodes/proctexture.jsonc")) } } \ No newline at end of file diff --git a/src/scripts/extractfiles.ts b/src/scripts/extractfiles.ts index 7041e1d..bd389b8 100644 --- a/src/scripts/extractfiles.ts +++ b/src/scripts/extractfiles.ts @@ -453,6 +453,7 @@ export const cacheFileJsonModes = constrainedMap()({ models: { parser: parse.models, lookup: noArchiveIndex(cacheMajors.models) }, oldmodels: { parser: parse.oldmodels, lookup: noArchiveIndex(cacheMajors.oldmodels) }, skeletons: { parser: parse.skeletalAnim, lookup: noArchiveIndex(cacheMajors.skeletalAnims) }, + proctextures: { parser: parse.proctexture, lookup: noArchiveIndex(cacheMajors.texturesOldPng) }, indices: { parser: parse.cacheIndex, lookup: indexfileIndex() }, rootindex: { parser: parse.rootCacheIndex, lookup: rootindexfileIndex() } @@ -503,7 +504,8 @@ export const cacheFileDecodeModes = constrainedMap()({ npcmodels: npcmodels, - ...(Object.fromEntries(Object.entries(cacheFileJsonModes).map(([k, v]) => [k, standardFile(v.parser, v.lookup)])) as Record) + ...(Object.fromEntries(Object.entries(cacheFileJsonModes) + .map(([k, v]) => [k, standardFile(v.parser, v.lookup)])) as Record) }); export async function extractCacheFiles(output: ScriptOutput, outdir: ScriptFS, source: CacheFileSource, args: { batched: boolean, batchlimit: number, mode: string, files: FileRange, edit: boolean, keepbuffers: boolean }) { diff --git a/src/scripts/openrs2ids.ts b/src/scripts/openrs2ids.ts index faf3ca9..8a0fd0a 100644 --- a/src/scripts/openrs2ids.ts +++ b/src/scripts/openrs2ids.ts @@ -5,11 +5,18 @@ import { ScriptOutput } from "../viewer/scriptsui"; export async function openrs2Ids(output: ScriptOutput, date: string, near: string, logcontents: boolean) { let allids = await validOpenrs2Caches(); if (date) { - let m = date.match(/20\d\d/); - if (!m) { throw new Error("4 digit year expected"); } - let year = +m[0]; - let enddate = new Date((year + 1) + ""); - let startdate = new Date(year + ""); + let startdate = new Date("");//nan + let enddate = new Date("");//nan + if (date.match(/^\d{4}$/)) { + startdate = new Date(date); + enddate = new Date((+date + 1) + ""); + } else if (date.match(/-/)) { + let parts = date.split("-"); + startdate = new Date(parts[0]); + enddate = new Date(parts[1]); + } + if (isNaN(+enddate)) { enddate = new Date("2100"); } + if (isNaN(+startdate)) { startdate = new Date("1900"); } allids = allids.filter(q => q.timestamp && new Date(q.timestamp) >= startdate && new Date(q.timestamp) <= enddate); } if (near) { @@ -34,24 +41,30 @@ export async function openrs2Ids(output: ScriptOutput, date: string, near: strin } let src = new Openrs2CacheSource(cache); try { - if (cache.builds[0].major >= 410) { - let index = await src.getCacheIndex(cacheMajors.index); - for (let i = 0; i < index.length; i++) { - let config = index[i]; - if (!config) { - line += " ".repeat(10); - } else { - let subcount = 0; - if (config.crc != 0 && config.subindexcount == 0) { + // if (cache.builds[0].major >= 410) { + let index = await src.getCacheIndex(cacheMajors.index); + for (let i = 0; i < index.length; i++) { + let config = index[i]; + if (!config) { + line += " ".repeat(10); + } else { + let subcount = 0; + if (config.crc != 0 && config.subindexcount == 0) { + try { let subindex = await src.getCacheIndex(config.minor); subcount = subindex.reduce((a, v) => a + (v ? 1 : 0), 0); - } else { - subcount = config.subindexcount; + } catch (e) { + subcount = NaN; } - line += ` ${subcount.toString().padStart(9)}`; + } else { + subcount = config.subindexcount; } + line += ` ${subcount.toString().padStart(9)}`; } } + // } + } catch (e) { + line += ` Error ${e}`; } finally { src.close(); }