-
Notifications
You must be signed in to change notification settings - Fork 10
/
portdata.sp
95 lines (75 loc) · 2.58 KB
/
portdata.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
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
public void OnPluginStart()
{
char path[2][128], map[128];
BuildPath(Path_SM, path[0], 128, "configs/mapdata.txt");
BuildPath(Path_SM, path[1], 128, "configs/mapdata.kv");
ArrayList maps = GetAllMapsName();
KeyValues oldk = new KeyValues("MapData");
KeyValues newk = new KeyValues("MapData");
if (!oldk.ImportFromFile(path[0]))
SetFailState("Failed to import from [%s]", path[0]);
if (!newk.ImportFromFile(path[1]))
SetFailState("Failed to import from [%s]", path[1]);
for(int index = 0; index < maps.Length; index++)
{
oldk.Rewind();
newk.Rewind();
maps.GetString(index, map, 128);
if (!oldk.JumpToKey(map, false))
{
LogMessage("Failed to jump from old: %s", map);
continue;
}
if (!newk.JumpToKey(map, false))
{
LogMessage("Failed to jump from new: %s", map);
continue;
}
char temp[128];
oldk.GetString("Desc", temp, 128);
Format(temp, 128, "%s %s", oldk.GetNum("Nice", 0) == 1 ? "*神图*" : "*咸鱼*", temp);
newk.SetString("m_Description", temp);
newk.SetString("m_CertainTimes", "all");
newk.SetNum("m_Price", oldk.GetNum("price", 1000));
newk.SetNum("m_PricePartyBlock", oldk.GetNum("price", 1000) * 10);
newk.SetNum("m_MinPlayers", oldk.GetNum("minplayers", 1000));
newk.SetNum("m_MaxPlayers", oldk.GetNum("maxplayers", 1000));
newk.SetNum("m_MaxCooldown", 100);
newk.SetNum("m_NominateOnly", oldk.GetNum("OnlyNomination", 0));
newk.SetNum("m_VipOnly", oldk.GetNum("OnlyAdmin", 0));
newk.SetNum("m_AdminOnly", oldk.GetNum("OnlyVIP", 0));
}
oldk.Rewind();
newk.Rewind();
newk.ExportToFile(path[1]);
}
stock ArrayList GetAllMapsName()
{
ArrayList maps = new ArrayList(ByteCountToCells(128));
DirectoryListing dir = OpenDirectory("maps");
if (dir == null)
{
LogError("GetAllMapsName -> Failed to open maps.");
return maps;
}
FileType type = FileType_Unknown;
char map[128];
while(dir.GetNext(map, 128, type))
{
if (type != FileType_File || StrContains(map, ".bsp", false) == -1)
continue;
int c = FindCharInString(map, '.', true);
map[c] = '\0';
if (!IsMapValid(map))
{
LogError("GetAllMapsName -> %s is invalid map.", map);
continue;
}
maps.PushString(map);
}
delete dir;
return maps;
}