Skip to content

Commit

Permalink
fix: Always refresh terminal solver solutions
Browse files Browse the repository at this point in the history
Hypixel adopted a anti-dupe measure where the entire container's items aren't sent at the same time.

Possible regression could be introduced where the `shouldClick` field isn't reset properly, causing the fake enchantments to "bleed" through to other GUIs.
  • Loading branch information
My-Name-Is-Jeff committed Feb 11, 2025
1 parent 034d172 commit d4bc147
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ package gg.skytils.skytilsmod.features.impl.dungeons.solvers.terminals
import gg.skytils.skytilsmod.Skytils
import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.events.impl.GuiContainerEvent
import gg.skytils.skytilsmod.events.impl.MainReceivePacketEvent
import gg.skytils.skytilsmod.utils.SuperSecretSettings
import gg.skytils.skytilsmod.utils.Utils
import net.minecraft.inventory.ContainerChest
import net.minecraft.item.EnumDyeColor
import net.minecraft.item.ItemStack
import net.minecraft.network.play.server.S2DPacketOpenWindow
import net.minecraft.network.play.server.S2FPacketSetSlot
import net.minecraft.network.play.server.S30PacketWindowItems
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
Expand All @@ -35,43 +40,62 @@ object SelectAllColorSolver {
val shouldClick = hashSetOf<Int>()
private var colorNeeded: String? = null
private val colors by lazy {
EnumDyeColor.entries.associateWith { it.getName().replace("_", " ").uppercase() }
EnumDyeColor.entries.associateWith { it.name.replace("_", " ").uppercase() }
}
private var windowId: Int? = null

@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (Skytils.config.selectAllColorTerminalSolver && Utils.inDungeons && event.container is ContainerChest && event.chestName.startsWith(
"Select all the"
)
) {
val promptColor = colors.entries.find { (_, name) ->
event.chestName.contains(name)
}?.key?.unlocalizedName
if (promptColor != colorNeeded) {
colorNeeded = promptColor
shouldClick.clear()
}
if (shouldClick.size == 0) {
for (slot in event.container.inventorySlots) {
if (slot.inventory === mc.thePlayer?.inventory || !slot.hasStack) continue
val item = slot.stack ?: continue
if (item.isItemEnchanted) continue
if (slot.slotNumber < 9 || slot.slotNumber > 44 || slot.slotNumber % 9 == 0 || slot.slotNumber % 9 == 8) continue
if (SuperSecretSettings.bennettArthur) {
if (Random.nextInt(3) == 0) shouldClick.add(slot.slotNumber)
} else if (item.unlocalizedName.contains(colorNeeded!!)) {
shouldClick.add(slot.slotNumber)
}
fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) {
shouldClick.clear()
colorNeeded = null
windowId = null
}

@SubscribeEvent
fun onPacket(event: MainReceivePacketEvent<*, *>) {
if (event.packet is S2DPacketOpenWindow) {
val chestName = event.packet.windowTitle.unformattedText
if (chestName.startsWith("Select all the")) {
windowId = event.packet.windowId

val promptColor = colors.entries.find { (_, name) ->
chestName.contains(name)
}?.key?.unlocalizedName
if (promptColor != colorNeeded) {
colorNeeded = promptColor
shouldClick.clear()
}
} else {
shouldClick.removeIf {
val slot = event.container.getSlot(it)
return@removeIf slot.hasStack && slot.stack.isItemEnchanted
}
shouldClick.clear()
colorNeeded = null
windowId = null
}
}

if (!Skytils.config.selectAllColorTerminalSolver || !TerminalFeatures.isInPhase3()) return

when (event.packet) {
is S2FPacketSetSlot -> {
if (event.packet.func_149175_c() != windowId) return
handleItemStack(event.packet.func_149173_d(), event.packet.func_149174_e())
}
is S30PacketWindowItems -> {
if (event.packet.func_148911_c() != windowId) return
event.packet.itemStacks.forEachIndexed(::handleItemStack)
}
}
}

private fun handleItemStack(slot: Int, item: ItemStack) {
val column = slot % 9
if (slot in 9..44 && column in 1..7) {
if (item.isItemEnchanted) {
shouldClick.remove(slot)
} else if (SuperSecretSettings.bennettArthur) {
if (Random.nextInt(3) == 0) shouldClick.add(slot)
} else if (item.unlocalizedName.contains(colorNeeded!!)) {
shouldClick.add(slot)
}
} else {
shouldClick.clear()
colorNeeded = null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,78 @@ package gg.skytils.skytilsmod.features.impl.dungeons.solvers.terminals
import gg.skytils.skytilsmod.Skytils
import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.events.impl.GuiContainerEvent
import gg.skytils.skytilsmod.events.impl.MainReceivePacketEvent
import gg.skytils.skytilsmod.utils.SuperSecretSettings
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.stripControlCodes
import net.minecraft.inventory.ContainerChest
import net.minecraft.item.ItemStack
import net.minecraft.network.play.server.S2DPacketOpenWindow
import net.minecraft.network.play.server.S2FPacketSetSlot
import net.minecraft.network.play.server.S30PacketWindowItems
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.random.Random

object StartsWithSequenceSolver {


@JvmField
val shouldClick = hashSetOf<Int>()
private var sequenceNeeded: String? = null
private val titlePattern = Regex("^What starts with: ['\"](.+)['\"]\\?$")
private var windowId: Int? = null

@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (Utils.inDungeons && Skytils.config.startsWithSequenceTerminalSolver && event.container is ContainerChest && event.chestName.startsWith(
"What starts with:"
)
) {
val sequence = titlePattern.find(event.chestName)?.groupValues?.get(1) ?: return
if (sequence != sequenceNeeded) {
sequenceNeeded = sequence
shouldClick.clear()
} else if (shouldClick.size == 0) {
for (slot in event.container.inventorySlots) {
if (slot.inventory === mc.thePlayer?.inventory || !slot.hasStack) continue
val item = slot.stack ?: continue
if (item.isItemEnchanted) continue
if (slot.slotNumber < 9 || slot.slotNumber > 44 || slot.slotNumber % 9 == 0 || slot.slotNumber % 9 == 8) continue
if (SuperSecretSettings.bennettArthur) {
if (Random.nextInt(3) == 0) shouldClick.add(slot.slotNumber)
} else if (item.displayName.stripControlCodes().startsWith(sequenceNeeded!!)) {
shouldClick.add(slot.slotNumber)
}
fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) {
shouldClick.clear()
sequenceNeeded = null
windowId = null
}

@SubscribeEvent
fun onPacket(event: MainReceivePacketEvent<*, *>) {
if (event.packet is S2DPacketOpenWindow) {
val chestName = event.packet.windowTitle.unformattedText
if (chestName.startsWith("What starts with:")) {
windowId = event.packet.windowId

val sequence = titlePattern.find(chestName)?.groupValues?.get(1) ?: return
if (sequence != sequenceNeeded) {
sequenceNeeded = sequence
shouldClick.clear()
}
} else {
shouldClick.removeIf {
val slot = event.container.getSlot(it)
return@removeIf slot.hasStack && slot.stack.isItemEnchanted
}
shouldClick.clear()
sequenceNeeded = null
windowId = null
}
}

if (!Skytils.config.startsWithSequenceTerminalSolver || !TerminalFeatures.isInPhase3()) return

when (event.packet) {
is S2FPacketSetSlot -> {
if (event.packet.func_149175_c() != windowId) return
handleItemStack(event.packet.func_149173_d(), event.packet.func_149174_e())
}
is S30PacketWindowItems -> {
if (event.packet.func_148911_c() != windowId) return
event.packet.itemStacks.forEachIndexed(::handleItemStack)
}
}
}

private fun handleItemStack(slot: Int, item: ItemStack) {
val column = slot % 9
if (slot in 9..44 && column in 1..7) {
if (item.isItemEnchanted) {
shouldClick.remove(slot)
} else if (SuperSecretSettings.bennettArthur) {
if (Random.nextInt(3) == 0) shouldClick.add(slot)
} else if (item.displayName.stripControlCodes().startsWith(sequenceNeeded!!)) {
shouldClick.add(slot)
}
} else {
shouldClick.clear()
sequenceNeeded = null
}
}

Expand Down

0 comments on commit d4bc147

Please sign in to comment.