-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c470b1
commit 9b00a6b
Showing
6 changed files
with
76 additions
and
9 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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/warmthdawn/mod/gugu_utils/asm/utils/SafeClassWriter.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,43 @@ | ||
package com.warmthdawn.mod.gugu_utils.asm.utils; | ||
|
||
import net.minecraft.launchwrapper.Launch; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
|
||
/** | ||
* Created by Thiakil on 16/11/2017. | ||
*/ | ||
public class SafeClassWriter extends ClassWriter { | ||
public SafeClassWriter(int flags) { | ||
super(flags); | ||
} | ||
|
||
public SafeClassWriter(ClassReader classReader, int flags) { | ||
super(classReader, flags); | ||
} | ||
|
||
protected String getCommonSuperClass(final String type1, final String type2) { | ||
Class<?> c, d; | ||
ClassLoader classLoader = Launch.classLoader; | ||
try { | ||
c = Class.forName(type1.replace('/', '.'), false, classLoader); | ||
d = Class.forName(type2.replace('/', '.'), false, classLoader); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e.toString()); | ||
} | ||
if (c.isAssignableFrom(d)) { | ||
return type1; | ||
} | ||
if (d.isAssignableFrom(c)) { | ||
return type2; | ||
} | ||
if (c.isInterface() || d.isInterface()) { | ||
return "java/lang/Object"; | ||
} else { | ||
do { | ||
c = c.getSuperclass(); | ||
} while (!c.isAssignableFrom(d)); | ||
return c.getName().replace('.', '/'); | ||
} | ||
} | ||
} |