diff --git a/mc.sh b/mc.sh index 0bdc9dc..208a5b4 100755 --- a/mc.sh +++ b/mc.sh @@ -9,6 +9,9 @@ mkdir -p $TEMP $TEMP/players $TEMP/world source src/log.sh source src/int.sh +source src/misc.sh +source src/palette.sh +source src/chunk.sh source src/packet.sh source src/hooks.sh @@ -22,6 +25,7 @@ function keep_alive() { sleep 5 log "sending keepalive" echo '092100000000000000ff' | xxd -p -r + # random data done } @@ -97,7 +101,7 @@ while true; do log "connection dyed" pkill -P $$ pkt_chatmessage "- $nick" "00000000000000000000000000000000" > $TEMP/players/$nick/broadcast - sleep 1 + sleep 0.3 rm -R "$TEMP/players/$nick" exit fi @@ -130,7 +134,7 @@ while true; do state='' elif [[ "$state" == '02' ]]; then nick=$(cut -c 5- <<< "$a" | xxd -p -r | grep -Poh '[A-Za-z0-9_-]*') - eid=$(printf "%02x" $RANDOM) + eid=$(printf "%04x" $RANDOM | cut -c 1-4) mkdir -p $TEMP/players/$nick echo -n $eid > $TEMP/players/$nick/eid pkt_chatmessage "+ $nick" "00000000000000000000000000000000" > $TEMP/players/$nick/broadcast @@ -189,13 +193,10 @@ while true; do echo -n "$(hexpacket_len "$res")14$res" | xxd -p -r log "sent inventory" - pkt_pos - - source src/palette.sh - hook_chunks - + pkt_pos spawn_players + state='' else @@ -222,10 +223,14 @@ while true; do echo "${pos[0]},${pos[1]},${pos[2]}" > $TEMP/players/$nick/position hook_move elif [[ $a == "12"* ]]; then + pos[0]=$(from_ieee754 $(cut -c 3-18 <<< "$a")) + pos[1]=$(from_ieee754 $(cut -c 19-34 <<< "$a")) + pos[2]=$(from_ieee754 $(cut -c 35-50 <<< "$a")) hook_move elif [[ $a == "13"* ]]; then - hook_move + log "received Player Rotation" elif [[ $a == "1a"* ]]; then + #cut -c 3- hook_dig elif [[ $a == "2c"* ]]; then hook_swing diff --git a/src/int.sh b/src/int.sh index 378bb52..5d998b7 100644 --- a/src/int.sh +++ b/src/int.sh @@ -43,9 +43,9 @@ function varint2int() { echo -n "$out" } -# parse_position(Position) +# decode_position(Position) # https://wiki.vg/Protocol#Position -function parse_position() { +function decode_position() { x=$((0x$1 >> 38)) y=$((0x$1 & 0xFFF)) z=$(((0x$1 >> 12) & 0x3FFFFFF)) diff --git a/src/packet.sh b/src/packet.sh index 16a2250..e037074 100644 --- a/src/packet.sh +++ b/src/packet.sh @@ -15,11 +15,18 @@ function pkt_pos() { log "sent player look and position" } +# pkt_chunk(chunk_x, chunk_z, fill) function pkt_chunk() { # palettes are really cool once you figure them out :3 # https://wiki.vg/Protocol#Chunk_Data_And_Update_Light local chunk + local fill + if [[ $3 == '' ]]; then + fill='01' + else + fill="$3" + fi res="$1" # chunk X res+="$2" # chunk Z @@ -31,26 +38,14 @@ function pkt_chunk() { if [[ -f $TEMP/world/$1$2 ]]; then chunk=$(cat $TEMP/world/$1$2) else - chunk="ffff" # amount of blocks, doesnt matter - chunk+="08" # palette - bits per block - #chunk+="04" # palette - bits per block - chunk+="$(int2varint ${#palette[@]})" # palette - entries amount - #chunk+="04" - - chunk+="${palette[@]}" - #chunk+="0f af0b 01 00" - + chunk_header + chunk+="8004" # len of next array l=$(echo -n "8002" | xxd -p -r | varint2int) - for (( i=0; i<$((l*16)); i++ )); do - chunk+="01" # third entry of palette - done + chunk+="$(repeat $((l*16)) "$fill")" - chunk+="0001" # biome palette - for i in {1..26}; do - chunk+="0000000000000001" # set biome - done + chunk_footer echo -n "$chunk" > $TEMP/world/$1$2 fi @@ -74,11 +69,31 @@ function pkt_effect() { log "sending effect" } +# pkt_particle(x, y, z, particle_id, count) +function pkt_particle() { + res="$(printf '%08x' $4)" # particle id + res+="01" # long distance + res+="0000000000000000" # X + res+="0000000000000000" # Y + res+="0000000000000000" # Z + res+="3f800000" # X offset + res+="3f800000" # Y offset + res+="3f800000" # Z offset + res+="00000001" # particle data + res+="$(printf '%08x' $5)" # particle count + res+="" # data (left blank) + echo -n "$(hexpacket_len "$res")24$res" | xxd -p -r + + + rhexlog "$res" + log "sending particle" +} + # pkt_playerinfo(name, eid) function pkt_playerinfo_add() { res="00" # add player res+="01" # total players - res+="0000000000000000000000000000$2" # random UUID + res+="0000000000000000000000000000$2" # UUID res+="$(str_len "$1")$(echo -n "$1" | xxd -p)" diff --git a/src/palette.sh b/src/palette.sh index 8826015..75490c1 100644 --- a/src/palette.sh +++ b/src/palette.sh @@ -8,7 +8,7 @@ palette=() palette+=("00") # air palette+=("01") # stone -palette+=("09") # grass +palette+=("09") # grass block palette+=("0a") # dirt palette+=("0e") # cobblestone palette+=("0f") # planks @@ -37,4 +37,4 @@ palette+=("00") # palette+=("00") # palette+=("00") # palette+=("00") # -palette+=("f60a") # grass +palette+=("f60a") # tallgrass