Monkey-patch in custom packets

This commit is contained in:
Tanner Collin 2020-09-05 22:19:48 -06:00
parent 71918953c2
commit 303612fcf1
2 changed files with 24 additions and 8 deletions

View File

@ -9,10 +9,7 @@ from minecraft.networking.types import (
from ....types import nbt from ....types import nbt
class ChunkDataPacket(Packet): class ChunkDataPacket(Packet):
@staticmethod id = 0x20
def get_id(context):
return 0x20 # FIXME
packet_name = 'chunk data' packet_name = 'chunk data'
fields = 'x', 'bit_mask_y', 'z', 'full_chunk' fields = 'x', 'bit_mask_y', 'z', 'full_chunk'

View File

@ -5,13 +5,26 @@ import sys
import re import re
from optparse import OptionParser from optparse import OptionParser
from custom.managers import DataManager, ChunksManager
from custom.networking.packets.clientbound.play import chunk_data
import minecraft.networking.packets
def get_packets(old_get_packets):
def wrapper(func, context):
print('Monkey-patched.')
packets = func(context)
packets.add(chunk_data.ChunkDataPacket)
return packets
return lambda x: wrapper(old_get_packets, x)
minecraft.networking.packets.clientbound.play.get_packets = get_packets(minecraft.networking.packets.clientbound.play.get_packets)
from minecraft import authentication from minecraft import authentication
from minecraft.exceptions import YggdrasilError from minecraft.exceptions import YggdrasilError
from minecraft.networking.connection import Connection from minecraft.networking.connection import Connection
from minecraft.networking.packets import Packet, clientbound, serverbound from minecraft.networking.packets import Packet, clientbound, serverbound
from custom.managers import DataManager, ChunksManager
def get_options(): def get_options():
parser = OptionParser() parser = OptionParser()
@ -111,12 +124,18 @@ def main():
print("Message (%s): %s" % ( print("Message (%s): %s" % (
chat_packet.field_string('position'), chat_packet.json_data)) chat_packet.field_string('position'), chat_packet.json_data))
chunks = ChunksManager(mcdata) #chunks = ChunksManager(mcdata)
chunks.register(connection) #chunks.register(connection)
connection.register_packet_listener( connection.register_packet_listener(
print_chat, clientbound.play.ChatMessagePacket) print_chat, clientbound.play.ChatMessagePacket)
def handle_chunk(chunk_packet):
print(chunk_packet)
def register(self, connection):
connection.register_packet_listener(handle_chunk, chunk_data.ChunkDataPacket)
connection.connect() connection.connect()
while True: while True: