mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-25 04:04:25 +00:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7456725158 | ||
|
|
8023f4d1ea | ||
|
|
54339f9e66 | ||
|
|
3abba80b3b | ||
|
|
a7b64a1645 | ||
|
|
56c7e9196d | ||
|
|
f334a61faa | ||
|
|
873705c4fb |
No files matched your search
@@ -0,0 +1,49 @@
|
||||
name: Compatibility Test
|
||||
description: Enter a Minecraft world with a build artifact and require a CSL log (Linux runner).
|
||||
|
||||
inputs:
|
||||
artifact-name:
|
||||
description: Build artifact containing the Universal jar
|
||||
required: true
|
||||
minecraft:
|
||||
description: Minecraft version
|
||||
required: true
|
||||
modloader:
|
||||
description: Loader to install (forge, fabric, neoforge)
|
||||
required: true
|
||||
java:
|
||||
description: Java version for the game
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: ${{ inputs.java }}
|
||||
|
||||
- uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: ${{ inputs.artifact-name }}
|
||||
path: run/mods
|
||||
|
||||
- uses: headlesshq/[email protected]
|
||||
env:
|
||||
LIBGL_ALWAYS_SOFTWARE: 'true'
|
||||
with:
|
||||
mc: ${{ inputs.minecraft }}
|
||||
modloader: ${{ inputs.modloader }}
|
||||
regex: .*${{ inputs.modloader }}.*
|
||||
java: ${{ inputs.java }}
|
||||
mc-runtime-test: ${{ inputs.modloader == 'forge' && 'lexforge' || inputs.modloader }}
|
||||
dummy-assets: 'false'
|
||||
headlessmc-command: '--jvm "-Djava.awt.headless=true -DMcRuntimeGameTest=false"'
|
||||
|
||||
- name: Upload CSL log
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: CustomSkinLoader-Log-${{ inputs.minecraft }}-${{ inputs.modloader }}-Java${{ inputs.java }}-${{ github.job }}-${{ github.run_number }}
|
||||
path: run/CustomSkinLoader/CustomSkinLoader.log
|
||||
if-no-files-found: error
|
||||
@@ -1,9 +1,15 @@
|
||||
name: Pull Request
|
||||
on:
|
||||
push:
|
||||
branches: [ci/minecraft-smoke]
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
branches: [15-develop]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
@@ -14,3 +20,36 @@ jobs:
|
||||
- uses: ./.github/actions/build
|
||||
with:
|
||||
artifact-name: CustomSkinLoader-PR-${{ github.run_number }}
|
||||
|
||||
compatibility:
|
||||
name: Compatibility Test (${{ matrix.minecraft }}, ${{ matrix.modloader }}, Java ${{ matrix.java }})
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
matrix:
|
||||
include:
|
||||
- { minecraft: '1.12.2', modloader: forge, java: '8' }
|
||||
- { minecraft: '1.16.5', modloader: forge, java: '8' }
|
||||
- { minecraft: '1.16.5', modloader: fabric, java: '8' }
|
||||
- { minecraft: '1.18.2', modloader: forge, java: '17' }
|
||||
- { minecraft: '1.20.2', modloader: forge, java: '17' }
|
||||
- { minecraft: '1.20.2', modloader: fabric, java: '17' }
|
||||
- { minecraft: '1.20.4', modloader: forge, java: '17' }
|
||||
- { minecraft: '1.21.1', modloader: neoforge, java: '21' }
|
||||
- { minecraft: '1.21.4', modloader: fabric, java: '21' }
|
||||
- { minecraft: '1.21.10', modloader: neoforge, java: '21' }
|
||||
- { minecraft: '1.21.11', modloader: fabric, java: '21' }
|
||||
- { minecraft: '26.1.2', modloader: fabric, java: '25' }
|
||||
- { minecraft: '26.2', modloader: fabric, java: '25' }
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- uses: ./.github/actions/compatibility
|
||||
with:
|
||||
artifact-name: CustomSkinLoader-PR-${{ github.run_number }}
|
||||
minecraft: ${{ matrix.minecraft }}
|
||||
modloader: ${{ matrix.modloader }}
|
||||
java: ${{ matrix.java }}
|
||||
@@ -0,0 +1,22 @@
|
||||
package customskinloader.bootstrap;
|
||||
|
||||
public final class ModLoaderInfo {
|
||||
public static final String NAME_PROPERTY = "customskinloader.modLoader.name";
|
||||
public static final String VERSION_PROPERTY = "customskinloader.modLoader.version";
|
||||
|
||||
private ModLoaderInfo() {
|
||||
}
|
||||
|
||||
public static void publish(String name, String version) {
|
||||
if (name == null || name.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Mod loader name must not be empty");
|
||||
}
|
||||
if (version == null || version.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Mod loader version must not be empty");
|
||||
}
|
||||
|
||||
System.setProperty(NAME_PROPERTY, name);
|
||||
System.setProperty(VERSION_PROPERTY, version);
|
||||
BootstrapLogger.LOGGER.info("Detected mod loader " + name + " " + version);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package customskinloader.bootstrap.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
public class ReflectionUtils {
|
||||
private static final Map<String, Class<?>> CLASSES = new ConcurrentHashMap<>();
|
||||
private static final Map<Pair<Class<?>, String>, Field> FIELDS = new ConcurrentHashMap<>();
|
||||
private static final Map<Triple<Class<?>, String, List<Class<?>>>, Method> METHODS = new ConcurrentHashMap<>();
|
||||
|
||||
public static Class<?> findClass(String className) {
|
||||
return CLASSES.computeIfAbsent(className, k -> {
|
||||
try {
|
||||
return Class.forName(k);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Field findField(Class<?> clazz, String fieldName) {
|
||||
return FIELDS.computeIfAbsent(Pair.of(clazz, fieldName), k -> {
|
||||
try {
|
||||
Field f = k.getLeft().getDeclaredField(k.getRight());
|
||||
f.setAccessible(true);
|
||||
return f;
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Method findMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
|
||||
return METHODS.computeIfAbsent(Triple.of(clazz, methodName, Arrays.asList(parameterTypes)), k -> {
|
||||
try {
|
||||
Method m = k.getLeft().getDeclaredMethod(k.getMiddle(), k.getRight().toArray(new Class<?>[0]));
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+6
@@ -10,6 +10,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import customskinloader.bootstrap.BootstrapLogger;
|
||||
import customskinloader.bootstrap.ModLoaderInfo;
|
||||
import customskinloader.bootstrap.installer.CommonJarInstaller;
|
||||
import customskinloader.bootstrap.transformer.ClassTransformationReport;
|
||||
import customskinloader.bootstrap.transformer.TransformerBootstrapSupport;
|
||||
@@ -35,6 +36,7 @@ final class TransformerBootstrap {
|
||||
|
||||
public static void initialize() {
|
||||
LOGGER.info("Initializing CustomSkinLoader Bootstrap for Fabric");
|
||||
publishModLoaderInfo();
|
||||
releaseRuntimeArtifacts();
|
||||
int targetCount = 0;
|
||||
for (String targetClassName : SUPPORT.collectTargetClassNames()) {
|
||||
@@ -44,6 +46,10 @@ final class TransformerBootstrap {
|
||||
LOGGER.info("Initialized CustomSkinLoader Bootstrap for Fabric with " + targetCount + " reflected Mixin target(s)");
|
||||
}
|
||||
|
||||
private static void publishModLoaderInfo() {
|
||||
ModLoaderInfo.publish("Fabric", FabricLoader.getInstance().getModContainer("fabricloader").map(m -> m.getMetadata().getVersion().getFriendlyString()).orElse("unknown"));
|
||||
}
|
||||
|
||||
private static void releaseRuntimeArtifacts() {
|
||||
try {
|
||||
Path commonJar = CommonJarInstaller.releaseCommonJar(FabricLoader.getInstance().getGameDir(), "intermediary");
|
||||
|
||||
+5
@@ -6,10 +6,12 @@ import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
||||
import customskinloader.bootstrap.BootstrapLogger;
|
||||
import customskinloader.bootstrap.ModLoaderInfo;
|
||||
import customskinloader.bootstrap.installer.CommonJarInstaller;
|
||||
import customskinloader.bootstrap.transformer.ClassTransformationReport;
|
||||
import customskinloader.bootstrap.transformer.TransformerBootstrapSupport;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import net.minecraftforge.fml.relauncher.FMLInjectionData;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
@@ -22,6 +24,9 @@ final class TransformerBootstrap {
|
||||
|
||||
public static void injectData(Map<String, Object> data) {
|
||||
try {
|
||||
Object[] version = FMLInjectionData.data();
|
||||
ModLoaderInfo.publish("Forge", version[0] + "." + version[1] + "." + version[2] + "." + version[3]);
|
||||
|
||||
Path runtimeDirectory = resolveRuntimeDirectory(data);
|
||||
LOGGER.info("Initializing CustomSkinLoader Bootstrap for Forge v1 in " + BootstrapLogger.formatPath(runtimeDirectory));
|
||||
Path commonJar = CommonJarInstaller.releaseCommonJar(runtimeDirectory, "srg");
|
||||
|
||||
+1
-2
@@ -1,10 +1,9 @@
|
||||
package customskinloader.bootstrap.forge.v2;
|
||||
|
||||
import customskinloader.bootstrap.util.ModLocatorUtils;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModsFolderLocator;
|
||||
|
||||
import customskinloader.bootstrap.util.ModLocatorUtils;
|
||||
|
||||
public final class CommonModLocator extends ModsFolderLocator {
|
||||
public CommonModLocator() {
|
||||
ModLocatorUtils.initialize(this, ModsFolderLocator.class, FMLPaths.GAMEDIR.get(), "srg");
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ public final class TransformationService implements ITransformationService {
|
||||
@Override
|
||||
public void initialize(IEnvironment environment) {
|
||||
LOGGER.info("Initializing CustomSkinLoader Bootstrap transformation service");
|
||||
TransformerBootstrap.publishModLoaderInfo();
|
||||
try {
|
||||
List<Path> extraLocators = ModDirTransformerDiscoverer.getExtraLocators();
|
||||
Path servicePath = Paths.get(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).toAbsolutePath().normalize();
|
||||
|
||||
+32
@@ -4,27 +4,59 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import cpw.mods.modlauncher.ArgumentHandler;
|
||||
import cpw.mods.modlauncher.Launcher;
|
||||
import cpw.mods.modlauncher.api.ITransformer;
|
||||
import cpw.mods.modlauncher.api.ITransformerVotingContext;
|
||||
import cpw.mods.modlauncher.api.TransformerVoteResult;
|
||||
import customskinloader.bootstrap.BootstrapLogger;
|
||||
import customskinloader.bootstrap.ModLoaderInfo;
|
||||
import customskinloader.bootstrap.transformer.ClassTransformationReport;
|
||||
import customskinloader.bootstrap.transformer.TransformerBootstrapSupport;
|
||||
import customskinloader.bootstrap.util.ReflectionUtils;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
final class TransformerBootstrap {
|
||||
private static final Logger LOGGER = BootstrapLogger.LOGGER;
|
||||
private static final TransformerBootstrapSupport SUPPORT = new TransformerBootstrapSupport(TransformerBootstrap.class,
|
||||
// official: neoforge 1.20.2-20.2.3 ~ 1.21.3-21.3.97
|
||||
// srg: forge *, neoforge 1.21.4-21.4.0 ~ 1.21.9-21.9.13
|
||||
Launcher.INSTANCE.environment().findLaunchHandler("forgeclient")
|
||||
.map(handle -> handle.getClass().getName().startsWith("net.neoforged.")).orElse(false) ? "official" : "srg");
|
||||
|
||||
private TransformerBootstrap() {
|
||||
}
|
||||
|
||||
public static void publishModLoaderInfo() {
|
||||
try {
|
||||
Object argumentHandler = ReflectionUtils.findField(Launcher.class, "argumentHandler").get(Launcher.INSTANCE);
|
||||
String[] args = (String[]) ReflectionUtils.findField(ArgumentHandler.class, "args").get(argumentHandler);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
if (Objects.equals(arg, "--fml.forgeVersion")) {
|
||||
// forge 1.13.2-25.0.216 ~ 1.20.2-48.1.0
|
||||
ModLoaderInfo.publish("Forge", args[i + 1]);
|
||||
return;
|
||||
} else if (Objects.equals(arg, "--fml.neoForgeVersion")) {
|
||||
// neoforge 1.20.2-20.2.3 ~ 1.21.9-21.9.13
|
||||
ModLoaderInfo.publish("NeoForge", args[i + 1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// forge 1.20.3-49.0.1+
|
||||
ModLoaderInfo.publish("Forge", FMLLoader.class.getPackage().getImplementationVersion());
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Could not determine mod loader", e);
|
||||
ModLoaderInfo.publish("Forge", "unknown");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ITransformer> buildTransformers() {
|
||||
List<ITransformer> transformers = new ArrayList<>();
|
||||
for (String targetClassName : SUPPORT.collectTargetClassNames()) {
|
||||
|
||||
+1
@@ -9,6 +9,7 @@ public final class CommonModLocator extends ModsFolderLocator {
|
||||
ModLocatorUtils.initialize(this, ModsFolderLocator.class, FMLPaths.GAMEDIR.get(), "official");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return ModLocatorUtils.LOCATOR_NAME;
|
||||
}
|
||||
|
||||
+4
@@ -1,9 +1,12 @@
|
||||
package customskinloader.bootstrap.neoforge.v2;
|
||||
|
||||
import customskinloader.bootstrap.BootstrapLogger;
|
||||
import customskinloader.bootstrap.ModLoaderInfo;
|
||||
import net.neoforged.fml.loading.FMLLoader;
|
||||
import net.neoforged.neoforgespi.transformation.ClassProcessorProvider;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
// NeoForge 21.9.14+
|
||||
public final class ClassProcessorProviderImpl implements ClassProcessorProvider {
|
||||
private static final Logger LOGGER = BootstrapLogger.LOGGER;
|
||||
|
||||
@@ -11,6 +14,7 @@ public final class ClassProcessorProviderImpl implements ClassProcessorProvider
|
||||
public void createProcessors(Context context, Collector collector) {
|
||||
// Always register the bridge processor so late transformer registrations can still be observed.
|
||||
LOGGER.info("Registering CustomSkinLoader Bootstrap NeoForge class processor");
|
||||
ModLoaderInfo.publish("NeoForge", FMLLoader.getCurrent().getVersionInfo().neoForgeVersion());
|
||||
collector.add(TransformerBootstrap.createProcessor());
|
||||
}
|
||||
}
|
||||
+1
@@ -4,6 +4,7 @@ import customskinloader.bootstrap.util.ModLocatorUtils;
|
||||
import net.neoforged.fml.loading.FMLPaths;
|
||||
import net.neoforged.fml.loading.moddiscovery.locators.ModsFolderLocator;
|
||||
|
||||
// NeoForge 20.6.14+
|
||||
public final class CommonModLocator extends ModsFolderLocator {
|
||||
public CommonModLocator() {
|
||||
ModLocatorUtils.initialize(this, ModsFolderLocator.class, FMLPaths.GAMEDIR.get(), "official");
|
||||
|
||||
@@ -218,7 +218,7 @@ public class CustomSkinLoader {
|
||||
logger.info("Operating System: " + System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ") version " + System.getProperty("os.version"));
|
||||
logger.info("Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor"));
|
||||
logger.info("Java VM Version: " + System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor"));
|
||||
logger.info("Minecraft: " + MinecraftUtil.getMinecraftMainVersion());
|
||||
logger.info("Minecraft: " + MinecraftUtil.getMinecraftMainVersion() + " (" + MinecraftUtil.getLoaderName() + " " + MinecraftUtil.getLoaderVersion() + ")");
|
||||
return logger;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ public class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IPro
|
||||
public List<IDefaultProfile> getDefaultProfiles() {
|
||||
return Lists.newArrayList(new LocalSkin(this),
|
||||
getCapeProfile(this, "OptiFine", "https://optifine.net/capes/{USERNAME}.png", 810),
|
||||
getCapeProfile(this, "CloakPlus", "http://161.35.130.99/capes/{USERNAME}.png", 840),
|
||||
//getCapeProfile(this, "LabyMod", "https://dl.labymod.net/capes/{STANDARD_UUID}", 850),
|
||||
getCapeProfile(this, "Cosmetica", "https://api.cosmetica.cc/get/cloak?username={USERNAME}&uuid={STANDARD_UUID}¬hirdparty", 860)
|
||||
getCapeProfile(this, "CloakPlus", "http://161.35.130.99/capes/{USERNAME}.png", 840)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ public class HttpRequestUtil {
|
||||
CustomSkinLoader.logger.debug("Try to read cache '" + request.cacheFile + "'.");
|
||||
return loadFromCache(request, new HttpResponce());
|
||||
}
|
||||
CustomSkinLoader.logger.debug("Try to request '" + request.url + (request.userAgent == null ? "'." : "' with user agent '" + request.userAgent + "'."));
|
||||
String userAgent = UserAgentUtil.expandUserAgent(request.userAgent);
|
||||
CustomSkinLoader.logger.debug("Try to request '" + request.url + "' with user agent '" + userAgent + "'.");
|
||||
//Check Cache
|
||||
if (StringUtils.isNotEmpty(request.payload) || CustomSkinLoader.config.forceDisableCache) {
|
||||
request.cacheTime = -1;//No Cache
|
||||
@@ -156,9 +157,7 @@ public class HttpRequestUtil {
|
||||
c.setRequestProperty("If-None-Match", cacheInfo.etag);
|
||||
}
|
||||
c.setRequestProperty("Accept-Encoding", "gzip");
|
||||
if (request.userAgent != null) {
|
||||
c.setRequestProperty("User-Agent", request.userAgent);
|
||||
}
|
||||
c.setRequestProperty("User-Agent", userAgent);
|
||||
if (StringUtils.isNotEmpty(request.payload)) {
|
||||
CustomSkinLoader.logger.info("Payload: " + request.payload);
|
||||
c.setRequestMethod("POST");
|
||||
|
||||
@@ -12,8 +12,6 @@ import com.google.gson.JsonParser;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
|
||||
/**
|
||||
* @author Alexander Xia
|
||||
@@ -24,13 +22,6 @@ public class MinecraftUtil {
|
||||
return Minecraft.getInstance().gameDirectory;
|
||||
}
|
||||
|
||||
public static TextureManager getTextureManager() {
|
||||
return Minecraft.getInstance().getTextureManager();
|
||||
}
|
||||
|
||||
public static SkinManager getSkinManager() {
|
||||
return Minecraft.getInstance().getSkinManager();
|
||||
}
|
||||
private static String minecraftMainVersion = null;
|
||||
|
||||
public static String getMinecraftMainVersion() {
|
||||
@@ -67,6 +58,17 @@ public class MinecraftUtil {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
private static final String MOD_LOADER_NAME_PROPERTY = "customskinloader.modLoader.name";
|
||||
private static final String MOD_LOADER_VERSION_PROPERTY = "customskinloader.modLoader.version";
|
||||
|
||||
public static String getLoaderName() {
|
||||
return System.getProperty(MOD_LOADER_NAME_PROPERTY, "unknown");
|
||||
}
|
||||
|
||||
public static String getLoaderVersion() {
|
||||
return System.getProperty(MOD_LOADER_VERSION_PROPERTY, "unknown");
|
||||
}
|
||||
|
||||
// (domain|ip)(:port)
|
||||
public static String getServerAddress() {
|
||||
ServerData data = Minecraft.getInstance().getCurrentServer();
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package customskinloader.utils;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
|
||||
public final class UserAgentUtil {
|
||||
public static final String DEFAULT_USER_AGENT_PLACEHOLDER = "{DEFAULT_USER_AGENT}";
|
||||
public static final String CSL_VERSION_PLACEHOLDER = "{CSL_VERSION}";
|
||||
public static final String MINECRAFT_VERSION_PLACEHOLDER = "{MINECRAFT_VERSION}";
|
||||
public static final String MOD_LOADER_NAME_PLACEHOLDER = "{MOD_LOADER_NAME}";
|
||||
public static final String MOD_LOADER_VERSION_PLACEHOLDER = "{MOD_LOADER_VERSION}";
|
||||
public static final String JAVA_VERSION_PLACEHOLDER = "{JAVA_VERSION}";
|
||||
|
||||
private UserAgentUtil() {
|
||||
}
|
||||
|
||||
public static String expandUserAgent(String userAgent) {
|
||||
String modVersion = sanitizeComponent(CustomSkinLoader.CustomSkinLoader_FULL_VERSION);
|
||||
String minecraftVersion = sanitizeComponent(MinecraftUtil.getMinecraftMainVersion());
|
||||
String loaderName = sanitizeComponent(MinecraftUtil.getLoaderName());
|
||||
String loaderVersion = sanitizeComponent(MinecraftUtil.getLoaderVersion());
|
||||
String javaVersion = sanitizeComponent(System.getProperty("java.version", "unknown"));
|
||||
|
||||
String defaultUserAgent = "CustomSkinLoader/" + modVersion
|
||||
+ " (Minecraft/" + minecraftVersion
|
||||
+ "; " + loaderName + "/" + loaderVersion
|
||||
+ "; Java/" + javaVersion + ")";
|
||||
|
||||
if (userAgent == null) {
|
||||
return defaultUserAgent;
|
||||
}
|
||||
return userAgent
|
||||
.replace(DEFAULT_USER_AGENT_PLACEHOLDER, defaultUserAgent)
|
||||
.replace(CSL_VERSION_PLACEHOLDER, modVersion)
|
||||
.replace(MINECRAFT_VERSION_PLACEHOLDER, minecraftVersion)
|
||||
.replace(MOD_LOADER_NAME_PLACEHOLDER, loaderName)
|
||||
.replace(MOD_LOADER_VERSION_PLACEHOLDER, loaderVersion)
|
||||
.replace(JAVA_VERSION_PLACEHOLDER, javaVersion);
|
||||
}
|
||||
|
||||
private static String sanitizeComponent(String value) {
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
return "unknown";
|
||||
}
|
||||
String component = value.trim();
|
||||
StringBuilder sanitized = new StringBuilder(component.length());
|
||||
for (int i = 0; i < component.length(); i++) {
|
||||
char c = component.charAt(i);
|
||||
sanitized.append(c >= '0' && c <= '9'
|
||||
|| c >= 'A' && c <= 'Z'
|
||||
|| c >= 'a' && c <= 'z'
|
||||
|| "!#$%&'*+-.^_`|~".indexOf(c) >= 0 ? c : '_');
|
||||
}
|
||||
return sanitized.toString();
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,6 @@ Supported special skin sites and profiles:
|
||||
- [MinecraftCapes](https://minecraftcapes.net/)
|
||||
- [OptiFineCape](https://optifine.net/home)
|
||||
- [Cloaks+](https://cloaksplus.com/)
|
||||
- [Cosmetica](https://cosmetica.cc/)
|
||||
- [Wynntils](https://wynntils.com/) compatible profile support
|
||||
|
||||
You can customize the skin load list and load textures from any compatible skin server. Skin server owners can also use ExtraList files to help users add their server.
|
||||
@@ -131,7 +130,6 @@ GitHub Actions intentionally runs on Windows with PowerShell, but local project
|
||||
- [MinecraftCapes](https://minecraftcapes.net/)
|
||||
- [OptiFineCape](https://optifine.net/home)
|
||||
- [Cloaks+](https://cloaksplus.com/)
|
||||
- [Cosmetica](https://cosmetica.cc/)
|
||||
|
||||
If you want to add another skin server to the default list, please open an [issue](https://github.com/xfl03/MCCustomSkinLoader/issues).
|
||||
|
||||
@@ -148,7 +146,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||
### Major Contributor
|
||||
|
||||
- 2013-2014 Jeremy Lam ([JLChnToZ](https://github.com/JLChnToZ))
|
||||
- 2014-2024 Alexander Xia ([xfl03](https://github.com/xfl03))
|
||||
- 2014-2026 [xfl03](https://github.com/xfl03)
|
||||
- 2020-2026 [ZekerZhayard](https://github.com/ZekerZhayard)
|
||||
|
||||
### Binary File
|
||||
|
||||
Reference in new issue
Block a user