This repository was archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGModNextbotGenerator.cpp
More file actions
201 lines (134 loc) · 5.23 KB
/
GModNextbotGenerator.cpp
File metadata and controls
201 lines (134 loc) · 5.23 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <filesystem>
namespace fs = std::filesystem;
void findAndReplaceAll(std::string& data, std::string toSearch, std::string replaceStr)
{
size_t pos = data.find(toSearch);
while (pos != std::string::npos)
{
data.replace(pos, toSearch.size(), replaceStr);
pos = data.find(toSearch, pos + replaceStr.size());
}
}
int main()
{
// Prepairing
std::ifstream nextbotLuaFile("nextbot_example.lua");
std::stringstream filestringstream;
std::string line;
while (std::getline(nextbotLuaFile, line)) {
filestringstream << line << std::endl;
}
std::string luaFile = filestringstream.str();
// Prepaired
std::string gmodPath;
std::string PNGPath;
std::string nextbotName;
std::string nextbotDisplayName;
std::string jumpSound;
std::string highJumpSound;
std::string chaseSound;
std::vector<std::string> tauntSounds;
// Questioning
std::cout << "Garry's Mod Nextbot Generator" << std::endl;
std::cout << "Made by Livelandr" << std::endl << std::endl;
std::cout << "Input your Garry's mod folder path: ";
std::getline(std::cin, gmodPath);
gmodPath = gmodPath + ((gmodPath[gmodPath.size() - 1] == '/') ? "" : "/");
if (!(fs::exists(gmodPath + "/hl2.exe"))) {
std::cout << "Invalid path!" << std::endl;
return 1;
}
std::cout << "Input nextbot entity name (Without spaces, only latinate!): ";
std::cin >> nextbotName;
std::cin.ignore();
std::cout << "Input nextbot display name: ";
std::getline(std::cin, nextbotDisplayName);
std::cout << "Input PNG file path (Nextbot face): ";
std::cin >> PNGPath;
if (!(fs::exists(PNGPath))) {
std::cout << "Invalid path!" << std::endl;
return 1;
}
if (PNGPath.substr(PNGPath.find_last_of(".") + 1) != "png") {
std::cout << "This file is not .png!" << std::endl;
return 1;
}
std::cin.ignore();
std::cout << "Input chase sound (.mp3 file): ";
std::getline(std::cin, chaseSound);
if (!(fs::exists(chaseSound))) {
std::cout << "Invalid path!" << std::endl;
return 1;
}
std::cout << "Input jump sound (.mp3 file): ";
std::getline(std::cin, jumpSound);
if (!(fs::exists(jumpSound))) {
std::cout << "Invalid path!" << std::endl;
return 1;
}
std::cout << "Input high jump sound (.mp3 file): ";
std::getline(std::cin, highJumpSound);
if (!(fs::exists(highJumpSound))) {
std::cout << "Invalid path!" << std::endl;
return 1;
}
int tauntSoundsCount;
std::cout << "How much taunt sounds you want?: ";
std::cin >> tauntSoundsCount;
if (tauntSoundsCount < 1) {
std::cout << "At least one taunt!" << std::endl;
return 1;
}
std::cin.ignore();
for (int i = 0; i < tauntSoundsCount; i++) {
std::string tauntSound;
std::cout << "Taunt sound #" << i + 1 << " path (.mp3): ";
std::getline(std::cin, tauntSound);
if (!(fs::exists(tauntSound))) {
std::cout << "Invalid path!" << std::endl;
return 1;
}
tauntSounds.push_back(tauntSound);
}
// Questioning ended!
std::string NextbotSoundsData;
NextbotSoundsData += R"(
["HighJump"] = ")" + nextbotName + "/" + "highjump.mp3" + "\",";
NextbotSoundsData += R"(
["Jump"] = ")" + nextbotName + "/" + "jump.mp3" + "\",";
NextbotSoundsData += R"(
["ChaseSound"] = ")" + nextbotName + "/" + "chase.mp3" + "\",";
NextbotSoundsData += R"(
["tauntSounds"] = {
)";
for (int i = 0; i < tauntSoundsCount; i++) {
NextbotSoundsData += " \"" + nextbotName + "/tauntSound_" + std::to_string(i + 1) + ".mp3\",";
}
NextbotSoundsData += "\n}";
// Nextbot generation
findAndReplaceAll(luaFile, "REPLACEME_NEXTBOTNAME", nextbotName);
findAndReplaceAll(luaFile, "REPLACEME_NEXTBOTDISPLAYNAME", nextbotDisplayName);
findAndReplaceAll(luaFile, "REPLACEME_NEXTBOTSOUNDS", NextbotSoundsData);
fs::current_path(gmodPath + "garrysmod/addons/");
fs::create_directory("generated_nextbot_" + nextbotName);
fs::current_path(gmodPath + "garrysmod/addons/generated_nextbot_" + nextbotName);
fs::create_directories("lua/entities");
fs::create_directories("sound/" + nextbotName);
fs::create_directories("materials/" + nextbotName);
std::ofstream readyFile(gmodPath + "garrysmod/addons/generated_nextbot_" + nextbotName + "/lua/entities/npc_" + nextbotName + ".lua");
readyFile << luaFile << std::endl;
readyFile.close();
std::string soundPath = gmodPath + "garrysmod/addons/generated_nextbot_" + nextbotName + "/sound/" + nextbotName;
fs::copy(jumpSound, soundPath + "/jump.mp3", std::filesystem::copy_options::overwrite_existing);
fs::copy(highJumpSound, soundPath + "/highjump.mp3", std::filesystem::copy_options::overwrite_existing);
fs::copy(chaseSound, soundPath + "/chase.mp3", std::filesystem::copy_options::overwrite_existing);
for (int i = 0; i < tauntSoundsCount; i++) {
fs::copy( tauntSounds[i], soundPath + "/tauntSound_" + std::to_string(i + 1) + ".mp3", std::filesystem::copy_options::overwrite_existing);
}
fs::copy(PNGPath, gmodPath + "garrysmod/addons/generated_nextbot_" + nextbotName + "/materials/" + nextbotName + "/npc_" + nextbotName + ".png", std::filesystem::copy_options::overwrite_existing);
}