Commit 89fce7f9c78b43a89fd881d75295be2e7231079f

Authored by Mumfrey
1 parent 0e3dd41e

add GuiTextField accessor interface

java/client/com/mumfrey/liteloader/client/overlays/IGuiTextField.java 0 → 100644
  1 +package com.mumfrey.liteloader.client.overlays;
  2 +
  3 +import com.mumfrey.liteloader.transformers.access.Accessor;
  4 +
  5 +/**
  6 + * Adapter for GuiTextField to expose internal properties, mainly to allow sensible subclassing
  7 + *
  8 + * @author Adam Mummery-Smith
  9 + */
  10 +@Accessor("GuiTextField")
  11 +public interface IGuiTextField
  12 +{
  13 + @Accessor("#2") public abstract int getXPosition();
  14 + @Accessor("#2") public abstract void setXPosition(int xPosition);
  15 +
  16 + @Accessor("#3") public abstract int getYPosition();
  17 + @Accessor("#3") public abstract void setYPosition(int yPosition);
  18 +
  19 + @Accessor("#4") public abstract int getInternalWidth();
  20 + @Accessor("#4") public abstract void setInternalWidth(int width);
  21 +
  22 + @Accessor("#5") public abstract int getHeight();
  23 + @Accessor("#5") public abstract void setHeight(int height);
  24 +
  25 + @Accessor("#12") public abstract boolean isEnabled();
  26 +// @Accessor("#12") public abstract void setEnabled(boolean enabled); // built in
  27 +
  28 + @Accessor("#13") public abstract int getLineScrollOffset();
  29 +
  30 + @Accessor("#16") public abstract int getTextColor();
  31 +// @Accessor("#16") public abstract void setTextColor(int color); // built in
  32 +
  33 + @Accessor("#17") public abstract int getDisabledTextColour();
  34 +// @Accessor("#17") public abstract void setDisabledTextColour(int color); // built in
  35 +}
java/client/com/mumfrey/liteloader/client/transformers/MinecraftTransformer.java
@@ -24,6 +24,7 @@ public class MinecraftTransformer extends AccessorTransformer @@ -24,6 +24,7 @@ public class MinecraftTransformer extends AccessorTransformer
24 protected void addAccessors() 24 protected void addAccessors()
25 { 25 {
26 this.addAccessor(Obf.IMinecraft.name); 26 this.addAccessor(Obf.IMinecraft.name);
  27 + this.addAccessor(Obf.IGuiTextField.name);
27 } 28 }
28 29
29 @Override 30 @Override
java/client/com/mumfrey/liteloader/gl/GL.java
@@ -1272,4 +1272,19 @@ public class GL @@ -1272,4 +1272,19 @@ public class GL
1272 { 1272 {
1273 GL11.glPolygonMode(face, mode); 1273 GL11.glPolygonMode(face, mode);
1274 } 1274 }
  1275 +
  1276 + public static void glPixelStorei(int pname, int param)
  1277 + {
  1278 + GL11.glPixelStorei(pname, param);
  1279 + }
  1280 +
  1281 + public static void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer pixels)
  1282 + {
  1283 + GL11.glReadPixels(x, y, width, height, format, type, pixels);
  1284 + }
  1285 +
  1286 + public static void glGetTexImage(int target, int level, int format, int type, ByteBuffer pixels)
  1287 + {
  1288 + GL11.glGetTexImage(target, level, format, type, pixels);
  1289 + }
1275 } 1290 }
java/common/com/mumfrey/liteloader/core/runtime/Obf.java
@@ -26,6 +26,7 @@ public class Obf @@ -26,6 +26,7 @@ public class Obf
26 public static final Obf PacketEventsClient = new Obf("com.mumfrey.liteloader.client.PacketEventsClient" ); 26 public static final Obf PacketEventsClient = new Obf("com.mumfrey.liteloader.client.PacketEventsClient" );
27 public static final Obf LoadingBar = new Obf("com.mumfrey.liteloader.client.gui.startup.LoadingBar" ); 27 public static final Obf LoadingBar = new Obf("com.mumfrey.liteloader.client.gui.startup.LoadingBar" );
28 public static final Obf IMinecraft = new Obf("com.mumfrey.liteloader.client.overlays.IMinecraft" ); 28 public static final Obf IMinecraft = new Obf("com.mumfrey.liteloader.client.overlays.IMinecraft" );
  29 + public static final Obf IGuiTextField = new Obf("com.mumfrey.liteloader.client.overlays.IGuiTextField" );
29 public static final Obf GameProfile = new Obf("com.mojang.authlib.GameProfile" ); 30 public static final Obf GameProfile = new Obf("com.mojang.authlib.GameProfile" );
30 public static final Obf MinecraftMain = new Obf("net.minecraft.client.main.Main" ); 31 public static final Obf MinecraftMain = new Obf("net.minecraft.client.main.Main" );
31 public static final Obf MinecraftServer = new Obf("net.minecraft.server.MinecraftServer" ); 32 public static final Obf MinecraftServer = new Obf("net.minecraft.server.MinecraftServer" );
@@ -62,6 +63,7 @@ public class Obf @@ -62,6 +63,7 @@ public class Obf
62 public static final Obf Entity = new Obf("net.minecraft.entity.Entity", "wv" ); 63 public static final Obf Entity = new Obf("net.minecraft.entity.Entity", "wv" );
63 public static final Obf RenderManager = new Obf("net.minecraft.client.renderer.entity.RenderManager", "cpt" ); 64 public static final Obf RenderManager = new Obf("net.minecraft.client.renderer.entity.RenderManager", "cpt" );
64 public static final Obf Render = new Obf("net.minecraft.client.renderer.entity.Render", "cpu" ); 65 public static final Obf Render = new Obf("net.minecraft.client.renderer.entity.Render", "cpu" );
  66 + public static final Obf GuiTextField = new Obf("net.minecraft.client.gui.GuiTextField", "bul" );
65 67
66 // Fields 68 // Fields
67 // ----------------------------------------------------------------------------------------- 69 // -----------------------------------------------------------------------------------------
@@ -205,6 +207,48 @@ public class Obf @@ -205,6 +207,48 @@ public class Obf
205 { 207 {
206 return String.format("L%s;", this.names[type].replace('.', '/')); 208 return String.format("L%s;", this.names[type].replace('.', '/'));
207 } 209 }
  210 +
  211 + /**
  212 + * Test whether any of this Obf's dimensions match the supplied name
  213 + *
  214 + * @param name
  215 + */
  216 + public boolean matches(String name)
  217 + {
  218 + return this.obf.equals(name) || this.srg.equals(name)|| this.name.equals(name);
  219 + }
  220 +
  221 + /**
  222 + * Test whether any of this Obf's dimensions match the supplied name or ordinal
  223 + *
  224 + * @param name
  225 + * @param ordinal
  226 + */
  227 + public boolean matches(String name, int ordinal)
  228 + {
  229 + if (this.isOrdinal() && ordinal > -1)
  230 + {
  231 + return this.getOrdinal() == ordinal;
  232 + }
  233 +
  234 + return this.matches(name);
  235 + }
  236 +
  237 + /**
  238 + * Returns true if this is an ordinal pointer
  239 + */
  240 + public boolean isOrdinal()
  241 + {
  242 + return false;
  243 + }
  244 +
  245 + /**
  246 + * Get the ordinal for this entry
  247 + */
  248 + public int getOrdinal()
  249 + {
  250 + return -1;
  251 + }
208 252
209 /** 253 /**
210 * @param seargeName 254 * @param seargeName
@@ -269,4 +313,55 @@ public class Obf @@ -269,4 +313,55 @@ public class Obf
269 313
270 return Obf.getByName(name); 314 return Obf.getByName(name);
271 } 315 }
  316 +
  317 + /**
  318 + * Ordinal reference, can be passed to some methods which accept an {@link Obf} to indicate an offset into a
  319 + * class rather than a named reference.
  320 + *
  321 + * @author Adam Mummery-Smith
  322 + */
  323 + public static class Ord extends Obf
  324 + {
  325 + /**
  326 + * Field/method offset
  327 + */
  328 + private final int ordinal;
  329 +
  330 + /**
  331 + * @param name Field/method name
  332 + * @param ordinal Field/method ordinal
  333 + */
  334 + public Ord(String name, int ordinal)
  335 + {
  336 + super(name);
  337 + this.ordinal = ordinal;
  338 + }
  339 +
  340 + /**
  341 + * @param ordinal Field ordinal
  342 + */
  343 + public Ord(int ordinal)
  344 + {
  345 + super("ord#" + ordinal);
  346 + this.ordinal = ordinal;
  347 + }
  348 +
  349 + /* (non-Javadoc)
  350 + * @see com.mumfrey.liteloader.core.runtime.Obf#isOrdinal()
  351 + */
  352 + @Override
  353 + public boolean isOrdinal()
  354 + {
  355 + return true;
  356 + }
  357 +
  358 + /* (non-Javadoc)
  359 + * @see com.mumfrey.liteloader.core.runtime.Obf#getOrdinal()
  360 + */
  361 + @Override
  362 + public int getOrdinal()
  363 + {
  364 + return this.ordinal;
  365 + }
  366 + }
272 } 367 }
java/common/com/mumfrey/liteloader/transformers/ByteCodeUtilities.java
@@ -526,7 +526,46 @@ public abstract class ByteCodeUtilities @@ -526,7 +526,46 @@ public abstract class ByteCodeUtilities
526 526
527 return null; 527 return null;
528 } 528 }
529 - 529 +
  530 + /**
  531 + * Find a method in the target class which matches the specified method name and descriptor
  532 + *
  533 + * @param classNode
  534 + * @param methodName
  535 + * @param desc
  536 + */
  537 + public static MethodNode findMethod(ClassNode classNode, Obf obf, String desc)
  538 + {
  539 + int ordinal = 0;
  540 +
  541 + for (MethodNode method : classNode.methods)
  542 + {
  543 + if (obf.matches(method.name, ordinal++) && method.desc.equals(desc))
  544 + return method;
  545 + }
  546 +
  547 + return null;
  548 + }
  549 +
  550 + /**
  551 + * Find a field in the target class which matches the specified field name
  552 + *
  553 + * @param classNode
  554 + * @param fieldName
  555 + */
  556 + public static FieldNode findField(ClassNode classNode, Obf obf)
  557 + {
  558 + int ordinal = 0;
  559 +
  560 + for (FieldNode field : classNode.fields)
  561 + {
  562 + if (obf.matches(field.name, ordinal++))
  563 + return field;
  564 + }
  565 +
  566 + return null;
  567 + }
  568 +
530 public static ClassNode loadClass(String className) throws IOException 569 public static ClassNode loadClass(String className) throws IOException
531 { 570 {
532 return ByteCodeUtilities.loadClass(className, true, null); 571 return ByteCodeUtilities.loadClass(className, true, null);
java/common/com/mumfrey/liteloader/transformers/access/AccessorTransformer.java
@@ -4,6 +4,8 @@ import java.io.IOException; @@ -4,6 +4,8 @@ import java.io.IOException;
4 import java.util.ArrayList; 4 import java.util.ArrayList;
5 import java.util.Iterator; 5 import java.util.Iterator;
6 import java.util.List; 6 import java.util.List;
  7 +import java.util.regex.Matcher;
  8 +import java.util.regex.Pattern;
7 9
8 import net.minecraft.launchwrapper.Launch; 10 import net.minecraft.launchwrapper.Launch;
9 11
@@ -33,6 +35,8 @@ import com.mumfrey.liteloader.util.log.LiteLoaderLogger; @@ -33,6 +35,8 @@ import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
33 */ 35 */
34 public abstract class AccessorTransformer extends ClassTransformer 36 public abstract class AccessorTransformer extends ClassTransformer
35 { 37 {
  38 + static final Pattern ordinalRefPattern = Pattern.compile("^#([0-9]{1,5})$");
  39 +
36 /** 40 /**
37 * An injection record 41 * An injection record
38 * 42 *
@@ -103,6 +107,13 @@ public abstract class AccessorTransformer extends ClassTransformer @@ -103,6 +107,13 @@ public abstract class AccessorTransformer extends ClassTransformer
103 */ 107 */
104 private Obf getObf(String name) 108 private Obf getObf(String name)
105 { 109 {
  110 + Matcher ordinalPattern = AccessorTransformer.ordinalRefPattern.matcher(name);
  111 + if (ordinalPattern.matches())
  112 + {
  113 + int ordinal = Integer.parseInt(ordinalPattern.group(1));
  114 + return new Obf.Ord(ordinal);
  115 + }
  116 +
106 if (this.obfProvider != null) 117 if (this.obfProvider != null)
107 { 118 {
108 Obf obf = this.obfProvider.getByName(name); 119 Obf obf = this.obfProvider.getByName(name);
@@ -228,14 +239,14 @@ public abstract class AccessorTransformer extends ClassTransformer @@ -228,14 +239,14 @@ public abstract class AccessorTransformer extends ClassTransformer
228 if (accessor != null) 239 if (accessor != null)
229 { 240 {
230 targetId = ByteCodeUtilities.<String>getAnnotationValue(accessor); 241 targetId = ByteCodeUtilities.<String>getAnnotationValue(accessor);
231 - Obf targetName = this.getObf(targetId);  
232 - if (this.injectAccessor(classNode, method, targetName)) return; 242 + Obf target = this.getObf(targetId);
  243 + if (this.injectAccessor(classNode, method, target)) return;
233 } 244 }
234 else if (invoker != null) 245 else if (invoker != null)
235 { 246 {
236 targetId = ByteCodeUtilities.<String>getAnnotationValue(invoker); 247 targetId = ByteCodeUtilities.<String>getAnnotationValue(invoker);
237 - Obf targetName = this.getObf(targetId);  
238 - if (this.injectInvoker(classNode, method, targetName)) return; 248 + Obf target = this.getObf(targetId);
  249 + if (this.injectInvoker(classNode, method, target)) return;
239 } 250 }
240 else 251 else
241 { 252 {
@@ -255,9 +266,9 @@ public abstract class AccessorTransformer extends ClassTransformer @@ -255,9 +266,9 @@ public abstract class AccessorTransformer extends ClassTransformer
255 * @param method 266 * @param method
256 * @param targetName 267 * @param targetName
257 */ 268 */
258 - private boolean injectAccessor(ClassNode classNode, MethodNode method, Obf targetName) 269 + private boolean injectAccessor(ClassNode classNode, MethodNode method, Obf target)
259 { 270 {
260 - FieldNode targetField = this.findField(classNode, targetName); 271 + FieldNode targetField = ByteCodeUtilities.findField(classNode, target);
261 if (targetField != null) 272 if (targetField != null)
262 { 273 {
263 LiteLoaderLogger.debug("[AccessorTransformer] Found field %s for %s", targetField.name, method.name); 274 LiteLoaderLogger.debug("[AccessorTransformer] Found field %s for %s", targetField.name, method.name);
@@ -283,9 +294,9 @@ public abstract class AccessorTransformer extends ClassTransformer @@ -283,9 +294,9 @@ public abstract class AccessorTransformer extends ClassTransformer
283 * @param method 294 * @param method
284 * @param targetName 295 * @param targetName
285 */ 296 */
286 - private boolean injectInvoker(ClassNode classNode, MethodNode method, Obf targetName) 297 + private boolean injectInvoker(ClassNode classNode, MethodNode method, Obf target)
287 { 298 {
288 - MethodNode targetMethod = this.findMethod(classNode, targetName, method.desc); 299 + MethodNode targetMethod = ByteCodeUtilities.findMethod(classNode, target, method.desc);
289 if (targetMethod != null) 300 if (targetMethod != null)
290 { 301 {
291 LiteLoaderLogger.debug("[AccessorTransformer] Found method %s for %s", targetMethod.name, method.name); 302 LiteLoaderLogger.debug("[AccessorTransformer] Found method %s for %s", targetMethod.name, method.name);
@@ -422,41 +433,6 @@ public abstract class AccessorTransformer extends ClassTransformer @@ -422,41 +433,6 @@ public abstract class AccessorTransformer extends ClassTransformer
422 } 433 }
423 434
424 /** 435 /**
425 - * Find a field in the target class which matches the specified field name  
426 - *  
427 - * @param classNode  
428 - * @param fieldName  
429 - */  
430 - private FieldNode findField(ClassNode classNode, Obf fieldName)  
431 - {  
432 - for (FieldNode field : classNode.fields)  
433 - {  
434 - if (fieldName.obf.equals(field.name) || fieldName.srg.equals(field.name)|| fieldName.name.equals(field.name))  
435 - return field;  
436 - }  
437 -  
438 - return null;  
439 - }  
440 -  
441 - /**  
442 - * Find a method in the target class which matches the specified method name and descriptor  
443 - *  
444 - * @param classNode  
445 - * @param methodName  
446 - * @param desc  
447 - */  
448 - private MethodNode findMethod(ClassNode classNode, Obf methodName, String desc)  
449 - {  
450 - for (MethodNode method : classNode.methods)  
451 - {  
452 - if ((methodName.obf.equals(method.name) || methodName.srg.equals(method.name)|| methodName.name.equals(method.name)) && method.desc.equals(desc))  
453 - return method;  
454 - }  
455 -  
456 - return null;  
457 - }  
458 -  
459 - /**  
460 * Add a method from the template interface to the target class 436 * Add a method from the template interface to the target class
461 * 437 *
462 * @param classNode 438 * @param classNode