aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/djtheredstoner
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/djtheredstoner')
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java133
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/ClassTransformer.java118
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/ITransformer.java98
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook.java16
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook.java32
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook.java16
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook.java15
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/ActiveRenderInfoTransformer.java68
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/EntityRendererTransformer.java128
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/MinecraftTransformer.java57
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/RenderManagerTransformer.java71
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/commands/PerspectiveModCommand.java19
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/config/PerspectiveModConfig.java42
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModTweaker.java77
14 files changed, 890 insertions, 0 deletions
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
new file mode 100644
index 0000000..8ef5ed5
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
@@ -0,0 +1,133 @@
+package me.djtheredstoner.perspectivemod;
+
+import me.djtheredstoner.perspectivemod.commands.PerspectiveModCommand;
+import me.djtheredstoner.perspectivemod.config.PerspectiveModConfig;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.settings.GameSettings;
+import net.minecraft.client.settings.KeyBinding;
+import net.minecraftforge.client.ClientCommandHandler;
+import net.minecraftforge.client.event.GuiOpenEvent;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.world.WorldEvent;
+import net.minecraftforge.fml.client.registry.ClientRegistry;
+import net.minecraftforge.fml.common.Mod;
+import net.minecraftforge.fml.common.event.FMLInitializationEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.opengl.Display;
+
+@Mod(modid = "djperspectivemod", name = "Perspective Mod v4", version = "4.5", acceptedMinecraftVersions = "[1.8.9]", clientSideOnly = true)
+public class PerspectiveMod {
+
+ @Mod.Instance
+ public static PerspectiveMod instance;
+
+ public final PerspectiveModConfig config = new PerspectiveModConfig();
+
+ public boolean perspectiveToggled = false;
+ public float cameraYaw = 0F;
+ public float cameraPitch = 0F;
+
+ private int previousPerspective = 0;
+ private boolean prevState = false;
+
+ private final Minecraft mc = Minecraft.getMinecraft();
+ private final KeyBinding perspectiveKey = new KeyBinding("Perspective", Keyboard.KEY_LMENU, "Perspective Mod");
+ private final Logger logger = LogManager.getLogger("Perspective Mod v4");
+
+ @Mod.EventHandler
+ public void init(FMLInitializationEvent event) {
+ config.preload();
+
+ ClientRegistry.registerKeyBinding(perspectiveKey);
+ new PerspectiveModCommand("perspectivemod").register();
+ new PerspectiveModCommand("pmod").register();
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ @SubscribeEvent
+ public void tick(TickEvent.RenderTickEvent event) {
+ boolean down = GameSettings.isKeyDown(perspectiveKey);
+ if(down != prevState && mc.currentScreen == null && mc.theWorld != null && mc.thePlayer != null) {
+ prevState = down;
+ onPressed(down);
+ }
+ }
+
+ @SubscribeEvent
+ public void onGuiOpen(GuiOpenEvent event) {
+ if (event.gui != null && perspectiveToggled && config.holdMode) {
+ resetPerspective();
+ }
+ }
+
+ @SubscribeEvent
+ public void onWorldLoad(WorldEvent.Load event) {
+ if (perspectiveToggled) {
+ resetPerspective();
+ }
+ }
+
+ public void onPressed(boolean state) {
+ if (config.modEnabled) {
+ if (state) {
+ cameraYaw = mc.thePlayer.rotationYaw;
+ cameraPitch = mc.thePlayer.rotationPitch;
+
+ if (perspectiveToggled) {
+ resetPerspective();
+ } else {
+ enterPerspective();
+ }
+ mc.renderGlobal.setDisplayListEntitiesDirty();
+ } else if (config.holdMode) {
+ resetPerspective();
+ }
+ } else if (perspectiveToggled) {
+ resetPerspective();
+ }
+ }
+
+ public void enterPerspective() {
+ perspectiveToggled = true;
+ previousPerspective = mc.gameSettings.thirdPersonView;
+ mc.gameSettings.thirdPersonView = 1;
+ }
+
+ public void resetPerspective() {
+ perspectiveToggled = false;
+ mc.gameSettings.thirdPersonView = previousPerspective;
+ mc.renderGlobal.setDisplayListEntitiesDirty();
+ }
+
+ public boolean overrideMouse() {
+ if (mc.inGameHasFocus && Display.isActive()) {
+ if (!perspectiveToggled) {
+ return true;
+ }
+
+ // CODE
+ mc.mouseHelper.mouseXYChange();
+ float f1 = mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
+ float f2 = f1 * f1 * f1 * 8.0F;
+ float f3 = (float) mc.mouseHelper.deltaX * f2;
+ float f4 = (float) mc.mouseHelper.deltaY * f2;
+
+ if(config.invertPitch) {
+ f4 = -f4;
+ }
+
+ cameraYaw += f3 * 0.15F;
+ cameraPitch += f4 * 0.15F;
+
+ if (cameraPitch > 90) cameraPitch = 90;
+ if (cameraPitch < -90) cameraPitch = -90;
+ mc.renderGlobal.setDisplayListEntitiesDirty();
+ }
+
+ return false;
+ }
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/ClassTransformer.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/ClassTransformer.java
new file mode 100644
index 0000000..c7db68b
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/ClassTransformer.java
@@ -0,0 +1,118 @@
+package me.djtheredstoner.perspectivemod.asm;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import me.djtheredstoner.perspectivemod.asm.transformers.ActiveRenderInfoTransformer;
+import me.djtheredstoner.perspectivemod.asm.transformers.EntityRendererTransformer;
+import me.djtheredstoner.perspectivemod.asm.transformers.MinecraftTransformer;
+import me.djtheredstoner.perspectivemod.asm.transformers.RenderManagerTransformer;
+import net.minecraft.launchwrapper.IClassTransformer;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.tree.ClassNode;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Collection;
+
+public class ClassTransformer implements IClassTransformer {
+
+ // create a logger to distinguish our errors from a normal error
+ private static final Logger LOGGER = LogManager.getLogger("Perspective Mod v4 Transformer");
+
+ // create a map of transformers
+ private final Multimap<String, ITransformer> transformerMap = ArrayListMultimap.create();
+
+ // make a jvm flag that could be used to dump transformed classes
+ // usable by adding -DdebugBytecode=true to the jvm arguments
+ public static final boolean outputBytecode = Boolean.parseBoolean(System.getProperty("debugBytecode", "false"));
+
+ public ClassTransformer() {
+ // any transformer will be registered here
+ registerTransformer(new EntityRendererTransformer());
+ registerTransformer(new RenderManagerTransformer());
+ registerTransformer(new MinecraftTransformer());
+ registerTransformer(new ActiveRenderInfoTransformer());
+ }
+
+ private void registerTransformer(ITransformer transformer) {
+ // loop through names of classes
+ for (String cls : transformer.getClassName()) {
+ // put the classes into the transformer map
+ transformerMap.put(cls, transformer);
+ }
+ }
+
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ @Override
+ public byte[] transform(String name, String transformedName, byte[] bytes) {
+ if (bytes == null) return null;
+
+ // get the list of transformers
+ Collection<ITransformer> transformers = transformerMap.get(transformedName);
+ // if empty, don't bother trying to run through transformation
+ if (transformers.isEmpty()) return bytes;
+
+ // wjat
+ ClassReader reader = new ClassReader(bytes);
+ ClassNode node = new ClassNode();
+ reader.accept(node, ClassReader.EXPAND_FRAMES);
+
+ // for every transformer, perform the transformations
+ for (ITransformer transformer : transformers) {
+ transformer.transform(node, transformedName);
+ }
+
+ // what?????
+ ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
+
+ try {
+ // write™
+ node.accept(writer);
+ } catch (Throwable t) {
+ LOGGER.error("Exception when transforming " + transformedName + " : " + t.getClass().getSimpleName());
+ t.printStackTrace();
+ }
+
+ if (outputBytecode) {
+ File bytecodeDirectory = new File("bytecode");
+ String transformedClassName;
+
+ // anonymous classes
+ if (transformedName.contains("$")) {
+ transformedClassName = transformedName.replace('$', '.') + ".class";
+ } else {
+ transformedClassName = transformedName + ".class";
+ }
+
+ if (!bytecodeDirectory.exists()) {
+ bytecodeDirectory.mkdirs();
+ }
+
+ File bytecodeOutput = new File(bytecodeDirectory, transformedClassName);
+
+ try {
+ if (!bytecodeOutput.exists()) {
+ bytecodeOutput.createNewFile();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try (FileOutputStream os = new FileOutputStream(bytecodeOutput)) {
+ // write to the generated class to /run/bytecode/classfile.class
+ // with the class bytes from transforming
+ os.write(writer.toByteArray());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // return the written bytes and finalize transform
+ return writer.toByteArray();
+ }
+
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/ITransformer.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/ITransformer.java
new file mode 100644
index 0000000..9ef82be
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/ITransformer.java
@@ -0,0 +1,98 @@
+package me.djtheredstoner.perspectivemod.asm;
+
+import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
+import org.objectweb.asm.tree.*;
+
+public interface ITransformer {
+
+ /**
+ * The class name that's being transformed
+ *
+ * @return the class name
+ */
+ String[] getClassName();
+
+ /**
+ * Perform any asm in order to transform code
+ *
+ * @param classNode the transformed class node
+ * @param name the transformed class name
+ */
+ void transform(ClassNode classNode, String name);
+
+ /**
+ * Map the method name from notch names
+ *
+ * @param classNode the transformed class node
+ * @param methodNode the transformed classes method node
+ * @return a mapped method name
+ */
+ default String mapMethodName(ClassNode classNode, MethodNode methodNode) {
+ return FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(classNode.name, methodNode.name, methodNode.desc);
+ }
+
+ /**
+ * Map the field name from notch names
+ *
+ * @param classNode the transformed class node
+ * @param fieldNode the transformed classes field node
+ * @return a mapped field name
+ */
+ default String mapFieldName(ClassNode classNode, FieldNode fieldNode) {
+ return FMLDeobfuscatingRemapper.INSTANCE.mapFieldName(classNode.name, fieldNode.name, fieldNode.desc);
+ }
+
+ /**
+ * Map the method desc from notch names
+ *
+ * @param methodNode the transformed method node
+ * @return a mapped method desc
+ */
+ default String mapMethodDesc(MethodNode methodNode) {
+ return FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(methodNode.desc);
+ }
+
+ /**
+ * Map the method name from notch names
+ *
+ * @param methodInsnNode the transformed method insn node
+ * @return a mapped insn method
+ */
+ default String mapMethodNameFromNode(MethodInsnNode methodInsnNode) {
+ return FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(methodInsnNode.owner, methodInsnNode.name, methodInsnNode.desc);
+ }
+
+ /**
+ * Map the field name from notch names
+ *
+ * @param fieldInsnNode the transformed field insn node
+ * @return a mapped insn field
+ */
+ default String mapFieldNameFromNode(FieldInsnNode fieldInsnNode) {
+ return FMLDeobfuscatingRemapper.INSTANCE.mapFieldName(fieldInsnNode.owner, fieldInsnNode.name, fieldInsnNode.desc);
+ }
+
+ default String mapClassName(String name) {
+ return FMLDeobfuscatingRemapper.INSTANCE.mapType(name);
+ }
+
+ /**
+ * Remove instructions to this method
+ *
+ * @param methodNode the method being cleared
+ */
+ default void clearInstructions(MethodNode methodNode) {
+ methodNode.instructions.clear();
+
+ // dont waste time clearing local variables if they're empty
+ if (!methodNode.localVariables.isEmpty()) {
+ methodNode.localVariables.clear();
+ }
+
+ // dont waste time clearing try-catches if they're empty
+ if (!methodNode.tryCatchBlocks.isEmpty()) {
+ methodNode.tryCatchBlocks.clear();
+ }
+ }
+
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook.java
new file mode 100644
index 0000000..94296d1
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook.java
@@ -0,0 +1,16 @@
+package me.djtheredstoner.perspectivemod.asm.hooks;
+
+import me.djtheredstoner.perspectivemod.PerspectiveMod;
+import net.minecraft.entity.player.EntityPlayer;
+
+public class ActiveRenderInfoHook {
+
+ public static float rotationYawHook(EntityPlayer entity) {
+ return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraYaw : entity.rotationYaw;
+ }
+
+ public static float rotationPitchHook(EntityPlayer entity) {
+ return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraPitch : entity.rotationPitch;
+ }
+
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook.java
new file mode 100644
index 0000000..a6ea788
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook.java
@@ -0,0 +1,32 @@
+package me.djtheredstoner.perspectivemod.asm.hooks;
+
+import me.djtheredstoner.perspectivemod.PerspectiveMod;
+import net.minecraft.client.Minecraft;
+import net.minecraft.entity.Entity;
+
+public class EntityRendererHook {
+
+ public static float rotationYawHook(Entity entity) {
+ return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraYaw : entity.rotationYaw;
+ }
+
+ public static float prevRotationYawHook(Entity entity) {
+ return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraYaw : entity.prevRotationYaw;
+ }
+
+ public static float rotationPitchHook(Entity entity) {
+ return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraPitch : entity.rotationPitch;
+ }
+
+ public static float prevRotationPitchHook(Entity entity) {
+ return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraPitch : entity.prevRotationPitch;
+ }
+
+ public static boolean mouseHook(Minecraft minecraft) {
+ return PerspectiveMod.instance == null ? minecraft.inGameHasFocus : PerspectiveMod.instance.overrideMouse();
+ }
+
+ public static double distanceHook(double value) {
+ return value;
+ }
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook.java
new file mode 100644
index 0000000..31914f8
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook.java
@@ -0,0 +1,16 @@
+package me.djtheredstoner.perspectivemod.asm.hooks;
+
+import me.djtheredstoner.perspectivemod.PerspectiveMod;
+import net.minecraft.client.settings.GameSettings;
+
+public class MinecraftHook {
+
+ public static void thirdPersonHook(GameSettings gameSettings, int value) {
+ if(PerspectiveMod.instance.perspectiveToggled) {
+ PerspectiveMod.instance.resetPerspective();
+ } else {
+ gameSettings.thirdPersonView = value;
+ }
+ }
+
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook.java
new file mode 100644
index 0000000..2f55de1
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook.java
@@ -0,0 +1,15 @@
+package me.djtheredstoner.perspectivemod.asm.hooks;
+
+import me.djtheredstoner.perspectivemod.PerspectiveMod;
+import net.minecraft.client.renderer.entity.RenderManager;
+
+public class RenderManagerHook {
+
+ public static void playerViewXHook(RenderManager renderManager, float value) {
+ renderManager.playerViewX = PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraPitch : value;
+ }
+
+ public static void playerViewYHook(RenderManager renderManager, float value) {
+ renderManager.playerViewY = PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraYaw : value;
+ }
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/ActiveRenderInfoTransformer.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/ActiveRenderInfoTransformer.java
new file mode 100644
index 0000000..9a37575
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/ActiveRenderInfoTransformer.java
@@ -0,0 +1,68 @@
+package me.djtheredstoner.perspectivemod.asm.transformers;
+
+import me.djtheredstoner.perspectivemod.asm.ITransformer;
+import org.objectweb.asm.tree.*;
+
+import java.util.ListIterator;
+
+import static org.objectweb.asm.Opcodes.*;
+
+public class ActiveRenderInfoTransformer implements ITransformer {
+
+ private static final String HOOK_CLASS = "me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook";
+
+ @Override
+ public String[] getClassName() {
+ return new String[]{"net.minecraft.client.renderer.ActiveRenderInfo"};
+ }
+
+ @Override
+ public void transform(ClassNode classNode, String name) {
+ for (MethodNode method : classNode.methods) {
+ String methodName = mapMethodName(classNode, method);
+
+ if (methodName.equals("updateRenderInfo") || methodName.equals("func_74583_a")) {
+ ListIterator<AbstractInsnNode> iterator = method.instructions.iterator();
+
+ while (iterator.hasNext()) {
+ AbstractInsnNode next = iterator.next();
+
+ if(next.getOpcode() == GETFIELD) {
+ FieldInsnNode insn = (FieldInsnNode) next;
+
+ String ownerName = mapClassName(insn.owner);
+ String fieldName = mapFieldNameFromNode(insn);
+
+ if(ownerName.equals("net/minecraft/entity/player/EntityPlayer") && insn.desc.equals("F")) {
+ InsnList insnList = null;
+
+ switch (fieldName) {
+ case "rotationPitch":
+ case "field_70125_A":
+ insnList = insertRotationHook("Pitch");
+ break;
+ case "rotationYaw":
+ case "field_70177_z":
+ insnList = insertRotationHook("Yaw");
+ break;
+ }
+
+ if(insnList != null) {
+ method.instructions.insertBefore(insn, insnList);
+ method.instructions.remove(insn);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private InsnList insertRotationHook(String field) {
+ InsnList insnList = new InsnList();
+
+ insnList.add(new MethodInsnNode(INVOKESTATIC, HOOK_CLASS, "rotation" + field + "Hook", "(Lnet/minecraft/entity/player/EntityPlayer;)F", false));
+
+ return insnList;
+ }
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/EntityRendererTransformer.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/EntityRendererTransformer.java
new file mode 100644
index 0000000..3b6a5ae
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/EntityRendererTransformer.java
@@ -0,0 +1,128 @@
+package me.djtheredstoner.perspectivemod.asm.transformers;
+
+import me.djtheredstoner.perspectivemod.asm.ITransformer;
+import org.objectweb.asm.tree.*;
+
+import java.util.Iterator;
+
+import static org.objectweb.asm.Opcodes.*;
+
+/**
+ * @see net.minecraft.client.renderer.EntityRenderer
+ */
+public class EntityRendererTransformer implements ITransformer {
+
+ private static final String HOOK_CLASS = "me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook";
+
+ @Override
+ public String[] getClassName() {
+ return new String[]{"net.minecraft.client.renderer.EntityRenderer"};
+ }
+
+ @Override
+ public void transform(ClassNode classNode, String name) {
+ for (MethodNode method : classNode.methods) {
+ String methodName = mapMethodName(classNode, method);
+
+ if (methodName.equals("orientCamera") || methodName.equals("func_78467_g")) {
+
+ Iterator<AbstractInsnNode> iterator = method.instructions.iterator();
+
+ while (iterator.hasNext()) {
+ AbstractInsnNode next = iterator.next();
+
+ if(next.getOpcode() == GETFIELD) {
+ FieldInsnNode insn = (FieldInsnNode)next;
+
+ String ownerName = mapClassName(insn.owner);
+ String fieldName = mapFieldNameFromNode(insn);
+
+ if(ownerName.equals("net/minecraft/entity/Entity" ) && insn.desc.equals("F")) {
+
+ InsnList insnList = null;
+
+ switch (fieldName) {
+ case "rotationYaw":
+ case "field_70177_z":
+ insnList = insertRotationHook("rotationYaw");
+ break;
+ case "prevRotationYaw":
+ case "field_70126_B":
+ insnList = insertRotationHook("prevRotationYaw");
+ break;
+ case "rotationPitch":
+ case "field_70125_A":
+ insnList = insertRotationHook("rotationPitch");
+ break;
+ case "prevRotationPitch":
+ case "field_70127_C":
+ insnList = insertRotationHook("prevRotationPitch");
+ break;
+ }
+
+ if(insnList != null) {
+ method.instructions.insertBefore(insn, insnList);
+ method.instructions.remove(insn);
+ }
+ }
+ } /*else if (next.getOpcode() == DLOAD) {
+ VarInsnNode insn = (VarInsnNode) next;
+
+ if(insn.getPrevious().getOpcode() == FCONST_0 && insn.getNext().getOpcode() == DNEG) {
+ method.instructions.insert(insn, insertDistanceHook());
+ }
+ }*/
+ }
+ } else if (methodName.equals("updateCameraAndRender") || methodName.equals("func_181560_a")) {
+
+ Iterator<AbstractInsnNode> iterator = method.instructions.iterator();
+
+ while (iterator.hasNext()) {
+ AbstractInsnNode next = iterator.next();
+
+ if(next.getOpcode() == GETFIELD) {
+ FieldInsnNode insn = (FieldInsnNode)next;
+
+ String ownerName = mapClassName(insn.owner);
+ String fieldName = mapFieldNameFromNode(insn);
+
+ if(ownerName.equals("net/minecraft/client/Minecraft") && (fieldName.equals("inGameHasFocus") || fieldName.equals("field_71415_G")) && insn.desc.equals("Z")
+ && insn.getNext().getNext().getNext().getOpcode() == IFEQ) {
+ method.instructions.insertBefore(insn, insertMouseHook());
+ method.instructions.remove(insn);
+ }
+ }
+ }
+ }
+ //Poggers Ultra FPS Praseodymium mode.
+ /* else if (methodName.equals("renderWorldPass") || methodName.equals("func_175068_a")) {
+
+ method.instructions.insert(method.instructions.getFirst(), new InsnNode(RETURN));
+ }*/
+ }
+ }
+
+ private InsnList insertRotationHook(String field) {
+ InsnList list = new InsnList();
+
+ list.add(new MethodInsnNode(INVOKESTATIC, HOOK_CLASS, field + "Hook", "(Lnet/minecraft/entity/Entity;)F", false));
+
+ return list;
+ }
+
+ private InsnList insertMouseHook() {
+ InsnList list = new InsnList();
+
+ list.add(new MethodInsnNode(INVOKESTATIC, HOOK_CLASS, "mouseHook", "(Lnet/minecraft/client/Minecraft;)Z", false));
+
+ return list;
+ }
+
+ private InsnList insertDistanceHook() {
+ InsnList list = new InsnList();
+
+ list.add(new MethodInsnNode(INVOKESTATIC, HOOK_CLASS, "distanceHook", "(D)D", false));
+
+ return list;
+ }
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/MinecraftTransformer.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/MinecraftTransformer.java
new file mode 100644
index 0000000..ca1874b
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/MinecraftTransformer.java
@@ -0,0 +1,57 @@
+package me.djtheredstoner.perspectivemod.asm.transformers;
+
+import me.djtheredstoner.perspectivemod.asm.ITransformer;
+import org.objectweb.asm.tree.*;
+
+import java.util.Iterator;
+
+import static org.objectweb.asm.Opcodes.*;
+
+/**
+ * @see net.minecraft.client.Minecraft
+ */
+public class MinecraftTransformer implements ITransformer {
+
+ private static final String HOOK_CLASS = "me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook";
+
+ @Override
+ public String[] getClassName() {
+ return new String[]{"net.minecraft.client.Minecraft"};
+ }
+
+ @Override
+ public void transform(ClassNode classNode, String name) {
+ for (MethodNode method : classNode.methods) {
+ String methodName = mapMethodName(classNode, method);
+
+ if (methodName.equals("runTick") || methodName.equals("func_71407_l")) {
+ Iterator<AbstractInsnNode> iterator = method.instructions.iterator();
+
+ while (iterator.hasNext()) {
+ AbstractInsnNode next = iterator.next();
+
+ if (next.getOpcode() == PUTFIELD) {
+ FieldInsnNode insn = (FieldInsnNode) next;
+
+ String ownerName = mapClassName(insn.owner);
+ String fieldName = mapFieldNameFromNode(insn);
+
+ if (ownerName.equals("net/minecraft/client/settings/GameSettings") &&
+ (fieldName.equals("thirdPersonView") || fieldName.equals("field_74320_O")) && insn.desc.equals("I")) {
+ method.instructions.insertBefore(insn, insertThirdPersonHook());
+ method.instructions.remove(insn);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public InsnList insertThirdPersonHook() {
+ InsnList list = new InsnList();
+
+ list.add(new MethodInsnNode(INVOKESTATIC, HOOK_CLASS, "thirdPersonHook", "(Lnet/minecraft/client/settings/GameSettings;I)V", false));
+
+ return list;
+ }
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/RenderManagerTransformer.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/RenderManagerTransformer.java
new file mode 100644
index 0000000..e41b81a
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/transformers/RenderManagerTransformer.java
@@ -0,0 +1,71 @@
+package me.djtheredstoner.perspectivemod.asm.transformers;
+
+import me.djtheredstoner.perspectivemod.asm.ITransformer;
+import org.objectweb.asm.tree.*;
+
+import java.util.Iterator;
+
+import static org.objectweb.asm.Opcodes.*;
+
+/**
+ * @see net.minecraft.client.renderer.entity.RenderManager
+ */
+public class RenderManagerTransformer implements ITransformer {
+ private static final String HOOK_CLASS = "me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook";
+
+ @Override
+ public String[] getClassName() {
+ return new String[]{"net.minecraft.client.renderer.entity.RenderManager"};
+ }
+
+ @Override
+ public void transform(ClassNode classNode, String name) {
+ for (MethodNode method : classNode.methods) {
+ String methodName = mapMethodName(classNode, method);
+
+ if (methodName.equals("cacheActiveRenderInfo") || methodName.equals("func_180597_a")) {
+ Iterator<AbstractInsnNode> iterator = method.instructions.iterator();
+
+ while (iterator.hasNext()) {
+ AbstractInsnNode next = iterator.next();
+
+ if (next.getOpcode() == PUTFIELD) {
+ FieldInsnNode insn = (FieldInsnNode)next;
+
+ String ownerName = mapClassName(insn.owner);
+ String fieldName = mapFieldNameFromNode(insn);
+
+ if (ownerName.equals("net/minecraft/client/renderer/entity/RenderManager") && insn.desc.equals("F")) {
+
+ InsnList insnList = null;
+
+ switch (fieldName) {
+ case "playerViewX":
+ case "field_78732_j":
+ insnList = insertRotationHook("playerViewX");
+ break;
+ case "playerViewY":
+ case "field_78735_i":
+ insnList = insertRotationHook("playerViewY");
+ break;
+ }
+
+ if(insnList != null) {
+ method.instructions.insertBefore(insn, insnList);
+ method.instructions.remove(insn);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public InsnList insertRotationHook(String field) {
+ InsnList list = new InsnList();
+
+ list.add(new MethodInsnNode(INVOKESTATIC, HOOK_CLASS, field + "Hook", "(Lnet/minecraft/client/renderer/entity/RenderManager;F)V", false));
+
+ return list;
+ }
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/commands/PerspectiveModCommand.java b/src/main/java/me/djtheredstoner/perspectivemod/commands/PerspectiveModCommand.java
new file mode 100644
index 0000000..00b0d27
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/commands/PerspectiveModCommand.java
@@ -0,0 +1,19 @@
+package me.djtheredstoner.perspectivemod.commands;
+
+import gg.essential.api.EssentialAPI;
+import gg.essential.api.commands.Command;
+import gg.essential.api.commands.DefaultHandler;
+import me.djtheredstoner.perspectivemod.PerspectiveMod;
+
+public class PerspectiveModCommand extends Command {
+
+ public PerspectiveModCommand(String name) {
+ super(name);
+ }
+
+ @DefaultHandler
+ public void handle() {
+ EssentialAPI.getGuiUtil().openScreen(PerspectiveMod.instance.config.gui());
+ }
+
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/config/PerspectiveModConfig.java b/src/main/java/me/djtheredstoner/perspectivemod/config/PerspectiveModConfig.java
new file mode 100644
index 0000000..dd10623
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/config/PerspectiveModConfig.java
@@ -0,0 +1,42 @@
+package me.djtheredstoner.perspectivemod.config;
+
+import gg.essential.vigilance.Vigilant;
+import gg.essential.vigilance.data.Property;
+import gg.essential.vigilance.data.PropertyType;
+
+import java.io.File;
+
+public class PerspectiveModConfig extends Vigilant {
+
+ @Property(
+ type = PropertyType.SWITCH,
+ name = "Perspective Mod",
+ category = "General",
+ subcategory = "General",
+ description = "Toggle Perspective Mod entirely."
+ )
+ public boolean modEnabled = true;
+
+ @Property(
+ type = PropertyType.SWITCH,
+ name = "Hold Mode",
+ category = "General",
+ subcategory = "General",
+ description = "Return to normal perspective after releasing keybind."
+ )
+ public boolean holdMode = true;
+
+ @Property(
+ type = PropertyType.SWITCH,
+ name = "Invert Pitch",
+ category = "General",
+ subcategory = "General",
+ description = "Invert the pitch while in perspective (same as blc/lunar)."
+ )
+ public boolean invertPitch = false;
+
+ public PerspectiveModConfig() {
+ super(new File("./config/perspectivemodv4.toml"));
+ initialize();
+ }
+}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModTweaker.java b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModTweaker.java
new file mode 100644
index 0000000..695f7a2
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModTweaker.java
@@ -0,0 +1,77 @@
+package me.djtheredstoner.perspectivemod.forge;
+
+import me.djtheredstoner.perspectivemod.asm.ClassTransformer;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraftforge.common.ForgeVersion;
+import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
+
+import javax.swing.*;
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.zip.ZipFile;
+
+
+@IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion)
+public class PerspectiveModTweaker implements IFMLLoadingPlugin {
+
+ public PerspectiveModTweaker() {
+ File mods = new File(Launch.minecraftHome, "mods");
+
+ if (!mods.exists()) {
+ mods.mkdirs(); // mods folder may not exist in dev yet
+ }
+
+ File[] coreModList = mods.listFiles((dir, name) -> name.endsWith(".jar"));
+ for (File file : coreModList) {
+ try {
+ try (ZipFile zipFile = new ZipFile(file)) {
+ if (zipFile.getEntry("net/canelex/perspectivemod/PerspectiveMod.class") != null) {
+ halt("<html><p>Perspective Mod v4 is not compatible with Perspective Mod v3 by Canelex. Please remove Canelex's in order to launch the game.</p></html>");
+ continue;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void halt(final String message) {
+ JOptionPane.showMessageDialog(null, message, "Launch Aborted", JOptionPane.ERROR_MESSAGE);
+ try {
+ final Class<?> aClass = Class.forName("java.lang.Shutdown");
+ final Method exit = aClass.getDeclaredMethod("exit", int.class);
+ exit.setAccessible(true);
+ exit.invoke(null, 0);
+ } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public String[] getASMTransformerClass() {
+ return new String[]{ClassTransformer.class.getName()};
+ }
+
+ @Override
+ public String getModContainerClass() {
+ return null;
+ }
+
+ @Override
+ public String getSetupClass() {
+ return null;
+ }
+
+ @Override
+ public void injectData(Map<String, Object> map) {
+
+ }
+
+ @Override
+ public String getAccessTransformerClass() {
+ return null;
+ }
+}