Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
doyaGu committed Sep 19, 2024
1 parent 741f6f5 commit 82b40dc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
20 changes: 9 additions & 11 deletions src/HookUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#define BML_HOOKUTILS_H

#include <cstdint>
#include <cassert>
#include <cstring>

namespace utils {
void OutputDebugA(const char *format, ...);
Expand All @@ -21,7 +19,7 @@ namespace utils {

template<typename T>
T ForceReinterpretCast(void *base, size_t offset) {
void *p = reinterpret_cast<char *>(base) + offset;
void *p = static_cast<char *>(base) + offset;
return *reinterpret_cast<T *>(&p);
}

Expand All @@ -35,16 +33,16 @@ namespace utils {

inline void **GetVTable(void *instance) {
if (instance) {
return *reinterpret_cast<void ***>(instance);
return *static_cast<void ***>(instance);
} else {
return nullptr;
}
}

template<typename T>
inline void LoadVTable(void *instance, T &table) {
void LoadVTable(void *instance, T &table) {
if (instance) {
void **src = reinterpret_cast<void**>(*reinterpret_cast<void**>(instance));
void **src = static_cast<void**>(*static_cast<void**>(instance));
void **dest = reinterpret_cast<void**>(&table);
for (size_t i = 0; i < sizeof(T) / sizeof(void *); ++i) {
dest[i] = src[i];
Expand All @@ -53,22 +51,22 @@ namespace utils {
}

template<typename T>
inline void SaveVTable(void *instance, T &table) {
void SaveVTable(void *instance, T &table) {
if (instance) {
void **src = reinterpret_cast<void**>(&table);
void **dest = reinterpret_cast<void**>(*reinterpret_cast<void**>(instance));
uint32_t originalProtection = UnprotectRegion((void *) dest, sizeof(T));
void **dest = static_cast<void**>(*static_cast<void**>(instance));
uint32_t originalProtection = UnprotectRegion(dest, sizeof(T));
for (size_t i = 0; i < sizeof(T) / sizeof(void *); ++i) {
dest[i] = src[i];
}
ProtectRegion((void *) dest, sizeof(T), originalProtection);
ProtectRegion(dest, sizeof(T), originalProtection);
}
}

void *HookVirtualMethod(void *instance, void *hook, size_t offset);

template<typename T>
inline void *HookVirtualMethod(void *instance, T hook, size_t offset) {
void *HookVirtualMethod(void *instance, T hook, size_t offset) {
return HookVirtualMethod(instance, TypeErase<T>(hook), offset);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/ScriptHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "BML/ScriptHelper.h"

#include "BML/Defines.h"

namespace ScriptHelper {
bool FindBB(CKBehavior *script, std::function<bool(CKBehavior *)> callback, const char *name, bool hierarchically,
int inputCnt, int outputCnt, int inputParamCnt, int outputParamCnt) {
Expand Down
3 changes: 3 additions & 0 deletions src/StringUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "StringUtils.h"

#include <cctype>
#include <cwctype>

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/StringUtils.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef BML_STRINGUTILS_H
#define BML_STRINGUTILS_H

#include <cctype>
#include <cwctype>
#include <string>
#include <vector>

Expand Down

0 comments on commit 82b40dc

Please sign in to comment.