Skip to content

Commit

Permalink
fixed cheat sync for multi-code cheats
Browse files Browse the repository at this point in the history
  • Loading branch information
Ownasaurus committed Aug 29, 2015
1 parent e22a292 commit 21a90ad
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 16 deletions.
107 changes: 92 additions & 15 deletions Source/Project64/CKaillera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,32 +175,105 @@ void CKaillera::processResult(CKailleraPacket ckp[])
}
else
{
// store the cheat locally
addCode(ckp[x].code);
// reload the cheats
g_BaseSystem->m_Cheats.LoadCheats(false);
if (strncmp(ckp[x].code, RESET, CODE_LENGTH) == 0) // this is a reset command (probably a cheat was disabled)
{
ck->clearCodes();
}
else if (strncmp(ckp[x].code, LOAD, CODE_LENGTH) == 0) // this is a load command command (probably just finished sending all cheats)
{
// reload the cheats
g_BaseSystem->m_Cheats.LoadCheats(false);
}
else // just a regular cheat
{
// store the cheat locally
addCode(ckp[x].code);
}

// send a confirmation response
CKailleraPacket response[4];
memset(response, 0, sizeof(response));
response[0].Type = PACKET_TYPE_CHEAT;
strncpy(response[0].code, CONFIRM, CODE_LENGTH);

playValuesLength = kailleraModifyPlayValues(response, sizeof(CKailleraPacket));

processResult(response);
sendConfirmCode();
}
break;
}
}
}

void CKaillera::sendResetCode()
{
CKailleraPacket response[4];
memset(response, 0, sizeof(response));
response[0].Type = PACKET_TYPE_CHEAT;
strncpy(response[0].code, RESET, CODE_LENGTH);

playValuesLength = kailleraModifyPlayValues(response, sizeof(CKailleraPacket));

processResult(response);
}
void CKaillera::sendLoadCode()
{
CKailleraPacket response[4];
memset(response, 0, sizeof(response));
response[0].Type = PACKET_TYPE_CHEAT;
strncpy(response[0].code, LOAD, CODE_LENGTH);

playValuesLength = kailleraModifyPlayValues(response, sizeof(CKailleraPacket));

processResult(response);
}

void CKaillera::sendConfirmCode()
{
CKailleraPacket response[4];
memset(response, 0, sizeof(response));
response[0].Type = PACKET_TYPE_CHEAT;
strncpy(response[0].code, CONFIRM, CODE_LENGTH);

playValuesLength = kailleraModifyPlayValues(response, sizeof(CKailleraPacket));

processResult(response);
}

void CKaillera::addCode(LPCSTR str)
{
char * newCode = new char[CODE_LENGTH];
strncpy(newCode, str, CODE_LENGTH);
int length = strlen(str);
char *c = new char[length + 1];
c[length] = '\0';
strncpy(c, str, length);
const char delimiter[] = ",";
char *token;
char *context = NULL;

token = strtok_s(c, delimiter, &context);

while (token != NULL)
{
char * newCode = new char[CODE_LENGTH];
strncpy(newCode, token, CODE_LENGTH);

codes.push_back(newCode);

codes.push_back(newCode);
token = strtok_s(NULL, delimiter, &context);
}
}

void CKaillera::delCode(LPCSTR str)
{
int length = numCodes();
for (int x = 0; x < length; x++)
{
if (strncmp(codes.at(x), str, strlen(str)) == 0) // the code matches at location x
{
// deallocate the memory for the code
char *c = codes.at(x);
delete(c);

// remove the code from the vector
codes.erase(codes.begin() + x);

// short circut out. our job is done
return;
}
}
}

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

void CKaillera::sendCodes()
{
sendResetCode();

CKailleraPacket ckp[4];

for (int x = 0; x < codes.size(); x++)
Expand All @@ -233,6 +308,8 @@ void CKaillera::sendCodes()

processResult(ckp);
}

sendLoadCode();
}

int CKaillera::numCodes()
Expand Down
8 changes: 8 additions & 0 deletions Source/Project64/CKaillera.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,22 @@ class CKaillera
void endGame();

void addCode(LPCSTR str);
void delCode(LPCSTR str);
LPCSTR getCode(int i);
void clearCodes();
void sendCodes();
int numCodes();

private:

const char* RESET = "00000000 0001";
const char* LOAD = "00000000 0002";
const char* CONFIRM = "00000000 0000";

void sendResetCode();
void sendLoadCode();
void sendConfirmCode();

kailleraInfos kInfos;
HMODULE KailleraHandle;
int LoadKailleraFuncs();
Expand Down
2 changes: 1 addition & 1 deletion Source/Project64/N64 System/Cheat Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void CCheats::LoadCheats(bool DisableSelected)

if (ck->isPlayingKailleraGame)
{
if (ck->playerNumber != 0) // if you're not player #1, the host
if (ck->playerNumber != 0) // if you're not player #1, (aka not the host)
{
// load the kaillera set of cheats
int number_of_codes = ck->numCodes();
Expand Down

0 comments on commit 21a90ad

Please sign in to comment.