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