fix: don't crash on open_window with an unrecognised window type - #3971
Open
liamnschermerhorn-code wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opening an unrecognised window type kills the bot outright.
windows.createWindow()returnsnullwhen it does not recognise the window type and cannot synthesise a layout — it can only synthesise one when the packet supplies a slot count, andopen_windowno longer sendsslotCount. So any unrecognised type takes that path, andprepareWindow()then dereferences the null: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:
which reliably terminates the bot.
Change
Emit
unknownWindowwith 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:
npx standardpasses on the changed file.