diff --git a/src/main/java/net/cortex/clientAddon/cracker/Lattice_cracker.java b/src/main/java/net/cortex/clientAddon/cracker/Lattice_cracker.java new file mode 100644 index 000000000..f69df4615 --- /dev/null +++ b/src/main/java/net/cortex/clientAddon/cracker/Lattice_cracker.java @@ -0,0 +1,256 @@ +package net.cortex.clientAddon.cracker; + +import net.earthcomputer.clientcommands.features.EnchantmentCracker; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Lattice_cracker +{ + static long[][] aLLL={{-1448260238L, -12778033679726L, -46671229957710L, 22119786771154L, 27708029636082L, -22438238668014L, -34239632860622L, -4382943687854L, 8584312843890L, -4127871589486L, 8400903310002L, -11734527753262L, 27623303114482L, -16857517642734L, 5491174120242L, 18668149070930L, -1330558201998L, 1101586846866L, 23911899122610L, -11978722732846L}, + {2456726561834L, -3261629580086L, -29057456210070L, -7883513836534L, 31945299444394L, -5904400710838L, -24028330086934L, -8636803292534L, 6821737120042L, -34305302959670L, -31018921034646L, 7060520311050L, 14765354278826L, -8758653587382L, -20175659537686L, 8317473550218L, -10921060491734L, -2987718797622L, 5900808190314L, 6352173884938L}, + {8042575855974L, 813702672838L, 21581825640486L, 8883610035334L, -26255500269850L, 1036335804230L, 23567418219942L, -59603824122L, 25940808379494L, 4627497995462L, -25095571369178L, -7790883610746L, -1444450725402L, 722857134662L, -18908505102170L, -23894342415098L, -15177942083738L, -12318375958586L, 12756255809062L, 15774489680518L}, + {-49926751308L, 22840726110964L, -3448514642380L, 6728711122292L, 50694484168884L, 11896772388852L, -17420761795788L, -21289175223692L, 10636143502772L, -12584063447820L, 10571621705780L, 33447933867892L, 16024538905268L, -21277299740172L, 2190719327540L, -16944424797068L, 6434888028084L, 17819255953140L, 8234121155124L, 6241722843508L}, + {8043754892887L, -38916266631993L, 23882357015095L, 2619077463719L, -20615629409769L, 19068392119431L, 63315709066743L, 2837792392807L, 14856374199767L, 411971439687L, -23683213006409L, -14139599229401L, -13615773431401L, 10242565925895L, 5574772802935L, 2355273254375L, -1682386002601L, 11336528427975L, 8415441228087L, -34697163633241L}, + {-5494973979516L, -3768771516220L, 7235101896964L, -19515695350460L, 23438541016452L, 57947009982916L, 3234283125252L, 5251495302724L, -25447099812220L, 6873097837252L, -12648694512892L, -933295214780L, -14975211774076L, 50371998929860L, 20863835786244L, 9710816168004L, -14836142880636L, -35171132322620L, -16681195776764L, 32376126316868L}, + {-5483787940079L, -14637515878623L, 17850398343217L, 8949933093441L, 9702913766737L, 26217836632417L, 32304808029809L, 5980854830209L, -16772670002287L, -6669745261663L, 8075973487793L, -579480295743L, 16430785130961L, 39330324946401L, 3935927565041L, 55523837974785L, 17014677604369L, -6696604575711L, -12431751833295L, 14269142784833L}, + {-8032964665055L, 21247545045553L, 30929614226497L, 38962464794449L, 4709664238433L, 46931283075185L, 5116035389057L, 25432913878417L, 13768716371361L, -8484093305167L, -5787236730687L, -5382118136879L, -12479184539679L, 8488349265137L, -33497656644863L, -19141840389615L, 13977842297377L, 4331186424625L, -15699184980671L, 27715581108305L}, + {4988218521118L, 12616703326718L, -21204778378274L, -729956697154L, -24269072369250L, -33943758228098L, -41702548156578L, 5942270699326L, -10232590131938L, -1083939647234L, -45758359739682L, -12708051193154L, 12552936562846L, -10046183846786L, -8702244465058L, 11381428035134L, 16650379494430L, 13944071383038L, 22893499623902L, -28409737139778L}, + {10859897282794L, -16009052371574L, -28077257042902L, 21097912872138L, -206584942742L, 3730747636746L, 25181579293354L, -20380089126070L, 27191160511978L, -7834730081654L, -18843310182102L, 8168779438538L, 8388211764330L, -14474887821046L, -9054197428310L, -8396358786998L, 1437819853546L, 12575312994186L, -11470762766806L, 19726741079754L}, + {-7785498351601L, 31356985997823L, 9909996108527L, -2817590650145L, -35685247940145L, 5288384100287L, 3640951362735L, 7298985169055L, -7100594185329L, 3894496912767L, 18834937831023L, -3750473468321L, 4118829931855L, 3561000485695L, -34042906421201L, 5619317918751L, 7859936104207L, 20120144351487L, 29419781112303L, -4450764058145L}, + {-15649636543501L, -1908413202397L, -1804244975789L, 26155764302211L, -7805507340621L, 15748335521507L, -34485888812525L, 12610082285635L, -2321680889485L, 7215291256227L, 44027603297491L, 23636070121219L, -7236256904141L, -25012997587869L, -2849669480557L, -17631285738045L, 26616579342067L, -7244259402973L, -6060271105453L, -2521340642173L}, + {-18491400876168L, -4900215517448L, -6830241347976L, 21163840042488L, 16159978118520L, 8593158356216L, -21634197842824L, -4431664618504L, -4381551121544L, 2043191225080L, 38341802238584L, -15917443100168L, -16154482083464L, 13179037980920L, 12206922936440L, 35960063377400L, 28251901052792L, -31724682033416L, 20311095066232L, 24433634684408L}, + {-4844884945495L, -16727797029063L, 3490148401609L, 9661359584601L, 10717868544489L, 13348777617273L, 28592339043849L, 10588371811737L, -2765442277847L, 8602169554873L, -27136636757431L, 7588778513881L, -12754114872727L, 26999493236729L, -25823672861047L, -28601553011175L, -7734381844823L, -12048436164551L, -1942349172023L, 24752019699289L}, + {-14937328018869L, 18082834551803L, -2403011299157L, 23070439929947L, 17344700465931L, -8725186803525L, -943262729877L, 12838792545563L, 7655689591755L, 13889301818747L, 7894717573675L, 20345079906779L, -879696337781L, 657627611707L, 25750462860011L, 7218811563675L, 28387117718859L, -6335132727557L, 40341554437035L, -18369247458469L}, + {6141026202367L, -19291564456977L, -18640159820833L, 6565390987983L, 32484313936063L, 1745196162479L, -13911857960545L, 22895682815119L, 13490667904639L, 1187363088239L, 12794002902879L, -16489025321393L, 9461976038463L, -30568369643217L, 35815397664031L, -10446584481777L, -10587809773057L, -3274582897937L, 4365799500511L, 2437771762127L}, + {-17541499701901L, -18091677238877L, 777749549267L, 36973368814339L, 12312441813043L, 5024920823907L, 10647975635859L, -28706250657341L, 3974671559411L, -2041065388253L, 15379662124627L, -11309664147325L, 26276636102067L, -6915167758877L, -4707210596077L, 7443560238915L, 269939794035L, -14698604981085L, 8977530018771L, 362272646659L}, + {-1386259850433L, 3423168589871L, -16619435989985L, 12373450925839L, 11511687981311L, -4577750951441L, -44635762644513L, 5932736678095L, -3126138837313L, -13089806339153L, 30467539820447L, 1498640112271L, -75452509057L, 10924282772847L, 1194982802783L, -29116057183153L, -32751811546561L, 13522518193967L, -18623108310241L, 6054998756879L}, + {10711311805721L, 1077561689513L, 36740932605753L, 23665386205641L, -8342605339303L, 19521111802345L, 12323744175993L, 10898789119497L, -31652527936103L, 1054227271209L, -17122992478279L, 17802438232649L, -10829462534695L, 35502810688105L, 10721860192249L, 30043314908809L, -4902738940391L, -26106192275799L, -5734346459079L, 10406576366281L}, + {-18091677238877L, 777749549267L, 36973368814339L, 12312441813043L, 5024920823907L, 10647975635859L, -28706250657341L, 3974671559411L, -2041065388253L, 15379662124627L, -11309664147325L, 26276636102067L, -6915167758877L, -4707210596077L, 7443560238915L, 269939794035L, -14698604981085L, 8977530018771L, 362272646659L, 36478988018483L}}; + + static double[][] aLLLinv={{2.13162820728e-14, -1.7763568394e-14, 1.7763568394e-14, 2.48689957516e-14, 3.5527136788e-15, -3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15, -3.5527136788e-15, 3.5527136788e-15, 7.1054273576e-15, 3.5527136788e-15, -2.13162820728e-14, 0.0, -2.13162820728e-14, -3.5527136788e-15, 1.42108547152e-14, -1.06581410364e-14}, + {0.0, 0.0, -7.1054273576e-15, -7.1054273576e-15, -1.06581410364e-14, 3.5527136788e-15, -1.06581410364e-14, 1.06581410364e-14, -7.1054273576e-15, 3.5527136788e-15, 3.5527136788e-15, -1.06581410364e-14, -7.1054273576e-15, -1.06581410364e-14, 1.06581410364e-14, -3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15}, + {-3.5527136788e-15, -3.5527136788e-15, 1.06581410364e-14, 1.06581410364e-14, 3.5527136788e-15, -7.1054273576e-15, 7.1054273576e-15, 0.0, 3.5527136788e-15, -1.42108547152e-14, -7.1054273576e-15, 0.0, 3.5527136788e-15, 0.0, -7.1054273576e-15, 0.0, 0.0, 0.0, 0.0, 3.5527136788e-15}, + {3.5527136788e-15, -3.5527136788e-15, -7.1054273576e-15, -3.5527136788e-15, 0.0, -3.5527136788e-15, -7.1054273576e-15, 7.1054273576e-15, 0.0, 7.1054273576e-15, 0.0, -3.5527136788e-15, 0.0, 0.0, 3.5527136788e-15, 0.0, 7.1054273576e-15, 3.5527136788e-15, 1.06581410364e-14, 0.0}, + {1.42108547152e-14, -3.5527136788e-15, -7.1054273576e-15, 7.1054273576e-15, 0.0, -3.5527136788e-15, -3.5527136788e-15, 7.1054273576e-15, -7.1054273576e-15, -1.06581410364e-14, -7.1054273576e-15, -7.1054273576e-15, 0.0, 7.1054273576e-15, -3.5527136788e-15, -3.5527136788e-15, -3.5527136788e-15, -7.1054273576e-15, 0.0, 0.0}, + {7.1054273576e-15, 0.0, 0.0, 3.5527136788e-15, 7.1054273576e-15, 1.42108547152e-14, -3.5527136788e-15, 3.5527136788e-15, 0.0, 3.5527136788e-15, 7.1054273576e-15, 7.1054273576e-15, -3.5527136788e-15, -7.1054273576e-15, -3.5527136788e-15, 0.0, 0.0, -3.5527136788e-15, 0.0, 0.0}, + {-1.06581410364e-14, 3.5527136788e-15, -1.06581410364e-14, -7.1054273576e-15, -3.5527136788e-15, -3.5527136788e-15, -3.5527136788e-15, 0.0, -7.1054273576e-15, 7.1054273576e-15, 7.1054273576e-15, -7.1054273576e-15, -3.5527136788e-15, 3.5527136788e-15, 7.1054273576e-15, 7.1054273576e-15, 7.1054273576e-15, -3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15}, + {0.0, 7.1054273576e-15, 0.0, -1.06581410364e-14, -3.5527136788e-15, -3.5527136788e-15, 7.1054273576e-15, 3.5527136788e-15, -3.5527136788e-15, -3.5527136788e-15, 3.5527136788e-15, 3.5527136788e-15, -7.1054273576e-15, 3.5527136788e-15, 7.1054273576e-15, 1.06581410364e-14, -7.1054273576e-15, 0.0, 0.0, 0.0}, + {2.13162820728e-14, 0.0, 2.13162820728e-14, -3.5527136788e-15, 3.5527136788e-15, 3.5527136788e-15, 7.1054273576e-15, 7.1054273576e-15, -1.06581410364e-14, -3.5527136788e-15, -1.42108547152e-14, 3.5527136788e-15, -3.5527136788e-15, -1.42108547152e-14, 7.1054273576e-15, -1.7763568394e-14, -1.42108547152e-14, 0.0, -1.42108547152e-14, 3.5527136788e-15}, + {4.26325641456e-14, -2.48689957516e-14, 0.0, 0.0, -3.5527136788e-15, 7.1054273576e-15, -7.1054273576e-15, 7.1054273576e-15, -1.06581410364e-14, -7.1054273576e-15, -7.1054273576e-15, 0.0, -1.06581410364e-14, 3.5527136788e-15, -7.1054273576e-15, -1.7763568394e-14, -1.06581410364e-14, -1.7763568394e-14, -3.5527136788e-15, 7.1054273576e-15}, + {3.5527136788e-15, -3.5527136788e-15, 3.5527136788e-15, 3.5527136788e-15, 0.0, -3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15, -7.1054273576e-15, -3.5527136788e-15, 3.5527136788e-15, 3.5527136788e-15, 3.5527136788e-15, 0.0, -3.5527136788e-15, 0.0, -3.5527136788e-15, 3.5527136788e-15, 0.0, -3.5527136788e-15}, + {3.5527136788e-15, 7.1054273576e-15, 3.5527136788e-15, 0.0, 0.0, 0.0, 3.5527136788e-15, -7.1054273576e-15, -7.1054273576e-15, 3.5527136788e-15, 0.0, 1.06581410364e-14, -7.1054273576e-15, 0.0, 7.1054273576e-15, -7.1054273576e-15, -7.1054273576e-15, 0.0, 3.5527136788e-15, 3.5527136788e-15}, + {-3.5527136788e-15, -3.5527136788e-15, 1.7763568394e-14, 7.1054273576e-15, -7.1054273576e-15, 3.5527136788e-15, 2.13162820728e-14, -7.1054273576e-15, 1.06581410364e-14, -3.5527136788e-15, 0.0, 7.1054273576e-15, -1.06581410364e-14, 0.0, 0.0, 7.1054273576e-15, 7.1054273576e-15, 3.5527136788e-15, -7.1054273576e-15, -3.5527136788e-15}, + {3.5527136788e-15, -7.1054273576e-15, 1.42108547152e-14, 7.1054273576e-15, 3.5527136788e-15, 3.5527136788e-15, 1.42108547152e-14, -3.5527136788e-15, 7.1054273576e-15, -3.5527136788e-15, -7.1054273576e-15, 0.0, 3.5527136788e-15, 3.5527136788e-15, 3.5527136788e-15, -1.06581410364e-14, -7.1054273576e-15, 1.42108547152e-14, -7.1054273576e-15, -3.5527136788e-15}, + {-2.48689957516e-14, 0.0, 0.0, 0.0, 0.0, 3.5527136788e-15, 3.5527136788e-15, -7.1054273576e-15, 1.06581410364e-14, 1.06581410364e-14, 0.0, -3.5527136788e-15, 3.5527136788e-15, -7.1054273576e-15, 1.06581410364e-14, 1.42108547152e-14, 7.1054273576e-15, 1.06581410364e-14, 0.0, 0.0}, + {2.13162820728e-14, 3.5527136788e-15, -7.1054273576e-15, -1.06581410364e-14, 0.0, 0.0, -3.5527136788e-15, 7.1054273576e-15, -1.42108547152e-14, 0.0, 0.0, -3.5527136788e-15, -3.5527136788e-15, -1.06581410364e-14, 0.0, -1.06581410364e-14, -7.1054273576e-15, -1.06581410364e-14, 3.5527136788e-15, 7.1054273576e-15}, + {-1.42108547152e-14, -7.1054273576e-15, 7.1054273576e-15, 1.42108547152e-14, 0.0, -3.5527136788e-15, 1.42108547152e-14, -3.5527136788e-15, 1.7763568394e-14, 0.0, -7.1054273576e-15, 7.1054273576e-15, 1.06581410364e-14, 7.1054273576e-15, -3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15, 0.0, -7.1054273576e-15, -7.1054273576e-15}, + {-3.5527136788e-15, -7.1054273576e-15, -1.06581410364e-14, 7.1054273576e-15, 7.1054273576e-15, -3.5527136788e-15, 3.5527136788e-15, 0.0, 7.1054273576e-15, 7.1054273576e-15, 7.1054273576e-15, -7.1054273576e-15, 3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15, 3.5527136788e-15, -3.5527136788e-15, 7.1054273576e-15, -3.5527136788e-15, 7.1054273576e-15}, + {-7.1054273576e-15, 3.5527136788e-15, 7.1054273576e-15, 1.06581410364e-14, 7.1054273576e-15, 0.0, 0.0, -1.06581410364e-14, 7.1054273576e-15, 0.0, 1.42108547152e-14, 0.0, 1.06581410364e-14, 7.1054273576e-15, 0.0, 1.06581410364e-14, 0.0, 3.5527136788e-15, 3.5527136788e-15, 0.0}, + {-1.7763568394e-14, 0.0, 3.5527136788e-15, 3.5527136788e-15, -7.1054273576e-15, -3.5527136788e-15, 7.1054273576e-15, -7.1054273576e-15, 7.1054273576e-15, 1.06581410364e-14, 7.1054273576e-15, -3.5527136788e-15, 1.06581410364e-14, 7.1054273576e-15, -3.5527136788e-15, 1.42108547152e-14, 0.0, 3.5527136788e-15, 0.0, 3.5527136788e-15}}; + + + static long[] P={0L, 49720483695876L, 137139456763464L, 233987836661708L, 14307911880080L, 83935042429844L, 145080971318744L, 160613567801436L, 33313044635424L, 71300602445348L, 191662796360040L, 35596010767596L, 139814728398000L, 103370737179828L, 120424722284792L, 233843537749372L, 272110203194944L, 20902998949700L, 160211348143240L, 245358588709388L}; + + private static long[] multiply(long[][] matrix, long[] vector) { + int rows = matrix.length; + int columns = matrix[0].length; + + long[] result = new long[rows]; + + for (int row = 0; row < rows; row++) { + long sum = 0; + for (int column = 0; column < columns; column++) { + sum += matrix[column][row]* vector[column]; + } + result[row] = sum; + } + return result; + } + + + private static double[] multiply(double[][] matrix, double[] vector) { + int rows = matrix.length; + int columns = matrix[0].length; + + double[] result = new double[rows]; + + for (int row = 0; row < rows; row++) { + double sum = 0; + for (int column = 0; column < columns; column++) { + sum += matrix[column][row]* vector[column]; + } + result[row] = sum; + } + return result; + } + + + private static long[] multiply(long[] vector, long scalar) { + long[] result = new long[vector.length]; + + for (int i = 0; i < vector.length; i++) { + result[i]=vector[i]*scalar; + } + return result; + } + + + private static long[] add(long[] vectorA,long[] vectorB) + { + long[] result = new long[vectorA.length]; + for(int i=0;imax[i]) + return false; + return true; + } + private static boolean getNextPoint(long[] components,long[] v, long[][] A,long[] mins,long[] maxs)//mutates components and v + { + long[] v_ref=v; + for(int index=0;index maxs[index]) + { + components[index] = mins[index]; + v=sub(v,multiply(A[index],maxs[index]-mins[index]+1)); + } + else + { + for(int i=0;i dumbiterate(long[] mins, long[] maxs, long[][] A/*aLLL matrix*/, long[] P/*arbitary lattice point*/, long[] LowerBounds, long[] UpperBounds) + { + long[] temp = mins.clone(); + long[] v=add(multiply(A,temp),P); + List results=new ArrayList<>(); + while(true) + { + if(isInRegion(v,LowerBounds,UpperBounds)) + { + EnchantmentCracker.LOGGER.info("Found possible seed: " + Arrays.toString(v)); + results.add(v.clone()); + } + if(!getNextPoint(temp, v, A, mins, maxs)) + return results; + } + } + + private static List findAllSeedTuplesInBB(long[] UpperBounds,long[] LowerBounds) + { + int N=UpperBounds.length; + double[] min = new double[N]; + double[] max = new double[N]; + for(int x=0;x a=findAllSeedTuplesInBB(UpperBounds,LowerBounds); + if(a.size()==0) + return 0; + return lcg(a.get(0)[bits.length-1]);//returns the seed after + } +} + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/net/cortex/clientAddon/cracker/SeedCracker.java b/src/main/java/net/cortex/clientAddon/cracker/SeedCracker.java new file mode 100644 index 000000000..73e45476c --- /dev/null +++ b/src/main/java/net/cortex/clientAddon/cracker/SeedCracker.java @@ -0,0 +1,101 @@ +package net.cortex.clientAddon.cracker; + +import net.earthcomputer.clientcommands.features.EnchantmentCracker; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.network.packet.EntitySpawnS2CPacket; +import net.minecraft.entity.EntityType; +import net.minecraft.network.MessageType; +import net.minecraft.server.network.packet.PlayerMoveC2SPacket; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Formatting; + +import java.util.Random; +import static net.earthcomputer.clientcommands.features.EnchantmentCracker.MULTIPLIER; + +public class SeedCracker { + public interface OnCrack {void callback(long seed); } + + + public static OnCrack callback; + public static long[] bits=new long[20]; + public static int expectedItems=0; + public static boolean cracking=false; + + //returns True on success or false on failer + private static boolean throwItems() + { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + player.setPositionAndAngles(player.x, player.y, player.z, 0, 90); + MinecraftClient.getInstance().getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.LookOnly(0, 90, true)); // point to correct location + for (int i = 0; i < 20; i++) { + EnchantmentCracker.EnchantManipulationStatus status = EnchantmentCracker.throwItem(); + if (status != EnchantmentCracker.EnchantManipulationStatus.OK && status != EnchantmentCracker.EnchantManipulationStatus.NOT_CRACKED) { + MinecraftClient.getInstance().inGameHud.addChatMessage(MessageType.GAME_INFO, new TranslatableText("itemCrack.notEnoughItems").formatted(Formatting.RED)); + EnchantmentCracker.LOGGER.info("Unable to use rng SeedCracker |not enough items|"); + return false; + } + } + return true; + } + public static void attemptCrack() + { + cracking=false; + long seed= Lattice_cracker.crack(SeedCracker.bits); + + if(seed==0)//Basicaly if seed is zero it means it failed to try to crack again + { + SeedCracker.crack(SeedCracker.callback); + return; + } + //Else, got a seed + + Random rand=new Random(); + rand.setSeed(seed ^ MULTIPLIER); + 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"); + }*/ + + callback.callback(EnchantmentCracker.getSeed(rand));//extract seed and call callback + } + public static void crack(OnCrack Callback){ + callback=Callback; + if(throwItems()) + { + cracking=true; + expectedItems=20; + } + } + + public static void onEntityCreation(EntitySpawnS2CPacket packet) { + if (packet.getEntityTypeId() == EntityType.ITEM && SeedCracker.expectedItems>0) { + + long rand_val = (long) ((Math.atan2(packet.getVelocityz(), packet.getVelocityX()) + 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(SeedCracker.expectedItems==0&&SeedCracker.cracking)//if its the last item + { + SeedCracker.attemptCrack(); + } + /* + else + { + long rand_val = (long) ((Math.atan2(this.getVelocityz(), this.getVelocityX()) + Math.PI) / (Math.PI * 2) * ((float) (1 << 24))); + long top_bits = rand_val; + short value = (short) ((top_bits >> (24 - 4)) ^ 0x8L); + System.out.println("Entity item spawn: Top 4 bits of direction: "+padLeftZeros(Long.toBinaryString(value), 4)); + }*/ + } +} diff --git a/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java b/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java index 5075a6695..351360e44 100644 --- a/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java +++ b/src/main/java/net/earthcomputer/clientcommands/ClientCommands.java @@ -30,8 +30,10 @@ public static void registerCommands(CommandDispatcher dispa WikiCommand.register(dispatcher); CEnchantCommand.register(dispatcher); + CrackRNGCommand.register(dispatcher); + if (MinecraftClient.getInstance().isIntegratedServerRunning()) { - CrackPlayerRNGCommand.register(dispatcher); + CheatCrackRNGCommand.register(dispatcher); } } } diff --git a/src/main/java/net/earthcomputer/clientcommands/command/CrackPlayerRNGCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/CheatCrackRNGCommand.java similarity index 75% rename from src/main/java/net/earthcomputer/clientcommands/command/CrackPlayerRNGCommand.java rename to src/main/java/net/earthcomputer/clientcommands/command/CheatCrackRNGCommand.java index fa064bb7f..4c978463f 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/CrackPlayerRNGCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/CheatCrackRNGCommand.java @@ -8,18 +8,18 @@ import static net.earthcomputer.clientcommands.command.ClientCommandManager.*; import static net.minecraft.server.command.CommandManager.*; -public class CrackPlayerRNGCommand { +public class CheatCrackRNGCommand { public static void register(CommandDispatcher dispatcher) { - addClientSideCommand("ccrackplayerrng"); + addClientSideCommand("ccheatcrackrng"); - dispatcher.register(literal("ccrackplayerrng") + dispatcher.register(literal("ccheatcrackrng") .executes(ctx -> crackPlayerRNG(ctx.getSource()))); } private static int crackPlayerRNG(ServerCommandSource source) { long seed = EnchantmentCracker.singlePlayerCrackRNG(); - sendFeedback(new TranslatableText("commands.ccrackplayerrng.success", Long.toHexString(seed))); + sendFeedback(new TranslatableText("commands.ccrackrng.success", Long.toHexString(seed))); return (int) seed; } diff --git a/src/main/java/net/earthcomputer/clientcommands/command/CrackRNGCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/CrackRNGCommand.java new file mode 100644 index 000000000..5a131a011 --- /dev/null +++ b/src/main/java/net/earthcomputer/clientcommands/command/CrackRNGCommand.java @@ -0,0 +1,34 @@ +package net.earthcomputer.clientcommands.command; + +import com.mojang.brigadier.CommandDispatcher; +import net.cortex.clientAddon.cracker.SeedCracker; +import net.earthcomputer.clientcommands.TempRules; +import net.earthcomputer.clientcommands.features.EnchantmentCracker; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.TranslatableText; + +import static net.earthcomputer.clientcommands.command.ClientCommandManager.addClientSideCommand; +import static net.earthcomputer.clientcommands.command.ClientCommandManager.sendFeedback; +import static net.earthcomputer.clientcommands.features.EnchantmentCracker.EnumCrackState.CRACKED_PLAYER_SEED; +import static net.earthcomputer.clientcommands.features.EnchantmentCracker.MULTIPLIER; +import static net.minecraft.server.command.CommandManager.literal; + +public class CrackRNGCommand { + + public static void register(CommandDispatcher dispatcher) { + addClientSideCommand("ccrackrng"); + + dispatcher.register(literal("ccrackrng") + .executes(ctx -> crackPlayerRNG(ctx.getSource()))); + } + + private static int crackPlayerRNG(ServerCommandSource source) { + SeedCracker.crack(seed -> { + sendFeedback(new TranslatableText("commands.ccrackrng.success", Long.toHexString(seed))); + EnchantmentCracker.playerRand.setSeed(seed ^ MULTIPLIER); + TempRules.enchCrackState=CRACKED_PLAYER_SEED; + }); + return 0; + } + +} diff --git a/src/main/java/net/earthcomputer/clientcommands/features/EnchantmentCracker.java b/src/main/java/net/earthcomputer/clientcommands/features/EnchantmentCracker.java index 080940655..477e9a98e 100644 --- a/src/main/java/net/earthcomputer/clientcommands/features/EnchantmentCracker.java +++ b/src/main/java/net/earthcomputer/clientcommands/features/EnchantmentCracker.java @@ -94,7 +94,7 @@ public class EnchantmentCracker { * we want and determine n. */ - private static final Logger LOGGER = LogManager.getLogger("EnchantmentCracker"); + public static final Logger LOGGER = LogManager.getLogger("EnchantmentCracker"); // RNG CHECK /* @@ -287,14 +287,14 @@ public static void drawEnchantmentGUIOverlay() { * This section is in charge of the logic of the cracking */ - private static final long MULTIPLIER = 0x5deece66dL; - private static final long ADDEND = 0xbL; - private static final long MASK = (1L << 48) - 1; + public static final long MULTIPLIER = 0x5deece66dL; + public static final long ADDEND = 0xbL; + public static final long MASK = (1L << 48) - 1; private static Set possibleXPSeeds = new HashSet<>(1 << 20); private static boolean onFirstXPSeed = true; private static Set possiblePlayerRandSeeds = new HashSet<>(1 << 16); - private static Random playerRand = new Random(); + public static Random playerRand = new Random(); private static boolean doneEnchantment = false; public static BlockPos enchantingTablePos = null; @@ -558,13 +558,8 @@ public void body() { @Override public void onCompleted() { - Slot matchingSlot = player.container.slotList.stream() - .filter(Slot::hasStack).findAny().orElse(null); - assert matchingSlot != null; - expectedThrows++; - for (int i = 0; i < 4; i++) playerRand.nextInt(); - - MinecraftClient.getInstance().interactionManager.method_2906(player.container.syncId, matchingSlot.id, 0, SlotActionType.THROW, player); + EnchantManipulationStatus status = throwItem(); + assert status == EnchantManipulationStatus.OK; scheduleDelay(); } @@ -615,12 +610,11 @@ public static EnchantManipulationStatus throwItemsUntil(Predicate condit } */ - /* public static EnchantManipulationStatus throwItemsUntil(Predicate condition, int max) { if (TempRules.enchCrackState != EnumCrackState.CRACKED) return EnchantManipulationStatus.NOT_CRACKED; - long seed = ReflectionHelper.getPrivateValue(Random.class, playerRand, "seed").get(); + long seed = getSeed(playerRand); Random rand = new Random(seed ^ MULTIPLIER); int itemsNeeded = 0; @@ -632,28 +626,37 @@ public static EnchantManipulationStatus throwItemsUntil(Predicate condit if (itemsNeeded > max) return EnchantManipulationStatus.IMPOSSIBLE; - EntityPlayerSP player = Minecraft.getMinecraft().player; - for (int i = 0; i < itemsNeeded; i++) { - EnchantManipulationStatus status = manipulateEnchantmentsSanityCheck(player); + EnchantManipulationStatus status = throwItem(); if (status != EnchantManipulationStatus.OK) return status; - Slot matchingSlot = player.inventoryContainer.inventorySlots.stream() - .filter(Slot::getHasStack).findAny().orElse(null); - if (matchingSlot == null) { - return EnchantManipulationStatus.EMPTY_INVENTORY; - } + } + + return EnchantManipulationStatus.OK; + } + + public static EnchantManipulationStatus throwItem() { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + + EnchantManipulationStatus status = manipulateEnchantmentsSanityCheck(player); + if (status != EnchantManipulationStatus.OK && status != EnchantManipulationStatus.NOT_CRACKED) + return status; + Slot matchingSlot = player.container.slotList.stream() + .filter(Slot::hasStack).findAny().orElse(null); + if (matchingSlot == null) { + return EnchantManipulationStatus.EMPTY_INVENTORY; + } + if (status != EnchantManipulationStatus.NOT_CRACKED) { expectedThrows++; for (int j = 0; j < 4; j++) { playerRand.nextInt(); } - Minecraft.getMinecraft().playerController.windowClick(player.inventoryContainer.windowId, - matchingSlot.slotNumber, 0, ClickType.THROW, player); } + MinecraftClient.getInstance().interactionManager.method_2906(player.container.syncId, + matchingSlot.id, 0, SlotActionType.THROW, player); - return EnchantManipulationStatus.OK; + return status; } - */ public static long singlePlayerCrackRNG() { ServerPlayerEntity serverPlayer = MinecraftClient.getInstance().getServer().getPlayerManager().getPlayer(MinecraftClient.getInstance().player.getUuid()); @@ -763,7 +766,7 @@ public static List getEnchantmentsInTable(int slot) { } RANDOM_SEED.setAccessible(true); } - private static long getSeed(Random rand) { + public static long getSeed(Random rand) { try { return ((AtomicLong) RANDOM_SEED.get(rand)).get(); } catch (ReflectiveOperationException e) { @@ -787,4 +790,4 @@ public String asString() { } } -} \ No newline at end of file +} diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/net/earthcomputer/clientcommands/mixin/MixinClientPlayNetworkHandler.java index 40400bd30..e0ab0f7eb 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/MixinClientPlayNetworkHandler.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/MixinClientPlayNetworkHandler.java @@ -1,9 +1,11 @@ package net.earthcomputer.clientcommands.mixin; import com.mojang.brigadier.CommandDispatcher; +import net.cortex.clientAddon.cracker.SeedCracker; import net.earthcomputer.clientcommands.ClientCommands; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.packet.CommandTreeS2CPacket; +import net.minecraft.client.network.packet.EntitySpawnS2CPacket; import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import org.spongepowered.asm.mixin.Mixin; @@ -24,4 +26,9 @@ public void onOnCommandTree(CommandTreeS2CPacket packet, CallbackInfo ci) { ClientCommands.registerCommands((CommandDispatcher) (Object) commandDispatcher); } + @Inject(method = "onEntitySpawn", at = @At("RETURN")) + public void onOnEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo ci) { + SeedCracker.onEntityCreation(packet); + } + } diff --git a/src/main/resources/assets/clientcommands/lang/en_us.json b/src/main/resources/assets/clientcommands/lang/en_us.json index d681f313f..57a1a7210 100644 --- a/src/main/resources/assets/clientcommands/lang/en_us.json +++ b/src/main/resources/assets/clientcommands/lang/en_us.json @@ -4,7 +4,7 @@ "commands.ccalc.expected": "Expected %s", "commands.ccalc.invalidArgumentCount": "Function \"%s\" cannot take %d arguments", - "commands.ccrackplayerrng.success": "Player RNG cracked: %d", + "commands.ccrackrng.success": "Player RNG cracked: %d", "commands.cenchant.expectedWithWithout": "Expected \"with\"/\"without\"", "commands.cenchant.incompatible": "Incompatible enchantments", @@ -93,6 +93,8 @@ "enchCrack.addInfo": "Add Info", - "enchCrack.toolBreakWarning": "Warning: tool has %d durability left" + "enchCrack.toolBreakWarning": "Warning: tool has %d durability left", + + "itemCrack.notEnoughItems": "Unable to use RNG SeedCracker: Not Enough Items in Player Hand" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c162f62bd..d50b92b0b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -11,6 +11,6 @@ "fabric": "*" }, "mixins": { - "client": "mixins.clientcommands.json" + "client": ["mixins.clientcommands.json"] } }