-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathClient.java
More file actions
3962 lines (3491 loc) · 132 KB
/
Copy pathClient.java
File metadata and controls
3962 lines (3491 loc) · 132 KB
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* rscplus
*
* <p>This file is part of rscplus.
*
* <p>rscplus is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* <p>rscplus is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* <p>You should have received a copy of the GNU General Public License along with rscplus. If not,
* see <http://www.gnu.org/licenses/>.
*
* <p>Authors: see <https://github.com/RSCPlus/rscplus>
*/
package Game;
import static Replay.game.constants.Game.itemActionMap;
import Client.JClassPatcher;
import Client.JConfig;
import Client.KeybindSet;
import Client.Launcher;
import Client.Logger;
import Client.NotificationsHandler;
import Client.NotificationsHandler.NotifType;
import Client.ScaledWindow;
import Client.ServerExtensions;
import Client.Settings;
import Client.Speedrun;
import Client.TwitchIRC;
import Client.Util;
import Client.WikiURL;
import Client.World;
import Client.WorldMapWindow;
import Replay.game.constants.Game.ItemAction;
import java.applet.Applet;
import java.awt.Component;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* This class prepares the client for login, handles chat messages, and performs player related
* calculations.
*/
public class Client {
// Game's client instance
public static Object instance;
// Create an executor for scheduling future actions. (Pool size of 1 for a single-threaded scheduler)
public static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
public static Map<String, LinkedList<String>> tracerInstructions =
new LinkedHashMap<String, LinkedList<String>>();
public static List<NPC> npc_list = new ArrayList<>();
public static List<NPC> npc_list_retained = new ArrayList<>();
public static List<Item> item_list = new ArrayList<>();
public static List<Item> item_list_retained = new ArrayList<>();
public static final int SKILL_ATTACK = 0;
public static final int SKILL_DEFENSE = 1;
public static final int SKILL_STRENGTH = 2;
public static final int SKILL_HP = 3;
public static final int SKILL_RANGED = 4;
public static final int SKILL_PRAYER = 5;
public static final int SKILL_MAGIC = 6;
public static final int SKILL_COOKING = 7;
public static final int SKILL_WOODCUT = 8;
public static final int SKILL_FLETCHING = 9;
public static final int SKILL_FISHING = 10;
public static final int SKILL_FIREMAKING = 11;
public static final int SKILL_CRAFTING = 12;
public static final int SKILL_SMITHING = 13;
public static final int SKILL_MINING = 14;
public static final int SKILL_HERBLAW = 15;
public static final int SKILL_AGILITY = 16;
public static final int SKILL_THIEVING = 17;
public static final int STAT_PRAYER = 4;
public static final int[] DRAIN_RATES = {15, 15, 15, 30, 30, 30, 5, 10, 10, 60, 60, 60, 60, 60};
public static final int STATE_LOGIN = 1;
public static final int STATE_GAME = 2;
public static final int SCREEN_CLICK_TO_LOGIN = 0; // also is this value while logged in
public static final int SCREEN_REGISTER_NEW_ACCOUNT = 1;
public static final int SCREEN_USERNAME_PASSWORD_LOGIN = 2;
public static final int SCREEN_PASSWORD_RECOVERY = 3;
public static final int MENU_NONE = 0;
public static final int MENU_INVENTORY = 1;
public static final int MENU_MINIMAP = 2;
public static final int MENU_STATS_QUESTS = 3;
public static final int MENU_MAGIC_PRAYERS = 4;
public static final int MENU_FRIENDS_IGNORE = 5;
public static final int MENU_SETTINGS = 6;
public static final int MENU_STATS = 0;
public static final int MENU_QUESTS = 1;
public static final int CHAT_NONE = 0;
public static final int CHAT_PRIVATE = 1;
public static final int CHAT_PRIVATE_OUTGOING = 2;
public static final int CHAT_QUEST = 3;
public static final int CHAT_CHAT = 4;
public static final int CHAT_PRIVATE_LOG_IN_OUT = 5;
public static final int CHAT_TRADE_REQUEST_RECEIVED =
6; // only used when another player sends you a trade request. (hopefully!)
public static final int CHAT_OTHER =
7; // used for when you send a player a duel/trade request, follow someone, or drop an item
public static final int CHAT_INCOMING_OPTION = 8;
public static final int CHAT_CHOSEN_OPTION = 9;
public static final int CHAT_WINDOWED_MSG = 10;
public static final int COMBAT_CONTROLLED = 0;
public static final int COMBAT_AGGRESSIVE = 1;
public static final int COMBAT_ACCURATE = 2;
public static final int COMBAT_DEFENSIVE = 3;
public static int state = STATE_LOGIN;
public static final int POPUP_CANCEL_RECOVERY = 10;
public static final int POPUP_BANK_SEARCH = 11;
public static final int WRENCH_ALIGNMENT_FIX = 5;
public static final int WRENCH_ALIGNMENT_NO_FIX = 0;
public static int max_inventory;
public static int inventory_count;
public static long magic_timer = 0L;
public static int combat_timer;
public static boolean isGameLoaded;
public static boolean show_bank;
public static boolean bank_interface_drawn;
public static boolean show_duel;
public static boolean show_duelconfirm;
public static int show_friends;
public static int show_menu;
public static int show_stats_or_quests;
public static boolean show_questionmenu;
public static int show_report;
public static boolean show_shop;
public static boolean show_sleeping;
public static boolean show_trade;
public static boolean show_tradeconfirm;
public static boolean show_welcome;
public static boolean show_appearance;
public static boolean runReplayHook = false;
public static boolean runReplayCloseHook = false;
public static int[] inventory_items;
public static long poison_timer = 0L;
public static boolean is_poisoned = false;
public static boolean is_in_wild;
public static int wild_level;
// fatigue units as sent by the server
public static int fatigue;
// fatigue in units
public static int current_fatigue_units;
// fatigue in percentage
private static float currentFatigue;
public static boolean[] prayers_on;
// equipment stats (array position 4 holds prayer bonus to determine change drain rate)
public static int[] current_equipment_stats;
public static int[] current_level;
public static int[] base_level;
public static int[] xp;
public static String[] skill_name;
public static int combat_style;
public static int friends_count;
public static String[] friends;
public static String[] friends_world;
public static String[] friends_formerly;
public static int[] friends_online;
public static int ignores_count;
public static String[] ignores;
public static String[] ignores_formerly;
public static String[] ignores_copy;
public static String[] ignores_formerly_copy;
public static String pm_username;
public static String pm_text;
public static String pm_enteredText;
public static String pm_enteredTextCopy = ""; // must be initialized
public static String lastpm_username = null;
public static String modal_text;
public static String modal_enteredText;
public static int login_screen;
public static String username_login;
public static String password_login;
public static int autologin_timeout;
public static boolean on_tut_island;
public static Object player_object;
public static String player_name = "";
public static int player_id = -1;
public static boolean resolvedName = false;
public static String playerAlias = "";
public static String xpUsername = "";
public static boolean knowWhoIAm = false;
public static int player_posX = -1;
public static int player_posY = -1;
public static int player_height = -1;
public static int player_width = -1;
public static int regionX = -1;
public static int regionY = -1;
public static int worldX = -1;
public static int worldY = -1;
public static int localRegionX = -1;
public static int localRegionY = -1;
public static int planeWidth = -1;
public static int planeHeight = -1;
public static int planeIndex = -1;
public static boolean loadingArea = false;
public static Object clientStream;
public static Object writeBuffer;
public static Object menuCommon;
public static Object packetsIncoming;
public static final int TRACER_LINES = 100;
// bank items and their count for each type, new bank items are first to get updated and indicate
// bank excluding inventory types and bank items do include them (in regular mode), as bank
// operations are messy they get excluded also in searchable bank
public static int[] bank_items_count;
public static int[] bank_items;
public static int[] new_bank_items_count;
public static int[] new_bank_items;
public static int bank_active_page;
public static int bank_items_max;
// these two variables, they indicate distinct bank items count
public static int new_count_items_bank;
public static int count_items_bank;
public static int selectedItem;
public static int selectedItemSlot;
public static boolean is_hover;
public static int fps;
/** An array of Strings that stores text used in the client */
public static String[] strings;
public static XPDropHandler xpdrop_handler = new XPDropHandler();
public static XPBar xpbar = new XPBar();
private static TwitchIRC twitch = new TwitchIRC();
public static MouseHandler handler_mouse;
public static KeyboardHandler handler_keyboard;
private static long updateTimer = 0;
private static long last_time = 0;
public static boolean showRecordAlwaysDialogue = false;
public static long update_timer;
public static long updates;
public static long updatesPerSecond;
public static String lastSoundEffect = "";
public static BigInteger modulus;
public static BigInteger exponent;
public static int maxRetries;
public static byte[] fontData;
public static byte[] indexData;
public static byte[] hbarOrigData;
public static byte[] hbarRetroData;
public static String lastServerMessage = "";
public static int[] inputFilterCharFontAddr;
public static byte[] lastIncomingBytes;
public static Thread loginMessageHandlerThread;
public static String loginMessageTop =
"To connect to a server, please configure your World URLs.";
public static String loginMessageBottom =
"Click on the @yel@settings gear@whi@ and select the @cya@World List@whi@ tab.";
public static boolean showingNoWorldsMessage = false;
public static String connectionMismatchMessageTop =
"Connection couldn't be verified. Please update " + Launcher.binaryPrefix + "RSC+.";
public static String connectionMismatchMessageBottomWithSub =
"If already updated, relaunch the client in a few minutes and try again.";
public static String connectionMismatchMessageBottom =
"If already updated, ensure the world file data is accurate.";
public static final int NUM_SKILLS = 18;
/**
* A boolean array that stores if the XP per hour should be shown for a given skill when hovering
* on the XP bar.
*
* <p>This should only be false for a skill if there has been less than 2 XP drops during the
* current tracking session, since there is not enough data to calculate the XP per hour.
*/
private static HashMap<String, Boolean[]> showXpPerHour = new HashMap<String, Boolean[]>();
/** An array to store the XP per hour for a given skill */
private static HashMap<String, Double[]> xpPerHour = new HashMap<String, Double[]>();
// the total XP gained in a given skill within the sample period
private static final int TOTAL_XP_GAIN = 0;
// the time of the last XP drop in a given skill
private static final int TIME_OF_LAST_XP_DROP = 1;
// the time of the first XP drop in a given skill within the sample period
private static final int TIME_OF_FIRST_XP_DROP = 2;
// the total number of XP drops recorded within the sample period, plus 1
private static final int TOTAL_XP_DROPS = 3;
// the amount of XP gained since last processed
private static final int LAST_XP_GAIN = 4;
// first dimension of this array is skill ID.
// second dimension is the constants in block above.
private static HashMap<String, Double[][]> lastXpGain = new HashMap<String, Double[][]>();
// player name -> combat style
public static HashMap<String, Integer> playerCombatStyles = new HashMap<>();
// holds players XP since last processing xp drops
private static HashMap<String, Float[]> xpLast = new HashMap<String, Float[]>();
public static HashMap<String, Integer[]> xpGoals = new HashMap<String, Integer[]>();
public static HashMap<String, Float[]> lvlGoals = new HashMap<String, Float[]>();
private static float[] xpGain = new float[18];
/** The client version */
public static int version;
public static String inputFilterChars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"\u00a3$%^&*()-_=+[{]};:\'@#~,<.>/?\\| ";
public static String[] menuOptions;
public static int tileSize;
public static long menu_timer;
public static String lastAction;
public static int login_delay;
public static String server_address;
public static int serverjag_port;
public static int session_id;
public static boolean failedRecovery = false;
public static int recoveryChangeDays;
public static int tipOfDay = -1;
public static Object panelWelcome;
public static Object panelLogin;
public static Object panelRegister;
public static Object panelRecovery;
public static Object panelRecoveryQuestions;
public static Object panelContactDetails;
public static int controlWelcomeType;
public static int controlServerType;
public static int controlLoginTop;
public static int controlLoginBottom;
public static int loginUserInput;
public static int loginPassInput;
public static int loginLostPasswordButton;
public static int registerButton;
public static int controlRegister;
public static int chooseUserInput;
public static int choosePasswordInput;
public static int chooseConfirmPassInput;
public static int acceptTermsCheckbox;
public static int chooseSubmitRegisterButton;
public static int chooseCancelRegisterButton;
public static int controlRecoveryTop;
public static int controlRecoveryBottom;
public static int controlRecoveryQuestion[] = new int[5];
public static int controlRecoveryInput[] = new int[5];
public static int recoverOldPassInput;
public static int recoverNewPassInput;
public static int recoverConfirmPassInput;
public static int chooseSubmitRecoveryButton;
public static int chooseCancelRecoveryButton;
public static int controlRecoveryQuestions;
public static String controlRecoveryText[] = new String[5];
public static int controlRecoveryIns[] = new int[5];
public static int controlAnswerInput[] = new int[5];
public static int controlQuestion[] = new int[5];
public static int controlCustomQuestion[] = new int[5];
public static int chooseFinishSetRecoveryButton;
public static int controlContactDetails;
public static int fullNameInput;
public static int zipCodeInput;
public static int countryInput;
public static int emailInput;
public static int chooseSubmitContactDetailsButton;
public static boolean showAppearanceChange;
public static boolean showRecoveryQuestions;
public static boolean showContactDetails;
public static boolean firstTimeRunningRSCPlus = false;
public static boolean customSfxVolumeSet = false;
public static int mouse_click;
public static boolean singleButtonMode;
public static boolean firstTime = true;
public static Object worldInstance;
public static int lastHeightOffset;
// BELOW VARIABLE USED IN THE REMOVE X RESIZABLE BUG-FIX WHEN TRADING
public static String[] items_remove_message =
new String[] {"Enter number of items to remove and press enter"};
public static Boolean lastIsMembers = null;
// used in original client
public static boolean members;
public static boolean veterans;
// used to distinguish live world, in replay there are two similar variables
public static boolean worldMembers;
public static boolean worldVeterans;
public static Object soundSub = null;
public static Object gameContainer = null;
public static boolean usingRetroTabs = false;
public static MusicDef loginTrack = MusicDef.NONE;
public static AreaDefinition[][][] areaDefinitions = new AreaDefinition[4][100][100];
public static final String[] colorDict = {
// less common colors should go at the bottom b/c we can break search loop early
// several of the orange & green colours are basically the same colour, even in-game
"(?i)@cya@", "|@@|cyan ",
"(?i)@whi@", "|@@|white ",
"(?i)@red@", "|@@|red ",
"(?i)@gre@", "|@@|green ",
"(?i)@lre@", "|@@|red,intensity_faint ",
"(?i)@dre@", "|@@|red,intensity_bold ",
"(?i)@ran@", "|@@|red,blink_fast ", // TODO: consider handling this specially
"(?i)@yel@", "|@@|yellow ",
"(?i)@mag@", "|@@|magenta,intensity_bold ",
"(?i)@gr1@", "|@@|green ",
"(?i)@gr2@", "|@@|green ",
"(?i)@gr3@", "|@@|green ",
"(?i)@ora@", "|@@|red,intensity_faint ",
"(?i)@or1@", "|@@|red,intensity_faint ",
"(?i)@or2@", "|@@|red,intensity_faint ",
"(?i)@or3@", "|@@|red ",
"(?i)@blu@", "|@@|blue ",
"(?i)@bla@", "|@@|black "
};
public static int objectCount;
public static int[] objectDirections;
public static int[] objectX;
public static int[] objectY;
public static int[] objectID;
/**
* Iterates through {@link #strings} array and checks if various conditions are met. Used for
* patching client text.
*/
public static void adaptStrings() {}
// string 662 is the one in version 235 that contains the "from: " used in login welcome screen
public static void adaptLoginInfo() {
if (!Settings.SHOW_LOGIN_IP_ADDRESS.get(Settings.currentProfile)
&& strings[662].startsWith("from:")) {
strings[662] = "@bla@from: ";
} else if (Settings.SHOW_LOGIN_IP_ADDRESS.get(Settings.currentProfile)
&& strings[662].startsWith("@bla@from:")) {
strings[662] = "from: ";
}
}
public static Callable<Void> takeLevelUpScreenshot = () -> {
// Add the screenshot to the queue
Renderer.takeScreenshot(true);
return null;
};
public static int shadowSleepCount;
/*
This method replaces u.a (IJ)
shadowSleepCount is unused in the client, but is hooked and incremented properly anyway.
According to "Hixk": https://github.com/RSCPlus/rscplus/pull/16#issuecomment-648823713
This function was recreated from the disassembly of the function, please leave the original
code commented out in the function and explain why it was removed!
TODO: Figure out what unknown is
*/
public static final void shadowSleep(int unknown, long ms) {
/* Removing this increases stability according to the Hixk issue linked above */
// if (unknown != 0) return;
try {
Thread.sleep(ms);
} catch (Exception e) {
}
shadowSleepCount += 1;
}
public static void CrashFixRoutine(Throwable e, int index) {
Logger.Error("A crash was prevented, here is some information about it.");
PrintException(e, index);
}
public static void PrintException(Throwable e, int index) {
String printMessage = "Caller: " + JClassPatcher.ExceptionSignatures.get(index) + "\n\n";
if (e.getMessage() != null) printMessage = "Message: " + e.getMessage() + "\n" + printMessage;
StackTraceElement[] stacktrace = e.getStackTrace();
for (int i = 0; i < stacktrace.length; i++) {
StackTraceElement element = stacktrace[i];
printMessage += element.getClassName() + "." + element.getMethodName() + "(UNKNOWN)";
if (i != stacktrace.length - 1) printMessage += "\n";
}
// Add tracer information
Iterator tracerIterator = tracerInstructions.entrySet().iterator();
if (tracerIterator.hasNext()) {
printMessage += "\n\n";
}
while (tracerIterator.hasNext()) {
Map.Entry element = (Map.Entry) tracerIterator.next();
String name = (String) element.getKey();
String[] tracer = (String[]) ((LinkedList<String>) element.getValue()).toArray();
printMessage += "[" + name + "]\n";
for (int i = 0; i < tracer.length; i++) {
String instruction = (String) tracer[i];
if (instruction != null) {
printMessage += instruction;
if (i != tracer.length - 1) printMessage += "\n";
}
}
if (tracerIterator.hasNext()) printMessage += "\n\n";
}
Logger.Error("EXCEPTION\n" + printMessage);
}
public static Throwable HandleException(Throwable e, int index) {
if (!Settings.EXCEPTION_HANDLER.get(Settings.currentProfile)) return e;
PrintException(e, index);
return e;
}
public static void TracerHandler(int indexHigh, int indexLow) {
// Convert index
if (indexHigh < 0) indexHigh += Short.MAX_VALUE * 2;
if (indexLow < 0) indexLow += Short.MAX_VALUE * 2;
int index = (indexHigh << 16) | indexLow;
Thread thread = Thread.currentThread();
String threadName = thread.getName();
LinkedList<String> instructions;
if (tracerInstructions.containsKey(threadName)) {
instructions = tracerInstructions.get(threadName);
} else {
instructions =
new LinkedList<String>() {
private Object threadLock = new Object();
@Override
public boolean add(String object) {
boolean result;
if (this.size() >= TRACER_LINES) removeFirst();
synchronized (threadLock) {
result = super.add(object);
}
return result;
}
@Override
public String removeFirst() {
String result;
synchronized (threadLock) {
result = super.removeFirst();
}
return result;
}
@Override
public String[] toArray() {
String[] result;
synchronized (threadLock) {
result = new String[size()];
for (int i = 0; i < size(); i++) result[i] = get(i);
}
return result;
}
};
tracerInstructions.put(threadName, instructions);
}
// Add decoded instruction to tracer
String instruction = JClassPatcher.InstructionBytecode.get(index);
instructions.add(instruction);
}
public static void loadAreaDefinitions() {
// Set default region
for (int floor = 0; floor < 4; floor++) {
for (int x = AreaDefinition.REGION_X_OFFSET;
x < AreaDefinition.SIZE_X + AreaDefinition.REGION_X_OFFSET;
x++) {
for (int y = AreaDefinition.REGION_Y_OFFSET;
y < AreaDefinition.SIZE_Y + AreaDefinition.REGION_Y_OFFSET;
y++) {
if (AreaDefinition.hasLand(floor * 10000 + x * 100 + y)) {
areaDefinitions[floor][x][y] = AreaDefinition.DEFAULT_LAND;
} else {
areaDefinitions[floor][x][y] = AreaDefinition.DEFAULT;
}
}
}
}
InputStream input = null;
try {
String zipPath =
Settings.Dir.CONFIG_DIR
+ File.separator
+ Settings.CUSTOM_MUSIC_PATH.get(Settings.currentProfile);
try {
FileInputStream fis = new FileInputStream(zipPath);
BufferedInputStream bis = new BufferedInputStream(fis);
ZipInputStream zis = new ZipInputStream(bis);
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
if (ze.getName().equalsIgnoreCase("areas.json")) {
input = zis;
break;
}
}
} catch (Exception e) {
Logger.Info("No music to load at " + zipPath);
return;
}
if (null == input) {
return;
}
String areaJson = Util.readString(input);
JSONArray obj = new JSONArray(areaJson);
for (int i = 0; i < obj.length(); i++) {
JSONObject entry = obj.getJSONObject(i);
try {
String filename = entry.getString("title");
String trackname = entry.getString("trackname");
String filetype = entry.getString("filetype");
loginTrack = new MusicDef(trackname, filename, filetype);
continue;
} catch (Exception e) {
}
try {
String soundfont = entry.getString("soundfont");
MusicPlayer.loadSoundFont(soundfont);
continue;
} catch (Exception e) {
}
try {
int floor = entry.getInt("floor");
int chunkX = entry.getInt("regionX");
int chunkY = entry.getInt("regionY");
String trackname = entry.getString("trackname");
String filename = entry.getString("filename");
String filetype = entry.getString("filetype");
// Spread the same music track across multiple chunks if an x2 or y2 value is defined
int chunkX2 = chunkX;
int chunkY2 = chunkY;
try {
chunkX2 = entry.getInt("regionX2");
} catch (Exception e) {
}
try {
chunkY2 = entry.getInt("regionY2");
} catch (Exception e) {
}
MusicDef musicDef = new MusicDef(trackname, filename, filetype);
AreaDefinition areaDef = new AreaDefinition(musicDef, true);
for (int x = chunkX; x <= chunkX2; x++) {
for (int y = chunkY; y <= chunkY2; y++) {
areaDefinitions[floor][x][y] = areaDef;
}
}
} catch (Exception e) {
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != input) {
try {
input.close();
} catch (Exception e) {
}
}
}
}
public static AreaDefinition getCurrentAreaDefinition() {
int chunkX = getChunkX();
int chunkY = getChunkY();
// Return default chunk if out of bounds
if (chunkX >= AreaDefinition.SIZE_X + AreaDefinition.REGION_X_OFFSET
|| chunkY >= AreaDefinition.SIZE_Y + AreaDefinition.REGION_Y_OFFSET
|| chunkX < AreaDefinition.REGION_X_OFFSET
|| chunkY < AreaDefinition.REGION_Y_OFFSET) return AreaDefinition.DEFAULT;
return areaDefinitions[getFloor()][chunkX][chunkY];
}
public static Object getObjectModel(int i) {
try {
return Array.get(Reflection.objectModels.get(Client.instance), i);
} catch (Exception e) {
return null;
}
}
public static void gameModelRotate(Object model, int rotation) {
try {
Reflection.gameModelRotate.setAccessible(true);
Reflection.gameModelRotate.invoke(model, 0, -31616, rotation, 0);
Reflection.gameModelRotate.setAccessible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void gameModelSetLight(Object model) {
try {
Reflection.gameModelSetLight.setAccessible(true);
Reflection.gameModelSetLight.invoke(model, -50, 48, -10, -50, true, 48, 117);
Reflection.gameModelSetLight.setAccessible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void init() {
loadAreaDefinitions();
adaptStrings();
handler_mouse = new MouseHandler();
handler_keyboard = new KeyboardHandler();
Applet applet = Game.getInstance().getApplet();
applet.addMouseListener(handler_mouse);
applet.addMouseMotionListener(handler_mouse);
applet.addMouseWheelListener(handler_mouse);
applet.addKeyListener(handler_keyboard);
applet.setFocusTraversalKeysEnabled(false);
if (Settings.DISASSEMBLE.get(Settings.currentProfile)) dumpStrings();
// Initialize login
init_login();
init_extra();
init_chat_tab_assets();
// check if "Gender" of appearance panel should be patched
// first is of the string to "Body" then in
// patch_gender_hook adds text "Type"
if (Settings.PATCH_GENDER.get(Settings.currentProfile)) {
strings[91] = "Body";
}
}
public static boolean skipToLogin() {
if (firstTimeRunningRSCPlus) {
return false;
}
boolean skipToLogin = false;
if (Settings.WORLDS_TO_DISPLAY == 1 && Settings.WORLD.get(Settings.currentProfile) != 0) {
String curWorldURL = Settings.WORLD_URLS.get(1);
try {
String address = InetAddress.getByName(curWorldURL).toString();
if (Util.isLocalhost(address)) {
// no configured world or localhost only
skipToLogin = true;
}
} catch (UnknownHostException e) {
skipToLogin = true;
}
}
return skipToLogin
|| (!Settings.noWorldsConfigured
&& Settings.START_LOGINSCREEN.get(Settings.currentProfile));
}
/**
* Decides if the text of "to change your contact details, etc" should be moved down to make it
* well aligned
*
* @return the needed alignment or none
*/
public static int wrenchFixHook() {
return Settings.PATCH_WRENCH_MENU_SPACING.get(Settings.currentProfile)
? WRENCH_ALIGNMENT_FIX
: WRENCH_ALIGNMENT_NO_FIX;
}
/**
* Reference for JClassPatcher and any other required. Indicates if should show account and
* security settings
*
* @return
*/
public static boolean showSecuritySettings() {
return Settings.SHOW_ACCOUNT_SECURITY_SETTINGS.get(Settings.currentProfile);
}
/**
* Method that gets called when starting game, normally would go to Welcome screen but if no world
* configured (using RSC+ for replay mode) skip directly to login for replays
*/
public static void resetLoginHook() {
if (skipToLogin()) {
login_screen = SCREEN_USERNAME_PASSWORD_LOGIN;
}
}
public static void init_extra() {
try (InputStream is = Launcher.getResourceAsStream("/assets/fontdata.bin")) {
fontData = new byte[is.available()];
is.read(fontData);
} catch (IOException e) {
Logger.Warn("Could not load font data, will not log prettified windowed server messages");
fontData = null;
}
inputFilterCharFontAddr = new int[256];
for (int code = 0; code < 256; ++code) {
int index = inputFilterChars.indexOf(code);
if (index == -1) {
index = 74;
}
inputFilterCharFontAddr[code] = index * 9;
}
}
public static void init_chat_tab_assets() {
try (InputStream is = Launcher.getResourceAsStream("/assets/hbar/hbar2_retro_compat.dat")) {
hbarRetroData = new byte[is.available()];
is.read(hbarRetroData);
} catch (IOException e) {
Logger.Warn("Could not load old hbar2 data, will not be able to draw old chat tabs");
hbarRetroData = null;
}
try (InputStream is = Launcher.getResourceAsStream("/assets/hbar/hbar2_orig.dat")) {
hbarOrigData = new byte[is.available()];
is.read(hbarOrigData);
} catch (IOException e) {
Logger.Warn("Could not load hbar2 data, will not be able to go back to the modern chat tabs");
hbarOrigData = null;
}
}
public static boolean forceDisconnect = false;
public static boolean forceReconnect = false;
public static boolean isUnderground() {
return planeIndex == 3;
}
public static void setObjectDirection(int idx, int direction) {
objectDirections[idx] = direction;
}
/** This works with world position! */
public static int getGameObjectIndex(int x, int y) {
for (int i = 0; i < objectCount; i++) {
int worldX = regionX + objectX[i];
int worldY = regionY + objectY[i];
if (worldX == x && worldY == y) return i;
}
return -1;
}
public static void setGameObjectDirection(int modelIndex, int direction) {
if (modelIndex == -1) return;
// Only update direction if it needs to be
if (objectDirections[modelIndex] != direction) {
Object model = getObjectModel(modelIndex);
gameModelRotate(model, objectDirections[modelIndex] * -32);
gameModelRotate(model, direction * 32);
objectDirections[modelIndex] = direction;
}
}
/**
* An updater that runs frequently to update calculations for XP/fatigue drops, the XP bar, etc.
*
* <p>This updater does not handle any rendering, for rendering see {@link Renderer#present}
*/
public static void update() {
// historical: RSC+ changed version here from 234 to 235 from 2016-10-10 up until 2022-01-16
// version = 235;
if (!exponent.toString().equals(JConfig.SERVER_RSA_EXPONENT))
exponent = new BigInteger(JConfig.SERVER_RSA_EXPONENT);
if (!modulus.toString().equals(JConfig.SERVER_RSA_MODULUS))
modulus = new BigInteger(JConfig.SERVER_RSA_MODULUS);
long time = System.currentTimeMillis();
long nanoTime = System.nanoTime();
float delta_time = (float) (nanoTime - last_time) / 1000000000.0f;
last_time = nanoTime;
// Set the mudclient volume
if (!customSfxVolumeSet) {
SoundEffects.adjustMudClientSfxVolume();
customSfxVolumeSet = true;
}
// Handle area data
if (Settings.CUSTOM_MUSIC.get(Settings.currentProfile)) {
if (state == STATE_GAME) {
AreaDefinition area = getCurrentAreaDefinition();
MusicPlayer.playTrack(area.music);
} else if (state == STATE_LOGIN) {
MusicPlayer.playTrack(loginTrack);
}
}
Camera.setLookatTile(getPlayerWaypointX(), getPlayerWaypointY());
Camera.update(delta_time);
if (Settings.takingSceneryScreenshots && state == STATE_GAME) {
setGameObjectDirection(
getGameObjectIndex(720, 1520), Renderer.screenshot_scenery_scenery_rotation);
}
/*
if (state == STATE_GAME) {
for (int i = 0; i< objectDirections.length; i++) {
Object model = getObjectModel(i);