From 90747a61f8ec78d8b2e435cc2e463645feeda2fb Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 01/16] Remove static blocks initializing write-only String arrays These arrays are only written to, never read. This looks like a performance optimization to avoid string allocation at run-time as these arrays are otherwise unused. These kinds of optimizations are not needed on modern hardware, they just make the code structure more complicated. --- .../java/agolf/game/GameBackgroundCanvas.java | 13 -------- .../main/java/com/aapeli/bigtext/BigText.java | 4 --- .../java/com/aapeli/client/BadWordFilter.java | 8 ----- .../main/java/com/aapeli/client/Class79.java | 7 ----- .../main/java/com/aapeli/client/Class80.java | 7 ----- .../main/java/com/aapeli/client/Class81.java | 20 ------------- .../main/java/com/aapeli/client/Class88.java | 13 -------- .../main/java/com/aapeli/client/Class89.java | 7 ----- .../main/java/com/aapeli/client/HtmlText.java | 10 ------- .../java/com/aapeli/client/IPanel_Sub40.java | 13 -------- .../java/com/aapeli/client/ImageTracker.java | 9 ------ .../java/com/aapeli/client/Panel_Sub24.java | 19 ------------ .../java/com/aapeli/colorgui/ColorButton.java | 4 --- .../com/aapeli/colorgui/ColorTextArea.java | 4 --- .../java/com/aapeli/multiuser/ChatBase.java | 11 ------- .../java/com/aapeli/multiuser/ChatLobby.java | 19 ------------ .../com/aapeli/multiuser/ChatTextArea.java | 13 -------- .../java/com/aapeli/multiuser/UserList.java | 30 ------------------- 18 files changed, 211 deletions(-) diff --git a/client/src/main/java/agolf/game/GameBackgroundCanvas.java b/client/src/main/java/agolf/game/GameBackgroundCanvas.java index 1edf7821..dfcca401 100644 --- a/client/src/main/java/agolf/game/GameBackgroundCanvas.java +++ b/client/src/main/java/agolf/game/GameBackgroundCanvas.java @@ -33,8 +33,6 @@ public class GameBackgroundCanvas extends Canvas { private int[][] anIntArrayArray97; private boolean[] aBooleanArray98; public static int anInt99; - private static final String[] aStringArray100 = new String[11]; - protected GameBackgroundCanvas(GameContainer gameContainer, Image backgroundImage) { this.gameContainer = gameContainer; @@ -735,17 +733,6 @@ private int method129(int var1, int var2, double var3) { } static { - aStringArray100[0] = "A "; - aStringArray100[1] = "T "; - aStringArray100[2] = "S "; - aStringArray100[3] = "R "; - aStringArray100[4] = "Ads:"; - aStringArray100[5] = "I "; - aStringArray100[6] = "L "; - aStringArray100[7] = "N "; - aStringArray100[8] = "B "; - aStringArray100[9] = "C "; - aStringArray100[10] = "V "; aColor75 = new Color(240, 240, 255); anIntArray78 = new int[]{3, 5, 8, 49}; anIntArray79 = new int[]{2, 3, 5, 25}; diff --git a/client/src/main/java/com/aapeli/bigtext/BigText.java b/client/src/main/java/com/aapeli/bigtext/BigText.java index 5daa7c4c..472fe843 100644 --- a/client/src/main/java/com/aapeli/bigtext/BigText.java +++ b/client/src/main/java/com/aapeli/bigtext/BigText.java @@ -33,8 +33,6 @@ public class BigText { private int anInt1323; private int anInt1324; public static boolean aBoolean1325; - private static final String[] aStringArray1326 = new String[2]; - public static void initialize(ImageManager var0) { anImageManager1316 = var0; @@ -279,8 +277,6 @@ private void method1558(int var1, Component var2) { } static { - aStringArray1326[0] = "bigtext.gif"; - aStringArray1326[1] = "Dialog"; aColor1312 = Color.white; anIntArray1314 = new int[]{0, 23, 47, 71, 95, 116, 136, 160, 183, 195, 219, 243, 264, 299, 323, 347, 370, 394, 418, 442, 465, 489, 513, 542, 566, 590, 614, 637, 661, 685, 700, 714, 736, 756, 777, 798, 819, 839, 859, 881, 901, 913, 924, 949, 972, 1002, 1027, 1051, 1071, 1097, 1126, 1149, 1172, 1186, 1200, 1225, 1246, 1270, 1281, 1303, 1328, 1339, 1354, 1378, 1402}; anInt1315 = anIntArray1314.length; diff --git a/client/src/main/java/com/aapeli/client/BadWordFilter.java b/client/src/main/java/com/aapeli/client/BadWordFilter.java index a2d06e52..89f41076 100644 --- a/client/src/main/java/com/aapeli/client/BadWordFilter.java +++ b/client/src/main/java/com/aapeli/client/BadWordFilter.java @@ -19,7 +19,6 @@ public final class BadWordFilter { private String[] aStringArray1344; private String[] aStringArray1345; private char[] aCharArray1346; - private static final String[] aStringArray1347 = new String[7]; public BadWordFilter(TextManager var1) { @@ -309,13 +308,6 @@ private char method1575() { } static { - aStringArray1347[0] = "BadWords"; - aStringArray1347[1] = "GoodWords"; - aStringArray1347[2] = "fi"; - aStringArray1347[3] = "BadNicks"; - aStringArray1347[4] = "bdgw"; - aStringArray1347[5] = "ptkv"; - aStringArray1347[6] = "CurseChars"; aStringArray1339 = new String[25]; aStringArray1339[0] = "|<"; aStringArray1339[1] = "<>"; diff --git a/client/src/main/java/com/aapeli/client/Class79.java b/client/src/main/java/com/aapeli/client/Class79.java index 8d4e3f94..e15d1a42 100644 --- a/client/src/main/java/com/aapeli/client/Class79.java +++ b/client/src/main/java/com/aapeli/client/Class79.java @@ -15,7 +15,6 @@ class Class79 { private int anInt1369; private int anInt1370; private final HtmlText aHtmlText1371; - private static final String[] aStringArray1372 = new String[3]; protected Class79(HtmlText var1, Graphics var2, int var3, boolean var4) { @@ -85,10 +84,4 @@ protected void method1608(Graphics var1, int var2, int var3) { } } - - static { - aStringArray1372[0] = " \'height\'="; - aStringArray1372[1] = "\'relatx\'="; - aStringArray1372[2] = "[HtmlLine: words.size="; - } } diff --git a/client/src/main/java/com/aapeli/client/Class80.java b/client/src/main/java/com/aapeli/client/Class80.java index 57e56c85..7b5588ed 100644 --- a/client/src/main/java/com/aapeli/client/Class80.java +++ b/client/src/main/java/com/aapeli/client/Class80.java @@ -12,7 +12,6 @@ class Class80 { private int anInt1375; private int anInt1376; private final Class79 aClass79_1377; - private static final String[] aStringArray1378 = new String[3]; protected Class80(Class79 var1, String var2, Font var3, int var4, int var5) { @@ -35,10 +34,4 @@ protected void method1610(Graphics var1, int var2, int var3) { var1.setFont(this.aFont1374); var1.drawString(this.aString1373, var2 + this.anInt1375, var3); } - - static { - aStringArray1378[0] = "\" \'relx\'="; - aStringArray1378[1] = "\" \'font\'=\""; - aStringArray1378[2] = "[HtmlWord: \'word\'=\""; - } } diff --git a/client/src/main/java/com/aapeli/client/Class81.java b/client/src/main/java/com/aapeli/client/Class81.java index c200b94b..fc3660db 100644 --- a/client/src/main/java/com/aapeli/client/Class81.java +++ b/client/src/main/java/com/aapeli/client/Class81.java @@ -10,8 +10,6 @@ class Class81 { private String aString1379; private Graphics aGraphics1380; private final HtmlText aHtmlText1381; - private static final String[] aStringArray1382 = new String[15]; - protected Class81(HtmlText var1, String var2, Graphics var3) { this.aHtmlText1381 = var1; @@ -111,22 +109,4 @@ private boolean method1617(String[] var1) { return false; } - - static { - aStringArray1382[0] = "small"; - aStringArray1382[1] = "br/"; - aStringArray1382[2] = "/small"; - aStringArray1382[3] = ""; - aStringArray1382[4] = "/strong"; - aStringArray1382[5] = "br /"; - aStringArray1382[6] = "strong"; - aStringArray1382[7] = "/big"; - aStringArray1382[8] = "/b"; - aStringArray1382[9] = "center"; - aStringArray1382[10] = "
"; - aStringArray1382[11] = "
"; - aStringArray1382[12] = "br"; - aStringArray1382[13] = "/center"; - aStringArray1382[14] = "big"; - } } diff --git a/client/src/main/java/com/aapeli/client/Class88.java b/client/src/main/java/com/aapeli/client/Class88.java index baa88ce7..b9e7af4d 100644 --- a/client/src/main/java/com/aapeli/client/Class88.java +++ b/client/src/main/java/com/aapeli/client/Class88.java @@ -24,8 +24,6 @@ class Class88 implements ActionListener { private int anInt1506; private int anInt1507; private Frame_Sub3_Sub3 aFrame_Sub3_Sub3_1508; - private static final String[] aStringArray1509 = new String[11]; - protected Class88(Parameters var1, TextManager var2, ImageManager var3) { this.aParameters1500 = var1; @@ -218,17 +216,6 @@ private static String method1708(String var0) { } static { - aStringArray1509[0] = "MD5"; - aStringArray1509[1] = "TellFriend_ExtButton"; - aStringArray1509[2] = "Voi"; - aStringArray1509[3] = "..."; - aStringArray1509[4] = "message="; - aStringArray1509[5] = "session="; - aStringArray1509[6] = "hash="; - aStringArray1509[7] = "emails[]="; - aStringArray1509[8] = "Miksei"; - aStringArray1509[9] = "Aita"; - aStringArray1509[10] = "Perjantai"; aColor1499 = new Color(64, 160, 255); } } diff --git a/client/src/main/java/com/aapeli/client/Class89.java b/client/src/main/java/com/aapeli/client/Class89.java index 94d5cdba..38684132 100644 --- a/client/src/main/java/com/aapeli/client/Class89.java +++ b/client/src/main/java/com/aapeli/client/Class89.java @@ -11,7 +11,6 @@ class Class89 { private String aString1529; private String aString1530; private final TextManager aTextManager1531; - private static final String[] aStringArray1532 = new String[4]; protected Class89(TextManager var1, String var2, XmlUnit var3, boolean var4) { @@ -44,10 +43,4 @@ protected String method1737(int var1) { return this.aString1528; } - static { - aStringArray1532[0] = "plural"; - aStringArray1532[1] = "singular"; - aStringArray1532[2] = "zero"; - aStringArray1532[3] = "fr"; - } } diff --git a/client/src/main/java/com/aapeli/client/HtmlText.java b/client/src/main/java/com/aapeli/client/HtmlText.java index c18060c5..f0170d56 100644 --- a/client/src/main/java/com/aapeli/client/HtmlText.java +++ b/client/src/main/java/com/aapeli/client/HtmlText.java @@ -9,9 +9,6 @@ public class HtmlText { private Vector aVector1348; - private static final String[] aStringArray1349 = new String[4]; - - public HtmlText(Graphics var1, int var2, String var3) { this.aVector1348 = this.method1589(var1, var2, var3); } @@ -88,11 +85,4 @@ private void method1591(Class79 var1, Vector var2) { } } - - static { - aStringArray1349[0] = "
"; - aStringArray1349[1] = "
"; - aStringArray1349[2] = "
"; - aStringArray1349[3] = "[HtmlText: lines.size="; - } } diff --git a/client/src/main/java/com/aapeli/client/IPanel_Sub40.java b/client/src/main/java/com/aapeli/client/IPanel_Sub40.java index 5308a1ba..af803a60 100644 --- a/client/src/main/java/com/aapeli/client/IPanel_Sub40.java +++ b/client/src/main/java/com/aapeli/client/IPanel_Sub40.java @@ -25,7 +25,6 @@ class IPanel_Sub40 extends IPanel implements ActionListener { private RoundButton aRoundButton3215; private RoundButton aRoundButton3216; private RoundButton aRoundButton3217; - private static final String[] aStringArray3218 = new String[12]; protected IPanel_Sub40(AApplet var1, Frame_Sub3_Sub1 var2, int var3, int var4) { @@ -104,18 +103,6 @@ private void method821() { } static { - aStringArray3218[0] = "GameFin_W_GameOver"; - aStringArray3218[1] = "GameFin_R_Congratulations"; - aStringArray3218[2] = "GameFin_R_OK"; - aStringArray3218[3] = "GameFin_W_CreateAccount"; - aStringArray3218[4] = "GameFin_W_Continue"; - aStringArray3218[5] = "RS_PersonalRecord"; - aStringArray3218[6] = "WM_StatsNotSaved"; - aStringArray3218[7] = "RM_FirstRanking"; - aStringArray3218[8] = "GameFin_"; - aStringArray3218[9] = "WS_ScoreNotSaved"; - aStringArray3218[10] = "tf-background.gif"; - aStringArray3218[11] = "Dialog"; aColor3205 = new Color(240, 240, 240); aColor3206 = Color.black; aColor3207 = new Color(128, 255, 128); diff --git a/client/src/main/java/com/aapeli/client/ImageTracker.java b/client/src/main/java/com/aapeli/client/ImageTracker.java index 52bf52ee..930e66e2 100644 --- a/client/src/main/java/com/aapeli/client/ImageTracker.java +++ b/client/src/main/java/com/aapeli/client/ImageTracker.java @@ -22,8 +22,6 @@ class ImageTracker implements Runnable { private AApplet anAApplet1400; private Thread aThread1401; private boolean aBoolean1402; - private static final String[] aStringArray1403 = new String[4]; - protected ImageTracker(Applet var1, boolean var2) { this.anApplet1396 = var1; @@ -304,11 +302,4 @@ private synchronized void method1647(String var1) { } } - - static { - aStringArray1403[0] = "\", moving from \'notloaded\' to \'loaded\'"; - aStringArray1403[1] = "ImageTracker: Loaded image \""; - aStringArray1403[2] = "ImageTracker: Start loading image \""; - aStringArray1403[3] = "ImageTracker: Finished loading image \""; - } } diff --git a/client/src/main/java/com/aapeli/client/Panel_Sub24.java b/client/src/main/java/com/aapeli/client/Panel_Sub24.java index 443f6af3..c5dd97fb 100644 --- a/client/src/main/java/com/aapeli/client/Panel_Sub24.java +++ b/client/src/main/java/com/aapeli/client/Panel_Sub24.java @@ -50,8 +50,6 @@ class Panel_Sub24 extends Panel implements ActionListener, FocusListener { private boolean aBoolean640; private Image anImage641; private Graphics aGraphics642; - private static final String[] aStringArray643 = new String[17]; - protected Panel_Sub24(TextManager var1, ImageManager var2, Class88 var3, Frame_Sub3_Sub3 var4) { this.aTextManager628 = var1; @@ -361,23 +359,6 @@ private boolean method484(String var1) { } static { - aStringArray643[0] = "TellFriend_MessageTitle"; - aStringArray643[1] = "tf-background.gif"; - aStringArray643[2] = "TellFriend_EmailNotSent"; - aStringArray643[3] = "tf-char-sent.gif"; - aStringArray643[4] = "tf-btn-send.gif"; - aStringArray643[5] = "tf-char-error.gif"; - aStringArray643[6] = "TellFriend_EmailSent"; - aStringArray643[7] = "tf-btn-close.gif"; - aStringArray643[8] = "TellFriend_EmailTitle"; - aStringArray643[9] = "TellFriend_Info"; - aStringArray643[10] = "TellFriend_EmailHelp"; - aStringArray643[11] = "TellFriend_ButtonClose"; - aStringArray643[12] = "TellFriend_EmailRemove"; - aStringArray643[13] = "TellFriend_ButtonSend"; - aStringArray643[14] = "TellFriend_EmailAdd"; - aStringArray643[15] = "Serif"; - aStringArray643[16] = "Dialog"; aColor616 = new Color(240, 240, 240); aColor617 = Color.black; aColor618 = new Color(255, 224, 224); diff --git a/client/src/main/java/com/aapeli/colorgui/ColorButton.java b/client/src/main/java/com/aapeli/colorgui/ColorButton.java index b0cd0fef..f9530e92 100644 --- a/client/src/main/java/com/aapeli/colorgui/ColorButton.java +++ b/client/src/main/java/com/aapeli/colorgui/ColorButton.java @@ -58,8 +58,6 @@ public class ColorButton extends IPanel implements MouseMotionListener, MouseLis private Class90 aClass90_3285; private boolean aBoolean3286; public static boolean aBoolean3287; - private static final String[] aStringArray3288 = new String[2]; - public ColorButton() { this((String) null); @@ -578,8 +576,6 @@ public void innerSetFlashState(boolean var1) { } static { - aStringArray3288[0] = "Dialog"; - aStringArray3288[1] = " "; aColor3253 = new Color(192, 192, 192); } } diff --git a/client/src/main/java/com/aapeli/colorgui/ColorTextArea.java b/client/src/main/java/com/aapeli/colorgui/ColorTextArea.java index 9e4b9ef8..2303cc0b 100644 --- a/client/src/main/java/com/aapeli/colorgui/ColorTextArea.java +++ b/client/src/main/java/com/aapeli/colorgui/ColorTextArea.java @@ -60,8 +60,6 @@ public class ColorTextArea extends IPanel implements ComponentListener, Adjustme private int anInt3350; private int anInt3351; private Object anObject3352; - private static final String[] aStringArray3353 = new String[2]; - public ColorTextArea(int var1, int var2) { this(var1, var2, (Font) null); @@ -376,8 +374,6 @@ private void method854(int var1, boolean var2) { } static { - aStringArray3353[0] = " "; - aStringArray3353[1] = "] "; aColorArray3327 = new Color[]{new Color(0, 0, 0), new Color(224, 0, 0), new Color(0, 160, 0), new Color(0, 0, 240), new Color(160, 128, 0), new Color(160, 0, 160), new Color(0, 144, 160), new Color(112, 112, 112), new Color(255, 255, 255)}; aColor3328 = new Color(255, 255, 255); aColor3329 = new Color(192, 192, 192); diff --git a/client/src/main/java/com/aapeli/multiuser/ChatBase.java b/client/src/main/java/com/aapeli/multiuser/ChatBase.java index 1e58ae71..16c4e963 100644 --- a/client/src/main/java/com/aapeli/multiuser/ChatBase.java +++ b/client/src/main/java/com/aapeli/multiuser/ChatBase.java @@ -55,8 +55,6 @@ public abstract class ChatBase extends IPanel implements ComponentListener, User private String aString2357; private Vector chatListeners; private Object synchronizedObject; - private static final String[] aStringArray2360 = new String[9]; - public ChatBase(Parameters var1, TextManager var2, ImageManager var3, BadWordFilter var4, boolean var5, boolean var6, int var7, int var8) { this(var1, var2, var3, var4, true, true, var5, var6, false, var7, var8); @@ -625,15 +623,6 @@ private void method896() { } static { - aStringArray2360[0] = "Chat_NoUnconfirmedChatNote"; - aStringArray2360[1] = "Chat_NoGuestChatAndRegNote"; - aStringArray2360[2] = "ServerSay_SheriffUnMutedUser"; - aStringArray2360[3] = "ServerSay_SheriffMutedUser"; - aStringArray2360[4] = "L10N:"; - aStringArray2360[5] = "ServerSay_SheriffGaveWarning"; - aStringArray2360[6] = "Chat_SayButton"; - aStringArray2360[7] = "Chat_InputHelp"; - aStringArray2360[8] = "Chat_Welcome"; aColor2342 = new Color(144, 144, 224); aBoolean2343 = true; } diff --git a/client/src/main/java/com/aapeli/multiuser/ChatLobby.java b/client/src/main/java/com/aapeli/multiuser/ChatLobby.java index 772cd875..410cb169 100644 --- a/client/src/main/java/com/aapeli/multiuser/ChatLobby.java +++ b/client/src/main/java/com/aapeli/multiuser/ChatLobby.java @@ -15,8 +15,6 @@ public class ChatLobby extends ChatBase { private ColorCheckbox aColorCheckbox3664; private ColorCheckbox aColorCheckbox3665; private boolean aBoolean3666; - private static final String[] aStringArray3667 = new String[14]; - public ChatLobby(Parameters var1, TextManager var2, ImageManager var3, BadWordFilter var4, int var5, int var6) { this(var1, var2, var3, var4, false, false, var5, var6); @@ -265,21 +263,4 @@ private void method905() { this.aColorCheckbox3665 = new ColorCheckbox(super.textManager.getShared("Chat_Lobby_NoGameMessages")); this.add(this.aColorCheckbox3665); } - - static { - aStringArray3667[0] = "Chat_Lobby_UsersStartedUnnamedGame"; - aStringArray3667[1] = "Chat_Lobby_UsersStartedGame"; - aStringArray3667[2] = "Chat_Lobby_UserJoinedGame"; - aStringArray3667[3] = "Chat_Lobby_NoJoinPartMessages"; - aStringArray3667[4] = "Chat_Lobby_NoGameMessages"; - aStringArray3667[5] = "Chat_Lobby_User"; - aStringArray3667[6] = "ReturnedFromGame"; - aStringArray3667[7] = "Joined"; - aStringArray3667[8] = "Chat_Lobby_UserWathicngGame"; - aStringArray3667[9] = "ConnectionProblem"; - aStringArray3667[10] = "Chat_Lobby_UserLeft"; - aStringArray3667[11] = "Chat_Lobby_CantChallengeNone"; - aStringArray3667[12] = "Chat_Lobby_CantChallengeSelf"; - aStringArray3667[13] = "Chat_Lobby_UserCreatedGame"; - } } diff --git a/client/src/main/java/com/aapeli/multiuser/ChatTextArea.java b/client/src/main/java/com/aapeli/multiuser/ChatTextArea.java index a36728f7..97485e6b 100644 --- a/client/src/main/java/com/aapeli/multiuser/ChatTextArea.java +++ b/client/src/main/java/com/aapeli/multiuser/ChatTextArea.java @@ -14,8 +14,6 @@ public class ChatTextArea extends ColorTextArea { private TextManager aTextManager4728; private BadWordFilter aBadWordFilter4729; private Hashtable aHashtable4730; - private static final String[] aStringArray4731 = new String[11]; - public ChatTextArea(TextManager var1, int var2, int var3) { this(var1, (BadWordFilter) null, var2, var3, (Font) null); @@ -197,17 +195,6 @@ private String method862(String var1, boolean var2) { } static { - aStringArray4731[0] = "Chat_MessageFlood"; - aStringArray4731[1] = "Chat_UserAction"; - aStringArray4731[2] = "/me "; - aStringArray4731[3] = "Chat_UserSay"; - aStringArray4731[4] = "Chat_MessagePrivateMessageUserLeft"; - aStringArray4731[5] = "Chat_SheriffSay"; - aStringArray4731[6] = "Chat_ServerBroadcast"; - aStringArray4731[7] = "Chat_ServerSay"; - aStringArray4731[8] = "Chat_UserSayPrivate"; - aStringArray4731[9] = "Chat_Message"; - aStringArray4731[10] = "Dialog"; DEFAULT_FONT = new Font("Dialog", 0, 12); SMALL_FONT = new Font("Dialog", 0, 11); } diff --git a/client/src/main/java/com/aapeli/multiuser/UserList.java b/client/src/main/java/com/aapeli/multiuser/UserList.java index 92d2bdc0..d290f135 100644 --- a/client/src/main/java/com/aapeli/multiuser/UserList.java +++ b/client/src/main/java/com/aapeli/multiuser/UserList.java @@ -91,7 +91,6 @@ public class UserList extends IPanel implements ComponentListener, ItemListener, private ChatBase aChatBase3502; private Languages aLanguages3503; private Hashtable aHashtable3504; - private static final String[] aStringArray3505 = new String[29]; public UserList(UserListHandler var1, TextManager var2, ImageManager var3, boolean var4, boolean var5, boolean var6) { @@ -938,35 +937,6 @@ private UserListItem method937(String var1, boolean var2, int var3) { } static { - aStringArray3505[0] = "UserList_SortByNick"; - aStringArray3505[1] = "UserList_Privately"; - aStringArray3505[2] = "UserList_Ignore"; - aStringArray3505[3] = "UserList_SortByRanking"; - aStringArray3505[4] = "ranking-icons.gif"; - aStringArray3505[5] = "mute"; - aStringArray3505[6] = "info"; - aStringArray3505[7] = "unmute"; - aStringArray3505[8] = "UserList_Sheriff"; - aStringArray3505[9] = "2:"; - aStringArray3505[10] = "Admin"; - aStringArray3505[11] = "Send message..."; - aStringArray3505[12] = "Remove user..."; - aStringArray3505[13] = "Unmute user"; - aStringArray3505[14] = "1 hour"; - aStringArray3505[15] = "6 hours"; - aStringArray3505[16] = "Copy chat"; - aStringArray3505[17] = "15 minutes"; - aStringArray3505[18] = "1 day (admin)"; - aStringArray3505[19] = "Mute user"; - aStringArray3505[20] = "5 minutes"; - aStringArray3505[21] = "Get user info"; - aStringArray3505[22] = "Sheriff"; - aStringArray3505[23] = "Broadcast message..."; - aStringArray3505[24] = "UserList_OpenPlayerCard"; - aStringArray3505[25] = "3:"; - aStringArray3505[26] = "_blank"; - aStringArray3505[27] = "guestinfotarget"; - aStringArray3505[28] = "Dialog"; aColor3453 = Color.white; aColor3454 = Color.black; aFont3455 = new Font("Dialog", 0, 9); From c75ccb9fc4dd8d3251edcc54f0bf8ee9daa7020d Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 02/16] Deobfuscate SynchronizedInteger This revealed that the `anInt997` field was unused and could be removed. --- .../main/java/agolf/SynchronizedInteger.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/client/src/main/java/agolf/SynchronizedInteger.java b/client/src/main/java/agolf/SynchronizedInteger.java index f426435c..a168cba2 100644 --- a/client/src/main/java/agolf/SynchronizedInteger.java +++ b/client/src/main/java/agolf/SynchronizedInteger.java @@ -3,41 +3,39 @@ public class SynchronizedInteger { - private long aLong996; - private int anInt997; + private long n; public SynchronizedInteger() { this(0); } - protected SynchronizedInteger(int var1) { - this.set(var1); + protected SynchronizedInteger(int n) { + this.set(n); } - public synchronized int set(int var1) { - this.priv_set(var1); - this.anInt997 = var1; - return var1; + public synchronized int set(int n) { + this.priv_set(n); + return n; } public synchronized int get_upd() { - return this.set((this.aLong996 > 0L ? (int) ((2269700342778490L - this.aLong996) / 31L) : (int) ((this.aLong996 + 110157223978885L) / 7L)) + 1); + return this.set((this.n > 0L ? (int) ((2269700342778490L - this.n) / 31L) : (int) ((this.n + 110157223978885L) / 7L)) + 1); } - public synchronized int get_upd(int var1) { - return this.set((this.aLong996 > 0L ? (int) ((2269700342778490L - this.aLong996) / 31L) : (int) ((this.aLong996 + 110157223978885L) / 7L)) + var1); + public synchronized int get_upd(int i) { + return this.set((this.n > 0L ? (int) ((2269700342778490L - this.n) / 31L) : (int) ((this.n + 110157223978885L) / 7L)) + i); } public synchronized int get() { - return this.aLong996 > 0L ? (int) ((2269700342778490L - this.aLong996) / 31L) : (int) ((this.aLong996 + 110157223978885L) / 7L); + return this.n > 0L ? (int) ((2269700342778490L - this.n) / 31L) : (int) ((this.n + 110157223978885L) / 7L); } - private void priv_set(int var1) { - if (var1 % 2 == 0) { - this.aLong996 = 2269700342778490L - (long) var1 * 31L; + private void priv_set(int n) { + if (n % 2 == 0) { + this.n = 2269700342778490L - (long) n * 31L; } else { - this.aLong996 = -110157223978885L + (long) var1 * 7L; + this.n = -110157223978885L + (long) n * 7L; } } } From 5a16e6b11f55c9b3c7d76fc6e01e628b90027da9 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 03/16] Deobfuscate code UI code about rating tracks --- .../java/agolf/game/GameTrackInfoPanel.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/agolf/game/GameTrackInfoPanel.java b/client/src/main/java/agolf/game/GameTrackInfoPanel.java index 10cdf16f..51c20949 100644 --- a/client/src/main/java/agolf/game/GameTrackInfoPanel.java +++ b/client/src/main/java/agolf/game/GameTrackInfoPanel.java @@ -9,7 +9,6 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Image; -import java.awt.LayoutManager; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -180,7 +179,7 @@ public void update(Graphics g) { public void actionPerformed(ActionEvent evt) { Object evtSource = evt.getSource(); if (evtSource == this.buttonNoVote) { - this.method388(false); + this.setHasNotRatedTrack(false); this.repaint(); } else { for (int i = 0; i <= 10; ++i) { @@ -189,7 +188,7 @@ public void actionPerformed(ActionEvent evt) { ++this.trackTotalRatings; this.trackRating += i; this.trackAverageRating = (double) this.trackRating / (double) this.trackTotalRatings; - this.method388(false); + this.setHasNotRatedTrack(false); this.repaint(); return; } @@ -260,7 +259,7 @@ protected void parseTrackInfoStats(String trackAuthor, String trackName, int[] p } if (!this.gameContainer.synchronizedTrackTestMode.get()) { // Toggles some buttons??! - this.method388(true); + this.setHasNotRatedTrack(true); } else { this.toggleAcceptRejectButtons(trackTestMode1); this.method390(trackTestMode2); @@ -331,11 +330,11 @@ private String[] parseBestPlayerInformation(String var1) { return var2; } - private void method388(boolean var1) { - if (var1 != this.hasNotRatedTrack) { - this.hasNotRatedTrack = var1; + private void setHasNotRatedTrack(boolean hasNotRatedTrack) { + if (hasNotRatedTrack != this.hasNotRatedTrack) { + this.hasNotRatedTrack = hasNotRatedTrack; this.setVisible(false); - if (var1) { + if (hasNotRatedTrack) { this.add(this.buttonNoVote); for (int var2 = 0; var2 <= 10; ++var2) { @@ -349,12 +348,12 @@ private void method388(boolean var1) { } } - private void toggleAcceptRejectButtons(boolean var1) { + private void toggleAcceptRejectButtons(boolean trackPending) { if (!this.gameContainer.safeMode) { - if (var1 != this.trackPending) { - this.trackPending = var1; + if (trackPending != this.trackPending) { + this.trackPending = trackPending; this.setVisible(false); - if (var1) { + if (trackPending) { this.add(this.buttonReject); this.add(this.buttonAccept); } else { From c42c613079b8590dadfad87073b4435010f44192 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 04/16] Deobfuscate UI code about skipping tracks --- .../src/main/java/agolf/game/GameControlPanel.java | 12 ++++++------ client/src/main/java/agolf/game/GamePanel.java | 8 ++++---- .../main/java/agolf/game/GamePlayerInfoPanel.java | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/client/src/main/java/agolf/game/GameControlPanel.java b/client/src/main/java/agolf/game/GameControlPanel.java index c3ac1217..367a6e62 100644 --- a/client/src/main/java/agolf/game/GameControlPanel.java +++ b/client/src/main/java/agolf/game/GameControlPanel.java @@ -53,17 +53,17 @@ public void update(Graphics var1) { var1.fillRect(0, 0, this.anInt342, this.anInt343); } - public void actionPerformed(ActionEvent var1) { - Object var2 = var1.getSource(); - if (var2 == this.buttonSkip) { - if (this.gameContainer.gamePanel.method339(this.playerCount == 1)) { + public void actionPerformed(ActionEvent event) { + Object source = event.getSource(); + if (source == this.buttonSkip) { + if (this.gameContainer.gamePanel.skipButtonPressed(this.playerCount == 1)) { this.setVisible(false); this.remove(this.buttonSkip); this.setVisible(true); this.skipButtonVisible = false; } - } else if (var2 == this.buttonNewGame) { + } else if (source == this.buttonNewGame) { this.buttonNewGame.removeActionListener(this); this.setVisible(false); this.remove(this.buttonNewGame); @@ -71,7 +71,7 @@ public void actionPerformed(ActionEvent var1) { this.aGamePlayerInfoPanel__341.readyForNewGameLocal(); this.gameContainer.gamePanel.requestNewGame(); } else { - if (var2 == this.buttonBack) { + if (source == this.buttonBack) { this.buttonBack.removeActionListener(this); this.setVisible(false); this.remove(this.buttonBack); diff --git a/client/src/main/java/agolf/game/GamePanel.java b/client/src/main/java/agolf/game/GamePanel.java index ac2160ff..27fe4ea7 100644 --- a/client/src/main/java/agolf/game/GamePanel.java +++ b/client/src/main/java/agolf/game/GamePanel.java @@ -429,11 +429,11 @@ protected void sendEndStroke(int playerid, SynchronizedBool[] settings, int var3 this.gameContainer.connection.writeData("game\t" + data); } - protected boolean method339(boolean var1) { + protected boolean skipButtonPressed(boolean isSinglePlayer) { if (this.state == 1) { - if (!var1) { - this.gamePlayerInfoPanel.method366(); - if (this.gamePlayerInfoPanel.method376() && this.gameCanvas.method137()) { + if (!isSinglePlayer) { + this.gamePlayerInfoPanel.voteSkip(); + if (this.gamePlayerInfoPanel.shouldSkipTrack() && this.gameCanvas.method137()) { this.gameCanvas.restartGame(); } diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index 5beea558..c71c163c 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -434,7 +434,7 @@ protected void setGameOutcome(int[] outcome) { this.repaint(); } - protected void method366() { + protected void voteSkip() { this.voteSkip(this.playerId); } @@ -507,9 +507,9 @@ protected void method375(int[][] var1) { this.repaint(); } - protected boolean method376() { - for (int var1 = 0; var1 < this.playerCount; ++var1) { - if (this.anIntArray394[var1] == 0 && !this.playerVotedToSkip[var1]) { + protected boolean shouldSkipTrack() { + for (int player = 0; player < this.playerCount; ++player) { + if (this.anIntArray394[player] == 0 && !this.playerVotedToSkip[player]) { return false; } } From 6eadcf2521a3ee7bf254d2f588de60c3414e9b39 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 05/16] Deobfuscate UI code about track score multipliers Looks like the server never sends track score multipliers currently. Nevertheless, this is code is nice to deobfuscate to better understand surrounding code. --- .../src/main/java/agolf/game/GamePanel.java | 14 ++++++------ .../java/agolf/game/GamePlayerInfoPanel.java | 22 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/client/src/main/java/agolf/game/GamePanel.java b/client/src/main/java/agolf/game/GamePanel.java index 27fe4ea7..6a240612 100644 --- a/client/src/main/java/agolf/game/GamePanel.java +++ b/client/src/main/java/agolf/game/GamePanel.java @@ -137,13 +137,13 @@ public void handlePacket(String[] args) { } else if (args[1].equals("scoringmulti")) { int len = args.length - 2; - int[] var3 = new int[len]; + int[] trackScoresMultipliers = new int[len]; - for (int trackCount = 0; trackCount < len; ++trackCount) { - var3[trackCount] = Integer.parseInt(args[2 + trackCount]); + for (int track = 0; track < len; ++track) { + trackScoresMultipliers[track] = Integer.parseInt(args[2 + track]); } - this.gamePlayerInfoPanel.method356(var3); + this.gamePlayerInfoPanel.setTrackScoresMultipliers(trackScoresMultipliers); } else if (args[1].equals("players")) { int len = (args.length - 2) / 3; int playerCountIndex = 2; @@ -307,9 +307,9 @@ else if (args[1].equals("starttrack")) { this.gameTrackInfoPanel.parseTrackInfoStats(trackInformation[0], trackInformation[1], trackStats[0], trackStats[1], trackInformation[2], trackInformation[3], trackTestMode1, trackTestMode2, this.gameCanvas.method134()); - int numberOfPlayers = this.gamePlayerInfoPanel.startNextTrack(); - if (numberOfPlayers > 1) { - this.gameChatPanel.addMessage(gameContainer.textManager.getGame("GameChat_ScoreMultiNotify", numberOfPlayers)); + int trackScoreMultiplier = this.gamePlayerInfoPanel.startNextTrack(); + if (trackScoreMultiplier > 1) { + this.gameChatPanel.addMessage(gameContainer.textManager.getGame("GameChat_ScoreMultiNotify", trackScoreMultiplier)); } this.gameControlPanel.displaySkipButton(); // checks if you can skip on first shot diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index c71c163c..9f63dc71 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -50,7 +50,7 @@ class GamePlayerInfoPanel extends Panel implements ItemListener, MouseListener { private int[] anIntArray394; private boolean[] playerVotedToSkip; private boolean[] playerReadyForNewGame; - private int[] anIntArray397; + private int[] trackScoresMultipliers; private int[][] anIntArrayArray398; private Choicer aChoicer399; private Image image; @@ -67,7 +67,7 @@ protected GamePlayerInfoPanel(GameContainer gameContainer, int width, int height this.setLayout(null); this.currentTimeForShot = -1; this.initialized = false; - this.anIntArray397 = null; + this.trackScoresMultipliers = null; this.anIntArrayArray398 = null; } @@ -145,12 +145,12 @@ public void update(Graphics g) { this.graphics.drawString(var9 >= 0 ? String.valueOf(var9) : this.gameContainer.textManager.getGame("GamePlayerInfo_Skipped"), 130 + track * 20, offsetY); this.graphics.setColor(color); - } else if (this.anIntArray397[track] == 1) { + } else if (this.trackScoresMultipliers[track] == 1) { this.graphics.drawString("-", 130 + track * 20 + 5, offsetY); } else { this.graphics.setFont(fontDialog10); this.graphics.setColor(playerColors[player][1]); - this.graphics.drawString("(*" + this.anIntArray397[track] + ")", 130 + track * 20, offsetY - 1); + this.graphics.drawString("(*" + this.trackScoresMultipliers[track] + ")", 130 + track * 20, offsetY - 1); this.graphics.setFont(font); this.graphics.setColor(color); } @@ -292,10 +292,10 @@ protected void init(int playerCount, int trackCount, int maxStrokes, int strokeT this.anIntArray394[player] = 0; } - this.anIntArray397 = new int[trackCount]; + this.trackScoresMultipliers = new int[trackCount]; for (int track = 0; track < trackCount; ++track) { - this.anIntArray397[track] = 1; + this.trackScoresMultipliers[track] = 1; } this.playerId = -1; @@ -304,8 +304,8 @@ protected void init(int playerCount, int trackCount, int maxStrokes, int strokeT this.repaint(); } - protected void method356(int[] var1) { - this.anIntArray397 = var1; + protected void setTrackScoresMultipliers(int[] trackScoresMultipliers) { + this.trackScoresMultipliers = trackScoresMultipliers; this.repaint(); } @@ -360,7 +360,7 @@ protected int startNextTrack() { ++this.currentTrackIndex; this.repaint(); - return this.anIntArray397[this.currentTrackIndex]; + return this.trackScoresMultipliers[this.currentTrackIndex]; } protected boolean method361(int var1) { @@ -369,7 +369,7 @@ protected boolean method361(int var1) { } else { int var2 = this.trackStrokes[var1][this.currentTrackIndex].get(); if (this.trackScoring == 0) { - var2 /= this.anIntArray397[this.currentTrackIndex]; + var2 /= this.trackScoresMultipliers[this.currentTrackIndex]; } return var2 >= this.maxStrokes; @@ -392,7 +392,7 @@ protected boolean startTurn(int playerId) { protected void method363(int playerId, boolean isStrokeEnd) { if (this.trackScoring == 0) { - int var3 = !isStrokeEnd ? this.anIntArray397[this.currentTrackIndex] : 1; + int var3 = !isStrokeEnd ? this.trackScoresMultipliers[this.currentTrackIndex] : 1; this.trackStrokes[playerId][this.currentTrackIndex].get_upd(var3); this.playersId[playerId].get_upd(var3); } else { From 68533664705fd45d85ff338e978de905cad9c322 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 06/16] Deobfuscate some code around leaving an ongoing game --- .../java/agolf/game/GameControlPanel.java | 15 +++++------ .../src/main/java/agolf/game/GamePanel.java | 10 +++---- .../java/agolf/game/GamePlayerInfoPanel.java | 27 ++++++++++--------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/client/src/main/java/agolf/game/GameControlPanel.java b/client/src/main/java/agolf/game/GameControlPanel.java index 367a6e62..7616ffcf 100644 --- a/client/src/main/java/agolf/game/GameControlPanel.java +++ b/client/src/main/java/agolf/game/GameControlPanel.java @@ -70,15 +70,12 @@ public void actionPerformed(ActionEvent event) { this.setVisible(true); this.aGamePlayerInfoPanel__341.readyForNewGameLocal(); this.gameContainer.gamePanel.requestNewGame(); - } else { - if (source == this.buttonBack) { - this.buttonBack.removeActionListener(this); - this.setVisible(false); - this.remove(this.buttonBack); - this.setVisible(true); - this.gameContainer.gamePanel.method342(); - } - + } else if (source == this.buttonBack) { + this.buttonBack.removeActionListener(this); + this.setVisible(false); + this.remove(this.buttonBack); + this.setVisible(true); + this.gameContainer.gamePanel.leaveGame(); } } diff --git a/client/src/main/java/agolf/game/GamePanel.java b/client/src/main/java/agolf/game/GamePanel.java index 6a240612..6438532f 100644 --- a/client/src/main/java/agolf/game/GamePanel.java +++ b/client/src/main/java/agolf/game/GamePanel.java @@ -173,14 +173,14 @@ else if (args[1].equals("owninfo")) { } } - else if (args[1].equals("part")) { + else if (args[1].equals("part")) { // player left game int playerId = Integer.parseInt(args[2]); - String playerName = this.gamePlayerInfoPanel.playerNames[playerId]; - boolean var23 = this.gamePlayerInfoPanel.method358(playerId, Integer.parseInt(args[3])); - if (var23) { + boolean changed = this.gamePlayerInfoPanel.setPlayerPartStatus(playerId, Integer.parseInt(args[3])); + if (changed) { this.gameControlPanel.method329(); } + String playerName = this.gamePlayerInfoPanel.playerNames[playerId]; this.gameChatPanel.addMessage(this.gameContainer.textManager.getGame("GameChat_Part", playerName)); this.gameChatPanel.removeUserColour(playerName); this.gameControlPanel.method330(); @@ -460,7 +460,7 @@ protected void requestNewGame() { this.gameContainer.connection.writeData("game\tnewgame"); } - protected void method342() { + protected void leaveGame() { this.gameCanvas.restartGame(); this.gamePlayerInfoPanel.stopTimer(); this.gameContainer.gameApplet.setGameState(0); diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index 9f63dc71..ebb93987 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -47,7 +47,7 @@ class GamePlayerInfoPanel extends Panel implements ItemListener, MouseListener { protected String[] playerClans; private SynchronizedInteger[][] trackStrokes; private SynchronizedInteger[] playersId; - private int[] anIntArray394; + private int[] playerLeaveReasons; // see PART_ enums in Lobby class private boolean[] playerVotedToSkip; private boolean[] playerReadyForNewGame; private int[] trackScoresMultipliers; @@ -119,7 +119,8 @@ public void update(Graphics g) { for (int player = 0; player < this.playerCount; ++player) { Font font = this.playerId == player ? fontDialog12b : fontDialog12; - Color color = playerColors[player][this.anIntArray394[player] == 0 ? 0 : 1]; + int playerLeft = this.playerLeaveReasons[player] == 0 ? 0 : 1; + Color color = playerColors[player][playerLeft]; this.graphics.setFont(font); this.graphics.setColor(color); if (this.playerCount > 1) { @@ -159,7 +160,7 @@ public void update(Graphics g) { this.graphics.drawString("= " + this.playersId[player].get(), 130 + this.trackCount * 20 + 15, offsetY); String playerInfo; int[] scoreDifferences = this.getScoreDifferences(); - if (scoreDifferences != null && this.anIntArray394[player] == 0) { + if (scoreDifferences != null && this.playerLeaveReasons[player] == 0) { playerInfo = null; if (scoreDifferences[player] == 0) { if (this.gameOutcome == null) { @@ -212,11 +213,11 @@ public void update(Graphics g) { playerInfo = "GamePlayerInfo_ReadyForNewGame"; } - if (this.anIntArray394[player] == 5) { + if (this.playerLeaveReasons[player] == 5) { playerInfo = "GamePlayerInfo_Quit_ConnectionProblem"; } - if (this.anIntArray394[player] == 4) { + if (this.playerLeaveReasons[player] == 4) { playerInfo = "GamePlayerInfo_Quit_Part"; } @@ -283,13 +284,13 @@ protected void init(int playerCount, int trackCount, int maxStrokes, int strokeT this.playersId[player] = new SynchronizedInteger(); } - this.anIntArray394 = new int[playerCount]; + this.playerLeaveReasons = new int[playerCount]; this.playerVotedToSkip = new boolean[playerCount]; this.playerReadyForNewGame = new boolean[playerCount]; for (int player = 0; player < playerCount; ++player) { this.playerNames[player] = this.playerClans[player] = null; - this.anIntArray394[player] = 0; + this.playerLeaveReasons[player] = 0; } this.trackScoresMultipliers = new int[trackCount]; @@ -321,11 +322,11 @@ protected void addPlayer(int playerID, String name, String clan, boolean isLocal this.addMouseListener(this); } - protected boolean method358(int playerId, int var2) { - if (var2 == 6) { + protected boolean setPlayerPartStatus(int playerId, int status) { + if (status == 6) { this.playerNames[playerId] = null; } else { - this.anIntArray394[playerId] = var2; + this.playerLeaveReasons[playerId] = status; if (this.gameContainer.gamePanel.state == 2) { this.gameContainer.gamePanel.state = 3; this.repaint(); @@ -463,7 +464,7 @@ protected void readyForNewGame(int var1) { protected void method371(int state) { if (state == 2) { for (int player = 0; player < this.playerCount && state == 2; ++player) { - if (this.anIntArray394[player] != 0) { + if (this.playerLeaveReasons[player] != 0) { state = 3; this.gameContainer.gamePanel.state = 3; } @@ -509,7 +510,7 @@ protected void method375(int[][] var1) { protected boolean shouldSkipTrack() { for (int player = 0; player < this.playerCount; ++player) { - if (this.anIntArray394[player] == 0 && !this.playerVotedToSkip[player]) { + if (this.playerLeaveReasons[player] == 0 && !this.playerVotedToSkip[player]) { return false; } } @@ -534,7 +535,7 @@ private int[] getScoreDifferences() { int score; for (int i = 0; i < this.playerCount; ++i) { - if (this.anIntArray394[i] == 0) { + if (this.playerLeaveReasons[i] == 0) { score = this.playersId[i].get(); if (this.trackScoring == 0 && score < bestScore) { bestScore = score; From 36e3cb0e4b810022ec3916869e61e8175873326a Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 07/16] Deobfuscate some code around track score comparisons --- .../src/main/java/agolf/game/GamePanel.java | 22 +++--- .../java/agolf/game/GamePlayerInfoPanel.java | 75 ++++++++++--------- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/client/src/main/java/agolf/game/GamePanel.java b/client/src/main/java/agolf/game/GamePanel.java index 6438532f..d48b6e14 100644 --- a/client/src/main/java/agolf/game/GamePanel.java +++ b/client/src/main/java/agolf/game/GamePanel.java @@ -187,22 +187,22 @@ else if (args[1].equals("part")) { // player left game } else if (args[1].equals("say")) { int playerId = Integer.parseInt(args[2]); this.gameChatPanel.addSay(playerId, this.gamePlayerInfoPanel.playerNames[playerId], args[3], false); - } else if (args[1].equals("cr")) { - StringTokenizer var19 = new StringTokenizer(args[2], ","); - int playerTypes = var19.countTokens(); - int[][] var25 = new int[5][playerTypes]; - - for (int var1 = 0; var1 < 5; ++var1) { - for (int startIndex = 0; startIndex < playerTypes; ++startIndex) { - var25[var1][startIndex] = Integer.parseInt(var19.nextToken()); + } else if (args[1].equals("cr")) { // get results to compare track score against + StringTokenizer tokenizer = new StringTokenizer(args[2], ","); + int tracks = tokenizer.countTokens(); + int[][] comparisonScores = new int[5][tracks]; + + for (int comparisonType = 0; comparisonType < 5; ++comparisonType) { + for (int track = 0; track < tracks; ++track) { + comparisonScores[comparisonType][track] = Integer.parseInt(tokenizer.nextToken()); } - if (var1 < 4) { - var19 = new StringTokenizer(args[3 + var1], ","); + if (comparisonType < 4) { + tokenizer = new StringTokenizer(args[3 + comparisonType], ","); } } - this.gamePlayerInfoPanel.method375(var25); + this.gamePlayerInfoPanel.initResultsComparison(comparisonScores); } else if (args[1].equals("start")) { if (this.playerCount > 1) { if (this.aBoolean363) { diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index ebb93987..aef97bee 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -22,14 +22,14 @@ class GamePlayerInfoPanel extends Panel implements ItemListener, MouseListener { private static final Font fontDialog10 = new Font("Dialog", Font.PLAIN, 10); private static final Color currentTrackScoreHighlightColor = new Color(224, 255, 224); private static final Color aColor372 = new Color(128, 208, 128); - private static final Color aColor373 = new Color(224, 0, 0); - private static final Color aColor374 = new Color(0, 128, 0); - private static final Color[][] playerColors = new Color[][]{ + private static final Color losingComparisonColor = new Color(224, 0, 0); + private static final Color leadingComparisonColor = new Color(0, 128, 0); + private static final Color[][] playerColors = new Color[][]{ // first color == player is in game, second == player has left the game {new Color(0, 0, 255), new Color(128, 128, 255)}, {new Color(255, 0, 0), new Color(255, 128, 128)}, {new Color(128, 128, 0), new Color(128, 128, 64)}, {new Color(0, 160, 0), new Color(64, 160, 64)} }; - private static int anInt376; + private static int scoreComparisonMode; private GameContainer gameContainer; private final int width; private final int height; @@ -51,8 +51,8 @@ class GamePlayerInfoPanel extends Panel implements ItemListener, MouseListener { private boolean[] playerVotedToSkip; private boolean[] playerReadyForNewGame; private int[] trackScoresMultipliers; - private int[][] anIntArrayArray398; - private Choicer aChoicer399; + private int[][] resultsToCompareScoreAgainst; + private Choicer compareResultsChoicer; private Image image; private Graphics graphics; private GamePlayerInfoPanelTimerThread timerThread; @@ -68,7 +68,7 @@ protected GamePlayerInfoPanel(GameContainer gameContainer, int width, int height this.currentTimeForShot = -1; this.initialized = false; this.trackScoresMultipliers = null; - this.anIntArrayArray398 = null; + this.resultsToCompareScoreAgainst = null; } public void addNotify() { @@ -91,21 +91,22 @@ public void update(Graphics g) { this.graphics.setColor(GameApplet.colourGameBackground); this.graphics.fillRect(0, 0, this.width, this.height); if (this.initialized) { - int[] var2 = null; - if (this.anIntArrayArray398 != null && anInt376 > 0) { - var2 = this.anIntArrayArray398[anInt376 - 1]; + // draw score comparison row + int[] comparedResults = null; + if (this.resultsToCompareScoreAgainst != null && scoreComparisonMode > 0) { + comparedResults = this.resultsToCompareScoreAgainst[scoreComparisonMode - 1]; this.graphics.setFont(fontDialog12); this.graphics.setColor(aColor372); this.graphics.drawString(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultNick"), 20, 20); - int var3 = 0; + int totalComparisonStrokes = 0; - for (int offset = 0; offset <= this.currentTrackIndex && offset < this.trackCount; ++offset) { - this.graphics.drawString(var2[offset] > 0 ? String.valueOf(var2[offset]) : "?", 130 + offset * 20, 20); - var3 += var2[offset]; + for (int comparedTrackIndex = 0; comparedTrackIndex <= this.currentTrackIndex && comparedTrackIndex < this.trackCount; ++comparedTrackIndex) { + this.graphics.drawString(comparedResults[comparedTrackIndex] > 0 ? String.valueOf(comparedResults[comparedTrackIndex]) : "?", 130 + comparedTrackIndex * 20, 20); + totalComparisonStrokes += comparedResults[comparedTrackIndex]; } - if (var3 > 0) { - this.graphics.drawString("= " + var3, 130 + this.trackCount * 20 + 15, 20); + if (totalComparisonStrokes > 0) { + this.graphics.drawString("= " + totalComparisonStrokes, 130 + this.trackCount * 20 + 15, 20); } } @@ -133,18 +134,18 @@ public void update(Graphics g) { for (int track = 0; track < this.trackCount; ++track) { if (track <= this.currentTrackIndex) { - int var9 = this.trackStrokes[player][track].get(); - if (var2 != null) { - if (track < this.currentTrackIndex && var9 < var2[track]) { - this.graphics.setColor(aColor374); + int strokes = this.trackStrokes[player][track].get(); + if (comparedResults != null) { + if (track < this.currentTrackIndex && strokes < comparedResults[track]) { + this.graphics.setColor(leadingComparisonColor); } - if (var9 > var2[track] && var2[track] > 0) { - this.graphics.setColor(aColor373); + if (strokes > comparedResults[track] && comparedResults[track] > 0) { + this.graphics.setColor(losingComparisonColor); } } - this.graphics.drawString(var9 >= 0 ? String.valueOf(var9) : this.gameContainer.textManager.getGame("GamePlayerInfo_Skipped"), 130 + track * 20, offsetY); + this.graphics.drawString(strokes >= 0 ? String.valueOf(strokes) : this.gameContainer.textManager.getGame("GamePlayerInfo_Skipped"), 130 + track * 20, offsetY); this.graphics.setColor(color); } else if (this.trackScoresMultipliers[track] == 1) { this.graphics.drawString("-", 130 + track * 20 + 5, offsetY); @@ -233,7 +234,7 @@ public void update(Graphics g) { } public void itemStateChanged(ItemEvent var1) { - anInt376 = this.aChoicer399.getSelectedIndex(); + scoreComparisonMode = this.compareResultsChoicer.getSelectedIndex(); this.repaint(); } @@ -490,20 +491,20 @@ protected String[] method374() { return this.playerNames; } - protected void method375(int[][] var1) { - this.anIntArrayArray398 = var1; - this.aChoicer399 = new Choicer(); - this.aChoicer399.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultNone")); - this.aChoicer399.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultOwn", this.playerNames[0])); - this.aChoicer399.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultTop100Average")); - this.aChoicer399.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultBestOfDay")); - this.aChoicer399.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultBestOfAllTime")); - this.aChoicer399.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultIdeal")); - this.aChoicer399.select(anInt376); - this.aChoicer399.setBounds(555, 5, 170, 20); - this.aChoicer399.addItemListener(this); + protected void initResultsComparison(int[][] results) { + this.resultsToCompareScoreAgainst = results; + this.compareResultsChoicer = new Choicer(); + this.compareResultsChoicer.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultNone")); + this.compareResultsChoicer.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultOwn", this.playerNames[0])); + this.compareResultsChoicer.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultTop100Average")); + this.compareResultsChoicer.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultBestOfDay")); + this.compareResultsChoicer.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultBestOfAllTime")); + this.compareResultsChoicer.addItem(this.gameContainer.textManager.getGame("GamePlayerInfo_CompareResultIdeal")); + this.compareResultsChoicer.select(scoreComparisonMode); + this.compareResultsChoicer.setBounds(555, 5, 170, 20); + this.compareResultsChoicer.addItemListener(this); this.setVisible(false); - this.add(this.aChoicer399); + this.add(this.compareResultsChoicer); this.setVisible(true); this.repaint(); } From 8128b05ed1384a07388e864273e8cda3030f7a81 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 08/16] Add comments to GamePlayerInfoPanel UI drawing code --- .../main/java/agolf/game/GamePlayerInfoPanel.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index aef97bee..0f600357 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -118,20 +118,22 @@ public void update(Graphics g) { this.graphics.fillRect(130 + this.currentTrackIndex * 20 - 5, offsetY - 13 + 1, 21, this.playerCount * 15 + 2 - 2); } + // draw player status text for (int player = 0; player < this.playerCount; ++player) { Font font = this.playerId == player ? fontDialog12b : fontDialog12; int playerLeft = this.playerLeaveReasons[player] == 0 ? 0 : 1; Color color = playerColors[player][playerLeft]; this.graphics.setFont(font); this.graphics.setColor(color); - if (this.playerCount > 1) { + if (this.playerCount > 1) { // draw 1., 2., etc in front of player name this.graphics.drawString(player + 1 + ".", 2, offsetY); } - if (this.playerNames[player] != null) { + if (this.playerNames[player] != null) { // draw player name this.graphics.drawString(this.playerNames[player], 20, offsetY); } + // draw track scores for (int track = 0; track < this.trackCount; ++track) { if (track <= this.currentTrackIndex) { int strokes = this.trackStrokes[player][track].get(); @@ -158,11 +160,13 @@ public void update(Graphics g) { } } + // draw sum of player strokes this.graphics.drawString("= " + this.playersId[player].get(), 130 + this.trackCount * 20 + 15, offsetY); - String playerInfo; + + String playerInfo = null; int[] scoreDifferences = this.getScoreDifferences(); + // draw difference with leader's score if (scoreDifferences != null && this.playerLeaveReasons[player] == 0) { - playerInfo = null; if (scoreDifferences[player] == 0) { if (this.gameOutcome == null) { playerInfo = this.gameContainer.textManager.getGame("GamePlayerInfo_Leader"); @@ -178,6 +182,7 @@ public void update(Graphics g) { playerInfo = null; String timeRemaining = null; + // draw "waiting for player" text if lobby has empty slots if (this.playerNames[player] == null) { playerInfo = "GamePlayerInfo_WaitingPlayer"; } From 87324a3f5035eaa173081bbfbbe9729e916911b6 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 09/16] Miscellaneous deobfuscation in client code These are some small changes that did not really fit in with other commits. --- .../java/agolf/game/GameBackgroundCanvas.java | 6 +- .../src/main/java/agolf/game/GameCanvas.java | 2 +- .../java/agolf/game/GameControlPanel.java | 8 +-- .../src/main/java/agolf/game/GamePanel.java | 42 ++++++------- .../java/agolf/game/GamePlayerInfoPanel.java | 25 ++++---- .../java/agolf/game/GameTrackInfoPanel.java | 63 ++++++++++--------- .../server/game/gametypes/GolfGame.java | 4 +- 7 files changed, 75 insertions(+), 75 deletions(-) diff --git a/client/src/main/java/agolf/game/GameBackgroundCanvas.java b/client/src/main/java/agolf/game/GameBackgroundCanvas.java index dfcca401..8bfcf0a7 100644 --- a/client/src/main/java/agolf/game/GameBackgroundCanvas.java +++ b/client/src/main/java/agolf/game/GameBackgroundCanvas.java @@ -67,13 +67,11 @@ public void update(Graphics g) { } protected String[] generateTrackInformation() { - String[] var1 = new String[]{this.trackAuthor, this.trackName, this.trackFirstBest, this.trackLastBest}; - return var1; + return new String[]{this.trackAuthor, this.trackName, this.trackFirstBest, this.trackLastBest}; } protected int[][] generateTrackStatistics() { - int[][] var1 = new int[][]{this.trackStats, this.trackRatings}; - return var1; + return new int[][]{this.trackStats, this.trackRatings}; } //this useless func is called when we get start packet diff --git a/client/src/main/java/agolf/game/GameCanvas.java b/client/src/main/java/agolf/game/GameCanvas.java index ac8851cf..2280c77d 100644 --- a/client/src/main/java/agolf/game/GameCanvas.java +++ b/client/src/main/java/agolf/game/GameCanvas.java @@ -593,7 +593,7 @@ public synchronized void mousePressed(MouseEvent event) { this.removeMouseListener(this); this.removeKeyListener(this); this.setCursor(cursorDefault); - if (super.gameContainer.gamePanel.canStroke(true)) { + if (super.gameContainer.gamePanel.tryStroke(true)) { super.gameContainer.gamePanel.setBeginStroke(this.currentPlayerID, x, y, this.shootingMode); //this.doHackedStroke(this.currentPlayerID, true, x, y, this.keyCountMod4); this.doStroke(this.currentPlayerID, true, x, y, this.shootingMode); diff --git a/client/src/main/java/agolf/game/GameControlPanel.java b/client/src/main/java/agolf/game/GameControlPanel.java index 7616ffcf..6cd0b660 100644 --- a/client/src/main/java/agolf/game/GameControlPanel.java +++ b/client/src/main/java/agolf/game/GameControlPanel.java @@ -102,7 +102,7 @@ protected void displaySkipButton() { this.setVisible(true); } - protected void method327(int state) { + protected void setState(int state) { this.setVisible(false); this.removeAll(); this.skipButtonVisible = false; @@ -130,8 +130,8 @@ protected void method327(int state) { if (this.playerCount > 1) { this.playerNamesDisplayModeChoicer = new Choicer(); - for (int var2 = 0; var2 < 4; ++var2) { - this.playerNamesDisplayModeChoicer.addItem(this.gameContainer.textManager.getGame("GameControl_Names" + var2)); + for (int option = 0; option < 4; ++option) { + this.playerNamesDisplayModeChoicer.addItem(this.gameContainer.textManager.getGame("GameControl_Names" + option)); } this.playerNamesDisplayModeChoicer.select(this.playerCount <= 2 ? 0 : 3); @@ -159,7 +159,7 @@ protected void method329() { this.remove(this.buttonNewGame); } - protected void method330() { + protected void refreshBackButton() { if (this.playerCount != 1) { this.setVisible(false); this.remove(this.buttonBack); diff --git a/client/src/main/java/agolf/game/GamePanel.java b/client/src/main/java/agolf/game/GamePanel.java index d48b6e14..dba8976a 100644 --- a/client/src/main/java/agolf/game/GamePanel.java +++ b/client/src/main/java/agolf/game/GamePanel.java @@ -183,7 +183,7 @@ else if (args[1].equals("part")) { // player left game String playerName = this.gamePlayerInfoPanel.playerNames[playerId]; this.gameChatPanel.addMessage(this.gameContainer.textManager.getGame("GameChat_Part", playerName)); this.gameChatPanel.removeUserColour(playerName); - this.gameControlPanel.method330(); + this.gameControlPanel.refreshBackButton(); } else if (args[1].equals("say")) { int playerId = Integer.parseInt(args[2]); this.gameChatPanel.addSay(playerId, this.gamePlayerInfoPanel.playerNames[playerId], args[3], false); @@ -219,7 +219,7 @@ else if (args[1].equals("part")) { // player left game this.aBoolean363 = false; this.gameCanvas.createMap(16777216); - this.gamePlayerInfoPanel.method359(); + this.gamePlayerInfoPanel.reset(); this.gameTrackInfoPanel.resetCurrentTrack(); this.setState(1); } @@ -333,7 +333,7 @@ else if (args[1].equals("starttrack")) { } } else if (args[1].equals("beginstroke")) { int playerId = Integer.parseInt(args[2]); - this.gamePlayerInfoPanel.method363(playerId, false); + this.gamePlayerInfoPanel.strokeStartedOrEnded(playerId, false); this.gameContainer.soundManager.playGameMove(); this.gameCanvas.decodeCoords(playerId, false, args[3]); @@ -394,7 +394,7 @@ protected void sendChatMessage(String message) { protected void setBeginStroke(int playerId, int x, int y, int shootingMode) { this.gameTrackInfoPanel.method384(); - this.gamePlayerInfoPanel.method363(playerId, false); + this.gamePlayerInfoPanel.strokeStartedOrEnded(playerId, false); String data = "beginstroke\t" + this.encodeCoords(x, y, shootingMode); this.gameContainer.connection.writeData("game\t" + data); this.gameContainer.soundManager.playGameMove(); @@ -403,15 +403,15 @@ protected void setBeginStroke(int playerId, int x, int y, int shootingMode) { protected void method336() { String var1 = this.gameCanvas.method142(); if (var1 != null) { - this.gamePlayerInfoPanel.method363(0, false); + this.gamePlayerInfoPanel.strokeStartedOrEnded(0, false); String var2 = "beginstroke\t" + var1; this.gameContainer.connection.writeData("game\t" + var2); this.gameCanvas.decodeCoords(0, true, var1); } } - protected boolean isValidPlayerID(int var1) { - return this.gamePlayerInfoPanel.method361(var1); + protected boolean isValidPlayerID(int player) { + return this.gamePlayerInfoPanel.isOverStrokeLimit(player); } protected void sendEndStroke(int playerid, SynchronizedBool[] settings, int var3) { @@ -419,7 +419,7 @@ protected void sendEndStroke(int playerid, SynchronizedBool[] settings, int var3 for (int index = 0; index < settings.length; ++index) { if (var3 == index && !settings[index].get()) { - this.gamePlayerInfoPanel.method363(index, true); + this.gamePlayerInfoPanel.strokeStartedOrEnded(index, true); data = data + "p"; } else { data = data + (settings[index].get() ? "t" : "f"); @@ -469,18 +469,18 @@ protected void leaveGame() { } protected void rateTrack(int track, int rating) { - String var3 = "rate\t" + track + "\t" + rating; - this.gameContainer.connection.writeData("game\t" + var3); + String message = "rate\t" + track + "\t" + rating; + this.gameContainer.connection.writeData("game\t" + message); } protected void respondNewGame(int track, boolean accept) {// why track - String var3 = "rejectaccept\t" + track + "\t" + (accept ? "t" : "f"); - this.gameContainer.connection.writeData("game\t" + var3); + String message = "rejectaccept\t" + track + "\t" + (accept ? "t" : "f"); + this.gameContainer.connection.writeData("game\t" + message); } - protected void method345(int var1) { - String var2 = "backtoprivate\t" + var1; - this.gameContainer.connection.writeData("game\t" + var2); + protected void backToPrivate(int currentTrack) { + String message = "backtoprivate\t" + currentTrack; + this.gameContainer.connection.writeData("game\t" + message); } protected boolean maxFps() { @@ -499,7 +499,7 @@ public void broadcastMessage(String message) { this.gameChatPanel.addBroadcastMessage(message); } - protected boolean canStroke(boolean stopInfoPanel) { + protected boolean tryStroke(boolean didNotTimeout) { synchronized (canStrokeLock) { if (this.isWaitingForTurnStart) { return false; @@ -508,7 +508,7 @@ protected boolean canStroke(boolean stopInfoPanel) { this.isWaitingForTurnStart = true; } - if (stopInfoPanel) {// ??????????????????????????????????? + if (didNotTimeout) { this.gamePlayerInfoPanel.stopTimer(); } else { this.gameCanvas.doZeroLengthStroke(); @@ -549,13 +549,13 @@ private void addMultiPlayerPanels(int mode) { private void setState(int state) { if (state != this.state) { this.state = state; - this.gamePlayerInfoPanel.method371(state); - this.gameControlPanel.method327(state); + this.gamePlayerInfoPanel.setState(state); + this.gameControlPanel.setState(state); } } - private String encodeCoords(int x, int y, int mod) { - int var4 = x * 375 * 4 + y * 4 + mod;//mod.. or something, possible values 0..3 + private String encodeCoords(int x, int y, int shootingMode) { + int var4 = x * 375 * 4 + y * 4 + shootingMode; String out = Integer.toString(var4, 36); while (out.length() < 4) { diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index 0f600357..3e688e63 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -295,7 +295,8 @@ protected void init(int playerCount, int trackCount, int maxStrokes, int strokeT this.playerReadyForNewGame = new boolean[playerCount]; for (int player = 0; player < playerCount; ++player) { - this.playerNames[player] = this.playerClans[player] = null; + this.playerNames[player] = null; + this.playerClans[player] = null; this.playerLeaveReasons[player] = 0; } @@ -306,7 +307,7 @@ protected void init(int playerCount, int trackCount, int maxStrokes, int strokeT } this.playerId = -1; - this.method359(); + this.reset(); this.initialized = true; this.repaint(); } @@ -344,7 +345,7 @@ protected boolean setPlayerPartStatus(int playerId, int status) { return false; } - protected void method359() { + protected void reset() { for (int player = 0; player < this.playerCount; ++player) { for (int track = 0; track < this.trackCount; ++track) { this.trackStrokes[player][track].set(0); @@ -370,16 +371,16 @@ protected int startNextTrack() { return this.trackScoresMultipliers[this.currentTrackIndex]; } - protected boolean method361(int var1) { + protected boolean isOverStrokeLimit(int player) { if (this.maxStrokes == 0) { return false; } else { - int var2 = this.trackStrokes[var1][this.currentTrackIndex].get(); + int strokes = this.trackStrokes[player][this.currentTrackIndex].get(); if (this.trackScoring == 0) { - var2 /= this.trackScoresMultipliers[this.currentTrackIndex]; + strokes /= this.trackScoresMultipliers[this.currentTrackIndex]; } - return var2 >= this.maxStrokes; + return strokes >= this.maxStrokes; } } @@ -397,7 +398,7 @@ protected boolean startTurn(int playerId) { return playerId == this.playerId; } - protected void method363(int playerId, boolean isStrokeEnd) { + protected void strokeStartedOrEnded(int playerId, boolean isStrokeEnd) { if (this.trackScoring == 0) { int var3 = !isStrokeEnd ? this.trackScoresMultipliers[this.currentTrackIndex] : 1; this.trackStrokes[playerId][this.currentTrackIndex].get_upd(var3); @@ -462,12 +463,12 @@ protected void readyForNewGameLocal() { this.readyForNewGame(this.playerId); } - protected void readyForNewGame(int var1) { - this.playerReadyForNewGame[var1] = true; + protected void readyForNewGame(int player) { + this.playerReadyForNewGame[player] = true; this.repaint(); } - protected void method371(int state) { + protected void setState(int state) { if (state == 2) { for (int player = 0; player < this.playerCount && state == 2; ++player) { if (this.playerLeaveReasons[player] != 0) { @@ -577,7 +578,7 @@ protected boolean run() { --this.currentTimeForShot; this.repaint(); if (this.currentTimeForShot <= 0) { - this.gameContainer.gamePanel.canStroke(false); + this.gameContainer.gamePanel.tryStroke(false); this.stopTimer(); return false; } else { diff --git a/client/src/main/java/agolf/game/GameTrackInfoPanel.java b/client/src/main/java/agolf/game/GameTrackInfoPanel.java index 51c20949..2a147a85 100644 --- a/client/src/main/java/agolf/game/GameTrackInfoPanel.java +++ b/client/src/main/java/agolf/game/GameTrackInfoPanel.java @@ -52,8 +52,8 @@ class GameTrackInfoPanel extends Panel implements ActionListener { private ConfirmButton buttonBack; private boolean hasNotRatedTrack; private boolean trackPending; - private boolean aBoolean436; - private boolean aBoolean437; + private boolean backButtonVisible; + private boolean rButtonVisible; private Image image; private Graphics graphics; private boolean created; @@ -65,7 +65,11 @@ protected GameTrackInfoPanel(GameContainer gameContainer, int width, int height, this.height = height; this.setSize(width, height); this.showLongAvgResult = var4; - this.created = this.hasNotRatedTrack = this.trackPending = this.aBoolean436 = this.aBoolean437 = false; + this.created = false; + this.hasNotRatedTrack = false; + this.trackPending = false; + this.backButtonVisible = false; + this.rButtonVisible = false; this.numTracks = -1; this.resetCurrentTrack(); } @@ -200,8 +204,8 @@ public void actionPerformed(ActionEvent evt) { this.repaint(); } else if (evtSource == this.buttonBack) { - this.gameContainer.gamePanel.method345(this.currentTrack); - this.method390(false); + this.gameContainer.gamePanel.backToPrivate(this.currentTrack); + this.setBackButtonVisible(false); this.repaint(); } else if (evtSource == this.buttonR) { this.gameContainer.gamePanel.method336(); @@ -262,18 +266,17 @@ protected void parseTrackInfoStats(String trackAuthor, String trackName, int[] p this.setHasNotRatedTrack(true); } else { this.toggleAcceptRejectButtons(trackTestMode1); - this.method390(trackTestMode2); - this.method391(var9); + this.setBackButtonVisible(trackTestMode2); + this.setRButtonVisible(var9); } this.repaint(); } protected void method384() { - if (this.aBoolean437) { - this.method391(false); + if (this.rButtonVisible) { + this.setRButtonVisible(false); } - } protected int method385() { @@ -312,22 +315,22 @@ private void create() { this.buttonR.addActionListener(this); } - private String[] parseBestPlayerInformation(String var1) { - String[] var2 = new String[]{null, null}; - if (var1 != null) { - int var3 = var1.indexOf(44); - var2[0] = var1.substring(0, var3); - var2[1] = var1.substring(var3 + 1); - var3 = var2[1].indexOf(44); - if (var3 > 0) { - var2[1] = var2[1].substring(0, var3); + private String[] parseBestPlayerInformation(String data) { + String[] bestPlayerInformation = new String[]{null, null}; + if (data != null) { + int splitPosition = data.indexOf(','); + bestPlayerInformation[0] = data.substring(0, splitPosition); + bestPlayerInformation[1] = data.substring(splitPosition + 1); + splitPosition = bestPlayerInformation[1].indexOf(','); + if (splitPosition > 0) { + bestPlayerInformation[1] = bestPlayerInformation[1].substring(0, splitPosition); } - long var4 = Long.parseLong(var2[1]); - var2[1] = this.gameContainer.textManager.getDateWithTodayYesterday(var4); + long bestPlayerTimestamp = Long.parseLong(bestPlayerInformation[1]); + bestPlayerInformation[1] = this.gameContainer.textManager.getDateWithTodayYesterday(bestPlayerTimestamp); } - return var2; + return bestPlayerInformation; } private void setHasNotRatedTrack(boolean hasNotRatedTrack) { @@ -366,12 +369,12 @@ private void toggleAcceptRejectButtons(boolean trackPending) { } } - private void method390(boolean var1) { + private void setBackButtonVisible(boolean backButtonVisible) { if (!this.gameContainer.safeMode) { - if (var1 != this.aBoolean436) { - this.aBoolean436 = var1; + if (backButtonVisible != this.backButtonVisible) { + this.backButtonVisible = backButtonVisible; this.setVisible(false); - if (var1) { + if (backButtonVisible) { this.add(this.buttonBack); } else { this.remove(this.buttonBack); @@ -382,11 +385,11 @@ private void method390(boolean var1) { } } - private void method391(boolean var1) { - if (var1 != this.aBoolean437) { - this.aBoolean437 = var1; + private void setRButtonVisible(boolean rButtonVisible) { + if (rButtonVisible != this.rButtonVisible) { + this.rButtonVisible = rButtonVisible; this.setVisible(false); - if (var1) { + if (rButtonVisible) { this.add(this.buttonR); } else { this.remove(this.buttonR); diff --git a/server/src/main/java/org/moparforia/server/game/gametypes/GolfGame.java b/server/src/main/java/org/moparforia/server/game/gametypes/GolfGame.java index 38d20868..546541bf 100644 --- a/server/src/main/java/org/moparforia/server/game/gametypes/GolfGame.java +++ b/server/src/main/java/org/moparforia/server/game/gametypes/GolfGame.java @@ -122,9 +122,7 @@ protected void reset() { public void startGame() { writeAll(new Packet(PacketType.DATA, Tools.tabularize("game", "start"))); StringBuilder buff = new StringBuilder(); - for (int i = 0; i < getPlayers().size(); i++) { - buff.append("t"); - } + buff.append("t".repeat(getPlayers().size())); playStatus = buff.toString().replace("t", "f"); TrackStats track = statsManager.getStats(tracks.get(0)); writeAll(new Packet(PacketType.DATA, Tools.tabularize("game", "resetvoteskip"))); From 641457bd6487d0429d2e4054bd5d6eb961ccc5c4 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 10/16] Deobfuscate code around map parsing and rendering --- .../java/agolf/game/GameBackgroundCanvas.java | 69 +++++---- .../src/main/java/agolf/game/GameCanvas.java | 145 +++++++++--------- .../src/main/java/agolf/game/GamePanel.java | 44 +++--- 3 files changed, 130 insertions(+), 128 deletions(-) diff --git a/client/src/main/java/agolf/game/GameBackgroundCanvas.java b/client/src/main/java/agolf/game/GameBackgroundCanvas.java index 8bfcf0a7..7d8d59f5 100644 --- a/client/src/main/java/agolf/game/GameBackgroundCanvas.java +++ b/client/src/main/java/agolf/game/GameBackgroundCanvas.java @@ -18,7 +18,7 @@ public class GameBackgroundCanvas extends Canvas { protected GameContainer gameContainer; private Image backgroundImg; protected Image image; - private Graphics aGraphics85; + private Graphics graphics; private String trackAuthor; private String trackName; private String trackComment; @@ -86,11 +86,11 @@ protected void createMap(int var1) { this.image = this.backgroundImg; } - this.aGraphics85 = this.image.getGraphics(); + this.graphics = this.image.getGraphics(); } Image var2 = this.gameContainer.imageManager.createImage(this.gameContainer.spriteManager.getPixelsFromTileCode(var1), 15, 15); - this.aGraphics85.setColor(aColor75); + this.graphics.setColor(aColor75); for (int y = 0; y < 25; ++y) { @@ -98,9 +98,9 @@ protected void createMap(int var1) { this.trackTiles[x][y] = var1; if (var1 == 0) { - this.aGraphics85.fillRect(x * 15, y * 15, 15, 15); + this.graphics.fillRect(x * 15, y * 15, 15, 15); } else { - this.aGraphics85.drawImage(var2, x * 15, y * 15, this); + this.graphics.drawImage(var2, x * 15, y * 15, this); } } } @@ -109,10 +109,10 @@ protected void createMap(int var1) { this.repaint(); } - protected boolean parseMapCommands(String var1) { + protected boolean parseMapCommands(String map) { try { - return this.parseMapInstruction(var1); - } catch (Exception var3) { + return this.parseMapInstruction(map); + } catch (Exception e) { return false; } } @@ -134,7 +134,7 @@ protected Image getTileAt(int var1, int var2) { } Image var7 = this.gameContainer.imageManager.createImage(imageData, 15, 15); - this.aGraphics85.drawImage(var7, var1 * 15, var2 * 15, this); + this.graphics.drawImage(var7, var1 * 15, var2 * 15, this); return var7; } @@ -212,22 +212,25 @@ protected boolean[] method120() { return this.aBooleanArray98; } - private boolean parseMapInstruction(String var1) throws Exception { + private boolean parseMapInstruction(String map) throws Exception { this.trackSettings = defaultTrackSettings; - this.trackFirstBest = this.trackLastBest = this.trackComment = null; - this.trackStats = this.trackRatings = null; - - StringTokenizer tknzr = new StringTokenizer(var1, "\n"); - int shiet = 0; - while(tknzr.hasMoreTokens()) { - String line = tknzr.nextToken(); + this.trackFirstBest = null; + this.trackLastBest = null; + this.trackComment = null; + this.trackStats = null; + this.trackRatings = null; + + StringTokenizer tokenizer = new StringTokenizer(map, "\n"); + int requiredLinesParsed = 0; + while(tokenizer.hasMoreTokens()) { + String line = tokenizer.nextToken(); if(line.startsWith("V ") && Integer.parseInt(line.substring(2)) == 1) { - shiet++; + requiredLinesParsed++; } else if(line.startsWith("A ")) { - shiet++; + requiredLinesParsed++; this.trackAuthor = line.substring(2).trim(); } else if(line.startsWith("N ")) { - shiet++; + requiredLinesParsed++; this.trackName = line.substring(2).trim(); } else if(line.startsWith("C ")) { this.trackComment = line.substring(2).trim(); @@ -256,19 +259,19 @@ private boolean parseMapInstruction(String var1) throws Exception { } else if(line.startsWith("L ")) { this.trackLastBest = line.substring(2); } else if(line.startsWith("R ")) { - StringTokenizer subtknzr = new StringTokenizer(line.substring(2), ","); - if(subtknzr.countTokens() != 11) { + StringTokenizer subTokenizer = new StringTokenizer(line.substring(2), ","); + if(subTokenizer.countTokens() != 11) { return false; } this.trackRatings = new int[11]; for(int i = 0; i < 11; i++) { - this.trackRatings[i] = Integer.parseInt(subtknzr.nextToken()); + this.trackRatings[i] = Integer.parseInt(subTokenizer.nextToken()); } } else if(line.startsWith("T ")) { - shiet++; - /** + requiredLinesParsed++; + /* * - * The below is the map parsing shit + * The below is the map parsing: * firstly the input map is "expanded", any letter preceeding by a number is duplicated that number times. * If input letter is A,B,C, the letter + the next three are concatenated into one int (4 * bytes) * If input letters are D,E,F,G,H,I, the current tile is exactly the same as an adjacent one so @@ -278,8 +281,8 @@ private boolean parseMapInstruction(String var1) throws Exception { */ String mapData = line.substring(2); - StringTokenizer subtknzr = new StringTokenizer(mapData, ","); - mapData = this.expandMap(subtknzr.nextToken()); + StringTokenizer subTokenizer = new StringTokenizer(mapData, ","); + mapData = this.expandMap(subTokenizer.nextToken()); int cursorIndex = 0; int tileX; @@ -343,8 +346,8 @@ private boolean parseMapInstruction(String var1) throws Exception { int var12; int var14; - if (subtknzr.hasMoreTokens()) { - mapData = subtknzr.nextToken(); + if (subTokenizer.hasMoreTokens()) { + mapData = subTokenizer.nextToken(); if (!mapData.startsWith("Ads:")) { return false; } @@ -360,7 +363,7 @@ private boolean parseMapInstruction(String var1) throws Exception { } } } - if(shiet != 4) { + if(requiredLinesParsed != 4) { return false; } @@ -656,11 +659,11 @@ private void drawMap() { var20 = 0; } } - } catch (OutOfMemoryError var24) { + } catch (OutOfMemoryError e) { ; } - this.aGraphics85.drawImage(this.gameContainer.imageManager.createImage(mapPixels, 735, 375), 0, 0, this); + this.graphics.drawImage(this.gameContainer.imageManager.createImage(mapPixels, 735, 375), 0, 0, this); } private boolean castsShadow(int x, int y) { diff --git a/client/src/main/java/agolf/game/GameCanvas.java b/client/src/main/java/agolf/game/GameCanvas.java index 2280c77d..031c671a 100644 --- a/client/src/main/java/agolf/game/GameCanvas.java +++ b/client/src/main/java/agolf/game/GameCanvas.java @@ -35,14 +35,14 @@ public class GameCanvas extends GameBackgroundCanvas implements Runnable, MouseM private int mouseY; private int shootingMode; private int anInt2816; - private double aDouble2817; - private double aDouble2818; + private double startPositionX; + private double startPositionY; private double bounciness; private double somethingSpeedThing; private double[] resetPositionX; private double[] resetPositionY; - private Vector[] teleportStarts; - private Vector[] teleportExists; + private Vector[] teleportStarts; + private Vector[] teleportExists; private short[][][] magnetMap; private double[] playerX; private double[] playerY; @@ -130,12 +130,12 @@ public void update(Graphics g) { for (int player = 0; player < this.playerCount; ++player) { if (this.aBooleanArray2830[player] && player != this.currentPlayerID) { - this.drawPlayerInfo(this.graphics, player, this.onHoleSync[player].get() ? 2.1666666666666665D : 0.0D); + this.drawPlayer(this.graphics, player, this.onHoleSync[player].get() ? 2.1666666666666665D : 0.0D); } } this.graphics.setColor(whiteColour); - this.drawPlayerInfo(this.graphics, this.currentPlayerID, this.onHoleSync[this.currentPlayerID].get() ? 2.1666666666666665D : 0.0D); + this.drawPlayer(this.graphics, this.currentPlayerID, this.onHoleSync[this.currentPlayerID].get() ? 2.1666666666666665D : 0.0D); } if (isCheating) { @@ -168,14 +168,14 @@ public void run() { boolean[] teleported = new boolean[this.playerCount]; int[] spinningStuckCounter = new int[this.playerCount]; - for (int var19 = 0; var19 < this.playerCount; ++var19) { - magnetStuckCounter[var19] = downhillStuckCounter[var19] = 0; - tempCoordX[var19] = tempCoord2X[var19] = this.playerX[var19]; - tempCoordY[var19] = tempCoord2Y[var19] = this.playerY[var19]; - onHole[var19] = onLiquidOrSwamp[var19] = false; - var10[var19] = this.onHoleSync[var19].get() ? 2.1666666666666665D : 0.0D; - teleported[var19] = false; - spinningStuckCounter[var19] = 0; + for (int player = 0; player < this.playerCount; ++player) { + magnetStuckCounter[player] = downhillStuckCounter[player] = 0; + tempCoordX[player] = tempCoord2X[player] = this.playerX[player]; + tempCoordY[player] = tempCoord2Y[player] = this.playerY[player]; + onHole[player] = onLiquidOrSwamp[player] = false; + var10[player] = this.onHoleSync[player].get() ? 2.1666666666666665D : 0.0D; + teleported[player] = false; + spinningStuckCounter[player] = 0; } boolean shouldSpinAroundHole = false; @@ -486,11 +486,11 @@ public void run() { for (int j = 0; j < this.playerCount; ++j) { if (this.aBooleanArray2830[j] && j != this.currentPlayerID) { - this.drawPlayerInfo(ballGraphic, j, var10[j]); + this.drawPlayer(ballGraphic, j, var10[j]); } } - this.drawPlayerInfo(ballGraphic, this.currentPlayerID, var10[this.currentPlayerID]); + this.drawPlayer(ballGraphic, this.currentPlayerID, var10[this.currentPlayerID]); if (this.playerX[i] < tempCoord3X[i]) { x1 = (int) (this.playerX[i] - 6.5D + 0.5D); } @@ -672,106 +672,103 @@ protected void createMap(int var1) { this.repaint(); } - protected boolean parseMap(String commandLines, String var2, int var3) { - boolean var4 = super.parseMapCommands(commandLines); + protected boolean init(String commandLines, String playerStatuses, int gameId) { + boolean parseSuccessful = super.parseMapCommands(commandLines); this.aString2835 = null; - StringTokenizer commnadTokens = new StringTokenizer(commandLines, "\n"); + StringTokenizer commandTokens = new StringTokenizer(commandLines, "\n"); - int var10; - while (commnadTokens.hasMoreTokens()) { - String currentCommand = commnadTokens.nextToken(); + while (commandTokens.hasMoreTokens()) { + String currentCommand = commandTokens.nextToken(); char commandType = currentCommand.charAt(0); if (commandType == 'B' || commandType == 'L') { - int var8 = currentCommand.indexOf(','); - int var9 = currentCommand.indexOf(',', var8 + 1); - var10 = currentCommand.indexOf(',', var9 + 1); + int recordHolderName = currentCommand.indexOf(','); + int recordTimestamp = currentCommand.indexOf(',', recordHolderName + 1); + int var10 = currentCommand.indexOf(',', recordTimestamp + 1); currentCommand = currentCommand.substring(var10 + 1); int var11 = currentCommand.indexOf('='); if (var11 > -1) { - var3 = Integer.parseInt(currentCommand.substring(0, var11)); + gameId = Integer.parseInt(currentCommand.substring(0, var11)); this.aString2835 = currentCommand.substring(var11 + 1); } } } - Vector startPosition = new Vector(); + Vector startPositions = new Vector<>(); this.resetPositionX = new double[4]; this.resetPositionY = new double[4]; this.teleportExists = new Vector[4]; this.teleportStarts = new Vector[4]; - Vector magnetVec = new Vector(); + Vector magnetVec = new Vector<>(); - for (var10 = 0; var10 < 4; ++var10) { - this.resetPositionX[var10] = this.resetPositionY[var10] = -1.0D; - this.teleportExists[var10] = new Vector(); - this.teleportStarts[var10] = new Vector(); + for (int i = 0; i < 4; ++i) { + this.resetPositionX[i] = this.resetPositionY[i] = -1.0D; + this.teleportExists[i] = new Vector<>(); + this.teleportStarts[i] = new Vector<>(); } - int x; - double[] element; // Iterates over the 49*25 map for (int y = 0; y < 25; ++y) { - for (x = 0; x < 49; ++x) { + for (int x = 0; x < 49; ++x) { if (super.trackTiles[x][y] / 16777216 == 2) { - int var14 = super.trackTiles[x][y] / 65536 % 256 + 24; + int tile = super.trackTiles[x][y] / 65536 % 256 + 24; double screenX = (double) (x * 15) + 7.5D; double screenY = (double) (y * 15) + 7.5D; //24 Start Position Common - if (var14 == 24) { - element = new double[]{screenX, screenY}; - startPosition.addElement(element); + if (tile == 24) { + double[] startPosition = new double[]{screenX, screenY}; + startPositions.addElement(startPosition); } //48 Start Position Blue //49 Start Position Red //50 Start Positiono Yellow //51 Start Position Green - if (var14 >= 48 && var14 <= 51) { - this.resetPositionX[var14 - 48] = screenX; - this.resetPositionY[var14 - 48] = screenY; + if (tile >= 48 && tile <= 51) { + this.resetPositionX[tile - 48] = screenX; + this.resetPositionY[tile - 48] = screenY; } - int var20; + int teleportIndex; //33 Teleport Exit Blue //35 Teleport Exit Red //37 Teleport Exit Yellow //39 Teleport Exit Green - if (var14 == 33 || var14 == 35 || var14 == 37 || var14 == 39) { - var20 = (var14 - 33) / 2; - element = new double[]{screenX, screenY}; - this.teleportExists[var20].addElement(element); + if (tile == 33 || tile == 35 || tile == 37 || tile == 39) { + teleportIndex = (tile - 33) / 2; + double[] teleporter = new double[]{screenX, screenY}; + this.teleportExists[teleportIndex].addElement(teleporter); } //33 Teleport Start Blue //35 Teleport Start Red //37 Teleport Start Yellow //39 Teleport Start Green - if (var14 == 32 || var14 == 34 || var14 == 36 || var14 == 38) { - var20 = (var14 - 32) / 2; - element = new double[]{screenX, screenY}; - this.teleportStarts[var20].addElement(element); + if (tile == 32 || tile == 34 || tile == 36 || tile == 38) { + teleportIndex = (tile - 32) / 2; + double[] teleporter = new double[]{screenX, screenY}; + this.teleportStarts[teleportIndex].addElement(teleporter); } //44 magnet attract //45 magnet repel - if (var14 == 44 || var14 == 45) { - int[] var43 = new int[]{(int) (screenX + 0.5D), (int) (screenY + 0.5D), var14}; - magnetVec.addElement(var43); + if (tile == 44 || tile == 45) { + int[] magnet = new int[]{(int) (screenX + 0.5D), (int) (screenY + 0.5D), tile}; + magnetVec.addElement(magnet); } } } } - x = startPosition.size(); - if (x == 0) { - this.aDouble2817 = this.aDouble2818 = -1.0D; + int startPositionsCount = startPositions.size(); + if (startPositionsCount == 0) { + this.startPositionX = this.startPositionY = -1.0D; } else { - element = (double[]) startPosition.elementAt(var3 % x); - this.aDouble2817 = element[0]; - this.aDouble2818 = element[1]; + double[] startPosition = startPositions.elementAt(gameId % startPositionsCount); + this.startPositionX = startPosition[0]; + this.startPositionY = startPosition[1]; } int magnetVecLen = magnetVec.size(); @@ -837,12 +834,12 @@ protected boolean parseMap(String commandLines, String var2, int var3) { this.aBooleanArray2834[i] = true; this.resetPosition(i, true); this.onHoleSync[i].set(false); - this.aBooleanArray2830[i] = var2.charAt(i) == 't'; + this.aBooleanArray2830[i] = playerStatuses.charAt(i) == 't'; } - this.rngSeed = new Seed((long) var3); + this.rngSeed = new Seed(gameId); this.repaint(); - return var4; + return parseSuccessful; } protected boolean method134() { @@ -1015,7 +1012,7 @@ private void doHackedStroke(int playerId, boolean isLocalPlayer, int mouseX, int HackedShot hs = new HackedShot(playerCount, onShoreSetting, collisionMode, currentPlayerID, temp_anInt2816, - aDouble2817, aDouble2818, bounciness, somethingSpeedThing, resetPositionX, resetPositionY, + startPositionX, startPositionY, bounciness, somethingSpeedThing, resetPositionX, resetPositionY, teleportStarts, teleportExists, magnetMap, playerX, playerY, temp_aDoubleArray2828, temp_aDoubleArray2829, aBooleanArray2830, onHoleSync, temp_aBoolean2832, aBooleanArray2834, temp_aSeed_2836, anInt2839, temp_aBoolean2843, super.collisionMap, super.trackTiles); @@ -1034,14 +1031,14 @@ private void doHackedStroke(int playerId, boolean isLocalPlayer, int mouseX, int } - private void resetPosition(int playerId, boolean var2) { + private void resetPosition(int playerId, boolean gameStart) { if (this.resetPositionX[playerId] >= 0.0D && this.resetPositionX[playerId] >= 0.0D) { this.playerX[playerId] = this.resetPositionX[playerId]; this.playerY[playerId] = this.resetPositionY[playerId]; - } else if (this.aDouble2817 >= 0.0D && this.aDouble2818 >= 0.0D) { - this.playerX[playerId] = this.aDouble2817; - this.playerY[playerId] = this.aDouble2818; - if (var2) { + } else if (this.startPositionX >= 0.0D && this.startPositionY >= 0.0D) { + this.playerX[playerId] = this.startPositionX; + this.playerY[playerId] = this.startPositionY; + if (gameStart) { this.aBooleanArray2834[playerId] = false; } @@ -1602,7 +1599,7 @@ private void drawTile(int tileX, int tileY, Graphics var3, Graphics var4) { var4.drawImage(tile, tileX * 15, tileY * 15, this); } - private void drawPlayerInfo(Graphics g, int playerid, double var3) { + private void drawPlayer(Graphics g, int playerid, double var3) { int x = (int) (this.playerX[playerid] - 6.5D + 0.5D); int y = (int) (this.playerY[playerid] - 6.5D + 0.5D); int var7 = 13; @@ -1612,13 +1609,13 @@ private void drawPlayerInfo(Graphics g, int playerid, double var3) { var7 = (int) ((double) var7 - var3 * 2.0D); } - int var8 = 0; + int ballSpriteOffset = 0; if (super.gameContainer.graphicsQualityIndex == 3) { - var8 = (x / 5 + y / 5) % 2 * 4; + ballSpriteOffset = (x / 5 + y / 5) % 2 * 4; } if (var3 == 0.0D) { - g.drawImage(this.ballSprites[playerid + var8], x, y, this); + g.drawImage(this.ballSprites[playerid + ballSpriteOffset], x, y, this); if (this.playerNamesDisplayMode > 0 && this.aBooleanArray2834[playerid] && this.gameState != 2 && this.playerCount > 1) { String[] playerName = super.gameContainer.gamePanel.getPlayerName(playerid); if (this.playerNamesDisplayMode == 1) { @@ -1649,7 +1646,7 @@ private void drawPlayerInfo(Graphics g, int playerid, double var3) { StringDraw.drawOutlinedString(g, backgroundColour, playerName[0], textX, y + 13 - 3, -1); } } else { - g.drawImage(this.ballSprites[playerid + var8], x, y, x + var7, y + var7, 0, 0, 13, 13, this); + g.drawImage(this.ballSprites[playerid + ballSpriteOffset], x, y, x + var7, y + var7, 0, 0, 13, 13, this); } } diff --git a/client/src/main/java/agolf/game/GamePanel.java b/client/src/main/java/agolf/game/GamePanel.java index dba8976a..fc56496b 100644 --- a/client/src/main/java/agolf/game/GamePanel.java +++ b/client/src/main/java/agolf/game/GamePanel.java @@ -224,7 +224,9 @@ else if (args[1].equals("part")) { // player left game this.setState(1); } else if (args[1].equals("starttrack")) { - /**game + // [1] = "startrack", (optional [2] == track test mode), [2 or 3] == player statuses, [3 or 4] == game id, [4 or 5] == track data + /* + * game * starttrack * t 1908821 * V 1 @@ -256,20 +258,20 @@ else if (args[1].equals("starttrack")) { String fullInstruction = ""; for (int commandIndex = startIndex; commandIndex < argsLen; ++commandIndex) { - char var12 = args[commandIndex].charAt(0); - if (var12 == 'A') { + char command = args[commandIndex].charAt(0); + if (command == 'A') { author = args[commandIndex].substring(2); } - if (var12 == 'N') { + if (command == 'N') { name = args[commandIndex].substring(2); } - if (var12 == 'T') { + if (command == 'T') { data = args[commandIndex].substring(2); } - if (var12 == 'T' && args[commandIndex].charAt(2) == '!') {// a track we already played? + if (command == 'T' && args[commandIndex].charAt(2) == '!') {// a track we already played? args[commandIndex] = "T " + this.gameContainer.trackCollection.getTrack(author, name); hasPlayed = true; } @@ -287,21 +289,21 @@ else if (args[1].equals("starttrack")) { this.gameContainer.trackCollection.addTrack(author, name, data); } - this.gameCanvas.parseMap(fullInstruction, args[trackTestMode ? 3 : 2], Integer.parseInt(args[trackTestMode ? 4 : 3])); - - /* trackinformatino - [0]=author, [1]=trackname, [2]=firstbest, [3]=lastbest - - statistics: - var15[0][0]= number completeed - var15[0][1]= total attempts - var15[0][2]= best par (stroke count) - var15[0][3]= number of best par strokes - var15[1][0]= number of ratings: 0 - var15[1][1]= number of ratings: 1 - var15[1][2]= number of ratings: 2 - var15[1][3]= number of ratings: 3 - */ + this.gameCanvas.init(fullInstruction, args[trackTestMode ? 3 : 2], Integer.parseInt(args[trackTestMode ? 4 : 3])); + + /* trackinformation + [0]=author, [1]=trackname, [2]=firstbest, [3]=lastbest + + statistics: + var15[0][0]= number completeed + var15[0][1]= total attempts + var15[0][2]= best par (stroke count) + var15[0][3]= number of best par strokes + var15[1][0]= number of ratings: 0 + var15[1][1]= number of ratings: 1 + var15[1][2]= number of ratings: 2 + var15[1][3]= number of ratings: 3 + */ String[] trackInformation = this.gameCanvas.generateTrackInformation(); int[][] trackStats = this.gameCanvas.generateTrackStatistics(); From 74fec6e024cc8c684f15187c48f8d8e395ddc7a3 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 11/16] Invert boolean parameter in tryStroke This is easier to understand than a double negative. No functional changes. --- client/src/main/java/agolf/game/GameCanvas.java | 2 +- client/src/main/java/agolf/game/GamePanel.java | 8 ++++---- client/src/main/java/agolf/game/GamePlayerInfoPanel.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/main/java/agolf/game/GameCanvas.java b/client/src/main/java/agolf/game/GameCanvas.java index 031c671a..350e092c 100644 --- a/client/src/main/java/agolf/game/GameCanvas.java +++ b/client/src/main/java/agolf/game/GameCanvas.java @@ -593,7 +593,7 @@ public synchronized void mousePressed(MouseEvent event) { this.removeMouseListener(this); this.removeKeyListener(this); this.setCursor(cursorDefault); - if (super.gameContainer.gamePanel.tryStroke(true)) { + if (super.gameContainer.gamePanel.tryStroke(false)) { super.gameContainer.gamePanel.setBeginStroke(this.currentPlayerID, x, y, this.shootingMode); //this.doHackedStroke(this.currentPlayerID, true, x, y, this.keyCountMod4); this.doStroke(this.currentPlayerID, true, x, y, this.shootingMode); diff --git a/client/src/main/java/agolf/game/GamePanel.java b/client/src/main/java/agolf/game/GamePanel.java index fc56496b..987d386b 100644 --- a/client/src/main/java/agolf/game/GamePanel.java +++ b/client/src/main/java/agolf/game/GamePanel.java @@ -501,7 +501,7 @@ public void broadcastMessage(String message) { this.gameChatPanel.addBroadcastMessage(message); } - protected boolean tryStroke(boolean didNotTimeout) { + protected boolean tryStroke(boolean didTimeout) { synchronized (canStrokeLock) { if (this.isWaitingForTurnStart) { return false; @@ -510,10 +510,10 @@ protected boolean tryStroke(boolean didNotTimeout) { this.isWaitingForTurnStart = true; } - if (didNotTimeout) { - this.gamePlayerInfoPanel.stopTimer(); - } else { + if (didTimeout) { this.gameCanvas.doZeroLengthStroke(); + } else { + this.gamePlayerInfoPanel.stopTimer(); } return true; diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index 3e688e63..941e515f 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -578,7 +578,7 @@ protected boolean run() { --this.currentTimeForShot; this.repaint(); if (this.currentTimeForShot <= 0) { - this.gameContainer.gamePanel.tryStroke(false); + this.gameContainer.gamePanel.tryStroke(true); this.stopTimer(); return false; } else { From 1021c9be12acd698b476fced56447d414fd2fcc9 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 12/16] Deobfuscate TextManager This class works in a similar way to SoundManager, it contains a map for localization strings that are specific to Minigolf as well as a map for strings that were shared between multiple Playforia games. As part of this I renamed Class89 -> LocalizationNode which represents an XML node containing translations for a single entry. --- .../java/com/aapeli/client/BadWordFilter.java | 2 +- .../main/java/com/aapeli/client/Class89.java | 46 -- .../com/aapeli/client/LocalizationNode.java | 45 ++ .../java/com/aapeli/client/TextManager.java | 651 +++++++++--------- 4 files changed, 372 insertions(+), 372 deletions(-) delete mode 100644 client/src/main/java/com/aapeli/client/Class89.java create mode 100644 client/src/main/java/com/aapeli/client/LocalizationNode.java diff --git a/client/src/main/java/com/aapeli/client/BadWordFilter.java b/client/src/main/java/com/aapeli/client/BadWordFilter.java index 89f41076..444fc495 100644 --- a/client/src/main/java/com/aapeli/client/BadWordFilter.java +++ b/client/src/main/java/com/aapeli/client/BadWordFilter.java @@ -38,7 +38,7 @@ protected BadWordFilter(TextManager var1, boolean var2, String var3) { this.aString1342 = aString1335; this.aString1343 = aString1336; - if (var1.method1719().equalsIgnoreCase("fi")) { + if (var1.getLanguage().equalsIgnoreCase("fi")) { this.aString1342 = this.aString1342 + "bdgw"; this.aString1343 = this.aString1343 + "ptkv"; } diff --git a/client/src/main/java/com/aapeli/client/Class89.java b/client/src/main/java/com/aapeli/client/Class89.java deleted file mode 100644 index 38684132..00000000 --- a/client/src/main/java/com/aapeli/client/Class89.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.aapeli.client; - -import com.aapeli.client.TextManager; -import com.aapeli.tools.Tools; -import com.aapeli.tools.XmlUnit; - -class Class89 { - - private String aString1527; - private String aString1528; - private String aString1529; - private String aString1530; - private final TextManager aTextManager1531; - - - protected Class89(TextManager var1, String var2, XmlUnit var3, boolean var4) { - this.aTextManager1531 = var1; - this.aString1527 = var2.substring(0, 2).toLowerCase(); - this.aString1528 = var3.getChildValue("singular"); - this.aString1529 = var3.getChildValue("plural"); - this.aString1530 = var3.getChildValue("zero"); - if (var4) { - this.aString1528 = Tools.reverse(this.aString1528); - this.aString1529 = Tools.reverse(this.aString1529); - this.aString1530 = Tools.reverse(this.aString1530); - } - - } - - protected String method1737(int var1) { - if (var1 == 0) { - if (this.aString1530 != null) { - return this.aString1530; - } - - if (this.aString1529 != null && !this.aString1527.equals("fr")) { - return this.aString1529; - } - } else if ((var1 < 0 || var1 > 1) && this.aString1529 != null) { - return this.aString1529; - } - - return this.aString1528; - } - -} diff --git a/client/src/main/java/com/aapeli/client/LocalizationNode.java b/client/src/main/java/com/aapeli/client/LocalizationNode.java new file mode 100644 index 00000000..59d16f56 --- /dev/null +++ b/client/src/main/java/com/aapeli/client/LocalizationNode.java @@ -0,0 +1,45 @@ +package com.aapeli.client; + +import com.aapeli.tools.Tools; +import com.aapeli.tools.XmlUnit; + +class LocalizationNode { + + private String language; + private String singular; + private String plural; + private String zero; + private final TextManager textManager; + + + protected LocalizationNode(TextManager textManager, String language, XmlUnit unit, boolean reversed) { + this.textManager = textManager; + this.language = language.substring(0, 2).toLowerCase(); + this.singular = unit.getChildValue("singular"); + this.plural = unit.getChildValue("plural"); + this.zero = unit.getChildValue("zero"); + if (reversed) { + this.singular = Tools.reverse(this.singular); + this.plural = Tools.reverse(this.plural); + this.zero = Tools.reverse(this.zero); + } + + } + + protected String getLocalization(int quantity) { + if (quantity == 0) { + if (this.zero != null) { + return this.zero; + } + + if (this.plural != null && !this.language.equals("fr")) { + return this.plural; + } + } else if ((quantity < 0 || quantity > 1) && this.plural != null) { + return this.plural; + } + + return this.singular; + } + +} diff --git a/client/src/main/java/com/aapeli/client/TextManager.java b/client/src/main/java/com/aapeli/client/TextManager.java index 7d033d47..a60ab9a2 100644 --- a/client/src/main/java/com/aapeli/client/TextManager.java +++ b/client/src/main/java/com/aapeli/client/TextManager.java @@ -18,136 +18,136 @@ public final class TextManager implements Runnable { - private Parameters aParameters1512; - private Thread aThread1513; - private String aString1514; - private Hashtable aHashtable1515; - private Hashtable aHashtable1516; - private String aString1517; - private boolean aBoolean1518; - private boolean aBoolean1519; + private Parameters parameters; + private Thread textLoaderThread; + private String language; + private Hashtable gameTable; + private Hashtable sharedTable; + private String errorMessage; + private boolean useLanguageFiles; // true == use language xml files, false == use locale .loc files + private boolean debug; - public TextManager(Applet var1, String var2) { - this(var1, var2, false); + public TextManager(Applet applet, String var2) { + this(applet, var2, false); } - public TextManager(Applet var1, String var2, boolean var3) { - this(var3); - this.aString1514 = var2; - this.aBoolean1518 = false; - this.method1731(var1); + public TextManager(Applet applet, String var2, boolean debug) { + this(debug); + this.language = var2; + this.useLanguageFiles = false; + this.loadTexts(applet); } - public TextManager(Parameters var1) { - this(var1, false, false); + public TextManager(Parameters parameters) { + this(parameters, false, false); } - public TextManager(Parameters var1, boolean var2) { - this(var1, false, var2); + public TextManager(Parameters parameters, boolean debug) { + this(parameters, false, debug); } - public TextManager(Parameters var1, boolean var2, boolean var3) { - this(var3); - this.aParameters1512 = var1; - String var4 = var1.getTranslationLang(); - if (var4 != null) { - this.aString1514 = var4; - this.aBoolean1518 = true; + public TextManager(Parameters parameters, boolean loadTextsInSeparateThread, boolean debug) { + this(debug); + this.parameters = parameters; + String language = parameters.getTranslationLang(); + if (language != null) { + this.language = language; + this.useLanguageFiles = true; } else { - this.aString1514 = var1.getLocale(); - this.aBoolean1518 = false; + this.language = parameters.getLocale(); + this.useLanguageFiles = false; } - if (var2) { - this.aThread1513 = new Thread(this); - this.aThread1513.start(); + if (loadTextsInSeparateThread) { + this.textLoaderThread = new Thread(this); + this.textLoaderThread.start(); } else { - this.method1731(var1.getApplet()); + this.loadTexts(parameters.getApplet()); } } - private TextManager(boolean var1) { - this.aBoolean1519 = var1; - this.aHashtable1515 = new Hashtable(); - this.aHashtable1516 = new Hashtable(); - this.aString1517 = null; - this.aThread1513 = null; + private TextManager(boolean debug) { + this.debug = debug; + this.gameTable = new Hashtable(); + this.sharedTable = new Hashtable(); + this.errorMessage = null; + this.textLoaderThread = null; } public void run() { - if (this.aBoolean1519) { + if (this.debug) { System.out.println("TextManager.run(): Start loading texts"); } - this.method1731(this.aParameters1512.getApplet()); - this.aThread1513 = null; - if (this.aBoolean1519) { + this.loadTexts(this.parameters.getApplet()); + this.textLoaderThread = null; + if (this.debug) { System.out.println("TextManager.run(): Finished loading texts"); } } - public String getGame(String var1) { - return this.getGame(var1, (String[]) null); + public String getGame(String key) { + return this.getGame(key, (String[]) null); } - public boolean isAvailable(String var1) { - return this.method1729(var1, 1) != null; + public boolean isAvailable(String key) { + return this.getText(key, 1) != null; } - public String getIfAvailable(String var1) { - return this.getIfAvailable(var1, (String) null); + public String getIfAvailable(String key) { + return this.getIfAvailable(key, null); } - public String getIfAvailable(String var1, String var2) { - String var3 = this.method1729(var1, 1); - return var3 != null ? var3 : var2; + public String getIfAvailable(String key, String fallback) { + String result = this.getText(key, 1); + return result != null ? result : fallback; } - public String getGame(String var1, String var2) { - String[] var3 = new String[]{var2}; - return this.getGame(var1, var3); + public String getGame(String key, String argument1) { + String[] arguments = new String[]{argument1}; + return this.getGame(key, arguments); } - public String getGame(String var1, String var2, String var3) { - String[] var4 = new String[]{var2, var3}; - return this.getGame(var1, var4); + public String getGame(String key, String var2, String var3) { + String[] arguments = new String[]{var2, var3}; + return this.getGame(key, arguments); } - public String getGame(String var1, String var2, String var3, String var4) { - String[] var5 = new String[]{var2, var3, var4}; - return this.getGame(var1, var5); + public String getGame(String key, String argument2, String argument3, String argument4) { + String[] arguments = new String[]{argument2, argument3, argument4}; + return this.getGame(key, arguments); } - public String getGame(String var1, String var2, String var3, String var4, String var5) { - String[] var6 = new String[]{var2, var3, var4, var5}; - return this.getGame(var1, var6); + public String getGame(String key, String argument2, String argument3, String argument4, String argument5) { + String[] arguments = new String[]{argument2, argument3, argument4, argument5}; + return this.getGame(key, arguments); } - public String getGame(String var1, String var2, String var3, String var4, String var5, String var6) { - String[] var7 = new String[]{var2, var3, var4, var5, var6}; - return this.getGame(var1, var7); + public String getGame(String key, String argument2, String argument3, String argument4, String argument5, String argument6) { + String[] arguments = new String[]{argument2, argument3, argument4, argument5, argument6}; + return this.getGame(key, arguments); } - public String getGame(String var1, int var2) { - String[] var3 = new String[]{"" + var2}; - return this.getGame(var1, var3); + public String getGame(String key, int argument2) { + String[] arguments = new String[]{"" + argument2}; + return this.getGame(key, arguments); } - public String getGame(String var1, int var2, int var3) { - String[] var4 = new String[]{"" + var2, "" + var3}; - return this.getGame(var1, var4); + public String getGame(String key, int argument2, int argument3) { + String[] arguments = new String[]{"" + argument2, "" + argument3}; + return this.getGame(key, arguments); } - public String getGame(String var1, int var2, int var3, int var4) { - String[] var5 = new String[]{"" + var2, "" + var3, "" + var4}; - return this.getGame(var1, var5); + public String getGame(String key, int argument2, int argument3, int argument4) { + String[] arguments = new String[]{"" + argument2, "" + argument3, "" + argument4}; + return this.getGame(key, arguments); } - public String getGame(String var1, int var2, int var3, int var4, int var5) { - String[] var6 = new String[]{"" + var2, "" + var3, "" + var4, "" + var5}; - return this.getGame(var1, var6); + public String getGame(String key, int argument2, int argument3, int argument4, int argument5) { + String[] arguments = new String[]{"" + argument2, "" + argument3, "" + argument4, "" + argument5}; + return this.getGame(key, arguments); } public String getNumber(long var1) { @@ -206,52 +206,52 @@ public String getNumber(double var1, boolean var3, int var4) { } } - public String getTime(long var1) { - return this.getTime(var1 * 1000L, false); + public String getTime(long seconds) { + return this.getTime(seconds * 1000L, false); } - public String getTime(long var1, boolean var3) { - boolean var4 = var1 < 0L; - if (var4) { - var1 = -var1; + public String getTime(long time, boolean var3) { + boolean isNegative = time < 0L; + if (isNegative) { + time = -time; } - int var5 = (int) ((var1 % 1000L + 5L) / 10L); + int secondFraction = (int) ((time % 1000L + 5L) / 10L); if (!var3) { - var1 += 500L; + time += 500L; } - var1 /= 1000L; - int var6 = (int) (var1 % 60L); - var1 /= 60L; - int var7 = (int) (var1 % 60L); - int var8 = (int) (var1 / 60L); - boolean var9 = var8 > 0; - boolean var10 = var9 || var7 > 0 || !var3; - boolean var11 = var3 && var8 == 0; - String var12 = var4 ? "-" : ""; - if (var9) { - var12 = var12 + var8; + time /= 1000L; + int seconds = (int) (time % 60L); + time /= 60L; + int minutes = (int) (time % 60L); + int hours = (int) (time / 60L); + boolean includeHours = hours > 0; + boolean includeMinutes = includeHours || minutes > 0 || !var3; + boolean includeSecondFraction = var3 && hours == 0; + String result = isNegative ? "-" : ""; + if (includeHours) { + result = result + hours; } - if (var9 && var10) { - var12 = var12 + this.getShared("SeparatorHourMinute") + (var7 < 10 ? "0" : ""); + if (includeHours && includeMinutes) { + result = result + this.getShared("SeparatorHourMinute") + (minutes < 10 ? "0" : ""); } - if (var10) { - var12 = var12 + var7 + this.getShared("SeparatorMinuteSecond") + (var6 < 10 ? "0" : ""); + if (includeMinutes) { + result = result + minutes + this.getShared("SeparatorMinuteSecond") + (seconds < 10 ? "0" : ""); } - var12 = var12 + var6; - if (var11) { - var12 = var12 + this.getShared("SeparatorSecondFraction") + (var5 < 10 ? "0" : "") + var5; + result = result + seconds; + if (includeSecondFraction) { + result = result + this.getShared("SeparatorSecondFraction") + (secondFraction < 10 ? "0" : "") + secondFraction; } - return var12; + return result; } - public String getDate(long var1, boolean var3) { - return this.method1727(var1, var3 ? 1 : 0); + public String getDate(long timestamp, boolean includeTime) { + return this.getDate(timestamp, includeTime ? 1 : 0); } public String getClock(long var1, boolean var3) { @@ -264,8 +264,8 @@ public String getCurrentDateAndClock(boolean var1) { return var4; } - public String getDateWithTodayYesterday(long var1) { - return this.method1727(var1, 2); + public String getDateWithTodayYesterday(long timestamp) { + return this.getDate(timestamp, 2); } public char getDecimalSeparator() { @@ -273,40 +273,40 @@ public char getDecimalSeparator() { return var1.charAt(0); } - public String getShared(String var1) { - return this.getShared(var1, (String[]) null); + public String getShared(String key) { + return this.getShared(key, (String[]) null); } - public String getShared(String var1, String var2) { - String[] var3 = new String[]{var2}; - return this.getShared(var1, var3); + public String getShared(String key, String argument) { + String[] arguments = new String[]{argument}; + return this.getShared(key, arguments); } - public String getShared(String var1, String var2, String var3) { - String[] var4 = new String[]{var2, var3}; - return this.getShared(var1, var4); + public String getShared(String key, String argument1, String argument2) { + String[] arguments = new String[]{argument1, argument2}; + return this.getShared(key, arguments); } - public String getShared(String var1, String var2, String var3, String var4) { - String[] var5 = new String[]{var2, var3, var4}; - return this.getShared(var1, var5); + public String getShared(String key, String argument2, String argument3, String argument4) { + String[] arguments = new String[]{argument2, argument3, argument4}; + return this.getShared(key, arguments); } - public String getShared(String var1, String var2, String var3, String var4, String var5) { - String[] var6 = new String[]{var2, var3, var4, var5}; - return this.getShared(var1, var6); + public String getShared(String key, String argument2, String argument3, String argument4, String argument5) { + String[] arguments = new String[]{argument2, argument3, argument4, argument5}; + return this.getShared(key, arguments); } - public String getWithQuantity(String var1, int var2) { - return this.getGame(var1, new String[]{"" + var2}, var2); + public String getWithQuantity(String key, int quantity) { + return this.getGame(key, new String[]{"" + quantity}, quantity); } - public String getWithQuantity(String var1, String[] var2, int var3) { - return this.getGame(var1, var2, var3); + public String getWithQuantity(String key, String[] arguments, int quantity) { + return this.getGame(key, arguments, quantity); } public boolean isLoadingFinished() { - return this.aThread1513 == null; + return this.textLoaderThread == null; } public void waitLoadingFinished() { @@ -317,127 +317,125 @@ public void waitLoadingFinished() { } public Parameters getParameters() { - return this.aParameters1512; + return this.parameters; } public void destroy() { - if (this.aThread1513 == null) { - if (this.aHashtable1515 != null) { - this.aHashtable1515.clear(); - this.aHashtable1515 = null; + if (this.textLoaderThread == null) { + if (this.gameTable != null) { + this.gameTable.clear(); + this.gameTable = null; } - if (this.aHashtable1516 != null) { - this.aHashtable1516.clear(); - this.aHashtable1516 = null; + if (this.sharedTable != null) { + this.sharedTable.clear(); + this.sharedTable = null; } - this.aParameters1512 = null; - this.aString1514 = null; - this.aString1517 = null; + this.parameters = null; + this.language = null; + this.errorMessage = null; } } - protected String method1719() { - return this.aString1514; + protected String getLanguage() { + return this.language; } - private String getGame(String var1, String[] var2) { - return this.getGame(var1, var2, 1); + private String getGame(String key, String[] arguments) { + return this.getGame(key, arguments, 1); } - private String getGame(String var1, String[] var2, int var3) { - String var4 = this.method1722(var1, var2, var3); - if (var4 != null) { - return var4; + private String getGame(String key, String[] arguments, int quantity) { + String result = this.getText(key, arguments, quantity); + if (result != null) { + return result; } else { - var4 = this.method1729(var1, var3); - if (var2 != null) { - int var5 = var2.length; + result = this.getText(key, quantity); + if (arguments != null) { + int argumentsCount = arguments.length; - for (int var6 = 0; var6 < var5; ++var6) { - var4 = Tools.replaceFirst(var4, "%" + (var6 + 1), var2[var6]); + for (int i = 0; i < argumentsCount; ++i) { + result = Tools.replaceFirst(result, "%" + (i + 1), arguments[i]); } } - return var4; + return result; } } - private String method1722(String var1, String[] var2, int var3) { - if (this.aThread1513 != null) { + private String getText(String key, String[] arguments, int quantity) { + if (this.textLoaderThread != null) { return "[Loading texts...]"; - } else if (this.aHashtable1515 == null && this.aString1517 != null) { - return "[" + this.aString1517 + "]"; + } else if (this.gameTable == null && this.errorMessage != null) { + return "[" + this.errorMessage + "]"; } else { - String var4 = this.method1729(var1, var3); - if (var4 == null) { - if (this.aBoolean1519) { - System.out.println("TextManager.getText(\"" + var1 + "\"): Key not found"); + String result = this.getText(key, quantity); + if (result == null) { + if (this.debug) { + System.out.println("TextManager.getText(\"" + key + "\"): Key not found"); } - return this.method1723(var1, var2); + return this.getFallbackString(key, arguments); } else { return null; } } } - private String method1723(String var1, String[] var2) { - String var3 = "{" + var1 + "}"; - if (var2 != null) { - int var4 = var2.length; + private String getFallbackString(String key, String[] arguments) { + String var3 = "{" + key + "}"; + if (arguments != null) { - for (int var5 = 0; var5 < var4; ++var5) { - var3 = var3 + " (" + var2[var5] + ")"; + for (String s : arguments) { + var3 = var3 + " (" + s + ")"; } } return var3; } - private String getShared(String var1, String[] var2) { - return this.getShared(var1, var2, 1); + private String getShared(String key, String[] arguments) { + return this.getShared(key, arguments, 1); } - private String getShared(String var1, String[] var2, int var3) { - if (this.aThread1513 != null) { + private String getShared(String key, String[] arguments, int quantity) { + if (this.textLoaderThread != null) { return "[Loading texts...]"; - } else if (this.aHashtable1516 == null && this.aString1517 != null) { - return "[" + this.aString1517 + "]"; + } else if (this.sharedTable == null && this.errorMessage != null) { + return "[" + this.errorMessage + "]"; } else { - String var4 = this.method1730(var1, var3); - if (var4 == null) { - return this.method1723(var1, var2); + String localizedString = this.getSharedString(key, quantity); + if (localizedString == null) { + return this.getFallbackString(key, arguments); } else { - if (var2 != null) { - int var5 = var2.length; - - for (int var6 = 0; var6 < var5; ++var6) { - var4 = Tools.replaceFirst(var4, "%" + (var6 + 1), var2[var6]); + if (arguments != null) { + int argumentsCount = arguments.length; + for (int i = 0; i < argumentsCount; ++i) { + localizedString = Tools.replaceFirst(localizedString, "%" + (i + 1), arguments[i]); } } - return var4; + return localizedString; } } } - private String method1726(long var1, boolean var3) { - if ((var1 <= -1000L || var1 >= 1000L) && var3) { - boolean var4 = var1 < 0L; + private String method1726(long n, boolean separateThousands) { + if ((n <= -1000L || n >= 1000L) && separateThousands) { + boolean var4 = n < 0L; if (var4) { - var1 = -var1; + n = -n; } String var5 = ""; String var6 = this.getShared("SeparatorThousand"); do { - int var7 = (int) (var1 % 1000L); + int var7 = (int) (n % 1000L); var5 = var7 + var5; - var1 /= 1000L; - if (var1 > 0L) { + n /= 1000L; + if (n > 0L) { if (var7 < 10) { var5 = "00" + var5; } else if (var7 < 100) { @@ -446,7 +444,7 @@ private String method1726(long var1, boolean var3) { var5 = var6 + var5; } - } while (var1 > 0L); + } while (n > 0L); if (var4) { var5 = "-" + var5; @@ -454,47 +452,51 @@ private String method1726(long var1, boolean var3) { return var5; } else { - return "" + var1; - } - } - - private String method1727(long var1, int var3) { - Calendar var4 = Calendar.getInstance(); - var4.setTime(new Date(var1)); - int var5 = var4.get(1); - int var6 = var4.get(2) + 1; - int var7 = var4.get(5); - if (var3 == 0) { - return var5 + "-" + (var6 < 10 ? "0" : "") + var6 + "-" + (var7 < 10 ? "0" : "") + var7; + return "" + n; + } + } + + /** + * + * @param mode -- 0 == just date, no time, standard format; 1 == just date, no time, locale format; 2 == + */ + private String getDate(long timestamp, int mode) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date(timestamp)); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH) + 1; + int day = calendar.get(Calendar.DATE); + if (mode == 0) { + return year + "-" + (month < 10 ? "0" : "") + month + "-" + (day < 10 ? "0" : "") + day; } else { - String var8 = this.getShared("DateFormat"); - var8 = Tools.replaceFirst(var8, "%1", "" + var7); - var8 = Tools.replaceFirst(var8, "%2", this.getShared("DateMonth" + var6)); - var8 = Tools.replaceFirst(var8, "%3", "" + var5); - if (var3 == 1) { - return var8; + String result = this.getShared("DateFormat"); + result = Tools.replaceFirst(result, "%1", "" + day); + result = Tools.replaceFirst(result, "%2", this.getShared("DateMonth" + month)); + result = Tools.replaceFirst(result, "%3", "" + year); + if (mode == 1) { + return result; } else { try { - Calendar var9 = Calendar.getInstance(); - var9.set(11, 0); - var9.set(12, 0); - var9.set(13, 0); - var9.set(14, 0); - long var10 = var9.getTime().getTime(); - long var12 = var10 - 86400000L; - long var14 = var10 + 86400000L; - if (var1 >= var12 && var1 < var10) { - var8 = this.getShared("DateYesterday"); + Calendar today = Calendar.getInstance(); + today.set(Calendar.HOUR_OF_DAY, 0); + today.set(Calendar.MINUTE, 0); + today.set(Calendar.SECOND, 0); + today.set(Calendar.MILLISECOND, 0); + long startOfToday = today.getTime().getTime(); + long startOfYesterday = startOfToday - 86400000L; + long endOfToday = startOfToday + 86400000L; + if (timestamp >= startOfYesterday && timestamp < startOfToday) { + result = this.getShared("DateYesterday"); } - if (var1 >= var10 && var1 < var14) { - var8 = this.getShared("DateToday"); + if (timestamp >= startOfToday && timestamp < endOfToday) { + result = this.getShared("DateToday"); } - } catch (Exception var16) { + } catch (Exception e) { ; } - return var8; + return result; } } } @@ -508,14 +510,14 @@ private String method1728(long var1, int var3) { } int var6 = var4.get(var5 ? 11 : 10); - int var7 = var4.get(12); + int var7 = var4.get(Calendar.MINUTE); String var8 = ""; if (!var5) { if (var6 == 0) { var6 = 12; } - int var9 = var4.get(9); + int var9 = var4.get(Calendar.AM_PM); if (var9 == 0) { var8 = this.getShared("ClockAM"); } else if (var9 == 1) { @@ -537,184 +539,183 @@ private String method1728(long var1, int var3) { } } - protected String method1729(String var1, int var2) { - var1 = var1.toLowerCase(); - if (this.aBoolean1518) { - Class89 var3 = (Class89) ((Class89) this.aHashtable1515.get(var1)); - return var3 == null ? null : var3.method1737(var2); + protected String getText(String key, int quantity) { + key = key.toLowerCase(); + if (this.useLanguageFiles) { + LocalizationNode localizationNode = (LocalizationNode) this.gameTable.get(key); + return localizationNode == null ? null : localizationNode.getLocalization(quantity); } else { - return (String) ((String) this.aHashtable1515.get(var1)); + return (String) this.gameTable.get(key); } } - protected String method1730(String var1, int var2) { - var1 = var1.toLowerCase(); - if (this.aBoolean1518) { - Class89 var3 = (Class89) ((Class89) this.aHashtable1516.get(var1)); - return var3 == null ? null : var3.method1737(var2); + protected String getSharedString(String key, int quantity) { + key = key.toLowerCase(); + if (this.useLanguageFiles) { + LocalizationNode localizationNode = (LocalizationNode) this.sharedTable.get(key); + return localizationNode == null ? null : localizationNode.getLocalization(quantity); } else { - return (String) ((String) this.aHashtable1516.get(var1)); + return (String) this.sharedTable.get(key); } } - private void method1731(Applet var1) { - if (this.aBoolean1518) { - this.method1734(var1); + private void loadTexts(Applet applet) { + if (this.useLanguageFiles) { + this.loadLanguageFiles(applet); } else { - this.method1732(var1); + this.loadLocaleFiles(applet); } } - private void method1732(Applet var1) { - URL var2 = var1.getCodeBase(); - this.aHashtable1515 = this.method1733(var2); + private void loadLocaleFiles(Applet applet) { + URL codeBase = applet.getCodeBase(); + this.gameTable = this.loadLocalizationTable(codeBase); try { - if (FileUtil.isFileUrl(var2)) { - var2 = new URL(var2, FileUtil.RESOURCE_DIR); + if (FileUtil.isFileUrl(codeBase)) { + codeBase = new URL(codeBase, FileUtil.RESOURCE_DIR); } else { - var2 = new URL(var2, "../Shared/"); + codeBase = new URL(codeBase, "../Shared/"); } - } catch (MalformedURLException var4) { + } catch (MalformedURLException e) { ; } - this.aHashtable1516 = this.method1733(var2); + this.sharedTable = this.loadLocalizationTable(codeBase); } - private Hashtable method1733(URL var1) { - Hashtable var2 = new Hashtable(); - BufferedReader var3 = null; - String var4 = this.aString1514 + ".loc"; + private Hashtable loadLocalizationTable(URL baseUrl) { + Hashtable localizationTable = new Hashtable(); + BufferedReader reader = null; + String languageFileName = this.language + ".loc"; try { - URL var5 = new URL(var1, "locale/"); - var5 = new URL(var5, var4); - InputStream var6 = var5.openStream(); + URL localeUrl = new URL(baseUrl, "locale/"); + localeUrl = new URL(localeUrl, languageFileName); + InputStream inputStream = localeUrl.openStream(); - InputStreamReader var7; + InputStreamReader inputStreamReader; try { - var7 = new InputStreamReader(var6, "Cp1252"); - } catch (UnsupportedEncodingException var12) { - var7 = new InputStreamReader(var6); + inputStreamReader = new InputStreamReader(inputStream, "Cp1252"); + } catch (UnsupportedEncodingException e) { + inputStreamReader = new InputStreamReader(inputStream); } - var3 = new BufferedReader(var7); + reader = new BufferedReader(inputStreamReader); - String var8; - while ((var8 = var3.readLine()) != null) { - var8 = var8.trim(); - if (var8.length() > 0 && var8.charAt(0) != 35) { - int var10 = var8.indexOf(61); - if (var10 <= 0) { - if (this.aBoolean1519) { - System.out.println("Missing \'=\'-character in \"" + this.aString1514 + "\"-locale file: \"" + var8 + "\""); + String line; + while ((line = reader.readLine()) != null) { + line = line.trim(); + if (line.length() > 0 && line.charAt(0) != '#') { + int equalSignLocation = line.indexOf('='); + if (equalSignLocation <= 0) { + if (this.debug) { + System.out.println("Missing '='-character in \"" + this.language + "\"-locale file: \"" + line + "\""); Thread.dumpStack(); } } else { - String var9 = var8.substring(0, var10).trim(); - if (var9.length() == 0) { - if (this.aBoolean1519) { - System.out.println("Empty key in \"" + this.aString1514 + "\"-locale file: \"" + var8 + "\""); + String key = line.substring(0, equalSignLocation).trim(); + if (key.length() == 0) { + if (this.debug) { + System.out.println("Empty key in \"" + this.language + "\"-locale file: \"" + line + "\""); Thread.dumpStack(); } } else { - var2.put(var9.toLowerCase(), var8.substring(var10 + 1).trim()); + localizationTable.put(key.toLowerCase(), line.substring(equalSignLocation + 1).trim()); } } } } - } catch (FileNotFoundException var13) { - if (this.aBoolean1519) { - System.out.println("Missing localization file \"" + var4 + "\""); + } catch (FileNotFoundException e) { + if (this.debug) { + System.out.println("Missing localization file \"" + languageFileName + "\""); } - this.aString1517 = "Texts for \'" + this.aString1514 + "\' not available"; - var2 = null; - } catch (Exception var14) { - if (this.aBoolean1519) { - var14.printStackTrace(); + this.errorMessage = "Texts for '" + this.language + "' not available"; + localizationTable = null; + } catch (Exception e) { + if (this.debug) { + e.printStackTrace(); } - this.aString1517 = var14.toString(); - var2 = null; + this.errorMessage = e.toString(); + localizationTable = null; } try { - var3.close(); - } catch (Exception var11) { + reader.close(); + } catch (Exception e) { ; } - return var2; + return localizationTable; } - private void method1734(Applet var1) { - URL var2 = var1.getCodeBase(); + private void loadLanguageFiles(Applet applet) { + URL codeBase = applet.getCodeBase(); String var5 = null; - int var6 = this.aString1514.indexOf(47); - if (var6 > 0) { - var5 = this.aString1514.substring(var6 + 1); - this.aString1514 = this.aString1514.substring(0, var6); + int slashLocation = this.language.indexOf('/'); + if (slashLocation > 0) { + var5 = this.language.substring(slashLocation + 1); + this.language = this.language.substring(0, slashLocation); } - String var3; - String var4; + String languageDirectory; + String gameFilename; String var7; int var8; - if (FileUtil.isFileUrl(var2)) { - var7 = var2.toString(); - var8 = var7.indexOf(58, var7.indexOf(58) + 1) + 2; - int var9 = var7.indexOf(47, var8); + if (FileUtil.isFileUrl(codeBase)) { + var7 = codeBase.toString(); + var8 = var7.indexOf(':', var7.indexOf(':') + 1) + 2; + int var9 = var7.indexOf('/', var8); try { - URL var10 = new URL(var2, FileUtil.LANGUAGE_DIR); - var10 = new URL(var10, this.aString1514 + "/"); - var3 = var10.toExternalForm(); - } catch (MalformedURLException var11) { - var3 = "file:" + FileUtil.LANGUAGE_DIR + this.aString1514 + "/"; + URL var10 = new URL(codeBase, FileUtil.LANGUAGE_DIR); + var10 = new URL(var10, this.language + "/"); + languageDirectory = var10.toExternalForm(); + } catch (MalformedURLException e) { + languageDirectory = "file:" + FileUtil.LANGUAGE_DIR + this.language + "/"; } - var4 = var7.substring(var8, var9); + gameFilename = var7.substring(var8, var9); } else { - var7 = var2.toString(); + var7 = codeBase.toString(); var8 = var7.length(); - if (var7.charAt(var8 - 1) == 47) { + if (var7.charAt(var8 - 1) == '/') { var7 = var7.substring(0, var8 - 1); --var8; } - var6 = var7.lastIndexOf(47); - var3 = var7.substring(0, var6 + 1) + "l10n/" + this.aString1514 + "/"; - var4 = var7.substring(var6 + 1); + int slashLocation2 = var7.lastIndexOf('/'); + languageDirectory = var7.substring(0, slashLocation2 + 1) + "l10n/" + this.language + "/"; + gameFilename = var7.substring(slashLocation2 + 1); } if (var5 != null) { - var4 = var5; + gameFilename = var5; } - this.aHashtable1515 = this.method1735(var3 + var4 + ".xml"); - this.aHashtable1516 = this.method1735(var3 + "Shared.xml"); + this.gameTable = this.readTable(languageDirectory + gameFilename + ".xml"); + this.sharedTable = this.readTable(languageDirectory + "Shared.xml"); } - private Hashtable method1735(String var1) { - EncodedXmlReader var2 = new EncodedXmlReader(var1, /*this.aBoolean1519*/true); - XmlUnit var3 = var2.readXmlUnit(); - if (var3 == null) { - System.out.println("Failed to read localization file \'" + var1 + "\'"); - this.aString1517 = "XML read error"; + private Hashtable readTable(String fileUrl) { + EncodedXmlReader reader = new EncodedXmlReader(fileUrl, /*this.aBoolean1519*/true); + XmlUnit unit = reader.readXmlUnit(); + if (unit == null) { + System.out.println("Failed to read localization file '" + fileUrl + "'"); + this.errorMessage = "XML read error"; return null; } else { - XmlUnit[] var4 = var3.getChildren("str"); - int var5 = var4.length; - Hashtable var6 = new Hashtable(); + XmlUnit[] children = unit.getChildren("str"); + Hashtable table = new Hashtable<>(); - for (int var7 = 0; var7 < var5; ++var7) { - var6.put(var4[var7].getAttribute("key").toLowerCase(), new Class89(this, this.aString1514, var4[var7], Tools.getBoolean(var4[var7].getAttribute("reverse")))); + for (XmlUnit child : children) { + table.put(child.getAttribute("key").toLowerCase(), new LocalizationNode(this, this.language, child, Tools.getBoolean(child.getAttribute("reverse")))); } - return var6; + return table; } } } From 3064727c260048c06f754e1b9dfd533f6bf4ac9d Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 13/16] Rename get_upd -> add in SynchronizedInteger This more accurately reflects what the code does. The return value was never used so I also changed the method to return void. Since get_upd() without any parameters was just adding 1 to the internal integer, I removed the method to simplify the class; now when 1 needs to be added to the internal int, add(1) can be called. --- client/src/main/java/agolf/SynchronizedInteger.java | 8 ++------ .../src/main/java/agolf/game/GamePlayerInfoPanel.java | 10 +++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/client/src/main/java/agolf/SynchronizedInteger.java b/client/src/main/java/agolf/SynchronizedInteger.java index a168cba2..b6d99f86 100644 --- a/client/src/main/java/agolf/SynchronizedInteger.java +++ b/client/src/main/java/agolf/SynchronizedInteger.java @@ -19,12 +19,8 @@ public synchronized int set(int n) { return n; } - public synchronized int get_upd() { - return this.set((this.n > 0L ? (int) ((2269700342778490L - this.n) / 31L) : (int) ((this.n + 110157223978885L) / 7L)) + 1); - } - - public synchronized int get_upd(int i) { - return this.set((this.n > 0L ? (int) ((2269700342778490L - this.n) / 31L) : (int) ((this.n + 110157223978885L) / 7L)) + i); + public synchronized void add(int i) { + this.set((this.n > 0L ? (int) ((2269700342778490L - this.n) / 31L) : (int) ((this.n + 110157223978885L) / 7L)) + i); } public synchronized int get() { diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index 941e515f..f9778b88 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -401,10 +401,10 @@ protected boolean startTurn(int playerId) { protected void strokeStartedOrEnded(int playerId, boolean isStrokeEnd) { if (this.trackScoring == 0) { int var3 = !isStrokeEnd ? this.trackScoresMultipliers[this.currentTrackIndex] : 1; - this.trackStrokes[playerId][this.currentTrackIndex].get_upd(var3); - this.playersId[playerId].get_upd(var3); + this.trackStrokes[playerId][this.currentTrackIndex].add(var3); + this.playersId[playerId].add(var3); } else { - this.trackStrokes[playerId][this.currentTrackIndex].get_upd(); + this.trackStrokes[playerId][this.currentTrackIndex].add(1); } this.repaint(); @@ -418,7 +418,7 @@ protected void setScores(int trackId, int[] scores) { for (int track = 0; track <= trackId; ++track) { int strokes = this.trackStrokes[player][track].get(); if (strokes >= 0) { - this.playersId[player].get_upd(strokes); + this.playersId[player].add(strokes); } } } @@ -482,7 +482,7 @@ protected void setState(int state) { protected void method372() { if (this.trackScoring == 0) { - this.playersId[this.activePlayerId].get_upd(-this.trackStrokes[this.activePlayerId][this.currentTrackIndex].get()); + this.playersId[this.activePlayerId].add(-this.trackStrokes[this.activePlayerId][this.currentTrackIndex].get()); } this.trackStrokes[this.activePlayerId][this.currentTrackIndex].set(-1); From e77d7f763d0a9924a7ebbb046e019b790ae5a6b1 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 14/16] Deobfuscate Parameters class --- client/src/main/java/agolf/GameApplet.java | 8 +- .../main/java/com/aapeli/client/Class88.java | 12 +- .../java/com/aapeli/client/Parameters.java | 468 +++++++++--------- 3 files changed, 249 insertions(+), 239 deletions(-) diff --git a/client/src/main/java/agolf/GameApplet.java b/client/src/main/java/agolf/GameApplet.java index 7a42333d..5c99d09e 100644 --- a/client/src/main/java/agolf/GameApplet.java +++ b/client/src/main/java/agolf/GameApplet.java @@ -38,16 +38,16 @@ public class GameApplet extends AApplet { private boolean verbose = false; - public void initApplet(Parameters var1) { + public void initApplet(Parameters parameters) { this.syncIsValidSite = new SynchronizedBool(this.isValidSite()); this.setBackground(colourGameBackground); this.setForeground(colourTextBlack); - this.gameContainer = new GameContainer(this, var1); + this.gameContainer = new GameContainer(this, parameters); this.aBoolean3773 = false; } - public void textsLoadedNotify(TextManager var1) { - this.gameContainer.textManager = var1; + public void textsLoadedNotify(TextManager textManager) { + this.gameContainer.textManager = textManager; } public void defineSounds(SoundManager soundManager) { diff --git a/client/src/main/java/com/aapeli/client/Class88.java b/client/src/main/java/com/aapeli/client/Class88.java index b9e7af4d..e4c80aa1 100644 --- a/client/src/main/java/com/aapeli/client/Class88.java +++ b/client/src/main/java/com/aapeli/client/Class88.java @@ -1,9 +1,5 @@ package com.aapeli.client; -import com.aapeli.client.Frame_Sub3_Sub3; -import com.aapeli.client.ImageManager; -import com.aapeli.client.Parameters; -import com.aapeli.client.TextManager; import com.aapeli.colorgui.ColorButton; import java.awt.Color; @@ -29,7 +25,7 @@ protected Class88(Parameters var1, TextManager var2, ImageManager var3) { this.aParameters1500 = var1; this.aTextManager1501 = var2; this.anImageManager1502 = var3; - this.anInt1506 = var1.method1655() ? 1 : 2; + this.anInt1506 = var1.getTellFriend() ? 1 : 2; this.anInt1507 = 0; try { @@ -40,8 +36,8 @@ protected Class88(Parameters var1, TextManager var2, ImageManager var3) { this.anInt1506 = 0; } - this.aString1504 = var1.method1656(); - this.aString1505 = var1.method1657(); + this.aString1504 = var1.getTellFriendPage(); + this.aString1505 = var1.getTellFriendTarget(); if (this.aString1504 == null || this.aString1505 == null) { this.anInt1506 = 0; } @@ -132,7 +128,7 @@ protected boolean method1702(String[] var1, String var2, int var3, int var4, int var10 = var10 + "hash=" + var9; URL var14 = new URL(this.aString1504 + "?" + var10); - this.aParameters1500.method1654().showDocument(var14, this.aString1505); + this.aParameters1500.getAppletContext().showDocument(var14, this.aString1505); return true; } catch (Exception var12) { ; diff --git a/client/src/main/java/com/aapeli/client/Parameters.java b/client/src/main/java/com/aapeli/client/Parameters.java index 94a372cb..2769d973 100644 --- a/client/src/main/java/com/aapeli/client/Parameters.java +++ b/client/src/main/java/com/aapeli/client/Parameters.java @@ -11,25 +11,25 @@ public final class Parameters { - private static final String aString1416 = "127.0.0.1"; + private static final String LOCALHOST = "127.0.0.1"; //private static final String aString1416 = "192.168.1.23"; - private static final String aString1417 = "en"; - private static final String aString1418 = "playforia"; - private static final String aString1419 = "http://www.playforia.com/"; - private static final String aString1420 = "_top"; - private Applet anApplet1421; - private AApplet anAApplet1422; - private String aString1423; - private String aString1424; - private String aString1425; - private String aString1426; - private String aString1427; - private String aString1428; - private String aString1429; + private static final String ENGLISH_LANGUAGE = "en"; + private static final String PLAYFORIA_SITE_NAME = "playforia"; + private static final String PLAYFORIA_QUIT_PAGE = "http://www.playforia.com/"; + private static final String QUIT_TARGET = "_top"; + private Applet applet; + private AApplet aApplet; + private String codeBaseHost; + private String documentBaseHost; + private String serverIp; + private String locale; + private String translationLanguage; + private String chatLang; + private String siteName; private String sessionLocale; private String session; private String welcomeMessage; - private String aString1433; + private String quitTarget; private String urlRegisterPage; private String urlVipPage; private String urlUserInfoPage; @@ -46,75 +46,83 @@ public final class Parameters { private boolean tellFriend; private boolean guestAutoLogin; private boolean disableGuestLobbyChat; - private int anInt1450; + private int serverPort; private URL urlCreditPage; - private URL anURL1452; + private URL quitPageUrl; private String[][] imageAliases; private int[] anIntArray1454; private int anInt1455; private String[] aStringArray1456; private String aString1457; private boolean debug; - private static final String[] aStringArray1459 = new String[73]; - public Parameters(Applet var1) { - this(var1, false); + public Parameters(Applet applet) { + this(applet, false); } - public Parameters(Applet var1, boolean var2) { - this.anApplet1421 = var1; - if (var1 instanceof AApplet) { - this.anAApplet1422 = (AApplet) ((AApplet) var1); + public Parameters(Applet applet, boolean debug) { + this.applet = applet; + if (applet instanceof AApplet) { + this.aApplet = (AApplet) applet; } - this.aString1423 = var1.getCodeBase().getHost().toLowerCase(); - this.aString1424 = var1.getDocumentBase().getHost().toLowerCase(); + this.codeBaseHost = applet.getCodeBase().getHost().toLowerCase(); + this.documentBaseHost = applet.getDocumentBase().getHost().toLowerCase(); this.anInt1455 = 0; - this.debug = var2; - this.method1660(); + this.debug = debug; + this.init(); } - public static boolean getBooleanValue(String var0) { - return var0 == null ? false : var0.equalsIgnoreCase("true") || var0.equalsIgnoreCase("t") || var0.equalsIgnoreCase("yes") || var0.equalsIgnoreCase("y") || var0.equals("1") || var0.equals("1.0") || var0.equals("1,0"); - } - - public String getParameter(String var1) { - String var2 = this.anApplet1421.getParameter(var1); - if (var2 == null) { - var2 = this.anApplet1421.getParameter(var1.toLowerCase()); + public static boolean getBooleanValue(String key) { + if (key == null) { + return false; + } + return key.equalsIgnoreCase("true") || + key.equalsIgnoreCase("t") || + key.equalsIgnoreCase("yes") || + key.equalsIgnoreCase("y") || + key.equals("1") || + key.equals("1.0") || + key.equals("1,0"); + } + + public String getParameter(String key) { + String value = this.applet.getParameter(key); + if (value == null) { + value = this.applet.getParameter(key.toLowerCase()); } - if (var2 == null) { - var2 = this.anApplet1421.getParameter(var1.toUpperCase()); + if (value == null) { + value = this.applet.getParameter(key.toUpperCase()); } - if (var2 == null) { + if (value == null) { return null; } else { - var2 = var2.trim(); - return var2.length() == 0 ? null : var2; + value = value.trim(); + return value.length() == 0 ? null : value; } } public String getServerIp() { - return this.aString1425; + return this.serverIp; } public int getServerPort() { - return this.anInt1450; + return this.serverPort; } public String getLocale() { - return this.aString1426; + return this.locale; } public String getTranslationLang() { - return this.aString1427; + return this.translationLanguage; } public String getChatLang() { - return this.aString1428 != null ? this.aString1428 : this.aString1427; + return this.chatLang != null ? this.chatLang : this.translationLanguage; } public String getLang() { @@ -122,7 +130,7 @@ public String getLang() { } public String getSiteName() { - return this.aString1429; + return this.siteName; } public String getSessionLocale() { @@ -173,7 +181,7 @@ public boolean showPlayerCard(String var1) { return false; } - this.method1676(this.toURL(this.urlUserInfoPage + var1), this.urlTargetUserInfo); + this.showUrl(this.toURL(this.urlUserInfoPage + var1), this.urlTargetUserInfo); return true; } @@ -183,10 +191,10 @@ public boolean showPlayerCard(String var1) { return false; } - this.method1676(var3, this.urlTargetUserInfo); + this.showUrl(var3, this.urlTargetUserInfo); return true; } - } catch (Exception var4) { + } catch (Exception e) { ; } @@ -197,9 +205,9 @@ public void showPlayerList(String[] var1) { this.showPlayerList(var1, (String) null); } - public void showPlayerList(String[] var1, String var2) { + public void showPlayerList(String[] nicks, String var2) { try { - if (var1 == null) { + if (nicks == null) { if (this.debug) { System.out.println("Parameters.showPlayerList(null,...)"); } @@ -209,26 +217,26 @@ public void showPlayerList(String[] var1, String var2) { } if (this.debug) { - System.out.println("Parameters.showPlayerList(...): nicks.length=" + var1.length); + System.out.println("Parameters.showPlayerList(...): nicks.length=" + nicks.length); } - if (this.method1675(var1, var2)) { + if (this.method1675(nicks, var2)) { return; } - this.showPlayerList(var1, (boolean[]) null, var2); - this.aStringArray1456 = var1; + this.showPlayerList(nicks, null, var2); + this.aStringArray1456 = nicks; this.aString1457 = var2; this.anInt1455 = 1; - } catch (Exception var4) { + } catch (Exception e) { ; } } - public void showPlayerListWinners(boolean[] var1) { + public void showPlayerListWinners(boolean[] winners) { try { - if (var1 == null) { + if (winners == null) { if (this.debug) { System.out.println("Parameters.showPlayerListWinners(null)"); } @@ -238,19 +246,18 @@ public void showPlayerListWinners(boolean[] var1) { } if (this.debug) { - System.out.println("Parameters.showPlayerListWinners(...): winners.length=" + var1.length); + System.out.println("Parameters.showPlayerListWinners(...): winners.length=" + winners.length); } - int var2 = var1.length; - boolean var3 = false; + boolean winnerExists = false; - for (int var4 = 0; var4 < var2; ++var4) { - if (var1[var4]) { - var3 = true; + for (boolean winner : winners) { + if (winner) { + winnerExists = true; } } - if (!var3) { + if (!winnerExists) { this.removePlayerListWinners(); return; } @@ -259,9 +266,9 @@ public void showPlayerListWinners(boolean[] var1) { return; } - this.showPlayerList(this.aStringArray1456, var1, this.aString1457); + this.showPlayerList(this.aStringArray1456, winners, this.aString1457); this.anInt1455 = 2; - } catch (Exception var5) { + } catch (Exception e) { ; } @@ -277,24 +284,24 @@ public void removePlayerList() { return; } - this.showPlayerList((String[]) null, (boolean[]) null, (String) null); + this.showPlayerList(null, null, null); this.anInt1455 = 0; - } catch (Exception var2) { + } catch (Exception e) { ; } } public boolean showRegisterPage() { - return this.method1676(this.toURL(this.urlRegisterPage), (String) null); + return this.showUrl(this.toURL(this.urlRegisterPage), null); } public void showCreditPurchasePage() { this.showCreditPurchasePage(true); } - public void showCreditPurchasePage(boolean var1) { - this.method1676(this.urlCreditPage, var1 ? "_blank" : null); + public void showCreditPurchasePage(boolean openInNewTab) { + this.showUrl(this.urlCreditPage, openInNewTab ? "_blank" : null); } public boolean isCreditPurchasePageAvailable() { @@ -302,7 +309,7 @@ public boolean isCreditPurchasePageAvailable() { } public void showQuitPage() { - this.method1676(this.anURL1452, this.aString1433); + this.showUrl(this.quitPageUrl, this.quitTarget); } public String[][] getImageAliases() { @@ -325,25 +332,25 @@ public String getTicket() { return this.ticket; } - public boolean callJavaScriptJSON(String var1) { + public boolean callJavaScriptJSON(String json) { if (this.debug) { - System.out.println("Parameters.callJavaScriptJSON(\"" + var1 + "\")"); + System.out.println("Parameters.callJavaScriptJSON(\"" + json + "\")"); } if (this.json == null) { return false; } else { try { - var1 = Tools.replaceAll(var1, "\'", "\\\'"); - String var2 = Tools.replaceFirst(this.json, "%o", "\'" + var1 + "\'"); + json = Tools.replaceAll(json, "'", "\\'"); + String var2 = Tools.replaceFirst(this.json, "%o", "'" + json + "'"); URL var3 = this.toURL(var2); if (var3 == null) { return false; } else { - this.method1676(var3, (String) null); + this.showUrl(var3, null); return true; } - } catch (Exception var4) { + } catch (Exception e) { return false; } } @@ -380,23 +387,23 @@ public void updateWebPageInfoBox(int var1, int var2, int var3) { } public Applet getApplet() { - return this.anApplet1421; + return this.applet; } public AApplet getAApplet() { - return this.anAApplet1422; + return this.aApplet; } public void destroy() { - this.aString1425 = null; - this.aString1426 = null; - this.aString1427 = null; - this.aString1428 = null; - this.aString1429 = null; + this.serverIp = null; + this.locale = null; + this.translationLanguage = null; + this.chatLang = null; + this.siteName = null; this.sessionLocale = null; this.session = null; this.welcomeMessage = null; - this.aString1433 = null; + this.quitTarget = null; this.urlRegisterPage = null; this.urlVipPage = null; this.urlUserInfoPage = null; @@ -411,45 +418,45 @@ public void destroy() { this.ticket = null; this.json = null; this.urlCreditPage = null; - this.imageAliases = (String[][]) null; + this.imageAliases = null; this.anIntArray1454 = null; this.aStringArray1456 = null; this.aString1457 = null; - this.aString1424 = null; - this.aString1423 = null; + this.documentBaseHost = null; + this.codeBaseHost = null; } - protected AppletContext method1654() { - return this.anApplet1421.getAppletContext(); + protected AppletContext getAppletContext() { + return this.applet.getAppletContext(); } - protected boolean method1655() { + protected boolean getTellFriend() { return this.tellFriend; } - protected String method1656() { + protected String getTellFriendPage() { return this.urlTellFriendPage; } - protected String method1657() { + protected String getTellFriendTarget() { return this.urlTargetTellFriend; } - protected String method1658() { + protected String getTournamentRound() { return this.tournamentRound; } - protected String method1659() { + protected String getSubgame() { return this.subgame; } - private void method1660() { - this.aString1425 = this.getParamServer(); - this.anInt1450 = this.getParamPort(); - this.aString1426 = this.getParamLocale(); - this.aString1427 = this.getParamLanguage(); - this.aString1428 = this.getParamChatLanguage(); - this.aString1429 = this.getParamSiteName(); + private void init() { + this.serverIp = this.getParamServer(); + this.serverPort = this.getParamPort(); + this.locale = this.getParamLocale(); + this.translationLanguage = this.getParamLanguage(); + this.chatLang = this.getParamChatLanguage(); + this.siteName = this.getParamSiteName(); this.sessionLocale = this.getParameter("sessionlocale"); this.session = this.getParameter("session"); this.welcomeMessage = this.getParameter("welcomemessage"); @@ -457,8 +464,8 @@ private void method1660() { this.welcomeMessage = this.getParameter("gamewelcome"); } - this.anURL1452 = this.getParamQuitPage(); - this.aString1433 = this.getParamQuitTarget(); + this.quitPageUrl = this.getParamQuitPage(); + this.quitTarget = this.getParamQuitTarget(); this.urlRegisterPage = this.getParameter("registerpage"); this.urlVipPage = this.getParameter("vippage"); this.urlCreditPage = this.toURL(this.getParameter("creditpage")); @@ -488,82 +495,82 @@ private void method1660() { private String getParamServer() { try { - String var1 = this.getParameter("server"); - int var2 = var1.lastIndexOf(':'); - return var1.substring(0, var2); - } catch (Exception var3) { - return this.aString1423.length() > 0 ? this.aString1423 : aString1416; + String server = this.getParameter("server"); + int portIndex = server.lastIndexOf(':'); + return server.substring(0, portIndex); + } catch (Exception e) { + return this.codeBaseHost.length() > 0 ? this.codeBaseHost : LOCALHOST; } } private int getParamPort() { try { - String var1 = this.getParameter("server"); - int var2 = var1.lastIndexOf(':'); - return Integer.parseInt(var1.substring(var2 + 1)); - } catch (Exception var4) { + String server = this.getParameter("server"); + int portIndex = server.lastIndexOf(':'); + return Integer.parseInt(server.substring(portIndex + 1)); + } catch (Exception e) { try { return Integer.parseInt(this.getParameter("port")); - } catch (Exception var3) { + } catch (Exception e2) { return 4200; } } } private String getParamLocale() { - String var1; + String locale; try { - var1 = this.getParameter("locale"); - if (var1 != null) { - return var1; + locale = this.getParameter("locale"); + if (locale != null) { + return locale; } - } catch (Exception var4) { + } catch (Exception e) { ; } - if (this.aString1423.endsWith("aapeli.com")) { + if (this.codeBaseHost.endsWith("aapeli.com")) { return "fi"; - } else if (this.aString1423.endsWith("playray.com")) { - return aString1417; + } else if (this.codeBaseHost.endsWith("playray.com")) { + return ENGLISH_LANGUAGE; } else { - if (this.aString1423.endsWith(".playforia.com")) { + if (this.codeBaseHost.endsWith(".playforia.com")) { try { - var1 = this.aString1423.substring(0, this.aString1423.indexOf(46)); - if (var1.length() > 0 && !var1.equals("www")) { - return var1; + locale = this.codeBaseHost.substring(0, this.codeBaseHost.indexOf(46)); + if (locale.length() > 0 && !locale.equals("www")) { + return locale; } - } catch (Exception var3) { + } catch (Exception e) { ; } } - if (this.aString1423.indexOf("playray") >= 0) { + if (this.codeBaseHost.contains("playray")) { try { - var1 = this.aString1423.substring(this.aString1423.lastIndexOf(46) + 1); - if (var1.length() > 0) { - return var1; + locale = this.codeBaseHost.substring(this.codeBaseHost.lastIndexOf(46) + 1); + if (locale.length() > 0) { + return locale; } - } catch (Exception var2) { + } catch (Exception e) { ; } } - return aString1417; + return ENGLISH_LANGUAGE; } } private String getParamLanguage() { try { - String var1 = this.getParameter("lang"); - if (var1 != null) { - return var1; + String language = this.getParameter("lang"); + if (language != null) { + return language; } - var1 = this.getParameter("language"); - if (var1 != null) { - return var1; + language = this.getParameter("language"); + if (language != null) { + return language; } - } catch (Exception var2) { + } catch (Exception e) { ; } @@ -572,16 +579,16 @@ private String getParamLanguage() { private String getParamChatLanguage() { try { - String var1 = this.getParameter("chatlang"); - if (var1 != null) { - return var1; + String chatLanguage = this.getParameter("chatlang"); + if (chatLanguage != null) { + return chatLanguage; } - var1 = this.getParameter("serverlang"); - if (var1 != null) { - return var1; + chatLanguage = this.getParameter("serverlang"); + if (chatLanguage != null) { + return chatLanguage; } - } catch (Exception var2) { + } catch (Exception e) { ; } @@ -590,56 +597,63 @@ private String getParamChatLanguage() { private String getParamSiteName() { try { - String var1 = this.getParameter("sitename"); - if (var1 != null) { - return var1; + String siteName = this.getParameter("sitename"); + if (siteName != null) { + return siteName; } - } catch (Exception var2) { + } catch (Exception e) { ; } - return this.aString1424.indexOf("aapeli.") >= 0 ? "aapeli" : (this.aString1424.indexOf("playforia.") >= 0 ? aString1418 : (this.aString1424.indexOf("playray.") >= 0 ? "playray" : aString1418)); + if (this.documentBaseHost.contains("aapeli.")) { + return "aapeli"; + } else if (this.documentBaseHost.contains("playforia.")) { + return PLAYFORIA_SITE_NAME; + } else if (this.documentBaseHost.contains("playray.")) { + return "playray"; + } + return PLAYFORIA_SITE_NAME; } private URL getParamQuitPage() { - URL var1 = this.toURL(this.getParameter("quitpage")); - if (var1 != null) { - return var1; + URL quitPage = this.toURL(this.getParameter("quitpage")); + if (quitPage != null) { + return quitPage; } else { - var1 = this.toURL(this.aString1424); - return var1 != null ? var1 : this.toURL(aString1419); + quitPage = this.toURL(this.documentBaseHost); + return quitPage != null ? quitPage : this.toURL(PLAYFORIA_QUIT_PAGE); } } private String getParamQuitTarget() { - String var1 = this.getParameter("quittarget"); - return var1 != null ? var1 : aString1420; + String quitTarget = this.getParameter("quittarget"); + return quitTarget != null ? quitTarget : QUIT_TARGET; } private String[][] getParamImageAliases() { - String var1 = this.getParameter("imagealias"); - if (var1 == null) { - return (String[][]) null; + String imageAliases = this.getParameter("imagealias"); + if (imageAliases == null) { + return null; } else { - StringTokenizer var2 = new StringTokenizer(var1, " "); - int var3 = var2.countTokens(); - if (var3 == 0) { - return (String[][]) null; + StringTokenizer tokenizer = new StringTokenizer(imageAliases, " "); + int tokenCount = tokenizer.countTokens(); + if (tokenCount == 0) { + return null; } else { - String[][] var4 = new String[var3][2]; + String[][] result = new String[tokenCount][2]; - for (int var7 = 0; var7 < var3; ++var7) { - String var5 = var2.nextToken(); - int var6 = var5.indexOf(58); - if (var6 <= 0 || var6 == var5.length() - 1) { - return (String[][]) null; + for (int i = 0; i < tokenCount; ++i) { + String token = tokenizer.nextToken(); + int var6 = token.indexOf(':'); + if (var6 <= 0 || var6 == token.length() - 1) { + return null; } - var4[var7][0] = var5.substring(0, var6); - var4[var7][1] = this.method1670(var5.substring(var6 + 1)); + result[i][0] = token.substring(0, var6); + result[i][1] = this.method1670(token.substring(var6 + 1)); } - return var4; + return result; } } } @@ -664,42 +678,42 @@ private String method1670(String var1) { } private int[] getParamRegRemindShowTime() { - String var1 = this.getParameter("regremindshowtime"); - if (var1 == null) { + String regRemindShowTime = this.getParameter("regremindshowtime"); + if (regRemindShowTime == null) { return null; } else { - StringTokenizer var2 = new StringTokenizer(var1, ","); - int var3 = var2.countTokens(); - if (var3 == 0) { + StringTokenizer tokenizer = new StringTokenizer(regRemindShowTime, ","); + int tokenCount = tokenizer.countTokens(); + if (tokenCount == 0) { return null; } else { - int[] var4 = new int[var3]; + int[] result = new int[tokenCount]; - for (int var5 = 0; var5 < var3; ++var5) { + for (int i = 0; i < tokenCount; ++i) { try { - var4[var5] = Integer.parseInt(var2.nextToken()); - } catch (NumberFormatException var7) { + result[i] = Integer.parseInt(tokenizer.nextToken()); + } catch (NumberFormatException e) { return null; } - if (var4[var5] <= 0) { + if (result[i] <= 0) { return null; } - if (var5 > 0 && var4[var5] <= var4[var5 - 1]) { + if (i > 0 && result[i] <= result[i - 1]) { return null; } } - return var4; + return result; } } } - private URL toURL(String var1) { + private URL toURL(String s) { try { - return new URL(var1); - } catch (MalformedURLException var3) { + return new URL(s); + } catch (MalformedURLException e) { return null; } } @@ -710,76 +724,76 @@ private void showPlayerList(String[] nicks, boolean[] winners, String subgame) { } if (this.urlUserListPage != null) { - String var4 = this.urlUserListPage.toLowerCase(); - String var5 = null; + String result = null; if (nicks != null) { - var5 = ""; - int var6 = nicks.length; + result = ""; + int len = nicks.length; - for (int var7 = 0; var7 < var6; ++var7) { - var5 = var5 + nicks[var7]; + for (int i = 0; i < len; ++i) { + result = result + nicks[i]; if (winners != null) { - var5 = var5 + (winners[var7] ? "*" : ""); + result = result + (winners[i] ? "*" : ""); } - if (var7 < var6 - 1) { - var5 = var5 + ','; + if (i < len - 1) { + result = result + ','; } } - var5 = this.method1674(var5); + result = this.htmlEncode(result); } String var8; + String var4 = this.urlUserListPage.toLowerCase(); if (var4.startsWith("http:")) { if (this.urlTargetUserList != null) { var8 = this.urlUserListPage; - if (var5 != null) { - var8 = var8 + var5; + if (result != null) { + var8 = var8 + result; if (subgame != null) { var8 = var8 + "&subgame=" + subgame; } } - this.method1676(this.toURL(var8), this.urlTargetUserList); + this.showUrl(this.toURL(var8), this.urlTargetUserList); } } else { if (var4.startsWith("javascript:")) { var8 = this.urlUserListPage; - var8 = Tools.replaceFirst(var8, "%n", var5 != null ? var5 : ""); + var8 = Tools.replaceFirst(var8, "%n", result != null ? result : ""); var8 = Tools.replaceFirst(var8, "%s", subgame != null ? subgame : ""); URL var9 = this.toURL(var8); if (var9 == null) { return; } - this.method1676(var9, this.urlTargetUserList); + this.showUrl(var9, this.urlTargetUserList); } } } } - private String method1674(String var1) { - int var2 = var1.length(); - StringBuffer var3 = new StringBuffer(var2 * 3); + private String htmlEncode(String s) { + int len = s.length(); + StringBuffer result = new StringBuffer(len * 3); - for (int var6 = 0; var6 < var2; ++var6) { - char var4 = var1.charAt(var6); - if ((var4 < 65 || var4 > 90) && (var4 < 97 || var4 > 122) && (var4 < 48 || var4 > 57) && var4 != 45 && var4 != 126 && var4 != 44) { - String var5 = Integer.toHexString(var4 & 255); - var3.append('%'); - if (var5.length() < 2) { - var3.append(0); + for (int i = 0; i < len; ++i) { + char c = s.charAt(i); + if ((c < 65 || c > 90) && (c < 97 || c > 122) && (c < 48 || c > 57) && c != 45 && c != 126 && c != 44) { + String hex = Integer.toHexString(c & 255); + result.append('%'); + if (hex.length() < 2) { + result.append(0); } - var3.append(var5); + result.append(hex); } else { - var3.append(var4); + result.append(c); } } - return var3.toString(); + return result.toString(); } private boolean method1675(String[] var1, String var2) { @@ -807,15 +821,15 @@ private boolean method1675(String[] var1, String var2) { } } - private boolean method1676(URL var1, String var2) { - if (var1 == null) { + private boolean showUrl(URL url, String target) { + if (url == null) { return false; } else { - AppletContext var3 = this.anApplet1421.getAppletContext(); - if (var2 != null) { - var3.showDocument(var1, var2); + AppletContext appletContext = this.applet.getAppletContext(); + if (target != null) { + appletContext.showDocument(url, target); } else { - var3.showDocument(var1); + appletContext.showDocument(url); } return true; From 472b64da49824b46005fea21c47f1aafff4c3c55 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 15/16] Deobfuscate more code in GamePlayerInfoPanel This also includes removing the iterative modifying of the offsetY (now renamed to yBaseline) variable for drawing player info, instead it can be calculated in the loop based on the index variable. --- .../src/main/java/agolf/game/GamePanel.java | 2 +- .../java/agolf/game/GamePlayerInfoPanel.java | 96 ++++++++++--------- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/client/src/main/java/agolf/game/GamePanel.java b/client/src/main/java/agolf/game/GamePanel.java index 987d386b..46b74549 100644 --- a/client/src/main/java/agolf/game/GamePanel.java +++ b/client/src/main/java/agolf/game/GamePanel.java @@ -211,7 +211,7 @@ else if (args[1].equals("part")) { // player left game //this.requestFocus();//todo this is annoying as fuck } - this.gameContainer.gameApplet.showPlayerList(this.gamePlayerInfoPanel.method374()); + this.gameContainer.gameApplet.showPlayerList(this.gamePlayerInfoPanel.getPlayerNames()); } else { this.gameContainer.gameApplet.removePlayerListWinnders(); } diff --git a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java index f9778b88..dca01dbc 100644 --- a/client/src/main/java/agolf/game/GamePlayerInfoPanel.java +++ b/client/src/main/java/agolf/game/GamePlayerInfoPanel.java @@ -46,7 +46,7 @@ class GamePlayerInfoPanel extends Panel implements ItemListener, MouseListener { protected String[] playerNames; protected String[] playerClans; private SynchronizedInteger[][] trackStrokes; - private SynchronizedInteger[] playersId; + private SynchronizedInteger[] totalStrokes; private int[] playerLeaveReasons; // see PART_ enums in Lobby class private boolean[] playerVotedToSkip; private boolean[] playerReadyForNewGame; @@ -110,12 +110,12 @@ public void update(Graphics g) { } } - int offsetY = (5 - this.playerCount) * 13; + int yBaseline = (5 - this.playerCount) * 13; // draw highlight around scores for current track if (this.currentTrackIndex >= 0 && this.currentTrackIndex < this.trackCount) { this.graphics.setColor(currentTrackScoreHighlightColor); - this.graphics.fillRect(130 + this.currentTrackIndex * 20 - 5 + 1, offsetY - 13, 19, this.playerCount * 15 + 2); - this.graphics.fillRect(130 + this.currentTrackIndex * 20 - 5, offsetY - 13 + 1, 21, this.playerCount * 15 + 2 - 2); + this.graphics.fillRect(130 + this.currentTrackIndex * 20 - 5 + 1, yBaseline - 13, 19, this.playerCount * 15 + 2); + this.graphics.fillRect(130 + this.currentTrackIndex * 20 - 5, yBaseline - 13 + 1, 21, this.playerCount * 15 + 2 - 2); } // draw player status text @@ -125,12 +125,16 @@ public void update(Graphics g) { Color color = playerColors[player][playerLeft]; this.graphics.setFont(font); this.graphics.setColor(color); - if (this.playerCount > 1) { // draw 1., 2., etc in front of player name - this.graphics.drawString(player + 1 + ".", 2, offsetY); + + int yOffset = yBaseline + 15 * player; + // draw 1., 2., etc in front of player name + if (this.playerCount > 1) { + this.graphics.drawString(player + 1 + ".", 2, yOffset); } - if (this.playerNames[player] != null) { // draw player name - this.graphics.drawString(this.playerNames[player], 20, offsetY); + // draw player name + if (this.playerNames[player] != null) { + this.graphics.drawString(this.playerNames[player], 20, yOffset); } // draw track scores @@ -147,91 +151,89 @@ public void update(Graphics g) { } } - this.graphics.drawString(strokes >= 0 ? String.valueOf(strokes) : this.gameContainer.textManager.getGame("GamePlayerInfo_Skipped"), 130 + track * 20, offsetY); + this.graphics.drawString(strokes >= 0 ? String.valueOf(strokes) : this.gameContainer.textManager.getGame("GamePlayerInfo_Skipped"), 130 + track * 20, yOffset); this.graphics.setColor(color); } else if (this.trackScoresMultipliers[track] == 1) { - this.graphics.drawString("-", 130 + track * 20 + 5, offsetY); + this.graphics.drawString("-", 130 + track * 20 + 5, yOffset); } else { this.graphics.setFont(fontDialog10); this.graphics.setColor(playerColors[player][1]); - this.graphics.drawString("(*" + this.trackScoresMultipliers[track] + ")", 130 + track * 20, offsetY - 1); + this.graphics.drawString("(*" + this.trackScoresMultipliers[track] + ")", 130 + track * 20, yOffset - 1); this.graphics.setFont(font); this.graphics.setColor(color); } } // draw sum of player strokes - this.graphics.drawString("= " + this.playersId[player].get(), 130 + this.trackCount * 20 + 15, offsetY); + this.graphics.drawString("= " + this.totalStrokes[player].get(), 130 + this.trackCount * 20 + 15, yOffset); - String playerInfo = null; + String scoreDifference = null; int[] scoreDifferences = this.getScoreDifferences(); // draw difference with leader's score if (scoreDifferences != null && this.playerLeaveReasons[player] == 0) { if (scoreDifferences[player] == 0) { if (this.gameOutcome == null) { - playerInfo = this.gameContainer.textManager.getGame("GamePlayerInfo_Leader"); + scoreDifference = this.gameContainer.textManager.getGame("GamePlayerInfo_Leader"); } } else { - playerInfo = this.gameContainer.textManager.getGame("GamePlayerInfo_AfterLeader", (scoreDifferences[player] > 0 ? "+" : "") + scoreDifferences[player]); + scoreDifference = this.gameContainer.textManager.getGame("GamePlayerInfo_AfterLeader", (scoreDifferences[player] > 0 ? "+" : "") + scoreDifferences[player]); } - if (playerInfo != null) { - this.graphics.drawString(playerInfo, 130 + this.trackCount * 20 + 15 + 40, offsetY); + if (scoreDifference != null) { + this.graphics.drawString(scoreDifference, 130 + this.trackCount * 20 + 15 + 40, yOffset); } } - playerInfo = null; - String timeRemaining = null; + String statusMessage = null; // draw "waiting for player" text if lobby has empty slots if (this.playerNames[player] == null) { - playerInfo = "GamePlayerInfo_WaitingPlayer"; + statusMessage = "GamePlayerInfo_WaitingPlayer"; } + String timeRemaining = null; if (this.playerCount > 1 && this.activePlayerId == player) { if (this.activePlayerId == this.playerId) { - playerInfo = "GamePlayerInfo_OwnTurn"; + statusMessage = "GamePlayerInfo_OwnTurn"; if (this.timerThread != null && this.currentTimeForShot > 0 && (this.strokeTimeout > 0 || this.strokeTimeout == 0 && this.currentTimeForShot <= 30)) { timeRemaining = " (" + this.gameContainer.textManager.getTime(this.currentTimeForShot) + ")"; } } else { - playerInfo = "GamePlayerInfo_PlayerTurn"; + statusMessage = "GamePlayerInfo_PlayerTurn"; } } if (this.gameOutcome != null) { if (this.gameOutcome[player] == 1) { - playerInfo = "GamePlayerInfo_Winner"; + statusMessage = "GamePlayerInfo_Winner"; } else if (this.gameOutcome[player] == 0) { - playerInfo = "GamePlayerInfo_Draw"; + statusMessage = "GamePlayerInfo_Draw"; } } - if (playerInfo != null) { - this.graphics.drawString(this.gameContainer.textManager.getGame(playerInfo) + (timeRemaining != null ? timeRemaining : ""), 130 + this.trackCount * 20 + 15 + 40 + 40, offsetY); + if (statusMessage != null) { + this.graphics.drawString(this.gameContainer.textManager.getGame(statusMessage) + (timeRemaining != null ? timeRemaining : ""), 130 + this.trackCount * 20 + 15 + 40 + 40, yOffset); } - playerInfo = null; + String extraMessage = null; if (this.playerVotedToSkip[player]) { - playerInfo = "GamePlayerInfo_VoteSkipTrack"; + extraMessage = "GamePlayerInfo_VoteSkipTrack"; } if (this.playerReadyForNewGame[player]) { - playerInfo = "GamePlayerInfo_ReadyForNewGame"; + extraMessage = "GamePlayerInfo_ReadyForNewGame"; } if (this.playerLeaveReasons[player] == 5) { - playerInfo = "GamePlayerInfo_Quit_ConnectionProblem"; + extraMessage = "GamePlayerInfo_Quit_ConnectionProblem"; } if (this.playerLeaveReasons[player] == 4) { - playerInfo = "GamePlayerInfo_Quit_Part"; + extraMessage = "GamePlayerInfo_Quit_Part"; } - if (playerInfo != null) { - this.graphics.drawString(this.gameContainer.textManager.getGame(playerInfo), 130 + this.trackCount * 20 + 15 + 40 + 40 + 100, offsetY); + if (extraMessage != null) { + this.graphics.drawString(this.gameContainer.textManager.getGame(extraMessage), 130 + this.trackCount * 20 + 15 + 40 + 40 + 100, yOffset); } - - offsetY += 15; } } @@ -280,14 +282,14 @@ protected void init(int playerCount, int trackCount, int maxStrokes, int strokeT this.playerNames = new String[playerCount]; this.playerClans = new String[playerCount]; this.trackStrokes = new SynchronizedInteger[playerCount][trackCount]; - this.playersId = new SynchronizedInteger[playerCount]; + this.totalStrokes = new SynchronizedInteger[playerCount]; for (int player = 0; player < playerCount; ++player) { for (int track = 0; track < trackCount; ++track) { this.trackStrokes[player][track] = new SynchronizedInteger(); } - this.playersId[player] = new SynchronizedInteger(); + this.totalStrokes[player] = new SynchronizedInteger(); } this.playerLeaveReasons = new int[playerCount]; @@ -351,7 +353,7 @@ protected void reset() { this.trackStrokes[player][track].set(0); } - this.playersId[player].set(0); + this.totalStrokes[player].set(0); this.playerVotedToSkip[player] = this.playerReadyForNewGame[player] = false; } @@ -400,9 +402,9 @@ protected boolean startTurn(int playerId) { protected void strokeStartedOrEnded(int playerId, boolean isStrokeEnd) { if (this.trackScoring == 0) { - int var3 = !isStrokeEnd ? this.trackScoresMultipliers[this.currentTrackIndex] : 1; - this.trackStrokes[playerId][this.currentTrackIndex].add(var3); - this.playersId[playerId].add(var3); + int strokeCount = !isStrokeEnd ? this.trackScoresMultipliers[this.currentTrackIndex] : 1; + this.trackStrokes[playerId][this.currentTrackIndex].add(strokeCount); + this.totalStrokes[playerId].add(strokeCount); } else { this.trackStrokes[playerId][this.currentTrackIndex].add(1); } @@ -413,12 +415,12 @@ protected void strokeStartedOrEnded(int playerId, boolean isStrokeEnd) { protected void setScores(int trackId, int[] scores) { for (int player = 0; player < this.playerCount; ++player) { this.trackStrokes[player][trackId].set(scores[player]); - this.playersId[player].set(0); + this.totalStrokes[player].set(0); for (int track = 0; track <= trackId; ++track) { int strokes = this.trackStrokes[player][track].get(); if (strokes >= 0) { - this.playersId[player].add(strokes); + this.totalStrokes[player].add(strokes); } } } @@ -482,7 +484,7 @@ protected void setState(int state) { protected void method372() { if (this.trackScoring == 0) { - this.playersId[this.activePlayerId].add(-this.trackStrokes[this.activePlayerId][this.currentTrackIndex].get()); + this.totalStrokes[this.activePlayerId].add(-this.trackStrokes[this.activePlayerId][this.currentTrackIndex].get()); } this.trackStrokes[this.activePlayerId][this.currentTrackIndex].set(-1); @@ -493,7 +495,7 @@ protected String[] getPlayerName(int playerId) { return new String[]{this.playerNames[playerId], this.playerClans[playerId]}; } - protected String[] method374() { + protected String[] getPlayerNames() { return this.playerNames; } @@ -543,7 +545,7 @@ private int[] getScoreDifferences() { int score; for (int i = 0; i < this.playerCount; ++i) { if (this.playerLeaveReasons[i] == 0) { - score = this.playersId[i].get(); + score = this.totalStrokes[i].get(); if (this.trackScoring == 0 && score < bestScore) { bestScore = score; } @@ -558,7 +560,7 @@ private int[] getScoreDifferences() { int winnerCount = 0; for (int i = 0; i < this.playerCount; ++i) { - score = this.playersId[i].get(); + score = this.totalStrokes[i].get(); if (score == bestScore) { scoreDifferences[i] = 0; ++winnerCount; From 068ddc1fec71a2c09e9082d333764ce801cd9d73 Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 18 May 2024 23:04:32 +0300 Subject: [PATCH 16/16] Miscellaneous cleanup in server code These are drive-by fixes while debugging an issue, no functional changes. Highlight: renaming PacketHandlerFactoryGeneratorClassHelperImplementationDecorator -> PacketHandlerFactory. Looks like the original implementor was having fun with design pattern names. --- .../java/org/moparforia/server/Server.java | 18 +++++++----------- .../server/event/ClientDisconnectedEvent.java | 2 +- .../moparforia/server/event/TimedEvent.java | 5 ++--- .../server/net/ClientChannelHandler.java | 8 ++++---- ...ecorator.java => PacketHandlerFactory.java} | 14 +++++--------- 5 files changed, 19 insertions(+), 28 deletions(-) rename server/src/main/java/org/moparforia/server/net/{PacketHandlerFactoryGeneratorClassHelperImplementationDecorator.java => PacketHandlerFactory.java} (80%) diff --git a/server/src/main/java/org/moparforia/server/Server.java b/server/src/main/java/org/moparforia/server/Server.java index 404c96dd..8659aeb8 100644 --- a/server/src/main/java/org/moparforia/server/Server.java +++ b/server/src/main/java/org/moparforia/server/Server.java @@ -169,7 +169,7 @@ public void start() { return; } - packetHandlers = PacketHandlerFactoryGeneratorClassHelperImplementationDecorator.getPacketHandlers(); + packetHandlers = PacketHandlerFactory.getPacketHandlers(); System.out.println("Loaded " + packetHandlers.size() + " packet handler type(s)"); ChannelFactory factory = new NioServerSocketChannelFactory( @@ -179,16 +179,12 @@ public void start() { ServerBootstrap bootstrap = new ServerBootstrap(factory); final ClientChannelHandler clientHandler = new ClientChannelHandler(this); final IdleStateHandler idleState = new IdleStateHandler(new HashedWheelTimer(1, TimeUnit.SECONDS), 2, 0, 0); - bootstrap.setPipelineFactory(new ChannelPipelineFactory() { - public ChannelPipeline getPipeline() { - return Channels.pipeline( - new DelimiterBasedFrameDecoder(250, Delimiters.lineDelimiter()), - new PacketDecoder(), - new PacketEncoder(), - idleState, - clientHandler); - } - }); + bootstrap.setPipelineFactory(() -> Channels.pipeline( + new DelimiterBasedFrameDecoder(250, Delimiters.lineDelimiter()), + new PacketDecoder(), + new PacketEncoder(), + idleState, + clientHandler)); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.keepAlive", true); try { diff --git a/server/src/main/java/org/moparforia/server/event/ClientDisconnectedEvent.java b/server/src/main/java/org/moparforia/server/event/ClientDisconnectedEvent.java index 7ae8ce4e..09852fd8 100644 --- a/server/src/main/java/org/moparforia/server/event/ClientDisconnectedEvent.java +++ b/server/src/main/java/org/moparforia/server/event/ClientDisconnectedEvent.java @@ -16,7 +16,7 @@ public ClientDisconnectedEvent(Channel channel) { @Override public void process(Server server) { Player player; - if((player = (Player)channel.getAttachment()) != null) { + if ((player = (Player)channel.getAttachment()) != null) { if (player.getLobby() != null) { player.getLobby().removePlayer(player, Lobby.PART_REASON_USERLEFT,null); } diff --git a/server/src/main/java/org/moparforia/server/event/TimedEvent.java b/server/src/main/java/org/moparforia/server/event/TimedEvent.java index dd0aa520..c3b5e93e 100644 --- a/server/src/main/java/org/moparforia/server/event/TimedEvent.java +++ b/server/src/main/java/org/moparforia/server/event/TimedEvent.java @@ -2,13 +2,12 @@ import org.moparforia.server.Server; -@SuppressWarnings("SameParameterValue") public abstract class TimedEvent extends Event { private final long time; - public TimedEvent(long time) { - this.time = System.currentTimeMillis() + time; + public TimedEvent(long milliseconds) { + this.time = System.currentTimeMillis() + milliseconds; } @Override diff --git a/server/src/main/java/org/moparforia/server/net/ClientChannelHandler.java b/server/src/main/java/org/moparforia/server/net/ClientChannelHandler.java index 24e200d3..e6ecba48 100644 --- a/server/src/main/java/org/moparforia/server/net/ClientChannelHandler.java +++ b/server/src/main/java/org/moparforia/server/net/ClientChannelHandler.java @@ -35,24 +35,24 @@ public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exce } @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { + public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) { //noinspection ThrowableResultOfMethodCallIgnored e.getCause().printStackTrace(); e.getChannel().close(); } @Override - public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { + public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) { server.addEvent(new ClientConnectedEvent(e.getChannel())); } @Override - public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { + public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) { Channel channel = e.getChannel(); server.addEvent(new ClientDisconnectedEvent(channel)); final int id = channel.getId(); if (server.hasPlayer(id)) { - server.addEvent(new TimedEvent(30000) { // todo: confirm this time + server.addEvent(new TimedEvent(30_000) { // todo: confirm this time @Override public void process(Server server) { if (server.hasPlayer(id) && !server.getPlayer(id).getChannel().isOpen()) { diff --git a/server/src/main/java/org/moparforia/server/net/PacketHandlerFactoryGeneratorClassHelperImplementationDecorator.java b/server/src/main/java/org/moparforia/server/net/PacketHandlerFactory.java similarity index 80% rename from server/src/main/java/org/moparforia/server/net/PacketHandlerFactoryGeneratorClassHelperImplementationDecorator.java rename to server/src/main/java/org/moparforia/server/net/PacketHandlerFactory.java index 117ffbc7..67741f77 100644 --- a/server/src/main/java/org/moparforia/server/net/PacketHandlerFactoryGeneratorClassHelperImplementationDecorator.java +++ b/server/src/main/java/org/moparforia/server/net/PacketHandlerFactory.java @@ -6,11 +6,7 @@ import java.util.ArrayList; import java.util.HashMap; -/** - * Playforia - * 14.6.2013 - */ -public class PacketHandlerFactoryGeneratorClassHelperImplementationDecorator { +public class PacketHandlerFactory { //todo packethandlers for each game type ( should be pretty much the same for golf and golf2 ) public static final HashMap> getPacketHandlers() { @@ -19,10 +15,10 @@ public static final HashMap> getPacketHandl new LoginTypeHandler(), new NewHandler(), new PongHandler(), new ReconnectHandler(), new TlogHandler(), new TrackTestLoginHandler(), new VersionHandler(), new LobbyCreateSinglePlayerHandler(), new LobbyMultiplayerHandler(), new LobbyDualplayerHandler(), new QuitHandler()}; - ArrayList data = new ArrayList(); - ArrayList command = new ArrayList(); - ArrayList string = new ArrayList(); - ArrayList none = new ArrayList(); + ArrayList data = new ArrayList<>(); + ArrayList command = new ArrayList<>(); + ArrayList string = new ArrayList<>(); + ArrayList none = new ArrayList<>(); for (PacketHandler handler : handlers) { switch (handler.getType()) { case DATA: