-
Notifications
You must be signed in to change notification settings - Fork 34
/
Client.java
2250 lines (1997 loc) · 75.8 KB
/
Client.java
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.Settings;
import Client.TwitchIRC;
import Replay.game.constants.Game.ItemAction;
import java.applet.Applet;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import javax.swing.JOptionPane;
/**
* 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;
public static Map<String, LinkedList<String>> tracerInstructions =
new LinkedHashMap<String, LinkedList<String>>();
public static List<NPC> npc_list = new ArrayList<>();
public static List<Item> item_list = 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 MENU_NONE = 0;
public static final int MENU_INVENTORY = 1;
public static final int MENU_MINIMAP = 2;
public static final int MENU_STATS = 3;
public static final int MENU_FRIENDS = 4;
public static final int MENU_SETTINGS = 5;
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 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 show_duel;
public static boolean show_duelconfirm;
public static int show_friends;
public static int show_menu;
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 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;
// 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 lastpm_username = null;
public static String mouseText = "";
public static int login_screen;
public static String username_login;
public static int autologin_timeout;
public static Object player_object;
public static String player_name = "";
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 boolean sleepCmdSent = false;
public static int sleepBagIdx = -1;
public static Object clientStream;
public static Object writeBuffer;
public static Object menuCommon;
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;
// 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;
/** 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 float[] xpdrop_state = new float[18];
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 byte[] fontData;
public static String lastServerMessage = "";
public static int[] inputFilterCharFontAddr;
public static Thread loginMessageHandlerThread;
public static String loginMessageTop =
"To connect to a server, please configure your World URLs.";
public static String loginMessageBottom =
"Hit @gre@Ctrl-O@whi@ to access Settings and select the \"World List\" tab.";
/**
* 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 boolean[] showXpPerHour = new boolean[18];
/** An array to store the XP per hour for a given skill */
private static double[] xpPerHour = new double[18];
/**
* A multi-dimensional array that stores the last time XP was gained for a given skill.
*
* <p>The first dimension stores the skill index corresponding to the constants defined in the
* client class ( {@link #SKILL_ATTACK}, etc.)<br>
* The second dimension stores:<br>
* - [0] the total XP gained in a given skill within the sample period,<br>
* - [1] the time of the last XP drop in a given skill,<br>
* - [2] the time of the first XP drop in a given skill within the sample period,<br>
* - [3] and the total number of XP drops recorded within the sample period, plus 1.
*/
private static double[][] lastXpGain = new double[18][4];
/** The client version */
public static int version;
public static String[] menuOptions;
public static int tileSize;
public static long menu_timer;
public static String lastAction;
/**
* 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 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 init() {
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();
// Skip first login screen and don't wipe user info
login_screen = 2;
init_extra();
}
public static void init_extra() {
InputStream is = Launcher.getResourceAsStream("/assets/fontdata.bin");
try {
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;
}
String inputFilterChars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"\u00a3$%^&*()-_=+[{]};:\'@#~,<.>/?\\| ";
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 boolean forceDisconnect = false;
public static boolean forceReconnect = false;
/**
* 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() {
// FIXME: This is a hack from a rsc client update (so we can skip updating the client this time)
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;
Camera.setLookatTile(getPlayerWaypointX(), getPlayerWaypointY());
Camera.update(delta_time);
Replay.update();
if (Settings.RECORD_AUTOMATICALLY_FIRST_TIME.get(Settings.currentProfile)
&& showRecordAlwaysDialogue) {
int response =
JOptionPane.showConfirmDialog(
Game.getInstance().getApplet(),
"If you'd like, you can record your session every time you play by default.\n"
+ "\n"
+ "These recordings do not leave your computer unless you manually do it on purpose.\n"
+ "They also take up negligible space. You could fit about a 6 hour session on a floppy disk, depending on what you do.\n"
+ "\n"
+ "Recordings can be played back later, even offline, and capture the data the server sends and that you send the server.\n"
+ "Your password is not in the capture.\n"
+ "\n"
+ "Would you like to record all your play sessions by default?\n"
+ "\n"
+ "NOTE: This option can be toggled in the Settings interface (ctrl-o by default) under the Replay tab.",
"rscplus",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
Launcher.icon);
if (response == JOptionPane.YES_OPTION || response == JOptionPane.CLOSED_OPTION) {
Settings.RECORD_AUTOMATICALLY.put(Settings.currentProfile, true);
} else if (response == JOptionPane.NO_OPTION) {
Settings.RECORD_AUTOMATICALLY.put(Settings.currentProfile, false);
}
Settings.RECORD_AUTOMATICALLY_FIRST_TIME.put(Settings.currentProfile, false);
Settings.save();
}
if (state == STATE_GAME) {
Client.getPlayerName();
Client.adaptLoginInfo();
}
Game.getInstance().updateTitle();
if (forceDisconnect) {
Client.closeConnection(false);
forceDisconnect = false;
}
if (forceReconnect) {
Client.loseConnection(false);
forceReconnect = false;
}
// Handle skipping to next replay
if (!Replay.isPlaying && Replay.replayServer != null && Replay.replayServer.isDone) {
if (ReplayQueue.currentIndex < ReplayQueue.queue.size()) {
if (!ReplayQueue.skipped) {
ReplayQueue.nextReplay();
}
}
ReplayQueue.skipped = false;
}
// Process playback actions for replays
Replay.processPlaybackAction();
// Process playback queue for replays
ReplayQueue.processPlaybackQueue();
// Close replay, order matters on these two!
if (runReplayCloseHook) {
Replay.handleReplayClosing();
runReplayCloseHook = false;
}
// Login hook on this thread
if (runReplayHook && state == STATE_LOGIN) {
Renderer.replayOption = 2;
runReplayHook = false;
login_hook();
}
updates++;
time = System.currentTimeMillis();
if (time >= update_timer) {
updatesPerSecond = updates;
update_timer = time + 1000;
updates = 0;
}
}
public static void processFatigueXPDrops() {
// Process XP drops
boolean dropXP = xpdrop_state[SKILL_HP] > 0.0f; // TODO: Declare dropXP outside of this method
for (int i = 0; i < xpdrop_state.length; i++) {
float xpGain = getXP(i) - xpdrop_state[i]; // TODO: Declare xpGain outside of this method
xpdrop_state[i] += xpGain;
if (xpGain > 0.0f && dropXP) {
if (Settings.SHOW_XPDROPS.get(Settings.currentProfile))
xpdrop_handler.add("+" + xpGain + " (" + skill_name[i] + ")", Renderer.color_text);
// XP/hr calculations
// TODO: After 5-10 minutes of tracking XP, make it display a rolling average instead of a
// session
// average
if ((System.currentTimeMillis() - lastXpGain[i][1]) <= 180000) {
// < 3 minutes since last XP drop
lastXpGain[i][0] = xpGain + lastXpGain[i][0];
xpPerHour[i] =
3600 * (lastXpGain[i][0]) / ((System.currentTimeMillis() - lastXpGain[i][2]) / 1000);
lastXpGain[i][3]++;
showXpPerHour[i] = true;
lastXpGain[i][1] = System.currentTimeMillis();
} else {
lastXpGain[i][0] = xpGain;
lastXpGain[i][1] = lastXpGain[i][2] = System.currentTimeMillis();
lastXpGain[i][3] = 0;
showXpPerHour[i] = false;
}
if (i == SKILL_HP && xpbar.current_skill != -1) continue;
xpbar.setSkill(i);
}
}
// Process fatigue drops
if (Settings.SHOW_FATIGUEDROPS.get(Settings.currentProfile)) {
final float actualFatigue = getActualFatigue();
final float fatigueGain = actualFatigue - currentFatigue;
final int fatigueUnitsGain = fatigue - current_fatigue_units;
String gainText = "";
if (fatigueGain > 0.0f && !isWelcomeScreen()) {
gainText =
"+"
+ trimNumber(fatigueGain, Settings.FATIGUE_FIGURES.get(Settings.currentProfile))
+ "% (Fatigue)";
if (Settings.SHOW_FATIGUEUNITS.get(Settings.currentProfile))
gainText += (" [" + fatigueUnitsGain + " U]");
xpdrop_handler.add(gainText, Renderer.color_fatigue);
currentFatigue = actualFatigue;
current_fatigue_units = fatigue;
}
}
// Prevents a fatigue drop upon first login during a session
if (isWelcomeScreen() && currentFatigue != getActualFatigue()) {
currentFatigue = getActualFatigue();
current_fatigue_units = fatigue;
}
}
public static void init_login() {
for (int i = 0; i < xpdrop_state.length; i++) xpdrop_state[i] = 0.0f;
Camera.init();
state = STATE_LOGIN;
isGameLoaded = false;
Renderer.replayOption = 0;
twitch.disconnect();
resetLoginMessage();
Replay.closeReplayPlayback();
Replay.closeReplayRecording();
adaptStrings();
player_name = "";
}
public static void init_game() {
// Reset values to make the client more deterministic
// This helps out the replay mode to have matching output from the time it was recorded
Camera.init();
combat_style = Settings.COMBAT_STYLE.get(Settings.currentProfile);
state = STATE_GAME;
bank_active_page = 0;
combat_timer = 0;
if (TwitchIRC.isUsing()) twitch.connect();
}
public static void login_hook() {
// Order of comparison matters here
Replay.init(ReplayQueue.currentReplayName);
if (Renderer.replayOption == 2) {
if (!Replay.initializeReplayPlayback()) Renderer.replayOption = 0;
} else if (Renderer.replayOption == 1
|| Settings.RECORD_AUTOMATICALLY.get(Settings.currentProfile)) {
Replay.initializeReplayRecording();
}
if (Settings.noWorldsConfigured
&& Settings.WORLD.get(Settings.currentProfile) != 0
&& !Replay.isPlaying) {
closeConnection(false);
loginMessageHandlerThread = new Thread(new LoginMessageHandler());
loginMessageHandlerThread.start();
}
}
public static void disconnect_hook() {
// ::lostcon or closeConnection
Replay.closeReplayRecording();
}
// check if login attempt is not a valid login or reconnect, send to disconnect hook
// response 1 i don't know exactly what's for might be trying to connect in combat or something
public static void login_attempt_hook(int response, boolean reconnecting, int[] xtea_keys) {
// at this stage just close it
if (response == 1 || ((response & 64) == 0)) {
disconnect_hook();
}
}
public static void error_game_hook(String s) {
// from here its error_game_ + s -> check if its error_game_crash, thats the finalizing one that
// interrupts
// things
Logger.Error("Error game reported: " + s);
if (s.toLowerCase().equals("crash")) {
disconnect_hook();
}
}
/**
* Hooks the message that hovering over X thing gives in the client
*
* @param tooltipMessage - the message in raw color format
*/
public static String mouse_action_hook(String tooltipMessage) {
if (Settings.SHOW_MOUSE_TOOLTIP.get(Settings.currentProfile)) {
mouseText = tooltipMessage;
// Remove top-left action text in extended mode
if (Settings.SHOW_EXTENDED_TOOLTIP.get(Settings.currentProfile)) return "";
}
return tooltipMessage;
}
/**
* Tells the client that the adjacent region is loading, so not to do spikes in position printing
*
* @param isLoading - the flag for loading
*/
public static void isLoadingHook(boolean isLoading) {
if (worldX == -1 && worldY == -1) {
worldX = localRegionX + regionX;
worldY = localRegionY + regionY;
} else {
if (isLoading) {
Camera.reset_lookat();
} else {
worldX = localRegionX + regionX;
worldY = localRegionY + regionY;
}
}
}
public static void resetLoginMessage() {
setLoginMessage("Please enter your username and password", "");
}
/** Stores the user's display name in {@link #player_name}. */
public static void getPlayerName() {
try {
String name = (String) Reflection.characterName.get(player_object);
if (name != null) {
if (!name.equals(player_name)) {
player_name = name;
Camera.reset_lookat();
}
}
} catch (IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
}
}
public static int getPlayerWaypointX() {
int x = 0;
try {
x = (int) Reflection.characterWaypointX.get(player_object);
} catch (Exception e) {
}
return x;
}
public static int getPlayerWaypointY() {
int y = 0;
try {
y = (int) Reflection.characterWaypointY.get(player_object);
} catch (Exception e) {
}
return y;
}
/** Returns the coordinates of the player */
public static String getCoords() {
return "(" + worldX + "," + worldY + ")";
}
/**
* Intercepts chat messages sent by the user and parses them for commands.
*
* @param line a chat message sent by the user
* @return a modified chat message
*/
public static String processChatCommand(String line) {
// TODO: Move Twitch related checks to their own method to stay consistent
if (TwitchIRC.isUsing() && line.startsWith("/")) {
String message = line.substring(1, line.length());
String[] messageArray = message.split(" ");
message = processClientChatCommand(message);
if (messageArray.length > 1 && "me".equals(messageArray[0])) {
message = message.substring(3);
twitch.sendEmote(message, true);
} else {
twitch.sendMessage(message, true);
}
return "::";
}
line = processClientChatCommand(line);
processClientCommand(line);
return line;
}
// TODO: Use processClientChatCommand instead of this method
public static String processPrivateCommand(String line) {
return processClientChatCommand(line);
}
/**
* Parses a chat message sent by the user for client related commands.
*
* @param line a chat message sent by the user
* @return a modified chat message
*/
private static String processClientCommand(String line) {
if (line.startsWith("::")) {
String[] commandArray = line.substring(2, line.length()).toLowerCase().split(" ");
switch (commandArray[0]) {
case "togglebypassattack":
Settings.toggleAttackAlwaysLeftClick();
break;
case "toggleroofs":
Settings.toggleHideRoofs();
break;
case "togglecombat":
Settings.toggleCombatMenuShown();
break;
case "togglecolor":
Settings.toggleColorTerminal();
break;
case "togglehitbox":
Settings.toggleShowHitbox();
break;
case "togglefatigue":
Settings.toggleFatigueAlert();
break;
case "toggletwitch":
Settings.toggleTwitchHide();
break;
case "toggleplayerinfo":
Settings.toggleShowPlayerNameOverlay();
break;
case "togglefriendinfo":
Settings.toggleShowFriendNameOverlay();
break;
case "togglenpcinfo":
Settings.toggleShowNPCNameOverlay();
break;
case "toggleidsinfo":
Settings.toggleExtendIdsOverlay();
break;
case "toggleiteminfo":
Settings.toggleShowItemGroundOverlay();
break;
case "togglelogindetails":
Settings.toggleShowLoginIpAddress();
break;
case "togglestartsearchedbank":
if (commandArray.length > 1) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i < commandArray.length; i++) {
if (commandArray[i].trim().equals("")) continue;
sb.append(commandArray[i].trim().toLowerCase());
if (i < commandArray.length - 1) sb.append(" ");
}
Settings.toggleStartSearchedBank(sb.toString(), true);
} else {
Settings.toggleStartSearchedBank("", false);
}
break;
case "banksearch":
// enters searchable bank mode, to return normal mode player has to speak to the banker
// again
if (commandArray.length > 1) {
Bank.search(commandArray, false);
} else {
Bank.search(commandArray, true);
}
break;
case "sleep":
Client.sleep();
break;
case "screenshot":
Renderer.takeScreenshot(false);
break;
case "debug":
Settings.toggleDebug();
break;
case "togglexpdrops":
Settings.toggleXpDrops();
break;
case "togglefatiguedrops":
Settings.toggleFatigueDrops();
break;
case "fov":
if (commandArray.length > 1) {
Settings.setClientFoV(commandArray[1]);
}
break;
case "logout":
Client.logout();
break;
case "toggleposition":
Settings.togglePosition();
break;
case "toggleretrofps":
Settings.toggleRetroFPS();
break;
case "toggleinvcount":
Settings.toggleInvCount();
break;
case "togglebuffs":
Settings.toggleBuffs();
break;
case "togglestatusdisplay":
Settings.toggleHpPrayerFatigueOverlay();
break;
case "help":
try {
Help.help(Integer.parseInt(commandArray[2]), commandArray[1]);
} catch (Exception e) {
Help.help(0, "help");
}
break;
default:
if (commandArray[0] != null) {
return "::";
}
break;
}
}
return line;
}
/**
* Parses a chat message sent by the user for chat related commands.
*
* @param line a chat message sent by the user
* @return a modified chat message
*/
private static String processClientChatCommand(String line) {
if (line.startsWith("::")) {
String command = line.substring(2, line.length()).toLowerCase();
if ("total".equals(command)) {
return "My Total Level is " + getTotalLevel() + " (" + getTotalXP() + " xp).";
} else if ("fatigue".equals(command)) {
return "My Fatigue is at " + currentFatigue + "%.";
} else if ("cmb".equals(command)) {
// this command breaks character limits and might be bannable... would not recommend sending
// this
// command over PM to rs2/rs3
return "@whi@My Combat is Level "
+ "@gre@"
+
// basic melee stats
((base_level[SKILL_ATTACK]
+ base_level[SKILL_STRENGTH]
+ base_level[SKILL_DEFENSE]
+ base_level[SKILL_HP])
* 0.25
// add ranged levels if ranger
+ ((base_level[SKILL_ATTACK] + base_level[SKILL_STRENGTH])
< base_level[SKILL_RANGED] * 1.5
? base_level[SKILL_RANGED] * 0.25
: 0)
// prayer and mage