From 45211d251b81ef614a9deb245eefcc222eaa4c95 Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 11:33:10 +0100 Subject: [PATCH 1/9] Add basic CMake configuration. --- .gitignore | 3 ++- CMakeLists.txt | 5 +++++ CMakePresets.json | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 CMakePresets.json diff --git a/.gitignore b/.gitignore index 7fe3670..3eee07a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ generated_proto/ demoinfogo.exe demoinfogo.opensdf protobuf-2.5.0/ -test.dem \ No newline at end of file +test.dem +/out \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9391a0b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.19) + +project(csgo-demoinfo) + +find_package(protobuf CONFIG REQUIRED) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..51b380b --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,39 @@ +{ + "version": 4, + "configurePresets": [ + { + "name": "base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "CMAKE_PREFIX_PATH": "${sourceDir}/vendor/out/zlib;${sourceDir}/vendor/out/protobuf;" + } + }, + { + "name": "debug", + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "release", + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ] +} \ No newline at end of file From fcd5424345a3f609b752f15249d954f62a1c6690 Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 14:17:15 +0100 Subject: [PATCH 2/9] Remove invalid character from netmessages_public. --- demoinfogo/netmessages_public.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demoinfogo/netmessages_public.proto b/demoinfogo/netmessages_public.proto index b599cce..7cff0ae 100644 --- a/demoinfogo/netmessages_public.proto +++ b/demoinfogo/netmessages_public.proto @@ -35,7 +35,7 @@ // There is an important difference between the signed int types (sint32 and sint64) // and the "standard" int types (int32 and int64) when it comes to encoding negative // numbers. If you use int32 or int64 as the type for a negative number, the -// resulting varint is always ten bytes long – it is, effectively, treated like a +// resulting varint is always ten bytes long - it is, effectively, treated like a // very large unsigned integer. If you use one of the signed types, the resulting // varint uses ZigZag encoding, which is much more efficient. From eb87ae8fc163f5e144ad6018d9c4e3752bcd83d0 Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 12:15:34 +0100 Subject: [PATCH 3/9] Build protos. --- CMakeLists.txt | 2 ++ demoinfogo/CMakeLists.txt | 16 ++++++++++++++++ demoinfogo/cstrike15_usermessages_public.proto | 2 ++ demoinfogo/netmessages_public.proto | 1 + 4 files changed, 21 insertions(+) create mode 100644 demoinfogo/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9391a0b..42c78a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,3 +3,5 @@ cmake_minimum_required(VERSION 3.19) project(csgo-demoinfo) find_package(protobuf CONFIG REQUIRED) + +add_subdirectory(demoinfogo) diff --git a/demoinfogo/CMakeLists.txt b/demoinfogo/CMakeLists.txt new file mode 100644 index 0000000..f8869cc --- /dev/null +++ b/demoinfogo/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(demoinfogo-proto OBJECT + "${CMAKE_CURRENT_LIST_DIR}/cstrike15_usermessages_public.proto" + "${CMAKE_CURRENT_LIST_DIR}/netmessages_public.proto" +) + +target_link_libraries(demoinfogo-proto PUBLIC protobuf::libprotobuf) + +set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") + +target_include_directories(demoinfogo-proto PUBLIC "$") + +protobuf_generate( + TARGET demoinfogo-proto + IMPORT_DIRS "${CMAKE_CURRENT_LIST_DIR}" + PROTOC_OUT_DIR "${PROTO_BINARY_DIR}" +) diff --git a/demoinfogo/cstrike15_usermessages_public.proto b/demoinfogo/cstrike15_usermessages_public.proto index 3ae219a..979f187 100644 --- a/demoinfogo/cstrike15_usermessages_public.proto +++ b/demoinfogo/cstrike15_usermessages_public.proto @@ -27,6 +27,8 @@ // //============================================================================= +syntax = "proto2"; + // We care more about speed than code size option optimize_for = SPEED; diff --git a/demoinfogo/netmessages_public.proto b/demoinfogo/netmessages_public.proto index 7cff0ae..8446291 100644 --- a/demoinfogo/netmessages_public.proto +++ b/demoinfogo/netmessages_public.proto @@ -39,6 +39,7 @@ // very large unsigned integer. If you use one of the signed types, the resulting // varint uses ZigZag encoding, which is much more efficient. +syntax = "proto2"; // Commenting this out allows it to be compiled for SPEED or LITE_RUNTIME. // option optimize_for = SPEED; From 80fb3bbe40a6b330f5bf3d32e95c5a85036accae Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 12:26:22 +0100 Subject: [PATCH 4/9] Add CMake build support. --- CMakePresets.json | 3 ++- demoinfogo/CMakeLists.txt | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 51b380b..c9df525 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -14,7 +14,8 @@ "CMAKE_C_COMPILER": "cl", "CMAKE_CXX_COMPILER": "cl", "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", - "CMAKE_PREFIX_PATH": "${sourceDir}/vendor/out/zlib;${sourceDir}/vendor/out/protobuf;" + "CMAKE_PREFIX_PATH": "${sourceDir}/vendor/out/zlib;${sourceDir}/vendor/out/protobuf;", + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded" } }, { diff --git a/demoinfogo/CMakeLists.txt b/demoinfogo/CMakeLists.txt index f8869cc..ea7f7d9 100644 --- a/demoinfogo/CMakeLists.txt +++ b/demoinfogo/CMakeLists.txt @@ -1,11 +1,13 @@ -add_library(demoinfogo-proto OBJECT +# Build protocol buffers. +# +add_library(demoinfogo-proto OBJECT STATIC "${CMAKE_CURRENT_LIST_DIR}/cstrike15_usermessages_public.proto" "${CMAKE_CURRENT_LIST_DIR}/netmessages_public.proto" ) target_link_libraries(demoinfogo-proto PUBLIC protobuf::libprotobuf) -set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") +set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_proto") target_include_directories(demoinfogo-proto PUBLIC "$") @@ -14,3 +16,25 @@ protobuf_generate( IMPORT_DIRS "${CMAKE_CURRENT_LIST_DIR}" PROTOC_OUT_DIR "${PROTO_BINARY_DIR}" ) + +# Build the executable. +# +add_executable(demoinfogo + demofile.cpp + demofile.h + + demofilebitbuf.cpp + demofilebitbuf.h + + demofiledump.cpp + demofiledump.h + + demofilepropdecode.cpp + demofilepropdecode.h + + demoinfogo.cpp +) + +target_include_directories(demoinfogo PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +target_link_libraries(demoinfogo demoinfogo-proto) From c01798de844bc193626604512863652a6931bc0e Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 12:44:50 +0100 Subject: [PATCH 5/9] Install the binary. --- demoinfogo/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/demoinfogo/CMakeLists.txt b/demoinfogo/CMakeLists.txt index ea7f7d9..b96ecf5 100644 --- a/demoinfogo/CMakeLists.txt +++ b/demoinfogo/CMakeLists.txt @@ -38,3 +38,9 @@ add_executable(demoinfogo target_include_directories(demoinfogo PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(demoinfogo demoinfogo-proto) + +# Install the executable. +# +install(TARGETS demoinfogo + RUNTIME DESTINATION "bin" +) From 187e738fe38dad29d45c07bbd1b0dce092cf6775 Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 12:44:55 +0100 Subject: [PATCH 6/9] Add instructions. --- demoinfogo/README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/demoinfogo/README.md b/demoinfogo/README.md index 24c4f74..ead993d 100644 --- a/demoinfogo/README.md +++ b/demoinfogo/README.md @@ -8,7 +8,7 @@ Demos and network messages in CS:GO use Google's Protocol Buffers (protobuf). Pr Building demoinfogo ------------------- -### Windows +### Windows In order to build demoinfogo on Windows, follow these steps: @@ -19,6 +19,33 @@ In order to build demoinfogo on Windows, follow these steps: 5. Open `demoinfogo/demoinfogo.vcxproj` in Microsoft Visual Studio 2010. Building the Release configuration creates the binary `demoinfogo/demoinfogo.exe` +### CMake on Windows + +Build and install the following libraries using CMake. + +* protobuf v21.12: https://github.com/protocolbuffers/protobuf/releases/tag/v21.12 +* zlib v1.2.13 (needed for protobuf): https://github.com/protocolbuffers/protobuf/releases/tag/v21.12 + +These libraries must be installed into `csgo-demoinfo/vendor/out`. + +``` +csgo-demoinfogo/ + ... + vendor/ + out/ + protobuf/ + zlib/ +``` + +To build `demoinfogo` with CMake, follow these steps: + +``` +cmake --preset release +cmake --build out/build/release --target install + +.\out\install\release\bin\demoinfogo.exe +``` + Working with Network Messages ----------------------------- From cc7c96ef3e2eecf44d16d38dcf46183301b21710 Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 13:19:49 +0100 Subject: [PATCH 7/9] Remove ZLIB dependency. --- CMakePresets.json | 2 +- demoinfogo/README.md | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index c9df525..1fd72bb 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -14,7 +14,7 @@ "CMAKE_C_COMPILER": "cl", "CMAKE_CXX_COMPILER": "cl", "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", - "CMAKE_PREFIX_PATH": "${sourceDir}/vendor/out/zlib;${sourceDir}/vendor/out/protobuf;", + "CMAKE_PREFIX_PATH": "${sourceDir}/vendor/out/protobuf/${presetName};", "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded" } }, diff --git a/demoinfogo/README.md b/demoinfogo/README.md index ead993d..312562a 100644 --- a/demoinfogo/README.md +++ b/demoinfogo/README.md @@ -23,10 +23,9 @@ In order to build demoinfogo on Windows, follow these steps: Build and install the following libraries using CMake. -* protobuf v21.12: https://github.com/protocolbuffers/protobuf/releases/tag/v21.12 -* zlib v1.2.13 (needed for protobuf): https://github.com/protocolbuffers/protobuf/releases/tag/v21.12 - -These libraries must be installed into `csgo-demoinfo/vendor/out`. +* protobuf v21.12: https://github.com/protocolbuffers/protobuf/releases/tag/v21.12. **Note:** You can build with `-Dprotobuf_WITH_ZLIB=OFF` as ZLIB support is not needed.* + +These libraries must be installed into `csgo-demoinfo/vendor/out/{library name}/{preset name}`. For example: ``` csgo-demoinfogo/ @@ -34,10 +33,11 @@ csgo-demoinfogo/ vendor/ out/ protobuf/ - zlib/ + release/ + debug/ ``` -To build `demoinfogo` with CMake, follow these steps: +To build `demoinfogo` with CMake (in `release` mode), open a Visual Studio developer console and follow these steps: ``` cmake --preset release From d5064db008140d87feeff82d1d487d8876742ae8 Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 13:27:59 +0100 Subject: [PATCH 8/9] Make preset names consistent. --- CMakePresets.json | 4 ++-- demoinfogo/README.md | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 1fd72bb..1231321 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -19,7 +19,7 @@ } }, { - "name": "debug", + "name": "Debug", "inherits": [ "base" ], @@ -28,7 +28,7 @@ } }, { - "name": "release", + "name": "Release", "inherits": [ "base" ], diff --git a/demoinfogo/README.md b/demoinfogo/README.md index 312562a..f0f3963 100644 --- a/demoinfogo/README.md +++ b/demoinfogo/README.md @@ -33,17 +33,21 @@ csgo-demoinfogo/ vendor/ out/ protobuf/ - release/ - debug/ + Release/ + Debug/ ``` -To build `demoinfogo` with CMake (in `release` mode), open a Visual Studio developer console and follow these steps: +To build `demoinfogo` with CMake (in `Release` mode), open a Visual Studio developer console and follow these steps: ``` -cmake --preset release -cmake --build out/build/release --target install +cmake --preset Release +cmake --build out/build/Release --target install +``` + +The program can be invoked with: -.\out\install\release\bin\demoinfogo.exe +``` +.\out\install\Release\bin\demoinfogo.exe ``` Working with Network Messages From 5aee4a7d923de4bb13d3c7ae1ee24b2cb7d27ba9 Mon Sep 17 00:00:00 2001 From: Matevz Fabjancic Date: Sat, 18 Feb 2023 14:58:59 +0100 Subject: [PATCH 9/9] Use per-build-type MSVC_RUNTIME_LIBRARY. --- CMakePresets.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 1231321..4de125b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,7 +15,7 @@ "CMAKE_CXX_COMPILER": "cl", "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", "CMAKE_PREFIX_PATH": "${sourceDir}/vendor/out/protobuf/${presetName};", - "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded" + "CMAKE_EXPORT_COMPILE_COMMANDS": true } }, { @@ -24,7 +24,8 @@ "base" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDebug" } }, { @@ -33,7 +34,8 @@ "base" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded" } } ]