about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2020-02-22 16:56:19 +0100
committerEmile <hanemile@protonmail.com>2020-02-22 16:56:19 +0100
commitbccb90b150393f693fffe2477fc31f1efced2186 (patch)
treecb1247ffb6d9ae52bb32eb8629ec453f75b4f50b
parent190153620b24d868cb76483862628eac273b1d1c (diff)
resotre the player state
-rw-r--r--src/run.go24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/run.go b/src/run.go
index 9afad38..9783821 100644
--- a/src/run.go
+++ b/src/run.go
@@ -7,28 +7,42 @@ import (
 	"github.com/radare/r2pipe-go"
 )
 
+// StepIn steps in and stores the state of the registers for the given bot
 func stepIn(r2p *r2pipe.Pipe) string {
 	_ = r2cmd(r2p, "aes")
+
+	// store the regisers
 	registers := r2cmd(r2p, "aerR")
 	registersStripped := strings.Replace(registers, "\n", ";", -1)
 	return registersStripped
 }
 
-func switchPlayer(currentPlayer int, config Config) int {
-	return (currentPlayer + 1) % len(config.Bots)
+func switchPlayer(r2p *r2pipe.Pipe, currentPlayer int, config Config) int {
+
+	// calculate the index of the nextPlayer
+	nextPlayer := (currentPlayer + 1) % len(config.Bots)
+
+	// restore the registers to the state of the next bot
+	r2cmd(r2p, config.Bots[nextPlayer].Regs)
+
+	return nextPlayer
 }
 
 func user(r2p *r2pipe.Pipe, id int, registers string, config Config) string {
 	var res string
 
-	// res += "\x1b[2J\x1b[0;0H"
+	res += "\x1b[2J\x1b[0;0H"
 	res += fmt.Sprintf("USER %d\n", id)
 	res += fmt.Sprintf("%s\n", r2cmd(r2p, "aer"))
 	res += "+++\n"
+	//res += fmt.Sprintf("%s\n", r2cmd(r2p, fmt.Sprintf("%s %d @ 0\n", "prc=f", config.Memsize)))
 	res += fmt.Sprintf("%s\n", r2cmd(r2p, fmt.Sprintf("%s %d @ 0\n", "prx", config.Memsize)))
 	res += "+++\n"
-	res += fmt.Sprintf("%s\n", r2cmd("pxw 32 @r:SP"))
-	res += fmt.Sprintf("%s\n", r2cmd("pD %d @ %s"%(size[uidx], orig[uidx]))
+	res += fmt.Sprintf("%s\n", r2cmd(r2p, "pxw 32 @r:SP"))
+
+	r2command := fmt.Sprintf("pd %d @ %d", len(config.Bots[id].Source)/2, config.Bots[id].Addr)
+	r2cmdString := r2cmd(r2p, r2command)
+	res += fmt.Sprintf("%s\n", r2cmdString)
 
 	return res
 }