mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-25 04:04:25 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5868a39adb | ||
|
|
f7e000cb82 | ||
|
|
c40bb38e20 | ||
|
|
4449ccdd45 | ||
|
|
67e56957e7 | ||
|
|
ea432f2405 | ||
|
|
eee978fc83 | ||
|
|
9698d4098a | ||
|
|
3f779c9028 | ||
|
|
3945599fb4 | ||
|
|
b50e6a934f |
No files matched your search
@@ -0,0 +1,36 @@
|
|||||||
|
# Java Gradle CircleCI 2.0 configuration file
|
||||||
|
version: 2
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
docker:
|
||||||
|
- image: circleci/openjdk:8-jdk
|
||||||
|
|
||||||
|
working_directory: ~/repo
|
||||||
|
|
||||||
|
environment:
|
||||||
|
JVM_OPTS: -Xmx3200m
|
||||||
|
TERM: dumb
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
|
||||||
|
- restore_cache:
|
||||||
|
keys:
|
||||||
|
- gradle-cache
|
||||||
|
|
||||||
|
# Gradle Wrapper
|
||||||
|
# - run: sudo chmod +x gradlew
|
||||||
|
# - run: ./gradlew --version
|
||||||
|
# - run: ./gradlew clean build
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
- run: gradle --version
|
||||||
|
- run: gradle clean build
|
||||||
|
|
||||||
|
- store_artifacts:
|
||||||
|
path: ./build/libs
|
||||||
|
|
||||||
|
- save_cache:
|
||||||
|
paths:
|
||||||
|
- ~/.gradle
|
||||||
|
key: gradle-cache
|
||||||
+2
-1
@@ -22,4 +22,5 @@ hs_err_pid*
|
|||||||
.settings/
|
.settings/
|
||||||
|
|
||||||
#gradle
|
#gradle
|
||||||
.gradle/
|
.gradle/
|
||||||
|
build/
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
/build/
|
||||||
|
/src/main/
|
||||||
|
|
||||||
@@ -3,4 +3,4 @@ minecraft_full_versions=1.12
|
|||||||
#forge gradle needs forge version
|
#forge gradle needs forge version
|
||||||
forge_mc_version=1.12
|
forge_mc_version=1.12
|
||||||
forge_version=14.21.1.2387
|
forge_version=14.21.1.2387
|
||||||
mappings_version=snapshot_20170813
|
mappings_version=snapshot_20180203
|
||||||
@@ -0,0 +1,402 @@
|
|||||||
|
package net.minecraft.client.gui;
|
||||||
|
|
||||||
|
import com.google.common.collect.ComparisonChain;
|
||||||
|
import com.google.common.collect.Ordering;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||||
|
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EnumPlayerModelParts;
|
||||||
|
import net.minecraft.scoreboard.IScoreCriteria;
|
||||||
|
import net.minecraft.scoreboard.ScoreObjective;
|
||||||
|
import net.minecraft.scoreboard.ScorePlayerTeam;
|
||||||
|
import net.minecraft.scoreboard.Scoreboard;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraft.world.GameType;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class GuiPlayerTabOverlay extends Gui
|
||||||
|
{
|
||||||
|
private static final Ordering<NetworkPlayerInfo> ENTRY_ORDERING = Ordering.from(new GuiPlayerTabOverlay.PlayerComparator());
|
||||||
|
private final Minecraft mc;
|
||||||
|
private final GuiIngame guiIngame;
|
||||||
|
private ITextComponent footer;
|
||||||
|
private ITextComponent header;
|
||||||
|
/** The last time the playerlist was opened (went from not being renderd, to being rendered) */
|
||||||
|
private long lastTimeOpened;
|
||||||
|
/** Weither or not the playerlist is currently being rendered */
|
||||||
|
private boolean isBeingRendered;
|
||||||
|
|
||||||
|
public GuiPlayerTabOverlay(Minecraft mcIn, GuiIngame guiIngameIn)
|
||||||
|
{
|
||||||
|
this.mc = mcIn;
|
||||||
|
this.guiIngame = guiIngameIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name that should be renderd for the player supplied
|
||||||
|
*/
|
||||||
|
public String getPlayerName(NetworkPlayerInfo networkPlayerInfoIn)
|
||||||
|
{
|
||||||
|
return networkPlayerInfoIn.getDisplayName() != null ? networkPlayerInfoIn.getDisplayName().getFormattedText() : ScorePlayerTeam.formatPlayerName(networkPlayerInfoIn.getPlayerTeam(), networkPlayerInfoIn.getGameProfile().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by GuiIngame to update the information stored in the playerlist, does not actually render the list,
|
||||||
|
* however.
|
||||||
|
*/
|
||||||
|
public void updatePlayerList(boolean willBeRendered)
|
||||||
|
{
|
||||||
|
if (willBeRendered && !this.isBeingRendered)
|
||||||
|
{
|
||||||
|
this.lastTimeOpened = Minecraft.getSystemTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isBeingRendered = willBeRendered;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the playerlist, its background, headers and footers.
|
||||||
|
*/
|
||||||
|
public void renderPlayerlist(int width, Scoreboard scoreboardIn, @Nullable ScoreObjective scoreObjectiveIn)
|
||||||
|
{
|
||||||
|
NetHandlerPlayClient nethandlerplayclient = this.mc.player.connection;
|
||||||
|
List<NetworkPlayerInfo> list = ENTRY_ORDERING.<NetworkPlayerInfo>sortedCopy(nethandlerplayclient.getPlayerInfoMap());
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
|
||||||
|
for (NetworkPlayerInfo networkplayerinfo : list)
|
||||||
|
{
|
||||||
|
int k = this.mc.fontRenderer.getStringWidth(this.getPlayerName(networkplayerinfo));
|
||||||
|
i = Math.max(i, k);
|
||||||
|
|
||||||
|
if (scoreObjectiveIn != null && scoreObjectiveIn.getRenderType() != IScoreCriteria.EnumRenderType.HEARTS)
|
||||||
|
{
|
||||||
|
k = this.mc.fontRenderer.getStringWidth(" " + scoreboardIn.getOrCreateScore(networkplayerinfo.getGameProfile().getName(), scoreObjectiveIn).getScorePoints());
|
||||||
|
j = Math.max(j, k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list = list.subList(0, Math.min(list.size(), 80));
|
||||||
|
int l3 = list.size();
|
||||||
|
int i4 = l3;
|
||||||
|
int j4;
|
||||||
|
|
||||||
|
for (j4 = 1; i4 > 20; i4 = (l3 + j4 - 1) / j4)
|
||||||
|
{
|
||||||
|
++j4;
|
||||||
|
}
|
||||||
|
|
||||||
|
//boolean flag = this.mc.isIntegratedServerRunning() || this.mc.getConnection().getNetworkManager().isEncrypted();
|
||||||
|
boolean flag = true;//Modified
|
||||||
|
int l;
|
||||||
|
|
||||||
|
if (scoreObjectiveIn != null)
|
||||||
|
{
|
||||||
|
if (scoreObjectiveIn.getRenderType() == IScoreCriteria.EnumRenderType.HEARTS)
|
||||||
|
{
|
||||||
|
l = 90;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i1 = Math.min(j4 * ((flag ? 9 : 0) + i + l + 13), width - 50) / j4;
|
||||||
|
int j1 = width / 2 - (i1 * j4 + (j4 - 1) * 5) / 2;
|
||||||
|
int k1 = 10;
|
||||||
|
int l1 = i1 * j4 + (j4 - 1) * 5;
|
||||||
|
List<String> list1 = null;
|
||||||
|
|
||||||
|
if (this.header != null)
|
||||||
|
{
|
||||||
|
list1 = this.mc.fontRenderer.listFormattedStringToWidth(this.header.getFormattedText(), width - 50);
|
||||||
|
|
||||||
|
for (String s : list1)
|
||||||
|
{
|
||||||
|
l1 = Math.max(l1, this.mc.fontRenderer.getStringWidth(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> list2 = null;
|
||||||
|
|
||||||
|
if (this.footer != null)
|
||||||
|
{
|
||||||
|
list2 = this.mc.fontRenderer.listFormattedStringToWidth(this.footer.getFormattedText(), width - 50);
|
||||||
|
|
||||||
|
for (String s1 : list2)
|
||||||
|
{
|
||||||
|
l1 = Math.max(l1, this.mc.fontRenderer.getStringWidth(s1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list1 != null)
|
||||||
|
{
|
||||||
|
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + list1.size() * this.mc.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE);
|
||||||
|
|
||||||
|
for (String s2 : list1)
|
||||||
|
{
|
||||||
|
int i2 = this.mc.fontRenderer.getStringWidth(s2);
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s2, (float)(width / 2 - i2 / 2), (float)k1, -1);
|
||||||
|
k1 += this.mc.fontRenderer.FONT_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
++k1;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + i4 * 9, Integer.MIN_VALUE);
|
||||||
|
|
||||||
|
for (int k4 = 0; k4 < l3; ++k4)
|
||||||
|
{
|
||||||
|
int l4 = k4 / i4;
|
||||||
|
int i5 = k4 % i4;
|
||||||
|
int j2 = j1 + l4 * i1 + l4 * 5;
|
||||||
|
int k2 = k1 + i5 * 9;
|
||||||
|
drawRect(j2, k2, j2 + i1, k2 + 8, 553648127);
|
||||||
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
GlStateManager.enableAlpha();
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||||
|
|
||||||
|
if (k4 < list.size())
|
||||||
|
{
|
||||||
|
NetworkPlayerInfo networkplayerinfo1 = list.get(k4);
|
||||||
|
GameProfile gameprofile = networkplayerinfo1.getGameProfile();
|
||||||
|
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
EntityPlayer entityplayer = ((net.minecraft.world.World)this.mc.world).getPlayerEntityByUUID(gameprofile.getId());//Modified
|
||||||
|
boolean flag1 = entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.CAPE) && ("Dinnerbone".equals(gameprofile.getName()) || "Grumm".equals(gameprofile.getName()));
|
||||||
|
this.mc.getTextureManager().bindTexture(networkplayerinfo1.getLocationSkin());
|
||||||
|
int l2 = 8 + (flag1 ? 8 : 0);
|
||||||
|
int i3 = 8 * (flag1 ? -1 : 1);
|
||||||
|
Gui.drawScaledCustomSizeModalRect(j2, k2, 8.0F, (float)l2, 8, i3, 8, 8, 64.0F, 64.0F);
|
||||||
|
|
||||||
|
if (entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.HAT))
|
||||||
|
{
|
||||||
|
int j3 = 8 + (flag1 ? 8 : 0);
|
||||||
|
int k3 = 8 * (flag1 ? -1 : 1);
|
||||||
|
Gui.drawScaledCustomSizeModalRect(j2, k2, 40.0F, (float)j3, 8, k3, 8, 8, 64.0F, 64.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
j2 += 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
String s4 = this.getPlayerName(networkplayerinfo1);
|
||||||
|
|
||||||
|
if (networkplayerinfo1.getGameType() == GameType.SPECTATOR)
|
||||||
|
{
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(TextFormatting.ITALIC + s4, (float)j2, (float)k2, -1862270977);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s4, (float)j2, (float)k2, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scoreObjectiveIn != null && networkplayerinfo1.getGameType() != GameType.SPECTATOR)
|
||||||
|
{
|
||||||
|
int k5 = j2 + i + 1;
|
||||||
|
int l5 = k5 + l;
|
||||||
|
|
||||||
|
if (l5 - k5 > 5)
|
||||||
|
{
|
||||||
|
this.drawScoreboardValues(scoreObjectiveIn, k2, gameprofile.getName(), k5, l5, networkplayerinfo1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.drawPing(i1, j2 - (flag ? 9 : 0), k2, networkplayerinfo1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list2 != null)
|
||||||
|
{
|
||||||
|
k1 = k1 + i4 * 9 + 1;
|
||||||
|
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + list2.size() * this.mc.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE);
|
||||||
|
|
||||||
|
for (String s3 : list2)
|
||||||
|
{
|
||||||
|
int j5 = this.mc.fontRenderer.getStringWidth(s3);
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s3, (float)(width / 2 - j5 / 2), (float)k1, -1);
|
||||||
|
k1 += this.mc.fontRenderer.FONT_HEIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void drawPing(int p_175245_1_, int p_175245_2_, int p_175245_3_, NetworkPlayerInfo networkPlayerInfoIn)
|
||||||
|
{
|
||||||
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
this.mc.getTextureManager().bindTexture(ICONS);
|
||||||
|
int i = 0;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
if (networkPlayerInfoIn.getResponseTime() < 0)
|
||||||
|
{
|
||||||
|
j = 5;
|
||||||
|
}
|
||||||
|
else if (networkPlayerInfoIn.getResponseTime() < 150)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
else if (networkPlayerInfoIn.getResponseTime() < 300)
|
||||||
|
{
|
||||||
|
j = 1;
|
||||||
|
}
|
||||||
|
else if (networkPlayerInfoIn.getResponseTime() < 600)
|
||||||
|
{
|
||||||
|
j = 2;
|
||||||
|
}
|
||||||
|
else if (networkPlayerInfoIn.getResponseTime() < 1000)
|
||||||
|
{
|
||||||
|
j = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
j = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.zLevel += 100.0F;
|
||||||
|
this.drawTexturedModalRect(p_175245_2_ + p_175245_1_ - 11, p_175245_3_, 0, 176 + j * 8, 10, 8);
|
||||||
|
this.zLevel -= 100.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawScoreboardValues(ScoreObjective objective, int p_175247_2_, String name, int p_175247_4_, int p_175247_5_, NetworkPlayerInfo info)
|
||||||
|
{
|
||||||
|
int i = objective.getScoreboard().getOrCreateScore(name, objective).getScorePoints();
|
||||||
|
|
||||||
|
if (objective.getRenderType() == IScoreCriteria.EnumRenderType.HEARTS)
|
||||||
|
{
|
||||||
|
this.mc.getTextureManager().bindTexture(ICONS);
|
||||||
|
|
||||||
|
if (this.lastTimeOpened == info.getRenderVisibilityId())
|
||||||
|
{
|
||||||
|
if (i < info.getLastHealth())
|
||||||
|
{
|
||||||
|
info.setLastHealthTime(Minecraft.getSystemTime());
|
||||||
|
info.setHealthBlinkTime((long)(this.guiIngame.getUpdateCounter() + 20));
|
||||||
|
}
|
||||||
|
else if (i > info.getLastHealth())
|
||||||
|
{
|
||||||
|
info.setLastHealthTime(Minecraft.getSystemTime());
|
||||||
|
info.setHealthBlinkTime((long)(this.guiIngame.getUpdateCounter() + 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Minecraft.getSystemTime() - info.getLastHealthTime() > 1000L || this.lastTimeOpened != info.getRenderVisibilityId())
|
||||||
|
{
|
||||||
|
info.setLastHealth(i);
|
||||||
|
info.setDisplayHealth(i);
|
||||||
|
info.setLastHealthTime(Minecraft.getSystemTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
info.setRenderVisibilityId(this.lastTimeOpened);
|
||||||
|
info.setLastHealth(i);
|
||||||
|
int j = MathHelper.ceil((float)Math.max(i, info.getDisplayHealth()) / 2.0F);
|
||||||
|
int k = Math.max(MathHelper.ceil((float)(i / 2)), Math.max(MathHelper.ceil((float)(info.getDisplayHealth() / 2)), 10));
|
||||||
|
boolean flag = info.getHealthBlinkTime() > (long)this.guiIngame.getUpdateCounter() && (info.getHealthBlinkTime() - (long)this.guiIngame.getUpdateCounter()) / 3L % 2L == 1L;
|
||||||
|
|
||||||
|
if (j > 0)
|
||||||
|
{
|
||||||
|
float f = Math.min((float)(p_175247_5_ - p_175247_4_ - 4) / (float)k, 9.0F);
|
||||||
|
|
||||||
|
if (f > 3.0F)
|
||||||
|
{
|
||||||
|
for (int l = j; l < k; ++l)
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)l * f, (float)p_175247_2_, flag ? 25 : 16, 0, 9, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j1 = 0; j1 < j; ++j1)
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, flag ? 25 : 16, 0, 9, 9);
|
||||||
|
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
if (j1 * 2 + 1 < info.getDisplayHealth())
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, 70, 0, 9, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j1 * 2 + 1 == info.getDisplayHealth())
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, 79, 0, 9, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j1 * 2 + 1 < i)
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, j1 >= 10 ? 160 : 52, 0, 9, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j1 * 2 + 1 == i)
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, j1 >= 10 ? 169 : 61, 0, 9, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float f1 = MathHelper.clamp((float)i / 20.0F, 0.0F, 1.0F);
|
||||||
|
int i1 = (int)((1.0F - f1) * 255.0F) << 16 | (int)(f1 * 255.0F) << 8;
|
||||||
|
String s = "" + (float)i / 2.0F;
|
||||||
|
|
||||||
|
if (p_175247_5_ - this.mc.fontRenderer.getStringWidth(s + "hp") >= p_175247_4_)
|
||||||
|
{
|
||||||
|
s = s + "hp";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s, (float)((p_175247_5_ + p_175247_4_) / 2 - this.mc.fontRenderer.getStringWidth(s) / 2), (float)p_175247_2_, i1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String s1 = TextFormatting.YELLOW + "" + i;
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s1, (float)(p_175247_5_ - this.mc.fontRenderer.getStringWidth(s1)), (float)p_175247_2_, 16777215);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFooter(@Nullable ITextComponent footerIn)
|
||||||
|
{
|
||||||
|
this.footer = footerIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeader(@Nullable ITextComponent headerIn)
|
||||||
|
{
|
||||||
|
this.header = headerIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetFooterHeader()
|
||||||
|
{
|
||||||
|
this.header = null;
|
||||||
|
this.footer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
static class PlayerComparator implements Comparator<NetworkPlayerInfo>
|
||||||
|
{
|
||||||
|
private PlayerComparator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compare(NetworkPlayerInfo p_compare_1_, NetworkPlayerInfo p_compare_2_)
|
||||||
|
{
|
||||||
|
ScorePlayerTeam scoreplayerteam = p_compare_1_.getPlayerTeam();
|
||||||
|
ScorePlayerTeam scoreplayerteam1 = p_compare_2_.getPlayerTeam();
|
||||||
|
return ComparisonChain.start().compareTrueFirst(p_compare_1_.getGameType() != GameType.SPECTATOR, p_compare_2_.getGameType() != GameType.SPECTATOR).compare(scoreplayerteam != null ? scoreplayerteam.getName() : "", scoreplayerteam1 != null ? scoreplayerteam1.getName() : "").compare(p_compare_1_.getGameProfile().getName(), p_compare_2_.getGameProfile().getName()).result();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package net.minecraft.client.gui.spectator;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||||
|
import net.minecraft.client.gui.Gui;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.network.play.client.CPacketSpectate;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class PlayerMenuObject implements ISpectatorMenuObject
|
||||||
|
{
|
||||||
|
private final GameProfile profile;
|
||||||
|
private final ResourceLocation resourceLocation;
|
||||||
|
|
||||||
|
public PlayerMenuObject(GameProfile profileIn)
|
||||||
|
{
|
||||||
|
this.profile = profileIn;
|
||||||
|
/*
|
||||||
|
this.resourceLocation = AbstractClientPlayer.getLocationSkin(profileIn.getName());
|
||||||
|
AbstractClientPlayer.getDownloadImageSkin(this.resourceLocation, profileIn.getName());
|
||||||
|
*/
|
||||||
|
this.resourceLocation = customskinloader.fake.FakeClientPlayer.getLocationSkin(profileIn.getName());
|
||||||
|
customskinloader.fake.FakeClientPlayer.getDownloadImageSkin(this.resourceLocation, profileIn.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectItem(SpectatorMenu menu)
|
||||||
|
{
|
||||||
|
Minecraft.getMinecraft().getConnection().sendPacket(new CPacketSpectate(this.profile.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITextComponent getSpectatorName()
|
||||||
|
{
|
||||||
|
return new TextComponentString(this.profile.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renderIcon(float brightness, int alpha)
|
||||||
|
{
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(this.resourceLocation);
|
||||||
|
GlStateManager.color(1.0F, 1.0F, 1.0F, (float)alpha / 255.0F);
|
||||||
|
Gui.drawScaledCustomSizeModalRect(2, 2, 8.0F, 8.0F, 8, 8, 12, 12, 64.0F, 64.0F);
|
||||||
|
Gui.drawScaledCustomSizeModalRect(2, 2, 40.0F, 8.0F, 8, 8, 12, 12, 64.0F, 64.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,7 +70,7 @@ public class SkinManager
|
|||||||
*/
|
*/
|
||||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
||||||
{
|
{
|
||||||
return this.fakeManager.loadSkin(profileTexture, textureType, skinAvailableCallback);
|
return this.fakeManager.loadSkin(profileTexture, textureType, skinAvailableCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure)
|
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure)
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
/build/
|
||||||
|
/src/main/
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
minecraft_version=1.12.1
|
minecraft_version=1.12.1
|
||||||
minecraft_full_versions=1.12.1
|
minecraft_full_versions=1.12.1,1.12.2
|
||||||
#forge gradle needs forge version
|
#forge gradle needs forge version
|
||||||
forge_mc_version=1.12.1
|
forge_mc_version=1.12.2
|
||||||
forge_version=14.22.0.2452
|
forge_version=14.23.2.2611
|
||||||
mappings_version=snapshot_20170813
|
mappings_version=snapshot_20180210
|
||||||
@@ -0,0 +1,402 @@
|
|||||||
|
package net.minecraft.client.gui;
|
||||||
|
|
||||||
|
import com.google.common.collect.ComparisonChain;
|
||||||
|
import com.google.common.collect.Ordering;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||||
|
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.EnumPlayerModelParts;
|
||||||
|
import net.minecraft.scoreboard.IScoreCriteria;
|
||||||
|
import net.minecraft.scoreboard.ScoreObjective;
|
||||||
|
import net.minecraft.scoreboard.ScorePlayerTeam;
|
||||||
|
import net.minecraft.scoreboard.Scoreboard;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraft.world.GameType;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class GuiPlayerTabOverlay extends Gui
|
||||||
|
{
|
||||||
|
private static final Ordering<NetworkPlayerInfo> ENTRY_ORDERING = Ordering.from(new GuiPlayerTabOverlay.PlayerComparator());
|
||||||
|
private final Minecraft mc;
|
||||||
|
private final GuiIngame guiIngame;
|
||||||
|
private ITextComponent footer;
|
||||||
|
private ITextComponent header;
|
||||||
|
/** The last time the playerlist was opened (went from not being renderd, to being rendered) */
|
||||||
|
private long lastTimeOpened;
|
||||||
|
/** Weither or not the playerlist is currently being rendered */
|
||||||
|
private boolean isBeingRendered;
|
||||||
|
|
||||||
|
public GuiPlayerTabOverlay(Minecraft mcIn, GuiIngame guiIngameIn)
|
||||||
|
{
|
||||||
|
this.mc = mcIn;
|
||||||
|
this.guiIngame = guiIngameIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name that should be renderd for the player supplied
|
||||||
|
*/
|
||||||
|
public String getPlayerName(NetworkPlayerInfo networkPlayerInfoIn)
|
||||||
|
{
|
||||||
|
return networkPlayerInfoIn.getDisplayName() != null ? networkPlayerInfoIn.getDisplayName().getFormattedText() : ScorePlayerTeam.formatPlayerName(networkPlayerInfoIn.getPlayerTeam(), networkPlayerInfoIn.getGameProfile().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by GuiIngame to update the information stored in the playerlist, does not actually render the list,
|
||||||
|
* however.
|
||||||
|
*/
|
||||||
|
public void updatePlayerList(boolean willBeRendered)
|
||||||
|
{
|
||||||
|
if (willBeRendered && !this.isBeingRendered)
|
||||||
|
{
|
||||||
|
this.lastTimeOpened = Minecraft.getSystemTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isBeingRendered = willBeRendered;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the playerlist, its background, headers and footers.
|
||||||
|
*/
|
||||||
|
public void renderPlayerlist(int width, Scoreboard scoreboardIn, @Nullable ScoreObjective scoreObjectiveIn)
|
||||||
|
{
|
||||||
|
NetHandlerPlayClient nethandlerplayclient = this.mc.player.connection;
|
||||||
|
List<NetworkPlayerInfo> list = ENTRY_ORDERING.<NetworkPlayerInfo>sortedCopy(nethandlerplayclient.getPlayerInfoMap());
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
|
||||||
|
for (NetworkPlayerInfo networkplayerinfo : list)
|
||||||
|
{
|
||||||
|
int k = this.mc.fontRenderer.getStringWidth(this.getPlayerName(networkplayerinfo));
|
||||||
|
i = Math.max(i, k);
|
||||||
|
|
||||||
|
if (scoreObjectiveIn != null && scoreObjectiveIn.getRenderType() != IScoreCriteria.EnumRenderType.HEARTS)
|
||||||
|
{
|
||||||
|
k = this.mc.fontRenderer.getStringWidth(" " + scoreboardIn.getOrCreateScore(networkplayerinfo.getGameProfile().getName(), scoreObjectiveIn).getScorePoints());
|
||||||
|
j = Math.max(j, k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list = list.subList(0, Math.min(list.size(), 80));
|
||||||
|
int l3 = list.size();
|
||||||
|
int i4 = l3;
|
||||||
|
int j4;
|
||||||
|
|
||||||
|
for (j4 = 1; i4 > 20; i4 = (l3 + j4 - 1) / j4)
|
||||||
|
{
|
||||||
|
++j4;
|
||||||
|
}
|
||||||
|
|
||||||
|
//boolean flag = this.mc.isIntegratedServerRunning() || this.mc.getConnection().getNetworkManager().isEncrypted();
|
||||||
|
boolean flag = true;//Modified
|
||||||
|
int l;
|
||||||
|
|
||||||
|
if (scoreObjectiveIn != null)
|
||||||
|
{
|
||||||
|
if (scoreObjectiveIn.getRenderType() == IScoreCriteria.EnumRenderType.HEARTS)
|
||||||
|
{
|
||||||
|
l = 90;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i1 = Math.min(j4 * ((flag ? 9 : 0) + i + l + 13), width - 50) / j4;
|
||||||
|
int j1 = width / 2 - (i1 * j4 + (j4 - 1) * 5) / 2;
|
||||||
|
int k1 = 10;
|
||||||
|
int l1 = i1 * j4 + (j4 - 1) * 5;
|
||||||
|
List<String> list1 = null;
|
||||||
|
|
||||||
|
if (this.header != null)
|
||||||
|
{
|
||||||
|
list1 = this.mc.fontRenderer.listFormattedStringToWidth(this.header.getFormattedText(), width - 50);
|
||||||
|
|
||||||
|
for (String s : list1)
|
||||||
|
{
|
||||||
|
l1 = Math.max(l1, this.mc.fontRenderer.getStringWidth(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> list2 = null;
|
||||||
|
|
||||||
|
if (this.footer != null)
|
||||||
|
{
|
||||||
|
list2 = this.mc.fontRenderer.listFormattedStringToWidth(this.footer.getFormattedText(), width - 50);
|
||||||
|
|
||||||
|
for (String s1 : list2)
|
||||||
|
{
|
||||||
|
l1 = Math.max(l1, this.mc.fontRenderer.getStringWidth(s1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list1 != null)
|
||||||
|
{
|
||||||
|
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + list1.size() * this.mc.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE);
|
||||||
|
|
||||||
|
for (String s2 : list1)
|
||||||
|
{
|
||||||
|
int i2 = this.mc.fontRenderer.getStringWidth(s2);
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s2, (float)(width / 2 - i2 / 2), (float)k1, -1);
|
||||||
|
k1 += this.mc.fontRenderer.FONT_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
++k1;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + i4 * 9, Integer.MIN_VALUE);
|
||||||
|
|
||||||
|
for (int k4 = 0; k4 < l3; ++k4)
|
||||||
|
{
|
||||||
|
int l4 = k4 / i4;
|
||||||
|
int i5 = k4 % i4;
|
||||||
|
int j2 = j1 + l4 * i1 + l4 * 5;
|
||||||
|
int k2 = k1 + i5 * 9;
|
||||||
|
drawRect(j2, k2, j2 + i1, k2 + 8, 553648127);
|
||||||
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
GlStateManager.enableAlpha();
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||||
|
|
||||||
|
if (k4 < list.size())
|
||||||
|
{
|
||||||
|
NetworkPlayerInfo networkplayerinfo1 = list.get(k4);
|
||||||
|
GameProfile gameprofile = networkplayerinfo1.getGameProfile();
|
||||||
|
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
EntityPlayer entityplayer = ((net.minecraft.world.World)this.mc.world).getPlayerEntityByUUID(gameprofile.getId());//Modified
|
||||||
|
boolean flag1 = entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.CAPE) && ("Dinnerbone".equals(gameprofile.getName()) || "Grumm".equals(gameprofile.getName()));
|
||||||
|
this.mc.getTextureManager().bindTexture(networkplayerinfo1.getLocationSkin());
|
||||||
|
int l2 = 8 + (flag1 ? 8 : 0);
|
||||||
|
int i3 = 8 * (flag1 ? -1 : 1);
|
||||||
|
Gui.drawScaledCustomSizeModalRect(j2, k2, 8.0F, (float)l2, 8, i3, 8, 8, 64.0F, 64.0F);
|
||||||
|
|
||||||
|
if (entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.HAT))
|
||||||
|
{
|
||||||
|
int j3 = 8 + (flag1 ? 8 : 0);
|
||||||
|
int k3 = 8 * (flag1 ? -1 : 1);
|
||||||
|
Gui.drawScaledCustomSizeModalRect(j2, k2, 40.0F, (float)j3, 8, k3, 8, 8, 64.0F, 64.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
j2 += 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
String s4 = this.getPlayerName(networkplayerinfo1);
|
||||||
|
|
||||||
|
if (networkplayerinfo1.getGameType() == GameType.SPECTATOR)
|
||||||
|
{
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(TextFormatting.ITALIC + s4, (float)j2, (float)k2, -1862270977);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s4, (float)j2, (float)k2, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scoreObjectiveIn != null && networkplayerinfo1.getGameType() != GameType.SPECTATOR)
|
||||||
|
{
|
||||||
|
int k5 = j2 + i + 1;
|
||||||
|
int l5 = k5 + l;
|
||||||
|
|
||||||
|
if (l5 - k5 > 5)
|
||||||
|
{
|
||||||
|
this.drawScoreboardValues(scoreObjectiveIn, k2, gameprofile.getName(), k5, l5, networkplayerinfo1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.drawPing(i1, j2 - (flag ? 9 : 0), k2, networkplayerinfo1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list2 != null)
|
||||||
|
{
|
||||||
|
k1 = k1 + i4 * 9 + 1;
|
||||||
|
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + list2.size() * this.mc.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE);
|
||||||
|
|
||||||
|
for (String s3 : list2)
|
||||||
|
{
|
||||||
|
int j5 = this.mc.fontRenderer.getStringWidth(s3);
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s3, (float)(width / 2 - j5 / 2), (float)k1, -1);
|
||||||
|
k1 += this.mc.fontRenderer.FONT_HEIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void drawPing(int p_175245_1_, int p_175245_2_, int p_175245_3_, NetworkPlayerInfo networkPlayerInfoIn)
|
||||||
|
{
|
||||||
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
this.mc.getTextureManager().bindTexture(ICONS);
|
||||||
|
int i = 0;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
if (networkPlayerInfoIn.getResponseTime() < 0)
|
||||||
|
{
|
||||||
|
j = 5;
|
||||||
|
}
|
||||||
|
else if (networkPlayerInfoIn.getResponseTime() < 150)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
else if (networkPlayerInfoIn.getResponseTime() < 300)
|
||||||
|
{
|
||||||
|
j = 1;
|
||||||
|
}
|
||||||
|
else if (networkPlayerInfoIn.getResponseTime() < 600)
|
||||||
|
{
|
||||||
|
j = 2;
|
||||||
|
}
|
||||||
|
else if (networkPlayerInfoIn.getResponseTime() < 1000)
|
||||||
|
{
|
||||||
|
j = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
j = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.zLevel += 100.0F;
|
||||||
|
this.drawTexturedModalRect(p_175245_2_ + p_175245_1_ - 11, p_175245_3_, 0, 176 + j * 8, 10, 8);
|
||||||
|
this.zLevel -= 100.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawScoreboardValues(ScoreObjective objective, int p_175247_2_, String name, int p_175247_4_, int p_175247_5_, NetworkPlayerInfo info)
|
||||||
|
{
|
||||||
|
int i = objective.getScoreboard().getOrCreateScore(name, objective).getScorePoints();
|
||||||
|
|
||||||
|
if (objective.getRenderType() == IScoreCriteria.EnumRenderType.HEARTS)
|
||||||
|
{
|
||||||
|
this.mc.getTextureManager().bindTexture(ICONS);
|
||||||
|
|
||||||
|
if (this.lastTimeOpened == info.getRenderVisibilityId())
|
||||||
|
{
|
||||||
|
if (i < info.getLastHealth())
|
||||||
|
{
|
||||||
|
info.setLastHealthTime(Minecraft.getSystemTime());
|
||||||
|
info.setHealthBlinkTime((long)(this.guiIngame.getUpdateCounter() + 20));
|
||||||
|
}
|
||||||
|
else if (i > info.getLastHealth())
|
||||||
|
{
|
||||||
|
info.setLastHealthTime(Minecraft.getSystemTime());
|
||||||
|
info.setHealthBlinkTime((long)(this.guiIngame.getUpdateCounter() + 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Minecraft.getSystemTime() - info.getLastHealthTime() > 1000L || this.lastTimeOpened != info.getRenderVisibilityId())
|
||||||
|
{
|
||||||
|
info.setLastHealth(i);
|
||||||
|
info.setDisplayHealth(i);
|
||||||
|
info.setLastHealthTime(Minecraft.getSystemTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
info.setRenderVisibilityId(this.lastTimeOpened);
|
||||||
|
info.setLastHealth(i);
|
||||||
|
int j = MathHelper.ceil((float)Math.max(i, info.getDisplayHealth()) / 2.0F);
|
||||||
|
int k = Math.max(MathHelper.ceil((float)(i / 2)), Math.max(MathHelper.ceil((float)(info.getDisplayHealth() / 2)), 10));
|
||||||
|
boolean flag = info.getHealthBlinkTime() > (long)this.guiIngame.getUpdateCounter() && (info.getHealthBlinkTime() - (long)this.guiIngame.getUpdateCounter()) / 3L % 2L == 1L;
|
||||||
|
|
||||||
|
if (j > 0)
|
||||||
|
{
|
||||||
|
float f = Math.min((float)(p_175247_5_ - p_175247_4_ - 4) / (float)k, 9.0F);
|
||||||
|
|
||||||
|
if (f > 3.0F)
|
||||||
|
{
|
||||||
|
for (int l = j; l < k; ++l)
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)l * f, (float)p_175247_2_, flag ? 25 : 16, 0, 9, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j1 = 0; j1 < j; ++j1)
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, flag ? 25 : 16, 0, 9, 9);
|
||||||
|
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
if (j1 * 2 + 1 < info.getDisplayHealth())
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, 70, 0, 9, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j1 * 2 + 1 == info.getDisplayHealth())
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, 79, 0, 9, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j1 * 2 + 1 < i)
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, j1 >= 10 ? 160 : 52, 0, 9, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j1 * 2 + 1 == i)
|
||||||
|
{
|
||||||
|
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, j1 >= 10 ? 169 : 61, 0, 9, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float f1 = MathHelper.clamp((float)i / 20.0F, 0.0F, 1.0F);
|
||||||
|
int i1 = (int)((1.0F - f1) * 255.0F) << 16 | (int)(f1 * 255.0F) << 8;
|
||||||
|
String s = "" + (float)i / 2.0F;
|
||||||
|
|
||||||
|
if (p_175247_5_ - this.mc.fontRenderer.getStringWidth(s + "hp") >= p_175247_4_)
|
||||||
|
{
|
||||||
|
s = s + "hp";
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s, (float)((p_175247_5_ + p_175247_4_) / 2 - this.mc.fontRenderer.getStringWidth(s) / 2), (float)p_175247_2_, i1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String s1 = TextFormatting.YELLOW + "" + i;
|
||||||
|
this.mc.fontRenderer.drawStringWithShadow(s1, (float)(p_175247_5_ - this.mc.fontRenderer.getStringWidth(s1)), (float)p_175247_2_, 16777215);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFooter(@Nullable ITextComponent footerIn)
|
||||||
|
{
|
||||||
|
this.footer = footerIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeader(@Nullable ITextComponent headerIn)
|
||||||
|
{
|
||||||
|
this.header = headerIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetFooterHeader()
|
||||||
|
{
|
||||||
|
this.header = null;
|
||||||
|
this.footer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
static class PlayerComparator implements Comparator<NetworkPlayerInfo>
|
||||||
|
{
|
||||||
|
private PlayerComparator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compare(NetworkPlayerInfo p_compare_1_, NetworkPlayerInfo p_compare_2_)
|
||||||
|
{
|
||||||
|
ScorePlayerTeam scoreplayerteam = p_compare_1_.getPlayerTeam();
|
||||||
|
ScorePlayerTeam scoreplayerteam1 = p_compare_2_.getPlayerTeam();
|
||||||
|
return ComparisonChain.start().compareTrueFirst(p_compare_1_.getGameType() != GameType.SPECTATOR, p_compare_2_.getGameType() != GameType.SPECTATOR).compare(scoreplayerteam != null ? scoreplayerteam.getName() : "", scoreplayerteam1 != null ? scoreplayerteam1.getName() : "").compare(p_compare_1_.getGameProfile().getName(), p_compare_2_.getGameProfile().getName()).result();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package net.minecraft.client.gui.spectator;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||||
|
import net.minecraft.client.gui.Gui;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.network.play.client.CPacketSpectate;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class PlayerMenuObject implements ISpectatorMenuObject
|
||||||
|
{
|
||||||
|
private final GameProfile profile;
|
||||||
|
private final ResourceLocation resourceLocation;
|
||||||
|
|
||||||
|
public PlayerMenuObject(GameProfile profileIn)
|
||||||
|
{
|
||||||
|
this.profile = profileIn;
|
||||||
|
/*
|
||||||
|
this.resourceLocation = AbstractClientPlayer.getLocationSkin(profileIn.getName());
|
||||||
|
AbstractClientPlayer.getDownloadImageSkin(this.resourceLocation, profileIn.getName());
|
||||||
|
*/
|
||||||
|
this.resourceLocation = customskinloader.fake.FakeClientPlayer.getLocationSkin(profileIn.getName());
|
||||||
|
customskinloader.fake.FakeClientPlayer.getDownloadImageSkin(this.resourceLocation, profileIn.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectItem(SpectatorMenu menu)
|
||||||
|
{
|
||||||
|
Minecraft.getMinecraft().getConnection().sendPacket(new CPacketSpectate(this.profile.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITextComponent getSpectatorName()
|
||||||
|
{
|
||||||
|
return new TextComponentString(this.profile.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renderIcon(float brightness, int alpha)
|
||||||
|
{
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(this.resourceLocation);
|
||||||
|
GlStateManager.color(1.0F, 1.0F, 1.0F, (float)alpha / 255.0F);
|
||||||
|
Gui.drawScaledCustomSizeModalRect(2, 2, 8.0F, 8.0F, 8, 8, 12, 12, 64.0F, 64.0F);
|
||||||
|
Gui.drawScaledCustomSizeModalRect(2, 2, 40.0F, 8.0F, 8, 8, 12, 12, 64.0F, 64.0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,7 +71,7 @@ public class SkinManager
|
|||||||
*/
|
*/
|
||||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, @Nullable final SkinManager.SkinAvailableCallback skinAvailableCallback)
|
||||||
{
|
{
|
||||||
return this.fakeManager.loadSkin(profileTexture, textureType, skinAvailableCallback);
|
return this.fakeManager.loadSkin(profileTexture, textureType, skinAvailableCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure)
|
public void loadProfileTextures(final GameProfile profile, final SkinManager.SkinAvailableCallback skinAvailableCallback, final boolean requireSecure)
|
||||||
|
|||||||
@@ -21,148 +21,157 @@ 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 (C) Jeremy Lam [JLChnToZ] 2013 & Alexander Xia [xfl03] 2014-2018
|
||||||
* @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 File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader"),
|
public static final File DATA_DIR=new File(MinecraftUtil.getMinecraftDataDir(),"CustomSkinLoader"),
|
||||||
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
|
LOG_FILE=new File(DATA_DIR,"CustomSkinLoader.log"),
|
||||||
CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json");
|
CONFIG_FILE=new File(DATA_DIR,"CustomSkinLoader.json");
|
||||||
public static final SkinSiteProfile[] DEFAULT_LOAD_LIST={
|
public static final SkinSiteProfile[] DEFAULT_LOAD_LIST={
|
||||||
SkinSiteProfile.createMojangAPI("Mojang"),
|
SkinSiteProfile.createMojangAPI("Mojang"),
|
||||||
SkinSiteProfile.createCustomSkinAPI("LittleSkin","https://mcskin.littleservice.cn/"),
|
SkinSiteProfile.createCustomSkinAPI("LittleSkin","https://mcskin.littleservice.cn/"),
|
||||||
SkinSiteProfile.createCustomSkinAPI("BlessingSkin","http://skin.prinzeugen.net/"),
|
SkinSiteProfile.createCustomSkinAPI("BlessingSkin","http://skin.prinzeugen.net/"),
|
||||||
//OneSkin has been removed temporarily
|
//OneSkin has been removed temporarily
|
||||||
//SkinSiteProfile.createCustomSkinAPI("OneSkin","http://fleey.cn/skin/skin_user/skin_json.php/"),
|
//SkinSiteProfile.createCustomSkinAPI("OneSkin","http://fleey.cn/skin/skin_user/skin_json.php/"),
|
||||||
//Minecrack could not load skin correctly
|
//Minecrack could not load skin correctly
|
||||||
//SkinSiteProfile.creatLegacy("Minecrack","http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png","http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png",null),
|
//SkinSiteProfile.creatLegacy("Minecrack","http://minecrack.fr.nf/mc/skinsminecrackd/{USERNAME}.png","http://minecrack.fr.nf/mc/cloaksminecrackd/{USERNAME}.png",null),
|
||||||
SkinSiteProfile.createUniSkinAPI("SkinMe","http://www.skinme.cc/uniskin/"),
|
SkinSiteProfile.createUniSkinAPI("SkinMe","http://www.skinme.cc/uniskin/"),
|
||||||
SkinSiteProfile.createLegacy("LocalSkin","LocalSkin/skins/{USERNAME}.png","LocalSkin/capes/{USERNAME}.png","LocalSkin/elytras/{USERNAME}.png")};
|
SkinSiteProfile.createLegacy("LocalSkin","LocalSkin/skins/{USERNAME}.png","LocalSkin/capes/{USERNAME}.png","LocalSkin/elytras/{USERNAME}.png")};
|
||||||
|
|
||||||
public static final Gson GSON=new GsonBuilder().setPrettyPrinting().create();
|
public static final Gson GSON=new GsonBuilder().setPrettyPrinting().create();
|
||||||
public static final Logger logger=initLogger();
|
public static final Logger logger=initLogger();
|
||||||
public static final Config config=Config.loadConfig0();
|
public static final Config config=Config.loadConfig0();
|
||||||
|
|
||||||
private static final ProfileCache profileCache=new ProfileCache();
|
private static final ProfileCache profileCache=new ProfileCache();
|
||||||
private static final DynamicSkullManager dynamicSkullManager=new DynamicSkullManager();
|
private static final DynamicSkullManager dynamicSkullManager=new DynamicSkullManager();
|
||||||
|
|
||||||
//For User Skin
|
//For User Skin
|
||||||
public static Map loadProfile(GameProfile gameProfile){
|
public static Map loadProfile(GameProfile gameProfile){
|
||||||
String username=gameProfile.getName();
|
String username=gameProfile.getName();
|
||||||
//Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713
|
String credential=MinecraftUtil.getCredential(gameProfile);
|
||||||
if(username==null){
|
//Fix: http://hopper.minecraft.net/crashes/minecraft/MCX-2773713
|
||||||
logger.warning("Could not load profile: username is null.");
|
if(username==null){
|
||||||
return Maps.newHashMap();
|
logger.warning("Could not load profile: username is null.");
|
||||||
}
|
return Maps.newHashMap();
|
||||||
String tempName=Thread.currentThread().getName();
|
}
|
||||||
Thread.currentThread().setName(username);//Change Thread Name
|
String tempName=Thread.currentThread().getName();
|
||||||
UserProfile profile=null;
|
Thread.currentThread().setName(username);//Change Thread Name
|
||||||
if(profileCache.isReady(username)){
|
UserProfile profile=null;
|
||||||
logger.info("Cached profile will be used.");
|
if(profileCache.isReady(credential)){
|
||||||
profile=profileCache.getProfile(username);
|
logger.info("Cached profile will be used.");
|
||||||
if(profile==null){
|
profile=profileCache.getProfile(credential);
|
||||||
logger.warning("(!Cached Profile is empty!) Expiry:"+profileCache.getExpiry(username));
|
if(profile==null){
|
||||||
if(profileCache.isExpired(username))//force load
|
logger.warning("(!Cached Profile is empty!) Expiry:"+profileCache.getExpiry(credential));
|
||||||
profile=loadProfile0(gameProfile);
|
if(profileCache.isExpired(credential))//force load
|
||||||
}
|
profile=loadProfile0(gameProfile);
|
||||||
else
|
}
|
||||||
logger.info(profile.toString(profileCache.getExpiry(username)));
|
else
|
||||||
}else{
|
logger.info(profile.toString(profileCache.getExpiry(credential)));
|
||||||
profileCache.setLoading(username, true);
|
}else{
|
||||||
profile=loadProfile0(gameProfile);
|
profileCache.setLoading(credential, true);
|
||||||
}
|
profile=loadProfile0(gameProfile);
|
||||||
Thread.currentThread().setName(tempName);
|
}
|
||||||
return ModelManager0.fromUserProfile(profile);
|
Thread.currentThread().setName(tempName);
|
||||||
}
|
return ModelManager0.fromUserProfile(profile);
|
||||||
//Core
|
}
|
||||||
public static UserProfile loadProfile0(GameProfile gameProfile){
|
//Core
|
||||||
String username=gameProfile.getName();
|
public static UserProfile loadProfile0(GameProfile gameProfile){
|
||||||
profileCache.setLoading(username, true);
|
String username=gameProfile.getName();
|
||||||
logger.info("Loading "+username+"'s profile.");
|
String credential=MinecraftUtil.getCredential(gameProfile);
|
||||||
if(config.loadlist==null||config.loadlist.isEmpty()){
|
|
||||||
logger.info("LoadList is Empty.");
|
profileCache.setLoading(credential, true);
|
||||||
return null;
|
logger.info("Loading "+username+"'s profile.");
|
||||||
}
|
if(config.loadlist==null||config.loadlist.isEmpty()){
|
||||||
|
logger.info("LoadList is Empty.");
|
||||||
UserProfile profile0=new UserProfile();
|
return null;
|
||||||
for(int i=0;i<config.loadlist.size();i++){
|
}
|
||||||
SkinSiteProfile ssp=config.loadlist.get(i);
|
|
||||||
logger.info((i+1)+"/"+config.loadlist.size()+" Try to load profile from '"+ssp.name+"'.");
|
UserProfile profile0=new UserProfile();
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
for(int i=0;i<config.loadlist.size();i++){
|
||||||
if(loader==null){
|
SkinSiteProfile ssp=config.loadlist.get(i);
|
||||||
logger.info("Type '"+ssp.type+"' is not defined.");
|
logger.info((i+1)+"/"+config.loadlist.size()+" Try to load profile from '"+ssp.name+"'.");
|
||||||
continue;
|
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
}
|
if(loader==null){
|
||||||
UserProfile profile=null;
|
logger.info("Type '"+ssp.type+"' is not defined.");
|
||||||
try{
|
continue;
|
||||||
profile=loader.loadProfile(ssp, gameProfile);
|
}
|
||||||
}catch(Exception e){
|
UserProfile profile=null;
|
||||||
logger.warning("Exception occurs while loading.");
|
try{
|
||||||
logger.warning(e);
|
profile=loader.loadProfile(ssp, gameProfile);
|
||||||
}
|
}catch(Exception e){
|
||||||
if(profile==null)
|
logger.warning("Exception occurs while loading.");
|
||||||
continue;
|
logger.warning(e);
|
||||||
if(!config.forceLoadAllTextures){
|
if(e.getCause()!=null) {
|
||||||
profile0=profile;
|
logger.warning("Caused By:");
|
||||||
break;
|
logger.warning(e.getCause());
|
||||||
}
|
}
|
||||||
profile0.mix(profile);
|
}
|
||||||
if(profile0.isFull())
|
if(profile==null)
|
||||||
break;
|
continue;
|
||||||
}
|
if(!config.forceLoadAllTextures){
|
||||||
if(!profile0.isEmpty()){
|
profile0=profile;
|
||||||
logger.info(username+"'s profile loaded.");
|
break;
|
||||||
profileCache.updateCache(username, profile0);
|
}
|
||||||
profileCache.setLoading(username, false);
|
profile0.mix(profile);
|
||||||
logger.info(profile0.toString(profileCache.getExpiry(username)));
|
if(profile0.isFull())
|
||||||
return profile0;
|
break;
|
||||||
}
|
}
|
||||||
logger.info(username+"'s profile not found in load list.");
|
if(!profile0.isEmpty()){
|
||||||
|
logger.info(username+"'s profile loaded.");
|
||||||
if(config.enableLocalProfileCache){
|
profileCache.updateCache(credential, profile0);
|
||||||
UserProfile profile=profileCache.getLocalProfile(username);
|
profileCache.setLoading(credential, false);
|
||||||
if(profile==null)
|
logger.info(profile0.toString(profileCache.getExpiry(credential)));
|
||||||
logger.info(username+"'s LocalProfile not found.");
|
return profile0;
|
||||||
else{
|
}
|
||||||
profileCache.updateCache(username, profile, false);
|
logger.info(username+"'s profile not found in load list.");
|
||||||
profileCache.setLoading(username, false);
|
|
||||||
logger.info(username+"'s LocalProfile will be used.");
|
if(config.enableLocalProfileCache){
|
||||||
logger.info(profile.toString(profileCache.getExpiry(username)));
|
UserProfile profile=profileCache.getLocalProfile(credential);
|
||||||
return profile;
|
if(profile==null)
|
||||||
}
|
logger.info(username+"'s LocalProfile not found.");
|
||||||
}
|
else{
|
||||||
profileCache.setLoading(username, false);
|
profileCache.updateCache(credential, profile, false);
|
||||||
return null;
|
profileCache.setLoading(credential, false);
|
||||||
}
|
logger.info(username+"'s LocalProfile will be used.");
|
||||||
|
logger.info(profile.toString(profileCache.getExpiry(credential)));
|
||||||
//For Skull
|
return profile;
|
||||||
public static Map<Type, MinecraftProfileTexture> loadProfileFromCache(final GameProfile gameProfile) {
|
}
|
||||||
String username=gameProfile.getName();
|
}
|
||||||
if(username==null)
|
profileCache.setLoading(credential, false);
|
||||||
return dynamicSkullManager.getTexture(gameProfile);
|
return null;
|
||||||
if(config.enableUpdateSkull?profileCache.isReady(username):profileCache.isExist(username)){
|
}
|
||||||
UserProfile profile=profileCache.getProfile(username);
|
|
||||||
return ModelManager0.fromUserProfile(profile);
|
//For Skull
|
||||||
}
|
public static Map<Type, MinecraftProfileTexture> loadProfileFromCache(final GameProfile gameProfile) {
|
||||||
//profileCache.setLoading(username, true);
|
String username=gameProfile.getName();
|
||||||
Thread loadThread=new Thread(){
|
String credential=MinecraftUtil.getCredential(gameProfile);
|
||||||
public void run(){
|
|
||||||
loadProfile0(gameProfile);//Load in thread
|
if(credential==null)
|
||||||
}
|
return dynamicSkullManager.getTexture(gameProfile);
|
||||||
};
|
if(config.enableUpdateSkull?profileCache.isReady(credential):profileCache.isExist(credential)){
|
||||||
loadThread.setName(username+"'s skull");
|
UserProfile profile=profileCache.getProfile(credential);
|
||||||
loadThread.start();
|
return ModelManager0.fromUserProfile(profile);
|
||||||
return Maps.newHashMap();
|
}
|
||||||
}
|
//profileCache.setLoading(username, true);
|
||||||
|
Thread loadThread=new Thread(){
|
||||||
private static Logger initLogger() {
|
public void run(){
|
||||||
Logger logger=new Logger(LOG_FILE);
|
loadProfile0(gameProfile);//Load in thread
|
||||||
logger.info("CustomSkinLoader "+CustomSkinLoader_FULL_VERSION);
|
}
|
||||||
logger.info("DataDir: "+DATA_DIR.getAbsolutePath());
|
};
|
||||||
logger.info("Minecraft: "+MinecraftUtil.getMinecraftMainVersion()+"("+MinecraftUtil.getMinecraftVersionText()+")");
|
loadThread.setName(username+"'s skull");
|
||||||
return logger;
|
loadThread.start();
|
||||||
}
|
return Maps.newHashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger initLogger() {
|
||||||
|
Logger logger=new Logger(LOG_FILE);
|
||||||
|
logger.info("CustomSkinLoader "+CustomSkinLoader_FULL_VERSION);
|
||||||
|
logger.info("DataDir: "+DATA_DIR.getAbsolutePath());
|
||||||
|
logger.info("Minecraft: "+MinecraftUtil.getMinecraftMainVersion()+"("+MinecraftUtil.getMinecraftVersionText()+")");
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,88 +8,88 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Logger {
|
public class Logger {
|
||||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
public enum Level{
|
public enum Level{
|
||||||
DEBUG("DEBUG",false),
|
DEBUG("DEBUG",false),
|
||||||
INFO("INFO",true),
|
INFO("INFO",true),
|
||||||
WARNING("WARNING",true);
|
WARNING("WARNING",true);
|
||||||
|
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
boolean display;
|
boolean display;
|
||||||
Level(String name,boolean display){
|
Level(String name,boolean display){
|
||||||
this.name=name;
|
this.name=name;
|
||||||
this.display=display;
|
this.display=display;
|
||||||
}
|
}
|
||||||
public String getName(){
|
public String getName(){
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
public boolean display(){
|
public boolean display(){
|
||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private BufferedWriter writer=null;
|
private BufferedWriter writer=null;
|
||||||
public Logger(){
|
public Logger(){
|
||||||
//Logger isn't created.
|
//Logger isn't created.
|
||||||
}
|
}
|
||||||
public Logger(File logFile){
|
public Logger(File logFile){
|
||||||
try {
|
try {
|
||||||
if(!logFile.getParentFile().exists()){
|
if(!logFile.getParentFile().exists()){
|
||||||
logFile.getParentFile().mkdirs();
|
logFile.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
if(!logFile.exists())
|
if(!logFile.exists())
|
||||||
logFile.createNewFile();
|
logFile.createNewFile();
|
||||||
|
|
||||||
writer = new BufferedWriter(new OutputStreamWriter(
|
writer = new BufferedWriter(new OutputStreamWriter(
|
||||||
new FileOutputStream(logFile), "UTF-8"));
|
new FileOutputStream(logFile), "UTF-8"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void close(){
|
public void close(){
|
||||||
if(writer!=null){
|
if(writer!=null){
|
||||||
try {
|
try {
|
||||||
writer.close();
|
writer.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(Level level,String msg){
|
public void log(Level level,String msg){
|
||||||
if(!level.display()&&writer==null)
|
if(!level.display()&&writer==null)
|
||||||
return;
|
return;
|
||||||
StringBuilder sb=new StringBuilder();
|
StringBuilder sb=new StringBuilder();
|
||||||
sb.append("[").append(Thread.currentThread().getName()).append(" ").append(level.getName()).append("] ");
|
sb.append("[").append(Thread.currentThread().getName()).append(" ").append(level.getName()).append("] ");
|
||||||
sb.append(msg);
|
sb.append(msg);
|
||||||
if(level.display())
|
if(level.display())
|
||||||
System.out.println(sb.toString());
|
System.out.println(sb.toString());
|
||||||
if(writer==null)
|
if(writer==null)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
StringBuilder sb2=new StringBuilder();
|
StringBuilder sb2=new StringBuilder();
|
||||||
sb2.append("[").append(DATE_FORMAT.format(new Date())).append("] ");
|
sb2.append("[").append(DATE_FORMAT.format(new Date())).append("] ");
|
||||||
sb2.append(sb.toString()).append("\r\n");
|
sb2.append(sb.toString()).append("\r\n");
|
||||||
writer.write(sb2.toString());
|
writer.write(sb2.toString());
|
||||||
writer.flush();
|
writer.flush();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void debug(String msg){
|
public void debug(String msg){
|
||||||
log(Level.DEBUG,msg);
|
log(Level.DEBUG,msg);
|
||||||
}
|
}
|
||||||
public void info(String msg){
|
public void info(String msg){
|
||||||
log(Level.INFO,msg);
|
log(Level.INFO,msg);
|
||||||
}
|
}
|
||||||
public void warning(String msg){
|
public void warning(String msg){
|
||||||
log(Level.WARNING,msg);
|
log(Level.WARNING,msg);
|
||||||
}
|
}
|
||||||
public void warning(Exception e){
|
public void warning(Throwable e){
|
||||||
log(Level.WARNING,"Exception: "+e.toString());
|
log(Level.WARNING,"Exception: "+e.toString());
|
||||||
StackTraceElement[] stes=e.getStackTrace();
|
StackTraceElement[] stes=e.getStackTrace();
|
||||||
for(StackTraceElement ste : stes){
|
for(StackTraceElement ste : stes){
|
||||||
log(Level.WARNING,ste.toString());
|
log(Level.WARNING,ste.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,181 +15,181 @@ import customskinloader.utils.HttpTextureUtil;
|
|||||||
import customskinloader.utils.HttpUtil0;
|
import customskinloader.utils.HttpUtil0;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
//Program
|
//Program
|
||||||
public String version;
|
public String version;
|
||||||
public List<SkinSiteProfile> loadlist;
|
public List<SkinSiteProfile> loadlist;
|
||||||
|
|
||||||
//Function
|
//Function
|
||||||
public boolean enableDynamicSkull=true;
|
public boolean enableDynamicSkull=true;
|
||||||
public boolean enableTransparentSkin=true;
|
public boolean enableTransparentSkin=true;
|
||||||
public boolean ignoreHttpsCertificate=false;
|
public boolean ignoreHttpsCertificate=false;
|
||||||
public boolean forceLoadAllTextures=false;
|
public boolean forceLoadAllTextures=false;
|
||||||
|
|
||||||
//Cache
|
//Cache
|
||||||
public int cacheExpiry=10;
|
public int cacheExpiry=20;
|
||||||
public boolean enableUpdateSkull=false;
|
public boolean enableUpdateSkull=false;
|
||||||
public boolean enableLocalProfileCache=false;
|
public boolean enableLocalProfileCache=false;
|
||||||
public boolean enableCacheAutoClean=false;
|
public boolean enableCacheAutoClean=false;
|
||||||
|
|
||||||
|
|
||||||
//Init config
|
//Init config
|
||||||
public Config(SkinSiteProfile[] loadlist){
|
public Config(SkinSiteProfile[] loadlist){
|
||||||
this.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
this.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||||
this.loadlist=Arrays.asList(loadlist);
|
this.loadlist=Arrays.asList(loadlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Config loadConfig0() {
|
public static Config loadConfig0() {
|
||||||
Config config=loadConfig();
|
Config config=loadConfig();
|
||||||
|
|
||||||
//LoadList null checker
|
//LoadList null checker
|
||||||
if(config.loadlist==null){
|
if(config.loadlist==null){
|
||||||
config.loadlist=new ArrayList<SkinSiteProfile>();
|
config.loadlist=new ArrayList<SkinSiteProfile>();
|
||||||
}else{
|
}else{
|
||||||
for(int i=0;i<config.loadlist.size();i++){
|
for(int i=0;i<config.loadlist.size();i++){
|
||||||
if(config.loadlist.get(i)==null)
|
if(config.loadlist.get(i)==null)
|
||||||
config.loadlist.remove(i--);
|
config.loadlist.remove(i--);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Init program
|
//Init program
|
||||||
config.loadExtraList();
|
config.loadExtraList();
|
||||||
config.initLocalFolder();
|
config.initLocalFolder();
|
||||||
if(config.ignoreHttpsCertificate)
|
if(config.ignoreHttpsCertificate)
|
||||||
HttpUtil0.ignoreHttpsCertificate();
|
HttpUtil0.ignoreHttpsCertificate();
|
||||||
if(config.enableCacheAutoClean && !config.enableLocalProfileCache){
|
if(config.enableCacheAutoClean && !config.enableLocalProfileCache){
|
||||||
try{
|
try{
|
||||||
FileUtils.deleteDirectory(HttpRequestUtil.CACHE_DIR);
|
FileUtils.deleteDirectory(HttpRequestUtil.CACHE_DIR);
|
||||||
FileUtils.deleteDirectory(HttpTextureUtil.getCacheDir());
|
FileUtils.deleteDirectory(HttpTextureUtil.getCacheDir());
|
||||||
CustomSkinLoader.logger.info("Successfully cleaned cache.");
|
CustomSkinLoader.logger.info("Successfully cleaned cache.");
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
CustomSkinLoader.logger.warning("Exception occurs while cleaning cache: "+e.toString());
|
CustomSkinLoader.logger.warning("Exception occurs while cleaning cache: "+e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Output config
|
//Output config
|
||||||
CustomSkinLoader.logger.info("EnableDynamicSkull:"+config.enableDynamicSkull+
|
CustomSkinLoader.logger.info("EnableDynamicSkull:"+config.enableDynamicSkull+
|
||||||
", EnableTranSkin:"+config.enableTransparentSkin+
|
", EnableTranSkin:"+config.enableTransparentSkin+
|
||||||
", IgnoreHttpsCertificate:"+config.ignoreHttpsCertificate+
|
", IgnoreHttpsCertificate:"+config.ignoreHttpsCertificate+
|
||||||
", CacheExpiry:"+config.cacheExpiry+
|
", CacheExpiry:"+config.cacheExpiry+
|
||||||
", EnableUpdateSkull:"+config.enableUpdateSkull+
|
", EnableUpdateSkull:"+config.enableUpdateSkull+
|
||||||
", EnableLocalProfileCache:"+config.enableLocalProfileCache+
|
", EnableLocalProfileCache:"+config.enableLocalProfileCache+
|
||||||
", EnableCacheAutoClean:"+config.enableCacheAutoClean+
|
", EnableCacheAutoClean:"+config.enableCacheAutoClean+
|
||||||
", LoadList:"+(config.loadlist==null?0:config.loadlist.size()));
|
", LoadList:"+(config.loadlist==null?0:config.loadlist.size()));
|
||||||
|
|
||||||
//Check config version
|
//Check config version
|
||||||
float floatVersion=0f;
|
float floatVersion=0f;
|
||||||
float configVersion=0f;
|
float configVersion=0f;
|
||||||
try{
|
try{
|
||||||
floatVersion=Float.parseFloat(CustomSkinLoader.CustomSkinLoader_VERSION);
|
floatVersion=Float.parseFloat(CustomSkinLoader.CustomSkinLoader_VERSION);
|
||||||
configVersion=Float.parseFloat(config.version);
|
configVersion=Float.parseFloat(config.version);
|
||||||
if(configVersion==15.1f)//To avoid some bug
|
if(configVersion==15.1f)//To avoid some bug
|
||||||
configVersion=14.6f;
|
configVersion=14.6f;
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
CustomSkinLoader.logger.warning("Exception occurs while parsing version: "+e.toString());
|
CustomSkinLoader.logger.warning("Exception occurs while parsing version: "+e.toString());
|
||||||
}
|
}
|
||||||
if(config.version==null || configVersion==0f || floatVersion > configVersion){
|
if(config.version==null || configVersion==0f || floatVersion > configVersion){
|
||||||
CustomSkinLoader.logger.info("Config File is out of date: "+config.version);
|
CustomSkinLoader.logger.info("Config File is out of date: "+config.version);
|
||||||
config.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
config.version=CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||||
writeConfig(config,true);
|
writeConfig(config,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Config loadConfig() {
|
private static Config loadConfig() {
|
||||||
CustomSkinLoader.logger.info("Config File: "+CustomSkinLoader.CONFIG_FILE.getAbsolutePath());
|
CustomSkinLoader.logger.info("Config File: "+CustomSkinLoader.CONFIG_FILE.getAbsolutePath());
|
||||||
if(!CustomSkinLoader.CONFIG_FILE.exists()){
|
if(!CustomSkinLoader.CONFIG_FILE.exists()){
|
||||||
CustomSkinLoader.logger.info("Config file not found, use default instead.");
|
CustomSkinLoader.logger.info("Config file not found, use default instead.");
|
||||||
return initConfig();
|
return initConfig();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
CustomSkinLoader.logger.info("Try to load config.");
|
CustomSkinLoader.logger.info("Try to load config.");
|
||||||
String json=FileUtils.readFileToString(CustomSkinLoader.CONFIG_FILE,Charsets.UTF_8);
|
String json=FileUtils.readFileToString(CustomSkinLoader.CONFIG_FILE,Charsets.UTF_8);
|
||||||
Config config=CustomSkinLoader.GSON.fromJson(json, Config.class);
|
Config config=CustomSkinLoader.GSON.fromJson(json, Config.class);
|
||||||
CustomSkinLoader.logger.info("Successfully load config.");
|
CustomSkinLoader.logger.info("Successfully load config.");
|
||||||
return config;
|
return config;
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
CustomSkinLoader.logger.info("Failed to load config, use default instead.("+e.toString()+")");
|
CustomSkinLoader.logger.info("Failed to load config, use default instead.("+e.toString()+")");
|
||||||
File brokenFile=new File(CustomSkinLoader.DATA_DIR,"BROKEN-CustomSkinLoader.json");
|
File brokenFile=new File(CustomSkinLoader.DATA_DIR,"BROKEN-CustomSkinLoader.json");
|
||||||
if(brokenFile.exists())
|
if(brokenFile.exists())
|
||||||
brokenFile.delete();
|
brokenFile.delete();
|
||||||
CustomSkinLoader.CONFIG_FILE.renameTo(brokenFile);
|
CustomSkinLoader.CONFIG_FILE.renameTo(brokenFile);
|
||||||
return initConfig();
|
return initConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadExtraList(){
|
private void loadExtraList(){
|
||||||
File listAddition=new File(CustomSkinLoader.DATA_DIR,"ExtraList");
|
File listAddition=new File(CustomSkinLoader.DATA_DIR,"ExtraList");
|
||||||
if(!listAddition.isDirectory()){
|
if(!listAddition.isDirectory()){
|
||||||
listAddition.mkdirs();
|
listAddition.mkdirs();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<SkinSiteProfile> adds=new ArrayList<SkinSiteProfile>();
|
List<SkinSiteProfile> adds=new ArrayList<SkinSiteProfile>();
|
||||||
File[] files=listAddition.listFiles();
|
File[] files=listAddition.listFiles();
|
||||||
for(File file:files){
|
for(File file:files){
|
||||||
if(!file.getName().toLowerCase().endsWith(".json")&&!file.getName().toLowerCase().endsWith(".txt"))
|
if(!file.getName().toLowerCase().endsWith(".json")&&!file.getName().toLowerCase().endsWith(".txt"))
|
||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
CustomSkinLoader.logger.info("Try to load Extra List.("+file.getName()+")");
|
CustomSkinLoader.logger.info("Try to load Extra List.("+file.getName()+")");
|
||||||
String json=FileUtils.readFileToString(file,Charsets.UTF_8);
|
String json=FileUtils.readFileToString(file,Charsets.UTF_8);
|
||||||
SkinSiteProfile ssp=CustomSkinLoader.GSON.fromJson(json, SkinSiteProfile.class);
|
SkinSiteProfile ssp=CustomSkinLoader.GSON.fromJson(json, SkinSiteProfile.class);
|
||||||
CustomSkinLoader.logger.info("Successfully load Extra List.");
|
CustomSkinLoader.logger.info("Successfully load Extra List.");
|
||||||
file.delete();
|
file.delete();
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
if(loader==null){
|
if(loader==null){
|
||||||
CustomSkinLoader.logger.info("Extra List will be ignore: Type '"+ssp.type+"' is not defined.");
|
CustomSkinLoader.logger.info("Extra List will be ignore: Type '"+ssp.type+"' is not defined.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean duplicate=false;
|
boolean duplicate=false;
|
||||||
for(SkinSiteProfile ssp0:this.loadlist){
|
for(SkinSiteProfile ssp0:this.loadlist){
|
||||||
if(!ssp0.type.equalsIgnoreCase(ssp.type))
|
if(!ssp0.type.equalsIgnoreCase(ssp.type))
|
||||||
continue;
|
continue;
|
||||||
if(loader.compare(ssp0, ssp)){
|
if(loader.compare(ssp0, ssp)){
|
||||||
duplicate=true;
|
duplicate=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!duplicate){
|
if(!duplicate){
|
||||||
adds.add(ssp);
|
adds.add(ssp);
|
||||||
CustomSkinLoader.logger.info("Successfully apply Extra List.("+ssp.name+")");
|
CustomSkinLoader.logger.info("Successfully apply Extra List.("+ssp.name+")");
|
||||||
}else{
|
}else{
|
||||||
CustomSkinLoader.logger.info("Extra List will be ignore: Duplicate.("+ssp.name+")");
|
CustomSkinLoader.logger.info("Extra List will be ignore: Duplicate.("+ssp.name+")");
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
CustomSkinLoader.logger.info("Failed to load Extra List.("+e.toString()+")");
|
CustomSkinLoader.logger.info("Failed to load Extra List.("+e.toString()+")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(adds.size()!=0){
|
if(adds.size()!=0){
|
||||||
adds.addAll(this.loadlist);
|
adds.addAll(this.loadlist);
|
||||||
this.loadlist=adds;
|
this.loadlist=adds;
|
||||||
writeConfig(this,true);
|
writeConfig(this,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initLocalFolder(){
|
private void initLocalFolder(){
|
||||||
for(SkinSiteProfile ssp:this.loadlist){
|
for(SkinSiteProfile ssp:this.loadlist){
|
||||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||||
if(loader==null)
|
if(loader==null)
|
||||||
continue;
|
continue;
|
||||||
loader.initLocalFolder(ssp);
|
loader.initLocalFolder(ssp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Config initConfig() {
|
private static Config initConfig() {
|
||||||
Config config=new Config(CustomSkinLoader.DEFAULT_LOAD_LIST);
|
Config config=new Config(CustomSkinLoader.DEFAULT_LOAD_LIST);
|
||||||
writeConfig(config,false);
|
writeConfig(config,false);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
private static void writeConfig(Config config,boolean update){
|
private static void writeConfig(Config config,boolean update){
|
||||||
String json=CustomSkinLoader.GSON.toJson(config);
|
String json=CustomSkinLoader.GSON.toJson(config);
|
||||||
if(CustomSkinLoader.CONFIG_FILE.exists())
|
if(CustomSkinLoader.CONFIG_FILE.exists())
|
||||||
CustomSkinLoader.CONFIG_FILE.delete();
|
CustomSkinLoader.CONFIG_FILE.delete();
|
||||||
try {
|
try {
|
||||||
CustomSkinLoader.CONFIG_FILE.createNewFile();
|
CustomSkinLoader.CONFIG_FILE.createNewFile();
|
||||||
FileUtils.write(CustomSkinLoader.CONFIG_FILE, json, Charsets.UTF_8);
|
FileUtils.write(CustomSkinLoader.CONFIG_FILE, json, Charsets.UTF_8);
|
||||||
CustomSkinLoader.logger.info("Successfully "+(update?"update":"create")+" config.");
|
CustomSkinLoader.logger.info("Successfully "+(update?"update":"create")+" config.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CustomSkinLoader.logger.info("Failed to "+(update?"update":"create")+" config.("+e.toString()+")");
|
CustomSkinLoader.logger.info("Failed to "+(update?"update":"create")+" config.("+e.toString()+")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,62 +3,62 @@ package customskinloader.config;
|
|||||||
import customskinloader.loader.jsonapi.CustomSkinAPIPlus.CustomSkinAPIPlusPrivacy;
|
import customskinloader.loader.jsonapi.CustomSkinAPIPlus.CustomSkinAPIPlusPrivacy;
|
||||||
|
|
||||||
public class SkinSiteProfile {
|
public class SkinSiteProfile {
|
||||||
public String name;
|
public String name;
|
||||||
public String type;
|
public String type;
|
||||||
public String userAgent;
|
public String userAgent;
|
||||||
|
|
||||||
public String root;
|
public String root;
|
||||||
public CustomSkinAPIPlusPrivacy privacy;
|
public CustomSkinAPIPlusPrivacy privacy;
|
||||||
|
|
||||||
public Boolean checkPNG;//Not suitable for local skin
|
public Boolean checkPNG;//Not suitable for local skin
|
||||||
public String skin;
|
public String skin;
|
||||||
public String model;
|
public String model;
|
||||||
public String cape;
|
public String cape;
|
||||||
public String elytra;
|
public String elytra;
|
||||||
|
|
||||||
public static SkinSiteProfile createMojangAPI(String name){
|
public static SkinSiteProfile createMojangAPI(String name){
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
SkinSiteProfile ssp=new SkinSiteProfile();
|
||||||
ssp.name=name;
|
ssp.name=name;
|
||||||
ssp.type="MojangAPI";
|
ssp.type="MojangAPI";
|
||||||
return ssp;
|
return ssp;
|
||||||
}
|
}
|
||||||
public static SkinSiteProfile createCustomSkinAPI(String name,String root){
|
public static SkinSiteProfile createCustomSkinAPI(String name,String root){
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
SkinSiteProfile ssp=new SkinSiteProfile();
|
||||||
ssp.name=name;
|
ssp.name=name;
|
||||||
ssp.type="CustomSkinAPI";
|
ssp.type="CustomSkinAPI";
|
||||||
ssp.root=root;
|
ssp.root=root;
|
||||||
return ssp;
|
return ssp;
|
||||||
}
|
}
|
||||||
public static SkinSiteProfile creatCustomSkinAPIPlus(String name,String root){
|
public static SkinSiteProfile creatCustomSkinAPIPlus(String name,String root){
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
SkinSiteProfile ssp=new SkinSiteProfile();
|
||||||
ssp.name=name;
|
ssp.name=name;
|
||||||
ssp.type="CustomSkinAPIPlus";
|
ssp.type="CustomSkinAPIPlus";
|
||||||
ssp.root=root;
|
ssp.root=root;
|
||||||
ssp.privacy=new CustomSkinAPIPlusPrivacy();
|
ssp.privacy=new CustomSkinAPIPlusPrivacy();
|
||||||
return ssp;
|
return ssp;
|
||||||
}
|
}
|
||||||
public static SkinSiteProfile createUniSkinAPI(String name,String root){
|
public static SkinSiteProfile createUniSkinAPI(String name,String root){
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
SkinSiteProfile ssp=new SkinSiteProfile();
|
||||||
ssp.name=name;
|
ssp.name=name;
|
||||||
ssp.type="UniSkinAPI";
|
ssp.type="UniSkinAPI";
|
||||||
ssp.root=root;
|
ssp.root=root;
|
||||||
return ssp;
|
return ssp;
|
||||||
}
|
}
|
||||||
public static SkinSiteProfile createLegacy(String name,String skin,String cape,String elytra){
|
public static SkinSiteProfile createLegacy(String name,String skin,String cape,String elytra){
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
SkinSiteProfile ssp=new SkinSiteProfile();
|
||||||
ssp.name=name;
|
ssp.name=name;
|
||||||
ssp.type="Legacy";
|
ssp.type="Legacy";
|
||||||
ssp.checkPNG=false;
|
ssp.checkPNG=false;
|
||||||
ssp.skin=skin;
|
ssp.skin=skin;
|
||||||
ssp.model="default";
|
ssp.model="default";
|
||||||
ssp.cape=cape;
|
ssp.cape=cape;
|
||||||
ssp.elytra=elytra;
|
ssp.elytra=elytra;
|
||||||
return ssp;
|
return ssp;
|
||||||
}
|
}
|
||||||
public static SkinSiteProfile createElfSkin(String name){
|
public static SkinSiteProfile createElfSkin(String name){
|
||||||
SkinSiteProfile ssp=new SkinSiteProfile();
|
SkinSiteProfile ssp=new SkinSiteProfile();
|
||||||
ssp.name=name;
|
ssp.name=name;
|
||||||
ssp.type="ElfSkin";
|
ssp.type="ElfSkin";
|
||||||
return ssp;
|
return ssp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package customskinloader.fake;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||||
|
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
||||||
|
|
||||||
|
import customskinloader.CustomSkinLoader;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
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.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.StringUtils;
|
||||||
|
|
||||||
|
public class FakeClientPlayer {
|
||||||
|
//For Legacy Skin
|
||||||
|
public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username)
|
||||||
|
{
|
||||||
|
//CustomSkinLoader.logger.debug("FakeClientPlayer/getDownloadImageSkin "+username);
|
||||||
|
TextureManager textman = Minecraft.getMinecraft().getTextureManager();
|
||||||
|
ITextureObject ito = textman.getTexture(resourceLocationIn);
|
||||||
|
|
||||||
|
if (ito == null || !(ito instanceof ThreadDownloadImageData))
|
||||||
|
{
|
||||||
|
//if Legacy Skin for username not loaded yet
|
||||||
|
SkinManager skinman = Minecraft.getMinecraft().getSkinManager();
|
||||||
|
UUID offlineUUID=EntityPlayer.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));
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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;
|
||||||
|
|
||||||
|
loaded=true;
|
||||||
|
|
||||||
|
|
||||||
|
TextureManager textman = Minecraft.getMinecraft().getTextureManager();
|
||||||
|
ITextureObject ito = textman.getTexture(location);
|
||||||
|
|
||||||
|
if(ito!=null)
|
||||||
|
textman.loadTexture(resourceLocationIn, ito);
|
||||||
|
CustomSkinLoader.logger.debug("Legacy Texture ("+resourceLocationIn+") Loaded as "+
|
||||||
|
ito==null?null:ito.toString()+" ("+location+")");
|
||||||
|
//textman.bindTexture(resourceLocationIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,110 +8,110 @@ import java.awt.image.ImageObserver;
|
|||||||
|
|
||||||
public class FakeSkinBuffer implements net.minecraft.client.renderer.IImageBuffer {
|
public class FakeSkinBuffer implements net.minecraft.client.renderer.IImageBuffer {
|
||||||
|
|
||||||
private int[] imageData;
|
private int[] imageData;
|
||||||
private int ratio=1;
|
private int ratio=1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BufferedImage parseUserSkin(BufferedImage image) {
|
public BufferedImage parseUserSkin(BufferedImage image) {
|
||||||
if(image==null)
|
if(image==null)
|
||||||
return null;
|
return null;
|
||||||
ratio = image.getWidth() / 64;
|
ratio = image.getWidth() / 64;
|
||||||
BufferedImage bufferedimage = new BufferedImage(64 * ratio, 64 * ratio, 2);
|
BufferedImage bufferedimage = new BufferedImage(64 * ratio, 64 * ratio, 2);
|
||||||
Graphics graphics = bufferedimage.getGraphics();
|
Graphics graphics = bufferedimage.getGraphics();
|
||||||
graphics.setColor(new Color(0,0,0,0));
|
graphics.setColor(new Color(0,0,0,0));
|
||||||
graphics.fillRect(0,0,64,64);
|
graphics.fillRect(0,0,64,64);
|
||||||
graphics.drawImage(image,0,0,(ImageObserver)null);
|
graphics.drawImage(image,0,0,(ImageObserver)null);
|
||||||
if (image.getHeight() == 32 * ratio){//Single Layer
|
if (image.getHeight() == 32 * ratio){//Single Layer
|
||||||
//Revert to original algorithm
|
//Revert to original algorithm
|
||||||
//Right Leg -> Left Leg
|
//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, 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, 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, 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, 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, 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
|
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
|
//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, 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, 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, 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, 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, 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.drawImage(bufferedimage, 48 * ratio, 52 * ratio, 44 * ratio, 64 * ratio, 52 * ratio, 20 * ratio, 56 * ratio, 32 * ratio, (ImageObserver)null);//Back
|
||||||
}
|
}
|
||||||
graphics.dispose();
|
graphics.dispose();
|
||||||
this.imageData = ((DataBufferInt)bufferedimage.getRaster().getDataBuffer()).getData();
|
this.imageData = ((DataBufferInt)bufferedimage.getRaster().getDataBuffer()).getData();
|
||||||
|
|
||||||
setAreaDueToConfig( 0 * ratio, 0 * ratio,32 * ratio,16 * ratio);//Head - 1
|
setAreaDueToConfig( 0 * ratio, 0 * ratio,32 * ratio,16 * ratio);//Head - 1
|
||||||
setAreaTransparent(32 * ratio, 0 * ratio,64 * ratio,16 * ratio);//Head - 2
|
setAreaTransparent(32 * ratio, 0 * ratio,64 * ratio,16 * ratio);//Head - 2
|
||||||
|
|
||||||
setAreaDueToConfig( 0 * ratio,16 * ratio,16 * ratio,32 * ratio);//Right Leg - 1
|
setAreaDueToConfig( 0 * ratio,16 * ratio,16 * ratio,32 * ratio);//Right Leg - 1
|
||||||
setAreaDueToConfig(16 * ratio,16 * ratio,40 * ratio,32 * ratio);//Body - 1
|
setAreaDueToConfig(16 * ratio,16 * ratio,40 * ratio,32 * ratio);//Body - 1
|
||||||
setAreaDueToConfig(40 * ratio,16 * ratio,56 * ratio,32 * ratio);//Right Arm - 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( 0 * ratio,32 * ratio,16 * ratio,48 * ratio);//Right Leg - 2
|
||||||
setAreaTransparent(16 * ratio,32 * ratio,40 * ratio,48 * ratio);//Body - 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(40 * ratio,32 * ratio,56 * ratio,48 * ratio);//Right Arm - 2
|
||||||
|
|
||||||
setAreaTransparent( 0 * ratio,48 * ratio,16 * ratio,64 * ratio);//Left Leg - 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(16 * ratio,48 * ratio,32 * ratio,64 * ratio);//Left Leg - 1
|
||||||
setAreaDueToConfig(32 * ratio,48 * ratio,48 * ratio,64 * ratio);//Left Arm - 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
|
setAreaTransparent(48 * ratio,48 * ratio,64 * ratio,64 * ratio);//Left Arm - 2
|
||||||
|
|
||||||
return bufferedimage;
|
return bufferedimage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 2^24-1
|
/* 2^24-1
|
||||||
* 00000000 11111111 11111111 11111111 */
|
* 00000000 11111111 11111111 11111111 */
|
||||||
private static final int A=16777215;
|
private static final int A=16777215;
|
||||||
private static final int WHITE=getARGB(255,255,255,255);
|
private static final int WHITE=getARGB(255,255,255,255);
|
||||||
private static final int BLACK=getARGB(255,0,0,0);
|
private static final int BLACK=getARGB(255,0,0,0);
|
||||||
private boolean isFilled(int x0,int y0,int x1,int y1){
|
private boolean isFilled(int x0,int y0,int x1,int y1){
|
||||||
int data=this.imageData[getPosition(x0,y0)];
|
int data=this.imageData[getPosition(x0,y0)];
|
||||||
if(data!=WHITE && data!=BLACK)
|
if(data!=WHITE && data!=BLACK)
|
||||||
return false;
|
return false;
|
||||||
for (int x=x0;x<x1;++x)
|
for (int x=x0;x<x1;++x)
|
||||||
for (int y=y0;y<y1;++y)
|
for (int y=y0;y<y1;++y)
|
||||||
if(this.imageData[getPosition(x,y)]!=data)
|
if(this.imageData[getPosition(x,y)]!=data)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private void setAreaTransparent(int x0,int y0,int x1,int y1){
|
private void setAreaTransparent(int x0,int y0,int x1,int y1){
|
||||||
if(!isFilled(x0,y0,x1,y1))
|
if(!isFilled(x0,y0,x1,y1))
|
||||||
return;
|
return;
|
||||||
for (int x=x0;x<x1;++x)
|
for (int x=x0;x<x1;++x)
|
||||||
for (int y=y0;y<y1;++y)
|
for (int y=y0;y<y1;++y)
|
||||||
this.imageData[getPosition(x,y)] &= A;
|
this.imageData[getPosition(x,y)] &= A;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -2^24
|
/* -2^24
|
||||||
* 00000001 00000000 00000000 00000000 ->
|
* 00000001 00000000 00000000 00000000 ->
|
||||||
* 11111110 11111111 11111111 11111111 ->
|
* 11111110 11111111 11111111 11111111 ->
|
||||||
* 11111111 00000000 00000000 00000000 */
|
* 11111111 00000000 00000000 00000000 */
|
||||||
private static final int B=-16777216;
|
private static final int B=-16777216;
|
||||||
private void setAreaOpaque(int x0,int y0,int x1,int y1){
|
private void setAreaOpaque(int x0,int y0,int x1,int y1){
|
||||||
for (int x=x0;x<x1;++x)
|
for (int x=x0;x<x1;++x)
|
||||||
for (int y=y0;y<y1;++y)
|
for (int y=y0;y<y1;++y)
|
||||||
this.imageData[getPosition(x,y)] |= B;
|
this.imageData[getPosition(x,y)] |= B;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAreaDueToConfig(int x0,int y0,int x1,int y1){
|
private void setAreaDueToConfig(int x0,int y0,int x1,int y1){
|
||||||
if(customskinloader.CustomSkinLoader.config.enableTransparentSkin)
|
if(customskinloader.CustomSkinLoader.config.enableTransparentSkin)
|
||||||
setAreaTransparent(x0,y0,x1,y1);
|
setAreaTransparent(x0,y0,x1,y1);
|
||||||
else
|
else
|
||||||
setAreaOpaque(x0,y0,x1,y1);
|
setAreaOpaque(x0,y0,x1,y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void skinAvailable(){
|
public void skinAvailable(){
|
||||||
//A callback when skin loaded
|
//A callback when skin loaded
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getARGB(int a,int r,int g,int b){
|
private static int getARGB(int a,int r,int g,int b){
|
||||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPosition(int x,int y){
|
private int getPosition(int x,int y){
|
||||||
return x+y*64*ratio;
|
return x+y*64*ratio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,81 +28,80 @@ 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 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) {
|
public FakeSkinManager(TextureManager textureManagerInstance, File skinCacheDirectory, MinecraftSessionService sessionService) {
|
||||||
this.textureManager=textureManagerInstance;
|
this.textureManager=textureManagerInstance;
|
||||||
HttpTextureUtil.defaultCacheDir=skinCacheDirectory;
|
HttpTextureUtil.defaultCacheDir=skinCacheDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type textureType){
|
public ResourceLocation loadSkin(MinecraftProfileTexture profileTexture, Type textureType){
|
||||||
return this.loadSkin(profileTexture, textureType, null);
|
return this.loadSkin(profileTexture, textureType, null);
|
||||||
}
|
}
|
||||||
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, final SkinAvailableCallback skinAvailableCallback){
|
public ResourceLocation loadSkin(final MinecraftProfileTexture profileTexture, final Type textureType, final SkinAvailableCallback skinAvailableCallback){
|
||||||
HttpTextureInfo info=HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl());
|
HttpTextureInfo info=HttpTextureUtil.toHttpTextureInfo(profileTexture.getUrl());
|
||||||
|
|
||||||
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);
|
final ResourceLocation resourcelocation = new ResourceLocation("skins/" + info.hash);
|
||||||
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
|
ITextureObject itextureobject = this.textureManager.getTexture(resourcelocation);
|
||||||
|
|
||||||
if (itextureobject != null)//Have already loaded
|
if (itextureobject != null)//Have already loaded
|
||||||
makeCallback(skinAvailableCallback,textureType, resourcelocation, profileTexture);
|
makeCallback(skinAvailableCallback,textureType, resourcelocation, profileTexture);
|
||||||
else{
|
else{
|
||||||
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(),
|
ThreadDownloadImageData threaddownloadimagedata = new ThreadDownloadImageData(info.cacheFile, info.url, DefaultPlayerSkin.getDefaultSkinLegacy(),
|
||||||
new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture));
|
new BaseBuffer(skinAvailableCallback, textureType, resourcelocation, profileTexture));
|
||||||
this.textureManager.loadTexture(resourcelocation, threaddownloadimagedata);
|
this.textureManager.loadTexture(resourcelocation, threaddownloadimagedata);
|
||||||
}
|
}
|
||||||
return resourcelocation;
|
return resourcelocation;
|
||||||
}
|
}
|
||||||
public void loadProfileTextures(final GameProfile profile, final SkinAvailableCallback skinAvailableCallback, final boolean requireSecure){
|
public void loadProfileTextures(final GameProfile profile, final SkinAvailableCallback skinAvailableCallback, final boolean requireSecure){
|
||||||
THREAD_POOL.submit(new Runnable(){
|
THREAD_POOL.submit(new Runnable(){
|
||||||
public void run(){
|
public void run(){
|
||||||
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
final Map<Type, MinecraftProfileTexture> map = Maps.<Type, MinecraftProfileTexture>newHashMap();
|
||||||
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
map.putAll(customskinloader.CustomSkinLoader.loadProfile(profile));
|
||||||
|
|
||||||
Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||||
public void run(){
|
public void run(){
|
||||||
for(Type type:Type.values())
|
for(Type type:Type.values())
|
||||||
if(map.containsKey(type))
|
if(map.containsKey(type))
|
||||||
FakeSkinManager.this.loadSkin((MinecraftProfileTexture)map.get(type), type, skinAvailableCallback);
|
FakeSkinManager.this.loadSkin((MinecraftProfileTexture)map.get(type), type, skinAvailableCallback);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile){
|
public Map<Type, MinecraftProfileTexture> loadSkinFromCache(GameProfile profile){
|
||||||
return CustomSkinLoader.loadProfileFromCache(profile);
|
return CustomSkinLoader.loadProfileFromCache(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void makeCallback(SkinAvailableCallback callback,Type type, ResourceLocation location, MinecraftProfileTexture texture){
|
private static void makeCallback(SkinAvailableCallback callback,Type type, ResourceLocation location, MinecraftProfileTexture texture){
|
||||||
if(callback!=null)
|
if(callback!=null)
|
||||||
callback.skinAvailable(type, location, texture);
|
callback.skinAvailable(type, location, texture);
|
||||||
}
|
}
|
||||||
private class BaseBuffer implements IImageBuffer{
|
private class BaseBuffer implements IImageBuffer{
|
||||||
private IImageBuffer buffer;
|
private IImageBuffer buffer;
|
||||||
|
|
||||||
private SkinAvailableCallback callback;
|
private SkinAvailableCallback callback;
|
||||||
private Type type;
|
private Type type;
|
||||||
private ResourceLocation location;
|
private ResourceLocation location;
|
||||||
private MinecraftProfileTexture texture;
|
private MinecraftProfileTexture texture;
|
||||||
public BaseBuffer(SkinAvailableCallback callback,Type type,ResourceLocation location,MinecraftProfileTexture texture){
|
public BaseBuffer(SkinAvailableCallback callback,Type type,ResourceLocation location,MinecraftProfileTexture texture){
|
||||||
this.buffer=(type==Type.SKIN?new FakeSkinBuffer():null);
|
this.buffer=(type==Type.SKIN?new FakeSkinBuffer():null);
|
||||||
|
|
||||||
this.callback=callback;
|
this.callback=callback;
|
||||||
this.type=type;
|
this.type=type;
|
||||||
this.location=location;
|
this.location=location;
|
||||||
this.texture=texture;
|
this.texture=texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage parseUserSkin(BufferedImage image){
|
public BufferedImage parseUserSkin(BufferedImage image){
|
||||||
return buffer==null?image:buffer.parseUserSkin(image);
|
return buffer==null?image:buffer.parseUserSkin(image);
|
||||||
}
|
}
|
||||||
public void skinAvailable(){
|
public void skinAvailable(){
|
||||||
if (buffer != null)
|
if (buffer != null)
|
||||||
buffer.skinAvailable();
|
buffer.skinAvailable();
|
||||||
|
|
||||||
FakeSkinManager.makeCallback(callback,type, location, texture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
FakeSkinManager.makeCallback(callback,type, location, texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,84 +18,84 @@ import customskinloader.utils.HttpRequestUtil.HttpRequest;
|
|||||||
import customskinloader.utils.HttpRequestUtil.HttpResponce;
|
import customskinloader.utils.HttpRequestUtil.HttpResponce;
|
||||||
|
|
||||||
public class JsonAPILoader implements ProfileLoader.IProfileLoader {
|
public class JsonAPILoader implements ProfileLoader.IProfileLoader {
|
||||||
|
|
||||||
public interface IJsonAPI {
|
public interface IJsonAPI {
|
||||||
public String toJsonUrl(String root,String username);
|
public String toJsonUrl(String root,String username);
|
||||||
public String getPayload(SkinSiteProfile ssp);
|
public String getPayload(SkinSiteProfile ssp);
|
||||||
public UserProfile toUserProfile(String root,String json,boolean local);
|
public UserProfile toUserProfile(String root,String json,boolean local);
|
||||||
public String getName();
|
public String getName();
|
||||||
}
|
}
|
||||||
public static class ErrorProfile{
|
public static class ErrorProfile{
|
||||||
public int errno;
|
public int errno;
|
||||||
public String msg;
|
public String msg;
|
||||||
}
|
}
|
||||||
public static enum Type{
|
public static enum Type{
|
||||||
CustomSkinAPI(new CustomSkinAPI()),CustomSkinAPIPlus(new CustomSkinAPIPlus()),UniSkinAPI(new UniSkinAPI());
|
CustomSkinAPI(new CustomSkinAPI()),CustomSkinAPIPlus(new CustomSkinAPIPlus()),UniSkinAPI(new UniSkinAPI());
|
||||||
public IJsonAPI jsonAPI;
|
public IJsonAPI jsonAPI;
|
||||||
private Type(IJsonAPI jsonAPI){
|
private Type(IJsonAPI jsonAPI){
|
||||||
this.jsonAPI=jsonAPI;
|
this.jsonAPI=jsonAPI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type type;
|
private Type type;
|
||||||
public JsonAPILoader(Type type){
|
public JsonAPILoader(Type type){
|
||||||
this.type=type;
|
this.type=type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
||||||
String username=gameProfile.getName();
|
String username=gameProfile.getName();
|
||||||
boolean local=HttpUtil0.isLocal(ssp.root);
|
boolean local=HttpUtil0.isLocal(ssp.root);
|
||||||
if(ssp.root==null||ssp.root.equals("")){
|
if(ssp.root==null||ssp.root.equals("")){
|
||||||
CustomSkinLoader.logger.info("Root not defined.");
|
CustomSkinLoader.logger.info("Root not defined.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String jsonUrl=type.jsonAPI.toJsonUrl(ssp.root, username);
|
String jsonUrl=type.jsonAPI.toJsonUrl(ssp.root, username);
|
||||||
String json;
|
String json;
|
||||||
if(local){
|
if(local){
|
||||||
File jsonFile=new File(jsonUrl);
|
File jsonFile=new File(jsonUrl);
|
||||||
if(!jsonFile.exists()){
|
if(!jsonFile.exists()){
|
||||||
CustomSkinLoader.logger.info("Profile File not found.");
|
CustomSkinLoader.logger.info("Profile File not found.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
json=IOUtils.toString(new FileInputStream(jsonFile));
|
json=IOUtils.toString(new FileInputStream(jsonFile));
|
||||||
}else{
|
}else{
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(jsonUrl).setCacheTime(60).setUserAgent(ssp.userAgent).setPayload(type.jsonAPI.getPayload(ssp)));
|
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(jsonUrl).setCacheTime(90).setUserAgent(ssp.userAgent).setPayload(type.jsonAPI.getPayload(ssp)));
|
||||||
json=responce.content;
|
json=responce.content;
|
||||||
}
|
}
|
||||||
if(json==null||json.equals("")){
|
if(json==null||json.equals("")){
|
||||||
CustomSkinLoader.logger.info("Profile not found.");
|
CustomSkinLoader.logger.info("Profile not found.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorProfile profile=CustomSkinLoader.GSON.fromJson(json, ErrorProfile.class);
|
ErrorProfile profile=CustomSkinLoader.GSON.fromJson(json, ErrorProfile.class);
|
||||||
if(profile.errno!=0){
|
if(profile.errno!=0){
|
||||||
CustomSkinLoader.logger.info("Error "+profile.errno+": "+profile.msg);
|
CustomSkinLoader.logger.info("Error "+profile.errno+": "+profile.msg);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserProfile p=type.jsonAPI.toUserProfile(ssp.root, json, local);
|
UserProfile p=type.jsonAPI.toUserProfile(ssp.root, json, local);
|
||||||
if(p==null||p.isEmpty()){
|
if(p==null||p.isEmpty()){
|
||||||
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
||||||
return null;
|
return null;
|
||||||
}else{
|
}else{
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||||
return StringUtils.isNoneEmpty(ssp0.root)?ssp0.root.equalsIgnoreCase(ssp1.root):true;
|
return StringUtils.isNoneEmpty(ssp0.root)?ssp0.root.equalsIgnoreCase(ssp1.root):true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return type.jsonAPI.getName();
|
return type.jsonAPI.getName();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void initLocalFolder(SkinSiteProfile ssp) {
|
public void initLocalFolder(SkinSiteProfile ssp) {
|
||||||
if(HttpUtil0.isLocal(ssp.root)){
|
if(HttpUtil0.isLocal(ssp.root)){
|
||||||
File f=new File(ssp.root);
|
File f=new File(ssp.root);
|
||||||
if(!f.exists())
|
if(!f.exists())
|
||||||
f.mkdirs();
|
f.mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,78 +17,78 @@ import customskinloader.utils.HttpTextureUtil;
|
|||||||
import customskinloader.utils.HttpUtil0;
|
import customskinloader.utils.HttpUtil0;
|
||||||
|
|
||||||
public class LegacyLoader implements ProfileLoader.IProfileLoader {
|
public class LegacyLoader implements ProfileLoader.IProfileLoader {
|
||||||
public static final String USERNAME_REGEX="\\{USERNAME\\}";
|
public static final String USERNAME_REGEX="\\{USERNAME\\}";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
||||||
String username=gameProfile.getName();
|
String username=gameProfile.getName();
|
||||||
UserProfile profile=new UserProfile();
|
UserProfile profile=new UserProfile();
|
||||||
if(StringUtils.isNoneEmpty(ssp.skin)){
|
if(StringUtils.isNoneEmpty(ssp.skin)){
|
||||||
String skin=ssp.skin.replaceAll(USERNAME_REGEX, username);
|
String skin=ssp.skin.replaceAll(USERNAME_REGEX, username);
|
||||||
if(HttpUtil0.isLocal(ssp.skin)){
|
if(HttpUtil0.isLocal(ssp.skin)){
|
||||||
File skinFile=new File(CustomSkinLoader.DATA_DIR,skin);
|
File skinFile=new File(CustomSkinLoader.DATA_DIR,skin);
|
||||||
if(skinFile.exists()&&skinFile.isFile())
|
if(skinFile.exists()&&skinFile.isFile())
|
||||||
profile.skinUrl=HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified()));
|
profile.skinUrl=HttpTextureUtil.getLocalLegacyFakeUrl(skin, HttpTextureUtil.getHash(skin, skinFile.length(), skinFile.lastModified()));
|
||||||
}else{
|
}else{
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(60));
|
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(90));
|
||||||
if(responce.success)
|
if(responce.success)
|
||||||
profile.skinUrl=HttpTextureUtil.getLegacyFakeUrl(skin);
|
profile.skinUrl=HttpTextureUtil.getLegacyFakeUrl(skin);
|
||||||
}
|
}
|
||||||
profile.model=profile.hasSkinUrl()?ssp.model:null;
|
profile.model=profile.hasSkinUrl()?ssp.model:null;
|
||||||
}
|
}
|
||||||
if(StringUtils.isNoneEmpty(ssp.cape)){
|
if(StringUtils.isNoneEmpty(ssp.cape)){
|
||||||
String cape=ssp.cape.replaceAll(USERNAME_REGEX, username);
|
String cape=ssp.cape.replaceAll(USERNAME_REGEX, username);
|
||||||
if(HttpUtil0.isLocal(ssp.cape)){
|
if(HttpUtil0.isLocal(ssp.cape)){
|
||||||
File capeFile=new File(CustomSkinLoader.DATA_DIR,cape);
|
File capeFile=new File(CustomSkinLoader.DATA_DIR,cape);
|
||||||
if(capeFile.exists()&&capeFile.isFile())
|
if(capeFile.exists()&&capeFile.isFile())
|
||||||
profile.capeUrl=HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified()));
|
profile.capeUrl=HttpTextureUtil.getLocalLegacyFakeUrl(cape, HttpTextureUtil.getHash(cape, capeFile.length(), capeFile.lastModified()));
|
||||||
}else{
|
}else{
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(cape).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(60));
|
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(cape).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(90));
|
||||||
if(responce.success)
|
if(responce.success)
|
||||||
profile.capeUrl=HttpTextureUtil.getLegacyFakeUrl(cape);
|
profile.capeUrl=HttpTextureUtil.getLegacyFakeUrl(cape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ModelManager0.isElytraSupported()&&StringUtils.isNoneEmpty(ssp.elytra)){
|
if(ModelManager0.isElytraSupported()&&StringUtils.isNoneEmpty(ssp.elytra)){
|
||||||
String elytra=ssp.elytra.replaceAll(USERNAME_REGEX, username);
|
String elytra=ssp.elytra.replaceAll(USERNAME_REGEX, username);
|
||||||
if(HttpUtil0.isLocal(ssp.elytra)){
|
if(HttpUtil0.isLocal(ssp.elytra)){
|
||||||
File elytraFile=new File(CustomSkinLoader.DATA_DIR,elytra);
|
File elytraFile=new File(CustomSkinLoader.DATA_DIR,elytra);
|
||||||
if(elytraFile.exists()&&elytraFile.isFile())
|
if(elytraFile.exists()&&elytraFile.isFile())
|
||||||
profile.elytraUrl=HttpTextureUtil.getLocalLegacyFakeUrl(elytra, HttpTextureUtil.getHash(elytra, elytraFile.length(), elytraFile.lastModified()));
|
profile.elytraUrl=HttpTextureUtil.getLocalLegacyFakeUrl(elytra, HttpTextureUtil.getHash(elytra, elytraFile.length(), elytraFile.lastModified()));
|
||||||
}else{
|
}else{
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(elytra).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(60));
|
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest(elytra).setUserAgent(ssp.userAgent).setCheckPNG(ssp.checkPNG!=null&&ssp.checkPNG!=false).setLoadContent(false).setCacheTime(90));
|
||||||
if(responce.success)
|
if(responce.success)
|
||||||
profile.elytraUrl=HttpTextureUtil.getLegacyFakeUrl(elytra);
|
profile.elytraUrl=HttpTextureUtil.getLegacyFakeUrl(elytra);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(profile.isEmpty()){
|
if(profile.isEmpty()){
|
||||||
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
CustomSkinLoader.logger.info("Both skin and cape not found.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||||
return (StringUtils.isNoneEmpty(ssp0.skin)?ssp0.skin.equalsIgnoreCase(ssp1.skin):true) || (StringUtils.isNoneEmpty(ssp0.cape)?ssp0.cape.equalsIgnoreCase(ssp1.cape):true);
|
return (StringUtils.isNoneEmpty(ssp0.skin)?ssp0.skin.equalsIgnoreCase(ssp1.skin):true) || (StringUtils.isNoneEmpty(ssp0.cape)?ssp0.cape.equalsIgnoreCase(ssp1.cape):true);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Legacy";
|
return "Legacy";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initLocalFolder(SkinSiteProfile ssp) {
|
public void initLocalFolder(SkinSiteProfile ssp) {
|
||||||
if(HttpUtil0.isLocal(ssp.skin))
|
if(HttpUtil0.isLocal(ssp.skin))
|
||||||
initFolder(ssp.skin);
|
initFolder(ssp.skin);
|
||||||
if(HttpUtil0.isLocal(ssp.cape))
|
if(HttpUtil0.isLocal(ssp.cape))
|
||||||
initFolder(ssp.cape);
|
initFolder(ssp.cape);
|
||||||
if(HttpUtil0.isLocal(ssp.elytra))
|
if(HttpUtil0.isLocal(ssp.elytra))
|
||||||
initFolder(ssp.elytra);
|
initFolder(ssp.elytra);
|
||||||
}
|
}
|
||||||
private void initFolder(String target){
|
private void initFolder(String target){
|
||||||
String file=target.replaceAll(USERNAME_REGEX, "init");
|
String file=target.replaceAll(USERNAME_REGEX, "init");
|
||||||
File folder=new File(CustomSkinLoader.DATA_DIR,file).getParentFile();
|
File folder=new File(CustomSkinLoader.DATA_DIR,file).getParentFile();
|
||||||
if(folder!=null&&!folder.exists())
|
if(folder!=null&&!folder.exists())
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,8 @@ 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.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;
|
||||||
|
|
||||||
@@ -29,66 +31,89 @@ import customskinloader.utils.MinecraftUtil;
|
|||||||
|
|
||||||
public class MojangAPILoader implements ProfileLoader.IProfileLoader {
|
public class MojangAPILoader implements ProfileLoader.IProfileLoader {
|
||||||
|
|
||||||
public static final MinecraftSessionService defaultSessionService=MinecraftUtil.getSessionService();
|
public static final MinecraftSessionService defaultSessionService=MinecraftUtil.getSessionService();
|
||||||
@Override
|
@Override
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
||||||
Map<MinecraftProfileTexture.Type,MinecraftProfileTexture> map=getTextures(gameProfile);
|
Map<MinecraftProfileTexture.Type,MinecraftProfileTexture> map=getTextures(gameProfile);
|
||||||
if(!map.isEmpty()){
|
if(!map.isEmpty()){
|
||||||
CustomSkinLoader.logger.info("Default profile will be used.");
|
CustomSkinLoader.logger.info("Default profile will be used.");
|
||||||
return ModelManager0.toUserProfile(map);
|
return ModelManager0.toUserProfile(map);
|
||||||
}
|
}
|
||||||
String username=gameProfile.getName();
|
String username=gameProfile.getName();
|
||||||
GameProfile newGameProfile=loadGameProfile(username);
|
GameProfile newGameProfile=loadGameProfile(username);
|
||||||
if(newGameProfile==null){
|
if(newGameProfile==null){
|
||||||
CustomSkinLoader.logger.info("Profile not found.("+username+"'s profile not found.)");
|
CustomSkinLoader.logger.info("Profile not found.("+username+"'s profile not found.)");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
newGameProfile=defaultSessionService.fillProfileProperties(newGameProfile, false);
|
newGameProfile=fillGameProfile(newGameProfile);
|
||||||
map=getTextures(newGameProfile);
|
map=getTextures(newGameProfile);
|
||||||
if(!map.isEmpty()){
|
if(!map.isEmpty()){
|
||||||
gameProfile.getProperties().putAll(newGameProfile.getProperties());
|
gameProfile.getProperties().putAll(newGameProfile.getProperties());
|
||||||
return ModelManager0.toUserProfile(map);
|
return ModelManager0.toUserProfile(map);
|
||||||
}
|
}
|
||||||
CustomSkinLoader.logger.info("Profile not found.("+username+" doesn't have skin/cape.)");
|
CustomSkinLoader.logger.info("Profile not found.("+username+" doesn't have skin/cape.)");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameProfile loadGameProfile(String username) throws Exception{
|
//Username -> UUID
|
||||||
//Doc (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time)
|
public static GameProfile loadGameProfile(String username) throws Exception{
|
||||||
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest("https://api.mojang.com/users/profiles/minecraft/"+username).setCacheTime(0));
|
//Doc (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time)
|
||||||
if(StringUtils.isEmpty(responce.content))
|
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest("https://api.mojang.com/users/profiles/minecraft/"+username).setCacheTime(0));
|
||||||
return null;
|
if(StringUtils.isEmpty(responce.content))
|
||||||
Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
return null;
|
||||||
GameProfile gameProfile=gson.fromJson(responce.content, GameProfile.class);
|
|
||||||
if(gameProfile.getId()==null)
|
Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
||||||
return null;
|
GameProfile gameProfile=gson.fromJson(responce.content, GameProfile.class);
|
||||||
return new GameProfile(gameProfile.getId(),gameProfile.getName());
|
|
||||||
}
|
if(gameProfile.getId()==null)
|
||||||
public static Map<MinecraftProfileTexture.Type,MinecraftProfileTexture> getTextures(GameProfile gameProfile) throws Exception{
|
return null;
|
||||||
Property textureProperty=(Property)Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
|
return new GameProfile(gameProfile.getId(),gameProfile.getName());
|
||||||
if (textureProperty==null)
|
}
|
||||||
return new HashMap();
|
//UUID -> Profile
|
||||||
String value=textureProperty.getValue();
|
public static GameProfile fillGameProfile(GameProfile profile) throws Exception{
|
||||||
if(StringUtils.isBlank(value))
|
//Doc (http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape)
|
||||||
return new HashMap();
|
HttpResponce responce=HttpRequestUtil.makeHttpRequest(new HttpRequest("https://sessionserver.mojang.com/session/minecraft/profile/"+UUIDTypeAdapter.fromUUID(profile.getId())).setCacheTime(90));
|
||||||
String json=new String(Base64.decodeBase64(value),Charsets.UTF_8);
|
if(StringUtils.isEmpty(responce.content))
|
||||||
Gson gson=new GsonBuilder().registerTypeAdapter(UUID.class,new UUIDTypeAdapter()).create();
|
return profile;
|
||||||
MinecraftTexturesPayload result=gson.fromJson(json,MinecraftTexturesPayload.class);
|
|
||||||
if (result==null||result.getTextures()==null)
|
Gson gson=new GsonBuilder()
|
||||||
return new HashMap();
|
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
||||||
return result.getTextures();
|
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
||||||
}
|
.create();
|
||||||
|
MinecraftProfilePropertiesResponse propertiesResponce=gson.fromJson(responce.content, MinecraftProfilePropertiesResponse.class);
|
||||||
@Override
|
GameProfile newGameProfile=new GameProfile(propertiesResponce.getId(),propertiesResponce.getName());
|
||||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
newGameProfile.getProperties().putAll(propertiesResponce.getProperties());
|
||||||
return true;
|
|
||||||
}
|
return newGameProfile;
|
||||||
@Override
|
}
|
||||||
public String getName() {
|
|
||||||
return "MojangAPI";
|
public static Map<MinecraftProfileTexture.Type,MinecraftProfileTexture> getTextures(GameProfile gameProfile) throws Exception{
|
||||||
}
|
if(gameProfile==null)
|
||||||
|
return new HashMap();
|
||||||
|
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 void initLocalFolder(SkinSiteProfile ssp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,27 +8,27 @@ import customskinloader.config.SkinSiteProfile;
|
|||||||
import customskinloader.profile.UserProfile;
|
import customskinloader.profile.UserProfile;
|
||||||
|
|
||||||
public class ProfileLoader {
|
public class ProfileLoader {
|
||||||
private static final IProfileLoader[] DEFAULT_LOADERS={
|
private static final IProfileLoader[] DEFAULT_LOADERS={
|
||||||
new MojangAPILoader(),
|
new MojangAPILoader(),
|
||||||
new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPI),
|
new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPI),
|
||||||
new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPIPlus),
|
new JsonAPILoader(JsonAPILoader.Type.CustomSkinAPIPlus),
|
||||||
new LegacyLoader(),
|
new LegacyLoader(),
|
||||||
new JsonAPILoader(JsonAPILoader.Type.UniSkinAPI)};
|
new JsonAPILoader(JsonAPILoader.Type.UniSkinAPI)};
|
||||||
|
|
||||||
public static final HashMap<String,IProfileLoader> LOADERS=initLoaders();
|
public static final HashMap<String,IProfileLoader> LOADERS=initLoaders();
|
||||||
|
|
||||||
private static HashMap<String, IProfileLoader> initLoaders() {
|
private static HashMap<String, IProfileLoader> initLoaders() {
|
||||||
HashMap<String, IProfileLoader> loaders=new HashMap<String, IProfileLoader>();
|
HashMap<String, IProfileLoader> loaders=new HashMap<String, IProfileLoader>();
|
||||||
for(IProfileLoader loader:DEFAULT_LOADERS){
|
for(IProfileLoader loader:DEFAULT_LOADERS){
|
||||||
loaders.put(loader.getName().toLowerCase(), loader);
|
loaders.put(loader.getName().toLowerCase(), loader);
|
||||||
}
|
}
|
||||||
return loaders;
|
return loaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IProfileLoader {
|
public interface IProfileLoader {
|
||||||
public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception;
|
public UserProfile loadProfile(SkinSiteProfile ssp,GameProfile gameProfile) throws Exception;
|
||||||
public boolean compare(SkinSiteProfile ssp0,SkinSiteProfile ssp1);
|
public boolean compare(SkinSiteProfile ssp0,SkinSiteProfile ssp1);
|
||||||
public String getName();
|
public String getName();
|
||||||
public void initLocalFolder(SkinSiteProfile ssp);
|
public void initLocalFolder(SkinSiteProfile ssp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,77 +14,77 @@ import customskinloader.profile.UserProfile;
|
|||||||
import customskinloader.utils.HttpTextureUtil;
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
|
|
||||||
public class CustomSkinAPI implements IJsonAPI {
|
public class CustomSkinAPI implements IJsonAPI {
|
||||||
private static final String TEXTURES="textures/";
|
private static final String TEXTURES="textures/";
|
||||||
private static final String SUFFIX=".json";
|
private static final String SUFFIX=".json";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toJsonUrl(String root, String username) {
|
public String toJsonUrl(String root, String username) {
|
||||||
return new StringBuilder().append(root).append(username).append(SUFFIX).toString();
|
return new StringBuilder().append(root).append(username).append(SUFFIX).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
CustomSkinAPIProfile profile=CustomSkinLoader.GSON.fromJson(json, CustomSkinAPIProfile.class);
|
CustomSkinAPIProfile profile=CustomSkinLoader.GSON.fromJson(json, CustomSkinAPIProfile.class);
|
||||||
UserProfile p=new UserProfile();
|
UserProfile p=new UserProfile();
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(profile.skin)){
|
if(StringUtils.isNotBlank(profile.skin)){
|
||||||
p.skinUrl=root+TEXTURES+profile.skin;
|
p.skinUrl=root+TEXTURES+profile.skin;
|
||||||
if(local)
|
if(local)
|
||||||
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
|
p.skinUrl=HttpTextureUtil.getLocalFakeUrl(p.skinUrl);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(profile.cape)){
|
if(StringUtils.isNotBlank(profile.cape)){
|
||||||
p.capeUrl=root+TEXTURES+profile.cape;
|
p.capeUrl=root+TEXTURES+profile.cape;
|
||||||
if(local)
|
if(local)
|
||||||
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(profile.elytra)){
|
if(StringUtils.isNotBlank(profile.elytra)){
|
||||||
p.elytraUrl=root+TEXTURES+profile.elytra;
|
p.elytraUrl=root+TEXTURES+profile.elytra;
|
||||||
if(local)
|
if(local)
|
||||||
p.elytraUrl=HttpTextureUtil.getLocalFakeUrl(p.elytraUrl);
|
p.elytraUrl=HttpTextureUtil.getLocalFakeUrl(p.elytraUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String,String> textures=new LinkedHashMap<String,String>();
|
Map<String,String> textures=new LinkedHashMap<String,String>();
|
||||||
if(profile.skins!=null)
|
if(profile.skins!=null)
|
||||||
textures.putAll(profile.skins);
|
textures.putAll(profile.skins);
|
||||||
if(profile.textures!=null)
|
if(profile.textures!=null)
|
||||||
textures.putAll(profile.textures);
|
textures.putAll(profile.textures);
|
||||||
if(textures.isEmpty())
|
if(textures.isEmpty())
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
boolean hasSkin=false;
|
boolean hasSkin=false;
|
||||||
for(String model:textures.keySet()){
|
for(String model:textures.keySet()){
|
||||||
Model enumModel=ModelManager0.getEnumModel(model);
|
Model enumModel=ModelManager0.getEnumModel(model);
|
||||||
if(enumModel==null||StringUtils.isEmpty(textures.get(model)))
|
if(enumModel==null||StringUtils.isEmpty(textures.get(model)))
|
||||||
continue;
|
continue;
|
||||||
if(ModelManager0.isSkin(enumModel))
|
if(ModelManager0.isSkin(enumModel))
|
||||||
if(hasSkin)
|
if(hasSkin)
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
hasSkin=true;
|
hasSkin=true;
|
||||||
String url=root+TEXTURES+textures.get(model);
|
String url=root+TEXTURES+textures.get(model);
|
||||||
if(local)
|
if(local)
|
||||||
url=HttpTextureUtil.getLocalFakeUrl(url);
|
url=HttpTextureUtil.getLocalFakeUrl(url);
|
||||||
p.put(enumModel, url);
|
p.put(enumModel, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
private class CustomSkinAPIProfile{
|
private class CustomSkinAPIProfile{
|
||||||
public String username;
|
public String username;
|
||||||
public Map<String,String> textures;
|
public LinkedHashMap<String,String> textures;
|
||||||
|
|
||||||
public Map<String,String> skins;
|
public LinkedHashMap<String,String> skins;
|
||||||
|
|
||||||
public String skin;
|
public String skin;
|
||||||
public String cape;
|
public String cape;
|
||||||
public String elytra;
|
public String elytra;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getPayload(SkinSiteProfile ssp) {
|
public String getPayload(SkinSiteProfile ssp) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "CustomSkinAPI";
|
return "CustomSkinAPI";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,67 +16,67 @@ import customskinloader.utils.MinecraftUtil;
|
|||||||
|
|
||||||
public class CustomSkinAPIPlus implements IJsonAPI {
|
public class CustomSkinAPIPlus implements IJsonAPI {
|
||||||
|
|
||||||
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);
|
||||||
}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);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toJsonUrl(String root, String username) {
|
public String toJsonUrl(String root, String username) {
|
||||||
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toJsonUrl(root, username);
|
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toJsonUrl(root, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPayload(SkinSiteProfile ssp) {
|
public String getPayload(SkinSiteProfile ssp) {
|
||||||
if(ssp.privacy==null)
|
if(ssp.privacy==null)
|
||||||
ssp.privacy=new CustomSkinAPIPlusPrivacy();
|
ssp.privacy=new CustomSkinAPIPlusPrivacy();
|
||||||
return new Gson().toJson(new CustomSkinAPIPlusPayload(ssp.privacy));
|
return new Gson().toJson(new CustomSkinAPIPlusPayload(ssp.privacy));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toUserProfile(root, json, local);
|
return JsonAPILoader.Type.CustomSkinAPI.jsonAPI.toUserProfile(root, json, local);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
public String gameVersion;//minecraft version
|
||||||
public String modVersion;//mod version
|
public String modVersion;//mod version
|
||||||
public String serverAddress;//ip:port
|
public String serverAddress;//ip:port
|
||||||
public String clientID;//Minecraft Client ID
|
public String clientID;//Minecraft Client ID
|
||||||
public CustomSkinAPIPlusPayload(CustomSkinAPIPlusPrivacy privacy){
|
public CustomSkinAPIPlusPayload(CustomSkinAPIPlusPrivacy privacy){
|
||||||
if(privacy.gameVersion)
|
if(privacy.gameVersion)
|
||||||
gameVersion=MinecraftUtil.getMinecraftMainVersion();
|
gameVersion=MinecraftUtil.getMinecraftMainVersion();
|
||||||
if(privacy.modVersion)
|
if(privacy.modVersion)
|
||||||
modVersion=CustomSkinLoader.CustomSkinLoader_VERSION;
|
modVersion=CustomSkinLoader.CustomSkinLoader_VERSION;
|
||||||
if(privacy.serverAddress)
|
if(privacy.serverAddress)
|
||||||
serverAddress=MinecraftUtil.isLanServer()?null:MinecraftUtil.getStandardServerAddress();
|
serverAddress=MinecraftUtil.isLanServer()?null:MinecraftUtil.getStandardServerAddress();
|
||||||
if(privacy.clientID)
|
if(privacy.clientID)
|
||||||
clientID=CustomSkinAPIPlus.clientID;
|
clientID=CustomSkinAPIPlus.clientID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class CustomSkinAPIPlusPrivacy{
|
public static class CustomSkinAPIPlusPrivacy{
|
||||||
public boolean gameVersion=true;
|
public boolean gameVersion=true;
|
||||||
public boolean modVersion=true;
|
public boolean modVersion=true;
|
||||||
public boolean serverAddress=true;
|
public boolean serverAddress=true;
|
||||||
public boolean clientID=true;
|
public boolean clientID=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,67 +14,67 @@ import customskinloader.profile.ModelManager0.Model;
|
|||||||
import customskinloader.utils.HttpTextureUtil;
|
import customskinloader.utils.HttpTextureUtil;
|
||||||
|
|
||||||
public class UniSkinAPI implements IJsonAPI {
|
public class UniSkinAPI implements IJsonAPI {
|
||||||
private static final String TEXTURES="textures/";
|
private static final String TEXTURES="textures/";
|
||||||
private static final String SUFFIX=".json";
|
private static final String SUFFIX=".json";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toJsonUrl(String root, String username) {
|
public String toJsonUrl(String root, String username) {
|
||||||
return new StringBuilder().append(root).append(username).append(SUFFIX).toString();
|
return new StringBuilder().append(root).append(username).append(SUFFIX).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserProfile toUserProfile(String root, String json, boolean local) {
|
public UserProfile toUserProfile(String root, String json, boolean local) {
|
||||||
UniSkinAPIProfile profile=CustomSkinLoader.GSON.fromJson(json, UniSkinAPIProfile.class);
|
UniSkinAPIProfile profile=CustomSkinLoader.GSON.fromJson(json, UniSkinAPIProfile.class);
|
||||||
UserProfile p=new UserProfile();
|
UserProfile p=new UserProfile();
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(profile.cape)){
|
if(StringUtils.isNotBlank(profile.cape)){
|
||||||
p.capeUrl=root+TEXTURES+profile.cape;
|
p.capeUrl=root+TEXTURES+profile.cape;
|
||||||
if(local)
|
if(local)
|
||||||
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
p.capeUrl=HttpTextureUtil.getLocalFakeUrl(p.capeUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(profile.skins==null||profile.skins.isEmpty())
|
if(profile.skins==null||profile.skins.isEmpty())
|
||||||
return p;
|
return p;
|
||||||
if(profile.model_preference==null||profile.model_preference.isEmpty())
|
if(profile.model_preference==null||profile.model_preference.isEmpty())
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
boolean hasSkin=false;
|
boolean hasSkin=false;
|
||||||
for(String model:profile.model_preference){
|
for(String model:profile.model_preference){
|
||||||
Model enumModel=ModelManager0.getEnumModel(model);
|
Model enumModel=ModelManager0.getEnumModel(model);
|
||||||
if(enumModel==null||StringUtils.isEmpty(profile.skins.get(model)))
|
if(enumModel==null||StringUtils.isEmpty(profile.skins.get(model)))
|
||||||
continue;
|
continue;
|
||||||
if(ModelManager0.isSkin(enumModel))
|
if(ModelManager0.isSkin(enumModel))
|
||||||
if(hasSkin)
|
if(hasSkin)
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
hasSkin=true;
|
hasSkin=true;
|
||||||
String url=root+TEXTURES+profile.skins.get(model);
|
String url=root+TEXTURES+profile.skins.get(model);
|
||||||
if(local)
|
if(local)
|
||||||
url=HttpTextureUtil.getLocalFakeUrl(url);
|
url=HttpTextureUtil.getLocalFakeUrl(url);
|
||||||
p.put(enumModel, url);
|
p.put(enumModel, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Json profile for UniSkinAPI
|
* Json profile for UniSkinAPI
|
||||||
* Source Code: https://github.com/RecursiveG/UniSkinMod/blob/master/src/main/java/org/devinprogress/uniskinmod/UniSkinApiProfile.java#L18-L22
|
* Source Code: https://github.com/RecursiveG/UniSkinMod/blob/master/src/main/java/org/devinprogress/uniskinmod/UniSkinApiProfile.java#L18-L22
|
||||||
* @author RecursiveG
|
* @author RecursiveG
|
||||||
*/
|
*/
|
||||||
private class UniSkinAPIProfile{
|
private class UniSkinAPIProfile{
|
||||||
public String player_name;
|
public String player_name;
|
||||||
public long last_update;
|
public long last_update;
|
||||||
public List<String> model_preference;
|
public List<String> model_preference;
|
||||||
public Map<String,String> skins;
|
public Map<String,String> skins;
|
||||||
|
|
||||||
public String cape;
|
public String cape;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getPayload(SkinSiteProfile ssp) {
|
public String getPayload(SkinSiteProfile ssp) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "UniSkinAPI";
|
return "UniSkinAPI";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,133 +31,133 @@ 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 HashMap<GameProfile,SkullTexture>();
|
||||||
private Map<GameProfile,Map<Type,MinecraftProfileTexture>> staticTextures=new HashMap<GameProfile,Map<Type,MinecraftProfileTexture>>();
|
private Map<GameProfile,Map<Type,MinecraftProfileTexture>> staticTextures=new HashMap<GameProfile,Map<Type,MinecraftProfileTexture>>();
|
||||||
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=(Property)Iterables.getFirst(profile.getProperties().get("textures"), null);
|
||||||
if (textureProperty==null){
|
if (textureProperty==null){
|
||||||
staticTextures.put(profile, new HashMap());
|
staticTextures.put(profile, new HashMap());
|
||||||
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, new HashMap());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String json=new String(Base64.decodeBase64(value),Charsets.UTF_8);
|
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, new HashMap());
|
||||||
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))?new HashMap():parseTextures(result.textures));
|
||||||
|
|
||||||
if(StringUtils.isNotEmpty(result.index)){
|
if(StringUtils.isNotEmpty(result.index)){
|
||||||
File indexFile=new File(CustomSkinLoader.DATA_DIR,result.index);
|
File indexFile=new File(CustomSkinLoader.DATA_DIR,result.index);
|
||||||
try{
|
try{
|
||||||
String index=FileUtils.readFileToString(indexFile, Charsets.UTF_8);
|
String index=FileUtils.readFileToString(indexFile, Charsets.UTF_8);
|
||||||
if(StringUtils.isNotEmpty(index)){
|
if(StringUtils.isNotEmpty(index)){
|
||||||
ArrayList<String> skins=CustomSkinLoader.GSON.fromJson(index, ArrayList.class);
|
ArrayList<String> skins=CustomSkinLoader.GSON.fromJson(index, ArrayList.class);
|
||||||
if(skins!=null&&!skins.isEmpty())
|
if(skins!=null&&!skins.isEmpty())
|
||||||
result.skins=skins;
|
result.skins=skins;
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
CustomSkinLoader.logger.warning("Exception occurs while parsing index file: "+e.toString());
|
CustomSkinLoader.logger.warning("Exception occurs while parsing index file: "+e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!CustomSkinLoader.config.enableDynamicSkull||result.skins==null||result.skins.isEmpty())
|
if(!CustomSkinLoader.config.enableDynamicSkull||result.skins==null||result.skins.isEmpty())
|
||||||
return;
|
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
|
for(int i=0;i<result.skins.size();i++){//check and cache skins
|
||||||
String skin=result.skins.get(i);
|
String skin=result.skins.get(i);
|
||||||
if(HttpUtil0.isLocal(skin)){
|
if(HttpUtil0.isLocal(skin)){
|
||||||
//Local Skin
|
//Local Skin
|
||||||
File skinFile=new File(CustomSkinLoader.DATA_DIR,skin);
|
File skinFile=new File(CustomSkinLoader.DATA_DIR,skin);
|
||||||
if(skinFile.isFile()&&skinFile.length()>0){
|
if(skinFile.isFile()&&skinFile.length()>0){
|
||||||
//Skin found
|
//Skin found
|
||||||
String fakeUrl=HttpTextureUtil.getLocalFakeUrl(skin);
|
String fakeUrl=HttpTextureUtil.getLocalFakeUrl(skin);
|
||||||
result.skins.set(i, fakeUrl);
|
result.skins.set(i, fakeUrl);
|
||||||
}else{
|
}else{
|
||||||
//Could not find skin
|
//Could not find skin
|
||||||
result.skins.remove(i--);
|
result.skins.remove(i--);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}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;
|
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 new HashMap();
|
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 new HashMap();
|
||||||
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 new HashMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,106 +16,106 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
|
|||||||
* @since 13.1
|
* @since 13.1
|
||||||
*/
|
*/
|
||||||
public class ModelManager0 {
|
public class ModelManager0 {
|
||||||
public static enum Model{
|
public static 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 HashMap<String,Model> models=new HashMap<String,Model>();
|
||||||
private static Type typeElytra=null;
|
private static Type typeElytra=null;
|
||||||
static{
|
static{
|
||||||
for(Type type:Type.values()){
|
for(Type type:Type.values()){
|
||||||
if(type.ordinal()==2)//ELYTRA
|
if(type.ordinal()==2)//ELYTRA
|
||||||
typeElytra=type;
|
typeElytra=type;
|
||||||
}
|
}
|
||||||
models.put("default", Model.SKIN_DEFAULT);
|
models.put("default", Model.SKIN_DEFAULT);
|
||||||
models.put("slim", Model.SKIN_SLIM);
|
models.put("slim", Model.SKIN_SLIM);
|
||||||
models.put("cape", Model.CAPE);
|
models.put("cape", Model.CAPE);
|
||||||
if(typeElytra!=null)
|
if(typeElytra!=null)
|
||||||
models.put("elytra", Model.ELYTRA);
|
models.put("elytra", Model.ELYTRA);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get enum for the model.
|
* Get enum for the model.
|
||||||
* @param model - string model
|
* @param model - string model
|
||||||
* @since 14.5
|
* @since 14.5
|
||||||
*/
|
*/
|
||||||
public static Model getEnumModel(String model){
|
public static Model getEnumModel(String model){
|
||||||
return models.get(model);
|
return models.get(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if model is skin.
|
* Check if model is skin.
|
||||||
* @since 14.5
|
* @since 14.5
|
||||||
* */
|
* */
|
||||||
public static boolean isSkin(Model model){
|
public static boolean isSkin(Model model){
|
||||||
return model==Model.SKIN_DEFAULT||model==Model.SKIN_SLIM;
|
return model==Model.SKIN_DEFAULT||model==Model.SKIN_SLIM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if elytra is supported.
|
* Check if elytra is supported.
|
||||||
* @since 14.5
|
* @since 14.5
|
||||||
*/
|
*/
|
||||||
public static boolean isElytraSupported(){
|
public static boolean isElytraSupported(){
|
||||||
return typeElytra!=null;
|
return typeElytra!=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse hashMapProfile to UserProfile
|
* Parse hashMapProfile to UserProfile
|
||||||
* @param profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
* @param profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
||||||
* @return profile - UserProfile instance
|
* @return profile - UserProfile instance
|
||||||
* @since 13.1
|
* @since 13.1
|
||||||
*/
|
*/
|
||||||
public static UserProfile toUserProfile(Map profile){
|
public static UserProfile toUserProfile(Map profile){
|
||||||
UserProfile userProfile=new UserProfile();
|
UserProfile userProfile=new UserProfile();
|
||||||
if(profile==null)
|
if(profile==null)
|
||||||
return userProfile;
|
return userProfile;
|
||||||
MinecraftProfileTexture skin=(MinecraftProfileTexture)profile.get(Type.SKIN);
|
MinecraftProfileTexture skin=(MinecraftProfileTexture)profile.get(Type.SKIN);
|
||||||
userProfile.skinUrl= skin==null?null:skin.getUrl();//Avoid NullPointerException
|
userProfile.skinUrl= skin==null?null:skin.getUrl();//Avoid NullPointerException
|
||||||
userProfile.model= skin==null?null:skin.getMetadata("model");
|
userProfile.model= skin==null?null:skin.getMetadata("model");
|
||||||
if(StringUtils.isEmpty(userProfile.model))
|
if(StringUtils.isEmpty(userProfile.model))
|
||||||
userProfile.model="default";
|
userProfile.model="default";
|
||||||
|
|
||||||
MinecraftProfileTexture cape=(MinecraftProfileTexture)profile.get(Type.CAPE);
|
MinecraftProfileTexture cape=(MinecraftProfileTexture)profile.get(Type.CAPE);
|
||||||
userProfile.capeUrl= cape==null?null:cape.getUrl();
|
userProfile.capeUrl= cape==null?null:cape.getUrl();
|
||||||
return userProfile;
|
return userProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse UserProfile to hashMapProfile
|
* Parse UserProfile to hashMapProfile
|
||||||
* @param profile - UserProfile instance
|
* @param profile - UserProfile instance
|
||||||
* @return profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
* @return profile - hashMapProfile (HashMap<String,MinecraftProfileTexture>)
|
||||||
* @since 13.1
|
* @since 13.1
|
||||||
*/
|
*/
|
||||||
public static Map fromUserProfile(UserProfile profile){
|
public static Map fromUserProfile(UserProfile profile){
|
||||||
Map map=Maps.newHashMap();
|
Map map=Maps.newHashMap();
|
||||||
if(profile==null)
|
if(profile==null)
|
||||||
return map;
|
return map;
|
||||||
if(profile.skinUrl!=null){
|
if(profile.skinUrl!=null){
|
||||||
Map metadata=null;
|
Map metadata=null;
|
||||||
if(profile.model!=null&&profile.model.equals("slim")){
|
if(profile.model!=null&&profile.model.equals("slim")){
|
||||||
metadata = Maps.newHashMap();
|
metadata = Maps.newHashMap();
|
||||||
metadata.put("model", "slim");
|
metadata.put("model", "slim");
|
||||||
}
|
}
|
||||||
map.put(Type.SKIN, getProfileTexture(profile.skinUrl,metadata));
|
map.put(Type.SKIN, getProfileTexture(profile.skinUrl,metadata));
|
||||||
}
|
}
|
||||||
if(profile.capeUrl!=null)
|
if(profile.capeUrl!=null)
|
||||||
map.put(Type.CAPE, getProfileTexture(profile.capeUrl,null));
|
map.put(Type.CAPE, getProfileTexture(profile.capeUrl,null));
|
||||||
if(typeElytra!=null && profile.elytraUrl!=null)
|
if(typeElytra!=null && profile.elytraUrl!=null)
|
||||||
map.put(typeElytra, getProfileTexture(profile.elytraUrl,null));
|
map.put(typeElytra, getProfileTexture(profile.elytraUrl,null));
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse url to MinecraftProfileTexture
|
* Parse url to MinecraftProfileTexture
|
||||||
*
|
*
|
||||||
* @param url - textureUrl
|
* @param url - textureUrl
|
||||||
* metadata - metadata
|
* metadata - metadata
|
||||||
* @return MinecraftProfileTexture
|
* @return MinecraftProfileTexture
|
||||||
* @since 14.5
|
* @since 14.5
|
||||||
*/
|
*/
|
||||||
public static MinecraftProfileTexture getProfileTexture(String url,Map metadata){
|
public static MinecraftProfileTexture getProfileTexture(String url,Map metadata){
|
||||||
return new MinecraftProfileTexture(url,metadata);
|
return new MinecraftProfileTexture(url,metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,96 +11,96 @@ import customskinloader.CustomSkinLoader;
|
|||||||
import customskinloader.utils.TimeUtil;
|
import customskinloader.utils.TimeUtil;
|
||||||
|
|
||||||
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 HashMap<String,CachedProfile> cachedProfiles=new HashMap<String,CachedProfile>();
|
||||||
private HashMap<String,UserProfile> localProfiles=new HashMap<String,UserProfile>();
|
private HashMap<String,UserProfile> localProfiles=new HashMap<String,UserProfile>();
|
||||||
|
|
||||||
public ProfileCache(){
|
public ProfileCache(){
|
||||||
if(!PROFILE_CACHE_DIR.exists())
|
if(!PROFILE_CACHE_DIR.exists())
|
||||||
PROFILE_CACHE_DIR.mkdir();
|
PROFILE_CACHE_DIR.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExist(String username){
|
public boolean isExist(String username){
|
||||||
return cachedProfiles.containsKey(username.toLowerCase());
|
return cachedProfiles.containsKey(username.toLowerCase());
|
||||||
}
|
}
|
||||||
public boolean isReady(String username){
|
public boolean isReady(String username){
|
||||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||||
return cp==null?false:(cp.loading||cp.expiryTime>TimeUtil.getCurrentUnixTimestamp());
|
return cp==null?false:(cp.loading||cp.expiryTime>TimeUtil.getCurrentUnixTimestamp());
|
||||||
}
|
}
|
||||||
public boolean isExpired(String username){
|
public boolean isExpired(String username){
|
||||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||||
return cp==null?true:(cp.expiryTime<=TimeUtil.getCurrentUnixTimestamp());
|
return cp==null?true:(cp.expiryTime<=TimeUtil.getCurrentUnixTimestamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserProfile getProfile(String username){
|
public UserProfile getProfile(String username){
|
||||||
return getCachedProfile(username).profile;
|
return getCachedProfile(username).profile;
|
||||||
}
|
}
|
||||||
public long getExpiry(String username){
|
public long getExpiry(String username){
|
||||||
return getCachedProfile(username).expiryTime;
|
return getCachedProfile(username).expiryTime;
|
||||||
}
|
}
|
||||||
public UserProfile getLocalProfile(String username){
|
public UserProfile getLocalProfile(String username){
|
||||||
if(localProfiles.containsKey(username.toLowerCase()))
|
if(localProfiles.containsKey(username.toLowerCase()))
|
||||||
return localProfiles.get(username.toLowerCase());
|
return localProfiles.get(username.toLowerCase());
|
||||||
return loadLocalProfile(username);
|
return loadLocalProfile(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoading(String username,boolean loading){
|
public void setLoading(String username,boolean loading){
|
||||||
getCachedProfile(username).loading=loading;
|
getCachedProfile(username).loading=loading;
|
||||||
}
|
}
|
||||||
public void updateCache(String username,UserProfile profile){
|
public void updateCache(String username,UserProfile profile){
|
||||||
updateCache(username,profile,CustomSkinLoader.config.enableLocalProfileCache);
|
updateCache(username,profile,CustomSkinLoader.config.enableLocalProfileCache);
|
||||||
}
|
}
|
||||||
public void updateCache(String username,UserProfile profile,boolean saveLocalProfile){
|
public void updateCache(String username,UserProfile profile,boolean saveLocalProfile){
|
||||||
CachedProfile cp=getCachedProfile(username);
|
CachedProfile cp=getCachedProfile(username);
|
||||||
cp.profile=profile;
|
cp.profile=profile;
|
||||||
cp.expiryTime=TimeUtil.getUnixTimestampRandomDelay(CustomSkinLoader.config.cacheExpiry);
|
cp.expiryTime=TimeUtil.getUnixTimestampRandomDelay(CustomSkinLoader.config.cacheExpiry);
|
||||||
if(!saveLocalProfile)
|
if(!saveLocalProfile)
|
||||||
return;
|
return;
|
||||||
saveLocalProfile(username,profile);
|
saveLocalProfile(username,profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CachedProfile getCachedProfile(String username){
|
private CachedProfile getCachedProfile(String username){
|
||||||
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
CachedProfile cp=cachedProfiles.get(username.toLowerCase());
|
||||||
if(cp!=null)
|
if(cp!=null)
|
||||||
return cp;
|
return cp;
|
||||||
cp=new CachedProfile();
|
cp=new CachedProfile();
|
||||||
cachedProfiles.put(username.toLowerCase(), cp);
|
cachedProfiles.put(username.toLowerCase(), cp);
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
private UserProfile loadLocalProfile(String username){
|
private UserProfile loadLocalProfile(String username){
|
||||||
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);
|
localProfiles.put(username.toLowerCase(), null);
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
String json=IOUtils.toString(new FileInputStream(localProfile));
|
String json=IOUtils.toString(new FileInputStream(localProfile));
|
||||||
UserProfile profile=CustomSkinLoader.GSON.fromJson(json, UserProfile.class);
|
UserProfile profile=CustomSkinLoader.GSON.fromJson(json, UserProfile.class);
|
||||||
localProfiles.put(username.toLowerCase(), profile);
|
localProfiles.put(username.toLowerCase(), profile);
|
||||||
CustomSkinLoader.logger.info("Successfully load LocalProfile.");
|
CustomSkinLoader.logger.info("Successfully load LocalProfile.");
|
||||||
return profile;
|
return profile;
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
CustomSkinLoader.logger.info("Failed to load LocalProfile.("+e.toString()+")");
|
CustomSkinLoader.logger.info("Failed to load LocalProfile.("+e.toString()+")");
|
||||||
localProfiles.put(username.toLowerCase(), null);
|
localProfiles.put(username.toLowerCase(), null);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
private void saveLocalProfile(String username,UserProfile profile){
|
private void saveLocalProfile(String username,UserProfile profile){
|
||||||
String json=CustomSkinLoader.GSON.toJson(profile);
|
String json=CustomSkinLoader.GSON.toJson(profile);
|
||||||
File localProfile=new File(PROFILE_CACHE_DIR,username.toLowerCase()+".json");
|
File localProfile=new File(PROFILE_CACHE_DIR,username+".json");
|
||||||
if(localProfile.exists())
|
if(localProfile.exists())
|
||||||
localProfile.delete();
|
localProfile.delete();
|
||||||
try {
|
try {
|
||||||
localProfile.createNewFile();
|
localProfile.createNewFile();
|
||||||
IOUtils.write(json, new FileOutputStream(localProfile));
|
IOUtils.write(json, new FileOutputStream(localProfile));
|
||||||
CustomSkinLoader.logger.info("Successfully save LocalProfile.");
|
CustomSkinLoader.logger.info("Successfully save LocalProfile.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CustomSkinLoader.logger.info("Failed to save LocalProfile.("+e.toString()+")");
|
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,94 @@ 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.capeUrl=url;
|
||||||
return;
|
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;
|
||||||
if(StringUtils.isEmpty(this.capeUrl))
|
if(StringUtils.isEmpty(this.capeUrl))
|
||||||
this.capeUrl=profile.capeUrl;
|
this.capeUrl=profile.capeUrl;
|
||||||
if(StringUtils.isEmpty(this.elytraUrl))
|
if(StringUtils.isEmpty(this.elytraUrl))
|
||||||
this.elytraUrl=profile.elytraUrl;
|
this.elytraUrl=profile.elytraUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,109 +17,109 @@ import net.minecraft.launchwrapper.IClassTransformer;
|
|||||||
|
|
||||||
public class ClassTransformer implements IClassTransformer {
|
public class ClassTransformer implements IClassTransformer {
|
||||||
|
|
||||||
private ZipFile zipFile = null;
|
private ZipFile zipFile = null;
|
||||||
private ArrayList<String> classes=new ArrayList<String>();
|
private ArrayList<String> classes=new ArrayList<String>();
|
||||||
|
|
||||||
public ClassTransformer() {
|
public ClassTransformer() {
|
||||||
ModSystemTweaker.logger.info("ClassTransformer Begin");
|
ModSystemTweaker.logger.info("ClassTransformer Begin");
|
||||||
try {
|
try {
|
||||||
URLClassLoader ucl = (URLClassLoader)this.getClass().getClassLoader();
|
URLClassLoader ucl = (URLClassLoader)this.getClass().getClassLoader();
|
||||||
URL urls[] = ucl.getURLs();
|
URL urls[] = ucl.getURLs();
|
||||||
for (URL url : urls) {
|
for (URL url : urls) {
|
||||||
if(MinecraftUtil.isCoreFile(url)){
|
if(MinecraftUtil.isCoreFile(url)){
|
||||||
ModSystemTweaker.logger.debug(url.toString()+" : SKIP (core file).");
|
ModSystemTweaker.logger.debug(url.toString()+" : SKIP (core file).");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(MinecraftUtil.isLibraryFile(url)){
|
if(MinecraftUtil.isLibraryFile(url)){
|
||||||
ModSystemTweaker.logger.debug(url.toString()+" : SKIP (library file).");
|
ModSystemTweaker.logger.debug(url.toString()+" : SKIP (library file).");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
File file = new File(url.toURI());
|
File file = new File(url.toURI());
|
||||||
if(file==null||!file.isFile()){
|
if(file==null||!file.isFile()){
|
||||||
ModSystemTweaker.logger.info(url.toString()+" : EXCEPTION (file not found).");
|
ModSystemTweaker.logger.info(url.toString()+" : EXCEPTION (file not found).");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ZipFile tempZipFile = getZipFile(file);
|
ZipFile tempZipFile = getZipFile(file);
|
||||||
if(tempZipFile==null){
|
if(tempZipFile==null){
|
||||||
ModSystemTweaker.logger.info(url.toString()+" : EXCEPTION (^ Message ^).");
|
ModSystemTweaker.logger.info(url.toString()+" : EXCEPTION (^ Message ^).");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tempZipFile.getEntry("customskinloader/tweaker/ClassTransformer.class") == null){
|
if (tempZipFile.getEntry("customskinloader/tweaker/ClassTransformer.class") == null){
|
||||||
tempZipFile.close();
|
tempZipFile.close();
|
||||||
ModSystemTweaker.logger.debug(url.toString()+" : FINISH (not target).");
|
ModSystemTweaker.logger.debug(url.toString()+" : FINISH (not target).");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
zipFile = tempZipFile;
|
zipFile = tempZipFile;
|
||||||
Enumeration<ZipEntry> entries=(Enumeration<ZipEntry>) zipFile.entries();
|
Enumeration<ZipEntry> entries=(Enumeration<ZipEntry>) zipFile.entries();
|
||||||
StringBuilder sb=new StringBuilder();
|
StringBuilder sb=new StringBuilder();
|
||||||
while(entries.hasMoreElements()){
|
while(entries.hasMoreElements()){
|
||||||
ZipEntry entry=entries.nextElement();
|
ZipEntry entry=entries.nextElement();
|
||||||
String name=entry.getName();
|
String name=entry.getName();
|
||||||
if(name.endsWith(".class")&&(!name.contains("/")||name.startsWith("net"))){
|
if(name.endsWith(".class")&&(!name.contains("/")||name.startsWith("net"))){
|
||||||
classes.add(name);
|
classes.add(name);
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
sb.append(name);
|
sb.append(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ModSystemTweaker.logger.info(url.toString()+" : CHOOSE.");
|
ModSystemTweaker.logger.info(url.toString()+" : CHOOSE.");
|
||||||
ModSystemTweaker.logger.info("Classes:" + sb.toString());
|
ModSystemTweaker.logger.info("Classes:" + sb.toString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ModSystemTweaker.logger.warning(e);
|
ModSystemTweaker.logger.warning(e);
|
||||||
}
|
}
|
||||||
if (zipFile == null) {
|
if (zipFile == null) {
|
||||||
ModSystemTweaker.logger.info("Can not find JAR in the classpath.");
|
ModSystemTweaker.logger.info("Can not find JAR in the classpath.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ZipFile getZipFile(File file)
|
private static ZipFile getZipFile(File file)
|
||||||
{
|
{
|
||||||
ZipFile zipFile0=null;
|
ZipFile zipFile0=null;
|
||||||
try {
|
try {
|
||||||
zipFile0 = new ZipFile(file);
|
zipFile0 = new ZipFile(file);
|
||||||
return zipFile0;
|
return zipFile0;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ModSystemTweaker.logger.warning(e);
|
ModSystemTweaker.logger.warning(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] transform(String name, String transformedName, byte bytes[]) {
|
public byte[] transform(String name, String transformedName, byte bytes[]) {
|
||||||
if (zipFile == null)
|
if (zipFile == null)
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
||||||
String fullName = new StringBuilder().append(name.startsWith("net") ? name.replaceAll("\\.", "\\/") : name).append(".class").toString();//Notch(Run)/MCP(Dev) Class Name
|
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(!classes.contains(fullName)){//Check Name
|
||||||
if(name.equals(transformedName))
|
if(name.equals(transformedName))
|
||||||
return bytes;
|
return bytes;
|
||||||
fullName = new StringBuilder().append(transformedName.replaceAll("\\.", "\\/")).append(".class").toString();//MCP Class Name
|
fullName = new StringBuilder().append(transformedName.replaceAll("\\.", "\\/")).append(".class").toString();//MCP Class Name
|
||||||
if(!classes.contains(fullName))//check Again
|
if(!classes.contains(fullName))//check Again
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
ZipEntry ze = zipFile.getEntry(fullName);
|
ZipEntry ze = zipFile.getEntry(fullName);
|
||||||
if (ze == null)
|
if (ze == null)
|
||||||
return bytes;
|
return bytes;
|
||||||
byte diBytes[] = getClass(ze);
|
byte diBytes[] = getClass(ze);
|
||||||
if (diBytes != null) {
|
if (diBytes != null) {
|
||||||
ModSystemTweaker.logger.info("Class '" + name + "'("+transformedName+") transformed.");
|
ModSystemTweaker.logger.info("Class '" + name + "'("+transformedName+") transformed.");
|
||||||
return diBytes;
|
return diBytes;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getClass(ZipEntry ze) {
|
private byte[] getClass(ZipEntry ze) {
|
||||||
try {
|
try {
|
||||||
InputStream is = zipFile.getInputStream(ze);
|
InputStream is = zipFile.getInputStream(ze);
|
||||||
byte[] bytes = IOUtils.toByteArray(is);
|
byte[] bytes = IOUtils.toByteArray(is);
|
||||||
if ((long)bytes.length == ze.getSize())
|
if ((long)bytes.length == ze.getSize())
|
||||||
return bytes;
|
return bytes;
|
||||||
ModSystemTweaker.logger.info("Failed: " + ze.getName() + " " + bytes.length + " / " + ze.getSize());
|
ModSystemTweaker.logger.info("Failed: " + ze.getName() + " " + bytes.length + " / " + ze.getSize());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,30 +9,30 @@ import net.minecraft.launchwrapper.ITweaker;
|
|||||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||||
|
|
||||||
public class ModSystemTweaker implements ITweaker {
|
public class ModSystemTweaker implements ITweaker {
|
||||||
|
|
||||||
public static Logger logger = new Logger();
|
public static Logger logger = new Logger();
|
||||||
|
|
||||||
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
|
public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {
|
||||||
File tweakerLogFile = new File(gameDir,"CustomSkinLoader/Tweaker.log");
|
File tweakerLogFile = new File(gameDir,"CustomSkinLoader/Tweaker.log");
|
||||||
logger = new Logger(tweakerLogFile);
|
logger = new Logger(tweakerLogFile);
|
||||||
|
|
||||||
logger.info("Using ModSystemTweaker");
|
logger.info("Using ModSystemTweaker");
|
||||||
logger.info("ModSystemTweaker: acceptOptions");
|
logger.info("ModSystemTweaker: acceptOptions");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||||
logger.info("ModSystemTweaker: injectIntoClassLoader");
|
logger.info("ModSystemTweaker: injectIntoClassLoader");
|
||||||
classLoader.registerTransformer("customskinloader.tweaker.ClassTransformer");
|
classLoader.registerTransformer("customskinloader.tweaker.ClassTransformer");
|
||||||
logger.info("ClassTransformer Registered");
|
logger.info("ClassTransformer Registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLaunchTarget() {
|
public String getLaunchTarget() {
|
||||||
logger.info("ModSystemTweaker: getLaunchTarget");
|
logger.info("ModSystemTweaker: getLaunchTarget");
|
||||||
return "net.minecraft.client.main.Main";
|
return "net.minecraft.client.main.Main";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getLaunchArguments() {
|
public String[] getLaunchArguments() {
|
||||||
logger.info("ModSystemTweaker: getLaunchArguments");
|
logger.info("ModSystemTweaker: getLaunchArguments");
|
||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,33 +12,33 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
|||||||
|
|
||||||
public class Tweaker implements ITweaker {
|
public class Tweaker implements ITweaker {
|
||||||
|
|
||||||
private String[] args;
|
private String[] args;
|
||||||
|
|
||||||
public static Logger logger = new Logger();
|
public static Logger logger = new Logger();
|
||||||
|
|
||||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||||
File tweakerLogFile = new File(gameDir,"CustomSkinLoader/Tweaker.log");
|
File tweakerLogFile = new File(gameDir,"CustomSkinLoader/Tweaker.log");
|
||||||
logger = new Logger(tweakerLogFile);
|
logger = new Logger(tweakerLogFile);
|
||||||
|
|
||||||
logger.info("Using Tweaker");
|
logger.info("Using Tweaker");
|
||||||
logger.info("Tweaker: acceptOptions");
|
logger.info("Tweaker: acceptOptions");
|
||||||
|
|
||||||
String[] temp={"--gameDir",gameDir.getAbsolutePath(),"--assetsDir",assetsDir.getAbsolutePath(),"--version",profile};
|
String[] temp={"--gameDir",gameDir.getAbsolutePath(),"--assetsDir",assetsDir.getAbsolutePath(),"--version",profile};
|
||||||
this.args=ArrayUtils.addAll(args.toArray(new String[args.size()]), temp);
|
this.args=ArrayUtils.addAll(args.toArray(new String[args.size()]), temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||||
logger.info("Tweaker: injectIntoClassLoader");
|
logger.info("Tweaker: injectIntoClassLoader");
|
||||||
logger.info("Loaded as a library.");
|
logger.info("Loaded as a library.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLaunchTarget() {
|
public String getLaunchTarget() {
|
||||||
logger.info("Tweaker: getLaunchTarget");
|
logger.info("Tweaker: getLaunchTarget");
|
||||||
return "net.minecraft.client.main.Main";
|
return "net.minecraft.client.main.Main";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getLaunchArguments() {
|
public String[] getLaunchArguments() {
|
||||||
logger.info("Tweaker: getLaunchArguments");
|
logger.info("Tweaker: getLaunchArguments");
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,193 +20,194 @@ 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 int cacheTime=600;//-1=No Cache 0=Always Cache t=Default Cache Time(second)
|
||||||
public File cacheFile=null;//Default Cache File
|
public File cacheFile=null;//Default Cache File
|
||||||
|
|
||||||
public HttpRequest(String url){
|
public HttpRequest(String url){
|
||||||
this.url=url;
|
this.url=url;
|
||||||
}
|
}
|
||||||
public HttpRequest setUserAgent(String userAgent){
|
public HttpRequest setUserAgent(String userAgent){
|
||||||
this.userAgent=userAgent;
|
this.userAgent=userAgent;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public HttpRequest setPayload(String payload){
|
public HttpRequest setPayload(String payload){
|
||||||
this.payload=payload;
|
this.payload=payload;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public HttpRequest setLoadContent(boolean loadContent){
|
public HttpRequest setLoadContent(boolean loadContent){
|
||||||
this.loadContent=loadContent;
|
this.loadContent=loadContent;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public HttpRequest setCheckPNG(boolean checkPNG){
|
public HttpRequest setCheckPNG(boolean checkPNG){
|
||||||
this.checkPNG=checkPNG;
|
this.checkPNG=checkPNG;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public HttpRequest setCacheTime(int cacheTime){
|
public HttpRequest setCacheTime(int cacheTime){
|
||||||
this.cacheTime=cacheTime;
|
this.cacheTime=cacheTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public HttpRequest setCacheFile(File cacheFile){
|
public HttpRequest setCacheFile(File cacheFile){
|
||||||
this.cacheFile=cacheFile;
|
this.cacheFile=cacheFile;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class HttpResponce{
|
public static class HttpResponce{
|
||||||
public String content=null;
|
public String content=null;
|
||||||
public int responceCode=-1;
|
public int responceCode=-1;
|
||||||
public boolean success=false;
|
public boolean success=false;
|
||||||
public boolean fromCache=false;
|
public boolean fromCache=false;
|
||||||
}
|
}
|
||||||
public static class CacheInfo{
|
public static class CacheInfo{
|
||||||
public String url;
|
public String url;
|
||||||
public String etag=null;
|
public String etag=null;
|
||||||
|
|
||||||
public long lastModified=-1;//ms
|
public long lastModified=-1;//ms
|
||||||
public long expire=-1;//UNIX timestamp
|
public long expire=-1;//UNIX timestamp
|
||||||
}
|
}
|
||||||
public static final File CACHE_DIR=new File(CustomSkinLoader.DATA_DIR,"caches");
|
public static final File CACHE_DIR=new File(CustomSkinLoader.DATA_DIR,"caches");
|
||||||
|
|
||||||
public static HttpResponce makeHttpRequest(HttpRequest request){
|
public static HttpResponce makeHttpRequest(HttpRequest request){
|
||||||
try{
|
try{
|
||||||
CustomSkinLoader.logger.info("Try to request '"+request.url+(request.userAgent==null?"'.":"' with user agent '"+request.userAgent+"'."));
|
CustomSkinLoader.logger.debug("Try to request '"+request.url+(request.userAgent==null?"'.":"' with user agent '"+request.userAgent+"'."));
|
||||||
//Check Cache
|
//Check Cache
|
||||||
if(StringUtils.isNotEmpty(request.payload))
|
if(StringUtils.isNotEmpty(request.payload))
|
||||||
request.cacheTime=-1;//No Cache
|
request.cacheTime=-1;//No Cache
|
||||||
File cacheInfoFile=null;
|
File cacheInfoFile=null;
|
||||||
CacheInfo cacheInfo=new CacheInfo();
|
CacheInfo cacheInfo=new CacheInfo();
|
||||||
if(request.cacheFile==null && request.cacheTime>=0){
|
if(request.cacheFile==null && request.cacheTime>=0){
|
||||||
String hash=DigestUtils.sha1Hex(request.url);
|
String hash=DigestUtils.sha1Hex(request.url);
|
||||||
request.cacheFile=new File(CACHE_DIR,hash);
|
request.cacheFile=new File(CACHE_DIR,hash);
|
||||||
cacheInfoFile=new File(CACHE_DIR,hash+".json");
|
cacheInfoFile=new File(CACHE_DIR,hash+".json");
|
||||||
}
|
}
|
||||||
if(request.cacheTime==0 && request.cacheFile.isFile())
|
if(request.cacheTime==0 && request.cacheFile.isFile())
|
||||||
return loadFromCache(request,new HttpResponce());
|
return loadFromCache(request,new HttpResponce());
|
||||||
if(cacheInfoFile!=null&&cacheInfoFile.isFile()){
|
if(cacheInfoFile!=null&&cacheInfoFile.isFile()){
|
||||||
String json=FileUtils.readFileToString(cacheInfoFile);
|
String json=FileUtils.readFileToString(cacheInfoFile);
|
||||||
if(StringUtils.isNotEmpty(json))
|
if(StringUtils.isNotEmpty(json))
|
||||||
cacheInfo=CustomSkinLoader.GSON.fromJson(json, CacheInfo.class);
|
cacheInfo=CustomSkinLoader.GSON.fromJson(json, CacheInfo.class);
|
||||||
if(cacheInfo==null)
|
if(cacheInfo==null)
|
||||||
cacheInfo=new CacheInfo();
|
cacheInfo=new CacheInfo();
|
||||||
if(cacheInfo.expire>=TimeUtil.getCurrentUnixTimestamp())
|
if(cacheInfo.expire>=TimeUtil.getCurrentUnixTimestamp())
|
||||||
return loadFromCache(request,new HttpResponce(),cacheInfo.expire);
|
return loadFromCache(request,new HttpResponce(),cacheInfo.expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Init Connection
|
//Init Connection
|
||||||
String url=new URI(request.url).toASCIIString();
|
String url=new URI(request.url).toASCIIString();
|
||||||
if(!url.equalsIgnoreCase(request.url))
|
if(!url.equalsIgnoreCase(request.url))
|
||||||
CustomSkinLoader.logger.info("Encoded URL: "+url);
|
CustomSkinLoader.logger.debug("Encoded URL: "+url);
|
||||||
HttpURLConnection c = (HttpURLConnection) (new URL(url)).openConnection();
|
HttpURLConnection c = (HttpURLConnection) (new URL(url)).openConnection();
|
||||||
c.setReadTimeout(1000 * 10);
|
c.setReadTimeout(1000 * 10);
|
||||||
c.setConnectTimeout(1000 * 10);
|
c.setConnectTimeout(1000 * 10);
|
||||||
c.setDoInput(true);
|
c.setDoInput(true);
|
||||||
c.setUseCaches(false);
|
c.setUseCaches(false);
|
||||||
c.setInstanceFollowRedirects(true);
|
c.setInstanceFollowRedirects(true);
|
||||||
|
|
||||||
//Make Connection
|
//Make Connection
|
||||||
if(cacheInfo.lastModified>=0)
|
if(cacheInfo.lastModified>=0)
|
||||||
c.setIfModifiedSince(cacheInfo.lastModified);
|
c.setIfModifiedSince(cacheInfo.lastModified);
|
||||||
if(cacheInfo.etag!=null)
|
if(cacheInfo.etag!=null)
|
||||||
c.setRequestProperty("If-None-Match",cacheInfo.etag);
|
c.setRequestProperty("If-None-Match",cacheInfo.etag);
|
||||||
c.setRequestProperty("Accept-Encoding","gzip");
|
c.setRequestProperty("Accept-Encoding","gzip");
|
||||||
if(request.userAgent!=null)
|
if(request.userAgent!=null)
|
||||||
c.setRequestProperty("User-Agent",request.userAgent);
|
c.setRequestProperty("User-Agent",request.userAgent);
|
||||||
if(StringUtils.isNotEmpty(request.payload)){
|
if(StringUtils.isNotEmpty(request.payload)){
|
||||||
CustomSkinLoader.logger.info("Payload: "+request.payload);
|
CustomSkinLoader.logger.info("Payload: "+request.payload);
|
||||||
c.setDoOutput(true);
|
c.setDoOutput(true);
|
||||||
OutputStream os=c.getOutputStream();
|
OutputStream os=c.getOutputStream();
|
||||||
IOUtils.write(request.payload, os);
|
IOUtils.write(request.payload, os);
|
||||||
IOUtils.closeQuietly(os);
|
IOUtils.closeQuietly(os);
|
||||||
}
|
}
|
||||||
c.connect();
|
c.connect();
|
||||||
|
|
||||||
//Check Connection
|
//Check Connection
|
||||||
HttpResponce responce=new HttpResponce();
|
HttpResponce responce=new HttpResponce();
|
||||||
responce.responceCode=c.getResponseCode();
|
responce.responceCode=c.getResponseCode();
|
||||||
int res=c.getResponseCode()/100;
|
int res=c.getResponseCode()/100;
|
||||||
if(res==4||res==5){//Failed
|
if(res==4||res==5){//Failed
|
||||||
CustomSkinLoader.logger.info("Failed to request (Response Code: "+c.getResponseCode()+")");
|
CustomSkinLoader.logger.debug("Failed to request (Response Code: "+c.getResponseCode()+")");
|
||||||
return responce;
|
return responce;
|
||||||
}
|
}
|
||||||
responce.success=true;
|
responce.success=true;
|
||||||
CustomSkinLoader.logger.info("Successfully request (Response Code: "+c.getResponseCode()+" , Content Length: "+c.getContentLength()+")");
|
CustomSkinLoader.logger.debug("Successfully request (Response Code: "+c.getResponseCode()+" , Content Length: "+c.getContentLength()+")");
|
||||||
if(responce.responceCode==HttpURLConnection.HTTP_NOT_MODIFIED)
|
if(responce.responceCode==HttpURLConnection.HTTP_NOT_MODIFIED)
|
||||||
return loadFromCache(request,responce);
|
return loadFromCache(request,responce);
|
||||||
|
|
||||||
//Load Content
|
//Load Content
|
||||||
InputStream is="gzip".equals(c.getContentEncoding())?new GZIPInputStream(c.getInputStream()):c.getInputStream();
|
InputStream is="gzip".equals(c.getContentEncoding())?new GZIPInputStream(c.getInputStream()):c.getInputStream();
|
||||||
byte [] bytes = IOUtils.toByteArray(is);
|
byte [] bytes = IOUtils.toByteArray(is);
|
||||||
if(request.checkPNG&&(bytes.length<=4||bytes[1]!=(byte)'P'||bytes[2]!=(byte)'N'||bytes[3]!=(byte)'G')){
|
if(request.checkPNG&&(bytes.length<=4||bytes[1]!=(byte)'P'||bytes[2]!=(byte)'N'||bytes[3]!=(byte)'G')){
|
||||||
CustomSkinLoader.logger.info("Failed to request (Not Standard PNG)");
|
CustomSkinLoader.logger.debug("Failed to request (Not Standard PNG)");
|
||||||
responce.success=false;
|
responce.success=false;
|
||||||
return responce;
|
return responce;
|
||||||
}
|
}
|
||||||
if(request.cacheFile!=null){
|
if(request.cacheFile!=null){
|
||||||
FileUtils.writeByteArrayToFile(request.cacheFile, bytes);
|
FileUtils.writeByteArrayToFile(request.cacheFile, bytes);
|
||||||
if(cacheInfoFile!=null){
|
if(cacheInfoFile!=null){
|
||||||
cacheInfo.url=request.url;
|
cacheInfo.url=request.url;
|
||||||
cacheInfo.etag=c.getHeaderField("ETag");
|
cacheInfo.etag=c.getHeaderField("ETag");
|
||||||
cacheInfo.lastModified=c.getLastModified();
|
cacheInfo.lastModified=c.getLastModified();
|
||||||
cacheInfo.expire=getExpire(c,request.cacheTime);
|
cacheInfo.expire=getExpire(c,request.cacheTime);
|
||||||
FileUtils.write(cacheInfoFile, CustomSkinLoader.GSON.toJson(cacheInfo));
|
FileUtils.write(cacheInfoFile, CustomSkinLoader.GSON.toJson(cacheInfo));
|
||||||
}
|
}
|
||||||
CustomSkinLoader.logger.info("Saved to cache (Length: "+request.cacheFile.length()+" , Path: '"+request.cacheFile.getAbsolutePath()+"' , Expire: "+cacheInfo.expire+")");
|
CustomSkinLoader.logger.debug("Saved to cache (Length: "+request.cacheFile.length()+" , Path: '"+request.cacheFile.getAbsolutePath()+"' , Expire: "+cacheInfo.expire+")");
|
||||||
}
|
}
|
||||||
if(!request.loadContent)
|
if(!request.loadContent)
|
||||||
return responce;
|
return responce;
|
||||||
responce.content=new String(bytes,Charsets.UTF_8);
|
responce.content=new String(bytes,Charsets.UTF_8);
|
||||||
CustomSkinLoader.logger.info("Content: "+responce.content);
|
CustomSkinLoader.logger.debug("Content: "+responce.content);
|
||||||
return responce;
|
return responce;
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
CustomSkinLoader.logger.info("Failed to request (Exception: "+e.toString()+")");
|
CustomSkinLoader.logger.debug("Failed to request (Exception: "+e.toString()+")");
|
||||||
return loadFromCache(request,new HttpResponce());
|
return loadFromCache(request,new HttpResponce());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getCacheFile(String hash){
|
public static File getCacheFile(String hash){
|
||||||
return new File(CACHE_DIR,hash);
|
return new File(CACHE_DIR,hash);
|
||||||
}
|
}
|
||||||
private static HttpResponce loadFromCache(HttpRequest request,HttpResponce responce){
|
private static HttpResponce loadFromCache(HttpRequest request,HttpResponce responce){
|
||||||
return loadFromCache(request,responce,0);
|
return loadFromCache(request,responce,0);
|
||||||
}
|
}
|
||||||
private static HttpResponce loadFromCache(HttpRequest request,HttpResponce responce,long expireTime){
|
private static HttpResponce loadFromCache(HttpRequest request,HttpResponce responce,long expireTime){
|
||||||
if(request.cacheFile==null||!request.cacheFile.isFile())
|
if(request.cacheFile==null||!request.cacheFile.isFile())
|
||||||
return responce;
|
return responce;
|
||||||
CustomSkinLoader.logger.info("Cache file found (Length: "+request.cacheFile.length()+" , Path: '"+request.cacheFile.getAbsolutePath()+"' , Expire: "+expireTime+"')");
|
CustomSkinLoader.logger.debug("Cache file found (Length: "+request.cacheFile.length()+" , Path: '"+request.cacheFile.getAbsolutePath()+"' , Expire: "+expireTime+"')");
|
||||||
responce.fromCache=true;
|
responce.fromCache=true;
|
||||||
responce.success=true;
|
responce.success=true;
|
||||||
if(!request.loadContent)
|
if(!request.loadContent)
|
||||||
return responce;
|
return responce;
|
||||||
|
|
||||||
CustomSkinLoader.logger.info("Try to load from cache '"+request.cacheFile.getAbsolutePath()+"'.");
|
CustomSkinLoader.logger.info("Try to load from cache '"+request.cacheFile.getAbsolutePath()+"'.");
|
||||||
try {
|
try {
|
||||||
responce.content=FileUtils.readFileToString(request.cacheFile);
|
responce.content=FileUtils.readFileToString(request.cacheFile);
|
||||||
CustomSkinLoader.logger.info("Successfully to load from cache");
|
CustomSkinLoader.logger.debug("Successfully load from cache");
|
||||||
} catch (IOException e) {
|
CustomSkinLoader.logger.debug("Content: "+responce.content);
|
||||||
CustomSkinLoader.logger.info("Failed to load from cache (Exception: "+e.toString()+")");
|
} catch (IOException e) {
|
||||||
responce.success=false;
|
CustomSkinLoader.logger.debug("Failed to load from cache (Exception: "+e.toString()+")");
|
||||||
}
|
responce.success=false;
|
||||||
return responce;
|
}
|
||||||
}
|
return responce;
|
||||||
private final static Pattern MAX_AGE_PATTERN = Pattern.compile(".*?max-age=(\\d+).*?");
|
}
|
||||||
private static long getExpire(HttpURLConnection connection,int cacheTime){
|
private final static Pattern MAX_AGE_PATTERN = Pattern.compile(".*?max-age=(\\d+).*?");
|
||||||
String cacheControl=connection.getHeaderField("Cache-Control");
|
private static long getExpire(HttpURLConnection connection,int cacheTime){
|
||||||
if(StringUtils.isNotEmpty(cacheControl)){
|
String cacheControl=connection.getHeaderField("Cache-Control");
|
||||||
Matcher m=MAX_AGE_PATTERN.matcher(cacheControl);
|
if(StringUtils.isNotEmpty(cacheControl)){
|
||||||
if(m!=null && m.matches())
|
Matcher m=MAX_AGE_PATTERN.matcher(cacheControl);
|
||||||
return TimeUtil.getUnixTimestamp(Long.parseLong(m.group(m.groupCount())));
|
if(m!=null && m.matches())
|
||||||
}
|
return TimeUtil.getUnixTimestamp(Long.parseLong(m.group(m.groupCount())));
|
||||||
long expires=connection.getExpiration();
|
}
|
||||||
if(expires>0)
|
long expires=connection.getExpiration();
|
||||||
return expires/1000;
|
if(expires>0)
|
||||||
return TimeUtil.getUnixTimestampRandomDelay(cacheTime==0 ? 86400 : cacheTime);
|
return expires/1000;
|
||||||
|
return TimeUtil.getUnixTimestampRandomDelay(cacheTime==0 ? 86400 : cacheTime);
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,75 +8,75 @@ import org.apache.commons.io.FilenameUtils;
|
|||||||
import customskinloader.CustomSkinLoader;
|
import customskinloader.CustomSkinLoader;
|
||||||
|
|
||||||
public class HttpTextureUtil {
|
public class HttpTextureUtil {
|
||||||
public static class HttpTextureInfo{
|
public static class HttpTextureInfo{
|
||||||
public String url="";
|
public String url="";
|
||||||
public File cacheFile;
|
public File cacheFile;
|
||||||
public String hash;
|
public String hash;
|
||||||
}
|
}
|
||||||
private static final String
|
private static final String
|
||||||
LEGACY_MARK="(LEGACY)",
|
LEGACY_MARK="(LEGACY)",
|
||||||
LOCAL_MARK="(LOCAL)",
|
LOCAL_MARK="(LOCAL)",
|
||||||
LOCAL_LEGACY_MARK="(LOCAL_LEGACY)";
|
LOCAL_LEGACY_MARK="(LOCAL_LEGACY)";
|
||||||
public static File defaultCacheDir;
|
public static File defaultCacheDir;
|
||||||
public static void cleanCacheDir(){
|
public static void cleanCacheDir(){
|
||||||
if(defaultCacheDir!=null){
|
if(defaultCacheDir!=null){
|
||||||
defaultCacheDir.delete();
|
defaultCacheDir.delete();
|
||||||
defaultCacheDir.mkdirs();
|
defaultCacheDir.mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static File getCacheDir(){
|
public static File getCacheDir(){
|
||||||
return defaultCacheDir==null?new File(MinecraftUtil.getMinecraftDataDir(),"assets/skins"):defaultCacheDir;
|
return defaultCacheDir==null?new File(MinecraftUtil.getMinecraftDataDir(),"assets/skins"):defaultCacheDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl){
|
public static HttpTextureInfo toHttpTextureInfo(String fakeUrl){
|
||||||
HttpTextureInfo info=new HttpTextureInfo();
|
HttpTextureInfo info=new HttpTextureInfo();
|
||||||
if(fakeUrl.startsWith("http")){
|
if(fakeUrl.startsWith("http")){
|
||||||
info.url=fakeUrl;
|
info.url=fakeUrl;
|
||||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
||||||
info.cacheFile=getCacheFile(info.hash);
|
info.cacheFile=getCacheFile(info.hash);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
if(fakeUrl.startsWith(LOCAL_LEGACY_MARK)){
|
if(fakeUrl.startsWith(LOCAL_LEGACY_MARK)){
|
||||||
fakeUrl=fakeUrl.replace(LOCAL_LEGACY_MARK, "");
|
fakeUrl=fakeUrl.replace(LOCAL_LEGACY_MARK, "");
|
||||||
String[] t=fakeUrl.split(",",2);
|
String[] t=fakeUrl.split(",",2);
|
||||||
if(t.length!=2)
|
if(t.length!=2)
|
||||||
return info;
|
return info;
|
||||||
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,t[1]);
|
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,t[1]);
|
||||||
info.hash=t[0];
|
info.hash=t[0];
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
if(fakeUrl.startsWith(LOCAL_MARK)){
|
if(fakeUrl.startsWith(LOCAL_MARK)){
|
||||||
fakeUrl=fakeUrl.replace(LOCAL_MARK, "");
|
fakeUrl=fakeUrl.replace(LOCAL_MARK, "");
|
||||||
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,fakeUrl);
|
info.cacheFile=new File(CustomSkinLoader.DATA_DIR,fakeUrl);
|
||||||
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
info.hash=FilenameUtils.getBaseName(fakeUrl);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
if(fakeUrl.startsWith(LEGACY_MARK)){
|
if(fakeUrl.startsWith(LEGACY_MARK)){
|
||||||
fakeUrl=fakeUrl.replace(LEGACY_MARK, "");
|
fakeUrl=fakeUrl.replace(LEGACY_MARK, "");
|
||||||
info.url=fakeUrl;
|
info.url=fakeUrl;
|
||||||
info.hash=DigestUtils.sha1Hex(info.url);;
|
info.hash=DigestUtils.sha1Hex(info.url);;
|
||||||
info.cacheFile=HttpTextureUtil.getCacheFile(info.hash);
|
info.cacheFile=HttpTextureUtil.getCacheFile(info.hash);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLegacyFakeUrl(String url){
|
public static String getLegacyFakeUrl(String url){
|
||||||
return LEGACY_MARK+url;
|
return LEGACY_MARK+url;
|
||||||
}
|
}
|
||||||
public static String getLocalFakeUrl(String path){
|
public static String getLocalFakeUrl(String path){
|
||||||
return LOCAL_MARK+path;
|
return LOCAL_MARK+path;
|
||||||
}
|
}
|
||||||
public static String getLocalLegacyFakeUrl(String path,String hash){
|
public static String getLocalLegacyFakeUrl(String path,String hash){
|
||||||
return LOCAL_LEGACY_MARK+hash+","+path;
|
return LOCAL_LEGACY_MARK+hash+","+path;
|
||||||
}
|
}
|
||||||
public static String getHash(String url,long size,long lastModified){
|
public static String getHash(String url,long size,long lastModified){
|
||||||
return DigestUtils.sha1Hex(size+url+lastModified);
|
return DigestUtils.sha1Hex(size+url+lastModified);
|
||||||
}
|
}
|
||||||
public static File getCacheFile(String hash){
|
public static File getCacheFile(String hash){
|
||||||
return getCacheFile(defaultCacheDir,hash);
|
return getCacheFile(defaultCacheDir,hash);
|
||||||
}
|
}
|
||||||
public static File getCacheFile(File cacheDir,String hash){
|
public static File getCacheFile(File cacheDir,String hash){
|
||||||
return new File(new File(cacheDir,hash.length()>2?hash.substring(0,2):"xx"), hash);
|
return new File(new File(cacheDir,hash.length()>2?hash.substring(0,2):"xx"), hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,66 +14,66 @@ 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? false : !url.startsWith("http");
|
||||||
}
|
}
|
||||||
|
|
||||||
//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.setDefaultHostnameVerifier(doNotVerify);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parseAddress(String address) {
|
public static String parseAddress(String address) {
|
||||||
if(StringUtils.isEmpty(address))
|
if(StringUtils.isEmpty(address))
|
||||||
return null;
|
return null;
|
||||||
String[] addresses=address.split(":");
|
String[] addresses=address.split(":");
|
||||||
InetAddress add;
|
InetAddress add;
|
||||||
try {
|
try {
|
||||||
add = InetAddress.getByName(addresses[0]);
|
add = InetAddress.getByName(addresses[0]);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
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){
|
public static boolean isLanServer(String standardAddress){
|
||||||
if(StringUtils.isEmpty(standardAddress))
|
if(StringUtils.isEmpty(standardAddress))
|
||||||
return true;
|
return true;
|
||||||
String[] addresses=standardAddress.split(":");
|
String[] addresses=standardAddress.split(":");
|
||||||
int numIp=getNumIp(addresses[0]);
|
int numIp=getNumIp(addresses[0]);
|
||||||
return numIp==0||numIp==getNumIp("127.0.0.1")||
|
return numIp==0||numIp==getNumIp("127.0.0.1")||
|
||||||
(numIp>=getNumIp("192.168.0.0")&&numIp<=getNumIp("192.168.255.255"))||
|
(numIp>=getNumIp("192.168.0.0")&&numIp<=getNumIp("192.168.255.255"))||
|
||||||
(numIp>=getNumIp("10.0.0.0")&&numIp<=getNumIp("10.255.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"));
|
(numIp>=getNumIp("172.16.0.0")&&numIp<=getNumIp("172.31.255.255"));
|
||||||
}
|
}
|
||||||
public static int getNumIp(String ip){
|
public static int getNumIp(String ip){
|
||||||
int num=0;
|
int num=0;
|
||||||
String[] ips=ip.split("\\.");
|
String[] ips=ip.split("\\.");
|
||||||
if(ips.length!=4)
|
if(ips.length!=4)
|
||||||
return 0;
|
return 0;
|
||||||
for(int i=0;i<4;i++)
|
for(int i=0;i<4;i++)
|
||||||
num+=Integer.parseInt(ips[i])*(256^(3-i));
|
num+=Integer.parseInt(ips[i])*(256^(3-i));
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
@@ -20,105 +21,110 @@ import net.minecraft.client.renderer.texture.TextureManager;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MinecraftUtil {
|
public class MinecraftUtil {
|
||||||
public static File getMinecraftDataDir(){
|
public static File getMinecraftDataDir(){
|
||||||
return net.minecraft.client.Minecraft.getMinecraft().mcDataDir;
|
return net.minecraft.client.Minecraft.getMinecraft().mcDataDir;
|
||||||
}
|
}
|
||||||
public static MinecraftSessionService getSessionService(){
|
public static MinecraftSessionService getSessionService(){
|
||||||
return net.minecraft.client.Minecraft.getMinecraft().getSessionService();
|
return net.minecraft.client.Minecraft.getMinecraft().getSessionService();
|
||||||
}
|
}
|
||||||
public static TextureManager getTextureManager(){
|
public static TextureManager getTextureManager(){
|
||||||
return net.minecraft.client.Minecraft.getMinecraft().getTextureManager();
|
return net.minecraft.client.Minecraft.getMinecraft().getTextureManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<String> minecraftVersion=new ArrayList<String>();
|
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*).*?");
|
private final static Pattern MINECRAFT_VERSION_PATTERN = Pattern.compile(".*?(\\d+\\.\\d+[\\.]?\\d*).*?");
|
||||||
public static ArrayList<String> getMinecraftVersions(){
|
public static ArrayList<String> getMinecraftVersions(){
|
||||||
if(minecraftVersion!=null&&!minecraftVersion.isEmpty())
|
if(minecraftVersion!=null&&!minecraftVersion.isEmpty())
|
||||||
return minecraftVersion;
|
return minecraftVersion;
|
||||||
testProbe();
|
testProbe();
|
||||||
return minecraftVersion;
|
return minecraftVersion;
|
||||||
}
|
}
|
||||||
public static String getMinecraftVersionText(){
|
public static String getMinecraftVersionText(){
|
||||||
StringBuilder sb=new StringBuilder();
|
StringBuilder sb=new StringBuilder();
|
||||||
for(String version:getMinecraftVersions())
|
for(String version:getMinecraftVersions())
|
||||||
sb.append(version).append(" ");
|
sb.append(version).append(" ");
|
||||||
return StringUtils.trim(sb.toString());
|
return StringUtils.trim(sb.toString());
|
||||||
}
|
}
|
||||||
public static String getMinecraftMainVersion(){
|
public static String getMinecraftMainVersion(){
|
||||||
if(minecraftMainVersion!=null)
|
if(minecraftMainVersion!=null)
|
||||||
return minecraftMainVersion;
|
return minecraftMainVersion;
|
||||||
for(String version:getMinecraftVersions()){
|
for(String version:getMinecraftVersions()){
|
||||||
Matcher m = null;
|
Matcher m = null;
|
||||||
try{
|
try{
|
||||||
m=MINECRAFT_VERSION_PATTERN.matcher(version);
|
m=MINECRAFT_VERSION_PATTERN.matcher(version);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if(m==null || !m.matches())
|
if(m==null || !m.matches())
|
||||||
continue;
|
continue;
|
||||||
minecraftMainVersion=m.group(m.groupCount());
|
minecraftMainVersion=m.group(m.groupCount());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return minecraftMainVersion;
|
return minecraftMainVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (domain|ip)(:port)
|
// (domain|ip)(:port)
|
||||||
public static String getServerAddress(){
|
public static String getServerAddress(){
|
||||||
net.minecraft.client.multiplayer.ServerData data=net.minecraft.client.Minecraft.getMinecraft().getCurrentServerData();
|
net.minecraft.client.multiplayer.ServerData data=net.minecraft.client.Minecraft.getMinecraft().getCurrentServerData();
|
||||||
if(data==null)//Single Player
|
if(data==null)//Single Player
|
||||||
return null;
|
return null;
|
||||||
return data.serverIP;
|
return data.serverIP;
|
||||||
}
|
}
|
||||||
// ip:port
|
// ip:port
|
||||||
public static String getStandardServerAddress(){
|
public static String getStandardServerAddress(){
|
||||||
return HttpUtil0.parseAddress(getServerAddress());
|
return HttpUtil0.parseAddress(getServerAddress());
|
||||||
}
|
}
|
||||||
public static boolean isLanServer(){
|
public static boolean isLanServer(){
|
||||||
return HttpUtil0.isLanServer(getStandardServerAddress());
|
return HttpUtil0.isLanServer(getStandardServerAddress());
|
||||||
}
|
}
|
||||||
public static String getCurrentUsername(){
|
public static String getCurrentUsername(){
|
||||||
return net.minecraft.client.Minecraft.getMinecraft().getSession().getProfile().getName();
|
return net.minecraft.client.Minecraft.getMinecraft().getSession().getProfile().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Pattern MINECRAFT_CORE_FILE_PATTERN = Pattern.compile("^(.*?)/versions/([^\\/\\\\]*?)/([^\\/\\\\]*?).jar$");
|
private final static Pattern MINECRAFT_CORE_FILE_PATTERN = Pattern.compile("^(.*?)/versions/([^\\/\\\\]*?)/([^\\/\\\\]*?).jar$");
|
||||||
private static void testProbe(){
|
private static void testProbe(){
|
||||||
minecraftVersion.clear();
|
minecraftVersion.clear();
|
||||||
URLClassLoader ucl = (URLClassLoader)new MinecraftUtil().getClass().getClassLoader();
|
URLClassLoader ucl = (URLClassLoader)new MinecraftUtil().getClass().getClassLoader();
|
||||||
URL urls[] = ucl.getURLs();
|
URL urls[] = ucl.getURLs();
|
||||||
for(URL url:urls){
|
for(URL url:urls){
|
||||||
Matcher m = null;
|
Matcher m = null;
|
||||||
try{
|
try{
|
||||||
m=MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
m=MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if(m==null || !m.matches())
|
if(m==null || !m.matches())
|
||||||
continue;
|
continue;
|
||||||
minecraftVersion.add(m.group(2));
|
minecraftVersion.add(m.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCoreFile(URL url){
|
public static boolean isCoreFile(URL url){
|
||||||
Matcher m = null;
|
Matcher m = null;
|
||||||
try{
|
try{
|
||||||
m=MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
m=MINECRAFT_CORE_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return m!=null && m.matches();
|
return m!=null && m.matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Pattern LIBRARY_FILE_PATTERN = Pattern.compile("^(.*?)/libraries/(.*?)/([^\\/\\\\]*?).jar$");
|
private final static Pattern LIBRARY_FILE_PATTERN = Pattern.compile("^(.*?)/libraries/(.*?)/([^\\/\\\\]*?).jar$");
|
||||||
public static boolean isLibraryFile(URL url){
|
public static boolean isLibraryFile(URL url){
|
||||||
Matcher m = null;
|
Matcher m = null;
|
||||||
try{
|
try{
|
||||||
m=LIBRARY_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
m=LIBRARY_FILE_PATTERN.matcher(URLDecoder.decode(url.getPath(),"UTF-8"));
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return m!=null && m.matches();
|
return m!=null && m.matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getCredential(GameProfile profile) {
|
||||||
|
return (profile==null || profile.hashCode()==0) ? null :
|
||||||
|
(profile.getId()==null ? profile.getName() : String.format("%s-%s", profile.getName(),profile.getId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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,2 @@
|
|||||||
|
/bin/
|
||||||
|
/build/
|
||||||
+7
-7
@@ -13,15 +13,15 @@ buildscript {
|
|||||||
}
|
}
|
||||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||||
|
|
||||||
ext.MINECRAFT_VERSION="1.12"
|
ext.MINECRAFT_VERSION="1.12.2"
|
||||||
ext.FORGE_VERSION="14.21.1.2387"
|
ext.FORGE_VERSION="14.23.2.2611"
|
||||||
ext.MAPPING_VERSION="snapshot_20170813"
|
ext.MAPPING_VERSION="snapshot_20180210"
|
||||||
ext.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"
|
ext.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"
|
||||||
|
|
||||||
ext.snapshot = !(rootProject.ext.config.snapshot==""||rootProject.ext.config.snapshot=="0"||rootProject.ext.config.snapshot==0)
|
ext.snapshot = !(rootProject.ext.config.snapshot==""||rootProject.ext.config.snapshot=="0"||rootProject.ext.config.snapshot==0)
|
||||||
|
|
||||||
archivesBaseName = "CustomSkinLoader_Forge"
|
archivesBaseName = "CustomSkinLoader_Forge"
|
||||||
version = rootProject.ext.config.version + rootProject.ext.config.dev_version + (snapshot?"-SNAPSHOT-"+System.getenv("BUILD_NUMBER"):"")
|
version = rootProject.ext.config.version + rootProject.ext.config.dev_version + (snapshot?"-SNAPSHOT-"+System.getenv("CIRCLE_BUILD_NUM"):"")
|
||||||
group = "customskinloader"
|
group = "customskinloader"
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = "1.6"
|
sourceCompatibility = targetCompatibility = "1.6"
|
||||||
@@ -85,8 +85,8 @@ processResources
|
|||||||
mcVersion :MINECRAFT_VERSION,
|
mcVersion :MINECRAFT_VERSION,
|
||||||
mcFullVersions :MINECRAFT_FULL_VERSIONS,
|
mcFullVersions :MINECRAFT_FULL_VERSIONS,
|
||||||
forgeVersion :FORGE_VERSION,
|
forgeVersion :FORGE_VERSION,
|
||||||
gitVersion :System.getenv("GIT_COMMIT"),
|
gitVersion :System.getenv("CIRCLE_SHA1"),
|
||||||
buildUrl :System.getenv("BUILD_URL")
|
buildUrl :System.getenv("CIRCLE_BUILD_URL")
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,24 +13,24 @@ import customskinloader.forge.TransformerManager.IMethodTransformer;
|
|||||||
import customskinloader.forge.TransformerManager.TransformTarget;
|
import customskinloader.forge.TransformerManager.TransformTarget;
|
||||||
|
|
||||||
public class PlayerTabTransformer {
|
public class PlayerTabTransformer {
|
||||||
@TransformTarget(className="net.minecraft.client.gui.GuiPlayerTabOverlay",
|
@TransformTarget(className="net.minecraft.client.gui.GuiPlayerTabOverlay",
|
||||||
methodNames={"func_175249_a","renderPlayerlist"},
|
methodNames={"func_175249_a","renderPlayerlist"},
|
||||||
desc="(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V")
|
desc="(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V")
|
||||||
public static class ScoreObjectiveTransformer implements IMethodTransformer{
|
public static class ScoreObjectiveTransformer implements IMethodTransformer{
|
||||||
//From: http://git.oschina.net/AsteriskTeam/TabIconHackForge/blob/master/src/main/java/kengxxiao/tabiconhack/coremod/TabIconHackForgeClassTransformer.java#L30-L43
|
//From: http://git.oschina.net/AsteriskTeam/TabIconHackForge/blob/master/src/main/java/kengxxiao/tabiconhack/coremod/TabIconHackForgeClassTransformer.java#L30-L43
|
||||||
@Override
|
@Override
|
||||||
public void transform(ClassNode cn, MethodNode mn) {
|
public void transform(ClassNode cn, MethodNode mn) {
|
||||||
ListIterator<AbstractInsnNode> iterator = mn.instructions.iterator();
|
ListIterator<AbstractInsnNode> iterator = mn.instructions.iterator();
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext())
|
||||||
{
|
{
|
||||||
AbstractInsnNode node = iterator.next();
|
AbstractInsnNode node = iterator.next();
|
||||||
if (node instanceof VarInsnNode)
|
if (node instanceof VarInsnNode)
|
||||||
{
|
{
|
||||||
VarInsnNode varNode = (VarInsnNode) node;
|
VarInsnNode varNode = (VarInsnNode) node;
|
||||||
if (varNode.getOpcode() == Opcodes.ISTORE && varNode.var == 11)
|
if (varNode.getOpcode() == Opcodes.ISTORE && varNode.var == 11)
|
||||||
mn.instructions.set(varNode.getPrevious(), new InsnNode(Opcodes.ICONST_1));
|
mn.instructions.set(varNode.getPrevious(), new InsnNode(Opcodes.ICONST_1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,75 +14,75 @@ import customskinloader.forge.TransformerManager.IMethodTransformer;
|
|||||||
import customskinloader.forge.TransformerManager.TransformTarget;
|
import customskinloader.forge.TransformerManager.TransformTarget;
|
||||||
|
|
||||||
public class SkinManagerTransformer {
|
public class SkinManagerTransformer {
|
||||||
@TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
@TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
||||||
methodNames={"<init>"},
|
methodNames={"<init>"},
|
||||||
desc="(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V")
|
desc="(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V")
|
||||||
public static class InitTransformer implements IMethodTransformer{
|
public static class InitTransformer implements IMethodTransformer{
|
||||||
@Override
|
@Override
|
||||||
public void transform(ClassNode cn,MethodNode mn) {
|
public void transform(ClassNode cn,MethodNode mn) {
|
||||||
cn.fields.add(new FieldNode(Opcodes.ACC_PRIVATE, "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;", null, null));
|
cn.fields.add(new FieldNode(Opcodes.ACC_PRIVATE, "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;", null, null));
|
||||||
mn.instructions.clear();
|
mn.instructions.clear();
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,"java/lang/Object","<init>","()V", false));
|
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,"java/lang/Object","<init>","()V", false));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||||
mn.instructions.add(new TypeInsnNode(Opcodes.NEW, "customskinloader/fake/FakeSkinManager"));
|
mn.instructions.add(new TypeInsnNode(Opcodes.NEW, "customskinloader/fake/FakeSkinManager"));
|
||||||
mn.instructions.add(new InsnNode(Opcodes.DUP));
|
mn.instructions.add(new InsnNode(Opcodes.DUP));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,3));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,3));
|
||||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,"customskinloader/fake/FakeSkinManager","<init>",
|
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,"customskinloader/fake/FakeSkinManager","<init>",
|
||||||
"(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V", false));
|
"(Lnet/minecraft/client/renderer/texture/TextureManager;Ljava/io/File;Lcom/mojang/authlib/minecraft/MinecraftSessionService;)V", false));
|
||||||
mn.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
mn.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
mn.instructions.add(new InsnNode(Opcodes.RETURN));
|
mn.instructions.add(new InsnNode(Opcodes.RETURN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
@TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
||||||
methodNames={"func_152789_a","loadSkin"},
|
methodNames={"func_152789_a","loadSkin"},
|
||||||
desc="(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;")
|
desc="(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;")
|
||||||
public static class LoadSkinTransformer implements IMethodTransformer{
|
public static class LoadSkinTransformer implements IMethodTransformer{
|
||||||
@Override
|
@Override
|
||||||
public void transform(ClassNode cn,MethodNode mn) {
|
public void transform(ClassNode cn,MethodNode mn) {
|
||||||
mn.instructions.clear();
|
mn.instructions.clear();
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||||
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,3));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,3));
|
||||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadSkin",
|
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadSkin",
|
||||||
"(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;", false));
|
"(Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;)Lnet/minecraft/util/ResourceLocation;", false));
|
||||||
mn.instructions.add(new InsnNode(Opcodes.ARETURN));
|
mn.instructions.add(new InsnNode(Opcodes.ARETURN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
@TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
||||||
methodNames={"func_152790_a","loadProfileTextures"},
|
methodNames={"func_152790_a","loadProfileTextures"},
|
||||||
desc="(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V")
|
desc="(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V")
|
||||||
public static class LoadProfileTexturesTransformer implements IMethodTransformer{
|
public static class LoadProfileTexturesTransformer implements IMethodTransformer{
|
||||||
@Override
|
@Override
|
||||||
public void transform(ClassNode cn,MethodNode mn) {
|
public void transform(ClassNode cn,MethodNode mn) {
|
||||||
mn.instructions.clear();
|
mn.instructions.clear();
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||||
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,2));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ILOAD,3));
|
mn.instructions.add(new VarInsnNode(Opcodes.ILOAD,3));
|
||||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadProfileTextures",
|
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadProfileTextures",
|
||||||
"(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V", false));
|
"(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/resources/SkinManager$SkinAvailableCallback;Z)V", false));
|
||||||
mn.instructions.add(new InsnNode(Opcodes.RETURN));
|
mn.instructions.add(new InsnNode(Opcodes.RETURN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
@TransformTarget(className="net.minecraft.client.resources.SkinManager",
|
||||||
methodNames={"func_152788_a","loadSkinFromCache"},
|
methodNames={"func_152788_a","loadSkinFromCache"},
|
||||||
desc="(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;")
|
desc="(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;")
|
||||||
public static class LoadSkinFromCacheTransformer implements IMethodTransformer{
|
public static class LoadSkinFromCacheTransformer implements IMethodTransformer{
|
||||||
@Override
|
@Override
|
||||||
public void transform(ClassNode cn,MethodNode mn) {
|
public void transform(ClassNode cn,MethodNode mn) {
|
||||||
mn.instructions.clear();
|
mn.instructions.clear();
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
|
||||||
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/resources/SkinManager", "fakeManager", "Lcustomskinloader/fake/FakeSkinManager;"));
|
||||||
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,1));
|
||||||
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadSkinFromCache",
|
mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,"customskinloader/fake/FakeSkinManager","loadSkinFromCache",
|
||||||
"(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;", false));
|
"(Lcom/mojang/authlib/GameProfile;)Ljava/util/Map;", false));
|
||||||
mn.instructions.add(new InsnNode(Opcodes.ARETURN));
|
mn.instructions.add(new InsnNode(Opcodes.ARETURN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package customskinloader.forge;
|
||||||
|
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.objectweb.asm.tree.InsnList;
|
||||||
|
import org.objectweb.asm.tree.MethodInsnNode;
|
||||||
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
|
import customskinloader.forge.TransformerManager.IMethodTransformer;
|
||||||
|
import customskinloader.forge.TransformerManager.TransformTarget;
|
||||||
|
|
||||||
|
public class SpectatorMenuTransformer {
|
||||||
|
@TransformTarget(className="net.minecraft.client.gui.spectator.PlayerMenuObject",
|
||||||
|
methodNames={"<init>"},
|
||||||
|
desc="(Lcom/mojang/authlib/GameProfile;)V")
|
||||||
|
public static class PlayerMenuObjectTransformer implements IMethodTransformer{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transform(ClassNode cn, MethodNode mn) {
|
||||||
|
InsnList il=mn.instructions;
|
||||||
|
ListIterator<AbstractInsnNode> li=il.iterator();
|
||||||
|
|
||||||
|
boolean flag=false;
|
||||||
|
while(li.hasNext()) {
|
||||||
|
AbstractInsnNode ain=li.next();
|
||||||
|
if(ain.getOpcode()!=Opcodes.INVOKESTATIC)
|
||||||
|
continue;
|
||||||
|
//MethodInsnNode min=(MethodInsnNode)nn;
|
||||||
|
//min.owner="customskinloader/fake/FakeClientPlayer";
|
||||||
|
if(!flag) {
|
||||||
|
//First InvokeStatic
|
||||||
|
il.set(ain, new MethodInsnNode(Opcodes.INVOKESTATIC,"customskinloader/fake/FakeClientPlayer","getLocationSkin",
|
||||||
|
"(Ljava/lang/String;)Lnet/minecraft/util/ResourceLocation;",false));
|
||||||
|
flag=true;
|
||||||
|
}else {
|
||||||
|
//Second InvokeStatic
|
||||||
|
il.set(ain, new MethodInsnNode(Opcodes.INVOKESTATIC,"customskinloader/fake/FakeClientPlayer","getDownloadImageSkin",
|
||||||
|
"(Lnet/minecraft/util/ResourceLocation;Ljava/lang/String;)Lnet/minecraft/client/renderer/ThreadDownloadImageData;",false));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,77 +19,79 @@ import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRema
|
|||||||
import net.minecraftforge.fml.relauncher.FMLRelaunchLog;
|
import net.minecraftforge.fml.relauncher.FMLRelaunchLog;
|
||||||
import customskinloader.forge.PlayerTabTransformer.ScoreObjectiveTransformer;
|
import customskinloader.forge.PlayerTabTransformer.ScoreObjectiveTransformer;
|
||||||
import customskinloader.forge.SkinManagerTransformer.*;
|
import customskinloader.forge.SkinManagerTransformer.*;
|
||||||
|
import customskinloader.forge.SpectatorMenuTransformer.PlayerMenuObjectTransformer;
|
||||||
|
|
||||||
public class TransformerManager implements IClassTransformer {
|
public class TransformerManager implements IClassTransformer {
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
public @interface TransformTarget{
|
public @interface TransformTarget{
|
||||||
public String className();
|
public String className();
|
||||||
public String[] methodNames();
|
public String[] methodNames();
|
||||||
public String desc();
|
public String desc();
|
||||||
}
|
}
|
||||||
public interface IMethodTransformer{
|
public interface IMethodTransformer{
|
||||||
public void transform(ClassNode cn,MethodNode mn);
|
public void transform(ClassNode cn,MethodNode mn);
|
||||||
}
|
}
|
||||||
private static final IMethodTransformer[] TRANFORMERS={
|
private static final IMethodTransformer[] TRANFORMERS={
|
||||||
new InitTransformer(),
|
new InitTransformer(),
|
||||||
new LoadSkinTransformer(),
|
new LoadSkinTransformer(),
|
||||||
new LoadProfileTexturesTransformer(),
|
new LoadProfileTexturesTransformer(),
|
||||||
new LoadSkinFromCacheTransformer(),
|
new LoadSkinFromCacheTransformer(),
|
||||||
new ScoreObjectiveTransformer()};
|
new ScoreObjectiveTransformer(),
|
||||||
private Map<String, Map<String, IMethodTransformer>> map;
|
new PlayerMenuObjectTransformer()};
|
||||||
public TransformerManager(){
|
private Map<String, Map<String, IMethodTransformer>> map;
|
||||||
map = new HashMap<String, Map<String, IMethodTransformer>>();
|
public TransformerManager(){
|
||||||
for(IMethodTransformer t:TRANFORMERS){
|
map = new HashMap<String, Map<String, IMethodTransformer>>();
|
||||||
|
for(IMethodTransformer t:TRANFORMERS){
|
||||||
FMLRelaunchLog.info("[CSL DEBUG] REGISTERING TRANSFORMER %s",t.getClass().getName());
|
FMLRelaunchLog.info("[CSL DEBUG] REGISTERING TRANSFORMER %s",t.getClass().getName());
|
||||||
if(!t.getClass().isAnnotationPresent(TransformTarget.class)){
|
if(!t.getClass().isAnnotationPresent(TransformTarget.class)){
|
||||||
FMLRelaunchLog.info("[CSL DEBUG] ERROR occurs while parsing Annotation.");
|
FMLRelaunchLog.info("[CSL DEBUG] ERROR occurs while parsing Annotation.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
addMethodTransformer(t.getClass().getAnnotation(TransformTarget.class),t);
|
addMethodTransformer(t.getClass().getAnnotation(TransformTarget.class),t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void addMethodTransformer(TransformTarget target, IMethodTransformer transformer) {
|
private void addMethodTransformer(TransformTarget target, IMethodTransformer transformer) {
|
||||||
if (!map.containsKey(target.className()))
|
if (!map.containsKey(target.className()))
|
||||||
map.put(target.className(), new HashMap<String, IMethodTransformer>());
|
map.put(target.className(), new HashMap<String, IMethodTransformer>());
|
||||||
for(String methodName:target.methodNames()){
|
for(String methodName:target.methodNames()){
|
||||||
map.get(target.className()).put(methodName + target.desc(), transformer);
|
map.get(target.className()).put(methodName + target.desc(), transformer);
|
||||||
FMLRelaunchLog.info("[CSL DEBUG] REGISTERING METHOD %s(%s)",target.className(),methodName + target.desc());
|
FMLRelaunchLog.info("[CSL DEBUG] REGISTERING METHOD %s(%s)",target.className(),methodName + target.desc());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//From: https://github.com/RecursiveG/UniSkinMod/blob/1.9.4/src/main/java/org/devinprogress/uniskinmod/coremod/BaseAsmTransformer.java#L83-L114
|
//From: https://github.com/RecursiveG/UniSkinMod/blob/1.9.4/src/main/java/org/devinprogress/uniskinmod/coremod/BaseAsmTransformer.java#L83-L114
|
||||||
@Override
|
@Override
|
||||||
public byte[] transform(String obfClassName, String className, byte[] bytes) {
|
public byte[] transform(String obfClassName, String className, byte[] bytes) {
|
||||||
if (!map.containsKey(className)) return bytes;
|
if (!map.containsKey(className)) return bytes;
|
||||||
FMLRelaunchLog.info("[CSL DEBUG] CLASS %s will be transformed", className);
|
FMLRelaunchLog.info("[CSL DEBUG] CLASS %s will be transformed", className);
|
||||||
Map<String, IMethodTransformer> transMap = map.get(className);
|
Map<String, IMethodTransformer> transMap = map.get(className);
|
||||||
|
|
||||||
ClassReader cr = new ClassReader(bytes);
|
ClassReader cr = new ClassReader(bytes);
|
||||||
ClassNode cn = new ClassNode();
|
ClassNode cn = new ClassNode();
|
||||||
cr.accept(cn, 0);
|
cr.accept(cn, 0);
|
||||||
|
|
||||||
// NOTE: `map` = convert obfuscated name to srgName;
|
// NOTE: `map` = convert obfuscated name to srgName;
|
||||||
List<MethodNode> ml = new ArrayList<MethodNode>();
|
List<MethodNode> ml = new ArrayList<MethodNode>();
|
||||||
ml.addAll(cn.methods);
|
ml.addAll(cn.methods);
|
||||||
for (MethodNode mn : ml) {
|
for (MethodNode mn : ml) {
|
||||||
String methodName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(obfClassName, mn.name, mn.desc);
|
String methodName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(obfClassName, mn.name, mn.desc);
|
||||||
String methodDesc = FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(mn.desc);
|
String methodDesc = FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(mn.desc);
|
||||||
if (transMap.containsKey(methodName + methodDesc)) {
|
if (transMap.containsKey(methodName + methodDesc)) {
|
||||||
try {
|
try {
|
||||||
FMLRelaunchLog.info("[CSL DEBUG] Transforming method %s in class %s(%s)", methodName + methodDesc, obfClassName, className);
|
FMLRelaunchLog.info("[CSL DEBUG] Transforming method %s in class %s(%s)", methodName + methodDesc, obfClassName, className);
|
||||||
transMap.get(methodName + methodDesc).transform(cn,mn);
|
transMap.get(methodName + methodDesc).transform(cn,mn);
|
||||||
FMLRelaunchLog.info("[CSL DEBUG] Successfully transformed method %s in class %s(%s)", methodName + methodDesc, obfClassName, className);
|
FMLRelaunchLog.info("[CSL DEBUG] Successfully transformed method %s in class %s(%s)", methodName + methodDesc, obfClassName, className);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FMLRelaunchLog.warning("[CSL DEBUG] An error happened when transforming method %s in class %s(%s). The whole class was not modified.", methodName + methodDesc, obfClassName, className);
|
FMLRelaunchLog.warning("[CSL DEBUG] An error happened when transforming method %s in class %s(%s). The whole class was not modified.", methodName + methodDesc, obfClassName, className);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
cn.accept(cw);
|
cn.accept(cw);
|
||||||
return cw.toByteArray();
|
return cw.toByteArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,8 @@ Custom Skin Loader mod for Minecraft.
|
|||||||
You can use it to load any skin from any website.
|
You can use it to load any skin from any website.
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
Build Server : [Infinity Studio CI](https://jenkins.mcdev.se/job/CustomSkinLoader/)
|
Build Server : [CircleCI](https://circleci.com/gh/xfl03/MCCustomSkinLoader) & [~~Infinity Studio CI~~](https://ci.infstudio.net/job/CustomSkinLoader/)
|
||||||
[](https://ci.infstudio.net/job/CustomSkinLoader/)
|
Release Page : [MCBBS](http://www.mcbbs.net/thread-269807-1-1.html) & [GitHub](https://github.com/xfl03/MCCustomSkinLoader/releases) & [CurseForge](https://minecraft.curseforge.com/projects/customskinloader)
|
||||||
Release Page : [MCBBS](http://www.mcbbs.net/thread-269807-1-1.html)
|
|
||||||
|
|
||||||
## Feature
|
## Feature
|
||||||
### Plenty of Skin Load API Support and Customizable Skin Load List
|
### Plenty of Skin Load API Support and Customizable Skin Load List
|
||||||
@@ -75,7 +74,7 @@ Including some code from
|
|||||||
- [AsteriskTeam/TabIconHackForge](http://git.oschina.net/AsteriskTeam/TabIconHackForge) (GPLv3)
|
- [AsteriskTeam/TabIconHackForge](http://git.oschina.net/AsteriskTeam/TabIconHackForge) (GPLv3)
|
||||||
- [RecursiveG/UniSkinMod](https://github.com/RecursiveG/UniSkinMod) (GPLv3)
|
- [RecursiveG/UniSkinMod](https://github.com/RecursiveG/UniSkinMod) (GPLv3)
|
||||||
|
|
||||||
Copyright(C) 2013-2017 JLChnToZ xfl03
|
Copyright(C) 2013-2018 JLChnToZ xfl03
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ buildscript {
|
|||||||
url = "http://forgemavenmirror.sinaapp.com/maven"
|
url = "http://forgemavenmirror.sinaapp.com/maven"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
jcenter()
|
jcenter()
|
||||||
maven {
|
maven {
|
||||||
name = "forge"
|
name = "forge"
|
||||||
url = "http://files.minecraftforge.net/maven"
|
url = "http://files.minecraftforge.net/maven"
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name=CustomSkinLoader
|
name=CustomSkinLoader
|
||||||
group=customskinloader
|
group=customskinloader
|
||||||
version=14.7
|
version=14.8
|
||||||
dev_version=
|
dev_version=
|
||||||
#RELEASE: snapshot=0
|
#RELEASE: snapshot=0
|
||||||
snapshot=0
|
snapshot=0
|
||||||
+6
-4
@@ -30,7 +30,7 @@ configFile.withReader {
|
|||||||
project.ext.config = new ConfigSlurper().parse prop
|
project.ext.config = new ConfigSlurper().parse prop
|
||||||
}
|
}
|
||||||
//Example: 14.4a-SNAPSHOT-20160820
|
//Example: 14.4a-SNAPSHOT-20160820
|
||||||
version = rootProject.ext.config.version + rootProject.ext.config.dev_version + ((rootProject.ext.config.snapshot==""||rootProject.ext.config.snapshot=="0"||rootProject.ext.config.snapshot==0)?'':('-SNAPSHOT-'+System.getenv("BUILD_NUMBER")))
|
version = rootProject.ext.config.version + rootProject.ext.config.dev_version + ((rootProject.ext.config.snapshot==""||rootProject.ext.config.snapshot=="0"||rootProject.ext.config.snapshot==0)?'':('-SNAPSHOT-'+System.getenv("CIRCLE_BUILD_NUM")))
|
||||||
group = config.group
|
group = config.group
|
||||||
archivesBaseName = rootProject.ext.config.name+"_"+config.minecraft_version
|
archivesBaseName = rootProject.ext.config.name+"_"+config.minecraft_version
|
||||||
|
|
||||||
@@ -72,8 +72,10 @@ processResources {
|
|||||||
mcVersion:config.minecraft_version,
|
mcVersion:config.minecraft_version,
|
||||||
mcFullVersions:config.minecraft_full_versions,
|
mcFullVersions:config.minecraft_full_versions,
|
||||||
forgeVersion:config.forge_version,
|
forgeVersion:config.forge_version,
|
||||||
gitVersion:System.getenv("GIT_COMMIT"),
|
//gitVersion:System.getenv("GIT_COMMIT"),
|
||||||
buildUrl:System.getenv("BUILD_URL")
|
//buildUrl:System.getenv("BUILD_URL")
|
||||||
|
gitVersion:System.getenv("CIRCLE_SHA1"),
|
||||||
|
buildUrl:System.getenv("CIRCLE_BUILD_URL")
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
task copyResources << {
|
task copyResources << {
|
||||||
@@ -99,7 +101,7 @@ task afterBuild << {
|
|||||||
copy {
|
copy {
|
||||||
from 'build/libs'
|
from 'build/libs'
|
||||||
into '../build/libs'
|
into '../build/libs'
|
||||||
include '**/*.jar'
|
include '**/*.jar'
|
||||||
exclude '**/*-srg.jar'
|
exclude '**/*-srg.jar'
|
||||||
exclude '**/*-dev.jar'
|
exclude '**/*-dev.jar'
|
||||||
exclude '**/*-sources.jar'
|
exclude '**/*-sources.jar'
|
||||||
|
|||||||
Reference in new issue
Block a user