From efec3d420d60b03cf7b619f310f0a943a40fa0be Mon Sep 17 00:00:00 2001 From: cuckydev Date: Sat, 9 Feb 2019 16:11:06 -0500 Subject: [PATCH] Added Nikumaru Counter --- .gitignore | 4 +-- src/Ending.cpp | 15 ++++---- src/Game.cpp | 8 +++-- src/MycParam.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ src/MycParam.h | 10 ++++++ 5 files changed, 116 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 98c0f6ff..35d613e6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,8 @@ # Misc /obj -Config.dat -*rofile.dat +*.dat +*.rec build.7z build.zip diff --git a/src/Ending.cpp b/src/Ending.cpp index f38f0131..5e9113f2 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -11,19 +11,22 @@ #include "KeyControl.h" #include "Escape.h" #include "Organya.h" +#include "MycParam.h" #include "Main.h" #include "Stage.h" #include "Draw.h" #include "TextScr.h" +#define MAX_STRIP 0x10 + CREDIT Credit; -STRIP Strip[16]; +STRIP Strip[MAX_STRIP]; ILLUSTRATION Illust; //Update casts void ActionStripper() { - for (int s = 0; s < 16; s++) + for (int s = 0; s < MAX_STRIP; s++) { //Move up if (Strip[s].flag & 0x80 && Credit.mode) @@ -37,7 +40,7 @@ void ActionStripper() //Draw casts void PutStripper() { - for (int s = 0; s < 16; s++) + for (int s = 0; s < MAX_STRIP; s++) { if (Strip[s].flag & 0x80) { @@ -58,7 +61,7 @@ void PutStripper() //Create a cast object void SetStripper(int x, int y, char *text, int cast) { - for (int s = 0; s < 16; s++) + for (int s = 0; s < MAX_STRIP; s++) { if (!(Strip[s].flag & 0x80)) { @@ -81,7 +84,7 @@ void SetStripper(int x, int y, char *text, int cast) //Regenerate cast text void RestoreStripper() { - for (int s = 0; s < 16; s++) + for (int s = 0; s < MAX_STRIP; s++) { if (Strip[s].flag & 0x80) { @@ -436,7 +439,7 @@ int Scene_DownIsland(int mode) PutBitmap3(&rc_frame, 80 + (WINDOW_WIDTH - 320) / 2, 80 + (WINDOW_HEIGHT - 240) / 2, &rc_sky, 21); PutBitmap3(&rc_frame, sprite.x / 0x200 - 20 + (WINDOW_WIDTH - 320) / 2, sprite.y / 512 - 12 + (WINDOW_HEIGHT - 240) / 2, &rc_sprite, 21); PutBitmap3(&rc_frame, 80 + (WINDOW_WIDTH - 320) / 2, 128 + (WINDOW_HEIGHT - 240) / 2, &rc_ground, 21); - //PutTimeCounter(16, 8); + PutTimeCounter(16, 8); PutFramePerSecound(); if (!Flip_SystemTask()) diff --git a/src/Game.cpp b/src/Game.cpp index 32fd6677..e3ebd343 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -28,6 +28,7 @@ #include "Caret.h" #include "Map.h" #include "Main.h" +#include "MycParam.h" #include "MapName.h" #include "Sound.h" #include "Organya.h" @@ -258,7 +259,7 @@ int ModeTitle() bContinue = IsProfile(); //Set character - time_counter = 0;//LoadTimeCounter(); + time_counter = LoadTimeCounter(); if (time_counter && time_counter < 18000) char_type = 1; @@ -395,8 +396,8 @@ int ModeTitle() //Draw carets PutCaret(0, 0); - //if (time_counter) - // PutTimeCounter(16, 8); + if (time_counter) + PutTimeCounter(16, 8); PutFramePerSecound(); @@ -569,6 +570,7 @@ int ModeAction() } PutMapName(false); + PutTimeCounter(16, 8); if (g_GameFlags & 2) { diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 84eda38c..0c83da67 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -3,6 +3,7 @@ #include "MycParam.h" #include "NpChar.h" #include "CommonDefines.h" +#include "Tags.h" #include "ArmsItem.h" #include "ValueView.h" #include "TextScr.h" @@ -28,6 +29,8 @@ ARMS_LEVEL gArmsLevelTable[14] = {{40, 60, 200}} }; +int time_count; + void AddExpMyChar(int x) { int lv = gArmsData[gSelectedArms].level - 1; @@ -341,3 +344,90 @@ void PutMyAir(int x, int y) PutBitmap3(&grcGame, x, y, &rcAir[0], 26); } } + +void PutTimeCounter(int x, int y) +{ + RECT rcTime[3]; + rcTime[0] = {112, 104, 120, 112}; + rcTime[1] = {120, 104, 128, 112}; + rcTime[2] = {128, 104, 160, 112}; + + if (gMC.equip & 0x100) + { + //Draw clock and increase time + if (g_GameFlags & 2) + { + if (time_count < 300000) + ++time_count; + + if (time_count % 30 <= 10) + PutBitmap3(&grcGame, x, y, &rcTime[1], 26); + else + PutBitmap3(&grcGame, x, y, &rcTime[0], 26); + } + else + { + PutBitmap3(&grcGame, x, y, &rcTime[0], 26); + } + + //Draw time + PutNumber4(x, y, time_count / 3000, false); + PutNumber4(x + 20, y, time_count / 50 % 60, true); + PutNumber4(x + 32, y, time_count / 5 % 10, false); + PutBitmap3(&grcGame, x + 30, y, &rcTime[2], 26); + } + else + { + time_count = 0; + } +} + +int LoadTimeCounter() +{ + //Open file + char path[PATH_LENGTH]; + sprintf(path, "%s/290.rec", gModulePath); + + SDL_RWops *fp = SDL_RWFromFile(path, "rb"); + if (!fp) + return 0; + + REC rec; + + //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); + + //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]; + p[1] -= rec.random[i]; + p[2] -= rec.random[i]; + p[3] -= rec.random[i] >> 1; + } + + //Verify checksum's result + if (rec.counter[0] == rec.counter[1] && rec.counter[0] == rec.counter[2]) + { + time_count = rec.counter[0]; + return rec.counter[0]; + } + else + { + time_count = 0; + return 0; + } +} diff --git a/src/MycParam.h b/src/MycParam.h index 216d1fa3..2547791c 100644 --- a/src/MycParam.h +++ b/src/MycParam.h @@ -1,9 +1,16 @@ #pragma once +#include struct ARMS_LEVEL { int exp[3]; }; +struct REC +{ + int32_t counter[4]; + uint8_t random[4]; +}; + extern ARMS_LEVEL gArmsLevelTable[14]; void AddExpMyChar(int x); @@ -18,3 +25,6 @@ void PutArmsEnergy(bool flash); void PutActiveArmsList(); void PutMyLife(bool flash); void PutMyAir(int x, int y); +void PutTimeCounter(int x, int y); + +int LoadTimeCounter();