Greasy Fork is available in English.

KBP

Kogama BytePacker

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.greasyfork.org/scripts/470596/1218452/KBP.js

// ==UserScript==
// @name		KBP
// @version		1.0
// @description	Kogama BytePacker
// @author		Unknown
// @match       http://*/*
// @match       https://*/*
// @grant		none
// @run-at		document-start
// ==/UserScript==

const BytePacker=()=>{
    const t = new Worker(window.URL.createObjectURL(new Blob(["onmessage=" + (e => {
            let t = e.data.buffer,
                a = {
                    proto: [],
                    woList: [],
                    links: [],
                    oLinks: []
                };
            const r = Object.fromEntries(Object.entries({
                    PlayModeAvatar: 0,
                    CubeModel: 1,
                    PointLight: 2,
                    TriggerBox: 3,
                    Mover: 4,
                    Path: 5,
                    PathNode: 6,
                    SpawnPoint: 7,
                    CubeModelPrototypeTerrain: 8,
                    Group: 9,
                    Action: 10,
                    BlueprintActivator: 11,
                    ParticleEmitter: 12,
                    SoundEmitter: 13,
                    BlueprintFire: 14,
                    BlueprintSmoke: 15,
                    BlueprintExplosion: 16,
                    Flag: 17,
                    TestLogicCube: 18,
                    Battery: 19,
                    ToggleBox: 20,
                    Negate: 21,
                    And: 22,
                    Explosives: 23,
                    TextMsg: 24,
                    Fire: 25,
                    Smoke: 26,
                    TimeTrigger: 27,
                    Teleporter: 28,
                    Goal: 29,
                    PickupItemHealthPack: 30,
                    PickupItemCenterGun: 31,
                    CubeModelTerrainFineGrained: 32,
                    PressurePlate: 33,
                    PickupItemImpulseGun: 34,
                    PickupItemBazookaGun: 35,
                    PickupItemRailGun: 36,
                    PickupItemSpawner: 37,
                    Skybox: 38,
                    SpawnPointRed: 39,
                    SpawnPointGreen: 40,
                    SpawnPointYellow: 41,
                    SpawnPointBlue: 42,
                    ModelToggle: 43,
                    WaterPlane: 44,
                    Blueprint: 45,
                    PulseBox: 46,
                    RandomBox: 47,
                    SentryGun: 48,
                    CollectibleItem: 49,
                    MovingPlatformNode: 50,
                    WaterPlanePreset: 51,
                    LightPreset: 52,
                    Ghost: 53,
                    PickupCubeGun: 54,
                    CheckPoint: 55,
                    HoverCraft: 56,
                    WorldObjectSpawnerVehicle: 57,
                    MonoPlane: 58,
                    JetPack: 59,
                    RoundCube: 60,
                    AdvancedGhost: 61,
                    HamsterWheel: 62,
                    KillLimit: 63,
                    OculusKillLimit: 64,
                    CountingCube: 65,
                    Jakob4: 118,
                    Jakob5: 119,
                    Jakob6: 120,
                    Jakob7: 121,
                    Jakob8: 122,
                    Jakob9: 123,
                    Jakob10: 124,
                    Jakob11: 125,
                    Jakob12: 126,
                    Jakob13: 127,
                    Jakob14: 128,
                    Jakob15: 129,
                    GamePoint: 130,
                    GamePassProgressionDataObject: 131,
                    Christian3: 132,
                    BuildModeAvatar: 133,
                    AvatarSpawnRoleCreator: 134,
                    GameOptionsDataObject: 135,
                    Christian7: 136,
                    Christian8: 137,
                    Christian9: 138,
                    Christian10: 139,
                    Christian11: 140,
                    Christian12: 141,
                    Christian13: 142,
                    Christian14: 143,
                    Christian15: 144,
                    CameraSettings: 145,
                    GravityCube: 146,
                    GameCoin: 148,
                    GameCoinChest: 149,
                    Theme: 150,
                    Caspar7: 151,
                    Caspar8: 152,
                    Caspar9: 153,
                    Caspar10: 154,
                    Caspar11: 155,
                    Caspar12: 156,
                    Caspar13: 157,
                    Caspar14: 158,
                    Caspar15: 159,
                    ShrinkGun: 160,
                    TeamEditor: 161,
                    TriggerCube: 162,
                    Thomas4: 163,
                    CollectTheItemCollectableInstance: 164,
                    ShootableButton: 165,
                    UseLever: 166,
                    CollectTheItemDropOff: 167,
                    CollectTheItemCollectable: 168,
                    CollectTheItem: 169,
                    WindTurbine: 170,
                    GlobalSoundEmitter: 171,
                    Mathias3: 172,
                    Mathias4: 173,
                    Mathias5: 174,
                    Mathias6: 175,
                    Mathias7: 176,
                    Mathias8: 177,
                    Mathias9: 178,
                    Mathias10: 179,
                    TimeAttackFlag: 180,
                    GamePointChest: 181,
                    Marcus3: 182,
                    Marcus4: 183,
                    Marcus5: 184,
                    Marcus6: 185,
                    Marcus7: 186,
                    Marcus8: 187,
                    Marcus9: 188,
                    Marcus10: 189
                }).map(e => e.reverse())),
                i = e => new DataView(Uint8Array.from(e).buffer),
                s = e => {
                    let t = [],
                        a = i(e.splice(0, 4)).getInt32();
                    for (let r = 0; r < a; r++) {
                        let a = {};
                        a.x = i(e.splice(0, 2)).getInt16(),
                            a.y = i(e.splice(0, 2)).getInt16(),
                            a.z = i(e.splice(0, 2)).getInt16(),
                            a.flags = e.shift(),
                            0 == (1 & a.flags) && (a.corners = e.splice(0, 8)),
                            0 == (2 & a.flags) ? a.materials = e.splice(0, 6) : a.material = e.shift(), t.push([a.pos, a]);
                        for (let e = 1; e < a.flags >> 2; e++) {
                            let r = Object.assign({}, a);
                            0 == (1 & a.flags) && (r.corners = [...a.corners]), 0 == (2 & a.flags) && (r.materials = [...a.materials]), r.x += e, t.push([r.pos, r])
                        }
                    }
                    return t
                },
                l = e => {
                    let t = (e => {
                        let t = 0,
                            a = 0;
                        for (; 35 != a;) {
                            let r = e[a / 7];
                            if (t |= (127 & r) << a, 0 == (128 & r)) return [t, a / 7 + 1];
                            a += 7
                        }
                    })(e);
                    return e.splice(0, t[1]), (new TextDecoder).decode(new Uint8Array([...e.splice(0, t[0])]))
                },
                n = e => {
                    let t = i(e.splice(0, 4)).getInt32();
                    if (t > 1e3) throw "Hashtable size limit";
                    for (let r = 0; r < t; r++) {
                        let t = l(e),
                            r = 0,
                            s = 0;
                        switch (i(e.splice(0, 1)).getUint8()) {
                        case 0:
                            r = i(e.splice(0, 4)).getInt32();
                            break;
                        case 1:
                            r = [], s = i(e.splice(0, 4)).getInt32();
                            for (let t = 0; t < s; t++) r.push(i(e.splice(0, 4)).getInt32());
                            break;
                        case 2:
                            r = i(e.splice(0, 4)).getFloat32();
                            break;
                        case 3:
                            r = [], s = i(e.splice(0, 4)).getInt32();
                            for (let t = 0; t < s; t++) r.push(i(e.splice(0, 4)).getFloat32());
                            break;
                        case 5:
                            r = i(e.splice(0, 1)).getUint8() > 0;
                            break;
                        case 6:
                            r = [], s = i(e.splice(0, 4)).getInt32();
                            for (let t = 0; t < s; t++) r.push(i(e.splice(0, 1)).getUint8() > 0);
                            break;
                        case 7:
                            r = l(e);
                            break;
                        case 8:
                            r = n(e);
                            break;
                        case 9:
                            r = i(e.splice(0, 1)).getUint8();
                            break;
                        case 10:
                            r = i(e.splice(0, 8)).getBigInt64();
                            break;
                        case 11:
                            r = [], s = i(e.splice(0, 4)).getInt32();
                            for (let t = 0; t < s; t++) r.push(i(e.splice(0, 8)).getBigInt64())
                        }
                        a[t] = r
                    }
                };
            num = i(t.splice(0, 4)).getInt32();
            for (let e = 0; e < num; e++) {
                let e = {};
                    e.id = i(t.splice(0, 4)).getInt32(),
                    e.scale = i(t.splice(0, 4)).getFloat32(),
                    e.profileId = i(t.splice(0, 4)).getInt32(),
                    e.cubes = s(t.splice(0, i(t.splice(0, 4)).getInt32())),
                    a.proto.push(e)
            }
            num = i(t.splice(0, 4)).getInt32();
            for (let e = 0; e < num; e++) {
                let e = i(t.splice(0, 4)).getInt32(),
                    s = i(t.splice(0, 4)).getInt32(),
                    l = i(t.splice(0, 4)).getInt32(),
                    p = i(t.splice(0, 4)).getInt32();
                p = r[p] || p;
                let o = i(t.splice(0, 4)).getFloat32(),
                    c = i(t.splice(0, 4)).getFloat32(),
                    u = i(t.splice(0, 4)).getFloat32(),
                    g = i(t.splice(0, 4)).getFloat32(),
                    h = i(t.splice(0, 4)).getFloat32(),
                    m = i(t.splice(0, 4)).getFloat32(),
                    I = i(t.splice(0, 4)).getFloat32(),
                    d = i(t.splice(0, 4)).getFloat32(),
                    f = i(t.splice(0, 4)).getFloat32(),
                    b = i(t.splice(0, 4)).getFloat32(),
                    C = n(t),
                    y = i(t.splice(0, 1)).getUint8(),
                    k = null;
                0 != (1 & y) && (k = i(t.splice(0, 4)).getInt32()), 0 != (2 & y) && (k = i(t.splice(0, 4)).getInt32());
                let A = n(t);
                a.woList.push({
                    woType: p,
                    data2: A,
                    data: C,
                    id: e,
                    groupId: s,
                    itemId: l,
                    pos: {
                        x: o,
                        y: c,
                        z: u
                    },
                    rot: {
                        x: g,
                        y: h,
                        z: m,
                        w: I
                    },
                    scale: {
                        x: d,
                        y: f,
                        z: b
                    },
                    owner: y,
                    ownerId: k,
                })
            }
            num = i(t.splice(0, 4)).getInt32();
            for (let e = 0; e < num; e++) {
                let e = i(t.splice(0, 4)).getInt32(),
                    r = i(t.splice(0, 4)).getInt32(),
                    s = i(t.splice(0, 4)).getInt32();
                a.links.push({
                    id: e,
                    input: r,
                    output: s
                })
            }
            num = i(t.splice(0, 4)).getInt32();
            for (let e = 0; e < num; e++) {
                let e = i(t.splice(0, 4)).getInt32(),
                    r = i(t.splice(0, 4)).getInt32(),
                    s = i(t.splice(0, 4)).getInt32();
                a.oLinks.push({
                    id: e,
                    WOID: s,
                    connectorWOID: r
                })
            }
            self.postMessage(a)
        }).toString()], {
            type: "text/javascript"
        }))),
        a = e => new DataView(Uint8Array.from(e).buffer),
        r = (e, t) => [...new Uint8Array(t.of(e).buffer).reverse()];
    return {
        getWorld(e, a) {
            t.postMessage({
                buffer: e
            }), t.onmessage = (e => a(e.data))
        },
        getAvatarsMeta(e) {
            let t = {},
                r = a(e.splice(0, 4)).getInt32();
            for (let i = 0; i < r; i++) {
                t[a(e.splice(0, 4)).getInt32()] = this.getAvatarMeta(e)
            }
            return t
        },
        setAvatarsMeta(e) {
            let t = [];
            t.push(...r(Object.keys(e).length, Int32Array));
            for (let a in e) t.push(...r(a, Int32Array)), t.push(...this.setAvatarMeta(e[a]));
            return t
        },
        getAvatarMeta(e) {
            let t = {};
            return t.avatarId = a(e.splice(0, 4)).getInt32(), t.name = (e => {
                let t = (e => {
                        let t = 0,
                            a = 0;
                        for (; 35 != a;) {
                            let r = e[a / 7];
                            if (t |= (127 & r) << a, 0 == (128 & r)) return [t, a / 7 + 1];
                            a += 7
                        }
                    })(e),
                    a = t[0],
                    r = t[1];
                return e.splice(0, r), (new TextDecoder).decode(new Uint8Array([...e.splice(0, a)]))
            })(e), t.priceGold = a(e.splice(0, 4)).getInt32(), t.isOnMarketPlace = a(e.shift()).getUint8() > 0, t.canBeSoldOnMarketPlace = a(e.shift()).getUint8() > 0, t
        },
        setAvatarMeta(e) {
            let t = [];
            return t.push(...r(e.avatarId, Int32Array)), t.push(...(e => {
                let t = [],
                    a = (e => {
                        let t = [];
                        for (; e >= 128; e >>= 7) t.push((128 | e) % 256);
                        return t.push(e % 256), t
                    })(e.length);
                return t.push(a), t.push(...(new TextEncoder).encode(e)), t
            })(e.name)), t.push(...r(e.priceGold, Int32Array)), t.push(e.isOnMarketPlace > 0), t.push(e.canBeSoldOnMarketPlace > 0), t
        },
        getRPC(e) {
            let t = {};
            return t.flags = e.shift(), 0 != (1 & t.flags) && (t.interaction = e.shift()), 0 != (2 & t.flags) ? t.damage = a(e.splice(0, 4)).getFloat32() : t.damage = {
                9: 11.5,
                6: 110,
                4: 100,
                7: 13,
                14: 12.5,
                19: 12.5,
                5: 15,
                15: 15,
                24: 12,
                26: 25
            } [t.interaction] || 0, 0 != (4 & t.flags) ? (t.x = a(e.splice(0, 4)).getFloat32(), t.y = a(e.splice(0, 4)).getFloat32(), t.z = a(e.splice(0, 4)).getFloat32()) : Object.assign(t, {
                x: 0,
                y: 0,
                z: 0
            }), 0 != (8 & t.flags) ? t.type = e.shift() : t.type = 0, t
        },
        setRPC(e) {
            let t = [];
            return t.push(e.flags || 15), 0 != (1 & e.flags) && t.push(e.interaction || 0), 0 != (2 & e.flags) && t.push(...r(e.damage || 0, Float32Array)), 0 != (4 & e.flags) && t.push(...r(e.x || 0, Float32Array), ...r(e.y || 0, Float32Array), ...r(e.z || 0, Float32Array)), 0 != (8 & e.flags) && t.push(e.type || 0), t
        },
        getRuntime(t) {
            let r = {};
            const i = Object.fromEntries(Object.entries({
                Undefined: 0,
                FineGrainedSingleCubeAdd: 1,
                FineGrainedSingleCubeRemove: 2,
                Bazooka: 3,
                AvatarImpact25: 4,
                FineGrainedSingleCubeRemovedAddedFineGrainedCube: 5,
                VehicleImpact25: 6,
                AvatarImpact50: 7,
                AvatarImpact75: 8,
                VehicleImpact50: 9,
                VehicleImpact75: 10,
                SwordTerrainDestroy: 15,
                ImpulseGunImpact: 16
            }).map(e => e.reverse()));
            let s = t.shift();
            return r.type = i[s] || "Undefined", 1 == s || 2 == s || 5 == s ? (r.material = -1, "FineGrainedSingleCubeAdd" == r.type && (r.material = t.shift()), r.x = a(t.splice(0, 2)).getInt16(), r.y = a(t.splice(0, 2)).getInt16(), r.z = a(t.splice(0, 2)).getInt16()) : (3 == s || 4 == s || s >= 6 && s <= 10 || 15 == s || 16 == s) && (r.x = a(t.splice(0, 2)).getInt16(), r.y = a(t.splice(0, 2)).getInt16(), r.z = a(t.splice(0, 2)).getInt16()), e
        },
        setRuntime(e) {
            let t = [];
            const a = {
                Undefined: 0,
                FineGrainedSingleCubeAdd: 1,
                FineGrainedSingleCubeRemove: 2,
                Bazooka: 3,
                AvatarImpact25: 4,
                FineGrainedSingleCubeRemovedAddedFineGrainedCube: 5,
                VehicleImpact25: 6,
                AvatarImpact50: 7,
                AvatarImpact75: 8,
                VehicleImpact50: 9,
                VehicleImpact75: 10,
                SwordTerrainDestroy: 15,
                ImpulseGunImpact: 16
            };
            //Object.fromEntries(Object.entries(a).map(e => e.reverse()));
            let i = a[e.type];
            t.push(i), 1 == i || 2 == i || 5 == i ? ("FineGrainedSingleCubeAdd" == e.type && t.push(e.material > -1 ? e.material : 0), t.push(...r(e.x), Int16Array), t.push(...r(e.y), Int16Array), t.push(...r(e.z), Int16Array)) : (3 == i || 4 == i || i >= 6 && i <= 10 || 15 == i || 16 == i) && (t.push(...r(e.x), Int16Array), t.push(...r(e.y), Int16Array), t.push(...r(e.z), Int16Array))
            return t
        },
        getCube(e) {
            let t = {};
            return t.action = e.shift(), t.pos = [a(e.splice(0, 2)).getInt16(),a(e.splice(0, 2)).getInt16(),a(e.splice(0, 2)).getInt16()], t.material = -1, 0 == t.action ? t : (t.flags = e.shift(), 0 == (1 & t.flags) && (t.corners = e.splice(0, 8)), 0 == (2 & t.flags) ? t.materials = e.splice(0, 6) : t.material = e.shift(), t)
        },
        setCube(e) {
            let t = [];
            return t.push(e.material > -1 ? 2 : 0), t.push(...r(e.x, Int16Array)), t.push(...r(e.y, Int16Array)), t.push(...r(e.z, Int16Array)), e.material < 0 ? new Uint8Array(t) : (t.push(e.flags), 0 == (1 & e.flags) && t.push(...e.corners || [20, 120, 124, 24, 4, 104, 100, 0]), 0 == (2 & e.flags) ? t.push(...e.materials || [e.material, e.material, e.material, e.material, e.material, e.material]) : t.push(e.material), new Uint8Array(t))
        }
    }
}