forked from Bots-United/jk_botti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_models.cpp
228 lines (181 loc) · 5.44 KB
/
bot_models.cpp
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//
// JK_Botti - be more human!
//
// bot_models.cpp
//
#ifndef _WIN32
#include <string.h>
#endif
#include <extdll.h>
#include <dllapi.h>
#include <h_export.h>
#include <meta_api.h>
#include "bot.h"
#ifndef __linux__
#include <windows.h>
#include <sys/types.h>
#include <sys/stat.h>
#else
#include <sys/stat.h>
#include <dirent.h>
#endif
skin_t bot_skins[MAX_SKINS];
int number_skins;
#define VALVE_MAX_SKINS 10
#define GEARBOX_MAX_SKINS 10
// default player models for various MODs...
char *default_bot_models[VALVE_MAX_SKINS + GEARBOX_MAX_SKINS] = {
"barney", "gina", "gman", "gordon", "helmet",
"hgrunt", "recon", "robo", "scientist", "zombie",
"beret", "cl_suit", "drill", "fassn", "grunt",
"massn", "otis", "recruit", "shephard", "tower"
};
// default names for each of the above player models...
char *default_bot_names[VALVE_MAX_SKINS + GEARBOX_MAX_SKINS] = {
"Barney", "Gina", "G-Man", "Gordon", "Helmet",
"H-Grunt", "Recon", "Robo", "Scientist", "Zombie",
"Beret", "Cleansuit", "Drill", "Female Assassin", "Grunt",
"Male Assassin", "Otis", "Recruit", "Shephard", "Tower"
};
#ifndef __linux__
// MS-DOS directory wildcard routines...
static HANDLE FindDirectory(HANDLE hFile, char *dirname, int sizeof_dirname, char *dirspec)
{
WIN32_FIND_DATA pFindFileData;
if (hFile == NULL)
{
hFile = FindFirstFile(dirspec, &pFindFileData);
if (hFile == INVALID_HANDLE_VALUE)
{
hFile = NULL;
return hFile; // bugfix
}
while (pFindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
if (FindNextFile(hFile, &pFindFileData) == 0)
{
FindClose(hFile);
hFile = NULL;
return hFile;
}
}
safe_strcopy(dirname, sizeof_dirname, pFindFileData.cFileName);
return hFile;
}
else
{
if (FindNextFile(hFile, &pFindFileData) == 0)
{
FindClose(hFile);
hFile = NULL;
return hFile;
}
while (pFindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
if (FindNextFile(hFile, &pFindFileData) == 0)
{
FindClose(hFile);
hFile = NULL;
return hFile;
}
}
safe_strcopy(dirname, sizeof_dirname, pFindFileData.cFileName);
return hFile;
}
}
#else
// Linux directory wildcard routines...
static DIR *FindDirectory(DIR *directory, char *dirname, int sizeof_dirname, char *dirspec)
{
char pathname[256];
struct dirent *dirent;
struct stat stat_str;
if (directory == NULL)
{
if ((directory = opendir(dirspec)) == NULL)
return NULL;
}
while ((dirent = readdir(directory)) != NULL)
{
safevoid_snprintf(pathname, sizeof(pathname), "%s/%s", dirspec, dirent->d_name);
if (stat(pathname, &stat_str) == 0)
{
if (stat_str.st_mode & S_IFDIR)
{
safe_strcopy(dirname, sizeof_dirname, dirent->d_name);
return directory;
}
}
}
/* at end of directory? */
closedir(directory);
return NULL;
}
#endif
//
void LoadBotModels(void)
{
char game_dir[256];
char path[MAX_PATH];
char search_path[MAX_PATH];
char dirname[MAX_PATH];
char filename[MAX_PATH];
int index;
struct stat stat_str;
#ifndef __linux__
HANDLE directory = NULL;
#else
DIR *directory = NULL;
#endif
for (index=0; index < MAX_SKINS; index++)
bot_skins[index].skin_used = FALSE;
number_skins = VALVE_MAX_SKINS;
if(submod_id == SUBMOD_OP4)
number_skins += GEARBOX_MAX_SKINS;
for (index=0; index < number_skins; index++)
{
safe_strcopy(bot_skins[index].model_name, sizeof(bot_skins[index].model_name), default_bot_models[index]);
safe_strcopy(bot_skins[index].bot_name, sizeof(bot_skins[index].bot_name), default_bot_names[index]);
}
// find the directory name of the currently running MOD...
GetGameDir (game_dir);
safevoid_snprintf(path, sizeof(path), "%s/models/player", game_dir);
if (stat(path, &stat_str) != 0)
{
// use the valve/models/player directory if no MOD models/player
strcpy(path, "valve/models/player");
}
#ifndef __linux__
safevoid_snprintf(search_path, sizeof(search_path), "%s/*", path);
#else
strcpy(search_path, path);
#endif
while ((directory = FindDirectory(directory, dirname, sizeof(dirname), search_path)) != NULL)
{
if ((strcmp(dirname, ".") == 0) || (strcmp(dirname, "..") == 0))
continue;
safevoid_snprintf(filename, sizeof(filename), "%s/%s/%s.mdl", path, dirname, dirname);
if (stat(filename, &stat_str) == 0)
{
// add this model to the array of models...
for (index=0; dirname[index]; index++)
dirname[index] = tolower(dirname[index]);
// check for duplicate...
for (index=0; index < number_skins; index++)
{
if (strcmp(dirname, bot_skins[index].model_name) == 0)
break;
}
if (index == number_skins)
{
// add this model to the bot_skins array...
safe_strcopy(bot_skins[number_skins].model_name, sizeof(bot_skins[number_skins].model_name), dirname);
dirname[0] = toupper(dirname[0]);
safe_strcopy(bot_skins[number_skins].bot_name, sizeof(bot_skins[number_skins].bot_name), dirname);
number_skins++;
}
}
if (number_skins == MAX_SKINS)
break; // break out if max models reached
}
}