Skip to content

fix: don't crash on open_window with an unrecognised window type - #3971

Open
liamnschermerhorn-code wants to merge 1 commit into
PrismarineJS:masterfrom
liamnschermerhorn-code:upstream/fix-modded-window-crash
Open

fix: don't crash on open_window with an unrecognised window type#3971
liamnschermerhorn-code wants to merge 1 commit into
PrismarineJS:masterfrom
liamnschermerhorn-code:upstream/fix-modded-window-crash

Conversation

@liamnschermerhorn-code

Copy link
Copy Markdown

Opening an unrecognised window type kills the bot outright.

windows.createWindow() returns null when it does not recognise the window type and cannot synthesise a layout — it can only synthesise one when the packet supplies a slot count, and open_window no longer sends slotCount. So any unrecognised type takes that path, and prepareWindow() then dereferences the null:

TypeError: Cannot read properties of null (reading 'id')
    at prepareWindow (lib/plugins/inventory.js:690)
    at Client.<anonymous> (lib/plugins/inventory.js:710)

This is reachable on any server with a mod- or plugin-registered menu, so the bot dies rather than degrading.

Reproduction

Against a NeoForge 26.2 server running Valkyrien Skies Eureka, sneak-right-clicking a ship helm sends:

open_window { windowId: 1, inventoryType: 74, windowTitle: { translate: "gui.vs_eureka.ship_helm" } }

which reliably terminates the bot.

Change

Emit unknownWindow with the raw packet and return, instead of dereferencing the null. Consumers that care about custom menus can listen for it; everyone else simply keeps a live bot. Behaviour for all recognised window types is unchanged.

After the change, the same interaction yields:

[unknownWindow] type=74 title="gui.vs_eureka.ship_helm"
BOT ALIVE: yes

npx standard passes on the changed file.

windows.createWindow() returns null when it does not recognise the window type and
cannot synthesise a layout, which it can only do when the packet supplies a slot
count. open_window no longer sends slotCount, so any unrecognised type takes that
path. prepareWindow() then dereferenced the null and threw, killing the bot:

  TypeError: Cannot read properties of null (reading 'id')
      at prepareWindow (lib/plugins/inventory.js:690)
      at Client.<anonymous> (lib/plugins/inventory.js:710)

This is reachable on any server with a mod- or plugin-registered menu: opening one
terminates the bot outright rather than degrading. Reproduced against a NeoForge
26.2 server, where right-clicking a Valkyrien Skies Eureka ship helm sends
inventoryType 74 and reliably kills the bot.

Emit 'unknownWindow' with the raw packet and return instead. Consumers that care
about custom menus can listen for it; everyone else keeps a live bot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant