mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-15 08:25:21 +01:00
Merge development into plugin-auth
This commit is contained in:
@@ -11,14 +11,18 @@ import static emu.grasscutter.Configuration.*;
|
||||
|
||||
public final class Crypto {
|
||||
private static final SecureRandom secureRandom = new SecureRandom();
|
||||
public static final long ENCRYPT_SEED = Long.parseUnsignedLong("11468049314633205968");
|
||||
public static byte[] ENCRYPT_SEED_BUFFER = new byte[0];
|
||||
|
||||
public static byte[] DISPATCH_KEY;
|
||||
public static byte[] DISPATCH_SEED;
|
||||
|
||||
public static byte[] ENCRYPT_KEY;
|
||||
public static long ENCRYPT_SEED = Long.parseUnsignedLong("11468049314633205968");
|
||||
public static byte[] ENCRYPT_SEED_BUFFER = new byte[0];
|
||||
|
||||
public static void loadKeys() {
|
||||
DISPATCH_KEY = FileUtils.read(KEYS_FOLDER + "/dispatchKey.bin");
|
||||
DISPATCH_SEED = FileUtils.read(KEYS_FOLDER + "/dispatchSeed.bin");
|
||||
|
||||
ENCRYPT_KEY = FileUtils.read(KEYS_FOLDER + "/secretKey.bin");
|
||||
ENCRYPT_SEED_BUFFER = FileUtils.read(KEYS_FOLDER + "/secretKeyBuffer.bin");
|
||||
}
|
||||
@@ -55,6 +59,6 @@ public final class Crypto {
|
||||
public static byte[] createSessionKey(int length) {
|
||||
byte[] bytes = new byte[length];
|
||||
secureRandom.nextBytes(bytes);
|
||||
return bytes;
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,9 @@ public final class Language {
|
||||
JsonObject object = this.languageData;
|
||||
|
||||
int index = 0;
|
||||
String result = "This value does not exist. Please report this to the Discord: " + key;
|
||||
String valueNotFoundPattern = "This value does not exist. Please report this to the Discord: ";
|
||||
String result = valueNotFoundPattern + key;
|
||||
boolean isValueFound = false;
|
||||
|
||||
while (true) {
|
||||
if(index == keys.length) break;
|
||||
@@ -171,10 +173,18 @@ public final class Language {
|
||||
if(element.isJsonObject())
|
||||
object = element.getAsJsonObject();
|
||||
else {
|
||||
isValueFound = true;
|
||||
result = element.getAsString(); break;
|
||||
}
|
||||
} else break;
|
||||
}
|
||||
|
||||
if (!isValueFound && !languageCode.equals("en-US")) {
|
||||
var englishValue = Grasscutter.getLanguage("en-US").get(key);
|
||||
if (!englishValue.contains(valueNotFoundPattern)) {
|
||||
result += "\nhere is english version:\n" + englishValue;
|
||||
}
|
||||
}
|
||||
|
||||
this.cachedTranslations.put(key, result); return result;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import emu.grasscutter.Grasscutter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@@ -304,14 +306,79 @@ public final class Utils {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a linear interpolation using a table of fixed points to create an effective piecewise f(x) = y function.
|
||||
* @param x
|
||||
* @param xyArray Array of points in [[x0,y0], ... [xN, yN]] format
|
||||
* @return f(x) = y
|
||||
*/
|
||||
public static int lerp(int x, int[][] xyArray) {
|
||||
try {
|
||||
if (x <= xyArray[0][0]){ // Clamp to first point
|
||||
return xyArray[0][1];
|
||||
} else if (x >= xyArray[xyArray.length-1][0]) { // Clamp to last point
|
||||
return xyArray[xyArray.length-1][1];
|
||||
}
|
||||
// At this point we're guaranteed to have two lerp points, and pity be somewhere between them.
|
||||
for (int i=0; i < xyArray.length-1; i++) {
|
||||
if (x == xyArray[i+1][0]) {
|
||||
return xyArray[i+1][1];
|
||||
}
|
||||
if (x < xyArray[i+1][0]) {
|
||||
// We are between [i] and [i+1], interpolation time!
|
||||
// Using floats would be slightly cleaner but we can just as easily use ints if we're careful with order of operations.
|
||||
int position = x - xyArray[i][0];
|
||||
int fullDist = xyArray[i+1][0] - xyArray[i][0];
|
||||
int prevValue = xyArray[i][1];
|
||||
int fullDelta = xyArray[i+1][1] - prevValue;
|
||||
return prevValue + ( (position * fullDelta) / fullDist );
|
||||
}
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Grasscutter.getLogger().error("Malformed lerp point array. Must be of form [[x0, y0], ..., [xN, yN]].");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an int is in an int[]
|
||||
* @param key int to look for
|
||||
* @param array int[] to look in
|
||||
* @return key in array
|
||||
*/
|
||||
public static boolean intInArray(int key, int[] array) {
|
||||
for (int i : array) {
|
||||
if (i == key) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of minuend without any elements found in subtrahend.
|
||||
* @param minuend The array we want elements from
|
||||
* @param subtrahend The array whose elements we don't want
|
||||
* @return The array with only the elements we want, in the order that minuend had them
|
||||
*/
|
||||
public static int[] setSubtract(int[] minuend, int[] subtrahend) {
|
||||
IntList temp = new IntArrayList();
|
||||
for (int i : minuend) {
|
||||
if (!intInArray(i, subtrahend)) {
|
||||
temp.add(i);
|
||||
}
|
||||
}
|
||||
return temp.toIntArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the language code from a given locale.
|
||||
* @param locale A locale.
|
||||
* @return A string in the format of 'XX-XX'.
|
||||
*/
|
||||
public static String getLanguageCode(Locale locale) {
|
||||
return String.format("%s-%s", locale.getLanguage(), locale.getCountry());
|
||||
}
|
||||
public static String getLanguageCode(Locale locale) {
|
||||
return String.format("%s-%s", locale.getLanguage(), locale.getCountry());
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 encodes a given byte array.
|
||||
|
||||
Reference in New Issue
Block a user