@@ -175,32 +175,105 @@ void CKaillera::processResult(CKailleraPacket ckp[])
175175 }
176176 else
177177 {
178- // store the cheat locally
179- addCode (ckp[x].code );
180- // reload the cheats
181- g_BaseSystem->m_Cheats .LoadCheats (false );
178+ if (strncmp (ckp[x].code , RESET, CODE_LENGTH) == 0 ) // this is a reset command (probably a cheat was disabled)
179+ {
180+ ck->clearCodes ();
181+ }
182+ else if (strncmp (ckp[x].code , LOAD, CODE_LENGTH) == 0 ) // this is a load command command (probably just finished sending all cheats)
183+ {
184+ // reload the cheats
185+ g_BaseSystem->m_Cheats .LoadCheats (false );
186+ }
187+ else // just a regular cheat
188+ {
189+ // store the cheat locally
190+ addCode (ckp[x].code );
191+ }
182192
183193 // send a confirmation response
184- CKailleraPacket response[4 ];
185- memset (response, 0 , sizeof (response));
186- response[0 ].Type = PACKET_TYPE_CHEAT;
187- strncpy (response[0 ].code , CONFIRM, CODE_LENGTH);
188-
189- playValuesLength = kailleraModifyPlayValues (response, sizeof (CKailleraPacket));
190-
191- processResult (response);
194+ sendConfirmCode ();
192195 }
193196 break ;
194197 }
195198 }
196199}
197200
201+ void CKaillera::sendResetCode ()
202+ {
203+ CKailleraPacket response[4 ];
204+ memset (response, 0 , sizeof (response));
205+ response[0 ].Type = PACKET_TYPE_CHEAT;
206+ strncpy (response[0 ].code , RESET, CODE_LENGTH);
207+
208+ playValuesLength = kailleraModifyPlayValues (response, sizeof (CKailleraPacket));
209+
210+ processResult (response);
211+ }
212+ void CKaillera::sendLoadCode ()
213+ {
214+ CKailleraPacket response[4 ];
215+ memset (response, 0 , sizeof (response));
216+ response[0 ].Type = PACKET_TYPE_CHEAT;
217+ strncpy (response[0 ].code , LOAD, CODE_LENGTH);
218+
219+ playValuesLength = kailleraModifyPlayValues (response, sizeof (CKailleraPacket));
220+
221+ processResult (response);
222+ }
223+
224+ void CKaillera::sendConfirmCode ()
225+ {
226+ CKailleraPacket response[4 ];
227+ memset (response, 0 , sizeof (response));
228+ response[0 ].Type = PACKET_TYPE_CHEAT;
229+ strncpy (response[0 ].code , CONFIRM, CODE_LENGTH);
230+
231+ playValuesLength = kailleraModifyPlayValues (response, sizeof (CKailleraPacket));
232+
233+ processResult (response);
234+ }
235+
198236void CKaillera::addCode (LPCSTR str)
199237{
200- char * newCode = new char [CODE_LENGTH];
201- strncpy (newCode, str, CODE_LENGTH);
238+ int length = strlen (str);
239+ char *c = new char [length + 1 ];
240+ c[length] = ' \0 ' ;
241+ strncpy (c, str, length);
242+ const char delimiter[] = " ," ;
243+ char *token;
244+ char *context = NULL ;
245+
246+ token = strtok_s (c, delimiter, &context);
247+
248+ while (token != NULL )
249+ {
250+ char * newCode = new char [CODE_LENGTH];
251+ strncpy (newCode, token, CODE_LENGTH);
252+
253+ codes.push_back (newCode);
202254
203- codes.push_back (newCode);
255+ token = strtok_s (NULL , delimiter, &context);
256+ }
257+ }
258+
259+ void CKaillera::delCode (LPCSTR str)
260+ {
261+ int length = numCodes ();
262+ for (int x = 0 ; x < length; x++)
263+ {
264+ if (strncmp (codes.at (x), str, strlen (str)) == 0 ) // the code matches at location x
265+ {
266+ // deallocate the memory for the code
267+ char *c = codes.at (x);
268+ delete (c);
269+
270+ // remove the code from the vector
271+ codes.erase (codes.begin () + x);
272+
273+ // short circut out. our job is done
274+ return ;
275+ }
276+ }
204277}
205278
206279void CKaillera::clearCodes ()
@@ -220,6 +293,8 @@ LPCSTR CKaillera::getCode(int i)
220293
221294void CKaillera::sendCodes ()
222295{
296+ sendResetCode ();
297+
223298 CKailleraPacket ckp[4 ];
224299
225300 for (int x = 0 ; x < codes.size (); x++)
@@ -233,6 +308,8 @@ void CKaillera::sendCodes()
233308
234309 processResult (ckp);
235310 }
311+
312+ sendLoadCode ();
236313}
237314
238315int CKaillera::numCodes ()
0 commit comments