Skip to content

Commit

Permalink
Порт на MC 1.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAndrey committed Apr 29, 2023
1 parent a005d66 commit aacb886
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 56 deletions.
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ repositories {
if (repositories.hasProperty('redserver')) {
redserver()
}
maven {
url 'https://libraries.minecraft.net/'
}
mavenCentral()
}

Expand All @@ -35,8 +38,8 @@ archivesBaseName = 'FontFix'
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_6

dependencies {
compile group: 'net.minecraftforge', name: 'forgeSrc', version: '1.4.7-6.6.2.534'
compile group: 'net.minecraft', name: 'launchwrapper', version: '1.5'
compile group: 'net.minecraftforge', name: 'forgeSrc', version: '1.6.4-9.11.1.1345'
compile group: 'net.minecraft', name: 'launchwrapper', version: '1.8'
}

tasks.withType(JavaCompile) {
Expand All @@ -61,7 +64,7 @@ artifacts {

/* Reobf task */
task reobf(type: BON, dependsOn: jar) {
mcpFolder = getProperty('minecraft.mcp.dir') + '/1.4.7-forge'
mcpFolder = getProperty('minecraft.mcp.dir') + '/1.6.4-forge'
input = jar.archivePath
output = jar.archivePath
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Project
group=me.theandrey
version=1.4.7
version=1.6.4
93 changes: 41 additions & 52 deletions src/main/java/me/theandrey/fontfix/ASMTransformer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.theandrey.fontfix;

import java.util.ListIterator;
import cpw.mods.fml.relauncher.IClassTransformer;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
Expand All @@ -19,65 +19,54 @@ public class ASMTransformer implements IClassTransformer {
"\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F" +
"\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F" +
"\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E\u044F";
private static final String ASCII_TEXTURE = "/font/default.png";
private static final String CYRILLIC_TEXTURE = "/font/default_ru.png";
private static final String ASCII_TEXTURE = "textures/font/ascii.png";
private static final String ASCII_TEXTURE_RU = "textures/font/ascii_ru.png";

@Override
public byte[] transform(String name, byte[] bytes) {
if (name.equals("bn")) {
return patchStringTranslate(bytes, true);
} else if (name.equals("net.minecraft.util.StringTranslate")) {
return patchStringTranslate(bytes, false);
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (name.equals("bke")) {
return patchLocale(bytes, true);
} else if (name.equals("net.minecraft.client.resources.Locale")) {
return patchLocale(bytes, false);
} else if (name.equals("atv")) {
return patchMinecraft(bytes, true);
} else if (name.equals("net.minecraft.client.Minecraft")) {
return patchMinecraft(bytes, LoadingPlugin.isGameObfuscated());
} else if (name.equals("u") || name.equals("net.minecraft.util.ChatAllowedCharacters")) {
return patchMinecraft(bytes, false);
} else if (name.equals("v") || name.equals("net.minecraft.util.ChatAllowedCharacters")) {
return patchAllowedCharacters(bytes);
}

return bytes;
}

/**
* Делает русскую локаль не-unicode
*/
@SuppressWarnings("deprecation")
private byte[] patchStringTranslate(byte[] bytes, boolean obf) {
private byte[] patchLocale(byte[] bytes, boolean obf) {
ClassNode clazz = Utils.readClass(bytes);

final String findMethod = obf ? "a" : "setLanguage";
final String isUnicode = obf ? "e" : "isUnicode";
final String currentLanguage = obf ? "d" : "currentLanguage";
final Type classMc = Utils.getObjectType(obf ? "atv" : "net.minecraft.client.Minecraft");
final Type classSettings = Utils.getObjectType(obf ? "aul" : "net.minecraft.client.settings.GameSettings");
final Type classLocale = Utils.getObjectType(obf ? "bke" : "net.minecraft.client.resources.Locale");
final String findMethod = obf ? "b" : "checkUnicode";
final String getMinecraft = obf ? "w" : "getMinecraft";
final String gameSettings = obf ? "u" : "gameSettings";

for (MethodNode method : clazz.methods) {
if (method.name.equals(findMethod) && method.desc.equals(Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class)))) {

ListIterator<AbstractInsnNode> iter = method.instructions.iterator();

while (iter.hasNext()) {
AbstractInsnNode insn = iter.next();

if (insn.getOpcode() == PUTFIELD) {
FieldInsnNode fieldInsn = ((FieldInsnNode)insn);

// Присвоения значения 'currentLanguage'
if (fieldInsn.owner.equals(clazz.name) && fieldInsn.name.equals(currentLanguage) && fieldInsn.desc.equals(Type.getType(String.class).getDescriptor())) {

LabelNode label = new LabelNode();
InsnList list = new InsnList();
list.add(new LdcInsnNode("ru_RU"));
list.add(new VarInsnNode(ALOAD, 1)); // #1 param
list.add(new MethodInsnNode(INVOKEVIRTUAL, Type.getInternalName(String.class), "equals", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class))));
list.add(new JumpInsnNode(IFEQ, label));
list.add(new VarInsnNode(ALOAD, 0)); // this
list.add(new InsnNode(ICONST_0));
list.add(new FieldInsnNode(PUTFIELD, clazz.name, isUnicode, Type.BOOLEAN_TYPE.getDescriptor())); // this
list.add(label);

method.instructions.insert(insn, list);
break;
}
}
}

if (method.name.equals(findMethod) && method.desc.equals(Type.getMethodDescriptor(Type.VOID_TYPE))) {
InsnList list = new InsnList();
LabelNode label = new LabelNode();

list.add(new LdcInsnNode("ru_RU"));
list.add(new MethodInsnNode(INVOKESTATIC, classMc.getInternalName(), getMinecraft, Type.getMethodDescriptor(classMc)));
list.add(new FieldInsnNode(GETFIELD, classMc.getInternalName(), gameSettings, classSettings.getDescriptor()));
list.add(new FieldInsnNode(GETFIELD, classSettings.getInternalName(), obf ? "an" : "language", Type.getType(String.class).getDescriptor()));
list.add(new MethodInsnNode(INVOKEVIRTUAL, Type.getInternalName(String.class), "equals", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class))));
list.add(new JumpInsnNode(IFEQ, label));
list.add(new VarInsnNode(ALOAD, 0));
list.add(new InsnNode(ICONST_0));
list.add(new FieldInsnNode(PUTFIELD, classLocale.getInternalName(), "field_135029_d", Type.BOOLEAN_TYPE.getDescriptor()));
list.add(new InsnNode(RETURN));
list.add(label);

method.instructions.insert(list);
break;
}
}
Expand All @@ -91,11 +80,11 @@ private byte[] patchStringTranslate(byte[] bytes, boolean obf) {
*/
private byte[] patchMinecraft(byte[] bytes, boolean obf) {
ClassNode clazz = Utils.readClass(bytes);
final Type fondRenderer = Utils.getObjectType(obf ? "atq" : "net.minecraft.client.gui.FontRenderer");
final String startGame = obf ? "a" : "startGame";
final Type fondRenderer = Utils.getObjectType(obf ? "avi" : "net.minecraft.client.gui.FontRenderer");
final String mStartGame = obf ? "O" : "startGame";

for (MethodNode method : clazz.methods) {
if (method.name.equals(startGame) && method.desc.equals(Type.getMethodDescriptor(Type.VOID_TYPE))) {
if (method.name.equals(mStartGame) && method.desc.equals(Type.getMethodDescriptor(Type.VOID_TYPE))) {

ListIterator<AbstractInsnNode> iter = method.instructions.iterator();
boolean inConstructor = false;
Expand All @@ -113,7 +102,7 @@ private byte[] patchMinecraft(byte[] bytes, boolean obf) {
if (insn.getType() == AbstractInsnNode.LDC_INSN && inConstructor) {
LdcInsnNode ldc = (LdcInsnNode)insn;
if (ldc.cst.equals(ASCII_TEXTURE)) {
ldc.cst = CYRILLIC_TEXTURE;
ldc.cst = ASCII_TEXTURE_RU;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/theandrey/fontfix/LoadingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Map;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;

@IFMLLoadingPlugin.SortingIndex(900)
public class LoadingPlugin implements IFMLLoadingPlugin {

@Override
Expand Down
File renamed without changes

0 comments on commit aacb886

Please sign in to comment.