diff --git a/src/openonyx/events/PerformanceDiagnostics.java b/src/openonyx/events/PerformanceDiagnostics.java new file mode 100644 index 0000000..d0f73cb --- /dev/null +++ b/src/openonyx/events/PerformanceDiagnostics.java @@ -0,0 +1,200 @@ +package openonyx.events; + +import java.lang.Thread.State; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import openonyx.core.OnyxClient; +import org.apache.logging.log4j.Logger; + +public final class PerformanceDiagnostics { + private static final long g = 250L; + private static final String M = "Client thread"; + private static final long L = 10000000000L; + private static final Map STRING_MAP = new HashMap<>(); + private static volatile boolean m; + private static final long h = 15000000000L; + private static final float l = 8.0F; + private static volatile long I = System.nanoTime(); + private static final long d = 3000000000L; + private static volatile long i; + private static final long f = 5000000000L; + private static final int H = 40; + private static final int e = 12; + + private static void L(StackTraceElement[] stackTraceElements) { + StackTraceElement[] stackTraceElements2 = stackTraceElements; + if (stackTraceElements2.length != 0) { + L(stackTraceElements2[0].toString()); + StackTraceElement[] stackTraceElements1 = stackTraceElements2; + int ix = stackTraceElements2.length; + + for (int k = j = 0; k < ix; k = ++j) { + StackTraceElement stackTraceElement; + if ((stackTraceElement = stackTraceElements1[j]).getClassName().startsWith("client.onyx.")) { + L(new StringBuilder().insert(0, "onyx: ").append(stackTraceElement).toString()); + return; + } + } + } + } + + private static Thread L() { + for (Thread thread : Thread.getAllStackTraces().keySet()) { + if ("Client thread".equals(thread.getName())) { + return thread; + } + } + + return null; + } + + private static void L(String string, Thread thread) { + String string1 = string; + MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + long lx = memoryMXBean.getHeapMemoryUsage().getUsed() >> 20; + long mx = memoryMXBean.getHeapMemoryUsage().getMax() >> 20; + StringBuilder stringBuilder = new StringBuilder(2048); + stringBuilder.append(string1).append(" — heap ").append(lx).append('/').append(mx).append(" MB"); + StringBuilder stringBuilder1; + if (thread == null) { + stringBuilder1 = stringBuilder; + stringBuilder.append("\n the client thread is gone"); + } else { + Map map = Thread.getAllStackTraces(); + L(stringBuilder, thread, (StackTraceElement[])map.get(thread)); + if (thread.getState() == State.BLOCKED || thread.getState() == State.WAITING) { + Iterator iterator = map.entrySet().iterator(); + + while (iterator.hasNext()) { + Entry entry; + if ((entry = (Entry)iterator.next()).getKey() != thread) { + L(stringBuilder, (Thread)entry.getKey(), (StackTraceElement[])entry.getValue()); + } + } + } + + stringBuilder1 = stringBuilder; + } + + L(stringBuilder1); + OnyxClient.LOGGER.error(stringBuilder.toString()); + } + + private static void L(StringBuilder stringBuilder) { + StringBuilder stringBuilder1 = stringBuilder; + if (!STRING_MAP.isEmpty()) { + ArrayList arrayList; + (arrayList = new ArrayList<>(STRING_MAP.entrySet())).sort(Comparator.comparingInt(entry -> ((int[])entryx.getValue())[0]).reversed()); + int j = 0; + + for (Iterator iterator1 = iterator = STRING_MAP.values().iterator(); iterator1.hasNext(); iterator1 = iterator) { + int[] ix = (int[])iterator.next(); + j += ix[0]; + } + + stringBuilder1.append("\n where the time went, ").append(j).append(" samples:"); + int k = 0; + + for (int lx = k; lx < Math.min(12, arrayList.size()); lx = k) { + Entry entry = (Entry)arrayList.get(k); + StringBuilder stringBuilder2 = stringBuilder1.append("\n ").append(((int[])entry.getValue())[0]).append("x "); + k++; + stringBuilder2.append((String)entry.getKey()); + } + + STRING_MAP.clear(); + } + } + + public static void d() { + if (!m) { + m = true; + Thread thread = new Thread(() -> { + long lx = 0L; + long mx = 0L; + long n = System.nanoTime(); + long o = i; + + while (true) { + try { + Thread.sleep(250L); + } catch (InterruptedException interruptedException) { + Thread.currentThread().interrupt(); + return; + } + + Thread threadx; + if ((threadx = L()) != null) { + L(threadx.getStackTrace()); + } + + long p; + long q; + if ((q = (p = System.nanoTime()) - I) >= 3000000000L) { + if (lx == 0L || p - lx >= 10000000000L) { + lx = p; + L(new StringBuilder().insert(0, "No frame for ").append(q / 1000000L).append(" ms").toString(), threadx); + } + + n = p; + o = i; + } else { + lx = 0L; + if (p - n >= 5000000000L) { + float fx = (float)(i - o) * 1.0E9F / (float)(p - n); + n = p; + o = i; + if (!(fx >= 8.0F) && p - mx >= 15000000000L) { + mx = p; + Object[] objectsx = new Object[1]; + boolean blx = true; + objectsx[0] = fx; + L(String.format("Frames have fallen to %.1f fps", objectsx), threadx); + } + } + } + } + }, "onyx-freeze-watchdog"); + thread.setDaemon(true); + thread.setPriority(1); + thread.start(); + Logger logger = OnyxClient.LOGGER; + Object[] objects = new Object[2]; + boolean bl = true; + objects[0] = 3L; + objects[1] = 8; + logger.warn("Freeze watchdog armed — a stall of {} s or a drop under {} fps will be reported here", objects); + } + } + + private PerformanceDiagnostics() { + } + + private static void L(String string) { + STRING_MAP.computeIfAbsent(string, string1 -> { + int[] ix = new int[1]; + boolean bl = true; + return ix; + })[0]++; + } + + public static void L() { + I = System.nanoTime(); + i++; + } + + private static void L(StringBuilder stringBuilder, Thread thread, StackTraceElement[] stackTraceElements) { + stringBuilder.append("\n \"").append(thread.getName()).append("\" ").append(thread.getState()); + if (stackTraceElements != null) { + for (int j = ix = 0; j < Math.min(40, stackTraceElements.length); j = ix) { + stringBuilder.append("\n at ").append(stackTraceElements[ix++]); + } + } + } +} diff --git a/src/openonyx/events/Rotation.java b/src/openonyx/events/Rotation.java new file mode 100644 index 0000000..9b6b4d3 --- /dev/null +++ b/src/openonyx/events/Rotation.java @@ -0,0 +1,35 @@ +package openonyx.events; + +public record Rotation(float yaw, float pitch) { + public static String decrypt(String string) { + String string1 = string; + int n = 5 >> 1 << 3 ^ 5; + String string2; + int p = (string2 = string1).length(); + char[] e = new char[p]; + boolean bl = true; + int j; + int o = j = p - 1; + char[] c = e; + byte b = 2; + byte d = 87; + int k = o; + int i = n; + + while (k >= 0) { + int l = j; + int m = string2.charAt(j); + j--; + c[l] = (char)(m ^ i); + if (j < 0) { + break; + } + + m = j--; + c[m] = (char)(string2.charAt(m) ^ b); + k = j; + } + + return new String(c); + } +} diff --git a/src/openonyx/events/RotationFixMode.java b/src/openonyx/events/RotationFixMode.java new file mode 100644 index 0000000..d76573b --- /dev/null +++ b/src/openonyx/events/RotationFixMode.java @@ -0,0 +1,16 @@ +package openonyx.events; + +public enum RotationFixMode { + OFF, + SILENT, + STRICT; + + private static RotationFixMode[] L() { + RotationFixMode[] rotationFixModes = new RotationFixMode[3]; + boolean bl = true; + rotationFixModes[0] = OFF; + rotationFixModes[1] = STRICT; + rotationFixModes[2] = SILENT; + return rotationFixModes; + } +} diff --git a/src/openonyx/events/RotationManager.java b/src/openonyx/events/RotationManager.java new file mode 100644 index 0000000..0897cf2 --- /dev/null +++ b/src/openonyx/events/RotationManager.java @@ -0,0 +1,140 @@ +package openonyx.events; + +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.Entity; +import openonyx.core.MinecraftAccess; +import openonyx.protocol.RotationHandler; +import openonyx.protocol.group_m.Angles; +import openonyx.utilities.PlayerUtils; + +public class RotationManager implements MinecraftAccess { + private static RotationFixMode rotationFixMode = RotationFixMode.OFF; + private static boolean g = false; + private static float M = 0.0F; + private static boolean L = false; + private static float j = 0.0F; + private static boolean m = false; + private static boolean h = false; + private static EntityPlayerSP entityPlayerSP = null; + private static float I = 0.0F; + private static float d = 0.0F; + private static float i = 0.0F; + private static float f = 0.0F; + private static float H = 0.0F; + private static float e = 0.0F; + + public static void D() { + if (g) { + g = false; + if (mc.thePlayer != null) { + mc.thePlayer.rotationYaw = i; + mc.thePlayer.rotationPitch = e; + } + } + } + + public static boolean i() { + return !L() && h && rotationFixMode != RotationFixMode.OFF && mc.thePlayer != null; + } + + public static boolean D() { + return L; + } + + public static Rotation L() { + return m ? new Rotation(f, j) : new Rotation(M, H); + } + + public static float i() { + return H; + } + + public static float D() { + return I; + } + + public static float d() { + return d; + } + + public static void L(float f, float g) { + f = fx; + j = gx; + m = true; + M = fx; + H = gx; + } + + public static float L() { + return M; + } + + public static void d() { + h = false; + rotationFixMode = RotationFixMode.OFF; + } + + public static void L() { + if (mc.thePlayer != null) { + if (entityPlayerSP != mc.thePlayer) { + entityPlayerSP = mc.thePlayer; + M = mc.thePlayer.rotationYaw; + H = mc.thePlayer.rotationPitch; + f = M; + j = H; + m = true; + L = false; + } + + if (L()) { + Angles angles; + if ((angles = RotationHandler.INSTANCE.getAngles3()) == null) { + angles = PlayerUtils.L((Entity)mc.thePlayer); + } + + g = false; + L = true; + M = angles.yaw2(); + H = angles.pitch2(); + MovementRotation.L(M, H); + } else { + if (h) { + if (m) { + mc.thePlayer.lastReportedYaw = f; + mc.thePlayer.lastReportedPitch = j; + } + + i = mc.thePlayer.rotationYaw; + e = mc.thePlayer.rotationPitch; + g = true; + mc.thePlayer.rotationYaw = I; + mc.thePlayer.rotationPitch = d; + } + + L = h; + M = mc.thePlayer.rotationYaw; + H = mc.thePlayer.rotationPitch; + MovementRotation.L(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch); + } + } + } + + public static boolean d() { + return h; + } + + private static boolean L() { + return h ? false : RotationHandler.INSTANCE.getAngles3() != null || RotationHandler.INSTANCE.d() != null; + } + + public static RotationFixMode getRotationFixMode() { + return rotationFixMode; + } + + public static void setRotation(Rotation rotation, RotationFixMode rotationFixMode) { + I = rotation.yaw(); + d = rotation.pitch(); + rotationFixMode = rotationFixModex; + h = true; + } +} diff --git a/src/openonyx/events/RotationMath.java b/src/openonyx/events/RotationMath.java new file mode 100644 index 0000000..ad3e3ed --- /dev/null +++ b/src/openonyx/events/RotationMath.java @@ -0,0 +1,59 @@ +package openonyx.events; + +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; +import openonyx.core.MinecraftAccess; + +public class RotationMath implements MinecraftAccess { + public static float L(float f, float g, float h, float i, float j) { + if ((g = d(f, g, h)) >= i && g <= j) { + return g; + } + + if (h <= 0.0F) { + return MathHelper.clamp_float(g, i, j); + } + + g = g > j ? j : i; + double d = (g - f) / h; + return (float)(f + (double)((long)d) * h); + } + + public static float d(float f, float g, float h) { + if (h <= 0.0F) { + return g; + } + + double d = g - f; + return (float)(f + (double)Math.round(d / h) * h); + } + + public static Rotation L(Vec3 vec3, Rotation rotation) { + Vec3 vec31 = vec3; + vec3 = GeometryUtils.L(); + double d = vec31.xCoord - vec3.xCoord; + double e = vec31.yCoord - vec3.yCoord; + double f = vec31.zCoord - vec3.zCoord; + if (d * d + e * e + f * f < 1.0E-8) { + return rotation; + } + + float g = (float)(MathHelper.atan2(f, d) * 180.0 / Math.PI) - 90.0F; + float h = (float)(-(MathHelper.atan2(e, Math.sqrt(d * d + f * f)) * 180.0 / Math.PI)); + return new Rotation(rotation.yaw() + MathHelper.wrapAngleTo180_float(g - rotation.yaw()), MathHelper.clamp_float(h, -90.0F, 90.0F)); + } + + public static float L() { + double d; + double e = d = mc.gameSettings.mouseSensitivity * 0.6F + 0.2F; + return (float)(e * e * d * 8.0) * 0.15F; + } + + public static Rotation L(Vec3 vec3) { + return L(vec3, new Rotation(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch)); + } + + public static float L(float f, float g, float h) { + return f + MathHelper.wrapAngleTo180_float(g - f) * h; + } +}