Skip to content

Commit 9c51902

Browse files
committed
linting fixups
1 parent 587cf37 commit 9c51902

File tree

10 files changed

+26
-31
lines changed

10 files changed

+26
-31
lines changed

src/unrealsdk/game/bl2/antidebug.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,9 @@ typedef NTSTATUS(WINAPI* NtQueryInformationProcess_func)(HANDLE ProcessHandle,
2222
ULONG ProcessInformationLength,
2323
PULONG ReturnLength);
2424

25-
#if defined(__clang__)
26-
#pragma clang diagnostic push
27-
#pragma clang diagnostic ignored "-Wenum-constexpr-conversion"
28-
#endif
29-
30-
constexpr auto ThreadHideFromDebugger = static_cast<THREAD_INFORMATION_CLASS>(17);
31-
constexpr auto ProcessDebugObjectHandle = static_cast<PROCESSINFOCLASS>(30);
32-
33-
#if defined(__clang__)
34-
#pragma clang diagnostic pop
35-
#endif
25+
// These are undocumented values, not in the header, treat as size_t to avoid enum conversion errors
26+
constexpr size_t ThreadHideFromDebugger = 17;
27+
constexpr size_t ProcessDebugObjectHandle = 30;
3628

3729
// NOLINTEND(readability-identifier-naming)
3830

@@ -43,7 +35,7 @@ NTSTATUS NTAPI NtSetInformationThread_hook(HANDLE ThreadHandle,
4335
PVOID ThreadInformation,
4436
ULONG ThreadInformationLength) {
4537
// NOLINTEND(readability-identifier-naming)
46-
if (ThreadInformationClass == ThreadHideFromDebugger) {
38+
if (static_cast<size_t>(ThreadInformationClass) == ThreadHideFromDebugger) {
4739
return STATUS_SUCCESS;
4840
}
4941

@@ -61,7 +53,7 @@ NTSTATUS WINAPI NtQueryInformationProcess_hook(HANDLE ProcessHandle,
6153
ULONG ProcessInformationLength,
6254
PULONG ReturnLength) {
6355
// NOLINTEND(readability-identifier-naming)
64-
if (ProcessInformationClass == ProcessDebugObjectHandle) {
56+
if (static_cast<size_t>(ProcessInformationClass) == ProcessDebugObjectHandle) {
6557
return STATUS_PORT_NOT_SET;
6658
}
6759

src/unrealsdk/game/selector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ using all_known_games = std::tuple<BL2Hook, TPSHook>;
3737
* @tparam i Index of the game class being tested this iteration. Picked up automatically.
3838
* @param executable The executable name to match against.
3939
*/
40-
template <int i = 0>
40+
template <size_t i = 0>
4141
std::unique_ptr<AbstractHook> find_correct_hook(std::string_view executable) {
4242
if constexpr (i >= std::tuple_size_v<all_known_games>) {
4343
throw std::runtime_error("Failed to find compatible game hook!");

src/unrealsdk/hook_manager.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace {
8989
thread_local bool should_inject_next_call = false;
9090

9191
bool should_log_all_calls = false;
92-
std::unique_ptr<std::wostream> log_all_calls_stream;
92+
std::wofstream log_all_calls_stream{};
9393
std::mutex log_all_calls_stream_mutex{};
9494

9595
std::unordered_map<FName, utils::StringViewMap<std::wstring, List>> hooks{};
@@ -98,17 +98,17 @@ void log_all_calls(bool should_log) {
9898
// Only keep this file stream open while we need it
9999
if (should_log) {
100100
const std::lock_guard<std::mutex> lock(log_all_calls_stream_mutex);
101-
log_all_calls_stream = std::make_unique<std::wofstream>(
101+
log_all_calls_stream.open(
102102
utils::get_this_dll().parent_path()
103103
/ config::get_str("unrealsdk.log_all_calls_file").value_or("unrealsdk.calls.tsv"),
104-
std::ofstream::trunc);
104+
std::wofstream::trunc);
105105
}
106106

107107
should_log_all_calls = should_log;
108108

109109
if (!should_log) {
110110
const std::lock_guard<std::mutex> lock(log_all_calls_stream_mutex);
111-
log_all_calls_stream = nullptr;
111+
log_all_calls_stream.close();
112112
}
113113
}
114114

@@ -219,11 +219,14 @@ const List* preprocess_hook(std::wstring_view source, const UFunction* func, con
219219
std::wstring func_name{};
220220

221221
if (should_log_all_calls) {
222-
func_name = func->get_path_name();
223-
auto obj_name = obj->get_path_name();
222+
// Extra safety check
223+
if (log_all_calls_stream.is_open()) {
224+
func_name = func->get_path_name();
225+
auto obj_name = obj->get_path_name();
224226

225-
const std::lock_guard<std::mutex> lock(log_all_calls_stream_mutex);
226-
*log_all_calls_stream << source << L'\t' << func_name << L'\t' << obj_name << L'\n';
227+
const std::lock_guard<std::mutex> lock(log_all_calls_stream_mutex);
228+
log_all_calls_stream << source << L'\t' << func_name << L'\t' << obj_name << L'\n';
229+
}
227230
}
228231

229232
// Check if anything matches the function FName

src/unrealsdk/unreal/structs/fname.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ FName::operator std::wstring() const {
7070
return stream.str();
7171
}
7272

73-
FName operator"" _fn(const wchar_t* str, size_t /*len*/) {
73+
FName operator""_fn(const wchar_t* str, size_t /*len*/) {
7474
return FName{str};
7575
}
7676

src/unrealsdk/unreal/structs/fname.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct FName {
6363
* @param str The string to create a name of.
6464
* @param len The length of the string.
6565
*/
66-
FName operator"" _fn(const wchar_t* str, size_t len);
66+
FName operator""_fn(const wchar_t* str, size_t len);
6767

6868
} // namespace unrealsdk::unreal
6969

src/unrealsdk/unreal/structs/gnames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bool FNameEntry::is_wide(void) const {
1111
#ifdef UE4
1212

1313
FNameEntry* TStaticIndirectArrayThreadSafeRead_FNameEntry::at(size_t idx) const {
14-
if (idx >= (size_t)this->Count) {
14+
if (std::cmp_greater_equal(idx, this->Count)) {
1515
throw std::out_of_range("FNameEntry index out of range");
1616
}
1717
// NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic,

src/unrealsdk/unreal/structs/gobjects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace unrealsdk::unreal {
77
#ifdef UE4
88

99
FUObjectItem* FChunkedFixedUObjectArray::at(size_t idx) const {
10-
if (idx >= (size_t)this->Count) {
10+
if (std::cmp_greater_equal(idx, this->Count)) {
1111
throw std::out_of_range("FChunkedFixedUObjectArray index out of range");
1212
}
1313
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)

src/unrealsdk/unreal/structs/tpersistentobjectptr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ template <typename T>
1717
const TPersistentObjectPtr<T>* get_addr_from(const UObject* obj,
1818
const UObjectProperty* prop,
1919
size_t idx) {
20-
if (idx >= (size_t)prop->ArrayDim) {
20+
if (std::cmp_greater_equal(idx, prop->ArrayDim)) {
2121
throw std::out_of_range("Property index out of range");
2222
}
2323

@@ -29,7 +29,7 @@ template <typename T>
2929
const TPersistentObjectPtr<T>* get_addr_from(const WrappedStruct& wrapped_struct,
3030
const UObjectProperty* prop,
3131
size_t idx) {
32-
if (idx >= (size_t)prop->ArrayDim) {
32+
if (std::cmp_greater_equal(idx, prop->ArrayDim)) {
3333
throw std::out_of_range("Property index out of range");
3434
}
3535

@@ -44,7 +44,7 @@ const TPersistentObjectPtr<T>* get_addr_from_array(const WrappedArray& array, si
4444
throw std::invalid_argument("WrappedArray property was of invalid type "
4545
+ (std::string)array.type->Class->Name);
4646
}
47-
if (idx >= (size_t)array.base->count) {
47+
if (std::cmp_greater_equal(idx, array.base->count)) {
4848
throw std::out_of_range("WrappedArray index out of range");
4949
}
5050

src/unrealsdk/unreal/wrappers/gnames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ size_t GNames::size(void) const {
1515
}
1616

1717
FNameEntry* GNames::at(size_t idx) const {
18-
if (idx >= (size_t)this->internal->Count) {
18+
if (std::cmp_greater_equal(idx, this->internal->Count)) {
1919
throw std::out_of_range("GObjects index out of range");
2020
}
2121
return this->internal->at(idx);

src/unrealsdk/unreal/wrappers/gobjects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ size_t GObjects::size(void) const {
7777
}
7878

7979
UObject* GObjects::obj_at(size_t idx) const {
80-
if (idx >= (size_t)this->internal->ObjObjects.Count) {
80+
if (std::cmp_greater_equal(idx, this->internal->ObjObjects.Count)) {
8181
throw std::out_of_range("GObjects index out of range");
8282
}
8383
return this->internal->ObjObjects.at(idx)->Object;

0 commit comments

Comments
 (0)