Skip to content

Commit 2d8ea4a

Browse files
committed
Version 1.3 Update
Major update with significant standard containers refactoring. Note that they are still being tested.
1 parent 00b72e2 commit 2d8ea4a

81 files changed

Lines changed: 14476 additions & 12609 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

nh3api/.clang-format

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ AttributeMacros: [
4040
'NH3API_CONSTEXPR_CPP_23',
4141
'NH3API_CONSTEXPR_CPP_20',
4242
'NH3API_MALLOC',
43-
'NH3API_MSVC_INTRIN',
4443
'NH3API_MSVC_LAYOUT',
4544
'NH3API_DEALLOCATOR',
4645
'NH3API_NO_VFTABLE',
47-
'NH3API_CONST',
4846
'NH3API_NAKED'
4947
]
5048
BinPackArguments: true
@@ -85,7 +83,7 @@ BreakInheritanceList: AfterComma
8583
BreakStringLiterals: true
8684
BreakTemplateDeclarations: Yes
8785
CompactNamespaces: false
88-
ContinuationIndentWidth: 4
86+
ContinuationIndentWidth: 8
8987
Cpp11BracedListStyle: false
9088
EmptyLineAfterAccessModifier: Never
9189
EmptyLineBeforeAccessModifier: LogicalBlock

nh3api/.clangd

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
CompileFlags:
2-
Add: [-Wall,
3-
-std=c++23,
4-
-D_X86_,
5-
-DNH3API_FLAG_INLINE_HEADERS,
6-
-m32,
7-
-Wno-unused-includes]
8-
# Remove: [-W*]
2+
Add: [
3+
-DNH3API_CLANGD, # Macro to guard code where clangd behaves weird. Do NOT define it in your code for compilation, as this is only for editing the code with clangd
4+
-Wall, # Enable (almost) every single clang warning
5+
-Wextra, # Enable additional warnings
6+
-std=c++23, # Don't worry, I'm not planning to break C++17 and v141_xp compatibility, this is just to implement C++23 features
7+
-D_X86_, # For whatever reason, WinAPI and MSVC STL requires it and the compiler doesn't define it by default
8+
-m32, # NH3API supports only 32-bit x86 architecture
9+
-Wno-unused-includes, # Do not warn about unused includes, this warning is broken anyway
10+
-Wno-unsafe-buffer-usage-in-libc-call, # We can't avoid calls to functions like memcpy for performance, especially on MSVC which is poor at optimizing things
11+
-Wno-unsafe-buffer-usage, # We also can't avoid raw pointer operations for binary compatibility (believe me, I would love to get rid of every single raw pointer in the library!)
12+
-Wno-unused-macros, # Most macros in NH3API are defined in nh3api_std.hpp, so this is useless, too
13+
-Wno-c++98-compat, # NH3API has dropped support for C++98/C++11/C++14
14+
-Wno-c++98-compat-pedantic, # Ditto
15+
-Wno-pre-c++14-compat, # Ditto
16+
-Wno-pre-c++17-compat, # Ditto
17+
]
918

1019
Index:
1120
StandardLibrary: true
@@ -14,39 +23,67 @@ Diagnostics:
1423
Suppress: unused-includes
1524
UnusedIncludes: None
1625
ClangTidy:
17-
Add: [performance*, modernize*, cppcoreguidelines*, misc*]
26+
Add: "*"
1827
Remove: [
19-
cppcoreguidelines-avoid-c-arrays,
20-
cppcoreguidelines-avoid-const-or-ref-data-members,
21-
cppcoreguidelines-avoid-do-while,
22-
cppcoreguidelines-avoid-magic-numbers,
23-
cppcoreguidelines-avoid-non-const-global-variables,
24-
cppcoreguidelines-macro-usage,
25-
cppcoreguidelines-non-private-member-variables-in-classes,
26-
cppcoreguidelines-pro-bounds-constant-array-index,
27-
cppcoreguidelines-pro-bounds-pointer-arithmetic,
28-
cppcoreguidelines-pro-type-const-cast,
29-
cppcoreguidelines-pro-type-member-init,
30-
cppcoreguidelines-pro-type-reinterpret-cast,
31-
cppcoreguidelines-pro-type-static-cast-downcast,
32-
cppcoreguidelines-pro-type-union-access,
33-
cppcoreguidelines-pro-type-vararg,
34-
cppcoreguidelines-virtual-class-destructor,
35-
misc-non-private-member-variables-in-classes,
36-
modernize-avoid-c-arrays,
37-
modernize-use-auto,
38-
modernize-use-ranges,
39-
modernize-use-trailing-return-type,
40-
performance-enum-size,
41-
performance-no-int-to-ptr,
42-
readability*
28+
altera-*, # These checks are extremely niche
29+
google-explicit-constructor, # In theory, this would be good but leads to more verbose code
30+
hicpp-explicit-conversions, # Ditto
31+
misc-misplaced-const, # const pointer (not pointers-to-const) are often used in STL code
32+
cppcoreguidelines-avoid-c-arrays, # Can't avoid C-style arrays in the function arguments to force explicit string literals passed as parameters
33+
hicpp-avoid-c-arrays, # Ditto
34+
modernize-avoid-c-arrays, # Ditto
35+
google-readability-*, # We're following the LLVM style of braces for readability, so these checks do not fit
36+
hicpp-braces-around-statements, # Ditto
37+
google-runtime-int, # unsigned long and unsigned int are technically not the same, so we can't just use int32_t all of the time
38+
google-default-arguments, # Default arguments are often for binary compatibility reasons(the a)
39+
cert-dcl51-cpp, # We can't avoid identifiers starting with the underscore because we pull a lot of code from MSVC STL and changing it is too much unnecessary work
40+
bugprone-reserved-identifier, # Ditto
41+
cert-dcl37-c, # Ditto
42+
cert-dcl58-cpp, # Specializing std::hash is okay per C++ standard
43+
cppcoreguidelines-avoid-const-or-ref-data-members, # Disabled for binary compatibility
44+
bugprone-easily-swappable-parameters, # We have to strictly follow the original function signatures
45+
llvmlibc-*, # These checks are relevant only inside the LLVM libc implementation
46+
fuchsia-*, # Very cringeworthy checks
47+
hicpp-special-member-functions, # Useless alias for cppcoreguidelines-special-member-functions
48+
hicpp-use-auto, # auto makes the compilation a bit slower, also it doesn't always improve readability
49+
modernize-use-auto, # Ditto
50+
hicpp-no-assembler, # Inline assembly used for a few hacks inside NH3API
51+
hicpp-named-parameter, # Unnamed parameters are used to silence the "unused parameter warning", now this?
52+
modernize-use-ranges, # C++17 doesn't have std::ranges
53+
modernize-use-trailing-return-type, # Just no. This is a really bad practice.
54+
cppcoreguidelines-avoid-do-while, # do { ... } while(0) is often used in macros
55+
cppcoreguidelines-avoid-magic-numbers, # I don't really want to introduce every single new enum just in one place
56+
cppcoreguidelines-avoid-non-const-global-variables, # The game makes heavy use of non-const global variables and NH3API just follows the game architecture.
57+
cppcoreguidelines-macro-usage, # For portability across LLVM, GCC and MSVC, we can't really avoid macros.
58+
misc-non-private-member-variables-in-classes, # In NH3API every game type variable is public
59+
cppcoreguidelines-non-private-member-variables-in-classes, # Ditto
60+
cppcoreguidelines-pro-bounds-constant-array-index, # This is just insane.
61+
cppcoreguidelines-pro-bounds-pointer-arithmetic, # Not always possible to avoid completely
62+
cppcoreguidelines-pro-type-const-cast, # Not always possible to write const-correct code with virtual functions without const_cast.
63+
cppcoreguidelines-pro-type-member-init, # Disabled for performance reasons (NH3API is supposed to be completely zero-cost abstraction)
64+
hicpp-member-init, # Ditto
65+
cppcoreguidelines-pro-type-reinterpret-cast, # Sadly, for binary compatibility and performance reason, we have to use reinterpret_cast very often. But I know what I'm doing and you don't have to worry about it.
66+
cppcoreguidelines-pro-type-static-cast-downcast, # No dynamic_cast allowed anywhere in NH3API
67+
cppcoreguidelines-pro-type-union-access, # We can't avoid unions because of the binary compatibility, also std::variant is really poorly designed
68+
cppcoreguidelines-pro-type-vararg, # You can potentially get rid of the C-style va_args but this may disrupt the calling convention
69+
cppcoreguidelines-virtual-class-destructor, # NH3API can't define virtual destructors by design, it uses scalar_deleting_destructor for binary compatibility. Also you must NOT allocate and deallocate the game polymorphic types with the standard new/delete in your code, use NH3API overloads with exe_heap, which map to the appropriate .exe new/delete
70+
performance-enum-size, # In NH3API, the choice for the underlying type for enums often depends on where the enum is used. I pick the most optimal size for every single enum, especially when it oftens used/fits into a few variables of some structures. If the enum is not used in any structures as type of a member variable, I pick either uint32_t for flag enums or int32_t/uint32_t for other enums based on whether or not the negative values make sense, often for checks or their lack thereof
71+
performance-no-int-to-ptr, # NH3API uses too many uintptr_t-to-pointer conversions for readability and performance, we can't just avoid it. The whole library is kind of built around fixed addresses in the .exe binary
72+
readability* # Absolutely incompatible with NH3API
4373
]
74+
CheckOptions:
75+
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
76+
cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions: true
77+
cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted: true
78+
cppcoreguidelines-special-member-functions.AllowImplicitlyDeletedCopyOrMove: true
4479

4580
Completion:
46-
AllScopes: Yes
47-
ArgumentLists: Delimiters
48-
HeaderInsertion: Never
81+
AllScopes: Yes # Actually, not that bad.
82+
ArgumentLists: Delimiters # The default is FullPlaceholders, which inserts the function with a signature, including the types, which is ridiculous
83+
HeaderInsertion: Never # Never insert any headers automatically to make use of as least dependencies as possible
84+
CodePatterns: None # The idea itself is not that bad, the problem is that you have to either disable this option completely, or get used to annoying specific parts of the feature(like if...else if part, it drove me insane!)
4985

86+
# Inlay Hints make it difficult to write and edit the code, also since the argument names frequently are the same as parameter names, these are just an overkill
5087
InlayHints:
5188
BlockEnd: true
5289
ParameterNames: false
@@ -55,4 +92,4 @@ InlayHints:
5592
DefaultArguments: false
5693

5794
Hover:
58-
ShowAKA: true
95+
ShowAKA: true # One of the most useful features of clangd! Helpful, excellent, simple
Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
//===----------------------------------------------------------------------===//
77
#pragma once
88

9-
#include "widgets.hpp"
9+
#include "core/interface/widgets.hpp"
1010

1111
#pragma pack(push, 4)
12+
// Game chat /
13+
// Игровой чат.
1214
// size = 0x44 = 68, align = 4
1315
class CChatManager
1416
{
@@ -21,40 +23,26 @@ class CChatManager
2123
// Message text /
2224
// Текст сообщения.
2325
// offset: +0x0 = +0, size = 0x80 = 128
24-
std::array<char, 128> sText;
26+
std::array<char, 128> sText {};
2527

2628
// offset: +0x80 = +128, size = 0x4 = 4
27-
uint32_t killTime;
29+
uint32_t killTime { 0 };
2830

2931
// System message /
3032
// Системное сообщение.
3133
// offset: +0x84 = +132, size = 0x1 = 1
32-
bool isSystem;
34+
bool isSystem { false };
3335

34-
};
36+
unsigned char : 8;
37+
unsigned char : 8;
38+
unsigned char : 8;
3539

36-
private:
40+
} NH3API_MSVC_LAYOUT;
3741
/*
38-
CChatManager(int32_t maxChatLines)
39-
: msgArray(nullptr),
40-
currMsg(0),
41-
msgCount(0),
42-
changed(true),
43-
lastWidget(nullptr),
44-
maxLines(maxChatLines),
45-
widgetText(nullptr),
46-
position(-1),
47-
chatKilled(false),
48-
isSysMsg(false),
49-
channel(0),
50-
chatSample(nullptr),
51-
playerDropSample(nullptr),
52-
sysMsgSample(nullptr),
53-
turnDurSample(nullptr),
54-
playerEnterSample(nullptr)
42+
CChatManager(int32_t maxChatLines)
5543
{ SetMaxLines(maxChatLines); }
5644
57-
CChatManager(const ::nh3api::dummy_tag_t&)
45+
CChatManager(const nh3api::dummy_tag_t&)
5846
{}
5947
6048
~CChatManager()
@@ -67,25 +55,28 @@ class CChatManager
6755
*/
6856

6957
public:
70-
template<typename... Args>
58+
CChatManager() = delete;
59+
~CChatManager() = delete;
60+
61+
template<typename... Args> NH3API_FORMAT_PRINTF(2, 3)
7162
void AddChat(const char* cChatMsg, Args... args)
72-
{ CDECL_N(char, 0x553C40, this, cChatMsg, ::std::forward<Args>(args)...); }
63+
{ CDECL_N(char, 0x553C40, this, cChatMsg, std::forward<Args>(args)...); }
7364

74-
template<typename... Args>
65+
template<typename... Args> NH3API_FORMAT_PRINTF(2, 3)
7566
void TurnDurationMsg(const char* cChatMsg, Args... args)
76-
{ CDECL_N(char, 0x553D60, this, cChatMsg, ::std::forward<Args>(args)...); }
67+
{ CDECL_N(char, 0x553D60, this, cChatMsg, std::forward<Args>(args)...); }
7768

78-
template<typename... Args>
69+
template<typename... Args> NH3API_FORMAT_PRINTF(2, 3)
7970
void SystemMsg(const char* cChatMsg, Args... args)
80-
{ CDECL_N(char, 0x553EA0, this, cChatMsg, ::std::forward<Args>(args)...); }
71+
{ CDECL_N(char, 0x553EA0, this, cChatMsg, std::forward<Args>(args)...); }
8172

82-
template<typename... Args>
73+
template<typename... Args> NH3API_FORMAT_PRINTF(2, 3)
8374
void PlayerDropMsg(const char* cChatMsg, Args... args)
84-
{ CDECL_N(char, 0x553F60, this, cChatMsg, ::std::forward<Args>(args)...); }
75+
{ CDECL_N(char, 0x553F60, this, cChatMsg, std::forward<Args>(args)...); }
8576

86-
template<typename... Args>
77+
template<typename... Args> NH3API_FORMAT_PRINTF(2, 3)
8778
void PlayerEnterMsg(const char* cChatMsg, Args... args)
88-
{ CDECL_N(char, 0x554030, this, cChatMsg, ::std::forward<Args>(args)...); }
79+
{ CDECL_N(char, 0x554030, this, cChatMsg, std::forward<Args>(args)...); }
8980

9081
void UpdateWidget(textWidget* Widget, bool killOld, int32_t numLines)
9182
{ THISCALL_4(void, 0x554100, this, Widget, killOld, numLines); }
@@ -118,61 +109,73 @@ class CChatManager
118109
// Chat messages
119110
// Сообщения в чате.
120111
// offset: +0x0 = +0, size = 0x4 = 4
121-
CChatStr* msgArray;
112+
CChatStr* msgArray {nullptr};
122113

123114
// Current chat message index /
124115
// Индекс текущего сообщения в чате.
125116
// offset: +0x4 = +4, size = 0x4 = 4
126-
int32_t currMsg;
117+
int32_t currMsg {0};
127118

128119
// Number of chat messages /
129120
// Количество сообщений чата.
130121
// offset: +0x8 = +8, size = 0x4 = 4
131-
int32_t msgCount;
122+
int32_t msgCount {0};
132123

133124
// offset: +0xC = +12, size = 0x4 = 4
134-
const char* widgetText;
125+
const char* widgetText {nullptr};
135126

136127
// offset: +0x10 = +16, size = 0x4 = 4
137-
uint32_t pauseTime;
128+
uint32_t pauseTime {0};
138129

139130
// offset: +0x14 = +20, size = 0x1 = 1
140-
bool changed;
131+
bool changed {false};
132+
133+
unsigned char : 8;
134+
unsigned char : 8;
135+
unsigned char : 8;
141136

142137
// offset: +0x18 = +24, size = 0x4 = 4
143-
textWidget* lastWidget;
138+
textWidget* lastWidget {nullptr};
144139

145140
// offset: +0x1C = +28, size = 0x4 = 4
146-
int32_t maxLines;
141+
int32_t maxLines {0};
147142

148143
// offset: +0x20 = +32, size = 0x4 = 4
149-
int32_t position;
144+
int32_t position {-1};
150145

151146
// offset: +0x24 = +36, size = 0x1 = 1
152-
bool chatKilled;
147+
bool chatKilled {false};
148+
149+
unsigned char : 8;
150+
unsigned char : 8;
151+
unsigned char : 8;
153152

154153
// offset: +0x28 = +40, size = 0x4 = 4
155-
uint32_t channel;
154+
uint32_t channel {0};
156155

157156
// offset: +0x2C = +44, size = 0x1 = 1
158-
bool isSysMsg;
157+
bool isSysMsg {false};
158+
159+
unsigned char : 8;
160+
unsigned char : 8;
161+
unsigned char : 8;
159162

160163
// offset: +0x30 = +48, size = 0x4 = 4
161-
sample* chatSample;
164+
sample* chatSample {nullptr};
162165

163166
// offset: +0x34 = +52, size = 0x4 = 4
164-
sample* playerDropSample;
167+
sample* playerDropSample {nullptr};
165168

166169
// offset: +0x38 = +56, size = 0x4 = 4
167-
sample* sysMsgSample;
170+
sample* sysMsgSample {nullptr};
168171

169172
// offset: +0x3C = +60, size = 0x4 = 4
170-
sample* turnDurSample;
173+
sample* turnDurSample {nullptr};
171174

172175
// offset: +0x40 = +64, size = 0x4 = 4
173-
sample* playerEnterSample;
176+
sample* playerEnterSample {nullptr};
174177

175-
};
176-
#pragma pack(pop)
178+
} NH3API_MSVC_LAYOUT;
179+
#pragma pack(pop) // 4
177180

178181
inline CChatManager& chatMan = get_global_var_ref(0x69D800, CChatManager);

0 commit comments

Comments
 (0)