-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjitfunctions.py
293 lines (256 loc) · 10.1 KB
/
jitfunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import numpy as np
import numba
from jitpools import isaac_items
@numba.njit
def next_xorshift(
seed: numba.uint32, shift1: numba.uint32, shift2: numba.uint32, shift3: numba.uint32
):
seed ^= numba.uint32(seed >> shift1)
# print(seed)
seed ^= numba.uint32(seed << shift2)
# print(seed)
seed ^= numba.uint32(seed >> shift3)
return numba.uint32(seed)
@numba.njit
def previous_xorshift(
seed: numba.uint32, shift1: numba.uint32, shift2: numba.uint32, shift3: numba.uint32
):
seed = reverse_xor_rshift(seed, shift3)
# print(seed)
seed = reverse_xor_lshift(seed, shift2)
# print(seed)
seed = reverse_xor_rshift(seed, shift1)
return numba.uint32(seed)
@numba.njit
def reverse_xor_lshift(seed: numba.uint32, shift: numba.uint32):
i: numba.uint32 = shift
while i < 32:
seed ^= numba.uint32(seed << i)
i *= 2
return numba.uint32(seed)
@numba.njit
def reverse_xor_rshift(seed: numba.uint32, shift: numba.uint32):
seed = reverse_seed(seed)
seed = reverse_xor_lshift(seed, shift)
seed = reverse_seed(seed)
return numba.uint32(seed)
@numba.njit
def reverse_seed(seed: numba.uint32):
bin_str: np.ndarray = np.zeros(32, dtype=numba.uint32)
matrix: np.ndarray = 1 << np.arange(bin_str.size, dtype=numba.uint32)
matrix = np.flip(matrix)
i: int = 0
num: numba.uint32 = 0
while i < 32:
num = num + (seed % 2) * matrix[i]
seed = seed // 2
i += 1
if seed < 1:
break
return numba.uint32(num)
@numba.njit
def jit_reverser(
active: int = 0,
passive: int = 0,
card: int = 0,
trinket: int = 0,
pill_effect: int = 0,
start_seed: int = 0,
end_seed: int = 0xFFFFFFFF,
):
collectibles_number = 0x2DA
trinket_number = 0xBE
card_number = 0x16
potential_drop_seed: numba.uint32 = 0
potential_hold_seed: numba.uint32 = 0
potential_trinket_seed: numba.uint32 = 0
potential_nothing_seed: numba.uint32 = 0
start_seed: numba.uint32 = start_seed
current_seed: numba.uint32 = start_seed
end_seed: numba.uint32 = end_seed
active = active
passive = passive
card = card
pill_effect = pill_effect
trinket = trinket
trinket_found: numba.boolean = False
passive_found: numba.boolean = False
active_found: numba.boolean = False
hold_found: numba.boolean = False
hold_type: numba.uint32 = None
hold_seed: numba.uint32 = None
trinket_seed: numba.uint32 = None
nothing_seed: numba.uint32 = None
drop_seed: numba.uint32 = 0
first_item_type: numba.uint32 = -1
if active < passive:
min_item = active
max_item = passive
else:
min_item = passive
max_item = active
found_seed = []
while current_seed < end_seed:
# print('Trying seed: ' + str(hex(self.start_seed)))
item_id = current_seed % collectibles_number + 1
if item_id == min_item or item_id == max_item:
if isaac_items[item_id] == 1:
first_item_type = 1
active_found = True
else:
first_item_type = 0
passive_found = True
# print('First item found: ' + str(item_id) + ' (' + str(first_item_type) + ')')
drop_seed = current_seed
for i in range(0, 99):
drop_seed = previous_xorshift(drop_seed, 0x1, 0x5, 0x13)
item_id = drop_seed % collectibles_number + 1
if isaac_items[item_id] > -1:
if isaac_items[item_id] == first_item_type:
# print('Another ' + str(first_item_type) + ' was found before the second one. Break.')
break
else:
if item_id == min_item or item_id == max_item:
# print('Second item found: ' + str(item_id))
if isaac_items[item_id] == 1:
active_found = True
else:
passive_found = True
break
if passive_found and active_found:
check_point_1 = previous_xorshift(drop_seed, 0x1, 0x5, 0x13)
check_point_2 = previous_xorshift(check_point_1, 0x1, 0x5, 0x13)
check_point_3 = previous_xorshift(check_point_2, 0x1, 0x5, 0x13)
check_point_4 = previous_xorshift(check_point_3, 0x1, 0x5, 0x13)
check_point_5 = previous_xorshift(check_point_4, 0x1, 0x5, 0x13)
# Check if with trinket
if not check_point_1 % 3 and trinket != 0:
# print('Trinket possible')
potential_trinket_seed = check_point_1
if get_trinket(potential_trinket_seed, trinket, trinket_number):
trinket_seed = goto_start_seed(check_point_2)
# self.print_stats(self.trinket_seed)
found_seed.append(trinket_seed)
# break
else:
# print('This try will not yield the right trinket. Next.')
pass
elif trinket != 0:
# print('This try will not yield any trinket. Next')
pass
# Check if with card or pill
if card != 0 or pill_effect != 0:
if (
check_point_2 & 1
and not check_point_3 & 1
and check_point_4 % 3
):
# print('Pill possible')
if pill_effect != 0:
if get_pill(check_point_1, pill_effect):
hold_seed = goto_start_seed(check_point_5)
# self.print_stats(self.hold_seed)
found_seed.append(hold_seed)
# break
else:
# print('This try will not yield the right pill. Next.')
pass
else:
# print('This try will not yield a card. Next.')
pass
elif (
not check_point_2 & 1
and not check_point_3 & 1
and check_point_4 % 3
):
# print('Card possible')
if card != 0:
if get_card(check_point_1, card, card_number):
hold_seed = goto_start_seed(check_point_5)
# self.print_stats(self.hold_seed)
found_seed.append(hold_seed)
# break
else:
# print('This try will not yield the right card. Next')
pass
else:
# print('This try will not yield a pill. Next.')
pass
# Check if it will yield nothing
if check_point_1 & 1 and check_point_2 % 3:
# print('Theoretically nothing')
if (
card == 0
and pill_effect == 0
and trinket == 0
):
nothing_seed = goto_start_seed(check_point_3)
# self.print_stats(self.nothing_seed)
found_seed.append(nothing_seed)
# break
else:
# print('This try will yield a pill, card or trinket. Next')
pass
# print('The items are not found according to the asked requirement. Resetting.')
# break
passive_found = False
active_found = False
potential_drop_seed = 0
current_seed += calculate_next_step(current_seed, collectibles_number, min_item, max_item)
return found_seed
@numba.njit
def calculate_next_step(current_seed, collectibles_number, min_item, max_item):
modulo = current_seed % collectibles_number
if modulo + 1 < min_item:
return min_item - modulo - 1
elif min_item <= modulo + 1 < max_item:
return max_item - modulo - 1
else:
return collectibles_number - modulo + min_item - 1
@numba.njit
def goto_start_seed(seed):
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
for var in range(0, 0xF):
seed = previous_xorshift(seed, 0x3, 0x17, 0x19)
return seed
@numba.njit
def get_trinket(seed, trinket_id, trinket_number):
seed = previous_xorshift(seed, 0x1, 0x5, 0x13)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = previous_xorshift(seed, 0x1, 0xB, 0x10)
seed = next_xorshift(seed, 0x3, 0x17, 0x19)
seed = next_xorshift(seed, 0x3, 0x17, 0x19)
seed = next_xorshift(seed, 0x1, 0x9, 0x1D)
seed = next_xorshift(seed, 0x1, 0x5, 0x13)
if seed % trinket_number == trinket_id or trinket_id == -1:
return True
else:
return False
@numba.njit
def get_card(seed, card_id, card_number):
seed = next_xorshift(seed, 0x3, 0x3, 0x1D)
if seed % 0x19:
seed = next_xorshift(seed, 0x3, 0x3, 0x1D)
tmp_card = seed % 0x16 + 1
seed = next_xorshift(seed, 0x3, 0x3, 0x1D)
if not seed % 0x7:
tmp_card += 55
else:
tmp_card = -1
if card_id == tmp_card or card_id == -1:
return True
else:
return False
@numba.njit
def get_pill(seed, pill_effect_id):
return True
if __name__ == "__main__":
aa = jit_reverser(active=352, passive=116, trinket=3, start_seed=0x9555ea3, end_seed=0xFFFFFFFF)
print(aa)