-
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathwin.bat
More file actions
143 lines (121 loc) · 5.67 KB
/
win.bat
File metadata and controls
143 lines (121 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
@echo off
SetLocal EnableDelayedExpansion
title CS2
:: Set variables
set ROOT_DIR=%~dp0
set "gameinfo=server\game\csgo\gameinfo.gi"
set "searchString=Game csgo/addons/metamod"
set "insertAfter=Game_LowViolence csgo_lv"
set "bakFile=%gameinfo%.bak"
set "tempFile=%gameinfo%.tmp"
if not exist win.ini copy NUL win.ini
for /f %%S in (win.ini) do set %%S
cls
echo If you want to quit, close the CS2 window and type Y followed by Enter.
:: Ensure steamcmd exists
if not exist "%ROOT_DIR%steamcmd\steamcmd.exe" (
mkdir "%ROOT_DIR%steamcmd"
echo Downloading SteamCMD
powershell -Command "Invoke-WebRequest -Uri https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip -OutFile '%ROOT_DIR%steamcmd\steamcmd.zip'"
powershell -Command "Expand-Archive -Path '%ROOT_DIR%steamcmd\steamcmd.zip' -DestinationPath '%ROOT_DIR%steamcmd'"
del "%ROOT_DIR%steamcmd\steamcmd.zip"
)
:: Use SteamCMD to download CS2
:: If you want to validate files, put validate before +quit so it reads "+app_update 730 validate +quit"
echo Using SteamCMD to check for updates.
start /wait %ROOT_DIR%steamcmd\steamcmd.exe +force_install_dir ../server +login anonymous +app_update 730 +quit
:: Ensure gameinfo.gi exists
if not exist "%ROOT_DIR%%gameinfo%" (
echo The file %gameinfo% does not exist.
goto end
)
:: Create a backup file if it doesn't exist
if not exist "%bakFile%" (
echo Attempting to create backup file of %gameinfo%...
copy "%gameinfo%" "%bakFile%"
if %errorlevel% neq 0 (
echo Failed to create backup file. Error: %errorlevel%
goto end
) else (
echo Backup file %bakFile% created successfully.
)
) else (
echo Backup file %gameinfo% already exists.
)
:: Check if searchString exists in the file
echo Checking if %gameinfo% has already been patched...
findstr /m /c:"%searchString%" "%gameinfo%" >nul
if %errorlevel%==0 (
echo %gameinfo% has already been patched.
goto start
) else (
echo %gameinfo% needs to be patched...
)
:: Read the file, check each line for the insertAfter substring, and insert searchString
> "%tempFile%" (
set "added=0"
for /f "tokens=* delims=" %%a in ('findstr /n "^" "%gameinfo%"') do (
set "line=%%a"
setlocal enabledelayedexpansion
set "line=!line:*:=!"
if "!line!" neq "" (
if "!line!"=="!line:%insertAfter%=!" (
echo(!line!
) else (
if "!added!"=="0" (
echo(!line!
echo( %searchString%
set "added=1"
)
)
) else (
echo(
)
endlocal
)
)
:: Replace the original file with the modified content
if exist "%tempFile%" (
echo Temporary file %tempFile% created successfully. Preparing to replace %gameinfo%...
move /y "%tempFile%" "%gameinfo%"
if %errorlevel% neq 0 (
echo Failed to replace original file. Error: %errorlevel%
goto end
) else (
echo %gameinfo% has successfully been patched.
)
) else (
echo Failed to create or modify temporary file %tempFile%. Potential access issue or write protection.
)
:start
:: Deleting addons folder so no old plugins are left to cause issues
:: If you have modifications in your addons/ folder they should be in custom_files as these are merged at the end
echo Deleting addons folder.
rmdir /S /Q "%ROOT_DIR%server\game\csgo\addons\"
:: If you have modifications in your cfg/settings/ folder they should be in custom_files as these are merged at the end
echo Deleting cfg/settings folder.
rmdir /S /Q "%ROOT_DIR%server\game\csgo\cfg\settings\"
:: Patch server with mod files
echo Copying mod files.
xcopy "%ROOT_DIR%game\csgo\*" "%ROOT_DIR%server\game\csgo\" /K /S /E /I /H /Y >NUL
:: Merge Windows specific files
echo Merging Windows specific files.
xcopy "%ROOT_DIR%game\csgo\addons\windows\*" "%ROOT_DIR%server\game\csgo\" /K /S /E /I /H /Y >NUL
:: Merge your custom files in
echo Copying custom files from "%custom_folder%".
xcopy "%ROOT_DIR%%custom_folder%\*" "%ROOT_DIR%server\game\csgo\" /K /S /E /I /H /Y >NUL
:: Merge your custom files secrets in (if they exist)
if exist "%ROOT_DIR%custom_files_secret\" (
echo Copying custom files secret from "custom_files_secret".
xcopy "%ROOT_DIR%custom_files_secret\*" "%ROOT_DIR%server\game\csgo\" /K /S /E /I /H /Y >NUL
)
:: Start the server
echo CS2 started.
:: Start server as seperate process
start /wait %ROOT_DIR%server\game\bin\win64\cs2.exe -dedicated -console -debug -condebug -conclearlog -usercon -disable_workshop_command_filtering +game_type 0 +game_mode 0 +mapgroup mg_active +map de_dust2 -port %PORT% -ip 0.0.0.0 +net_public_adr %IP% -tickrate %TICKRATE% +sv_visiblemaxplayers %MAXPLAYERS% -authkey %API_KEY% +sv_setsteamaccount %STEAM_ACCOUNT% +sv_lan %LAN% +sv_password %SERVER_PASSWORD% +rcon_password %RCON_PASSWORD% +exec %EXEC%
:: Start server and capture output to log for debugging (commands must be entered in blank CS2 window) (Uncomment below and comment out above start command)
:: powershell -Command "& '%ROOT_DIR%server\game\bin\win64\cs2.exe' -dedicated -console -debug -condebug -conclearlog -usercon -disable_workshop_command_filtering +game_type 0 +game_mode 0 +mapgroup mg_active +map de_dust2 -port %PORT% -ip 0.0.0.0 +net_public_adr %IP% -tickrate %TICKRATE% +sv_visiblemaxplayers %MAXPLAYERS% -authkey %API_KEY% +sv_setsteamaccount %STEAM_ACCOUNT% +sv_lan %LAN% +sv_password %SERVER_PASSWORD% +rcon_password %RCON_PASSWORD% +exec %EXEC% 2>&1 | Tee-Object -FilePath 'console.log'"
echo WARNING: CS2 closed or crashed.
:end
pause
EndLocal