ffl resource header parsing using struct-fu sample
by arian_
HTML
<body>
<h1>upload an FFL resource, then open your console</h1>
<p>
if you need it, get it from archive.org: <a target="_blank" href="https://web.archive.org/web/20180502054513/http://download-cdn.miitomo.com/native/20180125111639/android/v2/asset_model_character_mii_AFLResHigh_2_3_dat.zip">https://web.archive.org/web/20180502054513/http://download-cdn.miitomo.com/native/20180125111639/android/v2/asset_model_character_mii_AFLResHigh_2_3_dat.zip</a>
<div style="font-size: 11px;">
before you try, if you paste that below it won't work since archive.org has no CORS policy :( this proxy from kaeru would work if it were https: <a target="_blank" href="http://ia-proxy.fs3d.net:8989/20180502054513id_/http://download-cdn.miitomo.com/native/20180125111639/android/v2/asset_model_character_mii_AFLResHigh_2_3_dat.zip">http://ia-proxy.fs3d.net:8989/20180502054513id_/http://download-cdn.miitomo.com/native/20180125111639/android/v2/asset_model_character_mii_AFLResHigh_2_3_dat.zip</a>
</div>
</p>
<!-- Inline HTML user interface elements. -->
<input type="file" id="fileInput" accept=".zip,.dat">
<form id="urlForm">
<input type="text" id="urlInput" placeholder="Or import from URL.">
<br> <button id="urlButton">Fetch File/Zip</button>
</form>
<div id="hide-when-loading-not-fflresmiddle-dat" style="display: none;">by default, we have loaded FFLResMiddle.dat (header ONLY...) for you</div>
<textarea id="output" rows="20" readonly style="width:100%;box-sizing:border-box;font-family:monospace;font-size:11px;margin-top:8px;"></textarea>
<script>
const FFLRESMIDDLE_DAT_HEADER_GZ_B64 =...
JavaScript
// @ts-check
// import * as _ from './struct-fu.js';
/* eslint @stylistic/indent: ['error', 2] -- Define indent rules. */
/* eslint @stylistic/spaced-comment: ['error', 'always', {
line: { markers: ['/<', '!<'] },
block: { markers: ['*'], balanced: true }
}],
@stylistic/no-multi-spaces: 'off'
-- Allow Doxygen-style inline brief comments.
*/
// import { unzipSync } from 'fflate';
// const fflate = { unzipSync };
// import * as _Import from './struct-fu.js';
/* globals _ -- Global dependencies. */
/** @typedef {import('./struct-fu')} _ */
// eslint-disable-next-line no-self-assign -- Get TypeScript to identify global imports.
globalThis._ = /** @type {_} */ (/** @type {*} */ (globalThis)._);
// eslint-disable-next-line @stylistic/max-statements-per-line -- Hack to use either UMD or browser ESM import.
// let _ = globalThis._; _ = (!_) ? _Import : _;
// Constants for resource header magic.
const FFLI_RESOURCE_HEADER_MAGIC_BE = 'FFRA';
const FFLI_RESOURCE_HEADER_MAGIC_LE = 'ARFF';
const FFLI_RESOURCE_HEADER_MAGIC_U32 = 0x46465241;
// This sample tries? to detect endianness from the magic.
const FFLI_RESOURCE_HEADER_EXPAND_BUFFER_SIZE_OFFSET = 0x0c;
const FFLI_RESOURCE_HEADER_EXPAND_BUFFER_SIZE_AFL_2_3 = 0x2502de0;
const FFLI_RESOURCE_HEADER_RESOURCE_TYPE_HINT_AFL_2_3 = 3;
// // ---------------------------------------------------------------------
// // JSDoc Struct Definitions
// // ---------------------------------------------------------------------
/**
* Structure making up each texture and shape element.
* @typedef {Object} FFLiResourcePartsInfo
* @property {number} dataPos - Offset of the data in the resource file.
* @property {number} dataSize
* @property {number} compressedSize
* @property {number} compressLevel - enum FFLiResourceCompressLevel
* @property {number} windowBits - enum FFLiResourceWindowBits
* @property {number} memoryLevel - enum FFLiResourceMemoryLevel
* @property...