-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive_bet_table.go
More file actions
98 lines (79 loc) · 3.04 KB
/
archive_bet_table.go
File metadata and controls
98 lines (79 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package mpq
import (
"fmt"
"github.com/Gophercraft/mpq/info"
)
// The header of the BET table
func (archive *Archive) BetTableHeader() (bet_table_header *info.BetTableHeader) {
bet_table_header = &archive.bet_table.header
return
}
// The number of entries in the BET table
func (archive *Archive) BetTableCount() (bet_table_count uint32) {
bet_table_count = archive.bet_table.header.EntryCount
return
}
// Look up an entry in the BET table, copying its information into bet_table_entry
func (archive *Archive) BetTableEntryIndex(index uint32, bet_table_entry *info.BetTableEntry) (err error) {
bet_table := &archive.bet_table
entry_size := uint64(bet_table.header.TableEntrySize)
entry_position := entry_size * uint64(index)
if entry_position >= bet_table.entries.Len() || entry_position+entry_size > bet_table.entries.Len() {
err = fmt.Errorf("mpq: BET table index is out of bounds")
return
}
// Read the file position
bet_table_entry.Position, err = bet_table.entries.Uint(entry_position+uint64(bet_table.header.BitIndex_FilePos), uint8(bet_table.header.BitCount_FilePos))
if err != nil {
return
}
bet_table_entry.FileSize, err = bet_table.entries.Uint(entry_position+uint64(bet_table.header.BitIndex_FileSize), uint8(bet_table.header.BitCount_FileSize))
if err != nil {
return
}
bet_table_entry.BlockSize, err = bet_table.entries.Uint(entry_position+uint64(bet_table.header.BitIndex_CompressedSize), uint8(bet_table.header.BitCount_CompressedSize))
if err != nil {
return
}
if bet_table.header.FlagCount != 0 {
var flag_index uint64
flag_index, err = bet_table.entries.Uint(entry_position+uint64(bet_table.header.BitIndex_FlagIndex), uint8(bet_table.header.BitCount_FlagIndex))
if err != nil {
return
}
if flag_index >= uint64(bet_table.header.FlagCount) {
err = fmt.Errorf("mpq: bad flag count")
return
}
bet_table_entry.FlagsIndex = uint32(flag_index)
}
return
}
// The number of unique file flags values in the BET table
func (archive *Archive) BetTableFileFlagsCount() (file_flags_count uint32) {
file_flags_count = archive.BetTableHeader().FlagCount
return
}
// Return file flags for an file flags index
func (archive *Archive) BetTableFileFlagsIndex(file_flags_index uint32) (file_flags info.FileFlag, err error) {
if file_flags_index >= archive.BetTableFileFlagsCount() {
err = fmt.Errorf("mpq: file flag index out of bounds")
return
}
file_flags = archive.bet_table.file_flags[file_flags_index]
return
}
// Return the name hash 2 at the the BET table index
func (archive *Archive) BetTableNameHash2Index(bet_table_index uint32) (name_hash_2 uint64, err error) {
bet_table := &archive.bet_table
if bet_table_index >= archive.BetTableCount() {
err = fmt.Errorf("mpq: BET table name hash 2 index out of bounds: %d/%d", bet_table_index, archive.BetTableCount())
return
}
name_hash_position := uint64(bet_table_index) * uint64(bet_table.header.BitTotal_NameHash2)
name_hash_2, err = bet_table.name_hashes.Uint(name_hash_position, uint8(bet_table.header.BitCount_NameHash2))
if err != nil {
return
}
return
}