Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions components/03-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,22 @@ class SteamUserMessages extends SteamUserConnection {
* Decode a protobuf.
* @param {object} proto - The protobuf class
* @param {Buffer|ByteBuffer} encoded - The data to decode
* @param {boolean} shouldReplaceDefaults
* @returns {object}
* @protected
*/
static _decodeProto(proto, encoded) {
static _decodeProto(proto, encoded, shouldReplaceDefaults = true) {
if (ByteBuffer.isByteBuffer(encoded)) {
encoded = encoded.toBuffer();
}

let decoded = proto.decode(encoded);
let objNoDefaults = proto.toObject(decoded, {longs: String});
let objWithDefaults = proto.toObject(decoded, {defaults: true, longs: String});
return replaceDefaults(objNoDefaults, objWithDefaults);
let obj = proto.toObject(decoded, {defaults: true, longs: String});
if (shouldReplaceDefaults) {
let objNoDefaults = proto.toObject(decoded, {longs: String});
obj = replaceDefaults(objNoDefaults, obj);
}
return obj;

function replaceDefaults(noDefaults, withDefaults) {
if (Array.isArray(withDefaults)) {
Expand Down
39 changes: 13 additions & 26 deletions components/content_manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports.parse = function(buffer) {
buffer = ByteBuffer.wrap(buffer, ByteBuffer.LITTLE_ENDIAN);
}

let manifest = {};
let files = [];
let magic;
let meta;
let length;
Expand All @@ -25,13 +25,13 @@ exports.parse = function(buffer) {
switch (magic) {
case PROTOBUF_PAYLOAD_MAGIC:
length = buffer.readUint32();
manifest.files = SteamUserMessages._decodeProto(Schema.ContentManifestPayload, buffer.slice(buffer.offset, buffer.offset + length)).mappings;
files = SteamUserMessages._decodeProto(Schema.ContentManifestPayload, buffer.slice(buffer.offset, buffer.offset + length), false).mappings;
buffer.skip(length);
break;

case PROTOBUF_METADATA_MAGIC:
length = buffer.readUint32();
meta = SteamUserMessages._decodeProto(Schema.ContentManifestMetadata, buffer.slice(buffer.offset, buffer.offset + length));
meta = SteamUserMessages._decodeProto(Schema.ContentManifestMetadata, buffer.slice(buffer.offset, buffer.offset + length), false);
buffer.skip(length);
break;

Expand All @@ -53,33 +53,20 @@ exports.parse = function(buffer) {
}
}

(manifest.files || []).forEach(function process(file) {
for (let i in file) {
if (!Object.hasOwnProperty.call(file, i)) {
continue;
}

if (file[i] instanceof ByteBuffer) {
file[i] = file[i].toString('hex');
} else if (file[i] instanceof ByteBuffer.Long) {
file[i] = file[i].toString();
} else if (Buffer.isBuffer(file[i])) {
file[i] = file[i].toString('hex');
} else if (file[i] && !Buffer.isBuffer(file[i]) && typeof file[i] === 'object') {
process(file[i]);
files.forEach(function(file) {
file.sha_filename = file.sha_filename.toString('hex');
file.sha_content = file.sha_content.toString('hex');
if (file.chunks) {
for (const chunk of file.chunks) {
chunk.sha = chunk.sha.toString('hex');
}
}
});

if (meta) {
for (let i in meta) {
if (Object.hasOwnProperty.call(meta, i)) {
manifest[i] = meta[i] instanceof ByteBuffer.Long ? meta[i].toString() : meta[i];
}
if ('linktarget' in file) {
file.linktarget = file.linktarget ? file.linktarget : null;
}
}
});

return manifest;
return { files, ...meta };
};

exports.decryptFilenames = function(manifest, key) {
Expand Down