mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-25 04:04:25 +00:00
Compare commits
283
Commits
14.7
..
14-develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
299c8f53cf | ||
|
|
13fb0a4f92 | ||
|
|
921374f24f | ||
|
|
d2d244c70e | ||
|
|
f201f344a2 | ||
|
|
76d6ed9a41 | ||
|
|
b807aa1fb1 | ||
|
|
d797ed378a | ||
|
|
c3f8f1eb8f | ||
|
|
226d953012 | ||
|
|
d1ab2fbf43 | ||
|
|
00a14010c6 | ||
|
|
a198e40fc7 | ||
|
|
5b820c537d | ||
|
|
6e1be02cf0 | ||
|
|
9abf9eb779 | ||
|
|
fbc95314ad | ||
|
|
d4576249ac | ||
|
|
dfe47f7c64 | ||
|
|
1199e10ca4 | ||
|
|
61287cf64c | ||
|
|
b16058340c | ||
|
|
ac09a51f48 | ||
|
|
3e5bd83b5c | ||
|
|
4ce00d07b5 | ||
|
|
6e9380be49 | ||
|
|
53050a63f5 | ||
|
|
34ac3ac4f2 | ||
|
|
f5b1989453 | ||
|
|
85923855d8 | ||
|
|
c8e96c11cd | ||
|
|
32e3e2e5a2 | ||
|
|
b7b5e9d6c8 | ||
|
|
dfa7db1731 | ||
|
|
b645fd1665 | ||
|
|
28fc81cb9a | ||
|
|
bb0a47de4b | ||
|
|
d09b1d9807 | ||
|
|
c207bdfc0e | ||
|
|
69d35a69b7 | ||
|
|
d767f40d32 | ||
|
|
5329a27d1a | ||
|
|
ddefe00ac0 | ||
|
|
dd4b706827 | ||
|
|
84072c62f3 | ||
|
|
2d00e12f0a | ||
|
|
b2b56f5be5 | ||
|
|
43c8ceb21e | ||
|
|
a0ad239770 | ||
|
|
c8f0f7e283 | ||
|
|
bfbd6ee31a | ||
|
|
f8f3caad39 | ||
|
|
bd409ae169 | ||
|
|
82f0aad9ff | ||
|
|
f2fce38137 | ||
|
|
7d19f3114c | ||
|
|
d7a1e0f31f | ||
|
|
201210f567 | ||
|
|
26ed002689 | ||
|
|
7d7e5c9060 | ||
|
|
81bf422250 | ||
|
|
776e31e158 | ||
|
|
4a92223158 | ||
|
|
264aacc8c0 | ||
|
|
0b000731b5 | ||
|
|
f0012b58df | ||
|
|
013c22ae95 | ||
|
|
01d02a27b0 | ||
|
|
077551e161 | ||
|
|
bd642d0106 | ||
|
|
fbec7ce6bb | ||
|
|
ea1b25a38f | ||
|
|
62018a3e8b | ||
|
|
f38a8ddcef | ||
|
|
63251c9f5e | ||
|
|
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 | ||
|
|
5ebee1f1e0 | ||
|
|
1eb8db550f | ||
|
|
52a232f982 | ||
|
|
eeebc30b58 | ||
|
|
46bccadca2 | ||
|
|
d7f207177c | ||
|
|
339e30247a | ||
|
|
ba8d86789d | ||
|
|
a9f19cfc8d | ||
|
|
8b1400ef0d | ||
|
|
82c2e80e76 | ||
|
|
8146773354 | ||
|
|
5ac6aa1865 | ||
|
|
dab8e3dd22 | ||
|
|
fdceb08a2c | ||
|
|
ad846f37a2 | ||
|
|
b8ce13606b | ||
|
|
2fbd3965e0 | ||
|
|
a714670b9a | ||
|
|
c5460624e3 | ||
|
|
9f63a770c3 | ||
|
|
4d234762d2 | ||
|
|
730b565c59 | ||
|
|
4d12d70bf0 | ||
|
|
42adcb5b27 | ||
|
|
77ddcc8bf5 | ||
|
|
d46adaac5e | ||
|
|
a6666b53a1 | ||
|
|
958860ecce | ||
|
|
6fab945eb1 | ||
|
|
e19b9d860f | ||
|
|
7adb0f9ef7 | ||
|
|
1bb130bb87 | ||
|
|
779e25f837 | ||
|
|
3a2d8f9caf | ||
|
|
0c91fb3975 | ||
|
|
290cbb63d8 | ||
|
|
100e661ac5 | ||
|
|
c490631f2c | ||
|
|
c519d09be4 | ||
|
|
e5a31ae49e | ||
|
|
68615ba724 | ||
|
|
10e57fe349 | ||
|
|
9f70ad0159 | ||
|
|
0d5538a110 | ||
|
|
27efbbfeb0 | ||
|
|
7fad8c602d | ||
|
|
29a0952bc4 | ||
|
|
b7107b7172 | ||
|
|
2adbc25f69 | ||
|
|
3bee9281ec | ||
|
|
917f9f650b | ||
|
|
edf6e241e4 | ||
|
|
d2c65f00c9 | ||
|
|
95ee345441 | ||
|
|
3ade4867d4 | ||
|
|
2d1951774d | ||
|
|
cc3616a074 | ||
|
|
42c48c5c2e | ||
|
|
030daf12a2 | ||
|
|
88763d64ef | ||
|
|
4f2b5edf84 | ||
|
|
cbe07b9003 | ||
|
|
b2867a0dbf | ||
|
|
65dacd8527 | ||
|
|
d2d425e96e | ||
|
|
0762e3e339 | ||
|
|
4cb1e348bb | ||
|
|
7bbfd19bfd | ||
|
|
be8b80bd55 | ||
|
|
47de6d3a89 | ||
|
|
f78a3b2565 | ||
|
|
016249c6ca | ||
|
|
860edd2e1a | ||
|
|
3e6e444857 | ||
|
|
d67b7c6296 | ||
|
|
94f6044c9a | ||
|
|
6b3531964e | ||
|
|
fbd06f147a | ||
|
|
e3020dad00 | ||
|
|
49fb976a2c | ||
|
|
78bc4b5f7e | ||
|
|
7a3dc4f9c2 | ||
|
|
2087f7bb94 | ||
|
|
e95edb16ac | ||
|
|
3b07b5ccca | ||
|
|
a3fb3cd770 | ||
|
|
b7b59c0b85 | ||
|
|
db6b54732e | ||
|
|
09e3b81552 | ||
|
|
2f494d295e | ||
|
|
e8e3a72ae7 | ||
|
|
ca8bd4e83d | ||
|
|
d789119c8f | ||
|
|
bfd1b41ecc | ||
|
|
5807acb34a | ||
|
|
f319d535ae | ||
|
|
f669d095b6 | ||
|
|
ca8b0ba185 | ||
|
|
7acef4d987 | ||
|
|
79404f659c | ||
|
|
85c86ff375 | ||
|
|
f4030701ee | ||
|
|
a36eca2a53 | ||
|
|
6ffdf2aafb | ||
|
|
fba9f7ca28 | ||
|
|
2d157e3d5b | ||
|
|
055aef17db | ||
|
|
622e834d26 | ||
|
|
469c8b62a9 | ||
|
|
1558ec819a | ||
|
|
883e7b45fc | ||
|
|
f30d3319b0 | ||
|
|
58276a7a0c | ||
|
|
883fb39380 | ||
|
|
1358a99f51 | ||
|
|
47ea01dc39 | ||
|
|
ee36f2f42a | ||
|
|
5868a39adb | ||
|
|
f7e000cb82 | ||
|
|
c40bb38e20 | ||
|
|
4449ccdd45 | ||
|
|
67e56957e7 | ||
|
|
ea432f2405 | ||
|
|
eee978fc83 | ||
|
|
9698d4098a | ||
|
|
3f779c9028 | ||
|
|
3945599fb4 | ||
|
|
b50e6a934f |
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Telegram
|
||||||
|
url: https://t.me/customskinloader
|
||||||
|
about: Gugugu
|
||||||
|
- name: QQ
|
||||||
|
url: https://jq.qq.com/?_wv=1027&k=vF16R5tg
|
||||||
|
about: Gugugu
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
name: Report Bug
|
||||||
|
description: Report a bug and help us improve CustomSkinLoader
|
||||||
|
labels: [ bug ]
|
||||||
|
title: "[Bug] "
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Here is the Report Bug issue for CustomSkinLoader
|
||||||
|
With a red asterisk for the mandatory items
|
||||||
|
Please keep the work order content neat and tidy, do not paste the contents of the log file directly onto the work order, it will look very messy and unattractive work orders
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Describe the bug
|
||||||
|
description: |
|
||||||
|
A clear and concise description of what the issue is.
|
||||||
|
Provide as much information as possible, videos, crash reports, etc.
|
||||||
|
DO NOT PASTE A CRASH REPORT HERE!!!
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: reproducing
|
||||||
|
attributes:
|
||||||
|
label: Steps to reproduce
|
||||||
|
description: How do you trigger this bug?
|
||||||
|
render: bash
|
||||||
|
value: |
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: crash-report
|
||||||
|
attributes:
|
||||||
|
label: Link to crash-report if applicable
|
||||||
|
description: |
|
||||||
|
The files are in the folder `<minecraft-directory>/crash-reports`
|
||||||
|
[Generate URL](https://mclo.gs)
|
||||||
|
placeholder: "Ex: https://mclo.gs/xxxxxx"
|
||||||
|
- type: input
|
||||||
|
id: csl-log
|
||||||
|
attributes:
|
||||||
|
label: Link to CustomSkinLoader.log if applicable
|
||||||
|
description: |
|
||||||
|
The path to the file is `<minecraft-directory>/CustomSkinLoader/CustomSkinLoader.log`.
|
||||||
|
[Generate URL](https://mclo.gs)
|
||||||
|
placeholder: "Ex: https://mclo.gs/xxxxxx"
|
||||||
|
- type: input
|
||||||
|
id: latest-log
|
||||||
|
attributes:
|
||||||
|
label: Link to latest.log if applicable
|
||||||
|
description: |
|
||||||
|
The path to the file is `<minecraft-directory>/logs/latest.log`.
|
||||||
|
[Generate URL](https://mclo.gs)
|
||||||
|
placeholder: "Ex: https://mclo.gs/xxxxxx"
|
||||||
|
- type: input
|
||||||
|
id: forge-log
|
||||||
|
attributes:
|
||||||
|
label: "[Only Forge User] Link to Forge Log if applicable"
|
||||||
|
description: |
|
||||||
|
The path to the file is `<minecraft-directory>/logs/debug.log` or `<minecraft-directory>/logs/fml-client-latest.log`.
|
||||||
|
if your mod loader isn't `Forge`, URL can set empty
|
||||||
|
[Generate URL](https://mclo.gs)
|
||||||
|
placeholder: "Ex: https://mclo.gs/xxxxxx"
|
||||||
|
- type: input
|
||||||
|
id: mod-version
|
||||||
|
attributes:
|
||||||
|
label: Mod Version
|
||||||
|
placeholder: "Ex: 14.16"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: mc-version
|
||||||
|
attributes:
|
||||||
|
label: Minecraft Version
|
||||||
|
placeholder: "Ex: 1.19.4"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: mc-launcher-version
|
||||||
|
attributes:
|
||||||
|
label: Minecraft Launcher Name and Version
|
||||||
|
placeholder: "Ex: HMCL v3.5.4.232"
|
||||||
|
description: |
|
||||||
|
If you don't know the version of the game, you can just fill in the name of the game launcher
|
||||||
|
- type: dropdown
|
||||||
|
id: loader-type
|
||||||
|
attributes:
|
||||||
|
label: Mod Loader
|
||||||
|
options:
|
||||||
|
- Quilt
|
||||||
|
- Fabric
|
||||||
|
- Forge
|
||||||
|
- <without mod loader>
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: operating-systems
|
||||||
|
attributes:
|
||||||
|
label: Operating System
|
||||||
|
options:
|
||||||
|
- Windows
|
||||||
|
- Linux
|
||||||
|
- macOS
|
||||||
|
- Other
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: checkboxes
|
||||||
|
id: prerequisites
|
||||||
|
attributes:
|
||||||
|
label: Before submitting a bug report
|
||||||
|
options:
|
||||||
|
- label: |
|
||||||
|
This bug wasn't already reported (I have searched bug reports on GitHub).
|
||||||
|
required: true
|
||||||
|
- label: |
|
||||||
|
This is a valid bug (I am able to reproduce this on the latest dev build).
|
||||||
|
required: true
|
||||||
|
- label: |
|
||||||
|
This problem is triggered in the latest version of the mod (if not the latest please upgrade the mod first)
|
||||||
|
required: true
|
||||||
|
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
name: 提交问题
|
||||||
|
description: 报告问题以帮助我们改进CustomSkinLoader
|
||||||
|
labels: [ bug ]
|
||||||
|
title: "[Bug] "
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
你好,这里是 `CustomSkinLoader`
|
||||||
|
标注红色星号的为必填项
|
||||||
|
以及,保持工单干净整洁,不要直接将日志内容粘贴到工单上,比如粘贴到描述内是不行的
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: 描述问题
|
||||||
|
description: |
|
||||||
|
简单的描述问题, 并提供类似图片、视频,以更好的报告错误(如果可以)
|
||||||
|
!注意:请不要在这里放日志文件或崩溃报告文件的内容
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: reproducing
|
||||||
|
attributes:
|
||||||
|
label: 复现步骤
|
||||||
|
description: 请问你是如何触发这个问题的
|
||||||
|
render: bash
|
||||||
|
value: |
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: crash-report
|
||||||
|
attributes:
|
||||||
|
label: 崩溃报告查看地址
|
||||||
|
description: |
|
||||||
|
在游戏目录下的 `crash-reports` 文件夹下,里面找最近的报告生成时间
|
||||||
|
客户端若无崩溃则直接填写 `客户端无崩溃`
|
||||||
|
[生成连接](https://mclo.gs)
|
||||||
|
placeholder: "示例: https://mclo.gs/xxxxxx"
|
||||||
|
- type: input
|
||||||
|
id: csl-log
|
||||||
|
attributes:
|
||||||
|
label: CustomSkinLoader.log 查看地址
|
||||||
|
description: |
|
||||||
|
文件路径:`<游戏路径>/CustomSkinLoader/CustomSkinLoader.log`.
|
||||||
|
[生成连接](https://mclo.gs)
|
||||||
|
placeholder: "示例: https://mclo.gs/xxxxxx"
|
||||||
|
- type: input
|
||||||
|
id: latest-log
|
||||||
|
attributes:
|
||||||
|
label: latest.log 查看地址
|
||||||
|
description: |
|
||||||
|
文件路径:`<游戏路径>/logs/latest.log`.
|
||||||
|
[生成连接](https://mclo.gs)
|
||||||
|
placeholder: "示例: https://mclo.gs/xxxxxx"
|
||||||
|
- type: input
|
||||||
|
id: forge-log
|
||||||
|
attributes:
|
||||||
|
label: "[仅Forge用户] Forge Log 查看地址"
|
||||||
|
description: |
|
||||||
|
文件路径:`<游戏路径>/logs/debug.log` 或者 `<游戏路径>/logs/fml-client-latest.log`.
|
||||||
|
若没有使用 `Forge` 加载器的,可以不填写
|
||||||
|
[生成连接](https://mclo.gs)
|
||||||
|
placeholder: "示例: https://mclo.gs/xxxxxx"
|
||||||
|
- type: input
|
||||||
|
id: mod-version
|
||||||
|
attributes:
|
||||||
|
label: 模组版本
|
||||||
|
placeholder: "示例: 14.16"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: mc-version
|
||||||
|
attributes:
|
||||||
|
label: Minecraft游戏版本
|
||||||
|
placeholder: "示例: 1.19.4"
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: mc-launcher-version
|
||||||
|
attributes:
|
||||||
|
label: Minecraft启动器 名称 及 版本
|
||||||
|
placeholder: "示例: HMCL v3.5.4.232"
|
||||||
|
description: |
|
||||||
|
若不知道游戏版本 可以只填写游戏启动器的名称
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: loader-type
|
||||||
|
attributes:
|
||||||
|
label: 模组加载器
|
||||||
|
options:
|
||||||
|
- Quilt
|
||||||
|
- Fabric
|
||||||
|
- Forge
|
||||||
|
- 不使用加载器
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: operating-systems
|
||||||
|
attributes:
|
||||||
|
label: 操作系统
|
||||||
|
options:
|
||||||
|
- Windows
|
||||||
|
- Linux
|
||||||
|
- macOS
|
||||||
|
- 其他操作系统
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: checkboxes
|
||||||
|
id: prerequisites
|
||||||
|
attributes:
|
||||||
|
label: 在提交错误报告之前,有没有做到...
|
||||||
|
options:
|
||||||
|
- label: |
|
||||||
|
先尝试搜索issues里面, 查看并确认打开或关闭的工单, 是否搜索不到
|
||||||
|
required: true
|
||||||
|
- label: |
|
||||||
|
确认你的模组版本是最新的开发版本,且文件下载正确,没有出现类似forge下载了fabric版的这类基础问题
|
||||||
|
required: true
|
||||||
|
- label: |
|
||||||
|
这个问题是在最新的mod版本触发(若不是最新的请先升级mod)
|
||||||
|
required: true
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
name: Suggestion
|
||||||
|
description: Suggest a new feature or change for CustomSkinLoader.
|
||||||
|
labels: [ enhancement ]
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Describe the feature
|
||||||
|
description: A clear and concise description of what the feature/change is.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: checkboxes
|
||||||
|
id: prerequisites
|
||||||
|
attributes:
|
||||||
|
label: Before submitting a suggestion
|
||||||
|
options:
|
||||||
|
- label: |
|
||||||
|
This feature doesn't already exist in the client. (I have checked every module and their settings on the **latest dev build**)
|
||||||
|
required: true
|
||||||
|
- label: |
|
||||||
|
This wasn't already suggested. (I have searched suggestions on GitHub and read the FAQ)
|
||||||
|
required: true
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
name: 反馈或建议
|
||||||
|
description: 给CustomSkinLoader这个模组提个建议
|
||||||
|
labels: [ enhancement ]
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: 描述一下
|
||||||
|
description: 简单描述一下该功能/变化是什么。
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: checkboxes
|
||||||
|
id: prerequisites
|
||||||
|
attributes:
|
||||||
|
label: 在提交反馈或建议之前,请先确认...
|
||||||
|
options:
|
||||||
|
- label: |
|
||||||
|
你要提交的反馈或者建议不存在于本模组的最新开发版下.
|
||||||
|
required: true
|
||||||
|
- label: |
|
||||||
|
以及在issues或者Wiki内搜索过, 并且无结果
|
||||||
|
required: true
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
name: Beta
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '14-develop'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-beta:
|
||||||
|
name: Build Beta
|
||||||
|
uses: ./.github/workflows/common.yml
|
||||||
|
with:
|
||||||
|
type: Beta
|
||||||
|
publish-task: uploadBeta
|
||||||
|
secrets: inherit
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
name: Canary
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '15-develop'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-canary:
|
||||||
|
name: Build Canary
|
||||||
|
uses: ./.github/workflows/common.yml
|
||||||
|
with:
|
||||||
|
type: Canary
|
||||||
|
publish-task: uploadCanary
|
||||||
|
secrets: inherit
|
||||||
@@ -0,0 +1,205 @@
|
|||||||
|
name: Common
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
type:
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
publish-task:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
is-snapshot:
|
||||||
|
required: false
|
||||||
|
type: boolean
|
||||||
|
default: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-common:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: Build
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
-
|
||||||
|
name: Set up JDK
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '8'
|
||||||
|
cache: 'gradle'
|
||||||
|
-
|
||||||
|
name: Build
|
||||||
|
env:
|
||||||
|
KEY_PASS: ${{ secrets.KEY_PASS }}
|
||||||
|
IS_SNAPSHOT: ${{ inputs.is-snapshot }}
|
||||||
|
run: |
|
||||||
|
echo Snapshot: $IS_SNAPSHOT
|
||||||
|
export GIT_COMMIT_DESC=$(git log --format=%B -n 1 $GITHUB_SHA)
|
||||||
|
./gradlew clean build --stacktrace
|
||||||
|
-
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
name: Publish to Github Artifact
|
||||||
|
with:
|
||||||
|
name: CustomSkinLoader-${{ inputs.type }}-${{ github.run_number }}
|
||||||
|
path: build/libs
|
||||||
|
|
||||||
|
Upload:
|
||||||
|
if: inputs.publish-task
|
||||||
|
needs: build-common
|
||||||
|
continue-on-error: true
|
||||||
|
environment: Build
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
website: [CurseForge_Modrinth]
|
||||||
|
modtype: [Fabric,Forge-Active,Forge-Legacy]
|
||||||
|
include:
|
||||||
|
-
|
||||||
|
website: TencentCOS
|
||||||
|
modtype: All
|
||||||
|
# -
|
||||||
|
# website: GitHub-Release
|
||||||
|
# modtype: All
|
||||||
|
-
|
||||||
|
website: GitHub-PreRelease
|
||||||
|
modtype: All
|
||||||
|
name: ${{ matrix.website }} (${{ matrix.modtype}})
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout Git Repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
-
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
name: Download Artifact Zips
|
||||||
|
with:
|
||||||
|
path: build
|
||||||
|
-
|
||||||
|
name: Preparation Folder
|
||||||
|
run: |
|
||||||
|
rsync -avz "build/$(ls build|grep "CustomSkinLoader")/" build/libs/
|
||||||
|
ls -lh build
|
||||||
|
-
|
||||||
|
if: ${{ matrix.modtype != 'All' }}
|
||||||
|
name: Checking and setting the environment
|
||||||
|
id: cslenv
|
||||||
|
run: |
|
||||||
|
output="$(ls build/libs | grep -v "sources")"
|
||||||
|
if [[ "${{ matrix.modtype }}" == "Forge"* ]]; then
|
||||||
|
modloader="Forge"
|
||||||
|
path=$(echo ${{ matrix.modtype }} | sed "s#-#/#")
|
||||||
|
else
|
||||||
|
modloader=${{ matrix.modtype }}
|
||||||
|
path=${{ matrix.modtype }}
|
||||||
|
fi
|
||||||
|
echo "path=$path" >> $GITHUB_OUTPUT
|
||||||
|
echo "modloader=$modloader" >> $GITHUB_OUTPUT
|
||||||
|
echo "filename=$(echo "$output"|grep $(echo ${{ matrix.modtype }}|sed "s#-##") )" >> $GITHUB_OUTPUT
|
||||||
|
echo "version=$(grep "version=" build.properties | grep -v "#" | sed "s/version=//")" >> $GITHUB_OUTPUT
|
||||||
|
echo "edition=$(echo ${{ matrix.modtype }} | sed "s/-//")" >> $GITHUB_OUTPUT
|
||||||
|
echo "minecraft_vers<<EOF" >> $GITHUB_OUTPUT
|
||||||
|
grep "minecraft_full_versions=" "$path"/build.properties | grep -v "#" | sed "s/minecraft_full_versions=//" | sed "s/,/\n/g" >> $GITHUB_OUTPUT
|
||||||
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
echo "java_vers<<EOF" >> $GITHUB_OUTPUT
|
||||||
|
grep "java_full_versions=" "$path"/build.properties | grep -v "#" | sed "s/java_full_versions=//" | sed "s/,/\n/g" >> $GITHUB_OUTPUT
|
||||||
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
-
|
||||||
|
if: startsWith(matrix.website, 'GitHub-')
|
||||||
|
name: Settings more strings to Environment
|
||||||
|
id: cslenv-github
|
||||||
|
run: |
|
||||||
|
#展开
|
||||||
|
echo "buildtime=$(TZ=Asia/Shanghai date "+%Y.%m.%d %H:%M")" >> $GITHUB_OUTPUT
|
||||||
|
echo "pathlist="$(find build/libs -type f|grep -v "sources"|grep -v "json")"" >> $GITHUB_OUTPUT
|
||||||
|
-
|
||||||
|
if: ${{ matrix.website == 'GitHub-PreRelease' && startsWith(github.ref, 'refs/heads') }}
|
||||||
|
name: 【GitHub Pre-Release】 Delete
|
||||||
|
uses: 8Mi-Tech/delete-release-assets-action@main
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag: CI-Build
|
||||||
|
deleteOnlyFromDrafts: false
|
||||||
|
-
|
||||||
|
if: ${{ matrix.website == 'GitHub-PreRelease' && startsWith(github.ref, 'refs/heads') }}
|
||||||
|
name: 【GitHub Pre-Release】 Set CI-Build Text
|
||||||
|
run: |
|
||||||
|
cat > build/ci-build.md << 'EOF'
|
||||||
|
Build Time / 构建时间 : ${{ steps.cslenv-github.outputs.buildtime }}
|
||||||
|
自动同步分支 ${{ github.ref_name }} 的代码,以保持最新
|
||||||
|
Synchronize ${{ github.ref_name }} branch code updates, keeping only the latest version
|
||||||
|
<br>
|
||||||
|
[如何使用 / How to uses?](https://github.com/xfl03/MCCustomSkinLoader/wiki/How-to-Use)
|
||||||
|
EOF
|
||||||
|
-
|
||||||
|
if: ${{ matrix.website == 'GitHub-PreRelease' && startsWith(github.ref, 'refs/heads') }}
|
||||||
|
name: 【GitHub Pre-Release】 Upload Tag
|
||||||
|
uses: richardsimko/update-tag@v1
|
||||||
|
with:
|
||||||
|
tag_name: CI-Build
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
if: ${{ matrix.website == 'GitHub-PreRelease' && startsWith(github.ref, 'refs/heads') }}
|
||||||
|
name: 【GitHub Pre-Release】 Publish
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
name: CustomSkinLoader CI-Build
|
||||||
|
tag_name: CI-Build
|
||||||
|
prerelease: true
|
||||||
|
body_path: build/ci-build.md
|
||||||
|
files: build/libs/*
|
||||||
|
#iles: "${{ steps.cslenv-github.outputs.pathlist }}"
|
||||||
|
-
|
||||||
|
if: ${{ matrix.website == 'GitHub-Release' && inputs.type == 'Release' }}
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
name: 【GitHub Release】 Publish
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
name: CustomSkinLoader ${{ github.ref }}
|
||||||
|
tag_name: ${{ github.ref }}
|
||||||
|
#generate_release_notes: true
|
||||||
|
files: ${{ steps.cslenv-github.outputs.pathlist }}
|
||||||
|
-
|
||||||
|
if: ${{ matrix.website == 'TencentCOS' }}
|
||||||
|
name: 【TencentCOS】 Publish
|
||||||
|
env:
|
||||||
|
COS_BUCKET: ${{ secrets.COS_BUCKET }}
|
||||||
|
COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}
|
||||||
|
COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}
|
||||||
|
IS_SNAPSHOT: ${{ inputs.is-snapshot }}
|
||||||
|
run: |
|
||||||
|
export GIT_COMMIT_DESC=$(git log --format=%B -n 1 $GITHUB_SHA)
|
||||||
|
./gradlew ${{ inputs.publish-task }} --info --stacktrace
|
||||||
|
# ./gradlew publishGprPublicationToGitHubPackagesRepository
|
||||||
|
|
||||||
|
-
|
||||||
|
if: ${{ matrix.website == 'CurseForge_Modrinth' && inputs.type == 'Release' }}
|
||||||
|
name: 【CurseForge & Modrinth】 Publish
|
||||||
|
uses: Kir-Antipov/[email protected]
|
||||||
|
with:
|
||||||
|
modrinth-id: idMHQ4n2
|
||||||
|
modrinth-featured: true
|
||||||
|
modrinth-unfeature-mode: subset
|
||||||
|
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
|
||||||
|
|
||||||
|
curseforge-id: 286924
|
||||||
|
curseforge-token: ${{ secrets.CURSEFORGE_API_KEY }}
|
||||||
|
|
||||||
|
name: CustomSkinLoader_${{ steps.cslenv.outputs.edition }}_${{ steps.cslenv.outputs.version }}
|
||||||
|
version: ${{ steps.cslenv.outputs.version }}-${{ steps.cslenv.outputs.edition }}
|
||||||
|
version-type: release
|
||||||
|
loaders: ${{ steps.cslenv.outputs.modloader }}
|
||||||
|
game-versions: |
|
||||||
|
${{ steps.cslenv.outputs.minecraft_vers }}
|
||||||
|
game-version-filter: releases
|
||||||
|
java: |
|
||||||
|
${{ steps.cslenv.outputs.java_vers }}
|
||||||
|
|
||||||
|
retry-attempts: 2
|
||||||
|
retry-delay: 10000
|
||||||
|
fail-mode: fail
|
||||||
|
|
||||||
|
files: |
|
||||||
|
build/libs/${{ steps.cslenv.outputs.filename }}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
name: Pull Request
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- synchronize
|
||||||
|
- reopened
|
||||||
|
branches:
|
||||||
|
- '14-develop'
|
||||||
|
- '15-develop'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-pull-request:
|
||||||
|
name: Build Pull Request
|
||||||
|
uses: ./.github/workflows/common.yml
|
||||||
|
with:
|
||||||
|
type: PullRequest
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
name: Release
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [released]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-release:
|
||||||
|
name: Build Release
|
||||||
|
uses: ./.github/workflows/common.yml
|
||||||
|
with:
|
||||||
|
type: Release
|
||||||
|
publish-task: upload
|
||||||
|
is-snapshot: false
|
||||||
|
secrets: inherit
|
||||||
+20
-9
@@ -1,25 +1,36 @@
|
|||||||
|
# Java
|
||||||
*.class
|
*.class
|
||||||
|
|
||||||
# Mobile Tools for Java (J2ME)
|
# Mobile Tools for Java (J2ME)
|
||||||
.mtj.tmp/
|
.mtj.tmp/
|
||||||
|
|
||||||
# Package Files #
|
|
||||||
*.jar
|
|
||||||
*.war
|
|
||||||
*.ear
|
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
|
||||||
#VSCode
|
# VSCode
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
#eclipse
|
# eclipse
|
||||||
|
bin/
|
||||||
*/.classpath
|
*/.classpath
|
||||||
.classpath
|
.classpath
|
||||||
*/.project
|
*/.project
|
||||||
.project
|
.project
|
||||||
.settings/
|
.settings/
|
||||||
|
*.launch
|
||||||
|
|
||||||
#gradle
|
# gradle
|
||||||
.gradle/
|
.gradle/
|
||||||
|
build/
|
||||||
|
logs/
|
||||||
|
run/
|
||||||
|
|
||||||
|
# IDEA
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
out/
|
||||||
|
|
||||||
|
#mac OS
|
||||||
|
.DS_Store
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
minecraft_version=1.12
|
|
||||||
minecraft_full_versions=1.12
|
|
||||||
#forge gradle needs forge version
|
|
||||||
forge_mc_version=1.12
|
|
||||||
forge_version=14.21.1.2387
|
|
||||||
mappings_version=snapshot_20170813
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package net.minecraft.client.resources;
|
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.cache.LoadingCache;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.minecraft.InsecureTextureException;
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.IImageBuffer;
|
|
||||||
import net.minecraft.client.renderer.ImageBufferDownload;
|
|
||||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
|
||||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
public class SkinManager
|
|
||||||
{
|
|
||||||
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue());
|
|
||||||
private final TextureManager textureManager;
|
|
||||||
private final File skinCacheDir;
|
|
||||||
private final MinecraftSessionService sessionService;
|
|
||||||
private final LoadingCache<GameProfile, Map<Type, MinecraftProfileTexture>> skinCacheLoader;
|
|
||||||
|
|
||||||
private customskinloader.fake.FakeSkinManager fakeManager;//Fake Skin Manager
|
|
||||||
|
|
||||||
public SkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService)
|
|
||||||
{
|
|
||||||
this.textureManager = textureManagerInstance;
|
|
||||||
this.skinCacheDir = skinCacheDirectory;
|
|
||||||
this.sessionService = sessionService;
|
|
||||||
this.skinCacheLoader = CacheBuilder.newBuilder().expireAfterAccess(15L, TimeUnit.SECONDS).<GameProfile, Map<Type, MinecraftProfileTexture>>build(new CacheLoader<GameProfile, Map<Type, MinecraftProfileTexture>>()
|
|
||||||
{
|
|
||||||
public Map<Type, MinecraftProfileTexture> load(GameProfile p_load_1_) throws Exception
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false);
|
|
||||||
}
|
|
||||||
catch (Throwable var3)
|
|
||||||
{
|
|
||||||
return Maps.<Type, MinecraftProfileTexture>newHashMap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.fakeManager=new customskinloader.fake.FakeSkinManager(textureManagerInstance,skinCacheDirectory,sessionService);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used in the Skull renderer to fetch a skin. May download the skin if it's not in the cache
|
|
||||||
*/
|
|
||||||
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type textureType)
|
|
||||||
{
|
|
||||||
return this.loadSkin(profileTexture, textureType, (SkinManager.SkinAvailableCallback)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* May download the skin if its not in the cache, can be passed a SkinManager#SkinAvailableCallback for handling
|
|
||||||
*/
|
|
||||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
|
||||||
{
|
|
||||||
return this.fakeManager.loadSkin(profileTexture, textureType, skinAvailableCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure)
|
|
||||||
{
|
|
||||||
this.fakeManager.loadProfileTextures(profile, skinAvailableCallback, requireSecure);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile)
|
|
||||||
{
|
|
||||||
return this.fakeManager.loadSkinFromCache(profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface SkinAvailableCallback
|
|
||||||
{
|
|
||||||
void skinAvailable(Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
minecraft_version=1.12.1
|
|
||||||
minecraft_full_versions=1.12.1
|
|
||||||
#forge gradle needs forge version
|
|
||||||
forge_mc_version=1.12.1
|
|
||||||
forge_version=14.22.0.2452
|
|
||||||
mappings_version=snapshot_20170813
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
package net.minecraft.client.resources;
|
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.cache.LoadingCache;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.authlib.minecraft.InsecureTextureException;
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.IImageBuffer;
|
|
||||||
import net.minecraft.client.renderer.ImageBufferDownload;
|
|
||||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
|
||||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
//From 1.12-mcp940
|
|
||||||
public class SkinManager
|
|
||||||
{
|
|
||||||
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue());
|
|
||||||
private final TextureManager textureManager;
|
|
||||||
private final File skinCacheDir;
|
|
||||||
private final MinecraftSessionService sessionService;
|
|
||||||
private final LoadingCache<GameProfile, Map<Type, MinecraftProfileTexture>> skinCacheLoader;
|
|
||||||
|
|
||||||
private customskinloader.fake.FakeSkinManager fakeManager;//Fake Skin Manager
|
|
||||||
|
|
||||||
public SkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService)
|
|
||||||
{
|
|
||||||
this.textureManager = textureManagerInstance;
|
|
||||||
this.skinCacheDir = skinCacheDirectory;
|
|
||||||
this.sessionService = sessionService;
|
|
||||||
this.skinCacheLoader = CacheBuilder.newBuilder().expireAfterAccess(15L, TimeUnit.SECONDS).<GameProfile, Map<Type, MinecraftProfileTexture>>build(new CacheLoader<GameProfile, Map<Type, MinecraftProfileTexture>>()
|
|
||||||
{
|
|
||||||
public Map<Type, MinecraftProfileTexture> load(GameProfile p_load_1_) throws Exception
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Minecraft.getMinecraft().getSessionService().getTextures(p_load_1_, false);
|
|
||||||
}
|
|
||||||
catch (Throwable var3)
|
|
||||||
{
|
|
||||||
return Maps.<Type, MinecraftProfileTexture>newHashMap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.fakeManager=new customskinloader.fake.FakeSkinManager(textureManagerInstance,skinCacheDirectory,sessionService);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used in the Skull renderer to fetch a skin. May download the skin if it's not in the cache
|
|
||||||
*/
|
|
||||||
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type textureType)
|
|
||||||
{
|
|
||||||
return this.loadSkin(profileTexture, textureType, (SkinManager.SkinAvailableCallback)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* May download the skin if its not in the cache, can be passed a SkinManager#SkinAvailableCallback for handling
|
|
||||||
*/
|
|
||||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
|
||||||
{
|
|
||||||
return this.fakeManager.loadSkin(profileTexture, textureType, skinAvailableCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure)
|
|
||||||
{
|
|
||||||
this.fakeManager.loadProfileTextures(profile, skinAvailableCallback, requireSecure);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile)
|
|
||||||
{
|
|
||||||
return this.fakeManager.loadSkinFromCache(profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface SkinAvailableCallback
|
|
||||||
{
|
|
||||||
void skinAvailable(Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+149
@@ -0,0 +1,149 @@
|
|||||||
|
# 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.2860<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.15-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.15-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.15-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.15-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.15-SNAPSHOT-00"
|
||||||
|
}
|
||||||
|
|
||||||
|
minecraft {
|
||||||
|
clientRunArgs += ["--tweakClass", "customskinloader.forge.ForgeDevTweaker", "--username", "<Your username>"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
1. Run `./gradlew setupDecompWorkspace` command.
|
||||||
|
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.15-SNAPSHOT-00") // Only required for MinecraftForge 1.8 ~ 1.16.5
|
||||||
|
implementation fg.deobf("mods:CustomSkinLoader_ForgeActive:14.15-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.15-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.
|
||||||
Binary file not shown.
@@ -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
|
||||||
@@ -6,5 +6,6 @@
|
|||||||
"mcFullVersions": "${mcFullVersions}",
|
"mcFullVersions": "${mcFullVersions}",
|
||||||
"forgeVersion": "${forgeVersion}",
|
"forgeVersion": "${forgeVersion}",
|
||||||
"gitVersion": "${gitVersion}",
|
"gitVersion": "${gitVersion}",
|
||||||
"buildUrl": "${buildUrl}"
|
"buildUrl": "${buildUrl}",
|
||||||
}
|
"buildTime": "${releaseTime}"
|
||||||
|
}
|
||||||
@@ -33,4 +33,4 @@ GPLv3: http://www.gnu.org/licenses/gpl.html
|
|||||||
其他 - 有用的链接
|
其他 - 有用的链接
|
||||||
源代码: https://github.com/xfl03/MCCustomSkinLoader
|
源代码: https://github.com/xfl03/MCCustomSkinLoader
|
||||||
发布页面: http://www.mcbbs.net/thread-269807-1-1.html
|
发布页面: http://www.mcbbs.net/thread-269807-1-1.html
|
||||||
构建服务器: https://ci.infstudio.net/job/CustomSkinLoader/
|
构建服务器: https://ci.infstudio.net/job/CustomSkinLoader/
|
||||||
@@ -2,17 +2,24 @@ 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.ThreadFactory;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
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.log.LogManager;
|
||||||
|
import customskinloader.log.Logger;
|
||||||
import customskinloader.profile.DynamicSkullManager;
|
import customskinloader.profile.DynamicSkullManager;
|
||||||
import customskinloader.profile.ModelManager0;
|
import customskinloader.profile.ModelManager0;
|
||||||
import customskinloader.profile.ProfileCache;
|
import customskinloader.profile.ProfileCache;
|
||||||
@@ -21,148 +28,227 @@ import customskinloader.utils.MinecraftUtil;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom skin loader mod for Minecraft.
|
* Custom skin loader mod for Minecraft.
|
||||||
* @author (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2016
|
*
|
||||||
|
* @author Jeremy Lam [JLChnToZ] 2013-2014 & Alexander Xia [xfl03] 2014-2023
|
||||||
* @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"),
|
|
||||||
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
|
public static final File
|
||||||
CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json");
|
DATA_DIR = new File(MinecraftUtil.getMinecraftDataDir(), "CustomSkinLoader"),
|
||||||
public static final SkinSiteProfile[] DEFAULT_LOAD_LIST={
|
LOG_FILE = new File(DATA_DIR, "CustomSkinLoader.log"),
|
||||||
SkinSiteProfile.createMojangAPI("Mojang"),
|
CONFIG_FILE = new File(DATA_DIR, "CustomSkinLoader.json");
|
||||||
SkinSiteProfile.createCustomSkinAPI("LittleSkin","https://mcskin.littleservice.cn/"),
|
|
||||||
SkinSiteProfile.createCustomSkinAPI("BlessingSkin","http://skin.prinzeugen.net/"),
|
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
//OneSkin has been removed temporarily
|
public static final Logger logger = initLogger();
|
||||||
//SkinSiteProfile.createCustomSkinAPI("OneSkin","http://fleey.cn/skin/skin_user/skin_json.php/"),
|
public static final Config config = initConfig();
|
||||||
//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),
|
private static final ProfileCache profileCache = new ProfileCache();
|
||||||
SkinSiteProfile.createUniSkinAPI("SkinMe","http://www.skinme.cc/uniskin/"),
|
private static final DynamicSkullManager dynamicSkullManager = new DynamicSkullManager();
|
||||||
SkinSiteProfile.createLegacy("LocalSkin","LocalSkin/skins/{USERNAME}.png","LocalSkin/capes/{USERNAME}.png","LocalSkin/elytras/{USERNAME}.png")};
|
|
||||||
|
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(
|
||||||
public static final Gson GSON=new GsonBuilder().setPrettyPrinting().create();
|
config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>());
|
||||||
public static final Logger logger=initLogger();
|
|
||||||
public static final Config config=Config.loadConfig0();
|
//Correct thread name in thread pool
|
||||||
|
private static final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
|
||||||
private static final ProfileCache profileCache=new ProfileCache();
|
private static final ThreadFactory customFactory = r -> {
|
||||||
private static final DynamicSkullManager dynamicSkullManager=new DynamicSkullManager();
|
Thread t = defaultFactory.newThread(r);
|
||||||
|
if (r instanceof Thread) {
|
||||||
//For User Skin
|
t.setName(((Thread) r).getName());
|
||||||
public static Map loadProfile(GameProfile gameProfile){
|
}
|
||||||
String username=gameProfile.getName();
|
return t;
|
||||||
//Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713
|
};
|
||||||
if(username==null){
|
//Thread pool will discard oldest task when queue reaches 333 tasks
|
||||||
logger.warning("Could not load profile: username is null.");
|
private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
|
||||||
return Maps.newHashMap();
|
config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES,
|
||||||
}
|
new LinkedBlockingQueue<>(333), customFactory, new ThreadPoolExecutor.DiscardOldestPolicy()
|
||||||
String tempName=Thread.currentThread().getName();
|
);
|
||||||
Thread.currentThread().setName(username);//Change Thread Name
|
|
||||||
UserProfile profile=null;
|
public static void loadProfileTextures(Runnable runnable) {
|
||||||
if(profileCache.isReady(username)){
|
THREAD_POOL.execute(runnable);
|
||||||
logger.info("Cached profile will be used.");
|
}
|
||||||
profile=profileCache.getProfile(username);
|
|
||||||
if(profile==null){
|
public static void loadProfileLazily(
|
||||||
logger.warning("(!Cached Profile is empty!) Expiry:"+profileCache.getExpiry(username));
|
GameProfile gameProfile, Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>> consumer) {
|
||||||
if(profileCache.isExpired(username))//force load
|
String username = gameProfile.getName();
|
||||||
profile=loadProfile0(gameProfile);
|
String credential = MinecraftUtil.getCredential(gameProfile);
|
||||||
}
|
// Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713
|
||||||
else
|
if (username == null) {
|
||||||
logger.info(profile.toString(profileCache.getExpiry(username)));
|
logger.warning("Could not load profile: username is null.");
|
||||||
}else{
|
consumer.accept(Maps.newHashMap());
|
||||||
profileCache.setLoading(username, true);
|
return;
|
||||||
profile=loadProfile0(gameProfile);
|
}
|
||||||
}
|
String tempName = Thread.currentThread().getName();
|
||||||
Thread.currentThread().setName(tempName);
|
Thread.currentThread().setName(username); // Change Thread Name
|
||||||
return ModelManager0.fromUserProfile(profile);
|
if (profileCache.isLoading(credential)) {
|
||||||
}
|
profileCache.putLoader(credential, consumer);
|
||||||
//Core
|
Thread.currentThread().setName(tempName);
|
||||||
public static UserProfile loadProfile0(GameProfile gameProfile){
|
return;
|
||||||
String username=gameProfile.getName();
|
}
|
||||||
profileCache.setLoading(username, true);
|
consumer.accept(loadProfile(gameProfile));
|
||||||
logger.info("Loading "+username+"'s profile.");
|
Thread.currentThread().setName(tempName);
|
||||||
if(config.loadlist==null||config.loadlist.isEmpty()){
|
profileCache.getLastLoader(credential).ifPresent(c -> loadProfileLazily(gameProfile, c));
|
||||||
logger.info("LoadList is Empty.");
|
}
|
||||||
return null;
|
|
||||||
}
|
//For User Skin
|
||||||
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadProfile(GameProfile gameProfile) {
|
||||||
UserProfile profile0=new UserProfile();
|
String credential = MinecraftUtil.getCredential(gameProfile);
|
||||||
for(int i=0;i<config.loadlist.size();i++){
|
UserProfile profile;
|
||||||
SkinSiteProfile ssp=config.loadlist.get(i);
|
if (profileCache.isReady(credential)) {
|
||||||
logger.info((i+1)+"/"+config.loadlist.size()+" Try to load profile from '"+ssp.name+"'.");
|
logger.info("Cached profile will be used.");
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
profile = profileCache.getProfile(credential);
|
||||||
if(loader==null){
|
if (profile == null) {
|
||||||
logger.info("Type '"+ssp.type+"' is not defined.");
|
logger.warning("(Cached Profile is empty!) Expiry: " + profileCache.getExpiry(credential));
|
||||||
continue;
|
if (profileCache.isExpired(credential)) { // force load
|
||||||
}
|
profile = loadProfile0(gameProfile, false);
|
||||||
UserProfile profile=null;
|
}
|
||||||
try{
|
} else {
|
||||||
profile=loader.loadProfile(ssp, gameProfile);
|
logger.info(profile.toString(profileCache.getExpiry(credential)));
|
||||||
}catch(Exception e){
|
}
|
||||||
logger.warning("Exception occurs while loading.");
|
} else {
|
||||||
logger.warning(e);
|
profileCache.setLoading(credential, true);
|
||||||
}
|
profile = loadProfile0(gameProfile, false);
|
||||||
if(profile==null)
|
}
|
||||||
continue;
|
return ModelManager0.fromUserProfile(profile);
|
||||||
if(!config.forceLoadAllTextures){
|
}
|
||||||
profile0=profile;
|
|
||||||
break;
|
//Core
|
||||||
}
|
public static UserProfile loadProfile0(GameProfile gameProfile, boolean isSkull) {
|
||||||
profile0.mix(profile);
|
String username = gameProfile.getName();
|
||||||
if(profile0.isFull())
|
String credential = MinecraftUtil.getCredential(gameProfile);
|
||||||
break;
|
|
||||||
}
|
profileCache.setLoading(credential, true);
|
||||||
if(!profile0.isEmpty()){
|
logger.info("Loading " + username + "'s profile.");
|
||||||
logger.info(username+"'s profile loaded.");
|
if (config.loadlist == null || config.loadlist.isEmpty()) {
|
||||||
profileCache.updateCache(username, profile0);
|
logger.info("LoadList is Empty.");
|
||||||
profileCache.setLoading(username, false);
|
return null;
|
||||||
logger.info(profile0.toString(profileCache.getExpiry(username)));
|
}
|
||||||
return profile0;
|
|
||||||
}
|
UserProfile profile0 = new UserProfile();
|
||||||
logger.info(username+"'s profile not found in load list.");
|
for (int i = 0; i < config.loadlist.size(); i++) {
|
||||||
|
SkinSiteProfile ssp = config.loadlist.get(i);
|
||||||
if(config.enableLocalProfileCache){
|
logger.info((i + 1) + "/" + config.loadlist.size() + " Try to load profile from '" + ssp.name + "'.");
|
||||||
UserProfile profile=profileCache.getLocalProfile(username);
|
if (ssp.type == null) {
|
||||||
if(profile==null)
|
logger.info("The type of '" + ssp.name + "' is null.");
|
||||||
logger.info(username+"'s LocalProfile not found.");
|
continue;
|
||||||
else{
|
}
|
||||||
profileCache.updateCache(username, profile, false);
|
ProfileLoader.IProfileLoader loader = ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
profileCache.setLoading(username, false);
|
if (loader == null) {
|
||||||
logger.info(username+"'s LocalProfile will be used.");
|
logger.info("Type '" + ssp.type + "' is not defined.");
|
||||||
logger.info(profile.toString(profileCache.getExpiry(username)));
|
continue;
|
||||||
return profile;
|
}
|
||||||
}
|
UserProfile profile = null;
|
||||||
}
|
try {
|
||||||
profileCache.setLoading(username, false);
|
profile = loader.loadProfile(ssp, gameProfile);
|
||||||
return null;
|
} catch (Exception e) {
|
||||||
}
|
logger.warning("Exception occurs while loading.");
|
||||||
|
logger.warning(e);
|
||||||
//For Skull
|
if (e.getCause() != null) {
|
||||||
public static Map<Type, MinecraftProfileTexture> loadProfileFromCache(final GameProfile gameProfile) {
|
logger.warning("Caused By:");
|
||||||
String username=gameProfile.getName();
|
logger.warning(e.getCause());
|
||||||
if(username==null)
|
}
|
||||||
return dynamicSkullManager.getTexture(gameProfile);
|
}
|
||||||
if(config.enableUpdateSkull?profileCache.isReady(username):profileCache.isExist(username)){
|
if (profile == null) {
|
||||||
UserProfile profile=profileCache.getProfile(username);
|
continue;
|
||||||
return ModelManager0.fromUserProfile(profile);
|
}
|
||||||
}
|
profile0.mix(profile);
|
||||||
//profileCache.setLoading(username, true);
|
if (isSkull && !profile0.hasSkinUrl()) {
|
||||||
Thread loadThread=new Thread(){
|
continue;
|
||||||
public void run(){
|
}
|
||||||
loadProfile0(gameProfile);//Load in thread
|
if (!config.forceLoadAllTextures) {
|
||||||
}
|
break;
|
||||||
};
|
}
|
||||||
loadThread.setName(username+"'s skull");
|
if (profile0.isFull()) {
|
||||||
loadThread.start();
|
break;
|
||||||
return Maps.newHashMap();
|
}
|
||||||
}
|
}
|
||||||
|
if (!profile0.isEmpty()) {
|
||||||
private static Logger initLogger() {
|
logger.info(username + "'s profile loaded.");
|
||||||
Logger logger=new Logger(LOG_FILE);
|
if (!config.enableCape) {
|
||||||
logger.info("CustomSkinLoader "+CustomSkinLoader_FULL_VERSION);
|
profile0.capeUrl = null;
|
||||||
logger.info("DataDir: "+DATA_DIR.getAbsolutePath());
|
}
|
||||||
logger.info("Minecraft: "+MinecraftUtil.getMinecraftMainVersion()+"("+MinecraftUtil.getMinecraftVersionText()+")");
|
profileCache.updateCache(credential, profile0);
|
||||||
return logger;
|
profileCache.setLoading(credential, false);
|
||||||
}
|
logger.info(profile0.toString(profileCache.getExpiry(credential)));
|
||||||
|
return profile0;
|
||||||
|
}
|
||||||
|
logger.info(username + "'s profile not found in load list.");
|
||||||
|
|
||||||
|
if (config.enableLocalProfileCache) {
|
||||||
|
UserProfile profile = profileCache.getLocalProfile(credential);
|
||||||
|
if (profile == null) {
|
||||||
|
logger.info(username + "'s LocalProfile not found.");
|
||||||
|
} else {
|
||||||
|
profileCache.updateCache(credential, profile, false);
|
||||||
|
profileCache.setLoading(credential, false);
|
||||||
|
logger.info(username + "'s LocalProfile will be used.");
|
||||||
|
logger.info(profile.toString(profileCache.getExpiry(credential)));
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
profileCache.setLoading(credential, false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//For Skull
|
||||||
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadProfileFromCache(
|
||||||
|
final GameProfile gameProfile) {
|
||||||
|
String username = gameProfile.getName();
|
||||||
|
String credential = MinecraftUtil.getCredential(gameProfile);
|
||||||
|
|
||||||
|
//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 " "
|
||||||
|
if (username == null || username.isEmpty() || username.equals(" ") || credential == null) {
|
||||||
|
return dynamicSkullManager.getTexture(gameProfile);
|
||||||
|
}
|
||||||
|
if (config.forceUpdateSkull ? profileCache.isReady(credential) : profileCache.isExist(credential)) {
|
||||||
|
UserProfile profile = profileCache.getProfile(credential);
|
||||||
|
return ModelManager0.fromUserProfile(profile);
|
||||||
|
}
|
||||||
|
if (!profileCache.isLoading(credential)) {
|
||||||
|
profileCache.setLoading(credential, true);
|
||||||
|
Runnable loadThread = () -> {
|
||||||
|
String tempName = Thread.currentThread().getName();
|
||||||
|
Thread.currentThread().setName(username + "'s skull");
|
||||||
|
loadProfile0(gameProfile, true);//Load in thread
|
||||||
|
Thread.currentThread().setName(tempName);
|
||||||
|
};
|
||||||
|
if (config.forceUpdateSkull) {
|
||||||
|
new Thread(loadThread).start();
|
||||||
|
} else {
|
||||||
|
threadPool.execute(loadThread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger initLogger() {
|
||||||
|
LogManager.setLogFile(LOG_FILE.toPath());
|
||||||
|
Logger logger = LogManager.getLogger("Core");
|
||||||
|
logger.info("CustomSkinLoader " + CustomSkinLoader_FULL_VERSION);
|
||||||
|
logger.info("DataDir: " + DATA_DIR.getAbsolutePath());
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create <code>Config</code> object.
|
||||||
|
* To use <code>logger</code>, please make sure call this function after <code>initLogger</code>.
|
||||||
|
*
|
||||||
|
* @return <code>Config</code>
|
||||||
|
*/
|
||||||
|
private static Config initConfig() {
|
||||||
|
Config config = Config.loadConfig0();
|
||||||
|
logger.enableLogStdOut = config.enableLogStdOut;
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,95 +1,8 @@
|
|||||||
package customskinloader;
|
package customskinloader;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
/**
|
||||||
import java.io.File;
|
* @deprecated From 14.16, use <code>customskinloader.log.Logger</code> instead.
|
||||||
import java.io.FileOutputStream;
|
*/
|
||||||
import java.io.OutputStreamWriter;
|
@Deprecated
|
||||||
import java.text.SimpleDateFormat;
|
public class Logger extends customskinloader.log.Logger {
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class Logger {
|
|
||||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
public enum Level{
|
|
||||||
DEBUG("DEBUG",false),
|
|
||||||
INFO("INFO",true),
|
|
||||||
WARNING("WARNING",true);
|
|
||||||
|
|
||||||
|
|
||||||
String name;
|
|
||||||
boolean display;
|
|
||||||
Level(String name,boolean display){
|
|
||||||
this.name=name;
|
|
||||||
this.display=display;
|
|
||||||
}
|
|
||||||
public String getName(){
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
public boolean display(){
|
|
||||||
return display;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private BufferedWriter writer=null;
|
|
||||||
public Logger(){
|
|
||||||
//Logger isn't created.
|
|
||||||
}
|
|
||||||
public Logger(File logFile){
|
|
||||||
try {
|
|
||||||
if(!logFile.getParentFile().exists()){
|
|
||||||
logFile.getParentFile().mkdirs();
|
|
||||||
}
|
|
||||||
if(!logFile.exists())
|
|
||||||
logFile.createNewFile();
|
|
||||||
|
|
||||||
writer = new BufferedWriter(new OutputStreamWriter(
|
|
||||||
new FileOutputStream(logFile), "UTF-8"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void close(){
|
|
||||||
if(writer!=null){
|
|
||||||
try {
|
|
||||||
writer.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(Level level,String msg){
|
|
||||||
if(!level.display()&&writer==null)
|
|
||||||
return;
|
|
||||||
StringBuilder sb=new StringBuilder();
|
|
||||||
sb.append("[").append(Thread.currentThread().getName()).append(" ").append(level.getName()).append("] ");
|
|
||||||
sb.append(msg);
|
|
||||||
if(level.display())
|
|
||||||
System.out.println(sb.toString());
|
|
||||||
if(writer==null)
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
StringBuilder sb2=new StringBuilder();
|
|
||||||
sb2.append("[").append(DATE_FORMAT.format(new Date())).append("] ");
|
|
||||||
sb2.append(sb.toString()).append("\r\n");
|
|
||||||
writer.write(sb2.toString());
|
|
||||||
writer.flush();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void debug(String msg){
|
|
||||||
log(Level.DEBUG,msg);
|
|
||||||
}
|
|
||||||
public void info(String msg){
|
|
||||||
log(Level.INFO,msg);
|
|
||||||
}
|
|
||||||
public void warning(String msg){
|
|
||||||
log(Level.WARNING,msg);
|
|
||||||
}
|
|
||||||
public void warning(Exception e){
|
|
||||||
log(Level.WARNING,"Exception: "+e.toString());
|
|
||||||
StackTraceElement[] stes=e.getStackTrace();
|
|
||||||
for(StackTraceElement ste : stes){
|
|
||||||
log(Level.WARNING,ste.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,195 +1,259 @@
|
|||||||
package customskinloader.config;
|
package customskinloader.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.io.Charsets;
|
|
||||||
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")
|
||||||
public class Config {
|
public class Config {
|
||||||
//Program
|
//Program
|
||||||
public String version;
|
public String version;
|
||||||
public List<SkinSiteProfile> loadlist;
|
public int buildNumber;
|
||||||
|
public List<SkinSiteProfile> loadlist;
|
||||||
//Function
|
|
||||||
public boolean enableDynamicSkull=true;
|
|
||||||
public boolean enableTransparentSkin=true;
|
|
||||||
public boolean ignoreHttpsCertificate=false;
|
|
||||||
public boolean forceLoadAllTextures=false;
|
|
||||||
|
|
||||||
//Cache
|
|
||||||
public int cacheExpiry=10;
|
|
||||||
public boolean enableUpdateSkull=false;
|
|
||||||
public boolean enableLocalProfileCache=false;
|
|
||||||
public boolean enableCacheAutoClean=false;
|
|
||||||
|
|
||||||
|
|
||||||
//Init config
|
|
||||||
public Config(SkinSiteProfile[] loadlist){
|
|
||||||
this.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
|
||||||
this.loadlist=Arrays.asList(loadlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Config loadConfig0() {
|
|
||||||
Config config=loadConfig();
|
|
||||||
|
|
||||||
//LoadList null checker
|
|
||||||
if(config.loadlist==null){
|
|
||||||
config.loadlist=new ArrayList<SkinSiteProfile>();
|
|
||||||
}else{
|
|
||||||
for(int i=0;i<config.loadlist.size();i++){
|
|
||||||
if(config.loadlist.get(i)==null)
|
|
||||||
config.loadlist.remove(i--);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Init program
|
|
||||||
config.loadExtraList();
|
|
||||||
config.initLocalFolder();
|
|
||||||
if(config.ignoreHttpsCertificate)
|
|
||||||
HttpUtil0.ignoreHttpsCertificate();
|
|
||||||
if(config.enableCacheAutoClean && !config.enableLocalProfileCache){
|
|
||||||
try{
|
|
||||||
FileUtils.deleteDirectory(HttpRequestUtil.CACHE_DIR);
|
|
||||||
FileUtils.deleteDirectory(HttpTextureUtil.getCacheDir());
|
|
||||||
CustomSkinLoader.logger.info("Successfully cleaned cache.");
|
|
||||||
}catch(Exception e){
|
|
||||||
CustomSkinLoader.logger.warning("Exception occurs while cleaning cache: "+e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Output config
|
|
||||||
CustomSkinLoader.logger.info("EnableDynamicSkull:"+config.enableDynamicSkull+
|
|
||||||
", EnableTranSkin:"+config.enableTransparentSkin+
|
|
||||||
", IgnoreHttpsCertificate:"+config.ignoreHttpsCertificate+
|
|
||||||
", CacheExpiry:"+config.cacheExpiry+
|
|
||||||
", EnableUpdateSkull:"+config.enableUpdateSkull+
|
|
||||||
", EnableLocalProfileCache:"+config.enableLocalProfileCache+
|
|
||||||
", EnableCacheAutoClean:"+config.enableCacheAutoClean+
|
|
||||||
", LoadList:"+(config.loadlist==null?0:config.loadlist.size()));
|
|
||||||
|
|
||||||
//Check config version
|
|
||||||
float floatVersion=0f;
|
|
||||||
float configVersion=0f;
|
|
||||||
try{
|
|
||||||
floatVersion=Float.parseFloat(CustomSkinLoader.CustomSkinLoader_VERSION);
|
|
||||||
configVersion=Float.parseFloat(config.version);
|
|
||||||
if(configVersion==15.1f)//To avoid some bug
|
|
||||||
configVersion=14.6f;
|
|
||||||
}catch (Exception e){
|
|
||||||
CustomSkinLoader.logger.warning("Exception occurs while parsing version: "+e.toString());
|
|
||||||
}
|
|
||||||
if(config.version==null || configVersion==0f || floatVersion > configVersion){
|
|
||||||
CustomSkinLoader.logger.info("Config File is out of date: "+config.version);
|
|
||||||
config.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
|
||||||
writeConfig(config,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Config loadConfig() {
|
//Function
|
||||||
CustomSkinLoader.logger.info("Config File: "+CustomSkinLoader.CONFIG_FILE.getAbsolutePath());
|
public boolean enableDynamicSkull = true;
|
||||||
if(!CustomSkinLoader.CONFIG_FILE.exists()){
|
public boolean enableTransparentSkin = true;
|
||||||
CustomSkinLoader.logger.info("Config file not found, use default instead.");
|
public boolean forceIgnoreHttpsCertificate = false;
|
||||||
return initConfig();
|
public boolean forceLoadAllTextures = true;
|
||||||
}
|
public boolean enableCape = true;
|
||||||
try {
|
public int threadPoolSize = 8;
|
||||||
CustomSkinLoader.logger.info("Try to load config.");
|
/**
|
||||||
String json=FileUtils.readFileToString(CustomSkinLoader.CONFIG_FILE,Charsets.UTF_8);
|
* Can logger write message to standard output(System.out).
|
||||||
Config config=CustomSkinLoader.GSON.fromJson(json, Config.class);
|
* Because standard output won't write to latest.log after Forge 1.17,
|
||||||
CustomSkinLoader.logger.info("Successfully load config.");
|
* printing to standard output is meaningless,
|
||||||
return config;
|
* which makes this switch default value is <code>false</code>.
|
||||||
}catch (Exception e) {
|
* @since 14.15
|
||||||
CustomSkinLoader.logger.info("Failed to load config, use default instead.("+e.toString()+")");
|
*/
|
||||||
File brokenFile=new File(CustomSkinLoader.DATA_DIR,"BROKEN-CustomSkinLoader.json");
|
public boolean enableLogStdOut = false;
|
||||||
if(brokenFile.exists())
|
|
||||||
brokenFile.delete();
|
|
||||||
CustomSkinLoader.CONFIG_FILE.renameTo(brokenFile);
|
|
||||||
return initConfig();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadExtraList(){
|
|
||||||
File listAddition=new File(CustomSkinLoader.DATA_DIR,"ExtraList");
|
|
||||||
if(!listAddition.isDirectory()){
|
|
||||||
listAddition.mkdirs();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<SkinSiteProfile> adds=new ArrayList<SkinSiteProfile>();
|
|
||||||
File[] files=listAddition.listFiles();
|
|
||||||
for(File file:files){
|
|
||||||
if(!file.getName().toLowerCase().endsWith(".json")&&!file.getName().toLowerCase().endsWith(".txt"))
|
|
||||||
continue;
|
|
||||||
try {
|
|
||||||
CustomSkinLoader.logger.info("Try to load Extra List.("+file.getName()+")");
|
|
||||||
String json=FileUtils.readFileToString(file,Charsets.UTF_8);
|
|
||||||
SkinSiteProfile ssp=CustomSkinLoader.GSON.fromJson(json, SkinSiteProfile.class);
|
|
||||||
CustomSkinLoader.logger.info("Successfully load Extra List.");
|
|
||||||
file.delete();
|
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
|
||||||
if(loader==null){
|
|
||||||
CustomSkinLoader.logger.info("Extra List will be ignore: Type '"+ssp.type+"' is not defined.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
boolean duplicate=false;
|
|
||||||
for(SkinSiteProfile ssp0:this.loadlist){
|
|
||||||
if(!ssp0.type.equalsIgnoreCase(ssp.type))
|
|
||||||
continue;
|
|
||||||
if(loader.compare(ssp0, ssp)){
|
|
||||||
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 ignore: Duplicate.("+ssp.name+")");
|
|
||||||
}
|
|
||||||
}catch (Exception e) {
|
|
||||||
CustomSkinLoader.logger.info("Failed to load Extra List.("+e.toString()+")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(adds.size()!=0){
|
|
||||||
adds.addAll(this.loadlist);
|
|
||||||
this.loadlist=adds;
|
|
||||||
writeConfig(this,true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initLocalFolder(){
|
|
||||||
for(SkinSiteProfile ssp:this.loadlist){
|
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
|
||||||
if(loader==null)
|
|
||||||
continue;
|
|
||||||
loader.initLocalFolder(ssp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Config initConfig() {
|
//Profile Cache
|
||||||
Config config=new Config(CustomSkinLoader.DEFAULT_LOAD_LIST);
|
public int cacheExpiry = 30;
|
||||||
writeConfig(config,false);
|
public boolean forceUpdateSkull = false;
|
||||||
return config;
|
public boolean enableLocalProfileCache = false;
|
||||||
}
|
|
||||||
private static void writeConfig(Config config,boolean update){
|
//Network Cache
|
||||||
String json=CustomSkinLoader.GSON.toJson(config);
|
public boolean enableCacheAutoClean = false;
|
||||||
if(CustomSkinLoader.CONFIG_FILE.exists())
|
public boolean forceDisableCache = false;
|
||||||
CustomSkinLoader.CONFIG_FILE.delete();
|
|
||||||
try {
|
// Used by Gson to create an instance with default value.
|
||||||
CustomSkinLoader.CONFIG_FILE.createNewFile();
|
public Config() {
|
||||||
FileUtils.write(CustomSkinLoader.CONFIG_FILE, json, Charsets.UTF_8);
|
this(new ArrayList<>());
|
||||||
CustomSkinLoader.logger.info("Successfully "+(update?"update":"create")+" config.");
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
CustomSkinLoader.logger.info("Failed to "+(update?"update":"create")+" config.("+e.toString()+")");
|
//Init config
|
||||||
}
|
public Config(List<SkinSiteProfile> loadlist) {
|
||||||
}
|
this.version = CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||||
|
this.buildNumber = CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER;
|
||||||
|
this.loadlist = loadlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Config loadConfig0() {
|
||||||
|
Config config = loadConfig();
|
||||||
|
|
||||||
|
//LoadList null checker
|
||||||
|
if (config.loadlist == null) {
|
||||||
|
config.loadlist = new ArrayList<>();
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < config.loadlist.size(); i++) {
|
||||||
|
if (config.loadlist.get(i) == null)
|
||||||
|
config.loadlist.remove(i--);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Init program
|
||||||
|
config.loadExtraList();
|
||||||
|
config.updateLoadlist();
|
||||||
|
config.initLocalFolder();
|
||||||
|
config.threadPoolSize = Math.max(config.threadPoolSize, 1);
|
||||||
|
if (config.forceIgnoreHttpsCertificate)
|
||||||
|
HttpUtil0.ignoreHttpsCertificate();
|
||||||
|
if (config.enableCacheAutoClean && !config.enableLocalProfileCache) {
|
||||||
|
try {
|
||||||
|
FileUtils.deleteDirectory(HttpRequestUtil.CACHE_DIR);
|
||||||
|
FileUtils.deleteDirectory(HttpTextureUtil.getCacheDir());
|
||||||
|
CustomSkinLoader.logger.info("Successfully cleaned cache.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
CustomSkinLoader.logger.warning("Exception occurs while cleaning cache: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check config version
|
||||||
|
Version configVersion = Version.of(config.version);
|
||||||
|
if (CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER == 0 // Custom builds
|
||||||
|
|| 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.buildNumber = CustomSkinLoader.CustomSkinLoader_BUILD_NUMBER;
|
||||||
|
}
|
||||||
|
writeConfig(config, true);
|
||||||
|
|
||||||
|
//Output config
|
||||||
|
for (Field field : config.getClass().getDeclaredFields()) {
|
||||||
|
try {
|
||||||
|
Object value = field.get(config);
|
||||||
|
CustomSkinLoader.logger.info(field.getName() + " : " + value);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Config loadConfig() {
|
||||||
|
CustomSkinLoader.logger.info("Config File: " + CustomSkinLoader.CONFIG_FILE.getAbsolutePath());
|
||||||
|
if (!CustomSkinLoader.CONFIG_FILE.exists()) {
|
||||||
|
CustomSkinLoader.logger.info("Config file not found, use default instead.");
|
||||||
|
return initConfig();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CustomSkinLoader.logger.info("Try to load config.");
|
||||||
|
String json = FileUtils.readFileToString(CustomSkinLoader.CONFIG_FILE, "UTF-8");
|
||||||
|
Config config = Objects.requireNonNull(CustomSkinLoader.GSON.fromJson(json, Config.class));
|
||||||
|
CustomSkinLoader.logger.info("Successfully load config.");
|
||||||
|
return config;
|
||||||
|
} catch (Exception e) {
|
||||||
|
CustomSkinLoader.logger.info("Failed to load config, use default instead.(" + e + ")");
|
||||||
|
createBrokenFile(CustomSkinLoader.CONFIG_FILE);
|
||||||
|
return initConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadExtraList() {
|
||||||
|
File listAddition = new File(CustomSkinLoader.DATA_DIR, "ExtraList");
|
||||||
|
if (!listAddition.isDirectory()) {
|
||||||
|
listAddition.mkdirs();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<SkinSiteProfile> adds = new ArrayList<>();
|
||||||
|
File[] files = listAddition.listFiles();
|
||||||
|
for (File file : files != null ? files : new File[0]) {
|
||||||
|
if (!file.getName().toLowerCase().endsWith(".json") && !file.getName().toLowerCase().endsWith(".txt"))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
CustomSkinLoader.logger.info("Try to load Extra List.(" + file.getName() + ")");
|
||||||
|
String json = FileUtils.readFileToString(file, "UTF-8");
|
||||||
|
SkinSiteProfile ssp = CustomSkinLoader.GSON.fromJson(json, SkinSiteProfile.class);
|
||||||
|
CustomSkinLoader.logger.info("Successfully load Extra List.");
|
||||||
|
if (ssp.type != null) {
|
||||||
|
ProfileLoader.IProfileLoader loader = ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
|
if (loader == null) {
|
||||||
|
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;
|
||||||
|
if (loader.compare(ssp0, ssp)) {
|
||||||
|
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) {
|
||||||
|
CustomSkinLoader.logger.info("Failed to load Extra List.(" + e + ")");
|
||||||
|
createBrokenFile(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (adds.size() != 0) {
|
||||||
|
adds.addAll(this.loadlist);
|
||||||
|
this.loadlist = adds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
for (SkinSiteProfile ssp : this.loadlist) {
|
||||||
|
if (ssp.type == null)
|
||||||
|
continue;
|
||||||
|
ProfileLoader.IProfileLoader loader = ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
|
if (loader == null)
|
||||||
|
continue;
|
||||||
|
loader.init(ssp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
List<ICustomSkinLoaderPlugin.IDefaultProfile> profiles = new ArrayList<>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeConfig(Config config, boolean update) {
|
||||||
|
String json = CustomSkinLoader.GSON.toJson(config);
|
||||||
|
if (CustomSkinLoader.CONFIG_FILE.exists())
|
||||||
|
CustomSkinLoader.CONFIG_FILE.delete();
|
||||||
|
try {
|
||||||
|
CustomSkinLoader.CONFIG_FILE.createNewFile();
|
||||||
|
FileUtils.write(CustomSkinLoader.CONFIG_FILE, json, "UTF-8");
|
||||||
|
CustomSkinLoader.logger.info("Successfully " + (update ? "update" : "create") + " config.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
CustomSkinLoader.logger.info("Failed to " + (update ? "update" : "create") + " config.(" + e + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,64 +1,44 @@
|
|||||||
package customskinloader.config;
|
package customskinloader.config;
|
||||||
|
|
||||||
import customskinloader.loader.jsonapi.CustomSkinAPIPlus.CustomSkinAPIPlusPrivacy;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class SkinSiteProfile {
|
public class SkinSiteProfile {
|
||||||
public String name;
|
//Common
|
||||||
public String type;
|
public String name;
|
||||||
public String userAgent;
|
public String type;
|
||||||
|
public String userAgent;
|
||||||
public String root;
|
|
||||||
public CustomSkinAPIPlusPrivacy privacy;
|
//Mojang API
|
||||||
|
public String apiRoot;
|
||||||
public Boolean checkPNG;//Not suitable for local skin
|
public String sessionRoot;
|
||||||
public String skin;
|
|
||||||
public String model;
|
//Json API
|
||||||
public String cape;
|
public String root;
|
||||||
public String elytra;
|
|
||||||
|
//Legacy
|
||||||
public static SkinSiteProfile createMojangAPI(String name){
|
public Boolean checkPNG;//Not suitable for local skin
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
public String skin;
|
||||||
ssp.name=name;
|
public String model;
|
||||||
ssp.type="MojangAPI";
|
public String cape;
|
||||||
return ssp;
|
public String elytra;
|
||||||
}
|
|
||||||
public static SkinSiteProfile createCustomSkinAPI(String name,String root){
|
@Override
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
public String toString() {
|
||||||
ssp.name=name;
|
StringBuilder sb = new StringBuilder("{ ");
|
||||||
ssp.type="CustomSkinAPI";
|
Field[] fields = SkinSiteProfile.class.getDeclaredFields();
|
||||||
ssp.root=root;
|
boolean first = true;
|
||||||
return ssp;
|
for (Field field : fields) {
|
||||||
}
|
try {
|
||||||
public static SkinSiteProfile creatCustomSkinAPIPlus(String name,String root){
|
Object value = field.get(this);
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
if (value == null) continue;
|
||||||
ssp.name=name;
|
if (first) {
|
||||||
ssp.type="CustomSkinAPIPlus";
|
first = false;
|
||||||
ssp.root=root;
|
} else {
|
||||||
ssp.privacy=new CustomSkinAPIPlusPrivacy();
|
sb.append(", ");
|
||||||
return ssp;
|
}
|
||||||
}
|
sb.append("\"").append(field.getName()).append("\": \"").append(value).append("\"");
|
||||||
public static SkinSiteProfile createUniSkinAPI(String name,String root){
|
} catch (Exception ignored) { }
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
}
|
||||||
ssp.name=name;
|
return sb.append(" }").toString();
|
||||||
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="default";
|
|
||||||
ssp.cape=cape;
|
|
||||||
ssp.elytra=elytra;
|
|
||||||
return ssp;
|
|
||||||
}
|
|
||||||
public static SkinSiteProfile createElfSkin(String name){
|
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
|
||||||
ssp.name=name;
|
|
||||||
ssp.type="ElfSkin";
|
|
||||||
return ssp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,269 @@
|
|||||||
|
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 final ResourceLocation location;
|
||||||
|
private String type = null;
|
||||||
|
|
||||||
|
public FakeCapeBuffer(ResourceLocation location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FakeImage parseUserSkin(FakeImage image) {
|
||||||
|
if (image == null) return null;
|
||||||
|
if (isOptiFineCape(image)) {
|
||||||
|
//OptiFine cape should be converted to standard cape
|
||||||
|
this.image = convertOptiFineCape(image);
|
||||||
|
//OptiFine cape contains elytra texture
|
||||||
|
//this.type = "elytra";//But its elytra texture doesn't work
|
||||||
|
} else {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When resource packs were changed, the elytra image needs to be reloaded, and here will be entered again
|
||||||
|
// The first cape which find elytra texture is outdated will reload it
|
||||||
|
if (this.loaded == loadedGlobal) {
|
||||||
|
elytraImage = loadElytra(this.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Judge OptiFine cape.
|
||||||
|
* OptiFine cape is 46*22 or 92*44 pixels.
|
||||||
|
* <a href="https://optifine.net/capes/Notch.png">46*22 example</a>
|
||||||
|
* <a href="https://optifine.net/capes/OptiFineCape.png">92*44 example</a>
|
||||||
|
*
|
||||||
|
* @param image cape image
|
||||||
|
* @return true if is OptiFine cape
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
private static boolean isOptiFineCape(FakeImage image) {
|
||||||
|
int ratio = image.getWidth() / 46;
|
||||||
|
return image.getHeight() == 22 * ratio && image.getWidth() == 46 * ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert OptiFine cape to standard cape
|
||||||
|
*
|
||||||
|
* @param image OptiFine cape image
|
||||||
|
* @return standard cape image
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
private static FakeImage convertOptiFineCape(FakeImage image) {
|
||||||
|
int ratio = image.getWidth() / 46;
|
||||||
|
FakeImage newImage = image.createImage(64 * ratio, 32 * ratio);
|
||||||
|
copyImageData(image, newImage);
|
||||||
|
return newImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy image data to another image
|
||||||
|
*
|
||||||
|
* @param from from image
|
||||||
|
* @param to to image
|
||||||
|
*/
|
||||||
|
private static void copyImageData(FakeImage from, FakeImage to) {
|
||||||
|
int width = Math.min(from.getWidth(), to.getWidth());
|
||||||
|
int height = Math.min(from.getHeight(), to.getHeight());
|
||||||
|
for (int x = 0; x < width; ++x) {
|
||||||
|
for (int y = 0; y < height; ++y) {
|
||||||
|
to.setRGBA(x, y, from.getRGBA(x, y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package customskinloader.fake;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||||
|
|
||||||
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import customskinloader.utils.MinecraftUtil;
|
||||||
|
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||||
|
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||||
|
import net.minecraft.client.renderer.texture.SimpleTexture;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
|
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||||
|
import net.minecraft.client.resources.SkinManager;
|
||||||
|
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.StringUtils;
|
||||||
|
|
||||||
|
public class FakeClientPlayer {
|
||||||
|
/**
|
||||||
|
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinManager.SkinAvailableCallback)}
|
||||||
|
*/
|
||||||
|
public static ThreadDownloadImageData putCache(ThreadDownloadImageData threaddownloadimagedata, SkinManager.SkinAvailableCallback skinAvailableCallback, ResourceLocation resourcelocation) {
|
||||||
|
if (skinAvailableCallback instanceof FakeClientPlayer.LegacyBuffer) {//Cache for client player
|
||||||
|
textureCache.put(resourcelocation, threaddownloadimagedata);
|
||||||
|
}
|
||||||
|
return threaddownloadimagedata;
|
||||||
|
}
|
||||||
|
|
||||||
|
//For Legacy Skin
|
||||||
|
public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username) {
|
||||||
|
//CustomSkinLoader.logger.debug("FakeClientPlayer/getDownloadImageSkin "+username);
|
||||||
|
TextureManager textman = MinecraftUtil.getTextureManager();
|
||||||
|
ITextureObject ito = textman.getTexture(resourceLocationIn);
|
||||||
|
|
||||||
|
if (ito == null || !(ito instanceof ThreadDownloadImageData)) {
|
||||||
|
//if Legacy Skin for username not loaded yet
|
||||||
|
SkinManager skinman = MinecraftUtil.getSkinManager();
|
||||||
|
UUID offlineUUID = getOfflineUUID(username);
|
||||||
|
GameProfile offlineProfile = new GameProfile(offlineUUID, username);
|
||||||
|
|
||||||
|
//Load Default Skin
|
||||||
|
ResourceLocation defaultSkin = DefaultPlayerSkin.getDefaultSkin(offlineUUID);
|
||||||
|
ITextureObject defaultSkinObj = new SimpleTexture(defaultSkin);
|
||||||
|
textman.loadTexture(resourceLocationIn, defaultSkinObj);
|
||||||
|
|
||||||
|
//Load Skin from SkinManager
|
||||||
|
skinman.loadProfileTextures(offlineProfile, new LegacyBuffer(resourceLocationIn), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ito instanceof ThreadDownloadImageData)
|
||||||
|
return (ThreadDownloadImageData) ito;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResourceLocation getLocationSkin(String username) {
|
||||||
|
//CustomSkinLoader.logger.debug("FakeClientPlayer/getLocationSkin "+username);
|
||||||
|
return new ResourceLocation("skins/legacy-" + StringUtils.stripControlCodes(username));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID getOfflineUUID(String username) {
|
||||||
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<ResourceLocation, ITextureObject> textureCache = Maps.newHashMap();
|
||||||
|
|
||||||
|
public static class LegacyBuffer implements SkinAvailableCallback {
|
||||||
|
ResourceLocation resourceLocationIn;
|
||||||
|
boolean loaded = false;
|
||||||
|
|
||||||
|
public LegacyBuffer(ResourceLocation resourceLocationIn) {
|
||||||
|
CustomSkinLoader.logger.debug("Loading Legacy Texture (" + resourceLocationIn + ")");
|
||||||
|
this.resourceLocationIn = resourceLocationIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void skinAvailable(Type typeIn, ResourceLocation location, MinecraftProfileTexture profileTexture) {
|
||||||
|
if (typeIn != Type.SKIN || loaded)
|
||||||
|
return;
|
||||||
|
|
||||||
|
TextureManager textman = MinecraftUtil.getTextureManager();
|
||||||
|
ITextureObject ito = textman.getTexture(location);
|
||||||
|
if (ito == null)
|
||||||
|
ito = textureCache.get(location);
|
||||||
|
if (ito == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
loaded = true;
|
||||||
|
textman.loadTexture(resourceLocationIn, ito);
|
||||||
|
CustomSkinLoader.logger.debug("Legacy Texture (" + resourceLocationIn + ") Loaded as " +
|
||||||
|
ito.toString() + " (" + location + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package customskinloader.fake;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
public class FakeMinecraftProfileTexture extends MinecraftProfileTexture {
|
||||||
|
private HttpTextureUtil.HttpTextureInfo info;
|
||||||
|
private ResourceLocation resourceLocation;
|
||||||
|
|
||||||
|
public FakeMinecraftProfileTexture(String url, Map<String, String> metadata) {
|
||||||
|
super(url, metadata);
|
||||||
|
this.info = HttpTextureUtil.toHttpTextureInfo(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceLocation(ResourceLocation resourceLocation) {
|
||||||
|
this.resourceLocation = resourceLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceLocation getResourceLocation() {
|
||||||
|
return this.resourceLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUrl() {
|
||||||
|
return this.info.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRawUrl() {
|
||||||
|
return super.getUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHash() {
|
||||||
|
return this.info.hash == null ? super.getHash() : this.info.hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getCacheFile() {
|
||||||
|
return this.info.cacheFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,117 +1,186 @@
|
|||||||
package customskinloader.fake;
|
package customskinloader.fake;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.DataBufferInt;
|
import java.util.function.Function;
|
||||||
import java.awt.image.ImageObserver;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class FakeSkinBuffer implements net.minecraft.client.renderer.IImageBuffer {
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import customskinloader.fake.texture.FakeBufferedImage;
|
||||||
|
import customskinloader.fake.texture.FakeImage;
|
||||||
|
import customskinloader.fake.texture.FakeNativeImage;
|
||||||
|
import net.minecraft.client.renderer.IImageBuffer;
|
||||||
|
import net.minecraft.client.renderer.texture.NativeImage;
|
||||||
|
|
||||||
private int[] imageData;
|
public class FakeSkinBuffer implements IImageBuffer {
|
||||||
private int ratio=1;
|
private int ratio = 1;
|
||||||
|
FakeImage image = null;
|
||||||
@Override
|
|
||||||
public BufferedImage parseUserSkin(BufferedImage image) {
|
|
||||||
if(image==null)
|
|
||||||
return null;
|
|
||||||
ratio = image.getWidth() / 64;
|
|
||||||
BufferedImage bufferedimage = new BufferedImage(64 * ratio, 64 * ratio, 2);
|
|
||||||
Graphics graphics = bufferedimage.getGraphics();
|
|
||||||
graphics.setColor(new Color(0,0,0,0));
|
|
||||||
graphics.fillRect(0,0,64,64);
|
|
||||||
graphics.drawImage(image,0,0,(ImageObserver)null);
|
|
||||||
if (image.getHeight() == 32 * ratio){//Single Layer
|
|
||||||
//Revert to original algorithm
|
|
||||||
//Right Leg -> Left Leg
|
|
||||||
graphics.drawImage(bufferedimage, 24 * ratio, 48 * ratio, 20 * ratio, 52 * ratio, 4 * ratio, 16 * ratio, 8 * ratio, 20 * ratio, (ImageObserver)null);//Top
|
|
||||||
graphics.drawImage(bufferedimage, 28 * ratio, 48 * ratio, 24 * ratio, 52 * ratio, 8 * ratio, 16 * ratio, 12 * ratio, 20 * ratio, (ImageObserver)null);//Bottom
|
|
||||||
graphics.drawImage(bufferedimage, 20 * ratio, 52 * ratio, 16 * ratio, 64 * ratio, 8 * ratio, 20 * ratio, 12 * ratio, 32 * ratio, (ImageObserver)null);//Left
|
|
||||||
graphics.drawImage(bufferedimage, 24 * ratio, 52 * ratio, 20 * ratio, 64 * ratio, 4 * ratio, 20 * ratio, 8 * ratio, 32 * ratio, (ImageObserver)null);//Front
|
|
||||||
graphics.drawImage(bufferedimage, 28 * ratio, 52 * ratio, 24 * ratio, 64 * ratio, 0 * ratio, 20 * ratio, 4 * ratio, 32 * ratio, (ImageObserver)null);//Right
|
|
||||||
graphics.drawImage(bufferedimage, 32 * ratio, 52 * ratio, 28 * ratio, 64 * ratio, 12 * ratio, 20 * ratio, 16 * ratio, 32 * ratio, (ImageObserver)null);//Back
|
|
||||||
//Right Arm -> Left Arm
|
|
||||||
graphics.drawImage(bufferedimage, 40 * ratio, 48 * ratio, 36 * ratio, 52 * ratio, 44 * ratio, 16 * ratio, 48 * ratio, 20 * ratio, (ImageObserver)null);//Top
|
|
||||||
graphics.drawImage(bufferedimage, 44 * ratio, 48 * ratio, 40 * ratio, 52 * ratio, 48 * ratio, 16 * ratio, 52 * ratio, 20 * ratio, (ImageObserver)null);//Bottom
|
|
||||||
graphics.drawImage(bufferedimage, 36 * ratio, 52 * ratio, 32 * ratio, 64 * ratio, 48 * ratio, 20 * ratio, 52 * ratio, 32 * ratio, (ImageObserver)null);//Left
|
|
||||||
graphics.drawImage(bufferedimage, 40 * ratio, 52 * ratio, 36 * ratio, 64 * ratio, 44 * ratio, 20 * ratio, 48 * ratio, 32 * ratio, (ImageObserver)null);//Front
|
|
||||||
graphics.drawImage(bufferedimage, 44 * ratio, 52 * ratio, 40 * ratio, 64 * ratio, 40 * ratio, 20 * ratio, 44 * ratio, 32 * ratio, (ImageObserver)null);//Right
|
|
||||||
graphics.drawImage(bufferedimage, 48 * ratio, 52 * ratio, 44 * ratio, 64 * ratio, 52 * ratio, 20 * ratio, 56 * ratio, 32 * ratio, (ImageObserver)null);//Back
|
|
||||||
}
|
|
||||||
graphics.dispose();
|
|
||||||
this.imageData = ((DataBufferInt)bufferedimage.getRaster().getDataBuffer()).getData();
|
|
||||||
|
|
||||||
setAreaDueToConfig( 0 * ratio, 0 * ratio,32 * ratio,16 * ratio);//Head - 1
|
|
||||||
setAreaTransparent(32 * ratio, 0 * ratio,64 * ratio,16 * ratio);//Head - 2
|
|
||||||
|
|
||||||
setAreaDueToConfig( 0 * ratio,16 * ratio,16 * ratio,32 * ratio);//Right Leg - 1
|
|
||||||
setAreaDueToConfig(16 * ratio,16 * ratio,40 * ratio,32 * ratio);//Body - 1
|
|
||||||
setAreaDueToConfig(40 * ratio,16 * ratio,56 * ratio,32 * ratio);//Right Arm - 1
|
|
||||||
|
|
||||||
setAreaTransparent( 0 * ratio,32 * ratio,16 * ratio,48 * ratio);//Right Leg - 2
|
|
||||||
setAreaTransparent(16 * ratio,32 * ratio,40 * ratio,48 * ratio);//Body - 2
|
|
||||||
setAreaTransparent(40 * ratio,32 * ratio,56 * ratio,48 * ratio);//Right Arm - 2
|
|
||||||
|
|
||||||
setAreaTransparent( 0 * ratio,48 * ratio,16 * ratio,64 * ratio);//Left Leg - 2
|
|
||||||
setAreaDueToConfig(16 * ratio,48 * ratio,32 * ratio,64 * ratio);//Left Leg - 1
|
|
||||||
setAreaDueToConfig(32 * ratio,48 * ratio,48 * ratio,64 * ratio);//Left Arm - 1
|
|
||||||
setAreaTransparent(48 * ratio,48 * ratio,64 * ratio,64 * ratio);//Left Arm - 2
|
|
||||||
|
|
||||||
return bufferedimage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 2^24-1
|
|
||||||
* 00000000 11111111 11111111 11111111 */
|
|
||||||
private static final int A=16777215;
|
|
||||||
private static final int WHITE=getARGB(255,255,255,255);
|
|
||||||
private static final int BLACK=getARGB(255,0,0,0);
|
|
||||||
private boolean isFilled(int x0,int y0,int x1,int y1){
|
|
||||||
int data=this.imageData[getPosition(x0,y0)];
|
|
||||||
if(data!=WHITE && data!=BLACK)
|
|
||||||
return false;
|
|
||||||
for (int x=x0;x<x1;++x)
|
|
||||||
for (int y=y0;y<y1;++y)
|
|
||||||
if(this.imageData[getPosition(x,y)]!=data)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
private void setAreaTransparent(int x0,int y0,int x1,int y1){
|
|
||||||
if(!isFilled(x0,y0,x1,y1))
|
|
||||||
return;
|
|
||||||
for (int x=x0;x<x1;++x)
|
|
||||||
for (int y=y0;y<y1;++y)
|
|
||||||
this.imageData[getPosition(x,y)] &= A;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -2^24
|
|
||||||
* 00000001 00000000 00000000 00000000 ->
|
|
||||||
* 11111110 11111111 11111111 11111111 ->
|
|
||||||
* 11111111 00000000 00000000 00000000 */
|
|
||||||
private static final int B=-16777216;
|
|
||||||
private void setAreaOpaque(int x0,int y0,int x1,int y1){
|
|
||||||
for (int x=x0;x<x1;++x)
|
|
||||||
for (int y=y0;y<y1;++y)
|
|
||||||
this.imageData[getPosition(x,y)] |= B;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setAreaDueToConfig(int x0,int y0,int x1,int y1){
|
|
||||||
if(customskinloader.CustomSkinLoader.config.enableTransparentSkin)
|
|
||||||
setAreaTransparent(x0,y0,x1,y1);
|
|
||||||
else
|
|
||||||
setAreaOpaque(x0,y0,x1,y1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//parseUserSkin for 1.15+
|
||||||
|
public static NativeImage processLegacySkin(NativeImage image, Runnable processTask, Function<NativeImage, NativeImage> processLegacySkin) {
|
||||||
|
if (processTask instanceof IImageBuffer) {
|
||||||
|
return ((IImageBuffer) processTask).func_195786_a(image);
|
||||||
|
}
|
||||||
|
return processLegacySkin.apply(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
//parseUserSkin for 1.13+
|
||||||
public void skinAvailable(){
|
public NativeImage func_195786_a(NativeImage image) {
|
||||||
//A callback when skin loaded
|
if (image == null)
|
||||||
}
|
return null;
|
||||||
|
|
||||||
private static int getARGB(int a,int r,int g,int b){
|
FakeImage img = parseUserSkin(new FakeNativeImage(image));
|
||||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
if (img instanceof FakeNativeImage)
|
||||||
}
|
return ((FakeNativeImage) img).getImage();
|
||||||
|
|
||||||
private int getPosition(int x,int y){
|
CustomSkinLoader.logger.warning("Failed to parseUserSkin(func_195786_a).");
|
||||||
return x+y*64*ratio;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//parseUserSkin for 1.12.2-
|
||||||
|
public BufferedImage parseUserSkin(BufferedImage image) {
|
||||||
|
if (image == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
FakeImage img = parseUserSkin(new FakeBufferedImage(image));
|
||||||
|
if (img instanceof FakeBufferedImage)
|
||||||
|
return ((FakeBufferedImage) img).getImage();
|
||||||
|
|
||||||
|
CustomSkinLoader.logger.warning("Failed to parseUserSkin.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeImage parseUserSkin(FakeImage image) {
|
||||||
|
if (image == null) return null;
|
||||||
|
this.ratio = image.getWidth() / 64;
|
||||||
|
|
||||||
|
if (image.getHeight() != image.getWidth()) {//Single Layer
|
||||||
|
//Create a new image and copy origin image data
|
||||||
|
FakeImage img = image.createImage(64 * ratio, 64 * ratio);
|
||||||
|
img.copyImageData(image);
|
||||||
|
image.close();
|
||||||
|
image = img;
|
||||||
|
image.fillArea(0 * ratio, 32 * ratio, 64 * ratio, 32 * ratio);
|
||||||
|
|
||||||
|
//Right Leg -> Left Leg
|
||||||
|
image.copyArea(4 * ratio, 16 * ratio, 16 * ratio, 32 * ratio, 4 * ratio, 4 * ratio, true, false);//Top
|
||||||
|
image.copyArea(8 * ratio, 16 * ratio, 16 * ratio, 32 * ratio, 4 * ratio, 4 * ratio, true, false);//Bottom
|
||||||
|
image.copyArea(0 * ratio, 20 * ratio, 24 * ratio, 32 * ratio, 4 * ratio, 12 * ratio, true, false);//Right
|
||||||
|
image.copyArea(4 * ratio, 20 * ratio, 16 * ratio, 32 * ratio, 4 * ratio, 12 * ratio, true, false);//Front
|
||||||
|
image.copyArea(8 * ratio, 20 * ratio, 8 * ratio, 32 * ratio, 4 * ratio, 12 * ratio, true, false);//Left
|
||||||
|
image.copyArea(12 * ratio, 20 * ratio, 16 * ratio, 32 * ratio, 4 * ratio, 12 * ratio, true, false);//Back
|
||||||
|
//Right Arm -> Left Arm
|
||||||
|
image.copyArea(44 * ratio, 16 * ratio, -8 * ratio, 32 * ratio, 4 * ratio, 4 * ratio, true, false);//Top
|
||||||
|
image.copyArea(48 * ratio, 16 * ratio, -8 * ratio, 32 * ratio, 4 * ratio, 4 * ratio, true, false);//Bottom
|
||||||
|
image.copyArea(40 * ratio, 20 * ratio, 0 * ratio, 32 * ratio, 4 * ratio, 12 * ratio, true, false);//Right
|
||||||
|
image.copyArea(44 * ratio, 20 * ratio, -8 * ratio, 32 * ratio, 4 * ratio, 12 * ratio, true, false);//Front
|
||||||
|
image.copyArea(48 * ratio, 20 * ratio, -16 * ratio, 32 * ratio, 4 * ratio, 12 * ratio, true, false);//Left
|
||||||
|
image.copyArea(52 * ratio, 20 * ratio, -8 * ratio, 32 * ratio, 4 * ratio, 12 * ratio, true, false);//Back
|
||||||
|
}
|
||||||
|
|
||||||
|
this.image = image;
|
||||||
|
setAreaDueToConfig(0 * ratio, 0 * ratio, 32 * ratio, 16 * ratio);//Head - 1
|
||||||
|
setAreaTransparent(32 * ratio, 0 * ratio, 64 * ratio, 16 * ratio);//Head - 2
|
||||||
|
setAreaDueToConfig(16 * ratio, 16 * ratio, 40 * ratio, 32 * ratio);//Body - 1
|
||||||
|
setAreaTransparent(16 * ratio, 32 * ratio, 40 * ratio, 48 * ratio);//Body - 2
|
||||||
|
|
||||||
|
setAreaDueToConfig(40 * ratio, 16 * ratio, 56 * ratio, 32 * ratio);//Right Arm - 1
|
||||||
|
setAreaTransparent(40 * ratio, 32 * ratio, 56 * ratio, 48 * ratio);//Right Arm - 2
|
||||||
|
setAreaDueToConfig(0 * ratio, 16 * ratio, 16 * ratio, 32 * ratio);//Right Leg - 1
|
||||||
|
setAreaTransparent(0 * ratio, 32 * ratio, 16 * ratio, 48 * ratio);//Right Leg - 2
|
||||||
|
|
||||||
|
setAreaDueToConfig(32 * ratio, 48 * ratio, 48 * ratio, 64 * ratio);//Left Arm - 1
|
||||||
|
setAreaTransparent(48 * ratio, 48 * ratio, 64 * ratio, 64 * ratio);//Left Arm - 2
|
||||||
|
setAreaDueToConfig(16 * ratio, 48 * ratio, 32 * ratio, 64 * ratio);//Left Leg - 1
|
||||||
|
setAreaTransparent(0 * ratio, 48 * ratio, 16 * ratio, 64 * ratio);//Left Leg - 2
|
||||||
|
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
|
||||||
|
* Must be called after parseUserSkin
|
||||||
|
*
|
||||||
|
* @return type of skin (slim / default)
|
||||||
|
* @since 14.9
|
||||||
|
*/
|
||||||
|
public String judgeType() {
|
||||||
|
if (this.image == null)
|
||||||
|
return "default";
|
||||||
|
int bgColor = image.getRGBA(63 * ratio, 20 * ratio);
|
||||||
|
/*
|
||||||
|
* If background is transparent, all the pixels in ((54, 20), (55, 31)) areas is transparent,
|
||||||
|
* which means it is Alex model.
|
||||||
|
* If background is opaque, all the pixels in ((54, 20), (55, 31)) areas is same with background,
|
||||||
|
* which means it is Alex model.
|
||||||
|
* Otherwise, it is Steve model.
|
||||||
|
* */
|
||||||
|
Predicate<Integer> predicate = EQU_BG.apply(bgColor);
|
||||||
|
for (int x = 54 * ratio; x <= 55 * ratio; ++x) {
|
||||||
|
for (int y = 20 * ratio; y <= 31 * ratio; ++y) {
|
||||||
|
int color = image.getRGBA(x, y);
|
||||||
|
if (!predicate.test(color)) {
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "slim";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 2^24-1
|
||||||
|
* 00000000 11111111 11111111 11111111 */
|
||||||
|
private static final int A = 16777215;
|
||||||
|
private static final int WHITE = getARGB(255, 255, 255, 255);
|
||||||
|
private static final int BLACK = getARGB(255, 0, 0, 0);
|
||||||
|
|
||||||
|
private boolean isFilled(int x0, int y0, int x1, int y1) {
|
||||||
|
int data = image.getRGBA(x0, y0);
|
||||||
|
if (data != WHITE && data != BLACK)
|
||||||
|
return false;
|
||||||
|
for (int x = x0; x < x1; ++x)
|
||||||
|
for (int y = y0; y < y1; ++y)
|
||||||
|
if (image.getRGBA(x, y) != data)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAreaTransparent(int x0, int y0, int x1, int y1) {
|
||||||
|
if (!isFilled(x0, y0, x1, y1))
|
||||||
|
return;
|
||||||
|
for (int x = x0; x < x1; ++x)
|
||||||
|
for (int y = y0; y < y1; ++y)
|
||||||
|
image.setRGBA(x, y, image.getRGBA(x, y) & A);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -2^24
|
||||||
|
* 00000001 00000000 00000000 00000000 ->
|
||||||
|
* 11111110 11111111 11111111 11111111 ->
|
||||||
|
* 11111111 00000000 00000000 00000000 */
|
||||||
|
private static final int B = -16777216;
|
||||||
|
|
||||||
|
private void setAreaOpaque(int x0, int y0, int x1, int y1) {
|
||||||
|
for (int x = x0; x < x1; ++x)
|
||||||
|
for (int y = y0; y < y1; ++y)
|
||||||
|
image.setRGBA(x, y, image.getRGBA(x, y) | B);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAreaDueToConfig(int x0, int y0, int x1, int y1) {
|
||||||
|
if (customskinloader.CustomSkinLoader.config.enableTransparentSkin)
|
||||||
|
setAreaTransparent(x0, y0, x1, y1);
|
||||||
|
else
|
||||||
|
setAreaOpaque(x0, y0, x1, y1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void skinAvailable() {
|
||||||
|
//A callback when skin loaded, nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getARGB(int a, int r, int g, int b) {
|
||||||
|
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getA(int argb) {
|
||||||
|
return (argb & B) >>> 24;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,107 +2,178 @@ package customskinloader.fake;
|
|||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
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.utils.HttpTextureUtil;
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
import customskinloader.utils.HttpTextureUtil.HttpTextureInfo;
|
import customskinloader.utils.MinecraftUtil;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.IImageBuffer;
|
import net.minecraft.client.renderer.IImageBuffer;
|
||||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
|
||||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
|
||||||
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.SkinManager;
|
||||||
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
|
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
public class FakeSkinManager{
|
public class FakeSkinManager {
|
||||||
private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue());
|
private final TextureManager textureManager;
|
||||||
private final TextureManager textureManager;
|
|
||||||
|
|
||||||
public FakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) {
|
private final Map<ResourceLocation, MinecraftProfileTexture> modelCache = new ConcurrentHashMap<>();
|
||||||
this.textureManager=textureManagerInstance;
|
|
||||||
HttpTextureUtil.defaultCacheDir=skinCacheDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type textureType){
|
|
||||||
return this.loadSkin(profileTexture, textureType, null);
|
|
||||||
}
|
|
||||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, final SkinAvailableCallback skinAvailableCallback){
|
|
||||||
HttpTextureInfo info=HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl());
|
|
||||||
|
|
||||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);
|
|
||||||
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
|
|
||||||
|
|
||||||
if (itextureobject != null)//Have already loaded
|
public FakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) {
|
||||||
makeCallback(skinAvailableCallback,textureType, resourcelocation, profileTexture);
|
this.textureManager = textureManagerInstance;
|
||||||
else{
|
HttpTextureUtil.defaultCacheDir = skinCacheDirectory;
|
||||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(),
|
}
|
||||||
new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture));
|
|
||||||
this.textureManager.loadTexture(resourcelocation, threaddownloadimagedata);
|
|
||||||
}
|
|
||||||
return resourcelocation;
|
|
||||||
}
|
|
||||||
public void loadProfileTextures(final GameProfile profile, final SkinAvailableCallback skinAvailableCallback, final boolean requireSecure){
|
|
||||||
THREAD_POOL.submit(new Runnable(){
|
|
||||||
public void run(){
|
|
||||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
|
||||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
|
||||||
|
|
||||||
Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
/**
|
||||||
public void run(){
|
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinAvailableCallback)}
|
||||||
for(Type type:Type.values())
|
*/
|
||||||
if(map.containsKey(type))
|
public static ResourceLocation setResourceLocation(ResourceLocation resourceLocation, MinecraftProfileTexture profileTexture) {
|
||||||
FakeSkinManager.this.loadSkin((MinecraftProfileTexture)map.get(type), type, skinAvailableCallback);
|
if (profileTexture instanceof FakeMinecraftProfileTexture) {
|
||||||
}
|
((FakeMinecraftProfileTexture) profileTexture).setResourceLocation(resourceLocation);
|
||||||
});
|
}
|
||||||
}
|
return resourceLocation;
|
||||||
});
|
}
|
||||||
}
|
|
||||||
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile){
|
|
||||||
return CustomSkinLoader.loadProfileFromCache(profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void makeCallback(SkinAvailableCallback callback,Type type, ResourceLocation location, MinecraftProfileTexture texture){
|
|
||||||
if(callback!=null)
|
|
||||||
callback.skinAvailable(type, location, texture);
|
|
||||||
}
|
|
||||||
private class BaseBuffer implements IImageBuffer{
|
|
||||||
private IImageBuffer buffer;
|
|
||||||
|
|
||||||
private SkinAvailableCallback callback;
|
|
||||||
private Type type;
|
|
||||||
private ResourceLocation location;
|
|
||||||
private MinecraftProfileTexture texture;
|
|
||||||
public BaseBuffer(SkinAvailableCallback callback,Type type,ResourceLocation location,MinecraftProfileTexture texture){
|
|
||||||
this.buffer=(type==Type.SKIN?new FakeSkinBuffer():null);
|
|
||||||
|
|
||||||
this.callback=callback;
|
|
||||||
this.type=type;
|
|
||||||
this.location=location;
|
|
||||||
this.texture=texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BufferedImage parseUserSkin(BufferedImage image){
|
|
||||||
return buffer==null?image:buffer.parseUserSkin(image);
|
|
||||||
}
|
|
||||||
public void skinAvailable(){
|
|
||||||
if (buffer != null)
|
|
||||||
buffer.skinAvailable();
|
|
||||||
|
|
||||||
FakeSkinManager.makeCallback(callback,type, location, texture);
|
/**
|
||||||
}
|
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinAvailableCallback)}
|
||||||
}
|
* <p>
|
||||||
|
* {@code skinAvailableCallback.skinAvailable(textureType, resourcelocation, profileTexture);} -> {@code skinAvailableCallback.skinAvailable(textureType, resourcelocation, this.fakeManager.getModelCache(profileTexture, resourcelocation));}
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
|
public static MinecraftProfileTexture getModelCache(MinecraftProfileTexture profileTexture, FakeSkinManager fakeManager, ResourceLocation location) {
|
||||||
|
return fakeManager.modelCache.getOrDefault(location, profileTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked from {@link SkinManager#loadSkin(MinecraftProfileTexture, MinecraftProfileTexture.Type, SkinAvailableCallback)}
|
||||||
|
*/
|
||||||
|
public static Object[] createThreadDownloadImageData(ImmutableList<Object> list, FakeSkinManager fakeManager, MinecraftProfileTexture profileTexture, MinecraftProfileTexture.Type textureType, SkinManager.SkinAvailableCallback skinAvailableCallback) {
|
||||||
|
Object[] params = list.toArray();
|
||||||
|
if (profileTexture instanceof FakeMinecraftProfileTexture && params.length > 1) {
|
||||||
|
FakeMinecraftProfileTexture fakeProfileTexture = (FakeMinecraftProfileTexture) profileTexture;
|
||||||
|
ResourceLocation resourcelocation = fakeProfileTexture.getResourceLocation();
|
||||||
|
if (fakeProfileTexture.getResourceLocation() != null) {
|
||||||
|
params[0] = fakeProfileTexture.getCacheFile();
|
||||||
|
if (params[params.length - 2] instanceof Boolean) {
|
||||||
|
params[params.length - 2] = true;
|
||||||
|
}
|
||||||
|
params[params.length - 1] = fakeManager.new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, fakeProfileTexture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final static String KEY = "CustomSkinLoaderInfo";
|
||||||
|
/**
|
||||||
|
* Invoked from {@link SkinManager#loadProfileTextures(GameProfile, SkinAvailableCallback, boolean)}
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public static void loadProfileTextures(Runnable runnable, GameProfile profile) {
|
||||||
|
CustomSkinLoader.loadProfileTextures(() -> CustomSkinLoader.loadProfileLazily(profile, m -> {
|
||||||
|
// This is a hack.
|
||||||
|
((Multimap) profile.getProperties()).put(KEY, m);
|
||||||
|
runnable.run();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked from {@link SkinManager#lambda$loadProfileTextures$1(GameProfile, boolean, SkinAvailableCallback)}
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getUserProfile(MinecraftSessionService sessionService, GameProfile profile, boolean requireSecure) {
|
||||||
|
// This is a hack.
|
||||||
|
return (Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>) ((Optional) profile.getProperties().removeAll(KEY).stream().findFirst()).orElse(Maps.newHashMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked from {@link SkinManager#lambda$null$0(Map, SkinAvailableCallback)}
|
||||||
|
*/
|
||||||
|
public static void loadElytraTexture(SkinManager skinManager, Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map, SkinManager.SkinAvailableCallback skinAvailableCallback) {
|
||||||
|
for (int i = 2; i < MinecraftProfileTexture.Type.values().length; i++) {
|
||||||
|
MinecraftProfileTexture.Type type = MinecraftProfileTexture.Type.values()[i];
|
||||||
|
if (map.containsKey(type)) {
|
||||||
|
skinManager.loadSkin(map.get(type), type, skinAvailableCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile 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(MinecraftUtil.getSkinManager().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(SkinManager.SkinAvailableCallback callback, MinecraftProfileTexture.Type type, ResourceLocation location, MinecraftProfileTexture texture) {
|
||||||
|
if (callback != null)
|
||||||
|
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 IImageBuffer buffer;
|
||||||
|
|
||||||
|
private SkinManager.SkinAvailableCallback callback;
|
||||||
|
private MinecraftProfileTexture.Type type;
|
||||||
|
private ResourceLocation location;
|
||||||
|
private FakeMinecraftProfileTexture texture;
|
||||||
|
|
||||||
|
public BaseBuffer(SkinManager.SkinAvailableCallback callback, MinecraftProfileTexture.Type type, ResourceLocation location, FakeMinecraftProfileTexture texture) {
|
||||||
|
switch (type) {
|
||||||
|
case SKIN: this.buffer = new FakeSkinBuffer(); break;
|
||||||
|
case CAPE: this.buffer = new FakeCapeBuffer(location); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.callback = callback;
|
||||||
|
this.type = type;
|
||||||
|
this.location = location;
|
||||||
|
this.texture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public net.minecraft.client.renderer.texture.NativeImage func_195786_a(net.minecraft.client.renderer.texture.NativeImage image) {
|
||||||
|
return buffer instanceof FakeSkinBuffer ? ((FakeSkinBuffer) buffer).func_195786_a(image) : image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage parseUserSkin(BufferedImage image) {
|
||||||
|
return buffer instanceof FakeSkinBuffer ? ((FakeSkinBuffer) buffer).parseUserSkin(image) : image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void skinAvailable() {
|
||||||
|
if (buffer != null) {
|
||||||
|
buffer.skinAvailable();
|
||||||
|
if (shouldJudgeType(texture) && buffer instanceof FakeSkinBuffer) {
|
||||||
|
//Auto judge skin type
|
||||||
|
Map<String, String> metadata = Maps.newHashMap();
|
||||||
|
String type = ((FakeSkinBuffer) buffer).judgeType();
|
||||||
|
metadata.put("model", type);
|
||||||
|
texture = new FakeMinecraftProfileTexture(texture.getRawUrl(), metadata);
|
||||||
|
FakeSkinManager.this.modelCache.put(location, texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FakeSkinManager.makeCallback(callback, type, location, texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
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.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 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package customskinloader.fake.itf;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.resources.IResourceManager;
|
||||||
|
|
||||||
|
public interface IFakeMinecraft {
|
||||||
|
// 1.13.2+
|
||||||
|
default IResourceManager func_195551_G() {
|
||||||
|
return (IResourceManager) ((Minecraft) this).getResourceManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package customskinloader.fake.texture;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
public class FakeBufferedImage implements FakeImage {
|
||||||
|
private BufferedImage image;
|
||||||
|
private Graphics graphics;
|
||||||
|
|
||||||
|
public FakeBufferedImage(int width, int height) {
|
||||||
|
this(new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB));
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeBufferedImage(BufferedImage image) {
|
||||||
|
this.image = image;
|
||||||
|
graphics = image.getGraphics();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage getImage() {
|
||||||
|
graphics.dispose();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeImage createImage(int width, int height) {
|
||||||
|
return new FakeBufferedImage(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeImage createImage(InputStream is) throws IOException {
|
||||||
|
return new FakeBufferedImage(ImageIO.read(is));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return image.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return image.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRGBA(int x, int y) {
|
||||||
|
return image.getRGB(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRGBA(int x, int y, int rgba) {
|
||||||
|
image.setRGB(x, y, rgba);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyImageData(FakeImage image) {
|
||||||
|
if (!(image instanceof FakeBufferedImage)) return;
|
||||||
|
BufferedImage img = ((FakeBufferedImage) image).getImage();
|
||||||
|
graphics.drawImage(img, 0, 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillArea(int x0, int y0, int width, int height) {
|
||||||
|
graphics.setColor(new Color(0, 0, 0, 0));
|
||||||
|
graphics.fillRect(x0, y0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyArea(int x0, int y0, int dx, int dy, int width, int height, boolean reversex, boolean reversey) {
|
||||||
|
int x1 = x0 + width, x2 = x0 + dx, x3 = x2 + width;
|
||||||
|
int y1 = y0 + height, y2 = y0 + dy, y3 = y2 + height;
|
||||||
|
graphics.drawImage(image,
|
||||||
|
reversex ? x3 : x2, reversey ? y3 : y2,
|
||||||
|
reversex ? x2 : x3, reversey ? y2 : y3,
|
||||||
|
x0, y0, x1, y1, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
graphics.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package customskinloader.fake.texture;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public interface FakeImage {
|
||||||
|
FakeImage createImage(int width, int height);
|
||||||
|
|
||||||
|
FakeImage createImage(InputStream is) throws IOException;
|
||||||
|
|
||||||
|
int getWidth();
|
||||||
|
|
||||||
|
int getHeight();
|
||||||
|
|
||||||
|
int getRGBA(int x, int y);
|
||||||
|
|
||||||
|
void setRGBA(int x, int y, int rgba);
|
||||||
|
|
||||||
|
void copyImageData(FakeImage image);
|
||||||
|
|
||||||
|
void fillArea(int x0, int y0, int width, int height);
|
||||||
|
|
||||||
|
void copyArea(int x0, int y0, int dx, int dy, int width, int height, boolean reversex, boolean reversey);
|
||||||
|
|
||||||
|
void close();
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package customskinloader.fake.texture;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.texture.NativeImage;
|
||||||
|
|
||||||
|
public class FakeNativeImage implements FakeImage {
|
||||||
|
private NativeImage image;
|
||||||
|
|
||||||
|
public FakeNativeImage(int width, int height) {
|
||||||
|
this(new NativeImage(width, height, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeNativeImage(NativeImage image) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NativeImage getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeImage createImage(int width, int height) {
|
||||||
|
return new FakeNativeImage(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeImage createImage(InputStream is) {
|
||||||
|
return new FakeNativeImage(NativeImage.func_195713_a(is));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return image.func_195702_a();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return image.func_195714_b();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRGBA(int x, int y) {
|
||||||
|
return image.func_195709_a(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRGBA(int x, int y, int rgba) {
|
||||||
|
image.func_195700_a(x, y, rgba);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyImageData(FakeImage image) {
|
||||||
|
if (!(image instanceof FakeNativeImage)) return;
|
||||||
|
this.image.func_195703_a(((FakeNativeImage) image).getImage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillArea(int x0, int y0, int width, int height) {
|
||||||
|
image.func_195715_a(x0, y0, width, height, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copyArea(int x0, int y0, int dx, int dy, int width, int height, boolean reversex, boolean reversey) {
|
||||||
|
image.func_195699_a(x0, y0, dx, dy, width, height, reversex, reversey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,101 +1,166 @@
|
|||||||
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 {
|
||||||
public String toJsonUrl(String root,String username);
|
List<IDefaultProfile> getDefaultProfiles(JsonAPILoader loader);
|
||||||
public String getPayload(SkinSiteProfile ssp);
|
|
||||||
public UserProfile toUserProfile(String root,String json,boolean local);
|
String toJsonUrl(String root, String username);
|
||||||
public String getName();
|
|
||||||
}
|
default String getPayload(SkinSiteProfile ssp) {
|
||||||
public static class ErrorProfile{
|
return null;
|
||||||
public int errno;
|
}
|
||||||
public String msg;
|
|
||||||
}
|
/**
|
||||||
public static enum Type{
|
* get JSON API payload, which will make a POST request
|
||||||
CustomSkinAPI(new CustomSkinAPI()),CustomSkinAPIPlus(new CustomSkinAPIPlus()),UniSkinAPI(new UniSkinAPI());
|
*
|
||||||
public IJsonAPI jsonAPI;
|
* @param ssp skin site profile
|
||||||
private Type(IJsonAPI jsonAPI){
|
* @param username username
|
||||||
this.jsonAPI=jsonAPI;
|
* @return JSON payload
|
||||||
}
|
* @since 14.16
|
||||||
}
|
*/
|
||||||
|
default String getPayload(SkinSiteProfile ssp, String username) {
|
||||||
private Type type;
|
return getPayload(ssp);
|
||||||
public JsonAPILoader(Type type){
|
}
|
||||||
this.type=type;
|
|
||||||
}
|
UserProfile toUserProfile(String root, String json, boolean local);
|
||||||
|
|
||||||
@Override
|
String getName();
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
}
|
||||||
String username=gameProfile.getName();
|
|
||||||
boolean local=HttpUtil0.isLocal(ssp.root);
|
public static class ErrorProfile {
|
||||||
if(ssp.root==null||ssp.root.equals("")){
|
public int errno;
|
||||||
CustomSkinLoader.logger.info("Root not defined.");
|
public String msg;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
String jsonUrl=type.jsonAPI.toJsonUrl(ssp.root, username);
|
private final IJsonAPI jsonAPI;
|
||||||
String json;
|
|
||||||
if(local){
|
public JsonAPILoader(IJsonAPI jsonAPI) {
|
||||||
File jsonFile=new File(jsonUrl);
|
this.jsonAPI = jsonAPI;
|
||||||
if(!jsonFile.exists()){
|
}
|
||||||
CustomSkinLoader.logger.info("Profile File not found.");
|
|
||||||
return null;
|
// === ICustomSkinLoaderPlugin ===
|
||||||
}
|
|
||||||
json=IOUtils.toString(new FileInputStream(jsonFile));
|
@Override
|
||||||
}else{
|
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(jsonUrl).setCacheTime(60).setUserAgent(ssp.userAgent).setPayload(type.jsonAPI.getPayload(ssp)));
|
return this;
|
||||||
json=responce.content;
|
}
|
||||||
}
|
|
||||||
if(json==null||json.equals("")){
|
@Override
|
||||||
CustomSkinLoader.logger.info("Profile not found.");
|
public List<IDefaultProfile> getDefaultProfiles() {
|
||||||
return null;
|
return this.jsonAPI.getDefaultProfiles(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorProfile profile=CustomSkinLoader.GSON.fromJson(json, ErrorProfile.class);
|
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||||
if(profile.errno!=0){
|
protected final JsonAPILoader loader;
|
||||||
CustomSkinLoader.logger.info("Error "+profile.errno+": "+profile.msg);
|
|
||||||
return null;
|
public DefaultProfile(JsonAPILoader loader) {
|
||||||
}
|
this.loader = loader;
|
||||||
|
}
|
||||||
UserProfile p=type.jsonAPI.toUserProfile(ssp.root, json, local);
|
|
||||||
if(p==null||p.isEmpty()){
|
@Override
|
||||||
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||||
return null;
|
ssp.type = this.loader.getName();
|
||||||
}else{
|
ssp.root = this.getRoot();
|
||||||
return p;
|
}
|
||||||
}
|
|
||||||
}
|
public abstract String getRoot();
|
||||||
@Override
|
}
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
|
||||||
return StringUtils.isNoneEmpty(ssp0.root)?ssp0.root.equalsIgnoreCase(ssp1.root):true;
|
// === IProfileLoader ===
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
||||||
return type.jsonAPI.getName();
|
String username = gameProfile.getName();
|
||||||
}
|
if (StringUtils.isEmpty(ssp.root)) {
|
||||||
@Override
|
CustomSkinLoader.logger.info("Root not defined.");
|
||||||
public void initLocalFolder(SkinSiteProfile ssp) {
|
return null;
|
||||||
if(HttpUtil0.isLocal(ssp.root)){
|
}
|
||||||
File f=new File(ssp.root);
|
boolean local = HttpUtil0.isLocal(ssp.root);
|
||||||
if(!f.exists())
|
String jsonUrl = this.jsonAPI.toJsonUrl(ssp.root, username);
|
||||||
f.mkdirs();
|
//Some API like MinecraftCapesAPI won't load profile at sometime
|
||||||
}
|
if (jsonUrl == null) {
|
||||||
}
|
CustomSkinLoader.logger.info("Profile url not found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String json;
|
||||||
|
if (local) {
|
||||||
|
File jsonFile = new File(CustomSkinLoader.DATA_DIR, jsonUrl);
|
||||||
|
if (!jsonFile.exists()) {
|
||||||
|
CustomSkinLoader.logger.info("Profile File not found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
json = IOUtils.toString(Files.newInputStream(jsonFile.toPath()), StandardCharsets.UTF_8);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
HttpRequestUtil.HttpResponce responce = HttpRequestUtil
|
||||||
|
.makeHttpRequest(new HttpRequestUtil.HttpRequest(jsonUrl).setCacheTime(90)
|
||||||
|
.setUserAgent(ssp.userAgent).setPayload(this.jsonAPI.getPayload(ssp, username)));
|
||||||
|
json = responce.content;
|
||||||
|
} catch (ProfileNotFoundException ignored) {
|
||||||
|
CustomSkinLoader.logger.info("Profile not found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (json == null || json.equals("")) {
|
||||||
|
CustomSkinLoader.logger.info("Profile not found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorProfile profile = CustomSkinLoader.GSON.fromJson(json, ErrorProfile.class);
|
||||||
|
if (profile.errno != 0) {
|
||||||
|
CustomSkinLoader.logger.info("Error " + profile.errno + ": " + profile.msg);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserProfile p = this.jsonAPI.toUserProfile(ssp.root, json, local);
|
||||||
|
if (p == null || p.isEmpty()) {
|
||||||
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||||
|
return !StringUtils.isNoneEmpty(ssp0.root) || ssp0.root.equalsIgnoreCase(ssp1.root);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.jsonAPI.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(SkinSiteProfile ssp) {
|
||||||
|
if (HttpUtil0.isLocal(ssp.root)) {
|
||||||
|
File f = new File(ssp.root);
|
||||||
|
if (!f.exists())
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
f.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When getting payload, this exception can end skin loading
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
public static class ProfileNotFoundException extends RuntimeException {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,94 +1,236 @@
|
|||||||
package customskinloader.loader;
|
package customskinloader.loader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
public class LegacyLoader implements ProfileLoader.IProfileLoader {
|
public class LegacyLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||||
public static final String USERNAME_REGEX="\\{USERNAME\\}";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
|
||||||
String username=gameProfile.getName();
|
|
||||||
UserProfile profile=new UserProfile();
|
|
||||||
if(StringUtils.isNoneEmpty(ssp.skin)){
|
|
||||||
String skin=ssp.skin.replaceAll(USERNAME_REGEX, username);
|
|
||||||
if(HttpUtil0.isLocal(ssp.skin)){
|
|
||||||
File skinFile=new File(CustomSkinLoader.DATA_DIR,skin);
|
|
||||||
if(skinFile.exists()&&skinFile.isFile())
|
|
||||||
profile.skinUrl=HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified()));
|
|
||||||
}else{
|
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(60));
|
|
||||||
if(responce.success)
|
|
||||||
profile.skinUrl=HttpTextureUtil.getLegacyFakeUrl(skin);
|
|
||||||
}
|
|
||||||
profile.model=profile.hasSkinUrl()?ssp.model:null;
|
|
||||||
}
|
|
||||||
if(StringUtils.isNoneEmpty(ssp.cape)){
|
|
||||||
String cape=ssp.cape.replaceAll(USERNAME_REGEX, 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!=false).setLoadContent(false).setCacheTime(60));
|
|
||||||
if(responce.success)
|
|
||||||
profile.capeUrl=HttpTextureUtil.getLegacyFakeUrl(cape);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(ModelManager0.isElytraSupported()&&StringUtils.isNoneEmpty(ssp.elytra)){
|
|
||||||
String elytra=ssp.elytra.replaceAll(USERNAME_REGEX, 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!=false).setLoadContent(false).setCacheTime(60));
|
|
||||||
if(responce.success)
|
|
||||||
profile.elytraUrl=HttpTextureUtil.getLegacyFakeUrl(elytra);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(profile.isEmpty()){
|
|
||||||
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||||
return (StringUtils.isNoneEmpty(ssp0.skin)?ssp0.skin.equalsIgnoreCase(ssp1.skin):true) || (StringUtils.isNoneEmpty(ssp0.cape)?ssp0.cape.equalsIgnoreCase(ssp1.cape):true);
|
return this;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "Legacy";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initLocalFolder(SkinSiteProfile ssp) {
|
public List<IDefaultProfile> getDefaultProfiles() {
|
||||||
if(HttpUtil0.isLocal(ssp.skin))
|
return Lists.newArrayList(new LocalSkin(this),
|
||||||
initFolder(ssp.skin);
|
getCapeProfile(this, "OptiFine", "https://optifine.net/capes/{USERNAME}.png", 810),
|
||||||
if(HttpUtil0.isLocal(ssp.cape))
|
getCapeProfile(this, "CloakPlus", "http://161.35.130.99/capes/{USERNAME}.png", 840),
|
||||||
initFolder(ssp.cape);
|
getCapeProfile(this, "LabyMod", "https://dl.labymod.net/capes/{STANDARD_UUID}", 850),
|
||||||
if(HttpUtil0.isLocal(ssp.elytra))
|
getCapeProfile(this, "Cosmetica", "https://api.cosmetica.cc/get/cloak?username={USERNAME}&uuid={STANDARD_UUID}¬hirdparty", 860)
|
||||||
initFolder(ssp.elytra);
|
);
|
||||||
}
|
}
|
||||||
private void initFolder(String target){
|
|
||||||
String file=target.replaceAll(USERNAME_REGEX, "init");
|
public abstract static class DefaultProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||||
File folder=new File(CustomSkinLoader.DATA_DIR,file).getParentFile();
|
protected final LegacyLoader loader;
|
||||||
if(folder!=null&&!folder.exists())
|
|
||||||
folder.mkdirs();
|
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 710;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get cape Profile¬
|
||||||
|
*
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
public static LegacyLoader.DefaultProfile getCapeProfile(LegacyLoader loader, String name, String capeRoot, int priority) {
|
||||||
|
return new DefaultProfile(loader) {
|
||||||
|
@Override
|
||||||
|
public String getSkinRoot() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCapeRoot() {
|
||||||
|
return capeRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElytraRoot() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String USERNAME_PLACEHOLDER = "{USERNAME}";
|
||||||
|
public static final String UUID_PLACEHOLDER = "{UUID}";
|
||||||
|
/**
|
||||||
|
* Mojang UUID with -
|
||||||
|
*
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
public static final String STANDARD_UUID_PLACEHOLDER = "{STANDARD_UUID}";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) {
|
||||||
|
UserProfile profile = new UserProfile();
|
||||||
|
//Try to load all textures
|
||||||
|
getTextureUrl(ssp, gameProfile, ssp.skin, it -> {
|
||||||
|
profile.skinUrl = it;
|
||||||
|
profile.model = ssp.model;
|
||||||
|
});
|
||||||
|
getTextureUrl(ssp, gameProfile, ssp.cape, it -> profile.capeUrl = it);
|
||||||
|
getTextureUrl(ssp, gameProfile, ssp.elytra, it -> profile.elytraUrl = it);
|
||||||
|
|
||||||
|
if (profile.isEmpty()) {
|
||||||
|
CustomSkinLoader.logger.info("No texture could be found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
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
|
||||||
|
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||||
|
return Objects.equals(ssp0.skin, ssp1.skin) && Objects.equals(ssp0.cape, ssp1.cape) &&
|
||||||
|
Objects.equals(ssp0.elytra, ssp1.elytra);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Legacy";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(SkinSiteProfile ssp) {
|
||||||
|
initFolder(ssp.skin);
|
||||||
|
initFolder(ssp.cape);
|
||||||
|
initFolder(ssp.elytra);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
private void initFolder(String target) {
|
||||||
|
//Only local skin should init folder
|
||||||
|
if (!HttpUtil0.isLocal(target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String file = target.replace(USERNAME_PLACEHOLDER, "init");
|
||||||
|
File folder = new File(CustomSkinLoader.DATA_DIR, file).getParentFile();
|
||||||
|
if (folder != null && !folder.exists()) {
|
||||||
|
folder.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String expandURL(String url, String username) {
|
||||||
|
String t = url.replace(USERNAME_PLACEHOLDER, username);
|
||||||
|
if (!t.contains(UUID_PLACEHOLDER) && !t.contains(STANDARD_UUID_PLACEHOLDER)) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
String uuid = MojangAPILoader.getMojangUuidByUsername(username, true);
|
||||||
|
//If Mojang uuid not found, won't load the texture
|
||||||
|
if (uuid == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String styledUuid = uuid.replace("-", "");
|
||||||
|
return t.replace(UUID_PLACEHOLDER, styledUuid).replace(STANDARD_UUID_PLACEHOLDER, uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,94 +1,232 @@
|
|||||||
package customskinloader.loader;
|
package customskinloader.loader;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
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 java.util.concurrent.ConcurrentHashMap;
|
||||||
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;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
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.binary.Base64;
|
||||||
import customskinloader.utils.HttpRequestUtil.HttpResponce;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import customskinloader.utils.MinecraftUtil;
|
|
||||||
|
|
||||||
public class MojangAPILoader implements ProfileLoader.IProfileLoader {
|
public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||||
|
|
||||||
public static final MinecraftSessionService defaultSessionService=MinecraftUtil.getSessionService();
|
@Override
|
||||||
@Override
|
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
return this;
|
||||||
Map<MinecraftProfileTexture.Type,MinecraftProfileTexture> map=getTextures(gameProfile);
|
}
|
||||||
if(!map.isEmpty()){
|
|
||||||
CustomSkinLoader.logger.info("Default profile will be used.");
|
|
||||||
return ModelManager0.toUserProfile(map);
|
|
||||||
}
|
|
||||||
String username=gameProfile.getName();
|
|
||||||
GameProfile newGameProfile=loadGameProfile(username);
|
|
||||||
if(newGameProfile==null){
|
|
||||||
CustomSkinLoader.logger.info("Profile not found.("+username+"'s profile not found.)");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
newGameProfile=defaultSessionService.fillProfileProperties(newGameProfile, false);
|
|
||||||
map=getTextures(newGameProfile);
|
|
||||||
if(!map.isEmpty()){
|
|
||||||
gameProfile.getProperties().putAll(newGameProfile.getProperties());
|
|
||||||
return ModelManager0.toUserProfile(map);
|
|
||||||
}
|
|
||||||
CustomSkinLoader.logger.info("Profile not found.("+username+" doesn't have skin/cape.)");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameProfile loadGameProfile(String username) throws Exception{
|
|
||||||
//Doc (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time)
|
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest("https://api.mojang.com/users/profiles/minecraft/"+username).setCacheTime(0));
|
|
||||||
if(StringUtils.isEmpty(responce.content))
|
|
||||||
return null;
|
|
||||||
Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
|
||||||
GameProfile gameProfile=gson.fromJson(responce.content, GameProfile.class);
|
|
||||||
if(gameProfile.getId()==null)
|
|
||||||
return null;
|
|
||||||
return new GameProfile(gameProfile.getId(),gameProfile.getName());
|
|
||||||
}
|
|
||||||
public static Map<MinecraftProfileTexture.Type,MinecraftProfileTexture> getTextures(GameProfile gameProfile) throws Exception{
|
|
||||||
Property textureProperty=(Property)Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
|
|
||||||
if (textureProperty==null)
|
|
||||||
return new HashMap();
|
|
||||||
String value=textureProperty.getValue();
|
|
||||||
if(StringUtils.isBlank(value))
|
|
||||||
return new HashMap();
|
|
||||||
String json=new String(Base64.decodeBase64(value),Charsets.UTF_8);
|
|
||||||
Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create();
|
|
||||||
MinecraftTexturesPayload result=gson.fromJson(json,MinecraftTexturesPayload.class);
|
|
||||||
if (result==null||result.getTextures()==null)
|
|
||||||
return new HashMap();
|
|
||||||
return result.getTextures();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "MojangAPI";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initLocalFolder(SkinSiteProfile ssp) {
|
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);
|
||||||
|
if (!map.isEmpty()) {
|
||||||
|
CustomSkinLoader.logger.info("Default profile will be used.");
|
||||||
|
return ModelManager0.toUserProfile(map);
|
||||||
|
}
|
||||||
|
String username = gameProfile.getName();
|
||||||
|
GameProfile newGameProfile = loadGameProfileCached(ssp.apiRoot, username);
|
||||||
|
if (newGameProfile == null) {
|
||||||
|
CustomSkinLoader.logger.info("Profile not found.(" + username + "'s profile not found.)");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
newGameProfile = fillGameProfile(ssp.sessionRoot, newGameProfile);
|
||||||
|
map = getTextures(newGameProfile);
|
||||||
|
if (!map.isEmpty()) {
|
||||||
|
gameProfile.getProperties().putAll(newGameProfile.getProperties());
|
||||||
|
return ModelManager0.toUserProfile(map);
|
||||||
|
}
|
||||||
|
CustomSkinLoader.logger.info("Profile not found.(" + username + " doesn't have skin/cape.)");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<String, GameProfile> gameProfileCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static GameProfile loadGameProfileCached(String apiRoot, String username) {
|
||||||
|
return gameProfileCache.computeIfAbsent(apiRoot + " " + username,
|
||||||
|
ignored -> loadGameProfile(apiRoot, username));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Username -> UUID
|
||||||
|
public static GameProfile loadGameProfile(String apiRoot, String username) {
|
||||||
|
//Doc (https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs)
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
||||||
|
|
||||||
|
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(
|
||||||
|
new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft")
|
||||||
|
.setCacheTime(600).setPayload(gson.toJson(Collections.singletonList(username)))
|
||||||
|
);
|
||||||
|
if (StringUtils.isEmpty(responce.content)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameProfile[] profiles = gson.fromJson(responce.content, GameProfile[].class);
|
||||||
|
if (profiles.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
GameProfile gameProfile = profiles[0];
|
||||||
|
|
||||||
|
if (gameProfile.getId() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new GameProfile(gameProfile.getId(), gameProfile.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Mojang UUID by username.
|
||||||
|
*
|
||||||
|
* @param username username to query
|
||||||
|
* @param standard if - in UUID
|
||||||
|
* @return UUID in Mojang API style string. Returns {@code null} if username not found in Mojang API.
|
||||||
|
*/
|
||||||
|
public static String getMojangUuidByUsername(String username, boolean standard) {
|
||||||
|
GameProfile profile = loadGameProfileCached(getMojangApiRoot(), username);
|
||||||
|
if (profile == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
UUID id = profile.getId();
|
||||||
|
return standard ? id.toString() : UUIDTypeAdapter.fromUUID(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//UUID -> Profile
|
||||||
|
public static GameProfile fillGameProfile(String sessionRoot, GameProfile profile) {
|
||||||
|
//Doc (http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape)
|
||||||
|
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(
|
||||||
|
new HttpRequestUtil.HttpRequest(sessionRoot + "session/minecraft/profile/"
|
||||||
|
+ UUIDTypeAdapter.fromUUID(profile.getId())).setCacheTime(90));
|
||||||
|
if (StringUtils.isEmpty(responce.content)) {
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gson gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
||||||
|
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
||||||
|
.create();
|
||||||
|
MinecraftProfilePropertiesResponse propertiesResponce = gson.fromJson(responce.content, MinecraftProfilePropertiesResponse.class);
|
||||||
|
GameProfile newGameProfile = new GameProfile(propertiesResponce.getId(), propertiesResponce.getName());
|
||||||
|
newGameProfile.getProperties().putAll(propertiesResponce.getProperties());
|
||||||
|
|
||||||
|
return newGameProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile gameProfile) {
|
||||||
|
if (gameProfile == null) {
|
||||||
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
|
Property textureProperty = Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
|
||||||
|
if (textureProperty == null) {
|
||||||
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
|
String value = textureProperty.getValue();
|
||||||
|
if (StringUtils.isBlank(value)) {
|
||||||
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
|
String json = new String(Base64.decodeBase64(value), StandardCharsets.UTF_8);
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
||||||
|
MinecraftTexturesPayload result = gson.fromJson(json, MinecraftTexturesPayload.class);
|
||||||
|
if (result == null || result.getTextures() == null) {
|
||||||
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
|
return result.getTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||||
|
return (!StringUtils.isNoneEmpty(ssp0.apiRoot) || ssp0.apiRoot.equalsIgnoreCase(ssp1.apiRoot)) ||
|
||||||
|
(!StringUtils.isNoneEmpty(ssp0.sessionRoot) || ssp0.sessionRoot.equalsIgnoreCase(ssp1.sessionRoot));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "MojangAPI";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(SkinSiteProfile ssp) {
|
||||||
|
//Init default api & session root for Mojang API
|
||||||
|
if (ssp.apiRoot == null)
|
||||||
|
ssp.apiRoot = getMojangApiRoot();
|
||||||
|
if (ssp.sessionRoot == null)
|
||||||
|
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_SESSION_ROOT = "https://sessionserver{DO_NOT_MODIFY}.mojang.com/";
|
||||||
|
|
||||||
|
public static String getMojangApiRoot() {
|
||||||
|
return MOJANG_API_ROOT.replace("{DO_NOT_MODIFY}", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMojangSessionRoot() {
|
||||||
|
return MOJANG_SESSION_ROOT.replace("{DO_NOT_MODIFY}", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,32 +3,31 @@ 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.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),
|
private static HashMap<String, IProfileLoader> initLoaders() {
|
||||||
new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPIPlus),
|
HashMap<String, ProfileLoader.IProfileLoader> profileLoaders = new HashMap<>();
|
||||||
new LegacyLoader(),
|
for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS) {
|
||||||
new JsonAPILoader(JsonAPILoader.Type.UniSkinAPI)};
|
ProfileLoader.IProfileLoader profileLoader = plugin.getProfileLoader();
|
||||||
|
if (profileLoader != null) {
|
||||||
public static final HashMap<String,IProfileLoader> LOADERS=initLoaders();
|
profileLoaders.put(profileLoader.getName().toLowerCase(), profileLoader);
|
||||||
|
CustomSkinLoader.logger.info("Add a profile loader: " + profileLoader.getName());
|
||||||
private static HashMap<String, IProfileLoader> initLoaders() {
|
}
|
||||||
HashMap<String, IProfileLoader> loaders=new HashMap<String, IProfileLoader>();
|
}
|
||||||
for(IProfileLoader loader:DEFAULT_LOADERS){
|
return profileLoaders;
|
||||||
loaders.put(loader.getName().toLowerCase(), loader);
|
}
|
||||||
}
|
|
||||||
return loaders;
|
public interface IProfileLoader {
|
||||||
}
|
UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception;
|
||||||
|
boolean compare(SkinSiteProfile ssp0,SkinSiteProfile ssp1);
|
||||||
public interface IProfileLoader {
|
String getName();
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception;
|
void init(SkinSiteProfile ssp);
|
||||||
public boolean compare(SkinSiteProfile ssp0,SkinSiteProfile ssp1);
|
}
|
||||||
public String getName();
|
|
||||||
public void initLocalFolder(SkinSiteProfile ssp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,90 +1,144 @@
|
|||||||
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.loader.JsonAPILoader;
|
||||||
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
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 IJsonAPI {
|
public class CustomSkinAPI implements JsonAPILoader.IJsonAPI {
|
||||||
private static final String TEXTURES="textures/";
|
|
||||||
private static final String SUFFIX=".json";
|
|
||||||
|
|
||||||
@Override
|
public static class LittleSkin extends JsonAPILoader.DefaultProfile {
|
||||||
public String toJsonUrl(String root, String username) {
|
public LittleSkin(JsonAPILoader loader) {
|
||||||
return new StringBuilder().append(root).append(username).append(SUFFIX).toString();
|
super(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
public String getName() {
|
||||||
CustomSkinAPIProfile profile=CustomSkinLoader.GSON.fromJson(json, CustomSkinAPIProfile.class);
|
return "LittleSkin";
|
||||||
UserProfile p=new UserProfile();
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(profile.skin)){
|
@Override
|
||||||
p.skinUrl=root+TEXTURES+profile.skin;
|
public int getPriority() {
|
||||||
if(local)
|
return 200;
|
||||||
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
|
}
|
||||||
}
|
|
||||||
if(StringUtils.isNotBlank(profile.cape)){
|
@Override
|
||||||
p.capeUrl=root+TEXTURES+profile.cape;
|
public String getRoot() {
|
||||||
if(local)
|
return "https://littleskin.cn/csl/";
|
||||||
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
}
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(profile.elytra)){
|
|
||||||
p.elytraUrl=root+TEXTURES+profile.elytra;
|
public static class BlessingSkin extends JsonAPILoader.DefaultProfile {
|
||||||
if(local)
|
public BlessingSkin(JsonAPILoader loader) {
|
||||||
p.elytraUrl=HttpTextureUtil.getLocalFakeUrl(p.elytraUrl);
|
super(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String,String> textures=new LinkedHashMap<String,String>();
|
@Override
|
||||||
if(profile.skins!=null)
|
public String getName() {
|
||||||
textures.putAll(profile.skins);
|
return "BlessingSkin";
|
||||||
if(profile.textures!=null)
|
}
|
||||||
textures.putAll(profile.textures);
|
|
||||||
if(textures.isEmpty())
|
@Override
|
||||||
return p;
|
public int getPriority() {
|
||||||
|
return 300;
|
||||||
boolean hasSkin=false;
|
}
|
||||||
for(String model:textures.keySet()){
|
|
||||||
Model enumModel=ModelManager0.getEnumModel(model);
|
@Override
|
||||||
if(enumModel==null||StringUtils.isEmpty(textures.get(model)))
|
public String getRoot() {
|
||||||
continue;
|
return "https://skin.prinzeugen.net/";
|
||||||
if(ModelManager0.isSkin(enumModel))
|
}
|
||||||
if(hasSkin)
|
}
|
||||||
continue;
|
|
||||||
else
|
// // OneSkin has been removed temporarily
|
||||||
hasSkin=true;
|
// public static class OneSkin extends JsonAPILoader.DefaultProfile {
|
||||||
String url=root+TEXTURES+textures.get(model);
|
// public OneSkin(JsonAPILoader loader) { super(loader); }
|
||||||
if(local)
|
// @Override public String getName() { return "OneSkin"; }
|
||||||
url=HttpTextureUtil.getLocalFakeUrl(url);
|
// @Override public int getPriority() { return 500; }
|
||||||
p.put(enumModel, url);
|
// @Override public String getRoot() { return "http://fleey.cn/skin/skin_user/skin_json.php/"; }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return p;
|
private static final String TEXTURES = "textures/";
|
||||||
}
|
private static final String SUFFIX = ".json";
|
||||||
private class CustomSkinAPIProfile{
|
|
||||||
public String username;
|
@Override
|
||||||
public Map<String,String> textures;
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
|
return Lists.newArrayList(new LittleSkin(loader), new BlessingSkin(loader));
|
||||||
public Map<String,String> skins;
|
}
|
||||||
|
|
||||||
public String skin;
|
@Override
|
||||||
public String cape;
|
public String toJsonUrl(String root, String username) {
|
||||||
public String elytra;
|
return root + username + SUFFIX;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public String getPayload(SkinSiteProfile ssp) {
|
@Override
|
||||||
return null;
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
}
|
CustomSkinAPIProfile profile = CustomSkinLoader.GSON.fromJson(json, CustomSkinAPIProfile.class);
|
||||||
@Override
|
UserProfile p = new UserProfile();
|
||||||
public String getName() {
|
|
||||||
return "CustomSkinAPI";
|
if (StringUtils.isNotBlank(profile.skin)) {
|
||||||
}
|
p.skinUrl = root + TEXTURES + profile.skin;
|
||||||
|
if (local)
|
||||||
|
p.skinUrl = HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(profile.cape)) {
|
||||||
|
p.capeUrl = root + TEXTURES + profile.cape;
|
||||||
|
if (local)
|
||||||
|
p.capeUrl = HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(profile.elytra)) {
|
||||||
|
p.elytraUrl = root + TEXTURES + profile.elytra;
|
||||||
|
if (local)
|
||||||
|
p.elytraUrl = HttpTextureUtil.getLocalFakeUrl(p.elytraUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> textures = new LinkedHashMap<>();
|
||||||
|
if (profile.skins != null)
|
||||||
|
textures.putAll(profile.skins);
|
||||||
|
if (profile.textures != null)
|
||||||
|
textures.putAll(profile.textures);
|
||||||
|
if (textures.isEmpty())
|
||||||
|
return p;
|
||||||
|
|
||||||
|
boolean hasSkin = false;
|
||||||
|
for (String model : textures.keySet()) {
|
||||||
|
ModelManager0.Model enumModel = ModelManager0.getEnumModel(model);
|
||||||
|
if (enumModel == null || StringUtils.isEmpty(textures.get(model)))
|
||||||
|
continue;
|
||||||
|
if (ModelManager0.isSkin(enumModel))
|
||||||
|
if (hasSkin)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
hasSkin = true;
|
||||||
|
String url = root + TEXTURES + textures.get(model);
|
||||||
|
if (local)
|
||||||
|
url = HttpTextureUtil.getLocalFakeUrl(url);
|
||||||
|
p.put(enumModel, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CustomSkinAPIProfile {
|
||||||
|
public String username;
|
||||||
|
public LinkedHashMap<String, String> textures;
|
||||||
|
|
||||||
|
public LinkedHashMap<String, String> skins;
|
||||||
|
|
||||||
|
public String skin;
|
||||||
|
public String cape;
|
||||||
|
public String elytra;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "CustomSkinAPI";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,82 +1,65 @@
|
|||||||
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(){
|
||||||
File clientIDFile=new File(CustomSkinLoader.DATA_DIR,"CustomSkinAPIPlus-ClientID");
|
File clientIDFile=new File(CustomSkinLoader.DATA_DIR,"CustomSkinAPIPlus-ClientID");
|
||||||
|
|
||||||
if(clientIDFile.isFile())
|
if(clientIDFile.isFile())
|
||||||
try{
|
try{
|
||||||
clientID=FileUtils.readFileToString(clientIDFile);
|
clientID=FileUtils.readFileToString(clientIDFile, "UTF-8");
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if(clientID==null){
|
if(clientID==null){
|
||||||
clientID=UUID.randomUUID().toString();
|
clientID=UUID.randomUUID().toString();
|
||||||
try {
|
try {
|
||||||
FileUtils.write(clientIDFile, clientID);
|
FileUtils.write(clientIDFile, clientID, "UTF-8");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public String toJsonUrl(String root, String username) {
|
|
||||||
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toJsonUrl(root, username);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPayload(SkinSiteProfile ssp) {
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
if(ssp.privacy==null)
|
return Lists.newArrayList();
|
||||||
ssp.privacy=new CustomSkinAPIPlusPrivacy();
|
}
|
||||||
return new Gson().toJson(new CustomSkinAPIPlusPayload(ssp.privacy));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
public String getPayload(SkinSiteProfile ssp) {
|
||||||
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toUserProfile(root, json, local);
|
return new Gson().toJson(new CustomSkinAPIPlusPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "CustomSKinAPIPlus";
|
return "CustomSKinAPIPlus";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CustomSkinAPIPlusPayload{
|
public static class CustomSkinAPIPlusPayload{
|
||||||
public String gameVersion;//minecraft version
|
String gameVersion;//minecraft version
|
||||||
public String modVersion;//mod version
|
String modVersion;//mod version
|
||||||
public String serverAddress;//ip:port
|
String serverAddress;//ip:port
|
||||||
public String clientID;//Minecraft Client ID
|
String clientID;//Minecraft Client ID
|
||||||
public CustomSkinAPIPlusPayload(CustomSkinAPIPlusPrivacy privacy){
|
CustomSkinAPIPlusPayload(){
|
||||||
if(privacy.gameVersion)
|
gameVersion = MinecraftUtil.getMinecraftMainVersion();
|
||||||
gameVersion=MinecraftUtil.getMinecraftMainVersion();
|
modVersion = CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||||
if(privacy.modVersion)
|
serverAddress = MinecraftUtil.isLanServer() ? null : MinecraftUtil.getStandardServerAddress();
|
||||||
modVersion=CustomSkinLoader.CustomSkinLoader_VERSION;
|
clientID = CustomSkinAPIPlus.clientID;
|
||||||
if(privacy.serverAddress)
|
}
|
||||||
serverAddress=MinecraftUtil.isLanServer()?null:MinecraftUtil.getStandardServerAddress();
|
}
|
||||||
if(privacy.clientID)
|
|
||||||
clientID=CustomSkinAPIPlus.clientID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static class CustomSkinAPIPlusPrivacy{
|
|
||||||
public boolean gameVersion=true;
|
|
||||||
public boolean modVersion=true;
|
|
||||||
public boolean serverAddress=true;
|
|
||||||
public boolean clientID=true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
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.reflect.TypeToken;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
|
import customskinloader.profile.ModelManager0;
|
||||||
|
import customskinloader.profile.UserProfile;
|
||||||
|
|
||||||
|
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
|
||||||
|
public String toJsonUrl(String root, String username) {
|
||||||
|
return root + username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
|
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> result = new Gson().fromJson(json, new TypeToken<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>>() {
|
||||||
|
}.getType());
|
||||||
|
return ModelManager0.toUserProfile(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "ElyByAPI";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
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.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
|
import customskinloader.profile.ModelManager0;
|
||||||
|
import customskinloader.profile.UserProfile;
|
||||||
|
|
||||||
|
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
|
||||||
|
public String toJsonUrl(String root, String username) {
|
||||||
|
return root + username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
|
GlitchlessApiResponse result = new Gson().fromJson(json, GlitchlessApiResponse.class);
|
||||||
|
if (!result.textures.containsKey(MinecraftProfileTexture.Type.SKIN))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return ModelManager0.toUserProfile(result.textures);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "GlitchlessAPI";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GlitchlessApiResponse {
|
||||||
|
protected Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package customskinloader.loader.jsonapi;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
import customskinloader.config.SkinSiteProfile;
|
||||||
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.loader.MojangAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
|
import customskinloader.profile.UserProfile;
|
||||||
|
import customskinloader.utils.TextureUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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, false);
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserProfile profile = new UserProfile();
|
||||||
|
profile.capeUrl = TextureUtil.parseBase64Texture(result.textures.cape);
|
||||||
|
|
||||||
|
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,78 +3,103 @@ 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.loader.JsonAPILoader;
|
||||||
import customskinloader.loader.JsonAPILoader.IJsonAPI;
|
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 IJsonAPI {
|
public class UniSkinAPI implements JsonAPILoader.IJsonAPI {
|
||||||
private static final String TEXTURES="textures/";
|
|
||||||
private static final String SUFFIX=".json";
|
|
||||||
|
|
||||||
@Override
|
public static class SkinMe extends JsonAPILoader.DefaultProfile {
|
||||||
public String toJsonUrl(String root, String username) {
|
public SkinMe(JsonAPILoader loader) {
|
||||||
return new StringBuilder().append(root).append(username).append(SUFFIX).toString();
|
super(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
public String getName() {
|
||||||
UniSkinAPIProfile profile=CustomSkinLoader.GSON.fromJson(json, UniSkinAPIProfile.class);
|
return "SkinMe";
|
||||||
UserProfile p=new UserProfile();
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(profile.cape)){
|
@Override
|
||||||
p.capeUrl=root+TEXTURES+profile.cape;
|
public int getPriority() {
|
||||||
if(local)
|
return 500;
|
||||||
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
if(profile.skins==null||profile.skins.isEmpty())
|
public String getRoot() {
|
||||||
return p;
|
return "http://www.skinme.cc/uniskin/";
|
||||||
if(profile.model_preference==null||profile.model_preference.isEmpty())
|
}
|
||||||
return p;
|
}
|
||||||
|
|
||||||
boolean hasSkin=false;
|
private static final String TEXTURES = "textures/";
|
||||||
for(String model:profile.model_preference){
|
private static final String SUFFIX = ".json";
|
||||||
Model enumModel=ModelManager0.getEnumModel(model);
|
|
||||||
if(enumModel==null||StringUtils.isEmpty(profile.skins.get(model)))
|
@Override
|
||||||
continue;
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
if(ModelManager0.isSkin(enumModel))
|
return Lists.newArrayList(new SkinMe(loader));
|
||||||
if(hasSkin)
|
}
|
||||||
continue;
|
|
||||||
else
|
@Override
|
||||||
hasSkin=true;
|
public String toJsonUrl(String root, String username) {
|
||||||
String url=root+TEXTURES+profile.skins.get(model);
|
return root + username + SUFFIX;
|
||||||
if(local)
|
}
|
||||||
url=HttpTextureUtil.getLocalFakeUrl(url);
|
|
||||||
p.put(enumModel, url);
|
@Override
|
||||||
}
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
|
UniSkinAPIProfile profile = CustomSkinLoader.GSON.fromJson(json, UniSkinAPIProfile.class);
|
||||||
return p;
|
UserProfile p = new UserProfile();
|
||||||
}
|
|
||||||
/**
|
if (StringUtils.isNotBlank(profile.cape)) {
|
||||||
* Json profile for UniSkinAPI
|
p.capeUrl = root + TEXTURES + profile.cape;
|
||||||
* Source Code: https://github.com/RecursiveG/UniSkinMod/blob/master/src/main/java/org/devinprogress/uniskinmod/UniSkinApiProfile.java#L18-L22
|
if (local)
|
||||||
* @author RecursiveG
|
p.capeUrl = HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
||||||
*/
|
}
|
||||||
private class UniSkinAPIProfile{
|
|
||||||
public String player_name;
|
if (profile.skins == null || profile.skins.isEmpty())
|
||||||
public long last_update;
|
return p;
|
||||||
public List<String> model_preference;
|
if (profile.model_preference == null || profile.model_preference.isEmpty())
|
||||||
public Map<String,String> skins;
|
return p;
|
||||||
|
|
||||||
public String cape;
|
boolean hasSkin = false;
|
||||||
}
|
for (String model : profile.model_preference) {
|
||||||
@Override
|
ModelManager0.Model enumModel = ModelManager0.getEnumModel(model);
|
||||||
public String getPayload(SkinSiteProfile ssp) {
|
if (enumModel == null || StringUtils.isEmpty(profile.skins.get(model)))
|
||||||
return null;
|
continue;
|
||||||
}
|
if (ModelManager0.isSkin(enumModel))
|
||||||
@Override
|
if (hasSkin)
|
||||||
public String getName() {
|
continue;
|
||||||
return "UniSkinAPI";
|
else
|
||||||
}
|
hasSkin = true;
|
||||||
|
String url = root + TEXTURES + profile.skins.get(model);
|
||||||
|
if (local)
|
||||||
|
url = HttpTextureUtil.getLocalFakeUrl(url);
|
||||||
|
p.put(enumModel, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Json profile for UniSkinAPI
|
||||||
|
* <a href="https://github.com/RecursiveG/UniSkinMod/blob/master/src/main/java/org/devinprogress/uniskinmod/UniSkinApiProfile.java#L18-L22">Source Code</a>
|
||||||
|
*
|
||||||
|
* @author RecursiveG
|
||||||
|
*/
|
||||||
|
private static class UniSkinAPIProfile {
|
||||||
|
public String player_name;
|
||||||
|
public long last_update;
|
||||||
|
public List<String> model_preference;
|
||||||
|
public Map<String, String> skins;
|
||||||
|
|
||||||
|
public String cape;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "UniSkinAPI";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package customskinloader.loader.jsonapi;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import customskinloader.config.SkinSiteProfile;
|
||||||
|
import customskinloader.loader.JsonAPILoader;
|
||||||
|
import customskinloader.loader.MojangAPILoader;
|
||||||
|
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||||
|
import customskinloader.profile.UserProfile;
|
||||||
|
import customskinloader.utils.TextureUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wynntils cape API
|
||||||
|
* <a href="https://wynntils.com/">Home</a>
|
||||||
|
* Test player: Cael
|
||||||
|
*
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
public class WynntilsAPI implements JsonAPILoader.IJsonAPI {
|
||||||
|
|
||||||
|
public static class Wynntils extends JsonAPILoader.DefaultProfile {
|
||||||
|
public Wynntils(JsonAPILoader loader) {
|
||||||
|
super(loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Wynntils";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return 820;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRoot() {
|
||||||
|
return "https://athena.wynntils.com/user/getInfo";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ICustomSkinLoaderPlugin.IDefaultProfile> getDefaultProfiles(JsonAPILoader loader) {
|
||||||
|
return Lists.newArrayList(new Wynntils(loader));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toJsonUrl(String root, String username) {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
|
WynntilsApiResponse result = new Gson().fromJson(json, WynntilsApiResponse.class);
|
||||||
|
if (result.user == null || result.user.cosmetics == null || result.user.cosmetics.texture == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserProfile profile = new UserProfile();
|
||||||
|
String fakeUrl = TextureUtil.parseBase64Texture(result.user.cosmetics.texture);
|
||||||
|
if (result.user.cosmetics.hasCape) {
|
||||||
|
profile.capeUrl = fakeUrl;
|
||||||
|
} else if (result.user.cosmetics.hasElytra) {
|
||||||
|
profile.elytraUrl = fakeUrl;
|
||||||
|
} else {
|
||||||
|
CustomSkinLoader.logger.warning("Illegal response found in Wynntils");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPayload(SkinSiteProfile ssp, String username) {
|
||||||
|
WynntilsApiRequest req = new WynntilsApiRequest();
|
||||||
|
req.uuid = MojangAPILoader.getMojangUuidByUsername(username, true);
|
||||||
|
if (req.uuid == null) {
|
||||||
|
throw new JsonAPILoader.ProfileNotFoundException();
|
||||||
|
}
|
||||||
|
return new Gson().toJson(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "WynntilsAPI";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WynntilsApiRequest {
|
||||||
|
public String uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WynntilsApiResponse {
|
||||||
|
public User user;
|
||||||
|
|
||||||
|
public static class User {
|
||||||
|
public String accountType;
|
||||||
|
public Cosmetics cosmetics;
|
||||||
|
|
||||||
|
public static class Cosmetics {
|
||||||
|
public boolean hasCape;
|
||||||
|
public boolean hasElytra;
|
||||||
|
public boolean hasEars;
|
||||||
|
public String texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package customskinloader.log;
|
||||||
|
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
public class LogManager {
|
||||||
|
private static Path logFile;
|
||||||
|
private static Writer logWriter;
|
||||||
|
private static final Map<String, Logger> loggers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static void setLogFile(Path logFile) {
|
||||||
|
//Not updated
|
||||||
|
if (logFile == null || logFile.equals(LogManager.logFile)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogManager.logFile = logFile;
|
||||||
|
try {
|
||||||
|
//Close previous writer
|
||||||
|
if (logWriter != null) {
|
||||||
|
logWriter.close();
|
||||||
|
}
|
||||||
|
//Set new writer
|
||||||
|
Files.createDirectories(logFile.getParent());
|
||||||
|
logWriter = Files.newBufferedWriter(logFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE);
|
||||||
|
loggers.forEach((k, v) -> v.setWriter(logWriter));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger getLogger(String loggerName) {
|
||||||
|
return loggers.computeIfAbsent(loggerName,
|
||||||
|
it -> new Logger(logWriter, "CustomSkinLoader " + loggerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
package customskinloader.log;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the Logger
|
||||||
|
* Moved from <code>customskinloader.Logger</code>
|
||||||
|
*
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
public class Logger {
|
||||||
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A copy of <code>Config.enableLogStdOut</code>.
|
||||||
|
* Because <code>Config.loadConfig0()</code> will use <code>Logger.log()</code>,
|
||||||
|
* which means cannot access <code>CustomSkinLoader.config</code> here.
|
||||||
|
*
|
||||||
|
* @see customskinloader.config.Config#enableLogStdOut
|
||||||
|
* @since 14.15
|
||||||
|
*/
|
||||||
|
public boolean enableLogStdOut = false;
|
||||||
|
|
||||||
|
public enum Level {
|
||||||
|
DEBUG("DEBUG", false),
|
||||||
|
INFO("INFO", true),
|
||||||
|
WARNING("WARNING", true);
|
||||||
|
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
final boolean display;
|
||||||
|
|
||||||
|
Level(String name, boolean display) {
|
||||||
|
this.name = name;
|
||||||
|
this.display = display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean display() {
|
||||||
|
return display;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Writer writer = null;
|
||||||
|
|
||||||
|
public void setWriter(Writer writer) {
|
||||||
|
this.writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Logger() {
|
||||||
|
//Logger isn't created.
|
||||||
|
}
|
||||||
|
|
||||||
|
public Logger(String logFile) {
|
||||||
|
this(new File(logFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Logger(File logFile) {
|
||||||
|
this(logFile, "Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Logger with File
|
||||||
|
*
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
public Logger(File logFile, String loggerName) {
|
||||||
|
this.loggerName = loggerName;
|
||||||
|
try {
|
||||||
|
if (!logFile.getParentFile().exists()) {
|
||||||
|
logFile.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
if (!logFile.exists()) {
|
||||||
|
logFile.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
writer = new BufferedWriter(new OutputStreamWriter(
|
||||||
|
Files.newOutputStream(logFile.toPath()), StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
System.out.println("Log Path: " + logFile.getAbsolutePath());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Logger with special Writer
|
||||||
|
*
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
public Logger(@Nullable Writer writer, String loggerName) {
|
||||||
|
this.loggerName = loggerName;
|
||||||
|
this.writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger name in log
|
||||||
|
*
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
String loggerName;
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
if (writer != null) {
|
||||||
|
try {
|
||||||
|
writer.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Judge if a level can be printed to standard output(System.out) with config.
|
||||||
|
*
|
||||||
|
* @param level log level
|
||||||
|
* @return true - print
|
||||||
|
*/
|
||||||
|
private boolean canPrintToStdOut(Level level) {
|
||||||
|
return level.display() && enableLogStdOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(Level level, String msg) {
|
||||||
|
//When it neither be printed to standard output nor write to file
|
||||||
|
if (!canPrintToStdOut(level) && writer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Format, print and write
|
||||||
|
String sb = String.format("[%s] [%s/%s] [%s]: %s",
|
||||||
|
DATE_FORMAT.format(new Date()), Thread.currentThread().getName(), level.getName(), loggerName, msg);
|
||||||
|
if (canPrintToStdOut(level)) {
|
||||||
|
System.out.println(sb);
|
||||||
|
}
|
||||||
|
if (writer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String sb2 = String.format("%s\r\n", sb);
|
||||||
|
writer.write(sb2);//Writer.write has lock
|
||||||
|
writer.flush();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debug(String msg) {
|
||||||
|
log(Level.DEBUG, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debug(String format, Object... objs) {
|
||||||
|
debug(String.format(format, objs));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info(String msg) {
|
||||||
|
log(Level.INFO, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info(String format, Object... objs) {
|
||||||
|
info(String.format(format, objs));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning(String msg) {
|
||||||
|
log(Level.WARNING, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning(String format, Object... objs) {
|
||||||
|
warning(String.format(format, objs));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning(Throwable e) {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
e.printStackTrace(new PrintWriter(sw));
|
||||||
|
log(Level.WARNING, "Exception: " + sw);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package customskinloader.plugin;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import customskinloader.config.SkinSiteProfile;
|
||||||
|
import customskinloader.loader.ProfileLoader;
|
||||||
|
|
||||||
|
public interface ICustomSkinLoaderPlugin {
|
||||||
|
/**
|
||||||
|
* @return return a non-null value if need to add a new profile loader, otherwise return null.
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package customskinloader.plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class PluginLoader {
|
||||||
|
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()),
|
||||||
|
new JsonAPILoader(new WynntilsAPI()),
|
||||||
|
};
|
||||||
|
public static final ArrayList<ICustomSkinLoaderPlugin> PLUGINS = loadPlugins();
|
||||||
|
|
||||||
|
private static ArrayList<ICustomSkinLoaderPlugin> loadPlugins() {
|
||||||
|
File pluginsDir = new File(CustomSkinLoader.DATA_DIR, "Plugins");
|
||||||
|
ArrayList<URL> urls = new ArrayList<>();
|
||||||
|
if (!pluginsDir.isDirectory()) {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
pluginsDir.mkdirs();
|
||||||
|
} else {
|
||||||
|
for (File plugin : FileUtils.listFiles(pluginsDir, new String[]{"jar", "zip"}, false)) {
|
||||||
|
try {
|
||||||
|
urls.add(plugin.toURI().toURL());
|
||||||
|
CustomSkinLoader.logger.info("Found a jar or zip file: " + plugin.getName());
|
||||||
|
} 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()));
|
||||||
|
for (ICustomSkinLoaderPlugin plugin : sl) {
|
||||||
|
plugins.add(plugin);
|
||||||
|
}
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package customskinloader.profile;
|
package customskinloader.profile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import org.apache.commons.codec.Charsets;
|
import org.apache.commons.codec.Charsets;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
@@ -31,133 +29,132 @@ import customskinloader.utils.HttpTextureUtil;
|
|||||||
import customskinloader.utils.HttpUtil0;
|
import customskinloader.utils.HttpUtil0;
|
||||||
|
|
||||||
public class DynamicSkullManager {
|
public class DynamicSkullManager {
|
||||||
public static class SkullTexture{
|
public static class SkullTexture{
|
||||||
public Map<Type,MinecraftProfileTexture> textures;
|
public Map<Type,MinecraftProfileTexture> textures;
|
||||||
public String index;//Index File
|
public String index;//Index File
|
||||||
public ArrayList<String> skins;
|
public ArrayList<String> skins;
|
||||||
public int interval;
|
public int interval;
|
||||||
public boolean fromZero;
|
public boolean fromZero;
|
||||||
//For program
|
//For program
|
||||||
public long startTime;
|
public long startTime;
|
||||||
public int period;
|
public int period;
|
||||||
}
|
}
|
||||||
private Map<GameProfile,SkullTexture> dynamicTextures=new HashMap<GameProfile,SkullTexture>();
|
private Map<GameProfile, SkullTexture> dynamicTextures = new ConcurrentHashMap<>();
|
||||||
private Map<GameProfile,Map<Type,MinecraftProfileTexture>> staticTextures=new HashMap<GameProfile,Map<Type,MinecraftProfileTexture>>();
|
private Map<GameProfile, Map<Type, MinecraftProfileTexture>> staticTextures = new ConcurrentHashMap<>();
|
||||||
private List<GameProfile> loadingList=new ArrayList<GameProfile>();
|
private List<GameProfile> loadingList=new ArrayList<GameProfile>();
|
||||||
|
|
||||||
private void parseGameProfile(GameProfile profile){
|
private void parseGameProfile(GameProfile profile){
|
||||||
Property textureProperty=(Property)Iterables.getFirst(profile.getProperties().get("textures"), null);
|
Property textureProperty = Iterables.getFirst(profile.getProperties().get("textures"), null);
|
||||||
if (textureProperty==null){
|
if (textureProperty==null){
|
||||||
staticTextures.put(profile, new HashMap());
|
staticTextures.put(profile, Maps.<Type, MinecraftProfileTexture>newHashMap());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String value=textureProperty.getValue();
|
String value=textureProperty.getValue();
|
||||||
if(StringUtils.isBlank(value)){
|
if(StringUtils.isBlank(value)){
|
||||||
staticTextures.put(profile, new HashMap());
|
staticTextures.put(profile, Maps.<Type, MinecraftProfileTexture>newHashMap());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String json=new String(Base64.decodeBase64(value),Charsets.UTF_8);
|
@SuppressWarnings("deprecation") String json = new String(Base64.decodeBase64(value), Charsets.UTF_8);
|
||||||
Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create();
|
Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create();
|
||||||
SkullTexture result=gson.fromJson(json,SkullTexture.class);
|
SkullTexture result=gson.fromJson(json,SkullTexture.class);
|
||||||
if(result==null){
|
if(result==null){
|
||||||
staticTextures.put(profile, new HashMap());
|
staticTextures.put(profile, Maps.<Type, MinecraftProfileTexture>newHashMap());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
staticTextures.put(profile, (result.textures==null||!result.textures.containsKey(Type.SKIN))?new HashMap():parseTextures(result.textures));
|
staticTextures.put(profile, (result.textures==null || !result.textures.containsKey(Type.SKIN)) ?
|
||||||
|
Maps.<Type, MinecraftProfileTexture>newHashMap() : parseTextures(result.textures));
|
||||||
if(StringUtils.isNotEmpty(result.index)){
|
|
||||||
File indexFile=new File(CustomSkinLoader.DATA_DIR,result.index);
|
if(StringUtils.isNotEmpty(result.index)){
|
||||||
try{
|
File indexFile=new File(CustomSkinLoader.DATA_DIR,result.index);
|
||||||
String index=FileUtils.readFileToString(indexFile, Charsets.UTF_8);
|
try{
|
||||||
if(StringUtils.isNotEmpty(index)){
|
String index=FileUtils.readFileToString(indexFile, "UTF-8");
|
||||||
ArrayList<String> skins=CustomSkinLoader.GSON.fromJson(index, ArrayList.class);
|
if(StringUtils.isNotEmpty(index)){
|
||||||
if(skins!=null&&!skins.isEmpty())
|
String[] skins = CustomSkinLoader.GSON.fromJson(index, String[].class);
|
||||||
result.skins=skins;
|
if(skins != null && skins.length != 0)
|
||||||
}
|
result.skins = Lists.newArrayList(skins);
|
||||||
}catch(Exception e){
|
}
|
||||||
CustomSkinLoader.logger.warning("Exception occurs while parsing index file: "+e.toString());
|
}catch(Exception e){
|
||||||
}
|
CustomSkinLoader.logger.warning("Exception occurs while parsing index file: "+e.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(!CustomSkinLoader.config.enableDynamicSkull||result.skins==null||result.skins.isEmpty())
|
|
||||||
return;
|
if(!CustomSkinLoader.config.enableDynamicSkull||result.skins==null||result.skins.isEmpty())
|
||||||
|
return;
|
||||||
CustomSkinLoader.logger.info("Try to load Dynamic Skull: "+json);
|
|
||||||
|
CustomSkinLoader.logger.info("Try to load Dynamic Skull: "+json);
|
||||||
for(int i=0;i<result.skins.size();i++){//check and cache skins
|
|
||||||
String skin=result.skins.get(i);
|
for(int i=0;i<result.skins.size();i++){//check and cache skins
|
||||||
if(HttpUtil0.isLocal(skin)){
|
String skin=result.skins.get(i);
|
||||||
//Local Skin
|
if(HttpUtil0.isLocal(skin)){
|
||||||
File skinFile=new File(CustomSkinLoader.DATA_DIR,skin);
|
//Local Skin
|
||||||
if(skinFile.isFile()&&skinFile.length()>0){
|
File skinFile=new File(CustomSkinLoader.DATA_DIR,skin);
|
||||||
//Skin found
|
if(skinFile.isFile()&&skinFile.length()>0){
|
||||||
String fakeUrl=HttpTextureUtil.getLocalFakeUrl(skin);
|
//Skin found
|
||||||
result.skins.set(i, fakeUrl);
|
String fakeUrl=HttpTextureUtil.getLocalFakeUrl(skin);
|
||||||
}else{
|
result.skins.set(i, fakeUrl);
|
||||||
//Could not find skin
|
}else{
|
||||||
result.skins.remove(i--);
|
//Could not find skin
|
||||||
continue;
|
result.skins.remove(i--);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//Online Skin
|
//Online Skin
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setCacheFile(HttpTextureUtil.getCacheFile(FilenameUtils.getBaseName(skin))).setCacheTime(0).setLoadContent(false));
|
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setCacheFile(HttpTextureUtil.getCacheFile(FilenameUtils.getBaseName(skin))).setCacheTime(0).setLoadContent(false));
|
||||||
if(!responce.success){
|
if(!responce.success){
|
||||||
//Could not load skin
|
//Could not load skin
|
||||||
result.skins.remove(i--);
|
result.skins.remove(i--);
|
||||||
continue;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if(result.skins.isEmpty()){//Nothing loaded
|
||||||
if(result.skins.isEmpty()){//Nothing loaded
|
CustomSkinLoader.logger.info("Failed: Nothing loaded.");
|
||||||
CustomSkinLoader.logger.info("Failed: Nothing loaded.");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
result.interval=Math.max(result.interval, 50);
|
||||||
result.interval=Math.max(result.interval, 50);
|
if(result.fromZero)
|
||||||
if(result.fromZero)
|
result.startTime=System.currentTimeMillis();
|
||||||
result.startTime=System.currentTimeMillis();
|
result.period=result.interval*result.skins.size();
|
||||||
result.period=result.interval*result.skins.size();
|
CustomSkinLoader.logger.info("Successfully loaded Dynamic Skull: "+new Gson().toJson(result));
|
||||||
CustomSkinLoader.logger.info("Successfully loaded Dynamic Skull: "+new Gson().toJson(result));
|
dynamicTextures.put(profile, result);
|
||||||
dynamicTextures.put(profile, result);
|
staticTextures.remove(profile);
|
||||||
staticTextures.remove(profile);
|
}
|
||||||
}
|
|
||||||
|
//Support local skin for skull
|
||||||
//Support local skin for skull
|
public Map<Type, MinecraftProfileTexture> parseTextures(Map<Type, MinecraftProfileTexture> textures) {
|
||||||
public Map<Type, MinecraftProfileTexture> parseTextures(Map<Type, MinecraftProfileTexture> textures) {
|
MinecraftProfileTexture skin=textures.get(Type.SKIN);
|
||||||
MinecraftProfileTexture skin=textures.get(Type.SKIN);
|
String skinUrl=skin.getUrl();
|
||||||
String skinUrl=skin.getUrl();
|
if(!HttpUtil0.isLocal(skinUrl))
|
||||||
if(!HttpUtil0.isLocal(skinUrl))
|
return textures;
|
||||||
return textures;
|
File skinFile=new File(CustomSkinLoader.DATA_DIR,skinUrl);
|
||||||
File skinFile=new File(CustomSkinLoader.DATA_DIR,skinUrl);
|
if(!skinFile.isFile())
|
||||||
if(!skinFile.isFile())
|
return Maps.newHashMap();
|
||||||
return new HashMap();
|
textures.put(Type.SKIN, ModelManager0.getProfileTexture(HttpTextureUtil.getLocalFakeUrl(skinUrl), null));
|
||||||
textures.put(Type.SKIN, ModelManager0.getProfileTexture(HttpTextureUtil.getLocalFakeUrl(skinUrl), null));
|
return textures;
|
||||||
return textures;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Type,MinecraftProfileTexture> getTexture(final GameProfile profile){
|
public Map<Type,MinecraftProfileTexture> getTexture(final GameProfile profile){
|
||||||
if(staticTextures.get(profile)!=null)
|
if(staticTextures.get(profile)!=null)
|
||||||
return staticTextures.get(profile);
|
return staticTextures.get(profile);
|
||||||
if(loadingList.contains(profile))
|
if(loadingList.contains(profile))
|
||||||
return new HashMap();
|
return Maps.newHashMap();
|
||||||
if(dynamicTextures.containsKey(profile)){
|
if(dynamicTextures.containsKey(profile)){
|
||||||
SkullTexture texture=dynamicTextures.get(profile);
|
SkullTexture texture=dynamicTextures.get(profile);
|
||||||
long time=System.currentTimeMillis()-texture.startTime;
|
long time=System.currentTimeMillis()-texture.startTime;
|
||||||
int index=(int)Math.floor((time%texture.period)/texture.interval);
|
int index=(int)Math.floor((time%texture.period)/texture.interval);
|
||||||
Map<Type,MinecraftProfileTexture> map=Maps.newHashMap();
|
Map<Type,MinecraftProfileTexture> map=Maps.newHashMap();
|
||||||
map.put(Type.SKIN, ModelManager0.getProfileTexture(texture.skins.get(index), null));
|
map.put(Type.SKIN, ModelManager0.getProfileTexture(texture.skins.get(index), null));
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingList.add(profile);
|
loadingList.add(profile);
|
||||||
Thread loadThread=new Thread(){
|
Thread loadThread=new Thread(){
|
||||||
public void run(){
|
public void run(){
|
||||||
parseGameProfile(profile);//Load in thread
|
parseGameProfile(profile);//Load in thread
|
||||||
loadingList.remove(profile);
|
loadingList.remove(profile);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
loadThread.setName("Skull "+profile.hashCode());
|
loadThread.setName("Skull "+profile.hashCode());
|
||||||
loadThread.start();
|
loadThread.start();
|
||||||
return new HashMap();
|
return Maps.newHashMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,119 +3,128 @@ package customskinloader.profile;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
import customskinloader.fake.FakeMinecraftProfileTexture;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model Manager for 1.8 and higher.
|
* Model Manager for 1.8 and higher.
|
||||||
* A manager to check if model is available.
|
* A manager to check if model is available.
|
||||||
* It is the only class in package 'customskinloader' which has differences in different Minecraft version.
|
* It is the only class in package 'customskinloader' which has differences in different Minecraft version.
|
||||||
|
*
|
||||||
* @since 13.1
|
* @since 13.1
|
||||||
*/
|
*/
|
||||||
public class ModelManager0 {
|
public class ModelManager0 {
|
||||||
public static enum Model{
|
public enum Model {
|
||||||
SKIN_DEFAULT,
|
SKIN_DEFAULT,
|
||||||
SKIN_SLIM,
|
SKIN_SLIM,
|
||||||
CAPE,
|
CAPE,
|
||||||
ELYTRA
|
ELYTRA
|
||||||
}
|
}
|
||||||
private static HashMap<String,Model> models=new HashMap<String,Model>();
|
|
||||||
private static Type typeElytra=null;
|
private static HashMap<String, Model> models = new HashMap<String, Model>();
|
||||||
static{
|
private static MinecraftProfileTexture.Type typeElytra = null;
|
||||||
for(Type type:Type.values()){
|
|
||||||
if(type.ordinal()==2)//ELYTRA
|
static {
|
||||||
typeElytra=type;
|
for (MinecraftProfileTexture.Type type : MinecraftProfileTexture.Type.values()) {
|
||||||
}
|
if (type.ordinal() == 2)//ELYTRA
|
||||||
models.put("default", Model.SKIN_DEFAULT);
|
typeElytra = type;
|
||||||
models.put("slim", Model.SKIN_SLIM);
|
}
|
||||||
models.put("cape", Model.CAPE);
|
models.put("default", Model.SKIN_DEFAULT);
|
||||||
if(typeElytra!=null)
|
models.put("slim", Model.SKIN_SLIM);
|
||||||
models.put("elytra", Model.ELYTRA);
|
models.put("cape", Model.CAPE);
|
||||||
}
|
if (typeElytra != null) {
|
||||||
|
models.put("elytra", Model.ELYTRA);
|
||||||
/**
|
models.put("elytron", Model.ELYTRA);
|
||||||
* Get enum for the model.
|
}
|
||||||
* @param model - string model
|
}
|
||||||
* @since 14.5
|
|
||||||
*/
|
/**
|
||||||
public static Model getEnumModel(String model){
|
* Get enum for the model.
|
||||||
return models.get(model);
|
*
|
||||||
}
|
* @param model - string model
|
||||||
|
* @since 14.5
|
||||||
/**
|
*/
|
||||||
* Check if model is skin.
|
public static Model getEnumModel(String model) {
|
||||||
* @since 14.5
|
return models.get(model);
|
||||||
* */
|
}
|
||||||
public static boolean isSkin(Model model){
|
|
||||||
return model==Model.SKIN_DEFAULT||model==Model.SKIN_SLIM;
|
/**
|
||||||
}
|
* Check if model is skin.
|
||||||
|
*
|
||||||
/**
|
* @since 14.5
|
||||||
* Check if elytra is supported.
|
*/
|
||||||
* @since 14.5
|
public static boolean isSkin(Model model) {
|
||||||
*/
|
return model == Model.SKIN_DEFAULT || model == Model.SKIN_SLIM;
|
||||||
public static boolean isElytraSupported(){
|
}
|
||||||
return typeElytra!=null;
|
|
||||||
}
|
/**
|
||||||
|
* Check if elytra is supported.
|
||||||
/**
|
*
|
||||||
* Parse hashMapProfile to UserProfile
|
* @since 14.5
|
||||||
* @param profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
*/
|
||||||
* @return profile - UserProfile instance
|
public static boolean isElytraSupported() {
|
||||||
* @since 13.1
|
return typeElytra != null;
|
||||||
*/
|
}
|
||||||
public static UserProfile toUserProfile(Map profile){
|
|
||||||
UserProfile userProfile=new UserProfile();
|
/**
|
||||||
if(profile==null)
|
* Parse hashMapProfile to UserProfile
|
||||||
return userProfile;
|
*
|
||||||
MinecraftProfileTexture skin=(MinecraftProfileTexture)profile.get(Type.SKIN);
|
* @param profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
||||||
userProfile.skinUrl= skin==null?null:skin.getUrl();//Avoid NullPointerException
|
* @return profile - UserProfile instance
|
||||||
userProfile.model= skin==null?null:skin.getMetadata("model");
|
* @since 13.1
|
||||||
if(StringUtils.isEmpty(userProfile.model))
|
*/
|
||||||
userProfile.model="default";
|
public static UserProfile toUserProfile(Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> profile) {
|
||||||
|
UserProfile userProfile = new UserProfile();
|
||||||
MinecraftProfileTexture cape=(MinecraftProfileTexture)profile.get(Type.CAPE);
|
if (profile == null)
|
||||||
userProfile.capeUrl= cape==null?null:cape.getUrl();
|
return userProfile;
|
||||||
return userProfile;
|
MinecraftProfileTexture skin = profile.get(MinecraftProfileTexture.Type.SKIN);
|
||||||
}
|
userProfile.skinUrl = skin == null ? null : skin.getUrl();//Avoid NullPointerException
|
||||||
|
userProfile.model = skin == null ? null : skin.getMetadata("model");
|
||||||
/**
|
if (StringUtils.isEmpty(userProfile.model))
|
||||||
* Parse UserProfile to hashMapProfile
|
userProfile.model = "default";
|
||||||
* @param profile - UserProfile instance
|
|
||||||
* @return profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
MinecraftProfileTexture cape = profile.get(MinecraftProfileTexture.Type.CAPE);
|
||||||
* @since 13.1
|
userProfile.capeUrl = cape == null ? null : cape.getUrl();
|
||||||
*/
|
return userProfile;
|
||||||
public static Map fromUserProfile(UserProfile profile){
|
}
|
||||||
Map map=Maps.newHashMap();
|
|
||||||
if(profile==null)
|
/**
|
||||||
return map;
|
* Parse UserProfile to hashMapProfile
|
||||||
if(profile.skinUrl!=null){
|
*
|
||||||
Map metadata=null;
|
* @param profile - UserProfile instance
|
||||||
if(profile.model!=null&&profile.model.equals("slim")){
|
* @return profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
||||||
metadata = Maps.newHashMap();
|
* @since 13.1
|
||||||
metadata.put("model", "slim");
|
*/
|
||||||
}
|
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> fromUserProfile(UserProfile profile) {
|
||||||
map.put(Type.SKIN, getProfileTexture(profile.skinUrl,metadata));
|
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = Maps.newHashMap();
|
||||||
}
|
if (profile == null)
|
||||||
if(profile.capeUrl!=null)
|
return map;
|
||||||
map.put(Type.CAPE, getProfileTexture(profile.capeUrl,null));
|
if (profile.skinUrl != null) {
|
||||||
if(typeElytra!=null && profile.elytraUrl!=null)
|
Map<String, String> metadata = null;
|
||||||
map.put(typeElytra, getProfileTexture(profile.elytraUrl,null));
|
if ("slim".equals(profile.model) || "auto".equals(profile.model)) {
|
||||||
return map;
|
metadata = Maps.newHashMap();
|
||||||
}
|
metadata.put("model", profile.model);
|
||||||
|
}
|
||||||
/**
|
map.put(MinecraftProfileTexture.Type.SKIN, getProfileTexture(profile.skinUrl, metadata));
|
||||||
* Parse url to MinecraftProfileTexture
|
}
|
||||||
*
|
if (profile.capeUrl != null)
|
||||||
* @param url - textureUrl
|
map.put(MinecraftProfileTexture.Type.CAPE, getProfileTexture(profile.capeUrl, null));
|
||||||
* metadata - metadata
|
if (typeElytra != null && profile.elytraUrl != null)
|
||||||
* @return MinecraftProfileTexture
|
map.put(typeElytra, getProfileTexture(profile.elytraUrl, null));
|
||||||
* @since 14.5
|
return map;
|
||||||
*/
|
}
|
||||||
public static MinecraftProfileTexture getProfileTexture(String url,Map metadata){
|
|
||||||
return new MinecraftProfileTexture(url,metadata);
|
/**
|
||||||
}
|
* Parse url to MinecraftProfileTexture
|
||||||
|
*
|
||||||
|
* @param url - textureUrl
|
||||||
|
* @param metadata - metadata
|
||||||
|
* @return MinecraftProfileTexture
|
||||||
|
* @since 14.5
|
||||||
|
*/
|
||||||
|
public static MinecraftProfileTexture getProfileTexture(String url, Map<String, String> metadata) {
|
||||||
|
return new FakeMinecraftProfileTexture(url, metadata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,106 +1,126 @@
|
|||||||
package customskinloader.profile;
|
package customskinloader.profile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.util.Deque;
|
||||||
import java.io.FileOutputStream;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.apache.commons.io.IOUtils;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
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 HashMap<String,CachedProfile> cachedProfiles=new HashMap<String,CachedProfile>();
|
private Map<String, CachedProfile> cachedProfiles = new ConcurrentHashMap<>();
|
||||||
private HashMap<String,UserProfile> localProfiles=new HashMap<String,UserProfile>();
|
private Map<String, UserProfile> localProfiles = new ConcurrentHashMap<>();
|
||||||
|
private Map<String, Deque<Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>>>> profileLoaders = new ConcurrentHashMap<>();
|
||||||
public ProfileCache(){
|
|
||||||
if(!PROFILE_CACHE_DIR.exists())
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
PROFILE_CACHE_DIR.mkdir();
|
public ProfileCache(){
|
||||||
}
|
if(!PROFILE_CACHE_DIR.exists())
|
||||||
|
PROFILE_CACHE_DIR.mkdir();
|
||||||
public boolean isExist(String username){
|
}
|
||||||
return cachedProfiles.containsKey(username.toLowerCase());
|
|
||||||
}
|
public boolean isExist(String username){
|
||||||
public boolean isReady(String username){
|
return cachedProfiles.containsKey(username.toLowerCase());
|
||||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
}
|
||||||
return cp==null?false:(cp.loading||cp.expiryTime>TimeUtil.getCurrentUnixTimestamp());
|
public boolean isLoading(String username) {
|
||||||
}
|
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||||
public boolean isExpired(String username){
|
return cp != null && cp.loading;
|
||||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
}
|
||||||
return cp==null?true:(cp.expiryTime<=TimeUtil.getCurrentUnixTimestamp());
|
public boolean isReady(String username){
|
||||||
}
|
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||||
|
return cp != null && (cp.loading || cp.expiryTime > TimeUtil.getCurrentUnixTimestamp());
|
||||||
public UserProfile getProfile(String username){
|
}
|
||||||
return getCachedProfile(username).profile;
|
public boolean isExpired(String username){
|
||||||
}
|
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||||
public long getExpiry(String username){
|
return cp == null || (cp.expiryTime <= TimeUtil.getCurrentUnixTimestamp());
|
||||||
return getCachedProfile(username).expiryTime;
|
}
|
||||||
}
|
|
||||||
public UserProfile getLocalProfile(String username){
|
public UserProfile getProfile(String username){
|
||||||
if(localProfiles.containsKey(username.toLowerCase()))
|
return getCachedProfile(username).profile;
|
||||||
return localProfiles.get(username.toLowerCase());
|
}
|
||||||
return loadLocalProfile(username);
|
public long getExpiry(String username){
|
||||||
}
|
return getCachedProfile(username).expiryTime;
|
||||||
|
}
|
||||||
public void setLoading(String username,boolean loading){
|
public UserProfile getLocalProfile(String username){
|
||||||
getCachedProfile(username).loading=loading;
|
if(localProfiles.containsKey(username.toLowerCase()))
|
||||||
}
|
return localProfiles.get(username.toLowerCase());
|
||||||
public void updateCache(String username,UserProfile profile){
|
return loadLocalProfile(username);
|
||||||
updateCache(username,profile,CustomSkinLoader.config.enableLocalProfileCache);
|
}
|
||||||
}
|
public Optional<Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>>> getLastLoader(String username) {
|
||||||
public void updateCache(String username,UserProfile profile,boolean saveLocalProfile){
|
Deque<Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>>> deque = this.profileLoaders.get(username);
|
||||||
CachedProfile cp=getCachedProfile(username);
|
if (deque != null) {
|
||||||
cp.profile=profile;
|
return Optional.ofNullable(deque.pollLast());
|
||||||
cp.expiryTime=TimeUtil.getUnixTimestampRandomDelay(CustomSkinLoader.config.cacheExpiry);
|
}
|
||||||
if(!saveLocalProfile)
|
return Optional.empty();
|
||||||
return;
|
}
|
||||||
saveLocalProfile(username,profile);
|
|
||||||
}
|
public void setLoading(String username,boolean loading){
|
||||||
|
getCachedProfile(username).loading=loading;
|
||||||
private CachedProfile getCachedProfile(String username){
|
}
|
||||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
public void updateCache(String username,UserProfile profile){
|
||||||
if(cp!=null)
|
updateCache(username,profile,CustomSkinLoader.config.enableLocalProfileCache);
|
||||||
return cp;
|
}
|
||||||
cp=new CachedProfile();
|
public void updateCache(String username,UserProfile profile,boolean saveLocalProfile){
|
||||||
cachedProfiles.put(username.toLowerCase(), cp);
|
CachedProfile cp=getCachedProfile(username);
|
||||||
return cp;
|
cp.profile=profile;
|
||||||
}
|
cp.expiryTime=TimeUtil.getUnixTimestamp(CustomSkinLoader.config.cacheExpiry);
|
||||||
private UserProfile loadLocalProfile(String username){
|
if(!saveLocalProfile)
|
||||||
File localProfile=new File(PROFILE_CACHE_DIR,username.toLowerCase()+".json");
|
return;
|
||||||
if(!localProfile.exists()){
|
saveLocalProfile(username,profile);
|
||||||
localProfiles.put(username.toLowerCase(), null);
|
}
|
||||||
}
|
public void putLoader(String username, Consumer<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>> loader) {
|
||||||
try{
|
this.profileLoaders.putIfAbsent(username, new ConcurrentLinkedDeque<>());
|
||||||
String json=IOUtils.toString(new FileInputStream(localProfile));
|
this.profileLoaders.get(username).offerLast(loader);
|
||||||
UserProfile profile=CustomSkinLoader.GSON.fromJson(json, UserProfile.class);
|
}
|
||||||
localProfiles.put(username.toLowerCase(), profile);
|
|
||||||
CustomSkinLoader.logger.info("Successfully load LocalProfile.");
|
private CachedProfile getCachedProfile(String username){
|
||||||
return profile;
|
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||||
}catch(Exception e){
|
if(cp!=null)
|
||||||
CustomSkinLoader.logger.info("Failed to load LocalProfile.("+e.toString()+")");
|
return cp;
|
||||||
localProfiles.put(username.toLowerCase(), null);
|
cp=new CachedProfile();
|
||||||
}
|
cachedProfiles.put(username.toLowerCase(), cp);
|
||||||
return null;
|
return cp;
|
||||||
}
|
}
|
||||||
private void saveLocalProfile(String username,UserProfile profile){
|
private UserProfile loadLocalProfile(String username){
|
||||||
String json=CustomSkinLoader.GSON.toJson(profile);
|
File localProfile=new File(PROFILE_CACHE_DIR,username.toLowerCase()+".json");
|
||||||
File localProfile=new File(PROFILE_CACHE_DIR,username.toLowerCase()+".json");
|
if(!localProfile.exists()){
|
||||||
if(localProfile.exists())
|
localProfiles.put(username.toLowerCase(), null);
|
||||||
localProfile.delete();
|
}
|
||||||
try {
|
try{
|
||||||
localProfile.createNewFile();
|
String json = FileUtils.readFileToString(localProfile, "UTF-8");
|
||||||
IOUtils.write(json, new FileOutputStream(localProfile));
|
UserProfile profile=CustomSkinLoader.GSON.fromJson(json, UserProfile.class);
|
||||||
CustomSkinLoader.logger.info("Successfully save LocalProfile.");
|
localProfiles.put(username.toLowerCase(), profile);
|
||||||
} catch (Exception e) {
|
CustomSkinLoader.logger.info("Successfully load LocalProfile.");
|
||||||
CustomSkinLoader.logger.info("Failed to save LocalProfile.("+e.toString()+")");
|
return profile;
|
||||||
}
|
}catch(Exception e){
|
||||||
}
|
CustomSkinLoader.logger.info("Failed to load LocalProfile.("+e.toString()+")");
|
||||||
|
localProfiles.put(username.toLowerCase(), null);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
private void saveLocalProfile(String username, UserProfile profile){
|
||||||
|
String json=CustomSkinLoader.GSON.toJson(profile);
|
||||||
|
File localProfile=new File(PROFILE_CACHE_DIR,username+".json");
|
||||||
|
if(localProfile.exists())
|
||||||
|
localProfile.delete();
|
||||||
|
try {
|
||||||
|
FileUtils.write(localProfile, json, "UTF-8");
|
||||||
|
CustomSkinLoader.logger.info("Successfully save LocalProfile.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
CustomSkinLoader.logger.info("Failed to save LocalProfile.("+e.toString()+")");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class CachedProfile{
|
class CachedProfile{
|
||||||
public UserProfile profile;
|
public UserProfile profile;
|
||||||
public long expiryTime=0;
|
public long expiryTime=0;
|
||||||
public boolean loading=false;
|
public boolean loading=false;
|
||||||
}
|
}
|
||||||
@@ -9,94 +9,95 @@ import customskinloader.profile.ModelManager0.Model;
|
|||||||
* @since 13.1
|
* @since 13.1
|
||||||
*/
|
*/
|
||||||
public class UserProfile {
|
public class UserProfile {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct url for skin.
|
* Direct url for skin.
|
||||||
* @since 13.1
|
* @since 13.1
|
||||||
*/
|
*/
|
||||||
public String skinUrl=null;
|
public String skinUrl=null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model for skin.
|
* Model for skin.
|
||||||
* default/slim
|
* default/slim
|
||||||
* @since 13.1
|
* @since 13.1
|
||||||
*/
|
*/
|
||||||
public String model=null;
|
public String model=null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct url for cape.
|
* Direct url for cape.
|
||||||
* @since 13.1
|
* @since 13.1
|
||||||
*/
|
*/
|
||||||
public String capeUrl=null;
|
public String capeUrl=null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct url for elytra.
|
* Direct url for elytra.
|
||||||
* @since 14.5
|
* @since 14.5
|
||||||
*/
|
*/
|
||||||
public String elytraUrl=null;
|
public String elytraUrl=null;
|
||||||
|
|
||||||
public void put(Model model,String url){
|
public void put(Model model,String url){
|
||||||
if(model==null||StringUtils.isEmpty(url))
|
if(model==null||StringUtils.isEmpty(url))
|
||||||
return;
|
return;
|
||||||
switch(model){
|
switch(model){
|
||||||
case SKIN_DEFAULT:
|
case SKIN_DEFAULT:
|
||||||
this.skinUrl=url;
|
this.skinUrl=url;
|
||||||
this.model="default";
|
this.model="default";
|
||||||
return;
|
return;
|
||||||
case SKIN_SLIM:
|
case SKIN_SLIM:
|
||||||
this.skinUrl=url;
|
this.skinUrl=url;
|
||||||
this.model="slim";
|
this.model="slim";
|
||||||
return;
|
return;
|
||||||
case CAPE:
|
case CAPE:
|
||||||
this.capeUrl=url;
|
this.capeUrl=url;
|
||||||
return;
|
return;
|
||||||
case ELYTRA:
|
case ELYTRA:
|
||||||
this.capeUrl=url;
|
this.elytraUrl = url;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Get parsed String to output the instance.
|
||||||
* Get parsed String to output the instance.
|
*/
|
||||||
*/
|
@Override
|
||||||
@Override
|
public String toString(){
|
||||||
public String toString(){
|
return toString(0);
|
||||||
return toString(0);
|
}
|
||||||
}
|
public String toString(long expiry){
|
||||||
public String toString(long expiry){
|
return "(SkinUrl: "+skinUrl+
|
||||||
return "(SkinUrl: "+skinUrl+
|
" , Model: "+model+
|
||||||
" , Model: "+model+
|
" , CapeUrl: "+capeUrl+
|
||||||
" , CapeUrl: "+capeUrl+
|
(StringUtils.isBlank(elytraUrl)?" ":" , ElytraUrl: "+elytraUrl)+
|
||||||
(StringUtils.isBlank(elytraUrl)?" ":" , ElytraUrl: "+elytraUrl)+
|
(expiry==0?"":(" , Expiry: "+expiry))+")";
|
||||||
(expiry==0?"":(" , Expiry: "+expiry))+")";
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Check if the instance is empty.
|
||||||
* Check if the instance is empty.
|
* @return status (true - empty)
|
||||||
* @return status (true - empty)
|
*/
|
||||||
*/
|
public boolean isEmpty(){
|
||||||
public boolean isEmpty(){
|
return StringUtils.isEmpty(skinUrl) && StringUtils.isEmpty(capeUrl) && StringUtils.isEmpty(elytraUrl);
|
||||||
return StringUtils.isEmpty(skinUrl) && StringUtils.isEmpty(capeUrl) && StringUtils.isEmpty(elytraUrl);
|
}
|
||||||
}
|
/**
|
||||||
/**
|
* Check if the instance is full(Both skin and cape).
|
||||||
* Check if the instance is full(Both skin and cape).
|
* @return status (true - full)
|
||||||
* @return status (true - full)
|
* @since 14.7
|
||||||
* @since 14.7
|
*/
|
||||||
*/
|
public boolean isFull(){
|
||||||
public boolean isFull(){
|
return StringUtils.isNoneBlank(skinUrl,capeUrl);
|
||||||
return StringUtils.isNoneBlank(skinUrl,capeUrl);
|
}
|
||||||
}
|
public boolean hasSkinUrl(){
|
||||||
public boolean hasSkinUrl(){
|
return StringUtils.isNotEmpty(skinUrl);
|
||||||
return StringUtils.isNotEmpty(skinUrl);
|
}
|
||||||
}
|
public void mix(UserProfile profile){
|
||||||
public void mix(UserProfile profile){
|
if(profile==null)
|
||||||
if(profile==null)
|
return;
|
||||||
return;
|
if(StringUtils.isEmpty(this.skinUrl)) {
|
||||||
if(StringUtils.isEmpty(this.skinUrl))
|
this.skinUrl = profile.skinUrl;
|
||||||
this.skinUrl=profile.skinUrl;
|
this.model = profile.model;
|
||||||
if(StringUtils.isEmpty(this.capeUrl))
|
}
|
||||||
this.capeUrl=profile.capeUrl;
|
if(StringUtils.isEmpty(this.capeUrl))
|
||||||
if(StringUtils.isEmpty(this.elytraUrl))
|
this.capeUrl=profile.capeUrl;
|
||||||
this.elytraUrl=profile.elytraUrl;
|
if(StringUtils.isEmpty(this.elytraUrl))
|
||||||
}
|
this.elytraUrl=profile.elytraUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
package customskinloader.tweaker;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
|
|
||||||
import customskinloader.utils.MinecraftUtil;
|
|
||||||
import net.minecraft.launchwrapper.IClassTransformer;
|
|
||||||
|
|
||||||
public class ClassTransformer implements IClassTransformer {
|
|
||||||
|
|
||||||
private ZipFile zipFile = null;
|
|
||||||
private ArrayList<String> classes=new ArrayList<String>();
|
|
||||||
|
|
||||||
public ClassTransformer() {
|
|
||||||
ModSystemTweaker.logger.info("ClassTransformer Begin");
|
|
||||||
try {
|
|
||||||
URLClassLoader ucl = (URLClassLoader)this.getClass().getClassLoader();
|
|
||||||
URL urls[] = ucl.getURLs();
|
|
||||||
for (URL url : urls) {
|
|
||||||
if(MinecraftUtil.isCoreFile(url)){
|
|
||||||
ModSystemTweaker.logger.debug(url.toString()+" : SKIP (core file).");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(MinecraftUtil.isLibraryFile(url)){
|
|
||||||
ModSystemTweaker.logger.debug(url.toString()+" : SKIP (library file).");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
File file = new File(url.toURI());
|
|
||||||
if(file==null||!file.isFile()){
|
|
||||||
ModSystemTweaker.logger.info(url.toString()+" : EXCEPTION (file not found).");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ZipFile tempZipFile = getZipFile(file);
|
|
||||||
if(tempZipFile==null){
|
|
||||||
ModSystemTweaker.logger.info(url.toString()+" : EXCEPTION (^ Message ^).");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (tempZipFile.getEntry("customskinloader/tweaker/ClassTransformer.class") == null){
|
|
||||||
tempZipFile.close();
|
|
||||||
ModSystemTweaker.logger.debug(url.toString()+" : FINISH (not target).");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
zipFile = tempZipFile;
|
|
||||||
Enumeration<ZipEntry> entries=(Enumeration<ZipEntry>) zipFile.entries();
|
|
||||||
StringBuilder sb=new StringBuilder();
|
|
||||||
while(entries.hasMoreElements()){
|
|
||||||
ZipEntry entry=entries.nextElement();
|
|
||||||
String name=entry.getName();
|
|
||||||
if(name.endsWith(".class")&&(!name.contains("/")||name.startsWith("net"))){
|
|
||||||
classes.add(name);
|
|
||||||
sb.append(" ");
|
|
||||||
sb.append(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ModSystemTweaker.logger.info(url.toString()+" : CHOOSE.");
|
|
||||||
ModSystemTweaker.logger.info("Classes:" + sb.toString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ModSystemTweaker.logger.warning(e);
|
|
||||||
}
|
|
||||||
if (zipFile == null) {
|
|
||||||
ModSystemTweaker.logger.info("Can not find JAR in the classpath.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ZipFile getZipFile(File file)
|
|
||||||
{
|
|
||||||
ZipFile zipFile0=null;
|
|
||||||
try {
|
|
||||||
zipFile0 = new ZipFile(file);
|
|
||||||
return zipFile0;
|
|
||||||
} catch (Exception e) {
|
|
||||||
ModSystemTweaker.logger.warning(e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] transform(String name, String transformedName, byte bytes[]) {
|
|
||||||
if (zipFile == null)
|
|
||||||
return bytes;
|
|
||||||
|
|
||||||
String fullName = new StringBuilder().append(name.startsWith("net") ? name.replaceAll("\\.", "\\/") : name).append(".class").toString();//Notch(Run)/MCP(Dev) Class Name
|
|
||||||
if(!classes.contains(fullName)){//Check Name
|
|
||||||
if(name.equals(transformedName))
|
|
||||||
return bytes;
|
|
||||||
fullName = new StringBuilder().append(transformedName.replaceAll("\\.", "\\/")).append(".class").toString();//MCP Class Name
|
|
||||||
if(!classes.contains(fullName))//check Again
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
ZipEntry ze = zipFile.getEntry(fullName);
|
|
||||||
if (ze == null)
|
|
||||||
return bytes;
|
|
||||||
byte diBytes[] = getClass(ze);
|
|
||||||
if (diBytes != null) {
|
|
||||||
ModSystemTweaker.logger.info("Class '" + name + "'("+transformedName+") transformed.");
|
|
||||||
return diBytes;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] getClass(ZipEntry ze) {
|
|
||||||
try {
|
|
||||||
InputStream is = zipFile.getInputStream(ze);
|
|
||||||
byte[] bytes = IOUtils.toByteArray(is);
|
|
||||||
if ((long)bytes.length == ze.getSize())
|
|
||||||
return bytes;
|
|
||||||
ModSystemTweaker.logger.info("Failed: " + ze.getName() + " " + bytes.length + " / " + ze.getSize());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package customskinloader.tweaker;
|
|
||||||
|
|
||||||
import customskinloader.Logger;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.launchwrapper.ITweaker;
|
|
||||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
|
||||||
|
|
||||||
public class ModSystemTweaker implements ITweaker {
|
|
||||||
|
|
||||||
public static Logger logger = new Logger();
|
|
||||||
|
|
||||||
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
|
|
||||||
File tweakerLogFile = new File(gameDir,"CustomSkinLoader/Tweaker.log");
|
|
||||||
logger = new Logger(tweakerLogFile);
|
|
||||||
|
|
||||||
logger.info("Using ModSystemTweaker");
|
|
||||||
logger.info("ModSystemTweaker: acceptOptions");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
|
||||||
logger.info("ModSystemTweaker: injectIntoClassLoader");
|
|
||||||
classLoader.registerTransformer("customskinloader.tweaker.ClassTransformer");
|
|
||||||
logger.info("ClassTransformer Registered");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLaunchTarget() {
|
|
||||||
logger.info("ModSystemTweaker: getLaunchTarget");
|
|
||||||
return "net.minecraft.client.main.Main";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getLaunchArguments() {
|
|
||||||
logger.info("ModSystemTweaker: getLaunchArguments");
|
|
||||||
return new String[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package customskinloader.tweaker;
|
|
||||||
|
|
||||||
import customskinloader.Logger;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
|
|
||||||
import net.minecraft.launchwrapper.ITweaker;
|
|
||||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
|
||||||
|
|
||||||
public class Tweaker implements ITweaker {
|
|
||||||
|
|
||||||
private String[] args;
|
|
||||||
|
|
||||||
public static Logger logger = new Logger();
|
|
||||||
|
|
||||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
|
||||||
File tweakerLogFile = new File(gameDir,"CustomSkinLoader/Tweaker.log");
|
|
||||||
logger = new Logger(tweakerLogFile);
|
|
||||||
|
|
||||||
logger.info("Using Tweaker");
|
|
||||||
logger.info("Tweaker: acceptOptions");
|
|
||||||
|
|
||||||
String[] temp={"--gameDir",gameDir.getAbsolutePath(),"--assetsDir",assetsDir.getAbsolutePath(),"--version",profile};
|
|
||||||
this.args=ArrayUtils.addAll(args.toArray(new String[args.size()]), temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
|
||||||
logger.info("Tweaker: injectIntoClassLoader");
|
|
||||||
logger.info("Loaded as a library.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLaunchTarget() {
|
|
||||||
logger.info("Tweaker: getLaunchTarget");
|
|
||||||
return "net.minecraft.client.main.Main";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getLaunchArguments() {
|
|
||||||
logger.info("Tweaker: getLaunchArguments");
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,12 +7,12 @@ 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;
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.io.Charsets;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -20,193 +20,263 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
|
|
||||||
public class HttpRequestUtil {
|
public class HttpRequestUtil {
|
||||||
public static class HttpRequest{
|
public static class HttpRequest {
|
||||||
public String url;
|
public String url;
|
||||||
public String userAgent=null;
|
public String userAgent = null;
|
||||||
public String payload=null;
|
public String payload = null;
|
||||||
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)
|
/**
|
||||||
public File cacheFile=null;//Default Cache File
|
* Cache Time
|
||||||
|
* -1=No Cache 0=Always Cache t=Default Cache Time(second)
|
||||||
public HttpRequest(String url){
|
*/
|
||||||
this.url=url;
|
public int cacheTime = 600;
|
||||||
}
|
public File cacheFile = null;//Default Cache File
|
||||||
public HttpRequest setUserAgent(String userAgent){
|
|
||||||
this.userAgent=userAgent;
|
public HttpRequest(String url) {
|
||||||
return this;
|
this.url = url;
|
||||||
}
|
}
|
||||||
public HttpRequest setPayload(String payload){
|
|
||||||
this.payload=payload;
|
public HttpRequest setUserAgent(String userAgent) {
|
||||||
return this;
|
this.userAgent = userAgent;
|
||||||
}
|
return this;
|
||||||
public HttpRequest setLoadContent(boolean loadContent){
|
}
|
||||||
this.loadContent=loadContent;
|
|
||||||
return this;
|
public HttpRequest setPayload(String payload) {
|
||||||
}
|
this.payload = payload;
|
||||||
public HttpRequest setCheckPNG(boolean checkPNG){
|
return this;
|
||||||
this.checkPNG=checkPNG;
|
}
|
||||||
return this;
|
|
||||||
}
|
public HttpRequest setLoadContent(boolean loadContent) {
|
||||||
public HttpRequest setCacheTime(int cacheTime){
|
this.loadContent = loadContent;
|
||||||
this.cacheTime=cacheTime;
|
return this;
|
||||||
return this;
|
}
|
||||||
}
|
|
||||||
public HttpRequest setCacheFile(File cacheFile){
|
public HttpRequest setCheckPNG(boolean checkPNG) {
|
||||||
this.cacheFile=cacheFile;
|
this.checkPNG = checkPNG;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
public static class HttpResponce{
|
public HttpRequest setCacheTime(int cacheTime) {
|
||||||
public String content=null;
|
this.cacheTime = cacheTime;
|
||||||
public int responceCode=-1;
|
return this;
|
||||||
public boolean success=false;
|
}
|
||||||
public boolean fromCache=false;
|
|
||||||
}
|
public HttpRequest setCacheFile(File cacheFile) {
|
||||||
public static class CacheInfo{
|
this.cacheFile = cacheFile;
|
||||||
public String url;
|
return this;
|
||||||
public String etag=null;
|
}
|
||||||
|
}
|
||||||
public long lastModified=-1;//ms
|
|
||||||
public long expire=-1;//UNIX timestamp
|
public static class HttpResponce {
|
||||||
}
|
public String content = null;
|
||||||
public static final File CACHE_DIR=new File(CustomSkinLoader.DATA_DIR,"caches");
|
public int responceCode = -1;
|
||||||
|
public boolean success = false;
|
||||||
public static HttpResponce makeHttpRequest(HttpRequest request){
|
public boolean fromCache = false;
|
||||||
try{
|
}
|
||||||
CustomSkinLoader.logger.info("Try to request '"+request.url+(request.userAgent==null?"'.":"' with user agent '"+request.userAgent+"'."));
|
|
||||||
//Check Cache
|
public static class CacheInfo {
|
||||||
if(StringUtils.isNotEmpty(request.payload))
|
public String url;
|
||||||
request.cacheTime=-1;//No Cache
|
public String etag = null;
|
||||||
File cacheInfoFile=null;
|
|
||||||
CacheInfo cacheInfo=new CacheInfo();
|
public long lastModified = -1;//ms
|
||||||
if(request.cacheFile==null && request.cacheTime>=0){
|
public long expire = -1;//UNIX timestamp
|
||||||
String hash=DigestUtils.sha1Hex(request.url);
|
}
|
||||||
request.cacheFile=new File(CACHE_DIR,hash);
|
|
||||||
cacheInfoFile=new File(CACHE_DIR,hash+".json");
|
public static final File CACHE_DIR = new File(CustomSkinLoader.DATA_DIR, "caches");
|
||||||
}
|
|
||||||
if(request.cacheTime==0 && request.cacheFile.isFile())
|
public static HttpResponce makeHttpRequest(HttpRequest request) {
|
||||||
return loadFromCache(request,new HttpResponce());
|
return makeHttpRequest(request, 0);
|
||||||
if(cacheInfoFile!=null&&cacheInfoFile.isFile()){
|
}
|
||||||
String json=FileUtils.readFileToString(cacheInfoFile);
|
|
||||||
if(StringUtils.isNotEmpty(json))
|
public static HttpResponce makeHttpRequest(HttpRequest request, int redirectTime) {
|
||||||
cacheInfo=CustomSkinLoader.GSON.fromJson(json, CacheInfo.class);
|
try {
|
||||||
if(cacheInfo==null)
|
//No url provided, try to load from special cache file
|
||||||
cacheInfo=new CacheInfo();
|
if (request.url == null || request.url.isEmpty()) {
|
||||||
if(cacheInfo.expire>=TimeUtil.getCurrentUnixTimestamp())
|
CustomSkinLoader.logger.debug("Try to read cache '" + request.cacheFile + "'.");
|
||||||
return loadFromCache(request,new HttpResponce(),cacheInfo.expire);
|
return loadFromCache(request, new HttpResponce());
|
||||||
}
|
}
|
||||||
|
CustomSkinLoader.logger.debug("Try to request '" + request.url + (request.userAgent == null ? "'." : "' with user agent '" + request.userAgent + "'."));
|
||||||
//Init Connection
|
//Check Cache
|
||||||
String url=new URI(request.url).toASCIIString();
|
if (StringUtils.isNotEmpty(request.payload) || CustomSkinLoader.config.forceDisableCache) {
|
||||||
if(!url.equalsIgnoreCase(request.url))
|
request.cacheTime = -1;//No Cache
|
||||||
CustomSkinLoader.logger.info("Encoded URL: "+url);
|
}
|
||||||
HttpURLConnection c = (HttpURLConnection) (new URL(url)).openConnection();
|
File cacheInfoFile = null;
|
||||||
c.setReadTimeout(1000 * 10);
|
CacheInfo cacheInfo = new CacheInfo();
|
||||||
c.setConnectTimeout(1000 * 10);
|
if (request.cacheFile == null && request.cacheTime >= 0) {
|
||||||
c.setDoInput(true);
|
String hash = DigestUtils.sha1Hex(request.url);
|
||||||
c.setUseCaches(false);
|
request.cacheFile = new File(CACHE_DIR, hash);
|
||||||
c.setInstanceFollowRedirects(true);
|
cacheInfoFile = new File(CACHE_DIR, hash + ".json");
|
||||||
|
}
|
||||||
//Make Connection
|
//noinspection BulkFileAttributesRead
|
||||||
if(cacheInfo.lastModified>=0)
|
if (request.cacheTime == 0 && request.cacheFile.isFile()) {
|
||||||
c.setIfModifiedSince(cacheInfo.lastModified);
|
return loadFromCache(request, new HttpResponce());
|
||||||
if(cacheInfo.etag!=null)
|
}
|
||||||
c.setRequestProperty("If-None-Match",cacheInfo.etag);
|
if (cacheInfoFile != null && cacheInfoFile.isFile()) {
|
||||||
c.setRequestProperty("Accept-Encoding","gzip");
|
String json = FileUtils.readFileToString(cacheInfoFile, "UTF-8");
|
||||||
if(request.userAgent!=null)
|
if (StringUtils.isNotEmpty(json)) {
|
||||||
c.setRequestProperty("User-Agent",request.userAgent);
|
cacheInfo = CustomSkinLoader.GSON.fromJson(json, CacheInfo.class);
|
||||||
if(StringUtils.isNotEmpty(request.payload)){
|
}
|
||||||
CustomSkinLoader.logger.info("Payload: "+request.payload);
|
if (cacheInfo == null) {
|
||||||
c.setDoOutput(true);
|
cacheInfo = new CacheInfo();
|
||||||
OutputStream os=c.getOutputStream();
|
}
|
||||||
IOUtils.write(request.payload, os);
|
if (cacheInfo.expire >= TimeUtil.getCurrentUnixTimestamp()) {
|
||||||
IOUtils.closeQuietly(os);
|
return loadFromCache(request, new HttpResponce(), cacheInfo.expire);
|
||||||
}
|
}
|
||||||
c.connect();
|
}
|
||||||
|
|
||||||
//Check Connection
|
//Init Connection
|
||||||
HttpResponce responce=new HttpResponce();
|
URL rawUrl = new URL(request.url);
|
||||||
responce.responceCode=c.getResponseCode();
|
URI uri = new URI(
|
||||||
int res=c.getResponseCode()/100;
|
rawUrl.getProtocol(),
|
||||||
if(res==4||res==5){//Failed
|
rawUrl.getUserInfo(),
|
||||||
CustomSkinLoader.logger.info("Failed to request (Response Code: "+c.getResponseCode()+")");
|
rawUrl.getHost(),
|
||||||
return responce;
|
rawUrl.getPort(),
|
||||||
}
|
rawUrl.getPath(),
|
||||||
responce.success=true;
|
rawUrl.getQuery(),
|
||||||
CustomSkinLoader.logger.info("Successfully request (Response Code: "+c.getResponseCode()+" , Content Length: "+c.getContentLength()+")");
|
rawUrl.getRef()
|
||||||
if(responce.responceCode==HttpURLConnection.HTTP_NOT_MODIFIED)
|
);
|
||||||
return loadFromCache(request,responce);
|
String url = uri.toASCIIString();
|
||||||
|
if (!url.equalsIgnoreCase(request.url)) {
|
||||||
//Load Content
|
CustomSkinLoader.logger.debug("Encoded URL: " + url);
|
||||||
InputStream is="gzip".equals(c.getContentEncoding())?new GZIPInputStream(c.getInputStream()):c.getInputStream();
|
}
|
||||||
byte [] bytes = IOUtils.toByteArray(is);
|
HttpURLConnection c = (HttpURLConnection) (new URL(url)).openConnection();
|
||||||
if(request.checkPNG&&(bytes.length<=4||bytes[1]!=(byte)'P'||bytes[2]!=(byte)'N'||bytes[3]!=(byte)'G')){
|
c.setReadTimeout(1000 * 10);
|
||||||
CustomSkinLoader.logger.info("Failed to request (Not Standard PNG)");
|
c.setConnectTimeout(1000 * 10);
|
||||||
responce.success=false;
|
c.setDoInput(true);
|
||||||
return responce;
|
c.setUseCaches(false);
|
||||||
}
|
c.setInstanceFollowRedirects(true);
|
||||||
if(request.cacheFile!=null){
|
|
||||||
FileUtils.writeByteArrayToFile(request.cacheFile, bytes);
|
//Make Connection
|
||||||
if(cacheInfoFile!=null){
|
if (cacheInfo.lastModified >= 0) {
|
||||||
cacheInfo.url=request.url;
|
c.setIfModifiedSince(cacheInfo.lastModified);
|
||||||
cacheInfo.etag=c.getHeaderField("ETag");
|
}
|
||||||
cacheInfo.lastModified=c.getLastModified();
|
if (cacheInfo.etag != null) {
|
||||||
cacheInfo.expire=getExpire(c,request.cacheTime);
|
c.setRequestProperty("If-None-Match", cacheInfo.etag);
|
||||||
FileUtils.write(cacheInfoFile, CustomSkinLoader.GSON.toJson(cacheInfo));
|
}
|
||||||
}
|
c.setRequestProperty("Accept-Encoding", "gzip");
|
||||||
CustomSkinLoader.logger.info("Saved to cache (Length: "+request.cacheFile.length()+" , Path: '"+request.cacheFile.getAbsolutePath()+"' , Expire: "+cacheInfo.expire+")");
|
if (request.userAgent != null) {
|
||||||
}
|
c.setRequestProperty("User-Agent", request.userAgent);
|
||||||
if(!request.loadContent)
|
}
|
||||||
return responce;
|
if (StringUtils.isNotEmpty(request.payload)) {
|
||||||
responce.content=new String(bytes,Charsets.UTF_8);
|
CustomSkinLoader.logger.info("Payload: " + request.payload);
|
||||||
CustomSkinLoader.logger.info("Content: "+responce.content);
|
c.setRequestMethod("POST");
|
||||||
return responce;
|
c.setRequestProperty("Content-Type", "application/json");
|
||||||
|
c.setDoOutput(true);
|
||||||
}catch(Exception e){
|
OutputStream os = c.getOutputStream();
|
||||||
CustomSkinLoader.logger.info("Failed to request (Exception: "+e.toString()+")");
|
IOUtils.write(request.payload, os, "UTF-8");
|
||||||
return loadFromCache(request,new HttpResponce());
|
IOUtils.closeQuietly(os);
|
||||||
}
|
}
|
||||||
}
|
c.connect();
|
||||||
|
|
||||||
public static File getCacheFile(String hash){
|
//Check Connection
|
||||||
return new File(CACHE_DIR,hash);
|
HttpResponce responce = new HttpResponce();
|
||||||
}
|
responce.responceCode = c.getResponseCode();
|
||||||
private static HttpResponce loadFromCache(HttpRequest request,HttpResponce responce){
|
int res = c.getResponseCode();
|
||||||
return loadFromCache(request,responce,0);
|
if (res / 100 == 4 || res / 100 == 5) {//Failed
|
||||||
}
|
CustomSkinLoader.logger.debug("Failed to request (Response Code: " + res + ")");
|
||||||
private static HttpResponce loadFromCache(HttpRequest request,HttpResponce responce,long expireTime){
|
return responce;
|
||||||
if(request.cacheFile==null||!request.cacheFile.isFile())
|
}
|
||||||
return responce;
|
if (res == HttpURLConnection.HTTP_MOVED_PERM || res == HttpURLConnection.HTTP_MOVED_TEMP) {
|
||||||
CustomSkinLoader.logger.info("Cache file found (Length: "+request.cacheFile.length()+" , Path: '"+request.cacheFile.getAbsolutePath()+"' , Expire: "+expireTime+"')");
|
//Redirect
|
||||||
responce.fromCache=true;
|
if (redirectTime >= 4) {
|
||||||
responce.success=true;
|
CustomSkinLoader.logger.debug("Failed to request (Too many redirection)");
|
||||||
if(!request.loadContent)
|
return responce;
|
||||||
return responce;
|
}
|
||||||
|
request.url = c.getHeaderField("Location");//Get redirecting location
|
||||||
CustomSkinLoader.logger.info("Try to load from cache '"+request.cacheFile.getAbsolutePath()+"'.");
|
if (request.url == null) {
|
||||||
try {
|
CustomSkinLoader.logger.debug("Failed to request (Redirecting location not found)");
|
||||||
responce.content=FileUtils.readFileToString(request.cacheFile);
|
return responce;
|
||||||
CustomSkinLoader.logger.info("Successfully to load from cache");
|
}
|
||||||
} catch (IOException e) {
|
CustomSkinLoader.logger.debug("Redirect to: " + request.url);
|
||||||
CustomSkinLoader.logger.info("Failed to load from cache (Exception: "+e.toString()+")");
|
return makeHttpRequest(request, redirectTime + 1);//Recursion
|
||||||
responce.success=false;
|
}
|
||||||
}
|
responce.success = true;
|
||||||
return responce;
|
CustomSkinLoader.logger.debug("Successfully request (Response Code: " + res + " , Content Length: " + c.getContentLength() + ")");
|
||||||
}
|
if (responce.responceCode == HttpURLConnection.HTTP_NOT_MODIFIED) {
|
||||||
private final static Pattern MAX_AGE_PATTERN = Pattern.compile(".*?max-age=(\\d+).*?");
|
return loadFromCache(request, responce);
|
||||||
private static long getExpire(HttpURLConnection connection,int cacheTime){
|
}
|
||||||
String cacheControl=connection.getHeaderField("Cache-Control");
|
if (responce.responceCode == HttpURLConnection.HTTP_NO_CONTENT) {
|
||||||
if(StringUtils.isNotEmpty(cacheControl)){
|
request.cacheTime = 3600;
|
||||||
Matcher m=MAX_AGE_PATTERN.matcher(cacheControl);
|
}
|
||||||
if(m!=null && m.matches())
|
|
||||||
return TimeUtil.getUnixTimestamp(Long.parseLong(m.group(m.groupCount())));
|
//Load Content
|
||||||
}
|
InputStream is = "gzip".equals(c.getContentEncoding()) ? new GZIPInputStream(c.getInputStream()) : c.getInputStream();
|
||||||
long expires=connection.getExpiration();
|
byte[] bytes = IOUtils.toByteArray(is);
|
||||||
if(expires>0)
|
if (request.checkPNG && (bytes.length <= 4 || bytes[1] != (byte) 'P' || bytes[2] != (byte) 'N' || bytes[3] != (byte) 'G')) {
|
||||||
return expires/1000;
|
CustomSkinLoader.logger.debug("Failed to request (Not Standard PNG)");
|
||||||
return TimeUtil.getUnixTimestampRandomDelay(cacheTime==0 ? 86400 : cacheTime);
|
responce.success = false;
|
||||||
|
return responce;
|
||||||
}
|
}
|
||||||
|
if (request.cacheFile != null) {
|
||||||
|
FileUtils.writeByteArrayToFile(request.cacheFile, bytes);
|
||||||
|
if (cacheInfoFile != null) {
|
||||||
|
cacheInfo.url = request.url;
|
||||||
|
cacheInfo.etag = c.getHeaderField("ETag");
|
||||||
|
cacheInfo.lastModified = c.getLastModified();
|
||||||
|
cacheInfo.expire = getExpire(c, request.cacheTime);
|
||||||
|
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 + ")");
|
||||||
|
}
|
||||||
|
if (!request.loadContent) {
|
||||||
|
return responce;
|
||||||
|
}
|
||||||
|
responce.content = new String(bytes, StandardCharsets.UTF_8);
|
||||||
|
CustomSkinLoader.logger.debug("Content: " + responce.content);
|
||||||
|
return responce;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
CustomSkinLoader.logger.debug("Failed to request " + request.url + " (Exception: " + e + ")");
|
||||||
|
return loadFromCache(request, new HttpResponce());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getCacheFile(String hash) {
|
||||||
|
return new File(CACHE_DIR, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpResponce loadFromCache(HttpRequest request, HttpResponce responce) {
|
||||||
|
return loadFromCache(request, responce, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpResponce loadFromCache(HttpRequest request, HttpResponce responce, long expireTime) {
|
||||||
|
if (request.cacheFile == null || !request.cacheFile.isFile()) {
|
||||||
|
return responce;
|
||||||
|
}
|
||||||
|
CustomSkinLoader.logger.debug("Cache file found (Length: " + request.cacheFile.length() + " , Path: '" + request.cacheFile.getAbsolutePath() + "' , Expire: " + expireTime + ")");
|
||||||
|
responce.fromCache = true;
|
||||||
|
responce.success = true;
|
||||||
|
if (!request.loadContent) {
|
||||||
|
return responce;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomSkinLoader.logger.info("Try to load from cache '" + request.cacheFile.getAbsolutePath() + "'.");
|
||||||
|
try {
|
||||||
|
responce.content = FileUtils.readFileToString(request.cacheFile, "UTF-8");
|
||||||
|
CustomSkinLoader.logger.debug("Successfully load from cache");
|
||||||
|
CustomSkinLoader.logger.debug("Content: " + responce.content);
|
||||||
|
} catch (IOException e) {
|
||||||
|
CustomSkinLoader.logger.debug("Failed to load from cache (Exception: " + e + ")");
|
||||||
|
responce.success = false;
|
||||||
|
}
|
||||||
|
return responce;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static Pattern MAX_AGE_PATTERN = Pattern.compile(".*?max-age=(\\d+).*?");
|
||||||
|
|
||||||
|
private static long getExpire(HttpURLConnection connection, int cacheTime) {
|
||||||
|
String cacheControl = connection.getHeaderField("Cache-Control");
|
||||||
|
if (StringUtils.isNotEmpty(cacheControl)) {
|
||||||
|
Matcher m = MAX_AGE_PATTERN.matcher(cacheControl);
|
||||||
|
if (m.matches())
|
||||||
|
return TimeUtil.getUnixTimestamp(Long.parseLong(m.group(m.groupCount())));
|
||||||
|
}
|
||||||
|
long expires = connection.getExpiration();
|
||||||
|
if (expires > 0)
|
||||||
|
return expires / 1000;
|
||||||
|
return TimeUtil.getUnixTimestampRandomDelay(cacheTime == 0 ? 2592000 : cacheTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,75 +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
|
|
||||||
LEGACY_MARK="(LEGACY)",
|
private static final String
|
||||||
LOCAL_MARK="(LOCAL)",
|
LEGACY_MARK = "(LEGACY)",
|
||||||
LOCAL_LEGACY_MARK="(LOCAL_LEGACY)";
|
LOCAL_MARK = "(LOCAL)",
|
||||||
public static File defaultCacheDir;
|
LOCAL_LEGACY_MARK = "(LOCAL_LEGACY)",
|
||||||
public static void cleanCacheDir(){
|
BASE64_MARK = "(BASE64)";
|
||||||
if(defaultCacheDir!=null){
|
public static File defaultCacheDir;
|
||||||
defaultCacheDir.delete();
|
|
||||||
defaultCacheDir.mkdirs();
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
}
|
public static void cleanCacheDir() {
|
||||||
}
|
if (defaultCacheDir != null) {
|
||||||
public static File getCacheDir(){
|
defaultCacheDir.delete();
|
||||||
return defaultCacheDir==null?new File(MinecraftUtil.getMinecraftDataDir(),"assets/skins"):defaultCacheDir;
|
defaultCacheDir.mkdirs();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl){
|
|
||||||
HttpTextureInfo info=new HttpTextureInfo();
|
public static File getCacheDir() {
|
||||||
if(fakeUrl.startsWith("http")){
|
return defaultCacheDir == null ? new File(MinecraftUtil.getMinecraftDataDir(), "assets/skins") : defaultCacheDir;
|
||||||
info.url=fakeUrl;
|
}
|
||||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
|
||||||
info.cacheFile=getCacheFile(info.hash);
|
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl) {
|
||||||
|
HttpTextureInfo info = new HttpTextureInfo();
|
||||||
|
if (fakeUrl.startsWith("http")) {
|
||||||
|
info.url = fakeUrl;
|
||||||
|
info.hash = FilenameUtils.getBaseName(fakeUrl);
|
||||||
|
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=HttpTextureUtil.getCacheFile(info.hash);
|
info.cacheFile = HttpRequestUtil.getCacheFile(info.hash);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
return info;
|
//Base64 fake url format: `(BASE64)${hash}`
|
||||||
}
|
if (fakeUrl.startsWith(BASE64_MARK)) {
|
||||||
|
fakeUrl = fakeUrl.replace(BASE64_MARK, "");
|
||||||
public static String getLegacyFakeUrl(String url){
|
info.hash = fakeUrl;
|
||||||
return LEGACY_MARK+url;
|
info.cacheFile = getCacheFile(info.hash);
|
||||||
}
|
return info;
|
||||||
public static String getLocalFakeUrl(String path){
|
}
|
||||||
return LOCAL_MARK+path;
|
return info;
|
||||||
}
|
}
|
||||||
public static String getLocalLegacyFakeUrl(String path,String hash){
|
|
||||||
return LOCAL_LEGACY_MARK+hash+","+path;
|
public static String getLegacyFakeUrl(String url) {
|
||||||
}
|
return LEGACY_MARK + url;
|
||||||
public static String getHash(String url,long size,long lastModified){
|
}
|
||||||
return DigestUtils.sha1Hex(size+url+lastModified);
|
|
||||||
}
|
public static String getLocalFakeUrl(String path) {
|
||||||
public static File getCacheFile(String hash){
|
return LOCAL_MARK + path;
|
||||||
return getCacheFile(defaultCacheDir,hash);
|
}
|
||||||
}
|
|
||||||
public static File getCacheFile(File cacheDir,String hash){
|
public static String getLocalLegacyFakeUrl(String path, String hash) {
|
||||||
return new File(new File(cacheDir,hash.length()>2?hash.substring(0,2):"xx"), hash);
|
return LOCAL_LEGACY_MARK + hash + "," + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getBase64FakeUrl(String hash) {
|
||||||
|
return BASE64_MARK + hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHash(String url, long size, long lastModified) {
|
||||||
|
return DigestUtils.sha1Hex(size + url + lastModified);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,79 +1,127 @@
|
|||||||
package customskinloader.utils;
|
package customskinloader.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
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.HostnameVerifier;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
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? false : !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
|
||||||
public static void ignoreHttpsCertificate(){
|
public static void ignoreHttpsCertificate(){
|
||||||
HostnameVerifier doNotVerify = new HostnameVerifier() {
|
HostnameVerifier doNotVerify = new HostnameVerifier() {
|
||||||
|
|
||||||
public boolean verify(String hostname, SSLSession session) {
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
|
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
return new X509Certificate[] {};
|
return new X509Certificate[] {};
|
||||||
}
|
}
|
||||||
public void checkClientTrusted(X509Certificate[] chain, String authType){}
|
public void checkClientTrusted(X509Certificate[] chain, String authType){}
|
||||||
public void checkServerTrusted(X509Certificate[] chain, String authType){}
|
public void checkServerTrusted(X509Certificate[] chain, String authType){}
|
||||||
}};
|
}};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SSLContext sc = SSLContext.getInstance("TLS");
|
SSLContext sc = SSLContext.getInstance("TLS");
|
||||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
//HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||||
HttpsURLConnection.setDefaultHostnameVerifier(doNotVerify);
|
HttpsURLConnection.setDefaultSSLSocketFactory(new SSLSocketFactoryFacade());
|
||||||
} catch (Exception e) {
|
HttpsURLConnection.setDefaultHostnameVerifier(doNotVerify);
|
||||||
e.printStackTrace();
|
} catch (Exception e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public static String parseAddress(String address) {
|
|
||||||
if(StringUtils.isEmpty(address))
|
public static String parseAddress(String address) {
|
||||||
return null;
|
if(StringUtils.isEmpty(address))
|
||||||
String[] addresses=address.split(":");
|
return null;
|
||||||
InetAddress add;
|
String[] addresses=address.split(":");
|
||||||
try {
|
InetAddress add;
|
||||||
add = InetAddress.getByName(addresses[0]);
|
try {
|
||||||
} catch (UnknownHostException e) {
|
add = InetAddress.getByName(addresses[0]);
|
||||||
e.printStackTrace();
|
} catch (UnknownHostException e) {
|
||||||
return null;
|
e.printStackTrace();
|
||||||
}
|
return null;
|
||||||
return add.getHostAddress()+(addresses.length==2 ? addresses[1] : "25565");
|
}
|
||||||
}
|
return add.getHostAddress()+(addresses.length==2 ? addresses[1] : "25565");
|
||||||
public static boolean isLanServer(String standardAddress){
|
}
|
||||||
if(StringUtils.isEmpty(standardAddress))
|
public static boolean isLanServer(String standardAddress){
|
||||||
return true;
|
if(StringUtils.isEmpty(standardAddress))
|
||||||
String[] addresses=standardAddress.split(":");
|
return true;
|
||||||
int numIp=getNumIp(addresses[0]);
|
String[] addresses=standardAddress.split(":");
|
||||||
return numIp==0||numIp==getNumIp("127.0.0.1")||
|
int numIp=getNumIp(addresses[0]);
|
||||||
(numIp>=getNumIp("192.168.0.0")&&numIp<=getNumIp("192.168.255.255"))||
|
return numIp==0||numIp==getNumIp("127.0.0.1")||
|
||||||
(numIp>=getNumIp("10.0.0.0")&&numIp<=getNumIp("10.255.255.255"))||
|
(numIp>=getNumIp("192.168.0.0")&&numIp<=getNumIp("192.168.255.255"))||
|
||||||
(numIp>=getNumIp("172.16.0.0")&&numIp<=getNumIp("172.31.255.255"));
|
(numIp>=getNumIp("10.0.0.0")&&numIp<=getNumIp("10.255.255.255"))||
|
||||||
}
|
(numIp>=getNumIp("172.16.0.0")&&numIp<=getNumIp("172.31.255.255"));
|
||||||
public static int getNumIp(String ip){
|
}
|
||||||
int num=0;
|
public static int getNumIp(String ip){
|
||||||
String[] ips=ip.split("\\.");
|
int num=0;
|
||||||
if(ips.length!=4)
|
String[] ips=ip.split("\\.");
|
||||||
return 0;
|
if(ips.length!=4)
|
||||||
for(int i=0;i<4;i++)
|
return 0;
|
||||||
num+=Integer.parseInt(ips[i])*(256^(3-i));
|
for(int i=0;i<4;i++)
|
||||||
return num;
|
num+=Integer.parseInt(ips[i])*(256^(3-i));
|
||||||
}
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//https://stackoverflow.com/questions/30817934/extended-server-name-sni-extension-not-sent-with-jdk1-8-0-but-send-with-jdk1-7
|
||||||
|
public static class SSLSocketFactoryFacade extends SSLSocketFactory {
|
||||||
|
|
||||||
|
SSLSocketFactory sslsf;
|
||||||
|
|
||||||
|
public SSLSocketFactoryFacade() {
|
||||||
|
sslsf = (SSLSocketFactory) SSLSocketFactory.getDefault();;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getDefaultCipherSuites() {
|
||||||
|
return sslsf.getDefaultCipherSuites();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getSupportedCipherSuites() {
|
||||||
|
return sslsf.getSupportedCipherSuites();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOException {
|
||||||
|
return sslsf.createSocket(socket, s, i, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(String s, int i) throws IOException, UnknownHostException {
|
||||||
|
return sslsf.createSocket(s, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(String s, int i, InetAddress inetAddress, int i1) throws IOException, UnknownHostException {
|
||||||
|
return sslsf.createSocket(s, i, inetAddress, i1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
|
||||||
|
return createSocket(inetAddress, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress1, int i1) throws IOException {
|
||||||
|
return createSocket(inetAddress, i, inetAddress1, i1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package customskinloader.utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
public class JavaUtil {
|
||||||
|
public static URL[] getClasspath() {
|
||||||
|
if (JavaUtil.class.getClassLoader() instanceof URLClassLoader) {
|
||||||
|
//Java 8-
|
||||||
|
//Use URLClassLoader Directly
|
||||||
|
URLClassLoader ucl = (URLClassLoader) JavaUtil.class.getClassLoader();
|
||||||
|
return ucl.getURLs();
|
||||||
|
} else {
|
||||||
|
//Java 9+
|
||||||
|
//It uses APPClassLoader instead of URLClassLoader
|
||||||
|
//Get Classpath from properties and parse it to URL array
|
||||||
|
String classpath = System.getProperty("java.class.path");
|
||||||
|
String[] elements = classpath.split(File.pathSeparator);
|
||||||
|
if (elements.length == 0)
|
||||||
|
return new URL[0];
|
||||||
|
LinkedList<URL> urls = new LinkedList<URL>();
|
||||||
|
for (String ele : elements) {
|
||||||
|
try {
|
||||||
|
urls.add(new File(ele).toURI().toURL());
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return urls.toArray(new URL[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,124 +1,91 @@
|
|||||||
package customskinloader.utils;
|
package customskinloader.utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.invoke.MethodHandle;
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.multiplayer.ServerData;
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
|
import net.minecraft.client.resources.SkinManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Alexander Xia
|
* @author Alexander Xia
|
||||||
* @since 13.6
|
* @since 13.6
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MinecraftUtil {
|
public class MinecraftUtil {
|
||||||
public static File getMinecraftDataDir(){
|
public static File getMinecraftDataDir() {
|
||||||
return net.minecraft.client.Minecraft.getMinecraft().mcDataDir;
|
return Minecraft.getMinecraft().gameDir;
|
||||||
}
|
}
|
||||||
public static MinecraftSessionService getSessionService(){
|
|
||||||
return net.minecraft.client.Minecraft.getMinecraft().getSessionService();
|
public static TextureManager getTextureManager() {
|
||||||
}
|
return Minecraft.getMinecraft().getTextureManager();
|
||||||
public static TextureManager getTextureManager(){
|
}
|
||||||
return net.minecraft.client.Minecraft.getMinecraft().getTextureManager();
|
|
||||||
}
|
public static SkinManager getSkinManager() {
|
||||||
|
return Minecraft.getMinecraft().getSkinManager();
|
||||||
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(){
|
public static String getMinecraftMainVersion() {
|
||||||
if(minecraftVersion!=null&&!minecraftVersion.isEmpty())
|
//Check if cached version found
|
||||||
return minecraftVersion;
|
if (minecraftMainVersion != null) {
|
||||||
testProbe();
|
return minecraftMainVersion;
|
||||||
return minecraftVersion;
|
}
|
||||||
}
|
|
||||||
public static String getMinecraftVersionText(){
|
//version.json can be found in 1.14+
|
||||||
StringBuilder sb=new StringBuilder();
|
URL versionFile = MinecraftUtil.class.getResource("/version.json");
|
||||||
for(String version:getMinecraftVersions())
|
if (versionFile != null) {
|
||||||
sb.append(version).append(" ");
|
try (
|
||||||
return StringUtils.trim(sb.toString());
|
InputStream is = versionFile.openStream();
|
||||||
}
|
InputStreamReader isr = new InputStreamReader(is)
|
||||||
public static String getMinecraftMainVersion(){
|
) {
|
||||||
if(minecraftMainVersion!=null)
|
JsonObject obj = new JsonParser().parse(isr).getAsJsonObject();
|
||||||
return minecraftMainVersion;
|
minecraftMainVersion = obj.get("name").getAsString();
|
||||||
for(String version:getMinecraftVersions()){
|
return minecraftMainVersion;
|
||||||
Matcher m = null;
|
} catch (Exception ignored) {
|
||||||
try{
|
|
||||||
m=MINECRAFT_VERSION_PATTERN.matcher(version);
|
}
|
||||||
}catch(Exception e){
|
}
|
||||||
e.printStackTrace();
|
|
||||||
}
|
//RealmsSharedConstants.VERSION_STRING is available in 1.16-
|
||||||
if(m==null || !m.matches())
|
try {
|
||||||
continue;
|
Class<?> realmsSharedConstants = Class.forName("net.minecraft.realms.RealmsSharedConstants");
|
||||||
minecraftMainVersion=m.group(m.groupCount());
|
MethodHandle mh = MethodHandles.publicLookup().findStaticGetter(realmsSharedConstants, "VERSION_STRING", String.class);
|
||||||
break;
|
minecraftMainVersion = (String) mh.invoke();
|
||||||
}
|
return minecraftMainVersion;
|
||||||
return minecraftMainVersion;
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// (domain|ip)(:port)
|
//No version can be found
|
||||||
public static String getServerAddress(){
|
return "unknown";
|
||||||
net.minecraft.client.multiplayer.ServerData data=net.minecraft.client.Minecraft.getMinecraft().getCurrentServerData();
|
}
|
||||||
if(data==null)//Single Player
|
|
||||||
return null;
|
// (domain|ip)(:port)
|
||||||
return data.serverIP;
|
public static String getServerAddress() {
|
||||||
}
|
ServerData data = Minecraft.getMinecraft().getCurrentServerData();
|
||||||
// ip:port
|
if (data == null)//Single Player
|
||||||
public static String getStandardServerAddress(){
|
return null;
|
||||||
return HttpUtil0.parseAddress(getServerAddress());
|
return data.serverIP;
|
||||||
}
|
}
|
||||||
public static boolean isLanServer(){
|
|
||||||
return HttpUtil0.isLanServer(getStandardServerAddress());
|
// ip:port
|
||||||
}
|
public static String getStandardServerAddress() {
|
||||||
public static String getCurrentUsername(){
|
return HttpUtil0.parseAddress(getServerAddress());
|
||||||
return net.minecraft.client.Minecraft.getMinecraft().getSession().getProfile().getName();
|
}
|
||||||
}
|
|
||||||
|
public static boolean isLanServer() {
|
||||||
private final static Pattern MINECRAFT_CORE_FILE_PATTERN = Pattern.compile("^(.*?)/versions/([^\\/\\\\]*?)/([^\\/\\\\]*?).jar$");
|
return HttpUtil0.isLanServer(getStandardServerAddress());
|
||||||
private static void testProbe(){
|
}
|
||||||
minecraftVersion.clear();
|
|
||||||
URLClassLoader ucl = (URLClassLoader)new MinecraftUtil().getClass().getClassLoader();
|
public static String getCredential(GameProfile profile) {
|
||||||
URL urls[] = ucl.getURLs();
|
return (profile == null || profile.hashCode() == 0) ? null :
|
||||||
for(URL url:urls){
|
(profile.getId() == null ? profile.getName() : String.format("%s-%s", profile.getName(), profile.getId()));
|
||||||
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){
|
|
||||||
Matcher m = null;
|
|
||||||
try{
|
|
||||||
m=MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return m!=null && m.matches();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static Pattern LIBRARY_FILE_PATTERN = Pattern.compile("^(.*?)/libraries/(.*?)/([^\\/\\\\]*?).jar$");
|
|
||||||
public static boolean isLibraryFile(URL url){
|
|
||||||
Matcher m = null;
|
|
||||||
try{
|
|
||||||
m=LIBRARY_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return m!=null && m.matches();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package customskinloader.utils;
|
||||||
|
|
||||||
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class TextureUtil {
|
||||||
|
/**
|
||||||
|
* Save and get fake url of base64 texture
|
||||||
|
*
|
||||||
|
* @param base64 texture in base64 string
|
||||||
|
* @return base64 fake url
|
||||||
|
* @since 14.16
|
||||||
|
*/
|
||||||
|
public static String parseBase64Texture(String base64) {
|
||||||
|
byte[] capeBytes = Base64.decodeBase64(base64);
|
||||||
|
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);
|
||||||
|
return fakeUrl;
|
||||||
|
} catch (Exception e) {
|
||||||
|
CustomSkinLoader.logger.warning("Error parsing base64 image: " + base64);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package customskinloader.utils;
|
package customskinloader.utils;
|
||||||
|
|
||||||
public class TimeUtil {
|
public class TimeUtil {
|
||||||
public static long getCurrentUnixTimestamp(){
|
public static long getCurrentUnixTimestamp(){
|
||||||
return System.currentTimeMillis()/1000l;
|
return System.currentTimeMillis() / 1000L;
|
||||||
}
|
}
|
||||||
public static long getUnixTimestamp(long offset){
|
public static long getUnixTimestamp(long offset){
|
||||||
return getCurrentUnixTimestamp()+offset;
|
return getCurrentUnixTimestamp()+offset;
|
||||||
}
|
}
|
||||||
public static long getUnixTimestampRandomDelay(long offset){
|
public static long getUnixTimestampRandomDelay(long offset){
|
||||||
return getCurrentUnixTimestamp()+offset+random(0,5);
|
return getCurrentUnixTimestamp()+offset+random(0,5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int random(int min,int max){
|
private static int random(int min,int max){
|
||||||
return (int)(Math.random()*(max-min+1))+min;
|
return (int)(Math.random()*(max-min+1))+min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package customskinloader.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
public class Version implements Comparable {
|
||||||
|
private String version;
|
||||||
|
private int sub[];
|
||||||
|
|
||||||
|
public Version(String version) {
|
||||||
|
if (version == null) version = "";
|
||||||
|
this.version = version;
|
||||||
|
|
||||||
|
//Parse Subversion
|
||||||
|
String[] split = version.split("\\.");
|
||||||
|
sub = new int[split.length];
|
||||||
|
for (int i = 0; i < split.length; i++) {
|
||||||
|
if (StringUtils.isNumeric(split[i]))
|
||||||
|
sub[i] = Integer.parseInt(split[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Version of(String version) {
|
||||||
|
return new Version(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int compare(String version, String anotherVersion) {
|
||||||
|
return Version.of(version).compareTo(anotherVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Object o) {
|
||||||
|
if (o instanceof String) o = Version.of((String) o);//Parse String version
|
||||||
|
if (!(o instanceof Version)) throw new IllegalArgumentException(String.format("'%s' is not a Version.", o));
|
||||||
|
|
||||||
|
Version v = (Version) o;
|
||||||
|
int i = 0;
|
||||||
|
//Skip same subversion
|
||||||
|
while (i < sub.length && i < v.sub.length && sub[i] == v.sub[i]) i++;
|
||||||
|
//Compare first non-equal number
|
||||||
|
if (i < sub.length && i < v.sub.length)
|
||||||
|
return (sub[i] < v.sub[i]) ? -1 : ((sub[i] == v.sub[i]) ? 0 : 1); //Integer.compare(sub[i], v.sub[i]);
|
||||||
|
//Compare length if all subversion is same
|
||||||
|
return Integer.signum(sub.length - v.sub.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.minecraft.client.renderer;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.texture.NativeImage;
|
||||||
|
|
||||||
|
public interface IImageBuffer extends Runnable {
|
||||||
|
BufferedImage parseUserSkin(BufferedImage image);
|
||||||
|
|
||||||
|
NativeImage func_195786_a(NativeImage image);
|
||||||
|
|
||||||
|
void skinAvailable();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void run() {
|
||||||
|
this.skinAvailable();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package net.minecraft.client.renderer.texture;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty stack for 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_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getWidth
|
||||||
|
*/
|
||||||
|
public int func_195702_a() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getHeight
|
||||||
|
*/
|
||||||
|
public int func_195714_b() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copyImage image
|
||||||
|
*/
|
||||||
|
public void func_195703_a(NativeImage p_195703_1_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fillAreaRGBA x0 y0 weight height rgba
|
||||||
|
*/
|
||||||
|
public void func_195715_a(int p_195715_1_, int p_195715_2_, int p_195715_3_, int p_195715_4_, int p_195715_5_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copyAreaRGBA x0 y0 dx dy weight height reversex reversey
|
||||||
|
*/
|
||||||
|
public void func_195699_a(int p_195699_1_, int p_195699_2_, int p_195699_3_, int p_195699_4_, int p_195699_5_, int p_195699_6_, boolean p_195699_7_, boolean p_195699_8_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getPixelRGBA x y
|
||||||
|
*/
|
||||||
|
public int func_195709_a(int p_195709_1_, int p_195709_2_) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setPixelRGBA x y rgba
|
||||||
|
*/
|
||||||
|
public void func_195700_a(int p_195700_1_, int p_195700_2_, int p_195700_3_) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package net.minecraft.client.renderer.texture;
|
||||||
|
|
||||||
|
// exclude
|
||||||
|
public interface Texture {
|
||||||
|
}
|
||||||
@@ -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 {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
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
|
||||||
|
net/minecraft/client/Minecraft net/minecraft/class_310
|
||||||
|
gameDir field_1697
|
||||||
|
getCurrentServerData ()Lnet/minecraft/client/multiplayer/ServerData; method_1558
|
||||||
|
getMinecraft ()Lnet/minecraft/client/Minecraft; method_1551
|
||||||
|
getResourceManager ()Lnet/minecraft/client/resources/IResourceManager; method_1478
|
||||||
|
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/spectator/PlayerMenuObject net/minecraft/class_530
|
||||||
|
net/minecraft/client/multiplayer/ServerData net/minecraft/class_642
|
||||||
|
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
|
||||||
|
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/entity/RenderPlayer net/minecraft/class_1007
|
||||||
|
net/minecraft/client/renderer/entity/layers/LayerCape net/minecraft/class_972
|
||||||
|
net/minecraft/client/renderer/texture/ITextureObject net/minecraft/class_1062
|
||||||
|
net/minecraft/client/renderer/texture/NativeImage net/minecraft/class_1011
|
||||||
|
func_195699_a (IIIIIIZZ)V method_4304
|
||||||
|
func_195700_a (III)V method_4305
|
||||||
|
func_195702_a ()I method_4307
|
||||||
|
func_195703_a (Lnet/minecraft/client/renderer/texture/NativeImage;)V method_4317
|
||||||
|
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_195715_a (IIIII)V method_4326
|
||||||
|
net/minecraft/client/renderer/texture/SimpleTexture net/minecraft/class_1049
|
||||||
|
net/minecraft/client/renderer/texture/TextureManager net/minecraft/class_1060
|
||||||
|
getTexture (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/resources/DefaultPlayerSkin net/minecraft/class_1068
|
||||||
|
getDefaultSkin (Ljava/util/UUID;)Lnet/minecraft/util/ResourceLocation; method_4648
|
||||||
|
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
|
||||||
|
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/util/ResourceLocation; method_4656
|
||||||
|
net/minecraft/client/resources/SkinManager$3 net/minecraft/class_1071$3
|
||||||
|
field_152801_c field_152801_c
|
||||||
|
field_152802_d field_152802_d
|
||||||
|
net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/class_1071$class_1072
|
||||||
|
skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V onSkinTextureAvailable
|
||||||
|
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/StringUtils net/minecraft/class_3544
|
||||||
|
stripControlCodes (Ljava/lang/String;)Ljava/lang/String; method_15440
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
|
||||||
|
jar {
|
||||||
|
exclude 'customskinloader/tweaker/**'
|
||||||
|
exclude 'net/minecraft/client/renderer/RenderType.class'
|
||||||
|
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 {
|
||||||
|
maven {
|
||||||
|
name = "fabric"
|
||||||
|
url = "https://maven.fabricmc.net/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// This is the minimum version number that the mod should dependent in the development environment.
|
||||||
|
implementation "net.fabricmc:fabric-loader:0.12.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
import customskinloader.gradle.util.RemapUtil
|
||||||
|
import customskinloader.gradle.util.SourceUtil
|
||||||
|
import groovy.json.JsonSlurper
|
||||||
|
|
||||||
|
SourceUtil.addDependencies project, project(":Common"), project(":Vanilla/Common")
|
||||||
|
RemapUtil.remapSources project
|
||||||
|
|
||||||
|
// Resolve snapshot versions
|
||||||
|
tasks.publishModrinth.doFirst {
|
||||||
|
def snapshot = []
|
||||||
|
gameVersions.groupBy { v -> v.endsWith("-Snapshot") }.with {
|
||||||
|
this.tasks.publishModrinth.gameVersions = it[false]
|
||||||
|
snapshot = it[true]
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CustomSkinLoader Fabric edition should support all Minecraft snapshot edition.
|
||||||
|
def jsonSlurper = new JsonSlurper()
|
||||||
|
def officialVersionList = [] as Set
|
||||||
|
plugins.withId "net.minecraftforge.gradle.forge", { plugin ->
|
||||||
|
def currentRelease = null
|
||||||
|
// Get version manifest json.
|
||||||
|
// https://github.com/MinecraftForge/ForgeGradle/blob/fc67182a61926f0bdb0d12da5fba7f4322f64d86/src/main/java/net/minecraftforge/gradle/common/BasePlugin.java#L229
|
||||||
|
jsonSlurper.parse(plugin.cacheFile("McManifest.json")).versions.each { version ->
|
||||||
|
if (version.type == "snapshot") {
|
||||||
|
// If the first version is a snapshot, since Mojang no longer provides the target version for snapshots,
|
||||||
|
// we assume that new snapshots will not be supported until the next release.
|
||||||
|
if (currentRelease == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else if (version.type == "release") {
|
||||||
|
currentRelease = version.id.with {
|
||||||
|
it.toString().split($/\./$).with { "${it[0]}.${it[1]}" }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// We do not care about other types.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (snapshot.contains("${currentRelease}-Snapshot".toString())) {
|
||||||
|
officialVersionList << version.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsonSlurper.parse(new URL("https://meta.fabricmc.net/v2/versions/game")).each { version ->
|
||||||
|
// Exclude experimental editions which is not support in Modrinth.
|
||||||
|
if (!version.stable && officialVersionList.contains(version.version)) {
|
||||||
|
gameVersions << version.version.replace(" ", "-").replace("Pre-Release-", "pre") // Fix the id of the earlier preview versions of 1.14.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
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,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1
|
||||||
|
java_full_versions=8,9,10,11,12,13,14,15,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=Fabric.tsrg
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
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/Gui net/minecraft/class_332
|
||||||
|
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
|
||||||
|
renderPlayerlist (Lnet/minecraft/client/gui/Gui;ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V method_1919
|
||||||
|
net/minecraft/client/gui/spectator/PlayerMenuObject net/minecraft/class_530
|
||||||
|
net/minecraft/client/model/ModelRenderer net/minecraft/class_630
|
||||||
|
net/minecraft/client/renderer/IImageBuffer net/minecraft/class_760
|
||||||
|
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
|
||||||
|
func_210275_a (Lcom/mojang/authlib/GameProfile;ZLnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)V method_4653
|
||||||
|
func_229297_b_ (Ljava/util/Map;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)V method_4655
|
||||||
|
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$3 net/minecraft/class_1071$3
|
||||||
|
run ()V run
|
||||||
|
net/minecraft/client/resources/SkinManager$3$1 net/minecraft/class_1071$3$1
|
||||||
|
field_152803_a field_152803_a
|
||||||
|
field_152804_b field_152804_b
|
||||||
|
run ()V run
|
||||||
|
net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/class_1071$class_1072
|
||||||
|
skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V onSkinTextureAvailable
|
||||||
|
net/minecraft/scoreboard/ScoreObjective net/minecraft/class_266
|
||||||
|
net/minecraft/scoreboard/Scoreboard net/minecraft/class_269
|
||||||
|
net/minecraft/util/ResourceLocation net/minecraft/class_2960
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "customskinloader",
|
||||||
|
"version": "${modFullVersion}",
|
||||||
|
|
||||||
|
"name": "CustomSkinLoader",
|
||||||
|
"description": "Custom Skin Loader for Minecraft",
|
||||||
|
"authors": ["xfl03", "JLChnToZ"],
|
||||||
|
"contact": {
|
||||||
|
"homepage": "https://github.com/xfl03/MCCustomSkinLoader",
|
||||||
|
"issues": "https://github.com/xfl03/MCCustomSkinLoader/issues",
|
||||||
|
"sources": "https://github.com/xfl03/MCCustomSkinLoader"
|
||||||
|
},
|
||||||
|
"license": "GPL-3.0-only",
|
||||||
|
|
||||||
|
"environment": "client",
|
||||||
|
"mixins": [
|
||||||
|
"mixins.customskinloader.json"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"compatibilityLevel": "JAVA_8",
|
||||||
|
"mixinPriority": 1010,
|
||||||
|
"package": "customskinloader.mixin",
|
||||||
|
"client": [
|
||||||
|
"MixinGuiPlayerTabOverlay",
|
||||||
|
"MixinIResource",
|
||||||
|
"MixinIResourceManager",
|
||||||
|
"MixinLayerCape",
|
||||||
|
"MixinMinecraft",
|
||||||
|
"MixinRenderPlayer",
|
||||||
|
"MixinSkinManager",
|
||||||
|
"MixinSkinManager$V1",
|
||||||
|
"MixinSkinManager$V2",
|
||||||
|
"MixinThreadDownloadImageDataV2",
|
||||||
|
"MixinThreadDownloadImageDataV3"
|
||||||
|
],
|
||||||
|
"refmap": "mixins.customskinloader.refmap.json",
|
||||||
|
"plugin": "customskinloader.fabric.MixinConfigPlugin",
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
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_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,100 @@
|
|||||||
|
package customskinloader.fabric;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import customskinloader.log.LogManager;
|
||||||
|
import customskinloader.log.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 = LogManager.getLogger("Fabric");
|
||||||
|
private long world_version;
|
||||||
|
private long protocol_version;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad(String mixinPackage) {
|
||||||
|
LogManager.setLogFile(Paths.get("./CustomSkinLoader/CustomSkinLoader.log"));
|
||||||
|
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(".MixinSkinManager$V2")) {
|
||||||
|
result = this.world_version >= 2205 && this.protocol_version >= 554; // 19w38a+
|
||||||
|
} 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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
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_
|
||||||
|
net/minecraft/client/Minecraft net/minecraft/client/Minecraft
|
||||||
|
gameDir f_91069_
|
||||||
|
getCurrentServerData ()Lnet/minecraft/client/multiplayer/ServerData; m_91089_
|
||||||
|
getMinecraft ()Lnet/minecraft/client/Minecraft; m_91087_
|
||||||
|
getResourceManager ()Lnet/minecraft/client/resources/IResourceManager; m_91098_
|
||||||
|
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/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/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/resources/DefaultPlayerSkin net/minecraft/client/resources/DefaultPlayerSkin
|
||||||
|
getDefaultSkin (Ljava/util/UUID;)Lnet/minecraft/util/ResourceLocation; m_118627_
|
||||||
|
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_
|
||||||
|
loadSkin (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;)Lnet/minecraft/util/ResourceLocation; m_118825_
|
||||||
|
net/minecraft/client/resources/SkinManager$3 net/minecraft/client/resources/SkinManager$3
|
||||||
|
field_152801_c field_152801_c
|
||||||
|
field_152802_d field_152802_d
|
||||||
|
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,1.19.3,1.19.4,1.20,1.20.1
|
||||||
|
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
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"transformers": "transformers.js"
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
modLoader="javafml"
|
||||||
|
loaderVersion="[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="[37,)"
|
||||||
|
ordering="NONE"
|
||||||
|
side="CLIENT"
|
||||||
|
[[dependencies.customskinloader]]
|
||||||
|
modId="minecraft"
|
||||||
|
mandatory=true
|
||||||
|
versionRange="[1.17.1,)"
|
||||||
|
ordering="NONE"
|
||||||
|
side="CLIENT"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"pack": {
|
||||||
|
"description": "CustomSkinLoader resources",
|
||||||
|
"pack_format": 7
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,245 @@
|
|||||||
|
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 IntInsnNode = getJavaType('org.objectweb.asm.tree.IntInsnNode');
|
||||||
|
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;")) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if ((node.getOpcode() === Opcodes.INVOKESPECIAL && node.owner.equals("net/minecraft/resources/ResourceLocation") && checkName(node.name, "<init>") && node.desc.equals("(Ljava/lang/String;)V")) // 1.19-
|
||||||
|
|| (node.getOpcode() === Opcodes.INVOKESTATIC && node.owner.equals("net/minecraft/client/resources/SkinManager") && checkName(node.name, "m_242632_") && node.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Ljava/lang/String;)Lnet/minecraft/resources/ResourceLocation;"))) { // 1.19.1+
|
||||||
|
mn.instructions.insert(node, node = new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insert(node, node = new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "setResourceLocation", "(Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)Lnet/minecraft/resources/ResourceLocation;", false));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKEINTERFACE && node.owner.equals("net/minecraft/client/resources/SkinManager$SkinTextureCallback") && checkName(node.name, "onSkinTextureAvailable") && node.desc.equals("(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/resources/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V")) {
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(node, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 5));
|
||||||
|
mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "getModelCache", "(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcustomskinloader/fake/FakeSkinManager;Lnet/minecraft/resources/ResourceLocation;)Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;", false));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKESPECIAL && (node.owner.equals("net/minecraft/client/renderer/texture/HttpTexture") && checkName(node.name, "<init>") && node.desc.equals("(Ljava/io/File;Ljava/lang/String;Lnet/minecraft/resources/ResourceLocation;ZLjava/lang/Runnable;)V"))) {
|
||||||
|
var s = "(";
|
||||||
|
var args = Type.getType(node.desc).getArgumentTypes();
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
s = s + "Ljava/lang/Object;";
|
||||||
|
}
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.SWAP));
|
||||||
|
mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false));
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.SWAP));
|
||||||
|
mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "com/google/common/collect/ImmutableList", "of", s + ")Lcom/google/common/collect/ImmutableList;", false));
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
|
mn.instructions.insertBefore(node, new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
|
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.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "createThreadDownloadImageData", "(Lcom/google/common/collect/ImmutableList;Lcustomskinloader/fake/FakeSkinManager;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinTextureCallback;)[Ljava/lang/Object;", false));
|
||||||
|
for (var i = 0; i < args.length; i++) {
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.DUP));
|
||||||
|
mn.instructions.insertBefore(node, new IntInsnNode(Opcodes.BIPUSH, i));
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.AALOAD));
|
||||||
|
if (args[i].getInternalName().equals("Z")) {
|
||||||
|
mn.instructions.insertBefore(node, new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Boolean"));
|
||||||
|
mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false));
|
||||||
|
} else {
|
||||||
|
mn.instructions.insertBefore(node, new TypeInsnNode(Opcodes.CHECKCAST, args[i].getInternalName()));
|
||||||
|
}
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.SWAP));
|
||||||
|
}
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.POP));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (checkName(mn.name, "m_118817_") && mn.desc.equals("(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinTextureCallback;Z)V")) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKEINTERFACE
|
||||||
|
&& (node.owner.equals("java/util/concurrent/Executor") // 1.17.1
|
||||||
|
|| node.owner.equals("java/util/concurrent/ExecutorService")) // 1.18+
|
||||||
|
&& checkName(node.name, "execute") && node.desc.equals("(Ljava/lang/Runnable;)V")) {
|
||||||
|
mn.instructions.insertBefore(node, new VarInsnNode(Opcodes.ALOAD, 1));
|
||||||
|
mn.instructions.insert(node, new InsnNode(Opcodes.POP));
|
||||||
|
mn.instructions.set(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "loadProfileTextures", "(Ljava/lang/Runnable;Lcom/mojang/authlib/GameProfile;)V", false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (checkName(mn.name, "m_118821_") && mn.desc.equals("(Lcom/mojang/authlib/GameProfile;ZLnet/minecraft/client/resources/SkinManager$SkinTextureCallback;)V")) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKEINTERFACE && node.owner.equals("com/mojang/authlib/minecraft/MinecraftSessionService") && checkName(node.name, "getTextures") && node.desc.equals("(Lcom/mojang/authlib/GameProfile;Z)Ljava/util/Map;")) {
|
||||||
|
mn.instructions.set(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "customskinloader/fake/FakeSkinManager", "getUserProfile", "(Lcom/mojang/authlib/minecraft/MinecraftSessionService;Lcom/mojang/authlib/GameProfile;Z)Ljava/util/Map;", false));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (checkName(mn.name, "m_174849_") && mn.desc.equals("(Ljava/util/Map;Lnet/minecraft/client/resources/SkinManager$SkinTextureCallback;)V")) {
|
||||||
|
for (var iterator = mn.instructions.iterator(); iterator.hasNext();) {
|
||||||
|
var node = iterator.next();
|
||||||
|
if (node.getOpcode() === Opcodes.INVOKESTATIC && node.owner.equals("com/google/common/collect/ImmutableList") && checkName(node.name, "of") && node.desc.equals("(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList;")) {
|
||||||
|
mn.instructions.insertBefore(node, new InsnNode(Opcodes.POP2));
|
||||||
|
mn.instructions.insertBefore(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "com/mojang/authlib/minecraft/MinecraftProfileTexture$Type", "values", "()[Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;"))
|
||||||
|
mn.instructions.set(node, new MethodInsnNode(Opcodes.INVOKESTATIC, "com/google/common/collect/ImmutableList", "copyOf", "([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList;"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package net.minecraftforge.fml.common;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
//https://github.com/MinecraftForge/MinecraftForge/blob/1.13.x/src/main/java/net/minecraftforge/fml/common/Mod.java
|
||||||
|
//https://github.com/MinecraftForge/MinecraftForge/blob/1.12.x/src/main/java/net/minecraftforge/fml/common/Mod.java
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface Mod {
|
||||||
|
String value();
|
||||||
|
|
||||||
|
String modid() default "";
|
||||||
|
|
||||||
|
String name() default "";
|
||||||
|
|
||||||
|
String version() default "";
|
||||||
|
|
||||||
|
boolean clientSideOnly() default false;
|
||||||
|
|
||||||
|
String acceptedMinecraftVersions() default "";
|
||||||
|
|
||||||
|
String acceptableRemoteVersions() default "";
|
||||||
|
|
||||||
|
String certificateFingerprint() default "";
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@interface EventHandler {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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")
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
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,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_mc_version=1.12.2
|
||||||
|
forge_version=14.23.5.2768
|
||||||
|
mappings_version=stable_39
|
||||||
@@ -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
|
||||||
Loaded 100 of 195 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user