Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project: remove clang-format for good #772

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions .clang-format

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,3 @@ jobs:
name: NorthstarLauncher-${{ matrix.config.name }}-${{ steps.extract.outputs.commit }}
path: |
game/

format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DoozyX/[email protected]
with:
source: 'primedev'
exclude: 'primedev/include primedev/thirdparty primedev/wsockproxy'
extensions: 'h,cpp'
clangFormatVersion: 16
style: file

format-check-cmake-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: puneetmatharu/[email protected]
with:
args: "--in-place"
- run: |
git diff --exit-code
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Check [BUILD.md](BUILD.md) for instructions on how to compile, you can also down

## Format

This project uses [clang-format](https://clang.llvm.org/docs/ClangFormat.html), make sure you run `clang-format -i --style=file --exclude=primedev/include primedev/*.cpp primedev/*.h` when opening a Pull Request. Check the tool's website for instructions on how to integrate it with your IDE.
For project coding standards checkout [STANDARDS.md](STANDARDS.md).
57 changes: 57 additions & 0 deletions STANDARDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Code standards

There are exceptions, ask for them!

### Preamble

We do not use any auto-formatting tools as most solutions are limited in what they can do and setting them up can be a pain in the ass.

We used to use clang-format but have swapped it with this document.

You are more than welcome to reformat any files using the old formatting rules, but please SPLIT your formatting changes from the rest by making a separate PR!

### General rules

> Basic rules that apply all the time.

Always assert your assumptions!

Use PascalCase for all names.

Suffix structs with `_t`.

Prefix classes with `C` (class) and `I` (abstract class).

Prefix all class member variables with `m_`.

Prefixes `g_` for global variables and `s_` for static variables are welcome.

For hooking we use `o_<function name>` for function pointers pointing to the original implementation and `h_<function name>` for functions we replace them with.

Document all function implementations and their arguments (if the argument is self explanatory you don't need to document it) valve style:
```
//-----------------------------------------------------------------------------
// Purpose: MH_MakeHook wrapper
// Input : *ppOriginal - Original function being detoured
// pDetour - Detour function
// Output : true on success, false otherwise
//-----------------------------------------------------------------------------
```

Don't overcomment your code unless nescessary, expect the reader to have limited knowledge.

Use `FIXME` comments for possible improvements/issues, `NOTE` for important information one might want to look into.

### Valve source files

> Rules that apply to all files from original valve code base.

When adding or just modifying a file that's present in valve source place it where valve put it.

Always use hungarian notation in these files.

### New files

> Rules that apply to respawn or our own files.

When adding new files follow the general rules, you don't have to use hungarian notation. Put the file where you think it makes the most sense.
6 changes: 0 additions & 6 deletions primedev/client/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,8 @@ bool ShouldPlayAudioEvent(const char* eventName, const std::shared_ptr<EventOver
return true; // good to go
}

// clang-format off
AUTOHOOK(LoadSampleMetadata, mileswin64.dll + 0xF110,
bool, __fastcall, (void* sample, void* audioBuffer, unsigned int audioBufferLength, int audioType))
// clang-format on
{
// Raw source, used for voice data only
if (audioType == 0)
Expand Down Expand Up @@ -497,19 +495,15 @@ bool, __fastcall, (void* sample, void* audioBuffer, unsigned int audioBufferLeng
return res;
}

// clang-format off
AUTOHOOK(sub_1800294C0, mileswin64.dll + 0x294C0,
void*, __fastcall, (void* a1, void* a2))
// clang-format on
{
pszAudioEventName = reinterpret_cast<const char*>((*((__int64*)a2 + 6)));
return sub_1800294C0(a1, a2);
}

// clang-format off
AUTOHOOK(MilesLog, client.dll + 0x57DAD0,
void, __fastcall, (int level, const char* string))
// clang-format on
{
if (!Cvar_mileslog_enable->GetBool())
return;
Expand Down
4 changes: 0 additions & 4 deletions primedev/client/clientauthhooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ const int NOT_DECIDED_TO_SEND_TOKEN = 0;
const int AGREED_TO_SEND_TOKEN = 1;
const int DISAGREED_TO_SEND_TOKEN = 2;

// clang-format off
AUTOHOOK(AuthWithStryder, engine.dll + 0x1843A0,
void, __fastcall, (void* a1))
// clang-format on
{
// don't attempt to do Atlas auth if we are in vanilla compatibility mode
// this prevents users from joining untrustworthy servers (unless they use a concommand or something)
Expand Down Expand Up @@ -43,10 +41,8 @@ void, __fastcall, (void* a1))

char* p3PToken;

// clang-format off
AUTOHOOK(Auth3PToken, engine.dll + 0x183760,
char*, __fastcall, ())
// clang-format on
{
if (!g_pVanillaCompatibility->GetVanillaCompatibility() && g_pMasterServerManager->m_sOwnClientAuthToken[0])
{
Expand Down
2 changes: 0 additions & 2 deletions primedev/client/clientruihooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ AUTOHOOK_INIT()

ConVar* Cvar_rui_drawEnable;

// clang-format off
AUTOHOOK(DrawRUIFunc, engine.dll + 0xFC500,
bool, __fastcall, (void* a1, float* a2))
// clang-format on
{
if (!Cvar_rui_drawEnable->GetBool())
return 0;
Expand Down
2 changes: 0 additions & 2 deletions primedev/client/clientvideooverrides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

AUTOHOOK_INIT()

// clang-format off
AUTOHOOK_PROCADDRESS(BinkOpen, bink2w64.dll, BinkOpen,
void*, __fastcall, (const char* path, uint32_t flags))
// clang-format on
{
std::string filename(fs::path(path).filename().string());
spdlog::info("BinkOpen {}", filename);
Expand Down
4 changes: 0 additions & 4 deletions primedev/client/debugoverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ OverlayBase_t** s_pOverlays;
int* g_nRenderTickCount;
int* g_nOverlayTickCount;

// clang-format off
AUTOHOOK(DrawOverlay, engine.dll + 0xABCB0,
void, __fastcall, (OverlayBase_t * pOverlay))
// clang-format on
{
EnterCriticalSection(s_OverlayMutex);

Expand Down Expand Up @@ -205,10 +203,8 @@ void, __fastcall, (OverlayBase_t * pOverlay))
LeaveCriticalSection(s_OverlayMutex);
}

// clang-format off
AUTOHOOK(DrawAllOverlays, engine.dll + 0xAB780,
void, __fastcall, (bool bRender))
// clang-format on
{
EnterCriticalSection(s_OverlayMutex);

Expand Down
2 changes: 0 additions & 2 deletions primedev/client/languagehooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ std::string GetAnyInstalledAudioLanguage()
return "NO LANGUAGE DETECTED";
}

// clang-format off
AUTOHOOK(GetGameLanguage, tier0.dll + 0xF560,
char*, __fastcall, ())
// clang-format on
{
auto tier0Handle = GetModuleHandleA("tier0.dll");
auto Tier0_DetectDefaultLanguageType = GetProcAddress(tier0Handle, "Tier0_DetectDefaultLanguage");
Expand Down
2 changes: 0 additions & 2 deletions primedev/client/latencyflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ ConVar* Cvar_r_latencyflex;

void (*m_winelfx_WaitAndBeginFrame)();

// clang-format off
AUTOHOOK(OnRenderStart, client.dll + 0x1952C0,
void, __fastcall, ())
// clang-format on
{
if (Cvar_r_latencyflex->GetBool() && m_winelfx_WaitAndBeginFrame)
m_winelfx_WaitAndBeginFrame();
Expand Down
6 changes: 0 additions & 6 deletions primedev/client/modlocalisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ AUTOHOOK_INIT()

void* g_pVguiLocalize;

// clang-format off
AUTOHOOK(CLocalize__AddFile, localize.dll + 0x6D80,
bool, __fastcall, (void* pVguiLocalize, const char* path, const char* pathId, bool bIncludeFallbackSearchPaths))
// clang-format on
{
// save this for later
g_pVguiLocalize = pVguiLocalize;
Expand All @@ -19,10 +17,8 @@ bool, __fastcall, (void* pVguiLocalize, const char* path, const char* pathId, bo
return true;
}

// clang-format off
AUTOHOOK(CLocalize__ReloadLocalizationFiles, localize.dll + 0xB830,
void, __fastcall, (void* pVguiLocalize))
// clang-format on
{
// load all mod localization manually, so we keep track of all files, not just previously loaded ones
for (Mod mod : g_pModManager->m_LoadedMods)
Expand All @@ -34,10 +30,8 @@ void, __fastcall, (void* pVguiLocalize))
CLocalize__ReloadLocalizationFiles(pVguiLocalize);
}

// clang-format off
AUTOHOOK(CEngineVGui__Init, engine.dll + 0x247E10,
void, __fastcall, (void* self))
// clang-format on
{
CEngineVGui__Init(self); // this loads r1_english, valve_english, dev_english

Expand Down
2 changes: 0 additions & 2 deletions primedev/client/rejectconnectionfixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
AUTOHOOK_INIT()

// this is called from when our connection is rejected, this is the only case we're hooking this for
// clang-format off
AUTOHOOK(COM_ExplainDisconnection, engine.dll + 0x1342F0,
void,, (bool a1, const char* fmt, ...))
// clang-format on
{
va_list va;
va_start(va, fmt);
Expand Down
8 changes: 0 additions & 8 deletions primedev/core/filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ std::string ReadVPKOriginalFile(const char* path)
return ret;
}

// clang-format off
HOOK(AddSearchPathHook, AddSearchPath,
void, __fastcall, (IFileSystem * fileSystem, const char* pPath, const char* pathID, SearchPathAdd_t addType))
// clang-format on
{
AddSearchPath(fileSystem, pPath, pathID, addType);

Expand Down Expand Up @@ -97,10 +95,8 @@ bool TryReplaceFile(const char* pPath, bool shouldCompile)
}

// force modded files to be read from mods, not cache
// clang-format off
HOOK(ReadFromCacheHook, ReadFromCache,
bool, __fastcall, (IFileSystem * filesystem, char* pPath, void* result))
// clang-format off
{
if (TryReplaceFile(pPath, true))
return false;
Expand All @@ -109,10 +105,8 @@ bool, __fastcall, (IFileSystem * filesystem, char* pPath, void* result))
}

// force modded files to be read from mods, not vpk
// clang-format off
AUTOHOOK(ReadFileFromVPK, filesystem_stdio.dll + 0x5CBA0,
FileHandle_t, __fastcall, (VPKData* vpkInfo, uint64_t* b, char* filename))
// clang-format on
{
// don't compile here because this is only ever called from OpenEx, which already compiles
if (TryReplaceFile(filename, false))
Expand All @@ -124,10 +118,8 @@ FileHandle_t, __fastcall, (VPKData* vpkInfo, uint64_t* b, char* filename))
return ReadFileFromVPK(vpkInfo, b, filename);
}

// clang-format off
AUTOHOOK(CBaseFileSystem__OpenEx, filesystem_stdio.dll + 0x15F50,
FileHandle_t, __fastcall, (IFileSystem* filesystem, const char* pPath, const char* pOptions, uint32_t flags, const char* pPathID, char **ppszResolvedFilename))
// clang-format on
{
TryReplaceFile(pPath, true);
return CBaseFileSystem__OpenEx(filesystem, pPath, pOptions, flags, pPathID, ppszResolvedFilename);
Expand Down
6 changes: 0 additions & 6 deletions primedev/core/filesystem/rpakfilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ void LoadCustomMapPaks(char** pakName, bool* bNeedToFreePakName)
}
}

// clang-format off
HOOK(LoadPakAsyncHook, LoadPakAsync,
int, __fastcall, (char* pPath, void* unknownSingleton, int flags, void* pCallback0, void* pCallback1))
// clang-format on
{
HandlePakAliases(&pPath);

Expand Down Expand Up @@ -233,10 +231,8 @@ int, __fastcall, (char* pPath, void* unknownSingleton, int flags, void* pCallbac
return iPakHandle;
}

// clang-format off
HOOK(UnloadPakHook, UnloadPak,
void*, __fastcall, (int nPakHandle, void* pCallback))
// clang-format on
{
// stop tracking the pak
g_pPakLoadManager->RemoveLoadedPak(nPakHandle);
Expand All @@ -255,10 +251,8 @@ void*, __fastcall, (int nPakHandle, void* pCallback))

// we hook this exclusively for resolving stbsp paths, but seemingly it's also used for other stuff like vpk, rpak, mprj and starpak loads
// tbh this actually might be for memory mapped files or something, would make sense i think
// clang-format off
HOOK(ReadFileAsyncHook, ReadFileAsync,
void*, __fastcall, (const char* pPath, void* pCallback))
// clang-format on
{
fs::path path(pPath);
std::string newPath = "";
Expand Down
2 changes: 0 additions & 2 deletions primedev/core/math/color.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

// clang-format off
namespace NS::Colors
{
Color SCRIPT_UI (100, 255, 255);
Expand All @@ -24,4 +23,3 @@ namespace NS::Colors
Color CRIT (255, 0 , 0 );
Color OFF (0 , 0 , 0 );
};
// clang-format on
Loading
Loading