RuneHive-Game
Loading...
Searching...
No Matches
CacheNpcDefinition.java
Go to the documentation of this file.
1package com.runehive.fs.cache.decoder;
2
3import com.runehive.fs.cache.archive.Archive;
4
5import java.util.Arrays;
6
7public final class CacheNpcDefinition {
8
9 public static void unpackConfig(final Archive archive) {
10 buffer = Buffer.fromByteBuffer(archive.getData("npc.dat"));
11 final Buffer idx = Buffer.fromByteBuffer(archive.getData("npc.idx"));
12 int highestFileId = idx.readUnsignedShort();
13 //System.out.println("highest NPC=" + highestFileId);
14 offsets = new int[highestFileId + 1];
15 int offset = 0;
16 for (int i = 0; i < highestFileId; i++) {
17 final int size = idx.readUnsignedShort();
18 if (size == -1 || size == 65535) {
19 //System.err.println("BREAK AT " + j + " (size="+size+")");
20 break;
21 }
22 offsets[i] = offset;
23 offset += size;
24 //System.err.println("j=" + j + ", i=" + i + ", size=" + size);
25 }
26
28
29 for (int k = 0; k < 20; k++) {
31 }
32 }
33
34 public static CacheNpcDefinition lookup(int npcId) {
35 for (int cacheIndex = 0; cacheIndex < 20; cacheIndex++)
36 if (npcDefCache[cacheIndex].interfaceType == (long) npcId)
37 return npcDefCache[cacheIndex];
38
41 buffer.position = offsets[npcId];
42 entityDef.interfaceType = npcId;
43 entityDef.decode(buffer);
44 if (entityDef.combatLevel == 0) {
45 entityDef.combatLevel = 1;
46 }
47
48 switch (npcId) {
49 case 9855:
50 entityDef.actions = new String[5];
51 entityDef.actions[0] = "Talk-to";
52 entityDef.actions[2] = "Trade";
53 entityDef.actions[3] = "Skull";
54 entityDef.name = "Darth Pker";
55 entityDef.description = "The hunter of bounties".getBytes();
56 break;
57 case 5567:
58 entityDef.actions = new String[5];
59 entityDef.actions[0] = "Talk-to";
60 entityDef.actions[2] = "Pick-up";
61 entityDef.standingAnimation = 813;
62 entityDef.walkingAnimation = 1146;
63 entityDef.widthScale = 85;
64 entityDef.heightScale = 85;
65 entityDef.name = "Baby Darth";
66 entityDef.description = "The baby hunter of bounties".getBytes();
67 break;
68 case 6773:
69 entityDef.actions = new String[5];
70 entityDef.actions[0] = "Open";
71 break;
72 case 7481:
73 entityDef.name = "osroyale Vote Agent";
74 entityDef.actions = new String[5];
75 entityDef.actions[0] = "Talk-to";
76 entityDef.actions[2] = "Trade";
77 break;
78 case 7601:
79 entityDef.name = "Shady Insurance Agent";
80 entityDef.actions = new String[5];
81 entityDef.actions[0] = "Talk-to";
82 entityDef.actions[2] = "Open";
83 break;
84 case 2462:
85 entityDef.actions = new String[5];
86 entityDef.actions[0] = "Open";
87 break;
88 case 3216:
89 entityDef.name = "Melee store";
90 entityDef.actions = new String[5];
91 entityDef.actions[0] = "Open";
92 break;
93 case 3217:
94 entityDef.name = "Beginner Shops";
95 entityDef.actions = new String[5];
96 entityDef.actions[0] = "Open";
97 break;
98 case 3218:
99 entityDef.name = "Magic store";
100 entityDef.actions = new String[5];
101 entityDef.actions[0] = "Open";
102 break;
103
104 case 7062:
105 entityDef.name = "Ensouled Hunter";
106 break;
107 /* Fishing */
108 case 1518:
109 entityDef.name = "Shimps & Anchovies";
110 entityDef.actions = new String[5];
111 entityDef.actions[0] = "Net";
112 break;
113 case 1526:
114 entityDef.name = "Trout & Salmon";
115 entityDef.actions = new String[5];
116 entityDef.actions[0] = "Bait";
117 break;
118 case 311:
119 entityDef.actions = new String[5];
120 entityDef.actions[0] = "Talk-to";
121 entityDef.actions[2] = "Trade";
122 entityDef.actions[3] = "Claim-armour";
123 break;
124 case 1519:
125 entityDef.name = "Lobster & Swordfish";
126 break;
127 case 6533:
128 entityDef.name = "osroyale Skillermen";
129 break;
130 case 1520:
131 entityDef.name = "Shark";
132 break;
133 case 1521:
134 entityDef.name = "Manta ray";
135 entityDef.actions = new String[5];
136 entityDef.actions[0] = "Big Net";
137 break;
138 case 1534:
139 entityDef.name = "Monkfish";
140 entityDef.actions = new String[5];
141 entityDef.actions[0] = "Net";
142 break;
143 case 1536:
144 entityDef.name = "Dark crab";
145 break;
146 case 1600:
147 entityDef.actions = new String[5];
148 entityDef.actions[0] = "Bank";
149 break;
150 case 1603:
151 entityDef.actions = new String[5];
152 entityDef.actions[0] = "Talk-to";
153 entityDef.actions[2] = "Trade";
154
155 break;
156 case 326:
157 case 321:
158 entityDef.actions = new String[5];
159 entityDef.actions[0] = "Talk-to";
160 entityDef.actions[2] = "Dismiss";
161 break;
162 case 5419:
163 entityDef.actions = new String[5];
164 entityDef.actions[0] = "Open";
165 entityDef.actions[3] = "Trade";
166 break;
167 /** Crafting master. */
168 case 5811:
169 entityDef.actions = new String[5];
170 entityDef.actions[0] = "Tan";
171 entityDef.actions[2] = "Trade";
172 break;
173 /* Clanmaster */
174 case 3841:
175 entityDef.name = "Clanmaster";
176 entityDef.actions = new String[5];
177 entityDef.actions[0] = "Open";
178 break;
179 /* Clothing */
180 case 534:
181 entityDef.name = "Clothing store";
182 entityDef.actions = new String[5];
183 entityDef.actions[0] = "Open";
184 break;
185
186 /* Pure */
187 case 5440:
188 entityDef.name = "Pure store";
189 entityDef.actions = new String[5];
190 entityDef.actions[0] = "Open";
191 break;
192
193 /* Mage */
194 case 4400:
195 entityDef.name = "Mage store";
196 entityDef.actions = new String[5];
197 entityDef.actions[0] = "Open";
198 break;
199
200 /* Range */
201 case 1576:
202 entityDef.name = "Range store";
203 entityDef.actions = new String[5];
204 entityDef.actions[0] = "Open";
205 break;
206
207
208 case 1157:
209 case 1158:
210 case 1160:
211 entityDef.actions = new String[5];
212 entityDef.actions[1] = "Attack";
213 break;
214
215 /* Skill */
216 case 505:
217 entityDef.name = "Skilling store";
218 entityDef.actions = new String[5];
219 entityDef.actions[0] = "Open";
220 break;
221
222 /* Hunter */
223 case 1504:
224 entityDef.name = "Hunter store";
225 entityDef.actions = new String[5];
226 entityDef.actions[0] = "Open";
227 break;
228
229 /* Cook */
230 case 1199:
231 entityDef.name = "Consumable store";
232 entityDef.actions = new String[5];
233 entityDef.actions[0] = "Open";
234 break;
235
236 /* Farming */
237 case 3258:
238 entityDef.name = "Farming store";
239 entityDef.actions = new String[5];
240 entityDef.actions[0] = "Open";
241 break;
242
243 /* Achievement */
244 case 5527:
245 entityDef.actions = new String[5];
246 entityDef.actions[0] = "Talk-to";
247 entityDef.actions[2] = "Trade";
248 break;
249
250 /* Banker */
251 case 1480:
252 entityDef.actions = new String[5];
253 entityDef.actions[0] = "Talk-to";
254 entityDef.actions[2] = "Bank";
255 break;
256
257 /* Voting */
258 case 3531:
259 entityDef.name = "Vote";
260 entityDef.actions = new String[5];
261 entityDef.actions[0] = "Talk-to";
262 entityDef.actions[2] = "Trade";
263 entityDef.actions[3] = "Claim";
264 break;
265
266 /* Spellbook */
267 case 4397:
268 entityDef.name = "Spellbook";
269 entityDef.actions = new String[5];
270 entityDef.actions[0] = "Change";
271 break;
272
273 /* Royal Points */
274 case 5523:
275 entityDef.name = "The Donator King";
276 entityDef.actions = new String[5];
277 entityDef.actions[0] = "Talk-to";
278 entityDef.actions[2] = "Open-store";
279 entityDef.actions[3] = "Claim-purchase";
280 entityDef.description = "What more is there to say about The Donator King?.".getBytes();
281 break;
282
283 case 306:
284 entityDef.name = "osroyale Guide";
285 break;
286 case 5366:
287 entityDef.name = "Skilling Shop";
288 break;
289 case 364:
290 entityDef.name = "Skilling Store";
291 break;
292
293 /* Clothing */
294 case 1307:
295 entityDef.actions = new String[5];
296 entityDef.actions[0] = "Makeover";
297 break;
298
299 /* Thieving Stalls */
300 case 3439:
301 entityDef.name = "Merchant";
302 entityDef.actions = new String[5];
303 entityDef.actions[0] = "Sell goods";
304 break;
305
306 case 5919:
307 case 1755:
308 case 2186:
309 entityDef.actions = new String[5];
310 entityDef.actions[0] = "Trade";
311 break;
312 case 1757:
313 entityDef.actions = new String[5];
314 entityDef.actions[0] = "Talk-to";
315 break;
316 case 2180:
317 entityDef.actions = new String[5];
318 entityDef.actions[0] = "Exchange for firecape";
319 break;
320
321 /* Nieve */
322 case 490:
323 case 6797:
324 entityDef.actions = new String[5];
325 entityDef.actions[0] = "Talk-to";
326 entityDef.actions[2] = "Open-interface";
327 entityDef.actions[3] = "Offer-items";
328 break;
329 case 1756:
330 entityDef.name = "Void Knight";
331 entityDef.combatLevel = 0;
332 entityDef.actions = new String[5];
333 entityDef.actions[1] = "Attack";
334 break;
335 case 7431:
336 entityDef.name = "Skilling Store";
337 entityDef.combatLevel = 0;
338 entityDef.actions = new String[2];
339 entityDef.actions[1] = "Talk-to";
340 entityDef.actions[1] = "Trade";
341
342 break;
343 case 345:
344 entityDef.name = "Polly";
345 entityDef.description = "She takes pride in prestiging.".getBytes();
346 entityDef.actions = new String[5];
347 entityDef.actions[0] = "Talk-to";
348 entityDef.actions[2] = "Trade";
349 entityDef.actions[3] = "Prestige-panel";
350 entityDef.actions[4] = "Perk-information";
351 entityDef.walkingAnimation = 819;
352 entityDef.standingAnimation = 808;
353 entityDef.modelIds = new int[10];
354 entityDef.modelIds[0] = 391;
355 entityDef.modelIds[1] = 414;
356 entityDef.modelIds[2] = 18983;
357 entityDef.modelIds[3] = 361;
358 entityDef.modelIds[4] = 356;
359 entityDef.modelIds[5] = 556;
360 entityDef.modelIds[6] = 332;
361 entityDef.modelIds[7] = 474;
362 entityDef.modelIds[8] = 433;
363 entityDef.modelIds[9] = 16348;
364 entityDef.recolorTarget = new int[]{127, 127, 127, 127, 9168, -22419, 9143, 9168, 9143, 7744, 127, 127}; // Colour you want to change to//
365 entityDef.recolorOriginal = new int[]{4626, 10128, 10004, 5018, 61, 10351, 57280, 54183, 54503, 6798, 8741, 25238}; // Original colour
366 break;
367 case 6481:
368 entityDef.name = "Mac";
369 entityDef.description = "Only the most knowledgeable players of osroyale are worthy of such a cape.".getBytes();
370 entityDef.combatLevel = 126;
371 entityDef.walkingAnimation = 819;
372 //entityDef.standingAnimation = 808;
373 entityDef.actions = new String[5];
374 entityDef.actions[0] = "Talk-to";
375 entityDef.modelIds = new int[8];
376 entityDef.modelIds[0] = 29615;
377 entityDef.modelIds[1] = 29618;
378 entityDef.modelIds[2] = 29621;
379 entityDef.modelIds[3] = 29616;
380 entityDef.modelIds[4] = 29620;
381 entityDef.modelIds[5] = 176;
382 entityDef.modelIds[6] = 29619;
383 entityDef.modelIds[7] = 29622;
384 break;
385 case 367:
386 entityDef.actions = new String[5]; // Actions for the npc
387 entityDef.modelIds = new int[9]; //Number of models it uses
388 entityDef.modelIds[0] = 27636; //Bandos chest
389 entityDef.modelIds[1] = 27625; //Tassets
390 entityDef.modelIds[2] = 13307; //Barrows gloves
391 entityDef.modelIds[3] = 28826; //BCP (arms)
392 entityDef.modelIds[4] = 29250; //Primordial boots
393 entityDef.modelIds[5] = 32678; //Elder maul
394 entityDef.modelIds[6] = 14424; //Serp helm
395 entityDef.modelIds[7] = 31227; // Torture
396 entityDef.modelIds[8] = 29616; //Max cape
397 entityDef.standingAnimation = 7518; // Npc's Stand Emote
398 entityDef.walkingAnimation = 7520;
399 entityDef.recolorOriginal = new int[]{668, 675, 673, 815, 784};
400 entityDef.recolorTarget = new int[]{947, 960, 7104, 8146, 0};
401 entityDef.name = "Donator Guard";
402 entityDef.combatLevel = 420;
403 entityDef.description = "The protector of the donator zone.".getBytes(); // NPC description
404 break;
405 }
406
407 return entityDef;
408 }
409
410 public void decode(Buffer stream) {
411 int lastOpcode = -1;
412 do {
413 int opcode = stream.readUnsignedByte();
414 if (opcode == 0)
415 return;
416 if (opcode == 1) {
417 int j = stream.readUnsignedByte();
418 modelIds = new int[j];
419 for (int j1 = 0; j1 < j; j1++)
420 modelIds[j1] = stream.readUnsignedShort();
421
422 } else if (opcode == 2) {
424 } else if (opcode == 3)
425 description = stream.readBytes();
426 else if (opcode == 12)
427 size = stream.readSignedByte();
428 else if (opcode == 13)
430 else if (opcode == 14)
432 else if (opcode == 15)
433 stream.readUnsignedShort();
434 else if (opcode == 16)
435 stream.readUnsignedShort();
436 else if (opcode == 17) {
441 if (halfTurnAnimation == 65535) {
443 }
444 if (quarterClockwiseTurnAnimation == 65535) {
446 }
449 }
450 } else if (opcode == 18) {
451 stream.readUnsignedShort();
452 } else if (opcode >= 30 && opcode < 35) {
453 if (actions == null)
454 actions = new String[5];
455 actions[opcode - 30] = stream.readStringCp1252NullTerminated();
456 if (actions[opcode - 30].equalsIgnoreCase("hidden"))
457 actions[opcode - 30] = null;
458 } else if (opcode == 40) {
459 int colors = stream.readUnsignedByte();
460 recolorOriginal = new int[colors];
461 recolorTarget = new int[colors];
462 for (int k1 = 0; k1 < colors; k1++) {
463 recolorOriginal[k1] = stream.readUnsignedShort();
464 recolorTarget[k1] = stream.readUnsignedShort();
465 }
466 } else if (opcode == 41) {
467 int length = stream.readUnsignedByte();
468
469 for (int index = 0; index < length; index++) {
470 stream.readUnsignedShort();
471 stream.readUnsignedShort();
472 }
473 } else if (opcode == 60) {
474 int l = stream.readUnsignedByte();
475 anIntArray73 = new int[l];
476 for (int l1 = 0; l1 < l; l1++)
477 anIntArray73[l1] = stream.readUnsignedShort();
478
479 } else if (opcode == 90)
480 stream.readUnsignedShort();
481 else if (opcode == 91)
482 stream.readUnsignedShort();
483 else if (opcode == 92)
484 stream.readUnsignedShort();
485 else if (opcode == 93)
486 drawMapDot = false;
487 else if (opcode == 95)
489 else if (opcode == 97)
490 widthScale = stream.readUnsignedShort();
491 else if (opcode == 98)
493 else if (opcode == 99)
494 isVisible = true;
495 else if (opcode == 100)
496 lightModifier = stream.readSignedByte();
497 else if (opcode == 101)
498 shadowModifier = stream.readSignedByte() * 5;
499 else if (opcode == 102) {
500 int bitfield = stream.readUnsignedByte();
501 int len = 0;
502 for (int var5 = bitfield; var5 != 0; var5 >>= 1) {
503 ++len;
504 }
505
506 int[] headIconArchiveIds = new int[len];
507 short[] headIconSpriteIndex = new short[len];
508
509 for (int i = 0; i < len; i++) {
510 if ((bitfield & 1 << i) == 0) {
511 headIconArchiveIds[i] = -1;
512 headIconSpriteIndex[i] = -1;
513 } else {
514 headIconArchiveIds[i] = stream.readBigSmart2();
515 headIconSpriteIndex[i] = (short) stream.readUnsignedShortSmartMinusOne();
516 }
517 }
518
519 headIconSprite = headIconSpriteIndex[0];
520 } else if (opcode == 103) {
521 rotation = stream.readUnsignedShort();
522 } else if (opcode == 106) {
524 if (transformVarbit == 65535) {
525 transformVarbit = -1;
526 }
527
529 if (transformVarp == 65535) {
530 transformVarp = -1;
531 }
532
533 int var = -1;
534
535 int length = stream.readUnsignedByte();
536 childrenIDs = new int[length + 2];
537
538 for (int index = 0; index <= length; index++) {
539 childrenIDs[index] = stream.readUnsignedShort();
540 if (childrenIDs[index] == 65535) {
541 childrenIDs[index] = -1;
542 }
543 }
544
545 childrenIDs[length + 1] = var;
546 } else if (opcode == 107) {
547 isInteractable = false;
548 } else if (opcode == 109) {
549// rotationFlag = false;
550 } else if (opcode == 111) {
551// isPet = true;
552 } else if (opcode == 114) {
553 stream.readUnsignedShort();
554 } else if (opcode == 115) {
555 stream.readUnsignedShort();
556 stream.readUnsignedShort();
557 stream.readUnsignedShort();
558 stream.readUnsignedShort();
559 } else if (opcode == 116) {
560 stream.readUnsignedShort();
561 } else if (opcode == 117) {
562 stream.readUnsignedShort();
563 stream.readUnsignedShort();
564 stream.readUnsignedShort();
565 stream.readUnsignedShort();
566 } else if (opcode == 118) {
568 if (transformVarbit == 65535) {
569 transformVarbit = -1;
570 }
571
573 if (transformVarp == 65535) {
574 transformVarp = -1;
575 }
576
577 int var = stream.readUnsignedShort();
578 if (var == 0xFFFF) {
579 var = -1;
580 }
581
582 int length = stream.readUnsignedByte();
583 childrenIDs = new int[length + 2];
584
585 for (int index = 0; index <= length; index++) {
586 childrenIDs[index] = stream.readUnsignedShort();
587 if (childrenIDs[index] == 65535) {
588 childrenIDs[index] = -1;
589 }
590 }
591
592 childrenIDs[length + 1] = var;
593 } else if (opcode == 249) {
594 int length = stream.readUnsignedByte();
595
596 for (int i = 0; i < length; i++) {
597 boolean isString = stream.readUnsignedByte() == 1;
598 stream.readUnsignedTriByte();
599
600 if (isString) {
602 } else {
603 stream.readUnsignedInt();
604 }
605 }
606 } else {
607 System.out.println("Unrecognized NPC opcode " + opcode + ", last=" + lastOpcode);
608 return;
609 }
610 lastOpcode = opcode;
611 } while (true);
612 }
613
616 transformVarbit = -1;
618 transformVarp = -1;
619 combatLevel = -1;
620 anInt64 = 1834;
621 walkingAnimation = -1;
622 size = 1;
623 headIconSprite = -1;
625 interfaceType = -1L;
626 rotation = 32;
628 isInteractable = true;
629 heightScale = 128;
630 drawMapDot = true;
631 widthScale = 128;
632 isVisible = false;
633 }
634
636 public static int nextNpcDefCacheIndex;
637 public int transformVarbit;
639 public int transformVarp;
640 public static Buffer buffer;
641 public int combatLevel;
642 public final int anInt64;
643 public String name;
644 public String[] actions;
646 public byte size;
647 public int[] recolorTarget;
648 public static int[] offsets;
649 public int[] anIntArray73;
650 public int headIconSprite;
651 public int[] recolorOriginal;
653 public long interfaceType;
654 public int rotation;
657 public boolean isInteractable;
658 public int lightModifier;
659 public int heightScale;
660 public boolean drawMapDot;
661 public int[] childrenIDs;
662 public byte[] description;
663 public int widthScale;
664 public int shadowModifier;
665 public boolean isVisible;
666 public int[] modelIds;
667 public int interfaceZoom = 0;
668
669 @Override
670 public String toString() {
671 return "NpcDefinition{" +
672 "quarterAnticlockwiseTurnAnimation=" + quarterAnticlockwiseTurnAnimation +
673 ", transformVarbit=" + transformVarbit +
674 ", halfTurnAnimation=" + halfTurnAnimation +
675 ", transformVarp=" + transformVarp +
676 ", combatLevel=" + combatLevel +
677 ", anInt64=" + anInt64 +
678 ", name='" + name + '\'' +
679 ", actions=" + Arrays.toString(actions) +
680 ", walkingAnimation=" + walkingAnimation +
681 ", size=" + size +
682 ", recolorTarget=" + Arrays.toString(recolorTarget) +
683 ", anIntArray73=" + Arrays.toString(anIntArray73) +
684 ", anInt75=" + headIconSprite +
685 ", recolorOriginal=" + Arrays.toString(recolorOriginal) +
686 ", standingAnimation=" + standingAnimation +
687 ", interfaceType=" + interfaceType +
688 ", rotation=" + rotation +
689 ", quarterClockwiseTurnAnimation=" + quarterClockwiseTurnAnimation +
690 ", isInteractable=" + isInteractable +
691 ", lightModifier=" + lightModifier +
692 ", scaleY=" + heightScale +
693 ", drawMapDot=" + drawMapDot +
694 ", childrenIDs=" + Arrays.toString(childrenIDs) +
695 ", description=" + Arrays.toString(description) +
696 ", scaleXZ=" + widthScale +
697 ", shadowModifier=" + shadowModifier +
698 ", isVisible=" + isVisible +
699 ", modelId=" + Arrays.toString(modelIds) +
700 ", interfaceZoom=" + interfaceZoom +
701 '}';
702 }
703
704}
Represents an archive within the Cache.
Definition Archive.java:25
static Buffer fromByteBuffer(final ByteBuffer byteBuffer)
Definition Buffer.java:112
static CacheNpcDefinition lookup(int npcId)
static void unpackConfig(final Archive archive)