forked from nokka/d2s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.go
167 lines (153 loc) · 4.9 KB
/
character.go
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package d2s
import (
"encoding/json"
"fmt"
)
// Character represents all the d2s character data.
type Character struct {
Header header `json:"header"`
Attributes attributes `json:"attributes"`
Skills []skill `json:"skills"`
Items []item `json:"items"`
CorpseItems []item `json:"corpse_items"`
MercItems []item `json:"merc_items"`
GolemItem *item `json:"golem_item"`
IsDead uint16 `json:"is_dead"`
}
func (h *header) MarshalJSON() ([]byte, error) {
type Alias header
leftSkill, ok := skillMap[int(h.LeftSkill)]
if !ok {
leftSkill = ""
}
rightSkill, ok := skillMap[int(h.RightSkill)]
if !ok {
rightSkill = ""
}
leftSwapSkill, ok := skillMap[int(h.LeftSwapSkill)]
if !ok {
leftSwapSkill = ""
}
rightSwapSkill, ok := skillMap[int(h.RightSwapSkill)]
if !ok {
rightSwapSkill = ""
}
var assignedSkills []string
for _, skillID := range h.AssignedSkills {
skill, ok := skillMap[int(skillID)]
if ok {
assignedSkills = append(assignedSkills, skill)
}
}
return json.Marshal(&struct {
Identifier string `json:"identifier"`
CheckSum string `json:"checksum"`
Name string `json:"name"`
Status readableStatus `json:"status"`
Class string `json:"class"`
LastPlayed uint32 `json:"last_played"`
LeftSkill string `json:"left_skill"`
RightSkill string `json:"right_skill"`
LeftSwapSkill string `json:"left_swap_skill"`
RightSwapSkill string `json:"right_swap_skill"`
MercID string `json:"merc_id"`
AssignedSkills []string `json:"assigned_skills"`
QuestsNormal quests `json:"quests_normal"`
QuestsNm quests `json:"quests_nm"`
QuestsHell quests `json:"quests_hell"`
*Alias
}{
Identifier: fmt.Sprintf("%x", h.Identifier),
CheckSum: fmt.Sprintf("%x", h.CheckSum),
Name: h.Name.String(),
Status: h.Status.Readable(),
Class: h.Class.String(),
LastPlayed: h.LastPlayed,
LeftSkill: leftSkill,
RightSkill: rightSkill,
LeftSwapSkill: leftSwapSkill,
RightSwapSkill: rightSwapSkill,
MercID: fmt.Sprintf("%x", h.MercID),
AssignedSkills: assignedSkills,
QuestsNormal: h.QuestsNormal,
QuestsNm: h.QuestsNm,
QuestsHell: h.QuestsHell,
Alias: (*Alias)(h),
})
}
// Header determines the header data of a d2s file.
type header struct {
Identifier uint32 `json:"identifier"`
Version uint32 `json:"version"`
FileSize uint32 `json:"filesize"`
CheckSum uint32 `json:"checksum"`
ActiveArms uint32 `json:"active_arms"`
Name name `json:"name"`
Status status `json:"status"`
Progression progression `json:"progression"`
_ [2]byte
Class class `json:"class"`
_ [2]byte
Level byte `json:"level"`
_ [4]byte
LastPlayed uint32 `json:"last_played"`
_ [4]byte
AssignedSkills [16]uint32 `json:"assigned_skills"`
LeftSkill uint32 `json:"left_skill"`
RightSkill uint32 `json:"right_skill"`
LeftSwapSkill uint32 `json:"left_swap_skill"`
RightSwapSkill uint32 `json:"right_swap_skill"`
_ [32]byte
CurrentDifficulty difficulty `json:"difficulty"`
MapID uint32 `json:"map_id"`
_ [2]byte
DeadMerc uint16 `json:"dead_merc"`
MercID uint32 `json:"merc_id"`
MercNameID uint16 `json:"merc_name_id"`
MercType uint16 `json:"merc_type"`
MercExp uint32 `json:"merc_experience"`
_ [144]byte
QuestHeader [4]byte `json:"-"`
_ [6]byte
QuestsNormal quests `json:"quests_normal"`
QuestsNm quests `json:"quests_nm"`
QuestsHell quests `json:"quests_hell"`
WaypointHeader [2]byte `json:"-"`
_ [6]byte
WaypointsNormal [24]byte `json:"-"`
WaypointsNm [24]byte `json:"-"`
WaypointsHell [24]byte `json:"-"`
WaypointTrailer byte `json:"-"`
NPCHeader [2]byte `json:"-"`
_ byte
NPCIntroNormal [5]byte `json:"-"`
_ [3]byte
NPCIntroNm [5]byte `json:"-"`
_ [3]byte
NPCIntroHell [5]byte `json:"-"`
_ [3]byte
NPCReturnNorm [4]byte `json:"-"`
_ [4]byte
NPCReturnNm [4]byte `json:"-"`
_ [4]byte
NPCReturnHell [4]byte `json:"-"`
_ [4]byte
StatHeader [2]byte `json:"-"`
}
type skillData struct {
Header [2]byte
List [30]byte
}
type itemData struct {
Header [2]byte
Count uint16
}
type corpseData struct {
Header [2]byte
Count uint16
Unknown [12]byte
}
type golemData struct {
Header [2]byte
HasGolem byte
}