-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMain.java
More file actions
1525 lines (1356 loc) · 49.8 KB
/
Main.java
File metadata and controls
1525 lines (1356 loc) · 49.8 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
package bot;
import static org.reflections.scanners.Scanners.Resources;
import static org.reflections.scanners.Scanners.SubTypes;
import static org.reflections.util.ClasspathHelper.forJavaClassPath;
import bot.cli.CLIParser;
import bot.cli.ParseResult;
import bot.debugger.Debugger;
import callbacks.DrawCallback;
import callbacks.SleepCallback;
import compatibility.apos.Script;
import controller.Controller;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.AbstractMap.SimpleEntry;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableRowSorter;
import listeners.LoginListener;
import listeners.WindowListener;
import org.apache.commons.cli.ParseException;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;
import orsc.OpenRSC;
import orsc.mudclient;
import reflector.Reflector;
import scripting.idlescript.IdleScript;
import utils.Extractor;
import utils.Version;
/**
* This is the starting class of the entire IdleRSC project.
*
* @author Dvorak
*/
public class Main {
public static Config config = new Config();
private static final Reflections reflections =
new Reflections(
new ConfigurationBuilder()
.setScanners(SubTypes, Resources)
.addUrls(forJavaClassPath())
.filterInputsBy(new FilterBuilder()));
private static final Map<String, List<Class<?>>> scripts =
Stream.of(
new SimpleEntry<>("Native", reflections.getSubTypesOf(IdleScript.class)),
new SimpleEntry<>("APOS", reflections.getSubTypesOf(compatibility.apos.Script.class)),
new SimpleEntry<>("SBot", reflections.getSubTypesOf(compatibility.sbot.Script.class)))
.collect(Collectors.toMap(SimpleEntry::getKey, e -> new ArrayList<>(e.getValue())));
// this is tied to the start/stop button on the side panel.
private static Color themeTextColor = new java.awt.Color(219, 219, 219, 255);
private static Color themeBackColor = new java.awt.Color(40, 40, 40, 255);
private static boolean isRunning = false;
private static String username = "";
private static String themeName = "RuneDark Theme";
private static JMenuBar menuBar;
private static JMenu themeMenu, settingsMenu;
private static JFrame scriptFrame;
private static JFrame rscFrame; // main window frame
private static JButton startStopButton, buttonClear;
private static JCheckBox autoLoginCheckbox,
logWindowCheckbox,
debugCheckbox,
graphicsCheckbox,
render3DCheckbox,
botPaintCheckbox,
interlaceCheckbox,
autoscrollLogsCheckbox,
sidebarCheckbox,
customUiMode,
keepInvOpen,
gfxCheckbox; // all the checkboxes on the sidepanel.
private static JButton loadScriptButton,
pathwalkerButton,
takeScreenshotButton,
showIdButton,
openDebuggerButton,
resetXpButton;
private static JTextArea logArea; // self explanatory
private static JScrollPane scroller; // this is the main window for the log.
private static Debugger debugger = null;
private static Thread loginListener = null; // see LoginListener.java
private static final Thread positionListener = null; // see PositionListener.java
private static Thread windowListener = null; // see WindowListener.java
private static final Thread messageListener = null; // see MessageListener.java
private static Thread debuggerThread = null;
private static Controller controller =
null; // this is the queen bee that controls the actual bot and is the native
// scripting
// language.
private static Object currentRunningScript =
null; // the object instance of the current running script.
private static boolean shouldFilter = true;
private static boolean aposInitCalled = false;
// themeNames and colorCodes MUST have the same index values
// todo hash map
private static final String[] themeNames = {
"RuneDark Theme",
"2007scape Theme",
"Classic Theme",
"Purple Theme",
"Magenta Theme",
"Red Theme",
"Aquamarine Theme",
"Blue Theme",
"Green Theme",
"Brown Theme",
"Orange Theme",
"Gold Theme"
};
private static final Color[][] colorCodes = { // {background, text color, log color}
{
new java.awt.Color(40, 40, 40, 255), // Runelite Dark Mode
new java.awt.Color(219, 219, 219, 255)
},
{
new java.awt.Color(194, 177, 144, 255), // 2007scape Theme
new java.awt.Color(10, 10, 8, 255)
},
{
new java.awt.Color(91, 100, 128, 255), // Classic Theme
new java.awt.Color(0, 0, 0, 255)
},
{
new java.awt.Color(41, 21, 72, 255), // Purple Theme
new java.awt.Color(209, 186, 255, 255)
},
{
new java.awt.Color(141, 22, 129, 255), // Magenta Theme
new java.awt.Color(255, 217, 255, 255)
},
{
new java.awt.Color(110, 0, 16, 255), // Red Theme
new java.awt.Color(255, 183, 195, 255)
},
{
new java.awt.Color(11, 143, 137, 255), // Aquamarine Theme
new java.awt.Color(210, 255, 255, 255)
},
{
new java.awt.Color(22, 65, 182, 255), // Blue Theme
new java.awt.Color(191, 208, 255, 255)
},
{
new java.awt.Color(9, 94, 0, 255), // Green Theme
new java.awt.Color(195, 255, 187, 255)
},
{
new java.awt.Color(73, 48, 48, 255), // Brown Theme
new java.awt.Color(234, 202, 202, 255)
},
{
new java.awt.Color(159, 58, 0, 255), // Orange Theme
new java.awt.Color(255, 202, 188, 255)
},
{
new java.awt.Color(141, 113, 22, 255), // Gold Theme
new java.awt.Color(255, 254, 200, 255)
}
};
public static Color getThemeTextColor() {
return themeTextColor;
}
public static void setThemeTextColor(Color textColor) {
themeTextColor = textColor;
}
public static Color getThemeBackColor() {
return themeBackColor;
}
public static void setThemeBackColor(Color backColor) {
themeBackColor = backColor;
}
public static Color getColorCode(int x, int y) {
return colorCodes[x][y];
}
/**
* Set the Color elements for the Theme name entered Changes themeColorBack and themeTextColor
*
* @param theme String -- name of the "Theme"
*/
public static void setThemeElements(String theme) {
for (int i = 0; i < themeNames.length; i++) {
if (themeNames[i].equalsIgnoreCase(theme)) {
themeBackColor = colorCodes[i][0];
themeTextColor = colorCodes[i][1];
return;
}
}
}
/**
* Method to get the point to place Frame components at to center in rscFrame (client window) <br>
* * Note the actual point returned is actually to the top left of true center.
*
* @return Point location to center Frame components at
*/
public static Point getRscFrameCenter() {
Point topLeft = Main.rscFrame.getLocationOnScreen();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
return new Point(
Math.max(
0,
Math.min(
(int) screenSize.getWidth() - 655,
topLeft.x + (rscFrame.getWidth() / 2) - (scriptFrame.getWidth() / 2))),
Math.max(
0,
Math.min(
(int) screenSize.getHeight() - 405,
topLeft.y + (rscFrame.getHeight() / 2) - (scriptFrame.getHeight() / 2))));
}
/**
* Get the Color[] for the Theme name entered
*
* @param theme String -- name of the "Theme"
* @return Color[] -- with values [back, front]
*/
public static Color[] getThemeElements(String theme) {
for (int i = 0; i < themeNames.length; i++) {
if (themeNames[i].equalsIgnoreCase(theme)) {
return colorCodes[i];
}
}
return new Color[] {Color.BLACK, Color.WHITE};
}
public static Object getCurrentRunningScript() {
return currentRunningScript;
}
/** The initial program entrypoint for IdleRSC. */
public static void main(String[] args)
throws MalformedURLException, ClassNotFoundException, NoSuchMethodException,
SecurityException, InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, InterruptedException {
CLIParser parser = new CLIParser();
Version version = new Version();
ParseResult parseResult = new ParseResult();
parseResult = parseArgs(parseResult, parser, args);
if (parseResult.getUsername().equalsIgnoreCase("username") || parseResult.isUsingAccount()) {
new EntryFrame(parseResult);
parseResult = parseArgs(parseResult, parser, args);
}
setThemeElements(themeName);
if (parseResult.isHelp()) {
parser.printHelp();
}
if (parseResult.isVersion()) {
System.out.println(
"IdleRSC version "
+ version.getCommitDate()
+ "-"
+ version.getCommitCount()
+ "-"
+ version.getCommitHash());
System.out.println("Built with JDK " + version.getBuildJDK());
}
config.absorb(parseResult);
handleCache(config);
Reflector reflector = new Reflector(); // start up our reflector helper
OpenRSC client = reflector.createClient(); // start up our client jar
mudclient mud = reflector.getMud(client); // grab the mud from the client
controller = new Controller(reflector, client, mud); // start up our controller
debugger = new Debugger(reflector, client, mud, controller);
debuggerThread = new Thread(debugger);
debuggerThread.start();
if (!checkAssetFiles()) createAssetFiles();
SleepCallback.setOCRType(config.getOCRType());
// just building out the windows
JPanel botFrame = new JPanel();
themeMenu = new JMenu();
JPanel consoleFrame = new JPanel(); // log window
rscFrame = (JFrame) reflector.getClassMember("orsc.OpenRSC", "jframe");
if (config.getPositionX() == -1 || config.getPositionY() == -1) {
rscFrame.setLocationRelativeTo(null);
} else rscFrame.setLocation(config.getPositionX(), config.getPositionY());
if (controller.getPlayerName() != null) {
scriptFrame = new JFrame(controller.getPlayerName() + "'s Script Selector");
} else if (config.getUsername() != null && !config.getUsername().equalsIgnoreCase("username")) {
scriptFrame = new JFrame(config.getUsername() + "'s Script Selector");
} else {
scriptFrame = new JFrame("Script Selector");
}
initializeBotFrame(botFrame);
initializeConsoleFrame(consoleFrame);
initializeScriptFrame(scriptFrame);
initializeMenuBar();
JButton[] buttonArray = {
startStopButton,
loadScriptButton,
pathwalkerButton,
takeScreenshotButton,
showIdButton,
openDebuggerButton,
resetXpButton
};
JCheckBox[] checkBoxArray = {
autoLoginCheckbox,
logWindowCheckbox,
debugCheckbox,
graphicsCheckbox,
render3DCheckbox,
botPaintCheckbox,
interlaceCheckbox,
sidebarCheckbox,
gfxCheckbox
};
Dimension buttonSize = new Dimension(125, 25);
// todo swap side bar by swapping container contents
for (JCheckBox jCheckbox : checkBoxArray) {
jCheckbox.setBackground(themeBackColor);
jCheckbox.setForeground(themeTextColor);
jCheckbox.setFocusable(false);
}
for (JButton jButton : buttonArray) {
jButton.setBackground(themeBackColor.darker());
jButton.setForeground(themeTextColor);
jButton.setFocusable(false);
jButton.setMaximumSize(buttonSize);
jButton.setPreferredSize(buttonSize);
}
botFrame.setBackground(themeBackColor);
rscFrame.getContentPane().setBackground(themeBackColor);
botFrame.setBorder(BorderFactory.createLineBorder(themeBackColor));
// combine everything into our client
rscFrame.add(botFrame, BorderLayout.EAST);
rscFrame.add(menuBar, BorderLayout.NORTH);
rscFrame.add(consoleFrame, BorderLayout.SOUTH);
consoleFrame.setVisible(config.isLogWindowVisible());
botFrame.setVisible(config.isSidebarVisible());
if (config.getUsername() != null) {
log("Starting client for " + config.getUsername());
}
log("IdleRSC initialized.");
// don't do anything until RSC is loaded.
while (!controller.isLoaded()) controller.sleep(1);
// Set Sizes After initilizing for correct sizing
rscFrame.setMinimumSize(new Dimension(533, 405)); // this doesn't seem to be doing anything
rscFrame.setSize(new Dimension(533, 405));
if (config.isLogWindowVisible())
rscFrame.setSize(new Dimension(rscFrame.getWidth(), rscFrame.getHeight() + 188));
if (config.isSidebarVisible())
rscFrame.setSize(new Dimension(rscFrame.getWidth() + 122, rscFrame.getHeight()));
// Set checkboxes on side panel using "get" methods
autoLoginCheckbox.setSelected(config.isAutoLogin());
graphicsCheckbox.setSelected(config.isGraphicsEnabled());
render3DCheckbox.setSelected(config.isRender3DEnabled());
gfxCheckbox.setSelected(config.isGraphicsEnabled());
controller.setDrawing(config.isGraphicsEnabled(), 0);
controller.setRender3D(config.isRender3DEnabled());
logWindowCheckbox.setSelected(config.isLogWindowVisible());
sidebarCheckbox.setSelected(config.isSidebarVisible());
debugCheckbox.setSelected(config.isDebug());
interlaceCheckbox.setSelected(config.isGraphicsInterlacingEnabled());
botPaintCheckbox.setSelected(config.isBotPaintVisible());
customUiMode.setSelected(config.getNewUi());
keepInvOpen.setSelected(config.getKeepOpen());
// Set client properties from checkboxes
if (config.getKeepOpen()) controller.setKeepInventoryOpenMode(keepInvOpen.isSelected());
if (config.isGraphicsInterlacingEnabled())
controller.setInterlacer(config.isGraphicsInterlacingEnabled());
if (config.isScriptSelectorOpen()) showLoadScript();
if (config.isDebug()) debugger.open();
log("Initializing WindowListener...");
windowListener =
new Thread(
new WindowListener(
botFrame,
consoleFrame,
rscFrame,
settingsMenu,
themeMenu,
menuBar,
scroller,
logArea,
controller,
buttonClear,
autoscrollLogsCheckbox,
buttonArray,
checkBoxArray));
windowListener.start();
log("WindowListener started.");
// give everything a nice synchronization break juuuuuuuuuuuuuust in case...
Thread.sleep(1000);
if (autoLoginCheckbox.isSelected()) controller.login();
// start up our listener threads
log("Initializing LoginListener...");
loginListener = new Thread(new LoginListener(controller));
loginListener.start();
log("LoginListener initialized.");
Thread.sleep(1200);
if (config.getScriptName() != null && !config.getScriptName().isEmpty()) {
if (!loadAndRunScript(config.getScriptName())) {
System.out.println("Could not find script: " + config.getScriptName());
} else {
while (!controller.isLoggedIn()) controller.sleep(640);
isRunning = true;
startStopButton.setText("Stop");
}
syncMainMenuButtonsEnabledStatusToBackingState();
}
if (config.getScreenRefresh()) {
DrawCallback.setNextRefresh( // was 25k
System.currentTimeMillis() + 25000L + (long) (Math.random() * 10000));
}
// System.out.println("Next screen refresh at: " +
// DrawCallback.getNextRefresh());
while (true) {
if (isRunning()) {
if (currentRunningScript == null) continue;
// handle native scripts
if (currentRunningScript instanceof IdleScript) {
((IdleScript) currentRunningScript).setController(controller);
int sleepAmount =
((IdleScript) currentRunningScript).start(config.getScriptArguments()) + 1;
Thread.sleep(sleepAmount);
} else if (currentRunningScript instanceof compatibility.sbot.Script) {
controller.displayMessage(
"@red@IdleRSC: Note that SBot scripts are mostly, but not fully compatible.", 3);
controller.displayMessage(
"@red@IdleRSC: If you still experience problems after modifying script please report.",
3);
((compatibility.sbot.Script) currentRunningScript).setController(controller);
String sbotScriptName = config.getScriptName();
((compatibility.sbot.Script) currentRunningScript)
.start(sbotScriptName, config.getScriptArguments());
Thread.sleep(618); // wait 1 tick before performing next action
} else if (currentRunningScript instanceof compatibility.apos.Script) {
if (!controller.isSleeping()) {
StringBuilder params = new StringBuilder();
if (config.getScriptArguments() != null) {
for (int i = 0; i < config.getScriptArguments().length; i++) {
String arg = config.getScriptArguments()[i];
if (i == 0) params = new StringBuilder(arg);
else params.append(" ").append(arg);
}
}
if (!aposInitCalled) {
Script.setController(controller);
((compatibility.apos.Script) currentRunningScript).init(params.toString());
aposInitCalled = true;
}
int sleepAmount = ((compatibility.apos.Script) currentRunningScript).main() + 1;
Thread.sleep(sleepAmount);
} else {
Thread.sleep(10);
}
}
} else {
if (controller.getNeedToMove() && controller.isLoggedIn() && controller.isAutoLogin()) {
controller.moveCharacter();
}
aposInitCalled = false;
Thread.sleep(100);
}
}
}
public static ParseResult parseArgs(ParseResult parseResult, CLIParser parser, String[] args)
throws InterruptedException {
try {
parseResult = parser.parse(args);
} catch (ParseException e) {
System.err.println(e.getMessage() + "\n");
parser.printHelp();
System.out.println("Closing Bot in 5 minute...");
Thread.sleep(340000);
System.exit(1);
}
return parseResult;
}
/** Clears the log window. */
public static void clearLog() {
logArea.setText("");
}
/**
* Add a line to the log window.
*
* @param text
*/
public static void log(String text) {
System.out.println(text);
if (logArea == null) {
return; // messages will still add text if element isVisible is false.
}
logArea.append(text + "\n");
if (autoscrollLogsCheckbox.isSelected()) {
logArea.setCaretPosition(logArea.getDocument().getLength());
}
}
/**
* For logging function calls in an easy manner.
*
* @param method -- the method called.
* @param params -- the object(s) which were sent to the function. You may put in any object.
*/
public static void logMethod(String method, Object... params) {
if (isDebug()) {
StringBuilder current = new StringBuilder(method + "(");
if (params != null && params.length > 0) {
for (Object o : params) {
current.append(o.toString()).append(", ");
}
current = new StringBuilder(current.substring(0, current.length() - 2));
}
current.append(")");
log(current.toString());
}
}
private static void initializeMenuBar() {
int[] keyEvents = {
KeyEvent.VK_1,
KeyEvent.VK_2,
KeyEvent.VK_3,
KeyEvent.VK_4,
KeyEvent.VK_5,
KeyEvent.VK_6,
KeyEvent.VK_7,
KeyEvent.VK_8,
KeyEvent.VK_9,
KeyEvent.VK_0,
KeyEvent.VK_F1,
KeyEvent.VK_F2,
KeyEvent.VK_F3,
KeyEvent.VK_F5,
};
// Make the menu bar
menuBar = new JMenuBar();
settingsMenu = new JMenu("Settings");
themeMenu = new JMenu("Theme Menu");
gfxCheckbox = new JCheckBox("GFX");
logWindowCheckbox = new JCheckBox("Console");
sidebarCheckbox = new JCheckBox("Sidebar");
// add our elements to the main bar
menuBar.add(settingsMenu);
menuBar.add(themeMenu);
menuBar.add(Box.createHorizontalGlue()); // from right
menuBar.add(gfxCheckbox);
menuBar.add(logWindowCheckbox);
menuBar.add(sidebarCheckbox);
// style our elements
settingsMenu.setBackground(themeBackColor);
settingsMenu.setBorder(BorderFactory.createLineBorder(themeBackColor));
settingsMenu.setForeground(themeTextColor);
themeMenu.setForeground(themeTextColor);
menuBar.setBackground(themeBackColor);
menuBar.setBorder(BorderFactory.createLineBorder(themeBackColor));
gfxCheckbox.addActionListener(
e -> {
if (controller != null) {
graphicsCheckbox.setSelected(gfxCheckbox.isSelected());
controller.setDrawing(gfxCheckbox.isSelected(), 0);
if (gfxCheckbox.isSelected()) {
DrawCallback.setNextRefresh(-1);
} else if (gfxCheckbox.isSelected() && config.getScreenRefresh()) {
DrawCallback.setNextRefresh(
(System.currentTimeMillis() + 25000L + (long) (Math.random() * 10000)));
}
}
});
// Build Theme Menu
JMenuItem menuItem;
for (int i = 0; i < themeNames.length; i++) {
menuItem = new JMenuItem(themeNames[i], keyEvents[i]);
menuItem.setAccelerator(KeyStroke.getKeyStroke((char) keyEvents[i]));
int finalI = i;
menuItem.addActionListener(
e -> {
themeName = themeNames[finalI];
});
themeMenu.add(menuItem);
}
JMenuItem _accOpp;
// Define settings menu drop down
Component[] _settingsMenu = {
_accOpp = new JMenuItem("Account Startup Settings", KeyEvent.VK_F4), // S key
customUiMode = new JCheckBox("Custom In-game UI"),
keepInvOpen = new JCheckBox("Keep Inventory Open"),
};
// Add elements to settings menu
for (Component _menuItem : _settingsMenu) {
settingsMenu.add(_menuItem);
}
// prevent tab/etc "focusing" an element
menuBar.setFocusable(false);
themeMenu.setFocusable(false);
gfxCheckbox.setFocusable(false);
logWindowCheckbox.setFocusable(false);
sidebarCheckbox.setFocusable(false);
customUiMode.setFocusable(false);
keepInvOpen.setFocusable(false);
// menuItem.setAccelerator(KeyStroke.getKeyStroke((char) KeyEvent.VK_F4));
// //opens 2 authframes
_accOpp.addActionListener(
e -> {
AuthFrame authFrame =
new AuthFrame("Editing the account - " + config.getUsername(), null, null);
authFrame.setLoadSettings(true);
authFrame.addActionListener(
e1 -> { // ALWAYS make properties lowercase
username = authFrame.getUsername();
controller.log("IdleRSC: " + username + " account settings saved");
authFrame.storeAuthData(authFrame);
authFrame.setVisible(false);
});
settingsMenu.setPopupMenuVisible(false);
authFrame.setVisible(true);
});
customUiMode.addActionListener(
e -> {
settingsMenu.setPopupMenuVisible(false);
controller.setCustomUiMode(customUiMode.isSelected());
});
keepInvOpen.addActionListener(
e -> {
settingsMenu.setPopupMenuVisible(false);
controller.setKeepInventoryOpenMode(keepInvOpen.isSelected());
});
}
/**
* Sets up the sidepanel
*
* @param botFrame -- the sidepanel frame
*/
private static void initializeBotFrame(JComponent botFrame) {
botFrame.setLayout(new BoxLayout(botFrame, BoxLayout.Y_AXIS));
startStopButton = new JButton(isRunning ? "Stop" : "Start");
startStopButton.setEnabled(currentRunningScript != null);
autoLoginCheckbox = new JCheckBox("Auto-Login");
debugCheckbox = new JCheckBox("Debug Messages");
graphicsCheckbox = new JCheckBox("Show Graphics");
render3DCheckbox = new JCheckBox("Render 3D");
botPaintCheckbox = new JCheckBox("Show Bot Paint");
interlaceCheckbox = new JCheckBox("Interlace");
loadScriptButton = new JButton("Load Script");
pathwalkerButton = new JButton("PathWalker");
// all the buttons on the sidepanel.
takeScreenshotButton = new JButton("Screenshot");
showIdButton = new JButton("Show IDs");
openDebuggerButton = new JButton("Debugger");
resetXpButton = new JButton("Reset XP");
startStopButton.addActionListener(
e -> {
if (currentRunningScript == null) {
return;
}
isRunning = !isRunning;
if (isRunning) {
startStopButton.setText("Stop");
} else {
startStopButton.setText("Start");
}
syncMainMenuButtonsEnabledStatusToBackingState();
});
loadScriptButton.addActionListener(e -> showLoadScript());
pathwalkerButton.addActionListener(
e -> {
if (!isRunning) {
loadAndRunScript("PathWalker");
config.setScriptArguments(new String[] {""});
isRunning = true;
startStopButton.setText("Stop");
} else {
JOptionPane.showMessageDialog(null, "Stop the current script first.");
}
syncMainMenuButtonsEnabledStatusToBackingState();
});
openDebuggerButton.addActionListener(
e -> {
controller.log("IdleRSC: Opening Debug Window", "gre");
debugger.open();
});
resetXpButton.addActionListener(e -> DrawCallback.resetXpCounter());
showIdButton.addActionListener(e -> controller.toggleViewId());
takeScreenshotButton.addActionListener(e -> controller.takeScreenshot(""));
autoLoginCheckbox.addActionListener(
e -> {
if (autoLoginCheckbox.isSelected()) controller.login();
});
graphicsCheckbox.addActionListener(
e -> {
if (controller != null) {
gfxCheckbox.setSelected(graphicsCheckbox.isSelected());
controller.setDrawing(graphicsCheckbox.isSelected(), 0);
if (graphicsCheckbox.isSelected()) {
DrawCallback.setNextRefresh(-1);
} else if (graphicsCheckbox.isSelected() && config.getScreenRefresh()) {
DrawCallback.setNextRefresh(
(System.currentTimeMillis() + 25000L + (long) (Math.random() * 10000)));
}
}
});
render3DCheckbox.addActionListener(
e -> {
if (controller != null) {
controller.setRender3D(render3DCheckbox.isSelected());
}
});
botPaintCheckbox.addActionListener(
e -> {
if (controller != null) {
controller.setBotPaint(botPaintCheckbox.isSelected());
}
});
interlaceCheckbox.addActionListener(
e -> {
if (controller != null) {
controller.setInterlacer(interlaceCheckbox.isSelected());
}
});
Dimension buttonSize = new Dimension(125, 25);
botFrame.add(startStopButton);
botFrame.add(loadScriptButton);
botFrame.add(pathwalkerButton);
botFrame.add(autoLoginCheckbox);
botFrame.add(debugCheckbox);
botFrame.add(interlaceCheckbox);
botFrame.add(botPaintCheckbox);
botFrame.add(render3DCheckbox);
botFrame.add(graphicsCheckbox);
botFrame.add(takeScreenshotButton);
botFrame.add(showIdButton);
botFrame.add(openDebuggerButton);
botFrame.add(resetXpButton);
botFrame.setSize(buttonSize.width, botFrame.getHeight());
}
/**
* Sets up the log window
*
* @param consoleFrame -- the log window frame
*/
private static void initializeConsoleFrame(JPanel consoleFrame) {
buttonClear = new JButton("Clear");
autoscrollLogsCheckbox = new JCheckBox("Lock scroll to bottom", true);
logArea = new JTextArea(9, 44);
logArea.setEditable(false);
scroller = new JScrollPane(logArea);
buttonClear.setBackground(themeBackColor.darker());
buttonClear.setForeground(themeTextColor);
autoscrollLogsCheckbox.setBackground(themeBackColor);
autoscrollLogsCheckbox.setForeground(themeTextColor);
logArea.setBackground(themeBackColor.brighter());
logArea.setForeground(themeTextColor);
scroller.setBackground(themeBackColor);
scroller.setForeground(themeTextColor);
consoleFrame.setBackground(themeBackColor);
consoleFrame.setForeground(themeTextColor);
consoleFrame.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridy = 1;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.anchor = GridBagConstraints.SOUTHEAST;
constraints.gridx = 2;
constraints.weightx = 0.5;
consoleFrame.add(autoscrollLogsCheckbox, constraints);
constraints.gridy = 1;
constraints.insets = new Insets(0, 5, 5, 5);
constraints.anchor = GridBagConstraints.SOUTHWEST;
constraints.gridx = 1;
constraints.weightx = 0.5;
consoleFrame.add(buttonClear, constraints);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 4;
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.NORTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
consoleFrame.add(new JScrollPane(logArea), constraints);
buttonClear.addActionListener(evt -> clearLog());
// consoleFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
consoleFrame.setSize(480, 320);
}
/**
* This function will go ahead and find the location of the `scriptName` and try to load the class
* file.
*
* @param scriptName -- the name of the script (without .class at the end.)
* @return boolean -- whether or not the script was successfully loaded.
*/
private static boolean loadAndRunScript(String scriptName) {
try {
currentRunningScript =
scripts.values().stream()
.flatMap(List::stream)
.filter(c -> c.getSimpleName().equalsIgnoreCase(scriptName))
.findFirst()
.map(
clazz -> {
try {
return clazz.getSuperclass().equals(compatibility.apos.Script.class)
? clazz.getDeclaredConstructor(String.class).newInstance("")
: clazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException
| IllegalAccessException
| NoSuchMethodException
| InvocationTargetException e) {
e.printStackTrace();
return null;
}
})
.orElse(null);
if (currentRunningScript == null) {
return false;
}
Main.config.setScriptName(scriptName);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* Initializes the script menu selector.
*
* @param scriptFrame -- the script menu selector frame.
*/
private static void initializeScriptFrame(JFrame scriptFrame) {
String[] columnNames = {"Name", "Type"};
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);
scripts.forEach(
(type, classes) ->
classes.stream()
.sorted(Comparator.comparing(Class::getSimpleName))
.forEach(clazz -> tableModel.addRow(new String[] {clazz.getSimpleName(), type})));
// Setup table
final JTable scriptTable =
new JTable(tableModel) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
JTableHeader header = scriptTable.getTableHeader();
header.setDefaultRenderer(
new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
JLabel label =
(JLabel)
super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
label.setBorder(
BorderFactory.createMatteBorder(
0, 0, 0, column == 0 ? 1 : 0, UIManager.getColor("controlDkShadow")));
label.setFont(header.getFont().deriveFont(Font.BOLD, 15f));
label.setHorizontalAlignment(SwingConstants.CENTER);
return label;
}
});
;
scriptTable.setSelectionMode(
ListSelectionModel.SINGLE_SELECTION); // Only allow single row selected at a time
scriptTable.setAutoCreateRowSorter(true); // Automatically create a table row sorter
header.setReorderingAllowed(false); // Disable reordering columns
header.setResizingAllowed(false); // Disable resizing columns
final JScrollPane scriptScroller = new JScrollPane(scriptTable);
// Setup script args field
final String scriptArgsPlaceholder = "Script args (ex: arg1 arg2 arg3 ...)";
final JTextField scriptArgs = new JTextField(scriptArgsPlaceholder);
scriptArgs.setForeground(Color.GRAY);
scriptArgs.addFocusListener(
getPlaceholderFocusListener(scriptArgs, scriptArgsPlaceholder, false));
// Setup filter field
final String scriptFilterPlaceholder = "Filter";
final JTextField scriptFilter = new JTextField(scriptFilterPlaceholder);
scriptFilter.setForeground(Color.GRAY);
scriptFilter.addFocusListener(
getPlaceholderFocusListener(scriptFilter, scriptFilterPlaceholder, true));
scriptFilter
.getDocument()
.addDocumentListener(
new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
filter();