Socket
Socket
Sign inDemoInstall

satisfactory-json

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

satisfactory-json - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

lib/streams.d.ts

2

lib/Archive.d.ts

@@ -52,4 +52,4 @@ /// <reference types="node" />

bytesRead: number;
cursor: number;
private buffer;
private cursor;
constructor(buffer: Buffer);

@@ -56,0 +56,0 @@ isSaving(): boolean;

@@ -17,2 +17,3 @@ #!/usr/bin/env node

.arguments('<source> <target>')
.option('-t, --time', 'time program')
.action((source, target) => {

@@ -36,3 +37,11 @@ sourceValue = source;

const json = JSON.parse(data);
if (program.time) {
// tslint:disable-next-line: no-console
console.time('json2sav');
}
const output = transform_1.json2sav(json);
if (program.time) {
// tslint:disable-next-line: no-console
console.timeEnd('json2sav');
}
fs.writeFile(targetValue, output, 'binary', (error2) => {

@@ -39,0 +48,0 @@ if (error2) {

@@ -16,2 +16,3 @@ #!/usr/bin/env node

.arguments('<source> <target>')
.option('-t, --time', 'time program')
.action((source, target) => {

@@ -34,3 +35,13 @@ sourceValue = source;

}
const output = JSON.stringify(transform_1.sav2json(Buffer.from(data, 'binary')));
const binaryData = Buffer.from(data, 'binary');
if (program.time) {
// tslint:disable-next-line: no-console
console.time('sav2json');
}
const transformed = transform_1.sav2json(binaryData);
if (program.time) {
// tslint:disable-next-line: no-console
console.timeEnd('sav2json');
}
const output = JSON.stringify(transformed);
fs.writeFile(targetValue, output, 'utf8', (error2) => {

@@ -37,0 +48,0 @@ if (error2) {

@@ -31,2 +31,7 @@ "use strict";

break;
case 'StrProperty':
for (let i = 0; i < itemCount.count; i++) {
ar._String(property.value.values, i);
}
break;
case 'ObjectProperty':

@@ -33,0 +38,0 @@ for (let i = 0; i < itemCount.count; i++) {

@@ -22,2 +22,91 @@ "use strict";

ar._Int(count, 'count');
let keyTransformFunc;
let valueTransformFunc;
// set function to transform the keys based on the type
switch (property.value.keyType) {
case 'IntProperty':
keyTransformFunc = transformIntPropertyKey;
break;
case 'ObjectProperty':
keyTransformFunc = transformObjectPropertyKey;
break;
case 'StrProperty':
keyTransformFunc = transformStringPropertyKey;
break;
default:
throw new Error('Unimplemented key type `' + property.value.keyType
+ '` in MapProperty `' + property.name + '`');
}
// set function to transform the values based on the type
switch (property.value.valueType) {
case 'StructProperty':
valueTransformFunc = transformStructPropertyValue;
break;
case 'ByteProperty':
/*
The following two maps both have the property.value.valueType ByteProperty.
But in the first case the values are stored as bytes and in the second case they are
stored as strings.
UPROPERTY(VisibleAnywhere, SaveGame)
TMap<FName, uint8> TestByteMap;
UPROPERTY(VisibleAnywhere, SaveGame)
TMap<FName, TEnumAsByte< EEnabled >> TestEnumAsByteMap;
*/
let isEnum = false;
if (ar.isSaving()) {
if (property.value.values.length > 0) {
isEnum = typeof property.value.values[0].value === 'string';
}
}
else {
// we need to determine whether the value is a string or just a byte
if (count.count > 0) { // with 0 elements it does not matter
isEnum = true;
const lar = ar;
const bytesRead = lar.bytesRead;
const cursor = lar.cursor;
try {
// peek key
const tmp = { key: '' };
keyTransformFunc(ar, tmp);
// peek value (try string)
const str = lar.readLengthPrefixedString();
if (str.length > 512) {
// heuristic in case the next key is magically again at a correct place
throw new Error('enum values should not be that long');
}
// peek next key (if two or more elements)
if (count.count > 1) {
keyTransformFunc(ar, tmp);
}
else {
// or peek string as name of the next property
lar.readLengthPrefixedString();
}
// if we managed to get here, this is probably a enum as we managed to get a string for
// the value correctly
}
catch (e) {
// it failed, so it's probably a byte
isEnum = false;
}
// reset cursor
lar.bytesRead = bytesRead;
lar.cursor = cursor;
}
}
if (isEnum) {
valueTransformFunc = transformEnumBytePropertyValue;
}
else {
valueTransformFunc = transformBytePropertyValue;
}
break;
default:
throw new Error('Unimplemented value type `' + property.value.valueType
+ '` in MapProperty `' + property.name + '`');
}
for (let i = 0; i < count.count; i++) {

@@ -28,56 +117,54 @@ if (ar.isLoading()) {

// transform key
switch (property.value.keyType) {
case 'IntProperty':
ar._Int(property.value.values[i], 'key');
break;
case 'ObjectProperty':
if (ar.isLoading()) {
property.value.values[i].key = {};
}
ar._String(property.value.values[i].key, 'levelName');
ar._String(property.value.values[i].key, 'pathName');
break;
default:
throw new Error('Unimplemented key type `' + property.value.keyType
+ '` in MapProperty `' + property.name + '`');
}
keyTransformFunc(ar, property.value.values[i]);
// transform value
switch (property.value.valueType) {
case 'StructProperty':
if (ar.isSaving()) {
const sar = ar;
for (const element of property.value.values[i].value) {
ar._String(element, 'name'); // Tag.Name
Property_1.default(ar, element);
}
sar.writeLengthPrefixedString('None'); // end of properties
}
else {
const props = [];
while (true) {
const innerProperty = {
name: '',
type: '',
index: 0,
value: ''
};
ar._String(innerProperty, 'name'); // Tag.Name
if (innerProperty.name === 'None') {
break; // end of properties
}
Property_1.default(ar, innerProperty);
props.push(innerProperty);
}
property.value.values[i].value = props;
}
break;
case 'ByteProperty':
ar._Byte(property.value.values[i], 'value');
break;
default:
throw new Error('Unimplemented value type `' + property.value.valueType
+ '` in MapProperty `' + property.name + '`');
valueTransformFunc(ar, property.value.values[i]);
}
}
exports.default = transformMapProperty;
function transformIntPropertyKey(ar, value) {
ar._Int(value, 'key');
}
function transformObjectPropertyKey(ar, value) {
if (ar.isLoading()) {
value.key = {};
}
ar._String(value.key, 'levelName');
ar._String(value.key, 'pathName');
}
function transformStringPropertyKey(ar, value) {
ar._String(value, 'key');
}
function transformStructPropertyValue(ar, value) {
if (ar.isSaving()) {
const sar = ar;
for (const element of value.value) {
ar._String(element, 'name'); // Tag.Name
Property_1.default(ar, element);
}
sar.writeLengthPrefixedString('None'); // end of properties
}
else {
const props = [];
while (true) {
const innerProperty = {
name: '',
type: '',
index: 0,
value: ''
};
ar._String(innerProperty, 'name'); // Tag.Name
if (innerProperty.name === 'None') {
break; // end of properties
}
Property_1.default(ar, innerProperty);
props.push(innerProperty);
}
value.value = props;
}
}
exports.default = transformMapProperty;
function transformBytePropertyValue(ar, value) {
ar._Byte(value, 'value');
}
function transformEnumBytePropertyValue(ar, value) {
ar._String(value, 'value');
}
{
"name": "satisfactory-json",
"version": "0.0.21",
"version": "0.0.22",
"description": "Convert Satisfactory save files to JSON and back",

@@ -25,4 +25,4 @@ "main": "lib/index.js",

"postversion": "git push && git push --tags",
"sav2json": "ts-node src/cli/sav2json.ts",
"json2sav": "ts-node src/cli/json2sav.ts"
"sav2json": "node lib/cli/sav2json.js",
"json2sav": "node lib/cli/json2sav.js"
},

@@ -29,0 +29,0 @@ "files": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc