|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using PKHeX.Core; |
| 5 | +using System.Windows.Forms; |
| 6 | +namespace WangPlugin |
| 7 | +{ |
| 8 | + internal class RecoverLower16BitsEuclid16 |
| 9 | + { |
| 10 | + public static uint Mult = 0x000343FD; |
| 11 | + public static uint Add = 0x00269EC3; |
| 12 | + public static uint rMult = 0xB9B33155; |
| 13 | + public static uint rAdd = 0xA170F641; |
| 14 | + public static long t0 = Add - 0xFFFF; |
| 15 | + public static long t1 = 0xFFFF * ((long)Mult + 1); |
| 16 | + public static uint seed = Util.Rand32(); |
| 17 | + |
| 18 | + internal static IEnumerable<uint> GetSeed(uint pid) |
| 19 | + { |
| 20 | + List<uint> list = new List<uint>(); |
| 21 | + const int bitshift = 32; |
| 22 | + const long inc = 1L << bitshift; |
| 23 | + uint num = (pid >> 16) << 16; |
| 24 | + uint num2 = (pid & 0xFFFF) << 16; |
| 25 | + long num3 = num2 - (Mult * num) - t0; |
| 26 | + long num4 = 0u; |
| 27 | + long kmax = (((t1 - num3) >> bitshift) << bitshift) + num3; |
| 28 | + for ( num4 = num3; num4 <= kmax; num4 += inc) |
| 29 | + { |
| 30 | + // compute modulo in steps for reuse in yielded value (x % Mult) |
| 31 | + long fix = num4 / Mult; |
| 32 | + long remainder = num4 - (Mult * fix); |
| 33 | + if (remainder >> 16 == 0) |
| 34 | + { |
| 35 | + uint num5 = num | (uint)fix; |
| 36 | + // if ((RNG.LCRNG.Advance(num5, 4) << 16) == num) |
| 37 | + { |
| 38 | + num5=(num5 * rMult) + rAdd; |
| 39 | + // MessageBox.Show("ok"); |
| 40 | + list.Add(num5); |
| 41 | + } |
| 42 | + } |
| 43 | + //yield return Prev(first | (uint)fix); |
| 44 | + } |
| 45 | + |
| 46 | + return list; |
| 47 | + } |
| 48 | + public static List<uint[]> CalcPIDIVsByXDRNG(uint pid) |
| 49 | + { |
| 50 | + |
| 51 | + IEnumerable<uint> enumerable = GetSeed(pid); |
| 52 | + |
| 53 | + if (enumerable.Count() == 0) |
| 54 | + { |
| 55 | + |
| 56 | + return null; |
| 57 | + } |
| 58 | + List<uint[]> list = new List<uint[]>(); |
| 59 | + using (IEnumerator<uint> enumerator = enumerable.GetEnumerator()) |
| 60 | + { |
| 61 | + while (enumerator.MoveNext()) |
| 62 | + { |
| 63 | + |
| 64 | + uint num = (seed = enumerator.Current); |
| 65 | + var B = RNG.XDRNG.Prev(seed); |
| 66 | + var A = RNG.XDRNG.Prev(B); |
| 67 | + |
| 68 | + var hi = A >> 16; |
| 69 | + var lo = B >> 16; ; |
| 70 | + list.Add(GetIVs(hi, lo)); |
| 71 | + // MessageBox.Show($"{seed}"); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + return list; |
| 76 | + } |
| 77 | + public static uint[] GetIVs(uint v1, uint v2) |
| 78 | + { |
| 79 | + return new uint[6] |
| 80 | + { |
| 81 | + (v1 & 0x1Fu), |
| 82 | + (v1 >> 5) & 0x1Fu, |
| 83 | + (v1 >> 10) & 0x1Fu, |
| 84 | + (v2 & 0x1Fu), |
| 85 | + (v2 >> 5) & 0x1Fu, |
| 86 | + (v2 >> 10) & 0x1Fu, |
| 87 | + }; |
| 88 | + } |
| 89 | + public static uint[] GetIVs(PKM pkm, List<uint[]> ivsList) |
| 90 | + { |
| 91 | + uint[] result = new uint[6]; |
| 92 | + if (ivsList.Count != 0) |
| 93 | + { |
| 94 | + result = ivsList.ElementAt(0); |
| 95 | + } |
| 96 | + return result; |
| 97 | + } |
| 98 | + |
| 99 | + public static void SetIVsFromList(PKM pkm, uint[] ivs) |
| 100 | + { |
| 101 | + int[] iVs = pkm.IVs; |
| 102 | + for (int i = 0; i < ivs.Length; i++) |
| 103 | + { |
| 104 | + iVs[i] = (int)ivs[i]; |
| 105 | + } |
| 106 | + pkm.IVs = iVs; |
| 107 | + } |
| 108 | + public static void advance(uint advances) |
| 109 | + { |
| 110 | + for (uint num = 0u; num < advances; num++) |
| 111 | + { |
| 112 | + next(); |
| 113 | + } |
| 114 | + } |
| 115 | + public static uint next() |
| 116 | + { |
| 117 | + return seed = seed * Mult + Add; |
| 118 | + } |
| 119 | + public static uint prev() |
| 120 | + { |
| 121 | + return seed = (seed * rMult) + rAdd; |
| 122 | + } |
| 123 | + public static ushort nextUShort() |
| 124 | + { |
| 125 | + return (ushort)(next() >> 16); |
| 126 | + } |
| 127 | + public static ushort prevUShort() |
| 128 | + { |
| 129 | + return (ushort)(prev() >> 16); |
| 130 | + } |
| 131 | + //太他妈的复杂我放弃!!!!!!!1 |
| 132 | + |
| 133 | + } |
| 134 | +} |
0 commit comments