-
Notifications
You must be signed in to change notification settings - Fork 6
bl1 / v2.0 fixups #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3a0c6d9
fix fframe step generating garbage
apple1417 0f61f39
only check params properties when validating delegate
apple1417 b12be19
fix __thiscall warning
apple1417 793b9ef
fix tps class interfaces offset
apple1417 7c36283
handle steam drm encrypting bl1 exe
apple1417 426a54a
swap to release with debug info
apple1417 aaea6ab
fix spelling
apple1417 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,3 @@ | ||
|
|
||
| // - NOTE - | ||
| // Copied from bl2/antidebug.cpp | ||
| // | ||
|
|
||
| #include "unrealsdk/pch.h" | ||
|
|
||
| #include "unrealsdk/game/bl1/bl1.h" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #include "unrealsdk/pch.h" | ||
| #include "unrealsdk/game/bl1/bl1.h" | ||
| #include "unrealsdk/memory.h" | ||
| #include "unrealsdk/utils.h" | ||
|
|
||
| #if UNREALSDK_FLAVOUR == UNREALSDK_FLAVOUR_WILLOW && !defined(UNREALSDK_IMPORTING) | ||
|
|
||
| using namespace unrealsdk::utils; | ||
| using namespace unrealsdk::memory; | ||
|
|
||
| namespace unrealsdk::game { | ||
|
|
||
| namespace { | ||
|
|
||
| // This is ___tmainCRTStartup, so expect it's very stable | ||
| const constinit Pattern<14> UNPACKED_ENTRY_SIG{"6A 58 68 ?? ?? ?? ?? E8 ?? ?? ?? ?? 33 DB"}; | ||
|
|
||
| std::atomic<bool> ready = false; | ||
| std::mutex ready_mutex; | ||
| std::condition_variable ready_cv; | ||
|
|
||
| // This is probably orders of magnitude bigger than we need, but best be safe | ||
| const constexpr std::chrono::seconds FALLBACK_DELAY{5}; | ||
|
|
||
| // NOLINTBEGIN(readability-identifier-naming) | ||
|
|
||
| // NOLINTNEXTLINE(modernize-use-using) - need a typedef for calling conventions in msvc | ||
| typedef void(WINAPI* GetStatupInfoA_func)(LPSTARTUPINFOA); | ||
| GetStatupInfoA_func GetStatupInfoA_ptr; | ||
|
|
||
| void GetStartupInfoA_hook(LPSTARTUPINFOA lpStartupInfo) { | ||
| GetStatupInfoA_ptr(lpStartupInfo); | ||
|
|
||
| static_assert(decltype(ready)::is_always_lock_free, "need to lock on checking ready flag too"); | ||
| if (ready.load()) { | ||
| return; | ||
| } | ||
|
|
||
| const std::lock_guard<std::mutex> lock{ready_mutex}; | ||
| ready.store(true); | ||
| ready_cv.notify_all(); | ||
| } | ||
|
|
||
| // NOLINTEND(readability-identifier-naming) | ||
|
|
||
| } // namespace | ||
|
|
||
| void BL1Hook::wait_for_steam_drm(void) { | ||
| { | ||
| // Immediately suspend the other threads | ||
| const ThreadSuspender suspend{}; | ||
|
|
||
| if (UNPACKED_ENTRY_SIG.sigscan_nullable() != 0) { | ||
| // If we found a match, we're already unpacked | ||
| return; | ||
| } | ||
|
|
||
| LOG(MISC, "Waiting for steam drm unpack"); | ||
|
|
||
| // Set up a hook for GetStartupInfoA, which is the one of the first things the unpacked | ||
| // entry function calls, which we'll use to tell once it's been unpacked | ||
| MH_STATUS status = MH_OK; | ||
|
|
||
| status = MH_CreateHook(reinterpret_cast<LPVOID>(&GetStartupInfoA), | ||
| reinterpret_cast<LPVOID>(&GetStartupInfoA_hook), | ||
| reinterpret_cast<LPVOID*>(&GetStatupInfoA_ptr)); | ||
| if (status != MH_OK) { | ||
| LOG(ERROR, "Failed to create GetStartupInfoA hook: {:x}", | ||
| static_cast<uint32_t>(status)); | ||
|
|
||
| LOG(ERROR, "Falling back to a static delay"); | ||
| std::this_thread::sleep_for(FALLBACK_DELAY); | ||
| return; | ||
| } | ||
|
|
||
| status = MH_EnableHook(reinterpret_cast<LPVOID>(&GetStartupInfoA)); | ||
| if (status != MH_OK) { | ||
| LOG(ERROR, "Failed to enable GetStartupInfoA hook: {:x}", | ||
| static_cast<uint32_t>(status)); | ||
|
|
||
| LOG(ERROR, "Falling back to a static delay"); | ||
| std::this_thread::sleep_for(FALLBACK_DELAY); | ||
| return; | ||
| } | ||
|
|
||
| // Drop out of this scope and unsuspend the other threads, let the unpacker run | ||
| } | ||
|
|
||
| std::unique_lock lock(ready_mutex); | ||
| ready_cv.wait(lock, [] { return ready.load(); }); | ||
|
|
||
| MH_STATUS status = MH_OK; | ||
| status = MH_DisableHook(reinterpret_cast<LPVOID>(&GetStartupInfoA)); | ||
| if (status != MH_OK) { | ||
| LOG(ERROR, "Failed to disable GetStartupInfoA hook: {:x}", static_cast<uint32_t>(status)); | ||
|
|
||
| // If it fails, there isn't really any harm in leaving it active, just return | ||
| return; | ||
| } | ||
|
|
||
| status = MH_RemoveHook(reinterpret_cast<LPVOID>(&GetStartupInfoA)); | ||
| if (status != MH_OK) { | ||
| LOG(ERROR, "Failed to remove GetStartupInfoA hook: {:x}", static_cast<uint32_t>(status)); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| } // namespace unrealsdk::game | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for the duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disable vs remove? those aren't the same thing, best to clean up properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, i'm blind just assumed they were both remove lol