diff --git a/icon.js b/icon.js index 27ee66d..67ccfac 100644 --- a/icon.js +++ b/icon.js @@ -1,7 +1,8 @@ //todo: Make this a module/mjs file. C6 compatibility can stay, if needed. +//LOOKING FOR: LZARI implementation (for MAX), description of CBS compression (node zlib doesn't tackle it, even with RC4'ing the data) ICONJS_DEBUG = false; ICONJS_STRICT = true; -ICONJS_VERSION = "0.4.2"; +ICONJS_VERSION = "0.5.0"; function setDebug(value) { ICONJS_DEBUG = !!value; @@ -77,6 +78,7 @@ function convertBGR5A1toRGB5A1(bgrData) { let r = ((bgrData[index] >> 10) & 0b11111); // rrrrrgggggbbbbba (a = 1 because 0 is 127 which is 1.0f opacity for the GS) let newValue = 0b0000000000000001; + // mind you, the alpha bit ^ seems to be set randomly on textures, anyway. Maybe i'm reading these wrong? newValue |= (r << 1); newValue |= (g << 6); newValue |= (b << 11); @@ -166,7 +168,8 @@ function readIconFile(input) { }}; const magic = u32le(0); if (magic !== 0x010000) { - // USER WARNING: APPARENTLY NOT ALL ICONS ARE 0x010000. THIS THROW WILL BE DROPPED LATER. + // USER NOTICE: So far, I have yet to parse an icon that hasn't had 0x00010000 as it's magic. + // Can someone provide me pointers to such an icon if one exists? throw `Not a PS2 icon file (was ${magic}, expected ${0x010000})`; } const numberOfShapes = u32le(4); @@ -237,6 +240,7 @@ function readIconFile(input) { case 'U': { //where every 16-bit entry is a BGR5A1 color 0b[bbbbbgggggrrrrra] texture = new Uint16Array(input.slice(offset, (offset+0x8000))); + //see convertBGR5A1toRGB5A1() for more info. break; } case 'C': { @@ -257,6 +261,7 @@ function readIconFile(input) { **/ //output of this will be another u16[0x4000] of the decompressed texture //after that just parse output as-if it was uncompressed. + //see uncompressTexture() and convertBGR5A1toRGB5A1() for more info. size = u32le(offset); texture = {size, data: input.slice(offset+4, offset+(4+size))}; } @@ -333,7 +338,7 @@ function readEmsPsuFile(input){ offset += ((fdesc.size & 0b11111111110000000000) + 1024); } else { offset += fdesc.size; - // if we're already filling sectors fully, no to change anything about it + // if we're already filling 1k blocks fully, why change the value? } output[fdesc.filename] = { size: fdesc.size, @@ -370,7 +375,7 @@ function readPsvFile(input){ const type1 = u32le(56); const type2 = u32le(60); if(type1 !== 0x2c && type2 !== 2) { - throw `Not parsing, this is not a PS2 save export (was ${type1}:${type2}, expected 44:2)`; + throw `Not parsing, this is not in the PS2 save export format (was ${type1}:${type2}, expected 44:2)`; } const displayedSize = u32le(64); const ps2dOffset = u32le(68); @@ -509,5 +514,10 @@ function readSharkXPortSxpsFile(input) { if(typeof module !== "undefined") { // for C6JS - module.exports = {readIconFile, readPS2D, readEmsPsuFile, readPsvFile, readSharkXPortSxpsFile, setDebug, setStrictness}; + module.exports = { + readers: {readIconFile, readPS2D, readEmsPsuFile, readPsvFile, readSharkXPortSxpsFile}, + helpers: {uncompressTexture, convertBGR5A1toRGB5A1}, + options: {setDebug, setStrictness}, + version: ICONJS_VERSION + }; } \ No newline at end of file diff --git a/index.js b/index.js index c05023a..2de910a 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ -const iconjs = require("./icon.js"); +const icondumper2 = require("./icon.js"); +const iconjs = icondumper2.readers; const filesystem = require("fs"); const processObj = require("process"); @@ -7,45 +8,71 @@ require("util").inspect.defaultOptions.maxArrayLength = 10; require("util").inspect.defaultOptions.compact = true; require("util").inspect.defaultOptions.depth = 2; -// debugger -iconjs.setDebug(false); +// output debugging information +icondumper2.options.setDebug(false); // node.js client -if(processObj.argv[2] === "psu") { - let inputFile = filesystem.readFileSync(processObj.argv[3] ? processObj.argv[3] : "file.psu"); - const parsed = iconjs.readEmsPsuFile(inputFile.buffer.slice(inputFile.byteOffset, inputFile.byteOffset + inputFile.byteLength)); - const PS2D = iconjs.readPS2D(parsed[parsed.rootDirectory]["icon.sys"].data); - let output = {parsed, PS2D} - Object.keys(PS2D.filenames).forEach(function(file) { - output[file] = iconjs.readIconFile(parsed[parsed.rootDirectory][PS2D.filenames[file]].data); - }); - console.log(output); -} else if(processObj.argv[2] === "psv") { - let inputFile = filesystem.readFileSync(processObj.argv[3] ? processObj.argv[3] : "file.psv"); - const parsed = iconjs.readPsvFile(inputFile.buffer.slice(inputFile.byteOffset, inputFile.byteOffset + inputFile.byteLength)); - console.log(parsed); - const PS2D = iconjs.readPS2D(parsed["icon.sys"]); - let output = {parsed, PS2D}; - console.log(output); -} else if(processObj.argv[2] === "sps") { - let inputFile = filesystem.readFileSync(processObj.argv[3] ? processObj.argv[3] : "file.sps"); - const parsed = iconjs.readSharkXPortSxpsFile(inputFile.buffer.slice(inputFile.byteOffset, inputFile.byteOffset + inputFile.byteLength)); - console.log(parsed); - const PS2D = iconjs.readPS2D(parsed[parsed.rootDirectory]["icon.sys"].data); - let output = {parsed, PS2D} - Object.keys(PS2D.filenames).forEach(function(file) { - output[file] = iconjs.readIconFile(parsed[parsed.rootDirectory][PS2D.filenames[file]].data); - }); - console.log(output); -} else { - let inputFile = filesystem.readFileSync(processObj.argv[2] ? processObj.argv[2] : "icon.sys"); - const metadata = iconjs.readPS2D(inputFile.buffer.slice(inputFile.byteOffset, inputFile.byteOffset + inputFile.byteLength)); - console.log("\noutput:", metadata, "\n") +console.log(`icon.js version ${icondumper2.version}, 2023 (c) yellows111`); +switch(processObj.argv[2]) { + case "psu": { + let inputFile = filesystem.readFileSync(processObj.argv[3] ? processObj.argv[3] : "file.psu"); + const parsed = iconjs.readEmsPsuFile(inputFile.buffer.slice(inputFile.byteOffset, inputFile.byteOffset + inputFile.byteLength)); + const PS2D = iconjs.readPS2D(parsed[parsed.rootDirectory]["icon.sys"].data); + let output = {parsed, PS2D} + Object.keys(PS2D.filenames).forEach(function(file) { + output[file] = iconjs.readIconFile(parsed[parsed.rootDirectory][PS2D.filenames[file]].data); + }); + console.log(output); + break; + } + case "psv": { + let inputFile = filesystem.readFileSync(processObj.argv[3] ? processObj.argv[3] : "file.psv"); + const parsed = iconjs.readPsvFile(inputFile.buffer.slice(inputFile.byteOffset, inputFile.byteOffset + inputFile.byteLength)); + console.log(parsed); + const PS2D = iconjs.readPS2D(parsed["icon.sys"]); + let output = {parsed, PS2D}; + console.log(output); + break; + } + case "sps": + case "xps": { + let inputFile = filesystem.readFileSync(processObj.argv[3] ? processObj.argv[3] : "file.sps"); + const parsed = iconjs.readSharkXPortSxpsFile(inputFile.buffer.slice(inputFile.byteOffset, inputFile.byteOffset + inputFile.byteLength)); + console.log(parsed); + const PS2D = iconjs.readPS2D(parsed[parsed.rootDirectory]["icon.sys"].data); + let output = {parsed, PS2D} + Object.keys(PS2D.filenames).forEach(function(file) { + output[file] = iconjs.readIconFile(parsed[parsed.rootDirectory][PS2D.filenames[file]].data); + }); + console.log(output); + break; + } + case "sys": { + let inputFile = filesystem.readFileSync(processObj.argv[3] ? processObj.argv[3] : "icon.sys"); + const metadata = iconjs.readPS2D(inputFile.buffer.slice(inputFile.byteOffset, inputFile.byteOffset + inputFile.byteLength)); + console.log("\noutput:", metadata, "\n") + if(processObj.argv.length > 4 && processObj.argv[4].toLowerCase() === "--no-read-models") {break;} else { + Object.keys(metadata.filenames).forEach(function(file) { + let getFile = filesystem.readFileSync(metadata.filenames[file]); + const output = iconjs.readIconFile(getFile.buffer.slice(getFile.byteOffset, getFile.byteOffset + getFile.byteLength)); + //console.log(individialIcon); + console.log(`contents of ${metadata.filenames[file]} (${file}):`, output, "\n"); + }); + } + break; + } + default: { + //Template literal goes here. + console.log( +`${(processObj.argv.length > 2) ? "Unknown argument: "+processObj.argv[2]+"\n\n": ""}icondumper2 node.js client subcommands: +psu: Read a EMS Memory Adapter export file. +psv: Read a PS3 export file. +sps: Read a SharkPort export file. +xps: Read a X-Port export file. - Object.keys(metadata.filenames).forEach(function(file) { - let getFile = filesystem.readFileSync(metadata.filenames[file]); - const output = iconjs.readIconFile(getFile.buffer.slice(getFile.byteOffset, getFile.byteOffset + getFile.byteLength)); - //console.log(individialIcon); - console.log(`contents of ${metadata.filenames[file]} (${file}):`, output, "\n"); -}); +sys: Read a icon.sys (964 bytes) file, and attempt + to read icon files from the current directory. + (suppress behaviour with --no-read-models) +` ); // end of template + } } \ No newline at end of file diff --git a/input.htm b/input.htm index 2dce93a..1a4c1bc 100644 --- a/input.htm +++ b/input.htm @@ -28,6 +28,7 @@ attribute vec4 a_color; uniform float u_rotation; + uniform float u_scale; uniform highp vec3 u_ambientLight; //uniform highp vec3 u_lightColorA; //uniform highp vec3 u_lightColorB; @@ -44,7 +45,7 @@ (a_position.x * pos.x) + (a_position.z * pos.y), //transform the x position (0.0 - a_position.y) - 2.75, // invert the y position and move down -2.75, which will center the model (a_position.x * -pos.y) + (a_position.z * pos.x), //transform the z position - 3.5 + u_scale ); // flip it, scale it v_textureCoords = a_textureCoords; @@ -72,10 +73,13 @@ mediump vec4 texture_c = texture2D(u_sampler, v_textureCoords); highp vec3 ambientColorT = (u_ambientLight * vec3(texture_c)); highp vec3 ambientColorV = (u_ambientLight * vec3(v_color)); - //This has issues with oversaturation, but it means blended icons work. + //This has issues with oversaturation (JXCR), but it means blended icons work. + //This also makes scaling a bit strange (JXCR, WLK). Why does it change depending on the scale? if(v_color == vec4(1.0,1.0,1.0,1.0)) { gl_FragColor = vec4((ambientColorT * ambientColorV), texture_c.a); } else { + //WLK *SHOULD* follow this path, but doesn't. What can I do to fix this? + //Removing this path makes the models very dark, doing this fixes it, with oversaturation on false positives. gl_FragColor = vec4((ambientColorT * ambientColorV) * 2.0, texture_c.a); } } @@ -113,9 +117,9 @@

No File

Loaded

- Background/icon preview (rotate: ←/→ keys):
- - + Background/icon preview (rotate: ←/→ keys, scale: ↑/↓ keys):
+ +

Normal: (no file) Copying: (no file) Deleting: (no file)

@@ -146,28 +150,52 @@ File comments: (no title) - (no description)

icondumper2 (unknown icon.js version) [C: Loading...] — © 2023 yellows111 - + \ No newline at end of file