kaiwyvern.notes
← Notes

LCUX shims

plugins/sys/gamestate/*.js

Four small classes wrap the game client socket and turn its noisy messages into three or four stable getters plus change callbacks. Nothing is cached long-term: the value is always read from the last message the socket delivered.

Queue ids are grouped, not compared

The socket reports a numeric queue id, and plugins care about the mode family: classic, ARAM or swiftplay. The mapping lives in one table; adding a new queue means adding one line, not editing every caller.

const GAME_MODES = {
    420: "CLASSIC SOLO",
    440: "CLASSIC FLEX",
    450: "ARAM",
    1750: "ARENA \\ CHERRY",
    480: "SWIFTPLAY"
};

const CLASSIC_GROUP = new Set([400, 420, 440, 870, 880, 890, 1750, 3100, 3130, 3120, 3110, 3140]);
const ARAM_GROUP    = new Set([450, 2400, 3220, 3200, 3210, 3270]);
const SWIFT_GROUP   = new Set([480]);

Three sources of the same truth

The current queue id can arrive from the session, from the lobby or from matchmaking, and they do not always update at the same moment. ModeShim keeps all three and prefers the freshest non-null one instead of trusting a single source.

this._queueIdFromSession = null;
this._queueIdFromLobby = null;
this._queueIdFromMatchmaking = null;

getQueueId() {
    return this._queueIdFromMatchmaking
        ?? this._queueIdFromLobby
        ?? this._queueIdFromSession;
}

Subscriptions by observation

The socket has an observe() helper that returns a disposable. Each shim subscribes to one endpoint, reacts to eventType and keeps a local Set of listeners to notify. On stop() the subscription is disconnected — no dangling sockets after a reload.

this._subscription = this.socket.observe(
    'lol-inventory/v2/inventory/CHAMPION_SKIN',
    (msg) => {
        if (msg.eventType === 'Delete') this._removeSkin(msg.data);
        else this._addSkin(msg.data);
    }
);

One entry point

All four shims are created with the same socket and published as a single object. Plugins use window.gamestate and never import the internal classes — the surface stays small, and the implementation can be replaced without touching callers.

export function init({ socket }) {
    modeShim     = new ModeShim(socket);
    championShim = new ChampionShim(socket);
    swiftShim    = new SwiftShim(socket);
    ownedShim    = new OwnedShim(socket);
}

window.gamestate = {
    getCurrentMode:   () => modeShim?.getCurrentMode(),
    getQueueId:       () => modeShim?.getQueueId(),
    onModeChange:     (fn) => modeShim?.onModeChange(fn),

    getChampion:      () => championShim?.getChampion(),
    onChampionChange: (fn) => championShim?.onChampionChange(fn),

    getSwiftSelection:() => swiftShim?.getSwiftSelection(),
    getOwnedSkins:    () => ownedShim?.getOwnedSkins(),
    isSkinOwned:      (id) => ownedShim?.isSkinOwned(id)
};

Why optionals everywhere

Every method is written as modeShim?.getCurrentMode(). During startup the shims exist but the socket may not have answered yet; returning undefined is correct there, and an exception would break the whole plugin for a value that arrives a second later.