Skip to content

fix: support mod loaders Fixes: #322 #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/edition/java/proto/packet/brigadier/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *argPropReg) Encode(wr io.Writer, argType brigodier.ArgumentType, protoc
if err != nil {
return err
}
return util.WriteBytes(wr, property.Data)
return util.WriteRawBytes(wr, property.Data)
default:
codec, ok := r.byType[argType.String()]
id, ok2 := r.typeToID[argType.String()]
Expand Down
57 changes: 33 additions & 24 deletions pkg/edition/java/proto/util/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,47 +97,56 @@ func ReadStringWithoutLen(rd io.Reader) (string, error) {
return string(b), err
}

func ReadVarInt(r io.Reader) (result int, err error) {
func ReadVarInt(r io.Reader) (int, error) {
if br, ok := r.(io.ByteReader); ok {
var n uint32
for i := 0; ; i++ {
sec, err := br.ReadByte()
var (
result int32
numRead int
)
for {
b, err := br.ReadByte()
if err != nil {
return 0, err
}

n |= uint32(sec&0x7F) << uint32(7*i)
result |= int32(b&0x7F) << (7 * numRead)

if i >= 5 {
numRead++
if numRead > 5 {
return 0, errors.New("decode: VarInt is too big")
} else if sec&0x80 == 0 {
}

// MSB clear → last byte
if (b & 0x80) == 0 {
break
}
}
return int(n), nil
return int(result), nil
}

var bytes byte = 0
var b byte
var uresult uint32 = 0
const maxBytes = 5
var (
result int32
numRead int
buf [1]byte
)
for {
b, err = ReadUint8(r)
if err != nil {
return
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
uresult |= uint32(b&0x7F) << uint32(bytes*7)
bytes++
if bytes > 5 {
err = errors.New("decode: VarInt is too big")
return
b := buf[0]

result |= int32(b&0x7F) << (7 * numRead)

numRead++
if numRead > maxBytes {
return 0, errors.New("decode: VarInt is too big")
}
if (b & 0x80) == 0x80 {
continue
if (b & 0x80) == 0 {
break
}
break
}
result = int(int32(uresult))
return
return int(result), nil
}

// ReadVarIntArray reads a VarInt array from the reader.
Expand Down