-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.go
392 lines (384 loc) · 12.8 KB
/
items.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package osrscache
import (
"errors"
"fmt"
"io"
)
type Item struct {
ID uint16 `json:"id"`
Category uint16 `json:"category"`
Name string `json:"name"`
Examine string `json:"examine"`
MembersOnly bool `json:"members_only"`
Stackable bool `json:"stackable"`
Exchangeable bool `json:"exchangeable"`
Value int32 `json:"value"`
Weight int16 `json:"weight"`
ActionsGround [5]string `json:"actions_ground"`
ActionsInventory [5]string `json:"actions_inventory"`
NotedItemID uint16 `json:"noted_item_id"`
NotedTemplate uint16 `json:"noted_template"`
StackItemIDs [10]uint16 `json:"stack_item_ids"`
StackQuantities [10]uint16 `json:"stack_quantities"`
Team int8 `json:"team"`
BoughtLinkID uint16 `json:"bought_link_id"`
BoughtTemplate uint16 `json:"bought_template"`
PlaceholderItemID uint16 `json:"placeholder_item_id"`
PlaceholderTemplate uint16 `json:"placeholder_template"`
ShiftClickDropIndex uint8 `json:"shift_click_drop_index"`
Params map[uint32]any `json:"params"`
InventoryModelData InventoryModelData `json:"inventory_model_data"`
CharacterModelDataMale CharacterModelData `json:"character_model_data_male"`
CharacterModelDataFemale CharacterModelData `json:"character_model_data_female"`
WearPositionPrimary uint8 `json:"wear_position_primary"`
WearPositionSecondary uint8 `json:"wear_position_secondary"`
WearPositionTertiary uint8 `json:"wear_position_tertiary"`
}
type InventoryModelData struct {
ID uint16 `json:"id"`
Zoom uint16 `json:"zoom"`
RotationX uint16 `json:"rotation_x"`
RotationY uint16 `json:"rotation_y"`
RotationZ uint16 `json:"rotation_z"`
OffsetX uint16 `json:"offset_x"`
OffsetY uint16 `json:"offset_y"`
ScaleX uint16 `json:"scale_x"`
ScaleY uint16 `json:"scale_y"`
ScaleZ uint16 `json:"scale_z"`
RecolorFrom []uint16 `json:"recolor_from"`
RecolorTo []uint16 `json:"recolor_to"`
RetextureFrom []uint16 `json:"retexture_from"`
RetextureTo []uint16 `json:"retexture_to"`
Ambient int8 `json:"ambient"`
Contrast int8 `json:"contrast"`
}
type CharacterModelData struct {
ModelPrimary uint16 `json:"model_primary"`
ModelSecondary uint16 `json:"model_secondary"`
ModelTertiary uint16 `json:"model_tertiary"`
Offset uint8 `json:"offset"`
ChatHeadModelPrimary uint16 `json:"chat_head_model_primary"`
ChatHeadModelSecondary uint16 `json:"chat_head_model_secondary"`
}
func NewItem(id uint16) *Item {
return &Item{
ID: id,
Name: "null",
ActionsGround: [5]string{"", "", "Take", "", ""},
ActionsInventory: [5]string{"", "", "", "", "Drop"},
InventoryModelData: InventoryModelData{
Zoom: 2000,
ScaleX: 128,
ScaleY: 128,
ScaleZ: 128,
},
}
}
func (item *Item) Read(data []byte) error {
reader := NewReader(data)
for {
opcode, err := reader.ReadUint8()
if err != nil {
if errors.Is(err, io.EOF) {
break
}
return fmt.Errorf("reading opcode: %w", err)
}
if opcode == 0 {
break
}
switch opcode {
case 1:
item.InventoryModelData.ID, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model id: %w", err)
}
case 2:
item.Name, err = reader.ReadString()
if err != nil {
return fmt.Errorf("reading name: %w", err)
}
case 3:
item.Examine, err = reader.ReadString()
if err != nil {
return fmt.Errorf("reading examine: %w", err)
}
case 4:
item.InventoryModelData.Zoom, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model zoom2d: %w", err)
}
case 5:
item.InventoryModelData.RotationX, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model xan2d: %w", err)
}
case 6:
item.InventoryModelData.RotationY, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model yan2d: %w", err)
}
case 7:
item.InventoryModelData.OffsetX, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model xoffset2d: %w", err)
}
case 8:
item.InventoryModelData.OffsetY, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model yoffset2d: %w", err)
}
case 11:
item.Stackable = true
case 12:
item.Value, err = reader.ReadInt32()
if err != nil {
return fmt.Errorf("reading value: %w", err)
}
case 13:
item.WearPositionPrimary, err = reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading wear position primary: %w", err)
}
case 14:
item.WearPositionSecondary, err = reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading wear position secondary: %w", err)
}
case 16:
item.MembersOnly = true
case 23:
item.CharacterModelDataMale.ModelPrimary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading male character model primary: %w", err)
}
item.CharacterModelDataMale.Offset, err = reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading male character model offset: %w", err)
}
case 24:
item.CharacterModelDataMale.ModelSecondary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading male character model secondary: %w", err)
}
case 25:
item.CharacterModelDataFemale.ModelPrimary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading female character model primary: %w", err)
}
item.CharacterModelDataFemale.Offset, err = reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading female character model offset: %w", err)
}
case 26:
item.CharacterModelDataFemale.ModelSecondary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading female character model secondary: %w", err)
}
case 27:
item.WearPositionTertiary, err = reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading wear position tertiary: %w", err)
}
case 30, 31, 32, 33, 34:
item.ActionsGround[opcode-30], err = reader.ReadString()
if err != nil {
return fmt.Errorf("reading ground action 4: %w", err)
}
case 35, 36, 37, 38, 39:
item.ActionsInventory[opcode-35], err = reader.ReadString()
if err != nil {
return fmt.Errorf("reading inventory action 4: %w", err)
}
case 40:
length, err := reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading param length: %w", err)
}
item.InventoryModelData.RecolorFrom = make([]uint16, length)
item.InventoryModelData.RecolorTo = make([]uint16, length)
for i := 0; i < int(length); i++ {
item.InventoryModelData.RecolorFrom[i], err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading recolor from: %w", err)
}
item.InventoryModelData.RecolorTo[i], err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading recolor to: %w", err)
}
}
case 41:
length, err := reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading param length: %w", err)
}
item.InventoryModelData.RetextureFrom = make([]uint16, length)
item.InventoryModelData.RetextureTo = make([]uint16, length)
for i := 0; i < int(length); i++ {
item.InventoryModelData.RetextureFrom[i], err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading recolor from: %w", err)
}
item.InventoryModelData.RetextureTo[i], err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading recolor to: %w", err)
}
}
case 42:
item.ShiftClickDropIndex, err = reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading shift click drop index: %w", err)
}
case 65:
item.Exchangeable = true
case 75:
item.Weight, err = reader.ReadInt16()
if err != nil {
return fmt.Errorf("reading weight: %w", err)
}
case 78:
item.CharacterModelDataMale.ModelTertiary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading male character model chat head model secondary: %w", err)
}
case 79:
item.CharacterModelDataFemale.ModelTertiary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading female character model chat head model secondary: %w", err)
}
case 90:
item.CharacterModelDataMale.ChatHeadModelPrimary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading male character model chat head model primary: %w", err)
}
case 91:
item.CharacterModelDataFemale.ChatHeadModelPrimary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading female character model chat head model primary: %w", err)
}
case 92:
item.CharacterModelDataMale.ChatHeadModelSecondary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading male character model chat head model secondary: %w", err)
}
case 93:
item.CharacterModelDataFemale.ChatHeadModelSecondary, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading female character model chat head model secondary: %w", err)
}
case 94:
item.Category, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading category: %w", err)
}
case 95:
item.InventoryModelData.RotationZ, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model rotation z: %w", err)
}
case 97:
item.NotedItemID, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading noted item id: %w", err)
}
case 98:
item.NotedTemplate, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading noted template: %w", err)
}
case 100, 101, 102, 103, 104, 105, 106, 107, 108, 109:
item.StackItemIDs[opcode-100], err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading stack item ids: %w", err)
}
item.StackQuantities[opcode-100], err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading stack quantities: %w", err)
}
case 110:
item.InventoryModelData.ScaleX, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model scale x: %w", err)
}
case 111:
item.InventoryModelData.ScaleY, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model scale y: %w", err)
}
case 112:
item.InventoryModelData.ScaleZ, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading inventory model scale z: %w", err)
}
case 113:
item.InventoryModelData.Ambient, err = reader.ReadInt8()
if err != nil {
return fmt.Errorf("reading inventory model ambient: %w", err)
}
case 114:
item.InventoryModelData.Contrast, err = reader.ReadInt8()
if err != nil {
return fmt.Errorf("reading inventory model contrast: %w", err)
}
case 115:
item.Team, err = reader.ReadInt8()
if err != nil {
return fmt.Errorf("reading team: %w", err)
}
case 139:
item.BoughtLinkID, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading bought link id: %w", err)
}
case 140:
item.BoughtTemplate, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading bought template: %w", err)
}
case 148:
item.PlaceholderItemID, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading placeholder item id: %w", err)
}
case 149:
item.PlaceholderTemplate, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading placeholder template: %w", err)
}
case 249:
length, err := reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading param length: %w", err)
}
item.Params = make(map[uint32]any, length)
for i := 0; i < int(length); i++ {
isString, err := reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading is string: %w", err)
}
key, err := reader.ReadUint24()
if err != nil {
return fmt.Errorf("reading key: %w", err)
}
var value interface{}
if isString == 1 {
strValue, err := reader.ReadString()
if err != nil {
return fmt.Errorf("reading string value: %w", err)
}
value = strValue
} else {
intValue, err := reader.ReadUint32()
if err != nil {
return fmt.Errorf("reading uint32 value: %w", err)
}
value = intValue
}
item.Params[key] = value
}
default:
return fmt.Errorf("unknown opcode: %d", opcode)
}
}
return nil
}