-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat_randomizer_gui.py
More file actions
1828 lines (1607 loc) · 69.9 KB
/
stat_randomizer_gui.py
File metadata and controls
1828 lines (1607 loc) · 69.9 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
Elden Ring Starting Class Stat Randomizer - GUI Version
With Grace Unlock feature (requires game running)
"""
import os
import random
import shutil
import subprocess
import sys
import re
import json
import tkinter as tk
from tkinter import ttk, filedialog, messagebox, scrolledtext
from pathlib import Path
import threading
import struct
from typing import Optional, Callable
# Try to import pymem, fall back to manual implementation
PYMEM_AVAILABLE = False
try:
import pymem
import pymem.process
import pymem.pattern
PYMEM_AVAILABLE = True
except ImportError:
print("pymem not installed. Run: pip install pymem")
pass
# ============================================================
# Memory Manager using pymem (preferred) or ctypes fallback
# ============================================================
class MemoryManager:
"""Manages reading/writing to game process memory using pymem."""
# Known Elden Ring process names
ELDEN_RING_PROCESSES = [
"eldenring.exe",
"start_protected_game.exe",
]
def __init__(self):
self.pm = None # pymem instance
self.module_base = 0
self.module_size = 0
self.process_id = 0
self.process_name = ""
self.last_error = ""
@property
def is_attached(self):
return self.pm is not None
def attach(self, process_name: str = None) -> bool:
"""Attach to Elden Ring process using pymem."""
if not PYMEM_AVAILABLE:
self.last_error = "pymem not installed. Run: pip install pymem"
return False
# Detach first if already attached
if self.is_attached:
self.detach()
# Build list of process names to try
if process_name:
process_names = [process_name] + self.ELDEN_RING_PROCESSES
else:
process_names = self.ELDEN_RING_PROCESSES
# Try each process name
for name in process_names:
try:
self.pm = pymem.Pymem(name)
self.process_name = name
self.process_id = self.pm.process_id
# Get module info
module = pymem.process.module_from_name(self.pm.process_handle, name)
if module:
self.module_base = module.lpBaseOfDll
self.module_size = module.SizeOfImage
print(f"Attached to {name} (PID: {self.process_id})")
print(f"Module base: 0x{self.module_base:X}, size: {self.module_size} ({self.module_size / (1024*1024):.1f} MB)")
return True
else:
self.last_error = f"Could not get module info for {name}"
except pymem.exception.ProcessNotFound:
continue
except pymem.exception.CouldNotOpenProcess as e:
self.last_error = f"Could not open process (run as Administrator): {e}"
return False
except Exception as e:
self.last_error = f"Error attaching to {name}: {e}"
continue
self.last_error = f"Process not found. Tried: {', '.join(process_names)}"
return False
def detach(self) -> None:
"""Detach from the process."""
if self.pm:
try:
self.pm.close_process()
except Exception:
pass # Process may already be closed
finally:
self.pm = None
self.module_base = 0
self.module_size = 0
self.process_id = 0
self.process_name = ""
def read_bytes(self, address: int, size: int) -> bytes:
"""Read bytes from process memory."""
if not self.pm:
return b''
try:
return self.pm.read_bytes(address, size)
except Exception as e:
self.last_error = f"Read failed at 0x{address:X}: {e}"
return b''
def read_int64(self, address: int) -> int:
"""Read 64-bit integer from address."""
if not self.pm:
return 0
try:
return self.pm.read_longlong(address)
except Exception:
return 0
def read_int32(self, address: int) -> int:
"""Read 32-bit integer from address."""
if not self.pm:
return 0
try:
return self.pm.read_int(address)
except Exception:
return 0
def read_byte(self, address: int) -> int:
"""Read single byte from address."""
if not self.pm:
return 0
try:
return self.pm.read_uchar(address)
except Exception:
return 0
def write_bytes(self, address: int, data: bytes) -> bool:
"""Write bytes to process memory."""
if not self.pm:
return False
try:
self.pm.write_bytes(address, data, len(data))
return True
except Exception as e:
self.last_error = f"Write failed at 0x{address:X}: {e}"
return False
def write_byte(self, address: int, value: int) -> bool:
"""Write single byte to address."""
if not self.pm:
return False
try:
self.pm.write_uchar(address, value & 0xFF)
return True
except Exception as e:
self.last_error = f"Write failed at 0x{address:X}: {e}"
return False
def scan_aob(self, pattern: str, rel_offset: int, additional: int) -> int:
"""Scan for AOB pattern and resolve pointer using pymem."""
if not self.pm or self.module_size == 0:
self.last_error = "Cannot scan: not attached or module size is 0"
return 0
try:
# Convert pattern to pymem format (replace ?? with ..)
pymem_pattern = pattern.replace('??', '..')
# Use pymem's pattern scan
result = pymem.pattern.pattern_scan_module(
self.pm.process_handle,
pymem.process.module_from_name(self.pm.process_handle, self.process_name),
pymem_pattern
)
if result:
# Read relative offset and calculate absolute address
relative_offset = self.pm.read_int(result + rel_offset)
absolute_address = result + additional + relative_offset
print(f"Pattern found at 0x{result:X}, resolved to 0x{absolute_address:X}")
return absolute_address
else:
self.last_error = "Pattern not found in module memory"
return 0
except Exception as e:
self.last_error = f"Pattern scan failed: {e}"
# Fallback to manual scan
return self._manual_scan_aob(pattern, rel_offset, additional)
def _manual_scan_aob(self, pattern: str, rel_offset: int, additional: int) -> int:
"""Manual AOB scan fallback with chunked reading for performance."""
try:
# Parse pattern
parts = pattern.split(' ')
pattern_bytes: list[int] = []
mask: list[bool] = []
for part in parts:
if part == '??':
pattern_bytes.append(0)
mask.append(False)
else:
pattern_bytes.append(int(part, 16))
mask.append(True)
pattern_len = len(pattern_bytes)
# Chunked scanning - read 4MB at a time with overlap for pattern matching
CHUNK_SIZE = 4 * 1024 * 1024 # 4MB chunks
overlap = pattern_len - 1 # Overlap to catch patterns at chunk boundaries
offset = 0
while offset < self.module_size:
# Calculate chunk size (may be smaller for last chunk)
remaining = self.module_size - offset
current_chunk_size = min(CHUNK_SIZE, remaining)
# Read chunk
chunk_bytes = self.read_bytes(self.module_base + offset, current_chunk_size)
if not chunk_bytes or len(chunk_bytes) < pattern_len:
offset += current_chunk_size - overlap
continue
# Search for pattern in this chunk
search_end = len(chunk_bytes) - pattern_len + 1
for i in range(search_end):
found = True
for j in range(pattern_len):
if mask[j] and chunk_bytes[i + j] != pattern_bytes[j]:
found = False
break
if found:
pattern_address = self.module_base + offset + i
relative_offset_bytes = chunk_bytes[i + rel_offset:i + rel_offset + 4]
relative_offset_val = struct.unpack('<i', relative_offset_bytes)[0]
absolute_address = pattern_address + additional + relative_offset_val
print(f"[Manual/Chunked] Pattern found at 0x{pattern_address:X}, resolved to 0x{absolute_address:X}")
return absolute_address
# Move to next chunk with overlap
offset += current_chunk_size - overlap
self.last_error = "Pattern not found in module memory"
return 0
except Exception as e:
self.last_error = f"Manual scan failed: {e}"
return 0
# ============================================================
# Elden Ring Specifics
# ============================================================
# AOB Patterns for finding pointers (from Hexinton CE table)
EVENT_FLAG_MAN_AOB = "48 8B 3D ?? ?? ?? ?? 48 85 FF ?? ?? 32 C0 E9"
# Grace data organized by region: region -> {name: (offset, bit)}
# Offsets from Hexinton CE table - pointer chain: [[EventFlagMan]+0x28]+offset
GRACES_BY_REGION = {
# ============ MAIN GAME ============
"Roundtable Hold": {
"Table of Lost Grace": (0xA58, 1),
},
"Stranded Graveyard": {
"Cave of Knowledge": (0xAA5, 7),
"Stranded Graveyard": (0xAA5, 6),
},
"Limgrave": {
"The First Step": (0xCBE, 2),
"Church of Elleh": (0xCBE, 3),
"Artist's Shack (Limgrave)": (0xCBE, 0),
"Gatefront": (0xCBF, 0),
"Agheel Lake South": (0xCBF, 5),
"Agheel Lake North": (0xCBF, 3),
"Church of Dragon Communion": (0xCBF, 1),
"Fort Haight West": (0xCBF, 6),
"Third Church of Marika": (0xCBF, 7),
"Seaside Ruins": (0xCC0, 6),
"Mistwood Outskirts": (0xCC0, 5),
"Murkwater Coast": (0xCC0, 3),
"Summonwater Village Outskirts": (0xCC0, 0),
"Waypoint Ruins Cellar": (0xCC1, 7),
"Stormfoot Catacombs": (0xB3B, 5),
"Murkwater Catacombs": (0xB3B, 3),
"Groveside Cave": (0xB47, 0),
"Coastal Cave": (0xB49, 4),
"Murkwater Cave": (0xB47, 3),
"Highroad Cave": (0xB49, 2),
"Limgrave Tunnels": (0xB54, 6),
},
"Stormhill": {
"Stormhill Shack": (0xCBE, 1),
"Castleward Tunnel": (0xA41, 5),
"Margit, the Fell Omen": (0xA41, 6),
"Warmaster's Shack": (0xCC0, 1),
"Saintsbridge": (0xCC0, 2),
"Deathtouched Catacombs": (0xB3C, 4),
"Limgrave Tower Bridge": (0xB6E, 5),
"Divine Tower of Limgrave": (0xB6E, 3),
},
"Stormveil Castle": {
"Stormveil Main Gate": (0xA42, 7),
"Gateside Chamber": (0xA41, 4),
"Stormveil Cliffside": (0xA41, 3),
"Rampart Tower": (0xA41, 2),
"Liftside Chamber": (0xA41, 1),
"Secluded Cell": (0xA41, 0),
"Godrick the Grafted": (0xA41, 7),
},
"Weeping Peninsula": {
"Church of Pilgrimage": (0xCC4, 1),
"Castle Morne Rampart": (0xCC4, 0),
"Tombsward": (0xCC5, 7),
"South of the Lookout Tower": (0xCC5, 6),
"Ailing Village Outskirts": (0xCC5, 5),
"Beside the Crater-Pocked Glade": (0xCC5, 4),
"Isolated Merchant's Shack (Limgrave)": (0xCC5, 3),
"Fourth Church of Marika": (0xCC6, 5),
"Bridge of Sacrifice": (0xCC5, 2),
"Castle Morne Lift": (0xCC5, 1),
"Behind the Castle": (0xCC5, 0),
"Beside the Rampart Gaol": (0xCC6, 7),
"Morne Moangrave": (0xCC6, 6),
"Impaler's Catacombs": (0xB3B, 6),
"Tombsward Catacombs": (0xB3B, 7),
"Earthbore Cave": (0xB47, 2),
"Tombsward Cave": (0xB47, 1),
"Morne Tunnel": (0xB54, 7),
},
"Liurnia of the Lakes": {
"Lake-Facing Cliffs": (0xCCB, 7),
"Laskyar Ruins": (0xCCB, 5),
"Liurnia Lake Shore": (0xCCB, 6),
"Academy Gate Town": (0xCCB, 3),
"Artist's Shack (Liurnia)": (0xCCD, 6),
"Eastern Liurnia Lake Shore": (0xCCD, 0),
"Gate Town Bridge": (0xCCD, 1),
"Liurnia Highway North": (0xCCD, 2),
"Liurnia Highway South": (0xCD0, 3),
"Main Academy Gate": (0xCCB, 1),
"Scenic Isle": (0xCCB, 4),
"South Raya Lucaria Gate": (0xCCB, 2),
"Ruined Labyrinth": (0xCCE, 6),
"Boilprawn Shack": (0xCCD, 7),
"Church of Vows": (0xCCE, 7),
"Converted Tower": (0xCCF, 2),
"Eastern Tableland": (0xCCF, 5),
"Fallen Ruins of the Lake": (0xCCF, 3),
"Folly on the Lake": (0xCCD, 4),
"Jarburg": (0xCD0, 2),
"Mausoleum Compound": (0xCCE, 5),
"Ranni's Chamber": (0xCD0, 0),
"Revenger's Shack": (0xCCD, 5),
"Slumbering Wolf's Shack": (0xCCC, 0),
"Village of the Albinaurics": (0xCCD, 3),
"Crystalline Woods": (0xCD0, 4),
"East Gate Bridge Trestle": (0xCD0, 5),
"Foot of the Four Belfries": (0xCCC, 5),
"Gate Town North": (0xCCF, 6),
"Main Caria Manor Gate": (0xCCC, 1),
"Manor Lower Level": (0xCCE, 0),
"Manor Upper Level": (0xCCE, 1),
"Northern Liurnia Lake Shore": (0xCCC, 3),
"Road to the Manor": (0xCCC, 2),
"Royal Moongazing Grounds": (0xCCF, 7),
"Sorcerer's Isle": (0xCCC, 4),
"Temple Quarter": (0xCD0, 6),
"The Four Belfries": (0xCCE, 4),
"Academy Crystal Cave": (0xB48, 5),
"Behind Caria Manor": (0xCCF, 1),
"Black Knife Catacombs": (0xB3B, 2),
"Cliffbottom Catacombs": (0xB3B, 1),
"Lakeside Crystal Cave": (0xB48, 6),
"Liurnia Tower Bridge": (0xB6F, 2),
"Ranni's Rise": (0xCCE, 3),
"Ravine-Veiled Village": (0xCCE, 2),
"Raya Lucaria Crystal Tunnel": (0xB54, 5),
"Road's End Catacombs": (0xB3B, 4),
"Stillwater Cave": (0xB48, 7),
"Study Hall Entrance": (0xB6F, 3),
"The Ravine": (0xCCF, 4),
"Divine Tower of Liurnia": (0xB6F, 1),
},
"Bellum Highway": {
"Bellum Church": (0xCCC, 7),
"Church of Inhibition": (0xCD0, 7),
"East Raya Lucaria Gate": (0xCCB, 0),
"Frenzied Flame Village Outskirts": (0xCCF, 0),
"Grand Lift of Dectus": (0xCCC, 6),
},
"Ruin-Strewn Precipice": {
"Magma Wyrm": (0xBAB, 3),
"Ruin-Strewn Precipice": (0xBAB, 2),
"Ruin-Strewn Precipice Overlook": (0xBAB, 1),
},
"Moonlight Altar": {
"Altar South": (0xCD1, 3),
"Cathedral of Manus Celes": (0xCD1, 4),
"Moonlight Altar": (0xCD1, 5),
},
"Raya Lucaria Academy": {
"Church of the Cuckoo": (0xA73, 5),
"Debate Parlor": (0xA73, 6),
"Raya Lucaria Grand Library": (0xA73, 7),
"Schoolhouse Classroom": (0xA73, 4),
},
"Altus Plateau": {
"Abandoned Coffin": (0xCD7, 3),
"Altus Highway Junction": (0xCD7, 0),
"Altus Plateau": (0xCD7, 2),
"Bower of Bounty": (0xCD8, 5),
"Erdtree-Gazing Hill": (0xCD7, 1),
"Forest-Spanning Greatbridge": (0xCD8, 7),
"Rampartside Path": (0xCD8, 6),
"Road of Iniquity Side Path": (0xCD8, 4),
"Shaded Castle Inner Gate": (0xCDA, 6),
"Shaded Castle Ramparts": (0xCDA, 7),
"Windmill Heights": (0xCD9, 6),
"Windmill Village": (0xCD8, 3),
"Altus Tunnel": (0xB54, 2),
"Castellan's Hall": (0xCDA, 5),
"Old Altus Tunnel": (0xB54, 3),
"Perfumer's Grotto": (0xB49, 1),
"Sage's Cave": (0xB49, 0),
"Sainted Hero's Grave": (0xB3C, 7),
"Unsightly Catacombs": (0xB3C, 3),
},
"Mt. Gelmir": {
"Bridge of Iniquity": (0xCDD, 1),
"Craftsman's Shack": (0xCDE, 3),
"First Mt. Gelmir Campsite": (0xCDD, 0),
"Gelmir Hero's Grave": (0xB3C, 6),
"Ninth Mt. Gelmir Campsite": (0xCDE, 7),
"Primeval Sorcerer Azur": (0xCDE, 2),
"Road of Iniquity": (0xCDE, 6),
"Seethewater Cave": (0xB48, 4),
"Seethewater River": (0xCDE, 5),
"Seethewater Terminus": (0xCDE, 4),
"Volcano Cave": (0xB48, 2),
"Wyndham Catacombs": (0xB3B, 0),
},
"Leyndell Royal Capital (Pre-Ash)": {
"Auriza Side Tomb": (0xB3C, 2),
"Auriza Hero's Grave": (0xB3C, 5),
"Capital Rampart": (0xCD9, 5),
"Divine Tower of West Altus": (0xB70, 1),
"Divine Tower of West Altus: Gate": (0xB71, 7),
"Hermit Merchant's Shack": (0xCD8, 0),
"Minor Erdtree Church": (0xCD8, 1),
"Outer Wall Battleground": (0xCD9, 7),
"Outer Wall Phantom Tree": (0xCD8, 2),
"Sealed Tunnel": (0xB70, 0),
},
"Volcano Manor": {
"Abductor Virgin": (0xA8C, 1),
"Audience Pathway": (0xA8C, 2),
"Guest Hall": (0xA8C, 3),
"Prison Town Church": (0xA8C, 4),
"Rykard, Lord of Blasphemy": (0xA8C, 7),
"Subterranean Inquisition Chamber": (0xA8C, 0),
"Temple of Eiglay": (0xA8C, 6),
"Volcano Manor": (0xA8C, 5),
},
"Leyndell Royal Capital": {
"East Capital Rampart": (0xA4D, 1),
"Avenue Balcony": (0xA4E, 7),
"Lower Capital Church": (0xA4D, 0),
"West Capital Rampart": (0xA4E, 6),
"Fortified Manor, First Floor": (0xA4E, 3),
"Divine Bridge": (0xA4E, 2),
"Erdtree Sanctuary": (0xA4E, 6),
"Elden Throne": (0xA4D, 3),
"Queen's Bedchamber": (0xA4E, 4),
},
"Caelid": {
"Caelem Ruins": (0xCE4, 4),
"Caelid Highway South": (0xCE4, 2),
"Cathedral of Dragon Communion": (0xCE4, 3),
"Chair-Crypt of Sellia": (0xCE5, 0),
"Church of the Plague": (0xCE6, 5),
"Fort Gael North": (0xCE4, 5),
"Rotview Balcony": (0xCE4, 6),
"Sellia Backstreets": (0xCE5, 1),
"Sellia Under-Stair": (0xCE6, 7),
"Smoldering Church": (0xCE4, 7),
"Smoldering Wall": (0xCE5, 6),
"Southern Aeonia Swamp Bank": (0xCE5, 4),
"Abandoned Cave": (0xB4A, 7),
"Caelid Catacombs": (0xB3C, 0),
"Chamber Outside the Plaza": (0xCE6, 3),
"Deep Siofra Well": (0xCE5, 5),
"Gael Tunnel": (0xB54, 0),
"Gaol Cave": (0xB4A, 6),
"Impassable Greatbridge": (0xCE6, 6),
"Minor Erdtree Catacombs": (0xB3C, 1),
"Rear Gael Tunnel Entrance": (0xB5B, 6),
"Redmane Castle Plaza": (0xCE6, 4),
"Sellia Crystal Tunnel": (0xB55, 7),
"Starscourge Radahn": (0xCE6, 1),
"War-Dead Catacombs": (0xB3D, 7),
},
"Swamp of Aeonia": {
"Aeonia Swamp Shore": (0xCE4, 1),
"Astray from Caelid Highway North": (0xCE4, 0),
"Heart of Aeonia": (0xCE5, 3),
"Inner Aeonia": (0xCE5, 2),
},
"Greyoll's Dragonbarrow": {
"Bestial Sanctum": (0xCEA, 1),
"Divine Tower of Caelid: Basement": (0xB72, 7),
"Divine Tower of Caelid: Center": (0xB72, 6),
"Dragonbarrow Cave": (0xB48, 1),
"Dragonbarrow Fork": (0xCEA, 3),
"Dragonbarrow West": (0xCEA, 5),
"Farum Greatbridge": (0xCEB, 7),
"Fort Faroth": (0xCEA, 2),
"Isolated Divine Tower": (0xB74, 3),
"Isolated Merchant's Shack (Dragonbarrow)": (0xCEA, 4),
"Lenne's Rise": (0xCEA, 0),
"Sellia Hideaway": (0xB48, 0),
},
"Forbidden Lands": {
"Divine Tower of East Altus": (0xB73, 4),
"Divine Tower of East Altus: Gate": (0xB73, 5),
"Forbidden Lands": (0xCF0, 3),
"Grand Lift of Rold": (0xCF0, 1),
"Hidden Path to the Haligtree": (0xB3D, 3),
},
"Mountaintops of the Giants": {
"Ancient Snow Valley Ruins": (0xCF0, 0),
"Castle Sol Main Gate": (0xCF3, 5),
"Castle Sol Rooftop": (0xCF3, 3),
"Church of the Eclipse": (0xCF3, 4),
"First Church of Marika": (0xCF1, 6),
"Freezing Lake": (0xCF1, 7),
"Snow Valley Ruins Overlook": (0xCF3, 6),
"Spiritcaller's Cave": (0xB4A, 5),
"Whiteridge Road": (0xCF3, 7),
"Zamor Ruins": (0xCF0, 2),
},
"Flame Peak": {
"Church of Repose": (0xCF1, 4),
"Fire Giant": (0xCF1, 2),
"Foot of the Forge": (0xCF1, 3),
"Forge of the Giants": (0xCF1, 1),
"Giant's Gravepost": (0xCF1, 5),
"Giant's Mountaintop Catacombs": (0xB3D, 5),
"Giant-Conquering Hero's Grave": (0xB3D, 6),
},
"Consecrated Snowfield": {
"Apostate Derelict": (0xD03, 2),
"Cave of the Forlorn": (0xB49, 7),
"Consecrated Snowfield": (0xCF6, 1),
"Consecrated Snowfield Catacombs": (0xB3D, 4),
"Inner Consecrated Snowfield": (0xCF6, 0),
"Ordina, Liturgical Town": (0xD03, 3),
"Yelough Anix Tunnel": (0xB55, 4),
},
"Miquella's Haligtree": {
"Haligtree Canopy": (0xA80, 5),
"Haligtree Promenade": (0xA80, 6),
"Haligtree Town": (0xA80, 4),
"Haligtree Town Plaza": (0xA80, 3),
},
"Elphael, Brace of the Haligtree": {
"Drainage Channel": (0xA7F, 0),
"Elphael Inner Wall": (0xA7F, 1),
"Haligtree Roots": (0xA80, 7),
"Malenia, Goddess of Rot": (0xA7F, 3),
"Prayer Room": (0xA7F, 2),
},
"Crumbling Farum Azula": {
"Beside the Great Bridge": (0xA67, 1),
"Crumbling Beast Grave": (0xA66, 0),
"Crumbling Beast Grave Depths": (0xA67, 7),
"Dragon Temple": (0xA67, 5),
"Dragon Temple Altar": (0xA66, 1),
"Dragon Temple Lift": (0xA67, 3),
"Dragon Temple Rooftop": (0xA67, 2),
"Dragon Temple Transept": (0xA67, 4),
"Dragonlord Placidusax": (0xA66, 2),
"Maliketh, the Black Blade": (0xA66, 3),
"Tempest-Facing Balcony": (0xA67, 6),
},
"Ainsel River": {
"Ainsel River Downstream": (0xA5B, 2),
"Ainsel River Sluice Gate": (0xA5B, 3),
"Ainsel River Well Depths": (0xA5B, 4),
"Astel, Naturalborn of the Void": (0xA5F, 7),
"Dragonkin Soldier of Nokstella": (0xA5B, 5),
},
"Ainsel River Main": {
"Ainsel River Main": (0xA5B, 1),
"Nokstella, Eternal City": (0xA5B, 0),
"Nokstella Waterfall Basin": (0xA5C, 4),
},
"Lake of Rot": {
"Grand Cloister": (0xA5C, 5),
"Lake of Rot Shoreside": (0xA5C, 7),
},
"Nokron, Eternal City": {
"Nokron, Eternal City": (0xA62, 0),
"Ancestral Woods": (0xA5D, 7),
"Aqueduct-Facing Cliffs": (0xA5D, 6),
"Great Waterfall Basin": (0xA5C, 3),
"Mimic Tear": (0xA5C, 2),
"Night's Sacred Ground": (0xA5D, 5),
},
"Siofra River": {
"Below the Well": (0xA5D, 4),
"Siofra River Bank": (0xA5C, 1),
"Siofra River Well Depths": (0xA62, 1),
"Worshippers' Woods": (0xA5C, 0),
},
"Mohgwyn Palace": {
"Cocoon of the Empyrean": (0xA60, 5),
"Dynasty Mausoleum Entrance": (0xA60, 3),
"Dynasty Mausoleum Midpoint": (0xA60, 2),
"Palace Approach Ledge-Road": (0xA60, 4),
},
"Deeproot Depths": {
"Across the Roots": (0xA5E, 4),
"Deeproot Depths": (0xA5E, 6),
"Great Waterfall Crest": (0xA5E, 7),
"Prince of Death's Throne": (0xA5D, 1),
"Root-Facing Cliffs": (0xA5D, 0),
"The Nameless Eternal City": (0xA5E, 5),
},
# ============ SUBTERRANEAN SHUNNING-GROUNDS ============
"Subterranean Shunning-Grounds": {
"Cathedral of the Forsaken": (0xB79, 3),
"Forsaken Depths": (0xB79, 1),
"Frenzied Flame Proscription": (0xB7A, 7),
"Leyndell Catacombs": (0xB79, 0),
"Underground Roadside": (0xB79, 2),
},
# ============ LEYNDELL ASHEN CAPITAL ============
"Leyndell, Ashen Capital": {
"Divine Bridge (Ash)": (0xA50, 2),
"East Capital Rampart (Ash)": (0xA50, 5),
"Elden Throne (Ash)": (0xA50, 7),
"Erdtree Sanctuary (Ash)": (0xA50, 6),
"Leyndell, Capital of Ash": (0xA50, 4),
"Queen's Bedchamber (Ash)": (0xA50, 3),
},
"Stone Platform": {
"Fractured Marika": (0xAB1, 3),
},
# ============ DLC - GRAVESITE PLAIN ============
"Gravesite Plain": {
"Gravesite Plain": (0xD16, 7),
"Scorched Ruins": (0xD16, 6),
"Three-Path Cross": (0xD16, 5),
"Greatbridge, North": (0xD16, 2),
"Main Gate Cross": (0xD16, 4),
"Cliffroad Terminus": (0xD16, 3),
"Castle Front": (0xD17, 2),
"Pillar Path Cross": (0xD17, 5),
"Pillar Path Waypoint": (0xD17, 4),
"Ellac River Cave": (0xD17, 3),
"Ellac River Downstream": (0xD19, 1),
"Fog Rift Catacombs": (0xBB8, 7),
"Belurat Gaol": (0xBC4, 3),
"Ruined Forge Lava Intake": (0xBD1, 7),
"Dragon's Pit": (0xBDD, 2),
"Dragon's Pit Terminus": (0xBE3, 0),
},
"Castle Ensis": {
"Castle Ensis Checkpoint": (0xD18, 2),
"Castle Lord's Chamber": (0xD18, 1),
"Ensis Moongazing Grounds": (0xD18, 0),
},
"Cerulean Coast": {
"Cerulean Coast": (0xD19, 0),
"Cerulean Coast West": (0xD1A, 7),
"Cerulean Coast Cross": (0xD1A, 4),
"The Fissure": (0xD1A, 6),
"Finger Ruins of Rhia": (0xD1A, 5),
},
"Charo's Hidden Grave": {
"Charo's Hidden Grave": (0xD1B, 6),
"Lamenter's Gaol": (0xBC4, 1),
},
"Stone Coffin Fissure": {
"Stone Coffin Fissure": (0xAD7, 6),
"Fissure Cross": (0xAD7, 5),
"Fissure Waypoint": (0xAD7, 4),
"Fissure Depths": (0xAD7, 3),
"Garden of Deep Purple": (0xAD7, 7),
},
"Foot of the Jagged Peak": {
"Grand Altar of Dragon Communion": (0xD1B, 7),
"Foot of the Jagged Peak": (0xD1C, 5),
},
"Jagged Peak": {
"Jagged Peak Mountainside": (0xD1C, 4),
"Jagged Peak Summit": (0xD1C, 3),
"Rest of the Dead Dragon": (0xD1C, 2),
},
# ============ DLC - BELURAT / ENIR-ILIM ============
"Belurat, Tower Settlement": {
"Belurat, Tower Settlement": (0xABE, 6),
"Small Private Altar": (0xABE, 5),
"Stagefront": (0xABE, 4),
"Theatre of the Divine Beast": (0xABE, 7),
},
"Enir-Ilim": {
"Enir-Ilim Outer Wall": (0xABF, 3),
"First Rise": (0xABF, 2),
"Spiral Rise": (0xABF, 1),
"Cleansing Chamber Anteroom": (0xABF, 0),
"Divine Gate Front Staircase": (0xAC0, 7),
"Gate of Divinity": (0xABF, 5),
},
"Ancient Ruins of Rauh": {
"Viaduct Minor Tower": (0xD27, 3),
"Rauh Ancient Ruins, East": (0xD27, 2),
"Rauh Ancient Ruins, West": (0xD27, 1),
"Ancient Ruins Grand Stairway": (0xD28, 7),
"Church of the Bud, Main Entrance": (0xD27, 0),
"Church of the Bud": (0xD28, 6),
"Rivermouth Cave": (0xBDD, 3),
},
"Rauh Base": {
"Ancient Ruins Base": (0xD24, 7),
"Temple Town Ruins": (0xD24, 6),
"Ravine North": (0xD24, 5),
"Scorpion River Catacombs": (0xBB8, 6),
"Taylew's Ruined Forge": (0xBD1, 4),
},
# ============ DLC - SCADU ALTUS ============
"Scadu Altus": {
"Highroad Cross": (0xD22, 3),
"Scadu Altus, West": (0xD23, 4),
"Moorth Ruins": (0xD22, 1),
"Moorth Highway, South": (0xD23, 3),
"Fort of Reprimand": (0xD23, 2),
"Behind the Fort of Reprimand": (0xD23, 1),
"Scaduview Cross": (0xD23, 0),
"Bonny Village": (0xD22, 0),
"Bridge Leading to the Village": (0xD23, 7),
"Church District Highroad": (0xD23, 6),
"Cathedral of Manus Metyr": (0xD23, 5),
"Finger Birthing Grounds": (0xAFC, 3),
"Castle Watering Hole": (0xD24, 3),
"Recluses' River Upstream": (0xD24, 2),
"Recluses' River Downstream": (0xD24, 1),
"Darklight Catacombs": (0xBB8, 5),
"Bonny Gaol": (0xBC4, 2),
"Ruined Forge of Starfall Past": (0xBD1, 5),
},
"Abyssal Woods": {
"Abyssal Woods": (0xD1D, 3),
"Forsaken Graveyard": (0xD1D, 1),
"Woodland Trail": (0xD1D, 0),
"Church Ruins": (0xD1E, 7),
"Divided Falls": (0xD1D, 2),
},
"Midra's Manse": {
"Manse Hall": (0xB22, 6),
"Midra's Library": (0xB22, 5),
"Second Floor Chamber": (0xB22, 4),
"Discussion Chamber": (0xB22, 7),
},
# ============ DLC - SHADOW KEEP ============
"Shadow Keep": {
"Shadow Keep Main Gate": (0xACA, 1),
"Main Gate Plaza": (0xACA, 2),
},
"Shadow Keep, Church District": {
"Church District Entrance": (0xACB, 5),
"Sunken Chapel": (0xACB, 4),
"Tree-Worship Passage": (0xACB, 3),
"Tree-Worship Sanctum": (0xACB, 2),
},
"Specimen Storehouse": {
"Storehouse, First Floor": (0xACB, 0),
"Storehouse, Fourth Floor": (0xACC, 7),
"Storehouse, Seventh Floor": (0xACC, 6),
"Dark Chamber Entrance": (0xACC, 5),
"Storehouse, Back Section": (0xACC, 3),
"Storehouse, Loft": (0xACC, 2),
"West Rampart": (0xACD, 7),
"Messmer's Dark Chamber": (0xACB, 1),
},
"Scaduview": {
"Scaduview": (0xD26, 5),
"Shadow Keep, Back Gate": (0xD26, 4),
"Scadutree Base": (0xD2A, 7),
"Hinterland": (0xD26, 0),
"Hinterland Bridge": (0xD27, 6),
"Fingerstone Hill": (0xD27, 7),
},
}
# Flatten for compatibility
KNOWN_GRACES: dict[str, tuple[int, int]] = {}
for region, graces in GRACES_BY_REGION.items():
KNOWN_GRACES.update(graces)
# Grace presets for quick selection
GRACE_PRESETS: dict[str, list[str]] = {
"Bingo": [
"Scenic Isle",
"Ruined Labyrinth",
"Altus Highway Junction",
"Road of Iniquity",
"Inner Consecrated Snowfield",
"Snow Valley Ruins Overlook",
"Haligtree Roots",
],
"Early Game": [
"The First Step",
"Church of Elleh",
"Gatefront",
"Stormhill Shack",
"Agheel Lake South",
"Agheel Lake North",
"Waypoint Ruins Cellar",
],
"All Roundtables": [
"Table of Lost Grace",
],
"Divine Towers": [
"Divine Tower of Limgrave",
"Divine Tower of Liurnia",
"Divine Tower of West Altus",
"Divine Tower of East Altus",
"Divine Tower of Caelid: Center",
"Isolated Divine Tower",
],
"Legacy Dungeons": [
"Stormveil Main Gate",
"Godrick the Grafted",
"Raya Lucaria Grand Library",
"Volcano Manor",
"Rykard, Lord of Blasphemy",
"East Capital Rampart",
"Elden Throne",
"Haligtree Roots",
"Malenia, Goddess of Rot",
"Crumbling Beast Grave",
"Maliketh, the Black Blade",
],
}
# ============================================================
# Core Stat Randomizer Logic
# ============================================================
PLAYER_CLASSES = {
3000: 'Vagabond', 3001: 'Warrior', 3002: 'Hero', 3003: 'Bandit',
3004: 'Astrologer', 3005: 'Prophet', 3006: 'Confessor',
3007: 'Samurai', 3008: 'Prisoner', 3009: 'Wretch',
}
STAT_FIELDS = {
'level': 'soulLv', 'vigor': 'baseVit', 'mind': 'baseWil',
'endurance': 'baseEnd', 'strength': 'baseStr', 'dexterity': 'baseDex',
'intelligence': 'baseMag', 'faith': 'baseFai', 'arcane': 'baseLuc',
}
TARGET_LEVEL = 9
TOTAL_STATS = 88
MIN_STAT = 6
NUM_STATS = 8
DEFAULT_REGULATION_PATH = r"D:\ER MODS\ModEngine-2.1.0.0-win64\randomizer\regulation.bin"
SCRIPT_DIR = Path(__file__).parent
OUTPUT_DIR = SCRIPT_DIR / "output"
CONFIG_FILE = SCRIPT_DIR / "config.json"
def load_config() -> dict:
"""Load saved configuration."""
if CONFIG_FILE.exists():
try:
with open(CONFIG_FILE, 'r') as f:
return json.load(f)
except (json.JSONDecodeError, OSError, ValueError):
pass # Return empty config if file is corrupted
return {}
def save_config(config: dict) -> None:
"""Save configuration to file."""
try:
with open(CONFIG_FILE, 'w') as f:
json.dump(config, f, indent=2)
except (OSError, TypeError) as e:
print(f"Warning: Could not save config: {e}")
def find_witchybnd() -> Optional[str]:
"""Find WitchyBND executable."""
search_paths = [
SCRIPT_DIR / "WitchyBND.exe",
SCRIPT_DIR / "WitchyBND" / "WitchyBND.exe",
SCRIPT_DIR / "WitchyBND-v2.16.0.5" / "WitchyBND.exe",
SCRIPT_DIR / "tools" / "WitchyBND.exe",
]
for path in search_paths:
if path.exists():
return str(path)
return shutil.which("WitchyBND")
def randomize_stats(seed: int) -> dict[int, dict]:
"""Generate randomized stats for all classes using seed."""
random.seed(seed)
remaining_pool = TOTAL_STATS - (MIN_STAT * NUM_STATS)
all_stats: dict[int, dict] = {}
for row_id, class_name in PLAYER_CLASSES.items():
stats: dict[str, int] = {k: MIN_STAT for k in ['vigor', 'mind', 'endurance', 'strength',
'dexterity', 'intelligence', 'faith', 'arcane']}
for _ in range(remaining_pool):
stats[random.choice(list(stats.keys()))] += 1
stats['level'] = TARGET_LEVEL
all_stats[row_id] = {'name': class_name, 'stats': stats}
return all_stats
def format_stats_text(all_stats: dict[int, dict]) -> str:
"""Format stats as text for display."""
lines = ["-" * 65]
for row_id in sorted(all_stats.keys()):
d = all_stats[row_id]
s = d['stats']
total = sum(v for k, v in s.items() if k != 'level')
lines.append(f"[{d['name']:10s}] Lv:{s['level']:2d} | "
f"Vig:{s['vigor']:2d} Min:{s['mind']:2d} End:{s['endurance']:2d} "
f"Str:{s['strength']:2d} Dex:{s['dexterity']:2d} Int:{s['intelligence']:2d} "
f"Fai:{s['faith']:2d} Arc:{s['arcane']:2d} | Total: {total}")
lines.append("-" * 65)
return "\n".join(lines)
def export_csv(all_stats: dict[int, dict], seed: int, output_dir: Path) -> Path:
"""Export stats to CSV file."""
output_dir.mkdir(parents=True, exist_ok=True)
csv_path = output_dir / f"modified_{seed}.csv"
with open(csv_path, 'w') as f:
f.write("Row ID,Class,Level,Vigor,Mind,Endurance,Strength,Dexterity,Intelligence,Faith,Arcane\n")
for row_id in sorted(all_stats.keys()):
d = all_stats[row_id]
s = d['stats']
f.write(f"{row_id},{d['name']},{s['level']},{s['vigor']},{s['mind']},"
f"{s['endurance']},{s['strength']},{s['dexterity']},{s['intelligence']},"
f"{s['faith']},{s['arcane']}\n")
return csv_path
def run_witchybnd(witchybnd_path: str, target_path: str) -> tuple[bool, str]:
"""Run WitchyBND on a file/folder."""
result = subprocess.run([witchybnd_path, "-s", target_path], capture_output=True, text=True)
if result.stderr and result.stderr.strip():
return False, result.stderr
return True, ""
def find_charainitparam(folder: Path) -> Optional[Path]:
"""Find CharaInitParam.param file in unpacked folder."""
for root, dirs, files in os.walk(folder):
for f in files:
if "CharaInitParam" in f and f.endswith(".param"):
return Path(root) / f
return None
def find_equip_param(folder: Path, param_name: str) -> Optional[Path]:
"""Find a specific param file (e.g., EquipParamWeapon) in unpacked folder."""
for root, dirs, files in os.walk(folder):
for f in files:
if param_name in f and f.endswith(".param"):
return Path(root) / f
return None
def load_weapon_names(witchybnd_path: Optional[str] = None) -> dict[int, str]:
"""Load weapon ID to name mapping from Paramdex Names file."""