Skip to content

Commit

Permalink
Enforce clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamashi committed Dec 10, 2022
1 parent e2764cd commit 59ded2e
Show file tree
Hide file tree
Showing 114 changed files with 15,324 additions and 13,083 deletions.
44 changes: 17 additions & 27 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
---
BasedOnStyle: Microsoft
---
Language: Cpp

BasedOnStyle: LLVM
AccessModifierOffset: -4
AlwaysBreakTemplateDeclarations: Yes
AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlines: Left
AlignOperands: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortLambdasOnASingleLine: Inline
BraceWrapping:
AfterCaseLabel: true
IndentBraces: true
BreakBeforeBraces: Allman
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: Inner
ColumnLimit: 180
IndentWidth: 4
PenaltyBreakFirstLessLess: 180
PointerAlignment: Left
SpaceAfterTemplateKeyword: false

BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
SortIncludes: Never
SpaceBeforeParensOptions:
AfterControlStatements: false
35 changes: 35 additions & 0 deletions clang_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import time
import subprocess

def format_cpp_file(file_path, clang_format_path):
# Run clang-format on the file to format it
subprocess.run(["clang-format", "-i", file_path, "-style=file:" + clang_format_path, "-fallback-style=none"])

def recursive_directory_iteration(directory, clang_format_path):
# Iterate over all of the files in the directory
for filename in os.listdir(directory):
# Get the full path of the file
file_path = os.path.join(directory, filename)

# If the file is a directory, recursively iterate over it
if os.path.isdir(file_path):
recursive_directory_iteration(file_path, clang_format_path)
# If the file is a cpp file, format it
elif file_path.endswith(".cpp") or file_path.endswith(".h") or file_path.endswith(".hpp"):
format_cpp_file(file_path, clang_format_path)

print("Formatting C++ files...")

path = os.getcwd() + "\\.clang-format"
if not os.path.exists(path):
print("Could not find clang format config at " + path)
exit()

print("Found clang format config at " + path)

start_time = time.time()
# Start the recursive iteration from the current directory
recursive_directory_iteration(os.getcwd() + "/src", path)

print("Done formatting C++ files after " + str(time.time() - start_time) + " seconds")
2 changes: 1 addition & 1 deletion src/CET.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using namespace std::chrono_literals;

static std::unique_ptr<CET> s_pInstance{ nullptr };
static std::unique_ptr<CET> s_pInstance{nullptr};
static bool s_isRunning{true};

void CET::Initialize()
Expand Down
1 change: 0 additions & 1 deletion src/CET.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct CET
static bool IsRunning() noexcept;

private:

CET();

Paths m_paths;
Expand Down
11 changes: 5 additions & 6 deletions src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

struct PdbInfo
{
DWORD Signature;
BYTE Guid[16];
DWORD Age;
char PdbFileName[1];
DWORD Signature;
BYTE Guid[16];
DWORD Age;
char PdbFileName[1];
};

struct ImageVersion
Expand Down Expand Up @@ -37,8 +37,7 @@ void Image::Initialize()
{{0xB0, 0x99, 0x3F, 0x8E, 0xB2, 0x57, 0x46, 0x41, 0xA3, 0x77, 0x3B, 0x98, 0x97, 0x15, 0xC4, 0xBB}, MakeVersion(1, 52)},
{{0x69, 0x41, 0x44, 0x27, 0xDB, 0x02, 0x65, 0x4B, 0xA5, 0x7F, 0x5B, 0x1C, 0xD6, 0x79, 0x94, 0x32}, MakeVersion(1, 52)}, // Exclusive steam patch
{{0x4E, 0xE9, 0x22, 0x2A, 0x9D, 0xB5, 0xC6, 0x40, 0xA7, 0xD4, 0xAB, 0x3B, 0xCA, 0x7C, 0x30, 0x06}, MakeVersion(1, 60)},
{{0x75, 0xF0, 0x99, 0xC1, 0x83, 0x84, 0xF9, 0x43, 0x95, 0x00, 0x4E, 0x7D, 0x93, 0x73, 0x84, 0xDF}, MakeVersion(1, 61)}
};
{{0x75, 0xF0, 0x99, 0xC1, 0x83, 0x84, 0xF9, 0x43, 0x95, 0x00, 0x4E, 0x7D, 0x93, 0x73, 0x84, 0xDF}, MakeVersion(1, 61)}};

mem::module mainModule = mem::module::main();

Expand Down
10 changes: 2 additions & 8 deletions src/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ struct Image
{
void Initialize();

static std::tuple<uint32_t, uint16_t> GetSupportedVersion() noexcept
{
return std::make_tuple(1, 61);
}
static std::tuple<uint32_t, uint16_t> GetSupportedVersion() noexcept { return std::make_tuple(1, 61); }

static uint64_t MakeVersion(const uint32_t acMajor, const uint16_t acMinor) noexcept
{
return static_cast<uint64_t>(acMajor) << 32 | static_cast<uint64_t>(acMinor) << 16;
}
static uint64_t MakeVersion(const uint32_t acMajor, const uint16_t acMinor) noexcept { return static_cast<uint64_t>(acMajor) << 32 | static_cast<uint64_t>(acMinor) << 16; }

[[nodiscard]] std::tuple<uint32_t, uint16_t> GetVersion() const noexcept
{
Expand Down
59 changes: 21 additions & 38 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ void PatchesSettings::Load(const nlohmann::json& aConfig)
nlohmann::json PatchesSettings::Save() const
{
return {
{"remove_pedestrians", RemovePedestrians},
{"disable_async_compute", AsyncCompute},
{"disable_antialiasing", Antialiasing},
{"skip_start_menu", SkipStartMenu},
{"amd_smt", AmdSmt},
{"disable_intro_movies", DisableIntroMovies},
{"disable_vignette", DisableVignette},
{"disable_boundary_teleport", DisableBoundaryTeleport},
{"disable_win7_vsync", DisableWin7Vsync},
{"minimap_flicker", MinimapFlicker},
{"remove_pedestrians", RemovePedestrians},
{"disable_async_compute", AsyncCompute},
{"disable_antialiasing", Antialiasing},
{"skip_start_menu", SkipStartMenu},
{"amd_smt", AmdSmt},
{"disable_intro_movies", DisableIntroMovies},
{"disable_vignette", DisableVignette},
{"disable_boundary_teleport", DisableBoundaryTeleport},
{"disable_win7_vsync", DisableWin7Vsync},
{"minimap_flicker", MinimapFlicker},
};
}

Expand All @@ -49,13 +49,7 @@ void FontSettings::Load(const nlohmann::json& aConfig)

nlohmann::json FontSettings::Save() const
{
return {
{"path", Path},
{"language", Language},
{"base_size", BaseSize},
{"oversample_horizontal", OversampleHorizontal},
{"oversample_vertical", OversampleVertical}
};
return {{"path", Path}, {"language", Language}, {"base_size", BaseSize}, {"oversample_horizontal", OversampleHorizontal}, {"oversample_vertical", OversampleVertical}};
}

void FontSettings::ResetToDefaults()
Expand All @@ -81,14 +75,8 @@ nlohmann::json DeveloperSettings::Save() const
// set global "Enable ImGui Assertions"
g_ImGuiAssertionsEnabled = EnableImGuiAssertions;

return {
{"remove_dead_bindings", RemoveDeadBindings},
{"enable_imgui_assertions", EnableImGuiAssertions},
{"enable_debug", EnableDebug},
{"dump_game_options", DumpGameOptions},
{"max_lines_console_history", MaxLinesConsoleHistory},
{"persistent_console", PersistentConsole}
};
return {{"remove_dead_bindings", RemoveDeadBindings}, {"enable_imgui_assertions", EnableImGuiAssertions}, {"enable_debug", EnableDebug},
{"dump_game_options", DumpGameOptions}, {"max_lines_console_history", MaxLinesConsoleHistory}, {"persistent_console", PersistentConsole}};
}

void DeveloperSettings::ResetToDefaults()
Expand All @@ -106,7 +94,7 @@ void Options::Load()
return;

std::ifstream configFile(path);
if(!configFile)
if (!configFile)
return;

auto config = nlohmann::json::parse(configFile);
Expand All @@ -129,11 +117,7 @@ void Options::Load()

void Options::Save() const
{
nlohmann::json config = {
{"patches", Patches.Save()},
{"font", Font.Save()},
{"developer", Developer.Save()}
};
nlohmann::json config = {{"patches", Patches.Save()}, {"font", Font.Save()}, {"developer", Developer.Save()}};

const auto path = GetAbsolutePath(m_paths.Config(), "", true);
std::ofstream o(path);
Expand All @@ -154,27 +138,27 @@ Options::Options(Paths& aPaths)
{
const auto* exePathStr = aPaths.Executable().native().c_str();
const auto verInfoSz = GetFileVersionInfoSize(exePathStr, nullptr);
if(verInfoSz)
if (verInfoSz)
{
const auto verInfo = std::make_unique<BYTE[]>(verInfoSz);
if(GetFileVersionInfo(exePathStr, 0, verInfoSz, verInfo.get()))
if (GetFileVersionInfo(exePathStr, 0, verInfoSz, verInfo.get()))
{
struct
{
WORD Language;
WORD CodePage;
} *pTranslations;
}* pTranslations;

UINT transBytes = 0;
if(VerQueryValue(verInfo.get(), _T("\\VarFileInfo\\Translation"), reinterpret_cast<void**>(&pTranslations), &transBytes))
if (VerQueryValue(verInfo.get(), _T("\\VarFileInfo\\Translation"), reinterpret_cast<void**>(&pTranslations), &transBytes))
{
UINT dummy;
TCHAR* productName = nullptr;
TCHAR subBlock[64];
for(UINT i = 0; i < (transBytes / sizeof(*pTranslations)); i++)
for (UINT i = 0; i < (transBytes / sizeof(*pTranslations)); i++)
{
_stprintf(subBlock, _T("\\StringFileInfo\\%04x%04x\\ProductName"), pTranslations[i].Language, pTranslations[i].CodePage);
if(VerQueryValue(verInfo.get(), subBlock, reinterpret_cast<void**>(&productName), &dummy))
if (VerQueryValue(verInfo.get(), subBlock, reinterpret_cast<void**>(&productName), &dummy))
if (_tcscmp(productName, _T("Cyberpunk 2077")) == 0)
{
ExeValid = true;
Expand Down Expand Up @@ -211,7 +195,6 @@ Options::Options(Paths& aPaths)
Log::Error("Unsupported game version! Only {}.{:02d} is supported.", smajor, sminor);
throw std::runtime_error("Unsupported version");
}

}
else
{
Expand Down
49 changes: 24 additions & 25 deletions src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ struct PatchesSettings

[[nodiscard]] auto operator<=>(const PatchesSettings&) const = default;

bool RemovePedestrians{ false };
bool AsyncCompute{ false };
bool Antialiasing{ false };
bool SkipStartMenu{ false };
bool AmdSmt{ false };
bool DisableIntroMovies{ false };
bool DisableVignette{ false };
bool DisableBoundaryTeleport{ false };
bool DisableWin7Vsync{ false };
bool MinimapFlicker{ false };
bool RemovePedestrians{false};
bool AsyncCompute{false};
bool Antialiasing{false};
bool SkipStartMenu{false};
bool AmdSmt{false};
bool DisableIntroMovies{false};
bool DisableVignette{false};
bool DisableBoundaryTeleport{false};
bool DisableWin7Vsync{false};
bool MinimapFlicker{false};
};

struct FontSettings
Expand All @@ -32,11 +32,11 @@ struct FontSettings

[[nodiscard]] auto operator<=>(const FontSettings&) const = default;

std::string Path{ };
std::string Path{};
std::string Language{"Default"};
float BaseSize{ 18.0f };
int32_t OversampleHorizontal{ 3 };
int32_t OversampleVertical{ 1 };
float BaseSize{18.0f};
int32_t OversampleHorizontal{3};
int32_t OversampleVertical{1};
};

struct DeveloperSettings
Expand All @@ -47,12 +47,12 @@ struct DeveloperSettings

[[nodiscard]] auto operator<=>(const DeveloperSettings&) const = default;

bool RemoveDeadBindings{ true };
bool EnableImGuiAssertions{ false };
bool EnableDebug{ false };
bool DumpGameOptions{ false };
uint64_t MaxLinesConsoleHistory{ 1000 };
bool PersistentConsole{ true };
bool RemoveDeadBindings{true};
bool EnableImGuiAssertions{false};
bool EnableDebug{false};
bool DumpGameOptions{false};
uint64_t MaxLinesConsoleHistory{1000};
bool PersistentConsole{true};
};

struct Options
Expand All @@ -65,13 +65,12 @@ struct Options
void ResetToDefaults();

Image GameImage;
bool ExeValid{ false };
bool ExeValid{false};

PatchesSettings Patches{ };
FontSettings Font{ };
DeveloperSettings Developer{ };
PatchesSettings Patches{};
FontSettings Font{};
DeveloperSettings Developer{};

private:

Paths& m_paths;
};
2 changes: 1 addition & 1 deletion src/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const std::filesystem::path& Paths::TweakDB() const

Paths::Paths()
{
TCHAR exePathBuf[MAX_PATH] = { 0 };
TCHAR exePathBuf[MAX_PATH] = {0};
GetModuleFileName(GetModuleHandle(nullptr), exePathBuf, static_cast<DWORD>(std::size(exePathBuf)));
m_exe = exePathBuf;

Expand Down
1 change: 0 additions & 1 deletion src/Paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct Paths
const std::filesystem::path& TweakDB() const;

private:

friend struct CET;

Paths();
Expand Down
Loading

0 comments on commit 59ded2e

Please sign in to comment.