Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed torus race condition #174

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,26 @@ import com.mojang.blaze3d.systems.RenderSystem
import dev.lyzev.api.animation.EasingFunction
import dev.lyzev.api.animation.TimeAnimator
import dev.lyzev.api.events.*
import dev.lyzev.api.imgui.font.ImGuiFonts
import dev.lyzev.api.opengl.Render
import dev.lyzev.api.opengl.WrappedFramebuffer
import dev.lyzev.api.opengl.clear
import dev.lyzev.api.opengl.shader.Shader
import dev.lyzev.api.opengl.shader.ShaderPassThrough
import dev.lyzev.api.opengl.shader.ShaderReflection
import dev.lyzev.api.setting.settings.option
import dev.lyzev.api.setting.settings.slider
import dev.lyzev.schizoid.Schizoid
import dev.lyzev.schizoid.feature.IFeature
import dev.lyzev.schizoid.feature.features.module.ModuleToggleable
import dev.lyzev.schizoid.feature.features.module.ModuleToggleableRenderImGuiContent
import dev.lyzev.schizoid.feature.features.module.modules.render.ModuleToggleableTorus.Torus.Companion.normal1
import dev.lyzev.schizoid.feature.features.module.modules.render.ModuleToggleableTorus.Torus.Companion.normal2
import dev.lyzev.schizoid.feature.features.module.modules.render.ModuleToggleableTorus.Torus.Companion.normal3
import dev.lyzev.schizoid.feature.features.module.modules.render.ModuleToggleableTorus.Torus.Companion.normal4
import dev.lyzev.schizoid.feature.features.module.modules.render.ModuleToggleableTorus.frequency
import dev.lyzev.schizoid.feature.features.module.modules.render.ModuleToggleableTorus.lifetime
import imgui.ImGui.*
import imgui.flag.ImGuiCol
import imgui.flag.ImGuiWindowFlags
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.client.network.PlayerListEntry
import net.minecraft.client.render.BufferRenderer
import net.minecraft.client.render.Tessellator
import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormats
import net.minecraft.client.render.entity.LivingEntityRenderer
import net.minecraft.client.texture.AbstractTexture
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.util.math.MathHelper
Expand All @@ -46,6 +41,7 @@ object ModuleToggleableTargetESP : ModuleToggleable(
"Target ESP", "Renders a target ESP around the target player.", category = IFeature.Category.RENDER
), EventListener {

private val fbo = WrappedFramebuffer(useDepth = true)
private val timeAnimator = TimeAnimator(1000)

val duration by slider("Duration", "The duration of the target hud to show after hit.", 2000, 500, 10000, "ms")
Expand Down Expand Up @@ -77,6 +73,9 @@ object ModuleToggleableTargetESP : ModuleToggleable(
target = null
}
if (target == null) return@on
fbo.clear()
fbo.copyDepthFrom(mc.framebuffer)
fbo.beginWrite(false)
RenderSystem.enableDepthTest()
val cam = mc.gameRenderer.camera.pos
@Suppress("NAME_SHADOWING") val modelViewMat = Matrix4f(event.modelViewMat)
Expand All @@ -93,8 +92,7 @@ object ModuleToggleableTargetESP : ModuleToggleable(
ShaderReflection.bind()
ShaderReflection["ModelViewMat", false] = modelViewMat
ShaderReflection["ProjMat", false] = event.projMat
GL13.glActiveTexture(GL13.GL_TEXTURE0)
// ModuleToggleableRearView.rearView.beginRead()
RenderSystem.activeTexture(GL13.GL_TEXTURE0)
mc.framebuffer.beginRead()
ShaderReflection["Tex0"] = 0
ShaderReflection["Freq"] = frequency / 100f
Expand Down Expand Up @@ -143,8 +141,16 @@ object ModuleToggleableTargetESP : ModuleToggleable(
}
BufferRenderer.draw(bufferBuilder.end())
ShaderReflection.unbind()
RenderSystem.activeTexture(GL13.GL_TEXTURE0)
RenderSystem.disableDepthTest()
mc.framebuffer.beginWrite(false)
ShaderPassThrough.bind()
RenderSystem.activeTexture(GL13.GL_TEXTURE0)
fbo.beginRead()
ShaderPassThrough["Tex0"] = 0
ShaderPassThrough["Scale"] = 1f
ShaderPassThrough["Alpha"] = false
Shader.drawFullScreen()
ShaderPassThrough.unbind()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import com.mojang.blaze3d.systems.RenderSystem
import dev.lyzev.api.animation.EasingFunction
import dev.lyzev.api.events.*
import dev.lyzev.api.math.get
import dev.lyzev.api.opengl.Render
import dev.lyzev.api.opengl.WrappedFramebuffer
import dev.lyzev.api.opengl.clear
import dev.lyzev.api.opengl.shader.Shader
import dev.lyzev.api.opengl.shader.ShaderPassThrough
import dev.lyzev.api.opengl.shader.ShaderReflection
import dev.lyzev.api.setting.settings.slider
import dev.lyzev.api.setting.settings.switch
Expand All @@ -23,8 +26,8 @@ import net.minecraft.entity.Entity
import net.minecraft.network.packet.s2c.play.DamageTiltS2CPacket
import net.minecraft.network.packet.s2c.play.EntityDamageS2CPacket
import net.minecraft.util.hit.EntityHitResult
import net.minecraft.util.math.MathHelper.sin
import net.minecraft.util.math.MathHelper.cos
import net.minecraft.util.math.MathHelper.sin
import net.minecraft.util.math.Vec2f
import net.minecraft.util.math.Vec3d
import org.joml.Matrix4f
Expand All @@ -36,6 +39,8 @@ object ModuleToggleableTorus :
ModuleToggleable("Torus", "Renders a Torus with reflection effect.", category = IFeature.Category.RENDER),
EventListener {

private val fbo = WrappedFramebuffer(useDepth = true)

val depth by switch("Depth", "Whether to render the torus in depth.", false)
val frequency by slider("Noise frequency", "The strength of the noise effect.", 50, 0, 100, "%%")
val lifetime by slider("Lifetime", "The lifetime of the torus.", 1000, 1, 5000, "ms")
Expand Down Expand Up @@ -64,11 +69,26 @@ object ModuleToggleableTorus :
on<EventRenderWorld>(Event.Priority.LOW) { event ->
toruses.removeIf { System.currentTimeMillis() - it.spawn > lifetime }
if (toruses.isEmpty()) return@on
if (depth) RenderSystem.enableDepthTest()
else RenderSystem.disableDepthTest()
fbo.clear()
if (depth) {
fbo.copyDepthFrom(mc.framebuffer)
RenderSystem.enableDepthTest()
}
fbo.beginWrite(false)
toruses.forEach { torus ->
torus.render(event.modelViewMat, event.projMat)
}
if (depth)
RenderSystem.disableDepthTest()
mc.framebuffer.beginWrite(false)
ShaderPassThrough.bind()
RenderSystem.activeTexture(GL13.GL_TEXTURE0)
fbo.beginRead()
ShaderPassThrough["Tex0"] = 0
ShaderPassThrough["Scale"] = 1f
ShaderPassThrough["Alpha"] = false
Shader.drawFullScreen()
ShaderPassThrough.unbind()
}
}

Expand All @@ -85,7 +105,7 @@ object ModuleToggleableTorus :
ShaderReflection.bind()
ShaderReflection["ModelViewMat", false] = modelViewMat
ShaderReflection["ProjMat", false] = projMat
GL13.glActiveTexture(GL13.GL_TEXTURE0)
RenderSystem.activeTexture(GL13.GL_TEXTURE0)
// ModuleToggleableRearView.rearView.beginRead()
mc.framebuffer.beginRead()
ShaderReflection["Tex0"] = 0
Expand Down Expand Up @@ -125,7 +145,8 @@ object ModuleToggleableTorus :

normal1.set(cos(theta) * cos(phi), cos(theta) * sin(phi), sin(theta)).normalize()
normal2.set(cos(nextTheta) * cos(phi), cos(nextTheta) * sin(phi), sin(nextTheta)).normalize()
normal3.set(cos(nextTheta) * cos(nextPhi), cos(nextTheta) * sin(nextPhi), sin(nextTheta)).normalize()
normal3.set(cos(nextTheta) * cos(nextPhi), cos(nextTheta) * sin(nextPhi), sin(nextTheta))
.normalize()
normal4.set(cos(theta) * cos(nextPhi), cos(theta) * sin(nextPhi), sin(theta)).normalize()

bufferBuilder.vertex(x1, y1, z1).normal(normal1.x, normal1.y, normal1.z)
Expand All @@ -136,7 +157,6 @@ object ModuleToggleableTorus :
}
BufferRenderer.draw(bufferBuilder.end())
ShaderReflection.unbind()
RenderSystem.activeTexture(GL13.GL_TEXTURE0)
}

companion object {
Expand Down
Loading