mirror of
https://github.com/a2x/cs2-dumper.git
synced 2025-10-07 22:50:03 +08:00
Refactored code
This commit is contained in:
33
include/utility/address.hpp
Normal file
33
include/utility/address.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace utility {
|
||||
class Address {
|
||||
public:
|
||||
Address() noexcept = default;
|
||||
|
||||
explicit Address(const std::uintptr_t address) noexcept : address_(address) {}
|
||||
|
||||
[[nodiscard]] Address add(std::ptrdiff_t offset) const noexcept;
|
||||
|
||||
[[nodiscard]] std::uintptr_t address() const noexcept;
|
||||
|
||||
[[nodiscard]] Address get(std::size_t times = 1) const noexcept;
|
||||
|
||||
[[nodiscard]] bool is_valid() const noexcept;
|
||||
|
||||
[[nodiscard]] Address jmp(std::ptrdiff_t offset = 0x1) const noexcept;
|
||||
|
||||
[[nodiscard]] Address rip(std::ptrdiff_t offset = 0x3, std::size_t length = 7) const noexcept;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] T as() const noexcept {
|
||||
return reinterpret_cast<T>(address_);
|
||||
}
|
||||
|
||||
private:
|
||||
std::uintptr_t address_;
|
||||
};
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace utility {
|
||||
std::uint32_t murmur_hash2(const void* key, std::uint32_t length, std::uint32_t seed);
|
||||
}
|
22
include/utility/safe_handle.hpp
Normal file
22
include/utility/safe_handle.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#define _AMD64_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <handleapi.h>
|
||||
|
||||
namespace utility {
|
||||
namespace detail {
|
||||
struct HandleDisposer {
|
||||
using pointer = HANDLE;
|
||||
|
||||
void operator()(const HANDLE handle) const noexcept {
|
||||
if (handle != nullptr && handle != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(handle);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
using SafeHandle = std::unique_ptr<HANDLE, detail::HandleDisposer>;
|
||||
}
|
12
include/utility/string.hpp
Normal file
12
include/utility/string.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cctype>
|
||||
#include <string_view>
|
||||
|
||||
namespace utility::string {
|
||||
inline bool equals_ignore_case(const std::string_view str_1, const std::string_view str_2) noexcept {
|
||||
return (str_1.size() == str_2.size()) && std::equal(str_1.begin(), str_1.end(), str_2.begin(), [](const char a, const char b) {
|
||||
return std::tolower(a) == std::tolower(b);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user