diff --git a/modUtils.js b/modUtils.js index faedb8e..00e08ce 100644 --- a/modUtils.js +++ b/modUtils.js @@ -24,6 +24,13 @@ class ModUtils { script = ""; /** @type {{[key: string]: string}} */ dictionary = {}; + safeDictionary = new Proxy(this.dictionary, { + get(target, prop) { + if (typeof prop === 'symbol') prop = prop.toString(); + if (prop in target) return target[prop]; + throw new Error(`Property ${prop} is not defined in dictionary`); + } + }); /** @type {Function[]} */ postMinifyHandlers = []; diff --git a/patches/customLobby.js b/patches/customLobby.js index 9cd09ab..82ffc85 100644 --- a/patches/customLobby.js +++ b/patches/customLobby.js @@ -1,7 +1,7 @@ import ModUtils from '../modUtils.js'; // Custom lobby patches -export default (/** @type {ModUtils} */ { insertCode, replaceCode, replaceRawCode, dictionary: dict, waitForMinification }) => { +export default (/** @type {ModUtils} */ { insertCode, replaceCode, replaceRawCode, safeDictionary: dict, waitForMinification }) => { // set player id correctly insertCode(`function aBG(aBE) { diff --git a/patches/patches.js b/patches/patches.js index 53d719e..6d896ec 100644 --- a/patches/patches.js +++ b/patches/patches.js @@ -6,10 +6,10 @@ export default (/** @type {ModUtils} */ modUtils) => { } //export const requiredVariables = ["game", "playerId", "playerData", "rawPlayerNames", "gIsSingleplayer", "playerTerritories"]; -function applyPatches(/** @type {ModUtils} */ { replace, replaceOne, replaceRawCode, dictionary, matchOne, matchRawCode, escapeRegExp }) { +function applyPatches(/** @type {ModUtils} */ { replace, replaceOne, replaceRawCode, safeDictionary, matchOne, matchRawCode, escapeRegExp }) { // Constants for easy usage of otherwise long variable access expressions - const dict = dictionary; + const dict = safeDictionary; const playerId = `${dict.game}.${dict.playerId}`; const rawPlayerNames = `${dict.playerData}.${dict.rawPlayerNames}`; const gIsSingleplayer = `${dict.game}.${dict.gIsSingleplayer}`; @@ -153,7 +153,7 @@ canvas.font=aY.g0.g1(1,fontSize),canvas.fillStyle="rgba("+gR+","+tD+","+hj+",0.6 { // Player list and leaderboard filter tabs // Draw player list button - const uiOffset = dictionary.uiSizes + "." + dictionary.gap; + const uiOffset = dict.uiSizes + "." + dict.gap; const { groups: { drawFunction, topBarHeight } } = replaceOne(/(="";function (?\w+)\(\){[^}]+?(?\w+)\.fillRect\(0,(?\w+),\w+,1\),(?:\3\.fillRect\([^()]+\),)+\3\.font=\w+,(\w+\.\w+)\.textBaseline\(\3,1\),\5\.textAlign\(\3,1\),\3\.fillText\(\w+,Math\.floor\()(\w+)\/2\),(Math\.floor\(\w+\+\w+\/2\)\));/g, "$1($6 + $ - 22) / 2), $7; __fx.playerList.drawButton($, 12, 12, $ - 22);"); const buttonBoundsCheck = `__fx.utils.isPointInRectangle($, $, ${uiOffset} + 12, ${uiOffset} + 12, ${topBarHeight} - 22, ${topBarHeight} - 22)`