risupack 0.1.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unpack-risum-8Iw-UEO2.js","names":[],"sources":["../src/bundle.ts","../src/build-charx.ts","../src/inspect-risusave.ts","../src/unpack-charx.ts","../src/unpack-risum.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\nconst REQUIRE_PATTERN = /require\\s*\\(?[\"']([^\"']+)[\"']\\)?/g;\n\ninterface BundleState {\n entryPath: string;\n hoistedComments: string[];\n includedModules: Set<string>;\n preloads: string[];\n totalInputBytes: number;\n}\n\nfunction formatBytes(bytes: number): string {\n if (bytes === 0) {\n return \"0 B\";\n }\n\n const base = 1024;\n const sizes = [\"B\", \"KB\", \"MB\"];\n const index = Math.floor(Math.log(bytes) / Math.log(base));\n return `${Number.parseFloat((bytes / Math.pow(base, index)).toFixed(2))} ${sizes[index]}`;\n}\n\nfunction resolveModulePath(moduleName: string): string {\n return `${moduleName.replace(/\\./g, \"/\")}.lua`;\n}\n\nfunction minifyLua(content: string, hoistedComments: string[]): string {\n const tokenPattern =\n /(--\\[(=*)\\[[\\s\\S]*?\\]\\2\\])|(--.*)|(\\[(=*)\\[[\\s\\S]*?\\]\\5\\])|(\"([^\"\\\\]|\\\\.)*\")|('([^'\\\\]|\\\\.)*')/g;\n\n return content\n .replace(\n tokenPattern,\n (match: string, longComment?: string, _equals?: string, shortComment?: string) => {\n if (!longComment && !shortComment) {\n return match;\n }\n if (shortComment?.startsWith(\"--!\") || (longComment && /^--\\[(=*)\\[!/.test(match))) {\n hoistedComments.push(match);\n }\n return \" \";\n },\n )\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter((line) => line.length > 0)\n .join(\"\\n\");\n}\n\nfunction processModule(moduleName: string, state: BundleState): void {\n if (state.includedModules.has(moduleName)) {\n return;\n }\n\n const rootDirectory = path.dirname(path.resolve(state.entryPath));\n const modulePath = path.join(rootDirectory, resolveModulePath(moduleName));\n if (!fs.existsSync(modulePath)) {\n console.warn(`Warning: Module '${moduleName}' not found`);\n return;\n }\n\n const rawContent = fs.readFileSync(modulePath, \"utf8\");\n state.includedModules.add(moduleName);\n state.totalInputBytes += fs.statSync(modulePath).size;\n\n for (const match of rawContent.matchAll(new RegExp(REQUIRE_PATTERN.source, \"g\"))) {\n const dependency = match[1];\n if (dependency) {\n processModule(dependency, state);\n }\n }\n\n const minifiedContent = minifyLua(rawContent, state.hoistedComments);\n state.preloads.push(`package.preload[\"${moduleName}\"]=function(...)${minifiedContent} end`);\n}\n\nfunction bundleLua(entryPath: string, outputArgument: string): string {\n const resolvedEntryPath = path.resolve(entryPath);\n if (!fs.existsSync(resolvedEntryPath)) {\n throw new Error(`Entry file not found: ${entryPath}`);\n }\n\n let outputPath = path.resolve(outputArgument);\n if (fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory()) {\n outputPath = path.join(outputPath, path.basename(resolvedEntryPath));\n }\n if (path.extname(outputPath) !== \".lua\") {\n outputPath += \".lua\";\n }\n\n const state: BundleState = {\n entryPath: resolvedEntryPath,\n hoistedComments: [],\n includedModules: new Set(),\n preloads: [],\n totalInputBytes: fs.statSync(resolvedEntryPath).size,\n };\n const mainContent = fs.readFileSync(resolvedEntryPath, \"utf8\");\n\n for (const match of mainContent.matchAll(new RegExp(REQUIRE_PATTERN.source, \"g\"))) {\n const moduleName = match[1];\n if (moduleName) {\n processModule(moduleName, state);\n }\n }\n\n const mainMinified = minifyLua(mainContent, state.hoistedComments);\n const hoisted = state.hoistedComments.length > 0 ? `${state.hoistedComments.join(\"\\n\")}\\n` : \"\";\n const output = `${hoisted}${state.preloads.join(\"\\n\")}\\n${mainMinified}`;\n\n fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n fs.writeFileSync(outputPath, output, \"utf8\");\n\n const outputBytes = fs.statSync(outputPath).size;\n const reduction = ((state.totalInputBytes - outputBytes) / state.totalInputBytes) * 100;\n console.log(\n `Bundled ${path.relative(process.cwd(), resolvedEntryPath)} to ${path.relative(process.cwd(), outputPath)}`,\n );\n console.log(\n `${state.includedModules.size} modules, ${formatBytes(state.totalInputBytes)} to ${formatBytes(outputBytes)}, ${reduction.toFixed(2)}% reduction`,\n );\n return outputPath;\n}\n\nexport { bundleLua };\n","import crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport zlib from \"node:zlib\";\n\nimport { bundleLua } from \"./bundle.js\";\n\nconst DEFAULT_ICON = Buffer.from(\n \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEAQH/69v17QAAAABJRU5ErkJggg==\",\n \"base64\",\n);\nconst RPACK_MAP_PATH = path.join(\n path.dirname(fileURLToPath(import.meta.url)),\n \"..\",\n \"vendor\",\n \"rpack\",\n \"rpack_map.bin\",\n);\n\nconst CRC32_TABLE = (() => {\n const table = new Uint32Array(256);\n for (let index = 0; index < table.length; index += 1) {\n let value = index;\n for (let bit = 0; bit < 8; bit += 1) {\n if ((value & 1) !== 0) {\n value = 0xedb88320 ^ (value >>> 1);\n } else {\n value >>>= 1;\n }\n }\n table[index] = value >>> 0;\n }\n return table;\n})();\n\nfunction assert(condition: unknown, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\nfunction calculateCRC32(data) {\n let value = 0xffffffff;\n for (const byte of data) {\n value = CRC32_TABLE[(value ^ byte) & 0xff] ^ (value >>> 8);\n }\n return (value ^ 0xffffffff) >>> 0;\n}\n\nfunction createUUID(seed) {\n const bytes = crypto.createHash(\"sha256\").update(seed).digest().subarray(0, 16);\n bytes[6] = (bytes[6] & 0x0f) | 0x50;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = bytes.toString(\"hex\");\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\nfunction detectImageType(data) {\n if (data.subarray(0, 8).equals(Buffer.from(\"89504e470d0a1a0a\", \"hex\"))) {\n return \"PNG\";\n }\n if (data.subarray(0, 3).equals(Buffer.from(\"ffd8ff\", \"hex\"))) {\n return \"JPEG\";\n }\n if (\n data.subarray(0, 6).toString(\"ascii\") === \"GIF87a\" ||\n data.subarray(0, 6).toString(\"ascii\") === \"GIF89a\"\n ) {\n return \"GIF\";\n }\n if (\n data.subarray(0, 4).toString(\"ascii\") === \"RIFF\" &&\n data.subarray(8, 12).toString(\"ascii\") === \"WEBP\"\n ) {\n return \"WEBP\";\n }\n return \"Unknown\";\n}\n\nfunction getAssetCategory(extension) {\n const audio = new Set([\"flac\", \"mp3\", \"ogg\", \"wav\"]);\n const code = new Set([\"js\", \"lua\", \"ts\"]);\n const fonts = new Set([\"otf\", \"ttf\", \"woff\", \"woff2\"]);\n const images = new Set([\"avif\", \"gif\", \"jpeg\", \"jpg\", \"png\", \"webp\"]);\n const models = new Set([\"mmd\", \"obj\"]);\n const video = new Set([\"avi\", \"mkv\", \"mov\", \"mp4\", \"webm\"]);\n\n if (audio.has(extension)) {\n return \"audio\";\n }\n if (code.has(extension)) {\n return \"code\";\n }\n if (fonts.has(extension)) {\n return \"fonts\";\n }\n if (images.has(extension)) {\n return \"image\";\n }\n if (models.has(extension)) {\n return \"model\";\n }\n if (extension === \"onnx\" || extension === \"safetensors\" || extension === \"cpkt\") {\n return \"ai\";\n }\n if (video.has(extension)) {\n return \"video\";\n }\n return \"other\";\n}\n\nfunction readSource(manifestDirectory, source, label) {\n if (typeof source === \"string\") {\n return fs.readFileSync(path.resolve(manifestDirectory, source), \"utf8\");\n }\n assert(source && typeof source === \"object\", `${label} must be a file path or source object`);\n if (typeof source.content === \"string\") {\n return source.content;\n }\n assert(typeof source.file === \"string\", `${label}.file must be a string`);\n return fs.readFileSync(path.resolve(manifestDirectory, source.file), \"utf8\");\n}\n\nfunction sanitizeArchiveName(name: string): string {\n const sanitized = Array.from(name, (character) =>\n character.charCodeAt(0) < 32 ? \"_\" : character,\n )\n .join(\"\")\n .replace(/[<>:\"/\\\\|?*]/g, \"_\")\n .trim();\n return sanitized.slice(0, 100) || \"asset\";\n}\n\nfunction sortKeysDeep(value) {\n if (Array.isArray(value)) {\n return value.map(sortKeysDeep);\n }\n if (value && typeof value === \"object\" && !Buffer.isBuffer(value)) {\n const sorted = {};\n for (const key of Object.keys(value).sort()) {\n if (value[key] !== undefined) {\n sorted[key] = sortKeysDeep(value[key]);\n }\n }\n return sorted;\n }\n return value;\n}\n\nfunction parseFrontmatter(content, fileName) {\n const normalized = content.replace(/\\r\\n/g, \"\\n\");\n assert(normalized.startsWith(\"---\\n\"), `Missing frontmatter in ${fileName}`);\n const end = normalized.indexOf(\"\\n---\\n\", 4);\n assert(end !== -1, `Unclosed frontmatter in ${fileName}`);\n const metadata: Record<string, string | boolean> = {};\n for (const line of normalized.slice(4, end).split(\"\\n\")) {\n if (line.trim() === \"\") {\n continue;\n }\n const separator = line.indexOf(\":\");\n assert(separator !== -1, `Invalid frontmatter line in ${fileName}: ${line}`);\n const key = line.slice(0, separator).trim();\n const rawValue = line.slice(separator + 1).trim();\n assert(key !== \"\", `Empty frontmatter key in ${fileName}`);\n if (rawValue === \"true\") {\n metadata[key] = true;\n } else if (rawValue === \"false\") {\n metadata[key] = false;\n } else {\n metadata[key] = rawValue;\n }\n }\n return {\n body: normalized.slice(end + 5),\n metadata,\n };\n}\n\nfunction parseRegexBody(content, fileName) {\n const normalized = content.replace(/^\\n+/, \"\").replace(/\\n$/, \"\");\n const match = normalized.match(/^IN:\\s*\\n([\\s\\S]*?)\\nOUT:\\s*(?:\\n([\\s\\S]*))?$/);\n assert(match, `Invalid regex body in ${fileName}`);\n return {\n in: match[1],\n out: match[2] ?? \"\",\n };\n}\n\nfunction parseRegexDocument(content, fileName) {\n const { body, metadata } = parseFrontmatter(content, fileName);\n const parsed = parseRegexBody(body, fileName);\n return {\n ableFlag: metadata.ableFlag ?? true,\n comment: metadata.comment ?? \"\",\n flag: metadata.flag,\n in: parsed.in,\n out: parsed.out,\n type: metadata.type ?? \"editdisplay\",\n };\n}\n\nfunction buildRegexScripts(manifestDirectory, regexGroups: any[] = []) {\n const scripts: any[] = [];\n for (const group of regexGroups) {\n if (typeof group === \"string\") {\n scripts.push(\n parseRegexDocument(readSource(manifestDirectory, group, `regex ${group}`), group),\n );\n continue;\n }\n if (group.in !== undefined || group.out !== undefined) {\n assert(\n typeof group.in === \"string\" && typeof group.out === \"string\",\n \"Inline regex entries require in and out\",\n );\n scripts.push({\n ableFlag: group.ableFlag ?? true,\n comment: group.comment ?? \"\",\n flag: group.flag,\n in: group.in,\n out: group.out,\n type: group.type ?? \"editdisplay\",\n });\n continue;\n }\n\n assert(\n typeof group.file === \"string\",\n \"Regex entries require a file path, or inline in and out fields\",\n );\n scripts.push(\n parseRegexDocument(\n readSource(manifestDirectory, group.file, `regex ${group.file}`),\n group.file,\n ),\n );\n }\n return scripts;\n}\n\nfunction buildLorebook(manifest, manifestDirectory) {\n const folderKeys = new Map<string, string>();\n const folderNames = new Set<string>(manifest.folders ?? []);\n for (const entry of manifest.lorebook ?? []) {\n if (entry.folder) {\n folderNames.add(entry.folder);\n }\n }\n for (const name of folderNames) {\n folderKeys.set(\n name,\n `\\uf000folder:${createUUID(`${manifest.namespace ?? manifest.name}:folder:${name}`)}`,\n );\n }\n\n const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), \"risums-charx-lorebook-\"));\n try {\n const lorebook = (manifest.lorebook ?? []).map((entry, index) => {\n let content;\n if (entry.bundle) {\n assert(\n typeof entry.file === \"string\",\n `Bundled lorebook ${entry.comment ?? index + 1} requires a file`,\n );\n const entryPath = path.resolve(manifestDirectory, entry.file);\n const outputPath = entry.bundleOutput\n ? path.resolve(manifestDirectory, entry.bundleOutput)\n : path.join(temporaryDirectory, `lorebook-${index}.lua`);\n content = bundleLua(entryPath, outputPath);\n } else {\n content = readSource(\n manifestDirectory,\n entry,\n `lorebook ${entry.comment ?? entry.file ?? \"\"}`,\n );\n }\n return {\n activationPercent: entry.activationPercent,\n alwaysActive: entry.alwaysActive ?? false,\n bookVersion: entry.bookVersion ?? 2,\n comment: entry.comment ?? path.basename(entry.file ?? \"Lorebook\"),\n content,\n extentions: entry.extentions,\n folder: entry.folder ? folderKeys.get(entry.folder) : undefined,\n insertorder: entry.insertOrder ?? 100,\n key: entry.key ?? \"\",\n mode: entry.mode ?? \"normal\",\n secondkey: entry.secondaryKey ?? \"\",\n selective: entry.selective ?? false,\n useRegex: entry.useRegex ?? false,\n };\n });\n\n for (const name of folderNames) {\n lorebook.push({\n alwaysActive: false,\n bookVersion: 2,\n comment: name,\n content: \"\",\n insertorder: 100,\n key: folderKeys.get(name),\n mode: \"folder\",\n secondkey: \"\",\n selective: false,\n useRegex: false,\n });\n }\n return lorebook;\n } finally {\n fs.rmSync(temporaryDirectory, { force: true, recursive: true });\n }\n}\n\nfunction readBundledLua(entryPath: string, outputPath: string): string {\n bundleLua(entryPath, outputPath);\n return fs.readFileSync(outputPath, \"utf8\");\n}\n\nfunction buildTriggers(manifest, manifestDirectory) {\n const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), \"risums-charx-\"));\n try {\n return (manifest.triggers ?? []).map((trigger, index) => {\n let effect = trigger.effect;\n if (trigger.lua) {\n const entryPath = path.resolve(manifestDirectory, trigger.lua);\n let code;\n if (trigger.bundle ?? true) {\n const outputPath = trigger.bundleOutput\n ? path.resolve(manifestDirectory, trigger.bundleOutput)\n : path.join(temporaryDirectory, `trigger-${index}.lua`);\n code = readBundledLua(entryPath, outputPath);\n } else {\n code = fs.readFileSync(entryPath, \"utf8\");\n }\n effect = [{ code, type: \"triggerlua\" }];\n }\n assert(Array.isArray(effect), `Trigger ${index + 1} requires lua or effect`);\n return {\n comment: trigger.comment ?? \"\",\n conditions: trigger.conditions ?? [],\n effect,\n lowLevelAccess: trigger.lowLevelAccess,\n type: trigger.type ?? \"start\",\n };\n });\n } finally {\n fs.rmSync(temporaryDirectory, { force: true, recursive: true });\n }\n}\n\nfunction createRisuM(module, encodeMap) {\n const payload = Buffer.from(\n JSON.stringify(sortKeysDeep({ module, type: \"risuModule\" }), null, 2),\n \"utf8\",\n );\n const encoded = Buffer.allocUnsafe(payload.length);\n for (let index = 0; index < payload.length; index += 1) {\n encoded[index] = encodeMap[payload[index]];\n }\n const header = Buffer.alloc(6);\n header.writeUInt8(111, 0);\n header.writeUInt8(0, 1);\n header.writeUInt32LE(encoded.length, 2);\n return Buffer.concat([header, encoded, Buffer.from([0])]);\n}\n\nfunction createAssetFiles(manifest, manifestDirectory) {\n const cardAssets: any[] = [];\n const files: Array<{ data: Buffer; name: string }> = [];\n const takenNames = new Set<string>();\n\n function addAsset({ data, extension, name, type }) {\n const category = getAssetCategory(extension);\n const baseDirectory = `assets/${type === \"icon\" ? \"icon\" : \"other\"}/${category}`;\n const baseName = sanitizeArchiveName(name);\n let archiveName = baseName;\n let suffix = 0;\n while (takenNames.has(archiveName)) {\n suffix += 1;\n archiveName = `${baseName}_${suffix}`;\n }\n const archivePath = `${baseDirectory}/${archiveName}.${extension}`;\n takenNames.add(archiveName);\n cardAssets.push({\n ext: extension,\n name,\n type,\n uri: `embeded://${archivePath}`,\n });\n files.push({ data, name: archivePath });\n files.push({\n data: Buffer.from(JSON.stringify({ type: detectImageType(data) }, null, 2)),\n name: `x_meta/${archiveName}.json`,\n });\n }\n\n if (manifest.icon) {\n const iconPath = path.resolve(manifestDirectory, manifest.icon);\n const extension = path.extname(iconPath).slice(1).toLowerCase() || \"png\";\n addAsset({ data: fs.readFileSync(iconPath), extension, name: \"main\", type: \"icon\" });\n } else {\n addAsset({ data: DEFAULT_ICON, extension: \"png\", name: \"main\", type: \"icon\" });\n }\n\n for (const asset of manifest.assets ?? []) {\n assert(typeof asset.file === \"string\", \"Asset file must be a string\");\n const assetPath = path.resolve(manifestDirectory, asset.file);\n const extension = (asset.extension ?? path.extname(assetPath).slice(1)).toLowerCase();\n assert(extension !== \"\", `Cannot determine extension for ${asset.file}`);\n assert(/^[a-z0-9]+$/.test(extension), `Invalid extension for ${asset.file}: ${extension}`);\n addAsset({\n data: fs.readFileSync(assetPath),\n extension,\n name: asset.name ?? path.basename(assetPath, path.extname(assetPath)),\n type: \"x-risu-asset\",\n });\n }\n return { cardAssets, files };\n}\n\nfunction createCard(manifest, lorebook, cardAssets) {\n const entries = lorebook.map((entry) => ({\n case_sensitive: entry.extentions?.risu_case_sensitive ?? false,\n comment: entry.comment,\n constant: entry.alwaysActive,\n content: entry.content,\n enabled: true,\n extensions: {\n ...entry.extentions,\n risu_activationPercent: entry.activationPercent,\n risu_loreCache: entry.loreCache,\n },\n folder: entry.folder,\n insertion_order: entry.insertorder,\n keys: entry.key.split(\",\").map((key) => key.trim()),\n mode: entry.mode,\n name: entry.comment,\n secondary_keys: entry.selective\n ? entry.secondkey.split(\",\").map((key) => key.trim())\n : undefined,\n selective: entry.selective,\n use_regex: entry.useRegex,\n }));\n return {\n data: {\n alternate_greetings: [],\n assets: cardAssets,\n character_book: {\n entries,\n extensions: { risu_fullWordMatching: false },\n },\n character_version: manifest.version ?? \"\",\n creation_date: 0,\n creator: manifest.creator ?? \"\",\n creator_notes: manifest.description ?? \"\",\n description: \"\",\n extensions: {\n moduleNoneImage: manifest.icon ? undefined : true,\n risuai: {\n additionalText: \"\",\n backgroundHTML: manifest.CSS\n ? readSource(path.dirname(manifest.__path), manifest.CSS, \"CSS\")\n : \"\",\n bias: [],\n defaultVariables: \"\",\n hideChatIcon: manifest.hideIcon ?? false,\n inlayViewScreen: false,\n largePortrait: false,\n license: manifest.license ?? \"\",\n lorePlus: false,\n lowLevelAccess: manifest.lowLevelAccess ?? false,\n moduleNamespace: manifest.namespace,\n newGenData: undefined,\n prebuiltAssetCommand: \"\",\n prebuiltAssetExclude: [],\n prebuiltAssetStyle: \"\",\n sdData: [],\n toggles: manifest.toggles\n ? readSource(path.dirname(manifest.__path), manifest.toggles, \"toggles\")\n : \"\",\n utilityBot: false,\n viewScreen: \"none\",\n virtualscript: \"\",\n vits: {},\n },\n },\n first_mes: \"\",\n group_only_greetings: [],\n mes_example: \"\",\n modification_date: process.env.SOURCE_DATE_EPOCH\n ? Number(process.env.SOURCE_DATE_EPOCH)\n : Math.floor(Date.now() / 1000),\n name: manifest.name,\n nickname: \"\",\n personality: \"\",\n post_history_instructions: \"\",\n scenario: \"\",\n source: [],\n system_prompt: \"\",\n tags: manifest.tags ?? [],\n },\n spec: \"chara_card_v3\",\n spec_version: \"3.0\",\n };\n}\n\nfunction getDOSDateTime(date) {\n const year = Math.max(1980, date.getUTCFullYear());\n return {\n date: ((year - 1980) << 9) | ((date.getUTCMonth() + 1) << 5) | date.getUTCDate(),\n time:\n (date.getUTCHours() << 11) |\n (date.getUTCMinutes() << 5) |\n Math.floor(date.getUTCSeconds() / 2),\n };\n}\n\nfunction createZIP(files, timestamp) {\n assert(files.length <= 0xffff, \"ZIP contains too many files\");\n const centralRecords: Buffer[] = [];\n const localRecords: Buffer[] = [];\n let offset = 0;\n const { date, time } = getDOSDateTime(timestamp);\n\n for (const file of files) {\n const data = Buffer.from(file.data);\n const compressed = zlib.deflateRawSync(data, { level: 6 });\n const fileName = Buffer.from(file.name.replace(/\\\\/g, \"/\"), \"utf8\");\n const CRC32 = calculateCRC32(data);\n assert(\n data.length <= 0xffffffff && compressed.length <= 0xffffffff,\n `${file.name} exceeds ZIP32 limits`,\n );\n\n const localHeader = Buffer.alloc(30);\n localHeader.writeUInt32LE(0x04034b50, 0);\n localHeader.writeUInt16LE(20, 4);\n localHeader.writeUInt16LE(0x0800, 6);\n localHeader.writeUInt16LE(8, 8);\n localHeader.writeUInt16LE(time, 10);\n localHeader.writeUInt16LE(date, 12);\n localHeader.writeUInt32LE(CRC32, 14);\n localHeader.writeUInt32LE(compressed.length, 18);\n localHeader.writeUInt32LE(data.length, 22);\n localHeader.writeUInt16LE(fileName.length, 26);\n localHeader.writeUInt16LE(0, 28);\n localRecords.push(localHeader, fileName, compressed);\n\n const centralHeader = Buffer.alloc(46);\n centralHeader.writeUInt32LE(0x02014b50, 0);\n centralHeader.writeUInt16LE(20, 4);\n centralHeader.writeUInt16LE(20, 6);\n centralHeader.writeUInt16LE(0x0800, 8);\n centralHeader.writeUInt16LE(8, 10);\n centralHeader.writeUInt16LE(time, 12);\n centralHeader.writeUInt16LE(date, 14);\n centralHeader.writeUInt32LE(CRC32, 16);\n centralHeader.writeUInt32LE(compressed.length, 20);\n centralHeader.writeUInt32LE(data.length, 24);\n centralHeader.writeUInt16LE(fileName.length, 28);\n centralHeader.writeUInt16LE(0, 30);\n centralHeader.writeUInt16LE(0, 32);\n centralHeader.writeUInt16LE(0, 34);\n centralHeader.writeUInt16LE(0, 36);\n centralHeader.writeUInt32LE(0, 38);\n centralHeader.writeUInt32LE(offset, 42);\n centralRecords.push(centralHeader, fileName);\n offset += localHeader.length + fileName.length + compressed.length;\n }\n\n const centralDirectory = Buffer.concat(centralRecords);\n const end = Buffer.alloc(22);\n end.writeUInt32LE(0x06054b50, 0);\n end.writeUInt16LE(0, 4);\n end.writeUInt16LE(0, 6);\n end.writeUInt16LE(files.length, 8);\n end.writeUInt16LE(files.length, 10);\n end.writeUInt32LE(centralDirectory.length, 12);\n end.writeUInt32LE(offset, 16);\n end.writeUInt16LE(0, 20);\n return Buffer.concat([...localRecords, centralDirectory, end]);\n}\n\nfunction buildCharX(manifestPath: string, outputArgument?: string): string {\n const resolvedManifestPath = path.resolve(manifestPath);\n const manifestDirectory = path.dirname(resolvedManifestPath);\n const manifest = JSON.parse(fs.readFileSync(resolvedManifestPath, \"utf8\"));\n manifest.__path = resolvedManifestPath;\n assert(typeof manifest.name === \"string\" && manifest.name !== \"\", \"Manifest name is required\");\n\n const lorebook = buildLorebook(manifest, manifestDirectory);\n const regex = buildRegexScripts(manifestDirectory, manifest.regex);\n const trigger = buildTriggers(manifest, manifestDirectory);\n const { cardAssets, files: assetFiles } = createAssetFiles(manifest, manifestDirectory);\n const card = createCard(manifest, lorebook, cardAssets);\n const module = {\n description: `Module for ${manifest.name}`,\n id: createUUID(`${manifest.namespace ?? manifest.name}:module`),\n lorebook,\n name: `${manifest.name} Module`,\n regex,\n trigger,\n };\n\n const map = fs.readFileSync(RPACK_MAP_PATH);\n assert(map.length >= 256, `Invalid RPack map: ${RPACK_MAP_PATH}`);\n const files = [\n ...assetFiles,\n { data: Buffer.from(JSON.stringify(sortKeysDeep(card), null, 2)), name: \"card.json\" },\n { data: createRisuM(sortKeysDeep(module), map.subarray(0, 256)), name: \"module.risum\" },\n ].sort((left, right) => left.name.localeCompare(right.name));\n\n const outputPath = outputArgument\n ? path.resolve(outputArgument)\n : path.resolve(\n manifestDirectory,\n manifest.output ?? `../dist/${sanitizeArchiveName(manifest.name)}.charx`,\n );\n fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n const timestamp = process.env.SOURCE_DATE_EPOCH\n ? new Date(Number(process.env.SOURCE_DATE_EPOCH) * 1000)\n : new Date();\n fs.writeFileSync(outputPath, createZIP(files, timestamp));\n console.log(`Built ${path.relative(process.cwd(), outputPath)} (${files.length} files)`);\n return outputPath;\n}\n\nexport { buildCharX };\n","import zlib from \"node:zlib\";\n\nconst MAGIC = Buffer.from(\"RISUSAVE\\0\");\nconst MODULE_BLOCK_TYPE = 5;\n\ninterface ModuleRecord {\n id?: unknown;\n name?: unknown;\n namespace?: unknown;\n [key: string]: unknown;\n}\n\nfunction parseModuleBlock(database: Buffer): ModuleRecord[] {\n if (!database.subarray(0, MAGIC.length).equals(MAGIC)) {\n throw new Error(\"Invalid RISUSAVE header\");\n }\n\n let offset = MAGIC.length;\n while (offset < database.length) {\n if (offset + 3 > database.length) {\n throw new Error(`Truncated block header at byte ${offset}`);\n }\n const type = database[offset];\n const compressed = database[offset + 1] === 1;\n const nameLength = database[offset + 2];\n offset += 3;\n\n if (offset + nameLength + 4 > database.length) {\n throw new Error(`Truncated block name at byte ${offset}`);\n }\n const name = database.subarray(offset, offset + nameLength).toString(\"utf8\");\n offset += nameLength;\n const contentLength = database.readUInt32LE(offset);\n offset += 4;\n\n if (offset + contentLength > database.length) {\n throw new Error(`Truncated ${name} block at byte ${offset}`);\n }\n let content = database.subarray(offset, offset + contentLength);\n offset += contentLength;\n\n if (type !== MODULE_BLOCK_TYPE) {\n continue;\n }\n if (compressed) {\n content = zlib.gunzipSync(content);\n }\n return JSON.parse(content.toString(\"utf8\")) as ModuleRecord[];\n }\n throw new Error(\"RISUSAVE module block not found\");\n}\n\nexport { parseModuleBlock };\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport zlib from \"node:zlib\";\n\nconst RPACK_MAP_PATH = path.join(\n path.dirname(fileURLToPath(import.meta.url)),\n \"..\",\n \"vendor\",\n \"rpack\",\n \"rpack_map.bin\",\n);\n\nconst CRC32_TABLE = (() => {\n const table = new Uint32Array(256);\n for (let index = 0; index < table.length; index += 1) {\n let value = index;\n for (let bit = 0; bit < 8; bit += 1) {\n if ((value & 1) !== 0) {\n value = 0xedb88320 ^ (value >>> 1);\n } else {\n value >>>= 1;\n }\n }\n table[index] = value >>> 0;\n }\n return table;\n})();\n\nfunction assert(condition: unknown, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\nfunction calculateCRC32(data) {\n let value = 0xffffffff;\n for (const byte of data) {\n value = CRC32_TABLE[(value ^ byte) & 0xff] ^ (value >>> 8);\n }\n return (value ^ 0xffffffff) >>> 0;\n}\n\nfunction decodeModule(data: Buffer, map: Buffer): Record<string, any> {\n assert(data.length >= 7, \"module.risum is truncated\");\n assert(data.readUInt8(0) === 111, \"Invalid module.risum magic number\");\n assert(data.readUInt8(1) === 0, `Unsupported module.risum version: ${data.readUInt8(1)}`);\n\n const encodedLength = data.readUInt32LE(2);\n assert(encodedLength <= data.length - 6, \"module.risum payload is truncated\");\n assert(map.length >= 256, `Invalid RPack map: ${RPACK_MAP_PATH}`);\n\n let decodeMap;\n if (map.length >= 512) {\n decodeMap = map.subarray(256, 512);\n } else {\n decodeMap = Buffer.alloc(256);\n const seen = new Set();\n for (let index = 0; index < 256; index += 1) {\n const encoded = map[index];\n assert(!seen.has(encoded), \"RPack encode map is not a permutation\");\n seen.add(encoded);\n decodeMap[encoded] = index;\n }\n }\n\n const encoded = data.subarray(6, 6 + encodedLength);\n const decoded = Buffer.allocUnsafe(encoded.length);\n for (let index = 0; index < encoded.length; index += 1) {\n decoded[index] = decodeMap[encoded[index]];\n }\n\n const parsed = JSON.parse(decoded.toString(\"utf8\"));\n assert(\n parsed && parsed.type === \"risuModule\" && parsed.module,\n \"module.risum does not contain a Risu module\",\n );\n return parsed;\n}\n\nfunction findEndOfCentralDirectory(archive) {\n const minimumOffset = Math.max(0, archive.length - 0xffff - 22);\n for (let offset = archive.length - 22; offset >= minimumOffset; offset -= 1) {\n if (archive.readUInt32LE(offset) === 0x06054b50) {\n const commentLength = archive.readUInt16LE(offset + 20);\n if (offset + 22 + commentLength === archive.length) {\n return offset;\n }\n }\n }\n throw new Error(\"ZIP end record not found\");\n}\n\nfunction normalizeEntryName(name) {\n assert(name !== \"\", \"ZIP entry has an empty name\");\n assert(!name.includes(\"\\0\"), `ZIP entry contains a null byte: ${JSON.stringify(name)}`);\n\n const normalized = name.replace(/\\\\/g, \"/\");\n assert(!normalized.startsWith(\"/\"), `ZIP entry uses an absolute path: ${name}`);\n assert(!/^[a-zA-Z]:/.test(normalized), `ZIP entry uses an absolute path: ${name}`);\n\n const parts = normalized.split(\"/\");\n assert(!parts.includes(\"..\"), `ZIP entry escapes the output directory: ${name}`);\n return parts.filter((part) => part !== \"\" && part !== \".\").join(\"/\");\n}\n\nfunction sanitizeSourceName(name: string, fallback: string): string {\n const sanitized = Array.from(name, (character) =>\n character.charCodeAt(0) < 32 ? \"_\" : character,\n )\n .join(\"\")\n .replace(/[<>:\"/\\\\|?*]/g, \"_\")\n .replace(/[. ]+$/g, \"\")\n .trim();\n return sanitized || fallback;\n}\n\nfunction sortKeysDeep(value) {\n if (Array.isArray(value)) {\n return value.map(sortKeysDeep);\n }\n if (value && typeof value === \"object\" && !Buffer.isBuffer(value)) {\n const sorted = {};\n for (const key of Object.keys(value).sort()) {\n if (value[key] !== undefined) {\n sorted[key] = sortKeysDeep(value[key]);\n }\n }\n return sorted;\n }\n return value;\n}\n\nfunction takeSourcePath(directory, label, extension, takenPaths) {\n const baseName = sanitizeSourceName(label, \"untitled\");\n const suffix = baseName.toLowerCase().endsWith(extension) ? \"\" : extension;\n let candidate = `${directory}/${baseName}${suffix}`;\n let collision = 1;\n while (takenPaths.has(candidate)) {\n collision += 1;\n candidate = `${directory}/${baseName}_${collision}${suffix}`;\n }\n takenPaths.add(candidate);\n return candidate;\n}\n\nfunction createRegexDocument(regex) {\n const frontmatter = [`ableFlag: ${regex.ableFlag ?? true}`, `comment: ${regex.comment ?? \"\"}`];\n if (regex.flag !== undefined) {\n frontmatter.push(`flag: ${regex.flag}`);\n }\n frontmatter.push(`type: ${regex.type ?? \"editdisplay\"}`);\n return `---\\n${frontmatter.join(\"\\n\")}\\n---\\n\\nIN:\\n${regex.in ?? \"\"}\\nOUT:\\n${regex.out ?? \"\"}\\n`;\n}\n\nfunction createExpandedModuleSources(\n card: Record<string, any>,\n decodedModule: Record<string, any>,\n): Map<string, Buffer> {\n const moduleData = decodedModule.module;\n const files = new Map<string, Buffer>();\n const folderNames = new Map<any, any>();\n const folders: any[] = [];\n const takenPaths = new Set<string>();\n\n for (const entry of moduleData.lorebook ?? []) {\n if (entry.mode !== \"folder\") {\n continue;\n }\n folderNames.set(entry.key, entry.comment);\n folders.push(entry.comment);\n }\n\n const lorebook: any[] = [];\n for (const entry of moduleData.lorebook ?? []) {\n if (entry.mode === \"folder\") {\n continue;\n }\n const file = takeSourcePath(\"lorebooks\", entry.comment, \".md\", takenPaths);\n files.set(file, Buffer.from(entry.content ?? \"\", \"utf8\"));\n lorebook.push({\n activationPercent: entry.activationPercent,\n alwaysActive: entry.alwaysActive ?? false,\n bookVersion: entry.bookVersion ?? 2,\n comment: entry.comment ?? \"\",\n extentions: entry.extentions,\n file,\n folder: folderNames.get(entry.folder),\n insertOrder: entry.insertorder ?? 100,\n key: entry.key ?? \"\",\n mode: entry.mode ?? \"normal\",\n secondaryKey: entry.secondkey ?? \"\",\n selective: entry.selective ?? false,\n useRegex: entry.useRegex ?? false,\n });\n }\n\n const regex: string[] = [];\n for (const entry of moduleData.regex ?? []) {\n const file = takeSourcePath(\"regex\", entry.comment, \".md\", takenPaths);\n files.set(file, Buffer.from(createRegexDocument(entry), \"utf8\"));\n regex.push(file);\n }\n\n const triggers: any[] = [];\n for (let index = 0; index < (moduleData.trigger ?? []).length; index += 1) {\n const trigger = moduleData.trigger[index];\n const luaEffect =\n trigger.effect?.length === 1 && trigger.effect[0].type === \"triggerlua\"\n ? trigger.effect[0]\n : undefined;\n if (!luaEffect || typeof luaEffect.code !== \"string\") {\n triggers.push(trigger);\n continue;\n }\n\n const label = trigger.comment || `trigger-${index + 1}`;\n const luaPath = takeSourcePath(\"triggers\", label, \".lua\", takenPaths);\n files.set(luaPath, Buffer.from(luaEffect.code, \"utf8\"));\n triggers.push({\n bundle: false,\n comment: trigger.comment ?? \"\",\n conditions: trigger.conditions ?? [],\n lowLevelAccess: trigger.lowLevelAccess,\n lua: luaPath,\n type: trigger.type ?? \"start\",\n });\n }\n\n const risuai = card.data?.extensions?.risuai ?? {};\n const manifest: Record<string, any> = {\n card: \"card.json\",\n creator: card.data?.creator,\n description: card.data?.creator_notes ?? moduleData.description ?? \"\",\n folders,\n hideIcon: risuai.hideChatIcon ?? moduleData.hideIcon ?? false,\n lorebook,\n lowLevelAccess: risuai.lowLevelAccess ?? moduleData.lowLevelAccess ?? false,\n name: card.data?.name ?? moduleData.name,\n namespace: risuai.moduleNamespace ?? moduleData.namespace,\n regex,\n tags: card.data?.tags,\n triggers,\n version: card.data?.character_version ?? \"\",\n };\n\n const CSS = risuai.backgroundHTML ?? moduleData.backgroundEmbedding;\n if (CSS) {\n manifest.CSS = \"style.html\";\n files.set(\"style.html\", Buffer.from(CSS, \"utf8\"));\n }\n const toggles = risuai.toggles ?? moduleData.customModuleToggle;\n if (toggles) {\n manifest.toggles = \"toggles.txt\";\n files.set(\"toggles.txt\", Buffer.from(toggles, \"utf8\"));\n }\n\n const mainIcon = card.data?.assets?.find(\n (asset) => asset.type === \"icon\" && asset.name === \"main\",\n );\n if (mainIcon?.uri?.startsWith(\"embeded://\")) {\n manifest.icon = mainIcon.uri.slice(\"embeded://\".length);\n }\n\n const assets: any[] = [];\n for (const asset of card.data?.assets ?? []) {\n if (asset === mainIcon || !asset.uri?.startsWith(\"embeded://\")) {\n continue;\n }\n assets.push({\n extension: asset.ext,\n file: asset.uri.slice(\"embeded://\".length),\n name: asset.name,\n });\n }\n if (assets.length > 0) {\n manifest.assets = assets;\n }\n\n files.set(\n \"charx.json\",\n Buffer.from(`${JSON.stringify(sortKeysDeep(manifest), null, 2)}\\n`, \"utf8\"),\n );\n return files;\n}\n\nfunction parseZIP(archive: Buffer) {\n const endOffset = findEndOfCentralDirectory(archive);\n const diskNumber = archive.readUInt16LE(endOffset + 4);\n const centralDisk = archive.readUInt16LE(endOffset + 6);\n const diskEntries = archive.readUInt16LE(endOffset + 8);\n const totalEntries = archive.readUInt16LE(endOffset + 10);\n const centralSize = archive.readUInt32LE(endOffset + 12);\n const centralOffset = archive.readUInt32LE(endOffset + 16);\n\n assert(diskNumber === 0 && centralDisk === 0, \"Multi-disk ZIP archives are not supported\");\n assert(diskEntries === totalEntries, \"Inconsistent ZIP entry count\");\n assert(\n totalEntries !== 0xffff && centralSize !== 0xffffffff && centralOffset !== 0xffffffff,\n \"ZIP64 is not supported\",\n );\n\n const zipOffset = endOffset - centralSize - centralOffset;\n assert(zipOffset >= 0, \"Invalid ZIP central directory offset\");\n\n const entries: any[] = [];\n const names = new Set();\n let offset = zipOffset + centralOffset;\n for (let index = 0; index < totalEntries; index += 1) {\n assert(offset + 46 <= archive.length, \"ZIP central directory is truncated\");\n assert(\n archive.readUInt32LE(offset) === 0x02014b50,\n `Invalid ZIP central record at byte ${offset}`,\n );\n\n const flags = archive.readUInt16LE(offset + 8);\n const method = archive.readUInt16LE(offset + 10);\n const expectedCRC32 = archive.readUInt32LE(offset + 16);\n const compressedSize = archive.readUInt32LE(offset + 20);\n const uncompressedSize = archive.readUInt32LE(offset + 24);\n const nameLength = archive.readUInt16LE(offset + 28);\n const extraLength = archive.readUInt16LE(offset + 30);\n const commentLength = archive.readUInt16LE(offset + 32);\n const diskStart = archive.readUInt16LE(offset + 34);\n const localOffset = archive.readUInt32LE(offset + 42);\n const recordLength = 46 + nameLength + extraLength + commentLength;\n\n assert(offset + recordLength <= archive.length, \"ZIP central record is truncated\");\n assert((flags & 1) === 0, \"Encrypted ZIP entries are not supported\");\n assert(method === 0 || method === 8, `Unsupported ZIP compression method: ${method}`);\n assert(diskStart === 0, \"Multi-disk ZIP entries are not supported\");\n assert(\n compressedSize !== 0xffffffff &&\n uncompressedSize !== 0xffffffff &&\n localOffset !== 0xffffffff,\n \"ZIP64 entries are not supported\",\n );\n\n const rawName = archive.subarray(offset + 46, offset + 46 + nameLength);\n const decodedName = rawName.toString(\"utf8\");\n const directory = decodedName.endsWith(\"/\") || decodedName.endsWith(\"\\\\\");\n const name = normalizeEntryName(decodedName);\n assert(name !== \"\", \"ZIP entry resolves to an empty path\");\n assert(!names.has(name), `Duplicate ZIP entry: ${name}`);\n names.add(name);\n\n entries.push({\n compressedSize,\n directory,\n expectedCRC32,\n localOffset: zipOffset + localOffset,\n method,\n name,\n uncompressedSize,\n });\n offset += recordLength;\n }\n\n assert(offset === endOffset, \"ZIP central directory size does not match its records\");\n return entries;\n}\n\nfunction readEntry(archive, entry) {\n const offset = entry.localOffset;\n assert(offset + 30 <= archive.length, `ZIP local record is truncated: ${entry.name}`);\n assert(archive.readUInt32LE(offset) === 0x04034b50, `Invalid ZIP local record: ${entry.name}`);\n\n const nameLength = archive.readUInt16LE(offset + 26);\n const extraLength = archive.readUInt16LE(offset + 28);\n const dataOffset = offset + 30 + nameLength + extraLength;\n const dataEnd = dataOffset + entry.compressedSize;\n assert(dataEnd <= archive.length, `ZIP entry data is truncated: ${entry.name}`);\n\n const compressed = archive.subarray(dataOffset, dataEnd);\n const data = entry.method === 0 ? Buffer.from(compressed) : zlib.inflateRawSync(compressed);\n assert(data.length === entry.uncompressedSize, `ZIP entry size mismatch: ${entry.name}`);\n assert(\n calculateCRC32(data) === entry.expectedCRC32,\n `ZIP entry checksum mismatch: ${entry.name}`,\n );\n assert(!entry.directory || data.length === 0, `ZIP directory entry contains data: ${entry.name}`);\n return data;\n}\n\nfunction assertEmptyOutputDirectory(outputDirectory) {\n if (!fs.existsSync(outputDirectory)) {\n return;\n }\n assert(\n fs.statSync(outputDirectory).isDirectory(),\n `Output path is not a directory: ${outputDirectory}`,\n );\n assert(\n fs.readdirSync(outputDirectory).length === 0,\n `Output directory is not empty: ${outputDirectory}`,\n );\n}\n\nfunction unpackCharX(inputPath: string, outputPath: string): string {\n const resolvedInputPath = path.resolve(inputPath);\n const resolvedOutputPath = path.resolve(outputPath);\n const archive = fs.readFileSync(resolvedInputPath);\n const entries = parseZIP(archive);\n const extracted = new Map<string, { data: Buffer; directory: boolean }>();\n\n for (const entry of entries) {\n extracted.set(entry.name, {\n data: readEntry(archive, entry),\n directory: entry.directory,\n });\n }\n\n const cardEntry = extracted.get(\"card.json\");\n assert(cardEntry, \"CharX archive does not contain card.json\");\n assert(!cardEntry.directory, \"card.json is a directory\");\n const card = JSON.parse(cardEntry.data.toString(\"utf8\"));\n\n let decodedModule;\n let decodedModuleName;\n if (extracted.has(\"module.risum\")) {\n const moduleEntry = extracted.get(\"module.risum\");\n assert(moduleEntry, \"CharX archive does not contain module.risum\");\n assert(!moduleEntry.directory, \"module.risum is a directory\");\n const map = fs.readFileSync(RPACK_MAP_PATH);\n decodedModule = decodeModule(moduleEntry.data, map);\n decodedModuleName = extracted.has(\"module.json\") ? \"module.decoded.json\" : \"module.json\";\n }\n\n const expandedSources = decodedModule\n ? createExpandedModuleSources(card, decodedModule)\n : new Map();\n for (const name of expandedSources.keys()) {\n assert(\n !extracted.has(name),\n `Generated module source conflicts with an archive entry: ${name}`,\n );\n }\n\n assertEmptyOutputDirectory(resolvedOutputPath);\n fs.mkdirSync(resolvedOutputPath, { recursive: true });\n\n for (const [name, entry] of extracted) {\n if (name === \"module.risum\") {\n continue;\n }\n const destination = path.join(resolvedOutputPath, ...name.split(\"/\"));\n if (entry.directory) {\n fs.mkdirSync(destination, { recursive: true });\n continue;\n }\n fs.mkdirSync(path.dirname(destination), { recursive: true });\n fs.writeFileSync(destination, entry.data);\n }\n\n if (decodedModule) {\n fs.writeFileSync(\n path.join(resolvedOutputPath, decodedModuleName),\n `${JSON.stringify(decodedModule, null, 2)}\\n`,\n );\n }\n\n for (const [name, data] of expandedSources) {\n const destination = path.join(resolvedOutputPath, ...name.split(\"/\"));\n fs.mkdirSync(path.dirname(destination), { recursive: true });\n fs.writeFileSync(destination, data);\n }\n\n const relativeOutput = path.relative(process.cwd(), resolvedOutputPath) || \".\";\n const moduleNote = decodedModule ? ` and decoded ${decodedModuleName}` : \"\";\n console.log(\n `Unpacked ${entries.length - (decodedModule ? 1 : 0)} archive files to ${relativeOutput}${moduleNote}`,\n );\n return resolvedOutputPath;\n}\n\nexport { createExpandedModuleSources, decodeModule, parseZIP, unpackCharX };\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { createExpandedModuleSources } from \"./unpack-charx.js\";\n\nconst RPACK_MAP_PATH = path.join(\n path.dirname(fileURLToPath(import.meta.url)),\n \"..\",\n \"vendor\",\n \"rpack\",\n \"rpack_map.bin\",\n);\n\nfunction assert(condition: unknown, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\nfunction assertEmptyOutputDirectory(outputDirectory) {\n if (!fs.existsSync(outputDirectory)) {\n return;\n }\n assert(\n fs.statSync(outputDirectory).isDirectory(),\n `Output path is not a directory: ${outputDirectory}`,\n );\n assert(\n fs.readdirSync(outputDirectory).length === 0,\n `Output directory is not empty: ${outputDirectory}`,\n );\n}\n\nfunction decodeRPack(data, decodeMap) {\n for (let index = 0; index < data.length; index += 1) {\n data[index] = decodeMap[data[index]];\n }\n return data;\n}\n\nfunction readExactly(fileDescriptor, length, position, label) {\n const data = Buffer.allocUnsafe(length);\n let read = 0;\n while (read < length) {\n const count = fs.readSync(fileDescriptor, data, read, length - read, position + read);\n assert(count > 0, `${label} is truncated at byte ${position + read}`);\n read += count;\n }\n return data;\n}\n\nfunction sanitizeAssetName(name: string, fallback: string): string {\n const sanitized = Array.from(name, (character) =>\n character.charCodeAt(0) < 32 ? \"_\" : character,\n )\n .join(\"\")\n .replace(/[<>:\"/\\\\|?*]/g, \"_\")\n .replace(/[. ]+$/g, \"\")\n .trim();\n return sanitized.slice(0, 180) || fallback;\n}\n\nfunction detectAssetExtension(data, fallback) {\n if (data.subarray(0, 8).equals(Buffer.from(\"89504e470d0a1a0a\", \"hex\"))) {\n return \"png\";\n }\n if (data.subarray(0, 3).equals(Buffer.from(\"ffd8ff\", \"hex\"))) {\n return \"jpg\";\n }\n if (\n data.subarray(0, 6).toString(\"ascii\") === \"GIF87a\" ||\n data.subarray(0, 6).toString(\"ascii\") === \"GIF89a\"\n ) {\n return \"gif\";\n }\n if (\n data.subarray(0, 4).toString(\"ascii\") === \"RIFF\" &&\n data.subarray(8, 12).toString(\"ascii\") === \"WEBP\"\n ) {\n return \"webp\";\n }\n if (data.subarray(4, 12).toString(\"ascii\").includes(\"ftypavif\")) {\n return \"avif\";\n }\n return /^[a-z0-9]+$/i.test(fallback ?? \"\") ? fallback.toLowerCase() : \"bin\";\n}\n\nfunction takeAssetPath(asset, data, index, takenPaths) {\n const extension = detectAssetExtension(data, asset[2]);\n const baseName = sanitizeAssetName(asset[0] ?? \"\", `asset_${index + 1}`);\n let candidate = `assets/${baseName}.${extension}`;\n let collision = 1;\n while (takenPaths.has(candidate)) {\n collision += 1;\n candidate = `assets/${baseName}_${collision}.${extension}`;\n }\n takenPaths.add(candidate);\n return candidate;\n}\n\nfunction writeSources(outputDirectory, decodedModule, assetSources) {\n const card = {\n data: {\n name: decodedModule.module.name,\n },\n };\n const sources = createExpandedModuleSources(card, decodedModule);\n const manifestSource = sources.get(\"charx.json\");\n assert(manifestSource, \"Expanded module sources do not contain charx.json\");\n const manifest = JSON.parse(manifestSource.toString(\"utf8\"));\n manifest.assets = assetSources;\n sources.set(\"charx.json\", Buffer.from(`${JSON.stringify(manifest, null, 2)}\\n`, \"utf8\"));\n sources.set(\"module.json\", Buffer.from(`${JSON.stringify(decodedModule, null, 2)}\\n`, \"utf8\"));\n\n for (const [name, data] of sources) {\n const destination = path.join(outputDirectory, ...name.split(\"/\"));\n fs.mkdirSync(path.dirname(destination), { recursive: true });\n fs.writeFileSync(destination, data);\n }\n}\n\nfunction unpackRisuM(inputPath: string, outputPath: string): string {\n const resolvedInputPath = path.resolve(inputPath);\n const resolvedOutputPath = path.resolve(outputPath);\n assertEmptyOutputDirectory(resolvedOutputPath);\n\n const map = fs.readFileSync(RPACK_MAP_PATH);\n assert(map.length >= 512, `Invalid RPack map: ${RPACK_MAP_PATH}`);\n const decodeMap = map.subarray(256, 512);\n const fileDescriptor = fs.openSync(resolvedInputPath, \"r\");\n\n try {\n const fileSize = fs.fstatSync(fileDescriptor).size;\n const header = readExactly(fileDescriptor, 6, 0, \"RISUM header\");\n assert(header.readUInt8(0) === 111, \"Invalid RISUM magic number\");\n assert(header.readUInt8(1) === 0, `Unsupported RISUM version: ${header.readUInt8(1)}`);\n\n const payloadLength = header.readUInt32LE(2);\n const payload = readExactly(fileDescriptor, payloadLength, 6, \"RISUM module payload\");\n const decodedModule = JSON.parse(decodeRPack(payload, decodeMap).toString(\"utf8\"));\n assert(\n decodedModule?.type === \"risuModule\" && decodedModule.module,\n \"RISUM does not contain a Risu module\",\n );\n\n const assetMetadata = decodedModule.module.assets ?? [];\n const assetSources: any[] = [];\n const takenPaths = new Set<string>();\n let assetIndex = 0;\n let position = 6 + payloadLength;\n\n fs.mkdirSync(path.join(resolvedOutputPath, \"assets\"), { recursive: true });\n while (position < fileSize) {\n const marker = readExactly(fileDescriptor, 1, position, \"RISUM asset marker\").readUInt8(0);\n position += 1;\n if (marker === 0) {\n break;\n }\n assert(marker === 1, `Invalid RISUM asset marker at byte ${position - 1}: ${marker}`);\n assert(\n assetIndex < assetMetadata.length,\n \"RISUM contains more asset blocks than asset metadata entries\",\n );\n\n const lengthData = readExactly(fileDescriptor, 4, position, \"RISUM asset length\");\n const assetLength = lengthData.readUInt32LE(0);\n position += 4;\n const encodedAsset = readExactly(\n fileDescriptor,\n assetLength,\n position,\n `RISUM asset ${assetIndex + 1}`,\n );\n position += assetLength;\n\n const metadata = assetMetadata[assetIndex];\n assert(metadata, `RISUM asset ${assetIndex + 1} has no metadata`);\n const decodedAsset = decodeRPack(encodedAsset, decodeMap);\n const sourcePath = takeAssetPath(metadata, decodedAsset, assetIndex, takenPaths);\n const destination = path.join(resolvedOutputPath, ...sourcePath.split(\"/\"));\n fs.writeFileSync(destination, decodedAsset);\n assetSources.push({\n extension: path.extname(sourcePath).slice(1),\n file: sourcePath,\n name: metadata[0],\n });\n assetIndex += 1;\n\n if (assetIndex % 500 === 0) {\n console.log(`Extracted ${assetIndex} / ${assetMetadata.length} assets`);\n }\n }\n\n assert(\n assetIndex === assetMetadata.length,\n `RISUM contains ${assetIndex} asset blocks but declares ${assetMetadata.length}`,\n );\n assert(\n position === fileSize,\n `RISUM contains ${fileSize - position} trailing bytes after the end marker`,\n );\n writeSources(resolvedOutputPath, decodedModule, assetSources);\n\n const relativeOutput = path.relative(process.cwd(), resolvedOutputPath) || \".\";\n console.log(`Unpacked ${assetIndex} assets and module sources to ${relativeOutput}`);\n return resolvedOutputPath;\n } finally {\n fs.closeSync(fileDescriptor);\n }\n}\n\nexport { unpackRisuM };\n"],"mappings":";;;;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GACA,YAAY;GAEZ,MAAM,WAAW,cAAc;GAC/B,OAAO,UAAU,eAAe,aAAa,EAAE,iBAAiB;GAChE,MAAM,eAAe,YAAY,cAAc,SAAS;GACxD,MAAM,aAAa,cAAc,UAAU,cAAc,YAAY,UAAU;GAC/E,MAAM,cAAc,KAAK,KAAK,oBAAoB,GAAG,WAAW,MAAM,GAAG,CAAC;GAC1E,GAAG,cAAc,aAAa,YAAY;GAC1C,aAAa,KAAK;IAChB,WAAW,KAAK,QAAQ,UAAU,CAAC,CAAC,MAAM,CAAC;IAC3C,MAAM;IACN,MAAM,SAAS;GACjB,CAAC;GACD,cAAc;GAEd,IAAI,aAAa,QAAQ,GACvB,QAAQ,IAAI,aAAa,WAAW,KAAK,cAAc,OAAO,QAAQ;EAE1E;EAEA,OACE,eAAe,cAAc,QAC7B,kBAAkB,WAAW,6BAA6B,cAAc,QAC1E;EACA,OACE,aAAa,UACb,kBAAkB,WAAW,SAAS,qCACxC;EACA,aAAa,oBAAoB,eAAe,YAAY;EAE5D,MAAM,iBAAiB,KAAK,SAAS,QAAQ,IAAI,GAAG,kBAAkB,KAAK;EAC3E,QAAQ,IAAI,YAAY,WAAW,gCAAgC,gBAAgB;EACnF,OAAO;CACT,UAAU;EACR,GAAG,UAAU,cAAc;CAC7B;AACF"}
@@ -0,0 +1,2 @@
1
+ declare function unpackRisuM(inputPath: string, outputPath: string): string;
2
+ export { unpackRisuM };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "risupack",
3
+ "version": "0.1.0",
4
+ "description": "Command-line tools for packing and unpacking RisuAI modules",
5
+ "license": "AGPL-3.0-only",
6
+ "bin": {
7
+ "risupack": "dist/cli.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "vendor"
12
+ ],
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "vp build && tsc --project tsconfig.build.json",
22
+ "check": "tsc --noEmit",
23
+ "prepack": "npm run check && npm run build",
24
+ "prepare": "vp config"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^24.3.0",
28
+ "typescript": "^5.9.2",
29
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.9",
30
+ "vite-plus": "0.2.9"
31
+ },
32
+ "overrides": {
33
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.2.9"
34
+ },
35
+ "devEngines": {
36
+ "packageManager": {
37
+ "name": "npm",
38
+ "onFail": "download",
39
+ "version": "12.0.2"
40
+ }
41
+ },
42
+ "engines": {
43
+ "node": ">=20"
44
+ }
45
+ }
@@ -0,0 +1,6 @@
1
+
2
+ # License
3
+
4
+ Rpack.js is dual-licensed under the MIT License and AGPL-3.0 License.
5
+ - If you are using Rpack.js in other applications rather than Risuai, or you are trying to embed Risuai inside your own application, you must follow the AGPL-3.0 License.
6
+ - If you are using Rpack.js only within Risuai, you may use it under the MIT License.