Compare commits
2 commits
296e84b4cf
...
4f335421b4
Author | SHA1 | Date | |
---|---|---|---|
4f335421b4 | |||
bf8b3f73a6 |
9 changed files with 77 additions and 10 deletions
|
@ -82,4 +82,26 @@ export class ReaderBase {
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public readVarint() {
|
||||||
|
let total = 0;
|
||||||
|
let shift = 0;
|
||||||
|
let byte = this.readUByte();
|
||||||
|
|
||||||
|
if (!(byte & 0x80)) {
|
||||||
|
return (byte & 0x7F);
|
||||||
|
} else {
|
||||||
|
let end = false;
|
||||||
|
while (!end) {
|
||||||
|
if (shift) {
|
||||||
|
byte = this.readUByte();
|
||||||
|
}
|
||||||
|
total |= ((byte & 0x7F) << shift);
|
||||||
|
end = !(byte & 0x80);
|
||||||
|
shift += 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -112,4 +112,17 @@ export class WriterBase {
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public writeVarint(value: number) {
|
||||||
|
let temp: number;
|
||||||
|
while (value > 0) {
|
||||||
|
temp = value & 0x7F;
|
||||||
|
if (!!(value >>= 7)) {
|
||||||
|
temp |= 0xB4;
|
||||||
|
}
|
||||||
|
this.writeUByte(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
18
package-lock.json
generated
18
package-lock.json
generated
|
@ -11,9 +11,9 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"check-outdated": "^2.12.0",
|
"check-outdated": "^2.12.0",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"terser": "^5.27.0",
|
"terser": "^5.37.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.7.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@cspotcode/source-map-support": {
|
"node_modules/@cspotcode/source-map-support": {
|
||||||
|
@ -1289,10 +1289,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/terser": {
|
"node_modules/terser": {
|
||||||
"version": "5.27.0",
|
"version": "5.37.0",
|
||||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.27.0.tgz",
|
"resolved": "https://registry.npmjs.org/terser/-/terser-5.37.0.tgz",
|
||||||
"integrity": "sha512-bi1HRwVRskAjheeYl291n3JC4GgO/Ty4z1nVs5AAsmonJulGxpSektecnNedrwK9C7vpvVtcX3cw00VSLt7U2A==",
|
"integrity": "sha512-B8wRRkmre4ERucLM/uXx4MOV5cbnOlVAqUst+1+iLKPI0dOgFO28f84ptoQt9HEI537PMzfYa/d+GEPKTRXmYA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jridgewell/source-map": "^0.3.3",
|
"@jridgewell/source-map": "^0.3.3",
|
||||||
"acorn": "^8.8.2",
|
"acorn": "^8.8.2",
|
||||||
|
@ -1364,10 +1365,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "5.3.3",
|
"version": "5.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz",
|
||||||
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
|
"integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
"tsserver": "bin/tsserver"
|
"tsserver": "bin/tsserver"
|
||||||
|
|
|
@ -32,8 +32,8 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"check-outdated": "^2.12.0",
|
"check-outdated": "^2.12.0",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"terser": "^5.27.0",
|
"terser": "^5.37.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.7.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ export interface IReader {
|
||||||
readUShortString(): string,
|
readUShortString(): string,
|
||||||
readShortString(): string,
|
readShortString(): string,
|
||||||
readBytesAsString(bytesToRead:number): string,
|
readBytesAsString(bytesToRead:number): string,
|
||||||
|
readVarint(): number,
|
||||||
readShort(): number,
|
readShort(): number,
|
||||||
readUShort(): number,
|
readUShort(): number,
|
||||||
readInt(): number,
|
readInt(): number,
|
||||||
|
@ -25,4 +26,6 @@ export interface IReader {
|
||||||
readShortsAsString(shortsToRead:number): string,
|
readShortsAsString(shortsToRead:number): string,
|
||||||
readUString16(): string,
|
readUString16(): string,
|
||||||
readString16(): string,
|
readString16(): string,
|
||||||
|
readArbInt(length: number): number,
|
||||||
|
readArbUInt(length: number): number,
|
||||||
}
|
}
|
|
@ -106,4 +106,16 @@ export class ReaderBE extends ReaderBase implements IReader {
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public readArbInt(length: number) {
|
||||||
|
const value = this.buffer.readIntBE(this.offset, length);
|
||||||
|
this.offset += length;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public readArbUInt(length: number) {
|
||||||
|
const value = this.buffer.readUIntBE(this.offset, length);
|
||||||
|
this.offset += length;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -106,4 +106,16 @@ export class ReaderLE extends ReaderBase implements IReader {
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public readArbInt(length: number) {
|
||||||
|
const value = this.buffer.readIntLE(this.offset, length);
|
||||||
|
this.offset += length;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public readArbUInt(length: number) {
|
||||||
|
const value = this.buffer.readUIntLE(this.offset, length);
|
||||||
|
this.offset += length;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -12,6 +12,7 @@ export interface IWriter {
|
||||||
writeUByte(value:number): IWriter,
|
writeUByte(value:number): IWriter,
|
||||||
writeBool(value:boolean|number): IWriter,
|
writeBool(value:boolean|number): IWriter,
|
||||||
writeStringAsBytes(text:string): IWriter,
|
writeStringAsBytes(text:string): IWriter,
|
||||||
|
writeVarint(value: number): IWriter,
|
||||||
writeShort(value:number): IWriter,
|
writeShort(value:number): IWriter,
|
||||||
writeUShort(value:number): IWriter,
|
writeUShort(value:number): IWriter,
|
||||||
writeInt(value:number): IWriter,
|
writeInt(value:number): IWriter,
|
||||||
|
|
|
@ -173,6 +173,8 @@ export class WriterBE extends WriterBase implements IWriter {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ! TODO: Implement this properly. This was a quick, hacky implementation for mc-beta-server
|
||||||
|
// ! as it is used in one single place in the whole game's protocol.
|
||||||
public writeJavaUTF(text: string) {
|
public writeJavaUTF(text: string) {
|
||||||
const dataWriter = new WriterBE();
|
const dataWriter = new WriterBE();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue