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..42c78a5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.19) + +project(csgo-demoinfo) + +find_package(protobuf CONFIG REQUIRED) + +add_subdirectory(demoinfogo) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..4de125b --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,42 @@ +{ + "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/protobuf/${presetName};", + "CMAKE_EXPORT_COMPILE_COMMANDS": true + } + }, + { + "name": "Debug", + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDebug" + } + }, + { + "name": "Release", + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded" + } + } + ] +} \ No newline at end of file diff --git a/demoinfogo/CMakeLists.txt b/demoinfogo/CMakeLists.txt new file mode 100644 index 0000000..b96ecf5 --- /dev/null +++ b/demoinfogo/CMakeLists.txt @@ -0,0 +1,46 @@ +# 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_proto") + +target_include_directories(demoinfogo-proto PUBLIC "$") + +protobuf_generate( + TARGET demoinfogo-proto + 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) + +# Install the executable. +# +install(TARGETS demoinfogo + RUNTIME DESTINATION "bin" +) diff --git a/demoinfogo/README.md b/demoinfogo/README.md index 24c4f74..f0f3963 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,37 @@ 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. **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/ + ... + vendor/ + out/ + protobuf/ + Release/ + Debug/ +``` + +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 +``` + +The program can be invoked with: + +``` +.\out\install\Release\bin\demoinfogo.exe +``` + Working with Network Messages ----------------------------- 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 b599cce..8446291 100644 --- a/demoinfogo/netmessages_public.proto +++ b/demoinfogo/netmessages_public.proto @@ -35,10 +35,11 @@ // 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. +syntax = "proto2"; // Commenting this out allows it to be compiled for SPEED or LITE_RUNTIME. // option optimize_for = SPEED;