forked from sashavol/Frozlunky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frzsave_patch.cpp
54 lines (47 loc) · 1.42 KB
/
frzsave_patch.cpp
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
#include "frzsave_patch.h"
BYTE savefile_find[] = "spelunky_save";
std::string savefile_mask = "xxxxxxxxxxxxx";
BYTE savefile_override[] = "frzlunky_save";
//TODO force load LoadSavefile<eax>(int game<esi>) in preconditions.cpp
//TODO (not in this context) Fix special patches not being undone when speed daily is started
FrzSavePatch::FrzSavePatch(std::shared_ptr<Spelunky> spel) :
Patch(spel),
is_valid(true)
{
Address p = 0;
while(p = spel->find_mem(savefile_find, savefile_mask, p)) {
patch_addrs.push_back(p);
p++;
}
if(patch_addrs.size() == 0) {
DBG_EXPR(std::cout << "[FrzSavePatch] Failed to find spelunky_save.*" << std::endl);
is_valid = false;
return;
}
else {
DBG_EXPR(std::cout << "[FrzSavePatch] Patching " << patch_addrs.size() << " instances of spelunky_save.* => frzlunky_save.*" << std::endl);
DBG_EXPR(
std::cout << "[FrzSavePatch] [ ";
for(Address addr : patch_addrs) {
std::cout << addr << " ";
}
std::cout << "]" << std::endl;
);
}
}
bool FrzSavePatch::valid() {
return is_valid;
}
bool FrzSavePatch::_perform() {
for(Address addr : patch_addrs) {
spel->write_mem(addr, savefile_override, sizeof(savefile_override) - 1, true);
}
return true;
}
bool FrzSavePatch::_undo() {
//permanent
//for(Address addr : patch_addrs) {
// spel->write_mem(addr, savefile_find, sizeof(savefile_find) - 1, true);
//}
return true;
}