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

Add clang-tidy, x86 dll #20

Merged
merged 19 commits into from
Feb 25, 2024
Merged
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
6 changes: 6 additions & 0 deletions .clang-format.todo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Language: Cpp
BasedOnStyle: llvm
Standard: c++11
TabWidth: 4
PointerAlignment: Right
NamespaceIndentation: None
49 changes: 49 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Checks: '
bugprone-*
,cert-*
,cppcoreguidelines-*
,modernize-*
,performance-*
,readability-*
,portability-*
,clang-analyzer-unix
,clang-analyzer-security
,clang-analyzer-deadcode
,clang-analyzer-core
,clang-analyzer-cplusplus
,clang-analyzer-optin
,llvm-namespace-comment
,readability-static-accessed-through-instance
,misc-const-correctness
,-bugprone-reserved-identifier
,-bugprone-implicit-widening-of-multiplication-result
,-bugprone-easily-swappable-parameters
,-bugprone-narrowing-conversions
,-cert-dcl37-c
,-cert-dcl51-cpp
,-cert-msc32-c
,-cert-msc51-cpp
,-cert-msc30-c
,-cert-msc50-cpp
,-modernize-use-trailing-return-type
,-modernize-macro-to-enum
,-modernize-use-nullptr
,-modernize-use-using
,-modernize-avoid-c-arrays
,-modernize-use-auto
,-readability-avoid-unconditional-preprocessor-if
,-readability-identifier-length
,-readability-isolate-declaration
,-readability-magic-numbers
,-readability-braces-around-statements
,-readability-function-cognitive-complexity
,-cppcoreguidelines-macro-to-enum
,-cppcoreguidelines-macro-usage
,-cppcoreguidelines-pro-bounds-pointer-arithmetic
,-cppcoreguidelines-pro-type-cstyle-cast
,-cppcoreguidelines-init-variables
,-cppcoreguidelines-avoid-magic-numbers
,-cppcoreguidelines-pro-bounds-array-to-pointer-decay
,-cppcoreguidelines-avoid-c-arrays
,-cppcoreguidelines-narrowing-conversions
'
10 changes: 5 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CMake

on: [push]
on: [push, pull_request]

env:
BUILD_TYPE: Release
Expand Down Expand Up @@ -58,15 +58,15 @@ jobs:
run: conan profile detect

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

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

- name: Build
working-directory: ./build
run: cmake --build .
working-directory: build
run: cmake --build . --config Release

build-fedora-system:
if: true
Expand Down
74 changes: 70 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
name: libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm
path: build/libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm

dll:
dll_amd64:
if: true
runs-on: windows-latest

Expand All @@ -80,6 +80,13 @@ jobs:
with:
arch: x64

- name: Cache Conan
uses: actions/cache@v3
with:
key: conan-windows-amd64-${{ hashFiles('conanfile.py') }}
path: |
~/.conan2/p

- name: Install Conan
id: conan
uses: turtlebrowser/get-conan@main
Expand All @@ -98,18 +105,71 @@ jobs:

- name: Create archive
working-directory: ./build
run: Compress-Archive -Path Release/* -Destination bncsutil_${{ github.ref_name }}_amd64_dll.zip
run: |
New-Item -ItemType Directory -Path include/bncsutil -Force | Out-Null
Copy-Item -Path '../src/bncsutil/*.h' -Destination include/bncsutil
Compress-Archive -Path Release/* -DestinationPath bncsutil_${{ github.ref_name }}_amd64_dll.zip
Compress-Archive -Path include -DestinationPath "bncsutil_${{ github.ref_name }}_amd64_dll.zip" -Update

- uses: actions/upload-artifact@v4
with:
retention-days: 1
overwrite: true
name: bncsutil_${{ github.ref_name }}_amd64_dll.zip
path: build/bncsutil_${{ github.ref_name }}_amd64_dll.zip

dll_x86:
if: true
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x86

- name: Install Conan
id: conan
uses: turtlebrowser/get-conan@main

- name: Cache Conan
uses: actions/cache@v3
with:
key: conan-windows-x86-${{ hashFiles('conanfile.py') }}
path: |
~/.conan2/p

- name: Init conan
run: conan profile detect

- name: Install dependencies
shell: cmd
run: conan install . -of build -s build_type=Release -s:h arch=x86 -o *:shared=False --build=missing

- name: Build
shell: cmd
working-directory: ./build
run: .\conanbuild.bat && cmake .. -DCMAKE_GENERATOR_PLATFORM=x86 -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DBUILD_SHARED_LIBS=1 && cmake --build . --config Release

- name: Create archive
working-directory: ./build
run: |
New-Item -ItemType Directory -Path include/bncsutil -Force | Out-Null
Copy-Item -Path '../src/bncsutil/*.h' -Destination include/bncsutil
Compress-Archive -Path Release/* -DestinationPath bncsutil_${{ github.ref_name }}_x86_dll.zip
Compress-Archive -Path include -DestinationPath "bncsutil_${{ github.ref_name }}_x86_dll.zip" -Update

- uses: actions/upload-artifact@v4
with:
retention-days: 1
overwrite: true
name: bncsutil_${{ github.ref_name }}_x86_dll.zip
path: build/bncsutil_${{ github.ref_name }}_x86_dll.zip


release:
needs: [deb, rpm, dll]
needs: [deb, rpm, dll_amd64, dll_x86]
runs-on: ubuntu-latest

steps:
Expand All @@ -123,10 +183,15 @@ jobs:
with:
name: libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm

- name: Download dll
- name: Download dll amd64
uses: actions/download-artifact@v4
with:
name: bncsutil_${{ github.ref_name }}_amd64_dll.zip

- name: Download dll x86
uses: actions/download-artifact@v4
with:
name: bncsutil_${{ github.ref_name }}_x86_dll.zip

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
Expand All @@ -135,6 +200,7 @@ jobs:
libbncsutil-dev_${{ github.ref_name }}_amd64.deb
libbncsutil-devel-${{ github.ref_name }}.x86_64.rpm
bncsutil_${{ github.ref_name }}_amd64_dll.zip
bncsutil_${{ github.ref_name }}_x86_dll.zip
tag_name: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 11 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ set(SOURCES
"src/bncsutil/decodekey.cpp"
"src/bncsutil/file.cpp"
"src/bncsutil/libinfo.cpp"
"src/bncsutil/nls.c"
"src/bncsutil/oldauth.cpp"
"src/bncsutil/pe.c"
"src/bncsutil/sha1.c"
"src/bncsutil/stack.c"
)

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

if (WIN32)
set(USE_SYSTEM_LIBS 0)
option(USE_SYSTEM_LIBS "Use system libraries" OFF)
else()
set(USE_SYSTEM_LIBS 1)
option(USE_SYSTEM_LIBS "Use system libraries" ON)
endif()

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

#CPack configurtion
#CPack configuration
SET(CPACK_GENERATOR "DEB" "RPM")
SET(CPACK_PACKAGE_NAME "bncsutil")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Battle.Net Chat Service Utility")
SET(CPACK_PACKAGE_VENDOR "bncsutil")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
SET(CPACK_PACKAGE_DESCRIPTION "\
This will install the library to /usr/local/lib and header files to /usr/local/include.\n \
Make sure these directories are in your library and include paths. \
")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")

#DEB configuration
SET(CPACK_DEBIAN_PACKAGE_SECTION "libs")
Expand Down
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BNCSUtil was originally written by Eric Naeseth (shadypalm88) and has since
been maintained over the course of several years by the open source Battle.net community.

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

# Building

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

In `cmd` or Visual Studio dev console run:

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

### x86
```
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat" x86
conan install . -of build -s build_type=Release -s:h arch=x86 -o *:shared=False --build=missing
cd build
.\conanbuild.bat
cmake .. -G "Visual Studio 17 2022" -DCMAKE_GENERATOR_PLATFORM=x86 -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DBUILD_SHARED_LIBS=1
cmake --build . --config Release
```

Alternatively open `build/bncsutil.sln` and build from Visual Studio.

## Linux
Expand All @@ -58,17 +69,24 @@ If you are using pyenv or building python3 from source, make sure you have `libb
```
conan install . -of build -s build_type=Release --build=missing
cd build
./conanbuild.sh
cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DUSE_SYSTEM_LIBS=0
cmake --build . --target install --config Release
bash conanbuild.sh
cmake .. -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_LIBS=0
cmake --build . --config Release
```

## .deb and .rpm packages
After invoking CMake, cd to build folder and generate them with `cpack -G "DEB"` and `cpack -G "RPM"`.
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`.

Note that this is a "devel" package which also includes header files.
Note that this is a "development" package which also includes header files.

Library installs to `/usr/lib`, include files in `/usr/include/bncsutil`.
Library installs to `/usr/local/lib`, include files in `/usr/local/include/bncsutil`.

Packages are also available for download from github releases built on Debian Bookworm and Fedora latest.

# Development with CLion
1. Run conan from cli as per build instructions above
2. Open the project
3. Tools -> CMake -> Change Project Root -> build
4. Settings -> Build, Execution, Deployment -> CMake -> Add at least this cmake option: -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake

27 changes: 22 additions & 5 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from conan import ConanFile
from conan.tools.files import copy
from conan.tools.files import rename
import os

class Bncsutil(ConanFile):
settings = "os", "compiler", "build_type", "arch"
Expand All @@ -10,8 +12,23 @@ class Bncsutil(ConanFile):
)

def generate(self):
for dep in self.dependencies.values():
if dep.cpp_info.libdirs:
copy(self, "*.lib", dep.cpp_info.libdirs[0], self.build_folder)
if dep.cpp_info.bindirs:
copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder)
# Workaround for a conan bug producing wrongly named libraries..
if self.settings.os == "Windows":
gmp_libdir = self.dependencies["gmp"].cpp_info.libdir
gmp_from_name = f"{gmp_libdir}\libgmp.a"
gmp_to_name = f"{gmp_libdir}\gmp.lib"
gmpxx_from_name = f"{gmp_libdir}\libgmpxx.a"
gmpxx_to_name = f"{gmp_libdir}\gmpxx.lib"

if os.path.isfile(gmp_from_name):
print("Renaming " + gmp_from_name + " to " + gmp_to_name)
rename(self, gmp_from_name, gmp_to_name)
if os.path.isfile(gmpxx_from_name):
print("Renaming " + gmpxx_from_name + " to " + gmpxx_to_name)
rename(self, gmpxx_from_name, gmpxx_to_name)

for dep in self.dependencies.values():
if dep.cpp_info.libdirs:
copy(self, "*.lib", dep.cpp_info.libdirs[0], self.build_folder)
if dep.cpp_info.bindirs:
copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder)
5 changes: 5 additions & 0 deletions src/bncsutil/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* Boston, MA 02111-1307 USA
*/

#ifndef BUFFER_H
#define BUFFER_H

#include <bncsutil/mutil.h>

typedef struct msg_buffer *msg_buffer_t;
Expand Down Expand Up @@ -69,3 +72,5 @@ void buffer_add_32(msg_buffer_t, int32_t);
void buffer_add_u32(msg_buffer_t, uint32_t);

msg_reader_t create_reader(size_t initial_size);

#endif /* BUFFER_H */
1 change: 0 additions & 1 deletion src/bncsutil/cdkeydecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <cctype> // for isdigit(), isalnum(), and toupper()
#include <cstring> // for memcpy()
#include <cstdio> // for sscanf()
// #include <bncsutil/debug.h>

/**
* Implementation-specific CD-key hash structure.
Expand Down
2 changes: 1 addition & 1 deletion src/bncsutil/cdkeydecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MCEXP(CDKeyDecoder) {
inline char getHexValue(int v);
inline int getNumValue(char v);

inline void mult(const int r, const int x, int* a, int dcByte);
inline void mult(int r, int x, int* a, int dcByte);

public:
/**
Expand Down
2 changes: 1 addition & 1 deletion src/bncsutil/checkrevision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <bncsutil/pe.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <ctime>
#endif

#ifndef HIWORD
Expand Down
Loading