fix SPS/XPS crash, example icon

fix sps/xps parser crash: apparently those 4 bytes were for a third part of metadata for those files. HTML client now shows this information if available.

example icon: id2_example_001 (12 vertices, 4 triangles)

I've saved and included this icon in the .PSU and .SPS formats. .PSV is a bit more complicated for a valid export.

Example icon shows vertex colours with no animation nor includes a texture (texture type 3).

was considering adding new formats, but its not one of the big five (translation: not MAX/PWS or CBS), and I can barely find any examples to test with. Oh well. adding them to gitignore already. If the demand comes up, I've made the related hexpat's for them anyway.

.xpo and .spo (assuming they're like .xpo files) files are out of scope for this project, if anyone asks. Reason being is that they usually exclude icon data, and even icon.sys. This makes it rather useless to me.
This commit is contained in:
yellows111 2023-12-03 17:32:26 +00:00
parent 837dffc4dc
commit 5738fbb09c
9 changed files with 42 additions and 5 deletions

View File

@ -16,7 +16,7 @@ jobs:
- name: Compile documentation with JSDoc
run: npx jsdoc ./icon.js -d ./documentation -R ./README.md
- name: Upload Artifacts
uses: 'actions/upload-artifact@main'
uses: actions/upload-artifact@main
with:
name: JSDoc-compiled Documentation
path: './documentation/*'

3
.gitignore vendored
View File

@ -9,6 +9,9 @@ icon.sys
*.psv
*.xps
*.sps
*.npo
*.p2m
*.md
# Unused data

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,19 @@
# A test 12-vertice icon for testing icondumper2 clients.
# Original Wavefront OBJ file:
o DefaultObject001
v 1.250000 1.000000 0.000000
v -0.750000 1.000000 -1.000000
v -0.750000 1.000000 1.000000
v 0.000000 0.000000 0.000000
vn -0.0000 1.0000 -0.0000
vn -0.8000 -0.6000 -0.0000
vn 0.3904 -0.4880 0.7807
vn 0.3904 -0.4880 -0.7807
vt 0.000000 0.000000
vt 0.875000 0.500000
vt 0.875000 0.750000
s 0
f 1/1/1 2/2/1 3/3/1
f 4/1/2 3/3/2 2/2/2
f 3/3/3 4/1/3 1/1/3
f 4/1/4 2/2/4 1/1/4

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

15
icon.js
View File

@ -8,7 +8,7 @@ ICONJS_STRICT = true;
* @constant {string}
* @default
*/
const ICONJS_VERSION = "0.6.0";
const ICONJS_VERSION = "0.6.1";
/**
* Extension of DataView to add shortcuts for datatypes that I use often.
@ -576,11 +576,22 @@ function readSharkXPortSxpsFile(input) {
offset += (titleLength + 4);
const descriptionLength = u32le(offset);
const description = input.slice(offset + 4, (offset + 4) + descriptionLength);
offset += (descriptionLength + 8);
offset += (descriptionLength + 4);
const description2Length = u32le(offset);
let description2;
if(description2Length !== 0) {
description2 = input.slice(offset + 4, (offset + 4) + description2Length);
offset += (description2Length + 4);
} else {
offset += 4;
}
const comments = {
"game": stringScrubber((new TextDecoder("utf-8")).decode(title)),
"name": stringScrubber((new TextDecoder("utf-8")).decode(description))
}
if(description2Length !== 0) {
comments.desc = stringScrubber((new TextDecoder("utf-8")).decode(description2));
}
const totalSize = u32le(offset);
offset += 4;
const header = readSxpsDescriptor(input.slice(offset, offset + 250));

View File

@ -148,7 +148,7 @@
<span>Date&nbsp;modified: </span><span id="dateModified">--:--:--&nbsp;--/--/----</span><span> UTC+09:00</span>
</p>
<p>
<span>File comments: </span><span id="fileCommentGame">(no title)</span></span><span> - </span><span id="fileCommentName">(no description)</span>
<span>File comments: </span><span id="fileCommentGame">(no title)</span><span> - </span><span id="fileCommentName">(no description)</span><span> - </span><span id="fileCommentDesc">(no other text)</span>
</p>
<script>
// I usually don't do in-body <script>'s, but I didn't want to do an await onload() again
@ -271,6 +271,7 @@
document.getElementById("dateModified").textContent = "--:--:-- --/--/----";
document.getElementById("fileCommentGame").textContent = "(no title)";
document.getElementById("fileCommentName").textContent = "(no description)";
document.getElementById("fileCommentDesc").textContent = "(no other text)";
//reset globalstate parameters
GlobalState.iconState.cachedIconSys = null;
GlobalState.iconState.currentIcon = null;
@ -547,6 +548,9 @@
document.getElementById("dateModified").textContent = `${mTime.hours.toString().padStart("2","0")}:${mTime.minutes.toString().padStart("2","0")}:${mTime.seconds.toString().padStart("2","0")} ${mTime.day.toString().padStart("2","0")}/${mTime.month.toString().padStart("2","0")}/${mTime.year}`;
document.getElementById("fileCommentGame").textContent = vFilesystem.comments.game;
document.getElementById("fileCommentName").textContent = vFilesystem.comments.name;
if(vFilesystem.comments.hasOwnProperty("desc")) {
document.getElementById("fileCommentDesc").textContent = vFilesystem.comments.desc;
}
console.info("model files (*ps)", output2);
console.info("icon.sys (*ps)", output);
} catch(e) {
@ -635,7 +639,7 @@
<span id="version">icondumper2 <a href="./documentation" id="iconjsVersion">(unknown icon.js version)</a> [C: <span id="clientVersion">Loading...</span>] &mdash; &copy; <span id="currentYear">2023</span> yellows111</span>
<script>
document.getElementById("iconjsVersion").textContent = exports.version;
document.getElementById("clientVersion").textContent = "0.6.5";
document.getElementById("clientVersion").textContent = "0.6.6";
document.getElementById("currentYear").textContent = (new Date()).getFullYear().toString();
</script>
</body>