1+ /* *
2+ * Wrapper natives that stringify / unstringify parsed entity string values.
3+ */
4+
5+ static stock KeyValues KeyValueBuffer () {
6+ static KeyValues s_KVBuffer ;
7+ if (! s_KVBuffer ) {
8+ s_KVBuffer = new KeyValues (" " );
9+ }
10+ return s_KVBuffer ;
11+ }
12+
13+ static stock void VectorToString (const float vec [3 ], char [] buffer , int maxlen ) {
14+ KeyValueBuffer ().SetVector (" key" , vec );
15+ KeyValueBuffer ().GetString (" key" , buffer , maxlen );
16+ }
17+
18+ static stock void StringToVector (const char [] buffer , float vec [3 ]) {
19+ KeyValueBuffer ().SetString (" key" , buffer );
20+ KeyValueBuffer ().GetVector (" key" , vec );
21+ }
22+
23+
24+ public int Native_MapGetNum (Handle plugin , int argc ) {
25+ StringMultiMap map = GetNativeCell (1 );
26+
27+ char key [128 ], value [128 ];
28+ GetNativeString (2 , key , sizeof (key ));
29+
30+ return map .GetString (key , value , sizeof (value ))? StringToInt (value ) : GetNativeCell (3 );
31+ }
32+
33+ public int Native_MapAddNum (Handle plugin , int argc ) {
34+ StringMultiMap map = GetNativeCell (1 );
35+
36+ char key [128 ], value [128 ];
37+ GetNativeString (2 , key , sizeof (key ));
38+ IntToString (GetNativeCell (3 ), value , sizeof (value ));
39+
40+ map .AddString (key , value );
41+ return 0 ;
42+ }
43+
44+ public int Native_MapGetFloat (Handle plugin , int argc ) {
45+ StringMultiMap map = GetNativeCell (1 );
46+
47+ char key [128 ], value [128 ];
48+ GetNativeString (2 , key , sizeof (key ));
49+
50+ return view_as <int >(map .GetString (key , value , sizeof (value ))? StringToFloat (value ) : GetNativeCell (3 ));
51+ }
52+
53+ public int Native_MapAddFloat (Handle plugin , int argc ) {
54+ StringMultiMap map = GetNativeCell (1 );
55+
56+ char key [128 ], value [128 ];
57+ GetNativeString (2 , key , sizeof (key ));
58+ FloatToString (GetNativeCell (3 ), value , sizeof (value ));
59+
60+ map .AddString (key , value );
61+ return 0 ;
62+ }
63+
64+ public int Native_MapGetVector (Handle plugin , int argc ) {
65+ StringMultiMap map = GetNativeCell (1 );
66+
67+ char key [128 ], value [128 ];
68+ GetNativeString (2 , key , sizeof (key ));
69+
70+ float outputVec [3 ];
71+ if (map .GetString (key , value , sizeof (value ))) {
72+ StringToVector (value , outputVec );
73+ } else {
74+ GetNativeArray (4 , outputVec , 3 );
75+ }
76+ SetNativeArray (3 , outputVec , 3 );
77+ }
78+
79+ public int Native_MapAddVector (Handle plugin , int argc ) {
80+ StringMultiMap map = GetNativeCell (1 );
81+
82+ char key [128 ], value [128 ];
83+ GetNativeString (2 , key , sizeof (key ));
84+
85+ float vec [3 ];
86+ GetNativeArray (3 , vec , 3 );
87+
88+ VectorToString (vec , value , sizeof (value ));
89+ map .AddString (key , value );
90+ return 0 ;
91+ }
92+
93+ public int Native_MapIterGetNum (Handle plugin , int argc ) {
94+ StringMultiMapIterator mapIter = GetNativeCell (1 );
95+
96+ char value [128 ];
97+ return mapIter .GetString (value , sizeof (value ))? StringToInt (value ) : GetNativeCell (2 );
98+ }
99+
100+ public int Native_MapIterSetNum (Handle plugin , int argc ) {
101+ StringMultiMapIterator mapIter = GetNativeCell (1 );
102+
103+ char value [128 ];
104+ IntToString (GetNativeCell (2 ), value , sizeof (value ));
105+
106+ mapIter .SetString (value );
107+ return ;
108+ }
109+
110+ public int Native_MapIterGetFloat (Handle plugin , int argc ) {
111+ StringMultiMapIterator mapIter = GetNativeCell (1 );
112+
113+ char value [128 ];
114+ return view_as <int >(mapIter .GetString (value , sizeof (value ))?
115+ StringToFloat (value ) : GetNativeCell (2 ));
116+ }
117+
118+ public int Native_MapIterSetFloat (Handle plugin , int argc ) {
119+ StringMultiMapIterator mapIter = GetNativeCell (1 );
120+
121+ char value [128 ];
122+ FloatToString (GetNativeCell (2 ), value , sizeof (value ));
123+
124+ mapIter .SetString (value );
125+ return 0 ;
126+ }
127+
128+ public int Native_MapIterGetVector (Handle plugin , int argc ) {
129+ StringMultiMapIterator mapIter = GetNativeCell (1 );
130+
131+ char value [128 ];
132+
133+ float outputVec [3 ];
134+ if (mapIter .GetString (value , sizeof (value ))) {
135+ StringToVector (value , outputVec );
136+ } else {
137+ GetNativeArray (3 , outputVec , 3 );
138+ }
139+ SetNativeArray (2 , outputVec , 3 );
140+ }
141+
142+ public int Native_MapIterSetVector (Handle plugin , int argc ) {
143+ StringMultiMapIterator mapIter = GetNativeCell (1 );
144+
145+ char value [128 ];
146+
147+ float vec [3 ];
148+ GetNativeArray (2 , vec , 3 );
149+
150+ VectorToString (vec , value , sizeof (value ));
151+ mapIter .SetString (value );
152+ return 0 ;
153+ }
0 commit comments