Skip to content

Commit

Permalink
Add logic to parse new 1.21 commands
Browse files Browse the repository at this point in the history
  • Loading branch information
icza committed Dec 20, 2018
1 parent 9c7777d commit f833bc3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rep/repcmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const (
TypeIDMergeDarkArchon byte = 0x5a
TypeIDMakeGamePublic byte = 0x5b
TypeIDChat byte = 0x5c
TypeIDSelect121 byte = 0x63
)

// Type describes the command type.
Expand Down Expand Up @@ -160,6 +161,7 @@ var Types = []*Type{
{e("Merge Dark Archon"), TypeIDMergeDarkArchon},
{e("Make Game Public"), TypeIDMakeGamePublic},
{e("Chat"), TypeIDChat},
{e("Select121"), TypeIDSelect121},
}

// Named command types
Expand Down Expand Up @@ -235,6 +237,7 @@ var (
TypeMergeDarkArchon = Types[68]
TypeMakeGamePublic = Types[69]
TypeChat = Types[70]
TypeSelect121 = Types[71]
)

// typeIDType maps from type ID to type.
Expand Down
37 changes: 37 additions & 0 deletions repparser/repparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"log"
"sort"
"time"
Expand Down Expand Up @@ -511,10 +512,46 @@ func parseCommands(data []byte, r *rep.Replay) error {
case repcmd.TypeIDReplaySpeed:
sr.pos += 9

// New commands introduced in 1.21

case 0x60: // Some kind of Move ?
cmd = &repcmd.GeneralCmd{
Base: base,
Data: sr.readSlice(11),
}
case 0x61:
cmd = &repcmd.GeneralCmd{
Base: base,
Data: sr.readSlice(12),
}
case 0x62:
cmd = &repcmd.GeneralCmd{
Base: base,
Data: sr.readSlice(4),
}
case repcmd.TypeIDSelect121:
count := sr.getByte()
selectCmd := &repcmd.SelectCmd{
Base: base,
UnitTags: make([]repcmd.UnitTag, count),
}
for i := byte(0); i < count; i++ {
selectCmd.UnitTags[i] = repcmd.UnitTag(sr.getUint16())
sr.getUint16() // Unknown, always 0?
}
cmd = selectCmd
case 0x64, 0x65:
count := sr.getByte()
cmd = &repcmd.GeneralCmd{
Base: base,
Data: sr.readSlice(uint32(count) * 4),
}

default:
// We don't know how to parse this command, we have to skip
// to the end of the command block
// (potentially skipping additional commands...)
fmt.Printf("skipping typeID: %#v, frame: %d, playerID: %d, remaining bytes: %d [% x]\n", base.Type.ID, base.Frame, base.PlayerID, cmdBlockEndPos-sr.pos, sr.b[sr.pos:cmdBlockEndPos])
pec := &repcmd.ParseErrCmd{Base: base}
if len(cs.Cmds) > 0 {
pec.PrevCmd = cs.Cmds[len(cs.Cmds)-1]
Expand Down

0 comments on commit f833bc3

Please sign in to comment.