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

Make clang-format less strict #473

Closed
wants to merge 18 commits into from
13 changes: 2 additions & 11 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@ IndentWidth: 4
TabWidth: 4
UseCRLF: false
AlignTrailingComments: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: No
BinPackArguments: false
BinPackParameters: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
ObjCBinPackProtocolList: Auto
AlwaysBreakTemplateDeclarations: Yes
SpacesInSquareBrackets: false
SpacesInParentheses: false
SpaceAfterCStyleCast: false
Expand All @@ -27,9 +19,8 @@ SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
UseTab: Always
ColumnLimit: 140
ColumnLimit: 0
BreakBeforeBraces: Allman
AlignAfterOpenBracket: AlwaysBreak
IndentExternBlock: Indent
PointerAlignment: Left
SortIncludes: false
Expand Down
6 changes: 4 additions & 2 deletions NorthstarDLL/client/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,16 @@ void CustomAudioManager::ClearAudioOverrides()
m_loadedAudioOverridesRegex.clear();
}

template <typename Iter, typename RandomGenerator> Iter select_randomly(Iter start, Iter end, RandomGenerator& g)
template <typename Iter, typename RandomGenerator>
Iter select_randomly(Iter start, Iter end, RandomGenerator& g)
{
std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
std::advance(start, dis(g));
return start;
}

template <typename Iter> Iter select_randomly(Iter start, Iter end)
template <typename Iter>
Iter select_randomly(Iter start, Iter end)
{
static std::random_device rd;
static std::mt19937 gen(rd());
Expand Down
10 changes: 5 additions & 5 deletions NorthstarDLL/core/convar/convar.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define FCVAR_HIDDEN (1 << 4) // Hidden. Doesn't appear in find or auto complete. Like DEVELOPMENTONLY, but can't be compiled out.

// ConVar only
#define FCVAR_PROTECTED \
#define FCVAR_PROTECTED \
(1 << 5) // It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as
// value.
#define FCVAR_SPONLY (1 << 6) // This cvar cannot be changed by clients connected to a multiplayer server.
Expand All @@ -27,7 +27,7 @@
#define FCVAR_USERINFO (1 << 9) // changes the client's info string

#define FCVAR_PRINTABLEONLY (1 << 10) // This cvar's string cannot contain unprintable characters ( e.g., used for player name etc ).
#define FCVAR_GAMEDLL_FOR_REMOTE_CLIENTS \
#define FCVAR_GAMEDLL_FOR_REMOTE_CLIENTS \
(1 << 10) // When on concommands this allows remote clients to execute this cmd on the server.
// We are changing the default behavior of concommands to disallow execution by remote clients without
// this flag due to the number existing concommands that can lag or crash the server when clients abuse them.
Expand All @@ -53,16 +53,16 @@
#define FCVAR_MATERIAL_SYSTEM_THREAD (1 << 23) // Indicates this cvar is read from the material system thread
#define FCVAR_ARCHIVE_PLAYERPROFILE (1 << 24) // respawn-defined flag, same as FCVAR_ARCHIVE but writes to profile.cfg

#define FCVAR_SERVER_CAN_EXECUTE \
#define FCVAR_SERVER_CAN_EXECUTE \
(1 << 28) // the server is allowed to execute this command on clients via
// ClientCommand/NET_StringCmd/CBaseClientState::ProcessStringCmd.
#define FCVAR_SERVER_CANNOT_QUERY \
#define FCVAR_SERVER_CANNOT_QUERY \
(1 << 29) // If this is set, then the server is not allowed to query this cvar's value (via IServerPluginHelpers::StartQueryCvarValue).

// !!!NOTE!!! : this is likely incorrect, there are multiple concommands that the vanilla game registers with this flag that 100% should not
// be remotely executable i.e. multiple commands that only exist on client (screenshot, joystick_initialize) we now use
// FCVAR_GAMEDLL_FOR_REMOTE_CLIENTS in all places this flag was previously used
#define FCVAR_CLIENTCMD_CAN_EXECUTE \
#define FCVAR_CLIENTCMD_CAN_EXECUTE \
(1 << 30) // IVEngineClient::ClientCmd is allowed to execute this command.
// Note: IVEngineClient::ClientCmd_Unrestricted can run any client command.

Expand Down
128 changes: 64 additions & 64 deletions NorthstarDLL/core/hooks.h

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions NorthstarDLL/core/macros.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#pragma once
template <typename ReturnType, typename... Args> ReturnType CallVFunc(int index, void* thisPtr, Args... args)
template <typename ReturnType, typename... Args>
ReturnType CallVFunc(int index, void* thisPtr, Args... args)
{
return (*reinterpret_cast<ReturnType(__fastcall***)(void*, Args...)>(thisPtr))[index](thisPtr, args...);
}

template <typename T, size_t index, typename... Args> constexpr T CallVFunc_Alt(void* classBase, Args... args) noexcept
template <typename T, size_t index, typename... Args>
constexpr T CallVFunc_Alt(void* classBase, Args... args) noexcept
{
return ((*(T(__thiscall***)(void*, Args...))(classBase))[index])(classBase, args...);
}

#define STR_HASH(s) (std::hash<std::string>()(s))

// Example usage: M_VMETHOD(int, GetEntityIndex, 8, (CBaseEntity* ent), (this, ent))
#define M_VMETHOD(returnType, name, index, args, argsRaw) \
FORCEINLINE returnType name args noexcept \
{ \
return CallVFunc_Alt<returnType, index> argsRaw; \
#define M_VMETHOD(returnType, name, index, args, argsRaw) \
FORCEINLINE returnType name args noexcept \
{ \
return CallVFunc_Alt<returnType, index> argsRaw; \
}
35 changes: 32 additions & 3 deletions NorthstarDLL/core/math/bitbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,38 @@
INLINE int GetBitForBitnum(int bitNum)
{
static int bitsForBitnum[] = {
(1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4), (1 << 5), (1 << 6), (1 << 7), (1 << 8), (1 << 9), (1 << 10),
(1 << 11), (1 << 12), (1 << 13), (1 << 14), (1 << 15), (1 << 16), (1 << 17), (1 << 18), (1 << 19), (1 << 20), (1 << 21),
(1 << 22), (1 << 23), (1 << 24), (1 << 25), (1 << 26), (1 << 27), (1 << 28), (1 << 29), (1 << 30), (1 << 31),
(1 << 0),
(1 << 1),
(1 << 2),
(1 << 3),
(1 << 4),
(1 << 5),
(1 << 6),
(1 << 7),
(1 << 8),
(1 << 9),
(1 << 10),
(1 << 11),
(1 << 12),
(1 << 13),
(1 << 14),
(1 << 15),
(1 << 16),
(1 << 17),
(1 << 18),
(1 << 19),
(1 << 20),
(1 << 21),
(1 << 22),
(1 << 23),
(1 << 24),
(1 << 25),
(1 << 26),
(1 << 27),
(1 << 28),
(1 << 29),
(1 << 30),
(1 << 31),
};

return bitsForBitnum[(bitNum) & (BITS_PER_INT - 1)];
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/core/memalloc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "rapidjson/document.h"
//#include "include/rapidjson/allocators.h"
// #include "include/rapidjson/allocators.h"

extern "C" void* _malloc_base(size_t size);
extern "C" void* _calloc_base(size_t const count, size_t const size);
Expand Down
3 changes: 2 additions & 1 deletion NorthstarDLL/core/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class MemoryAddress
MemoryAddress operator-(const uintptr_t& other) const;
MemoryAddress operator*() const;

template <typename T> T As()
template <typename T>
T As()
{
return reinterpret_cast<T>(m_nAddress);
}
Expand Down
3 changes: 2 additions & 1 deletion NorthstarDLL/core/sourceinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// literally just copied from ttf2sdk definition
typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode);

template <typename T> class SourceInterface
template <typename T>
class SourceInterface
{
private:
T* m_interface;
Expand Down
52 changes: 26 additions & 26 deletions NorthstarDLL/core/structs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
//clang-format off
// clang-format off
// About this file:
// This file contains several macros used to define reversed structs
// The reason we use these macros is to make it easier to update existing structs
Expand All @@ -18,45 +18,45 @@
/*
OFFSET_STRUCT(Name)
{
STRUCT_SIZE(0x100) // Total in-memory struct size
FIELD(0x0, int field) // offset, signature
STRUCT_SIZE(0x100) // Total in-memory struct size
FIELD(0x0, int field) // offset, signature
}
*/

#define OFFSET_STRUCT(name) union name
#define STRUCT_SIZE(size) char __size[size];
#define STRUCT_FIELD_OFFSET(offset, signature) \
struct \
{ \
char CONCAT2(pad, __LINE__)[offset]; \
signature; \
};
#define OFFSET_STRUCT( name ) union name
pg9182 marked this conversation as resolved.
Show resolved Hide resolved
#define STRUCT_SIZE( size ) char __size[size];
#define STRUCT_FIELD_OFFSET( offset, signature ) \
struct \
{ \
char CONCAT2( pad, __LINE__ )[offset]; \
signature; \
};

// Special case for a 0-offset field
#define STRUCT_FIELD_NOOFFSET(offset, signature) signature;
#define STRUCT_FIELD_NOOFFSET( offset, signature ) signature;

// Based on: https://stackoverflow.com/questions/11632219/c-preprocessor-macro-specialisation-based-on-an-argument
// Yes, this is hacky, but it works quite well actually
// This basically makes sure that when the offset is 0x0, no padding field gets generated
#define OFFSET_0x0 ()

#define IIF(c) CONCAT2(IIF_, c)
#define IIF_0(t, ...) __VA_ARGS__
#define IIF_1(t, ...) t
#define IIF( c ) CONCAT2( IIF_, c )
#define IIF_0( t, ... ) __VA_ARGS__
#define IIF_1( t, ... ) t

#define PROBE(x) x, 1
#define MSVC_VA_ARGS_WORKAROUND(define, args) define args
#define CHECK(...) MSVC_VA_ARGS_WORKAROUND(CHECK_N, (__VA_ARGS__, 0))
#define DO_PROBE(offset) PROBE_PROXY(OFFSET_##offset) // concatenate prefix with offset
#define PROBE_PROXY(...) PROBE_PRIMITIVE(__VA_ARGS__) // expand arguments
#define PROBE_PRIMITIVE(x) PROBE_COMBINE_##x // merge
#define PROBE_COMBINE_(...) PROBE(~) // if merge successful, expand to probe
#define PROBE( x ) x, 1
#define MSVC_VA_ARGS_WORKAROUND( define, args ) define args
#define CHECK( ... ) MSVC_VA_ARGS_WORKAROUND( CHECK_N, ( __VA_ARGS__, 0 ) )
#define DO_PROBE( offset ) PROBE_PROXY( OFFSET_##offset ) // concatenate prefix with offset
#define PROBE_PROXY( ... ) PROBE_PRIMITIVE( __VA_ARGS__ ) // expand arguments
#define PROBE_PRIMITIVE( x ) PROBE_COMBINE_##x // merge
#define PROBE_COMBINE_( ... ) PROBE( ~) // if merge successful, expand to probe

#define CHECK_N(x, n, ...) n
#define CHECK_N( x, n, ... ) n

#define IS_0(offset) CHECK(DO_PROBE(offset))
#define IS_0( offset ) CHECK( DO_PROBE( offset ) )

#define FIELD(offset, signature) IIF(IS_0(offset))(STRUCT_FIELD_NOOFFSET, STRUCT_FIELD_OFFSET)(offset, signature)
#define FIELD( offset, signature ) IIF( IS_0( offset ) )( STRUCT_FIELD_NOOFFSET, STRUCT_FIELD_OFFSET )( offset, signature )
#define FIELDS FIELD

//clang-format on
// clang-format on
5 changes: 2 additions & 3 deletions NorthstarDLL/dedicated/dedicated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ ON_DLL_LOAD_DEDI("server.dll", DedicatedServerGameDLL, (CModule module))
if (Tier0::CommandLine()->CheckParm("-nopakdedi"))
{
module.Offset(0x6BA350).Patch("C3"); // dont load skins.rson from rpak if we don't have rpaks, as loading it will cause a crash
module.Offset(0x6BA300).Patch(
"B8 C8 00 00 00 C3"); // return 200 as the number of skins from server.dll + 6BA300, this is the normal value read from
// skins.rson and should be updated when we need it more modular
module.Offset(0x6BA300).Patch("B8 C8 00 00 00 C3"); // return 200 as the number of skins from server.dll + 6BA300, this is the normal value read from
// skins.rson and should be updated when we need it more modular
}
}
33 changes: 22 additions & 11 deletions NorthstarDLL/logging/crashhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ std::shared_ptr<ExceptionLog> storedException {};
#define RUNTIME_EXCEPTION 3765269347
// clang format did this :/
std::map<int, std::string> ExceptionNames = {
{EXCEPTION_ACCESS_VIOLATION, "Access Violation"}, {EXCEPTION_IN_PAGE_ERROR, "Access Violation"},
{EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "Array bounds exceeded"}, {EXCEPTION_DATATYPE_MISALIGNMENT, "Datatype misalignment"},
{EXCEPTION_FLT_DENORMAL_OPERAND, "Denormal operand"}, {EXCEPTION_FLT_DIVIDE_BY_ZERO, "Divide by zero (float)"},
{EXCEPTION_FLT_INEXACT_RESULT, "Inexact float result"}, {EXCEPTION_FLT_INVALID_OPERATION, "Invalid operation"},
{EXCEPTION_FLT_OVERFLOW, "Numeric overflow (float)"}, {EXCEPTION_FLT_STACK_CHECK, "Stack check"},
{EXCEPTION_FLT_UNDERFLOW, "Numeric underflow (float)"}, {EXCEPTION_ILLEGAL_INSTRUCTION, "Illegal instruction"},
{EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero (int)"}, {EXCEPTION_INT_OVERFLOW, "Numeric overfloat (int)"},
{EXCEPTION_INVALID_DISPOSITION, "Invalid disposition"}, {EXCEPTION_NONCONTINUABLE_EXCEPTION, "Non-continuable exception"},
{EXCEPTION_PRIV_INSTRUCTION, "Priviledged instruction"}, {EXCEPTION_STACK_OVERFLOW, "Stack overflow"},
{EXCEPTION_ACCESS_VIOLATION, "Access Violation"},
{EXCEPTION_IN_PAGE_ERROR, "Access Violation"},
{EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "Array bounds exceeded"},
{EXCEPTION_DATATYPE_MISALIGNMENT, "Datatype misalignment"},
{EXCEPTION_FLT_DENORMAL_OPERAND, "Denormal operand"},
{EXCEPTION_FLT_DIVIDE_BY_ZERO, "Divide by zero (float)"},
{EXCEPTION_FLT_INEXACT_RESULT, "Inexact float result"},
{EXCEPTION_FLT_INVALID_OPERATION, "Invalid operation"},
{EXCEPTION_FLT_OVERFLOW, "Numeric overflow (float)"},
{EXCEPTION_FLT_STACK_CHECK, "Stack check"},
{EXCEPTION_FLT_UNDERFLOW, "Numeric underflow (float)"},
{EXCEPTION_ILLEGAL_INSTRUCTION, "Illegal instruction"},
{EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero (int)"},
{EXCEPTION_INT_OVERFLOW, "Numeric overfloat (int)"},
{EXCEPTION_INVALID_DISPOSITION, "Invalid disposition"},
{EXCEPTION_NONCONTINUABLE_EXCEPTION, "Non-continuable exception"},
{EXCEPTION_PRIV_INSTRUCTION, "Priviledged instruction"},
{EXCEPTION_STACK_OVERFLOW, "Stack overflow"},
{RUNTIME_EXCEPTION, "Uncaught runtime exception:"},
};

Expand Down Expand Up @@ -101,9 +110,11 @@ std::string GetExceptionName(ExceptionLog& exc)
}

// Custom formatter for the Xmm registers
template <> struct fmt::formatter<M128A> : fmt::formatter<string_view>
template <>
struct fmt::formatter<M128A> : fmt::formatter<string_view>
{
template <typename FormatContext> auto format(const M128A& obj, FormatContext& ctx)
template <typename FormatContext>
auto format(const M128A& obj, FormatContext& ctx)
{
// Masking the top and bottom half of the long long
int v1 = obj.Low & INT_MAX;
Expand Down
3 changes: 2 additions & 1 deletion NorthstarDLL/masterserver/masterserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ void MasterServerManager::RequestServerList()
std::sort(
m_vRemoteServers.begin(),
m_vRemoteServers.end(),
[](RemoteServerInfo& a, RemoteServerInfo& b) { return a.playerCount > b.playerCount; });
[](RemoteServerInfo& a, RemoteServerInfo& b)
{ return a.playerCount > b.playerCount; });
}
else
{
Expand Down
9 changes: 6 additions & 3 deletions NorthstarDLL/mods/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ struct Test
ScriptContext context;
};

template <ScriptContext context> auto ModConCommandCallback_Internal(std::string name, const CCommand& command)
template <ScriptContext context>
auto ModConCommandCallback_Internal(std::string name, const CCommand& command)
{
if (g_pSquirrel<context>->m_pSQVM && g_pSquirrel<context>->m_pSQVM)
{
Expand Down Expand Up @@ -340,7 +341,8 @@ auto ModConCommandCallback(const CCommand& command)
auto res = std::find_if(
mod.ConCommands.begin(),
mod.ConCommands.end(),
[&commandString](const ModConCommand* other) { return other->Name == commandString; });
[&commandString](const ModConCommand* other)
{ return other->Name == commandString; });
if (res != mod.ConCommands.end())
{
found = *res;
Expand Down Expand Up @@ -455,7 +457,8 @@ void ModManager::LoadMods()
}

// sort by load prio, lowest-highest
std::sort(m_LoadedMods.begin(), m_LoadedMods.end(), [](Mod& a, Mod& b) { return a.LoadPriority < b.LoadPriority; });
std::sort(m_LoadedMods.begin(), m_LoadedMods.end(), [](Mod& a, Mod& b)
{ return a.LoadPriority < b.LoadPriority; });

for (Mod& mod : m_LoadedMods)
{
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef void (*callable_v)(void* v);

// clang-format off
#define assert_msg(exp, msg) assert((exp, msg))
//clang-format on
// clang-format on

#include "core/macros.h"

Expand Down
3 changes: 2 additions & 1 deletion NorthstarDLL/scripts/scriptdatatables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ struct Datatable

ConVar* Cvar_ns_prefer_datatable_from_disk;

template <ScriptContext context> Datatable* (*SQ_GetDatatableInternal)(HSquirrelVM* sqvm);
template <ScriptContext context>
Datatable* (*SQ_GetDatatableInternal)(HSquirrelVM* sqvm);

struct CSVData
{
Expand Down
Loading