Skip to content

Commit

Permalink
Now with ~80% less compile errors! Fixed missing jackson JSON mapper …
Browse files Browse the repository at this point in the history
…library, fixed PatchInt/LongHashMap, fixed WrappedScheduledTickHandler.

Signed-off-by: Ross Allan <rallanpcl@gmail.com>
  • Loading branch information
LunNova committed Apr 30, 2014
1 parent dc35931 commit 29e9977
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 79 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Expand Up @@ -20,6 +20,8 @@ apply plugin: 'forge'
dependencies {
compile 'org.javassist:javassist:3.18.1-GA'
compile 'com.github.stephenc.high-scale-lib:high-scale-lib:1.1.4'
compile 'org.codehaus.jackson:jackson-core-lgpl:1.9.13'
compile 'org.codehaus.jackson:jackson-mapper-lgpl:1.9.13'
}

sourceCompatibility = JavaVersion.VERSION_1_6
Expand Down
46 changes: 18 additions & 28 deletions buildSrc/src/nallar/nmsprepatcher/PrePatcher.java
Expand Up @@ -22,7 +22,6 @@ class PrePatcher {
private static final Logger log = Logger.getLogger("PatchLogger");
private static final Pattern privatePattern = Pattern.compile("^(\\s+?)private", Pattern.MULTILINE);
private static final Pattern extendsPattern = Pattern.compile("^public.*?\\s+?extends\\s+?([\\S^<]+?)(?:<(\\S+)>)?[\\s]+?(?:implements [^}]+?)?\\{", Pattern.MULTILINE);
private static final Pattern genericMethodPattern = Pattern.compile("@Generic\\s+?(public\\s+?(\\S*?)?\\s+?(\\S*?)\\s*?\\S+?\\s*?\\()[^\\{]*\\)\\s*?\\{", Pattern.DOTALL | Pattern.MULTILINE);
private static final Pattern declareMethodPattern = Pattern.compile("@Declare\\s+?(public\\s+?(?:(?:synchronized|static) )*(\\S*?)?\\s+?(\\S*?)\\s*?\\S+?\\s*?\\([^\\{]*\\)\\s*?\\{)", Pattern.DOTALL | Pattern.MULTILINE);
private static final Pattern declareFieldPattern = Pattern.compile("@Declare\\s+?(public [^;\r\n]+?)_?( = [^;\r\n]+?)?;", Pattern.DOTALL | Pattern.MULTILINE);
private static final Pattern packageFieldPattern = Pattern.compile("\n ? ?([^ ]+ ? ?[^ ]+);");
Expand Down Expand Up @@ -72,7 +71,6 @@ private static void addPatches(File file) {
List<String> imports = new ArrayList<String>();
while (importMatcher.find()) {
imports.add(importMatcher.group(1));
//log.severe(importMatcher.group(1));
}
for (String import_ : imports) {
if (import_.endsWith('.' + shortClassName)) {
Expand All @@ -83,13 +81,11 @@ private static void addPatches(File file) {
log.warning("Unable to find class " + shortClassName + " for " + file);
return;
}
String generic = extendsMatcher.group(2);
PatchInfo patchInfo = patchClasses.get(className);
if (patchInfo == null) {
patchInfo = new PatchInfo();
patchClasses.put(className, patchInfo);
}
patchInfo.genericType = generic;
patchInfo.shortClassName = shortClassName;
Matcher matcher = declareMethodPattern.matcher(contents);
while (matcher.find()) {
Expand Down Expand Up @@ -159,7 +155,6 @@ private static void addPatches(File file) {
ret = "0.0";
}
methodInfo.javaCode = matcher.group(1) + "return " + ret + ";}";
log.warning(methodInfo.toString());
}
Matcher fieldMatcher = declareFieldPattern.matcher(contents);
while (fieldMatcher.find()) {
Expand Down Expand Up @@ -187,16 +182,9 @@ private static void addPatches(File file) {
}
}
fieldInfo.javaCode = var + ';';
log.warning(fieldInfo.toString());
}
Matcher genericMatcher = genericMethodPattern.matcher(contents);
while (genericMatcher.find()) {
String original = genericMatcher.group(1);
String withoutGenerics = original.replace(' ' + generic + ' ', " Object ");
log.warning(original + " -> " + withoutGenerics);
}
if (contents.contains("\n@Public")) {
patchInfo.makeAllPublic = true;
patchInfo.makePublic = true;
}
}

Expand Down Expand Up @@ -305,14 +293,14 @@ private String javaString(boolean useGenerics) {
} else if (clazz.contains("[") || clazz.contains("]")) {
log.severe("Invalid Type " + this + ", contains broken array info.");
} else if (clazz.contains(".")) {
return "L" + clazz + genericSignatureIfNeeded(useGenerics) + ";";
return "L" + clazz.replace(".", "/") + genericSignatureIfNeeded(useGenerics) + ";";
}
String primitiveType = primitiveTypeToDescriptor(clazz);
if (primitiveType != null) {
return primitiveType;
}
log.severe("Unrecognised Type: " + this.toString());
return "Ljava.lang.Object;";
return "Ljava/lang/Object;";
}

public String descriptor() {
Expand Down Expand Up @@ -414,9 +402,8 @@ public int accessAsInt() {
private static class PatchInfo {
List<MethodInfo> methods = new ArrayList<MethodInfo>();
List<FieldInfo> fields = new ArrayList<FieldInfo>();
boolean makeAllPublic = false;
boolean makePublic = false;
String shortClassName;
String genericType;
}

private static PatchInfo patchForClass(String className) {
Expand All @@ -428,7 +415,6 @@ public static String patchSource(String inputSource, String inputClassName) {
if (patchInfo == null) {
return inputSource;
}
log.warning("Prepatching source for " + inputClassName);
inputSource = inputSource.trim().replace("\t", " ");
String shortClassName = patchInfo.shortClassName;
StringBuilder sourceBuilder = new StringBuilder(inputSource.substring(0, inputSource.lastIndexOf('}')))
Expand All @@ -445,9 +431,6 @@ public static String patchSource(String inputSource, String inputClassName) {
}
sourceBuilder.append("\n}");
inputSource = sourceBuilder.toString();
if (patchInfo.genericType != null) {
inputSource = inputSource.replaceAll("class " + shortClassName + "(<[^>]>)?", "class " + shortClassName + '<' + patchInfo.genericType + '>');
}
/*Matcher genericMatcher = genericMethodPattern.matcher(contents);
while (genericMatcher.find()) {
String original = genericMatcher.group(1);
Expand All @@ -468,10 +451,9 @@ public static String patchSource(String inputSource, String inputClassName) {
inputSource = inputSource.replace("private class", "public class");
inputSource = inputSource.replace("protected class", "public class");
inputSource = privatePattern.matcher(inputSource).replaceAll("$1protected");
if (patchInfo.makeAllPublic) {
if (patchInfo.makePublic) {
inputSource = inputSource.replace("protected ", "public ");
}
inputSource = inputSource.replace("protected void save(", "public void save(");
Matcher packageMatcher = packageFieldPattern.matcher(inputSource);
StringBuffer sb = new StringBuffer();
while (packageMatcher.find()) {
Expand Down Expand Up @@ -499,6 +481,14 @@ private static int replaceFlag(int in, int from, int to) {
return in;
}

private static int makeAccess(int access, boolean makePublic) {
access = makeAtLeastProtected(access);
if (makePublic) {
access = replaceFlag(access, Opcodes.ACC_PROTECTED, Opcodes.ACC_PUBLIC);
}
return access;
}

/**
* Changes access flags to be protected, unless already public.
*
Expand All @@ -523,24 +513,24 @@ public static byte[] patchCode(byte[] inputCode, String inputClassName) {
if (patchInfo == null) {
return inputCode;
}
log.warning("Prepatching code for " + inputClassName);
ClassReader classReader = new ClassReader(inputCode);
ClassNode classNode = new ClassNode();
classReader.accept(classNode, 0);
classNode.access = classNode.access & ~Opcodes.ACC_FINAL;
classNode.access = makeAccess(classNode.access, true);
for (FieldNode fieldNode : (Iterable<FieldNode>) classNode.fields) {
fieldNode.access = fieldNode.access & ~Opcodes.ACC_FINAL;
fieldNode.access = makeAtLeastProtected(fieldNode.access);
fieldNode.access = makeAccess(fieldNode.access, patchInfo.makePublic);
}
for (MethodNode methodNode : (Iterable<MethodNode>) classNode.methods) {
methodNode.access = methodNode.access & ~Opcodes.ACC_FINAL;
methodNode.access = makeAtLeastProtected(methodNode.access);
methodNode.access = makeAccess(methodNode.access, patchInfo.makePublic);
}
for (FieldInfo fieldInfo : patchInfo.fields) {
classNode.fields.add(new FieldNode(makeAtLeastProtected(fieldInfo.accessAsInt()), fieldInfo.name, fieldInfo.type.descriptor(), fieldInfo.type.signature(), null));
classNode.fields.add(new FieldNode(makeAccess(fieldInfo.accessAsInt(), patchInfo.makePublic), fieldInfo.name, fieldInfo.type.descriptor(), fieldInfo.type.signature(), null));
}
for (MethodInfo methodInfo : patchInfo.methods) {
classNode.methods.add(new MethodNode(makeAtLeastProtected(methodInfo.accessAsInt()), methodInfo.name, methodInfo.descriptor(), methodInfo.signature(), null));
classNode.methods.add(new MethodNode(makeAccess(methodInfo.accessAsInt() & ~Opcodes.ACC_FINAL, patchInfo.makePublic), methodInfo.name, methodInfo.descriptor(), methodInfo.signature(), null));
}
ClassWriter classWriter = new ClassWriter(classReader, 0);
classNode.accept(classWriter);
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/nallar/patched/collection/PatchIntHashMap.java
Expand Up @@ -13,11 +13,11 @@

@SuppressWarnings("unchecked")
@FakeExtend
public abstract class PatchIntHashMap<V> extends IntHashMap<V> {
public abstract class PatchIntHashMap extends IntHashMap {
private static final int EMPTY_KEY = Integer.MIN_VALUE;
private static final int BUCKET_SIZE = 4096;
int[][] keys;
private Object[][] values;
private java.lang.Object[][] values;
int size;
int modCount;

Expand All @@ -32,7 +32,7 @@ public boolean containsItem(int key) {

@Override
@Generic
public V lookup(int key) {
public Object lookup(int key) {
int index = keyIndex(key) & (BUCKET_SIZE - 1);
int[] inner = keys[index];
if (inner == null) {
Expand All @@ -44,9 +44,9 @@ public V lookup(int key) {
if (innerKey == EMPTY_KEY) {
return null;
} else if (innerKey == key) {
Object[] value = values[index];
java.lang.Object[] value = values[index];
if (value != null) {
return (V) value[i];
return (Object) value[i];
}
}
}
Expand All @@ -55,22 +55,22 @@ public V lookup(int key) {
}

@Override
public void addKey(int key, Object value) {
public void addKey(int key, java.lang.Object value) {
put(key, value);
}

@Override
@Declare
public synchronized V put(int key, Object value) {
public synchronized Object put(int key, java.lang.Object value) {
int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1));
int[] innerKeys = keys[index];
Object[] innerValues = values[index];
java.lang.Object[] innerValues = values[index];

if (innerKeys == null) {
// need to make a new chain
keys[index] = innerKeys = new int[8];
Arrays.fill(innerKeys, EMPTY_KEY);
values[index] = innerValues = new Object[8];
values[index] = innerValues = new java.lang.Object[8];
innerKeys[0] = key;
innerValues[0] = value;
size++;
Expand All @@ -83,10 +83,10 @@ public synchronized V put(int key, Object value) {
size++;
}
if (currentKey == EMPTY_KEY || currentKey == key) {
Object old = innerValues[i];
java.lang.Object old = innerValues[i];
innerKeys[i] = key;
innerValues[i] = value;
return (V) old;
return (Object) old;
}
}

Expand All @@ -102,7 +102,7 @@ public synchronized V put(int key, Object value) {
}

@Override
public Object removeObject(int key) {
public java.lang.Object removeObject(int key) {
int index = (keyIndex(key) & (BUCKET_SIZE - 1));
int[] inner = keys[index];
if (inner == null) {
Expand All @@ -116,7 +116,7 @@ public Object removeObject(int key) {
}

if (inner[i] == key) {
Object value = values[index][i];
java.lang.Object value = values[index][i];

for (i++; i < inner.length; i++) {
if (inner[i] == EMPTY_KEY) {
Expand Down Expand Up @@ -152,7 +152,7 @@ public void clearMap() {

private void initialize() {
keys = new int[BUCKET_SIZE][];
values = new Object[BUCKET_SIZE][];
values = new java.lang.Object[BUCKET_SIZE][];
}

private static int keyIndex(int key) {
Expand Down Expand Up @@ -195,7 +195,7 @@ private class ValueIterator implements Iterator {
private int expectedModCount;
private int lastReturned = EMPTY_KEY;
int prevKey = EMPTY_KEY;
Object prevValue;
java.lang.Object prevValue;

ValueIterator() {
expectedModCount = PatchIntHashMap.this.modCount;
Expand Down Expand Up @@ -223,7 +223,7 @@ public void remove() {
}

@Override
public Object next() {
public java.lang.Object next() {
if (PatchIntHashMap.this.modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
Expand All @@ -243,7 +243,7 @@ public Object next() {
if (keys[index] != null) {
if (innerIndex < keys[index].length) {
int key = keys[index][innerIndex];
Object value = values[index][innerIndex];
java.lang.Object value = values[index][innerIndex];
if (key == EMPTY_KEY) {
break;
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/nallar/patched/collection/PatchLongHashMap.java
Expand Up @@ -13,11 +13,11 @@

@SuppressWarnings("unchecked")
@FakeExtend
public abstract class PatchLongHashMap<V> extends LongHashMap<V> {
public abstract class PatchLongHashMap extends LongHashMap {
private static final long EMPTY_KEY = Long.MIN_VALUE;
private static final int BUCKET_SIZE = 8192;
private final long[][] keys = new long[BUCKET_SIZE][];
private final Object[][] values = new Object[BUCKET_SIZE][];
private final java.lang.Object[][] values = new java.lang.Object[BUCKET_SIZE][];
private int size;

@Override
Expand All @@ -38,7 +38,7 @@ public boolean containsItem(long key) {

@Override
@Generic
public V getValueByKey(long key) {
public Object getValueByKey(long key) {
int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1));
long[] inner = keys[index];
if (inner == null) {
Expand All @@ -50,9 +50,9 @@ public V getValueByKey(long key) {
if (innerKey == EMPTY_KEY) {
return null;
} else if (innerKey == key) {
Object[] value = values[index];
java.lang.Object[] value = values[index];
if (value != null) {
return (V) value[i];
return (Object) value[i];
}
}
}
Expand All @@ -61,22 +61,22 @@ public V getValueByKey(long key) {
}

@Override
public void add(long key, Object value) {
public void add(long key, java.lang.Object value) {
put(key, value);
}

@Override
@Declare
public synchronized V put(long key, Object value) {
public synchronized Object put(long key, java.lang.Object value) {
int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1));
long[] innerKeys = keys[index];
Object[] innerValues = values[index];
java.lang.Object[] innerValues = values[index];

if (innerKeys == null) {
// need to make a new chain
keys[index] = innerKeys = new long[8];
Arrays.fill(innerKeys, EMPTY_KEY);
values[index] = innerValues = new Object[8];
values[index] = innerValues = new java.lang.Object[8];
innerKeys[0] = key;
innerValues[0] = value;
size++;
Expand All @@ -89,10 +89,10 @@ public synchronized V put(long key, Object value) {
size++;
}
if (currentKey == EMPTY_KEY || currentKey == key) {
Object old = innerValues[i];
java.lang.Object old = innerValues[i];
innerKeys[i] = key;
innerValues[i] = value;
return (V) old;
return (Object) old;
}
}

Expand All @@ -108,7 +108,7 @@ public synchronized V put(long key, Object value) {
}

@Override
public synchronized Object remove(long key) {
public synchronized java.lang.Object remove(long key) {
int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1));
long[] inner = keys[index];
if (inner == null) {
Expand All @@ -122,7 +122,7 @@ public synchronized Object remove(long key) {
}

if (inner[i] == key) {
Object value = values[index][i];
java.lang.Object value = values[index][i];

for (i++; i < inner.length; i++) {
if (inner[i] == EMPTY_KEY) {
Expand Down

0 comments on commit 29e9977

Please sign in to comment.