diff --git a/data/file_list.yml b/data/file_list.yml index 23efc2e1..900aa3d4 100644 --- a/data/file_list.yml +++ b/data/file_list.yml @@ -158496,87 +158496,87 @@ Util/ScenePrepoFunction.o: - offset: 0x574094 size: 288 label: _ZN2rs32trySavePrepoCompleteMainScenarioEiilll - status: NotDecompiled + status: Matching - offset: 0x5741b4 size: 380 label: _ZN2rs22trySavePrepoStartStageEPKcRKN4sead7Vector3IfEElll - status: NotDecompiled + status: Matching - offset: 0x574330 size: 380 label: _ZN2rs21trySavePrepoExitStageEPKcRKN4sead7Vector3IfEElll - status: NotDecompiled + status: Matching - offset: 0x5744ac size: 380 label: _ZN2rs21trySavePrepoMissEventEPKcRKN4sead7Vector3IfEElll - status: NotDecompiled + status: Matching - offset: 0x574628 size: 364 label: _ZN2rs25trySavePrepoShineGetEventEPKciiilll - status: NotDecompiled + status: Matching - offset: 0x574794 size: 308 label: _ZN2rs30trySavePrepoReceiveAchievementEPKcilll - status: NotDecompiled + status: Matching - offset: 0x5748c8 size: 1216 label: _ZN2rs31trySavePrepoAchievementProgressE22GameDataHolderAccessorlll - status: NotDecompiled + status: Matching - offset: 0x574d88 size: 324 label: _ZN2rs23trySavePrepoGetCapEventEPKcilll - status: NotDecompiled + status: Matching - offset: 0x574ecc size: 328 label: _ZN2rs25trySavePrepoGetClothEventEPKcilll - status: NotDecompiled + status: Matching - offset: 0x575014 size: 328 label: _ZN2rs24trySavePrepoGetGiftEventEPKcilll - status: NotDecompiled + status: Matching - offset: 0x57515c size: 328 label: _ZN2rs27trySavePrepoGetStickerEventEPKcilll - status: NotDecompiled + status: Matching - offset: 0x5752a4 size: 292 label: _ZN2rs26trySavePrepoChangeCapEventEPKclll - status: NotDecompiled + status: Matching - offset: 0x5753c8 size: 296 label: _ZN2rs28trySavePrepoChangeClothEventEPKclll - status: NotDecompiled + status: Matching - offset: 0x5754f0 size: 308 label: _ZN2rs26trySavePrepoFirstHackEventEPKcilll - status: NotDecompiled + status: Matching - offset: 0x575624 size: 384 label: _ZN2rs30trySavePrepoGetCollectBgmEventEPKcS1_billl - status: NotDecompiled + status: Matching - offset: 0x5757a4 size: 504 label: _ZN2rs25trySavePrepoSettingsStateEbPKcRK14GameConfigDatall - status: NotDecompiled + status: Matching - offset: 0x57599c size: 256 label: _ZN2rs28trySavePrepoSeparatePlayModeEblll - status: NotDecompiled + status: Matching - offset: 0x575a9c size: 4 label: _ZN2rs5prepo17enableIsSavePrepoEv - status: NotDecompiled + status: Matching - offset: 0x575aa0 size: 4 label: _ZN2rs5prepo18disableIsSavePrepoEv - status: NotDecompiled + status: Matching - offset: 0x575aa4 size: 68 label: _ZN2rs5prepo18generateSaveDataIdEv - status: NotDecompiled + status: Matching - offset: 0x575ae8 size: 12 label: _ZN2rs5prepo17calcPrepoHashCodeEPKc - status: NotDecompiled + status: Matching Util/StageInputFunction.o: '.text': - offset: 0x575af4 diff --git a/lib/al/Library/Base/HashCodeUtil.cpp b/lib/al/Library/Base/HashCodeUtil.cpp index a6a45e40..4197ebe5 100644 --- a/lib/al/Library/Base/HashCodeUtil.cpp +++ b/lib/al/Library/Base/HashCodeUtil.cpp @@ -5,37 +5,37 @@ #include namespace al { -s32 calcHashCode(const char* str) { +u32 calcHashCode(const char* str) { if (str[0] == '\0') return 0; - s32 hashCode = 0; + u32 hashCode = 0; for (s32 i = 0; str[i] != '\0'; i++) hashCode = (hashCode * 0x1f) + str[i]; return hashCode; } -s32 calcHashCodeLower(const char* str) { - s32 hashCode = 0; +u32 calcHashCodeLower(const char* str) { + u32 hashCode = 0; for (s32 i = 0; str[i] != '\0'; i++) hashCode = (hashCode * 0x1f) + tolower(str[i]); return hashCode; } -s32 calcHashCodeFmt(const char* format, std::va_list argv) { +u32 calcHashCodeFmt(const char* format, std::va_list argv) { char buf[0x100]; vsnprintf(buf, 0x100, format, argv); return calcHashCode(buf); } -s32 calcHashCodeFmt(const char* format, ...) { +u32 calcHashCodeFmt(const char* format, ...) { std::va_list argv; va_start(argv, format); - s32 result = calcHashCodeFmt(format, argv); + u32 result = calcHashCodeFmt(format, argv); va_end(argv); return result; diff --git a/lib/al/Library/Base/HashCodeUtil.h b/lib/al/Library/Base/HashCodeUtil.h index 7e54a332..140bfe8a 100644 --- a/lib/al/Library/Base/HashCodeUtil.h +++ b/lib/al/Library/Base/HashCodeUtil.h @@ -4,9 +4,9 @@ #include namespace al { -s32 calcHashCode(const char* str); -s32 calcHashCodeLower(const char* str); -s32 calcHashCodeFmt(const char* format, std::va_list argv); -s32 calcHashCodeFmt(const char* format, ...); +u32 calcHashCode(const char* str); +u32 calcHashCodeLower(const char* str); +u32 calcHashCodeFmt(const char* format, std::va_list argv); +u32 calcHashCodeFmt(const char* format, ...); const char* getBaseName(const char* name); } // namespace al diff --git a/src/Util/ScenePrepoFunction.cpp b/src/Util/ScenePrepoFunction.cpp new file mode 100644 index 00000000..d2173b72 --- /dev/null +++ b/src/Util/ScenePrepoFunction.cpp @@ -0,0 +1,460 @@ +#include "Util/ScenePrepoFunction.h" + +#include +#include +#include + +#include "Library/Base/HashCodeUtil.h" + +#include "System/GameConfigData.h" +#include "System/GameDataFunction.h" +#include "System/GameDataUtil.h" +#include "Util/AchievementUtil.h" +#include "Util/ClothUtil.h" + +namespace rs { +static char buffer[0x2000]; + +bool trySavePrepoCompleteMainScenario(s32 worldId, s32 mainScenarioNo, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("complete_main_scenario_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(6)); + + playReport.Add("world_id", static_cast(worldId)); + playReport.Add("main_scenario_no", static_cast(mainScenarioNo)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoStartStage(const char* stageName, const sead::Vector3f& position, s64 playTime, + s64 saveDataId, s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("stage_in_out_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + // BUG: buffer too small (prepared for 8 entries, adds 9) + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(8)); + + playReport.Add("stage_name", static_cast(prepo::calcPrepoHashCode(stageName))); + playReport.Add("x", position.x); + playReport.Add("y", position.y); + playReport.Add("z", position.z); + playReport.Add("in_out_type", InOutType_Start); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoExitStage(const char* stageName, const sead::Vector3f& position, s64 playTime, + s64 saveDataId, s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("stage_in_out_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + // BUG: buffer too small (prepared for 8 entries, adds 9) + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(8)); + + playReport.Add("stage_name", static_cast(prepo::calcPrepoHashCode(stageName))); + playReport.Add("x", position.x); + playReport.Add("y", position.y); + playReport.Add("z", position.z); + playReport.Add("in_out_type", InOutType_Exit); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoMissEvent(const char* stageName, const sead::Vector3f& position, s64 playTime, + s64 saveDataId, s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("stage_in_out_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + // BUG: buffer too small (prepared for 8 entries, adds 9) + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(8)); + + playReport.Add("stage_name", static_cast(prepo::calcPrepoHashCode(stageName))); + playReport.Add("x", position.x); + playReport.Add("y", position.y); + playReport.Add("z", position.z); + playReport.Add("in_out_type", InOutType_Miss); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoShineGetEvent(const char* stageName, s32 shineId, s32 totalShineNum, + s32 totalShopShineNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("shine_get_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(8)); + + playReport.Add("stage_name", static_cast(prepo::calcPrepoHashCode(stageName))); + playReport.Add("shine_id", static_cast(shineId)); + playReport.Add("total_shine_num", static_cast(totalShineNum)); + playReport.Add("total_shop_shine_num", static_cast(totalShopShineNum)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoReceiveAchievement(const char* achievementName, s32 receivedNum, s64 playTime, + s64 saveDataId, s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("receive_achievement_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(6)); + + playReport.Add("achievement_name", static_cast(prepo::calcPrepoHashCode(achievementName))); + playReport.Add("received_num", static_cast(receivedNum)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoAchievementProgress(GameDataHolderAccessor accessor, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("achievement_progress_state"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(38)); + + playReport.Add("shine_gather", static_cast(GameDataFunction::getTotalShineNum(accessor))); + playReport.Add("shine_collect_coin_shop", + static_cast(calcBuyItemNumForCoinCollectByWorld(accessor))); + playReport.Add("shine_shine_2d", static_cast(calcGetShineNumDot(accessor))); + playReport.Add("shine_treasure_box", static_cast(calcGetShineNumTreasureBox(accessor))); + playReport.Add("shine_music_note", static_cast(calcGetShineNumNoteObj(accessor))); + // typo: athretic / athletic + playReport.Add("shine_timer_athretic", + static_cast(calcGetShineNumTimerAthletic(accessor))); + playReport.Add("shine_captain_kinopio", + static_cast(calcGetShineNumKinopioBrigade(accessor))); + playReport.Add("shine_traveling_peach", + static_cast(calcGetShineNumWorldTravelingPeach(accessor))); + playReport.Add("shine_collect_animal_all", + static_cast(calcGetShineNumCollectAnimal(accessor))); + playReport.Add("shine_kuribo_girl", static_cast(calcGetShineNumKuriboGirl(accessor))); + playReport.Add("shine_jugem", static_cast(calcGetShineNumJugemFish(accessor))); + playReport.Add("shine_seed", static_cast(calcGetShineNumGrowPlant(accessor))); + playReport.Add("shine_rabbit", static_cast(calcGetShineNumRabbit(accessor))); + playReport.Add("shine_dig_point", static_cast(calcGetShineNumDigPoint(accessor))); + playReport.Add("shine_cap_hanger", static_cast(calcGetShineNumCapHanger(accessor))); + playReport.Add("shine_bird", static_cast(calcGetShineNumBird(accessor))); + playReport.Add("shine_costume_room", static_cast(calcGetShineNumCostumeRoom(accessor))); + playReport.Add("shine_cap_throttle", static_cast(calcGetShineNumSlot(accessor))); + playReport.Add("shine_hide_and_seek_cap_man", + static_cast(calcGetShineNumHideAndSeekCapMan(accessor))); + playReport.Add("shine_collect_bgm", static_cast(calcGetShineNumCollectedBgm(accessor))); + playReport.Add("shine_hint_photo", static_cast(calcGetShineNumHintPhoto(accessor))); + playReport.Add("mini_game_race_man", static_cast(calcGetShineNumRace(accessor))); + playReport.Add("mini_game_figure_walker", + static_cast(calcGetShineNumFigureWalking(accessor))); + playReport.Add("mini_game_sphinx_quiz", static_cast(calcSphinxQuizCompleteNum(accessor))); + playReport.Add("souvenir_count", + static_cast(calcHaveGiftNum(accessor) + calcHaveStickerNum(accessor))); + playReport.Add("capture_count", static_cast(calcHackObjNum(accessor))); + playReport.Add("costume_cap", static_cast(calcHaveCapNum(accessor))); + playReport.Add("costume_clothes", static_cast(calcHaveClothNum(accessor))); + playReport.Add("other_moon_stone_all", static_cast(calcUnlockMoonRockNum(accessor))); + playReport.Add("other_world_warp_hole_all", + static_cast(calcWorldWarpHoleThroughNum(accessor))); + playReport.Add("other_check_point", static_cast(calcGetCheckpointNum(accessor))); + playReport.Add("other_coin", static_cast(getTotalCoinNum(accessor))); + playReport.Add("other_jump", static_cast(getPlayerJumpCount(accessor))); + playReport.Add("other_cap_throw", static_cast(getPlayerThrowCapCount(accessor))); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoGetCapEvent(const char* itemName, s32 totalNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("collect_item_get_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(7)); + + playReport.Add("category", ItemCategoryType_Cap); + playReport.Add("item_name", static_cast(prepo::calcPrepoHashCode(itemName))); + playReport.Add("total_num", static_cast(totalNum)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoGetClothEvent(const char* itemName, s32 totalNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("collect_item_get_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(7)); + + playReport.Add("category", ItemCategoryType_Cloth); + playReport.Add("item_name", static_cast(prepo::calcPrepoHashCode(itemName))); + playReport.Add("total_num", static_cast(totalNum)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoGetGiftEvent(const char* itemName, s32 totalNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("collect_item_get_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(7)); + + playReport.Add("category", ItemCategoryType_Gift); + playReport.Add("item_name", static_cast(prepo::calcPrepoHashCode(itemName))); + playReport.Add("total_num", static_cast(totalNum)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoGetStickerEvent(const char* itemName, s32 totalNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("collect_item_get_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(7)); + + playReport.Add("category", ItemCategoryType_Sticker); + playReport.Add("item_name", static_cast(prepo::calcPrepoHashCode(itemName))); + playReport.Add("total_num", static_cast(totalNum)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoChangeCapEvent(const char* itemName, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("cloth_change_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(6)); + + playReport.Add("category", ItemCategoryType_Cap); + playReport.Add("item_name", static_cast(prepo::calcPrepoHashCode(itemName))); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoChangeClothEvent(const char* itemName, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("cloth_change_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(6)); + + playReport.Add("category", ItemCategoryType_Cloth); + playReport.Add("item_name", static_cast(prepo::calcPrepoHashCode(itemName))); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoFirstHackEvent(const char* hackObjName, s32 totalHackedObjNum, s64 playTime, + s64 saveDataId, s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("first_hack_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(6)); + + playReport.Add("hack_obj_name", static_cast(prepo::calcPrepoHashCode(hackObjName))); + playReport.Add("total_hacked_obj_num", static_cast(totalHackedObjNum)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoGetCollectBgmEvent(const char* bgmResourceName, const char* bgmSituationName, + bool isBailout, s32 collectedBgmNum, s64 playTime, + s64 saveDataId, s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("get_collect_bgm_event"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(8)); + + playReport.Add("bgm_resource_name", + static_cast(prepo::calcPrepoHashCode(bgmResourceName))); + playReport.Add("bgm_situation_name", + static_cast(prepo::calcPrepoHashCode(bgmSituationName))); + playReport.Add("is_bailout", static_cast(isBailout)); + playReport.Add("collected_bgm_num", static_cast(collectedBgmNum)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoSettingsState(bool isKidsMode, const char* language, + const GameConfigData& configData, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("settings_state"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + // NOTE: buffer too large (prepared for 14 entries, adds 12) + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(14)); + + playReport.Add("is_kids_mode", static_cast(isKidsMode)); + playReport.Add("language", static_cast(prepo::calcPrepoHashCode(language))); + playReport.Add("camera_stick_sensitivity_level", + static_cast(configData.getCameraStickSensitivityLevel())); + bool isCameraReverseInputH = configData.isCameraReverseInputH(); + bool isCameraReverseInputV = configData.isCameraReverseInputV(); + playReport.Add("camera_reverse_input", + static_cast((isCameraReverseInputH << 1) | isCameraReverseInputV)); + playReport.Add("is_valid_camera_gyro", static_cast(configData.isValidCameraGyro())); + playReport.Add("camera_gyro_sensitivity_level", + static_cast(configData.getCameraGyroSensitivityLevel())); + playReport.Add("is_use_open_list_additional_button", + static_cast(configData.isUseOpenListAdditionalButton())); + playReport.Add("is_valid_pad_rumble", static_cast(configData.isValidPadRumble())); + playReport.Add("pad_rumble_level", static_cast(configData.getPadRumbleLevel())); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +bool trySavePrepoSeparatePlayMode(bool isSeparatePlayMode, s64 playTime, s64 saveDataId, + s64 acrossPlayTime) { + nn::account::Uid lastOpenedUser; + nn::prepo::PlayReport playReport = nn::prepo::PlayReport("separate_play_mode_state"); + + if (nn::account::GetLastOpenedUser(&lastOpenedUser).IsFailure() || !lastOpenedUser.IsValid()) + return false; + + playReport.SetBuffer(&buffer, nn::prepo::PlayReport::CalcBufferSize(5)); + + playReport.Add("is_separate_play_mode", static_cast(isSeparatePlayMode)); + playReport.Add("play_time", playTime); + playReport.Add("across_play_time", acrossPlayTime); + playReport.Add("save_data_id", saveDataId); + playReport.Add("app_version", 1l); + + return playReport.Save(lastOpenedUser).IsSuccess(); +} + +namespace prepo { +void enableIsSavePrepo() {} + +void disableIsSavePrepo() {} + +s64 generateSaveDataId() { + if (!nn::time::IsInitialized() && nn::time::Initialize().IsFailure()) + return -1l; + + nn::time::PosixTime time; + if (nn::time::StandardUserSystemClock::GetCurrentTime(&time).IsFailure()) + return -1l; + + return time.time; +} + +u32 calcPrepoHashCode(const char* str) { + if (!str) + return 0; + + return al::calcHashCode(str); +} +} // namespace prepo +} // namespace rs diff --git a/src/Util/ScenePrepoFunction.h b/src/Util/ScenePrepoFunction.h index f6e3b56e..98362e0f 100644 --- a/src/Util/ScenePrepoFunction.h +++ b/src/Util/ScenePrepoFunction.h @@ -3,32 +3,62 @@ #include #include -class GameDataHolderAccessor; +#include "System/GameDataHolderAccessor.h" + class GameConfigData; namespace rs { -bool trySavePrepoCompleteMainScenario(s32, s32, s64, s64, s64); -bool trySavePrepoStartStage(const char*, const sead::Vector3f&, s64, s64, s64); -bool trySavePrepoExitStage(const char*, const sead::Vector3f&, s64, s64, s64); -bool trySavePrepoMissEvent(const char*, const sead::Vector3f&, s64, s64, s64); -bool trySavePrepoShineGetEvent(const char*, s32, s32, s32, s64, s64, s64); -bool trySavePrepoReceiveAchievement(const char* s32, s64, s64, s64); -bool trySavePrepoAchievementProgress(GameDataHolderAccessor, s64, s64, s64); -bool trySavePrepoGetCapEvent(const char*, s32, s64, s64, s64); -bool trySavePrepoGetClothEvent(const char*, s32, s64, s64, s64); -bool trySavePrepoGetGiftEvent(const char*, s32, s64, s64, s64); -bool trySavePrepoGetStickerEvent(const char*, s32, s64, s64, s64); -bool trySavePrepoChangeCapEvent(const char*, s64, s64, s64); -bool trySavePrepoChangeClothEvent(const char*, s64, s64, s64); -bool trySavePrepoFirstHackEvent(const char*, s32, s64, s64, s64); -bool trySavePrepoGetCollectBgmEvent(const char*, const char*, bool, s32, s64, s64, s64); -bool trySavePrepoSettingsState(bool, const char*, const GameConfigData&, s64, s64); -bool trySavePrepoSeparatePlayMode(bool, s64, s64, s64); +enum InOutType : s64 { InOutType_Start, InOutType_Exit, InOutType_Miss }; + +enum ItemCategoryType : s64 { + ItemCategoryType_Cap, + ItemCategoryType_Cloth, + ItemCategoryType_Gift, + ItemCategoryType_Sticker +}; + +bool trySavePrepoCompleteMainScenario(s32 worldId, s32 mainScenarioNo, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoStartStage(const char* stageName, const sead::Vector3f& position, s64 playTime, + s64 saveDataId, s64 acrossPlayTime); +bool trySavePrepoExitStage(const char* stageName, const sead::Vector3f& position, s64 playTime, + s64 saveDataId, s64 acrossPlayTime); +bool trySavePrepoMissEvent(const char* stageName, const sead::Vector3f& position, s64 playTime, + s64 saveDataId, s64 acrossPlayTime); +bool trySavePrepoShineGetEvent(const char* stageName, s32 shineId, s32 totalShineNum, + s32 totalShopShineNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoReceiveAchievement(const char* achievementName, s32 receivedNum, s64 playTime, + s64 saveDataId, s64 acrossPlayTime); +bool trySavePrepoAchievementProgress(GameDataHolderAccessor accessor, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoGetCapEvent(const char* itemName, s32 totalNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoGetClothEvent(const char* itemName, s32 totalNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoGetGiftEvent(const char* itemName, s32 totalNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoGetStickerEvent(const char* itemName, s32 totalNum, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoChangeCapEvent(const char* itemName, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoChangeClothEvent(const char* itemName, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoFirstHackEvent(const char* hackObjName, s32 totalHackedObjNum, s64 playTime, + s64 saveDataId, s64 acrossPlayTime); +bool trySavePrepoGetCollectBgmEvent(const char* bgmResourceName, const char* bgmSituationName, + bool isBailout, s32 collectedBgmNum, s64 playTime, + s64 saveDataId, s64 acrossPlayTime); +bool trySavePrepoSettingsState(bool isKidsMode, const char* language, + const GameConfigData& configData, s64 saveDataId, + s64 acrossPlayTime); +bool trySavePrepoSeparatePlayMode(bool isSeparatePlayMode, s64 playTime, s64 saveDataId, + s64 acrossPlayTime); namespace prepo { void enableIsSavePrepo(); void disableIsSavePrepo(); s64 generateSaveDataId(); -s32 calcPrepoHashCode(const char*); +u32 calcPrepoHashCode(const char* str); } // namespace prepo } // namespace rs