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