fix lowest zoom level, avoid overdraw
This commit is contained in:
parent
6be388e108
commit
0911a80492
|
@ -1,8 +1,6 @@
|
|||
name: ci-build
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
@ -50,7 +48,7 @@ func dump_packet(w *pcapgo.Writer, from_client bool, pk packet.Header, payload [
|
|||
gopacket.Payload(packet_data.Bytes()),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
err = w.WritePacket(gopacket.CaptureInfo{
|
||||
|
@ -60,7 +58,7 @@ func dump_packet(w *pcapgo.Writer, from_client bool, pk packet.Header, payload [
|
|||
InterfaceIndex: 1,
|
||||
}, serialize_buf.Bytes())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,13 +80,13 @@ func (c *CaptureCMD) Usage() string {
|
|||
func (c *CaptureCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
||||
address, hostname, err := utils.ServerInput(c.server_address)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
logrus.Fatal(err)
|
||||
return 1
|
||||
}
|
||||
|
||||
fio, err := os.Create(hostname + "-" + time.Now().Format("2006-01-02_15-04-05") + ".pcap")
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
logrus.Fatal(err)
|
||||
return 1
|
||||
}
|
||||
defer fio.Close()
|
||||
|
@ -103,7 +101,7 @@ func (c *CaptureCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interfac
|
|||
|
||||
err = proxy.Run(ctx, address)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
logrus.Fatal(err)
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
@ -43,7 +42,8 @@ func (c *MergeCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
|
|||
|
||||
prov_out, err := mcdb.New(logrus.StandardLogger(), out_name, opt.DefaultCompression)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to open output %s\n", err)
|
||||
logrus.Errorf("failed to open output %s", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
for i, world_name := range c.worlds {
|
||||
|
@ -51,7 +51,7 @@ func (c *MergeCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
|
|||
logrus.Infof("Adding %s", world_name)
|
||||
s, err := os.Stat(world_name)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
logrus.Errorf("%s not found", world_name)
|
||||
logrus.Fatalf("%s not found", world_name)
|
||||
}
|
||||
if !s.IsDir() { // if its a zip temporarily unpack it to read it
|
||||
f, _ := os.Open(world_name)
|
||||
|
@ -61,7 +61,8 @@ func (c *MergeCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
|
|||
// merge it into the state
|
||||
err = c.merge_worlds(prov_out, world_name, first)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s %s\n", world_name, err)
|
||||
logrus.Errorf("%s %s", world_name, err)
|
||||
return 1
|
||||
}
|
||||
if !s.IsDir() { // remove temp folder again
|
||||
os.RemoveAll(world_name)
|
||||
|
@ -69,7 +70,7 @@ func (c *MergeCMD) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
|
|||
}
|
||||
|
||||
if err = prov_out.Close(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
logrus.Error(err)
|
||||
return 1
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
|
|
|
@ -70,7 +70,7 @@ func NewMapUI(w *WorldState) *MapUI {
|
|||
}
|
||||
|
||||
func (m *MapUI) Start() {
|
||||
m.ticker = time.NewTicker(66 * time.Millisecond)
|
||||
m.ticker = time.NewTicker(33 * time.Millisecond)
|
||||
go func() {
|
||||
for range m.ticker.C {
|
||||
if m.needRedraw {
|
||||
|
@ -123,14 +123,13 @@ func (m *MapUI) SchedRedraw() {
|
|||
// draw_img_scaled_pos draws src onto dst at bottom_left, scaled to size
|
||||
func draw_img_scaled_pos(dst *image.RGBA, src *image.RGBA, bottom_left image.Point, size_scaled int) {
|
||||
sbx := src.Bounds().Dx()
|
||||
sby := src.Bounds().Dy()
|
||||
ratio := int(float64(sbx) / float64(size_scaled))
|
||||
|
||||
ratio := float64(sbx) / float64(size_scaled)
|
||||
for x_in := 0; x_in < sbx; x_in++ {
|
||||
for y_in := 0; y_in < sby; y_in++ {
|
||||
for x_out := bottom_left.X; x_out < bottom_left.X+size_scaled; x_out++ {
|
||||
for y_out := bottom_left.Y; y_out < bottom_left.Y+size_scaled; y_out++ {
|
||||
x_in := (x_out - bottom_left.X) * ratio
|
||||
y_in := (y_out - bottom_left.Y) * ratio
|
||||
c := src.At(x_in, y_in)
|
||||
x_out := int(float64(bottom_left.X) + float64(x_in)/ratio)
|
||||
y_out := int(float64(bottom_left.Y) + float64(y_in)/ratio)
|
||||
dst.Set(x_out, y_out, c)
|
||||
}
|
||||
}
|
||||
|
@ -176,11 +175,10 @@ func (m *MapUI) Redraw() {
|
|||
chunks_x := int(max[0] - min[0] + 1) // how many chunk lengths is x coordinate
|
||||
chunks_y := int(max[1] - min[1] + 1)
|
||||
|
||||
total_width := 16 * math.Ceil(float64(chunks_x)/16)
|
||||
chunks_per_line := math.Min(total_width, float64(128/m.zoomLevel))
|
||||
|
||||
px_per_block := float64(128 / chunks_per_line / 16) // how many pixels per block
|
||||
sz_chunk := int(math.Ceil(px_per_block * 16))
|
||||
// total_width := 32 * math.Ceil(float64(chunks_x)/32)
|
||||
chunks_per_line := float64(128 / m.zoomLevel)
|
||||
px_per_block := 128 / chunks_per_line / 16 // how many pixels per block
|
||||
sz_chunk := int(math.Floor(px_per_block * 16))
|
||||
|
||||
for i := 0; i < len(m.img.Pix); i++ { // clear canvas
|
||||
m.img.Pix[i] = 0
|
||||
|
|
|
@ -449,7 +449,6 @@ func (w *WorldState) OnConnect(proxy *utils.ProxyContext) {
|
|||
*/
|
||||
|
||||
if w.withPacks {
|
||||
fmt.Println("reformatting packs")
|
||||
go func() {
|
||||
w.packs, _ = utils.GetPacks(w.proxy.Server)
|
||||
}()
|
||||
|
@ -464,10 +463,10 @@ func (w *WorldState) OnConnect(proxy *utils.ProxyContext) {
|
|||
w.ispre118 = ver < 18
|
||||
}
|
||||
if err != nil || len(gv) <= 1 {
|
||||
fmt.Println("couldnt determine game version, assuming > 1.18")
|
||||
logrus.Info("couldnt determine game version, assuming > 1.18")
|
||||
}
|
||||
if w.ispre118 {
|
||||
fmt.Println("using legacy (< 1.18)")
|
||||
logrus.Info("using legacy (< 1.18)")
|
||||
}
|
||||
|
||||
dim_id := gd.Dimension
|
||||
|
|
|
@ -70,15 +70,24 @@ func PacketLogger(header packet.Header, payload []byte, src, dst net.Addr) {
|
|||
logrus.Infof("Disconnect: %s", pk.Message)
|
||||
}
|
||||
|
||||
dir := color.GreenString("S") + "->" + color.CyanString("C")
|
||||
src_addr, _, _ := net.SplitHostPort(src.String())
|
||||
if IPPrivate(net.ParseIP(src_addr)) {
|
||||
dir = color.CyanString("C") + "->" + color.GreenString("S")
|
||||
dir_S2C := color.GreenString("S") + "->" + color.CyanString("C")
|
||||
dir_C2S := color.CyanString("C") + "->" + color.GreenString("S")
|
||||
var dir string = dir_S2C
|
||||
|
||||
if Client_addr != nil {
|
||||
if src == Client_addr {
|
||||
dir = dir_C2S
|
||||
}
|
||||
} else {
|
||||
src_addr, _, _ := net.SplitHostPort(src.String())
|
||||
if IPPrivate(net.ParseIP(src_addr)) {
|
||||
dir = dir_C2S
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("%s 0x%02x, %s", dir, pk.ID(), pk_name)
|
||||
|
||||
if slices.Contains(ExtraVerbose, pk_name) {
|
||||
logrus.Debugf("%+v\n", pk)
|
||||
logrus.Debugf("%+v", pk)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,6 +148,8 @@ func NewProxy(log *logrus.Logger) *ProxyContext {
|
|||
}
|
||||
}
|
||||
|
||||
var Client_addr net.Addr
|
||||
|
||||
func (p *ProxyContext) Run(ctx context.Context, server_address string) (err error) {
|
||||
if strings.HasSuffix(server_address, ".pcap") {
|
||||
return create_replay_connection(ctx, p.log, server_address, p.ConnectCB, p.PacketCB)
|
||||
|
|
|
@ -89,6 +89,9 @@ func ConnectServer(ctx context.Context, address string, ClientData *login.Client
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debug("Connected.")
|
||||
Client_addr = serverConn.LocalAddr()
|
||||
return serverConn, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue