From 33c4062e3155e4d41eb1c454ecc85f3d67129870 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 10 Oct 2023 12:51:28 +0700 Subject: [PATCH] Add workflows/build.yml --- .github/workflows/build.yml | 133 +++++++++++++++++++++++ .gitignore | 2 + CMakeLists.txt | 170 ++++++++++++++++++++++++++++++ Makefile | 47 --------- build.sh | 60 +++++++++++ cssdk/engine/maintypes.h | 7 ++ dist/config.ini | 26 ++--- include/engine_rehlds_api.h | 5 - include/precompiled.h | 2 + msvc/PostBuild.bat | 45 ++++++++ msvc/PreBuild.bat | 204 ++++++++++++++++++++++++++++++++++++ msvc/resemiclip.vcxproj | 41 ++++++-- src/meta_api.cpp | 8 +- version/appversion.sh | 153 +++++++++++++++++++++++++++ version/version.h | 10 ++ version_script.lds | 16 +++ 16 files changed, 853 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 CMakeLists.txt delete mode 100644 Makefile create mode 100755 build.sh create mode 100644 msvc/PostBuild.bat create mode 100644 msvc/PreBuild.bat create mode 100755 version/appversion.sh create mode 100644 version/version.h create mode 100644 version_script.lds diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8f7136b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,133 @@ +name: C/C++ CI + +on: + push: + branches: [master] + paths-ignore: + - '**.md' + + pull_request: + types: [opened, reopened, synchronize] + release: + types: [published] + +jobs: + windows: + name: 'Windows' + runs-on: windows-2019 + + env: + solution: 'msvc/resemiclip.sln' + buildPlatform: 'Win32' + buildRelease: 'Release' + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v1.1.3 + with: + vs-version: '16.8' + + - name: Build + run: | + msbuild ${{ env.solution }} -p:Configuration="${{ env.buildRelease }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false + + - name: Copy Binary files + run: | + mkdir publish\addons\resemiclip + move msvc\${{ env.buildRelease }}\resemiclip_mm.dll publish\addons\resemiclip\resemiclip_mm.dll + + - name: Deploy artifacts + uses: actions/upload-artifact@v3.1.1 + with: + name: win32 + path: publish/* + + linux: + name: 'Linux' + runs-on: ubuntu-latest + container: s1lentq/linux86buildtools:latest + outputs: + app-version: ${{ steps.app-version.outputs.version }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Build using Intel C++ Compiler 19.0 + run: | + rm -rf build && CC=icc CXX=icpc cmake -B build && cmake --build build -j8 + + - name: Reading appversion.h + id: app-version + run: | + if [ -e "version/appversion.h" ]; then + APP_VERSION=$(cat "version/appversion.h" | grep -wi '#define APP_VERSION_STRD' | sed -e 's/#define APP_VERSION_STRD[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g') + if [ $? -ne 0 ]; then + APP_VERSION="" + else + # Remove quotes + APP_VERSION=$(echo $APP_VERSION | xargs) + fi + fi + echo "version=${APP_VERSION}" >> "$GITHUB_OUTPUT" + shell: bash + + - name: Prepare Config files + run: | + mkdir -p publish/addons/resemiclip + rsync -a dist/ publish/addons/resemiclip/ + + - name: Copy Binary files + run: | + mv build/resemiclip_mm_i386.so publish/addons/resemiclip/resemiclip_mm_i386.so + + - name: Deploy artifacts + uses: actions/upload-artifact@v3.1.1 + id: upload-job + with: + name: linux32 + path: publish/* + + publish: + name: 'Publish' + runs-on: ubuntu-latest + needs: [windows, linux] + + steps: + - name: Deploying linux artifacts + uses: actions/download-artifact@v3 + with: + name: linux32 + + - name: Deploying windows artifacts + uses: actions/download-artifact@v3 + with: + name: win32 + + - name: Packaging binaries + id: packaging-job + if: | + github.event_name == 'release' && + github.event.action == 'published' && + startsWith(github.ref, 'refs/tags/') + run: | + 7z a -tzip resemiclip-${{ needs.linux.outputs.app-version }}.zip addons/ + + - name: Publish artifacts + uses: softprops/action-gh-release@v1 + id: publish-job + if: | + startsWith(github.ref, 'refs/tags/') && + steps.packaging-job.outcome == 'success' + with: + files: | + *.zip + env: + GITHUB_TOKEN: ${{ secrets.API_TOKEN }} diff --git a/.gitignore b/.gitignore index b790e17..b123ea6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .idea *.iml +/build **/msvc/ipch **/msvc/Debug* **/msvc/Release* @@ -13,3 +14,4 @@ **/msvc/*.txt **/msvc/*.db **/*.log +**/version/appversion.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ac76c46 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,170 @@ +#---------------------------------------- +# 1. Preparing build: +# rm -rf build +# mkdir build && cd build +# +# 2. Select compiler and build it +# - Compile with Clang: +# CC="clang" CXX="clang++" cmake .. +# make +# +# - Compile with Intel C++ Compiler: +# CC="icc" CXX="icpc" cmake .. +# make +# +# - Compile with GCC Compiler: +# cmake .. +# make +#---------------------------------------- + +cmake_minimum_required(VERSION 3.1) +project(resemiclip CXX) + +option(DEBUG "Build with debug information." OFF) +option(USE_STATIC_LIBSTDC "Enables static linking libstdc++." OFF) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Avoid -fPIC option +set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") + +set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32 -s") + +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-builtin -Wno-unknown-pragmas") + +# Remove noxref code and data +set(COMPILE_FLAGS "${COMPILE_FLAGS} -ffunction-sections -fdata-sections") + +if (DEBUG) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") +else() + set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") +endif() + +# Check Intel C++ compiler +if ("$ENV{CXX}" MATCHES "icpc") + # + # -fp-model=precise + # ICC uses -fp-model fast=1 by default for more aggressive optimizations on floating-point calculations + # https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/floating-point-options/fp-model-fp.html#fp-model-fp_GUID-99936BBA-1508-4E9F-AC09-FA98613CE2F5 + # + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ + -fp-model=precise\ + -Qoption,cpp,--treat_func_as_string_literal_cpp\ + -inline-forceinline\ + -no-ansi-alias") + + set(LINK_FLAGS "${LINK_FLAGS} \ + -static-intel\ + -no-intel-extensions") + + if (NOT DEBUG) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") + set(LINK_FLAGS "${LINK_FLAGS} -ipo") + endif() +else() + # Produce code optimized for the most common IA32/AMD64/EM64T processors. + # As new processors are deployed in the marketplace, the behavior of this option will change. + set(COMPILE_FLAGS "${COMPILE_FLAGS} \ + -mtune=generic -msse3\ + -Wno-write-strings\ + -fno-sized-deallocation -Wno-strict-aliasing") +endif() + +# GCC >= 8.3 +if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") +endif() + +if (NOT DEBUG) + set(LINK_FLAGS "${LINK_FLAGS} \ + -Wl,-gc-sections -Wl,--version-script=\"${PROJECT_SOURCE_DIR}/version_script.lds\"") +endif() + +set(PROJECT_SRC_DIR + "${PROJECT_SOURCE_DIR}/" + "${PROJECT_SOURCE_DIR}/src" + "${PROJECT_SOURCE_DIR}/include" + "${PROJECT_SOURCE_DIR}/version" +) + +set(PROJECT_CSSDK_DIR + "${PROJECT_SOURCE_DIR}/cssdk/common" + "${PROJECT_SOURCE_DIR}/cssdk/dlls" + "${PROJECT_SOURCE_DIR}/cssdk/engine" + "${PROJECT_SOURCE_DIR}/cssdk/game_shared" + "${PROJECT_SOURCE_DIR}/cssdk/pm_shared" + "${PROJECT_SOURCE_DIR}/cssdk/public" +) + +set(PROJECT_METAMOD_DIR + "${PROJECT_SOURCE_DIR}/metamod" +) + +set(MAIN_SRCS + "src/precompiled.cpp" + "src/h_export.cpp" + "src/gamedll_api.cpp" + "src/engine_rehlds_api.cpp" + "src/meta_api.cpp" + "src/main.cpp" + "src/config.cpp" +) + +set(PUBLIC_SRCS + "cssdk/public/interface.cpp" +) + +add_library(resemiclip SHARED ${appversion.sh}) + +if (NOT TARGET appversion) + add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/version/appversion.sh" "${PROJECT_SOURCE_DIR}/") +endif() + +add_dependencies(resemiclip appversion) + +target_include_directories(resemiclip PRIVATE + ${PROJECT_SRC_DIR} + ${PROJECT_CSSDK_DIR} + ${PROJECT_METAMOD_DIR} +) + +target_compile_definitions(resemiclip PRIVATE + _LINUX + LINUX + NDEBUG + _GLIBCXX_USE_CXX11_ABI=0 + HAVE_STRONG_TYPEDEF + _stricmp=strcasecmp + _strnicmp=strncasecmp + _vsnprintf=vsnprintf + _snprintf=snprintf +) + +target_sources(resemiclip PRIVATE + ${MAIN_SRCS} + ${PUBLIC_SRCS} +) + +target_link_libraries(resemiclip PRIVATE + dl +) + +if (USE_STATIC_LIBSTDC) + target_compile_definitions(resemiclip PRIVATE BUILD_STATIC_LIBSTDC) + set(LINK_FLAGS "${LINK_FLAGS} -static-libgcc -static-libstdc++") +endif() + +set(LINK_FLAGS "${LINK_FLAGS} \ + -Wl,-rpath,'$ORIGIN/.' \ + -L${PROJECT_SOURCE_DIR}/lib/linux32") + +set_target_properties(resemiclip PROPERTIES + OUTPUT_NAME resemiclip_mm_i386 + PREFIX "" + COMPILE_FLAGS ${COMPILE_FLAGS} + LINK_FLAGS ${LINK_FLAGS} + POSITION_INDEPENDENT_CODE OFF +) diff --git a/Makefile b/Makefile deleted file mode 100644 index 548c154..0000000 --- a/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -HLSDK = cssdk -METAMOD = metamod -M_INCLUDE = include - -NAME = resemiclip - -COMPILER = /opt/intel/bin/icpc - -OBJECTS = src/precompiled.cpp src/h_export.cpp src/gamedll_api.cpp src/engine_rehlds_api.cpp \ - src/meta_api.cpp src/main.cpp src/config.cpp cssdk/public/interface.cpp - -LINK = -static-intel -static-libgcc -no-intel-extensions - -OPT_FLAGS = -O3 -msse3 -ipo -no-prec-div -fp-model fast=2 -funroll-loops -fomit-frame-pointer -fno-stack-protector - -INCLUDE = -I. -I$(M_INCLUDE)/ -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine \ - -I$(HLSDK)/game_shared -I$(HLSDK)/pm_shared -I$(HLSDK)/public -I$(METAMOD) - -BIN_DIR = Release -CFLAGS = $(OPT_FLAGS) - -CFLAGS += -g -DNDEBUG -Dlinux -D__linux__ -D__USE_GNU -D_vsnprintf=vsnprintf -std=c++0x -shared -wd147,274 -fasm-blocks -m32 - -OBJ_LINUX := $(OBJECTS:%.c=$(BIN_DIR)/%.o) - -$(BIN_DIR)/%.o: %.c - $(COMPILER) $(INCLUDE) $(CFLAGS) -o $@ -c $< - -all: - mkdir -p $(BIN_DIR) - - $(MAKE) $(NAME) && strip -x $(BIN_DIR)/$(NAME)_mm_i386.so - -$(NAME): $(OBJ_LINUX) - $(COMPILER) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -o$(BIN_DIR)/$(NAME)_mm_i386.so - -check: - cppcheck $(INCLUDE) --quiet --max-configs=100 -D__linux__ -DNDEBUG . - -debug: - $(MAKE) all DEBUG=false - -default: all - -clean: - rm -rf Release/*.o - rm -rf Release/$(NAME)_mm_i386.so diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..5f474d9 --- /dev/null +++ b/build.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +main() +{ + CC=gcc + CXX=g++ + + if [[ "$*" =~ "--help" ]]; then + help + exit 0; + fi + + n=0 + args=() + for i in "$@" + do + case $i in + -j=*|--jobs=*) + jobs="-j${i#*=}" + shift + ;; + -c=*|--compiler=*) + C="${i#*=}" + shift + ;; + *) + args[$n]="$i" + ((++n)) + ;; + esac + done + + case "$C" in + ("intel"|"icc") CC=icc CXX=icpc ;; + ("gcc"|"g++") CC=gcc CXX=g++ ;; + ("clang"|"llvm") CC=clang CXX=clang++ ;; + *) + ;; + esac + + rm -rf build + mkdir build + pushd build &> /dev/null + CC=$CC CXX=$CXX cmake ${args[@]} .. + make ${jobs} + popd > /dev/null +} + +help() +{ + printf "Usage: ./build.sh \n\n" + printf " -c= | --compiler= - Select preferred C/C++ compiler to build\n" + printf " -j= | --jobs= - Specifies the number of jobs (commands) to run simultaneously (For faster building)\n\n" +} + +# Initialize +main $* + +# Exit normally +exit 0 diff --git a/cssdk/engine/maintypes.h b/cssdk/engine/maintypes.h index 40ae20c..7f54b18 100644 --- a/cssdk/engine/maintypes.h +++ b/cssdk/engine/maintypes.h @@ -49,4 +49,11 @@ typedef unsigned int string_t; // from engine's pr_comp.h; +// From engine/server.h +typedef enum sv_delta_s +{ + sv_packet_nodelta, + sv_packet_delta, +} sv_delta_t; + #endif // MAINTYPES_H diff --git a/dist/config.ini b/dist/config.ini index 64ba379..d91862f 100644 --- a/dist/config.ini +++ b/dist/config.ini @@ -1,18 +1,18 @@ # Description # -# semiclip 0|1 Выключить / Включить semiclip -# team 0|1|2|3 -# - 0 Semiclip действует для всех -# - 1 Semiclip действует только для T -# - 2 Semiclip действует только для CT -# - 3 Semiclip действут только для тиммейтов +# semiclip 0|1 Turn Off / Turn On semiclip +# team 0|1|2|3 +# - 0 Semiclip applies to everyone +# - 1 Semiclip applies only to T (Terrorist team) +# - 2 Semiclip applies only to CT (Counter-Terrorist team) +# - 3 Semiclip applies only to teammates # -# time 0|180 Сколько длится действие semiclip от начала раунда. -# crouch 0|1 Автоматизация подсадок. -# effects 0|1 Эффект прозрачности игрока зависит от расстоянии между игроками. -# distance 64|250 На какой дистанции игрок может иметь прозрачность и действие semiclip. -# transparency 0|255 Прозрачность игрока. -# penetfire 0|1 Пропускать огонь по "прозрачным" союзникам. +# time 0|180 How long does the semiclip effect last from the start of the round +# crouch 0|1 Automation of crouching (players can jump onto a crouching player) +# effects 0|1 Player transparency depends on the distance between players +# distance 64|250 At what distance can a player have transparency and the semiclip effect +# transparency 0|255 Player transparency +# penetfire 0|1 Allow bullets to pass through "transparent" allies # semiclip = 1; @@ -22,4 +22,4 @@ crouch = 1; effects = 0; distance = 200; transparency = 120; -penetfire = 0; \ No newline at end of file +penetfire = 0; diff --git a/include/engine_rehlds_api.h b/include/engine_rehlds_api.h index 2fccc5b..3fd6780 100644 --- a/include/engine_rehlds_api.h +++ b/include/engine_rehlds_api.h @@ -7,11 +7,6 @@ extern IRehldsApi* g_RehldsApi; extern IRehldsHookchains* g_RehldsHookchains; extern bool RehldsApi_Init(); -typedef enum sv_delta_s { - sv_packet_nodelta, - sv_packet_delta -} sv_delta_t; - typedef struct packet_entities_s { int num_entities; unsigned char flags[32]; diff --git a/include/precompiled.h b/include/precompiled.h index 0086be6..4e60f16 100644 --- a/include/precompiled.h +++ b/include/precompiled.h @@ -3,6 +3,8 @@ #include #include +#include "version/appversion.h" + #include "cbase.h" #include "entity_state.h" #include "pm_defs.h" diff --git a/msvc/PostBuild.bat b/msvc/PostBuild.bat new file mode 100644 index 0000000..cbee117 --- /dev/null +++ b/msvc/PostBuild.bat @@ -0,0 +1,45 @@ +@echo OFF +:: +:: Post-build auto-deploy script +:: Create and fill PublishPath.txt file with path to deployment folder +:: I.e. PublishPath.txt should contain one line with a folder path +:: Call it so: +:: IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") +:: + +SET targetDir=%~1 +SET targetDirPlay=%targetDir:Play=% + +SET targetName=%~2 +SET targetExt=%~3 +SET projectDir=%~4 +SET destination=PublishPath + +IF NOT "%targetDir%"=="%targetDirPlay%" ( + SET destination=PublishPath_play +) + +IF NOT EXIST "%projectDir%\%destination%.txt" ( + ECHO No deployment path specified. Create %destination%.txt near PostBuild.bat with paths on separate lines for auto deployment. + exit /B 0 +) + +FOR /f "tokens=* delims= usebackq" %%a IN ("%projectDir%\%destination%.txt") DO ( + ECHO Deploying to: %%a + IF NOT "%%a" == "" ( + copy /Y "%targetDir%%targetName%%targetExt%" "%%a" + IF NOT ERRORLEVEL 1 ( + IF EXIST "%targetDir%%targetName%.pdb" ( + copy /Y "%targetDir%%targetName%.pdb" "%%a" + ) + ) ELSE ( + ECHO PostBuild.bat ^(27^) : warning : Can't copy '%targetName%%targetExt%' to deploy path '%%a' + ) + ) +) + +IF "%%a" == "" ( + ECHO No deployment path specified. +) + +exit /B 0 \ No newline at end of file diff --git a/msvc/PreBuild.bat b/msvc/PreBuild.bat new file mode 100644 index 0000000..06ce6ba --- /dev/null +++ b/msvc/PreBuild.bat @@ -0,0 +1,204 @@ +@setlocal enableextensions enabledelayedexpansion +@echo off +:: +:: Pre-build auto-versioning script +:: + +set srcdir=%~1 +set repodir=%~2 + +set old_version= +set version_major=0 +set version_minor=0 +set version_modifed= + +set commitSHA= +set commitURL= +set commitCount=0 +set branch_name=master + +for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a" +set "YYYY=%dt:~0,4%" +set "MM=%dt:~4,2%" +set "DD=%dt:~6,2%" +set "hour=%dt:~8,2%" +set "min=%dt:~10,2%" +set "sec=%dt:~12,2%" + +:: +:: Remove leading zero from MM (e.g 09 > 9) +for /f "tokens=* delims=0" %%I in ("%MM%") do set MM=%%I +:: + +:: +:: Index into array to get month name +:: +for /f "tokens=%MM%" %%I in ("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do set "month=%%I" + +:: +:: Check for git.exe presence +:: +CALL git.exe describe >NUL 2>&1 +set errlvl="%ERRORLEVEL%" + +:: +:: Read old appversion.h, if present +:: +IF EXIST "%srcdir%\appversion.h" ( + FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\appversion.h") do ( + IF %%i==#define ( + IF %%j==APP_VERSION ( + :: Remove quotes + set v=%%k + set old_version=!v:"=! + ) + ) + ) +) + +IF %errlvl% == "1" ( + echo can't locate git.exe - auto-versioning step won't be performed + + :: if we haven't appversion.h, we need to create it + IF NOT "%old_version%" == "" ( + set commitCount=0 + ) +) + +:: +:: Read major, minor and maintenance version components from version.h +:: +IF EXIST "%srcdir%\version.h" ( + FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\version.h") do ( + IF %%i==#define ( + IF %%j==VERSION_MAJOR set version_major=%%k + IF %%j==VERSION_MINOR set version_minor=%%k + ) + ) +) + +:: +:: Read revision and release date from it +:: +IF NOT %errlvl% == "1" ( + :: Get current branch + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --abbrev-ref HEAD"') DO ( + set branch_name=%%i + ) + + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-list --count !branch_name!"') DO ( + IF NOT [%%i] == [] ( + set commitCount=%%i + ) + ) +) + +:: +:: Get remote url repository +:: +IF NOT %errlvl% == "1" ( + + set branch_remote=origin + :: Get remote name by current branch + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." config branch.!branch_name!.remote"') DO ( + set branch_remote=%%i + ) + :: Get remote url + FOR /F "tokens=2 delims=@" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO ( + set commitURL=%%i + ) + :: Get commit id + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --verify HEAD"') DO ( + set shafull=%%i + set commitSHA=!shafull:~0,+7! + ) + + IF [!commitURL!] == [] ( + + FOR /F "tokens=1" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO ( + set commitURL=%%i + ) + + :: strip .git + if "x!commitURL:~-4!"=="x.git" ( + set commitURL=!commitURL:~0,-4! + ) + + :: append extra string + If NOT "!commitURL!"=="!commitURL:bitbucket.org=!" ( + set commitURL=!commitURL!/commits/ + ) ELSE ( + set commitURL=!commitURL!/commit/ + ) + + ) ELSE ( + :: strip .git + if "x!commitURL:~-4!"=="x.git" ( + set commitURL=!commitURL:~0,-4! + ) + :: replace : to / + set commitURL=!commitURL::=/! + + :: append extra string + If NOT "!commitURL!"=="!commitURL:bitbucket.org=!" ( + set commitURL=https://!commitURL!/commits/ + ) ELSE ( + set commitURL=https://!commitURL!/commit/ + ) + ) +) + +:: +:: Detect local modifications +:: +set localChanged=0 +IF NOT %errlvl% == "1" ( + FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." ls-files -m"') DO ( + set localChanged=1 + ) +) + +IF [%localChanged%]==[1] ( + set version_modifed=+m +) + +:: +:: Now form full version string like 1.0.0.1 +:: + +set new_version=%version_major%.%version_minor%.%commitCount%%version_modifed% + +:: +:: Update appversion.h if version has changed or modifications/mixed revisions detected +:: +IF NOT "%new_version%"=="%old_version%" goto _update +goto _exit + +:_update +echo Updating appversion.h, new version is "%new_version%", the old one was %old_version% + +echo #ifndef __APPVERSION_H__>"%srcdir%\appversion.h" +echo #define __APPVERSION_H__>>"%srcdir%\appversion.h" +echo.>>"%srcdir%\appversion.h" +echo // >>"%srcdir%\appversion.h" +echo // This file is generated automatically.>>"%srcdir%\appversion.h" +echo // Don't edit it.>>"%srcdir%\appversion.h" +echo // >>"%srcdir%\appversion.h" +echo.>>"%srcdir%\appversion.h" +echo // Version defines>>"%srcdir%\appversion.h" +echo #define APP_VERSION "%new_version%">>"%srcdir%\appversion.h" + +echo.>>"%srcdir%\appversion.h" +echo #define APP_COMMIT_DATE "%month% %DD% %YYYY%">>"%srcdir%\appversion.h" +echo #define APP_COMMIT_TIME "%hour%:%min%:%sec%">>"%srcdir%\appversion.h" + +echo.>>"%srcdir%\appversion.h" +echo #define APP_COMMIT_SHA "%commitSHA%">>"%srcdir%\appversion.h" +echo #define APP_COMMIT_URL "%commitURL%">>"%srcdir%\appversion.h" +echo.>>"%srcdir%\appversion.h" + +echo #endif //__APPVERSION_H__>>"%srcdir%\appversion.h" +echo.>>"%srcdir%\appversion.h" + +:_exit +exit /B 0 diff --git a/msvc/resemiclip.vcxproj b/msvc/resemiclip.vcxproj index 6460b1a..00fd060 100644 --- a/msvc/resemiclip.vcxproj +++ b/msvc/resemiclip.vcxproj @@ -113,7 +113,6 @@ - false $(ProjectName)_mm @@ -123,7 +122,7 @@ TurnOffAllWarnings Full WIN32;NDEBUG;%(PreprocessorDefinitions) - ..\include\;..\metamod\;..\cssdk\common\;..\cssdk\dlls\;..\cssdk\engine\;..\cssdk\pm_shared\;..\cssdk\game_shared\;..\cssdk\public\ + ..\;..\include\;..\metamod\;..\cssdk\common\;..\cssdk\dlls\;..\cssdk\engine\;..\cssdk\pm_shared\;..\cssdk\game_shared\;..\cssdk\public\ Default MultiThreadedDebugDLL ProgramDatabase @@ -145,11 +144,25 @@ - subversion.always.run + build.always.run - subversion.always.run + build.always.run + echo Empty Action + Force build to run Pre-Build event + + IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\") + + + Setup version from Git revision + + + IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + + + Automatic deployment script + @@ -159,7 +172,7 @@ true false WIN32;%(PreprocessorDefinitions) - ..\include\;..\metamod\;..\cssdk\common\;..\cssdk\dlls\;..\cssdk\engine\;..\cssdk\pm_shared\;..\cssdk\game_shared\;..\cssdk\public\ + ..\;..\include\;..\metamod\;..\cssdk\common\;..\cssdk\dlls\;..\cssdk\engine\;..\cssdk\pm_shared\;..\cssdk\game_shared\;..\cssdk\public\ OnlyExplicitInline false false @@ -188,15 +201,29 @@ - subversion.always.run + build.always.run - subversion.always.run + build.always.run + echo Empty Action + Force build to run Pre-Build event + + IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\") + + + Setup version from Git revision + + + IF EXIST "$(ProjectDir)PostBuild.bat" (CALL "$(ProjectDir)PostBuild.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + + + Automatic deployment script + diff --git a/src/meta_api.cpp b/src/meta_api.cpp index bd24705..adae89c 100644 --- a/src/meta_api.cpp +++ b/src/meta_api.cpp @@ -3,10 +3,10 @@ plugin_info_t Plugin_info = { META_INTERFACE_VERSION, "ReSemiclip", - "2.3.9", - "13/02/17", - "s1lent & Adidasman", - "http://www.dedicated-server.ru/", + APP_VERSION, + APP_COMMIT_DATE, + "s1lent", + "https://github.com/s1lentq/resemiclip/", "ReSemiclip", PT_CHANGELEVEL, PT_ANYTIME diff --git a/version/appversion.sh b/version/appversion.sh new file mode 100755 index 0000000..9899780 --- /dev/null +++ b/version/appversion.sh @@ -0,0 +1,153 @@ +#!/bin/bash + +init() +{ + SOURCE_DIR="$@" + GIT_DIR=$SOURCE_DIR + VERSION_FILE=$SOURCE_DIR/version/version.h + APPVERSION_FILE=$SOURCE_DIR/version/appversion.h + + if test -z "`git --version`"; then + echo "Please install git client" + echo "sudo apt-get install git" + exit -1 + fi + + # Read old version + if [ -e "$APPVERSION_FILE" ]; then + OLD_VERSION=$(cat "$APPVERSION_FILE" | grep -wi '#define APP_VERSION' | sed -e 's/#define APP_VERSION[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g') + if [ $? -ne 0 ]; then + OLD_VERSION="" + else + # Remove quotes + OLD_VERSION=$(echo $OLD_VERSION | xargs) + fi + fi + + # Get major and minor information from version.h + MAJOR=$(cat "$VERSION_FILE" | grep -wi 'VERSION_MAJOR' | sed -e 's/.*VERSION_MAJOR.*[^0-9]\([0-9][0-9]*\).*/\1/i' -e 's/\r//g') + if [ $? -ne 0 -o "$MAJOR" = "" ]; then + MAJOR=0 + fi + + MINOR=$(cat "$VERSION_FILE" | grep -wi 'VERSION_MINOR' | sed -e 's/.*VERSION_MINOR.*[^0-9]\([0-9][0-9]*\).*/\1/i' -e 's/\r//g') + if [ $? -ne 0 -o "$MINOR" = "" ]; then + MINOR=0 + fi + + BRANCH_NAME=$(git -C "$GIT_DIR/" rev-parse --abbrev-ref HEAD) + if [ $? -ne 0 -o "$BRANCH_NAME" = "" ]; then + BRANCH_NAME=master + fi + + COMMIT_COUNT=$(git -C "$GIT_DIR/" rev-list --count $BRANCH_NAME) + if [ $? -ne 0 -o "$COMMIT_COUNT" = "" ]; then + COMMIT_COUNT=0 + fi + + # + # Configure remote url repository + # + # Get remote name by current branch + BRANCH_REMOTE=$(git -C "$GIT_DIR/" config branch.$BRANCH_NAME.remote) + if [ $? -ne 0 -o "$BRANCH_REMOTE" = "" ]; then + BRANCH_REMOTE=origin + fi + + # Get commit id + COMMIT_SHA=$(git -C "$GIT_DIR/" rev-parse --verify HEAD) + COMMIT_SHA=${COMMIT_SHA:0:7} + + # Get remote url + COMMIT_URL=$(git -C "$GIT_DIR/" config remote.$BRANCH_REMOTE.url) + + URL_CONSTRUCT=0 + + if [[ "$COMMIT_URL" == *"git@"* ]]; then + URL_CONSTRUCT=1 + + # Strip prefix 'git@' + COMMIT_URL=${COMMIT_URL#git@} + + # Strip postfix '.git' + COMMIT_URL=${COMMIT_URL%.git} + + # Replace ':' to '/' + COMMIT_URL=${COMMIT_URL/:/\/} + + elif [[ "$COMMIT_URL" == *"https://"* ]]; then + URL_CONSTRUCT=1 + + # Strip prefix 'https://' + COMMIT_URL=${COMMIT_URL#https://} + + # Strip postfix '.git' + COMMIT_URL=${COMMIT_URL%.git} + fi + + if test "$URL_CONSTRUCT" -eq 1; then + # Append extra string + if [[ "$COMMIT_URL" == *"bitbucket.org"* ]]; then + COMMIT_URL=$(echo https://$COMMIT_URL/commits/) + else + COMMIT_URL=$(echo https://$COMMIT_URL/commit/) + fi + fi + + # + # Detect local modifications + # + if [ `git -C "$GIT_DIR/" ls-files -m | wc -l` = 0 ]; then + MODIFIED= + else + MODIFIED=+m + fi + + NEW_VERSION="$MAJOR.$MINOR.$COMMIT_COUNT$MODIFIED" + + # Update appversion.h if version has changed or modifications/mixed revisions detected + if [ "$NEW_VERSION" != "$OLD_VERSION" ]; then + update_appversion + fi +} + +update_appversion() +{ + day=$(date +%d) + year=$(date +%Y) + hours=$(date +%H:%M:%S) + month=$(LANG=en_us_88591; date +"%b") + + # Write appversion.h + echo Updating appversion.h, new version is '"'$NEW_VERSION'"', the old one was $OLD_VERSION + + echo -e "#ifndef __APPVERSION_H__\r">"$APPVERSION_FILE" + echo -e "#define __APPVERSION_H__\r">>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + echo -e "//\r">>"$APPVERSION_FILE" + echo -e "// This file is generated automatically.\r">>"$APPVERSION_FILE" + echo -e "// Don't edit it.\r">>"$APPVERSION_FILE" + echo -e "//\r">>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + echo -e "// Version defines\r">>"$APPVERSION_FILE" + echo -e '#define APP_VERSION "'$NEW_VERSION'"\r'>>"$APPVERSION_FILE" + + echo -e "#define APP_VERSION_C $MAJOR,$MINOR,$COMMIT_COUNT\r">>"$APPVERSION_FILE" + echo -e '#define APP_VERSION_STRD "'$MAJOR.$MINOR.$COMMIT_COUNT'"\r'>>"$APPVERSION_FILE" + echo -e "#define APP_VERSION_FLAGS 0x0L\r">>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + echo -e '#define APP_COMMIT_DATE "'$month $day $year'"\r'>>"$APPVERSION_FILE" + echo -e '#define APP_COMMIT_TIME "'$hours'"\r'>>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + + echo -e '#define APP_COMMIT_SHA "'$COMMIT_SHA'"\r'>>"$APPVERSION_FILE" + echo -e '#define APP_COMMIT_URL "'$COMMIT_URL'"\r'>>"$APPVERSION_FILE" + echo -e "\r">>"$APPVERSION_FILE" + echo -e "#endif //__APPVERSION_H__\r">>"$APPVERSION_FILE" +} + +# Initialise +init $* + +# Exit normally +exit 0 diff --git a/version/version.h b/version/version.h new file mode 100644 index 0000000..47bde01 --- /dev/null +++ b/version/version.h @@ -0,0 +1,10 @@ +/* +* Version declaration dependency file +* +*/ + +#pragma once + +#define VERSION_MAJOR 2 +#define VERSION_MINOR 4 +#define VERSION_MAINTENANCE 0 diff --git a/version_script.lds b/version_script.lds new file mode 100644 index 0000000..0b8aa0c --- /dev/null +++ b/version_script.lds @@ -0,0 +1,16 @@ +RESEMICLIP_ABI_1.0 { + global: + GiveFnptrsToDll; + Meta_Attach; + Meta_Detach; + Meta_Query; + AMXX_Attach; + AMXX_CheckGame; + AMXX_Detach; + AMXX_PluginsLoaded; + AMXX_PluginsUnloaded; + AMXX_PluginsUnloading; + AMXX_Query; + local: + *; +};