Skip to content

Commit

Permalink
maint: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
diamante0018 committed Oct 30, 2023
1 parent 7f2683e commit 9407529
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 84 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- Release
steps:
- name: Check out files
uses: actions/checkout@v3.5.2
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
Expand All @@ -44,7 +44,7 @@ jobs:
run: msbuild /m /v:minimal /p:Configuration=${{matrix.configuration}} /p:Platform=Win32 build/black-ops-plugin.sln

- name: Upload ${{matrix.configuration}} binaries
uses: actions/upload-artifact@v3.1.2
uses: actions/upload-artifact@v3.1.3
with:
name: ${{matrix.configuration}} binaries
path: |
Expand Down
2 changes: 0 additions & 2 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ targetname "black-ops-plugin"
pchheader "std_include.hpp"
pchsource "src/client/std_include.cpp"

linkoptions {"/IGNORE:4254", "/PDBCompress"}

files {"./src/client/**.hpp", "./src/client/**.cpp"}

includedirs {"./src/client", "./src/common", "%{prj.location}/src"}
Expand Down
4 changes: 2 additions & 2 deletions src/client/component/command_additions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class component final : public component_interface {
game::select(0x355E69C, 0x243FB1C));
cmd_vstr_f_var->function = cmd_vstr_f;

if (game::environment::is_sp()) {
if (game::environment::is_sp()) {
// Fix (client) crash from SV_DropClient (server side)
utils::hook::set<std::uint8_t>(0x634C1D, 0xEB);
}
}
}
};
} // namespace command_additions
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/cryptography.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include "cryptography.hpp"

namespace jenkins_one_at_a_time {
unsigned int jenkins_one_at_a_time::compute(const std::string& data) {
unsigned int compute(const std::string& data) {
return compute(data.data(), data.size());
}

unsigned int jenkins_one_at_a_time::compute(const char* key, const size_t len) {
unsigned int compute(const char* key, const size_t len) {
unsigned int hash, i;
for (hash = i = 0; i < len; ++i) {
hash += key[i];
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/info_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class info_string {
info_string(const std::string_view& buffer);

void set(const std::string& key, const std::string& value);
std::string get(const std::string& key) const;
std::string build() const;
[[nodiscard]] std::string get(const std::string& key) const;
[[nodiscard]] std::string build() const;

private:
std::unordered_map<std::string, std::string> key_value_pairs_{};
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool read_file(const std::string& file, std::string* data) {
stream.seekg(0, std::ios::beg);

if (size > -1) {
data->resize(static_cast<uint32_t>(size));
data->resize(static_cast<std::size_t>(size));
stream.read(data->data(), size);
stream.close();
return true;
Expand Down
12 changes: 6 additions & 6 deletions src/common/utils/nt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library library::load(const std::string& name) {
}

library library::load(const std::filesystem::path& path) {
return library::load(path.generic_string());
return load(path.generic_string());
}

library library::get_by_address(void* address) {
Expand Down Expand Up @@ -98,7 +98,7 @@ bool library::is_valid() const {

std::string library::get_name() const {
if (!this->is_valid())
return "";
return {};

auto path = this->get_path();
const auto pos = path.find_last_of("/\\");
Expand All @@ -110,17 +110,17 @@ std::string library::get_name() const {

std::string library::get_path() const {
if (!this->is_valid())
return "";
return {};

char name[MAX_PATH] = {0};
char name[MAX_PATH]{};
GetModuleFileNameA(this->module_, name, sizeof name);

return name;
}

std::string library::get_folder() const {
if (!this->is_valid())
return "";
return {};

const auto path = std::filesystem::path(this->get_path());
return path.parent_path().generic_string();
Expand Down Expand Up @@ -221,7 +221,7 @@ void relaunch_self() {
ZeroMemory(&process_info, sizeof(process_info));
startup_info.cb = sizeof(startup_info);

char current_dir[MAX_PATH];
char current_dir[MAX_PATH]{};
GetCurrentDirectoryA(sizeof(current_dir), current_dir);
auto* const command_line = GetCommandLineA();

Expand Down
34 changes: 17 additions & 17 deletions src/common/utils/nt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ class library final {
bool operator!=(const library& obj) const { return !(*this == obj); };
bool operator==(const library& obj) const;

operator bool() const;
operator HMODULE() const;
[[nodiscard]] operator bool() const;
[[nodiscard]] operator HMODULE() const;

void unprotect() const;
void* get_entry_point() const;
size_t get_relative_entry_point() const;

bool is_valid() const;
std::string get_name() const;
std::string get_path() const;
std::string get_folder() const;
std::uint8_t* get_ptr() const;
[[nodiscard]] void* get_entry_point() const;
[[nodiscard]] size_t get_relative_entry_point() const;

[[nodiscard]] bool is_valid() const;
[[nodiscard]] std::string get_name() const;
[[nodiscard]] std::string get_path() const;
[[nodiscard]] std::string get_folder() const;
[[nodiscard]] std::uint8_t* get_ptr() const;
void free();

HMODULE get_handle() const;
[[nodiscard]] HMODULE get_handle() const;

template <typename T> T get_proc(const std::string& process) const {
if (!this->is_valid())
Expand Down Expand Up @@ -85,14 +85,14 @@ class library final {
return T();
}

std::vector<PIMAGE_SECTION_HEADER> get_section_headers() const;
[[nodiscard]] std::vector<PIMAGE_SECTION_HEADER> get_section_headers() const;

PIMAGE_NT_HEADERS get_nt_headers() const;
PIMAGE_DOS_HEADER get_dos_header() const;
PIMAGE_OPTIONAL_HEADER get_optional_header() const;
[[nodiscard]] PIMAGE_NT_HEADERS get_nt_headers() const;
[[nodiscard]] PIMAGE_DOS_HEADER get_dos_header() const;
[[nodiscard]] PIMAGE_OPTIONAL_HEADER get_optional_header() const;

void** get_iat_entry(const std::string& module_name,
const std::string& proc_name) const;
[[nodiscard]] void** get_iat_entry(const std::string& module_name,
const std::string& proc_name) const;

private:
HMODULE module_;
Expand Down
45 changes: 0 additions & 45 deletions src/common/utils/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,51 +93,6 @@ std::string get_clipboard_data() {
return {};
}

void strip(const char* in, char* out, size_t max) {
if (!in || !out)
return;

max--;
size_t current = 0;
while (*in != 0 && current < max) {
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);

if (*in == '^' && (color_index != 7 || *(in + 1) == '7')) {
++in;
} else {
*out = *in;
++out;
++current;
}

++in;
}

*out = '\0';
}

std::string convert(const std::wstring& wstr) {
std::string result;
result.reserve(wstr.size());

for (const auto& chr : wstr) {
result.push_back(static_cast<char>(chr));
}

return result;
}

std::wstring convert(const std::string& str) {
std::wstring result;
result.reserve(str.size());

for (const auto& chr : str) {
result.push_back(static_cast<wchar_t>(chr));
}

return result;
}

std::string replace(std::string str, const std::string& from,
const std::string& to) {
if (from.empty()) {
Expand Down
5 changes: 0 additions & 5 deletions src/common/utils/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ std::string dump_hex(const std::string& data,

std::string get_clipboard_data();

void strip(const char* in, char* out, size_t max);

std::string convert(const std::wstring& wstr);
std::wstring convert(const std::string& str);

std::string replace(std::string str, const std::string& from,
const std::string& to);
} // namespace utils::string

0 comments on commit 9407529

Please sign in to comment.