Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Commit

Permalink
Added more functionality to character select screen. (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
essial committed Nov 12, 2019
1 parent f81eb57 commit a6a9434
Show file tree
Hide file tree
Showing 25 changed files with 715 additions and 155 deletions.
19 changes: 11 additions & 8 deletions d2common/d2enum/hero.go
Expand Up @@ -3,12 +3,15 @@ package d2enum
type Hero int

const (
HeroNone Hero = 0
HeroBarbarian Hero = 1
HeroNecromancer Hero = 2
HeroPaladin Hero = 3
HeroAssassin Hero = 4
HeroSorceress Hero = 5
HeroAmazon Hero = 6
HeroDruid Hero = 7
HeroNone Hero = 0 //
HeroBarbarian Hero = 1 // Barbarian
HeroNecromancer Hero = 2 // Necromancer
HeroPaladin Hero = 3 // Paladin
HeroAssassin Hero = 4 // Assassin
HeroSorceress Hero = 5 // Sorceress
HeroAmazon Hero = 6 // Amazon
HeroDruid Hero = 7 // Druid
)

//go:generate stringer -linecomment -type Hero
//go:generate string2enum -samepkg -linecomment -type Hero
30 changes: 30 additions & 0 deletions d2common/d2enum/hero_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions d2common/d2enum/hero_string2enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions d2common/d2enum/region_id.go
@@ -0,0 +1,41 @@
package d2enum

type RegionIdType int

const (
RegionAct1Town RegionIdType = 1
RegionAct1Wilderness RegionIdType = 2
RegionAct1Cave RegionIdType = 3
RegionAct1Crypt RegionIdType = 4
RegionAct1Monestary RegionIdType = 5
RegionAct1Courtyard RegionIdType = 6
RegionAct1Barracks RegionIdType = 7
RegionAct1Jail RegionIdType = 8
RegionAct1Cathedral RegionIdType = 9
RegionAct1Catacombs RegionIdType = 10
RegionAct1Tristram RegionIdType = 11
RegionAct2Town RegionIdType = 12
RegionAct2Sewer RegionIdType = 13
RegionAct2Harem RegionIdType = 14
RegionAct2Basement RegionIdType = 15
RegionAct2Desert RegionIdType = 16
RegionAct2Tomb RegionIdType = 17
RegionAct2Lair RegionIdType = 18
RegionAct2Arcane RegionIdType = 19
RegionAct3Town RegionIdType = 20
RegionAct3Jungle RegionIdType = 21
RegionAct3Kurast RegionIdType = 22
RegionAct3Spider RegionIdType = 23
RegionAct3Dungeon RegionIdType = 24
RegionAct3Sewer RegionIdType = 25
RegionAct4Town RegionIdType = 26
RegionAct4Mesa RegionIdType = 27
RegionAct4Lava RegionIdType = 28
RegonAct5Town RegionIdType = 29
RegionAct5Siege RegionIdType = 30
RegionAct5Barricade RegionIdType = 31
RegionAct5Temple RegionIdType = 32
RegionAct5IceCaves RegionIdType = 33
RegionAct5Baal RegionIdType = 34
RegionAct5Lava RegionIdType = 35
)
9 changes: 9 additions & 0 deletions d2common/d2enum/region_layer.go
@@ -0,0 +1,9 @@
package d2enum

type RegionLayerType int

const (
RegionLayerTypeFloors RegionLayerType = 0
RegionLayerTypeWalls RegionLayerType = 1
RegionLayerTypeShadows RegionLayerType = 2
)
3 changes: 3 additions & 0 deletions d2common/d2resource/resource_paths.go
Expand Up @@ -80,6 +80,8 @@ const (
// -- Character Selection

CharacterSelectionBackground = "/data/global/ui/CharSelect/characterselectscreenEXP.dc6"
CharacterSelectionSelectBox = "/data/global/ui/CharSelect/charselectbox.dc6"
PopUpOkCancel = "/data/global/ui/FrontEnd/PopUpOKCancel.dc6"

// --- Game ---

Expand All @@ -101,6 +103,7 @@ const (
Font16 = "/data/local/font/latin/font16"
Font24 = "/data/local/font/latin/font24"
Font30 = "/data/local/font/latin/font30"
Font42 = "/data/local/font/latin/font42"
FontFormal12 = "/data/local/font/latin/fontformal12"
FontFormal11 = "/data/local/font/latin/fontformal11"
FontFormal10 = "/data/local/font/latin/fontformal10"
Expand Down
32 changes: 30 additions & 2 deletions d2common/stream_reader.go
Expand Up @@ -55,20 +55,48 @@ func (v *StreamReader) SetPosition(newPosition uint64) {
v.position = newPosition
}

// GetUInt32 returns a uint32 word from the stream
// GetUInt32 returns a uint32 dword from the stream
func (v *StreamReader) GetUInt32() uint32 {
result := (uint32(v.data[v.position+3]) << uint(24)) + (uint32(v.data[v.position+2]) << uint(16)) + (uint32(v.data[v.position+1]) << uint(8)) + uint32(v.data[v.position])
v.position += 4
return result
}

// GetInt32 returns an int32 word from the stream
// GetInt32 returns an int32 dword from the stream
func (v *StreamReader) GetInt32() int32 {
result := (int32(v.data[v.position+3]) << uint(24)) + (int32(v.data[v.position+2]) << uint(16)) + (int32(v.data[v.position+1]) << uint(8)) + int32(v.data[v.position])
v.position += 4
return result
}

// GetUint64 returns a uint64 qword from the stream
func (v *StreamReader) GetUint64() uint64 {
result := (uint64(v.data[v.position+7]) << uint(56)) +
(uint64(v.data[v.position+6]) << uint(48)) +
(uint64(v.data[v.position+5]) << uint(40)) +
(uint64(v.data[v.position+4]) << uint(32)) +
(uint64(v.data[v.position+3]) << uint(24)) +
(uint64(v.data[v.position+2]) << uint(16)) +
(uint64(v.data[v.position+1]) << uint(8)) +
uint64(v.data[v.position])
v.position += 8
return result
}

// GetInt64 returns a uint64 qword from the stream
func (v *StreamReader) GetInt64() int64 {
result := (uint64(v.data[v.position+7]) << uint(56)) +
(uint64(v.data[v.position+6]) << uint(48)) +
(uint64(v.data[v.position+5]) << uint(40)) +
(uint64(v.data[v.position+4]) << uint(32)) +
(uint64(v.data[v.position+3]) << uint(24)) +
(uint64(v.data[v.position+2]) << uint(16)) +
(uint64(v.data[v.position+1]) << uint(8)) +
uint64(v.data[v.position])
v.position += 8
return int64(result)
}

// ReadByte implements io.ByteReader
func (v *StreamReader) ReadByte() (byte, error) {
return v.GetByte(), nil
Expand Down
37 changes: 31 additions & 6 deletions d2common/stream_writer.go
Expand Up @@ -18,26 +18,51 @@ func (v *StreamWriter) PushByte(val byte) {
v.data = append(v.data, val)
}

// PushWord writes an uint16 word to the stream
func (v *StreamWriter) PushWord(val uint16) {
// PushUint16 writes an uint16 word to the stream
func (v *StreamWriter) PushUint16(val uint16) {
v.data = append(v.data, byte(val&0xFF))
v.data = append(v.data, byte((val>>8)&0xFF))
}

// PushSWord writes a int16 word to the stream
func (v *StreamWriter) PushSWord(val int16) {
// PushInt16 writes a int16 word to the stream
func (v *StreamWriter) PushInt16(val int16) {
v.data = append(v.data, byte(val&0xFF))
v.data = append(v.data, byte((val>>8)&0xFF))
}

// PushDword writes a uint32 dword to the stream
func (v *StreamWriter) PushDword(val uint32) {
// PushUint32 writes a uint32 dword to the stream
func (v *StreamWriter) PushUint32(val uint32) {
v.data = append(v.data, byte(val&0xFF))
v.data = append(v.data, byte((val>>8)&0xFF))
v.data = append(v.data, byte((val>>16)&0xFF))
v.data = append(v.data, byte((val>>24)&0xFF))
}

// PushUint64 writes a uint64 qword to the stream
func (v *StreamWriter) PushUint64(val uint64) {
v.data = append(v.data, byte(val&0xFF))
v.data = append(v.data, byte((val>>8)&0xFF))
v.data = append(v.data, byte((val>>16)&0xFF))
v.data = append(v.data, byte((val>>24)&0xFF))
v.data = append(v.data, byte((val>>32)&0xFF))
v.data = append(v.data, byte((val>>40)&0xFF))
v.data = append(v.data, byte((val>>48)&0xFF))
v.data = append(v.data, byte((val>>56)&0xFF))
}

// PushInt64 writes a uint64 qword to the stream
func (v *StreamWriter) PushInt64(val int64) {
result := uint64(val)
v.data = append(v.data, byte(result&0xFF))
v.data = append(v.data, byte((result>>8)&0xFF))
v.data = append(v.data, byte((result>>16)&0xFF))
v.data = append(v.data, byte((result>>24)&0xFF))
v.data = append(v.data, byte((result>>32)&0xFF))
v.data = append(v.data, byte((result>>40)&0xFF))
v.data = append(v.data, byte((result>>48)&0xFF))
v.data = append(v.data, byte((result>>56)&0xFF))
}

// GetBytes returns the the byte slice of the underlying data
func (v *StreamWriter) GetBytes() []byte {
return v.data
Expand Down
6 changes: 3 additions & 3 deletions d2common/stream_writer_test.go
Expand Up @@ -21,8 +21,8 @@ func TestStreamWriterByte(t *testing.T) {
func TestStreamWriterWord(t *testing.T) {
sr := CreateStreamWriter()
data := []byte{0x12, 0x34, 0x56, 0x78}
sr.PushWord(0x3412)
sr.PushWord(0x7856)
sr.PushUint16(0x3412)
sr.PushUint16(0x7856)
output := sr.GetBytes()
for i, d := range data {
if output[i] != d {
Expand All @@ -34,7 +34,7 @@ func TestStreamWriterWord(t *testing.T) {
func TestStreamWriterDword(t *testing.T) {
sr := CreateStreamWriter()
data := []byte{0x12, 0x34, 0x56, 0x78}
sr.PushDword(0x78563412)
sr.PushUint32(0x78563412)
output := sr.GetBytes()
for i, d := range data {
if output[i] != d {
Expand Down

0 comments on commit a6a9434

Please sign in to comment.