Skip to content

Commit 21a90ad

Browse files
committed
fixed cheat sync for multi-code cheats
1 parent e22a292 commit 21a90ad

3 files changed

Lines changed: 101 additions & 16 deletions

File tree

Source/Project64/CKaillera.cpp

Lines changed: 92 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
198236
void 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

206279
void CKaillera::clearCodes()
@@ -220,6 +293,8 @@ LPCSTR CKaillera::getCode(int i)
220293

221294
void 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

238315
int CKaillera::numCodes()

Source/Project64/CKaillera.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,22 @@ class CKaillera
5858
void endGame();
5959

6060
void addCode(LPCSTR str);
61+
void delCode(LPCSTR str);
6162
LPCSTR getCode(int i);
6263
void clearCodes();
6364
void sendCodes();
6465
int numCodes();
6566

6667
private:
6768

69+
const char* RESET = "00000000 0001";
70+
const char* LOAD = "00000000 0002";
6871
const char* CONFIRM = "00000000 0000";
72+
73+
void sendResetCode();
74+
void sendLoadCode();
75+
void sendConfirmCode();
76+
6977
kailleraInfos kInfos;
7078
HMODULE KailleraHandle;
7179
int LoadKailleraFuncs();

Source/Project64/N64 System/Cheat Class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void CCheats::LoadCheats(bool DisableSelected)
159159

160160
if (ck->isPlayingKailleraGame)
161161
{
162-
if (ck->playerNumber != 0) // if you're not player #1, the host
162+
if (ck->playerNumber != 0) // if you're not player #1, (aka not the host)
163163
{
164164
// load the kaillera set of cheats
165165
int number_of_codes = ck->numCodes();

0 commit comments

Comments
 (0)