mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Fix: Interpolate world positions with the frame's partial tick
- Pass the 1.8.9 HUD method's partial tick through the render hook into EventRender2D instead of reading Timer.renderPartialTicks reflectively - Let WorldView.snapshot() take that value so ESP projection matches the rendered world and no longer advances in 20 Hz steps - Keep the reflected timer read as a fallback and warn once when it cannot be resolved instead of silently interpolating with 0
This commit is contained in:
1 parent
d8a46a1b70
commit
ed7fa13e7f
9 files changed
+99
-19
No files matched your search
@@ -17,10 +17,19 @@ public final class Render2DEvents {
|
|||||||
* screen too, so the hook must pass this through.
|
* screen too, so the hook must pass this through.
|
||||||
*/
|
*/
|
||||||
public static void fire(Object platformContext, boolean inWorld) {
|
public static void fire(Object platformContext, boolean inWorld) {
|
||||||
|
fire(platformContext, inWorld, Float.NaN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param partialTicks the partial tick the game rendered this frame with.
|
||||||
|
* {@link Float#NaN} when the hook cannot supply it.
|
||||||
|
*/
|
||||||
|
public static void fire(Object platformContext, boolean inWorld,
|
||||||
|
float partialTicks) {
|
||||||
try {
|
try {
|
||||||
Render2DManager manager = OrangeX.getInstance().getRender2DManager();
|
Render2DManager manager = OrangeX.getInstance().getRender2DManager();
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
manager.fire(platformContext, inWorld);
|
manager.fire(platformContext, inWorld, partialTicks);
|
||||||
}
|
}
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
if (!failureLogged) {
|
if (!failureLogged) {
|
||||||
|
|||||||
@@ -15,10 +15,16 @@ public class EventRender2D {
|
|||||||
|
|
||||||
private final Render2D render2D;
|
private final Render2D render2D;
|
||||||
private final boolean inWorld;
|
private final boolean inWorld;
|
||||||
|
private final float partialTicks;
|
||||||
|
|
||||||
public EventRender2D(Render2D render2D, boolean inWorld) {
|
public EventRender2D(Render2D render2D, boolean inWorld) {
|
||||||
|
this(render2D, inWorld, Float.NaN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EventRender2D(Render2D render2D, boolean inWorld, float partialTicks) {
|
||||||
this.render2D = render2D;
|
this.render2D = render2D;
|
||||||
this.inWorld = inWorld;
|
this.inWorld = inWorld;
|
||||||
|
this.partialTicks = partialTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Render2D getRender2D() {
|
public Render2D getRender2D() {
|
||||||
@@ -31,4 +37,16 @@ public class EventRender2D {
|
|||||||
public boolean isInWorld() {
|
public boolean isInWorld() {
|
||||||
return inWorld;
|
return inWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The partial tick the game used for this frame's world render, i.e. the
|
||||||
|
* interpolation factor between the previous and the current tick.
|
||||||
|
*
|
||||||
|
* <p>Feature code must use this value instead of reading a timer of its own
|
||||||
|
* so projected world positions line up with the rendered world. It is
|
||||||
|
* {@link Float#NaN} when the hook could not supply one.</p>
|
||||||
|
*/
|
||||||
|
public float getPartialTicks() {
|
||||||
|
return partialTicks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,8 @@ public final class Render2DHook extends ClassHook {
|
|||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"No (F)V HUD method found in " + ctClass.getName());
|
"No (F)V HUD method found in " + ctClass.getName());
|
||||||
}
|
}
|
||||||
method.insertAfter("orangexbridge.Hooks.render2d(null, true);");
|
method.insertAfter(
|
||||||
|
"orangexbridge.Hooks.render2d(null, true, $1);");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
MappingMethod target = resolver.mapMethod(
|
MappingMethod target = resolver.mapMethod(
|
||||||
@@ -112,7 +113,10 @@ public final class Render2DHook extends ClassHook {
|
|||||||
methodDescriptor = target.getTargetDescriptor();
|
methodDescriptor = target.getTargetDescriptor();
|
||||||
}
|
}
|
||||||
CtMethod method = ctClass.getMethod(methodName, methodDescriptor);
|
CtMethod method = ctClass.getMethod(methodName, methodDescriptor);
|
||||||
method.insertAfter("orangexbridge.Hooks.render2d(null, true);");
|
// $1 is the frame's partial tick: pass it through so features
|
||||||
|
// interpolate world positions exactly like the world render.
|
||||||
|
method.insertAfter(
|
||||||
|
"orangexbridge.Hooks.render2d(null, true, $1);");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case V26_2: {
|
case V26_2: {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class ESP extends Module {
|
|||||||
|
|
||||||
WorldSnapshot snapshot;
|
WorldSnapshot snapshot;
|
||||||
try {
|
try {
|
||||||
snapshot = world.snapshot();
|
snapshot = world.snapshot(event.getPartialTicks());
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
// A broken wrapper must not kill the whole HUD frame.
|
// A broken wrapper must not kill the whole HUD frame.
|
||||||
System.err.println("[ESP] Failed to read world snapshot: "
|
System.err.println("[ESP] Failed to read world snapshot: "
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public final class Render2DManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void fire(Object platformContext) {
|
public void fire(Object platformContext) {
|
||||||
fire(platformContext, true);
|
fire(platformContext, true, Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,6 +45,15 @@ public final class Render2DManager {
|
|||||||
* event is dropped unless {@link #isRenderInMenus()} is on.
|
* event is dropped unless {@link #isRenderInMenus()} is on.
|
||||||
*/
|
*/
|
||||||
public void fire(Object platformContext, boolean inWorld) {
|
public void fire(Object platformContext, boolean inWorld) {
|
||||||
|
fire(platformContext, inWorld, Float.NaN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param partialTicks the partial tick the game rendered this frame with,
|
||||||
|
* or {@link Float#NaN} when the caller has none.
|
||||||
|
*/
|
||||||
|
public void fire(Object platformContext, boolean inWorld,
|
||||||
|
float partialTicks) {
|
||||||
if (!inWorld && !renderInMenus) {
|
if (!inWorld && !renderInMenus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -60,7 +69,7 @@ public final class Render2DManager {
|
|||||||
|
|
||||||
Render2D context = backend.createRender2D(fonts, platformContext);
|
Render2D context = backend.createRender2D(fonts, platformContext);
|
||||||
try {
|
try {
|
||||||
eventBus.post(new EventRender2D(context, inWorld));
|
eventBus.post(new EventRender2D(context, inWorld, partialTicks));
|
||||||
} finally {
|
} finally {
|
||||||
context.flush();
|
context.flush();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,21 @@ public interface WorldView {
|
|||||||
/**
|
/**
|
||||||
* Captures the camera and entity list for the current frame.
|
* Captures the camera and entity list for the current frame.
|
||||||
*
|
*
|
||||||
|
* @param partialTicks the partial tick the game rendered this frame with,
|
||||||
|
* taken from {@code EventRender2D}. This is the only
|
||||||
|
* value that keeps projections aligned with the
|
||||||
|
* rendered world; {@link Float#NaN} lets the
|
||||||
|
* implementation resolve one itself.
|
||||||
* @return {@code null} while no level is loaded (title screen, loading).
|
* @return {@code null} while no level is loaded (title screen, loading).
|
||||||
*/
|
*/
|
||||||
WorldSnapshot snapshot();
|
WorldSnapshot snapshot(float partialTicks);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether a caller-supplied frame partial tick can be used. NaN and
|
||||||
|
* out-of-range values are rejected so a misbehaving hook never
|
||||||
|
* freezes entity interpolation.
|
||||||
|
*/
|
||||||
|
static boolean isUsablePartialTick(float partialTicks) {
|
||||||
|
return partialTicks >= 0.0F && partialTicks <= 1.0F;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+22
-10
@@ -73,6 +73,7 @@ public final class V1_8_9WorldView implements WorldView {
|
|||||||
private final String[] villagerClassNames;
|
private final String[] villagerClassNames;
|
||||||
|
|
||||||
private Field partialTicksField;
|
private Field partialTicksField;
|
||||||
|
private boolean partialTicksWarningLogged;
|
||||||
private Field loadedEntitiesField;
|
private Field loadedEntitiesField;
|
||||||
private Field thirdPersonViewField;
|
private Field thirdPersonViewField;
|
||||||
private Field fovSettingField;
|
private Field fovSettingField;
|
||||||
@@ -116,7 +117,7 @@ public final class V1_8_9WorldView implements WorldView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldSnapshot snapshot() {
|
public WorldSnapshot snapshot(float partialTicks) {
|
||||||
Object world = ReflectionSupport.get(worldField, minecraft);
|
Object world = ReflectionSupport.get(worldField, minecraft);
|
||||||
Object viewEntity = ReflectionSupport.get(viewEntityField, minecraft);
|
Object viewEntity = ReflectionSupport.get(viewEntityField, minecraft);
|
||||||
Object localPlayer = ReflectionSupport.get(playerField, minecraft);
|
Object localPlayer = ReflectionSupport.get(playerField, minecraft);
|
||||||
@@ -125,18 +126,23 @@ public final class V1_8_9WorldView implements WorldView {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
float partialTicks = partialTicks();
|
// The render hook hands us the exact value the frame was rendered
|
||||||
|
// with. Only fall back to the timer when the caller has none, because a
|
||||||
|
// partial tick of 0 (or a stale one) makes every interpolated position
|
||||||
|
// advance in 20 Hz steps while the world renders smoothly.
|
||||||
|
float frameTicks = WorldView.isUsablePartialTick(partialTicks)
|
||||||
|
? partialTicks : partialTicks();
|
||||||
EntityAccess view = accessFor(viewEntity.getClass());
|
EntityAccess view = accessFor(viewEntity.getClass());
|
||||||
|
|
||||||
double eyeX = interpolate(view.posX, view.lastTickPosX, viewEntity, partialTicks);
|
double eyeX = interpolate(view.posX, view.lastTickPosX, viewEntity, frameTicks);
|
||||||
double eyeY = interpolate(view.posY, view.lastTickPosY, viewEntity, partialTicks)
|
double eyeY = interpolate(view.posY, view.lastTickPosY, viewEntity, frameTicks)
|
||||||
+ invokeFloat(view.eyeHeight, viewEntity);
|
+ invokeFloat(view.eyeHeight, viewEntity);
|
||||||
double eyeZ = interpolate(view.posZ, view.lastTickPosZ, viewEntity, partialTicks);
|
double eyeZ = interpolate(view.posZ, view.lastTickPosZ, viewEntity, frameTicks);
|
||||||
|
|
||||||
float yaw = interpolateAngle(view.rotationYaw, view.prevRotationYaw,
|
float yaw = interpolateAngle(view.rotationYaw, view.prevRotationYaw,
|
||||||
viewEntity, partialTicks);
|
viewEntity, frameTicks);
|
||||||
float pitch = interpolateAngle(view.rotationPitch, view.prevRotationPitch,
|
float pitch = interpolateAngle(view.rotationPitch, view.prevRotationPitch,
|
||||||
viewEntity, partialTicks);
|
viewEntity, frameTicks);
|
||||||
|
|
||||||
int thirdPerson = thirdPersonView();
|
int thirdPerson = thirdPersonView();
|
||||||
float cameraYaw = yaw;
|
float cameraYaw = yaw;
|
||||||
@@ -152,7 +158,7 @@ public final class V1_8_9WorldView implements WorldView {
|
|||||||
// Third person moves the camera back by the configured distance;
|
// Third person moves the camera back by the configured distance;
|
||||||
// first person sits 0.1 blocks behind the eye (EntityRenderer).
|
// first person sits 0.1 blocks behind the eye (EntityRenderer).
|
||||||
double cameraOffset = thirdPerson > 0
|
double cameraOffset = thirdPerson > 0
|
||||||
? thirdPersonDistance(partialTicks)
|
? thirdPersonDistance(frameTicks)
|
||||||
: FIRST_PERSON_OFFSET;
|
: FIRST_PERSON_OFFSET;
|
||||||
|
|
||||||
double yawRadians = Math.toRadians(cameraYaw);
|
double yawRadians = Math.toRadians(cameraYaw);
|
||||||
@@ -166,9 +172,9 @@ public final class V1_8_9WorldView implements WorldView {
|
|||||||
double cameraY = eyeY - forwardY * cameraOffset;
|
double cameraY = eyeY - forwardY * cameraOffset;
|
||||||
double cameraZ = eyeZ - forwardZ * cameraOffset;
|
double cameraZ = eyeZ - forwardZ * cameraOffset;
|
||||||
|
|
||||||
float fov = fieldOfView(partialTicks);
|
float fov = fieldOfView(frameTicks);
|
||||||
List<EntityTarget> targets = collectTargets(
|
List<EntityTarget> targets = collectTargets(
|
||||||
world, localPlayer, cameraX, cameraY, cameraZ, partialTicks);
|
world, localPlayer, cameraX, cameraY, cameraZ, frameTicks);
|
||||||
|
|
||||||
return new WorldSnapshot(new Vec3(cameraX, cameraY, cameraZ),
|
return new WorldSnapshot(new Vec3(cameraX, cameraY, cameraZ),
|
||||||
cameraYaw, cameraPitch, fov, targets);
|
cameraYaw, cameraPitch, fov, targets);
|
||||||
@@ -292,6 +298,12 @@ public final class V1_8_9WorldView implements WorldView {
|
|||||||
if (partialTicksField == null) {
|
if (partialTicksField == null) {
|
||||||
partialTicksField = ReflectionSupport.findField(
|
partialTicksField = ReflectionSupport.findField(
|
||||||
timer.getClass(), partialTicksName);
|
timer.getClass(), partialTicksName);
|
||||||
|
if (partialTicksField == null && !partialTicksWarningLogged) {
|
||||||
|
partialTicksWarningLogged = true;
|
||||||
|
System.err.println("[OrangeX] Cannot read "
|
||||||
|
+ partialTicksName + " from " + timer.getClass().getName()
|
||||||
|
+ ": world positions will not interpolate");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return partialTicksField == null
|
return partialTicksField == null
|
||||||
|
|||||||
+7
-2
@@ -86,7 +86,7 @@ public final class V26_2WorldView implements WorldView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldSnapshot snapshot() {
|
public WorldSnapshot snapshot(float partialTicks) {
|
||||||
Object level = ReflectionSupport.get(levelField, minecraft);
|
Object level = ReflectionSupport.get(levelField, minecraft);
|
||||||
Object localPlayer = ReflectionSupport.get(playerField, minecraft);
|
Object localPlayer = ReflectionSupport.get(playerField, minecraft);
|
||||||
Object gameRenderer = ReflectionSupport.get(gameRendererField, minecraft);
|
Object gameRenderer = ReflectionSupport.get(gameRendererField, minecraft);
|
||||||
@@ -95,12 +95,17 @@ public final class V26_2WorldView implements WorldView {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
float partialTicks = partialTicks();
|
|
||||||
Object camera = camera(gameRenderer);
|
Object camera = camera(gameRenderer);
|
||||||
if (camera == null) {
|
if (camera == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The 26.2 hook extracts the GUI from the game's delta tracker, so it
|
||||||
|
// supplies no partial tick and the tracker is the authoritative value.
|
||||||
|
if (!WorldView.isUsablePartialTick(partialTicks)) {
|
||||||
|
partialTicks = partialTicks();
|
||||||
|
}
|
||||||
|
|
||||||
Vec3 cameraPosition = readVec3(
|
Vec3 cameraPosition = readVec3(
|
||||||
ReflectionSupport.invoke(cameraPositionMethod, camera));
|
ReflectionSupport.invoke(cameraPositionMethod, camera));
|
||||||
float yaw = invokeFloat(cameraYRotMethod, camera);
|
float yaw = invokeFloat(cameraYRotMethod, camera);
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ public final class Hooks {
|
|||||||
Render2DEvents.fire(context, inWorld);
|
Render2DEvents.fire(context, inWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1.8.9 entry point: the HUD method receives the frame's partial tick, so
|
||||||
|
* injected code passes it straight through as {@code $1}.
|
||||||
|
*/
|
||||||
|
public static void render2d(Object context, boolean inWorld,
|
||||||
|
float partialTicks) {
|
||||||
|
Render2DEvents.fire(context, inWorld, partialTicks);
|
||||||
|
}
|
||||||
|
|
||||||
public static void render2d(Object context) {
|
public static void render2d(Object context) {
|
||||||
Render2DEvents.fire(context);
|
Render2DEvents.fire(context);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user