Saving Nikumaru Counter
This commit is contained in:
parent
efec3d420d
commit
ded926b422
8 changed files with 88 additions and 17 deletions
BIN
build/data/ArmsItemJapanese.tsc
Normal file
BIN
build/data/ArmsItemJapanese.tsc
Normal file
Binary file not shown.
BIN
build/data/CreditJapanese.tsc
Normal file
BIN
build/data/CreditJapanese.tsc
Normal file
Binary file not shown.
BIN
build/data/HeadJapanese.tsc
Normal file
BIN
build/data/HeadJapanese.tsc
Normal file
Binary file not shown.
1
build/data/StageSelectJapanese.tsc
Normal file
1
build/data/StageSelectJapanese.tsc
Normal file
|
@ -0,0 +1 @@
|
|||
drqqqNK}傑嘲飼<E598B2>楓屯榑リフラハテ<>眦)テテ愑2ツマ<EFBE82>額zzz}<7D><>KdrqqrNK}傑嘲飼<E598B2>楓篤淨セト般2ル閤<EFBE99>額zzz}<7D><>KdrqqsNK}傑嘲飼<E598B2>楓篤焼米チトハ}連額zzz}<7D><>KdrqqtNK}傑嘲飼<E598B2>楓鳶<E6A593>'}<7D>額zzz}<7D><>KdrqquNK}傑嘲飼<E598B2>楓沌フシ}<7D>額zzz}<7D><>KdrqqvNK}傑嘲飼<E598B2>楓瀞&ユ<>ハチ}<7D>額zzz}<7D><>KNK
|
|
@ -382,6 +382,75 @@ void PutTimeCounter(int x, int y)
|
|||
}
|
||||
}
|
||||
|
||||
bool SaveTimeCounter()
|
||||
{
|
||||
REC rec;
|
||||
|
||||
//Quit if player doesn't have the Nikumaru Counter
|
||||
if (!(gMC.equip & 0x100))
|
||||
return true;
|
||||
|
||||
//Get last time
|
||||
char path[PATH_LENGTH];
|
||||
sprintf(path, "%s/290.rec", gModulePath);
|
||||
|
||||
SDL_RWops *fp = SDL_RWFromFile(path, "rb");
|
||||
if (fp)
|
||||
{
|
||||
//Read data
|
||||
rec.counter[0] = SDL_ReadLE32(fp);
|
||||
rec.counter[1] = SDL_ReadLE32(fp);
|
||||
rec.counter[2] = SDL_ReadLE32(fp);
|
||||
rec.counter[3] = SDL_ReadLE32(fp);
|
||||
rec.random[0] = SDL_ReadU8(fp);
|
||||
rec.random[1] = SDL_ReadU8(fp);
|
||||
rec.random[2] = SDL_ReadU8(fp);
|
||||
rec.random[3] = SDL_ReadU8(fp);
|
||||
SDL_RWclose(fp);
|
||||
|
||||
//Decode from checksum
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
uint8_t *p = (uint8_t*)&rec.counter[i];
|
||||
p[0] -= (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? (rec.random[i]) : (rec.random[i] >> 1);
|
||||
p[1] -= rec.random[i];
|
||||
p[2] -= rec.random[i];
|
||||
p[3] -= (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? (rec.random[i] >> 1) : (rec.random[i]);
|
||||
}
|
||||
|
||||
//If this is faster than our new time, quit
|
||||
if (rec.counter[0] < time_count)
|
||||
return true;
|
||||
}
|
||||
|
||||
//Save new time
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
rec.counter[i] = time_count;
|
||||
rec.random[i] = Random(0, 250) + i;
|
||||
|
||||
uint8_t *p = (uint8_t*)&rec.counter[i];
|
||||
p[0] -= (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? (rec.random[i]) : (rec.random[i] >> 1);
|
||||
p[1] -= rec.random[i];
|
||||
p[2] -= rec.random[i];
|
||||
p[3] -= (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? (rec.random[i] >> 1) : (rec.random[i]);
|
||||
}
|
||||
|
||||
fp = SDL_RWFromFile(path, "wb");
|
||||
if (!fp)
|
||||
return false;
|
||||
SDL_WriteLE32(fp, rec.counter[0]);
|
||||
SDL_WriteLE32(fp, rec.counter[1]);
|
||||
SDL_WriteLE32(fp, rec.counter[2]);
|
||||
SDL_WriteLE32(fp, rec.counter[3]);
|
||||
SDL_WriteU8(fp, rec.random[0]);
|
||||
SDL_WriteU8(fp, rec.random[1]);
|
||||
SDL_WriteU8(fp, rec.random[2]);
|
||||
SDL_WriteU8(fp, rec.random[3]);
|
||||
SDL_RWclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
int LoadTimeCounter()
|
||||
{
|
||||
//Open file
|
||||
|
@ -405,18 +474,14 @@ int LoadTimeCounter()
|
|||
rec.random[3] = SDL_ReadU8(fp);
|
||||
SDL_RWclose(fp);
|
||||
|
||||
//HACK: this swaps the random values to correspond to the correct bytes
|
||||
*((uint32_t*)rec.random) = SDL_SwapLE32(*((uint32_t*)rec.random));
|
||||
|
||||
//Decode from checksum
|
||||
uint8_t *p;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
p = (uint8_t*)&rec.counter[i];
|
||||
p[0] -= rec.random[i];
|
||||
uint8_t *p = (uint8_t*)&rec.counter[i];
|
||||
p[0] -= (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? (rec.random[i]) : (rec.random[i] >> 1);
|
||||
p[1] -= rec.random[i];
|
||||
p[2] -= rec.random[i];
|
||||
p[3] -= rec.random[i] >> 1;
|
||||
p[3] -= (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? (rec.random[i] >> 1) : (rec.random[i]);
|
||||
}
|
||||
|
||||
//Verify checksum's result
|
||||
|
|
|
@ -26,5 +26,5 @@ void PutActiveArmsList();
|
|||
void PutMyLife(bool flash);
|
||||
void PutMyAir(int x, int y);
|
||||
void PutTimeCounter(int x, int y);
|
||||
|
||||
bool SaveTimeCounter();
|
||||
int LoadTimeCounter();
|
||||
|
|
|
@ -706,6 +706,11 @@ int TextScriptProc()
|
|||
ChangeMyUnit(z);
|
||||
gTS.p_read += 8;
|
||||
}
|
||||
else if (IS_COMMAND('S','T','C'))
|
||||
{
|
||||
SaveTimeCounter();
|
||||
gTS.p_read += 4;
|
||||
}
|
||||
else if (IS_COMMAND('T','R','A'))
|
||||
{
|
||||
z = GetTextScriptNo(gTS.p_read + 4);
|
||||
|
|
Loading…
Add table
Reference in a new issue