Skip to content

Commit 6d311d9

Browse files
committed
Initial commit.
Signed-off-by: Mai Ooizumi <mai@imomoe.moe>
0 parents  commit 6d311d9

File tree

5 files changed

+293
-0
lines changed

5 files changed

+293
-0
lines changed

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# Visual Studio
35+
/.vs
36+
x64/
37+
x86/
38+
build/
39+
*.vcxproj.user
40+
41+
# Visual Studio Code
42+
.vscode/
43+
44+
# CMake
45+
out/build/

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# CMakeList.txt : Top-level CMake project file, do global configuration
2+
# and include sub-projects here.
3+
#
4+
cmake_minimum_required (VERSION 3.8)
5+
6+
# Enable Hot Reload for MSVC compilers if supported.
7+
if (POLICY CMP0141)
8+
cmake_policy(SET CMP0141 NEW)
9+
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
10+
endif()
11+
12+
project ("CS2-Gameinfo-Patch")
13+
14+
# Include sub-projects.
15+
add_subdirectory ("CS2-Gameinfo-Patch")

CMakePresets.json

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"version": 3,
3+
"configurePresets": [
4+
{
5+
"name": "windows-base",
6+
"hidden": true,
7+
"generator": "Ninja",
8+
"binaryDir": "${sourceDir}/out/build/${presetName}",
9+
"installDir": "${sourceDir}/out/install/${presetName}",
10+
"cacheVariables": {
11+
"CMAKE_C_COMPILER": "cl.exe",
12+
"CMAKE_CXX_COMPILER": "cl.exe"
13+
},
14+
"condition": {
15+
"type": "equals",
16+
"lhs": "${hostSystemName}",
17+
"rhs": "Windows"
18+
}
19+
},
20+
{
21+
"name": "x64-debug",
22+
"displayName": "x64 Debug",
23+
"inherits": "windows-base",
24+
"architecture": {
25+
"value": "x64",
26+
"strategy": "external"
27+
},
28+
"cacheVariables": {
29+
"CMAKE_BUILD_TYPE": "Debug"
30+
}
31+
},
32+
{
33+
"name": "x64-release",
34+
"displayName": "x64 Release",
35+
"inherits": "x64-debug",
36+
"cacheVariables": {
37+
"CMAKE_BUILD_TYPE": "Release"
38+
}
39+
},
40+
{
41+
"name": "x86-debug",
42+
"displayName": "x86 Debug",
43+
"inherits": "windows-base",
44+
"architecture": {
45+
"value": "x86",
46+
"strategy": "external"
47+
},
48+
"cacheVariables": {
49+
"CMAKE_BUILD_TYPE": "Debug"
50+
}
51+
},
52+
{
53+
"name": "x86-release",
54+
"displayName": "x86 Release",
55+
"inherits": "x86-debug",
56+
"cacheVariables": {
57+
"CMAKE_BUILD_TYPE": "Release"
58+
}
59+
},
60+
{
61+
"name": "linux-debug",
62+
"displayName": "Linux Debug",
63+
"generator": "Ninja",
64+
"binaryDir": "${sourceDir}/out/build/${presetName}",
65+
"installDir": "${sourceDir}/out/install/${presetName}",
66+
"cacheVariables": {
67+
"CMAKE_BUILD_TYPE": "Debug"
68+
},
69+
"condition": {
70+
"type": "equals",
71+
"lhs": "${hostSystemName}",
72+
"rhs": "Linux"
73+
},
74+
"vendor": {
75+
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
76+
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
77+
}
78+
}
79+
},
80+
{
81+
"name": "macos-debug",
82+
"displayName": "macOS Debug",
83+
"generator": "Ninja",
84+
"binaryDir": "${sourceDir}/out/build/${presetName}",
85+
"installDir": "${sourceDir}/out/install/${presetName}",
86+
"cacheVariables": {
87+
"CMAKE_BUILD_TYPE": "Debug"
88+
},
89+
"condition": {
90+
"type": "equals",
91+
"lhs": "${hostSystemName}",
92+
"rhs": "Darwin"
93+
},
94+
"vendor": {
95+
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
96+
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
97+
}
98+
}
99+
}
100+
]
101+
}

CS2-Gameinfo-Patch/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# CMakeList.txt : CMake project for CS2-Gameinfo-Patch, include source and define
2+
# project specific logic here.
3+
#
4+
5+
# Add source to this project's executable.
6+
add_executable (CS2-Gameinfo-Patch "CS2-Gameinfo-Patch.cpp" )
7+
8+
if (CMAKE_VERSION VERSION_GREATER 3.12)
9+
set_property(TARGET CS2-Gameinfo-Patch PROPERTY CXX_STANDARD 20)
10+
endif()
11+
12+
# TODO: Add tests and install targets if needed.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include <exception>
2+
#include <filesystem>
3+
#include <fstream>
4+
#include <iosfwd>
5+
#include <iostream>
6+
#include <string>
7+
#include <vector>
8+
9+
static bool CheckEntry(std::string file)
10+
{
11+
std::ifstream inputFile(file);
12+
std::string line;
13+
14+
while (std::getline(inputFile, line))
15+
{
16+
if (line.find("metamod") != std::string::npos)
17+
{
18+
std::cerr << "ERROR: Metamod:Source entry already exists." << std::endl;
19+
return true;
20+
}
21+
}
22+
23+
inputFile.close();
24+
25+
return false;
26+
}
27+
28+
static bool UpdateFile(std::string file)
29+
{
30+
const std::string pattern = "Game_LowViolence";
31+
const std::string metamodEntry = "\n Game csgo/addons/metamod";
32+
33+
std::filesystem::copy(file, file + ".bak");
34+
std::ifstream inputFile(file);
35+
36+
if (!inputFile.is_open())
37+
{
38+
std::cerr << "ERROR: Unable to open file." << std::endl;
39+
return false;
40+
}
41+
42+
std::vector<std::string> fileContent;
43+
std::string line;
44+
while (std::getline(inputFile, line))
45+
{
46+
fileContent.push_back(line);
47+
}
48+
inputFile.close();
49+
50+
51+
// auto == std::vector<std::string>::iterator
52+
auto it = std::find_if(fileContent.begin(), fileContent.end(),
53+
[&](const std::string & str)
54+
{
55+
return str.find(pattern) != std::string::npos;
56+
});
57+
58+
if (it == fileContent.end())
59+
{
60+
std::cerr << "ERROR: Pattern not found in file." << std::endl;
61+
return false;
62+
}
63+
64+
fileContent.insert(it + 1, metamodEntry);
65+
std::ofstream outputFile(file);
66+
67+
if (!outputFile.is_open())
68+
{
69+
std::cerr << "ERROR: Unable to write file." << std::endl;
70+
return false;
71+
}
72+
73+
// auto == std::vector<std::string>::iterator::value_type
74+
for (const auto & line : fileContent)
75+
{
76+
outputFile << line << '\n';
77+
}
78+
outputFile.close();
79+
80+
return true;
81+
}
82+
83+
int main(int argc, const char * const * argv)
84+
{
85+
std::string filePath;
86+
if (argc > 1)
87+
{
88+
filePath = argv[1];
89+
if (!std::filesystem::exists(filePath))
90+
{
91+
std::cerr << "ERROR: Specified file path does not exist." << std::endl;
92+
return 1;
93+
}
94+
}
95+
else
96+
{
97+
filePath = "./game/csgo/gameinfo.gi";
98+
if (!std::filesystem::exists(filePath))
99+
{
100+
std::cerr << "ERROR: Gameinfo.gi does not exist." << std::endl;
101+
return 1;
102+
}
103+
}
104+
105+
try
106+
{
107+
if (CheckEntry(filePath))
108+
{
109+
return 2;
110+
}
111+
UpdateFile(filePath);
112+
}
113+
catch (const std::exception & e)
114+
{
115+
std::cerr << "ERROR: An error occurred: " << e.what() << std::endl;
116+
return 1;
117+
}
118+
119+
return 0;
120+
}

0 commit comments

Comments
 (0)