mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-25 04:04:25 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e94f4b0e99 | ||
|
|
5ee2eee382 | ||
|
|
3063de7ff0 | ||
|
|
583bf1fe6a | ||
|
|
a3de21497d | ||
|
|
51aec265be | ||
|
|
52caeb3bdc | ||
|
|
a3fa4e47c6 | ||
|
|
e1cde0afc7 | ||
|
|
3f379f3cbe | ||
|
|
f50640139a | ||
|
|
46b8635e10 | ||
|
|
02b24229f3 | ||
|
|
941b421d86 | ||
|
|
a67ed507ec | ||
|
|
851fa81f31 | ||
|
|
5bb16ededa | ||
|
|
1e5bfcd1e7 | ||
|
|
1b85fa8ff9 | ||
|
|
e1e5319bdb | ||
|
|
187be47e88 | ||
|
|
b2f8d2cc38 | ||
|
|
8b641e0227 | ||
|
|
c90cea3721 | ||
|
|
b0c11d11c6 | ||
|
|
c77ac58f6d | ||
|
|
16fadc56b4 | ||
|
|
fc6c43bac9 | ||
|
|
b6fc1610bc | ||
|
|
c7d04976e6 | ||
|
|
0eaf1960bf | ||
|
|
cff5846e7f | ||
|
|
c8fb6e216e | ||
|
|
a5d466e0a7 | ||
|
|
31fffa5d23 | ||
|
|
7e9f7fa498 | ||
|
|
f51b55be6e | ||
|
|
584c7b7518 | ||
|
|
51c8900562 | ||
|
|
ab7aebb753 | ||
|
|
dc5ecfb576 | ||
|
|
04899ff676 | ||
|
|
4df8ce38d6 | ||
|
|
3e001c4cdf | ||
|
|
d5dea652ff | ||
|
|
2a4226527d | ||
|
|
6c9494970f | ||
|
|
c84f506af1 | ||
|
|
a0e31ed883 | ||
|
|
8befcb32d8 | ||
|
|
fb50a3db6d | ||
|
|
4daacd18e8 | ||
|
|
98681e8251 | ||
|
|
ea5d890992 | ||
|
|
f5135872cc | ||
|
|
5d736dd4b5 | ||
|
|
1b2a4dc260 | ||
|
|
855131d1aa | ||
|
|
581a2dddea | ||
|
|
a1b52eb7ac | ||
|
|
0ed371fdc1 | ||
|
|
ee7e57cf78 | ||
|
|
90ed224dd8 | ||
|
|
a65445e989 | ||
|
|
da79597a16 | ||
|
|
9c6102a813 | ||
|
|
573c5e4a20 | ||
|
|
12441cc379 | ||
|
|
7df6336b56 | ||
|
|
2dd69e08da | ||
|
|
67fbcf5cec | ||
|
|
f898831276 | ||
|
|
83042f45bd | ||
|
|
dc6d135699 | ||
|
|
f42496e04c | ||
|
|
f003d57ddf | ||
|
|
b64700b9fb | ||
|
|
f64af50a07 | ||
|
|
a8c8edaf20 |
No files matched your search
+11
-3
@@ -25,9 +25,17 @@ jobs:
|
|||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
- run: gradle --version
|
- run: gradle --version
|
||||||
- run: gradle clean build
|
- run:
|
||||||
- run: gradle upload
|
name: Build
|
||||||
- run: gradle publishGprPublicationToGitHubPackagesRepository
|
command: |
|
||||||
|
export GIT_COMMIT_DESC=$(git log --format=%B -n 1 $CIRCLE_SHA1)
|
||||||
|
gradle clean build
|
||||||
|
- run:
|
||||||
|
name: Publish
|
||||||
|
command: |
|
||||||
|
export GIT_COMMIT_DESC=$(git log --format=%B -n 1 $CIRCLE_SHA1)
|
||||||
|
gradle upload --info
|
||||||
|
# - run: gradle publishGprPublicationToGitHubPackagesRepository
|
||||||
|
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: ./build/libs
|
path: ./build/libs
|
||||||
|
|||||||
+7
-2
@@ -11,6 +11,7 @@ hs_err_pid*
|
|||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
# eclipse
|
# eclipse
|
||||||
|
bin/
|
||||||
*/.classpath
|
*/.classpath
|
||||||
.classpath
|
.classpath
|
||||||
*/.project
|
*/.project
|
||||||
@@ -21,11 +22,15 @@ hs_err_pid*
|
|||||||
# gradle
|
# gradle
|
||||||
.gradle/
|
.gradle/
|
||||||
build/
|
build/
|
||||||
gradle/
|
logs/
|
||||||
gradlew*
|
|
||||||
run/
|
run/
|
||||||
|
|
||||||
# IDEA
|
# IDEA
|
||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
out/
|
out/
|
||||||
|
|
||||||
|
#mac OS
|
||||||
|
.DS_Store
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
/**
|
|
||||||
* Gradle Script for COS
|
|
||||||
* It can be used to upload or download file from Tencent Cloud COS.
|
|
||||||
* COS: https://cloud.tencent.com/document/product/436
|
|
||||||
*/
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'com.qcloud:cos_api:5.4.6'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
import com.qcloud.cos.COSClient
|
|
||||||
import com.qcloud.cos.ClientConfig
|
|
||||||
import com.qcloud.cos.auth.BasicCOSCredentials
|
|
||||||
import com.qcloud.cos.auth.COSCredentials
|
|
||||||
import com.qcloud.cos.model.PutObjectRequest
|
|
||||||
import com.qcloud.cos.model.GetObjectRequest
|
|
||||||
import com.qcloud.cos.region.Region
|
|
||||||
|
|
||||||
String getMcVersion(String filename) {
|
|
||||||
if (filename.endsWith(".json"))
|
|
||||||
return filename.substring(0, filename.indexOf('-'))
|
|
||||||
return filename.substring(filename.indexOf('_') + 1, filename.indexOf('-'))
|
|
||||||
}
|
|
||||||
|
|
||||||
String getKey(String filename) {
|
|
||||||
String name = filename.substring(0, filename.lastIndexOf('.'))
|
|
||||||
if (name.indexOf('-') == -1) return null
|
|
||||||
if (filename.endsWith(".json"))
|
|
||||||
return String.format(
|
|
||||||
"versions/%s/%s",
|
|
||||||
name,
|
|
||||||
filename
|
|
||||||
)
|
|
||||||
if (filename.endsWith(".jar")) {
|
|
||||||
if (filename.contains("Fabric") || filename.contains("Forge")) {
|
|
||||||
return String.format(
|
|
||||||
"mods/%s",
|
|
||||||
filename
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return String.format(
|
|
||||||
"libraries/customskinloader/%s/%s/%s",
|
|
||||||
name.substring(0, name.indexOf('-')),
|
|
||||||
name.substring(name.indexOf('-') + 1),
|
|
||||||
filename
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filename
|
|
||||||
}
|
|
||||||
|
|
||||||
ext.bucketName = System.getenv("COS_BUCKET")
|
|
||||||
ext.cosUrl = "https://csl.littleservice.cn/"
|
|
||||||
ext.cosClient0 = null
|
|
||||||
|
|
||||||
COSClient getCosClient() {
|
|
||||||
if (cosClient0 != null) return cosClient0
|
|
||||||
|
|
||||||
COSCredentials cred = new BasicCOSCredentials(System.getenv("COS_SECRET_ID"), System.getenv("COS_SECRET_KEY"))
|
|
||||||
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"))
|
|
||||||
cosClient0 = new COSClient(cred, clientConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
void uploadFile(String key, File file) {
|
|
||||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file)
|
|
||||||
getCosClient().putObject(putObjectRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
void downloadFile(String key, File file) {
|
|
||||||
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key)
|
|
||||||
getCosClient().getObject(getObjectRequest, file)
|
|
||||||
}
|
|
||||||
|
|
||||||
String toJson(Map<String, Object> map, int d) {
|
|
||||||
StringBuilder sb = new StringBuilder("{\n")
|
|
||||||
Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator()
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Map.Entry<String, Object> e = it.next()
|
|
||||||
String k = e.key
|
|
||||||
String v = null
|
|
||||||
if (e.value instanceof String) {
|
|
||||||
v = "\"" + e.value + "\""
|
|
||||||
} else if (e.value instanceof Map) {
|
|
||||||
v = toJson((Map) e.value, d + 1)
|
|
||||||
}
|
|
||||||
for (int i = 0; i < d * 2; i++) {
|
|
||||||
sb.append(' ')
|
|
||||||
}
|
|
||||||
if (it.hasNext()) {
|
|
||||||
sb.append(String.format("\"%s\" : %s,\n", k, v))
|
|
||||||
} else {
|
|
||||||
sb.append(String.format("\"%s\" : %s\n", k, v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < (d - 1) * 2; i++) {
|
|
||||||
sb.append(' ')
|
|
||||||
}
|
|
||||||
sb.append("}")
|
|
||||||
return sb.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
String toJson(Map<String, Object> map) {
|
|
||||||
return toJson(map, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeToFile(File f, String s) {
|
|
||||||
FileWriter fw = new FileWriter(f)
|
|
||||||
fw.write(s)
|
|
||||||
fw.flush()
|
|
||||||
fw.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
void uploadArtifacts(String shortVersion) {
|
|
||||||
File dir = rootProject.file("build/libs")
|
|
||||||
if (!dir.isDirectory()) return
|
|
||||||
|
|
||||||
String cslversion = shortVersion.replace(".", "")
|
|
||||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>()
|
|
||||||
LinkedHashMap<String, String> map2 = new LinkedHashMap<String, String>()
|
|
||||||
LinkedHashMap<String, String> map3 = new LinkedHashMap<String, String>()
|
|
||||||
map.put("version", shortVersion)
|
|
||||||
map.put("downloads", map2)
|
|
||||||
map.put("launchermeta", map3)
|
|
||||||
|
|
||||||
File[] files = dir.listFiles()
|
|
||||||
for (file in files) {
|
|
||||||
String key = getKey(file.getName())
|
|
||||||
if (key == null) continue
|
|
||||||
uploadFile(key, file)
|
|
||||||
String url = cosUrl + key
|
|
||||||
String mcversion = getMcVersion(file.getName())
|
|
||||||
println(String.format("csl-%s-%s\t%s", mcversion.replace(".", "").toLowerCase(), cslversion, url))
|
|
||||||
|
|
||||||
if (key.endsWith(".jar")) {
|
|
||||||
map2.put(mcversion, url)
|
|
||||||
} else if (key.endsWith(".json")) {
|
|
||||||
map3.put(mcversion, url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File latest = new File("build/libs/latest.json")
|
|
||||||
writeToFile(latest, toJson(map))
|
|
||||||
uploadFile("latest.json", latest)
|
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
|
||||||
uploadArtifacts = this.&uploadArtifacts
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/**
|
|
||||||
* Gradle Script for Remap
|
|
||||||
* Designed for remapping jar.
|
|
||||||
* Remap Jar: mcp<->srg<->notch
|
|
||||||
*/
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
maven {
|
|
||||||
name = "forge"
|
|
||||||
url = "http://files.minecraftforge.net/maven"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'net.md-5:SpecialSource:1.8.6'
|
|
||||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
import net.md_5.specialsource.JarMapping
|
|
||||||
import net.md_5.specialsource.JarRemapper
|
|
||||||
import net.md_5.specialsource.provider.JarProvider
|
|
||||||
import net.md_5.specialsource.provider.JointProvider
|
|
||||||
|
|
||||||
|
|
||||||
void reobfSrgToNotch() {
|
|
||||||
def srgName = "${archivesBaseName}-${version}-srg.jar"
|
|
||||||
def notchName = srgName.replace('-srg', '')
|
|
||||||
if (config.srg_notch_map == null) {
|
|
||||||
//Default Map
|
|
||||||
def mcpName = srgName.replace('-srg', '-dev')
|
|
||||||
applySpecialSource(srgName, mcpName, getDefaultMap("srg-mcp"))
|
|
||||||
applySpecialSource(mcpName, notchName, getDefaultMap("mcp-notch"))
|
|
||||||
} else {
|
|
||||||
//Custom Map
|
|
||||||
applySpecialSource(srgName, notchName, config.srg_notch_map)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void applySpecialSource(String inputName, String outputName, String mapFile) {
|
|
||||||
def mapping = new JarMapping()
|
|
||||||
def srgFile = file(mapFile)
|
|
||||||
def inputFile = file("build/libs/${inputName}")
|
|
||||||
def outputFile = file("build/libs/${outputName}")
|
|
||||||
def remapper = new JarRemapper(null, mapping)
|
|
||||||
def inputJar = net.md_5.specialsource.Jar.init(inputFile)
|
|
||||||
def inheritanceProviders = new JointProvider()
|
|
||||||
def jarProvider = new JarProvider(inputJar)
|
|
||||||
inheritanceProviders.add(jarProvider)
|
|
||||||
mapping.loadMappings(srgFile)
|
|
||||||
mapping.setFallbackInheritanceProvider(inheritanceProviders)
|
|
||||||
remapper.remapJar(inputJar, outputFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
String getDefaultMap(String srgType) {
|
|
||||||
def mcpVersion = minecraft.mappings.replace('_', "/")
|
|
||||||
return System.getProperty('user.home') + "/.gradle/caches/minecraft/de/oceanlabs/mcp/mcp_${mcpVersion}/${config.forge_mc_version}/srgs/${srgType}.srg"
|
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
|
||||||
reobfSrgToNotch = this.&reobfSrgToNotch
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/**
|
|
||||||
* Gradle Script for Version
|
|
||||||
* Format Version String
|
|
||||||
*/
|
|
||||||
|
|
||||||
boolean isRelease() {
|
|
||||||
String s = rootProject.ext.config.snapshot
|
|
||||||
return s == null || s == "" || s == "0"
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isSnapshot() {
|
|
||||||
return !isRelease()
|
|
||||||
}
|
|
||||||
|
|
||||||
String getBuildNum() {
|
|
||||||
if (System.getenv("CIRCLE_BUILD_NUM") != null)
|
|
||||||
return System.getenv("CIRCLE_BUILD_NUM")
|
|
||||||
return "00"
|
|
||||||
}
|
|
||||||
|
|
||||||
//Example: 14.10a-SNAPSHOT-33
|
|
||||||
String getCSLVersion() {
|
|
||||||
return rootProject.ext.config.version + rootProject.ext.config.dev_version +
|
|
||||||
(isRelease() ? '' : ('-SNAPSHOT-' + getBuildNum()))
|
|
||||||
}
|
|
||||||
|
|
||||||
//Example: 14.10a-s33
|
|
||||||
String getShortVersion() {
|
|
||||||
return getCSLVersion().replace("SNAPSHOT-", "s")
|
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
|
||||||
getCSLVersion = this.&getCSLVersion
|
|
||||||
getShortVersion = this.&getShortVersion
|
|
||||||
}
|
|
||||||
+152
@@ -0,0 +1,152 @@
|
|||||||
|
# Development and Contribution
|
||||||
|
|
||||||
|
## Building
|
||||||
|
1. Run `./gradlew setupDecompWorkspace clean build` command.
|
||||||
|
1. The built jars are all in `${rootprojectDir}/build/libs` folder.
|
||||||
|
|
||||||
|
*NOTICE: The jar file with specific Minecraft version is for the vanilla edition without Forge and Fabric. The json files are launcher profiles which only work when building with our CI server.*
|
||||||
|
|
||||||
|
## Running and Testing
|
||||||
|
For now, CustomSkinLoader is unable to run under self development environment, so it needs to add to another development environment as a library.
|
||||||
|
There are the available versions in different environments below:
|
||||||
|
|
||||||
|
| | Forge | Fabric |
|
||||||
|
|:-----------------------:|:-----------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------:|
|
||||||
|
| Runtime Environment | forge-1.8-11.14.0.1237 ~ 1.13.2-25.0.22<br/> forge-1.13.2-25.0.42 ~ latest | fabric-loader-0.4.3+build.134 ~ latest<br/> Minecraft 18w43b ~ latest<br/> *fabric-api is not required* |
|
||||||
|
| Development Environment | ForgeGradle-2.1-SNAPSHOT ~ latest<br/> forge-1.8-11.14.3.1503 ~ 1.12.2-14.23.5.2855<br/> forge-1.13.2-25.0.198 ~ latest | fabric-loom-(?) ~ latest<br/> fabric-loader-0.12.0 ~ latest<br/> Minecraft 18w49a ~ latest<br/> *fabric-api is not required* |
|
||||||
|
|
||||||
|
### Preliminary steps for testing local builds
|
||||||
|
1. Create a new empty minecraft development environment.
|
||||||
|
1. Add below contents to `build.gradle`:
|
||||||
|
```gradle
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url = "file:/${projectDir}/local-repo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
1. Create these folders in the new project directory, then copy the built jar and source jar into it:
|
||||||
|
```
|
||||||
|
Forge 1.8 ~ 1.16.5: ./local-repo/mods/CustomSkinLoader_ForgeLegacy/${version}
|
||||||
|
Forge 1.17.1 ~ latest: ./local-repo/mods/CustomSkinLoader_ForgeActive/${version}
|
||||||
|
Fabric: ./local-repo/mods/CustomSkinLoader_Fabric/${version}
|
||||||
|
```
|
||||||
|
*`${version}` should be repalced with something like `14.14-SNAPSHOT-00` manually*
|
||||||
|
1. Create a pom file in the same folder:
|
||||||
|
- Forge 1.8 ~ 1.16.5: `CustomSkinLoader_ForgeLegacy-${version}.pom`
|
||||||
|
```xml
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>mods</groupId>
|
||||||
|
<artifactId>CustomSkinLoader_ForgeLegacy</artifactId>
|
||||||
|
<!-- `${version}` should be repalced with something like `14.14-SNAPSHOT-00` manually -->
|
||||||
|
<version>${version}</version>
|
||||||
|
</project>
|
||||||
|
```
|
||||||
|
- Forge 1.17.1 ~ latest: `CustomSkinLoader_ForgeActive-${version}.pom`
|
||||||
|
```xml
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>mods</groupId>
|
||||||
|
<artifactId>CustomSkinLoader_ForgeActive</artifactId>
|
||||||
|
<!-- `${version}` should be repalced with something like `14.14-SNAPSHOT-00` manually -->
|
||||||
|
<version>${version}</version>
|
||||||
|
</project>
|
||||||
|
```
|
||||||
|
- Fabric: `CustomSkinLoader_Fabric-${version}.pom`
|
||||||
|
```xml
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>mods</groupId>
|
||||||
|
<artifactId>CustomSkinLoader_Fabric</artifactId>
|
||||||
|
<!-- `${version}` should be repalced with something like `14.14-SNAPSHOT-00` manually -->
|
||||||
|
<version>${version}</version>
|
||||||
|
</project>
|
||||||
|
```
|
||||||
|
|
||||||
|
### For ForgeGradle 2.x ( forge-1.8-11.14.3.1503 ~ forge-1.12.2-14.23.5.2847 )
|
||||||
|
1. Add below contents to `build.gradle`:
|
||||||
|
```gradle
|
||||||
|
dependencies {
|
||||||
|
deobfCompile "mods:CustomSkinLoader_ForgeLegacy:14.14-SNAPSHOT-00"
|
||||||
|
}
|
||||||
|
|
||||||
|
minecraft {
|
||||||
|
clientRunArgs += ["--tweakClass", "customskinloader.forge.ForgeDevTweaker", "--username", "<Your username>"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
1. Run `./gradlew setupDecompWorkspace eclipse` command.
|
||||||
|
1. Due to the run configurations which generated by ForgeGradle 2 has not been compatible with IntelliJ IDEA 2020 and above, we recommend to install [Eclipser](https://plugins.jetbrains.com/plugin/7153-eclipser) plugin. It can convert Eclipse run configurations to IDEA. (Right click to `*.launch` file in project folder, then select `Convert with Eclipser`, then a new IDEA run configuration will be created.)
|
||||||
|
1. For IDEA, open `Run/Debug Configurations` dialog, change classpath of module to the name contains `.main`.
|
||||||
|
1. Add `--tweakClass customskinloader.forge.ForgeDevTweaker --username <Your username>` to CLI arguments in `Run/Debug Configurations` dialog.
|
||||||
|
1. Then you can debug the mod in IDE or through `./gradlew runClient` command.
|
||||||
|
|
||||||
|
### For ForgeGradle 3.x ~ 5.x ( forge-1.12.2-14.23.5.2851 ~ latest )
|
||||||
|
1. Add below contents to `build.gradle`:
|
||||||
|
```gradle
|
||||||
|
dependencies {
|
||||||
|
implementation fg.deobf("mods:CustomSkinLoader_ForgeLegacy:14.14-SNAPSHOT-00") // Only required for MinecraftForge 1.8 ~ 1.16.5
|
||||||
|
implementation fg.deobf("mods:CustomSkinLoader_ForgeActive:14.14-SNAPSHOT-00") // Only required for MinecraftForge 1.17.1 ~ latest
|
||||||
|
}
|
||||||
|
|
||||||
|
minecraft {
|
||||||
|
runs {
|
||||||
|
client {
|
||||||
|
args += ["--username", "<Your username>"]
|
||||||
|
args += ["--tweakClass", "customskinloader.forge.ForgeDevTweaker"] // Only required for MinecraftForge 1.12.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
1. Setup the development environment and run the game as usual.
|
||||||
|
|
||||||
|
### For fabric-loom ( fabric-loader-0.12.0 ~ latest )
|
||||||
|
1. Add below contents to `build.gradle`:
|
||||||
|
```gradle
|
||||||
|
dependencies {
|
||||||
|
modImplementation "mods:CustomSkinLoader_Fabric:14.14-SNAPSHOT-00"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.runClient {
|
||||||
|
args += ["--username", "<Your username>"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
1. Add `--username <Your username>` to CLI arguments in `Run/Debug Configurations` dialog.
|
||||||
|
1. Run the game in IDE or through `./gradlew runClient` command..
|
||||||
|
|
||||||
|
## Depend on release builds
|
||||||
|
1. Check the latest version in https://littlesk.in/csl-latest .
|
||||||
|
1. Add below contents to `build.gradle`:
|
||||||
|
```gradle
|
||||||
|
// Before Gradle 5.x
|
||||||
|
repositories {
|
||||||
|
ivy {
|
||||||
|
url = "https://csl.littleservice.cn/"
|
||||||
|
layout "pattern", {
|
||||||
|
artifact "[organisation]/[artifact]-[revision](-[classifier])(.[ext])"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// After Gradle 6.x
|
||||||
|
repositories {
|
||||||
|
ivy {
|
||||||
|
url = "https://csl.littleservice.cn/"
|
||||||
|
metadataSources {
|
||||||
|
artifact()
|
||||||
|
}
|
||||||
|
patternLayout {
|
||||||
|
artifact "[organisation]/[artifact]-[revision](-[classifier])(.[ext])"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
1. Follow the same steps in **Running and Testing**.
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
- CustomSkinLoader is based on forge-1.12.2-14.23.5.2768 currently, including Fabric edition. We use custom reobfuscation mappings such as [Fabric.tsrg](Fabric/Fabric.tsrg) and [mixin.tsrg](Fabric/mixin.tsrg) to generate different editions jar and Mixin reference jsons.
|
||||||
|
- The source codes are all in `${projectDir}/sources` and resource files are in `${projectDir}/resources` instead of `src/main/java` and `src/main/resources`.
|
||||||
|
- Do not add other required mods.
|
||||||
File renamed without changes.
@@ -0,0 +1,5 @@
|
|||||||
|
forge_mc_version=1.12.2
|
||||||
|
forge_version=14.23.5.2768
|
||||||
|
mappings_version=stable_39
|
||||||
|
# this subproject is only to provide dependency for other subprojects.
|
||||||
|
is_real_project=false
|
||||||
@@ -2,20 +2,22 @@ package customskinloader;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
|
||||||
|
|
||||||
import customskinloader.config.Config;
|
import customskinloader.config.Config;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.loader.*;
|
import customskinloader.loader.ProfileLoader;
|
||||||
import customskinloader.profile.DynamicSkullManager;
|
import customskinloader.profile.DynamicSkullManager;
|
||||||
import customskinloader.profile.ModelManager0;
|
import customskinloader.profile.ModelManager0;
|
||||||
import customskinloader.profile.ProfileCache;
|
import customskinloader.profile.ProfileCache;
|
||||||
@@ -24,128 +26,161 @@ import customskinloader.utils.MinecraftUtil;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom skin loader mod for Minecraft.
|
* Custom skin loader mod for Minecraft.
|
||||||
|
*
|
||||||
* @author (C) Jeremy Lam [JLChnToZ] 2013-2014 & Alexander Xia [xfl03] 2014-2020
|
* @author (C) Jeremy Lam [JLChnToZ] 2013-2014 & Alexander Xia [xfl03] 2014-2020
|
||||||
* @version @MOD_FULL_VERSION@
|
* @version @MOD_FULL_VERSION@
|
||||||
*/
|
*/
|
||||||
public class CustomSkinLoader {
|
public class CustomSkinLoader {
|
||||||
public static final String CustomSkinLoader_VERSION="@MOD_VERSION@";
|
public static final String CustomSkinLoader_VERSION = "@MOD_VERSION@";
|
||||||
public static final String CustomSkinLoader_FULL_VERSION="@MOD_FULL_VERSION@";
|
public static final String CustomSkinLoader_FULL_VERSION = "@MOD_FULL_VERSION@";
|
||||||
|
public static final int CustomSkinLoader_BUILD_NUMBER = Integer.parseInt("@MOD_BUILD_NUMBER@");
|
||||||
|
|
||||||
public static final File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader"),
|
public static final File
|
||||||
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
|
DATA_DIR = new File(MinecraftUtil.getMinecraftDataDir(), "CustomSkinLoader"),
|
||||||
CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json");
|
LOG_FILE = new File(DATA_DIR, "CustomSkinLoader.log"),
|
||||||
public static final SkinSiteProfile[] DEFAULT_LOAD_LIST={
|
CONFIG_FILE = new File(DATA_DIR, "CustomSkinLoader.json");
|
||||||
SkinSiteProfile.createMojangAPI("Mojang"),
|
|
||||||
SkinSiteProfile.createCustomSkinAPI("LittleSkin","https://littlesk.in/csl/"),
|
|
||||||
SkinSiteProfile.createCustomSkinAPI("BlessingSkin","http://skin.prinzeugen.net/"),
|
|
||||||
//OneSkin has been removed temporarily
|
|
||||||
//SkinSiteProfile.createCustomSkinAPI("OneSkin","http://fleey.cn/skin/skin_user/skin_json.php/"),
|
|
||||||
//Minecrack could not load skin correctly
|
|
||||||
//SkinSiteProfile.creatLegacy("Minecrack","http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png","http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png",null),
|
|
||||||
SkinSiteProfile.createElyByAPI("ElyBy"),
|
|
||||||
SkinSiteProfile.createUniSkinAPI("SkinMe","http://www.skinme.cc/uniskin/"),
|
|
||||||
SkinSiteProfile.createLegacy("LocalSkin","LocalSkin/skins/{USERNAME}.png","LocalSkin/capes/{USERNAME}.png","LocalSkin/elytras/{USERNAME}.png"),
|
|
||||||
SkinSiteProfile.createGlitchlessAPI("GlitchlessGames","https://games.glitchless.ru/api/minecraft/users/profiles/textures/?nickname=")};
|
|
||||||
|
|
||||||
public static final Gson GSON=new GsonBuilder().setPrettyPrinting().create();
|
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
public static final Logger logger=initLogger();
|
public static final Logger logger = initLogger();
|
||||||
public static final Config config=Config.loadConfig0();
|
public static final Config config = Config.loadConfig0();
|
||||||
|
|
||||||
private static final ProfileCache profileCache=new ProfileCache();
|
private static final ProfileCache profileCache = new ProfileCache();
|
||||||
private static final DynamicSkullManager dynamicSkullManager=new DynamicSkullManager();
|
private static final DynamicSkullManager dynamicSkullManager = new DynamicSkullManager();
|
||||||
|
|
||||||
private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>());
|
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>());
|
||||||
|
|
||||||
|
//Correct thread name in thread pool
|
||||||
|
private static final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
|
||||||
|
private static final ThreadFactory customFactory = r -> {
|
||||||
|
Thread t = defaultFactory.newThread(r);
|
||||||
|
if (r instanceof Thread) {
|
||||||
|
t.setName(((Thread) r).getName());
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
//Thread pool will discard oldest task when queue reaches 333 tasks
|
||||||
|
private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
|
||||||
|
config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES,
|
||||||
|
new LinkedBlockingQueue<>(333), customFactory, new ThreadPoolExecutor.DiscardOldestPolicy()
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void loadProfileTextures(Runnable runnable) {
|
||||||
|
THREAD_POOL.execute(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadProfileLazily(GameProfile gameProfile, Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>> consumer) {
|
||||||
|
String username = gameProfile.getName();
|
||||||
|
String credential = MinecraftUtil.getCredential(gameProfile);
|
||||||
|
// Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713
|
||||||
|
if (username == null) {
|
||||||
|
logger.warning("Could not load profile: username is null.");
|
||||||
|
consumer.accept(Maps.newHashMap());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String tempName = Thread.currentThread().getName();
|
||||||
|
Thread.currentThread().setName(username); // Change Thread Name
|
||||||
|
if (profileCache.isLoading(credential)) {
|
||||||
|
profileCache.putLoader(credential, consumer);
|
||||||
|
Thread.currentThread().setName(tempName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
consumer.accept(loadProfile(gameProfile));
|
||||||
|
Thread.currentThread().setName(tempName);
|
||||||
|
profileCache.getLastLoader(credential).ifPresent(c -> loadProfileLazily(gameProfile, c));
|
||||||
|
}
|
||||||
|
|
||||||
//For User Skin
|
//For User Skin
|
||||||
public static Map<Type, MinecraftProfileTexture> loadProfile(GameProfile gameProfile){
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadProfile(GameProfile gameProfile) {
|
||||||
String username=gameProfile.getName();
|
String credential = MinecraftUtil.getCredential(gameProfile);
|
||||||
String credential=MinecraftUtil.getCredential(gameProfile);
|
|
||||||
//Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713
|
|
||||||
if(username==null){
|
|
||||||
logger.warning("Could not load profile: username is null.");
|
|
||||||
return Maps.newHashMap();
|
|
||||||
}
|
|
||||||
String tempName=Thread.currentThread().getName();
|
|
||||||
Thread.currentThread().setName(username);//Change Thread Name
|
|
||||||
UserProfile profile;
|
UserProfile profile;
|
||||||
if(profileCache.isReady(credential)){
|
if (profileCache.isReady(credential)) {
|
||||||
logger.info("Cached profile will be used.");
|
logger.info("Cached profile will be used.");
|
||||||
profile=profileCache.getProfile(credential);
|
profile = profileCache.getProfile(credential);
|
||||||
if(profile==null){
|
if (profile == null) {
|
||||||
logger.warning("(!Cached Profile is empty!) Expiry:"+profileCache.getExpiry(credential));
|
logger.warning("(Cached Profile is empty!) Expiry: " + profileCache.getExpiry(credential));
|
||||||
if(profileCache.isExpired(credential))//force load
|
if (profileCache.isExpired(credential)) { // force load
|
||||||
profile=loadProfile0(gameProfile);
|
profile = loadProfile0(gameProfile, false);
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
logger.info(profile.toString(profileCache.getExpiry(credential)));
|
logger.info(profile.toString(profileCache.getExpiry(credential)));
|
||||||
}else{
|
}
|
||||||
|
} else {
|
||||||
profileCache.setLoading(credential, true);
|
profileCache.setLoading(credential, true);
|
||||||
profile=loadProfile0(gameProfile);
|
profile = loadProfile0(gameProfile, false);
|
||||||
}
|
}
|
||||||
Thread.currentThread().setName(tempName);
|
|
||||||
return ModelManager0.fromUserProfile(profile);
|
return ModelManager0.fromUserProfile(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Core
|
//Core
|
||||||
public static UserProfile loadProfile0(GameProfile gameProfile){
|
public static UserProfile loadProfile0(GameProfile gameProfile, boolean isSkull) {
|
||||||
String username=gameProfile.getName();
|
String username = gameProfile.getName();
|
||||||
String credential=MinecraftUtil.getCredential(gameProfile);
|
String credential = MinecraftUtil.getCredential(gameProfile);
|
||||||
|
|
||||||
profileCache.setLoading(credential, true);
|
profileCache.setLoading(credential, true);
|
||||||
logger.info("Loading "+username+"'s profile.");
|
logger.info("Loading " + username + "'s profile.");
|
||||||
if(config.loadlist==null||config.loadlist.isEmpty()){
|
if (config.loadlist == null || config.loadlist.isEmpty()) {
|
||||||
logger.info("LoadList is Empty.");
|
logger.info("LoadList is Empty.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserProfile profile0=new UserProfile();
|
UserProfile profile0 = new UserProfile();
|
||||||
for(int i=0;i<config.loadlist.size();i++){
|
for (int i = 0; i < config.loadlist.size(); i++) {
|
||||||
SkinSiteProfile ssp=config.loadlist.get(i);
|
SkinSiteProfile ssp = config.loadlist.get(i);
|
||||||
logger.info((i+1)+"/"+config.loadlist.size()+" Try to load profile from '"+ssp.name+"'.");
|
logger.info((i + 1) + "/" + config.loadlist.size() + " Try to load profile from '" + ssp.name + "'.");
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
if (ssp.type == null) {
|
||||||
if(loader==null){
|
logger.info("The type of '" + ssp.name + "' is null.");
|
||||||
logger.info("Type '"+ssp.type+"' is not defined.");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UserProfile profile=null;
|
ProfileLoader.IProfileLoader loader = ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
try{
|
if (loader == null) {
|
||||||
profile=loader.loadProfile(ssp, gameProfile);
|
logger.info("Type '" + ssp.type + "' is not defined.");
|
||||||
}catch(Exception e){
|
continue;
|
||||||
|
}
|
||||||
|
UserProfile profile = null;
|
||||||
|
try {
|
||||||
|
profile = loader.loadProfile(ssp, gameProfile);
|
||||||
|
} catch (Exception e) {
|
||||||
logger.warning("Exception occurs while loading.");
|
logger.warning("Exception occurs while loading.");
|
||||||
logger.warning(e);
|
logger.warning(e);
|
||||||
if(e.getCause()!=null) {
|
if (e.getCause() != null) {
|
||||||
logger.warning("Caused By:");
|
logger.warning("Caused By:");
|
||||||
logger.warning(e.getCause());
|
logger.warning(e.getCause());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(profile==null)
|
if (profile == null) {
|
||||||
continue;
|
continue;
|
||||||
if(!config.forceLoadAllTextures){
|
|
||||||
profile0=profile;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
profile0.mix(profile);
|
profile0.mix(profile);
|
||||||
if(profile0.isFull())
|
if (isSkull && !profile0.hasSkinUrl()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!config.forceLoadAllTextures) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
if (profile0.isFull()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!profile0.isEmpty()){
|
if (!profile0.isEmpty()) {
|
||||||
logger.info(username+"'s profile loaded.");
|
logger.info(username + "'s profile loaded.");
|
||||||
if(!config.enableCape)
|
if (!config.enableCape) {
|
||||||
profile0.capeUrl = null;
|
profile0.capeUrl = null;
|
||||||
|
}
|
||||||
profileCache.updateCache(credential, profile0);
|
profileCache.updateCache(credential, profile0);
|
||||||
profileCache.setLoading(credential, false);
|
profileCache.setLoading(credential, false);
|
||||||
logger.info(profile0.toString(profileCache.getExpiry(credential)));
|
logger.info(profile0.toString(profileCache.getExpiry(credential)));
|
||||||
return profile0;
|
return profile0;
|
||||||
}
|
}
|
||||||
logger.info(username+"'s profile not found in load list.");
|
logger.info(username + "'s profile not found in load list.");
|
||||||
|
|
||||||
if(config.enableLocalProfileCache){
|
if (config.enableLocalProfileCache) {
|
||||||
UserProfile profile=profileCache.getLocalProfile(credential);
|
UserProfile profile = profileCache.getLocalProfile(credential);
|
||||||
if(profile==null)
|
if (profile == null) {
|
||||||
logger.info(username+"'s LocalProfile not found.");
|
logger.info(username + "'s LocalProfile not found.");
|
||||||
else{
|
} else {
|
||||||
profileCache.updateCache(credential, profile, false);
|
profileCache.updateCache(credential, profile, false);
|
||||||
profileCache.setLoading(credential, false);
|
profileCache.setLoading(credential, false);
|
||||||
logger.info(username+"'s LocalProfile will be used.");
|
logger.info(username + "'s LocalProfile will be used.");
|
||||||
logger.info(profile.toString(profileCache.getExpiry(credential)));
|
logger.info(profile.toString(profileCache.getExpiry(credential)));
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
@@ -155,14 +190,17 @@ public class CustomSkinLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//For Skull
|
//For Skull
|
||||||
public static Map<Type, MinecraftProfileTexture> loadProfileFromCache(final GameProfile gameProfile) {
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadProfileFromCache(final GameProfile gameProfile) {
|
||||||
String username=gameProfile.getName();
|
String username = gameProfile.getName();
|
||||||
String credential=MinecraftUtil.getCredential(gameProfile);
|
String credential = MinecraftUtil.getCredential(gameProfile);
|
||||||
|
|
||||||
if(username == null || credential == null)
|
//CustomSkinLoader needs username to load standard skin, if username not exist, only textures in NBT can be used
|
||||||
|
//Authlib 3.11.50 makes empty username to "\u0020"
|
||||||
|
if (username == null || username.isEmpty() || username.equals("\u0020") || credential == null) {
|
||||||
return dynamicSkullManager.getTexture(gameProfile);
|
return dynamicSkullManager.getTexture(gameProfile);
|
||||||
if(config.enableUpdateSkull?profileCache.isReady(credential):profileCache.isExist(credential)){
|
}
|
||||||
UserProfile profile=profileCache.getProfile(credential);
|
if (config.forceUpdateSkull ? profileCache.isReady(credential) : profileCache.isExist(credential)) {
|
||||||
|
UserProfile profile = profileCache.getProfile(credential);
|
||||||
return ModelManager0.fromUserProfile(profile);
|
return ModelManager0.fromUserProfile(profile);
|
||||||
}
|
}
|
||||||
if (!profileCache.isLoading(credential)) {
|
if (!profileCache.isLoading(credential)) {
|
||||||
@@ -170,10 +208,10 @@ public class CustomSkinLoader {
|
|||||||
Runnable loadThread = () -> {
|
Runnable loadThread = () -> {
|
||||||
String tempName = Thread.currentThread().getName();
|
String tempName = Thread.currentThread().getName();
|
||||||
Thread.currentThread().setName(username + "'s skull");
|
Thread.currentThread().setName(username + "'s skull");
|
||||||
loadProfile0(gameProfile);//Load in thread
|
loadProfile0(gameProfile, true);//Load in thread
|
||||||
Thread.currentThread().setName(tempName);
|
Thread.currentThread().setName(tempName);
|
||||||
};
|
};
|
||||||
if (config.enableUpdateSkull) {
|
if (config.forceUpdateSkull) {
|
||||||
new Thread(loadThread).start();
|
new Thread(loadThread).start();
|
||||||
} else {
|
} else {
|
||||||
threadPool.execute(loadThread);
|
threadPool.execute(loadThread);
|
||||||
@@ -183,10 +221,13 @@ public class CustomSkinLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Logger initLogger() {
|
private static Logger initLogger() {
|
||||||
Logger logger=new Logger(LOG_FILE);
|
Logger logger = new Logger(LOG_FILE);
|
||||||
logger.info("CustomSkinLoader "+CustomSkinLoader_FULL_VERSION);
|
logger.info("CustomSkinLoader " + CustomSkinLoader_FULL_VERSION);
|
||||||
logger.info("DataDir: "+DATA_DIR.getAbsolutePath());
|
logger.info("DataDir: " + DATA_DIR.getAbsolutePath());
|
||||||
logger.info("Minecraft: "+MinecraftUtil.getMinecraftMainVersion()+"("+MinecraftUtil.getMinecraftVersionText()+")");
|
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());
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,8 @@ import java.io.BufferedWriter;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -97,10 +99,8 @@ public class Logger {
|
|||||||
warning(String.format(format, objs));
|
warning(String.format(format, objs));
|
||||||
}
|
}
|
||||||
public void warning(Throwable e){
|
public void warning(Throwable e){
|
||||||
log(Level.WARNING,"Exception: "+e.toString());
|
StringWriter sw = new StringWriter();
|
||||||
StackTraceElement[] stes=e.getStackTrace();
|
e.printStackTrace(new PrintWriter(sw));
|
||||||
for(StackTraceElement ste : stes){
|
log(Level.WARNING,"Exception: "+sw.toString());
|
||||||
log(Level.WARNING,ste.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,42 +3,56 @@ package customskinloader.config;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import customskinloader.utils.Version;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.loader.ProfileLoader;
|
import customskinloader.loader.ProfileLoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
|
import customskinloader.plugin.PluginLoader;
|
||||||
import customskinloader.utils.HttpRequestUtil;
|
import customskinloader.utils.HttpRequestUtil;
|
||||||
import customskinloader.utils.HttpTextureUtil;
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
import customskinloader.utils.HttpUtil0;
|
import customskinloader.utils.HttpUtil0;
|
||||||
|
import customskinloader.utils.Version;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public class Config {
|
public class Config {
|
||||||
//Program
|
//Program
|
||||||
public String version;
|
public String version;
|
||||||
|
public int buildNumber;
|
||||||
public List<SkinSiteProfile> loadlist;
|
public List<SkinSiteProfile> loadlist;
|
||||||
|
|
||||||
//Function
|
//Function
|
||||||
public boolean enableDynamicSkull=true;
|
public boolean enableDynamicSkull=true;
|
||||||
public boolean enableTransparentSkin=true;
|
public boolean enableTransparentSkin=true;
|
||||||
public boolean ignoreHttpsCertificate=false;
|
public boolean forceIgnoreHttpsCertificate = false;
|
||||||
public boolean forceLoadAllTextures=false;
|
public boolean forceLoadAllTextures=false;
|
||||||
public boolean enableCape = true;
|
public boolean enableCape = true;
|
||||||
public int threadPoolSize = 1;
|
public int threadPoolSize = 3;
|
||||||
|
public int retryTime = 1;
|
||||||
|
|
||||||
//Cache
|
//Profile Cache
|
||||||
public int cacheExpiry=30;
|
public int cacheExpiry=30;
|
||||||
public boolean enableUpdateSkull=false;
|
public boolean forceUpdateSkull = false;
|
||||||
public boolean enableLocalProfileCache=false;
|
public boolean enableLocalProfileCache=false;
|
||||||
|
|
||||||
|
//Network Cache
|
||||||
public boolean enableCacheAutoClean=false;
|
public boolean enableCacheAutoClean=false;
|
||||||
|
public boolean forceDisableCache = false;
|
||||||
|
|
||||||
|
// Used by Gson to create an instance with default value.
|
||||||
|
public Config() {
|
||||||
|
this(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
//Init config
|
//Init config
|
||||||
public Config(SkinSiteProfile[] loadlist){
|
public Config(List<SkinSiteProfile> loadlist){
|
||||||
this.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
this.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||||
this.loadlist=Arrays.asList(loadlist);
|
this.buildNumber=CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER;
|
||||||
|
this.loadlist=loadlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Config loadConfig0() {
|
public static Config loadConfig0() {
|
||||||
@@ -56,9 +70,11 @@ public class Config {
|
|||||||
|
|
||||||
//Init program
|
//Init program
|
||||||
config.loadExtraList();
|
config.loadExtraList();
|
||||||
|
config.updateLoadlist();
|
||||||
config.initLocalFolder();
|
config.initLocalFolder();
|
||||||
config.threadPoolSize = Math.max(config.threadPoolSize, 1);
|
config.threadPoolSize = Math.max(config.threadPoolSize, 1);
|
||||||
if(config.ignoreHttpsCertificate)
|
config.retryTime = Math.max(config.retryTime, 0);
|
||||||
|
if(config.forceIgnoreHttpsCertificate)
|
||||||
HttpUtil0.ignoreHttpsCertificate();
|
HttpUtil0.ignoreHttpsCertificate();
|
||||||
if(config.enableCacheAutoClean && !config.enableLocalProfileCache){
|
if(config.enableCacheAutoClean && !config.enableLocalProfileCache){
|
||||||
try{
|
try{
|
||||||
@@ -72,25 +88,22 @@ public class Config {
|
|||||||
|
|
||||||
//Check config version
|
//Check config version
|
||||||
Version configVersion = Version.of(config.version);
|
Version configVersion = Version.of(config.version);
|
||||||
if (configVersion.compareTo(CustomSkinLoader.CustomSkinLoader_VERSION) < 0) {
|
if (CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER == 0 // Custom builds
|
||||||
CustomSkinLoader.logger.info("Config File is out of date: " + config.version);
|
|| configVersion.compareTo(CustomSkinLoader.CustomSkinLoader_VERSION) < 0
|
||||||
|
|| config.buildNumber < CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER) {
|
||||||
|
CustomSkinLoader.logger.info("Config File is out of date: " + config.version + ", build number: " + config.buildNumber);
|
||||||
config.version = CustomSkinLoader.CustomSkinLoader_VERSION;
|
config.version = CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||||
|
config.buildNumber = CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER;
|
||||||
//Update some config
|
|
||||||
if (configVersion.compareTo("14.10") < 0)//Lower than 14.10
|
|
||||||
config.enableCape = true;
|
|
||||||
writeConfig(config, true);
|
|
||||||
}
|
}
|
||||||
|
writeConfig(config, true);
|
||||||
|
|
||||||
//Output config
|
//Output config
|
||||||
for (Field field : config.getClass().getDeclaredFields()) {
|
for (Field field : config.getClass().getDeclaredFields()) {
|
||||||
try {
|
try {
|
||||||
Object value = field.get(config);
|
Object value = field.get(config);
|
||||||
if (value instanceof String || value instanceof Integer || value instanceof Boolean)
|
CustomSkinLoader.logger.info(field.getName() + " : " + value);
|
||||||
CustomSkinLoader.logger.info(field.getName() + " : " + value);
|
|
||||||
} catch (Exception ignored) { }
|
} catch (Exception ignored) { }
|
||||||
}
|
}
|
||||||
CustomSkinLoader.logger.info("loadList : " + (config.loadlist == null ? 0 : config.loadlist.size()));
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@@ -104,15 +117,12 @@ public class Config {
|
|||||||
try {
|
try {
|
||||||
CustomSkinLoader.logger.info("Try to load config.");
|
CustomSkinLoader.logger.info("Try to load config.");
|
||||||
String json=FileUtils.readFileToString(CustomSkinLoader.CONFIG_FILE, "UTF-8");
|
String json=FileUtils.readFileToString(CustomSkinLoader.CONFIG_FILE, "UTF-8");
|
||||||
Config config=CustomSkinLoader.GSON.fromJson(json, Config.class);
|
Config config=Objects.requireNonNull(CustomSkinLoader.GSON.fromJson(json, Config.class));
|
||||||
CustomSkinLoader.logger.info("Successfully load config.");
|
CustomSkinLoader.logger.info("Successfully load config.");
|
||||||
return config;
|
return config;
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
CustomSkinLoader.logger.info("Failed to load config, use default instead.("+e.toString()+")");
|
CustomSkinLoader.logger.info("Failed to load config, use default instead.("+e.toString()+")");
|
||||||
File brokenFile=new File(CustomSkinLoader.DATA_DIR,"BROKEN-CustomSkinLoader.json");
|
createBrokenFile(CustomSkinLoader.CONFIG_FILE);
|
||||||
if(brokenFile.exists())
|
|
||||||
brokenFile.delete();
|
|
||||||
CustomSkinLoader.CONFIG_FILE.renameTo(brokenFile);
|
|
||||||
return initConfig();
|
return initConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,40 +143,57 @@ public class Config {
|
|||||||
String json=FileUtils.readFileToString(file, "UTF-8");
|
String json=FileUtils.readFileToString(file, "UTF-8");
|
||||||
SkinSiteProfile ssp=CustomSkinLoader.GSON.fromJson(json, SkinSiteProfile.class);
|
SkinSiteProfile ssp=CustomSkinLoader.GSON.fromJson(json, SkinSiteProfile.class);
|
||||||
CustomSkinLoader.logger.info("Successfully load Extra List.");
|
CustomSkinLoader.logger.info("Successfully load Extra List.");
|
||||||
file.delete();
|
if (ssp.type != null) {
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
ProfileLoader.IProfileLoader loader = ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
if(loader==null){
|
if (loader == null) {
|
||||||
CustomSkinLoader.logger.info("Extra List will be ignore: Type '"+ssp.type+"' is not defined.");
|
CustomSkinLoader.logger.info("Extra List will be ignored: Type '" + ssp.type + "' is not defined.");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
boolean duplicate=false;
|
|
||||||
for(SkinSiteProfile ssp0:this.loadlist){
|
|
||||||
if(!ssp0.type.equalsIgnoreCase(ssp.type))
|
|
||||||
continue;
|
continue;
|
||||||
if(loader.compare(ssp0, ssp)){
|
|
||||||
duplicate=true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
boolean duplicate = false;
|
||||||
if(!duplicate){
|
for (SkinSiteProfile ssp0 : this.loadlist) {
|
||||||
adds.add(ssp);
|
if (!ssp0.type.equalsIgnoreCase(ssp.type))
|
||||||
CustomSkinLoader.logger.info("Successfully apply Extra List.("+ssp.name+")");
|
continue;
|
||||||
}else{
|
if (loader.compare(ssp0, ssp)) {
|
||||||
CustomSkinLoader.logger.info("Extra List will be ignore: Duplicate.("+ssp.name+")");
|
duplicate = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!duplicate) {
|
||||||
|
adds.add(ssp);
|
||||||
|
CustomSkinLoader.logger.info("Successfully apply Extra List.(" + ssp.name + ")");
|
||||||
|
} else {
|
||||||
|
CustomSkinLoader.logger.info("Extra List will be ignored: Duplicate.(" + ssp.name + ")");
|
||||||
|
}
|
||||||
|
file.delete();
|
||||||
|
} else {
|
||||||
|
CustomSkinLoader.logger.info("Extra List is invalid: Type is not defined.(" + file.getName() + ")");
|
||||||
|
createBrokenFile(file);
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
CustomSkinLoader.logger.info("Failed to load Extra List.("+e.toString()+")");
|
CustomSkinLoader.logger.info("Failed to load Extra List.("+e.toString()+")");
|
||||||
|
createBrokenFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(adds.size()!=0){
|
if(adds.size()!=0){
|
||||||
adds.addAll(this.loadlist);
|
adds.addAll(this.loadlist);
|
||||||
this.loadlist=adds;
|
this.loadlist=adds;
|
||||||
writeConfig(this,true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateLoadlist() {
|
||||||
|
PluginLoader.PLUGINS.stream()
|
||||||
|
.map(ICustomSkinLoaderPlugin::getDefaultProfiles)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.forEach(profile -> this.loadlist.stream()
|
||||||
|
.filter(ssp -> profile.getName().equals(ssp.name))
|
||||||
|
.forEach(profile::updateSkinSiteProfile));
|
||||||
|
}
|
||||||
|
|
||||||
private void initLocalFolder(){
|
private void initLocalFolder(){
|
||||||
for(SkinSiteProfile ssp:this.loadlist){
|
for(SkinSiteProfile ssp:this.loadlist){
|
||||||
|
if(ssp.type==null)
|
||||||
|
continue;
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
if(loader==null)
|
if(loader==null)
|
||||||
continue;
|
continue;
|
||||||
@@ -174,12 +201,43 @@ public class Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void createBrokenFile(File file) {
|
||||||
|
try {
|
||||||
|
File brokenFile = new File(file.getParentFile(), file.getName() + ".broken");
|
||||||
|
if (brokenFile.exists()) {
|
||||||
|
brokenFile.delete();
|
||||||
|
}
|
||||||
|
file.renameTo(brokenFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
CustomSkinLoader.logger.warning("Failed to create broken file. (" + file.getName() + ")");
|
||||||
|
CustomSkinLoader.logger.warning(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The config file does not exist or was broken.
|
||||||
private static Config initConfig() {
|
private static Config initConfig() {
|
||||||
Config config=new Config(CustomSkinLoader.DEFAULT_LOAD_LIST);
|
List<ICustomSkinLoaderPlugin.IDefaultProfile> profiles = new ArrayList<>();
|
||||||
writeConfig(config,false);
|
for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS) {
|
||||||
|
List<ICustomSkinLoaderPlugin.IDefaultProfile> defaultProfiles = plugin.getDefaultProfiles();
|
||||||
|
if (defaultProfiles != null) {
|
||||||
|
profiles.addAll(defaultProfiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
profiles.sort(Comparator.comparingInt(ICustomSkinLoaderPlugin.IDefaultProfile::getPriority));
|
||||||
|
|
||||||
|
List<SkinSiteProfile> loadlist = new ArrayList<>();
|
||||||
|
for (ICustomSkinLoaderPlugin.IDefaultProfile profile : profiles) {
|
||||||
|
SkinSiteProfile ssp = new SkinSiteProfile();
|
||||||
|
ssp.name = profile.getName();
|
||||||
|
profile.updateSkinSiteProfile(ssp);
|
||||||
|
loadlist.add(ssp);
|
||||||
|
}
|
||||||
|
|
||||||
|
Config config = new Config(loadlist);
|
||||||
|
writeConfig(config, false);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
private static void writeConfig(Config config,boolean update){
|
private static void writeConfig(Config config, boolean update){
|
||||||
String json=CustomSkinLoader.GSON.toJson(config);
|
String json=CustomSkinLoader.GSON.toJson(config);
|
||||||
if(CustomSkinLoader.CONFIG_FILE.exists())
|
if(CustomSkinLoader.CONFIG_FILE.exists())
|
||||||
CustomSkinLoader.CONFIG_FILE.delete();
|
CustomSkinLoader.CONFIG_FILE.delete();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package customskinloader.config;
|
package customskinloader.config;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class SkinSiteProfile {
|
public class SkinSiteProfile {
|
||||||
//Common
|
//Common
|
||||||
public String name;
|
public String name;
|
||||||
@@ -20,61 +22,23 @@ public class SkinSiteProfile {
|
|||||||
public String cape;
|
public String cape;
|
||||||
public String elytra;
|
public String elytra;
|
||||||
|
|
||||||
public static SkinSiteProfile createMojangAPI(String name) {
|
@Override
|
||||||
SkinSiteProfile ssp = new SkinSiteProfile();
|
public String toString() {
|
||||||
ssp.name = name;
|
StringBuilder sb = new StringBuilder("{ ");
|
||||||
ssp.type = "MojangAPI";
|
Field[] fields = SkinSiteProfile.class.getDeclaredFields();
|
||||||
return ssp;
|
boolean first = true;
|
||||||
}
|
for (Field field : fields) {
|
||||||
|
try {
|
||||||
public static SkinSiteProfile createCustomSkinAPI(String name, String root) {
|
Object value = field.get(this);
|
||||||
SkinSiteProfile ssp = new SkinSiteProfile();
|
if (value == null) continue;
|
||||||
ssp.name = name;
|
if (first) {
|
||||||
ssp.type = "CustomSkinAPI";
|
first = false;
|
||||||
ssp.root = root;
|
} else {
|
||||||
return ssp;
|
sb.append(", ");
|
||||||
}
|
}
|
||||||
|
sb.append("\"").append(field.getName()).append("\": \"").append(value).append("\"");
|
||||||
public static SkinSiteProfile creatCustomSkinAPIPlus(String name, String root) {
|
} catch (Exception ignored) { }
|
||||||
SkinSiteProfile ssp = new SkinSiteProfile();
|
}
|
||||||
ssp.name = name;
|
return sb.append(" }").toString();
|
||||||
ssp.type = "CustomSkinAPIPlus";
|
|
||||||
ssp.root = root;
|
|
||||||
return ssp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SkinSiteProfile createGlitchlessAPI(String name, String root) {
|
|
||||||
SkinSiteProfile ssp = new SkinSiteProfile();
|
|
||||||
ssp.name = name;
|
|
||||||
ssp.type = "GlitchlessAPI";
|
|
||||||
ssp.root = root;
|
|
||||||
return ssp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SkinSiteProfile createUniSkinAPI(String name, String root) {
|
|
||||||
SkinSiteProfile ssp = new SkinSiteProfile();
|
|
||||||
ssp.name = name;
|
|
||||||
ssp.type = "UniSkinAPI";
|
|
||||||
ssp.root = root;
|
|
||||||
return ssp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SkinSiteProfile createLegacy(String name, String skin, String cape, String elytra) {
|
|
||||||
SkinSiteProfile ssp = new SkinSiteProfile();
|
|
||||||
ssp.name = name;
|
|
||||||
ssp.type = "Legacy";
|
|
||||||
ssp.checkPNG = false;
|
|
||||||
ssp.skin = skin;
|
|
||||||
ssp.model = "auto";
|
|
||||||
ssp.cape = cape;
|
|
||||||
ssp.elytra = elytra;
|
|
||||||
return ssp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SkinSiteProfile createElyByAPI(String name) {
|
|
||||||
SkinSiteProfile ssp = new SkinSiteProfile();
|
|
||||||
ssp.name = name;
|
|
||||||
ssp.type = "ElyByAPI";
|
|
||||||
return ssp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
package customskinloader.fake;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import customskinloader.fake.itf.FakeInterfaceManager;
|
||||||
|
import customskinloader.fake.texture.FakeBufferedImage;
|
||||||
|
import customskinloader.fake.texture.FakeImage;
|
||||||
|
import customskinloader.utils.MinecraftUtil;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
public class FakeCapeBuffer extends FakeSkinBuffer {
|
||||||
|
private static final ResourceLocation TEXTURE_ELYTRA = new ResourceLocation("textures/entity/elytra.png");
|
||||||
|
private static int loadedGlobal = 0;
|
||||||
|
private static FakeImage elytraImage;
|
||||||
|
|
||||||
|
private static FakeImage loadElytra(FakeImage originalImage) {
|
||||||
|
loadedGlobal++;
|
||||||
|
try {
|
||||||
|
InputStream is = FakeInterfaceManager.IResource_getInputStream(FakeInterfaceManager.IResourceManager_getResource(FakeInterfaceManager.Minecraft_getResourceManager(Minecraft.getMinecraft()), TEXTURE_ELYTRA).get());
|
||||||
|
if (is != null) {
|
||||||
|
FakeImage image = originalImage.createImage(is);
|
||||||
|
if (image.getWidth() % 64 != 0 || image.getHeight() % 32 != 0) { // wtf?
|
||||||
|
return elytraImage;
|
||||||
|
}
|
||||||
|
image = resetImageFormat(image, 22, 0, 46, 22);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
} catch (IOException | NoSuchElementException ignored) { }
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int loaded = 0;
|
||||||
|
private double ratioX = -1;
|
||||||
|
private double ratioY = -1;
|
||||||
|
private ResourceLocation location;
|
||||||
|
private String type = null;
|
||||||
|
|
||||||
|
public FakeCapeBuffer(ResourceLocation location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FakeImage parseUserSkin(FakeImage image) {
|
||||||
|
if (image == null) return null;
|
||||||
|
this.image = image;
|
||||||
|
|
||||||
|
// When resource packs were changed, the elytra image needs to be reloaded, and here will be entered again
|
||||||
|
if (this.loaded == loadedGlobal) {
|
||||||
|
elytraImage = loadElytra(image);
|
||||||
|
}
|
||||||
|
this.loaded = loadedGlobal;
|
||||||
|
if (elytraImage != null) {
|
||||||
|
if (this.ratioX < 0)
|
||||||
|
this.ratioX = this.image.getWidth() / 64.0D;
|
||||||
|
if (this.ratioY < 0)
|
||||||
|
this.ratioY = this.image.getHeight() / 32.0D;
|
||||||
|
if (this.type == null)
|
||||||
|
this.type = this.judgeType();
|
||||||
|
|
||||||
|
if ("cape".equals(this.type)) {
|
||||||
|
this.image = resetImageFormat(this.image, 0, 0, 22, 17);
|
||||||
|
this.attachElytra(elytraImage);
|
||||||
|
if (this.image instanceof FakeBufferedImage) { // before 1.12.2
|
||||||
|
this.refreshTexture((FakeBufferedImage) this.image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.image;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Judge the cape type
|
||||||
|
*
|
||||||
|
* @return "elytra" if the cape contains elytra texture, otherwise "cape"
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String judgeType() {
|
||||||
|
if (this.image != null && elytraImage != null) {
|
||||||
|
// If all the pixels in ((22, 0), (45, 21)) is same as background, it means the cape doesn't contain elytra
|
||||||
|
Predicate<Integer> predicate = EQU_BG.apply(this.image.getRGBA(this.image.getWidth() - 1, this.image.getHeight() - 1));
|
||||||
|
return withElytraPixels((x, y) -> !predicate.test(this.image.getRGBA(x, y)), "elytra", "cape");
|
||||||
|
}
|
||||||
|
return "cape";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void attachElytra(FakeImage elytraImage) {
|
||||||
|
if (this.image != null) {
|
||||||
|
int capeW = this.image.getWidth(), capeH = this.image.getHeight();
|
||||||
|
int elytraW = elytraImage.getWidth(), elytraH = elytraImage.getHeight();
|
||||||
|
|
||||||
|
// scale cape and elytra to the same size
|
||||||
|
// cape part ((0, 0), (21, 16)) -> (22 * 17)
|
||||||
|
if (capeW < elytraW) {
|
||||||
|
this.image = scaleImage(this.image, true, elytraW / (double) capeW, 1, capeW / 64.0D, capeH / 32.0D, elytraW, capeH, 0, 0, 22, 17);
|
||||||
|
capeW = elytraW;
|
||||||
|
}
|
||||||
|
if (capeH < elytraH) {
|
||||||
|
this.image = scaleImage(this.image, true, 1, elytraH / (double) capeH, capeW / 64.0D, capeH / 32.0D, capeW, elytraH, 0, 0, 22, 17);
|
||||||
|
capeH = elytraH;
|
||||||
|
}
|
||||||
|
// elytra part ((22, 0), (45, 21)) -> (24 * 22)
|
||||||
|
if (elytraW < capeW) {
|
||||||
|
elytraImage = scaleImage(elytraImage, false, capeW / (double) elytraW, 1, elytraW / 64.0D, elytraH / 32.0D, capeW, elytraH, 22, 0, 46, 22);
|
||||||
|
elytraW = capeW;
|
||||||
|
}
|
||||||
|
if (elytraH < capeH) {
|
||||||
|
elytraImage = scaleImage(elytraImage, false, 1, capeH / (double) elytraH, elytraW / 64.0D, elytraH / 32.0D, elytraW, capeH, 22, 0, 46, 22);
|
||||||
|
elytraH = capeH;
|
||||||
|
}
|
||||||
|
this.ratioX = capeW / 64.0D;
|
||||||
|
this.ratioY = capeH / 32.0D;
|
||||||
|
|
||||||
|
// Overwrite pixels from elytra to cape
|
||||||
|
FakeImage finalElytraImage = elytraImage;
|
||||||
|
withElytraPixels((x, y) -> {
|
||||||
|
this.image.setRGBA(x, y, finalElytraImage.getRGBA(x, y));
|
||||||
|
return false;
|
||||||
|
}, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Traverse every elytra pixel
|
||||||
|
* @param predicate the predicate with x and y
|
||||||
|
* @param returnValue if the condition flag equals the condition, then return this value
|
||||||
|
* @param defaultReturnValue otherwise return this value
|
||||||
|
*/
|
||||||
|
private <R> R withElytraPixels(BiPredicate<Integer, Integer> predicate, R returnValue, R defaultReturnValue) {
|
||||||
|
int startX = (int) Math.ceil(22 * ratioX), endX = (int) Math.ceil(46 * ratioX);
|
||||||
|
int startY = (int) Math.ceil(0 * ratioY), endY = (int) Math.ceil(22 * ratioY);
|
||||||
|
int excludeX0 = (int) Math.ceil(24 * ratioX), excludeX1 = (int) Math.ceil(44 * ratioX);
|
||||||
|
int excludeY = (int) Math.ceil(2 * ratioY);
|
||||||
|
for (int x = startX; x < endX; ++x) {
|
||||||
|
for (int y = startY; y < endY; ++y) {
|
||||||
|
if (y < excludeY && (x < excludeX0 || x >= excludeX1)) continue;
|
||||||
|
if (predicate.test(x, y)) {
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultReturnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TextureID won't be regenerated when changing resource packs before 1.12.2
|
||||||
|
private void refreshTexture(FakeBufferedImage image) {
|
||||||
|
Object textureObj = MinecraftUtil.getTextureManager().getTexture(this.location);
|
||||||
|
if (textureObj != null) {
|
||||||
|
// NOTICE: OptiFine modified the upload process of the texture from ThreadDownloadImageData
|
||||||
|
// Therefore, it may not be correct to simply copy the vanilla behavior
|
||||||
|
FakeInterfaceManager.ThreadDownloadImageData_resetNewBufferedImage(textureObj, image.getImage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some cape image doesn't support alpha channel, so reset image format to ARGB
|
||||||
|
private static FakeImage resetImageFormat(FakeImage image, int startX, int startY, int endX, int endY) {
|
||||||
|
if (image != null) {
|
||||||
|
int width = image.getWidth(), height = image.getHeight();
|
||||||
|
image = scaleImage(image, true, 1, 1, width / 64.0D, height / 32.0D, width, height, startX, startY, endX, endY);
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale image
|
||||||
|
* @param image the image to scale.
|
||||||
|
* @param closeOldImage whether close old image
|
||||||
|
* @param scaleWidth width enlargement ratio
|
||||||
|
* @param scaleHeight height enlargement ratio
|
||||||
|
* @param ratioX the ratio of 64 of the old image width
|
||||||
|
* @param ratioY the ratio of 32 of the old image height
|
||||||
|
* @param width the width after scaling.
|
||||||
|
* @param height the height after scaling.
|
||||||
|
* @param startX the x where start to copy.
|
||||||
|
* @param startY the y where start to copy.
|
||||||
|
* @param endX the x where end to copy.
|
||||||
|
* @param endY the y where end to copy.
|
||||||
|
* @return the image after scaling.
|
||||||
|
*/
|
||||||
|
private static FakeImage scaleImage(FakeImage image, boolean closeOldImage, double scaleWidth, double scaleHeight, double ratioX, double ratioY, int width, int height, int startX, int startY, int endX, int endY) {
|
||||||
|
FakeImage newImage = image.createImage(width, height);
|
||||||
|
startX = (int) (startX * ratioX); endX = (int) (endX * ratioX);
|
||||||
|
startY = (int) (startY * ratioY); endY = (int) (endY * ratioY);
|
||||||
|
|
||||||
|
int x0 = (int) (startX * scaleWidth), x1 = (int) ((startX + 1) * scaleWidth), dx0 = x1 - x0;
|
||||||
|
for (int x = startX; x < endX; ++x) {
|
||||||
|
int y0 = (int) (startY * scaleHeight), y1 = (int) ((startY + 1) * scaleHeight), dy0 = y1 - y0;
|
||||||
|
for (int y = startY; y < endY; ++y) {
|
||||||
|
int rgba = image.getRGBA(x, y);
|
||||||
|
for (int dx = 0; dx < dx0; dx++) {
|
||||||
|
for (int dy = 0; dy < dy0; dy++) {
|
||||||
|
newImage.setRGBA(x0 + dx, y0 + dy, rgba);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
y0 = y1; y1 = (int) ((y + 2) * scaleHeight); dy0 = y1 - y0;
|
||||||
|
}
|
||||||
|
x0 = x1; x1 = (int) ((x + 2) * scaleWidth); dx0 = x1 - x0;
|
||||||
|
}
|
||||||
|
if (closeOldImage)
|
||||||
|
image.close();
|
||||||
|
return newImage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package customskinloader.fake;
|
package customskinloader.fake;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
@@ -12,14 +13,14 @@ import net.minecraft.client.renderer.texture.NativeImage;
|
|||||||
|
|
||||||
public class FakeSkinBuffer implements IImageBuffer {
|
public class FakeSkinBuffer implements IImageBuffer {
|
||||||
private int ratio = 1;
|
private int ratio = 1;
|
||||||
private FakeImage image = null;
|
FakeImage image = null;
|
||||||
|
|
||||||
//parseUserSkin for 1.15+
|
//parseUserSkin for 1.15+
|
||||||
public static NativeImage processLegacySkin(NativeImage image, Runnable processTask) {
|
public static NativeImage processLegacySkin(NativeImage image, Runnable processTask, Function<NativeImage, NativeImage> processLegacySkin) {
|
||||||
if (processTask instanceof IImageBuffer) {
|
if (processTask instanceof IImageBuffer) {
|
||||||
return ((IImageBuffer) processTask).func_195786_a(image);
|
return ((IImageBuffer) processTask).func_195786_a(image);
|
||||||
}
|
}
|
||||||
return new FakeSkinBuffer().func_195786_a(image);
|
return processLegacySkin.apply(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
//parseUserSkin for 1.13+
|
//parseUserSkin for 1.13+
|
||||||
@@ -94,6 +95,9 @@ public class FakeSkinBuffer implements IImageBuffer {
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Judge if the color is transparent or same with background */
|
||||||
|
static final Function<Integer, Predicate<Integer>> EQU_BG = bgColor -> getA(bgColor) == 0 ? (c) -> getA(c) == 0 : (c) -> c.equals(bgColor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Judge the type of skin
|
* Judge the type of skin
|
||||||
* Must be called after parseUserSkin
|
* Must be called after parseUserSkin
|
||||||
@@ -112,8 +116,7 @@ public class FakeSkinBuffer implements IImageBuffer {
|
|||||||
* which means it is Alex model.
|
* which means it is Alex model.
|
||||||
* Otherwise, it is Steve model.
|
* Otherwise, it is Steve model.
|
||||||
* */
|
* */
|
||||||
Predicate<Integer> predicate =
|
Predicate<Integer> predicate = EQU_BG.apply(bgColor);
|
||||||
getA(bgColor) == 0 ? (c) -> getA(c) == 0 : (c) -> c == bgColor;
|
|
||||||
for (int x = 54 * ratio; x <= 55 * ratio; ++x) {
|
for (int x = 54 * ratio; x <= 55 * ratio; ++x) {
|
||||||
for (int y = 20 * ratio; y <= 31 * ratio; ++y) {
|
for (int y = 20 * ratio; y <= 31 * ratio; ++y) {
|
||||||
int color = image.getRGBA(x, y);
|
int color = image.getRGBA(x, y);
|
||||||
|
|||||||
@@ -2,102 +2,121 @@ package customskinloader.fake;
|
|||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.hash.Hashing;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.fake.itf.IFakeMinecraft;
|
import customskinloader.fake.itf.FakeInterfaceManager;
|
||||||
import customskinloader.fake.itf.IFakeTextureManager_1;
|
|
||||||
import customskinloader.fake.itf.IFakeTextureManager_2;
|
|
||||||
import customskinloader.utils.HttpTextureUtil;
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
import customskinloader.utils.HttpTextureUtil.HttpTextureInfo;
|
|
||||||
import customskinloader.utils.MinecraftUtil;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.IImageBuffer;
|
import net.minecraft.client.renderer.IImageBuffer;
|
||||||
import net.minecraft.client.renderer.texture.SimpleTexture;
|
import net.minecraft.client.renderer.texture.SimpleTexture;
|
||||||
import net.minecraft.client.renderer.texture.Texture;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||||
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
|
import net.minecraft.client.resources.SkinManager;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
public class FakeSkinManager {
|
public class FakeSkinManager {
|
||||||
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(CustomSkinLoader.config.threadPoolSize, CustomSkinLoader.config.threadPoolSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>());
|
|
||||||
private final TextureManager textureManager;
|
private final TextureManager textureManager;
|
||||||
|
|
||||||
private final Map<ResourceLocation, MinecraftProfileTexture> modelCache = new HashMap<>();
|
private final Map<ResourceLocation, MinecraftProfileTexture> modelCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public FakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) {
|
public FakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) {
|
||||||
this.textureManager = textureManagerInstance;
|
this.textureManager = textureManagerInstance;
|
||||||
HttpTextureUtil.defaultCacheDir = skinCacheDirectory;
|
HttpTextureUtil.defaultCacheDir = skinCacheDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type textureType) {
|
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, MinecraftProfileTexture.Type textureType) {
|
||||||
return this.loadSkin(profileTexture, textureType, null);
|
return this.loadSkin(profileTexture, textureType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, final SkinAvailableCallback skinAvailableCallback) {
|
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final MinecraftProfileTexture.Type textureType, final SkinManager.SkinAvailableCallback skinAvailableCallback) {
|
||||||
HttpTextureInfo info = HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl());
|
return this.loadSkin(profileTexture, HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl()), textureType, skinAvailableCallback);
|
||||||
|
}
|
||||||
|
|
||||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);
|
private ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final HttpTextureUtil.HttpTextureInfo info, final MinecraftProfileTexture.Type textureType, final SkinManager.SkinAvailableCallback skinAvailableCallback) {
|
||||||
|
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + Hashing.sha1().hashUnencodedChars(info.hash).toString());
|
||||||
|
|
||||||
if (((IFakeTextureManager_1) this.textureManager).func_229267_b_(resourcelocation) != null) {//Have already loaded
|
if (FakeInterfaceManager.TextureManager_getTexture(this.textureManager, resourcelocation, null) != null) {//Have already loaded
|
||||||
makeCallback(skinAvailableCallback, textureType, resourcelocation, modelCache.getOrDefault(resourcelocation, profileTexture));
|
makeCallback(skinAvailableCallback, textureType, resourcelocation, modelCache.getOrDefault(resourcelocation, profileTexture));
|
||||||
} else {
|
} else {
|
||||||
SimpleTexture threaddownloadimagedata = MinecraftUtil.createThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture), textureType);
|
SimpleTexture threaddownloadimagedata = FakeThreadDownloadImageData.createThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(), new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture), textureType);
|
||||||
if (skinAvailableCallback instanceof FakeClientPlayer.LegacyBuffer)//Cache for client player
|
if (skinAvailableCallback instanceof FakeClientPlayer.LegacyBuffer)//Cache for client player
|
||||||
FakeClientPlayer.textureCache.put(resourcelocation, threaddownloadimagedata);
|
FakeClientPlayer.textureCache.put(resourcelocation, threaddownloadimagedata);
|
||||||
((IFakeTextureManager_2) this.textureManager).func_229263_a_(resourcelocation, (Texture) threaddownloadimagedata);
|
FakeInterfaceManager.TextureManager_loadTexture(this.textureManager, resourcelocation, threaddownloadimagedata);
|
||||||
}
|
}
|
||||||
return resourcelocation;
|
return resourcelocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadProfileTextures(final GameProfile profile, final SkinAvailableCallback skinAvailableCallback, final boolean requireSecure) {
|
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure) {
|
||||||
THREAD_POOL.execute(new Runnable() {
|
CustomSkinLoader.loadProfileTextures(() -> CustomSkinLoader.loadProfileLazily(profile, m -> {
|
||||||
public void run() {
|
final Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = Maps.newHashMap();
|
||||||
final Map<Type, MinecraftProfileTexture> map = Maps.newHashMap();
|
map.putAll(m);
|
||||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
|
||||||
|
|
||||||
((IFakeMinecraft) Minecraft.getMinecraft()).execute(() -> {
|
for (MinecraftProfileTexture.Type type : MinecraftProfileTexture.Type.values()) {
|
||||||
for (Type type : Type.values()) {
|
MinecraftProfileTexture profileTexture = map.get(type);
|
||||||
if (map.containsKey(type)) {
|
if (profileTexture != null) {
|
||||||
CustomSkinLoader.logger.debug("Loading type:" + type);
|
HttpTextureUtil.HttpTextureInfo info = HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl());
|
||||||
FakeSkinManager.this.loadSkin(map.get(type), type, skinAvailableCallback);
|
FakeThreadDownloadImageData.downloadTexture(info.cacheFile, info.url);
|
||||||
|
|
||||||
|
FakeInterfaceManager.Minecraft_addScheduledTask(Minecraft.getMinecraft(), () -> {
|
||||||
|
CustomSkinLoader.logger.debug("Loading type: " + type);
|
||||||
|
try {
|
||||||
|
this.loadSkin(profileTexture, info, type, skinAvailableCallback);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
CustomSkinLoader.logger.warning(t);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile) {
|
public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile) {
|
||||||
return CustomSkinLoader.loadProfileFromCache(profile);
|
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = CustomSkinLoader.loadProfileFromCache(profile);
|
||||||
|
for (Iterator<Map.Entry<MinecraftProfileTexture.Type, MinecraftProfileTexture>> it = map.entrySet().iterator(); it.hasNext(); ) {
|
||||||
|
Map.Entry<MinecraftProfileTexture.Type, MinecraftProfileTexture> entry = it.next();
|
||||||
|
MinecraftProfileTexture texture = entry.getValue();
|
||||||
|
if (shouldJudgeType(texture)) {
|
||||||
|
texture = this.modelCache.get(this.loadSkin(texture, entry.getKey()));
|
||||||
|
if (texture == null) { // remove texture if was not loaded before
|
||||||
|
it.remove();
|
||||||
|
} else {
|
||||||
|
map.put(entry.getKey(), texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void makeCallback(SkinAvailableCallback callback, Type type, ResourceLocation location, MinecraftProfileTexture texture) {
|
private static void makeCallback(SkinManager.SkinAvailableCallback callback, MinecraftProfileTexture.Type type, ResourceLocation location, MinecraftProfileTexture texture) {
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.skinAvailable(type, location, texture);
|
callback.skinAvailable(type, location, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean shouldJudgeType(MinecraftProfileTexture texture) {
|
||||||
|
return texture != null && "auto".equals(texture.getMetadata("model"));
|
||||||
|
}
|
||||||
|
|
||||||
private class BaseBuffer implements IImageBuffer {
|
private class BaseBuffer implements IImageBuffer {
|
||||||
private IImageBuffer buffer;
|
private IImageBuffer buffer;
|
||||||
|
|
||||||
private SkinAvailableCallback callback;
|
private SkinManager.SkinAvailableCallback callback;
|
||||||
private Type type;
|
private MinecraftProfileTexture.Type type;
|
||||||
private ResourceLocation location;
|
private ResourceLocation location;
|
||||||
private MinecraftProfileTexture texture;
|
private MinecraftProfileTexture texture;
|
||||||
|
|
||||||
public BaseBuffer(SkinAvailableCallback callback, Type type, ResourceLocation location, MinecraftProfileTexture texture) {
|
public BaseBuffer(SkinManager.SkinAvailableCallback callback, MinecraftProfileTexture.Type type, ResourceLocation location, MinecraftProfileTexture texture) {
|
||||||
this.buffer = (type == Type.SKIN ? new FakeSkinBuffer() : null);
|
switch (type) {
|
||||||
|
case SKIN: this.buffer = new FakeSkinBuffer(); break;
|
||||||
|
case CAPE: this.buffer = new FakeCapeBuffer(location); break;
|
||||||
|
}
|
||||||
|
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -110,13 +129,13 @@ public class FakeSkinManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage parseUserSkin(BufferedImage image) {
|
public BufferedImage parseUserSkin(BufferedImage image) {
|
||||||
return buffer == null ? image : buffer.parseUserSkin(image);
|
return buffer instanceof FakeSkinBuffer ? ((FakeSkinBuffer) buffer).parseUserSkin(image) : image;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void skinAvailable() {
|
public void skinAvailable() {
|
||||||
if (buffer != null) {
|
if (buffer != null) {
|
||||||
buffer.skinAvailable();
|
buffer.skinAvailable();
|
||||||
if ("auto".equals(texture.getMetadata("model")) && buffer instanceof FakeSkinBuffer) {
|
if (shouldJudgeType(texture) && buffer instanceof FakeSkinBuffer) {
|
||||||
//Auto judge skin type
|
//Auto judge skin type
|
||||||
Map<String, String> metadata = Maps.newHashMap();
|
Map<String, String> metadata = Maps.newHashMap();
|
||||||
String type = ((FakeSkinBuffer) buffer).judgeType();
|
String type = ((FakeSkinBuffer) buffer).judgeType();
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package customskinloader.fake;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import customskinloader.utils.HttpRequestUtil;
|
||||||
|
import net.minecraft.client.renderer.IImageBuffer;
|
||||||
|
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||||
|
import net.minecraft.client.renderer.texture.DownloadingTexture;
|
||||||
|
import net.minecraft.client.renderer.texture.SimpleTexture;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
public class FakeThreadDownloadImageData {
|
||||||
|
private static IThreadDownloadImageDataBuilder builder;
|
||||||
|
|
||||||
|
public static SimpleTexture createThreadDownloadImageData(File cacheFileIn, String imageUrlIn, ResourceLocation textureResourceLocationIn, IImageBuffer imageBufferIn, MinecraftProfileTexture.Type textureTypeIn) {
|
||||||
|
SimpleTexture texture = null;
|
||||||
|
if (FakeThreadDownloadImageData.builder == null) {
|
||||||
|
EnumMap<ThreadDownloadImageDataBuilder, Throwable> throwables = new EnumMap<>(ThreadDownloadImageDataBuilder.class);
|
||||||
|
for (ThreadDownloadImageDataBuilder builder : ThreadDownloadImageDataBuilder.values()) {
|
||||||
|
try {
|
||||||
|
FakeThreadDownloadImageData.builder = builder.get().get();
|
||||||
|
texture = FakeThreadDownloadImageData.builder.build(cacheFileIn, imageUrlIn, textureResourceLocationIn, imageBufferIn, textureTypeIn);
|
||||||
|
CustomSkinLoader.logger.info("ThreadDownloadImageData Class: %s", texture.getClass().getName());
|
||||||
|
break;
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throwables.put(builder, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texture == null) {
|
||||||
|
CustomSkinLoader.logger.warning("Unable to get ThreadDownloadImageData Class: ");
|
||||||
|
throwables.forEach((k, v) -> {
|
||||||
|
CustomSkinLoader.logger.warning("Caused by: (%s)", k.name());
|
||||||
|
CustomSkinLoader.logger.warning(v);
|
||||||
|
});
|
||||||
|
throw new RuntimeException("Unable to get ThreadDownloadImageData Class!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
texture = builder.build(cacheFileIn, imageUrlIn, textureResourceLocationIn, imageBufferIn, textureTypeIn);
|
||||||
|
}
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void downloadTexture(File cacheFile, String imageUrl) {
|
||||||
|
HttpRequestUtil.HttpRequest request = new HttpRequestUtil.HttpRequest(imageUrl).setLoadContent(false).setCacheTime(0).setCacheFile(cacheFile);
|
||||||
|
for (int i = 0; i <= CustomSkinLoader.config.retryTime; i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
CustomSkinLoader.logger.debug("Retry to download texture %s (%s)", imageUrl, i);
|
||||||
|
}
|
||||||
|
if (HttpRequestUtil.makeHttpRequest(request).success) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface IThreadDownloadImageDataBuilder {
|
||||||
|
SimpleTexture build(File cacheFile, String imageUrl, ResourceLocation textureResourceLocation, IImageBuffer imageBuffer, MinecraftProfileTexture.Type textureType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum ThreadDownloadImageDataBuilder {
|
||||||
|
// DO NOT replace new IThreadDownloadImageDataBuilder() with lambda.
|
||||||
|
V1(() -> new IThreadDownloadImageDataBuilder() { // Forge 1.8.x~1.12.x
|
||||||
|
@Override
|
||||||
|
public SimpleTexture build(File cacheFile, String imageUrl, ResourceLocation textureResourceLocation, IImageBuffer imageBuffer, MinecraftProfileTexture.Type textureType) {
|
||||||
|
return new ThreadDownloadImageData(cacheFile, imageUrl, textureResourceLocation, imageBuffer);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
V2(() -> new IThreadDownloadImageDataBuilder() { // Forge 1.13.x
|
||||||
|
@Override
|
||||||
|
public SimpleTexture build(File cacheFile, String imageUrl, ResourceLocation textureResourceLocation, IImageBuffer imageBuffer, MinecraftProfileTexture.Type textureType) {
|
||||||
|
return new net.minecraft.client.renderer.texture.ThreadDownloadImageData(cacheFile, imageUrl, textureResourceLocation, imageBuffer);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
V3(() -> new IThreadDownloadImageDataBuilder() { // Forge 1.14.x
|
||||||
|
@Override
|
||||||
|
public SimpleTexture build(File cacheFile, String imageUrl, ResourceLocation textureResourceLocation, IImageBuffer imageBuffer, MinecraftProfileTexture.Type textureType) {
|
||||||
|
return new DownloadingTexture(cacheFile, imageUrl, textureResourceLocation, imageBuffer);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
V4(() -> new IThreadDownloadImageDataBuilder() { // Forge 1.15.x~1.16.x
|
||||||
|
@Override
|
||||||
|
public SimpleTexture build(File cacheFile, String imageUrl, ResourceLocation textureResourceLocation, IImageBuffer imageBuffer, MinecraftProfileTexture.Type textureType) {
|
||||||
|
return new DownloadingTexture(cacheFile, imageUrl, textureResourceLocation, true, imageBuffer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
private final Supplier<IThreadDownloadImageDataBuilder> builder;
|
||||||
|
|
||||||
|
ThreadDownloadImageDataBuilder(Supplier<IThreadDownloadImageDataBuilder> builder) {
|
||||||
|
this.builder = builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Supplier<IThreadDownloadImageDataBuilder> get() {
|
||||||
|
return this.builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package customskinloader.fake.itf;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.texture.Texture;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
|
import net.minecraft.client.resources.IResource;
|
||||||
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
public class FakeInterfaceManager {
|
||||||
|
public static InputStream IResource_getInputStream(Object resource) {
|
||||||
|
return ((IFakeIResource.V2) resource).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<IResource> IResourceManager_getResource(Object resourceManager, ResourceLocation location) throws IOException {
|
||||||
|
return ((IFakeIResourceManager) resourceManager).getResource(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IResourceManager Minecraft_getResourceManager(Minecraft minecraft) {
|
||||||
|
return (IResourceManager) ((IFakeMinecraft) minecraft).func_195551_G();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Minecraft_addScheduledTask(Minecraft minecraft, Runnable runnable) {
|
||||||
|
((IFakeMinecraft) minecraft).execute(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TextureManager_loadTexture(TextureManager textureManager, ResourceLocation textureLocation, Object textureObj) {
|
||||||
|
((IFakeTextureManager.V2) textureManager).func_229263_a_(textureLocation, (Texture) textureObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Texture TextureManager_getTexture(TextureManager textureManager, ResourceLocation textureLocation, Object textureObj) {
|
||||||
|
return ((IFakeTextureManager.V1) textureManager).getTexture(textureLocation, (Texture) textureObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ThreadDownloadImageData_resetNewBufferedImage(Object threadDownloadImageData, BufferedImage image) {
|
||||||
|
((IFakeThreadDownloadImageData) threadDownloadImageData).resetNewBufferedImage(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package customskinloader.fake.itf;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import net.minecraft.client.resources.IResource;
|
||||||
|
|
||||||
|
/** {@link net.minecraft.client.resources.IResource} is no longer an interface since 22w14a */
|
||||||
|
public interface IFakeIResource {
|
||||||
|
// 1.13.2 ~ 22w13a
|
||||||
|
interface V1 {
|
||||||
|
default InputStream func_199027_b() {
|
||||||
|
return ((IResource) this).getInputStream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 22w14a+
|
||||||
|
interface V2 {
|
||||||
|
default InputStream open() {
|
||||||
|
return ((IFakeIResource.V1) this).func_199027_b();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package customskinloader.fake.itf;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
|
import net.minecraft.resources.IResource;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
public interface IFakeIResourceManager {
|
||||||
|
// 1.13.2 ~ 22w13a
|
||||||
|
default IResource func_199002_a(ResourceLocation location) throws IOException {
|
||||||
|
return (IResource) ((IResourceManager) this).getResource(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 22w14a+
|
||||||
|
default Optional getResource(ResourceLocation location) throws IOException {
|
||||||
|
return Optional.ofNullable(this.func_199002_a(location));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
package customskinloader.fake.itf;
|
package customskinloader.fake.itf;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.resources.IResourceManager;
|
||||||
|
|
||||||
public interface IFakeMinecraft {
|
public interface IFakeMinecraft {
|
||||||
|
// 1.13.2+
|
||||||
|
default IResourceManager func_195551_G() {
|
||||||
|
return (IResourceManager) ((Minecraft) this).getResourceManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.14+
|
||||||
default void execute(Runnable runnable) {
|
default void execute(Runnable runnable) {
|
||||||
((Minecraft) this).addScheduledTask(runnable);
|
((Minecraft) this).addScheduledTask(runnable);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package customskinloader.fake.itf;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||||
|
import net.minecraft.client.renderer.texture.Texture;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
public interface IFakeTextureManager {
|
||||||
|
interface V1 {
|
||||||
|
default boolean func_229263_a_(ResourceLocation textureLocation, Texture textureObj) {
|
||||||
|
return ((TextureManager) this).loadTexture(textureLocation, (ITextureObject) textureObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Texture func_229267_b_(ResourceLocation textureLocation) {
|
||||||
|
return (Texture) ((TextureManager) this).getTexture(textureLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Texture getTexture(ResourceLocation textureLocation, Texture textureObj) {
|
||||||
|
return func_229267_b_(textureLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface V2 {
|
||||||
|
default void func_229263_a_(ResourceLocation textureLocation, Texture textureObj) {
|
||||||
|
((IFakeTextureManager.V1) this).func_229263_a_(textureLocation, textureObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package customskinloader.fake.itf;
|
|
||||||
|
|
||||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
|
||||||
import net.minecraft.client.renderer.texture.Texture;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
public interface IFakeTextureManager_1 {
|
|
||||||
default boolean func_229263_a_(ResourceLocation textureLocation, Texture textureObj) {
|
|
||||||
return ((TextureManager) this).loadTexture(textureLocation, (ITextureObject) textureObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
default Texture func_229267_b_(ResourceLocation textureLocation) {
|
|
||||||
return (Texture) ((TextureManager) this).getTexture(textureLocation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package customskinloader.fake.itf;
|
|
||||||
|
|
||||||
import net.minecraft.client.renderer.texture.Texture;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
public interface IFakeTextureManager_2 {
|
|
||||||
default void func_229263_a_(ResourceLocation textureLocation, Texture textureObj) {
|
|
||||||
((IFakeTextureManager_1) this).func_229263_a_(textureLocation, textureObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package customskinloader.fake.itf;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
// This interface is only available before 1.12.2
|
||||||
|
public interface IFakeThreadDownloadImageData {
|
||||||
|
/**
|
||||||
|
* Reset {@link net.minecraft.client.renderer.ThreadDownloadImageData#bufferedImage} and
|
||||||
|
* {@link net.minecraft.client.renderer.ThreadDownloadImageData#textureUploaded} to false to refresh texture.
|
||||||
|
*/
|
||||||
|
void resetNewBufferedImage(BufferedImage image);
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
package customskinloader.fake.texture;
|
package customskinloader.fake.texture;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
public class FakeBufferedImage implements FakeImage {
|
public class FakeBufferedImage implements FakeImage {
|
||||||
private BufferedImage image;
|
private BufferedImage image;
|
||||||
@@ -25,6 +29,10 @@ public class FakeBufferedImage implements FakeImage {
|
|||||||
return new FakeBufferedImage(width, height);
|
return new FakeBufferedImage(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FakeImage createImage(InputStream is) throws IOException {
|
||||||
|
return new FakeBufferedImage(ImageIO.read(is));
|
||||||
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return image.getWidth();
|
return image.getWidth();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package customskinloader.fake.texture;
|
package customskinloader.fake.texture;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
public interface FakeImage {
|
public interface FakeImage {
|
||||||
FakeImage createImage(int width, int height);
|
FakeImage createImage(int width, int height);
|
||||||
|
|
||||||
|
FakeImage createImage(InputStream is) throws IOException;
|
||||||
|
|
||||||
int getWidth();
|
int getWidth();
|
||||||
|
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package customskinloader.fake.texture;
|
package customskinloader.fake.texture;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.texture.NativeImage;
|
import net.minecraft.client.renderer.texture.NativeImage;
|
||||||
|
|
||||||
public class FakeNativeImage implements FakeImage {
|
public class FakeNativeImage implements FakeImage {
|
||||||
@@ -21,6 +23,10 @@ public class FakeNativeImage implements FakeImage {
|
|||||||
return new FakeNativeImage(width, height);
|
return new FakeNativeImage(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FakeImage createImage(InputStream is) {
|
||||||
|
return new FakeNativeImage(NativeImage.func_195713_a(is));
|
||||||
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return image.func_195702_a();
|
return image.func_195702_a();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,105 +1,137 @@
|
|||||||
package customskinloader.loader;
|
package customskinloader.loader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
import org.apache.commons.io.IOUtils;
|
import java.util.List;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.loader.jsonapi.*;
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
import customskinloader.utils.HttpRequestUtil;
|
import customskinloader.utils.HttpRequestUtil;
|
||||||
import customskinloader.utils.HttpUtil0;
|
import customskinloader.utils.HttpUtil0;
|
||||||
import customskinloader.utils.HttpRequestUtil.HttpRequest;
|
import org.apache.commons.io.IOUtils;
|
||||||
import customskinloader.utils.HttpRequestUtil.HttpResponce;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class JsonAPILoader implements ProfileLoader.IProfileLoader {
|
public class JsonAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||||
|
|
||||||
public interface IJsonAPI {
|
public interface IJsonAPI {
|
||||||
|
List<IDefaultProfile> getDefaultProfiles(JsonAPILoader loader);
|
||||||
|
|
||||||
String toJsonUrl(String root, String username);
|
String toJsonUrl(String root, String username);
|
||||||
|
|
||||||
String getPayload(SkinSiteProfile ssp);
|
String getPayload(SkinSiteProfile ssp);
|
||||||
|
|
||||||
UserProfile toUserProfile(String root, String json, boolean local);
|
UserProfile toUserProfile(String root, String json, boolean local);
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
}
|
}
|
||||||
public static class ErrorProfile{
|
|
||||||
|
public static class ErrorProfile {
|
||||||
public int errno;
|
public int errno;
|
||||||
public String msg;
|
public String msg;
|
||||||
}
|
}
|
||||||
public enum Type{
|
|
||||||
CustomSkinAPI(new CustomSkinAPI()),
|
private final IJsonAPI jsonAPI;
|
||||||
CustomSkinAPIPlus(new CustomSkinAPIPlus()),
|
|
||||||
UniSkinAPI(new UniSkinAPI()),
|
public JsonAPILoader(IJsonAPI jsonAPI) {
|
||||||
ElyByAPI(new ElyByAPI()),
|
this.jsonAPI = jsonAPI;
|
||||||
GlitchlessAPI(new GlitchlessAPI());
|
|
||||||
public IJsonAPI jsonAPI;
|
|
||||||
Type(IJsonAPI jsonAPI){
|
|
||||||
this.jsonAPI=jsonAPI;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type type;
|
// === ICustomSkinLoaderPlugin ===
|
||||||
public JsonAPILoader(Type type){
|
|
||||||
this.type=type;
|
@Override
|
||||||
|
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IDefaultProfile> getDefaultProfiles() {
|
||||||
|
return this.jsonAPI.getDefaultProfiles(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||||
|
protected final JsonAPILoader loader;
|
||||||
|
|
||||||
|
public DefaultProfile(JsonAPILoader loader) {
|
||||||
|
this.loader = loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||||
|
ssp.type = this.loader.getName();
|
||||||
|
ssp.root = this.getRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
// === IProfileLoader ===
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
||||||
String username=gameProfile.getName();
|
String username = gameProfile.getName();
|
||||||
if(StringUtils.isEmpty(ssp.root) && type!=Type.ElyByAPI){
|
if (StringUtils.isEmpty(ssp.root)) {
|
||||||
CustomSkinLoader.logger.info("Root not defined.");
|
CustomSkinLoader.logger.info("Root not defined.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean local = HttpUtil0.isLocal(ssp.root);
|
boolean local = HttpUtil0.isLocal(ssp.root);
|
||||||
String jsonUrl=type.jsonAPI.toJsonUrl(ssp.root, username);
|
String jsonUrl = this.jsonAPI.toJsonUrl(ssp.root, username);
|
||||||
|
//Some API like MinecraftCapesAPI won't load profile at sometime
|
||||||
|
if (jsonUrl == null) {
|
||||||
|
CustomSkinLoader.logger.info("Profile url not found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
String json;
|
String json;
|
||||||
if(local){
|
if (local) {
|
||||||
File jsonFile = new File(CustomSkinLoader.DATA_DIR, jsonUrl);
|
File jsonFile = new File(CustomSkinLoader.DATA_DIR, jsonUrl);
|
||||||
if(!jsonFile.exists()){
|
if (!jsonFile.exists()) {
|
||||||
CustomSkinLoader.logger.info("Profile File not found.");
|
CustomSkinLoader.logger.info("Profile File not found.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
json=IOUtils.toString(new FileInputStream(jsonFile), "UTF-8");
|
json = IOUtils.toString(Files.newInputStream(jsonFile.toPath()), StandardCharsets.UTF_8);
|
||||||
}else{
|
} else {
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(jsonUrl).setCacheTime(90).setUserAgent(ssp.userAgent).setPayload(type.jsonAPI.getPayload(ssp)));
|
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(jsonUrl).setCacheTime(90).setUserAgent(ssp.userAgent).setPayload(this.jsonAPI.getPayload(ssp)));
|
||||||
json=responce.content;
|
json = responce.content;
|
||||||
}
|
}
|
||||||
if(json==null||json.equals("")){
|
if (json == null || json.equals("")) {
|
||||||
CustomSkinLoader.logger.info("Profile not found.");
|
CustomSkinLoader.logger.info("Profile not found.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorProfile profile=CustomSkinLoader.GSON.fromJson(json, ErrorProfile.class);
|
ErrorProfile profile = CustomSkinLoader.GSON.fromJson(json, ErrorProfile.class);
|
||||||
if(profile.errno!=0){
|
if (profile.errno != 0) {
|
||||||
CustomSkinLoader.logger.info("Error "+profile.errno+": "+profile.msg);
|
CustomSkinLoader.logger.info("Error " + profile.errno + ": " + profile.msg);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserProfile p=type.jsonAPI.toUserProfile(ssp.root, json, local);
|
UserProfile p = this.jsonAPI.toUserProfile(ssp.root, json, local);
|
||||||
if(p==null||p.isEmpty()){
|
if (p == null || p.isEmpty()) {
|
||||||
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
||||||
return null;
|
return null;
|
||||||
}else{
|
} else {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||||
return !StringUtils.isNoneEmpty(ssp0.root) || ssp0.root.equalsIgnoreCase(ssp1.root);
|
return !StringUtils.isNoneEmpty(ssp0.root) || ssp0.root.equalsIgnoreCase(ssp1.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return type.jsonAPI.getName();
|
return this.jsonAPI.getName();
|
||||||
}
|
}
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
|
||||||
@Override
|
@Override
|
||||||
public void init(SkinSiteProfile ssp) {
|
public void init(SkinSiteProfile ssp) {
|
||||||
if(HttpUtil0.isLocal(ssp.root)){
|
if (HttpUtil0.isLocal(ssp.root)) {
|
||||||
File f=new File(ssp.root);
|
File f = new File(ssp.root);
|
||||||
if(!f.exists())
|
if (!f.exists())
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
f.mkdirs();
|
f.mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,79 +1,163 @@
|
|||||||
package customskinloader.loader;
|
package customskinloader.loader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
import com.mojang.util.UUIDTypeAdapter;
|
import java.util.List;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.profile.ModelManager0;
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
import customskinloader.utils.HttpRequestUtil;
|
import customskinloader.utils.HttpRequestUtil;
|
||||||
import customskinloader.utils.HttpRequestUtil.HttpRequest;
|
|
||||||
import customskinloader.utils.HttpRequestUtil.HttpResponce;
|
|
||||||
import customskinloader.utils.HttpTextureUtil;
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
import customskinloader.utils.HttpUtil0;
|
import customskinloader.utils.HttpUtil0;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
public class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IDefaultProfile> getDefaultProfiles() {
|
||||||
|
return Collections.singletonList(new LocalSkin(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||||
|
protected final LegacyLoader loader;
|
||||||
|
|
||||||
|
public DefaultProfile(LegacyLoader loader) {
|
||||||
|
this.loader = loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||||
|
ssp.type = this.loader.getName();
|
||||||
|
if (ssp.checkPNG == null) {
|
||||||
|
ssp.checkPNG = false;
|
||||||
|
}
|
||||||
|
if (ssp.model == null) {
|
||||||
|
ssp.model = "auto";
|
||||||
|
}
|
||||||
|
//Set texture url when it is empty
|
||||||
|
//Remote texture url could be changed, it will be auto updated here
|
||||||
|
if (ssp.skin == null || !HttpUtil0.isLocal(this.getSkinRoot())) {
|
||||||
|
ssp.skin = this.getSkinRoot();
|
||||||
|
}
|
||||||
|
if (ssp.cape == null || !HttpUtil0.isLocal(this.getCapeRoot())) {
|
||||||
|
ssp.cape = this.getCapeRoot();
|
||||||
|
}
|
||||||
|
if (ssp.elytra == null || !HttpUtil0.isLocal(this.getElytraRoot())) {
|
||||||
|
ssp.elytra = this.getElytraRoot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getSkinRoot();
|
||||||
|
|
||||||
|
public abstract String getCapeRoot();
|
||||||
|
|
||||||
|
public abstract String getElytraRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LocalSkin extends LegacyLoader.DefaultProfile {
|
||||||
|
public LocalSkin(LegacyLoader loader) {
|
||||||
|
super(loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "LocalSkin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSkinRoot() {
|
||||||
|
return "LocalSkin/skins/{USERNAME}.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCapeRoot() {
|
||||||
|
return "LocalSkin/capes/{USERNAME}.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElytraRoot() {
|
||||||
|
return "LocalSkin/elytras/{USERNAME}.png";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Minecrack could not load skin correctly
|
||||||
|
// public static class Minecrack extends LegacyLoader.DefaultProfile {
|
||||||
|
// public Minecrack(LegacyLoader loader) { super(loader); }
|
||||||
|
// @Override public String getName() { return "Minecrack"; }
|
||||||
|
// @Override public int getPriority() { return 600; }
|
||||||
|
// @Override public String getSkinRoot() { return "http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png"; }
|
||||||
|
// @Override public String getCapeRoot() { return "http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png"; }
|
||||||
|
// @Override public String getElytraRoot() { return null; }
|
||||||
|
// }
|
||||||
|
|
||||||
public class LegacyLoader implements ProfileLoader.IProfileLoader {
|
|
||||||
public static final String USERNAME_PLACEHOLDER = "{USERNAME}";
|
public static final String USERNAME_PLACEHOLDER = "{USERNAME}";
|
||||||
public static final String UUID_PLACEHOLDER = "{UUID}";
|
public static final String UUID_PLACEHOLDER = "{UUID}";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) {
|
||||||
String username = gameProfile.getName();
|
|
||||||
UserProfile profile = new UserProfile();
|
UserProfile profile = new UserProfile();
|
||||||
if (StringUtils.isNoneEmpty(ssp.skin)) {
|
//Try to load all textures
|
||||||
String skin = expandURL(ssp.skin, username);
|
getTextureUrl(ssp, gameProfile, ssp.skin, it -> {
|
||||||
if (HttpUtil0.isLocal(ssp.skin)) {
|
profile.skinUrl = it;
|
||||||
File skinFile = new File(CustomSkinLoader.DATA_DIR, skin);
|
profile.model = ssp.model;
|
||||||
if (skinFile.exists() && skinFile.isFile())
|
});
|
||||||
profile.skinUrl = HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified()));
|
getTextureUrl(ssp, gameProfile, ssp.cape, it -> profile.capeUrl = it);
|
||||||
} else {
|
getTextureUrl(ssp, gameProfile, ssp.elytra, it -> profile.elytraUrl = it);
|
||||||
HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90));
|
|
||||||
if (responce.success)
|
|
||||||
profile.skinUrl = HttpTextureUtil.getLegacyFakeUrl(skin);
|
|
||||||
}
|
|
||||||
profile.model = profile.hasSkinUrl() ? ssp.model : null;
|
|
||||||
}
|
|
||||||
if (StringUtils.isNoneEmpty(ssp.cape)) {
|
|
||||||
String cape = expandURL(ssp.cape, username);
|
|
||||||
if (HttpUtil0.isLocal(ssp.cape)) {
|
|
||||||
File capeFile = new File(CustomSkinLoader.DATA_DIR, cape);
|
|
||||||
if (capeFile.exists() && capeFile.isFile())
|
|
||||||
profile.capeUrl = HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified()));
|
|
||||||
} else {
|
|
||||||
HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(cape).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90));
|
|
||||||
if (responce.success)
|
|
||||||
profile.capeUrl = HttpTextureUtil.getLegacyFakeUrl(cape);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ModelManager0.isElytraSupported() && StringUtils.isNoneEmpty(ssp.elytra)) {
|
|
||||||
String elytra = expandURL(ssp.elytra, username);
|
|
||||||
if (HttpUtil0.isLocal(ssp.elytra)) {
|
|
||||||
File elytraFile = new File(CustomSkinLoader.DATA_DIR, elytra);
|
|
||||||
if (elytraFile.exists() && elytraFile.isFile())
|
|
||||||
profile.elytraUrl = HttpTextureUtil.getLocalLegacyFakeUrl(elytra, HttpTextureUtil.getHash(elytra, elytraFile.length(), elytraFile.lastModified()));
|
|
||||||
} else {
|
|
||||||
HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(elytra).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false).setCacheTime(90));
|
|
||||||
if (responce.success)
|
|
||||||
profile.elytraUrl = HttpTextureUtil.getLegacyFakeUrl(elytra);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (profile.isEmpty()) {
|
if (profile.isEmpty()) {
|
||||||
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
CustomSkinLoader.logger.info("No texture could be found.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getTextureUrl(
|
||||||
|
SkinSiteProfile ssp, GameProfile gameProfile, String baseUrl, Consumer<String> onSuccess) {
|
||||||
|
//Base URL is empty
|
||||||
|
if (baseUrl == null || baseUrl.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String url = expandURL(baseUrl, gameProfile.getName());
|
||||||
|
//No texture can be loaded
|
||||||
|
if (url == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Local texture file logic
|
||||||
|
if (HttpUtil0.isLocal(url)) {
|
||||||
|
File file = new File(CustomSkinLoader.DATA_DIR, url);
|
||||||
|
if (file.exists() && file.isFile()) {
|
||||||
|
String fakeUrl = HttpTextureUtil.getLocalLegacyFakeUrl(url,
|
||||||
|
HttpTextureUtil.getHash(url, file.length(), file.lastModified()));
|
||||||
|
onSuccess.accept(fakeUrl);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Remote texture logic
|
||||||
|
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(url)
|
||||||
|
.setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG != null && ssp.checkPNG).setLoadContent(false));
|
||||||
|
if (responce.success) {
|
||||||
|
onSuccess.accept(HttpTextureUtil.getLegacyFakeUrl(url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||||
return (!StringUtils.isNoneEmpty(ssp0.skin) || ssp0.skin.equalsIgnoreCase(ssp1.skin)) || (!StringUtils.isNoneEmpty(ssp0.cape) || ssp0.cape.equalsIgnoreCase(ssp1.cape));
|
return Objects.equals(ssp0.skin, ssp1.skin) && Objects.equals(ssp0.cape, ssp1.cape) &&
|
||||||
|
Objects.equals(ssp0.elytra, ssp1.elytra);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,36 +167,34 @@ public class LegacyLoader implements ProfileLoader.IProfileLoader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(SkinSiteProfile ssp) {
|
public void init(SkinSiteProfile ssp) {
|
||||||
if (HttpUtil0.isLocal(ssp.skin))
|
initFolder(ssp.skin);
|
||||||
initFolder(ssp.skin);
|
initFolder(ssp.cape);
|
||||||
if (HttpUtil0.isLocal(ssp.cape))
|
initFolder(ssp.elytra);
|
||||||
initFolder(ssp.cape);
|
|
||||||
if (HttpUtil0.isLocal(ssp.elytra))
|
|
||||||
initFolder(ssp.elytra);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
private void initFolder(String target) {
|
private void initFolder(String target) {
|
||||||
|
//Only local skin should init folder
|
||||||
|
if (!HttpUtil0.isLocal(target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
String file = target.replace(USERNAME_PLACEHOLDER, "init");
|
String file = target.replace(USERNAME_PLACEHOLDER, "init");
|
||||||
File folder = new File(CustomSkinLoader.DATA_DIR, file).getParentFile();
|
File folder = new File(CustomSkinLoader.DATA_DIR, file).getParentFile();
|
||||||
if (folder != null && !folder.exists())
|
if (folder != null && !folder.exists()) {
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String expandURL(String url, String username) {
|
private String expandURL(String url, String username) {
|
||||||
String t = url.replace(USERNAME_PLACEHOLDER, username);
|
String t = url.replace(USERNAME_PLACEHOLDER, username);
|
||||||
if (t.contains(UUID_PLACEHOLDER))
|
if (!t.contains(UUID_PLACEHOLDER)) {
|
||||||
t = t.replace(UUID_PLACEHOLDER, getMojangUUID(username));
|
return t;
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
private String getMojangUUID(String username) {
|
|
||||||
GameProfile profile = MojangAPILoader.loadGameProfile(MojangAPILoader.getMojangApiRoot(), username);
|
|
||||||
if (profile == null) {
|
|
||||||
CustomSkinLoader.logger.info("UUID for %s not found.", username);
|
|
||||||
return "{ABORT}";
|
|
||||||
}
|
}
|
||||||
return UUIDTypeAdapter.fromUUID(profile.getId());
|
String uuid = MojangAPILoader.getMojangUuidByUsername(username);
|
||||||
|
//If Mojang uuid not found, won't load the texture
|
||||||
|
if (uuid == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return t.replace(UUID_PLACEHOLDER, uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
package customskinloader.loader;
|
package customskinloader.loader;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import org.apache.commons.codec.Charsets;
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
@@ -19,19 +18,75 @@ import com.mojang.authlib.properties.PropertyMap;
|
|||||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||||
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
||||||
import com.mojang.util.UUIDTypeAdapter;
|
import com.mojang.util.UUIDTypeAdapter;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.profile.ModelManager0;
|
import customskinloader.profile.ModelManager0;
|
||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
import customskinloader.utils.HttpRequestUtil;
|
import customskinloader.utils.HttpRequestUtil;
|
||||||
import customskinloader.utils.HttpRequestUtil.HttpRequest;
|
import org.apache.commons.codec.Charsets;
|
||||||
import customskinloader.utils.HttpRequestUtil.HttpResponce;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class MojangAPILoader implements ProfileLoader.IProfileLoader {
|
public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IDefaultProfile> getDefaultProfiles() {
|
||||||
|
return Lists.newArrayList(new Mojang(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||||
|
protected final MojangAPILoader loader;
|
||||||
|
|
||||||
|
public DefaultProfile(MojangAPILoader loader) {
|
||||||
|
this.loader = loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||||
|
ssp.type = this.loader.getName();
|
||||||
|
ssp.apiRoot = this.getAPIRoot();
|
||||||
|
ssp.sessionRoot = this.getSessionRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getAPIRoot();
|
||||||
|
|
||||||
|
public abstract String getSessionRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Mojang extends MojangAPILoader.DefaultProfile {
|
||||||
|
public Mojang(MojangAPILoader loader) {
|
||||||
|
super(loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Mojang";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAPIRoot() {
|
||||||
|
return getMojangApiRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSessionRoot() {
|
||||||
|
return getMojangSessionRoot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) {
|
||||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(gameProfile);
|
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(gameProfile);
|
||||||
if (!map.isEmpty()) {
|
if (!map.isEmpty()) {
|
||||||
CustomSkinLoader.logger.info("Default profile will be used.");
|
CustomSkinLoader.logger.info("Default profile will be used.");
|
||||||
@@ -58,31 +113,49 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader {
|
|||||||
//Doc (https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs)
|
//Doc (https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs)
|
||||||
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
||||||
|
|
||||||
HttpResponce responce = HttpRequestUtil.makeHttpRequest(
|
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(
|
||||||
new HttpRequest(apiRoot + "profiles/minecraft")
|
new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft")
|
||||||
.setCacheTime(-1).setPayload(gson.toJson(Collections.singletonList(username)))
|
.setCacheTime(600).setPayload(gson.toJson(Collections.singletonList(username)))
|
||||||
);
|
);
|
||||||
if (StringUtils.isEmpty(responce.content))
|
if (StringUtils.isEmpty(responce.content)) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
GameProfile[] profiles = gson.fromJson(responce.content, GameProfile[].class);
|
GameProfile[] profiles = gson.fromJson(responce.content, GameProfile[].class);
|
||||||
if (profiles.length == 0) return null;
|
if (profiles.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
GameProfile gameProfile = profiles[0];
|
GameProfile gameProfile = profiles[0];
|
||||||
|
|
||||||
if (gameProfile.getId() == null)
|
if (gameProfile.getId() == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
return new GameProfile(gameProfile.getId(), gameProfile.getName());
|
return new GameProfile(gameProfile.getId(), gameProfile.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Mojang UUID by username.
|
||||||
|
*
|
||||||
|
* @param username username to query
|
||||||
|
* @return UUID in Mojang API style string. Returns {@code null} if username not found in Mojang API.
|
||||||
|
*/
|
||||||
|
public static String getMojangUuidByUsername(String username) {
|
||||||
|
GameProfile profile = loadGameProfile(getMojangApiRoot(), username);
|
||||||
|
if (profile == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return UUIDTypeAdapter.fromUUID(profile.getId());
|
||||||
|
}
|
||||||
|
|
||||||
//UUID -> Profile
|
//UUID -> Profile
|
||||||
public static GameProfile fillGameProfile(String sessionRoot, GameProfile profile) {
|
public static GameProfile fillGameProfile(String sessionRoot, GameProfile profile) {
|
||||||
//Doc (http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape)
|
//Doc (http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape)
|
||||||
HttpResponce responce = HttpRequestUtil.makeHttpRequest(
|
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(
|
||||||
new HttpRequest(sessionRoot + "session/minecraft/profile/"
|
new HttpRequestUtil.HttpRequest(sessionRoot + "session/minecraft/profile/"
|
||||||
+ UUIDTypeAdapter.fromUUID(profile.getId())).setCacheTime(90));
|
+ UUIDTypeAdapter.fromUUID(profile.getId())).setCacheTime(90));
|
||||||
if (StringUtils.isEmpty(responce.content))
|
if (StringUtils.isEmpty(responce.content)) {
|
||||||
return profile;
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
Gson gson = new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
||||||
@@ -96,25 +169,30 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile gameProfile) {
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile gameProfile) {
|
||||||
if (gameProfile == null)
|
if (gameProfile == null) {
|
||||||
return Maps.newHashMap();
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
Property textureProperty = Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
|
Property textureProperty = Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
|
||||||
if (textureProperty == null)
|
if (textureProperty == null) {
|
||||||
return Maps.newHashMap();
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
String value = textureProperty.getValue();
|
String value = textureProperty.getValue();
|
||||||
if (StringUtils.isBlank(value))
|
if (StringUtils.isBlank(value)) {
|
||||||
return Maps.newHashMap();
|
return Maps.newHashMap();
|
||||||
@SuppressWarnings("deprecation") String json = new String(Base64.decodeBase64(value), Charsets.UTF_8);
|
}
|
||||||
|
String json = new String(Base64.decodeBase64(value), StandardCharsets.UTF_8);
|
||||||
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
||||||
MinecraftTexturesPayload result = gson.fromJson(json, MinecraftTexturesPayload.class);
|
MinecraftTexturesPayload result = gson.fromJson(json, MinecraftTexturesPayload.class);
|
||||||
if (result == null || result.getTextures() == null)
|
if (result == null || result.getTextures() == null) {
|
||||||
return Maps.newHashMap();
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
return result.getTextures();
|
return result.getTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||||
return true;
|
return (!StringUtils.isNoneEmpty(ssp0.apiRoot) || ssp0.apiRoot.equalsIgnoreCase(ssp1.apiRoot)) ||
|
||||||
|
(!StringUtils.isNoneEmpty(ssp0.sessionRoot) || ssp0.sessionRoot.equalsIgnoreCase(ssp1.sessionRoot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -126,14 +204,20 @@ public class MojangAPILoader implements ProfileLoader.IProfileLoader {
|
|||||||
public void init(SkinSiteProfile ssp) {
|
public void init(SkinSiteProfile ssp) {
|
||||||
//Init default api & session root for Mojang API
|
//Init default api & session root for Mojang API
|
||||||
if (ssp.apiRoot == null)
|
if (ssp.apiRoot == null)
|
||||||
ssp.apiRoot = "https://api.mojang.com/";
|
ssp.apiRoot = getMojangApiRoot();
|
||||||
if (ssp.sessionRoot == null)
|
if (ssp.sessionRoot == null)
|
||||||
ssp.sessionRoot = "https://sessionserver.mojang.com/";
|
ssp.sessionRoot = getMojangSessionRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent authlib-injector (https://github.com/yushijinhun/authlib-injector) from modifying these strings
|
||||||
private static final String MOJANG_API_ROOT = "https://api{DO_NOT_MODIFY}.mojang.com/";
|
private static final String MOJANG_API_ROOT = "https://api{DO_NOT_MODIFY}.mojang.com/";
|
||||||
|
private static final String MOJANG_SESSION_ROOT = "https://sessionserver{DO_NOT_MODIFY}.mojang.com/";
|
||||||
|
|
||||||
public static String getMojangApiRoot() {
|
public static String getMojangApiRoot() {
|
||||||
return MOJANG_API_ROOT.replace("{DO_NOT_MODIFY}", "");
|
return MOJANG_API_ROOT.replace("{DO_NOT_MODIFY}", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getMojangSessionRoot() {
|
||||||
|
return MOJANG_SESSION_ROOT.replace("{DO_NOT_MODIFY}", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,30 +3,25 @@ package customskinloader.loader;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.plugin.PluginLoader;
|
import customskinloader.plugin.PluginLoader;
|
||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
|
|
||||||
public class ProfileLoader {
|
public class ProfileLoader {
|
||||||
private static final IProfileLoader[] DEFAULT_LOADERS={
|
public static final HashMap<String, IProfileLoader> LOADERS = initLoaders();
|
||||||
new MojangAPILoader(),
|
|
||||||
new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPI),
|
|
||||||
new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPIPlus),
|
|
||||||
new JsonAPILoader(JsonAPILoader.Type.UniSkinAPI),
|
|
||||||
new JsonAPILoader(JsonAPILoader.Type.ElyByAPI),
|
|
||||||
new JsonAPILoader(JsonAPILoader.Type.GlitchlessAPI),
|
|
||||||
new LegacyLoader()};
|
|
||||||
|
|
||||||
public static final HashMap<String,IProfileLoader> LOADERS=initLoaders();
|
|
||||||
|
|
||||||
private static HashMap<String, IProfileLoader> initLoaders() {
|
private static HashMap<String, IProfileLoader> initLoaders() {
|
||||||
HashMap<String, IProfileLoader> loaders=new HashMap<String, IProfileLoader>();
|
HashMap<String, ProfileLoader.IProfileLoader> profileLoaders = new HashMap<>();
|
||||||
for(IProfileLoader loader:DEFAULT_LOADERS){
|
for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS) {
|
||||||
loaders.put(loader.getName().toLowerCase(), loader);
|
ProfileLoader.IProfileLoader profileLoader = plugin.getProfileLoader();
|
||||||
|
if (profileLoader != null) {
|
||||||
|
profileLoaders.put(profileLoader.getName().toLowerCase(), profileLoader);
|
||||||
|
CustomSkinLoader.logger.info("Add a profile loader: " + profileLoader.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
loaders.putAll(PluginLoader.loadPlugins());
|
return profileLoaders;
|
||||||
return loaders;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IProfileLoader {
|
public interface IProfileLoader {
|
||||||
|
|||||||
@@ -1,22 +1,51 @@
|
|||||||
package customskinloader.loader.jsonapi;
|
package customskinloader.loader.jsonapi;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.profile.ModelManager0;
|
import customskinloader.profile.ModelManager0;
|
||||||
import customskinloader.profile.ModelManager0.Model;
|
|
||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
import customskinloader.utils.HttpTextureUtil;
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class CustomSkinAPI implements JsonAPILoader.IJsonAPI {
|
||||||
|
|
||||||
|
public static class LittleSkin extends JsonAPILoader.DefaultProfile {
|
||||||
|
public LittleSkin(JsonAPILoader loader) { super(loader); }
|
||||||
|
@Override public String getName() { return "LittleSkin"; }
|
||||||
|
@Override public int getPriority() { return 200; }
|
||||||
|
@Override public String getRoot() { return "https://littleskin.cn/csl/"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BlessingSkin extends JsonAPILoader.DefaultProfile {
|
||||||
|
public BlessingSkin(JsonAPILoader loader) { super(loader); }
|
||||||
|
@Override public String getName() { return "BlessingSkin"; }
|
||||||
|
@Override public int getPriority() { return 300; }
|
||||||
|
@Override public String getRoot() { return "https://skin.prinzeugen.net/"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// // OneSkin has been removed temporarily
|
||||||
|
// public static class OneSkin extends JsonAPILoader.DefaultProfile {
|
||||||
|
// public OneSkin(JsonAPILoader loader) { super(loader); }
|
||||||
|
// @Override public String getName() { return "OneSkin"; }
|
||||||
|
// @Override public int getPriority() { return 500; }
|
||||||
|
// @Override public String getRoot() { return "http://fleey.cn/skin/skin_user/skin_json.php/"; }
|
||||||
|
// }
|
||||||
|
|
||||||
public class CustomSkinAPI implements IJsonAPI {
|
|
||||||
private static final String TEXTURES="textures/";
|
private static final String TEXTURES="textures/";
|
||||||
private static final String SUFFIX=".json";
|
private static final String SUFFIX=".json";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
|
return Lists.newArrayList(new LittleSkin(loader), new BlessingSkin(loader));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toJsonUrl(String root, String username) {
|
public String toJsonUrl(String root, String username) {
|
||||||
return root + username + SUFFIX;
|
return root + username + SUFFIX;
|
||||||
@@ -43,7 +72,7 @@ public class CustomSkinAPI implements IJsonAPI {
|
|||||||
p.elytraUrl=HttpTextureUtil.getLocalFakeUrl(p.elytraUrl);
|
p.elytraUrl=HttpTextureUtil.getLocalFakeUrl(p.elytraUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String,String> textures=new LinkedHashMap<String,String>();
|
Map<String,String> textures=new LinkedHashMap<>();
|
||||||
if(profile.skins!=null)
|
if(profile.skins!=null)
|
||||||
textures.putAll(profile.skins);
|
textures.putAll(profile.skins);
|
||||||
if(profile.textures!=null)
|
if(profile.textures!=null)
|
||||||
@@ -53,7 +82,7 @@ public class CustomSkinAPI implements IJsonAPI {
|
|||||||
|
|
||||||
boolean hasSkin=false;
|
boolean hasSkin=false;
|
||||||
for(String model:textures.keySet()){
|
for(String model:textures.keySet()){
|
||||||
Model enumModel=ModelManager0.getEnumModel(model);
|
ModelManager0.Model enumModel=ModelManager0.getEnumModel(model);
|
||||||
if(enumModel==null||StringUtils.isEmpty(textures.get(model)))
|
if(enumModel==null||StringUtils.isEmpty(textures.get(model)))
|
||||||
continue;
|
continue;
|
||||||
if(ModelManager0.isSkin(enumModel))
|
if(ModelManager0.isSkin(enumModel))
|
||||||
@@ -69,7 +98,7 @@ public class CustomSkinAPI implements IJsonAPI {
|
|||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
private class CustomSkinAPIProfile{
|
private static class CustomSkinAPIProfile{
|
||||||
public String username;
|
public String username;
|
||||||
public LinkedHashMap<String,String> textures;
|
public LinkedHashMap<String,String> textures;
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
package customskinloader.loader.jsonapi;
|
package customskinloader.loader.jsonapi;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.loader.JsonAPILoader;
|
import customskinloader.loader.JsonAPILoader;
|
||||||
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.profile.UserProfile;
|
|
||||||
import customskinloader.utils.MinecraftUtil;
|
import customskinloader.utils.MinecraftUtil;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
public class CustomSkinAPIPlus implements IJsonAPI {
|
public class CustomSkinAPIPlus extends CustomSkinAPI {
|
||||||
|
|
||||||
private static String clientID=null;
|
private static String clientID=null;
|
||||||
public CustomSkinAPIPlus(){
|
public CustomSkinAPIPlus(){
|
||||||
@@ -35,9 +34,10 @@ public class CustomSkinAPIPlus implements IJsonAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toJsonUrl(String root, String username) {
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toJsonUrl(root, username);
|
return Lists.newArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,11 +45,6 @@ public class CustomSkinAPIPlus implements IJsonAPI {
|
|||||||
return new Gson().toJson(new CustomSkinAPIPlusPayload());
|
return new Gson().toJson(new CustomSkinAPIPlusPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
|
||||||
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toUserProfile(root, json, local);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "CustomSKinAPIPlus";
|
return "CustomSKinAPIPlus";
|
||||||
|
|||||||
@@ -1,40 +1,47 @@
|
|||||||
package customskinloader.loader.jsonapi;
|
package customskinloader.loader.jsonapi;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.loader.JsonAPILoader;
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.profile.ModelManager0;
|
import customskinloader.profile.ModelManager0;
|
||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
import customskinloader.utils.MinecraftUtil;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ElyByAPI implements JsonAPILoader.IJsonAPI {
|
public class ElyByAPI implements JsonAPILoader.IJsonAPI {
|
||||||
|
|
||||||
|
public static class ElyBy extends JsonAPILoader.DefaultProfile {
|
||||||
|
public ElyBy(JsonAPILoader loader) { super(loader); }
|
||||||
|
@Override public String getName() { return "ElyBy"; }
|
||||||
|
@Override public int getPriority() { return 400; }
|
||||||
|
@Override public String getRoot() { return "http://skinsystem.ely.by/textures/"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TLauncher extends JsonAPILoader.DefaultProfile {
|
||||||
|
public TLauncher(JsonAPILoader loader) { super(loader); }
|
||||||
|
@Override public String getName() { return "TLauncher"; }
|
||||||
|
@Override public int getPriority() { return 550; }
|
||||||
|
@Override public String getRoot() { return "https://auth.tlauncher.org/skin/profile/texture/login/"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
|
return Lists.newArrayList(new ElyBy(loader), new TLauncher(loader));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toJsonUrl(String root, String username) {
|
public String toJsonUrl(String root, String username) {
|
||||||
return "http://skinsystem.ely.by/textures/" + username + "?version=2&minecraft_version=" + MinecraftUtil.getMinecraftMainVersion();
|
return root + username;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
Map<Type, MinecraftProfileTexture> result = new Gson().fromJson(json, new TypeToken<Map<Type, MinecraftProfileTexture>>() {
|
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> result = new Gson().fromJson(json, new TypeToken<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>>() { }.getType());
|
||||||
}.getType());
|
|
||||||
if (!result.containsKey(Type.SKIN))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
//Check URL
|
|
||||||
try {
|
|
||||||
URI uri = new URI(result.get(Type.SKIN).getUrl());
|
|
||||||
if (!uri.getHost().endsWith("ely.by"))
|
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ModelManager0.toUserProfile(result);
|
return ModelManager0.toUserProfile(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,31 @@
|
|||||||
package customskinloader.loader.jsonapi;
|
package customskinloader.loader.jsonapi;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.loader.JsonAPILoader;
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.profile.ModelManager0;
|
import customskinloader.profile.ModelManager0;
|
||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class GlitchlessAPI implements JsonAPILoader.IJsonAPI {
|
public class GlitchlessAPI implements JsonAPILoader.IJsonAPI {
|
||||||
|
|
||||||
|
public static class GlitchlessGames extends JsonAPILoader.DefaultProfile {
|
||||||
|
public GlitchlessGames(JsonAPILoader loader) { super(loader); }
|
||||||
|
@Override public String getName() { return "GlitchlessGames"; }
|
||||||
|
@Override public int getPriority() { return 700; }
|
||||||
|
@Override public String getRoot() { return "https://games.glitchless.ru/api/minecraft/users/profiles/textures/?nickname="; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
|
return Lists.newArrayList(new GlitchlessGames(loader));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toJsonUrl(String root, String username) {
|
public String toJsonUrl(String root, String username) {
|
||||||
return root + username;
|
return root + username;
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package customskinloader.loader.jsonapi;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import customskinloader.Logger;
|
||||||
|
import customskinloader.config.SkinSiteProfile;
|
||||||
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.loader.MojangAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
|
import customskinloader.profile.ModelManager0;
|
||||||
|
import customskinloader.profile.UserProfile;
|
||||||
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MinecraftCapesAPI implements JsonAPILoader.IJsonAPI {
|
||||||
|
|
||||||
|
public static class MinecraftCapes extends JsonAPILoader.DefaultProfile {
|
||||||
|
public MinecraftCapes(JsonAPILoader loader) {
|
||||||
|
super(loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "MinecraftCapes";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRoot() {
|
||||||
|
return "https://minecraftcapes.net/profile/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
|
return Lists.newArrayList(new MinecraftCapes(loader));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toJsonUrl(String root, String username) {
|
||||||
|
String uuid = MojangAPILoader.getMojangUuidByUsername(username);
|
||||||
|
//If uuid cannot be found, we won't load profile in this API.
|
||||||
|
if (uuid == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//API url is `${root}${uuid}`
|
||||||
|
return root + uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
|
MinecraftCapesApiResponse result = new Gson().fromJson(json, MinecraftCapesApiResponse.class);
|
||||||
|
if (result.textures == null || result.textures.cape == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String capeBase64 = result.textures.cape;
|
||||||
|
byte[] capeBytes = Base64.decodeBase64(capeBase64);
|
||||||
|
String hash = HttpTextureUtil.getHash(capeBytes);
|
||||||
|
File cacheFile = HttpTextureUtil.getCacheFile(hash);
|
||||||
|
String fakeUrl = HttpTextureUtil.getBase64FakeUrl(hash);
|
||||||
|
|
||||||
|
//Save base64 image to cache file
|
||||||
|
try {
|
||||||
|
FileUtils.writeByteArrayToFile(cacheFile, capeBytes);
|
||||||
|
CustomSkinLoader.logger.info("Saved base64 image to " + cacheFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
CustomSkinLoader.logger.warning("Error parsing base64 image: " + capeBase64);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserProfile profile = new UserProfile();
|
||||||
|
profile.capeUrl = fakeUrl;
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPayload(SkinSiteProfile ssp) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "MinecraftCapesAPI";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MinecraftCapesApiResponse {
|
||||||
|
public boolean animatedCape;
|
||||||
|
public boolean capeGlint;
|
||||||
|
public boolean upsideDown;
|
||||||
|
public MinecraftCapesApiTexture textures;
|
||||||
|
|
||||||
|
public static class MinecraftCapesApiTexture {
|
||||||
|
public String cape;
|
||||||
|
public String ears;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,20 +3,33 @@ package customskinloader.loader.jsonapi;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.config.SkinSiteProfile;
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
import customskinloader.profile.ModelManager0;
|
import customskinloader.profile.ModelManager0;
|
||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
import customskinloader.profile.ModelManager0.Model;
|
|
||||||
import customskinloader.utils.HttpTextureUtil;
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class UniSkinAPI implements JsonAPILoader.IJsonAPI {
|
||||||
|
|
||||||
|
public static class SkinMe extends JsonAPILoader.DefaultProfile {
|
||||||
|
public SkinMe(JsonAPILoader loader) { super(loader); }
|
||||||
|
@Override public String getName() { return "SkinMe"; }
|
||||||
|
@Override public int getPriority() { return 500; }
|
||||||
|
@Override public String getRoot() { return "http://www.skinme.cc/uniskin/"; }
|
||||||
|
}
|
||||||
|
|
||||||
public class UniSkinAPI implements IJsonAPI {
|
|
||||||
private static final String TEXTURES="textures/";
|
private static final String TEXTURES="textures/";
|
||||||
private static final String SUFFIX=".json";
|
private static final String SUFFIX=".json";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
|
return Lists.newArrayList(new SkinMe(loader));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toJsonUrl(String root, String username) {
|
public String toJsonUrl(String root, String username) {
|
||||||
return root + username + SUFFIX;
|
return root + username + SUFFIX;
|
||||||
@@ -40,7 +53,7 @@ public class UniSkinAPI implements IJsonAPI {
|
|||||||
|
|
||||||
boolean hasSkin=false;
|
boolean hasSkin=false;
|
||||||
for(String model:profile.model_preference){
|
for(String model:profile.model_preference){
|
||||||
Model enumModel=ModelManager0.getEnumModel(model);
|
ModelManager0.Model enumModel=ModelManager0.getEnumModel(model);
|
||||||
if(enumModel==null||StringUtils.isEmpty(profile.skins.get(model)))
|
if(enumModel==null||StringUtils.isEmpty(profile.skins.get(model)))
|
||||||
continue;
|
continue;
|
||||||
if(ModelManager0.isSkin(enumModel))
|
if(ModelManager0.isSkin(enumModel))
|
||||||
|
|||||||
@@ -1,7 +1,35 @@
|
|||||||
package customskinloader.plugin;
|
package customskinloader.plugin;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import customskinloader.config.SkinSiteProfile;
|
||||||
import customskinloader.loader.ProfileLoader;
|
import customskinloader.loader.ProfileLoader;
|
||||||
|
|
||||||
public interface ICustomSkinLoaderPlugin {
|
public interface ICustomSkinLoaderPlugin {
|
||||||
|
/**
|
||||||
|
* @return return a non-null value if need to add a new profile loader, otherwise return null.
|
||||||
|
*/
|
||||||
ProfileLoader.IProfileLoader getProfileLoader();
|
ProfileLoader.IProfileLoader getProfileLoader();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the default implementations which import by {@link ICustomSkinLoaderPlugin#getProfileLoader()}.
|
||||||
|
*/
|
||||||
|
List<IDefaultProfile> getDefaultProfiles();
|
||||||
|
|
||||||
|
interface IDefaultProfile {
|
||||||
|
/**
|
||||||
|
* @return the name of {@link SkinSiteProfile#name}.
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the lower the number, the first to load.
|
||||||
|
*/
|
||||||
|
int getPriority();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Complete the {@link SkinSiteProfile} from config and write to config.
|
||||||
|
*/
|
||||||
|
void updateSkinSiteProfile(SkinSiteProfile ssp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,35 +5,50 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.loader.LegacyLoader;
|
||||||
|
import customskinloader.loader.MojangAPILoader;
|
||||||
|
import customskinloader.loader.jsonapi.*;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
|
||||||
import customskinloader.loader.ProfileLoader;
|
|
||||||
|
|
||||||
public class PluginLoader {
|
public class PluginLoader {
|
||||||
public static HashMap<String, ProfileLoader.IProfileLoader> loadPlugins() {
|
public static final ICustomSkinLoaderPlugin[] DEFAULT_PLUGINS = new ICustomSkinLoaderPlugin[]{
|
||||||
|
new MojangAPILoader(),
|
||||||
|
new LegacyLoader(),
|
||||||
|
new JsonAPILoader(new CustomSkinAPI()),
|
||||||
|
new JsonAPILoader(new CustomSkinAPIPlus()),
|
||||||
|
new JsonAPILoader(new UniSkinAPI()),
|
||||||
|
new JsonAPILoader(new ElyByAPI()),
|
||||||
|
new JsonAPILoader(new GlitchlessAPI()),
|
||||||
|
new JsonAPILoader(new MinecraftCapesAPI())
|
||||||
|
};
|
||||||
|
public static final ArrayList<ICustomSkinLoaderPlugin> PLUGINS = loadPlugins();
|
||||||
|
|
||||||
|
private static ArrayList<ICustomSkinLoaderPlugin> loadPlugins() {
|
||||||
File pluginsDir = new File(CustomSkinLoader.DATA_DIR, "Plugins");
|
File pluginsDir = new File(CustomSkinLoader.DATA_DIR, "Plugins");
|
||||||
ArrayList<URL> urls = new ArrayList<URL>();
|
ArrayList<URL> urls = new ArrayList<>();
|
||||||
if (!pluginsDir.isDirectory()) {
|
if (!pluginsDir.isDirectory()) {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
pluginsDir.mkdirs();
|
pluginsDir.mkdirs();
|
||||||
} else {
|
} else {
|
||||||
for (File plugin : FileUtils.listFiles(pluginsDir, new String[] {"jar", "zip"}, false)) {
|
for (File plugin : FileUtils.listFiles(pluginsDir, new String[]{"jar", "zip"}, false)) {
|
||||||
try {
|
try {
|
||||||
urls.add(plugin.toURI().toURL());
|
urls.add(plugin.toURI().toURL());
|
||||||
CustomSkinLoader.logger.info("Found a jar or zip file: " + plugin.getName());
|
CustomSkinLoader.logger.info("Found a jar or zip file: " + plugin.getName());
|
||||||
} catch (MalformedURLException ignored) {}
|
} catch (MalformedURLException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ArrayList<ICustomSkinLoaderPlugin> plugins = Lists.newArrayList(DEFAULT_PLUGINS);
|
||||||
|
|
||||||
ServiceLoader<ICustomSkinLoaderPlugin> sl = ServiceLoader.load(ICustomSkinLoaderPlugin.class, new URLClassLoader(urls.toArray(new URL[0]), PluginLoader.class.getClassLoader()));
|
ServiceLoader<ICustomSkinLoaderPlugin> sl = ServiceLoader.load(ICustomSkinLoaderPlugin.class, new URLClassLoader(urls.toArray(new URL[0]), PluginLoader.class.getClassLoader()));
|
||||||
HashMap<String, ProfileLoader.IProfileLoader> profileLoaders = new HashMap<String, ProfileLoader.IProfileLoader>();
|
for (ICustomSkinLoaderPlugin plugin : sl) {
|
||||||
for (ICustomSkinLoaderPlugin cslPlugin : sl) {
|
plugins.add(plugin);
|
||||||
ProfileLoader.IProfileLoader profileLoader = cslPlugin.getProfileLoader();
|
|
||||||
profileLoaders.put(profileLoader.getName().toLowerCase(), profileLoader);
|
|
||||||
CustomSkinLoader.logger.info("Add profile loader: " + profileLoader.getName());
|
|
||||||
}
|
}
|
||||||
return profileLoaders;
|
return plugins;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,24 @@
|
|||||||
package customskinloader.profile;
|
package customskinloader.profile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.Deque;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
import customskinloader.utils.TimeUtil;
|
import customskinloader.utils.TimeUtil;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
public class ProfileCache {
|
public class ProfileCache {
|
||||||
public static File PROFILE_CACHE_DIR=new File(CustomSkinLoader.DATA_DIR,"ProfileCache");
|
public static File PROFILE_CACHE_DIR=new File(CustomSkinLoader.DATA_DIR,"ProfileCache");
|
||||||
|
|
||||||
private Map<String, CachedProfile> cachedProfiles = new ConcurrentHashMap<>();
|
private Map<String, CachedProfile> cachedProfiles = new ConcurrentHashMap<>();
|
||||||
private Map<String, UserProfile> localProfiles = new ConcurrentHashMap<>();
|
private Map<String, UserProfile> localProfiles = new ConcurrentHashMap<>();
|
||||||
|
private Map<String, Deque<Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>>>> profileLoaders = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public ProfileCache(){
|
public ProfileCache(){
|
||||||
@@ -49,6 +53,13 @@ public class ProfileCache {
|
|||||||
return localProfiles.get(username.toLowerCase());
|
return localProfiles.get(username.toLowerCase());
|
||||||
return loadLocalProfile(username);
|
return loadLocalProfile(username);
|
||||||
}
|
}
|
||||||
|
public Optional<Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>>> getLastLoader(String username) {
|
||||||
|
Deque<Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>>> deque = this.profileLoaders.get(username);
|
||||||
|
if (deque != null) {
|
||||||
|
return Optional.ofNullable(deque.pollLast());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
public void setLoading(String username,boolean loading){
|
public void setLoading(String username,boolean loading){
|
||||||
getCachedProfile(username).loading=loading;
|
getCachedProfile(username).loading=loading;
|
||||||
@@ -59,11 +70,15 @@ public class ProfileCache {
|
|||||||
public void updateCache(String username,UserProfile profile,boolean saveLocalProfile){
|
public void updateCache(String username,UserProfile profile,boolean saveLocalProfile){
|
||||||
CachedProfile cp=getCachedProfile(username);
|
CachedProfile cp=getCachedProfile(username);
|
||||||
cp.profile=profile;
|
cp.profile=profile;
|
||||||
cp.expiryTime=TimeUtil.getUnixTimestampRandomDelay(CustomSkinLoader.config.cacheExpiry);
|
cp.expiryTime=TimeUtil.getUnixTimestamp(CustomSkinLoader.config.cacheExpiry);
|
||||||
if(!saveLocalProfile)
|
if(!saveLocalProfile)
|
||||||
return;
|
return;
|
||||||
saveLocalProfile(username,profile);
|
saveLocalProfile(username,profile);
|
||||||
}
|
}
|
||||||
|
public void putLoader(String username, Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>> loader) {
|
||||||
|
this.profileLoaders.putIfAbsent(username, new ConcurrentLinkedDeque<>());
|
||||||
|
this.profileLoaders.get(username).offerLast(loader);
|
||||||
|
}
|
||||||
|
|
||||||
private CachedProfile getCachedProfile(String username){
|
private CachedProfile getCachedProfile(String username){
|
||||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class UserProfile {
|
|||||||
this.capeUrl=url;
|
this.capeUrl=url;
|
||||||
return;
|
return;
|
||||||
case ELYTRA:
|
case ELYTRA:
|
||||||
this.capeUrl=url;
|
this.elytraUrl = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.io.OutputStream;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
@@ -26,7 +27,11 @@ public class HttpRequestUtil {
|
|||||||
public boolean loadContent = true;
|
public boolean loadContent = true;
|
||||||
public boolean checkPNG = false;
|
public boolean checkPNG = false;
|
||||||
|
|
||||||
public int cacheTime = 600;//-1=No Cache 0=Always Cache t=Default Cache Time(second)
|
/**
|
||||||
|
* Cache Time
|
||||||
|
* -1=No Cache 0=Always Cache t=Default Cache Time(second)
|
||||||
|
*/
|
||||||
|
public int cacheTime = 600;
|
||||||
public File cacheFile = null;//Default Cache File
|
public File cacheFile = null;//Default Cache File
|
||||||
|
|
||||||
public HttpRequest(String url) {
|
public HttpRequest(String url) {
|
||||||
@@ -87,14 +92,16 @@ public class HttpRequestUtil {
|
|||||||
|
|
||||||
public static HttpResponce makeHttpRequest(HttpRequest request, int redirectTime) {
|
public static HttpResponce makeHttpRequest(HttpRequest request, int redirectTime) {
|
||||||
try {
|
try {
|
||||||
if(request.url.contains("{ABORT}")){
|
//No url provided, try to load from special cache file
|
||||||
CustomSkinLoader.logger.info("ABORT tag found in url, request has been aborted.");
|
if (request.url == null || request.url.isEmpty()) {
|
||||||
return new HttpResponce();
|
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 + "'."));
|
CustomSkinLoader.logger.debug("Try to request '" + request.url + (request.userAgent == null ? "'." : "' with user agent '" + request.userAgent + "'."));
|
||||||
//Check Cache
|
//Check Cache
|
||||||
if (StringUtils.isNotEmpty(request.payload))
|
if (StringUtils.isNotEmpty(request.payload) || CustomSkinLoader.config.forceDisableCache) {
|
||||||
request.cacheTime = -1;//No Cache
|
request.cacheTime = -1;//No Cache
|
||||||
|
}
|
||||||
File cacheInfoFile = null;
|
File cacheInfoFile = null;
|
||||||
CacheInfo cacheInfo = new CacheInfo();
|
CacheInfo cacheInfo = new CacheInfo();
|
||||||
if (request.cacheFile == null && request.cacheTime >= 0) {
|
if (request.cacheFile == null && request.cacheTime >= 0) {
|
||||||
@@ -102,32 +109,38 @@ public class HttpRequestUtil {
|
|||||||
request.cacheFile = new File(CACHE_DIR, hash);
|
request.cacheFile = new File(CACHE_DIR, hash);
|
||||||
cacheInfoFile = new File(CACHE_DIR, hash + ".json");
|
cacheInfoFile = new File(CACHE_DIR, hash + ".json");
|
||||||
}
|
}
|
||||||
if (request.cacheTime == 0 && request.cacheFile.isFile())
|
//noinspection BulkFileAttributesRead
|
||||||
|
if (request.cacheTime == 0 && request.cacheFile.isFile()) {
|
||||||
return loadFromCache(request, new HttpResponce());
|
return loadFromCache(request, new HttpResponce());
|
||||||
|
}
|
||||||
if (cacheInfoFile != null && cacheInfoFile.isFile()) {
|
if (cacheInfoFile != null && cacheInfoFile.isFile()) {
|
||||||
String json = FileUtils.readFileToString(cacheInfoFile, "UTF-8");
|
String json = FileUtils.readFileToString(cacheInfoFile, "UTF-8");
|
||||||
if (StringUtils.isNotEmpty(json))
|
if (StringUtils.isNotEmpty(json)) {
|
||||||
cacheInfo = CustomSkinLoader.GSON.fromJson(json, CacheInfo.class);
|
cacheInfo = CustomSkinLoader.GSON.fromJson(json, CacheInfo.class);
|
||||||
if (cacheInfo == null)
|
}
|
||||||
|
if (cacheInfo == null) {
|
||||||
cacheInfo = new CacheInfo();
|
cacheInfo = new CacheInfo();
|
||||||
if (cacheInfo.expire >= TimeUtil.getCurrentUnixTimestamp())
|
}
|
||||||
|
if (cacheInfo.expire >= TimeUtil.getCurrentUnixTimestamp()) {
|
||||||
return loadFromCache(request, new HttpResponce(), cacheInfo.expire);
|
return loadFromCache(request, new HttpResponce(), cacheInfo.expire);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Init Connection
|
//Init Connection
|
||||||
URL rawUrl = new URL(request.url);
|
URL rawUrl = new URL(request.url);
|
||||||
URI uri = new URI(
|
URI uri = new URI(
|
||||||
rawUrl.getProtocol(),
|
rawUrl.getProtocol(),
|
||||||
rawUrl.getUserInfo(),
|
rawUrl.getUserInfo(),
|
||||||
rawUrl.getHost(),
|
rawUrl.getHost(),
|
||||||
rawUrl.getPort(),
|
rawUrl.getPort(),
|
||||||
rawUrl.getPath(),
|
rawUrl.getPath(),
|
||||||
rawUrl.getQuery(),
|
rawUrl.getQuery(),
|
||||||
rawUrl.getRef()
|
rawUrl.getRef()
|
||||||
);
|
);
|
||||||
String url = uri.toASCIIString();
|
String url = uri.toASCIIString();
|
||||||
if (!url.equalsIgnoreCase(request.url))
|
if (!url.equalsIgnoreCase(request.url)) {
|
||||||
CustomSkinLoader.logger.debug("Encoded URL: " + url);
|
CustomSkinLoader.logger.debug("Encoded URL: " + url);
|
||||||
|
}
|
||||||
HttpURLConnection c = (HttpURLConnection) (new URL(url)).openConnection();
|
HttpURLConnection c = (HttpURLConnection) (new URL(url)).openConnection();
|
||||||
c.setReadTimeout(1000 * 10);
|
c.setReadTimeout(1000 * 10);
|
||||||
c.setConnectTimeout(1000 * 10);
|
c.setConnectTimeout(1000 * 10);
|
||||||
@@ -136,13 +149,16 @@ public class HttpRequestUtil {
|
|||||||
c.setInstanceFollowRedirects(true);
|
c.setInstanceFollowRedirects(true);
|
||||||
|
|
||||||
//Make Connection
|
//Make Connection
|
||||||
if (cacheInfo.lastModified >= 0)
|
if (cacheInfo.lastModified >= 0) {
|
||||||
c.setIfModifiedSince(cacheInfo.lastModified);
|
c.setIfModifiedSince(cacheInfo.lastModified);
|
||||||
if (cacheInfo.etag != null)
|
}
|
||||||
|
if (cacheInfo.etag != null) {
|
||||||
c.setRequestProperty("If-None-Match", cacheInfo.etag);
|
c.setRequestProperty("If-None-Match", cacheInfo.etag);
|
||||||
|
}
|
||||||
c.setRequestProperty("Accept-Encoding", "gzip");
|
c.setRequestProperty("Accept-Encoding", "gzip");
|
||||||
if (request.userAgent != null)
|
if (request.userAgent != null) {
|
||||||
c.setRequestProperty("User-Agent", request.userAgent);
|
c.setRequestProperty("User-Agent", request.userAgent);
|
||||||
|
}
|
||||||
if (StringUtils.isNotEmpty(request.payload)) {
|
if (StringUtils.isNotEmpty(request.payload)) {
|
||||||
CustomSkinLoader.logger.info("Payload: " + request.payload);
|
CustomSkinLoader.logger.info("Payload: " + request.payload);
|
||||||
c.setRequestProperty("Content-Type", "application/json");
|
c.setRequestProperty("Content-Type", "application/json");
|
||||||
@@ -177,10 +193,12 @@ public class HttpRequestUtil {
|
|||||||
}
|
}
|
||||||
responce.success = true;
|
responce.success = true;
|
||||||
CustomSkinLoader.logger.debug("Successfully request (Response Code: " + res + " , Content Length: " + c.getContentLength() + ")");
|
CustomSkinLoader.logger.debug("Successfully request (Response Code: " + res + " , Content Length: " + c.getContentLength() + ")");
|
||||||
if (responce.responceCode == HttpURLConnection.HTTP_NOT_MODIFIED)
|
if (responce.responceCode == HttpURLConnection.HTTP_NOT_MODIFIED) {
|
||||||
return loadFromCache(request, responce);
|
return loadFromCache(request, responce);
|
||||||
if (responce.responceCode == HttpURLConnection.HTTP_NO_CONTENT)
|
}
|
||||||
|
if (responce.responceCode == HttpURLConnection.HTTP_NO_CONTENT) {
|
||||||
request.cacheTime = 3600;
|
request.cacheTime = 3600;
|
||||||
|
}
|
||||||
|
|
||||||
//Load Content
|
//Load Content
|
||||||
InputStream is = "gzip".equals(c.getContentEncoding()) ? new GZIPInputStream(c.getInputStream()) : c.getInputStream();
|
InputStream is = "gzip".equals(c.getContentEncoding()) ? new GZIPInputStream(c.getInputStream()) : c.getInputStream();
|
||||||
@@ -199,16 +217,18 @@ public class HttpRequestUtil {
|
|||||||
cacheInfo.expire = getExpire(c, request.cacheTime);
|
cacheInfo.expire = getExpire(c, request.cacheTime);
|
||||||
FileUtils.write(cacheInfoFile, CustomSkinLoader.GSON.toJson(cacheInfo), "UTF-8");
|
FileUtils.write(cacheInfoFile, CustomSkinLoader.GSON.toJson(cacheInfo), "UTF-8");
|
||||||
}
|
}
|
||||||
|
//noinspection BulkFileAttributesRead
|
||||||
CustomSkinLoader.logger.debug("Saved to cache (Length: " + request.cacheFile.length() + " , Path: '" + request.cacheFile.getAbsolutePath() + "' , Expire: " + cacheInfo.expire + ")");
|
CustomSkinLoader.logger.debug("Saved to cache (Length: " + request.cacheFile.length() + " , Path: '" + request.cacheFile.getAbsolutePath() + "' , Expire: " + cacheInfo.expire + ")");
|
||||||
}
|
}
|
||||||
if (!request.loadContent)
|
if (!request.loadContent) {
|
||||||
return responce;
|
return responce;
|
||||||
responce.content = new String(bytes, "UTF-8");
|
}
|
||||||
|
responce.content = new String(bytes, StandardCharsets.UTF_8);
|
||||||
CustomSkinLoader.logger.debug("Content: " + responce.content);
|
CustomSkinLoader.logger.debug("Content: " + responce.content);
|
||||||
return responce;
|
return responce;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CustomSkinLoader.logger.debug("Failed to request (Exception: " + e.toString() + ")");
|
CustomSkinLoader.logger.debug("Failed to request " + request.url + " (Exception: " + e + ")");
|
||||||
return loadFromCache(request, new HttpResponce());
|
return loadFromCache(request, new HttpResponce());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,13 +242,15 @@ public class HttpRequestUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static HttpResponce loadFromCache(HttpRequest request, HttpResponce responce, long expireTime) {
|
private static HttpResponce loadFromCache(HttpRequest request, HttpResponce responce, long expireTime) {
|
||||||
if (request.cacheFile == null || !request.cacheFile.isFile())
|
if (request.cacheFile == null || !request.cacheFile.isFile()) {
|
||||||
return responce;
|
return responce;
|
||||||
CustomSkinLoader.logger.debug("Cache file found (Length: " + request.cacheFile.length() + " , Path: '" + request.cacheFile.getAbsolutePath() + "' , Expire: " + expireTime + "')");
|
}
|
||||||
|
CustomSkinLoader.logger.debug("Cache file found (Length: " + request.cacheFile.length() + " , Path: '" + request.cacheFile.getAbsolutePath() + "' , Expire: " + expireTime + ")");
|
||||||
responce.fromCache = true;
|
responce.fromCache = true;
|
||||||
responce.success = true;
|
responce.success = true;
|
||||||
if (!request.loadContent)
|
if (!request.loadContent) {
|
||||||
return responce;
|
return responce;
|
||||||
|
}
|
||||||
|
|
||||||
CustomSkinLoader.logger.info("Try to load from cache '" + request.cacheFile.getAbsolutePath() + "'.");
|
CustomSkinLoader.logger.info("Try to load from cache '" + request.cacheFile.getAbsolutePath() + "'.");
|
||||||
try {
|
try {
|
||||||
@@ -236,7 +258,7 @@ public class HttpRequestUtil {
|
|||||||
CustomSkinLoader.logger.debug("Successfully load from cache");
|
CustomSkinLoader.logger.debug("Successfully load from cache");
|
||||||
CustomSkinLoader.logger.debug("Content: " + responce.content);
|
CustomSkinLoader.logger.debug("Content: " + responce.content);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
CustomSkinLoader.logger.debug("Failed to load from cache (Exception: " + e.toString() + ")");
|
CustomSkinLoader.logger.debug("Failed to load from cache (Exception: " + e + ")");
|
||||||
responce.success = false;
|
responce.success = false;
|
||||||
}
|
}
|
||||||
return responce;
|
return responce;
|
||||||
@@ -254,7 +276,6 @@ public class HttpRequestUtil {
|
|||||||
long expires = connection.getExpiration();
|
long expires = connection.getExpiration();
|
||||||
if (expires > 0)
|
if (expires > 0)
|
||||||
return expires / 1000;
|
return expires / 1000;
|
||||||
return TimeUtil.getUnixTimestampRandomDelay(cacheTime == 0 ? 86400 : cacheTime);
|
return TimeUtil.getUnixTimestampRandomDelay(cacheTime == 0 ? 2592000 : cacheTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,76 +8,100 @@ import org.apache.commons.io.FilenameUtils;
|
|||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
|
|
||||||
public class HttpTextureUtil {
|
public class HttpTextureUtil {
|
||||||
public static class HttpTextureInfo{
|
public static class HttpTextureInfo {
|
||||||
public String url="";
|
public String url = "";
|
||||||
public File cacheFile;
|
public File cacheFile;
|
||||||
public String hash;
|
public String hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String
|
private static final String
|
||||||
LEGACY_MARK="(LEGACY)",
|
LEGACY_MARK = "(LEGACY)",
|
||||||
LOCAL_MARK="(LOCAL)",
|
LOCAL_MARK = "(LOCAL)",
|
||||||
LOCAL_LEGACY_MARK="(LOCAL_LEGACY)";
|
LOCAL_LEGACY_MARK = "(LOCAL_LEGACY)",
|
||||||
|
BASE64_MARK = "(BASE64)";
|
||||||
public static File defaultCacheDir;
|
public static File defaultCacheDir;
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public static void cleanCacheDir(){
|
public static void cleanCacheDir() {
|
||||||
if(defaultCacheDir!=null){
|
if (defaultCacheDir != null) {
|
||||||
defaultCacheDir.delete();
|
defaultCacheDir.delete();
|
||||||
defaultCacheDir.mkdirs();
|
defaultCacheDir.mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static File getCacheDir(){
|
|
||||||
return defaultCacheDir==null?new File(MinecraftUtil.getMinecraftDataDir(),"assets/skins"):defaultCacheDir;
|
public static File getCacheDir() {
|
||||||
|
return defaultCacheDir == null ? new File(MinecraftUtil.getMinecraftDataDir(), "assets/skins") : defaultCacheDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl){
|
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl) {
|
||||||
HttpTextureInfo info=new HttpTextureInfo();
|
HttpTextureInfo info = new HttpTextureInfo();
|
||||||
if(fakeUrl.startsWith("http")){
|
if (fakeUrl.startsWith("http")) {
|
||||||
info.url=fakeUrl;
|
info.url = fakeUrl;
|
||||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
info.hash = FilenameUtils.getBaseName(fakeUrl);
|
||||||
info.cacheFile=getCacheFile(info.hash);
|
info.cacheFile = getCacheFile(info.hash);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
if(fakeUrl.startsWith(LOCAL_LEGACY_MARK)){
|
if (fakeUrl.startsWith(LOCAL_LEGACY_MARK)) {
|
||||||
fakeUrl=fakeUrl.replace(LOCAL_LEGACY_MARK, "");
|
fakeUrl = fakeUrl.replace(LOCAL_LEGACY_MARK, "");
|
||||||
String[] t=fakeUrl.split(",",2);
|
String[] t = fakeUrl.split(",", 2);
|
||||||
if(t.length!=2)
|
if (t.length != 2)
|
||||||
return info;
|
return info;
|
||||||
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,t[1]);
|
info.cacheFile = new File(CustomSkinLoader.DATA_DIR, t[1]);
|
||||||
info.hash=t[0];
|
info.hash = t[0];
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
if(fakeUrl.startsWith(LOCAL_MARK)){
|
if (fakeUrl.startsWith(LOCAL_MARK)) {
|
||||||
fakeUrl=fakeUrl.replace(LOCAL_MARK, "");
|
fakeUrl = fakeUrl.replace(LOCAL_MARK, "");
|
||||||
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,fakeUrl);
|
info.cacheFile = new File(CustomSkinLoader.DATA_DIR, fakeUrl);
|
||||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
info.hash = FilenameUtils.getBaseName(fakeUrl);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
if(fakeUrl.startsWith(LEGACY_MARK)){
|
if (fakeUrl.startsWith(LEGACY_MARK)) {
|
||||||
fakeUrl=fakeUrl.replace(LEGACY_MARK, "");
|
fakeUrl = fakeUrl.replace(LEGACY_MARK, "");
|
||||||
info.url=fakeUrl;
|
info.url = fakeUrl;
|
||||||
info.hash=DigestUtils.sha1Hex(info.url);
|
info.hash = DigestUtils.sha1Hex(info.url);
|
||||||
info.cacheFile = HttpRequestUtil.getCacheFile(info.hash);
|
info.cacheFile = HttpRequestUtil.getCacheFile(info.hash);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
//Base64 fake url format: `(BASE64)${hash}`
|
||||||
|
if (fakeUrl.startsWith(BASE64_MARK)) {
|
||||||
|
fakeUrl = fakeUrl.replace(BASE64_MARK, "");
|
||||||
|
info.hash = fakeUrl;
|
||||||
|
info.cacheFile = getCacheFile(info.hash);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLegacyFakeUrl(String url){
|
public static String getLegacyFakeUrl(String url) {
|
||||||
return LEGACY_MARK+url;
|
return LEGACY_MARK + url;
|
||||||
}
|
}
|
||||||
public static String getLocalFakeUrl(String path){
|
|
||||||
return LOCAL_MARK+path;
|
public static String getLocalFakeUrl(String path) {
|
||||||
|
return LOCAL_MARK + path;
|
||||||
}
|
}
|
||||||
public static String getLocalLegacyFakeUrl(String path,String hash){
|
|
||||||
return LOCAL_LEGACY_MARK+hash+","+path;
|
public static String getLocalLegacyFakeUrl(String path, String hash) {
|
||||||
|
return LOCAL_LEGACY_MARK + hash + "," + path;
|
||||||
}
|
}
|
||||||
public static String getHash(String url,long size,long lastModified){
|
|
||||||
return DigestUtils.sha1Hex(size+url+lastModified);
|
public static String getBase64FakeUrl(String hash) {
|
||||||
|
return BASE64_MARK + hash;
|
||||||
}
|
}
|
||||||
public static File getCacheFile(String hash){
|
|
||||||
return getCacheFile(defaultCacheDir,hash);
|
public static String getHash(String url, long size, long lastModified) {
|
||||||
|
return DigestUtils.sha1Hex(size + url + lastModified);
|
||||||
}
|
}
|
||||||
public static File getCacheFile(File cacheDir,String hash){
|
|
||||||
return new File(new File(cacheDir,hash.length()>2?hash.substring(0,2):"xx"), hash);
|
public static String getHash(byte[] bytes) {
|
||||||
|
return DigestUtils.sha256Hex(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getCacheFile(String hash) {
|
||||||
|
return getCacheFile(defaultCacheDir, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getCacheFile(File cacheDir, String hash) {
|
||||||
|
return new File(new File(cacheDir, hash.length() > 2 ? hash.substring(0, 2) : "xx"), hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,14 +5,19 @@ import java.net.InetAddress;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLSession;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class HttpUtil0 {
|
public class HttpUtil0 {
|
||||||
public static boolean isLocal(String url){
|
public static boolean isLocal(String url){
|
||||||
return url != null && !url.startsWith("http");
|
return url != null && !url.startsWith("http://") && !url.startsWith("https://");
|
||||||
}
|
}
|
||||||
|
|
||||||
//From: http://blog.csdn.net/xiyushiyi/article/details/46685387
|
//From: http://blog.csdn.net/xiyushiyi/article/details/46685387
|
||||||
|
|||||||
@@ -1,22 +1,26 @@
|
|||||||
package customskinloader.utils;
|
package customskinloader.utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Constructor;
|
import java.io.FileReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.IImageBuffer;
|
|
||||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
|
||||||
import net.minecraft.client.renderer.texture.SimpleTexture;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
import net.minecraft.client.resources.SkinManager;
|
import net.minecraft.client.resources.SkinManager;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.realms.RealmsSharedConstants;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,78 +39,40 @@ public class MinecraftUtil {
|
|||||||
public static SkinManager getSkinManager() {
|
public static SkinManager getSkinManager() {
|
||||||
return Minecraft.getMinecraft().getSkinManager();
|
return Minecraft.getMinecraft().getSkinManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean is_1_15_plus = false;
|
|
||||||
private static Constructor<?> constructor = null;
|
|
||||||
public static SimpleTexture createThreadDownloadImageData(File cacheFileIn, String imageUrlIn, ResourceLocation textureResourceLocation, IImageBuffer imageBufferIn, MinecraftProfileTexture.Type textureType) {
|
|
||||||
if (constructor == null) {
|
|
||||||
Class<?> c;
|
|
||||||
try {
|
|
||||||
c = Class.forName("net.minecraft.client.renderer.texture.ThreadDownloadImageData", false, MinecraftUtil.class.getClassLoader()); // Forge 1.13
|
|
||||||
} catch (ClassNotFoundException e1) {
|
|
||||||
try {
|
|
||||||
c = Class.forName("net.minecraft.client.renderer.texture.DownloadingTexture", false, MinecraftUtil.class.getClassLoader()); // Forge 1.14+
|
|
||||||
} catch (ClassNotFoundException e2) {
|
|
||||||
c = ThreadDownloadImageData.class; // Forge 1.12- or Fabric or Vanilla
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
constructor = c.getConstructor(File.class, String.class, ResourceLocation.class, boolean.class, Runnable.class); // For 1.15+
|
|
||||||
is_1_15_plus = true;
|
|
||||||
} catch (NoSuchMethodException e1) {
|
|
||||||
try {
|
|
||||||
constructor = c.getConstructor(File.class, String.class, ResourceLocation.class, IImageBuffer.class); // For 1.15-
|
|
||||||
} catch (NoSuchMethodException e2) {
|
|
||||||
throw new RuntimeException(e2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (is_1_15_plus) {
|
|
||||||
return (SimpleTexture) constructor.newInstance(cacheFileIn, imageUrlIn, textureResourceLocation, textureType == MinecraftProfileTexture.Type.SKIN, imageBufferIn);
|
|
||||||
} else {
|
|
||||||
return (SimpleTexture) constructor.newInstance(cacheFileIn, imageUrlIn, textureResourceLocation, imageBufferIn);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static ArrayList<String> minecraftVersion = new ArrayList<String>();
|
|
||||||
private static String minecraftMainVersion = null;
|
private static String minecraftMainVersion = null;
|
||||||
private final static Pattern MINECRAFT_VERSION_PATTERN = Pattern.compile(".*?(\\d+\\.\\d+[\\.]?\\d*).*?");
|
|
||||||
|
|
||||||
public static ArrayList<String> getMinecraftVersions() {
|
|
||||||
if (minecraftVersion != null && !minecraftVersion.isEmpty())
|
|
||||||
return minecraftVersion;
|
|
||||||
testProbe();
|
|
||||||
return minecraftVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMinecraftVersionText() {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (String version : getMinecraftVersions())
|
|
||||||
sb.append(version).append(" ");
|
|
||||||
return StringUtils.trim(sb.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMinecraftMainVersion() {
|
public static String getMinecraftMainVersion() {
|
||||||
if (minecraftMainVersion != null)
|
//Check if cached version found
|
||||||
|
if (minecraftMainVersion != null) {
|
||||||
return minecraftMainVersion;
|
return minecraftMainVersion;
|
||||||
for (String version : getMinecraftVersions()) {
|
|
||||||
Matcher m = null;
|
|
||||||
try {
|
|
||||||
m = MINECRAFT_VERSION_PATTERN.matcher(version);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (m == null || !m.matches())
|
|
||||||
continue;
|
|
||||||
minecraftMainVersion = m.group(m.groupCount());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return minecraftMainVersion;
|
|
||||||
|
//version.json can be found in 1.14+
|
||||||
|
URL versionFile = MinecraftUtil.class.getResource("/version.json");
|
||||||
|
if (versionFile != null) {
|
||||||
|
try (
|
||||||
|
InputStream is = versionFile.openStream();
|
||||||
|
InputStreamReader isr = new InputStreamReader(is)
|
||||||
|
) {
|
||||||
|
JsonObject obj = new JsonParser().parse(isr).getAsJsonObject();
|
||||||
|
minecraftMainVersion = obj.get("name").getAsString();
|
||||||
|
return minecraftMainVersion;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//RealmsSharedConstants.VERSION_STRING is available in 1.16-
|
||||||
|
try {
|
||||||
|
Class<?> realmsSharedConstants = Class.forName("net.minecraft.realms.RealmsSharedConstants");
|
||||||
|
MethodHandle mh = MethodHandles.publicLookup().findStaticGetter(realmsSharedConstants, "VERSION_STRING", String.class);
|
||||||
|
minecraftMainVersion = (String) mh.invoke();
|
||||||
|
return minecraftMainVersion;
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
//No version can be found
|
||||||
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
// (domain|ip)(:port)
|
// (domain|ip)(:port)
|
||||||
@@ -126,49 +92,6 @@ public class MinecraftUtil {
|
|||||||
return HttpUtil0.isLanServer(getStandardServerAddress());
|
return HttpUtil0.isLanServer(getStandardServerAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCurrentUsername() {
|
|
||||||
return Minecraft.getMinecraft().getSession().getProfile().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static Pattern MINECRAFT_CORE_FILE_PATTERN = Pattern.compile("^(.*?)/versions/([^\\/\\\\]*?)/([^\\/\\\\]*?).jar$");
|
|
||||||
|
|
||||||
private static void testProbe() {
|
|
||||||
minecraftVersion.clear();
|
|
||||||
URL urls[] = JavaUtil.getClasspath();
|
|
||||||
for (URL url : urls) {
|
|
||||||
Matcher m = null;
|
|
||||||
try {
|
|
||||||
m = MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(), "UTF-8"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (m == null || !m.matches())
|
|
||||||
continue;
|
|
||||||
minecraftVersion.add(m.group(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isCoreFile(URL url) {
|
|
||||||
return regexMatch(url, MINECRAFT_CORE_FILE_PATTERN);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static Pattern LIBRARY_FILE_PATTERN = Pattern.compile("^(.*?)/libraries/(.*?)/([^\\/\\\\]*?).jar$");
|
|
||||||
|
|
||||||
public static boolean isLibraryFile(URL url) {
|
|
||||||
return regexMatch(url, LIBRARY_FILE_PATTERN);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean regexMatch(URL url, Pattern p) {
|
|
||||||
Matcher m;
|
|
||||||
try {
|
|
||||||
m = p.matcher(URLDecoder.decode(url.getPath(), "UTF-8"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return m.matches();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getCredential(GameProfile profile) {
|
public static String getCredential(GameProfile profile) {
|
||||||
return (profile == null || profile.hashCode() == 0) ? null :
|
return (profile == null || profile.hashCode() == 0) ? null :
|
||||||
(profile.getId() == null ? profile.getName() : String.format("%s-%s", profile.getName(), profile.getId()));
|
(profile.getId() == null ? profile.getName() : String.format("%s-%s", profile.getName(), profile.getId()));
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
package net.minecraft.client.renderer.texture;
|
package net.minecraft.client.renderer.texture;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty stack for NativeImage
|
* Empty stack for NativeImage
|
||||||
*/
|
*/
|
||||||
public class NativeImage {
|
public class NativeImage {
|
||||||
|
public static NativeImage func_195713_a(InputStream inputStreamIn) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public NativeImage(int p_i48122_1_, int p_i48122_2_, boolean p_i48122_3_) {
|
public NativeImage(int p_i48122_1_, int p_i48122_2_, boolean p_i48122_3_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.minecraft.client.resources;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
// this class shouldn't be created by ASM because of modlauncher issue.
|
||||||
|
public interface IResource {
|
||||||
|
InputStream getInputStream();
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package net.minecraft.client.resources;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
// this class shouldn't be created by ASM because of modlauncher issue.
|
||||||
|
public interface IResourceManager {
|
||||||
|
IResource getResource(ResourceLocation location) throws IOException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package net.minecraft.resources;
|
||||||
|
|
||||||
|
// exclude
|
||||||
|
public interface IResource {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package net.minecraft.resources;
|
||||||
|
|
||||||
|
// exclude
|
||||||
|
public interface IResourceManager {
|
||||||
|
|
||||||
|
}
|
||||||
+42
-22
@@ -1,24 +1,40 @@
|
|||||||
customskinloader/fake/itf/IFakeTextureManager_1 customskinloader/fake/itf/IFakeTextureManager_1
|
customskinloader/fake/itf/IFakeIResource$V1 customskinloader/fake/itf/IFakeIResource$V1
|
||||||
|
func_199027_b ()Ljava/io/InputStream; method_14482
|
||||||
|
customskinloader/fake/itf/IFakeIResource$V2 customskinloader/fake/itf/IFakeIResource$V2
|
||||||
|
open ()Ljava/io/InputStream; method_14482
|
||||||
|
customskinloader/fake/itf/IFakeIResourceManager customskinloader/fake/itf/IFakeIResourceManager
|
||||||
|
func_199002_a (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/resources/IResource; method_14486
|
||||||
|
getResource (Lnet/minecraft/util/ResourceLocation;)Ljava/util/Optional; method_14486
|
||||||
|
customskinloader/fake/itf/IFakeMinecraft customskinloader/fake/itf/IFakeMinecraft
|
||||||
|
func_195551_G ()Lnet/minecraft/resources/IResourceManager; method_1478
|
||||||
|
customskinloader/fake/itf/IFakeTextureManager$V1 customskinloader/fake/itf/IFakeTextureManager$V1
|
||||||
func_229263_a_ (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/Texture;)Z method_4616
|
func_229263_a_ (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/Texture;)Z method_4616
|
||||||
func_229267_b_ (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/texture/Texture; method_4619
|
func_229267_b_ (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/texture/Texture; method_4619
|
||||||
customskinloader/fake/itf/IFakeTextureManager_2 customskinloader/fake/itf/IFakeTextureManager_2
|
getTexture (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/Texture;)Lnet/minecraft/client/renderer/texture/Texture; method_34590
|
||||||
|
customskinloader/fake/itf/IFakeTextureManager$V2 customskinloader/fake/itf/IFakeTextureManager$V2
|
||||||
func_229263_a_ (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/Texture;)V method_4616
|
func_229263_a_ (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/Texture;)V method_4616
|
||||||
|
net/minecraft/client/Minecraft net/minecraft/class_310
|
||||||
|
gameDir field_1697
|
||||||
|
addScheduledTask (Ljava/lang/Runnable;)Lcom/google/common/util/concurrent/ListenableFuture; func_152344_a
|
||||||
|
getCurrentServerData ()Lnet/minecraft/client/multiplayer/ServerData; method_1558
|
||||||
|
getMinecraft ()Lnet/minecraft/client/Minecraft; method_1551
|
||||||
|
getResourceManager ()Lnet/minecraft/client/resources/IResourceManager; method_1478
|
||||||
|
getSessionService ()Lcom/mojang/authlib/minecraft/MinecraftSessionService; method_1495
|
||||||
|
getSkinManager ()Lnet/minecraft/client/resources/SkinManager; method_1582
|
||||||
|
getTextureManager ()Lnet/minecraft/client/renderer/texture/TextureManager; method_1531
|
||||||
net/minecraft/client/gui/GuiPlayerTabOverlay net/minecraft/class_355
|
net/minecraft/client/gui/GuiPlayerTabOverlay net/minecraft/class_355
|
||||||
net/minecraft/client/gui/spectator/PlayerMenuObject net/minecraft/class_530
|
net/minecraft/client/gui/spectator/PlayerMenuObject net/minecraft/class_530
|
||||||
net/minecraft/client/Minecraft net/minecraft/class_310
|
|
||||||
field_71412_D field_1697
|
|
||||||
func_110432_I ()Lnet/minecraft/util/Session; method_1548
|
|
||||||
func_110434_K ()Lnet/minecraft/client/renderer/texture/TextureManager; method_1531
|
|
||||||
func_147104_D ()Lnet/minecraft/client/multiplayer/ServerData; method_1558
|
|
||||||
func_152342_ad ()Lnet/minecraft/client/resources/SkinManager; method_1582
|
|
||||||
func_152347_ac ()Lcom/mojang/authlib/minecraft/MinecraftSessionService; method_1495
|
|
||||||
func_71410_x ()Lnet/minecraft/client/Minecraft; method_1551
|
|
||||||
net/minecraft/client/multiplayer/ServerData net/minecraft/class_642
|
net/minecraft/client/multiplayer/ServerData net/minecraft/class_642
|
||||||
field_78845_b field_3761
|
serverIP field_3761
|
||||||
|
net/minecraft/client/renderer/RenderType net/minecraft/class_1921
|
||||||
|
func_228644_e_ (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/RenderType; method_23580
|
||||||
net/minecraft/client/renderer/IImageBuffer net/minecraft/class_760
|
net/minecraft/client/renderer/IImageBuffer net/minecraft/class_760
|
||||||
func_152634_a ()V method_3238
|
|
||||||
func_195786_a (Lnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/NativeImage; method_3237
|
func_195786_a (Lnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/NativeImage; method_3237
|
||||||
|
parseUserSkin (Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage; func_78432_a
|
||||||
|
skinAvailable ()V method_3238
|
||||||
net/minecraft/client/renderer/ThreadDownloadImageData net/minecraft/class_1046
|
net/minecraft/client/renderer/ThreadDownloadImageData net/minecraft/class_1046
|
||||||
|
net/minecraft/client/renderer/entity/RenderPlayer net/minecraft/class_1007
|
||||||
|
net/minecraft/client/renderer/entity/layers/LayerCape net/minecraft/class_972
|
||||||
net/minecraft/client/renderer/texture/DownloadingTexture net/minecraft/class_1046
|
net/minecraft/client/renderer/texture/DownloadingTexture net/minecraft/class_1046
|
||||||
net/minecraft/client/renderer/texture/ITextureObject net/minecraft/class_1062
|
net/minecraft/client/renderer/texture/ITextureObject net/minecraft/class_1062
|
||||||
net/minecraft/client/renderer/texture/NativeImage net/minecraft/class_1011
|
net/minecraft/client/renderer/texture/NativeImage net/minecraft/class_1011
|
||||||
@@ -27,24 +43,28 @@ net/minecraft/client/renderer/texture/NativeImage net/minecraft/class_1011
|
|||||||
func_195702_a ()I method_4307
|
func_195702_a ()I method_4307
|
||||||
func_195703_a (Lnet/minecraft/client/renderer/texture/NativeImage;)V method_4317
|
func_195703_a (Lnet/minecraft/client/renderer/texture/NativeImage;)V method_4317
|
||||||
func_195709_a (II)I method_4315
|
func_195709_a (II)I method_4315
|
||||||
|
func_195713_a (Ljava/io/InputStream;)Lnet/minecraft/client/renderer/texture/NativeImage; method_4309
|
||||||
func_195714_b ()I method_4323
|
func_195714_b ()I method_4323
|
||||||
func_195715_a (IIIII)V method_4326
|
func_195715_a (IIIII)V method_4326
|
||||||
net/minecraft/client/renderer/texture/SimpleTexture net/minecraft/class_1049
|
net/minecraft/client/renderer/texture/SimpleTexture net/minecraft/class_1049
|
||||||
net/minecraft/client/renderer/texture/Texture net/minecraft/class_1044
|
net/minecraft/client/renderer/texture/Texture net/minecraft/class_1044
|
||||||
net/minecraft/client/renderer/texture/TextureManager net/minecraft/class_1060
|
net/minecraft/client/renderer/texture/TextureManager net/minecraft/class_1060
|
||||||
func_110579_a (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/ITextureObject;)Z method_4616
|
getTexture (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/texture/ITextureObject; method_4619
|
||||||
func_110581_b (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/texture/ITextureObject; method_4619
|
loadTexture (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/ITextureObject;)Z method_4616
|
||||||
net/minecraft/client/renderer/texture/ThreadDownloadImageData net/minecraft/class_1046
|
net/minecraft/client/renderer/texture/ThreadDownloadImageData net/minecraft/class_1046
|
||||||
net/minecraft/client/resources/DefaultPlayerSkin net/minecraft/class_1068
|
net/minecraft/client/resources/DefaultPlayerSkin net/minecraft/class_1068
|
||||||
func_177334_a (Ljava/util/UUID;)Lnet/minecraft/util/ResourceLocation; method_4648
|
getDefaultSkin (Ljava/util/UUID;)Lnet/minecraft/util/ResourceLocation; method_4648
|
||||||
func_177335_a ()Lnet/minecraft/util/ResourceLocation; method_4649
|
getDefaultSkinLegacy ()Lnet/minecraft/util/ResourceLocation; method_4649
|
||||||
|
net/minecraft/client/resources/IResource net/minecraft/class_3298
|
||||||
|
getInputStream ()Ljava/io/InputStream; method_14482
|
||||||
|
net/minecraft/client/resources/IResourceManager net/minecraft/class_3300
|
||||||
|
getResource (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/resources/IResource; method_14486
|
||||||
net/minecraft/client/resources/SkinManager net/minecraft/class_1071
|
net/minecraft/client/resources/SkinManager net/minecraft/class_1071
|
||||||
func_152790_a (Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V method_4652
|
loadProfileTextures (Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V method_4652
|
||||||
net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/class_1071$class_1072
|
net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/class_1071$class_1072
|
||||||
func_180521_a (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V onSkinTextureAvailable
|
skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V onSkinTextureAvailable
|
||||||
net/minecraft/tileentity/TileEntitySkull net/minecraft/class_2631
|
net/minecraft/resources/IResource net/minecraft/class_3298
|
||||||
|
net/minecraft/resources/IResourceManager net/minecraft/class_3300
|
||||||
net/minecraft/util/ResourceLocation net/minecraft/class_2960
|
net/minecraft/util/ResourceLocation net/minecraft/class_2960
|
||||||
net/minecraft/util/Session net/minecraft/class_320
|
|
||||||
func_148256_e ()Lcom/mojang/authlib/GameProfile; method_1677
|
|
||||||
net/minecraft/util/StringUtils net/minecraft/class_3544
|
net/minecraft/util/StringUtils net/minecraft/class_3544
|
||||||
func_76338_a (Ljava/lang/String;)Ljava/lang/String; method_15440
|
stripControlCodes (Ljava/lang/String;)Ljava/lang/String; method_15440
|
||||||
+54
-112
@@ -1,135 +1,77 @@
|
|||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
|
||||||
apply plugin: 'org.spongepowered.mixin'
|
|
||||||
|
|
||||||
ext.configFile = file "build.properties"
|
|
||||||
configFile.withReader {
|
|
||||||
def prop = new Properties()
|
|
||||||
prop.load(it)
|
|
||||||
project.ext.config = new ConfigSlurper().parse prop
|
|
||||||
}
|
|
||||||
apply from: rootProject.file("BuildScripts/version.gradle")
|
|
||||||
|
|
||||||
version = getCSLVersion()
|
|
||||||
group = "customskinloader"
|
|
||||||
archivesBaseName = "CustomSkinLoader_Fabric"
|
|
||||||
ext.shortVersion = getShortVersion()
|
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = 1.8
|
|
||||||
compileJava {
|
|
||||||
sourceCompatibility = targetCompatibility = 1.8
|
|
||||||
}
|
|
||||||
|
|
||||||
minecraft {
|
|
||||||
version = config.forge_mc_version + "-" + config.forge_version
|
|
||||||
runDir = "run"
|
|
||||||
mappings = config.mappings_version
|
|
||||||
|
|
||||||
replace '@MOD_VERSION@', rootProject.ext.config.version
|
|
||||||
replace '@MOD_FULL_VERSION@', project.version
|
|
||||||
replaceIn 'CustomSkinLoader.java'
|
|
||||||
}
|
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
exclude 'customskinloader/tweaker/**'
|
exclude 'customskinloader/tweaker/**'
|
||||||
|
exclude 'net/minecraft/client/renderer/RenderType.class'
|
||||||
exclude 'net/minecraft/client/renderer/texture/**'
|
exclude 'net/minecraft/client/renderer/texture/**'
|
||||||
|
exclude 'net/minecraft/client/resources/**'
|
||||||
|
exclude 'net/minecraft/resources/**'
|
||||||
|
exclude 'Profile.json'
|
||||||
|
}
|
||||||
|
sourceJar {
|
||||||
|
exclude 'customskinloader/tweaker/**'
|
||||||
|
exclude 'net/**'
|
||||||
|
exclude 'Profile.json'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
name = "sponge"
|
name = "fabric"
|
||||||
url = "https://repo.spongepowered.org/maven"
|
url = "https://maven.fabricmc.net/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.spongepowered:mixin:0.8'
|
// This is the minimum version number that the mod should dependent in the development environment.
|
||||||
|
implementation "net.fabricmc:fabric-loader:0.12.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin {
|
import customskinloader.gradle.util.RemapUtil
|
||||||
add sourceSets.main, "mixins.customskinloader.refmap.json"
|
import customskinloader.gradle.util.SourceUtil
|
||||||
reobfSrgFile = "mixin.srg"
|
import groovy.json.JsonSlurper
|
||||||
reobfNotchSrgFile = "mixin.srg"
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
SourceUtil.addDependencies project, project(":Common"), project(":Vanilla/Common")
|
||||||
main {
|
RemapUtil.remapSources project
|
||||||
java {
|
|
||||||
//Common
|
// Resolve snapshot versions
|
||||||
srcDir "${rootDir}/Common/source"
|
tasks.publishModrinth.doFirst {
|
||||||
//Vanilla
|
def snapshot = []
|
||||||
srcDir "${rootDir}/Vanilla/source"
|
gameVersions.groupBy { v -> v.endsWith("-Snapshot") }.with {
|
||||||
//Fabric
|
this.tasks.publishModrinth.gameVersions = it[false]
|
||||||
srcDir "source"
|
snapshot = it[true]
|
||||||
}
|
|
||||||
resources {
|
|
||||||
//Common
|
|
||||||
srcDir "${rootDir}/Common/resource"
|
|
||||||
exclude "Profile.json"
|
|
||||||
//Fabric
|
|
||||||
srcDir "resource"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
// The CustomSkinLoader Fabric edition should support all Minecraft snapshot edition.
|
||||||
expand([
|
def jsonSlurper = new JsonSlurper()
|
||||||
modVersion : rootProject.ext.config.version,
|
def officialVersionList = [] as Set
|
||||||
modFullVersion : project.version,
|
plugins.withId "net.minecraftforge.gradle.forge", { plugin ->
|
||||||
modShortFullVersion: shortVersion,
|
def currentRelease = null
|
||||||
mcVersion : config.minecraft_version,
|
// Get version manifest json.
|
||||||
mcFullVersions : config.minecraft_full_versions,
|
// https://github.com/MinecraftForge/ForgeGradle/blob/fc67182a61926f0bdb0d12da5fba7f4322f64d86/src/main/java/net/minecraftforge/gradle/common/BasePlugin.java#L229
|
||||||
forgeVersion : config.forge_version,
|
jsonSlurper.parse(plugin.cacheFile("McManifest.json")).versions.each { version ->
|
||||||
gitVersion : System.getenv("CIRCLE_SHA1"),
|
if (version.type == "snapshot") {
|
||||||
buildUrl : System.getenv("CIRCLE_BUILD_URL"),
|
// If the first version is a snapshot, assume the target release version is the same as the assets version.
|
||||||
releaseTime : new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
if (currentRelease == null) {
|
||||||
])
|
currentRelease = jsonSlurper.parse(new URL(version.url)).assets.with {
|
||||||
}
|
it.toString().split($/\./$).with { "${it[0]}.${it[1]}" }
|
||||||
|
}
|
||||||
apply from: rootProject.file("BuildScripts/remap.gradle")
|
}
|
||||||
task afterBuild {
|
} else if (version.type == "release") {
|
||||||
doLast {
|
currentRelease = version.id.with {
|
||||||
//renameSrgJar
|
it.toString().split($/\./$).with { "${it[0]}.${it[1]}" }
|
||||||
def file0 = file("build/libs/${archivesBaseName}-${version}.jar")
|
}
|
||||||
def file1 = file("build/libs/${archivesBaseName}-${version}-srg.jar")
|
} else {
|
||||||
file0.renameTo(file1)
|
// We do not care about other types.
|
||||||
|
return
|
||||||
//reobfSrgToNotch
|
}
|
||||||
reobfSrgToNotch()
|
if (snapshot.contains("${currentRelease}-Snapshot".toString())) {
|
||||||
|
officialVersionList << version.id
|
||||||
//copyBuildFile
|
|
||||||
copy {
|
|
||||||
from "build/libs"
|
|
||||||
into "${rootDir}/build/libs"
|
|
||||||
include "**/*.jar"
|
|
||||||
exclude "**/*-srg.jar"
|
|
||||||
exclude "**/*-dev.jar"
|
|
||||||
exclude "**/*-sources.jar"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
build.finalizedBy afterBuild
|
|
||||||
|
|
||||||
|
|
||||||
apply plugin: 'maven-publish'
|
|
||||||
publishing {
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
name = "GitHubPackages"
|
|
||||||
url = uri("https://maven.pkg.github.com/xfl03/MCCustomSkinLoader")
|
|
||||||
credentials {
|
|
||||||
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
|
|
||||||
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
publications {
|
jsonSlurper.parse(new URL("https://meta.fabricmc.net/v2/versions/game")).each { version ->
|
||||||
gpr(MavenPublication) {
|
// Exclude experimental editions which is not support in Modrinth.
|
||||||
groupId 'customskinloader'
|
if (!version.stable && officialVersionList.contains(version.version)) {
|
||||||
artifactId project.archivesBaseName
|
gameVersions << version.version.replace(" ", "-").replace("Pre-Release-", "pre") // Fix the id of the earlier preview versions of 1.14.
|
||||||
from(components.java)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tasks.withType(PublishToMavenRepository) {
|
|
||||||
onlyIf { System.getenv("GITHUB_TOKEN") != null }
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
minecraft_version=1.14
|
minecraft_version=1.14
|
||||||
minecraft_full_versions=1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1
|
minecraft_full_versions=1.14-Snapshot,1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15-Snapshot,1.15,1.15.1,1.15.2,1.16-Snapshot,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17-Snapshot,1.17,1.17.1,1.18-Snapshot,1.18,1.18.1,1.18.2,1.19-Snapshot,1.19,1.19.1,1.19.2
|
||||||
|
java_full_versions=8,9,10,11,12,13,14,15,16,17,18
|
||||||
#forge gradle needs forge version
|
#forge gradle needs forge version
|
||||||
forge_mc_version=1.12.2
|
forge_mc_version=1.12.2
|
||||||
forge_version=14.23.5.2768
|
forge_version=14.23.5.2768
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
CL: com/mojang/blaze3d/matrix/MatrixStack net/minecraft/class_4587
|
|
||||||
CL: net/minecraft/client/entity/AbstractClientPlayer net/minecraft/class_742
|
|
||||||
CL: net/minecraft/client/gui/GuiPlayerTabOverlay net/minecraft/class_355
|
|
||||||
CL: net/minecraft/client/Minecraft net/minecraft/class_310
|
|
||||||
CL: net/minecraft/client/renderer/ThreadDownloadImageData net/minecraft/class_1046
|
|
||||||
CL: net/minecraft/client/renderer/texture/NativeImage net/minecraft/class_1011
|
|
||||||
CL: net/minecraft/client/renderer/texture/TextureManager net/minecraft/class_1060
|
|
||||||
CL: net/minecraft/client/resources/SkinManager net/minecraft/class_1071
|
|
||||||
CL: net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/class_1071$class_1072
|
|
||||||
CL: net/minecraft/scoreboard/ScoreObjective net/minecraft/class_266
|
|
||||||
CL: net/minecraft/scoreboard/Scoreboard net/minecraft/class_269
|
|
||||||
CL: net/minecraft/tileentity/TileEntitySkull net/minecraft/class_2631
|
|
||||||
CL: net/minecraft/util/ResourceLocation net/minecraft/class_2960
|
|
||||||
FD: net/minecraft/client/renderer/ThreadDownloadImageData/processTask net/minecraft/class_1046/field_20843
|
|
||||||
MD: net/minecraft/client/entity/AbstractClientPlayer/getDownloadImageSkin (Lnet/minecraft/util/ResourceLocation;Ljava/lang/String;)Lnet/minecraft/client/renderer/ThreadDownloadImageData; net/minecraft/class_742/method_3120 (Lnet/minecraft/class_2960;Ljava/lang/String;)Lnet/minecraft/class_1046;
|
|
||||||
MD: net/minecraft/client/entity/AbstractClientPlayer/getLocationSkin (Ljava/lang/String;)Lnet/minecraft/util/ResourceLocation; net/minecraft/class_742/method_3124 (Ljava/lang/String;)Lnet/minecraft/class_2960;
|
|
||||||
MD: net/minecraft/client/gui/GuiPlayerTabOverlay/renderPlayerlist (ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V net/minecraft/class_355/method_1919 (ILnet/minecraft/class_269;Lnet/minecraft/class_266;)V
|
|
||||||
MD: net/minecraft/client/gui/GuiPlayerTabOverlay/renderPlayerlist (Lcom/mojang/blaze3d/matrix/MatrixStack;ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V net/minecraft/class_355/method_1919 (Lnet/minecraft/class_4587;ILnet/minecraft/class_269;Lnet/minecraft/class_266;)V
|
|
||||||
MD: net/minecraft/client/Minecraft/isIntegratedServerRunning ()Z net/minecraft/class_310/method_1542 ()Z
|
|
||||||
MD: net/minecraft/client/renderer/ThreadDownloadImageData/loadTexture (Ljava/io/InputStream;)Lnet/minecraft/client/renderer/texture/NativeImage; net/minecraft/class_1046/method_22795 (Ljava/io/InputStream;)Lnet/minecraft/class_1011;
|
|
||||||
MD: net/minecraft/client/renderer/ThreadDownloadImageData/processLegacySkin (Lnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/NativeImage; net/minecraft/class_1046/method_22798 (Lnet/minecraft/class_1011;)Lnet/minecraft/class_1011;
|
|
||||||
MD: net/minecraft/client/resources/SkinManager/loadProfileTextures (Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V net/minecraft/class_1071/method_4652 (Lcom/mojang/authlib/GameProfile;Lnet/minecraft/class_1071$class_1072;Z)V
|
|
||||||
MD: net/minecraft/client/resources/SkinManager/loadSkin (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation; net/minecraft/class_1071/method_4651 (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/class_1071$class_1072;)Lnet/minecraft/class_2960;
|
|
||||||
MD: net/minecraft/client/resources/SkinManager/loadSkinFromCache (Lcom/mojang/authlib/GameProfile;)Ljava/util/Map; net/minecraft/class_1071/method_4654 (Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;
|
|
||||||
MD: net/minecraft/tileentity/TileEntitySkull/updateGameProfile (Lcom/mojang/authlib/GameProfile;)Lcom/mojang/authlib/GameProfile; net/minecraft/class_2631/method_11335 (Lcom/mojang/authlib/GameProfile;)Lcom/mojang/authlib/GameProfile;
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
com/mojang/blaze3d/matrix/MatrixStack net/minecraft/class_4587
|
||||||
|
net/minecraft/client/Minecraft net/minecraft/class_310
|
||||||
|
isIntegratedServerRunning ()Z method_1542
|
||||||
|
net/minecraft/client/entity/AbstractClientPlayer net/minecraft/class_742
|
||||||
|
getDownloadImageSkin (Lnet/minecraft/util/ResourceLocation;Ljava/lang/String;)Lnet/minecraft/client/renderer/ThreadDownloadImageData; method_3120
|
||||||
|
getLocationSkin (Ljava/lang/String;)Lnet/minecraft/util/ResourceLocation; method_3124
|
||||||
|
net/minecraft/client/gui/GuiPlayerTabOverlay net/minecraft/class_355
|
||||||
|
renderPlayerlist (ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V method_1919
|
||||||
|
renderPlayerlist (Lcom/mojang/blaze3d/matrix/MatrixStack;ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V method_1919
|
||||||
|
net/minecraft/client/model/ModelRenderer net/minecraft/class_630
|
||||||
|
net/minecraft/client/renderer/IRenderTypeBuffer net/minecraft/class_4597
|
||||||
|
net/minecraft/client/renderer/RenderType net/minecraft/class_1921
|
||||||
|
getEntitySolid (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/RenderType; method_23572
|
||||||
|
net/minecraft/client/renderer/ThreadDownloadImageData net/minecraft/class_1046
|
||||||
|
bufferedImage field_110560_d
|
||||||
|
textureUploaded field_5215
|
||||||
|
processTask field_20843
|
||||||
|
loadTexture (Ljava/io/InputStream;)Lnet/minecraft/client/renderer/texture/NativeImage; method_22795
|
||||||
|
processLegacySkin (Lnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/NativeImage; method_22798
|
||||||
|
net/minecraft/client/renderer/entity/RenderPlayer net/minecraft/class_1007
|
||||||
|
renderItem (Lcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;ILnet/minecraft/client/entity/AbstractClientPlayer;Lnet/minecraft/client/model/ModelRenderer;Lnet/minecraft/client/model/ModelRenderer;)V method_23205
|
||||||
|
renderItem (Lcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;Lnet/minecraft/client/entity/AbstractClientPlayer;Lnet/minecraft/client/model/ModelRenderer;Lnet/minecraft/client/model/ModelRenderer;)V method_23205
|
||||||
|
net/minecraft/client/renderer/entity/layers/LayerCape net/minecraft/class_972
|
||||||
|
doRenderLayer (Lcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;ILnet/minecraft/client/entity/AbstractClientPlayer;FFFFFF)V method_4177
|
||||||
|
doRenderLayer (Lcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;ILnet/minecraft/client/entity/AbstractClientPlayer;FFFFFFF)V method_4177
|
||||||
|
net/minecraft/client/renderer/texture/NativeImage net/minecraft/class_1011
|
||||||
|
net/minecraft/client/renderer/texture/TextureManager net/minecraft/class_1060
|
||||||
|
net/minecraft/client/resources/SkinManager net/minecraft/class_1071
|
||||||
|
loadProfileTextures (Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V method_4652
|
||||||
|
loadSkin (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation; method_4651
|
||||||
|
loadSkinFromCache (Lcom/mojang/authlib/GameProfile;)Ljava/util/Map; method_4654
|
||||||
|
net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/class_1071$class_1072
|
||||||
|
net/minecraft/scoreboard/ScoreObjective net/minecraft/class_266
|
||||||
|
net/minecraft/scoreboard/Scoreboard net/minecraft/class_269
|
||||||
|
net/minecraft/util/ResourceLocation net/minecraft/class_2960
|
||||||
@@ -15,9 +15,6 @@
|
|||||||
|
|
||||||
"environment": "client",
|
"environment": "client",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
{
|
"mixins.customskinloader.json"
|
||||||
"config": "mixins.customskinloader.json",
|
|
||||||
"environment": "client"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,21 @@
|
|||||||
{
|
{
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
|
"mixinPriority": 1010,
|
||||||
"package": "customskinloader.mixin",
|
"package": "customskinloader.mixin",
|
||||||
"client": [
|
"client": [
|
||||||
"MixinGuiPlayerTabOverlay",
|
"MixinGuiPlayerTabOverlay",
|
||||||
|
"MixinIResource",
|
||||||
|
"MixinIResourceManager",
|
||||||
|
"MixinLayerCape",
|
||||||
"MixinMinecraft",
|
"MixinMinecraft",
|
||||||
|
"MixinRenderPlayer",
|
||||||
"MixinSkinManager",
|
"MixinSkinManager",
|
||||||
"MixinTextureManager",
|
"MixinTextureManager",
|
||||||
"MixinThreadDownloadImageData",
|
"MixinThreadDownloadImageDataV2",
|
||||||
"MixinTileEntitySkull"
|
"MixinThreadDownloadImageDataV3"
|
||||||
],
|
],
|
||||||
"refmap": "mixins.customskinloader.refmap.json",
|
"refmap": "mixins.customskinloader.refmap.json",
|
||||||
|
"plugin": "customskinloader.fabric.MixinConfigPlugin",
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package customskinloader.fabric;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.fabricmc.loader.impl.FabricLoaderImpl;
|
||||||
|
import net.fabricmc.loader.impl.game.patch.GameTransformer;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.commons.ClassRemapper;
|
||||||
|
import org.objectweb.asm.commons.SimpleRemapper;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
|
||||||
|
public class DevEnvRemapper extends SimpleRemapper {
|
||||||
|
// key: correct method owner names,
|
||||||
|
// value:
|
||||||
|
// left: fake method owner names,
|
||||||
|
// right: other classes which contain fake methods.
|
||||||
|
private static Map<String, Map.Entry<List<String>, List<String>>> remappedClasses = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
remappedClasses.put(
|
||||||
|
"net.minecraft.class_310",
|
||||||
|
new AbstractMap.SimpleEntry<>(
|
||||||
|
Lists.newArrayList("customskinloader.fake.itf.IFakeMinecraft"),
|
||||||
|
Lists.newArrayList("customskinloader.fake.itf.FakeInterfaceManager")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
remappedClasses.put(
|
||||||
|
"net.minecraft.class_1060",
|
||||||
|
new AbstractMap.SimpleEntry<>(
|
||||||
|
Lists.newArrayList("customskinloader.fake.itf.IFakeTextureManager$V1", "customskinloader.fake.itf.IFakeTextureManager$V2"),
|
||||||
|
Lists.newArrayList("customskinloader.fake.itf.FakeInterfaceManager")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
remappedClasses.put(
|
||||||
|
"net.minecraft.class_3298",
|
||||||
|
new AbstractMap.SimpleEntry<>(
|
||||||
|
Lists.newArrayList("customskinloader.fake.itf.IFakeIResource"),
|
||||||
|
Lists.newArrayList("customskinloader.fake.itf.FakeInterfaceManager")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
remappedClasses.put(
|
||||||
|
"net.minecraft.class_3300",
|
||||||
|
new AbstractMap.SimpleEntry<>(
|
||||||
|
Lists.newArrayList("customskinloader.fake.itf.IFakeIResourceManager"),
|
||||||
|
Lists.newArrayList("customskinloader.fake.itf.FakeInterfaceManager")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static void initRemapper() {
|
||||||
|
try {
|
||||||
|
if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
|
||||||
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||||
|
Field patchedClassesField = GameTransformer.class.getDeclaredField("patchedClasses");
|
||||||
|
patchedClassesField.setAccessible(true);
|
||||||
|
Map<String, byte[]> patchedClasses = (Map<String, byte[]>) patchedClassesField.get(FabricLoaderImpl.INSTANCE.getGameProvider().getEntrypointTransformer());
|
||||||
|
|
||||||
|
for (Map.Entry<String, Map.Entry<List<String>, List<String>>> entry : remappedClasses.entrySet()) {
|
||||||
|
List<String> targetClasses = new ArrayList<>(entry.getValue().getKey());
|
||||||
|
targetClasses.addAll(entry.getValue().getValue());
|
||||||
|
for (String clazz : targetClasses) {
|
||||||
|
byte[] classBytes = patchedClasses.get(clazz);
|
||||||
|
if (classBytes == null) {
|
||||||
|
classBytes = IOUtils.toByteArray(Objects.requireNonNull(cl.getResourceAsStream(clazz.replace(".", "/") + ".class")));
|
||||||
|
}
|
||||||
|
|
||||||
|
patchedClasses.put(clazz, remapClass(entry.getKey(), classBytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
MixinConfigPlugin.logger.warning(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remap all method names with specific method owner name.
|
||||||
|
public static byte[] remapClass(String owner, byte[] bytes) {
|
||||||
|
ClassNode cn = new ClassNode();
|
||||||
|
new ClassReader(bytes).accept(new ClassRemapper(cn, new DevEnvRemapper(owner)), ClassReader.EXPAND_FRAMES);
|
||||||
|
|
||||||
|
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
|
||||||
|
cn.accept(cw);
|
||||||
|
return cw.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String owner;
|
||||||
|
private final SimpleRemapper remapper = new SimpleRemapper(new HashMap<>()) {
|
||||||
|
@Override
|
||||||
|
public String map(String key) {
|
||||||
|
return FabricLoader.getInstance().getMappingResolver().unmapClassName("intermediary", Type.getType("L" + key + ";").getClassName()).replace(".", "/");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public DevEnvRemapper(String owner) {
|
||||||
|
super(new HashMap<>());
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String mapMethodName(String owner, String name, String desc) {
|
||||||
|
// Method desc should be unmapped in the development environment.
|
||||||
|
desc = this.remapper.mapDesc(desc);
|
||||||
|
|
||||||
|
String s = this.isFakeOwner(owner) ? FabricLoader.getInstance().getMappingResolver().mapMethodName("intermediary", this.owner, name, desc) : name;
|
||||||
|
return s == null ? name : s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFakeOwner(String owner) {
|
||||||
|
return remappedClasses.get(this.owner).getKey().contains(owner.replace("/", "."));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package customskinloader.fabric;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import customskinloader.Logger;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||||
|
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||||
|
|
||||||
|
public class MixinConfigPlugin implements IMixinConfigPlugin {
|
||||||
|
public static Logger logger = new Logger(new File("./CustomSkinLoader/FabricPlugin.log"));
|
||||||
|
|
||||||
|
private long world_version;
|
||||||
|
private long protocol_version;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad(String mixinPackage) {
|
||||||
|
URL versionJson = this.getClass().getResource("/version.json");
|
||||||
|
if (versionJson != null) {
|
||||||
|
logger.info("\"version.json\": " + versionJson.toString());
|
||||||
|
try (
|
||||||
|
InputStream is = versionJson.openStream();
|
||||||
|
InputStreamReader isr = new InputStreamReader(is)
|
||||||
|
) {
|
||||||
|
JsonObject object = new JsonParser().parse(isr).getAsJsonObject();
|
||||||
|
String name = object.get("name").getAsString();
|
||||||
|
this.world_version = object.get("world_version").getAsLong();
|
||||||
|
this.protocol_version = object.get("protocol_version").getAsLong();
|
||||||
|
logger.info("MinecraftVersion: {name='" + name + "', world_version='" + this.world_version + "', protocol_version='" + this.protocol_version + "'}");
|
||||||
|
} catch (Throwable t) {
|
||||||
|
logger.warning("An exception occurred when reading \"version.json\"!");
|
||||||
|
logger.warning(t);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.warning("Can't read \"version.json\"! Ignore this message if the version you start is earlier than 18w47b.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This mod will remap extra classes when in the development environment.
|
||||||
|
DevEnvRemapper.initRemapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRefMapperConfig() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||||
|
boolean result = true;
|
||||||
|
if (mixinClassName.endsWith(".MixinThreadDownloadImageDataV2")) {
|
||||||
|
result = (this.world_version >= 2205 && this.world_version <= 2722) && ((this.protocol_version >= 554 && this.protocol_version <= 754) || (this.protocol_version >= 801 && this.protocol_version <= 803) || (this.protocol_version >= 0x40000001 && this.protocol_version <= 0x40000022)); // 19w38a ~ 1.17-rc1
|
||||||
|
} else if (mixinClassName.endsWith(".MixinLayerCape") || mixinClassName.endsWith(".MixinRenderPlayer")) {
|
||||||
|
result = this.world_version >= 2210 && this.protocol_version >= 558; // 19w41a+
|
||||||
|
} else if (mixinClassName.endsWith(".MixinThreadDownloadImageDataV3")) {
|
||||||
|
result = this.world_version >= 2723 && ((this.protocol_version >= 755 && this.protocol_version < 801) || (this.protocol_version > 803 && this.protocol_version < 0x40000001) || this.protocol_version >= 0x40000023); // 1.17-rc2+
|
||||||
|
}
|
||||||
|
logger.info("target: " + targetClassName + ", mixin: " + mixinClassName + ", result: " + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getMixins() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// To be compatible with 0.7.11
|
||||||
|
public void preApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// To be compatible with 0.7.11
|
||||||
|
public void postApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
/bin/
|
|
||||||
/build/
|
|
||||||
/run/
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
customskinloader/fake/itf/IFakeIResource$V1 customskinloader/fake/itf/IFakeIResource$V1
|
||||||
|
func_199027_b ()Ljava/io/InputStream; m_6679_
|
||||||
|
customskinloader/fake/itf/IFakeIResource$V2 customskinloader/fake/itf/IFakeIResource$V2
|
||||||
|
open ()Ljava/io/InputStream; m_215507_
|
||||||
|
customskinloader/fake/itf/IFakeIResourceManager customskinloader/fake/itf/IFakeIResourceManager
|
||||||
|
func_199002_a (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/resources/IResource; m_142591_
|
||||||
|
getResource (Lnet/minecraft/util/ResourceLocation;)Ljava/util/Optional; m_213713_
|
||||||
|
customskinloader/fake/itf/IFakeMinecraft customskinloader/fake/itf/IFakeMinecraft
|
||||||
|
func_195551_G ()Lnet/minecraft/resources/IResourceManager; m_91098_
|
||||||
|
customskinloader/fake/itf/IFakeTextureManager$V1 customskinloader/fake/itf/IFakeTextureManager$V1
|
||||||
|
func_229263_a_ (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/Texture;)Z func_229263_a_
|
||||||
|
func_229267_b_ (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/texture/Texture; m_118506_
|
||||||
|
getTexture (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/Texture;)Lnet/minecraft/client/renderer/texture/Texture; m_174786_
|
||||||
|
customskinloader/fake/itf/IFakeTextureManager$V2 customskinloader/fake/itf/IFakeTextureManager$V2
|
||||||
|
func_229263_a_ (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/Texture;)V m_118495_
|
||||||
|
net/minecraft/client/Minecraft net/minecraft/client/Minecraft
|
||||||
|
gameDir f_91069_
|
||||||
|
addScheduledTask (Ljava/lang/Runnable;)Lcom/google/common/util/concurrent/ListenableFuture; func_152344_a
|
||||||
|
getCurrentServerData ()Lnet/minecraft/client/multiplayer/ServerData; m_91089_
|
||||||
|
getMinecraft ()Lnet/minecraft/client/Minecraft; m_91087_
|
||||||
|
getResourceManager ()Lnet/minecraft/client/resources/IResourceManager; m_91098_
|
||||||
|
getSessionService ()Lcom/mojang/authlib/minecraft/MinecraftSessionService; m_91108_
|
||||||
|
getSkinManager ()Lnet/minecraft/client/resources/SkinManager; m_91109_
|
||||||
|
getTextureManager ()Lnet/minecraft/client/renderer/texture/TextureManager; m_91097_
|
||||||
|
net/minecraft/client/gui/GuiPlayerTabOverlay net/minecraft/client/gui/components/PlayerTabOverlay
|
||||||
|
net/minecraft/client/gui/spectator/PlayerMenuObject net/minecraft/client/gui/spectator/PlayerMenuItem
|
||||||
|
net/minecraft/client/multiplayer/ServerData net/minecraft/client/multiplayer/ServerData
|
||||||
|
serverIP f_105363_
|
||||||
|
net/minecraft/client/renderer/RenderType net/minecraft/client/renderer/RenderType
|
||||||
|
func_228644_e_ (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/RenderType; m_110473_
|
||||||
|
net/minecraft/client/renderer/IImageBuffer customskinloader/fake/IFakeImageBuffer
|
||||||
|
func_195786_a (Lnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/NativeImage; func_195786_a
|
||||||
|
parseUserSkin (Ljava/awt/image/BufferedImage;)Ljava/awt/image/BufferedImage; parseUserSkin
|
||||||
|
skinAvailable ()V skinAvailable
|
||||||
|
net/minecraft/client/renderer/ThreadDownloadImageData net/minecraft/client/renderer/texture/HttpTexture
|
||||||
|
net/minecraft/client/renderer/entity/RenderPlayer net/minecraft/client/renderer/entity/player/PlayerRenderer
|
||||||
|
net/minecraft/client/renderer/entity/layers/LayerCape net/minecraft/client/renderer/entity/layers/CapeLayer
|
||||||
|
net/minecraft/client/renderer/texture/DownloadingTexture net/minecraft/client/renderer/texture/HttpTexture
|
||||||
|
net/minecraft/client/renderer/texture/ITextureObject net/minecraft/client/renderer/texture/ITextureObject
|
||||||
|
net/minecraft/client/renderer/texture/NativeImage com/mojang/blaze3d/platform/NativeImage
|
||||||
|
func_195699_a (IIIIIIZZ)V m_85025_
|
||||||
|
func_195700_a (III)V m_84988_
|
||||||
|
func_195702_a ()I m_84982_
|
||||||
|
func_195703_a (Lnet/minecraft/client/renderer/texture/NativeImage;)V m_85054_
|
||||||
|
func_195709_a (II)I m_84985_
|
||||||
|
func_195713_a (Ljava/io/InputStream;)Lnet/minecraft/client/renderer/texture/NativeImage; m_85058_
|
||||||
|
func_195714_b ()I m_85084_
|
||||||
|
func_195715_a (IIIII)V m_84997_
|
||||||
|
net/minecraft/client/renderer/texture/SimpleTexture net/minecraft/client/renderer/texture/SimpleTexture
|
||||||
|
net/minecraft/client/renderer/texture/Texture net/minecraft/client/renderer/texture/AbstractTexture
|
||||||
|
net/minecraft/client/renderer/texture/TextureManager net/minecraft/client/renderer/texture/TextureManager
|
||||||
|
getTexture (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/texture/ITextureObject; func_110581_b
|
||||||
|
loadTexture (Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/ITextureObject;)Z func_110579_a
|
||||||
|
net/minecraft/client/renderer/texture/ThreadDownloadImageData net/minecraft/client/renderer/texture/HttpTexture
|
||||||
|
net/minecraft/client/resources/DefaultPlayerSkin net/minecraft/client/resources/DefaultPlayerSkin
|
||||||
|
getDefaultSkin (Ljava/util/UUID;)Lnet/minecraft/util/ResourceLocation; m_118627_
|
||||||
|
getDefaultSkinLegacy ()Lnet/minecraft/util/ResourceLocation; m_118626_
|
||||||
|
net/minecraft/client/resources/IResource net/minecraft/server/packs/resources/Resource
|
||||||
|
getInputStream ()Ljava/io/InputStream; m_6679_
|
||||||
|
net/minecraft/client/resources/IResourceManager net/minecraft/server/packs/resources/ResourceManager
|
||||||
|
getResource (Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/resources/IResource; m_142591_
|
||||||
|
net/minecraft/client/resources/SkinManager net/minecraft/client/resources/SkinManager
|
||||||
|
loadProfileTextures (Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V m_118817_
|
||||||
|
net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/client/resources/SkinManager$SkinTextureCallback
|
||||||
|
skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V m_118856_
|
||||||
|
net/minecraft/resources/IResource net/minecraft/server/packs/resources/Resource
|
||||||
|
net/minecraft/resources/IResourceManager net/minecraft/server/packs/resources/ResourceManager
|
||||||
|
net/minecraft/util/ResourceLocation net/minecraft/resources/ResourceLocation
|
||||||
|
net/minecraft/util/StringUtils net/minecraft/util/StringUtil
|
||||||
|
stripControlCodes (Ljava/lang/String;)Ljava/lang/String; m_14406_
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes([
|
||||||
|
"Automatic-Module-Name" : "customskinloader"
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
exclude 'net/minecraft/client/renderer/RenderType.class'
|
||||||
|
exclude 'net/minecraft/client/renderer/texture/**'
|
||||||
|
exclude 'net/minecraft/client/resources/**'
|
||||||
|
exclude 'net/minecraft/resources/**'
|
||||||
|
}
|
||||||
|
sourceJar {
|
||||||
|
exclude 'com/**'
|
||||||
|
exclude 'net/**'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(":Forge/Common")
|
||||||
|
}
|
||||||
|
|
||||||
|
import customskinloader.gradle.util.RemapUtil
|
||||||
|
import customskinloader.gradle.util.SourceUtil
|
||||||
|
|
||||||
|
RemapUtil.remapSources project
|
||||||
|
SourceUtil.addDependencies project, project(":Common")
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
minecraft_version=1.17.1
|
||||||
|
minecraft_full_versions=1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2
|
||||||
|
java_full_versions=16,17,18
|
||||||
|
#forge gradle needs forge version
|
||||||
|
forge_mc_version=1.12.2
|
||||||
|
forge_version=14.23.5.2768
|
||||||
|
mappings_version=stable_39
|
||||||
|
srg_notch_map=Forge.tsrg
|
||||||
File renamed without changes.
@@ -1,5 +1,7 @@
|
|||||||
modLoader="javafml"
|
modLoader="javafml"
|
||||||
loaderVersion="[25,)"
|
loaderVersion="[37,)"
|
||||||
|
license="GPL-3.0-only"
|
||||||
|
issueTrackerURL="https://github.com/xfl03/MCCustomSkinLoader/issues"
|
||||||
[[mods]]
|
[[mods]]
|
||||||
modId="customskinloader"
|
modId="customskinloader"
|
||||||
version="${modFullVersion}"
|
version="${modFullVersion}"
|
||||||
@@ -7,12 +9,17 @@ displayName="CustomSkinLoader"
|
|||||||
description='''
|
description='''
|
||||||
Custom Skin Loader for Minecraft
|
Custom Skin Loader for Minecraft
|
||||||
'''
|
'''
|
||||||
issueTrackerURL="https://github.com/xfl03/MCCustomSkinLoader/issues"
|
|
||||||
displayURL="https://github.com/xfl03/MCCustomSkinLoader"
|
displayURL="https://github.com/xfl03/MCCustomSkinLoader"
|
||||||
authors=["xfl03", "JLChnToZ"]
|
authors=["xfl03", "JLChnToZ"]
|
||||||
[[dependencies.customskinloader]]
|
[[dependencies.customskinloader]]
|
||||||
modId="forge"
|
modId="forge"
|
||||||
mandatory=true
|
mandatory=true
|
||||||
versionRange="[25,)"
|
versionRange="[37,)"
|
||||||
|
ordering="NONE"
|
||||||
|
side="CLIENT"
|
||||||
|
[[dependencies.customskinloader]]
|
||||||
|
modId="minecraft"
|
||||||
|
mandatory=true
|
||||||
|
versionRange="[1.17.1,)"
|
||||||
ordering="NONE"
|
ordering="NONE"
|
||||||
side="CLIENT"
|
side="CLIENT"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"pack": {
|
||||||
|
"description": "CustomSkinLoader resources",
|
||||||
|
"pack_format": 7
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
var ASMAPI = getJavaType('net.minecraftforge.coremod.api.ASMAPI');
|
||||||
|
var Handle = getJavaType('org.objectweb.asm.Handle');
|
||||||
|
var Opcodes = getJavaType('org.objectweb.asm.Opcodes');
|
||||||
|
var Type = getJavaType('org.objectweb.asm.Type');
|
||||||
|
var FieldInsnNode = getJavaType('org.objectweb.asm.tree.FieldInsnNode');
|
||||||
|
var FieldNode = getJavaType('org.objectweb.asm.tree.FieldNode');
|
||||||
|
var InsnNode = getJavaType('org.objectweb.asm.tree.InsnNode');
|
||||||
|
var InvokeDynamicInsnNode = getJavaType('org.objectweb.asm.tree.InvokeDynamicInsnNode');
|
||||||
|
var MethodInsnNode = getJavaType('org.objectweb.asm.tree.MethodInsnNode');
|
||||||
|
var TypeInsnNode = getJavaType('org.objectweb.asm.tree.TypeInsnNode');
|
||||||
|
var VarInsnNode = getJavaType('org.objectweb.asm.tree.VarInsnNode');
|
||||||
|
|
||||||
|
function getJavaType(name) {
|
||||||
|
return Java.type(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare method and field names.
|
||||||
|
function checkName(name, srgName) {
|
||||||
|
return name.equals(mapName(srgName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-obfuscate method and field names.
|
||||||
|
function mapName(srgName) {
|
||||||
|
if (srgName.startsWith("f_")) return ASMAPI.mapField(srgName);
|
||||||
|
if (srgName.startsWith("m_")) return ASMAPI.mapMethod(srgName);
|
||||||
|
return srgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeCoreMod() {
|
||||||
|
return {
|
||||||
|
'SkinManagerTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/resources/SkinManager'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.fields.removeIf(function (fn) {
|
||||||
|
return fn.name.equals("fakeManager") && fn.desc.equals("Lcustomskinloader/fake/FakeSkinManager;");
|
||||||
|
});
|
||||||
|
cn.fields.add(new FieldNode(Opcodes.ACC_PRIVATE, "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;", null, null));
|
||||||
|
|
||||||
|
cn.methods.forEach(function (mn) {
|
||||||
|
if (checkName(mn.name, "<init>") && mn.desc.equals("(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V")) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.RETURN) {
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(node, new TypeInsnNode(Opcodes.NEW, "customskinloader/fake/FakeSkinManager"));
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.DUP));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 3));
|
||||||
|
mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESPECIAL, "customskinloader/fake/FakeSkinManager", "<init>", "(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V", false));
|
||||||
|
mn.instructions.insertBefore(node, new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (checkName(mn.name, "m_118828_") && mn.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinTextureCallback;)Lnet/minecraft/resources/ResourceLocation;")) {
|
||||||
|
var first = mn.instructions.getFirst();
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 3));
|
||||||
|
mn.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadSkin", "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinTextureCallback;)Lnet/minecraft/resources/ResourceLocation;", false));
|
||||||
|
mn.instructions.insertBefore(first, new InsnNode(Opcodes.ARETURN));
|
||||||
|
} else if (checkName(mn.name, "m_118817_") && mn.desc.equals("(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinTextureCallback;Z)V")) {
|
||||||
|
var first = mn.instructions.getFirst();
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ILOAD, 3));
|
||||||
|
mn.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadProfileTextures", "(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinTextureCallback;Z)V", false));
|
||||||
|
mn.instructions.insertBefore(first, new InsnNode(Opcodes.RETURN));
|
||||||
|
} else if (checkName(mn.name, "m_118815_") && mn.desc.equals("(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;")) {
|
||||||
|
var first = mn.instructions.getFirst();
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadSkinFromCache", "(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;", false));
|
||||||
|
mn.instructions.insertBefore(first, new InsnNode(Opcodes.ARETURN));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'IResourceTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/server/packs/resources/Resource'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResource$V1");
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResource$V2");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'IResourceManagerTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/server/packs/resources/ResourceManager'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResourceManager");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'MinecraftTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/Minecraft'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeMinecraft");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'TextureManagerTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/renderer/texture/TextureManager'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager$V1");
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager$V2");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'RenderPlayer_LayerCapeTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'names': function (target) {
|
||||||
|
return ['net/minecraft/client/renderer/entity/player/PlayerRenderer', 'net/minecraft/client/renderer/entity/layers/CapeLayer'];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.methods.forEach(function (mn) {
|
||||||
|
if ((checkName(mn.name, "m_117775_") && mn.desc.equals("(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/player/AbstractClientPlayer;Lnet/minecraft/client/model/geom/ModelPart;Lnet/minecraft/client/model/geom/ModelPart;)V")) // PlayerRenderer.renderHand
|
||||||
|
|| (checkName(mn.name, "m_6494_") && mn.desc.equals("(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/player/AbstractClientPlayer;FFFFFF)V"))) { // CapeLayer.render
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKESTATIC && node.owner.equals("net/minecraft/client/renderer/RenderType") && checkName(node.name, "m_110446_") && node.desc.equals("(Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/renderer/RenderType;")) { // RenderType.entitySolid
|
||||||
|
node.name = mapName("m_110473_"); // RenderType.entityTranslucent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'HttpTextureTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'METHOD',
|
||||||
|
'class': 'net/minecraft/client/renderer/texture/HttpTexture',
|
||||||
|
'methodName': 'm_118018_',
|
||||||
|
'methodDesc': '(Ljava/io/InputStream;)Lcom/mojang/blaze3d/platform/NativeImage;'
|
||||||
|
},
|
||||||
|
'transformer': function (mn) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if ((node.getOpcode() === Opcodes.INVOKEVIRTUAL || node.getOpcode() === Opcodes.INVOKESPECIAL) && node.owner.equals("net/minecraft/client/renderer/texture/HttpTexture") && checkName(node.name, "m_118032_") && node.desc.equals("(Lcom/mojang/blaze3d/platform/NativeImage;)Lcom/mojang/blaze3d/platform/NativeImage;")) {
|
||||||
|
// FakeSkinBuffer.processLegacySkin(image, this.onDownloaded, this::processLegacySkin);
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.SWAP));
|
||||||
|
mn.instructions.insertBefore(node, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/renderer/texture/HttpTexture", mapName("f_117997_"), "Ljava/lang/Runnable;"));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(node, new InvokeDynamicInsnNode("apply", "(Lnet/minecraft/client/renderer/texture/HttpTexture;)Ljava/util/function/Function;",
|
||||||
|
/* bsm */ new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;", false),
|
||||||
|
/* bsmArgs */ Type.getType("(Ljava/lang/Object;)Ljava/lang/Object;"),
|
||||||
|
/* bsmArgs */ new Handle(Opcodes.H_INVOKEVIRTUAL, "net/minecraft/client/renderer/texture/HttpTexture", mapName("m_118032_"), "(Lcom/mojang/blaze3d/platform/NativeImage;)Lcom/mojang/blaze3d/platform/NativeImage;", false),
|
||||||
|
/* bsmArgs */ Type.getType("(Lcom/mojang/blaze3d/platform/NativeImage;)Lcom/mojang/blaze3d/platform/NativeImage;")));
|
||||||
|
iterator.set(new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinBuffer", "processLegacySkin", "(Lcom/mojang/blaze3d/platform/NativeImage;Ljava/lang/Runnable;Ljava/util/function/Function;)Lcom/mojang/blaze3d/platform/NativeImage;", false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'PlayerTabOverlayTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'METHOD',
|
||||||
|
'class': 'net/minecraft/client/gui/components/PlayerTabOverlay',
|
||||||
|
'methodName': 'm_94544_',
|
||||||
|
'methodDesc': '(Lcom/mojang/blaze3d/vertex/PoseStack;ILnet/minecraft/world/scores/Scoreboard;Lnet/minecraft/world/scores/Objective;)V'
|
||||||
|
},
|
||||||
|
'transformer': function (mn) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKEVIRTUAL && node.owner.equals("net/minecraft/client/Minecraft") && checkName(node.name, "m_91090_") && node.desc.equals("()Z")) {
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.POP));
|
||||||
|
mn.instructions.set(node, new InsnNode(Opcodes.ICONST_1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package customskinloader.forge;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.IExtensionPoint;
|
||||||
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
|
||||||
|
@Mod("customskinloader")
|
||||||
|
public class ForgeMod {
|
||||||
|
public ForgeMod() {
|
||||||
|
this.setExtensionPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setExtensionPoint() {
|
||||||
|
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> "customskinloader", (remote, isServer) -> isServer));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
forge_mc_version=1.12.2
|
||||||
|
forge_version=14.23.5.2768
|
||||||
|
mappings_version=stable_39
|
||||||
|
# this subproject is only to provide dependency for other subprojects.
|
||||||
|
is_real_project=false
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package net.minecraftforge.fml;
|
||||||
|
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
public class ExtensionPoint<T> {
|
||||||
|
public static ExtensionPoint<Pair<Supplier<String>, BiPredicate<String, Boolean>>> DISPLAYTEST;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package net.minecraftforge.fml;
|
||||||
|
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public interface IExtensionPoint<T> {
|
||||||
|
class DisplayTest implements IExtensionPoint<DisplayTest> {
|
||||||
|
public DisplayTest(Supplier<String> suppliedVersion, BiPredicate<String, Boolean> remoteVersionTest) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.minecraftforge.fml;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class ModLoadingContext {
|
||||||
|
public static ModLoadingContext get() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void registerExtensionPoint(ExtensionPoint<T> point, Supplier<T> extension) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void registerExtensionPoint(Class<? extends IExtensionPoint<T>> point, Supplier<T> extension) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -12,7 +12,7 @@ import java.lang.annotation.Target;
|
|||||||
public @interface Mod {
|
public @interface Mod {
|
||||||
String value();
|
String value();
|
||||||
|
|
||||||
String modid();
|
String modid() default "";
|
||||||
|
|
||||||
String name() default "";
|
String name() default "";
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes([
|
||||||
|
"TweakClass": "customskinloader.forge.ForgeTweaker",
|
||||||
|
"TweakOrder": -10
|
||||||
|
])
|
||||||
|
}
|
||||||
|
exclude 'net/minecraft/client/renderer/texture/**'
|
||||||
|
exclude 'net/minecraft/client/resources/SkinManager.class'
|
||||||
|
exclude 'net/minecraft/client/resources/SkinManager$ISkinAvailableCallback.class'
|
||||||
|
exclude 'net/minecraft/resources/**'
|
||||||
|
}
|
||||||
|
sourceJar {
|
||||||
|
exclude 'net/**'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.signJar {
|
||||||
|
// To prevent modlauncher from checking signer information about Minecraft classes in CustomSkinLoader jar after forge-1.16.3-34.1.27.
|
||||||
|
exclude "net/minecraft/client/**"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(":Forge/Common")
|
||||||
|
}
|
||||||
|
|
||||||
|
minecraft {
|
||||||
|
replaceIn 'ForgeMod.java'
|
||||||
|
}
|
||||||
|
|
||||||
|
import customskinloader.gradle.util.SourceUtil
|
||||||
|
|
||||||
|
SourceUtil.addDependencies project, project(":Common")
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
minecraft_version=1.12.2
|
minecraft_version=1.12.2
|
||||||
minecraft_full_versions=1.8,1.8.8,1.8.9,1.9,1.9.4,1.10,1.10.2,1.11,1.11.2,1.12,1.12.1,1.12.2,1.13.2,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16.1
|
minecraft_full_versions=1.8,1.8.8,1.8.9,1.9,1.9.4,1.10,1.10.2,1.11,1.11.2,1.12,1.12.1,1.12.2,1.13.2,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5
|
||||||
|
java_full_versions=8,9,10,11,12,13,14,15,16,17,18
|
||||||
#forge gradle needs forge version
|
#forge gradle needs forge version
|
||||||
forge_mc_version=1.12.2
|
forge_mc_version=1.12.2
|
||||||
forge_version=14.23.5.2768
|
forge_version=14.23.5.2768
|
||||||
mappings_version=stable_39
|
mappings_version=stable_39
|
||||||
srg_notch_map=Forge.srg
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"transformers": "transformers.js"
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
modLoader="javafml"
|
||||||
|
loaderVersion="[25,37)"
|
||||||
|
license="GPL-3.0-only"
|
||||||
|
issueTrackerURL="https://github.com/xfl03/MCCustomSkinLoader/issues"
|
||||||
|
[[mods]]
|
||||||
|
modId="customskinloader"
|
||||||
|
version="${modFullVersion}"
|
||||||
|
displayName="CustomSkinLoader"
|
||||||
|
description='''
|
||||||
|
Custom Skin Loader for Minecraft
|
||||||
|
'''
|
||||||
|
displayURL="https://github.com/xfl03/MCCustomSkinLoader"
|
||||||
|
authors=["xfl03", "JLChnToZ"]
|
||||||
|
[[dependencies.customskinloader]]
|
||||||
|
modId="forge"
|
||||||
|
mandatory=true
|
||||||
|
versionRange="[25.0.9,25.0.22],[25.0.42,37.0.0)" # incompatible with CoreMods-0.3.0
|
||||||
|
ordering="NONE"
|
||||||
|
side="CLIENT"
|
||||||
|
[[dependencies.customskinloader]]
|
||||||
|
modId="minecraft"
|
||||||
|
mandatory=true
|
||||||
|
versionRange="[1.13.2,1.17.0)"
|
||||||
|
ordering="NONE"
|
||||||
|
side="CLIENT"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
customskinloader.forge.platform.DefaultFMLPlatform
|
||||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,258 @@
|
|||||||
|
var ASMAPI = getJavaType('net.minecraftforge.coremod.api.ASMAPI');
|
||||||
|
var Handle = getJavaType('org.objectweb.asm.Handle');
|
||||||
|
var Opcodes = getJavaType('org.objectweb.asm.Opcodes');
|
||||||
|
var Type = getJavaType('org.objectweb.asm.Type');
|
||||||
|
var FieldInsnNode = getJavaType('org.objectweb.asm.tree.FieldInsnNode');
|
||||||
|
var FieldNode = getJavaType('org.objectweb.asm.tree.FieldNode');
|
||||||
|
var InsnNode = getJavaType('org.objectweb.asm.tree.InsnNode');
|
||||||
|
var InvokeDynamicInsnNode = getJavaType('org.objectweb.asm.tree.InvokeDynamicInsnNode');
|
||||||
|
var JumpInsnNode = getJavaType('org.objectweb.asm.tree.JumpInsnNode');
|
||||||
|
var LabelNode = getJavaType('org.objectweb.asm.tree.LabelNode');
|
||||||
|
var MethodInsnNode = getJavaType('org.objectweb.asm.tree.MethodInsnNode');
|
||||||
|
var MethodNode = getJavaType('org.objectweb.asm.tree.MethodNode');
|
||||||
|
var TypeInsnNode = getJavaType('org.objectweb.asm.tree.TypeInsnNode');
|
||||||
|
var VarInsnNode = getJavaType('org.objectweb.asm.tree.VarInsnNode');
|
||||||
|
|
||||||
|
function getJavaType(name) {
|
||||||
|
try {
|
||||||
|
return Java.type(name);
|
||||||
|
} catch (ignored) {
|
||||||
|
// forge-1.13.2-25.0.23 ~ 1.13.2-25.0.41
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare method and field names, doesn't support forge-1.13.2-25.0.194 and earlier version.
|
||||||
|
function checkName(name, srgName) {
|
||||||
|
return name.equals(mapName(srgName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-obfuscate method and field names.
|
||||||
|
function mapName(srgName) {
|
||||||
|
try {
|
||||||
|
if (srgName.startsWith("field_")) return ASMAPI.mapField(srgName);
|
||||||
|
if (srgName.startsWith("func_")) return ASMAPI.mapMethod(srgName);
|
||||||
|
} catch (ignored) {
|
||||||
|
// Before forge-1.13.2-25.0.194
|
||||||
|
}
|
||||||
|
return srgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeCoreMod() {
|
||||||
|
return {
|
||||||
|
'SkinManagerTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/resources/SkinManager'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.fields.removeIf(function (fn) {
|
||||||
|
return fn.name.equals("fakeManager") && fn.desc.equals("Lcustomskinloader/fake/FakeSkinManager;");
|
||||||
|
});
|
||||||
|
cn.fields.add(new FieldNode(Opcodes.ACC_PRIVATE, "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;", null, null));
|
||||||
|
|
||||||
|
cn.methods.forEach(function (mn) {
|
||||||
|
if (checkName(mn.name, "<init>") && mn.desc.equals("(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V")) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.RETURN) {
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(node, new TypeInsnNode(Opcodes.NEW, "customskinloader/fake/FakeSkinManager"));
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.DUP));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 3));
|
||||||
|
mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESPECIAL, "customskinloader/fake/FakeSkinManager", "<init>", "(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V", false));
|
||||||
|
mn.instructions.insertBefore(node, new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (checkName(mn.name, "func_152789_a")
|
||||||
|
&& (mn.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;") // 1.13.2-
|
||||||
|
|| mn.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$ISkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;"))) { // 1.14.2+
|
||||||
|
var first = mn.instructions.getFirst();
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 3));
|
||||||
|
mn.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadSkin", "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;", false));
|
||||||
|
mn.instructions.insertBefore(first, new InsnNode(Opcodes.ARETURN));
|
||||||
|
} else if (checkName(mn.name, "func_152790_a")
|
||||||
|
&& (mn.desc.equals("(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V") // 1.13.2-
|
||||||
|
|| mn.desc.equals("(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$ISkinAvailableCallback;Z)V"))) { // 1.14.2+
|
||||||
|
var first = mn.instructions.getFirst();
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ILOAD, 3));
|
||||||
|
mn.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadProfileTextures", "(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V", false));
|
||||||
|
mn.instructions.insertBefore(first, new InsnNode(Opcodes.RETURN));
|
||||||
|
} else if (checkName(mn.name, "func_152788_a") && mn.desc.equals("(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;")) {
|
||||||
|
var first = mn.instructions.getFirst();
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadSkinFromCache", "(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;", false));
|
||||||
|
mn.instructions.insertBefore(first, new InsnNode(Opcodes.ARETURN));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'PlayerTabTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'names': function (target) {
|
||||||
|
return ['net/minecraft/client/gui/GuiPlayerTabOverlay', 'net/minecraft/client/gui/overlay/PlayerTabOverlayGui'];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.methods.forEach(function (mn) {
|
||||||
|
if ((checkName(mn.name, "func_175249_a") && mn.desc.equals("(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V")) // 1.15.2-
|
||||||
|
|| (checkName(mn.name, "func_238523_a_") && mn.desc.equals("(Lcom/mojang/blaze3d/matrix/MatrixStack;ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V"))) { // 1.16.1+
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKEVIRTUAL && node.owner.equals("net/minecraft/client/Minecraft") && checkName(node.name, "func_71387_A") && node.desc.equals("()Z")) {
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.POP));
|
||||||
|
mn.instructions.set(node, new InsnNode(Opcodes.ICONST_1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// For 1.13+
|
||||||
|
'AbstractTextureTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/renderer/texture/AbstractTexture'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("net/minecraft/client/renderer/texture/Texture");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'TextureTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/renderer/texture/Texture'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
if (cn.access === 0) {
|
||||||
|
cn.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT;
|
||||||
|
}
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// For 1.14+
|
||||||
|
'MinecraftTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/Minecraft'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeMinecraft");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'IResourceTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/resources/IResource'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResource$V1");
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResource$V2");
|
||||||
|
cn.interfaces.add("net/minecraft/client/resources/IResource");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'IResourceManagerTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/resources/IResourceManager'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResourceManager");
|
||||||
|
cn.interfaces.add("net/minecraft/client/resources/IResourceManager");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'ISkinAvailableCallbackTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/resources/SkinManager$ISkinAvailableCallback'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("net/minecraft/client/resources/SkinManager$SkinAvailableCallback");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// For 1.15+
|
||||||
|
'TextureManagerTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/renderer/texture/TextureManager'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager$V1");
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager$V2");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'DownloadingTextureTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'name': 'net/minecraft/client/renderer/texture/DownloadingTexture'
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.methods.forEach(function (mn) {
|
||||||
|
if (checkName(mn.name, "func_229159_a_") && mn.desc.equals("(Ljava/io/InputStream;)Lnet/minecraft/client/renderer/texture/NativeImage;")) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKESTATIC && node.owner.equals("net/minecraft/client/renderer/texture/DownloadingTexture") && checkName(node.name, "func_229163_c_") && node.desc.equals("(Lnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/NativeImage;")) {
|
||||||
|
// FakeSkinBuffer.processLegacySkin(image, this.processTask, DownloadingTexture::processLegacySkin);
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(node, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/renderer/texture/DownloadingTexture", mapName("field_229155_i_"), "Ljava/lang/Runnable;"));
|
||||||
|
mn.instructions.insertBefore(node, new InvokeDynamicInsnNode("apply", "()Ljava/util/function/Function;",
|
||||||
|
/* bsm */ new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;", false),
|
||||||
|
/* bsmArgs */ Type.getType("(Ljava/lang/Object;)Ljava/lang/Object;"),
|
||||||
|
/* bsmArgs */ new Handle(Opcodes.H_INVOKESTATIC, "net/minecraft/client/renderer/texture/DownloadingTexture", mapName("func_229163_c_"), "(Lnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/NativeImage;", false),
|
||||||
|
/* bsmArgs */ Type.getType("(Lnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/NativeImage;")));
|
||||||
|
iterator.set(new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinBuffer", "processLegacySkin", "(Lnet/minecraft/client/renderer/texture/NativeImage;Ljava/lang/Runnable;Ljava/util/function/Function;)Lnet/minecraft/client/renderer/texture/NativeImage;", false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'RenderPlayer_LayerCapeTransformer': {
|
||||||
|
'target': {
|
||||||
|
'type': 'CLASS',
|
||||||
|
'names': function (target) {
|
||||||
|
return ['net/minecraft/client/renderer/entity/PlayerRenderer', 'net/minecraft/client/renderer/entity/layers/CapeLayer'];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'transformer': function (cn) {
|
||||||
|
cn.methods.forEach(function (mn) {
|
||||||
|
if ((checkName(mn.name, "func_229145_a_") && mn.desc.equals("(Lcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;ILnet/minecraft/client/entity/player/AbstractClientPlayerEntity;Lnet/minecraft/client/renderer/model/ModelRenderer;Lnet/minecraft/client/renderer/model/ModelRenderer;)V")) // PlayerRenderer.renderItem
|
||||||
|
|| (checkName(mn.name, "func_225628_a_") && mn.desc.equals("(Lcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;ILnet/minecraft/client/entity/player/AbstractClientPlayerEntity;FFFFFF)V"))) { // CapeLayer.render
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKESTATIC && node.owner.equals("net/minecraft/client/renderer/RenderType") && checkName(node.name, "func_228634_a_") && node.desc.equals("(Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/client/renderer/RenderType;")) { // RenderType.getEntitySolid
|
||||||
|
node.name = mapName("func_228644_e_"); // RenderType.getEntityTranslucent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package customskinloader.forge;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.launchwrapper.ITweaker;
|
||||||
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tweaker for development environment.
|
||||||
|
*/
|
||||||
|
public class ForgeDevTweaker implements ITweaker {
|
||||||
|
@Override
|
||||||
|
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||||
|
// ForgeTweaker should be added after FMLTweaker being initialized.
|
||||||
|
((List<String>) Launch.blackboard.get("TweakClasses")).add(ForgeTweaker.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLaunchTarget() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getLaunchArguments() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
-5
@@ -1,10 +1,12 @@
|
|||||||
package customskinloader.forge;
|
package customskinloader.forge;
|
||||||
|
|
||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
import net.minecraftforge.fml.ExtensionPoint;
|
||||||
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
|
||||||
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
|
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forge Mod Container
|
* Forge Mod Container
|
||||||
@@ -15,15 +17,22 @@ import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
|
|||||||
name = "CustomSkinLoader",
|
name = "CustomSkinLoader",
|
||||||
version = "@MOD_FULL_VERSION@",
|
version = "@MOD_FULL_VERSION@",
|
||||||
clientSideOnly = true,
|
clientSideOnly = true,
|
||||||
acceptedMinecraftVersions = "[1.8,)",
|
acceptedMinecraftVersions = "[1.8,1.13)",
|
||||||
acceptableRemoteVersions = "*",
|
acceptableRemoteVersions = "*",
|
||||||
certificateFingerprint = "52885f395e68f42e9b3b629ba56ecf606f7d4269"
|
certificateFingerprint = "52885f395e68f42e9b3b629ba56ecf606f7d4269"
|
||||||
)//1.13-
|
)//1.13-
|
||||||
public class ForgeMod {
|
public class ForgeMod {
|
||||||
|
public ForgeMod() {
|
||||||
|
try {
|
||||||
|
this.setExtensionPoint();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
// before forge-1.13.2-25.0.103
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Mod.EventHandler
|
||||||
public void fingerprintError(FMLFingerprintViolationEvent event) {
|
public void fingerprintError(FMLFingerprintViolationEvent event) {
|
||||||
if (event.isDirectory()) return;//Development Environment
|
if ((boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment") || event.isDirectory()) return;//Development Environment
|
||||||
|
|
||||||
CustomSkinLoader.logger.warning("!!!Fingerprint ERROR!!!");
|
CustomSkinLoader.logger.warning("!!!Fingerprint ERROR!!!");
|
||||||
CustomSkinLoader.logger.warning("Failed to check fingerprint in file '" + event.getSource().getAbsolutePath() + "'.");
|
CustomSkinLoader.logger.warning("Failed to check fingerprint in file '" + event.getSource().getAbsolutePath() + "'.");
|
||||||
@@ -38,4 +47,9 @@ public class ForgeMod {
|
|||||||
|
|
||||||
throw new RuntimeException("Fingerprint ERROR, please **DO NOT MODIFY** any mod.");
|
throw new RuntimeException("Fingerprint ERROR, please **DO NOT MODIFY** any mod.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the mod being absent on the other network side does not cause the client to display the server as incompatible after forge-1.13.2-25.0.107.
|
||||||
|
private void setExtensionPoint() {
|
||||||
|
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> "customskinloader", (remote, isServer) -> isServer));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
-2
@@ -3,9 +3,9 @@ package customskinloader.forge;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin.Name;
|
|
||||||
|
|
||||||
@Name("CustomSkinLoader")
|
@IFMLLoadingPlugin.Name("CustomSkinLoader")
|
||||||
|
@IFMLLoadingPlugin.SortingIndex(-10)
|
||||||
public class ForgePlugin implements IFMLLoadingPlugin {
|
public class ForgePlugin implements IFMLLoadingPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -25,6 +25,7 @@ public class ForgePlugin implements IFMLLoadingPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectData(Map<String, Object> data) {
|
public void injectData(Map<String, Object> data) {
|
||||||
|
TransformerManager.isDevelopmentEnvironment = !(boolean) data.get("runtimeDeobfuscationEnabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package customskinloader.forge;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import customskinloader.Logger;
|
||||||
|
import net.minecraft.launchwrapper.ITweaker;
|
||||||
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||||
|
|
||||||
|
public class ForgeTweaker implements ITweaker {
|
||||||
|
public static Logger logger = new Logger(new File("./CustomSkinLoader/ForgePlugin.log"));
|
||||||
|
|
||||||
|
private final static String FML_PLATFORM_INITIALIZER = "customskinloader.forge.platform.IFMLPlatform$FMLPlatformInitializer";
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public ForgeTweaker() throws Exception {
|
||||||
|
// FML is loaded by LaunchClassLoader but we are in AppClassLoader.
|
||||||
|
if (!this.getClass().getClassLoader().equals(Launch.classLoader)) {
|
||||||
|
Field field = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions");
|
||||||
|
field.setAccessible(true);
|
||||||
|
|
||||||
|
String exclusionName = this.getClass().getName().substring(0, this.getClass().getName().lastIndexOf("."));
|
||||||
|
((Set<String>) field.get(Launch.classLoader)).remove(exclusionName);
|
||||||
|
Launch.classLoader.addClassLoaderExclusion(Logger.class.getName());
|
||||||
|
Launch.classLoader.addTransformerExclusion(exclusionName);
|
||||||
|
Launch.classLoader.loadClass(FML_PLATFORM_INITIALIZER).getMethod("initFMLPlatform").invoke(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLaunchTarget() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getLaunchArguments() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package customskinloader.forge;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import customskinloader.forge.platform.IFMLPlatform;
|
||||||
|
import org.objectweb.asm.commons.Remapper;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
|
public class TransformerManager {
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface TransformTarget {
|
||||||
|
String className();
|
||||||
|
|
||||||
|
String methodNameSrg() default "";
|
||||||
|
|
||||||
|
String[] methodNames() default {};
|
||||||
|
|
||||||
|
String desc() default "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IClassTransformer {
|
||||||
|
ClassNode transform(ClassNode cn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IMethodTransformer {
|
||||||
|
MethodNode transform(ClassNode cn, MethodNode mn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isDevelopmentEnvironment = false;
|
||||||
|
/** If true, match {@link TransformTarget#methodNames} if {@link TransformTarget#methodNameSrg} fails to match. */
|
||||||
|
public static boolean useDeobfName = false;
|
||||||
|
private final static Remapper remapper = IFMLPlatform.FMLPlatformInitializer.getPlatform().getRemapper();
|
||||||
|
|
||||||
|
public static String mapClassName(String name) {
|
||||||
|
return remapper.mapType(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String mapFieldName(String owner, String name, String desc) {
|
||||||
|
return remapper.mapFieldName(owner, name, desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String mapMethodName(String owner, String name, String desc) {
|
||||||
|
return remapper.mapMethodName(owner, name, desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String mapMethodDesc(String desc) {
|
||||||
|
return remapper.mapMethodDesc(desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkClassName(String name, String deobfName) {
|
||||||
|
if (isDevelopmentEnvironment) {
|
||||||
|
return name.equals(deobfName);
|
||||||
|
} else {
|
||||||
|
return mapClassName(name).equals(deobfName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkMethodName(String owner, String name, String desc, String srgName) {
|
||||||
|
if (isDevelopmentEnvironment) {
|
||||||
|
return mapMethodName(owner, srgName, desc).equals(name);
|
||||||
|
} else {
|
||||||
|
return mapMethodName(owner, name, desc).equals(srgName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkMethodDesc(String desc, String deobfDesc) {
|
||||||
|
if (isDevelopmentEnvironment) {
|
||||||
|
return desc.equals(deobfDesc);
|
||||||
|
} else {
|
||||||
|
return mapMethodDesc(desc).equals(deobfDesc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, IClassTransformer> classMap = new HashMap<>();
|
||||||
|
public Map<String, Map<Supplier<String>, IMethodTransformer>> srgMap = new HashMap<>();
|
||||||
|
public Map<String, Map<String, IMethodTransformer>> map = new HashMap<>();
|
||||||
|
|
||||||
|
public TransformerManager(IClassTransformer[] classTransformers, IMethodTransformer[] methodTransformers) {
|
||||||
|
for (IClassTransformer t : classTransformers) {
|
||||||
|
TransformTarget tt = this.getTransformTarget(t.getClass());
|
||||||
|
if (tt != null) {
|
||||||
|
addClassTransformer(tt.className(), t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (IMethodTransformer t : methodTransformers) {
|
||||||
|
TransformTarget tt = this.getTransformTarget(t.getClass());
|
||||||
|
if (tt != null) {
|
||||||
|
addMethodTransformer(tt, tt.className(), t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TransformTarget getTransformTarget(Class<?> cl) {
|
||||||
|
ForgeTweaker.logger.info("[CSL DEBUG] REGISTERING TRANSFORMER %s", cl.getName());
|
||||||
|
if (!cl.isAnnotationPresent(TransformTarget.class)) {
|
||||||
|
ForgeTweaker.logger.info("[CSL DEBUG] ERROR occurs while parsing Annotation");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return cl.getAnnotation(TransformTarget.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addClassTransformer(String className, IClassTransformer transformer) {
|
||||||
|
if (!classMap.containsKey(className)) {
|
||||||
|
classMap.put(className, transformer);
|
||||||
|
ForgeTweaker.logger.info("[CSL DEBUG] REGISTERING CLASS %s", className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMethodTransformer(TransformTarget target, String className, IMethodTransformer transformer) {
|
||||||
|
if (!srgMap.containsKey(className)) {
|
||||||
|
srgMap.put(className, new HashMap<>());
|
||||||
|
}
|
||||||
|
if (!target.methodNameSrg().equals("")) {
|
||||||
|
// FMLDeobfRemapper has not been setup when this line being reached.
|
||||||
|
Supplier<String> mappedMethod = () -> (isDevelopmentEnvironment ? mapMethodName(className.replace(".", "/"), target.methodNameSrg(), target.desc()) : target.methodNameSrg()) + target.desc();
|
||||||
|
srgMap.get(className).put(mappedMethod, transformer);
|
||||||
|
ForgeTweaker.logger.info("[CSL DEBUG] REGISTERING SRG METHOD %s::%s", className, target.methodNameSrg() + target.desc());
|
||||||
|
}
|
||||||
|
if (!map.containsKey(className))
|
||||||
|
map.put(className, new HashMap<>());
|
||||||
|
for (String methodName : target.methodNames()) {
|
||||||
|
map.get(className).put(methodName + target.desc(), transformer);
|
||||||
|
ForgeTweaker.logger.info("[CSL DEBUG] REGISTERING METHOD %s::%s", className, methodName + target.desc());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassNode transform(ClassNode classNode, String className) {
|
||||||
|
IClassTransformer transformer = classMap.get(className);
|
||||||
|
if (transformer != null) {
|
||||||
|
try {
|
||||||
|
classNode = transformer.transform(classNode);
|
||||||
|
ForgeTweaker.logger.info("[CSL DEBUG] Successfully transformed class %s", className);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ForgeTweaker.logger.warning("[CSL DEBUG] An error happened when transforming class %s", className);
|
||||||
|
ForgeTweaker.logger.warning(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return classNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MethodNode transform(ClassNode classNode, MethodNode methodNode, String className, String methodName, String methodDesc) {
|
||||||
|
String methodTarget = methodName + methodDesc;
|
||||||
|
Map<Supplier<String>, IMethodTransformer> transSrgMap = srgMap.get(className);
|
||||||
|
IMethodTransformer transformer = transSrgMap == null ? null : transSrgMap.get(transSrgMap.keySet().stream().filter(s -> s.get().equals(methodTarget)).findFirst().orElse(null));
|
||||||
|
|
||||||
|
Map<String, IMethodTransformer> transMap = map.get(className);
|
||||||
|
if (useDeobfName && transMap != null && transformer == null) {
|
||||||
|
transformer = transMap.get(methodTarget);
|
||||||
|
}
|
||||||
|
if (transformer != null) {
|
||||||
|
try {
|
||||||
|
methodNode = transformer.transform(classNode, methodNode);
|
||||||
|
ForgeTweaker.logger.info("[CSL DEBUG] Successfully transformed method %s in class %s", methodName, className);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ForgeTweaker.logger.warning("[CSL DEBUG] An error happened when transforming method %s in class %s", methodTarget, className);
|
||||||
|
ForgeTweaker.logger.warning(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return methodNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
-11
@@ -1,13 +1,13 @@
|
|||||||
package customskinloader.forge.loader;
|
package customskinloader.forge.loader;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import customskinloader.forge.TransformerManager;
|
import customskinloader.forge.TransformerManager;
|
||||||
import customskinloader.forge.transformer.FakeInterfacesTransformer;
|
import customskinloader.forge.transformer.FakeInterfacesTransformer;
|
||||||
import customskinloader.forge.transformer.PlayerTabTransformer;
|
import customskinloader.forge.transformer.PlayerTabTransformer;
|
||||||
import customskinloader.forge.transformer.SkinManagerTransformer;
|
import customskinloader.forge.transformer.SkinManagerTransformer;
|
||||||
import customskinloader.forge.transformer.SpectatorMenuTransformer;
|
import customskinloader.forge.transformer.SpectatorMenuTransformer;
|
||||||
import customskinloader.forge.transformer.TileEntitySkullTransformer;
|
|
||||||
import net.minecraft.launchwrapper.IClassTransformer;
|
import net.minecraft.launchwrapper.IClassTransformer;
|
||||||
import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
@@ -18,9 +18,14 @@ import org.objectweb.asm.tree.MethodNode;
|
|||||||
public class LaunchWrapper implements IClassTransformer {
|
public class LaunchWrapper implements IClassTransformer {
|
||||||
private static final TransformerManager.IClassTransformer[] CLASS_TRANSFORMERS = {
|
private static final TransformerManager.IClassTransformer[] CLASS_TRANSFORMERS = {
|
||||||
new FakeInterfacesTransformer.MinecraftTransformer(),
|
new FakeInterfacesTransformer.MinecraftTransformer(),
|
||||||
new FakeInterfacesTransformer.AbstractTextureTransfomer(),
|
new FakeInterfacesTransformer.ThreadDownloadImageDataTransformer(),
|
||||||
|
new FakeInterfacesTransformer.AbstractTextureTransformer(),
|
||||||
new FakeInterfacesTransformer.TextureTransformer(),
|
new FakeInterfacesTransformer.TextureTransformer(),
|
||||||
new FakeInterfacesTransformer.TextureManagerTransformer()
|
new FakeInterfacesTransformer.TextureManagerTransformer(),
|
||||||
|
new FakeInterfacesTransformer.ClientIResourceTransformer(),
|
||||||
|
new FakeInterfacesTransformer.ClientIResourceManagerTransformer(),
|
||||||
|
new FakeInterfacesTransformer.IResourceTransformer(),
|
||||||
|
new FakeInterfacesTransformer.IResourceManagerTransformer()
|
||||||
};
|
};
|
||||||
private static final TransformerManager.IMethodTransformer[] TRANFORMERS = {
|
private static final TransformerManager.IMethodTransformer[] TRANFORMERS = {
|
||||||
new SkinManagerTransformer.InitTransformer(),
|
new SkinManagerTransformer.InitTransformer(),
|
||||||
@@ -28,8 +33,7 @@ public class LaunchWrapper implements IClassTransformer {
|
|||||||
new SkinManagerTransformer.LoadProfileTexturesTransformer(),
|
new SkinManagerTransformer.LoadProfileTexturesTransformer(),
|
||||||
new SkinManagerTransformer.LoadSkinFromCacheTransformer(),
|
new SkinManagerTransformer.LoadSkinFromCacheTransformer(),
|
||||||
new PlayerTabTransformer.ScoreObjectiveTransformer(),
|
new PlayerTabTransformer.ScoreObjectiveTransformer(),
|
||||||
new SpectatorMenuTransformer.PlayerMenuObjectTransformer(),
|
new SpectatorMenuTransformer.PlayerMenuObjectTransformer()
|
||||||
new TileEntitySkullTransformer.UpdateGameProfileTransformer()
|
|
||||||
};
|
};
|
||||||
private TransformerManager transformerManager = new TransformerManager(CLASS_TRANSFORMERS, TRANFORMERS);
|
private TransformerManager transformerManager = new TransformerManager(CLASS_TRANSFORMERS, TRANFORMERS);
|
||||||
|
|
||||||
@@ -49,15 +53,18 @@ public class LaunchWrapper implements IClassTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Transform ClassNode
|
//Transform ClassNode
|
||||||
transformerManager.transform(cn);
|
cn = transformerManager.transform(cn, className);
|
||||||
|
ArrayList<MethodNode> methods = new ArrayList<>();
|
||||||
for (MethodNode mn : cn.methods) {
|
for (MethodNode mn : cn.methods) {
|
||||||
String methodName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(obfClassName, mn.name, mn.desc);
|
String mappedMethodName = TransformerManager.isDevelopmentEnvironment ? mn.name : TransformerManager.mapMethodName(cn.name, mn.name, mn.desc);
|
||||||
String methodDesc = FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(mn.desc);
|
String mappedMethodDesc = TransformerManager.isDevelopmentEnvironment ? mn.desc : TransformerManager.mapMethodDesc(mn.desc);
|
||||||
transformerManager.transform(cn, mn, className, methodName, methodDesc);
|
methods.add(transformerManager.transform(cn, mn, className, mappedMethodName, mappedMethodDesc));
|
||||||
}
|
}
|
||||||
|
cn.methods.clear();
|
||||||
|
cn.methods.addAll(methods);
|
||||||
|
|
||||||
//Parse Class Node to bytes
|
//Parse Class Node to bytes
|
||||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||||
cn.accept(cw);
|
cn.accept(cw);
|
||||||
return cw.toByteArray();
|
return cw.toByteArray();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package customskinloader.forge.platform;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import customskinloader.forge.ForgePlugin;
|
||||||
|
import net.minecraft.launchwrapper.ITweaker;
|
||||||
|
import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
|
||||||
|
import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||||
|
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
|
||||||
|
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||||
|
import org.objectweb.asm.commons.Remapper;
|
||||||
|
|
||||||
|
public class DefaultFMLPlatform implements IFMLPlatform {
|
||||||
|
private final static String FML_PLUGIN_WRAPPER = "net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result init(Set<IFMLPlatform> otherPlatforms) {
|
||||||
|
return otherPlatforms.size() == 0 ? Result.ACCEPT : Result.REJECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSide() {
|
||||||
|
return FMLLaunchHandler.side().name();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<String> getIgnoredMods() {
|
||||||
|
try {
|
||||||
|
return (List<String>) CoreModManager.class.getMethod("getLoadedCoremods").invoke(null); // 1.8
|
||||||
|
} catch (Exception e) {
|
||||||
|
return CoreModManager.getIgnoredMods(); // 1.8.8~1.12.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
Annotation name = this.getNameAnnotation();
|
||||||
|
if (name != null && !Strings.isNullOrEmpty(this.getNameValue(name))) {
|
||||||
|
return this.getNameValue(name);
|
||||||
|
}
|
||||||
|
return this.getFMLLoadingPluginClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSortingIndex() {
|
||||||
|
Annotation index = this.getSortingIndexAnnotation();
|
||||||
|
return index != null ? this.getSortingIndexValue(index) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITweaker createFMLPluginWrapper(String name, File location, int sortIndex) throws Exception {
|
||||||
|
Constructor<?> constructor = Class.forName(FML_PLUGIN_WRAPPER).getDeclaredConstructor(String.class, IFMLLoadingPlugin.class, File.class, int.class, String[].class);
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
return (ITweaker) constructor.newInstance(name, this.getFMLLoadingPluginClass().newInstance(), location, sortIndex, new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void addLoadPlugins(ITweaker tweaker) throws Exception {
|
||||||
|
Field field = CoreModManager.class.getDeclaredField("loadPlugins");
|
||||||
|
field.setAccessible(true);
|
||||||
|
((List<ITweaker>) field.get(null)).add(tweaker);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Remapper getRemapper() {
|
||||||
|
// DO NOT replace with lambda or replace call with method body.
|
||||||
|
return new Supplier<Remapper>() {
|
||||||
|
@Override
|
||||||
|
public Remapper get() {
|
||||||
|
return FMLDeobfuscatingRemapper.INSTANCE;
|
||||||
|
}
|
||||||
|
}.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<?> getFMLLoadingPluginClass() {
|
||||||
|
return ForgePlugin.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Annotation getNameAnnotation() {
|
||||||
|
return this.getFMLLoadingPluginClass().getAnnotation(IFMLLoadingPlugin.Name.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getNameValue(Annotation annotationIn) {
|
||||||
|
return ((IFMLLoadingPlugin.Name) annotationIn).value();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Annotation getSortingIndexAnnotation() {
|
||||||
|
return this.getFMLLoadingPluginClass().getAnnotation(IFMLLoadingPlugin.SortingIndex.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getSortingIndexValue(Annotation annotationIn) {
|
||||||
|
return ((IFMLLoadingPlugin.SortingIndex) annotationIn).value();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package customskinloader.forge.platform;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.CodeSource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import customskinloader.forge.ForgeTweaker;
|
||||||
|
import net.minecraft.launchwrapper.ITweaker;
|
||||||
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
import org.objectweb.asm.commons.Remapper;
|
||||||
|
|
||||||
|
public interface IFMLPlatform {
|
||||||
|
enum Result {
|
||||||
|
/**
|
||||||
|
* The platform container will be used.
|
||||||
|
*/
|
||||||
|
ACCEPT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The platform container won't be used.
|
||||||
|
*/
|
||||||
|
REJECT
|
||||||
|
}
|
||||||
|
|
||||||
|
class FMLPlatformInitializer {
|
||||||
|
private static IFMLPlatform platform;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static void initFMLPlatform() throws Exception {
|
||||||
|
Set<IFMLPlatform> platforms = new HashSet<>();
|
||||||
|
List<Throwable> throwables = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Iterator<IFMLPlatform> iterator = ServiceLoader.load(IFMLPlatform.class).iterator(); iterator.hasNext(); ) {
|
||||||
|
try {
|
||||||
|
platforms.add(iterator.next());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throwables.add(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IFMLPlatform platform0 : platforms) {
|
||||||
|
Set<IFMLPlatform> otherPlatforms = new HashSet<>(platforms);
|
||||||
|
otherPlatforms.remove(platform0);
|
||||||
|
if (platform0.init(otherPlatforms).equals(Result.ACCEPT)) {
|
||||||
|
if (platform == null) {
|
||||||
|
platform = platform0;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Duplicated platforms! (" + platform.getClass().getName() + ", " + platform0 + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (platform == null) {
|
||||||
|
for (int i = 0, len = throwables.size(); i < len; i++) {
|
||||||
|
Throwable throwable = throwables.get(i);
|
||||||
|
ForgeTweaker.logger.warning("Platform - %s :", i);
|
||||||
|
ForgeTweaker.logger.warning(throwable);
|
||||||
|
}
|
||||||
|
throw new RuntimeException("No available platform!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// CustomSkinLoader is a client side mod
|
||||||
|
if (!platform.getSide().equals("CLIENT")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeSource codeSource = FMLPlatformInitializer.class.getProtectionDomain().getCodeSource();
|
||||||
|
if (codeSource != null) {
|
||||||
|
URL location = codeSource.getLocation();
|
||||||
|
File file = new File(location.toURI());
|
||||||
|
if (file.isFile()) {
|
||||||
|
// This forces forge to reexamine the jar file for FML mods.
|
||||||
|
platform.getIgnoredMods().remove(file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
ITweaker tweaker = platform.createFMLPluginWrapper(platform.getName(), file, platform.getSortingIndex());
|
||||||
|
platform.addLoadPlugins(tweaker);
|
||||||
|
((List<ITweaker>) Launch.blackboard.get("Tweaks")).add(tweaker);
|
||||||
|
} else {
|
||||||
|
ForgeTweaker.logger.warning("No CodeSource, if this is not a development environment we might run into problems!");
|
||||||
|
ForgeTweaker.logger.warning(FMLPlatformInitializer.class.getProtectionDomain().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IFMLPlatform getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Result init(Set<IFMLPlatform> otherPlatforms);
|
||||||
|
|
||||||
|
String getSide();
|
||||||
|
|
||||||
|
List<String> getIgnoredMods();
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
int getSortingIndex();
|
||||||
|
|
||||||
|
ITweaker createFMLPluginWrapper(String name, File location, int sortIndex) throws Exception;
|
||||||
|
|
||||||
|
void addLoadPlugins(ITweaker tweaker) throws Exception;
|
||||||
|
|
||||||
|
Remapper getRemapper();
|
||||||
|
}
|
||||||
+123
@@ -0,0 +1,123 @@
|
|||||||
|
package customskinloader.forge.transformer;
|
||||||
|
|
||||||
|
import customskinloader.forge.TransformerManager;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.objectweb.asm.tree.FieldInsnNode;
|
||||||
|
import org.objectweb.asm.tree.InsnNode;
|
||||||
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
import org.objectweb.asm.tree.VarInsnNode;
|
||||||
|
|
||||||
|
public class FakeInterfacesTransformer {
|
||||||
|
public static class FakeInterfaceTransformer implements TransformerManager.IClassTransformer {
|
||||||
|
@Override
|
||||||
|
public ClassNode transform(ClassNode cn) {
|
||||||
|
if (cn.access == 0) {
|
||||||
|
cn.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT;
|
||||||
|
}
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.Minecraft"
|
||||||
|
)
|
||||||
|
public static class MinecraftTransformer implements TransformerManager.IClassTransformer {
|
||||||
|
@Override
|
||||||
|
public ClassNode transform(ClassNode cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeMinecraft");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.renderer.ThreadDownloadImageData"
|
||||||
|
)
|
||||||
|
public static class ThreadDownloadImageDataTransformer implements TransformerManager.IClassTransformer {
|
||||||
|
@Override
|
||||||
|
public ClassNode transform(ClassNode cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeThreadDownloadImageData");
|
||||||
|
|
||||||
|
MethodNode mn = new MethodNode(Opcodes.ACC_PUBLIC, "resetNewBufferedImage", "(Ljava/awt/image/BufferedImage;)V", null, null);
|
||||||
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.add(new InsnNode(Opcodes.ICONST_0));
|
||||||
|
mn.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, cn.name, TransformerManager.mapFieldName(cn.name, "field_110559_g", "Z"), "Z"));
|
||||||
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, cn.name, TransformerManager.mapFieldName(cn.name, "field_110560_d", "Ljava/awt/image/BufferedImage;"), "Ljava/awt/image/BufferedImage;"));
|
||||||
|
mn.instructions.add(new InsnNode(Opcodes.RETURN));
|
||||||
|
cn.methods.add(mn);
|
||||||
|
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.renderer.texture.AbstractTexture"
|
||||||
|
)
|
||||||
|
public static class AbstractTextureTransformer implements TransformerManager.IClassTransformer {
|
||||||
|
@Override
|
||||||
|
public ClassNode transform(ClassNode cn) {
|
||||||
|
cn.interfaces.add("net/minecraft/client/renderer/texture/Texture");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.renderer.texture.Texture"
|
||||||
|
)
|
||||||
|
public static class TextureTransformer extends FakeInterfacesTransformer.FakeInterfaceTransformer {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.renderer.texture.TextureManager"
|
||||||
|
)
|
||||||
|
public static class TextureManagerTransformer implements TransformerManager.IClassTransformer {
|
||||||
|
@Override
|
||||||
|
public ClassNode transform(ClassNode cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager$V1");
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager$V2");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.resources.IResource"
|
||||||
|
)
|
||||||
|
public static class ClientIResourceTransformer implements TransformerManager.IClassTransformer {
|
||||||
|
@Override
|
||||||
|
public ClassNode transform(ClassNode cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResource$V1");
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResource$V2");
|
||||||
|
cn.interfaces.add("net/minecraft/resources/IResource");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.resources.IResourceManager"
|
||||||
|
)
|
||||||
|
public static class ClientIResourceManagerTransformer implements TransformerManager.IClassTransformer {
|
||||||
|
@Override
|
||||||
|
public ClassNode transform(ClassNode cn) {
|
||||||
|
cn.interfaces.add("customskinloader/fake/itf/IFakeIResourceManager");
|
||||||
|
cn.interfaces.add("net/minecraft/resources/IResourceManager");
|
||||||
|
return cn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.resources.IResource"
|
||||||
|
)
|
||||||
|
public static class IResourceTransformer extends FakeInterfacesTransformer.FakeInterfaceTransformer {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.resources.IResourceManager"
|
||||||
|
)
|
||||||
|
public static class IResourceManagerTransformer extends FakeInterfacesTransformer.FakeInterfaceTransformer {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package customskinloader.forge.transformer;
|
||||||
|
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import customskinloader.forge.TransformerManager;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.objectweb.asm.tree.InsnNode;
|
||||||
|
import org.objectweb.asm.tree.MethodInsnNode;
|
||||||
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
|
public class PlayerTabTransformer {
|
||||||
|
@TransformerManager.TransformTarget(className = "net.minecraft.client.gui.GuiPlayerTabOverlay",
|
||||||
|
methodNameSrg = "func_175249_a",
|
||||||
|
methodNames = "renderPlayerlist",
|
||||||
|
desc = "(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V")
|
||||||
|
public static class ScoreObjectiveTransformer implements TransformerManager.IMethodTransformer {
|
||||||
|
//From: http://git.oschina.net/AsteriskTeam/TabIconHackForge/blob/master/src/main/java/kengxxiao/tabiconhack/coremod/TabIconHackForgeClassTransformer.java#L30-L43
|
||||||
|
@Override
|
||||||
|
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||||
|
for (ListIterator<AbstractInsnNode> iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
AbstractInsnNode node = iterator.next();
|
||||||
|
if (node.getOpcode() == Opcodes.INVOKEVIRTUAL) {
|
||||||
|
MethodInsnNode min = (MethodInsnNode) node;
|
||||||
|
if (TransformerManager.checkClassName(min.owner, "net/minecraft/client/Minecraft") && TransformerManager.checkMethodName(min.owner, min.name, min.desc, "func_71387_A") && TransformerManager.checkMethodDesc(min.desc, "()Z")) {
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.POP));
|
||||||
|
mn.instructions.set(node, new InsnNode(Opcodes.ICONST_1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package customskinloader.forge.transformer;
|
||||||
|
|
||||||
|
import customskinloader.forge.TransformerManager;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.objectweb.asm.tree.FieldInsnNode;
|
||||||
|
import org.objectweb.asm.tree.FieldNode;
|
||||||
|
import org.objectweb.asm.tree.FrameNode;
|
||||||
|
import org.objectweb.asm.tree.InsnList;
|
||||||
|
import org.objectweb.asm.tree.InsnNode;
|
||||||
|
import org.objectweb.asm.tree.MethodInsnNode;
|
||||||
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
import org.objectweb.asm.tree.TypeInsnNode;
|
||||||
|
import org.objectweb.asm.tree.VarInsnNode;
|
||||||
|
|
||||||
|
public class SkinManagerTransformer {
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.resources.SkinManager",
|
||||||
|
methodNameSrg = "<init>",
|
||||||
|
desc = "(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V"
|
||||||
|
)
|
||||||
|
public static class InitTransformer implements TransformerManager.IMethodTransformer {
|
||||||
|
@Override
|
||||||
|
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||||
|
cn.fields.removeIf(fn -> fn.name.equals("fakeManager") && fn.desc.equals("Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
cn.fields.add(new FieldNode(Opcodes.ACC_PRIVATE, "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;", null, null));
|
||||||
|
|
||||||
|
for (AbstractInsnNode ain : mn.instructions.toArray()) {
|
||||||
|
if (ain.getOpcode() == Opcodes.RETURN) {
|
||||||
|
InsnList il = new InsnList();
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
il.add(new TypeInsnNode(Opcodes.NEW, "customskinloader/fake/FakeSkinManager"));
|
||||||
|
il.add(new InsnNode(Opcodes.DUP));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 3));
|
||||||
|
il.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "customskinloader/fake/FakeSkinManager", "<init>", "(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V", false));
|
||||||
|
il.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
mn.instructions.insert(il);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.resources.SkinManager",
|
||||||
|
methodNameSrg = "func_152789_a",
|
||||||
|
methodNames = "loadSkin",
|
||||||
|
desc = "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;"
|
||||||
|
)
|
||||||
|
public static class LoadSkinTransformer implements TransformerManager.IMethodTransformer {
|
||||||
|
@Override
|
||||||
|
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||||
|
InsnList il = new InsnList();
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
il.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 3));
|
||||||
|
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadSkin", "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;", false));
|
||||||
|
il.add(new InsnNode(Opcodes.ARETURN));
|
||||||
|
il.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||||
|
mn.instructions.insert(il);
|
||||||
|
return mn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.resources.SkinManager",
|
||||||
|
methodNameSrg = "func_152790_a",
|
||||||
|
methodNames = "loadProfileTextures",
|
||||||
|
desc = "(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V"
|
||||||
|
)
|
||||||
|
public static class LoadProfileTexturesTransformer implements TransformerManager.IMethodTransformer {
|
||||||
|
@Override
|
||||||
|
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||||
|
InsnList il = new InsnList();
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
il.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 2));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ILOAD, 3));
|
||||||
|
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadProfileTextures", "(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V", false));
|
||||||
|
il.add(new InsnNode(Opcodes.RETURN));
|
||||||
|
il.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||||
|
mn.instructions.insert(il);
|
||||||
|
return mn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TransformerManager.TransformTarget(
|
||||||
|
className = "net.minecraft.client.resources.SkinManager",
|
||||||
|
methodNameSrg = "func_152788_a",
|
||||||
|
methodNames = "loadSkinFromCache",
|
||||||
|
desc = "(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;"
|
||||||
|
)
|
||||||
|
public static class LoadSkinFromCacheTransformer implements TransformerManager.IMethodTransformer {
|
||||||
|
@Override
|
||||||
|
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||||
|
InsnList il = new InsnList();
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
il.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "customskinloader/fake/FakeSkinManager", "loadSkinFromCache", "(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;", false));
|
||||||
|
il.add(new InsnNode(Opcodes.ARETURN));
|
||||||
|
il.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||||
|
mn.instructions.insert(il);
|
||||||
|
return mn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-8
@@ -3,7 +3,6 @@ package customskinloader.forge.transformer;
|
|||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
|
||||||
import customskinloader.forge.TransformerManager;
|
import customskinloader.forge.TransformerManager;
|
||||||
import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
@@ -11,20 +10,17 @@ import org.objectweb.asm.tree.InsnList;
|
|||||||
import org.objectweb.asm.tree.MethodInsnNode;
|
import org.objectweb.asm.tree.MethodInsnNode;
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
import customskinloader.forge.TransformerManager.IMethodTransformer;
|
|
||||||
import customskinloader.forge.TransformerManager.TransformTarget;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transformer of Spectator Menu for 1.13-
|
* Transformer of Spectator Menu for 1.13-
|
||||||
*/
|
*/
|
||||||
public class SpectatorMenuTransformer {
|
public class SpectatorMenuTransformer {
|
||||||
@TransformTarget(className = "net.minecraft.client.gui.spectator.PlayerMenuObject",
|
@TransformerManager.TransformTarget(className = "net.minecraft.client.gui.spectator.PlayerMenuObject",
|
||||||
methodNames = {"<init>"},
|
methodNameSrg = "<init>",
|
||||||
desc = "(Lcom/mojang/authlib/GameProfile;)V")
|
desc = "(Lcom/mojang/authlib/GameProfile;)V")
|
||||||
public static class PlayerMenuObjectTransformer implements IMethodTransformer {
|
public static class PlayerMenuObjectTransformer implements TransformerManager.IMethodTransformer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transform(ClassNode cn, MethodNode mn) {
|
public MethodNode transform(ClassNode cn, MethodNode mn) {
|
||||||
InsnList il = mn.instructions;
|
InsnList il = mn.instructions;
|
||||||
ListIterator<AbstractInsnNode> li = il.iterator();
|
ListIterator<AbstractInsnNode> li = il.iterator();
|
||||||
|
|
||||||
@@ -50,6 +46,7 @@ public class SpectatorMenuTransformer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return mn;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package net.minecraft.client.resources;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
// exclude
|
||||||
|
public class SkinManager {
|
||||||
|
public SkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) { }
|
||||||
|
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, MinecraftProfileTexture.Type textureType) { return null; }
|
||||||
|
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final MinecraftProfileTexture.Type textureType, final SkinManager.SkinAvailableCallback skinAvailableCallback) { return null; }
|
||||||
|
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure) { }
|
||||||
|
public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile) { return null; }
|
||||||
|
|
||||||
|
// put into mod jar to prevent https://github.com/cpw/modlauncher/issues/39
|
||||||
|
public interface SkinAvailableCallback {
|
||||||
|
default void skinAvailable(MinecraftProfileTexture.Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
||||||
|
this.onSkinTextureAvailable(typeIn, location, profileTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onSkinTextureAvailable(MinecraftProfileTexture.Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
||||||
|
((SkinManager.ISkinAvailableCallback) this).onSkinTextureAvailable(typeIn, location, profileTexture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// exclude
|
||||||
|
public interface ISkinAvailableCallback {
|
||||||
|
void onSkinTextureAvailable(MinecraftProfileTexture.Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
jcenter()
|
|
||||||
maven {
|
|
||||||
name = "forge"
|
|
||||||
url = "http://files.minecraftforge.net/maven"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
|
||||||
|
|
||||||
ext.configFile = file "build.properties"
|
|
||||||
configFile.withReader {
|
|
||||||
def prop = new Properties()
|
|
||||||
prop.load(it)
|
|
||||||
project.ext.config = new ConfigSlurper().parse prop
|
|
||||||
}
|
|
||||||
apply from: rootProject.file("BuildScripts/version.gradle")
|
|
||||||
|
|
||||||
archivesBaseName = "CustomSkinLoader_Forge"
|
|
||||||
version = getCSLVersion()
|
|
||||||
group = "customskinloader"
|
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = 1.8
|
|
||||||
compileJava {
|
|
||||||
sourceCompatibility = targetCompatibility = 1.8
|
|
||||||
}
|
|
||||||
jar {
|
|
||||||
manifest {
|
|
||||||
attributes([
|
|
||||||
"FMLCorePlugin" : "customskinloader.forge.ForgePlugin",
|
|
||||||
"FMLCorePluginContainsFMLMod": true,
|
|
||||||
"Specification-Title" : "CustomSkinLoader",
|
|
||||||
"Specification-Vendor" : "xfl03",
|
|
||||||
"Specification-Version" : "1",
|
|
||||||
"Implementation-Title" : "CustomSkinLoader",
|
|
||||||
"Implementation-Version" : "${version}",
|
|
||||||
"Implementation-Vendor" : "xfl03",
|
|
||||||
"Implementation-Timestamp" : new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
|
||||||
])
|
|
||||||
}
|
|
||||||
exclude 'net/minecraft/client/renderer/texture/**'
|
|
||||||
exclude 'net/minecraftforge/**'
|
|
||||||
}
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
java {
|
|
||||||
//Common
|
|
||||||
srcDir "${rootDir}/Common/source"
|
|
||||||
//Forge
|
|
||||||
srcDir "source"
|
|
||||||
}
|
|
||||||
resources {
|
|
||||||
//Common
|
|
||||||
srcDir "${rootDir}/Common/resource"
|
|
||||||
exclude "Profile.json"
|
|
||||||
//Forge
|
|
||||||
srcDir "resource"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
minecraft {
|
|
||||||
version = config.forge_mc_version + "-" + config.forge_version
|
|
||||||
runDir = "run"
|
|
||||||
mappings = config.mappings_version
|
|
||||||
clientJvmArgs += "-Dfml.coreMods.load=customskinloader.forge.ForgePlugin"
|
|
||||||
|
|
||||||
replace '@MOD_VERSION@', rootProject.ext.config.version
|
|
||||||
replace '@MOD_FULL_VERSION@', project.version
|
|
||||||
replaceIn 'CustomSkinLoader.java'
|
|
||||||
replaceIn 'ForgeMod.java'
|
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
|
||||||
filesNotMatching("**/*.js"){
|
|
||||||
expand([
|
|
||||||
modVersion : rootProject.ext.config.version,
|
|
||||||
modFullVersion: project.version,
|
|
||||||
mcVersion : config.minecraft_version,
|
|
||||||
mcFullVersions: config.minecraft_full_versions,
|
|
||||||
forgeVersion : config.forge_version,
|
|
||||||
gitVersion : System.getenv("CIRCLE_SHA1"),
|
|
||||||
buildUrl : System.getenv("CIRCLE_BUILD_URL"),
|
|
||||||
releaseTime : new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
|
||||||
])}
|
|
||||||
}
|
|
||||||
|
|
||||||
task signJar(type: SignJar, dependsOn: reobfJar) {
|
|
||||||
onlyIf { System.getenv("KEY_PASS") != null }
|
|
||||||
doLast { System.out.println("Jar will be signed.") }
|
|
||||||
|
|
||||||
inputFile = jar.archivePath
|
|
||||||
outputFile = jar.archivePath
|
|
||||||
|
|
||||||
keyStore = 'CustomSkinLoader.jks'
|
|
||||||
alias = 'CustomSkinLoader'
|
|
||||||
storePass = System.getenv("KEY_PASS")
|
|
||||||
keyPass = System.getenv("KEY_PASS")
|
|
||||||
}
|
|
||||||
build.dependsOn signJar
|
|
||||||
|
|
||||||
task afterBuild {
|
|
||||||
doLast {
|
|
||||||
//copyBuildFile
|
|
||||||
copy {
|
|
||||||
from "build/libs"
|
|
||||||
into "${rootDir}/build/libs"
|
|
||||||
include "**/*.jar"
|
|
||||||
exclude "**/*-sources.jar"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
build.finalizedBy afterBuild
|
|
||||||
|
|
||||||
|
|
||||||
apply plugin: 'maven-publish'
|
|
||||||
publishing {
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
name = "GitHubPackages"
|
|
||||||
url = uri("https://maven.pkg.github.com/xfl03/MCCustomSkinLoader")
|
|
||||||
credentials {
|
|
||||||
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
|
|
||||||
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
publications {
|
|
||||||
gpr(MavenPublication) {
|
|
||||||
groupId 'customskinloader'
|
|
||||||
artifactId project.archivesBaseName
|
|
||||||
from(components.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tasks.withType(PublishToMavenRepository) {
|
|
||||||
onlyIf { System.getenv("GITHUB_TOKEN") != null }
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
var FieldInsnNode = Java.type('org.objectweb.asm.tree.FieldInsnNode');
|
|
||||||
var InsnList = Java.type('org.objectweb.asm.tree.InsnList');
|
|
||||||
var InsnNode = Java.type('org.objectweb.asm.tree.InsnNode');
|
|
||||||
var MethodInsnNode = Java.type('org.objectweb.asm.tree.MethodInsnNode');
|
|
||||||
var VarInsnNode = Java.type('org.objectweb.asm.tree.VarInsnNode');
|
|
||||||
|
|
||||||
var Opcodes = Java.type('org.objectweb.asm.Opcodes');
|
|
||||||
|
|
||||||
function initializeCoreMod() {
|
|
||||||
return {
|
|
||||||
'PlayerTabTransformer': {
|
|
||||||
'target': {
|
|
||||||
'type': 'CLASS',
|
|
||||||
'names': function (target) {
|
|
||||||
return ['net/minecraft/client/gui/GuiPlayerTabOverlay', 'net/minecraft/client/gui/overlay/PlayerTabOverlayGui'];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'transformer': function (cn) {
|
|
||||||
cn.methods.forEach(function (mn) {
|
|
||||||
if (mn.name === 'func_175249_a' || mn.name === 'func_238523_a_') {
|
|
||||||
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
|
||||||
var node = iterator.next();
|
|
||||||
if (node.getOpcode() === Opcodes.INVOKEVIRTUAL && node.name === "func_71387_A") {
|
|
||||||
mn.instructions.insertBefore(node, new InsnNode(Opcodes.POP));
|
|
||||||
mn.instructions.set(node, new InsnNode(Opcodes.ICONST_1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return cn;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'TileEntitySkullTransformer': {
|
|
||||||
'target': {
|
|
||||||
'type': 'CLASS',
|
|
||||||
'names': function (target) {
|
|
||||||
return ['net/minecraft/tileentity/TileEntitySkull', 'net/minecraft/tileentity/SkullTileEntity'];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'transformer': function (cn) {
|
|
||||||
cn.methods.forEach(function (mn) {
|
|
||||||
if (mn.name === 'func_174884_b') {
|
|
||||||
var il = new InsnList();
|
|
||||||
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
|
||||||
il.add(new InsnNode(Opcodes.ARETURN));
|
|
||||||
mn.instructions.insert(il);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return cn;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// For 1.13+
|
|
||||||
'AbstractTextureTransformer': {
|
|
||||||
'target': {
|
|
||||||
'type': 'CLASS',
|
|
||||||
'name': 'net/minecraft/client/renderer/texture/AbstractTexture'
|
|
||||||
},
|
|
||||||
'transformer': function (cn) {
|
|
||||||
cn.interfaces.add("net/minecraft/client/renderer/texture/Texture");
|
|
||||||
return cn;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'TextureTransformer': {
|
|
||||||
'target': {
|
|
||||||
'type': 'CLASS',
|
|
||||||
'name': 'net/minecraft/client/renderer/texture/Texture'
|
|
||||||
},
|
|
||||||
'transformer': function (cn) {
|
|
||||||
if (cn.access === 0) {
|
|
||||||
cn.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT;
|
|
||||||
}
|
|
||||||
return cn;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// For 1.14+
|
|
||||||
'MinecraftTransformer': {
|
|
||||||
'target': {
|
|
||||||
'type': 'CLASS',
|
|
||||||
'name': 'net/minecraft/client/Minecraft'
|
|
||||||
},
|
|
||||||
'transformer': function (cn) {
|
|
||||||
cn.interfaces.add("customskinloader/fake/itf/IFakeMinecraft");
|
|
||||||
return cn;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// For 1.15+
|
|
||||||
'TextureManagerTransformer': {
|
|
||||||
'target': {
|
|
||||||
'type': 'CLASS',
|
|
||||||
'name': 'net/minecraft/client/renderer/texture/TextureManager'
|
|
||||||
},
|
|
||||||
'transformer': function (cn) {
|
|
||||||
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager_1");
|
|
||||||
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager_2");
|
|
||||||
return cn;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'DownloadingTextureTransformer': {
|
|
||||||
'target': {
|
|
||||||
'type': 'CLASS',
|
|
||||||
'name': 'net/minecraft/client/renderer/texture/DownloadingTexture'
|
|
||||||
},
|
|
||||||
'transformer': function (cn) {
|
|
||||||
cn.methods.forEach(function (mn) {
|
|
||||||
if (mn.name === 'func_229159_a_') {
|
|
||||||
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
|
||||||
var node = iterator.next();
|
|
||||||
if (node.getOpcode() === Opcodes.INVOKESTATIC && node.name === "func_229163_c_") {
|
|
||||||
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 0));
|
|
||||||
mn.instructions.insertBefore(node, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/renderer/texture/DownloadingTexture", "field_229155_i_", "Ljava/lang/Runnable;"));
|
|
||||||
iterator.set(new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinBuffer", "processLegacySkin", "(Lnet/minecraft/client/renderer/texture/NativeImage;Ljava/lang/Runnable;)Lnet/minecraft/client/renderer/texture/NativeImage;", false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return cn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
package customskinloader.forge;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import customskinloader.Logger;
|
|
||||||
import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
|
||||||
|
|
||||||
public class TransformerManager {
|
|
||||||
public static Logger logger = new Logger(new File("./CustomSkinLoader/ForgePlugin.log"));
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
public @interface TransformTarget {
|
|
||||||
String className();
|
|
||||||
|
|
||||||
String[] methodNames() default {};
|
|
||||||
|
|
||||||
String desc() default "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IClassTransformer {
|
|
||||||
void transform(ClassNode cn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IMethodTransformer {
|
|
||||||
void transform(ClassNode cn, MethodNode mn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, IClassTransformer> classMap = new HashMap<>();
|
|
||||||
public Map<String, Map<String, IMethodTransformer>> map = new HashMap<>();
|
|
||||||
|
|
||||||
public TransformerManager(IMethodTransformer... methodTransformers) {
|
|
||||||
this(new IClassTransformer[0], methodTransformers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransformerManager(IClassTransformer[] classTransformers, IMethodTransformer[] methodTransformers) {
|
|
||||||
for (IClassTransformer t : classTransformers) {
|
|
||||||
TransformTarget tt = this.getTransformTarget(t.getClass());
|
|
||||||
if (tt != null) {
|
|
||||||
addClassTransformer(tt.className(), t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (IMethodTransformer t : methodTransformers) {
|
|
||||||
TransformTarget tt = this.getTransformTarget(t.getClass());
|
|
||||||
if (tt != null) {
|
|
||||||
addMethodTransformer(tt, tt.className(), t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private TransformTarget getTransformTarget(Class<?> cl) {
|
|
||||||
logger.info("[CSL DEBUG] REGISTERING TRANSFORMER %s", cl.getName());
|
|
||||||
if (!cl.isAnnotationPresent(TransformTarget.class)) {
|
|
||||||
logger.info("[CSL DEBUG] ERROR occurs while parsing Annotation.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return cl.getAnnotation(TransformTarget.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addClassTransformer(String className, IClassTransformer transformer) {
|
|
||||||
if (!classMap.containsKey(className)) {
|
|
||||||
classMap.put(className, transformer);
|
|
||||||
logger.info("[CSL DEBUG] REGISTERING CLASS %s", className);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addMethodTransformer(TransformTarget target, String className, IMethodTransformer transformer) {
|
|
||||||
if (!map.containsKey(className))
|
|
||||||
map.put(className, new HashMap<String, IMethodTransformer>());
|
|
||||||
for (String methodName : target.methodNames()) {
|
|
||||||
map.get(className).put(methodName + target.desc(), transformer);
|
|
||||||
logger.info("[CSL DEBUG] REGISTERING METHOD %s(%s)", className, methodName + target.desc());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassNode transform(ClassNode classNode) {
|
|
||||||
IClassTransformer transformer = classMap.get(FMLDeobfuscatingRemapper.INSTANCE.map(classNode.name).replace("/", "."));
|
|
||||||
if (transformer != null) {
|
|
||||||
try {
|
|
||||||
transformer.transform(classNode);
|
|
||||||
logger.info("[CSL DEBUG] Successfully transformed class %s", classNode.name);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warning("[CSL DEBUG] An error happened when transforming class %s.", classNode.name);
|
|
||||||
logger.warning(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return classNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodNode transform(ClassNode classNode, MethodNode methodNode, String className, String methodName, String methodDesc) {
|
|
||||||
Map<String, IMethodTransformer> transMap = map.get(className);
|
|
||||||
String methodTarget = methodName + methodDesc;
|
|
||||||
if (transMap != null && transMap.containsKey(methodTarget)) {
|
|
||||||
try {
|
|
||||||
transMap.get(methodTarget).transform(classNode, methodNode);
|
|
||||||
logger.info("[CSL DEBUG] Successfully transformed method %s in class %s", methodName, className);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warning("[CSL DEBUG] An error happened when transforming method %s in class %s.", methodTarget, className);
|
|
||||||
logger.warning(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return methodNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package customskinloader.forge.loader;
|
|
||||||
|
|
||||||
import customskinloader.forge.TransformerManager;
|
|
||||||
import customskinloader.forge.transformer.FakeSkinManagerTransformer;
|
|
||||||
import customskinloader.forge.transformer.PlayerTabTransformer;
|
|
||||||
import customskinloader.forge.transformer.SkinManagerTransformer;
|
|
||||||
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ModLauncher for 1.13+
|
|
||||||
* @deprecated Use JavaScript Instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class ModLauncher {
|
|
||||||
|
|
||||||
private static final TransformerManager.IMethodTransformer[] TRANFORMERS = {
|
|
||||||
new SkinManagerTransformer.InitTransformer(),
|
|
||||||
new SkinManagerTransformer.LoadSkinTransformer(),
|
|
||||||
new SkinManagerTransformer.LoadProfileTexturesTransformer(),
|
|
||||||
new SkinManagerTransformer.LoadSkinFromCacheTransformer(),
|
|
||||||
new PlayerTabTransformer.ScoreObjectiveTransformer(),
|
|
||||||
new FakeSkinManagerTransformer.InitTransformer()
|
|
||||||
};
|
|
||||||
private TransformerManager transformerManager = new TransformerManager(TRANFORMERS);
|
|
||||||
|
|
||||||
public ClassNode transform(ClassNode input) {
|
|
||||||
for (MethodNode mn : input.methods) {
|
|
||||||
transformerManager.transform(input, mn, input.name, mn.name, mn.desc);
|
|
||||||
}
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Singleton
|
|
||||||
private volatile static ModLauncher INSTANCE = null;
|
|
||||||
|
|
||||||
public static ModLauncher instance() {
|
|
||||||
if (INSTANCE == null) {
|
|
||||||
synchronized (ModLauncher.class) {
|
|
||||||
if (INSTANCE == null) {
|
|
||||||
INSTANCE = new ModLauncher();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package customskinloader.forge.transformer;
|
|
||||||
|
|
||||||
import customskinloader.forge.TransformerManager;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
|
|
||||||
public class FakeInterfacesTransformer {
|
|
||||||
@TransformerManager.TransformTarget(
|
|
||||||
className = "net.minecraft.client.Minecraft"
|
|
||||||
)
|
|
||||||
public static class MinecraftTransformer implements TransformerManager.IClassTransformer {
|
|
||||||
@Override
|
|
||||||
public void transform(ClassNode cn) {
|
|
||||||
cn.interfaces.add("customskinloader/fake/itf/IFakeMinecraft");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TransformerManager.TransformTarget(
|
|
||||||
className = "net.minecraft.client.renderer.texture.AbstractTexture"
|
|
||||||
)
|
|
||||||
public static class AbstractTextureTransfomer implements TransformerManager.IClassTransformer {
|
|
||||||
@Override
|
|
||||||
public void transform(ClassNode cn) {
|
|
||||||
cn.interfaces.add("net/minecraft/client/renderer/texture/Texture");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TransformerManager.TransformTarget(
|
|
||||||
className = "net.minecraft.client.renderer.texture.Texture"
|
|
||||||
)
|
|
||||||
public static class TextureTransformer implements TransformerManager.IClassTransformer {
|
|
||||||
@Override
|
|
||||||
public void transform(ClassNode cn) {
|
|
||||||
if (cn.access == 0) {
|
|
||||||
cn.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TransformerManager.TransformTarget(
|
|
||||||
className = "net.minecraft.client.renderer.texture.TextureManager"
|
|
||||||
)
|
|
||||||
public static class TextureManagerTransformer implements TransformerManager.IClassTransformer {
|
|
||||||
@Override
|
|
||||||
public void transform(ClassNode cn) {
|
|
||||||
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager_1");
|
|
||||||
cn.interfaces.add("customskinloader/fake/itf/IFakeTextureManager_2");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package customskinloader.forge.transformer;
|
|
||||||
|
|
||||||
import customskinloader.forge.TransformerManager;
|
|
||||||
import customskinloader.forge.TransformerManager.IMethodTransformer;
|
|
||||||
import customskinloader.forge.TransformerManager.TransformTarget;
|
|
||||||
|
|
||||||
import org.objectweb.asm.tree.*;
|
|
||||||
|
|
||||||
import java.util.ListIterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transformer of FakeSkinManager for 1.13+
|
|
||||||
* @deprecated Use JavaScript Instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class FakeSkinManagerTransformer {
|
|
||||||
private final static String TARGET_CLASS = "net/minecraft/client/renderer/ThreadDownloadImageData";
|
|
||||||
private final static String NEW_TARGET_CLASS = "net/minecraft/client/renderer/texture/ThreadDownloadImageData";
|
|
||||||
private final static String CALLBACK_CLASS = "net/minecraft/client/resources/SkinManager$SkinAvailableCallback";
|
|
||||||
|
|
||||||
|
|
||||||
@TransformTarget(className = "customskinloader.fake.FakeSkinManager",
|
|
||||||
methodNames = {"<init>"},
|
|
||||||
desc = "(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V")
|
|
||||||
public static class InitTransformer implements IMethodTransformer {
|
|
||||||
@Override
|
|
||||||
public void transform(ClassNode cn, MethodNode mn) {
|
|
||||||
TransformerManager.logger.info("1.13 detected, FakeSkinManager will be transformed.");
|
|
||||||
//ClassNameRemapper.remapClassName(cn, TARGET_CLASS, NEW_TARGET_CLASS);
|
|
||||||
//MethodNameRemapper.remapMethodName(cn, CALLBACK_CLASS, "func_180521_a", "onSkinTextureAvailable");
|
|
||||||
|
|
||||||
InsnList il = mn.instructions;
|
|
||||||
ListIterator<AbstractInsnNode> li = il.iterator();
|
|
||||||
while (li.hasNext()) {
|
|
||||||
AbstractInsnNode ain = li.next();
|
|
||||||
if (ain instanceof MethodInsnNode) {
|
|
||||||
MethodInsnNode min = (MethodInsnNode) ain;
|
|
||||||
|
|
||||||
if (min.owner.equals(TARGET_CLASS)) {
|
|
||||||
min.owner = NEW_TARGET_CLASS;
|
|
||||||
//il.set(min, new MethodInsnNode(min.getOpcode(), NEW_TARGET_CLASS, min.name, min.desc, false));
|
|
||||||
}
|
|
||||||
if (min.owner.equals(CALLBACK_CLASS) && min.name.equals("func_180521_a")) {
|
|
||||||
min.name = "onSkinTextureAvailable";
|
|
||||||
//il.set(min, new MethodInsnNode(min.getOpcode(), min.owner, "onSkinTextureAvailable", min.desc, false));
|
|
||||||
}
|
|
||||||
} else if (ain instanceof TypeInsnNode) {
|
|
||||||
TypeInsnNode tin = (TypeInsnNode) ain;
|
|
||||||
|
|
||||||
if (tin.desc.equals(TARGET_CLASS)) {
|
|
||||||
tin.desc = NEW_TARGET_CLASS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loaded 100 of 180 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user