-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimehook.cpp
220 lines (192 loc) · 6.93 KB
/
primehook.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
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
#include "primehook.h"
#include <string>
#include <stdexcept>
#include "MemoryWatch/MemWatchEntry.h"
#include "DolphinProcess/DolphinAccessor.h"
#include "Common/CommonUtils.h"
#include <iostream>
#define MEM_START 0x80000000
#define INVENTORY_START 0x804578CC
PrimeHook::PrimeHook()
{
DolphinComm::DolphinAccessor::init();
DolphinComm::DolphinAccessor::hook();
DolphinComm::DolphinAccessor::updateRAMCache();
init_watches();
init_items();
artifact_list = init_artifacts();
}
PrimeHook::~PrimeHook(){
delete igt_entry;
delete gameid_entry;
}
std::vector<std::vector<int>> PrimeHook::item_values(){
//DolphinComm::DolphinAccessor::updateRAMCache();
std::vector<std::vector<int>> item_vals;
for(unsigned i = 0; i < item_grid.size(); i++){
std::vector<int> line;
for(unsigned j = 0; j < item_grid[i].size(); j++){
if(item_grid[i][j].entry->readMemoryFromRAM() == Common::MemOperationReturnCode::OK){
line.push_back(stoi(item_grid[i][j].entry->getStringFromMemory()));
}
else{
line.push_back(0);
}
}
item_vals.push_back(line);
}
return item_vals;
}
void PrimeHook::init_watches(){
igt_entry = new MemWatchEntry;
igt_entry->setTypeAndLength(Common::MemType::type_double, sizeof(double));
igt_entry->setConsoleAddress(0x804578CC);
igt_entry->setBoundToPointer(true);
igt_entry->addOffset(0xA0);
gameid_entry = new MemWatchEntry;
gameid_entry->setTypeAndLength(Common::MemType::type_string, sizeof(char) * 6);
gameid_entry->setConsoleAddress(MEM_START);
}
prime_item PrimeHook::create_item(std::string name, u32 offset, bool isCounter)
{
MemWatchEntry *item_entry = new MemWatchEntry;
item_entry->setTypeAndLength(Common::MemType::type_word, sizeof(u16));
item_entry->setConsoleAddress(INVENTORY_START);
item_entry->setBoundToPointer(true);
item_entry->addOffset(offset);
prime_item item = {name, offset, isCounter, 0, item_entry};
return item;
}
void PrimeHook::init_items(){
std::vector<prime_item> first_row = {
create_item("Missiles", 0x2EC, true),
create_item("Energy Tanks", 0x38C, true),
create_item("Wave Beam", 0x2DC, false),
create_item("Ice Beam", 0x2D4, false),
create_item("Plasma Beam", 0x2E4, false),
create_item("Scan Visor", 0x2F4, false)
};
std::vector<prime_item> second_row = {
create_item("Morph Ball", 0x34C, false),
create_item("Morph Ball Bombs", 0x2FC, false),
create_item("Boost Ball", 0x35C, false),
create_item("Spider Ball", 0x364, false),
create_item("Power Bombs", 0x304, true),
create_item("Thermal Visor", 0x314, false)
};
std::vector<prime_item> third_row = {
create_item("Super Missiles", 0x324, false),
create_item("Wavebuster", 0x3AC, false),
create_item("Ice Spreader", 0x33C, false),
create_item("Flamethrower", 0x30C, false),
create_item("Space Jump Boots", 0x340, false),
create_item("X-Ray Visor", 0x334, false)
};
std::vector<prime_item> fourth_row = {
create_item("Varia Suit", 0x37C, false),
create_item("Gravity Suit", 0x374, false),
create_item("Phazon Suit", 0x384, false),
create_item("Charge Beam", 0x318, false),
create_item("Grapple Beam", 0x32C, false)
};
item_grid = {first_row, second_row, third_row, fourth_row};
}
std::vector<prime_item> PrimeHook::init_artifacts(){
prime_item nature = create_item("Artifact of Nature", 0x3EB, false);
prime_item sun = create_item("Artifact of Sun", 0x3F0, false);
prime_item spirit = create_item("Artifact of Spirit", 0x400, false);
prime_item elder = create_item("Artifact of Elder", 0x3C0, false);
prime_item strength = create_item("Artifact of Strength", 0x3B8, false);
prime_item lifegiver = create_item("Artifact of Lifegiver", 0x3D0, false);
prime_item world = create_item("Artifact of World", 0x3F8, false);
prime_item wild = create_item("Artifact of Wild", 0x3C8, false);
prime_item chozo = create_item("Artifact of Chozo", 0x3E0, false);
prime_item truth = create_item("Artifact of Truth", 0x3B0, false);
prime_item newborn = create_item("Artifact of Newborn", 0x408, false);
prime_item warrior = create_item("Artifact of Warrior", 0x3D8, false);
return {nature, sun, spirit, elder, strength, lifegiver, world, wild, chozo, truth, newborn, warrior};
}
int PrimeHook::artifact_count(){
int sum = 0;
for(prime_item i : artifact_list){
if(i.entry->readMemoryFromRAM() == Common::MemOperationReturnCode::OK){
if(stoi(i.entry->getStringFromMemory())){
sum++;
}
}
}
return sum;
}
std::string PrimeHook::format_IGT(std::string raw_IGT)
{
double dIGT;
try
{
dIGT = stod(raw_IGT);
}
catch (const std::invalid_argument &ia)
{
return "??:??:??.???";
}
int IGT = (int)dIGT;
int hours = IGT / 3600;
int minutes = (IGT - (hours * 3600)) / 60;
int seconds = IGT - ((hours * 3600) + (minutes * 60));
int milliseconds = (int)(dIGT * 1000) % 1000;
char buffer[50];
sprintf(buffer, "%02d:%02d:%02d.%03d", hours, minutes, seconds, milliseconds);
return buffer;
}
std::string PrimeHook::get_IGT_value(){
//DolphinComm::DolphinAccessor::hook();
//DolphinComm::DolphinAccessor::updateRAMCache();
if(igt_entry != nullptr){
if(igt_entry->readMemoryFromRAM() == Common::MemOperationReturnCode::OK){
return format_IGT(igt_entry->getStringFromMemory());
}
return "";
}
return "nullptr here";
}
std::string PrimeHook::getStatus(){
DolphinComm::DolphinAccessor::DolphinStatus status = DolphinComm::DolphinAccessor::getStatus();
if(status == DolphinComm::DolphinAccessor::DolphinStatus::hooked){
return "hooked";
}
if(status == DolphinComm::DolphinAccessor::DolphinStatus::unHooked){
return "unhooked";
}
if(status == DolphinComm::DolphinAccessor::DolphinStatus::notRunning){
return "not running";
}
if(status == DolphinComm::DolphinAccessor::DolphinStatus::noEmu){
return "no emu";
}
return "status unknown";
}
bool PrimeHook::checkHook(){
if(getGameID() == "GM8E01"){
return true;
}
else{
//DolphinComm::DolphinAccessor::unHook();
return false;
}
}
bool PrimeHook::attemptHook(){
DolphinComm::DolphinAccessor::hook();
if(DolphinComm::DolphinAccessor::getStatus() == DolphinComm::DolphinAccessor::DolphinStatus::hooked){
if(getGameID() == "GM8E01"){
return true;
}
}
//DolphinComm::DolphinAccessor::unHook();
return false;
}
std::string PrimeHook::getGameID(){
std::string game_id = "";
if (gameid_entry->readMemoryFromRAM() == Common::MemOperationReturnCode::OK) {
game_id = gameid_entry->getStringFromMemory();
}
return game_id;
}