Skip to content

Commit

Permalink
Update patterns for gameupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlegitSenpaii committed Oct 24, 2024
1 parent 0525444 commit 650db40
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,57 @@
*
* Patterns:
* SteamContext::onUserStatsReceived jz > jnz
* 74 73 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 48 8b 10
* 74 1f b9 5b 56 d4 00 ba
*
* AchievementGui::updateModdedLabel //turn while true to while !true
* 75 5b 55 45 31 C0 45 31 -- jnz > jz
* -> if this doesnt work use: 74 7f 66 0f 1f 44 00 00 48 8b 10 -- jz > jnz
*
* //not needed anymore except if 0x02054feb needs to be changed
* AchievementGui::AchievementGui jz > jnz
* 84 8a 03 00 00 0f 1f 44 00
*
* ModManager::isVanilla // modifying this directly might break stuff
* -> this function is used in the linux version in PlayerData to determine if the game is modded or not.
* In Windows, it's not (or the compiler optimizes it out)
* Update: this function exits three times now?
* todo: check isVanillaMod & 2x isVanilla
*
* PlayerData::PlayerData CMOVNZ > CMOVZ -- Prefix (0f) discarded!!
* 45 f0 e8 12 e7 2f 01
* PlayerData::PlayerData changed how it does the achievement check with a null check for *(char *)(global + 0x310) i think..?
* 0f 84 35 07 00 00 48 81 c4 e8 26 00 00 -- jz > jnz
*
* SteamContext::setStat jz > jmp
* 74 2d ?? ?? ?? ?? 48 8b 10 80 7a 3e 00 74 17 80 7a 40 00 74 11 80 7a
* -> maybe patched by return in 0x0129b7c0 - todo: check that.. somehow..
*
* SteamContext::unlockAchievement jz > jmp
* 74 29 48 8b 10 80 7a 3e 00 74 17
* -> maybe patched by return in 0x013a31d0 - todo: check that.. somehow..
*
* AchievementGui::allowed (map) jnz > jmp
* 75 86 80 bb ef 01 00 00 00 0f 85 79 ff ff ff
* AchievementGui::allowed (map) jz > jmp
* 74 17 48 83 78 20 00 74 10
* 74 10 31 c0 5b 41 5c 41 5d 41 5e
*/

// TODO: Implement placeholders for the patterns
std::unordered_map<std::string, std::vector<uint8_t>> patternsToJNZ {
{"SteamContext::onUserStatsReceived", {0x74, 0x73, 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b, 0x10}},
{"AchievementGui::AchievementGui", {0x84, 0x8a, 0x03, 0x00, 0x00, 0x0f, 0x1f, 0x44, 0x00}}
std::unordered_map<std::string, std::vector<uint8_t>> patternsJZToJNZ {
{"SteamContext::onUserStatsReceived", { 0x74, 0x1F, 0xB9, 0x5B, 0x56, 0xD4, 0x00, 0xBA }},
{"PlayerData::PlayerData", {0x84, 0x35, 0x07, 0x00, 0x00, 0x48, 0x81, 0xc4, 0xe8, 0x26, 0x00, 0x00}} //prefix discarded
};

std::unordered_map<std::string, std::vector<uint8_t>> patternsToJMPFromJNZ {
{"AchievementGui::allowed", {0x75, 0x86, 0x80, 0xbb, 0xef, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x85, 0x79, 0xff, 0xff, 0xff}}
{"AchievementGui::updateModdedLabel", {0x75, 0x5b, 0x55, 0x45, 0x31, 0xC0, 0x45, 0x31}},
};

std::unordered_map<std::string, std::vector<uint8_t>> patternsToJMP {
std::unordered_map<std::string, std::vector<uint8_t>> patternsJZToJMP {
{"SteamContext::setStat", {0x74, 0x2d, 0x0f, 0x1f, 0x40, 0x00, 0x48, 0x8b, 0x10, 0x80, 0x7a, 0x3e, 0x00, 0x74, 0x17, 0x80, 0x7a, 0x40, 0x00, 0x74, 0x11, 0x80, 0x7a}},
{"SteamContext::unlockAchievement", {0x74, 0x29, 0x48, 0x8b, 0x10, 0x80, 0x7a, 0x3e, 0x00, 0x74, 0x17}}
{"SteamContext::unlockAchievement", {0x74, 0x29, 0x48, 0x8b, 0x10, 0x80, 0x7a, 0x3e, 0x00, 0x74, 0x17}},
//{"AchievementGui::allowed", {0x74, 0x17, 0x48, 0x83, 0x78, 0x20, 0x00, 0x74, 0x10}},
{"AchievementGui::allowed", {0x74, 0x10, 0x31, 0xc0, 0x5b, 0x41, 0x5c, 0x41, 0x5d, 0x41, 0x5e}},
};

std::unordered_map<std::string, std::vector<uint8_t>> patternsToCMOVZ {
{"PlayerData::PlayerData", {0x45, 0xf0, 0xe8, 0x12, 0xe7, 0x2f, 0x01}}
//{"PlayerData::PlayerData", {0x45, 0xf0, 0xe8, 0x12, 0xe7, 0x2f, 0x01}}
};

//Usage Example: ./FAE_Linux /home/senpaii/steamdrives/nvme1/SteamLibrary/steamapps/common/Factorio/bin/x64/factorio
Expand Down Expand Up @@ -92,12 +105,12 @@ int main(int argc, char *argv[]) {
// I have a slight suspicion that this can be moved into a loop

Log::LogF("Patching instructions to JNZ..\n");
for (auto &patternPair: patternsToJNZ) {
for (auto &patternPair: patternsJZToJNZ) {
doPatching(factorioFilePath, patternPair, 0);
}

Log::LogF("Patching instructions to JMP from JZ..\n");
for (auto &patternPair: patternsToJMP) {
for (auto &patternPair: patternsJZToJMP) {
doPatching(factorioFilePath, patternPair, 1);
}

Expand Down

0 comments on commit 650db40

Please sign in to comment.