1
1
package me .theandrey .fontfix ;
2
2
3
3
import java .util .ListIterator ;
4
- import cpw . mods . fml . relauncher .IClassTransformer ;
4
+ import net . minecraft . launchwrapper .IClassTransformer ;
5
5
import org .objectweb .asm .ClassWriter ;
6
6
import org .objectweb .asm .Type ;
7
7
import org .objectweb .asm .tree .*;
@@ -19,65 +19,54 @@ public class ASMTransformer implements IClassTransformer {
19
19
"\u0420 \u0421 \u0422 \u0423 \u0424 \u0425 \u0426 \u0427 \u0428 \u0429 \u042A \u042B \u042C \u042D \u042E \u042F " +
20
20
"\u0430 \u0431 \u0432 \u0433 \u0434 \u0435 \u0436 \u0437 \u0438 \u0439 \u043A \u043B \u043C \u043D \u043E \u043F " +
21
21
"\u0440 \u0441 \u0442 \u0443 \u0444 \u0445 \u0446 \u0447 \u0448 \u0449 \u044A \u044B \u044C \u044D \u044E \u044F " ;
22
- private static final String ASCII_TEXTURE = "/font/default .png" ;
23
- private static final String CYRILLIC_TEXTURE = "/font/default_ru .png" ;
22
+ private static final String ASCII_TEXTURE = "textures /font/ascii .png" ;
23
+ private static final String ASCII_TEXTURE_RU = "textures /font/ascii_ru .png" ;
24
24
25
25
@ Override
26
- public byte [] transform (String name , byte [] bytes ) {
27
- if (name .equals ("bn" )) {
28
- return patchStringTranslate (bytes , true );
29
- } else if (name .equals ("net.minecraft.util.StringTranslate" )) {
30
- return patchStringTranslate (bytes , false );
26
+ public byte [] transform (String name , String transformedName , byte [] bytes ) {
27
+ if (name .equals ("bke" )) {
28
+ return patchLocale (bytes , true );
29
+ } else if (name .equals ("net.minecraft.client.resources.Locale" )) {
30
+ return patchLocale (bytes , false );
31
+ } else if (name .equals ("atv" )) {
32
+ return patchMinecraft (bytes , true );
31
33
} else if (name .equals ("net.minecraft.client.Minecraft" )) {
32
- return patchMinecraft (bytes , LoadingPlugin . isGameObfuscated () );
33
- } else if (name .equals ("u " ) || name .equals ("net.minecraft.util.ChatAllowedCharacters" )) {
34
+ return patchMinecraft (bytes , false );
35
+ } else if (name .equals ("v " ) || name .equals ("net.minecraft.util.ChatAllowedCharacters" )) {
34
36
return patchAllowedCharacters (bytes );
35
37
}
38
+
36
39
return bytes ;
37
40
}
38
41
39
- /**
40
- * Делает русскую локаль не-unicode
41
- */
42
- @ SuppressWarnings ("deprecation" )
43
- private byte [] patchStringTranslate (byte [] bytes , boolean obf ) {
42
+ private byte [] patchLocale (byte [] bytes , boolean obf ) {
44
43
ClassNode clazz = Utils .readClass (bytes );
45
44
46
- final String findMethod = obf ? "a" : "setLanguage" ;
47
- final String isUnicode = obf ? "e" : "isUnicode" ;
48
- final String currentLanguage = obf ? "d" : "currentLanguage" ;
45
+ final Type classMc = Utils .getObjectType (obf ? "atv" : "net.minecraft.client.Minecraft" );
46
+ final Type classSettings = Utils .getObjectType (obf ? "aul" : "net.minecraft.client.settings.GameSettings" );
47
+ final Type classLocale = Utils .getObjectType (obf ? "bke" : "net.minecraft.client.resources.Locale" );
48
+ final String findMethod = obf ? "b" : "checkUnicode" ;
49
+ final String getMinecraft = obf ? "w" : "getMinecraft" ;
50
+ final String gameSettings = obf ? "u" : "gameSettings" ;
49
51
50
52
for (MethodNode method : clazz .methods ) {
51
- if (method .name .equals (findMethod ) && method .desc .equals (Type .getMethodDescriptor (Type .VOID_TYPE , Type .getType (String .class )))) {
52
-
53
- ListIterator <AbstractInsnNode > iter = method .instructions .iterator ();
54
-
55
- while (iter .hasNext ()) {
56
- AbstractInsnNode insn = iter .next ();
57
-
58
- if (insn .getOpcode () == PUTFIELD ) {
59
- FieldInsnNode fieldInsn = ((FieldInsnNode )insn );
60
-
61
- // Присвоения значения 'currentLanguage'
62
- if (fieldInsn .owner .equals (clazz .name ) && fieldInsn .name .equals (currentLanguage ) && fieldInsn .desc .equals (Type .getType (String .class ).getDescriptor ())) {
63
-
64
- LabelNode label = new LabelNode ();
65
- InsnList list = new InsnList ();
66
- list .add (new LdcInsnNode ("ru_RU" ));
67
- list .add (new VarInsnNode (ALOAD , 1 )); // #1 param
68
- list .add (new MethodInsnNode (INVOKEVIRTUAL , Type .getInternalName (String .class ), "equals" , Type .getMethodDescriptor (Type .BOOLEAN_TYPE , Type .getType (Object .class ))));
69
- list .add (new JumpInsnNode (IFEQ , label ));
70
- list .add (new VarInsnNode (ALOAD , 0 )); // this
71
- list .add (new InsnNode (ICONST_0 ));
72
- list .add (new FieldInsnNode (PUTFIELD , clazz .name , isUnicode , Type .BOOLEAN_TYPE .getDescriptor ())); // this
73
- list .add (label );
74
-
75
- method .instructions .insert (insn , list );
76
- break ;
77
- }
78
- }
79
- }
80
-
53
+ if (method .name .equals (findMethod ) && method .desc .equals (Type .getMethodDescriptor (Type .VOID_TYPE ))) {
54
+ InsnList list = new InsnList ();
55
+ LabelNode label = new LabelNode ();
56
+
57
+ list .add (new LdcInsnNode ("ru_RU" ));
58
+ list .add (new MethodInsnNode (INVOKESTATIC , classMc .getInternalName (), getMinecraft , Type .getMethodDescriptor (classMc )));
59
+ list .add (new FieldInsnNode (GETFIELD , classMc .getInternalName (), gameSettings , classSettings .getDescriptor ()));
60
+ list .add (new FieldInsnNode (GETFIELD , classSettings .getInternalName (), obf ? "an" : "language" , Type .getType (String .class ).getDescriptor ()));
61
+ list .add (new MethodInsnNode (INVOKEVIRTUAL , Type .getInternalName (String .class ), "equals" , Type .getMethodDescriptor (Type .BOOLEAN_TYPE , Type .getType (Object .class ))));
62
+ list .add (new JumpInsnNode (IFEQ , label ));
63
+ list .add (new VarInsnNode (ALOAD , 0 ));
64
+ list .add (new InsnNode (ICONST_0 ));
65
+ list .add (new FieldInsnNode (PUTFIELD , classLocale .getInternalName (), "field_135029_d" , Type .BOOLEAN_TYPE .getDescriptor ()));
66
+ list .add (new InsnNode (RETURN ));
67
+ list .add (label );
68
+
69
+ method .instructions .insert (list );
81
70
break ;
82
71
}
83
72
}
@@ -91,11 +80,11 @@ private byte[] patchStringTranslate(byte[] bytes, boolean obf) {
91
80
*/
92
81
private byte [] patchMinecraft (byte [] bytes , boolean obf ) {
93
82
ClassNode clazz = Utils .readClass (bytes );
94
- final Type fondRenderer = Utils .getObjectType (obf ? "atq " : "net.minecraft.client.gui.FontRenderer" );
95
- final String startGame = obf ? "a " : "startGame" ;
83
+ final Type fondRenderer = Utils .getObjectType (obf ? "avi " : "net.minecraft.client.gui.FontRenderer" );
84
+ final String mStartGame = obf ? "O " : "startGame" ;
96
85
97
86
for (MethodNode method : clazz .methods ) {
98
- if (method .name .equals (startGame ) && method .desc .equals (Type .getMethodDescriptor (Type .VOID_TYPE ))) {
87
+ if (method .name .equals (mStartGame ) && method .desc .equals (Type .getMethodDescriptor (Type .VOID_TYPE ))) {
99
88
100
89
ListIterator <AbstractInsnNode > iter = method .instructions .iterator ();
101
90
boolean inConstructor = false ;
@@ -113,7 +102,7 @@ private byte[] patchMinecraft(byte[] bytes, boolean obf) {
113
102
if (insn .getType () == AbstractInsnNode .LDC_INSN && inConstructor ) {
114
103
LdcInsnNode ldc = (LdcInsnNode )insn ;
115
104
if (ldc .cst .equals (ASCII_TEXTURE )) {
116
- ldc .cst = CYRILLIC_TEXTURE ;
105
+ ldc .cst = ASCII_TEXTURE_RU ;
117
106
}
118
107
}
119
108
0 commit comments