* separate send_packet and unhex functions
parent
6f7efbd409
commit
055aa370f0
|
@ -160,7 +160,7 @@ function hook_move() {
|
|||
if [[ ${pos[1]} -lt -96 ]]; then
|
||||
# utf-8 is actually only valid for strings created in the UTF world region
|
||||
# everything else is just sparkling unicode
|
||||
pkt_disconnect "$(xxd -p -r <<< "c2af5c5c5f28e38384295f2fc2af")"
|
||||
pkt_disconnect "$(unhex <<< "c2af5c5c5f28e38384295f2fc2af")"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ function hook_keepalive() {
|
|||
function hook_ping() {
|
||||
json='{"version":{"name":"1.18.1","protocol":757},"players":{"max":1,"online":0,"sample":[]},"description":{"text":"Minigame: §adigmeout§r | '"$time_left"' seconds per game"},"favicon":"data:image/png;base64,'"$(base64 -w0 icon.png)"'"}'
|
||||
res="$(str_len "$json")$(echo -n "$json" | xxd -p)"
|
||||
echo "$(hexpacket_len "$res")00$res" | xxd -p -r
|
||||
send_packet "00" "$res"
|
||||
}
|
||||
|
||||
function hook_inventory() {
|
||||
|
|
|
@ -148,7 +148,7 @@ function hook_swing() {
|
|||
function hook_ping() {
|
||||
json='{"version":{"name":"1.18.1","protocol":757},"players":{"max":1,"online":0,"sample":[]},"description":{"text":"§c♡♡♡§a h,,hi --><-- §c♡♡♡ §r \ncome see what I made?"},"favicon":"data:image/png;base64,'"$(base64 -w0 icon.png)"'"}'
|
||||
res="$(str_len "$json")$(echo -n "$json" | xxd -p)"
|
||||
echo "$(hexpacket_len "$res")00$res" | xxd -p -r
|
||||
send_packet "00" "$res"
|
||||
}
|
||||
|
||||
function hook_start() {
|
||||
|
|
19
mc.sh
19
mc.sh
|
@ -25,14 +25,14 @@ function keep_alive() {
|
|||
while true; do
|
||||
sleep 1
|
||||
log "sending keepalive"
|
||||
echo '092100000000000000ff' | xxd -p -r
|
||||
echo '092100000000000000ff' | unhex
|
||||
# random data
|
||||
|
||||
#res=$(printf '%016x' $time)
|
||||
#res=$res$res
|
||||
#log time: $res
|
||||
#time=$((time+240))
|
||||
#echo -n "$(hexpacket_len "$res")59$res" | xxd -p -r
|
||||
#echo -n "$(hexpacket_len "$res")59$res" | unhex
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ while true; do
|
|||
|
||||
state=''
|
||||
elif [[ "$state" == '02' ]]; then
|
||||
nick=$(cut -c 5- <<< "$a" | xxd -p -r | grep -Poh '[A-Za-z0-9_-]*')
|
||||
nick=$(cut -c 5- <<< "$a" | unhex | grep -Poh '[A-Za-z0-9_-]*')
|
||||
eid=$(printf "%04x" $RANDOM | cut -c 1-4)
|
||||
mkdir -p $TEMP/players/$nick
|
||||
echo -n $eid > $TEMP/players/$nick/eid
|
||||
|
@ -132,7 +132,7 @@ while true; do
|
|||
|
||||
# random uuid string len string (nick)
|
||||
res="0000000000000000000000000000$eid$(str_len "$nick")$(echo -n "$nick" | xxd -p)"
|
||||
echo -n "$(hexpacket_len "$res")02$res" | xxd -p -r
|
||||
send_packet "02" "$res"
|
||||
|
||||
res="0100$eid" # entity id
|
||||
res+="00" # not hardcore
|
||||
|
@ -156,13 +156,12 @@ while true; do
|
|||
res+="00" # is debug (surprisingly, no)
|
||||
res+="01" # is flat (yeah, sure)
|
||||
|
||||
|
||||
echo -n "$(hexpacket_len "$res")26$res" | xxd -p -r
|
||||
send_packet "26" "$res"
|
||||
log "sent join game"
|
||||
#res="$(encode_position 10 10 10)"
|
||||
#res+="00000000" # angle as float
|
||||
|
||||
#echo -n "$(hexpacket_len "$res")4B$res" | xxd -p -r
|
||||
#echo -n "$(hexpacket_len "$res")4B$res" | unhex
|
||||
#log "sent spawn position"
|
||||
|
||||
hook_inventory
|
||||
|
@ -183,7 +182,7 @@ while true; do
|
|||
fi
|
||||
elif [[ $a == "01"* ]]; then
|
||||
log "responding to 01"
|
||||
echo "$len$a" | xxd -p -r
|
||||
echo "$len$a" | unhex
|
||||
log "bye"
|
||||
exit
|
||||
elif [[ $a == "0f"* ]]; then
|
||||
|
@ -211,9 +210,9 @@ while true; do
|
|||
hook_block
|
||||
elif [[ $a == "03"* ]]; then
|
||||
if [[ $((0x$(cut -c 3-4 <<< "$a"))) -lt 127 ]]; then # lazy varint check
|
||||
msg=$(cut -c 5- <<< "$a" | xxd -p -r)
|
||||
msg=$(cut -c 5- <<< "$a" | unhex)
|
||||
else
|
||||
msg=$(cut -c 3- <<< "$a" | xxd -p -r)
|
||||
msg=$(cut -c 3- <<< "$a" | unhex)
|
||||
fi
|
||||
hook_chat
|
||||
else
|
||||
|
|
|
@ -73,7 +73,7 @@ function hook_ping() {
|
|||
#json='{"version":{"name":"1.18.1","protocol":757},"players":{"max":100,"online":5,"sample":[{"name":"uwu","id":"4566e69f-c907-48ee-8d71-d7ba5aa00d20"}]},"description":{"text":"Hello world"}}'
|
||||
json='{"version":{"name":"§a§kaaa§aUwU§kaaa","protocol":756},"players":{"max":1,"online":0,"sample":[]},"description":{"text":"§aUwU"},"favicon":"data:image/png;base64,'"$(base64 -w0 icon.png)"'"}'
|
||||
res="$(str_len "$json")$(echo -n "$json" | xxd -p)"
|
||||
echo "$(hexpacket_len "$res")00$res" | xxd -p -r
|
||||
send_packet "00" "$res"
|
||||
}
|
||||
|
||||
# on defining inventory contents
|
||||
|
|
|
@ -79,7 +79,7 @@ function packet_len() {
|
|||
|
||||
# hexpacket_len(hexpacket)
|
||||
function hexpacket_len() {
|
||||
int2varint $((($(echo -n "$1" | xxd -p -r | wc -c)+1)))
|
||||
int2varint $((($(echo -n "$1" | unhex | wc -c)+1)))
|
||||
}
|
||||
|
||||
# str_len(string)
|
||||
|
@ -89,7 +89,7 @@ function str_len() {
|
|||
|
||||
# hexstrl_len(hexstring)
|
||||
function hexstr_len() {
|
||||
int2varint $(echo -n "$1" | xxd -p -r | wc -c)
|
||||
int2varint $(echo -n "$1" | unhex | wc -c)
|
||||
}
|
||||
|
||||
# hex2bin(hexstring)
|
||||
|
|
|
@ -17,5 +17,5 @@ function hexlog() {
|
|||
echo -n "$@" | xxd >&2
|
||||
}
|
||||
function rhexlog() {
|
||||
echo -n "$@" | xxd -p -r | xxd >&2
|
||||
echo -n "$@" | unhex | xxd >&2
|
||||
}
|
||||
|
|
|
@ -4,3 +4,7 @@
|
|||
function repeat() {
|
||||
printf -- "$2%.0s" $(seq 1 $1)
|
||||
}
|
||||
|
||||
function unhex() {
|
||||
xxd -p -r -c999999
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ function pkt_pos() {
|
|||
res+="00" # teleport id (?)
|
||||
res+="00" # dismount vehicle?
|
||||
|
||||
echo -n "$(hexpacket_len "$res")38$res" | xxd -p -r
|
||||
send_packet "38" "$res"
|
||||
log "sent player look and position"
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ function pkt_chunk() {
|
|||
else
|
||||
chunk_header
|
||||
|
||||
l=$(echo -n "8002" | xxd -p -r | varint2int)
|
||||
l=$(echo -n "8002" | unhex | varint2int)
|
||||
|
||||
chunk+="$(repeat $((l*16)) "$fill")"
|
||||
|
||||
|
@ -54,7 +54,7 @@ function pkt_chunk() {
|
|||
|
||||
res+="00 01 00 00 00 00 00 00" # empty bitsets and light arrays
|
||||
|
||||
echo -n "$(hexpacket_len "$res")22$res" | xxd -p -r
|
||||
send_packet "22" "$res"
|
||||
|
||||
log "sending chunk data"
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ function pkt_effect() {
|
|||
res+="$(encode_position $1 $2 $3)"
|
||||
res+="00000000"
|
||||
res+="00"
|
||||
echo -n "$(hexpacket_len "$res")23$res" | xxd -p -r
|
||||
send_packet "23" "$res"
|
||||
log "sending effect"
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ function pkt_particle() {
|
|||
res+="00000001" # particle data
|
||||
res+="$(printf '%08x' $5)" # particle count
|
||||
res+="" # data (left blank)
|
||||
echo -n "$(hexpacket_len "$res")24$res" | xxd -p -r
|
||||
send_packet "24" "$res"
|
||||
|
||||
log "sending particle"
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ function pkt_playerinfo_add() {
|
|||
res+="01" # ping: 1ms
|
||||
res+="00" # has display name: false
|
||||
|
||||
echo -n "$(hexpacket_len "$res")36$res" | xxd -p -r
|
||||
send_packet "36" "$res"
|
||||
|
||||
log "sent playerinfo"
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ function pkt_spawnplayer() {
|
|||
res+="00" # Angle (256 steps)
|
||||
res+="00" # Pitch (...)
|
||||
|
||||
echo -n "$(hexpacket_len "$res")04$res" | xxd -p -r
|
||||
send_packet "04" "$res"
|
||||
log "sent spawnplayer"
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ function pkt_position() {
|
|||
res+="$(to_short $deltaY)"
|
||||
res+="$(to_short $deltaZ)"
|
||||
res+="00" # on ground
|
||||
echo -n "$(hexpacket_len "$res")29$res" | xxd -p -r
|
||||
send_packet "29" "$res"
|
||||
}
|
||||
|
||||
# pkt_chatmessage(msg, sender_uuid)
|
||||
|
@ -195,8 +195,8 @@ function pkt_chatmessage() {
|
|||
res="$(str_len "$json")$(echo -n "$json" | xxd -p)"
|
||||
res+="00" # position: chat box
|
||||
res+="$2"
|
||||
|
||||
echo -n "$(hexpacket_len "$res")0F$res" | xxd -p -r
|
||||
|
||||
send_packet "0f" "$res"
|
||||
}
|
||||
|
||||
# pkt_title(msg)
|
||||
|
@ -204,7 +204,7 @@ function pkt_title() {
|
|||
local txt
|
||||
txt='{"text":"'"$1"'"}'
|
||||
res="$(str_len "$txt")$(echo -n "$txt" | xxd -p)"
|
||||
echo -n "$(hexpacket_len "$res")5a$res" | xxd -p -r
|
||||
send_packet "5a" "$res"
|
||||
}
|
||||
|
||||
# pkt_subtitle(msg)
|
||||
|
@ -212,14 +212,14 @@ function pkt_subtitle() {
|
|||
local txt
|
||||
txt='{"text":"'"$1"'"}'
|
||||
res="$(str_len "$txt")$(echo -n "$txt" | xxd -p)"
|
||||
echo -n "$(hexpacket_len "$res")58$res" | xxd -p -r
|
||||
send_packet "58" "$res"
|
||||
}
|
||||
|
||||
# pkt_disconnect(reason)
|
||||
function pkt_disconnect() {
|
||||
txt='{"text":"'"$1"'"}'
|
||||
res="$(str_len "$txt")$(echo -n "$txt" | xxd -p)"
|
||||
echo -n "$(hexpacket_len "$res")1a$res" | xxd -p -r
|
||||
send_packet "1a" "$res"
|
||||
|
||||
pkill -P $$
|
||||
pkt_chatmessage "- $nick" "00000000000000000000000000000000" > $TEMP/players/$nick/broadcast
|
||||
|
@ -233,7 +233,7 @@ function pkt_experience() {
|
|||
res="00000000" # experience bar
|
||||
res+="$(int2varint $1)"
|
||||
res+="00"
|
||||
echo -n "$(hexpacket_len "$res")51$res" | xxd -p -r
|
||||
send_packet "51" "$res"
|
||||
}
|
||||
|
||||
# pkt_inventory(items)
|
||||
|
@ -252,7 +252,7 @@ function pkt_inventory() {
|
|||
done
|
||||
res+="01 00 01 00"
|
||||
|
||||
echo -n "$(hexpacket_len "$res")14$res" | xxd -p -r
|
||||
send_packet "14" "$res"
|
||||
log "sent inventory"
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ function pkt_diggingack() {
|
|||
res+="$4"
|
||||
res+="$5"
|
||||
res+="01"
|
||||
echo -n "$(hexpacket_len "$res")08$res" | xxd -p -r
|
||||
send_packet "08" "$res"
|
||||
log "sent dig ack"
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,8 @@ function pkt_blockbreak() {
|
|||
res="$(int2varint $((0x$eid)))"
|
||||
res+="$(encode_position $1 $2 $3)"
|
||||
res+="$4"
|
||||
echo -n "$(hexpacket_len "$res")09$res" | xxd -p -r
|
||||
|
||||
send_packet "09" "$res"
|
||||
}
|
||||
|
||||
# pkt_soundeffect(x, y, z, id)
|
||||
|
@ -285,7 +286,7 @@ function pkt_soundeffect() {
|
|||
res+="3f800000" # volume
|
||||
res+="3f800000" # pitch
|
||||
|
||||
echo -n "$(hexpacket_len "$res")5d$res" | xxd -p -r
|
||||
send_packet "5d" "$res"
|
||||
log "sound $(hexpacket_len "$res")5d$res"
|
||||
}
|
||||
|
||||
|
@ -293,6 +294,11 @@ function pkt_soundeffect() {
|
|||
function pkt_sendblock() {
|
||||
res="$(encode_position $1 $2 $3)"
|
||||
res+="$(int2varint $4)"
|
||||
|
||||
echo -n "$(hexpacket_len "$res")0c$res" | xxd -p -r
|
||||
|
||||
send_packet "0c" "$res"
|
||||
}
|
||||
|
||||
# send_packet(id, payload)
|
||||
function send_packet() {
|
||||
echo -n "$(hexpacket_len "$2")$1$2" | unhex
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue