-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactoring + Beta Forge patch
- Loading branch information
1 parent
32320d6
commit c0c67b2
Showing
10 changed files
with
166 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/uk/betacraft/legacyfix/patch/impl/BetaForgePatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package uk.betacraft.legacyfix.patch.impl; | ||
|
||
import javassist.CannotCompileException; | ||
import javassist.CtClass; | ||
import javassist.expr.ExprEditor; | ||
import javassist.expr.MethodCall; | ||
import uk.betacraft.legacyfix.patch.Patch; | ||
|
||
import java.lang.instrument.ClassDefinition; | ||
import java.lang.instrument.Instrumentation; | ||
|
||
/** | ||
* Patches b1.7.3 - b1.8.1 Forge | ||
*/ | ||
public class BetaForgePatch extends Patch { | ||
public BetaForgePatch() { | ||
super("betaforge", "Beta Forge"); | ||
} | ||
|
||
@Override | ||
public boolean apply(Instrumentation inst) throws Exception { | ||
CtClass clazz = pool.getOrNull("forge.ForgeHooksClient"); | ||
if (clazz == null) return false; | ||
|
||
clazz.instrument(new ExprEditor() { | ||
public void edit(MethodCall m) throws CannotCompileException { | ||
if (m.getMethodName().equals("toArray") && m.getSignature().equals("()[Ljava/lang/Object;")) { | ||
m.replace("$_ = $0.toArray(new Integer[0]);"); | ||
} | ||
} | ||
}); | ||
|
||
inst.redefineClasses(new ClassDefinition(Class.forName(clazz.getName()), clazz.toBytecode())); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/uk/betacraft/legacyfix/patch/impl/TexturePackFolderPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package uk.betacraft.legacyfix.patch.impl; | ||
|
||
import java.lang.instrument.ClassDefinition; | ||
import java.lang.instrument.Instrumentation; | ||
|
||
import javassist.CtClass; | ||
import javassist.CtMethod; | ||
import uk.betacraft.legacyfix.LFLogger; | ||
import uk.betacraft.legacyfix.patch.Patch; | ||
|
||
/** | ||
* Patch for unresponsive "Open texture pack folder" button in versions before 1.2-pre on Linux and macOS | ||
*/ | ||
public class TexturePackFolderPatch extends Patch { | ||
public TexturePackFolderPatch() { | ||
super("texturePackButton", "Patch open texture pack folder button"); | ||
} | ||
|
||
@Override | ||
public boolean apply(final Instrumentation inst) throws Exception { | ||
CtClass clazz; | ||
CtMethod method; | ||
CtClass string = pool.get("java.lang.String"); | ||
|
||
clazz = pool.getOrNull("org.lwjgl.Sys"); | ||
if (clazz == null) return false; | ||
|
||
method = clazz.getDeclaredMethod("openURL", new CtClass[] {string}); | ||
method.insertBefore( | ||
"if ($1 != null && $1.indexOf(\"file://\") == 0) {" + | ||
" String txpfolder = $1.substring(7);" + | ||
" try {" + | ||
" Class desktopClass = Class.forName(\"java.awt.Desktop\");" + | ||
" Object desktop = desktopClass.getMethod(\"getDesktop\").invoke((Object) null);" + | ||
" desktopClass.getMethod(\"browse\", java.net.URI.class).invoke(desktop, (new java.io.File(txpfolder)).toURI());" + | ||
" return true;" + | ||
" } catch (Throwable t) {" + | ||
" t.printStackTrace();" + // if failed, don't return and have a shot at the Sys.openURL method (vanilla behavior since 1.2-pre) | ||
" }" + | ||
"}" | ||
); | ||
|
||
inst.redefineClasses(new ClassDefinition(Class.forName(clazz.getName()), clazz.toBytecode())); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean shouldApply() { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.