Skip to content

Commit 0ccb5eb

Browse files
authored
Update to patch 18.40371 / build 564659 (#2)
1 parent 33b7efb commit 0ccb5eb

File tree

4 files changed

+28
-53
lines changed

4 files changed

+28
-53
lines changed

parser/consts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const DATA_OFFSET = 6
55
const ROOT_NODE_TOKEN = "BG"
66
const VERSION = "v0.3.1"
77

8-
var FOOTER = []uint8{0, 1, 0, 0, 0, 0, 0, 0}
8+
var FOOTER = []uint8{0x19, 0x0, 0x0, 0x0}
99

1010
var NODES_WITH_SUBSTRUCTURE = map[string]struct{}{
1111
"BG": {},

parser/gameCommandParser.go

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,48 +38,34 @@ func newBaseCommand(
3838
// that can be used.
3939
// =========================================================================
4040

41-
func parseGameCommands(data *[]byte, headerEndOffset int) ([]RawGameCommand, error) {
41+
func parseGameCommands(data *[]byte, headerEndOffset int, commandCount int) ([]RawGameCommand, error) {
4242
offset := bytes.Index((*data)[headerEndOffset:], FOOTER)
4343
// slog.Debug("Parsing command list", "offset", strconv.FormatInt(int64(headerEndOffset+offset), 16))
4444

4545
if offset == -1 {
4646
return nil, FooterNotFoundError(offset)
4747
}
4848

49-
firstFootEnd, err := findFooterOffset(data, headerEndOffset+offset)
50-
if err != nil {
51-
return nil, err
52-
}
53-
offset = firstFootEnd + 5
54-
lastIndex := 1
49+
offset += headerEndOffset - 19
5550
commandList := make([]RawGameCommand, 0)
5651

57-
for {
58-
if offset == len(*data)-1 {
59-
// We've reached the end!
60-
break
61-
}
62-
item, err := parseCommandList(data, offset, lastIndex)
52+
for i := 1; i <= commandCount; i++ {
53+
item, err := parseCommandList(data, offset, i)
6354
if err != nil {
6455
return commandList, err
6556
}
6657
// Add all the commands to the command list, flattening everything into a single list.
6758
commandList = append(commandList, item.commands...)
68-
if item.finalCommand {
69-
// We've reached the end! Someone resigned.
70-
break
71-
}
72-
lastIndex += 1
73-
if item.entryIdx != lastIndex {
74-
return commandList, fmt.Errorf("entryIdx was not sequential, item.entryIdx=%v, lastIndex=%v", item.entryIdx, lastIndex)
59+
if item.entryIdx != i {
60+
return commandList, fmt.Errorf("entryIdx was not sequential, item.entryIdx=%v, lastIndex=%v", item.entryIdx, i)
7561
}
7662
offset = item.offsetEnd
7763
}
7864

7965
return commandList, nil
8066
}
8167

82-
func findFooterOffset(data *[]byte, offset int) (int, error) {
68+
func findFooterEndOffset(data *[]byte, offset int) (int, error) {
8369
/*
8470
Each set of commands is followd by a "FOOTER" (footer is probably not the correct term) the demarcates the
8571
end of the command sequence and the beginning of the next. This function finds end of this footer and the
@@ -93,17 +79,21 @@ func findFooterOffset(data *[]byte, offset int) (int, error) {
9379
for i := 0; i < int(extraByteCount); i++ {
9480
extraByteNumbers[i] = derefedData[offset+i]
9581
}
82+
offset += int(extraByteCount)
9683
if extraByteCount > 0 {
9784
slog.Debug(fmt.Sprintf("foot has %v extra bytes: %v", extraByteCount, extraByteNumbers))
9885
}
9986

10087
unk := derefedData[offset]
101-
if unk != 1 {
102-
slog.Debug("unk not equal to 1", "unk", unk)
103-
return -1, UnkNotEqualTo1Error(offset)
88+
offset += 1
89+
90+
if unk == 0 {
91+
offset += 8
92+
} else if unk != 1 {
93+
slog.Debug("unk not equal to 0 or 1", "unk", unk)
94+
return -1, UnkNotExpectedValueError(offset)
10495
}
10596

106-
offset += 9
10797
oneFourthFooterLength := readUint16(data, offset)
10898
offset += 4
10999
endOffset := offset + 4*int(oneFourthFooterLength)
@@ -172,24 +162,7 @@ func parseCommandList(data *[]byte, offset int, lastCommandListIdx int) (Command
172162
}
173163
}
174164

175-
// TODO: Remove this and modify this to work for more than 1v1 replays.
176-
// Check if the last command is the resign command. Right now, the code panics because it cannot find a footer
177-
// after the resign command is issued. I haven't tried running this on team games yet, but I imagine that
178-
// it might work correctly. We'll need a smarter way to determine the end of the command stream.
179-
for _, cmd := range commands {
180-
if cmd.CommandType() == 16 {
181-
slog.Debug("Resign command issued", "cmd", cmd)
182-
// Resign command issued, return the command list
183-
return CommandList{
184-
-1,
185-
offset,
186-
true,
187-
commands,
188-
}, nil
189-
}
190-
}
191-
192-
footerEndOffset, err := findFooterOffset(data, offset)
165+
footerEndOffset, err := findFooterEndOffset(data, offset)
193166
if err != nil {
194167
return CommandList{}, err
195168
}
@@ -209,7 +182,6 @@ func parseCommandList(data *[]byte, offset int, lastCommandListIdx int) (Command
209182
return CommandList{
210183
int(entryIdx),
211184
offset,
212-
false,
213185
commands,
214186
}, nil
215187
}

parser/parser.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ func Parse(replayPath string, slim bool, stats bool, isGzip bool) (ReplayFormatt
8686
// fmt.Println(child)
8787
// }
8888

89+
commandCount := readUint32(&raw_data, 23)
90+
slog.Debug("commandCount", "commandCount", commandCount)
91+
8992
svBytes := bytes.Index(raw_data, []byte{0x73, 0x76}) // search for index of the "sv" bytes
9093
commandOffset := readUint32(&raw_data, svBytes+2)
9194
slog.Debug("commandOffset", "commandOffset", commandOffset)
92-
commandList, err := parseGameCommands(&raw_data, int(commandOffset))
95+
96+
commandList, err := parseGameCommands(&raw_data, int(commandOffset), int(commandCount))
9397
if err != nil {
9498
return ReplayFormatted{}, err
9599
}

parser/types.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ func (node NotRootNodeError) Error() string {
103103
}
104104

105105
type CommandList struct {
106-
entryIdx int
107-
offsetEnd int
108-
finalCommand bool
109-
commands []RawGameCommand
106+
entryIdx int
107+
offsetEnd int
108+
commands []RawGameCommand
110109
}
111110

112111
type FooterNotFoundError int
@@ -115,10 +114,10 @@ func (err FooterNotFoundError) Error() string {
115114
return fmt.Sprintf("Footer not found searching at offset=%v", int(err))
116115
}
117116

118-
type UnkNotEqualTo1Error int
117+
type UnkNotExpectedValueError int
119118

120-
func (err UnkNotEqualTo1Error) Error() string {
121-
return fmt.Sprintf("The unknown byte in footer search did not equal 1 at offset %v", strconv.FormatInt(int64(err), 16))
119+
func (err UnkNotExpectedValueError) Error() string {
120+
return fmt.Sprintf("The unknown byte in footer search did not equal 0 or 1 at offset %v", strconv.FormatInt(int64(err), 16))
122121
}
123122

124123
// ===============================

0 commit comments

Comments
 (0)