Skip to content

Commit 4c327fe

Browse files
committed
CMake support, VS 2015 build fix, support for mpir instead of gmp, removed vc8 build, removed makefile, fixed stdint conflicts with modern compilers, changed README to reflect the changes
1 parent 4f753af commit 4c327fe

16 files changed

Lines changed: 2566 additions & 3309 deletions

File tree

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
*.o
2-
/src/bncsutil/libbncsutil.so
2+
*.so
3+
Release/
4+
Debug/
5+
*.dll
6+
*.lib
7+
build/

CMake/Modules/FindGMP.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Try to find the GMP librairies
2+
# GMP_FOUND - system has GMP lib
3+
# GMP_INCLUDE_DIR - the GMP include directory
4+
# GMP_LIBRARIES - Libraries needed to use GMP
5+
6+
if (GMP_INCLUDE_DIR AND GMP_LIBRARIES)
7+
set(GMP_FIND_QUIETLY TRUE)
8+
endif (GMP_INCLUDE_DIR AND GMP_LIBRARIES)
9+
10+
find_path(GMP_INCLUDE_DIR NAMES gmp.h PATHS ${CMAKE_SOURCE_DIR}/depends/include)
11+
find_library(GMP_LIBRARIES NAMES gmp libgmp PATHS ${CMAKE_SOURCE_DIR}/depends/lib )
12+
13+
MESSAGE(STATUS "GMP libs: " ${GMP_LIBRARIES} " " ${GMPXX_LIBRARIES} )
14+
include(FindPackageHandleStandardArgs)
15+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMP DEFAULT_MSG GMP_INCLUDE_DIR GMP_LIBRARIES)
16+
mark_as_advanced(GMP_INCLUDE_DIR GMP_LIBRARIES)

CMake/Modules/FindMPIR.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Try to find the MPIR librairies
2+
# MPIR_FOUND - system has MPIR lib
3+
# MPIR_INCLUDE_DIR - the MPIR include directory
4+
# MPIR_LIBRARIES - Libraries needed to use MPIR
5+
6+
if (MPIR_INCLUDE_DIR AND MPIR_LIBRARIES)
7+
set(MPIR_FIND_QUIETLY TRUE)
8+
endif (MPIR_INCLUDE_DIR AND MPIR_LIBRARIES)
9+
10+
find_path(MPIR_INCLUDE_DIR NAMES mpir.h PATHS ${CMAKE_SOURCE_DIR}/depends/include)
11+
find_library(MPIR_LIBRARIES NAMES mpir libmpir PATHS ${CMAKE_SOURCE_DIR}/depends/lib )
12+
13+
MESSAGE(STATUS "MPIR libs: " ${MPIR_LIBRARIES} " " ${MPIRXX_LIBRARIES} )
14+
include(FindPackageHandleStandardArgs)
15+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPIR DEFAULT_MSG MPIR_INCLUDE_DIR MPIR_LIBRARIES)
16+
mark_as_advanced(MPIR_INCLUDE_DIR MPIR_LIBRARIES)

CMakeLists.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
project(bncsutil)
2+
cmake_minimum_required(VERSION 2.6)
3+
4+
set(SOURCE
5+
src/bncsutil/bsha1.cpp
6+
src/bncsutil/cdkeydecoder.cpp
7+
src/bncsutil/checkrevision.cpp
8+
src/bncsutil/debug.c
9+
src/bncsutil/decodekey.cpp
10+
src/bncsutil/file.cpp
11+
src/bncsutil/libinfo.cpp
12+
src/bncsutil/nls.c
13+
src/bncsutil/oldauth.cpp
14+
src/bncsutil/pe.c
15+
src/bncsutil/sha1.c
16+
src/bncsutil/stack.c
17+
)
18+
19+
set(HEADERS
20+
src/bncsutil/bncsutil.h
21+
src/bncsutil/bsha1.h
22+
src/bncsutil/buffer.h
23+
src/bncsutil/cdkeydecoder.h
24+
src/bncsutil/checkrevision.h
25+
src/bncsutil/debug.h
26+
src/bncsutil/decodekey.h
27+
src/bncsutil/file.h
28+
src/bncsutil/keytables.h
29+
src/bncsutil/libinfo.h
30+
src/bncsutil/ms_stdint.h
31+
src/bncsutil/mutil.h
32+
src/bncsutil/mutil_types.h
33+
src/bncsutil/nls.h
34+
src/bncsutil/oldauth.h
35+
src/bncsutil/pe.h
36+
src/bncsutil/sha1.h
37+
src/bncsutil/stack.h
38+
)
39+
40+
set(CMAKE_MODULE_PATH CMake/Modules)
41+
42+
add_library(${PROJECT_NAME} SHARED ${SOURCE} ${HEADERS})
43+
add_library(${PROJECT_NAME}_static STATIC ${SOURCE} ${HEADERS})
44+
45+
if (USE_MPIR)
46+
find_package(MPIR REQUIRED)
47+
include_directories(src ${MPIR_INCLUDE_DIR})
48+
target_link_libraries(${PROJECT_NAME} ${MPIR_LIBRARIES})
49+
add_definitions(-DUSE_MPIR=1)
50+
else()
51+
find_package(GMP REQUIRED)
52+
include_directories(src ${GMP_INCLUDE_DIR})
53+
target_link_libraries(${PROJECT_NAME} ${GMP_LIBRARIES})
54+
endif()
55+
56+
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME bncsutil)
57+
58+
if(UNIX)
59+
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION 1.3.2)
60+
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1)
61+
62+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -Wno-multichar -fPIC")
63+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -Wno-multichar -fPIC")
64+
endif()
65+
66+
if (WIN32)
67+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -DMUTIL_LIB_BUILD=1")
68+
target_link_libraries(${PROJECT_NAME} Version.lib)
69+
endif()
70+
71+
install(TARGETS bncsutil RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
72+
install(FILES src/bncsutil/bncsutil.h DESTINATION include)

README.md

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,29 @@ protocol. Specifically, BNCSUtil has functions that help with the cryptography
66
of game versions, keys, and passwords.
77

88
BNCSUtil was originally written by Eric Naeseth (shadypalm88) and has since
9-
been maintained over the course of several years by the Battle.net community.
9+
been maintained over the course of several years by the open source Battle.net community.
1010

11-
## Installing
12-
Simply place the `.so` or `.dll` file in the same directory as the application
13-
that wishes to use it. If this does not work, install the file into the system
14-
library directory.
15-
16-
### Windows
17-
Copy the file to:
18-
19-
```
20-
C:\Windows\System32
21-
```
22-
23-
### Linux
24-
If you just have the `.so` file, copy it to:
25-
26-
```
27-
/usr/lib/
28-
```
29-
30-
And run:
31-
32-
```
33-
sudo ldconfig
34-
```
35-
36-
If you have just compiled from source, run this instead:
37-
38-
```
39-
sudo make install
40-
```
11+
## Usage
12+
Add `bncsutil.h` to your include directory and link against `bncsutil.lib` or `libbncsutil.so`.
4113

4214
## Building
43-
### Windows
44-
The official build of BNCSUtil for Windows is produced using Visual Studio 2005
45-
using the solution file in the `vc8_build` folder.
15+
CMake is used to generate platform specific build files. The only external dependency is GMP (The GNU Multiple Precision Arithmetic Library ).
16+
It can be installed with a package manager from any major Linux distro. Debian example: `sudo apt-get install libgmp10`.
4617

47-
BNCSUtil requires GMP.
18+
### Windows
4819

49-
### Linux
50-
To build:
51-
```
52-
cd src/bncsutil
53-
make clean
54-
make
55-
```
20+
#### GMP
21+
If you are suing an older toolchain like VS 2005 or 2008, the GMP lib and header file is already included for you in `depends/include` and `depends/lib`. You can skip this step.
22+
For newer versions of Visual Studio we recommend to use MPIR library instead which is a drop-in replacement for GMP with better Windows support.
23+
1. Go to http://mpir.org/ and download the latest source archive.
24+
2. Open the VS solution file depending on which version you use, for example build.vc14 for VS 2015.
25+
3. Make a Release build of `lib_mpir_gc` project. This produces `mpir.lib` and `mpir.h` in `build.vc14\lib_mpir_gc\Win32\Release`. Copy the header file to `depends/include` and library to `depends/lib`.
5626

57-
If you are having build related issues, ensure that:
27+
#### VS build
28+
1. In root bncsutil folder run `cmake -G "Visual Studio 14 2015" -B./build -H./` if you used GMP or `cmake -G "Visual Studio 14 2015" -B./build -H./ -DUSE_MPIR=1` if you used MPIR in previous step. Change the Visual Studio version as needed.
29+
2. CMake will generate sln file in ./build. Open it and build the library.
5830

59-
- You have the `gcc` package installed.
60-
- You have the `glibc` development package installed.
61-
- You have the `gmp` development package installed.
31+
### Linux
32+
1. Install GMP with the package manager. Also install all the necessary deveklopment tools (gcc, make or build-essential package on Debian).
33+
2. Run `cmake -G "Unix Makefiles" -B./build -H./`.
34+
3. `cd build && make && make install`.

depends/include/README.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gmp.h present in this directory was moved from the original bncsutil source code and is here for compatibility reasons.
2+
In order to use a newer version for modern compilers, see the main readme.

0 commit comments

Comments
 (0)