Skip to content

Commit

Permalink
Use safer injection point
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh committed Dec 2, 2024
1 parent be22aea commit a029164
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
package me.ramidzkh.fabrishot.mixins;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.mojang.blaze3d.systems.RenderSystem;
import me.ramidzkh.fabrishot.Fabrishot;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(RenderSystem.class)
public class RenderSystemMixin {

@Unique
private static boolean wasLastFrameInCapture;

@Redirect(method = "flipFrame", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwSwapBuffers(J)V"), remap = false)
private static void glfwSwapBuffers(long window) {
@WrapWithCondition(method = "flipFrame", at = @At(value = "INVOKE", target = "Lorg/lwjgl/glfw/GLFW;glfwSwapBuffers(J)V"), remap = false)
private static boolean glfwSwapBuffers(long window) {
if (Fabrishot.isInCapture()) {
wasLastFrameInCapture = true;
return;
return false;
}

// skip a single black frame
if (wasLastFrameInCapture) {
wasLastFrameInCapture = false;
return;
return false;
}

GLFW.glfwSwapBuffers(window);
return true;
}
}

0 comments on commit a029164

Please sign in to comment.