Skip to content
This repository was archived by the owner on Jan 3, 2020. It is now read-only.

Commit c7b6494

Browse files
committed
auto clean cache
1 parent 5f4fd3a commit c7b6494

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/main/java/org/devinprogress/uniskinmod/CoreTransformer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class CoreTransformer implements IClassTransformer {
3030
// Insert code after the IF and hijack hashmap
3131
// Add MinecraftTextureProfile Manually
3232
// you have also pass p_152790_1_(GameProfile)
33-
33+
3434
// Hack into MinecraftProfileTexture.getHash()Ljava/lang/String;
3535
// SHA-1 of the url as the hash instead of the filename
3636
// workaround for different format of skin urls.
@@ -52,7 +52,7 @@ public static void injectCode(MethodNode mn){
5252
FieldInsnNode loadGameProfileToStack=(FieldInsnNode) ((FieldInsnNode)n).clone(null);
5353
n=ASMHelper.getNthInsnNode(mn, Opcodes.IFEQ,1);
5454
n=ASMHelper.getLabel(n).getNext();
55-
55+
5656
mn.instructions.insertBefore(n, new VarInsnNode(Opcodes.ALOAD,1));
5757
mn.instructions.insertBefore(n, new VarInsnNode(Opcodes.ALOAD,0));
5858
mn.instructions.insertBefore(n, loadGameProfileToStack);
@@ -67,6 +67,7 @@ public static void noOpaque(MethodNode mn){
6767

6868
public static void newHash(MethodNode mn){
6969
SkinCore.log("hash Transformer Hit");
70+
if(SkinCore.useMojangStyledHash)return;
7071
mn.instructions.clear();
7172
mn.instructions.add(new VarInsnNode(Opcodes.ALOAD,0));
7273
mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD,"com/mojang/authlib/minecraft/MinecraftProfileTexture","url","Ljava/lang/String;"));
@@ -75,7 +76,7 @@ public static void newHash(MethodNode mn){
7576
mn.maxLocals=1;
7677
mn.maxStack=1;
7778
}
78-
79+
7980
@Override
8081
public byte[] transform(String name, String transformedName, byte[] bytes) {
8182
return asm.transform(transformedName,bytes);

src/main/java/org/devinprogress/uniskinmod/SkinCore.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class SkinCore implements IFMLLoadingPlugin{
2121
private List<String> SkinURLs=new ArrayList<String>();
2222
private List<String> CloakURLs=new ArrayList<String>();
2323

24+
private boolean noCleanup=false;
25+
public static boolean useMojangStyledHash=false;
26+
2427
public SkinCore(){
2528
if(instance!=null)
2629
throw new RuntimeException("Duplicated Initialization for SkinCore");
@@ -87,25 +90,53 @@ public void injectData(Map<String, Object> data) {
8790
}
8891
br.close();
8992
fr.close();
93+
94+
if(!noCleanup){
95+
File skin_dir=new File(((File) data.get("mcLocation")).getAbsolutePath()
96+
+ File.separatorChar + "assets" + File.separatorChar
97+
+ "skins");
98+
if(skin_dir.exists()&&skin_dir.isDirectory()){
99+
skin_dir.delete();
100+
log("Skin Cache Cleared.");
101+
}
102+
}
90103
} catch (IOException e) {
91104
e.printStackTrace();
92105
}
93106
}
94107

95108
private boolean tryProcessLine(String line){
96109
log("Processing:"+line);
110+
line=line.trim();
97111
if(line.startsWith("#"))return true;
98112
if(!line.contains("%s"))return false;
99113
if(line.startsWith("Skin: ")){
100114
SkinURLs.add(line.split(" ",2)[1]);
101-
}else if(line.startsWith("Cloak: ")){
102-
CloakURLs.add(line.split(" ",2)[1]);
115+
}else if(line.startsWith("Cloak: ")) {
116+
CloakURLs.add(line.split(" ", 2)[1]);
117+
}else if(line.startsWith(":")){
118+
if(tryProcessOption(line.substring(1).trim()))
119+
return true;
120+
else
121+
return false;
103122
}else{
104123
return false;
105124
}
106125
return true;
107126
}
108127

128+
private boolean tryProcessOption(String line){
129+
if(line.equalsIgnoreCase("nocleanup")){
130+
noCleanup=true;
131+
return true;
132+
}else if(line.equalsIgnoreCase("usemojangstyledhash")){
133+
useMojangStyledHash=true;
134+
return true;
135+
}else{
136+
return false;
137+
}
138+
}
139+
109140
@Override
110141
public String getAccessTransformerClass() {
111142
return null;

0 commit comments

Comments
 (0)