-
Notifications
You must be signed in to change notification settings - Fork 2
/
vradcheck.sp
145 lines (115 loc) · 3.28 KB
/
vradcheck.sp
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
#include "sourcemod"
#define SNAME "[VRAD Cheker] "
#define PATH_MAPS "maps/"
//(LUMP POS * INT SIZE * INTS IN LUMP HEADER) + 2 INT HEADER
#define LUMP_LIGHTING 136 //(8 * 4 * 4) + 8
#define LUMP_LIGHTING_HDR 856 //(53 * 4 * 4) + 8
#define DEBUG 0
public Plugin myinfo =
{
name = "VRAD Checker",
author = "GAMMA CASE",
description = "Checks VRAD light parameter used as map compile option.",
version = "0.0.1",
url = "https://steamcommunity.com/id/_GAMMACASE_/"
}
char g_sPaths[][PLATFORM_MAX_PATH] = {"vradcheck_hdr.txt",
"vradcheck_ldr.txt",
"vradcheck_both.txt",
"vradcheck_other.txt"};
enum VRADParam
{
VRAD_HDR = 0,
VRAD_LDR = 1,
VRAD_BOTH,
VRAD_Other,
VRAD_LAST
}
public void OnPluginStart()
{
RegAdminCmd("sm_vradcheck", SM_VRADCheck, ADMFLAG_ROOT, "Starts VRAD check.");
}
public Action SM_VRADCheck(int client, int args)
{
DirectoryListing dir = OpenDirectory(PATH_MAPS, true);
if(!dir)
{
ReplyToCommand(client, SNAME..."Folder \"%s\" was not found.", PATH_MAPS);
return Plugin_Handled;
}
char file[PLATFORM_MAX_PATH], path[PLATFORM_MAX_PATH];
FileType type;
File map;
bool ldr, hdr;
StringMap maps = new StringMap();
while(dir.GetNext(file, sizeof(file), type))
{
if(type != FileType_File)
continue;
if(StrEqual(file[FindCharInString(file, '.', true) + 1], "bsp", false))
{
Format(path, sizeof(path), PATH_MAPS..."%s", file);
map = OpenFile(path, "rb", true);
if(!map)
{
ReplyToCommand(client, SNAME..."Can't open \"%s\" for reading.", path);
continue;
}
ldr = ProcessBSPLightLumps(map, LUMP_LIGHTING + 4) > 0;
hdr = ProcessBSPLightLumps(map, LUMP_LIGHTING_HDR + 4) > 0;
if(ldr && hdr)
maps.SetValue(file, VRAD_BOTH);
else if(hdr)
maps.SetValue(file, VRAD_HDR);
else if(ldr)
maps.SetValue(file, VRAD_LDR);
else
{
ReplyToCommand(client, SNAME..."Found map without light(?), or can't detect VRAD param. (Map: \"%s\")", file)
maps.SetValue(file, VRAD_Other);
}
delete map;
}
}
OutputMaps(client, maps)
delete maps;
delete dir;
return Plugin_Handled;
}
int ProcessBSPLightLumps(File map, int pos)
{
if(!map.Seek(pos, SEEK_SET))
return 0;
int data;
if(!map.ReadInt32(data))
return 0;
return data;
}
void OutputMaps(int client, StringMap maps)
{
StringMapSnapshot snap = maps.Snapshot();
File outfiles[VRAD_LAST];
for(int i = 0; i < view_as<int>(VRAD_LAST); i++)
{
outfiles[i] = OpenFile(g_sPaths[i], "w", true);
if(!outfiles[i])
{
ReplyToCommand(client, SNAME..."Can't create/open output file \"%s\" for writing.", g_sPaths[i]);
return;
}
}
char map[PLATFORM_MAX_PATH];
int count[VRAD_LAST];
VRADParam type;
for(int i = 0; i < snap.Length; i++)
{
snap.GetKey(i, map, sizeof(map))
maps.GetValue(map, type);
outfiles[type].WriteLine(map);
count[type]++;
}
ReplyToCommand(client, SNAME..."All maps have been successfully written to each specific file.\n"...
"Total maps: HDR: %i, LDR: %i, BOTH: %i, Other: %i", count[VRAD_HDR], count[VRAD_LDR], count[VRAD_BOTH], count[VRAD_Other]);
for(int i = 0; i < view_as<int>(VRAD_LAST); i++)
delete outfiles[i];
}