From 1f15d6219b120546e1c5849d0820058a016197c8 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 16 Sep 2023 21:40:49 +0000 Subject: [PATCH] Format code [skip actions] --- .../emu/grasscutter/net/packet/BasePacket.java | 1 - .../packet/recv/HandlerGetPlayerTokenReq.java | 3 +-- src/main/java/emu/grasscutter/utils/Crypto.java | 17 ++++++++--------- .../utils/algorithms/MersenneTwister64.java | 5 +++-- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/emu/grasscutter/net/packet/BasePacket.java b/src/main/java/emu/grasscutter/net/packet/BasePacket.java index 5918d93aa..bc65ae184 100644 --- a/src/main/java/emu/grasscutter/net/packet/BasePacket.java +++ b/src/main/java/emu/grasscutter/net/packet/BasePacket.java @@ -2,7 +2,6 @@ package emu.grasscutter.net.packet; import com.google.protobuf.GeneratedMessageV3; import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; -import emu.grasscutter.utils.Crypto; import java.io.*; public class BasePacket { diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java index edcc18a00..3a54acc52 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java @@ -119,8 +119,7 @@ public class HandlerGetPlayerTokenReq extends PacketHandler { var clientSeedEncrypted = Utils.base64Decode(req.getClientRandKey()); var clientSeed = ByteBuffer.wrap(cipher.doFinal(clientSeedEncrypted)).getLong(); - var seedBytes = - ByteBuffer.wrap(new byte[8]).putLong(encryptSeed ^ clientSeed).array(); + var seedBytes = ByteBuffer.wrap(new byte[8]).putLong(encryptSeed ^ clientSeed).array(); cipher.init(Cipher.ENCRYPT_MODE, Crypto.EncryptionKeys.get(req.getKeyId())); var seedEncrypted = cipher.doFinal(seedBytes); diff --git a/src/main/java/emu/grasscutter/utils/Crypto.java b/src/main/java/emu/grasscutter/utils/Crypto.java index 03f2644ac..597aa4c40 100644 --- a/src/main/java/emu/grasscutter/utils/Crypto.java +++ b/src/main/java/emu/grasscutter/utils/Crypto.java @@ -3,7 +3,6 @@ package emu.grasscutter.utils; import emu.grasscutter.Grasscutter; import emu.grasscutter.server.http.objects.QueryCurRegionRspJson; import emu.grasscutter.utils.algorithms.MersenneTwister64; - import java.io.ByteArrayOutputStream; import java.nio.file.Path; import java.security.*; @@ -36,9 +35,9 @@ public final class Crypto { try { CUR_SIGNING_KEY = - KeyFactory.getInstance("RSA") - .generatePrivate( - new PKCS8EncodedKeySpec(FileUtils.readResource("/keys/SigningKey.der"))); + KeyFactory.getInstance("RSA") + .generatePrivate( + new PKCS8EncodedKeySpec(FileUtils.readResource("/keys/SigningKey.der"))); Pattern pattern = Pattern.compile("([0-9]*)_Pub\\.der"); for (Path path : FileUtils.getPathsFromResource("/keys/game_keys")) { @@ -48,8 +47,8 @@ public final class Crypto { if (m.matches()) { var key = - KeyFactory.getInstance("RSA") - .generatePublic(new X509EncodedKeySpec(FileUtils.read(path))); + KeyFactory.getInstance("RSA") + .generatePublic(new X509EncodedKeySpec(FileUtils.read(path))); EncryptionKeys.put(Integer.valueOf(m.group(1)), key); } @@ -97,7 +96,7 @@ public final class Crypto { } public static QueryCurRegionRspJson encryptAndSignRegionData(byte[] regionInfo, String key_id) - throws Exception { + throws Exception { if (key_id == null) { throw new Exception("Key ID was not set"); } @@ -115,8 +114,8 @@ public final class Crypto { for (int i = 0; i < numChunks; i++) { byte[] chunk = - Arrays.copyOfRange( - regionInfo, i * chunkSize, Math.min((i + 1) * chunkSize, regionInfoLength)); + Arrays.copyOfRange( + regionInfo, i * chunkSize, Math.min((i + 1) * chunkSize, regionInfoLength)); byte[] encryptedChunk = cipher.doFinal(chunk); encryptedRegionInfoStream.write(encryptedChunk); } diff --git a/src/main/java/emu/grasscutter/utils/algorithms/MersenneTwister64.java b/src/main/java/emu/grasscutter/utils/algorithms/MersenneTwister64.java index 8709a2276..403b644a1 100644 --- a/src/main/java/emu/grasscutter/utils/algorithms/MersenneTwister64.java +++ b/src/main/java/emu/grasscutter/utils/algorithms/MersenneTwister64.java @@ -4,7 +4,8 @@ public final class MersenneTwister64 { // Period parameters private static final int N = 312; private static final int M = 156; - private static final long MATRIX_A = 0xB5026F5AA96619E9L; // private static final * constant vector a + private static final long MATRIX_A = + 0xB5026F5AA96619E9L; // private static final * constant vector a private static final long UPPER_MASK = 0xFFFFFFFF80000000L; // most significant w-r bits private static final int LOWER_MASK = 0x7FFFFFFF; // least significant r bits @@ -23,7 +24,7 @@ public final class MersenneTwister64 { long x; final long[] mag01 = {0x0L, MATRIX_A}; - if (mti >= N) { // generate N words at one time + if (mti >= N) { // generate N words at one time if (mti == N + 1) { setSeed(5489L); }