mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-22 07:29:13 +00:00
organization
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
module.exports = (id, chunkData, hasSubchunks) => {
|
||||
if (chunkData.length > 0x7fff) {
|
||||
throw new Error('chunkData can not be greater than 32767 bytes');
|
||||
}
|
||||
|
||||
const header = Buffer.alloc(4);
|
||||
header.writeUInt16LE(id);
|
||||
const chunkLengthBinaryString = chunkData.length.toString(2).padStart(15, '0');
|
||||
const secondByteBinary = `${hasSubchunks ? '1' : '0'}${chunkLengthBinaryString}`;
|
||||
header.writeUInt16LE(parseInt(secondByteBinary, 2), 2);
|
||||
|
||||
return Buffer.concat([header, chunkData]);
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (packetHeaderChunk, trackerListChunk) =>
|
||||
chunk(0x6755, Buffer.concat([packetHeaderChunk, trackerListChunk]), true);
|
||||
@@ -0,0 +1,9 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (x, y, z) => {
|
||||
const buf = Buffer.alloc(12);
|
||||
buf.writeFloatLE(x);
|
||||
buf.writeFloatLE(y, 4);
|
||||
buf.writeFloatLE(z, 8);
|
||||
return chunk(0x0004, buf, false);
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (trackerId, fieldChunks) => chunk(trackerId, Buffer.concat(fieldChunks), true);
|
||||
@@ -0,0 +1,3 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (trackerChunks) => chunk(0x0001, Buffer.concat(trackerChunks), true);
|
||||
@@ -0,0 +1,9 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (x, y, z) => {
|
||||
const buf = Buffer.alloc(12);
|
||||
buf.writeFloatLE(x);
|
||||
buf.writeFloatLE(y, 4);
|
||||
buf.writeFloatLE(z, 8);
|
||||
return chunk(0x0002, buf, false);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (x, y, z) => {
|
||||
const buf = Buffer.alloc(12);
|
||||
buf.writeFloatLE(x);
|
||||
buf.writeFloatLE(y, 4);
|
||||
buf.writeFloatLE(z, 8);
|
||||
return chunk(0x0000, buf, false);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (x, y, z) => {
|
||||
const buf = Buffer.alloc(12);
|
||||
buf.writeFloatLE(x);
|
||||
buf.writeFloatLE(y, 4);
|
||||
buf.writeFloatLE(z, 8);
|
||||
return chunk(0x0001, buf, false);
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (validity) => {
|
||||
const buf = Buffer.alloc(4);
|
||||
buf.writeFloatLE(validity);
|
||||
return chunk(0x0003, buf, false);
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (timestamp) => {
|
||||
const buf = Buffer.alloc(8);
|
||||
const timestampHigh = timestamp.toString(2).padStart(64, '0').substring(0, 32);
|
||||
const timestampLow = timestamp.toString(2).padStart(64, '0').substring(32);
|
||||
buf.writeUInt32LE(parseInt(timestampLow, 2));
|
||||
buf.writeUInt32LE(parseInt(timestampHigh, 2), 4);
|
||||
return chunk(0x0006, buf, false);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (x, y, z) => {
|
||||
const buf = Buffer.alloc(12);
|
||||
buf.writeFloatLE(x);
|
||||
buf.writeFloatLE(y, 4);
|
||||
buf.writeFloatLE(z, 8);
|
||||
return chunk(0x0005, buf, false);
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (packetHeaderChunk, systemNameChunk, trackerListChunk) =>
|
||||
chunk(0x6756, Buffer.concat([packetHeaderChunk, systemNameChunk, trackerListChunk]), true);
|
||||
@@ -0,0 +1,3 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (systemName) => chunk(0x0001, Buffer.from(systemName), false);
|
||||
@@ -0,0 +1,3 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (trackerId, trackerNameChunk) => chunk(trackerId, trackerNameChunk, true);
|
||||
@@ -0,0 +1,3 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (trackerChunks) => chunk(0x0002, Buffer.concat(trackerChunks), true);
|
||||
@@ -0,0 +1,3 @@
|
||||
const chunk = require('../chunk');
|
||||
|
||||
module.exports = (trackerName) => chunk(0x0000, Buffer.from(trackerName), false);
|
||||
@@ -0,0 +1,15 @@
|
||||
const chunk = require('./chunk');
|
||||
|
||||
module.exports = (timestamp, versionHigh, versionLow, frameId, framePacketCount) => {
|
||||
const packetHeader = Buffer.alloc(12);
|
||||
const timestampHigh = timestamp.toString(2).padStart(64, '0').substring(0, 32);
|
||||
const timestampLow = timestamp.toString(2).padStart(64, '0').substring(32);
|
||||
packetHeader.writeUInt32LE(parseInt(timestampLow, 2));
|
||||
packetHeader.writeUInt32LE(parseInt(timestampHigh, 2), 4);
|
||||
packetHeader.writeUint8(versionHigh, 8);
|
||||
packetHeader.writeUint8(versionLow, 9);
|
||||
packetHeader.writeUint8(frameId, 10);
|
||||
packetHeader.writeUint8(framePacketCount, 11);
|
||||
|
||||
return chunk(0x0000, packetHeader, false);
|
||||
};
|
||||
Reference in New Issue
Block a user