RBDB

RocketBall Decoder Buffer

Från och med 2022-07-18. Se den senaste versionen.

Detta skript bör inte installeras direkt. Det är ett bibliotek för andra skript att inkludera med meta-direktivet // @require https://update.greatest.deepsurf.us/scripts/448028/1071232/RBDB.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         RBDB
// @version      1.0
// @author       0vC4
// @description  RocketBall Decoder Buffer
// @namespace    https://greatest.deepsurf.us/users/670183-exnonull
// @license      MIT
// ==/UserScript==

class ReadBuffer {
    offset = 0
    buffer = []
    constructor(packet) {
        this.buffer = [...packet];
        this.offset = 0
    }

    get skip8() {
        this.u8;
        return this;
    }
    get skip16() {
        this.u16;
        return this;
    }
    get skip32() {
        this.u32;
        return this;
    }
    get skip64() {
        this.u64;
        return this;
    }
    get skip7() {
        this.int7;
        return this;
    }
    get skipString() {
        this.string;
        return this;
    }

    get u8() {
        let offset = this.offset;
        this.offset++;
        return new Uint8Array([this.buffer[offset]])[0];
    }
    get u16() {
        let offset = this.offset;
        this.offset += 2;
        return new Uint16Array(new Uint8Array(this.buffer.slice(offset, this.offset)).buffer)[0];
    }
    get u32() {
        let offset = this.offset;
        this.offset += 4;
        return new Uint32Array(new Uint8Array(this.buffer.slice(offset, this.offset)).buffer)[0];
    }
    get u64() {
        let offset = this.offset;
        this.offset += 8;
        return new BigUint64Array(new Uint8Array(this.buffer.slice(offset, this.offset)).buffer)[0];
    }

    get s8() {
        let offset = this.offset;
        this.offset++;
        return new Int8Array([this.buffer[offset]])[0];
    }
    get s16() {
        let offset = this.offset;
        this.offset += 2;
        return new Int16Array(new Uint8Array(this.buffer.slice(offset, this.offset)).buffer)[0];
    }
    get s32() {
        let offset = this.offset;
        this.offset += 4;
        return new Int32Array(new Uint8Array(this.buffer.slice(offset, this.offset)).buffer)[0];
    }
    get s64() {
        let offset = this.offset;
        this.offset += 8;
        return new BigInt64Array(new Uint8Array(this.buffer.slice(offset, this.offset)).buffer)[0];
    }

    get f32() {
        let offset = this.offset;
        this.offset += 4;
        return new Float32Array(new Uint8Array(this.buffer.slice(offset, this.offset)).buffer)[0];
    }
    get f64() {
        let offset = this.offset;
        this.offset += 8;
        return new Float64Array(new Uint8Array(this.buffer.slice(offset, this.offset)).buffer)[0];
    }

    get int7() {
        let offset = 0;
        let num = 0;
        while (offset != 0b100011) {
            let byte = this.buffer[this.offset + offset/7];
            num |= (byte&0x7f)<<offset;
            offset += 7;
            if ((byte&0x80) == 0) {
                this.offset += offset/7;
                return num;
            }
        }
        this.offset += offset/7;
        return num;
    }

    get string() {
        let offset = this.offset;
        let size = this.int7;
        this.offset += size;
        return new TextDecoder().decode(this.buffer.slice(offset, this.offset));
    }

    get array() {
        let offset = this.offset;
        this.offset += this.buffer.length-this.offset;
        return new Uint8Array(this.buffer.slice(offset, this.offset));
    }
}

class WriteBuffer {
    offset = 0
    buffer = []
    constructor(buffer) {
        this.buffer = [...buffer];
        this.offset = buffer.length;
    }

    u8(...nums) {
        for (let byte of new Uint8Array([...nums]))
            this.buffer[this.offset++] = byte;
        return this;
    }
    u16(...nums) {
        for (let byte of new Uint8Array(new Uint16Array([...nums]).buffer))
            this.buffer[this.offset++] = byte;
        return this;
    }
    u32(...nums) {
        for (let byte of new Uint8Array(new Uint32Array([...nums]).buffer))
            this.buffer[this.offset++] = byte;
        return this;
    }
    u64(...nums) {
        for (let byte of new Uint8Array(new BigUint64Array([...nums]).buffer))
            this.buffer[this.offset++] = byte;
        return this;
    }

    s8(...nums) {
        for (let byte of new Uint8Array([...nums]))
            this.buffer[this.offset++] = byte;
        return this;
    }
    s16(...nums) {
        for (let byte of new Uint8Array(new Int16Array([...nums]).buffer))
            this.buffer[this.offset++] = byte;
        return this;
    }
    s32(...nums) {
        for (let byte of new Uint8Array(new Int32Array([...nums]).buffer))
            this.buffer[this.offset++] = byte;
        return this;
    }
    s64(...nums) {
        for (let byte of new Uint8Array(new BigInt64Array([...nums]).buffer))
            this.buffer[this.offset++] = byte;
        return this;
    }

    f32(...nums) {
        for (let byte of new Uint8Array(new Float32Array([...nums]).buffer))
            this.buffer[this.offset++] = byte;
        return this;
    }
    f64(...nums) {
        for (let byte of new Uint8Array(new Float64Array([...nums]).buffer))
            this.buffer[this.offset++] = byte;
        return this;
    }

    int7(...nums) {
        const bytes = [];

        for (let num of nums) {
            while(num >= 0x80) {
                num >>= 7;
                bytes.push((num|0x80)%0x100);
            }
            bytes.push(num%0x100);
        }

        for (let byte of bytes)
            this.buffer[this.offset++] = byte;

        return this;
    }

    string(...strs) {
        for (let str of strs) {
            str = new TextEncoder().encode(str);
            this.int7(str.length);
            for (let byte of new TextEncoder().encode(str))
                this.buffer[this.offset++] = new Uint8Array([byte])[0];
        }
        return this;
    }

    array(bytes) {
        for (let byte of bytes)
            this.buffer[this.offset++] = new Uint8Array([byte])[0];
        return this;
    }
}
// 0vC4#7152