-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhook.cpp
More file actions
139 lines (123 loc) · 3.93 KB
/
hook.cpp
File metadata and controls
139 lines (123 loc) · 3.93 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
#include <map>
#include <vector>
#include <winbase.h>
#include "logger.h"
#include "lr2.h"
extern std::map<int, int> seedmap;
extern int toIdx(std::vector<int>&);
const char ConfigPath[] = ".\\LR2Unrandomizer.ini";
const unsigned int BufLen = 10;
using namespace LR2;
// This function verifies the input in field Lane
bool isValidLane(char* buf)
{
if (strlen(buf) == 7)
{
unsigned int mask = 0;
for (int i = 0; i < 7; i++)
{
if (!(buf[i] >= '0' && buf[i] <= '9'))
return false;
mask |= 1 << (buf[i] - '0');
}
if (mask == 0b1111111)
return true;
if (mask == 0b11111110)
{
for (int i = 0; i < 7; i++)
buf[i] -= 1;
return true;
}
}
return false;
}
bool setRandLane(std::vector<int>& lane)
{
// calculate the mapping from vector lane to int
int seqid = toIdx(lane);
int seed;
// configuration valid
if (seqid != -1 && seedmap.find(seqid) != seedmap.end())
{
std::vector<int> lane2;
lane2.reserve(7);
seed = seedmap[seqid];
console_log("seed = %d\n", seed);
*playRandseed = seed;
// convert to lr2 lane configuration
for (int i = 0; i < 7; i++)
lane2[lane[i]] = i;
playRandLanes[0] = 0;
for (int i = 0; i < 7; i++)
playRandLanes[i + 1] = lane2[i] + 1;
if (*replayStatus == 1)
for (int i = 0; i < *replayIdx; i++)
if ((*replayData)[i].type == 200)
{
(*replayData)[i].value = seed;
break;
}
return true;
}
else
{
return false;
}
}
// This function is hooked into the executable
void onSetupLanePerm()
{
if (*replayStatus == 2)
return;
char buf[BufLen];
GetPrivateProfileString("Config", "Use Unrandomizer", "true", buf, BufLen - 1, ConfigPath);
_strlwr_s(buf);
if (!strcmp(buf, "true") || !strcmp(buf, "on") || !strcmp(buf, "yes"))
{
if (*randomType1p == LANE_RANDOM && *entryKeyCount == 7)
{
GetPrivateProfileString("Config", "Lane", "", buf, BufLen - 1, ConfigPath);
console_log("Configuration input: %s\n", buf);
if (isValidLane(buf))
{
std::vector<int> lane;
lane.reserve(7);
for (int i = 0; i < 7; i++)
lane.push_back(buf[i] - '0');
bool result = setRandLane(lane);
if (!result)
console_log("Configuration %s cannot be generated\n", buf);
}
}
}
else
{
GetPrivateProfileString("Config", "Use R-Random", "false", buf, BufLen - 1, ConfigPath);
_strlwr_s(buf);
if (!strcmp(buf, "true") || !strcmp(buf, "on") || !strcmp(buf, "yes"))
{
if (*randomType1p == LANE_RANDOM && *entryKeyCount == 7)
{
int rranConf = (*playRandseed) % 12;
console_log("Using R-Random configuration %d\n", rranConf);
std::vector<int> lane;
lane.reserve(7);
for (int i = 0; i < 7; i++)
lane.push_back((rranConf & 1) ? i : 7 - 1 - i);
rranConf >>= 1;
rranConf += 1;
int temp;
for (int i = 0; i < rranConf; i++)
{
temp = lane[7 - 1];
for (int j = 5; j >= 0; j--)
lane[j + 1] = lane[j];
lane[0] = temp;
}
bool result = setRandLane(lane);
if (!result)
console_log("Configuration cannot be generated\n");
}
}
}
}