about summary refs log tree commit diff stats
path: root/Source/ChallengeRandomizer.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2019-11-16 21:17:48 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2019-11-16 21:17:48 -0800
commit133975b5a2ceca273182829f2f11042a5276c2f0 (patch)
treea7e3b13ffd81484b41122acef5189f060cca365c /Source/ChallengeRandomizer.cpp
parentfd2fa2211dc09c9030601fde1afd2f7823b22ed8 (diff)
downloadwitness-tutorializer-133975b5a2ceca273182829f2f11042a5276c2f0.tar.gz
witness-tutorializer-133975b5a2ceca273182829f2f11042a5276c2f0.tar.bz2
witness-tutorializer-133975b5a2ceca273182829f2f11042a5276c2f0.zip
Tabs -> spaces everywhere
Diffstat (limited to 'Source/ChallengeRandomizer.cpp')
-rw-r--r--Source/ChallengeRandomizer.cpp182
1 files changed, 91 insertions, 91 deletions
diff --git a/Source/ChallengeRandomizer.cpp b/Source/ChallengeRandomizer.cpp index de08885..e91e9ac 100644 --- a/Source/ChallengeRandomizer.cpp +++ b/Source/ChallengeRandomizer.cpp
@@ -3,106 +3,106 @@
3 3
4// Modify an opcode to use RNG2 instead of main RNG 4// Modify an opcode to use RNG2 instead of main RNG
5void ChallengeRandomizer::AdjustRng(int offset) { 5void ChallengeRandomizer::AdjustRng(int offset) {
6 int currentRng = _memory->ReadData<int>({offset}, 0x1)[0]; 6 int currentRng = _memory->ReadData<int>({offset}, 0x1)[0];
7 _memory->WriteData<int>({offset}, {currentRng + 0x20}); 7 _memory->WriteData<int>({offset}, {currentRng + 0x20});
8} 8}
9 9
10// Overwrite the pointer for the lightmap_generator (which is unused, afaict) to point to a secondary RNG. 10// Overwrite the pointer for the lightmap_generator (which is unused, afaict) to point to a secondary RNG.
11// Then, adjust all the RNG functions in challenge/doors to use this RNG. 11// Then, adjust all the RNG functions in challenge/doors to use this RNG.
12ChallengeRandomizer::ChallengeRandomizer(const std::shared_ptr<Memory>& memory, int seed) : _memory(memory) 12ChallengeRandomizer::ChallengeRandomizer(const std::shared_ptr<Memory>& memory, int seed) : _memory(memory)
13{ 13{
14 RNG_ADDR = _memory->ReadData<int>({GLOBALS + 0x10}, 1)[0]; 14 RNG_ADDR = _memory->ReadData<int>({GLOBALS + 0x10}, 1)[0];
15 RNG2_ADDR = _memory->ReadData<int>({GLOBALS + 0x30}, 1)[0]; 15 RNG2_ADDR = _memory->ReadData<int>({GLOBALS + 0x30}, 1)[0];
16 bool alreadyInjected = (RNG2_ADDR == RNG_ADDR + 4); 16 bool alreadyInjected = (RNG2_ADDR == RNG_ADDR + 4);
17 17
18 if (!alreadyInjected) _memory->WriteData<int>({GLOBALS + 0x30}, {RNG_ADDR + 4}); 18 if (!alreadyInjected) _memory->WriteData<int>({GLOBALS + 0x30}, {RNG_ADDR + 4});
19 _memory->WriteData<int>({GLOBALS + 0x30, 0}, {seed}); 19 _memory->WriteData<int>({GLOBALS + 0x30, 0}, {seed});
20 20
21 // do_success_side_effects 21 // do_success_side_effects
22 _memory->AddSigScan({0xFF, 0xC8, 0x99, 0x2B, 0xC2, 0xD1, 0xF8, 0x8B, 0xD0}, [&](int index) { 22 _memory->AddSigScan({0xFF, 0xC8, 0x99, 0x2B, 0xC2, 0xD1, 0xF8, 0x8B, 0xD0}, [&](int index) {
23 if (GLOBALS == 0x5B28C0) { // Version differences. 23 if (GLOBALS == 0x5B28C0) { // Version differences.
24 index += 0x3E; 24 index += 0x3E;
25 } else if (GLOBALS == 0x62D0A0) { 25 } else if (GLOBALS == 0x62D0A0) {
26 index += 0x42; 26 index += 0x42;
27 } 27 }
28 // Overwritten bytes start just after the movsxd rax, dword ptr ds:[rdi + 0x230] 28 // Overwritten bytes start just after the movsxd rax, dword ptr ds:[rdi + 0x230]
29 // aka test eax, eax; jle 2C; imul rcx, rax, 34 29 // aka test eax, eax; jle 2C; imul rcx, rax, 34
30 _memory->WriteData<byte>({index}, { 30 _memory->WriteData<byte>({index}, {
31 0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00, // mov ecx, [0x00000000] ;This is going to be the address of the custom RNG 31 0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00, // mov ecx, [0x00000000] ;This is going to be the address of the custom RNG
32 0x67, 0xC7, 0x01, 0x00, 0x00, 0x00, 0x00, // mov dword ptr ds:[ecx], 0x00000000 ;This is going to be the seed value 32 0x67, 0xC7, 0x01, 0x00, 0x00, 0x00, 0x00, // mov dword ptr ds:[ecx], 0x00000000 ;This is going to be the seed value
33 0x48, 0x83, 0xF8, 0x02, // cmp rax, 0x2 ;This is the short solve on the record player (which turns it off) 33 0x48, 0x83, 0xF8, 0x02, // cmp rax, 0x2 ;This is the short solve on the record player (which turns it off)
34 0x90, 0x90, 0x90 // nop nop nop 34 0x90, 0x90, 0x90 // nop nop nop
35 }); 35 });
36 int target = (GLOBALS + 0x30) - (index + 0x6); // +6 is for the length of the line 36 int target = (GLOBALS + 0x30) - (index + 0x6); // +6 is for the length of the line
37 _memory->WriteData<int>({index + 0x2}, {target}); 37 _memory->WriteData<int>({index + 0x2}, {target});
38 _memory->WriteData<int>({index + 0x9}, {seed}); // Because we're resetting seed every challenge, we need to run this injection every time. 38 _memory->WriteData<int>({index + 0x9}, {seed}); // Because we're resetting seed every challenge, we need to run this injection every time.
39 }); 39 });
40 40
41 if (!alreadyInjected) { 41 if (!alreadyInjected) {
42 // shuffle_integers 42 // shuffle_integers
43 _memory->AddSigScan({0x48, 0x89, 0x5C, 0x24, 0x10, 0x56, 0x48, 0x83, 0xEC, 0x20, 0x48, 0x63, 0xDA, 0x48, 0x8B, 0xF1, 0x83, 0xFB, 0x01}, [&](int index) { 43 _memory->AddSigScan({0x48, 0x89, 0x5C, 0x24, 0x10, 0x56, 0x48, 0x83, 0xEC, 0x20, 0x48, 0x63, 0xDA, 0x48, 0x8B, 0xF1, 0x83, 0xFB, 0x01}, [&](int index) {
44 AdjustRng(index + 0x23); 44 AdjustRng(index + 0x23);
45 }); 45 });
46 // shuffle<int> 46 // shuffle<int>
47 _memory->AddSigScan({0x33, 0xF6, 0x48, 0x8B, 0xD9, 0x39, 0x31, 0x7E, 0x51}, [&](int index) { 47 _memory->AddSigScan({0x33, 0xF6, 0x48, 0x8B, 0xD9, 0x39, 0x31, 0x7E, 0x51}, [&](int index) {
48 AdjustRng(index - 0x4); 48 AdjustRng(index - 0x4);
49 }); 49 });
50 // cut_random_edges 50 // cut_random_edges
51 _memory->AddSigScan({0x89, 0x44, 0x24, 0x3C, 0x33, 0xC0, 0x85, 0xC0, 0x75, 0xFA}, [&](int index) { 51 _memory->AddSigScan({0x89, 0x44, 0x24, 0x3C, 0x33, 0xC0, 0x85, 0xC0, 0x75, 0xFA}, [&](int index) {
52 AdjustRng(index + 0x3B); 52 AdjustRng(index + 0x3B);
53 }); 53 });
54 // get_empty_decoration_slot 54 // get_empty_decoration_slot
55 _memory->AddSigScan({0x42, 0x83, 0x3C, 0x80, 0x00, 0x75, 0xDF}, [&](int index) { 55 _memory->AddSigScan({0x42, 0x83, 0x3C, 0x80, 0x00, 0x75, 0xDF}, [&](int index) {
56 AdjustRng(index - 0x17); 56 AdjustRng(index - 0x17);
57 }); 57 });
58 // get_empty_dot_spot 58 // get_empty_dot_spot
59 _memory->AddSigScan({0xF7, 0xF3, 0x85, 0xD2, 0x74, 0xEC}, [&](int index) { 59 _memory->AddSigScan({0xF7, 0xF3, 0x85, 0xD2, 0x74, 0xEC}, [&](int index) {
60 AdjustRng(index - 0xB); 60 AdjustRng(index - 0xB);
61 }); 61 });
62 // add_exactly_this_many_bisection_dots 62 // add_exactly_this_many_bisection_dots
63 _memory->AddSigScan({0x48, 0x8B, 0xB4, 0x24, 0xB8, 0x00, 0x00, 0x00, 0x48, 0x8B, 0xBC, 0x24, 0xB0, 0x00, 0x00, 0x00}, [&](int index) { 63 _memory->AddSigScan({0x48, 0x8B, 0xB4, 0x24, 0xB8, 0x00, 0x00, 0x00, 0x48, 0x8B, 0xBC, 0x24, 0xB0, 0x00, 0x00, 0x00}, [&](int index) {
64 AdjustRng(index - 0x4); 64 AdjustRng(index - 0x4);
65 }); 65 });
66 // make_a_shaper 66 // make_a_shaper
67 _memory->AddSigScan({0xF7, 0xE3, 0xD1, 0xEA, 0x8D, 0x0C, 0x52}, [&](int index) { 67 _memory->AddSigScan({0xF7, 0xE3, 0xD1, 0xEA, 0x8D, 0x0C, 0x52}, [&](int index) {
68 AdjustRng(index - 0x10); 68 AdjustRng(index - 0x10);
69 AdjustRng(index + 0x1C); 69 AdjustRng(index + 0x1C);
70 AdjustRng(index + 0x49); 70 AdjustRng(index + 0x49);
71 }); 71 });
72 // Entity_Machine_Panel::init_pattern_data_lotus 72 // Entity_Machine_Panel::init_pattern_data_lotus
73 _memory->AddSigScan({0x40, 0x55, 0x56, 0x48, 0x8D, 0x6C, 0x24, 0xB1}, [&](int index) { 73 _memory->AddSigScan({0x40, 0x55, 0x56, 0x48, 0x8D, 0x6C, 0x24, 0xB1}, [&](int index) {
74 AdjustRng(index + 0x433); 74 AdjustRng(index + 0x433);
75 AdjustRng(index + 0x45B); 75 AdjustRng(index + 0x45B);
76 AdjustRng(index + 0x5A7); 76 AdjustRng(index + 0x5A7);
77 AdjustRng(index + 0x5D6); 77 AdjustRng(index + 0x5D6);
78 AdjustRng(index + 0x6F6); 78 AdjustRng(index + 0x6F6);
79 AdjustRng(index + 0xD17); 79 AdjustRng(index + 0xD17);
80 AdjustRng(index + 0xFDA); 80 AdjustRng(index + 0xFDA);
81 }); 81 });
82 // Entity_Record_Player::reroll_lotus_eater_stuff 82 // Entity_Record_Player::reroll_lotus_eater_stuff
83 _memory->AddSigScan({0xB8, 0xAB, 0xAA, 0xAA, 0xAA, 0x41, 0xC1, 0xE8}, [&](int index) { 83 _memory->AddSigScan({0xB8, 0xAB, 0xAA, 0xAA, 0xAA, 0x41, 0xC1, 0xE8}, [&](int index) {
84 AdjustRng(index - 0x13); 84 AdjustRng(index - 0x13);
85 AdjustRng(index + 0x34); 85 AdjustRng(index + 0x34);
86 }); 86 });
87 87
88 // These disable the random locations on timer panels, which would otherwise increment the RNG. 88 // These disable the random locations on timer panels, which would otherwise increment the RNG.
89 // I'm writing 31 C0 (xor eax, eax), then 3 NOPs, which pretends the RNG returns 0. 89 // I'm writing 31 C0 (xor eax, eax), then 3 NOPs, which pretends the RNG returns 0.
90 // do_lotus_minutes 90 // do_lotus_minutes
91 _memory->AddSigScan({0x0F, 0xBE, 0x6C, 0x08, 0xFF, 0x45}, [&](int index) { 91 _memory->AddSigScan({0x0F, 0xBE, 0x6C, 0x08, 0xFF, 0x45}, [&](int index) {
92 _memory->WriteData<byte>({index + 0x410}, {0x31, 0xC0, 0x90, 0x90, 0x90}); 92 _memory->WriteData<byte>({index + 0x410}, {0x31, 0xC0, 0x90, 0x90, 0x90});
93 }); 93 });
94 // do_lotus_tenths 94 // do_lotus_tenths
95 _memory->AddSigScan({0x00, 0x04, 0x00, 0x00, 0x41, 0x8D, 0x50, 0x09}, [&](int index) { 95 _memory->AddSigScan({0x00, 0x04, 0x00, 0x00, 0x41, 0x8D, 0x50, 0x09}, [&](int index) {
96 _memory->WriteData<byte>({index + 0xA2}, {0x31, 0xC0, 0x90, 0x90, 0x90}); 96 _memory->WriteData<byte>({index + 0xA2}, {0x31, 0xC0, 0x90, 0x90, 0x90});
97 }); 97 });
98 // do_lotus_eighths 98 // do_lotus_eighths
99 _memory->AddSigScan({0x75, 0xF5, 0x0F, 0xBE, 0x44, 0x08, 0xFF}, [&](int index) { 99 _memory->AddSigScan({0x75, 0xF5, 0x0F, 0xBE, 0x44, 0x08, 0xFF}, [&](int index) {
100 _memory->WriteData<byte>({index + 0x1AE}, {0x31, 0xC0, 0x90, 0x90, 0x90}); 100 _memory->WriteData<byte>({index + 0x1AE}, {0x31, 0xC0, 0x90, 0x90, 0x90});
101 }); 101 });
102 } 102 }
103 103
104 int failed = _memory->ExecuteSigScans(); 104 int failed = _memory->ExecuteSigScans();
105 if (failed != 0) { 105 if (failed != 0) {
106 std::cout << "Failed " << failed << " sigscans"; 106 std::cout << "Failed " << failed << " sigscans";
107 } 107 }
108} 108}