Skip to content

Commit 5571561

Browse files
authored
Merge pull request #20 from cen1/feature/clang-tidy
Add clang-tidy, x86 dll
2 parents 4c5fbe2 + 76721ea commit 5571561

File tree

20 files changed

+256
-83
lines changed

20 files changed

+256
-83
lines changed

.clang-format.todo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Language: Cpp
2+
BasedOnStyle: llvm
3+
Standard: c++11
4+
TabWidth: 4
5+
PointerAlignment: Right
6+
NamespaceIndentation: None

.clang-tidy

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Checks: '
2+
bugprone-*
3+
,cert-*
4+
,cppcoreguidelines-*
5+
,modernize-*
6+
,performance-*
7+
,readability-*
8+
,portability-*
9+
,clang-analyzer-unix
10+
,clang-analyzer-security
11+
,clang-analyzer-deadcode
12+
,clang-analyzer-core
13+
,clang-analyzer-cplusplus
14+
,clang-analyzer-optin
15+
,llvm-namespace-comment
16+
,readability-static-accessed-through-instance
17+
,misc-const-correctness
18+
,-bugprone-reserved-identifier
19+
,-bugprone-implicit-widening-of-multiplication-result
20+
,-bugprone-easily-swappable-parameters
21+
,-bugprone-narrowing-conversions
22+
,-cert-dcl37-c
23+
,-cert-dcl51-cpp
24+
,-cert-msc32-c
25+
,-cert-msc51-cpp
26+
,-cert-msc30-c
27+
,-cert-msc50-cpp
28+
,-modernize-use-trailing-return-type
29+
,-modernize-macro-to-enum
30+
,-modernize-use-nullptr
31+
,-modernize-use-using
32+
,-modernize-avoid-c-arrays
33+
,-modernize-use-auto
34+
,-readability-avoid-unconditional-preprocessor-if
35+
,-readability-identifier-length
36+
,-readability-isolate-declaration
37+
,-readability-magic-numbers
38+
,-readability-braces-around-statements
39+
,-readability-function-cognitive-complexity
40+
,-cppcoreguidelines-macro-to-enum
41+
,-cppcoreguidelines-macro-usage
42+
,-cppcoreguidelines-pro-bounds-pointer-arithmetic
43+
,-cppcoreguidelines-pro-type-cstyle-cast
44+
,-cppcoreguidelines-init-variables
45+
,-cppcoreguidelines-avoid-magic-numbers
46+
,-cppcoreguidelines-pro-bounds-array-to-pointer-decay
47+
,-cppcoreguidelines-avoid-c-arrays
48+
,-cppcoreguidelines-narrowing-conversions
49+
'

.github/workflows/cmake.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CMake
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
env:
66
BUILD_TYPE: Release
@@ -58,15 +58,15 @@ jobs:
5858
run: conan profile detect
5959

6060
- name: Install deps with conan
61-
run: conan install . -of ./build -s build_type=Release --build=missing
61+
run: conan install . -of build -s build_type=$BUILD_TYPE --build=missing
6262

6363
- name: Cmake
64-
working-directory: ./build
64+
working-directory: build
6565
run: bash conanbuild.sh && cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DUSE_SYSTEM_LIBS=0
6666

6767
- name: Build
68-
working-directory: ./build
69-
run: cmake --build .
68+
working-directory: build
69+
run: cmake --build . --config Release
7070

7171
build-fedora-system:
7272
if: true

.github/workflows/release.yml

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
name: libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm
7070
path: build/libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm
7171

72-
dll:
72+
dll_amd64:
7373
if: true
7474
runs-on: windows-latest
7575

@@ -80,6 +80,13 @@ jobs:
8080
with:
8181
arch: x64
8282

83+
- name: Cache Conan
84+
uses: actions/cache@v3
85+
with:
86+
key: conan-windows-amd64-${{ hashFiles('conanfile.py') }}
87+
path: |
88+
~/.conan2/p
89+
8390
- name: Install Conan
8491
id: conan
8592
uses: turtlebrowser/get-conan@main
@@ -98,18 +105,71 @@ jobs:
98105

99106
- name: Create archive
100107
working-directory: ./build
101-
run: Compress-Archive -Path Release/* -Destination bncsutil_${{ github.ref_name }}_amd64_dll.zip
108+
run: |
109+
New-Item -ItemType Directory -Path include/bncsutil -Force | Out-Null
110+
Copy-Item -Path '../src/bncsutil/*.h' -Destination include/bncsutil
111+
Compress-Archive -Path Release/* -DestinationPath bncsutil_${{ github.ref_name }}_amd64_dll.zip
112+
Compress-Archive -Path include -DestinationPath "bncsutil_${{ github.ref_name }}_amd64_dll.zip" -Update
102113
103114
- uses: actions/upload-artifact@v4
104115
with:
105116
retention-days: 1
106117
overwrite: true
107118
name: bncsutil_${{ github.ref_name }}_amd64_dll.zip
108119
path: build/bncsutil_${{ github.ref_name }}_amd64_dll.zip
120+
121+
dll_x86:
122+
if: true
123+
runs-on: windows-latest
124+
125+
steps:
126+
- uses: actions/checkout@v4
127+
128+
- uses: TheMrMilchmann/setup-msvc-dev@v3
129+
with:
130+
arch: x86
131+
132+
- name: Install Conan
133+
id: conan
134+
uses: turtlebrowser/get-conan@main
135+
136+
- name: Cache Conan
137+
uses: actions/cache@v3
138+
with:
139+
key: conan-windows-x86-${{ hashFiles('conanfile.py') }}
140+
path: |
141+
~/.conan2/p
142+
143+
- name: Init conan
144+
run: conan profile detect
145+
146+
- name: Install dependencies
147+
shell: cmd
148+
run: conan install . -of build -s build_type=Release -s:h arch=x86 -o *:shared=False --build=missing
149+
150+
- name: Build
151+
shell: cmd
152+
working-directory: ./build
153+
run: .\conanbuild.bat && cmake .. -DCMAKE_GENERATOR_PLATFORM=x86 -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DBUILD_SHARED_LIBS=1 && cmake --build . --config Release
154+
155+
- name: Create archive
156+
working-directory: ./build
157+
run: |
158+
New-Item -ItemType Directory -Path include/bncsutil -Force | Out-Null
159+
Copy-Item -Path '../src/bncsutil/*.h' -Destination include/bncsutil
160+
Compress-Archive -Path Release/* -DestinationPath bncsutil_${{ github.ref_name }}_x86_dll.zip
161+
Compress-Archive -Path include -DestinationPath "bncsutil_${{ github.ref_name }}_x86_dll.zip" -Update
162+
163+
- uses: actions/upload-artifact@v4
164+
with:
165+
retention-days: 1
166+
overwrite: true
167+
name: bncsutil_${{ github.ref_name }}_x86_dll.zip
168+
path: build/bncsutil_${{ github.ref_name }}_x86_dll.zip
109169

110170

111171
release:
112-
needs: [deb, rpm, dll]
172+
needs: [deb, rpm, dll_amd64, dll_x86]
113173
runs-on: ubuntu-latest
114174

115175
steps:
@@ -123,10 +183,15 @@ jobs:
123183
with:
124184
name: libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm
125185

126-
- name: Download dll
186+
- name: Download dll amd64
127187
uses: actions/download-artifact@v4
128188
with:
129189
name: bncsutil_${{ github.ref_name }}_amd64_dll.zip
190+
191+
- name: Download dll x86
192+
uses: actions/download-artifact@v4
193+
with:
194+
name: bncsutil_${{ github.ref_name }}_x86_dll.zip
130195

131196
- name: Create GitHub Release
132197
uses: softprops/action-gh-release@v1
@@ -135,6 +200,7 @@ jobs:
135200
libbncsutil-dev_${{ github.ref_name }}_amd64.deb
136201
libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm
137202
bncsutil_${{ github.ref_name }}_amd64_dll.zip
203+
bncsutil_${{ github.ref_name }}_x86_dll.zip
138204
tag_name: ${{ github.ref_name }}
139205
env:
140206
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@ set(SOURCES
3737
"src/bncsutil/decodekey.cpp"
3838
"src/bncsutil/file.cpp"
3939
"src/bncsutil/libinfo.cpp"
40+
"src/bncsutil/nls.c"
4041
"src/bncsutil/oldauth.cpp"
42+
"src/bncsutil/pe.c"
4143
"src/bncsutil/sha1.c"
44+
"src/bncsutil/stack.c"
4245
)
4346

4447
target_sources(bncsutil PRIVATE ${SOURCES} ${HEADERS})
4548

4649
if (WIN32)
47-
set(USE_SYSTEM_LIBS 0)
50+
option(USE_SYSTEM_LIBS "Use system libraries" OFF)
4851
else()
49-
set(USE_SYSTEM_LIBS 1)
52+
option(USE_SYSTEM_LIBS "Use system libraries" ON)
5053
endif()
5154

5255
if (CMAKE_GENERATOR_PLATFORM EQUAL "x86")
@@ -97,16 +100,20 @@ endif()
97100
install(TARGETS bncsutil RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
98101
install(FILES ${HEADERS} DESTINATION include/bncsutil)
99102

100-
#CPack configurtion
103+
#CPack configuration
101104
SET(CPACK_GENERATOR "DEB" "RPM")
102105
SET(CPACK_PACKAGE_NAME "bncsutil")
103106
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Battle.Net Chat Service Utility")
104107
SET(CPACK_PACKAGE_VENDOR "bncsutil")
105-
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
108+
SET(CPACK_PACKAGE_DESCRIPTION "\
109+
This will install the library to /usr/local/lib and header files to /usr/local/include.\n \
110+
Make sure these directories are in your library and include paths. \
111+
")
106112
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
107113
SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
108114
SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
109115
SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
116+
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
110117

111118
#DEB configuration
112119
SET(CPACK_DEBIAN_PACKAGE_SECTION "libs")

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ BNCSUtil was originally written by Eric Naeseth (shadypalm88) and has since
1616
been maintained over the course of several years by the open source Battle.net community.
1717

1818
# Usage
19-
Add `bncsutil.h` to your include directory and link against `bncsutil.lib` or `libbncsutil.so`.
19+
`#include <bncsutil/bncsutil.h>` and link against `bncsutil.lib` or `libbncsutil.so`.
2020

2121
# Building
2222

@@ -30,6 +30,7 @@ Conan is used to install dependencies. GMP can't be installed as a shared librar
3030

3131
In `cmd` or Visual Studio dev console run:
3232

33+
### amd64
3334
```
3435
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat" x64
3536
conan install . -of build -s build_type=Release -o *:shared=False --build=missing
@@ -39,6 +40,16 @@ cmake .. -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
3940
cmake --build . --config Release
4041
```
4142

43+
### x86
44+
```
45+
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat" x86
46+
conan install . -of build -s build_type=Release -s:h arch=x86 -o *:shared=False --build=missing
47+
cd build
48+
.\conanbuild.bat
49+
cmake .. -G "Visual Studio 17 2022" -DCMAKE_GENERATOR_PLATFORM=x86 -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DBUILD_SHARED_LIBS=1
50+
cmake --build . --config Release
51+
```
52+
4253
Alternatively open `build/bncsutil.sln` and build from Visual Studio.
4354

4455
## Linux
@@ -58,17 +69,24 @@ If you are using pyenv or building python3 from source, make sure you have `libb
5869
```
5970
conan install . -of build -s build_type=Release --build=missing
6071
cd build
61-
./conanbuild.sh
62-
cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DUSE_SYSTEM_LIBS=0
63-
cmake --build . --target install --config Release
72+
bash conanbuild.sh
73+
cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_LIBS=0
74+
cmake --build . --config Release
6475
```
6576

6677
## .deb and .rpm packages
6778
After invoking CMake, cd to build folder and generate them with `cpack -G "DEB"` and `cpack -G "RPM"`.
6879
You can then use `gdebi` to do a local install of .deb with automatic dependency resolution or `yum localinstall` on rpm distros. For dnf it's `dnf install <name>.rpm`.
6980

70-
Note that this is a "devel" package which also includes header files.
81+
Note that this is a "development" package which also includes header files.
7182

72-
Library installs to `/usr/lib`, include files in `/usr/include/bncsutil`.
83+
Library installs to `/usr/local/lib`, include files in `/usr/local/include/bncsutil`.
7384

7485
Packages are also available for download from github releases built on Debian Bookworm and Fedora latest.
86+
87+
# Development with CLion
88+
1. Run conan from cli as per build instructions above
89+
2. Open the project
90+
3. Tools -> CMake -> Change Project Root -> build
91+
4. Settings -> Build, Execution, Deployment -> CMake -> Add at least this cmake option: -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
92+

conanfile.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from conan import ConanFile
22
from conan.tools.files import copy
3+
from conan.tools.files import rename
4+
import os
35

46
class Bncsutil(ConanFile):
57
settings = "os", "compiler", "build_type", "arch"
@@ -10,8 +12,23 @@ class Bncsutil(ConanFile):
1012
)
1113

1214
def generate(self):
13-
for dep in self.dependencies.values():
14-
if dep.cpp_info.libdirs:
15-
copy(self, "*.lib", dep.cpp_info.libdirs[0], self.build_folder)
16-
if dep.cpp_info.bindirs:
17-
copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder)
15+
# Workaround for a conan bug producing wrongly named libraries..
16+
if self.settings.os == "Windows":
17+
gmp_libdir = self.dependencies["gmp"].cpp_info.libdir
18+
gmp_from_name = f"{gmp_libdir}\libgmp.a"
19+
gmp_to_name = f"{gmp_libdir}\gmp.lib"
20+
gmpxx_from_name = f"{gmp_libdir}\libgmpxx.a"
21+
gmpxx_to_name = f"{gmp_libdir}\gmpxx.lib"
22+
23+
if os.path.isfile(gmp_from_name):
24+
print("Renaming " + gmp_from_name + " to " + gmp_to_name)
25+
rename(self, gmp_from_name, gmp_to_name)
26+
if os.path.isfile(gmpxx_from_name):
27+
print("Renaming " + gmpxx_from_name + " to " + gmpxx_to_name)
28+
rename(self, gmpxx_from_name, gmpxx_to_name)
29+
30+
for dep in self.dependencies.values():
31+
if dep.cpp_info.libdirs:
32+
copy(self, "*.lib", dep.cpp_info.libdirs[0], self.build_folder)
33+
if dep.cpp_info.bindirs:
34+
copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder)

src/bncsutil/buffer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
* Boston, MA 02111-1307 USA
2424
*/
2525

26+
#ifndef BUFFER_H
27+
#define BUFFER_H
28+
2629
#include <bncsutil/mutil.h>
2730

2831
typedef struct msg_buffer *msg_buffer_t;
@@ -69,3 +72,5 @@ void buffer_add_32(msg_buffer_t, int32_t);
6972
void buffer_add_u32(msg_buffer_t, uint32_t);
7073

7174
msg_reader_t create_reader(size_t initial_size);
75+
76+
#endif /* BUFFER_H */

src/bncsutil/cdkeydecoder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <cctype> // for isdigit(), isalnum(), and toupper()
3232
#include <cstring> // for memcpy()
3333
#include <cstdio> // for sscanf()
34-
// #include <bncsutil/debug.h>
3534

3635
/**
3736
* Implementation-specific CD-key hash structure.

src/bncsutil/cdkeydecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ MCEXP(CDKeyDecoder) {
5959
inline char getHexValue(int v);
6060
inline int getNumValue(char v);
6161

62-
inline void mult(const int r, const int x, int* a, int dcByte);
62+
inline void mult(int r, int x, int* a, int dcByte);
6363

6464
public:
6565
/**

0 commit comments

Comments
 (0)