RBDB

RocketBall Decoder Buffer

נכון ליום 18-07-2022. ראה הגרסה האחרונה.

אין להתקין סקריפט זה ישירות. זוהי ספריה עבור סקריפטים אחרים // @require https://update.greatest.deepsurf.us/scripts/448028/1071502/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 = []
    finish = false
    constructor(packet) {
        this.buffer = [...packet];
        this.offset = 0
    }

    next(size=1) {
        let offset = this.offset;
        this.offset += size;
        if (this.offset == this.buffer.length) this.finish = true;
        return offset;
    }

    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() {
        return new Uint8Array([this.buffer[this.next()]])[0];
    }
    get u16() {
        return new Uint16Array(new Uint8Array(this.buffer.slice(this.next(2), this.offset)).buffer)[0];
    }
    get u32() {
        return new Uint32Array(new Uint8Array(this.buffer.slice(this.next(4), this.offset)).buffer)[0];
    }
    get u64() {
        return new BigUint64Array(new Uint8Array(this.buffer.slice(this.next(8), this.offset)).buffer)[0];
    }

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

    get f32() {
        return new Float32Array(new Uint8Array(this.buffer.slice(this.next(4), this.offset)).buffer)[0];
    }
    get f64() {
        return new Float64Array(new Uint8Array(this.buffer.slice(this.next(8), 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.next(offset/7);
                return num;
            }
        }
        this.next(offset/7);
        return num;
    }

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

    get array7() {
        return new Uint8Array(this.buffer.slice(this.next(this.int7), this.offset));
    }

    get string() {
        return new TextDecoder().decode(this.array7);
    }

    get pos() {
        const buffer = new ReadBuffer(this.array7);
        const scheme = [
            [13, 'x', 'f32'],
            [21, 'y', 'f32'],
        ];

        const data = {};
        while (!buffer.finish) {
            const slotId = buffer.u8;
            const [id, key, type] = scheme.find(([id]) => id == slotId);
            data[key] = buffer[type];
        }

        return data;
    }

    get object() {
        const buffer = new ReadBuffer(this.array7);
        const scheme = [
            [10, 'position', 'pos'],
            [16, 'type', 'int7'],
            [24, 'id', 'int7'],
            [37, 'angle', 'f32'],
            [42, 'speed', 'pos'],
        ];

        const data = {};
        while (!buffer.finish) {
            const slotId = buffer.u8;
            const [id, key, type] = scheme.find(([id]) => id == slotId);
            data[key] = buffer[type];
        }

        return data;
    }

    get entity() {
        const buffer = new ReadBuffer(this.array7);
        const scheme = [
            [8, 'id', 'int7'],
            [18, 'data', 'object'],
        ];

        const data = {};
        while (!buffer.finish) {
            const slotId = buffer.u8;
            const [id, key, type] = scheme.find(([id]) => id == slotId);
            data[key] = buffer[type];
        }

        return data;
    }

    get entities() {
        const buffer = new ReadBuffer(this.array7);
        const scheme = [
            [10, 'item', 'entity'],
        ];

        const data = [];
        while (!buffer.finish) {
            const slotId = buffer.u8;
            const [id, key, type] = scheme.find(([id]) => id == slotId);
            data.push(buffer[type]);
        }

        return data;
    }

    get user() {
        const buffer = new ReadBuffer(this.array7);
        const scheme = [
            [8, 'id', 'int7'],
            [18, 'username', 'string'],
            [40, 'team', 'u8'],
            [56, 'magic', 'u8'],
            [64, 'magic2', 'u16'],
        ];

        const data = {};
        while (!buffer.finish) {
            const slotId = buffer.u8;
            const [id, key, type] = scheme.find(([id]) => id == slotId);
            data[key] = buffer[type];
        }

        return data;
    }

    get users() {
        const buffer = new ReadBuffer(this.array7);
        const scheme = [
            [10, 'item', 'user'],
        ];

        const data = [];
        while (!buffer.finish) {
            const slotId = buffer.u8;
            const [id, key, type] = scheme.find(([id]) => id == slotId);
            data.push(buffer[type]);
        }

        return data;
    }
}

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;
    }

    array(...arrays) {
        for (let array of arrays)
            for (let byte of array)
                this.buffer[this.offset++] = new Uint8Array([byte])[0];
        return this;
    }

    array7(...arrays) {
        for (let array of arrays) {
            this.int7(array.length);
            for (let byte of array)
                this.buffer[this.offset++] = new Uint8Array([byte])[0];
        }
        return this;
    }

    string(...strs) {
        for (let str of strs) this.array7(new TextEncoder().encode(str));
        return this;
    }
}
// 0vC4#7152