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

Villager RNG Manipulation #642

Draft
wants to merge 47 commits into
base: fabric
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3e36064
temp changes
RealRTTV May 29, 2024
1cca6b4
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV May 29, 2024
5552602
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV May 30, 2024
b935782
finally i can hold on to a villager's rng state
RealRTTV May 31, 2024
fe4133a
ok, now that it's been held on to, i can try to predict it, but for s…
RealRTTV May 31, 2024
800fd92
ok now i can crack it, gotta figure out how to
RealRTTV Jun 1, 2024
5fcbf15
ok, now it works
RealRTTV Jun 2, 2024
b5fe87c
whoopsie
RealRTTV Jun 2, 2024
fa0fde5
need to check the ping checking
RealRTTV Jun 2, 2024
406d55a
ping checking might work, idk
RealRTTV Jun 11, 2024
f416f2b
Merge remote-tracking branch 'refs/remotes/upstream/fabric' into vill…
RealRTTV Jun 17, 2024
70aaf2a
yo, check out this broken code
RealRTTV Jun 19, 2024
f047024
Fixes to villager cracking
Earthcomputer Jun 19, 2024
c419414
IT WORKS!! btw i still have villager adjustment shenanigans
RealRTTV Jun 19, 2024
48bf868
Fix two pitch cracking and add three pitch cracking
Gaider10 Jun 19, 2024
2734f64
Add simulation for unhappy no and water splashing sounds
Gaider10 Jun 20, 2024
bff08d1
Merge pull request #1 from Gaider10/villager_rng_cracking
RealRTTV Jun 20, 2024
47e53f2
Add simulation for more actions and add trade cracking for levels abo…
Gaider10 Jun 20, 2024
4910518
Handle ambient sound inside trading gui correctly
Gaider10 Jun 20, 2024
e92307e
Merge pull request #2 from Gaider10/villager_rng_cracking
RealRTTV Jun 20, 2024
5e8f1f2
ok changed some stuff lol i think this might be good
RealRTTV Jun 20, 2024
4642e34
removed latticg code
RealRTTV Jun 20, 2024
0bc4167
removed unused diff
RealRTTV Jun 20, 2024
4e65243
added help dialog for failed clock, no clock set, cracking during the…
RealRTTV Jun 21, 2024
a6f6ed5
shit
RealRTTV Jun 21, 2024
deeb1e6
Use the ambient sound that detected the desync for recracking
Gaider10 Jun 21, 2024
e4732b9
Fix nighttime check
Gaider10 Jun 21, 2024
badfe97
Merge pull request #3 from Gaider10/villager_rng_cracking
RealRTTV Jun 21, 2024
5c304e4
- added custom out of sync messages
RealRTTV Jun 22, 2024
38b8d69
- added nicer display to goals using ItemParser
RealRTTV Jun 23, 2024
3813d7b
added toString
RealRTTV Jun 23, 2024
7c2fe74
??
RealRTTV Jun 29, 2024
9519911
changes in response to review
RealRTTV Jul 1, 2024
42e3a20
added three-item-goal and two-item-enchanted-goal
RealRTTV Jul 2, 2024
6ecb586
whoop
RealRTTV Jul 3, 2024
d6894f8
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Jul 9, 2024
c453a39
updated and some minor, minor stuff
RealRTTV Jul 9, 2024
6293252
Update clientcommands.aw
RealRTTV Jul 12, 2024
b4a94ef
removed wildcard import
RealRTTV Jul 13, 2024
75bd52e
Update DebugRandom.java
RealRTTV Jul 13, 2024
c170054
Update DebugRandom.java
RealRTTV Jul 13, 2024
c3e4090
Update DebugRandom.java
RealRTTV Jul 13, 2024
7ac0113
Update ItemAndEnchantmentsPredicateArgument.java
RealRTTV Jul 13, 2024
210dbf4
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Aug 9, 2024
d2fb531
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Sep 28, 2024
02ee3c7
fixed some todo items
RealRTTV Sep 28, 2024
295840b
Merge remote-tracking branch 'upstream/fabric' into villager_rng_crac…
RealRTTV Oct 5, 2024
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 @@ -19,10 +19,9 @@ public static void main(String[] args) throws IOException {
}

Path destDir = Path.of(args[0]);
genLattiCG(destDir);
genPlayerLattiCG(destDir);
}

private static void genLattiCG(Path destDir) throws IOException {
private static void genPlayerLattiCG(Path destDir) throws IOException {
ProgramBuilder program = Program.builder(LCG.JAVA);
program.skip(-CCrackRng.NUM_THROWS * 4);
for (int i = 0; i < CCrackRng.NUM_THROWS; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
UsageTreeCommand.register(dispatcher);
UuidCommand.register(dispatcher);
VarCommand.register(dispatcher);
VillagerCommand.register(dispatcher, context);
WeatherCommand.register(dispatcher);
WhisperEncryptedCommand.register(dispatcher);
WikiCommand.register(dispatcher);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/earthcomputer/clientcommands/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,13 @@ public enum PacketDumpMethod {

@Config
public static int maximumPacketFieldDepth = 10;

@Config(temporary = true, setter = @Config.Setter("setMaxVillagerBruteForceSimulationCalls"))
public static int maxVillagerBruteForceSimulationCalls = 12000;
public static void setMaxVillagerBruteForceSimulationCalls(int maxVillagerBruteForceSimulationCalls) {
Configs.maxVillagerBruteForceSimulationCalls = Mth.clamp(maxVillagerBruteForceSimulationCalls, 0, 1_000_000);
}

@Config(temporary = true)
public static int villagerAdjustment = 0;
Comment on lines +183 to +184
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove in favor of ping adjustments

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;

import java.util.HashMap;
Expand Down Expand Up @@ -101,4 +102,18 @@ public static String registerCode(Runnable code) {
runnables.put(randomString, code);
return randomString;
}

public static void updateOverlayProgressBar(int current, int total, int width, int time) {
MutableComponent builder = Component.empty();
int color = Mth.hsvToRgb(current / (total * 3.0f), 1.0f, 1.0f);
builder.append(Component.literal("[").withColor(0xAAAAAA));
builder.append(Component.literal("~" + Math.round(100.0 * current / total) + "%").withColor(color));
builder.append(Component.literal("] ").withColor(0xAAAAAA));
int filledWidth = (int) Math.round((double) width * current / total);
int unfilledWidth = width - filledWidth;
builder.append(Component.literal("|".repeat(filledWidth)).withColor(color));
builder.append(Component.literal("|".repeat(unfilledWidth)).withColor(0xAAAAAA));

addOverlayMessage(builder, time);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.earthcomputer.clientcommands.command.VillagerCommand;
import net.earthcomputer.clientcommands.util.MultiVersionCompat;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.commands.SharedSuggestionProvider;
Expand Down Expand Up @@ -38,6 +39,8 @@
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
RealRTTV marked this conversation as resolved.
Show resolved Hide resolved
import java.util.stream.Stream;

public class ItemAndEnchantmentsPredicateArgument implements ArgumentType<ItemAndEnchantmentsPredicateArgument.ItemAndEnchantmentsPredicate> {

Expand Down Expand Up @@ -126,7 +129,7 @@ public ItemAndEnchantmentsPredicate parse(StringReader reader) throws CommandSyn
return true;
};

return new ItemAndEnchantmentsPredicate(parser.item, predicate, parser.with.size());
return new ItemAndEnchantmentsPredicate(parser.item, predicate, parser.with, parser.without, parser.exact, parser.ordered);
}

@Override
Expand All @@ -152,17 +155,41 @@ public Collection<String> getExamples() {
return EXAMPLES;
}

public record ItemAndEnchantmentsPredicate(Item item, Predicate<List<EnchantmentInstance>> predicate, int numEnchantments) implements Predicate<ItemStack> {
public record ItemAndEnchantmentsPredicate(Item item, Predicate<List<EnchantmentInstance>> predicate, List<EnchantmentInstancePredicate> with, List<EnchantmentInstancePredicate> without, boolean exact, boolean ordered) implements Predicate<ItemStack> {
@Override
public boolean test(ItemStack stack) {
if (item != stack.getItem() && (item != Items.BOOK || stack.getItem() != Items.ENCHANTED_BOOK)) {
return false;
}
List<EnchantmentInstance> enchantments = stack.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).entrySet().stream()
List<EnchantmentInstance> enchantments = Stream.concat(stack.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).entrySet().stream(), stack.getOrDefault(DataComponents.STORED_ENCHANTMENTS, ItemEnchantments.EMPTY).entrySet().stream())
.map(entry -> new EnchantmentInstance(entry.getKey(), entry.getIntValue()))
.toList();
return predicate.test(enchantments);
}

@Override
public String toString() {
String itemName = item.getName(new ItemStack(item)).getString();

StringBuilder flagsBuilder = new StringBuilder();
if (exact) {
flagsBuilder.append("Exactly");
}
if (ordered) {
flagsBuilder.append("Ordered");
}
String flags = flagsBuilder.isEmpty() ? "" : " [" + flagsBuilder + ')';

String enchantments = Stream.concat(
with.stream().filter(enchantment -> enchantment.enchantment().unwrapKey().isPresent()).map(EnchantmentInstancePredicate::toString),
without.stream().filter(enchantment -> enchantment.enchantment().unwrapKey().isPresent()).map(enchantment -> "!" + enchantment)
).collect(Collectors.joining(", "));
if (!enchantments.isEmpty()) {
enchantments = '(' + enchantments + ')';
}

return String.format("%s%s %s", itemName, flags, enchantments);
}
}

private class Parser {
Expand Down Expand Up @@ -455,10 +482,15 @@ private void suggestOption() {
}
}

private record EnchantmentInstancePredicate(Holder<Enchantment> enchantment, MinMaxBounds.Ints level) implements Predicate<EnchantmentInstance> {
public record EnchantmentInstancePredicate(Holder<Enchantment> enchantment, MinMaxBounds.Ints level) implements Predicate<EnchantmentInstance> {
@Override
public boolean test(EnchantmentInstance enchInstance) {
return enchantment.equals(enchInstance.enchantment) && level.matches(enchInstance.level);
}

@Override
public String toString() {
return Component.translatable(enchantment.unwrapKey().get().location().toLanguageKey("enchantment")).getString() + " " + Objects.requireNonNullElse(VillagerCommand.displayRange(enchantment.value().getMaxLevel(), level), "*");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private CCrackRngGen() {}
private static final BigVector ORIGIN = DeserializeRt.vec(
"\u0a00ʈ뒦벎츖ʐ駗질긾ʘ뾖黱덪ʠ뚊ꃪ쀆ʨ躛\ue6d4锦ʰ힒볩ﱁʸꆽ\uaaf8葉ˀﲈ쎉錏ˈ\uf8a5\uf19e똠Ȁ");
private static final BigVector ROOT_ORIGIN = DeserializeRt.vec(
"\u0ad7醌뗤ꪜހ肀肀耠횑貵\ue4aaﰃ肀肀肀‟ࣞ뚂\uf1e0뮚Ҁ肀肀耠骤蟓ꊳ輆肀肀肀⃟뚂\uf1e0뭲肀肀肀ဦ\u089aꒇ펢뎧ڀ肀肀耠\udeb6英\ue0bb㺀肀肀耐\udfb6英\ue0bbʀ肀肀耠");
"\u0ad7醌뗤ꪜހ肀肀耠횑貵\ue4aaﰃ肀肀肀‟ࣞ뚂\uf1e0뮚Ҁ肀肀耠骤蟓ꊳ輆肀肀肀⃟뚂\uf1e0뭲肀肀肀ဦ࢚ꒇ펢뎧ڀ肀肀耠\udeb6英\ue0bb㺀肀肀耐\udfb6英\ue0bbʀ肀肀耠");
RealRTTV marked this conversation as resolved.
Show resolved Hide resolved

/**
* Finds all values of {@code seed} that could produce the given results in the following code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.earthcomputer.clientcommands.Configs;
import net.earthcomputer.clientcommands.command.ClientCommandHelper;
import net.earthcomputer.clientcommands.util.MultiVersionCompat;
import net.earthcomputer.clientcommands.task.ItemThrowTask;
import net.earthcomputer.clientcommands.task.LongTask;
Expand All @@ -30,7 +31,6 @@
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
Expand Down Expand Up @@ -113,7 +113,6 @@ public class EnchantmentCracker {
*/

public static final Logger LOGGER = LogUtils.getLogger();
private static final int PROGRESS_BAR_WIDTH = 50;

// RENDERING
/*
Expand Down Expand Up @@ -480,17 +479,7 @@ public void onCompleted() {

@Override
protected void onItemThrown(int current, int total) {
MutableComponent builder = Component.empty();
int color = Mth.hsvToRgb(current / (total * 3.0f), 1.0f, 1.0f);
builder.append(Component.literal("[").withColor(0xAAAAAA));
builder.append(Component.literal("~" + Math.round(100.0 * current / total) + "%").withColor(color));
builder.append(Component.literal("] ").withColor(0xAAAAAA));
int filledWidth = (int) Math.round((double) PROGRESS_BAR_WIDTH * current / total);
int unfilledWidth = PROGRESS_BAR_WIDTH - filledWidth;
builder.append(Component.literal("|".repeat(filledWidth)).withColor(color));
builder.append(Component.literal("|".repeat(unfilledWidth)).withColor(0xAAAAAA));

Minecraft.getInstance().gui.setOverlayMessage(builder, false);
ClientCommandHelper.updateOverlayProgressBar(current, total, 50, 60);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ record ErrorEntry(int tick, boolean isBox) {}
LootTable fishingLootTable = MCLootTables.FISHING.get().apply(SeedfindingUtil.getMCVersion());
for (var goal : goals) {
if (goal.value() instanceof ClientItemPredicateArgument.EnchantedItemPredicate predicate) {
if (predicate.isEnchantedBook() && predicate.predicate.numEnchantments() >= 2) {
if (predicate.isEnchantedBook() && predicate.predicate.with().size() >= 2) {
if (!hasWarnedMultipleEnchants) {
ClientCommandHelper.sendHelp(Component.translatable("commands.cfish.help.tooManyEnchants"));
hasWarnedMultipleEnchants = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package net.earthcomputer.clientcommands.features;

import net.earthcomputer.clientcommands.command.ClientCommandHelper;
import net.earthcomputer.clientcommands.command.VillagerCommand;
import net.earthcomputer.clientcommands.interfaces.IVillager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.GlobalPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundAddExperienceOrbPacket;
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.npc.Villager;
import org.jetbrains.annotations.Nullable;

import java.lang.ref.WeakReference;
import java.util.UUID;

public class VillagerCracker {
// This value was computed by brute forcing all seeds
public static final float MAX_ERROR = 5 * 0x1.0p-24f;

@Nullable
private static UUID villagerUuid = null;
@Nullable
private static WeakReference<Villager> cachedVillager = null;
@Nullable
private static GlobalPos clockPos = null;
@Nullable
public static VillagerCommand.Offer targetOffer = null;
@Nullable
private static Long lastServerTick = null;
private static boolean receivedClockRateWarning = false;

@Nullable
public static Villager getVillager() {
if (villagerUuid == null) {
cachedVillager = null;
return null;
}
if (cachedVillager != null) {
Villager villager = cachedVillager.get();
if (villager != null && !villager.isRemoved()) {
return villager;
}
}
ClientLevel level = Minecraft.getInstance().level;
if (level != null) {
for (Entity entity : level.entitiesForRendering()) {
if (entity.getUUID() == villagerUuid && entity instanceof Villager villager) {
cachedVillager = new WeakReference<>(villager);
return villager;
}
}
}
return null;
}

@Nullable
public static GlobalPos getClockPos() {
return clockPos;
}

public static void setTargetVillager(@Nullable Villager villager) {
Villager oldVillager = getVillager();
if (oldVillager != null) {
((IVillager) oldVillager).clientcommands_getVillagerRngSimulator().reset();
}

if (clockPos == null) {
ClientCommandHelper.sendHelp(Component.translatable("commands.cvillager.help.noClock"));
}

ClientLevel level = Minecraft.getInstance().level;

if (level.getDayTime() % 24000 < 12000) {
ClientCommandHelper.sendHelp(Component.translatable("commands.cvillager.help.day"));
}

VillagerCracker.cachedVillager = new WeakReference<>(villager);
VillagerCracker.villagerUuid = villager == null ? null : villager.getUUID();
}

public static void setClockPos(@Nullable GlobalPos pos) {
VillagerCracker.clockPos = pos;
}

public static void onSoundEventPlayed(ClientboundSoundPacket packet) {
Villager targetVillager = getVillager();
if (targetVillager == null || getClockPos() == null) {
return;
}

switch (packet.getSound().value().getLocation().toString()) {
case "minecraft:entity.villager.ambient", "minecraft:entity.villager.trade" -> ((IVillager) targetVillager).clientcommands_onAmbientSoundPlayed(packet.getPitch());
case "minecraft:entity.villager.no" -> ((IVillager) targetVillager).clientcommands_onNoSoundPlayed(packet.getPitch());
case "minecraft:entity.villager.yes" -> ((IVillager) targetVillager).clientcommands_onYesSoundPlayed(packet.getPitch());
case "minecraft:entity.generic.splash" -> ((IVillager) targetVillager).clientcommands_onSplashSoundPlayed(packet.getPitch());
}
}

public static void onXpOrbSpawned(ClientboundAddExperienceOrbPacket packet) {
Villager targetVillager = getVillager();
if (targetVillager == null) {
return;
}

((IVillager) targetVillager).clientcommands_onXpOrbSpawned(packet.getValue());
}

public static void onServerTick() {
long now = System.currentTimeMillis();

Villager targetVillager = getVillager();
if (targetVillager == null) {
lastServerTick = now;
return;
}

if (lastServerTick != null && now - lastServerTick > 80L && !receivedClockRateWarning) {
ClientCommandHelper.sendHelp(Component.translatable("commands.cvillager.help.tooSlow"));
receivedClockRateWarning = true;
}

((IVillager) targetVillager).clientcommands_onServerTick();

lastServerTick = now;
}
}
Loading
Loading