Skip to content

Commit

Permalink
Be more selective with what we replace for the CommaGMIPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
xeropresence committed Jun 7, 2024
1 parent 9183a51 commit 5e3104f
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions AOPP/CommaGMIPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ char* HttpStreamParser__DoLoopFuncAdder()
return reinterpret_cast<char*>(jumpLoc);
}

const std::string replacement(".val().replace(/,/g, '')");
const std::string target(".val()");

const std::vector<std::pair<std::string, std::string>> targets =
{
{ "$(':input[name=amount]').val()", "$(':input[name=amount]').val().replace(/,/g, '')" },
{ "$('#buyOrderUnitPrice').val()","$('#buyOrderUnitPrice').val().replace(/,/g, '')"},
{ "$('#sellOrderUnitPrice').val()","$('#sellOrderUnitPrice').val().replace(/,/g, '')"}
};
__declspec(noinline) int __fastcall HttpStreamParser__DoLoop(HttpStreamParser* a1, void* EDX, int a2)
{
typedef int(__thiscall* OriginalFunctionType)(HttpStreamParser*, int);
Expand All @@ -95,14 +100,17 @@ __declspec(noinline) int __fastcall HttpStreamParser__DoLoop(HttpStreamParser* a
{
std::string tmp;
tmp.assign(a1->user_read_buf_->data, result);
const auto search = tmp.find(target);

if (search != std::string::npos)
for (const auto& [target, replacement] : targets)
{
const auto lengthDelta = replacement.length() - target.length();
tmp.replace(search, target.length(), replacement);
memcpy(reinterpret_cast<char*>(a1->user_read_buf_->data), tmp.c_str(), tmp.length());
result += lengthDelta;
const auto search = tmp.find(target);

if (search != std::string::npos)
{
const auto lengthDelta = replacement.length() - target.length();
tmp.replace(search, target.length(), replacement);
memcpy(a1->user_read_buf_->data, tmp.c_str(), tmp.length());
result += lengthDelta;
}
}

}
Expand Down

0 comments on commit 5e3104f

Please sign in to comment.