Skip to content

Commit

Permalink
Add HoverEvent type, close inventories on open.
Browse files Browse the repository at this point in the history
Should avoid EnderChat triggering false positives with anti-cheats.
  • Loading branch information
retrixe committed Jan 31, 2022
1 parent 1add228 commit 71e694a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/minecraft/chatToJsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface BaseChat {
extra?: PlainTextChat[]
insertion?: string
clickEvent?: ClickEvent
// HoverEvent unsupported atm.
hoverEvent?: HoverEvent
}

export interface PlainTextChat extends BaseChat {
Expand All @@ -85,6 +85,12 @@ export interface ClickEvent {
value: string
}

// LOW-TODO: How can we display this in EnderChat?
export interface HoverEvent {
action: 'show_text' | 'show_item' | 'show_entity' | 'show_achievement' // <1.12
value: MinecraftChat
}

const hasColorCodes = (s: string) => /§[0-9a-fk-orx]/.test(s)
// const stripColorCodes = (s: string) => s.replace(/§[0-9a-fk-orx]/g, '').trim()
const parseColorCodes = (arg: string | PlainTextChat): PlainTextChat[] => {
Expand Down
11 changes: 10 additions & 1 deletion src/screens/ChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const errorHandler = (
}
const sendMessageErr = 'Failed to send message to server!'
const parseMessageErr = 'An error occurred when parsing chat.'
const inventoryCloseErr = 'An error occurred when closing an inventory window.'

let id = 0
// TODO: Ability to copy text.
Expand Down Expand Up @@ -127,7 +128,7 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => {
.writePacket(0x03, concatPacketData(['/spawn']))
.catch(errorHandler(addMessage, sendMessageErr))
}
} else if (packet.id === 0x0f) {
} else if (packet.id === 0x0f /* Chat Message (clientbound) */) {
try {
const [chatLength, chatVarIntLength] = readVarInt(packet.data)
const chatJson = packet.data
Expand All @@ -141,6 +142,14 @@ const ChatScreen = ({ navigation }: { navigation: ChatNavigationProp }) => {
} catch (e) {
errorHandler(addMessage, parseMessageErr)(e)
}
} else if (packet.id === 0x2e /* Open Window */) {
// Just close the window.
const [windowId] = readVarInt(packet.data)
const buf = Buffer.alloc(1)
buf.writeUInt8(windowId)
connection.connection // Close Window (serverbound)
.writePacket(0x09, buf)
.catch(errorHandler(addMessage, inventoryCloseErr))
}
})
return () => {
Expand Down

0 comments on commit 71e694a

Please sign in to comment.