Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
further refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shevernitskiy committed Jul 13, 2023
1 parent 2eb44cd commit e08ab51
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ BasedOnStyle: Mozilla
IndentWidth: 2
AlignAfterOpenBracket: true
AlignOperands: true
AlignConsecutiveMacros: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortEnumsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: WithoutElse
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
BinPackArguments: true
Expand Down
24 changes: 8 additions & 16 deletions src/hook/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ namespace Hooks {
// swap texture of specific char in chosen screen matrix (main/top)
template <auto T>
void InjectTTFChar(unsigned char symbol, int x, int y) {
if (ttf_injection_lock)
return;
if (ttf_injection_lock) return;

auto tile = ScreenManager::GetSingleton()->GetTile<T>(x, y);

Expand Down Expand Up @@ -583,18 +582,15 @@ namespace Hooks {
--bracket_count;
continue;
}
if (bracket_count > 0)
continue;
if (bracket_count > 0) continue;
conf = false;
if (s > 0) {
if (str[s - 1] == ' ' || str[s - 1] == '\"')
conf = true;
if (str[s - 1] == ' ' || str[s - 1] == '\"') conf = true;
if (str[s - 1] == '\'') {
if (s <= 0)
conf = true;
else if (s >= 2) {
if (str[s - 2] == ' ' || str[s - 2] == ',')
conf = true;
if (str[s - 2] == ' ' || str[s - 2] == ',') conf = true;
}
}
}
Expand All @@ -617,25 +613,21 @@ namespace Hooks {
--bracket_count;
continue;
}
if (bracket_count > 0)
continue;
if (bracket_count > 0) continue;
conf = false;
if (s > 0) {
if (str[s - 1] == ' ' || str[s - 1] == '\"')
conf = true;
if (str[s - 1] == ' ' || str[s - 1] == '\"') conf = true;
if (str[s - 1] == '\'') {
if (s <= 0)
conf = true;
else if (s >= 2) {
if (str[s - 2] == ' ' || str[s - 2] == ',')
conf = true;
if (str[s - 2] == ' ' || str[s - 2] == ',') conf = true;
}
}
}
if (s == 0 || conf) {
UpperCast(str[s], true);
if (str[s] != ' ' && str[s] != '\"')
return;
if (str[s] != ' ' && str[s] != '\"') return;
}
}
}
Expand Down
30 changes: 12 additions & 18 deletions src/hook/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,12 @@ namespace Hooks {
float br, bg, bb;

bool operator<(const struct texture_fullid& other) const {
if (texpos != other.texpos)
return texpos < other.texpos;
if (r != other.r)
return r < other.r;
if (g != other.g)
return g < other.g;
if (b != other.b)
return b < other.b;
if (br != other.br)
return br < other.br;
if (bg != other.bg)
return bg < other.bg;
if (texpos != other.texpos) return texpos < other.texpos;
if (r != other.r) return r < other.r;
if (g != other.g) return g < other.g;
if (b != other.b) return b < other.b;
if (br != other.br) return br < other.br;
if (bg != other.bg) return bg < other.bg;
return bb < other.bb;
}
};
Expand All @@ -136,13 +130,13 @@ namespace Hooks {
inline auto module_handle = reinterpret_cast<uintptr_t>(GetModuleHandle(0));

#define SETUP_ORIG_FUNC_OFFSET(fn_name, shift) auto fn_name##_orig = reinterpret_cast<fn_name>(module_handle + shift);
#define SETUP_ORIG_FUNC(fn_name) auto fn_name##_orig = reinterpret_cast<fn_name>(module_handle + Config::Offset::fn_name);
#define SETUP_ORIG_FUNC(fn_name) auto fn_name##_orig = reinterpret_cast<fn_name>(module_handle + Config::Offset::fn_name);
#define SETUP_ORIG_FUNC_FNAME(fn_name, module_name) \
auto fn_name##_orig = reinterpret_cast<fn_name>(GetProcAddress(GetModuleHandle(#module_name), #fn_name));
#define GET_ADDR(shift) reinterpret_cast<void*>(module_handle + shift)
#define ATTACH(fn_name) DetourAttach(&(reinterpret_cast<void*&>(fn_name##_orig)), (void*)fn_name##_hook);
#define DETACH(fn_name) DetourDetach(&(reinterpret_cast<void*&>(fn_name##_orig)), (void*)fn_name##_hook);
#define HOOK(fn_name) fn_name##_hook
#define GET_ADDR(shift) reinterpret_cast<void*>(module_handle + shift)
#define ATTACH(fn_name) DetourAttach(&(reinterpret_cast<void*&>(fn_name##_orig)), (void*)fn_name##_hook);
#define DETACH(fn_name) DetourDetach(&(reinterpret_cast<void*&>(fn_name##_orig)), (void*)fn_name##_hook);
#define HOOK(fn_name) fn_name##_hook
#define ORIGINAL(fn_name) fn_name##_orig

// translation
Expand All @@ -159,7 +153,7 @@ namespace Hooks {

// search
typedef int(__fastcall* standardstringentry)(std::string& str, int maxlen, unsigned int flag, std::set<InterfaceKey>& events,
uint16_t* utf);
const uint32_t* utf);
typedef void(__fastcall* upper_case_string)(std::string& str);
typedef void(__fastcall* simplify_string)(std::string& str);
typedef void(__fastcall* lower_case_string)(std::string& str);
Expand Down
10 changes: 5 additions & 5 deletions src/hook/keybindings.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#define STRINGENTRY_LETTERS 1
#define STRINGENTRY_SPACE 2
#define STRINGENTRY_NUMBERS 4
#define STRINGENTRY_CAPS 8
#define STRINGENTRY_SYMBOLS 16
#define STRINGENTRY_LETTERS 1
#define STRINGENTRY_SPACE 2
#define STRINGENTRY_NUMBERS 4
#define STRINGENTRY_CAPS 8
#define STRINGENTRY_SYMBOLS 16
#define STRINGENTRY_FILENAME 32

typedef long InterfaceKey;
Expand Down
26 changes: 6 additions & 20 deletions src/hook/screen_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,12 @@ class ScreenManager {

template <ScreenType screen_type>
ScreenTile* GetTile(int x, int y) {
if (screen_type == ScreenType::Top) {
return reinterpret_cast<ScreenTile*>(this->screen_top + x * this->dimy * 4 + y * 4);
} else {
return reinterpret_cast<ScreenTile*>(this->screen + x * this->dimy * 4 + y * 4);
}
return reinterpret_cast<ScreenTile*>((screen_type == ScreenType::Top ? this->screen_top : this->screen) + x * this->dimy * 4 + y * 4);
}

template <ScreenType screen_type>
ScreenTile* GetOffset(int offset) {
if (screen_type == ScreenType::Top) {
return reinterpret_cast<ScreenTile*>(this->screen_top + offset * 4);
} else {
return reinterpret_cast<ScreenTile*>(this->screen + offset * 4);
}
return reinterpret_cast<ScreenTile*>((screen_type == ScreenType::Top ? this->screen_top : this->screen) + offset * 4);
}

void AllocateScreen(int x, int y) {
Expand All @@ -49,17 +41,11 @@ class ScreenManager {

template <ScreenType screen_type>
void ClearScreen() {
if (screen_type == ScreenType::Top) {
if (this->screen_top != nullptr) {
delete[] this->screen_top;
}
this->screen_top = nullptr;
} else {
if (this->screen != nullptr) {
delete[] this->screen;
}
this->screen = nullptr;
auto& screen = screen_type == ScreenType::Top ? this->screen_top : this->screen;
if (screen != nullptr) {
delete[] screen;
}
screen = nullptr;
}

template <ScreenType screen_type>
Expand Down
1 change: 1 addition & 0 deletions src/pe_parser/pe_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <windows.h>

class PEParser {

public:
[[nodiscard]] static PEParser* GetSingleton() {
static PEParser singleton;
Expand Down

0 comments on commit e08ab51

Please sign in to comment.