Skip to content

Commit

Permalink
Allow specifying an offset to the next instruction when calling Patte…
Browse files Browse the repository at this point in the history
…rnSearchResult::abs() method
  • Loading branch information
danielkrupinski committed May 30, 2024
1 parent e99390f commit e6385fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 1 addition & 5 deletions Source/MemoryPatterns/Linux/ClientPatternsLinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ struct ClientPatterns {

[[nodiscard]] cs2::CCSPlayerController** localPlayerController() const noexcept
{
// fixme: add support for abs(offset)
const auto result = patternFinders.clientPatternFinder("48 83 3D ? ? ? ? ? 0F 95 C0 C3"_pat).add(3).abs().template as<std::byte*>();
if (result)
return reinterpret_cast<cs2::CCSPlayerController**>(result + 1);
return nullptr;
return patternFinders.clientPatternFinder("48 83 3D ? ? ? ? ? 0F 95 C0 C3"_pat).add(3).abs(5).template as<cs2::CCSPlayerController**>();
}
};
5 changes: 3 additions & 2 deletions Source/MemorySearch/PatternSearchResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ class PatternSearchResult {
return *this;
}

[[nodiscard]] GenericPointer abs() const noexcept
[[nodiscard]] GenericPointer abs(std::size_t offsetToNextInstruction = 4) const noexcept
{
if (base) {
using OffsetType = std::int32_t;
OffsetType offset;
assert(offsetToNextInstruction >= sizeof(OffsetType));
assert(foundPatternBytes.size() - extraOffset >= sizeof(OffsetType));
std::memcpy(&offset, foundPatternBytes.data() + extraOffset, sizeof(OffsetType));
return base.as<const std::byte*>() + patternFoundOffset + extraOffset + sizeof(OffsetType) + offset;
return base.as<const std::byte*>() + patternFoundOffset + extraOffset + offsetToNextInstruction + offset;
}
return {};
}
Expand Down

0 comments on commit e6385fc

Please sign in to comment.