Skip to content

Commit

Permalink
Rewrite /ccrackrng
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Mar 7, 2024
1 parent 9c69919 commit 80ee292
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 328 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ dependencies {
includedLibrary "com.seedfinding:mc_core:${project.seedfinding_core_version}"
includedLibrary "com.seedfinding:mc_seed:${project.seedfinding_seed_version}"

includedLibrary files('libs/LattiCG-1.06-rt.jar')

compileOnly 'com.demonwav.mcdev:annotations:2.0.0'

modRuntimeOnly('me.djtheredstoner:DevAuth-fabric:1.1.0') {
Expand Down
Binary file added libs/LattiCG-1.06-rt.jar
Binary file not shown.
256 changes: 0 additions & 256 deletions src/main/java/net/cortex/clientAddon/cracker/Lattice_cracker.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/net/cortex/clientAddon/cracker/SeedCrackTask.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import net.cortex.clientAddon.cracker.SeedCracker;
import net.earthcomputer.clientcommands.Configs;
import net.earthcomputer.clientcommands.ServerBrandManager;
import net.earthcomputer.clientcommands.features.CCrackRng;
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.network.chat.Component;
Expand All @@ -20,7 +20,7 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc

private static int crackPlayerRNG(FabricClientCommandSource source) {
ServerBrandManager.rngWarning();
SeedCracker.crack(seed -> {
CCrackRng.crack(seed -> {
source.sendFeedback(Component.translatable("commands.ccrackrng.success", Long.toHexString(seed)));
PlayerRandCracker.setSeed(seed);
Configs.playerCrackState = PlayerRandCracker.CrackState.CRACKED;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
package net.cortex.clientAddon.cracker;
package net.earthcomputer.clientcommands.features;

import net.earthcomputer.clientcommands.Configs;
import net.earthcomputer.clientcommands.command.ClientCommandHelper;
import net.earthcomputer.clientcommands.features.EnchantmentCracker;
import net.earthcomputer.clientcommands.features.PlayerRandCracker;
import net.earthcomputer.clientcommands.mixin.LegacyRandomSourceAccessor;
import net.earthcomputer.clientcommands.task.ItemThrowTask;
import net.earthcomputer.clientcommands.task.LongTask;
import net.earthcomputer.clientcommands.task.TaskManager;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.util.RandomSource;

public class SeedCracker {
public interface OnCrack {void callback(long seed); }
public class CCrackRng {
private static final float MAX_ERROR = 0.00883889f;

@FunctionalInterface
public interface OnCrack {
void callback(long seed);
}


public static OnCrack callback;
public static long[] bits=new long[20];
public static float[] nextFloats = new float[10];
public static int expectedItems=0;
public static LongTask currentTask;
private static int attemptCount = 0;
private static final int MAX_ATTEMPTS = 10;
private static final int MAX_ATTEMPTS = 5;
private static String currentTaskName = null;

private static String throwItems()
{
private static String throwItems() {
LocalPlayer player = Minecraft.getInstance().player;
assert player != null;
player.moveTo(player.getX(), player.getY(), player.getZ(), 0, 90);
Minecraft.getInstance().getConnection().send(new ServerboundMovePlayerPacket.Rot(0, 90, true)); // point to correct location
ItemThrowTask task = new ItemThrowTask(20) {
player.connection.send(new ServerboundMovePlayerPacket.Rot(0, 90, true)); // point to correct location
ItemThrowTask task = new ItemThrowTask(10) {
@Override
protected void onSuccess() {
SeedCracker.attemptCrack();
CCrackRng.attemptCrack();
}

@Override
Expand All @@ -62,41 +61,34 @@ protected void onItemSpawn(ClientboundAddEntityPacket packet) {

public static void attemptCrack()
{
long seed= Lattice_cracker.crack(SeedCracker.bits);

if(seed==0)//Basicaly if seed is zero it means it failed to try to crack again
{
long[] seeds = CCrackRngGen.getSeeds(
Math.max(0, nextFloats[0] - MAX_ERROR), Math.min(1, nextFloats[0] + MAX_ERROR),
Math.max(0, nextFloats[1] - MAX_ERROR), Math.min(1, nextFloats[1] + MAX_ERROR),
Math.max(0, nextFloats[2] - MAX_ERROR), Math.min(1, nextFloats[2] + MAX_ERROR),
Math.max(0, nextFloats[3] - MAX_ERROR), Math.min(1, nextFloats[3] + MAX_ERROR),
Math.max(0, nextFloats[4] - MAX_ERROR), Math.min(1, nextFloats[4] + MAX_ERROR),
Math.max(0, nextFloats[5] - MAX_ERROR), Math.min(1, nextFloats[5] + MAX_ERROR),
Math.max(0, nextFloats[6] - MAX_ERROR), Math.min(1, nextFloats[6] + MAX_ERROR),
Math.max(0, nextFloats[7] - MAX_ERROR), Math.min(1, nextFloats[7] + MAX_ERROR),
Math.max(0, nextFloats[8] - MAX_ERROR), Math.min(1, nextFloats[8] + MAX_ERROR),
Math.max(0, nextFloats[9] - MAX_ERROR), Math.min(1, nextFloats[9] + MAX_ERROR)
).toArray();

if (seeds.length != 1) {
attemptCount++;
if (attemptCount > MAX_ATTEMPTS) {
ClientCommandHelper.sendError(Component.translatable("commands.ccrackrng.failed"));
ClientCommandHelper.sendHelp(Component.translatable("commands.ccrackrng.failed.help"));
Configs.playerCrackState = PlayerRandCracker.CrackState.UNCRACKED;
currentTaskName = null;
} else {
SeedCracker.doCrack(SeedCracker.callback);
CCrackRng.doCrack(CCrackRng.callback);
}
return;
}
//Else, got a seed

Configs.playerCrackState = PlayerRandCracker.CrackState.CRACKED;

RandomSource rand=RandomSource.create(seed ^ 0x5deece66dL);
rand.nextFloat();
rand.nextFloat();
//rand.nextFloat();

/*
for(int i=0;i<13;i++) {
long x = (((long) (rand.nextFloat() * ((float) (1 << 24)))) >> (24 - 4))&0xFL;
System.out.print("Expected: "+padLeftZeros(Long.toBinaryString(x), 4)+" ");
System.out.print(padLeftZeros(Long.toBinaryString((((long) (rand.nextFloat() * ((float) (1 << 24)))) >> (24 - 4))&0xFL), 4)+" ");
System.out.print(padLeftZeros(Long.toBinaryString((((long) (rand.nextFloat() * ((float) (1 << 24)))) >> (24 - 4))&0xFL), 4)+" ");
System.out.print(padLeftZeros(Long.toBinaryString((((long) (rand.nextFloat() * ((float) (1 << 24)))) >> (24 - 4))&0xFL), 4)+" \n");
}*/

currentTaskName = null;
callback.callback(((LegacyRandomSourceAccessor) rand).getSeed().get());//extract seed and call callback
callback.callback(seeds[0]);
}

public static void crack(OnCrack callback) {
Expand All @@ -109,7 +101,7 @@ private static void doCrack(OnCrack Callback){
ClientCommandHelper.addOverlayMessage(Component.translatable("commands.ccrackrng.retries", attemptCount, MAX_ATTEMPTS), 100);
currentTaskName = throwItems();
Configs.playerCrackState = PlayerRandCracker.CrackState.CRACKING;
expectedItems = 20;
expectedItems = 10;
if (attemptCount == 1) {
Component message = Component.translatable("commands.ccrackrng.starting")
.append(" ")
Expand All @@ -120,12 +112,10 @@ private static void doCrack(OnCrack Callback){

public static void onEntityCreation(ClientboundAddEntityPacket packet) {
if (Configs.playerCrackState == PlayerRandCracker.CrackState.CRACKING) {
if (SeedCracker.expectedItems > 0) {
long rand_val = (long) ((Math.atan2(packet.getZa(), packet.getXa()) + Math.PI) / (Math.PI * 2) * ((float) (1 << 24)));
long top_bits = rand_val;
short value = (short) (((top_bits >> (24 - 4)) ^ 0x8L )&0xFL);//INSTEAD OF ^0x8L MAYBE DO +math.pi OR SOMETHING ELSE
SeedCracker.bits[20-SeedCracker.expectedItems]=(long)value;//could be improved
SeedCracker.expectedItems--;
if (CCrackRng.expectedItems > 0) {
float nextFloat = (float) Math.sqrt(packet.getXa() * packet.getXa() + packet.getZa() * packet.getZa()) * 50f;
CCrackRng.nextFloats[10 - CCrackRng.expectedItems] = nextFloat;
CCrackRng.expectedItems--;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package net.earthcomputer.clientcommands.features;

import com.seedfinding.latticg.math.component.BigMatrix;
import com.seedfinding.latticg.math.component.BigVector;
import com.seedfinding.latticg.math.lattice.enumerate.EnumerateRt;
import com.seedfinding.latticg.math.optimize.Optimize;
import com.seedfinding.latticg.util.DeserializeRt;
import java.util.stream.LongStream;

// CLASS GENERATED BY LATTICG, DO NOT EDIT MANUALLY
public final class CCrackRngGen {
private CCrackRngGen() {}
private static final BigMatrix BASIS = DeserializeRt.mat(
"ਊ\ued95膕쩅˴ꋄꊝ\ue001ʁ銧릿挂\ua7eb\ue702ʬ\uf198믅씁˚辑톹鄁˝ꊘ\udae2\udf02ʝ\ue7bf\ue0b1\ue602ˬ삭겦褂ʎ뇽\udeb1윁ʭ鮊\ue8cd쨂ˍ雏ꧮᄂ膲\uf5ba霆ʇ풁菆밁ˬ꺆\uf3e6" +
"ꔁ˺횪钖܂\ue4e9\ude80\uf6afȂ\udda2\ue2dfȂ곶\ue5ecꌱʓ\ud999쿀稂钇잕ꄥ˴鞹킔ं肮颖鋀Ă\ue788鶆뎩Ă계\uf0b1谫˧귁臝숃ʤ뺎螴鈁ˤ\ue9de胶꼂ʕﲥꓵᴂ캸싲\ue4a4Ђ궮뢉难Ă췑뗧\uf4fc" +
"Ă臲뷒草ʺ뛪ꚪ윁ˬ뇲\uf19cꈁʺ솋飖츁ˤ\udaef\uea8d\ue001ʤ뺎螴鈁ʬ\ue994궶쐂ʮꚍ\ue683ᜂ铄鲎낺Ȃ\uf4ac\uef89Ă胮잶贵ʧ횤쿔鸃ʬ\uf7d6\udab2fiʧ鯈ꮴ頂ʤ뾋쯡搂\ue4da\uefea跠Ă\ueca6" +
"톀\uf19aĂ\uf3cf藪谘˔\udeba\uda92茁ʴ鏋뺌퐂ʀ컩铚\uda01ʇ\uef9bꂸ㜂\uec94馷ﻏĂ\ufafb\ue89d̂鶔薚켑ʤ뾋쯡搂겼襁鉵ˮ闵\ueb9bꨂ˭\ude98\uf2fb茁˴\ue1a4ꛝ愂肮\ue7e3鰞" +
"˧폤\ufae2똁ʬ諤쯬켂ʚ쟐雂䄂\udd9f馕ሂ鶔薚켑ʕ훔힢蔂ˎ鞡룩\uf201ʭ\uf4c8웰㸂뒘\udb83뫆Ă臲ﺈ\ue485Ђ못ᄋ\udaecȂ閨\uedf3藧Ă쟹\ued91쐜ˤ鲈\uecff갂˝龙锒ʬ\uefae뫇圂껵\ud9a8ﺹĂ\uede1" +
"\uf0e8\ue0a7Ȃ跉铫꾞Ă膒覦︕ʧ膉黖漂햂탎鲮̂Ꞇꎪv˝\uded7軟蔁ˤ鲈\uecff갂ˬ貀횘ꈁ˳郍킇툂ʭ\ua7db\u0602뒽ꊽ钾Ȃ胎裐ꋃȂ蝹킜탚Ă\uecfa\uf6af验Ă\ufae0\udf89衕ʝ鋠횅褂˝\uded7軟蔁˕ﶵ" +
"싳옃ʓ뮈ꚋ\uf101Ȁ");
private static final BigMatrix ROOT_INV = DeserializeRt.mat(
"ਊ\u0380肀肀耐ހ肀肀耠ᎀ肀肀肀ċ肀肀肀䀆肀肀肀䀂肀肀肀䀏肀肀肀䀋肀肀肀老\u0b80肀肀耠\u0b80肀肀聀ڀ肀肀聀ኀ肀肀肀Ć肀肀肀老ྀ肀肀肀Ě肀肀肀老\u0e80肀肀聀\u0380肀肀耠ኀ肀肀聀 肀肀肀Ģ肀肀肀老\u0380肀肀耠᪀肀肀肀Ģ肀" +
"肀肀老ʀ肀肀聀ᎀ肀肀肀Ě肀肀肀老ᮀ肀肀聀ᾀ肀肀肀ă肀肀肀䀖肀肀肀老ʀ肀肀耠ྀ肀肀肀Ă肀肀肀ည肀肀肀 肀肀肀 肀肀肀ဟ肀肀肀老\u0e80肀肀肀ă肀肀肀ဦ肀肀肀老ʀ肀肀耐\u0b80肀肀肀ć肀肀肀老ڀ肀肀耐⊀肀肀肀ě肀肀肀老ʀ肀肀耈\u0380肀肀肀ď" +
"肀肀肀老ڀ肀肀耠\u0b80肀肀聀ހ肀肀肀ģ肀肀肀老\u0380肀肀耠ក肀肀肀Ċ肀肀肀 肀肀肀䀃肀肀肀 ț肀肀肀老➀肀肀肀Ħ肀肀肀老ʀ肀肀聀\2ʀ肀肀肀Ċ肀肀肀䀋肀肀肀䀎肀肀肀老\u0380肀肀耐\u0380肀肀聀ྀ肀肀肀ă肀肀肀ࠀȎ肀肀肀䀖肀肀肀老" +
"ڀ肀肀肀Ă肀肀肀ࠆ肀肀肀䀞肀肀肀老ڀ肀肀聀Ẁ肀肀肀Ć肀肀肀䀆肀肀肀䀆肀肀肀 肀肀肀ည肀肀肀老⾀肀肀肀ă肀肀肀老ʀ肀肀耠\2ʀ肀肀耠\u0380肀肀耠᪀肀肀肀ć肀肀肀䀟肀肀肀老ڀ肀肀聀\u0a80肀肀肀ă肀肀肀老ހ肀肀聀ހ肀肀耠");
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ʀ肀肀耠");

/**
* Finds all values of {@code seed} that could produce the given results in the following code:
* <pre>{@code
* Random rand = new Random(seed ^ 0x5DEECE66DL);
* // Go backwards by 39 random calls
* float nextFloat1 = rand.nextFloat();
* assert nextFloat1 >= minNextFloat1 && nextFloat1 < maxNextFloat1;
* // Skip 3 random calls
* float nextFloat2 = rand.nextFloat();
* assert nextFloat2 >= minNextFloat2 && nextFloat2 < maxNextFloat2;
* // Skip 3 random calls
* float nextFloat3 = rand.nextFloat();
* assert nextFloat3 >= minNextFloat3 && nextFloat3 < maxNextFloat3;
* // Skip 3 random calls
* float nextFloat4 = rand.nextFloat();
* assert nextFloat4 >= minNextFloat4 && nextFloat4 < maxNextFloat4;
* // Skip 3 random calls
* float nextFloat5 = rand.nextFloat();
* assert nextFloat5 >= minNextFloat5 && nextFloat5 < maxNextFloat5;
* // Skip 3 random calls
* float nextFloat6 = rand.nextFloat();
* assert nextFloat6 >= minNextFloat6 && nextFloat6 < maxNextFloat6;
* // Skip 3 random calls
* float nextFloat7 = rand.nextFloat();
* assert nextFloat7 >= minNextFloat7 && nextFloat7 < maxNextFloat7;
* // Skip 3 random calls
* float nextFloat8 = rand.nextFloat();
* assert nextFloat8 >= minNextFloat8 && nextFloat8 < maxNextFloat8;
* // Skip 3 random calls
* float nextFloat9 = rand.nextFloat();
* assert nextFloat9 >= minNextFloat9 && nextFloat9 < maxNextFloat9;
* // Skip 3 random calls
* float nextFloat10 = rand.nextFloat();
* assert nextFloat10 >= minNextFloat10 && nextFloat10 < maxNextFloat10;
* }</pre>
*
* <p>This code skips 0.000000% of seeds in its search.
*/
public static LongStream getSeeds(float minNextFloat1, float maxNextFloat1, float minNextFloat2, float maxNextFloat2, float minNextFloat3, float maxNextFloat3, float minNextFloat4, float maxNextFloat4, float minNextFloat5, float maxNextFloat5, float minNextFloat6, float maxNextFloat6, float minNextFloat7, float maxNextFloat7, float minNextFloat8, float maxNextFloat8, float minNextFloat9, float maxNextFloat9, float minNextFloat10, float maxNextFloat10) {
Optimize.Builder builder = Optimize.Builder.ofSize(10);
if (minNextFloat1 >= maxNextFloat1) {
return LongStream.empty();
}
builder.withLowerBound(0, (long) (minNextFloat1 * 0x1.0p24f) << 24).withUpperBound(0, (long) (maxNextFloat1 * 0x1.0p24f) << 24);
if (minNextFloat2 >= maxNextFloat2) {
return LongStream.empty();
}
builder.withLowerBound(1, (long) (minNextFloat2 * 0x1.0p24f) << 24).withUpperBound(1, (long) (maxNextFloat2 * 0x1.0p24f) << 24);
if (minNextFloat3 >= maxNextFloat3) {
return LongStream.empty();
}
builder.withLowerBound(2, (long) (minNextFloat3 * 0x1.0p24f) << 24).withUpperBound(2, (long) (maxNextFloat3 * 0x1.0p24f) << 24);
if (minNextFloat4 >= maxNextFloat4) {
return LongStream.empty();
}
builder.withLowerBound(3, (long) (minNextFloat4 * 0x1.0p24f) << 24).withUpperBound(3, (long) (maxNextFloat4 * 0x1.0p24f) << 24);
if (minNextFloat5 >= maxNextFloat5) {
return LongStream.empty();
}
builder.withLowerBound(4, (long) (minNextFloat5 * 0x1.0p24f) << 24).withUpperBound(4, (long) (maxNextFloat5 * 0x1.0p24f) << 24);
if (minNextFloat6 >= maxNextFloat6) {
return LongStream.empty();
}
builder.withLowerBound(5, (long) (minNextFloat6 * 0x1.0p24f) << 24).withUpperBound(5, (long) (maxNextFloat6 * 0x1.0p24f) << 24);
if (minNextFloat7 >= maxNextFloat7) {
return LongStream.empty();
}
builder.withLowerBound(6, (long) (minNextFloat7 * 0x1.0p24f) << 24).withUpperBound(6, (long) (maxNextFloat7 * 0x1.0p24f) << 24);
if (minNextFloat8 >= maxNextFloat8) {
return LongStream.empty();
}
builder.withLowerBound(7, (long) (minNextFloat8 * 0x1.0p24f) << 24).withUpperBound(7, (long) (maxNextFloat8 * 0x1.0p24f) << 24);
if (minNextFloat9 >= maxNextFloat9) {
return LongStream.empty();
}
builder.withLowerBound(8, (long) (minNextFloat9 * 0x1.0p24f) << 24).withUpperBound(8, (long) (maxNextFloat9 * 0x1.0p24f) << 24);
if (minNextFloat10 >= maxNextFloat10) {
return LongStream.empty();
}
builder.withLowerBound(9, (long) (minNextFloat10 * 0x1.0p24f) << 24).withUpperBound(9, (long) (maxNextFloat10 * 0x1.0p24f) << 24);
return EnumerateRt.enumerate(BASIS, ORIGIN, builder.build(), ROOT_INV, ROOT_ORIGIN)
.mapToLong(vec -> (vec.get(0).getNumerator().longValue() * 0x641598c21879L + 0x60dd589d4b7eL) & ((1L << 48) - 1));
}
}

0 comments on commit 80ee292

Please sign in to comment.