Upload files to "src/openonyx/skins"
This commit is contained in:
1 parent
4e53bf380d
commit
5738e90e8a
3 files changed
+260
No files matched your search
@@ -0,0 +1,190 @@
|
|||||||
|
package openonyx.skins;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import openonyx.connection.internal.AuthException;
|
||||||
|
import openonyx.connection.internal.AuthHttpClient;
|
||||||
|
import openonyx.connection.internal.AuthHttpClientData;
|
||||||
|
|
||||||
|
public final class SkinFetcher {
|
||||||
|
private static final int H = 15000;
|
||||||
|
private static final ExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(runnable -> {
|
||||||
|
Thread thread = new Thread(runnable, "onyx-skin-lookup");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
});
|
||||||
|
|
||||||
|
private SkinFetcher() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String L(String string) throws AuthException {
|
||||||
|
String string1 = string;
|
||||||
|
String string2 = new StringBuilder().insert(0, "https://api.mojang.com/users/profiles/minecraft/").append(AuthHttpClient.L(string1)).toString();
|
||||||
|
String[] strings = new String[0];
|
||||||
|
boolean bl = true;
|
||||||
|
AuthHttpClientData authHttpClientData;
|
||||||
|
if ((authHttpClientData = AuthHttpClient.L(string2, strings)).status() == 204 || authHttpClientData.status() == 404) {
|
||||||
|
throw new AuthException(new StringBuilder().insert(0, "No account named ").append(string1).toString());
|
||||||
|
} else if (!authHttpClientData.L()) {
|
||||||
|
throw new AuthException(new StringBuilder().insert(0, "Mojang lookup failed (").append(authHttpClientData.status()).append(")").toString());
|
||||||
|
} else if ((string = AuthHttpClient.L(authHttpClientData.L(), "id")) != null && string.length() == 32) {
|
||||||
|
return string;
|
||||||
|
} else {
|
||||||
|
throw new AuthException(new StringBuilder().insert(0, "Malformed profile for ").append(string1).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject L(String string) throws AuthException {
|
||||||
|
String string1 = string;
|
||||||
|
String string2 = new StringBuilder().insert(0, "https://sessionserver.mojang.com/session/minecraft/profile/").append(string1).toString();
|
||||||
|
String[] strings = new String[0];
|
||||||
|
boolean bl = true;
|
||||||
|
AuthHttpClientData authHttpClientData;
|
||||||
|
if (!(authHttpClientData = AuthHttpClient.L(string2, strings)).L()) {
|
||||||
|
throw new AuthException(new StringBuilder().insert(0, "Profile fetch failed (").append(authHttpClientData.status()).append(")").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonElement jsonElement3;
|
||||||
|
if ((jsonElement3 = authHttpClientData.L().get("properties")) != null && jsonElement3.isJsonArray()) {
|
||||||
|
Iterator iterator = jsonElement3.getAsJsonArray().iterator();
|
||||||
|
|
||||||
|
label47:
|
||||||
|
while (true) {
|
||||||
|
Iterator iterator1 = iterator;
|
||||||
|
|
||||||
|
while (iterator1.hasNext()) {
|
||||||
|
JsonElement jsonElement2;
|
||||||
|
if (!(jsonElement2 = (JsonElement)iterator.next()).isJsonObject()) {
|
||||||
|
iterator1 = iterator;
|
||||||
|
} else {
|
||||||
|
JsonObject jsonObject = jsonElement2.getAsJsonObject();
|
||||||
|
if ("textures".equals(AuthHttpClient.L(jsonObject, "name"))) {
|
||||||
|
if ((string = AuthHttpClient.L(jsonObject, "value")) == null) {
|
||||||
|
throw new AuthException("Profile has no textures");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
string = new String(Base64.getDecoder().decode(string), StandardCharsets.UTF_8);
|
||||||
|
JsonElement jsonElement1;
|
||||||
|
JsonElement jsonElement = (jsonElement1 = new JsonParser().parse(string)).isJsonObject()
|
||||||
|
? jsonElement1.getAsJsonObject().get("textures")
|
||||||
|
: null;
|
||||||
|
if (jsonElement != null && jsonElement.isJsonObject()) {
|
||||||
|
return jsonElement.getAsJsonObject();
|
||||||
|
}
|
||||||
|
continue label47;
|
||||||
|
} catch (RuntimeException runtimeException) {
|
||||||
|
throw new AuthException("Malformed texture property", runtimeException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator1 = iterator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new AuthException("Profile has no textures");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new AuthException("Profile has no textures");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void L(String string, Consumer<SkinFetcherData> consumer, Consumer<String> consumer1) {
|
||||||
|
EXECUTOR_SERVICE.submit(() -> {
|
||||||
|
try {
|
||||||
|
consumer.accept(L(string));
|
||||||
|
} catch (AuthException authException) {
|
||||||
|
consumer1.accept(authException.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SkinFetcherData L(String string) throws AuthException {
|
||||||
|
String string1 = string;
|
||||||
|
JsonElement jsonElement;
|
||||||
|
if ((jsonElement = L(L(string1)).get("SKIN")) != null && jsonElement.isJsonObject()) {
|
||||||
|
String string2;
|
||||||
|
if ((string2 = AuthHttpClient.L(jsonElement.getAsJsonObject(), "url")) == null) {
|
||||||
|
throw new AuthException(new StringBuilder().insert(0, string1).append(" has no custom skin").toString());
|
||||||
|
} else {
|
||||||
|
return new SkinFetcherData(L(string2), L(jsonElement.getAsJsonObject()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new AuthException(new StringBuilder().insert(0, string1).append(" has no custom skin").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BufferedImage L(String string) throws AuthException {
|
||||||
|
String string1 = string;
|
||||||
|
HttpURLConnection httpURLConnection = null;
|
||||||
|
|
||||||
|
BufferedImage bufferedImage1;
|
||||||
|
try {
|
||||||
|
httpURLConnection = (HttpURLConnection)new URL(string1).openConnection();
|
||||||
|
httpURLConnection.setConnectTimeout(15000);
|
||||||
|
httpURLConnection.setReadTimeout(15000);
|
||||||
|
httpURLConnection.setRequestProperty("User-Agent", "onyx");
|
||||||
|
InputStream inputStream = httpURLConnection.getInputStream();
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedImage bufferedImage;
|
||||||
|
if ((bufferedImage = ImageIO.read(inputStream)) == null) {
|
||||||
|
throw new AuthException("Skin download was not an image");
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferedImage1 = bufferedImage;
|
||||||
|
} catch (Throwable throwable1) {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throwable1.addSuppressed(throwable);
|
||||||
|
throw throwable1;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw throwable1;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw throwable1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException iOException) {
|
||||||
|
throw new AuthException("Couldn't download the skin", iOException);
|
||||||
|
} finally {
|
||||||
|
if (httpURLConnection != null) {
|
||||||
|
httpURLConnection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bufferedImage1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String L(JsonObject jsonObject) {
|
||||||
|
JsonObject jsonObject1 = jsonObject;
|
||||||
|
JsonElement jsonElement;
|
||||||
|
if ((jsonElement = jsonObject1.get("metadata")) != null && jsonElement.isJsonObject()) {
|
||||||
|
String string = AuthHttpClient.L(jsonElement.getAsJsonObject(), "model");
|
||||||
|
if ("slim".equals(string)) {
|
||||||
|
return "slim";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package openonyx.skins;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public record SkinFetcherData(BufferedImage image, String modelType) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package openonyx.skins;
|
||||||
|
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
public final class SkinOverride {
|
||||||
|
private static volatile ResourceLocation resourceLocation;
|
||||||
|
private static volatile String e;
|
||||||
|
|
||||||
|
public static boolean L() {
|
||||||
|
return resourceLocation != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String decrypt(String string) {
|
||||||
|
String string1 = string;
|
||||||
|
int k = --5 << 3 ^ 6;
|
||||||
|
String string2;
|
||||||
|
int n = (string2 = string1).length();
|
||||||
|
char[] ex = new char[n];
|
||||||
|
boolean bl = true;
|
||||||
|
int i;
|
||||||
|
int m = i = n - 1;
|
||||||
|
char[] c = ex;
|
||||||
|
byte d = 23;
|
||||||
|
k = m;
|
||||||
|
byte b = 93;
|
||||||
|
|
||||||
|
while (k >= 0) {
|
||||||
|
int l = i;
|
||||||
|
int j = string2.charAt(i);
|
||||||
|
i--;
|
||||||
|
c[l] = (char)(j ^ b);
|
||||||
|
if (i < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
j = i--;
|
||||||
|
c[j] = (char)(string2.charAt(j) ^ d);
|
||||||
|
k = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResourceLocation getResourceLocation() {
|
||||||
|
return resourceLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SkinOverride() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void L(ResourceLocation resourceLocation, String string) {
|
||||||
|
resourceLocation = resourceLocationx;
|
||||||
|
e = string == null ? "default" : string;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void L() {
|
||||||
|
resourceLocation = null;
|
||||||
|
e = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String L() {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user