Skip to content

Commit

Permalink
Fix custom injections err
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuxyz00 committed Jan 30, 2025
1 parent 6d7b7ed commit 3bb49d2
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions CasioEmuMsvc/Gui/Injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,40 @@ bool Injector::IsHexString(const std::string& str) {
}

void Injector::InitCustomInjectionsFile() {
std::filesystem::path filepath = "./hc-inj.txt";
if (!std::filesystem::exists(filepath)) {
const std::filesystem::path filepath = "./hc-inj.txt";

if (std::filesystem::exists(filepath)) {
return;
}

const std::string template_content = R"(# Custom Injection Template
# Format: name = {
# address = "hex_data",
# address = "hex_data"
# }
)";

try {
std::ofstream file(filepath);
if (file.is_open()) {
file << "# Function added by hieuxyz\n\n";
file << "ex1 = {\n";
file << " 0xd180 = \"30303030\",\n";
file << " 0xe9e0 = \"1234567890\"\n";
file << "}\n\n";
file << "ex2 = {\n";
file << " 0xd830 = \"11111111\",\n";
file << " 0xe9f0 = \"88888888\"\n";
file << "}\n";
file.close();
if (!file) {
throw std::runtime_error("Failed to create injection template file");
}
file << template_content;
if (!file) {
throw std::runtime_error("Failed to write injection template content");
}
file.close();
} catch (const std::exception& e) {
// TODO: Add proper logging
}
}

bool Injector::ParseCustomInjections(const std::string& content) {
customInjections.clear();

if (content.empty()) {
return true;
}

std::istringstream stream(content);
std::string line;
Expand Down Expand Up @@ -102,9 +116,8 @@ bool Injector::ParseCustomInjections(const std::string& content) {
currentInj.pairs.push_back(pair);
}
}
}

return !customInjections.empty();
}
return true;
}

void Injector::LoadCustomInjections() {
Expand Down

0 comments on commit 3bb49d2

Please sign in to comment.