Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Box Expansion #102

Merged
merged 13 commits into from
Jun 11, 2024
7 changes: 5 additions & 2 deletions src/mod/externals/Dpr/UI/BoxListNavigate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ namespace Dpr::UI {
int32_t _arrayWidth;
int32_t _arrayHeight;
UnityEngine::UI::GridLayoutGroup::Object* _layout;


void* _leftTop;
void* _rightTop;
void* _leftBottom;
void* _rightBottom;
void* _NavigatorList_k__BackingField;
};
};
}
23 changes: 12 additions & 11 deletions src/mod/externals/Dpr/UI/BoxWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "BoxStatusPanel.h"
#include "BoxTray.h"
#include "externals/DG/Tweening/Tween.h"
#include "externals/System/Action.h"

namespace Dpr::UI {
struct BoxWindow : ILClass<BoxWindow> {
Expand Down Expand Up @@ -79,10 +80,10 @@ namespace Dpr::UI {
UnityEngine::Transform::Object* _effectRoot; // 0x200
int32_t _animStateIn; // 0x208
int32_t _animStateOut; // 0x20C
void* _controlType; // 0x210
void* _operationType; // 0x214
void* _displayMode; // 0x218
void* _statusType; // 0x21C
int32_t _controlType; // 0x210
int32_t _operationType; // 0x214
int32_t _displayMode; // 0x218
int32_t _statusType; // 0x21C
void* _battleTeam; // 0x220
BoxTray::Object* _boxTray; // 0x228
void* _navigator; // 0x230
Expand Down Expand Up @@ -110,17 +111,17 @@ namespace Dpr::UI {
void* _fromNavigators; // 0x2C0
void* _toNavigators; // 0x2C8
void* _existSwapIndexes; // 0x2D0
void* _searchType; // 0x2D8
int32_t _searchType; // 0x2D8
void* _searchData; // 0x2E0
bool _isDuckOn; // 0x2E8
void* _param; // 0x2F0
void* _selected; // 0x2F8
UnityEngine::Events::UnityAction::Object* _onSelected; // 0x300
UnityEngine::Events::UnityAction::Object* _onDecide; // 0x308
UnityEngine::Events::UnityAction::Object* _onConfirm; // 0x310
UnityEngine::Events::UnityAction::Object* _onComplete; // 0x318
UnityEngine::Events::UnityAction::Object* _onCancelSelect; // 0x320
void* _targetLangId; // 0x328
System::Action::Object* _onSelected; // 0x300
System::Action::Object* _onDecide; // 0x308
System::Action::Object* _onConfirm; // 0x310
System::Action::Object* _onComplete; // 0x318
System::Action::Object* _onCancelSelect; // 0x320
int32_t _targetLangId; // 0x328
UnityEngine::Coroutine::Object* _coOpen; // 0x330
UnityEngine::Coroutine::Object* _coClose; // 0x338
void* _modelView; // 0x340
Expand Down
4 changes: 2 additions & 2 deletions src/mod/externals/PlayerWork.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "externals/Pml/PokePara/SavePokeParty.h"
#include "externals/Pml/PokeParty.h"
#include "externals/ReBuffnameData.h"
#include "externals/SmartPoint/Components/PlayerPrefsProvider_PlayerWork_.h"
#include "externals/SmartPoint/Components/PlayerPrefsProvider.h"
#include "externals/System/Nullable.h"
#include "externals/System/Primitives.h"
#include "externals/System/String.h"
Expand Down Expand Up @@ -168,7 +168,7 @@ struct PlayerWork : ILClass<PlayerWork, 0x04c59b58> {

static_assert(offsetof(StaticFields, _SafariBallNum_k__BackingField) == 72);

struct Fields : SmartPoint::Components::PlayerPrefsProvider_PlayerWork_::Fields {
struct Fields : SmartPoint::Components::PlayerPrefsProvider<PlayerWork>::Fields {
PlayerWork::SaveData::Object _saveData;
int32_t _transitionZoneID;
int32_t _locatorIndex;
Expand Down
22 changes: 22 additions & 0 deletions src/mod/externals/SmartPoint/Components/PlayerPrefsProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "externals/il2cpp-api.h"

// Forward declaration to avoid circular dependencies
struct ViewerSettings;

namespace SmartPoint::Components {
template <typename T>
struct PlayerPrefsProvider : ILClass<T> {
struct Fields {
bool _loaded;
};

static inline StaticILMethod<0x04c90330, ViewerSettings>
VeryTwistedSpoon marked this conversation as resolved.
Show resolved Hide resolved
Method$SmartPoint_Components_PlayerPrefsProvider_PlayerWork_get_instance;

static inline typename T::Object* get_Instance(ILMethod<T>& method) {
return ILClass<T>::template external<typename T::Object*>(0x02324910, *method);
}
};
}

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion src/mod/externals/UnityEngine/UI/GridLayoutGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace UnityEngine::UI {
};

inline void set_cellSize(Vector2::Object value) {
VeryTwistedSpoon marked this conversation as resolved.
Show resolved Hide resolved
external<void>(0x024b7130, this, value);
Vector2::Fields valueProxy = { .x = value.fields.x, .y = value.fields.y };
external<void>(0x024b7130, this, valueProxy);
};
};
}
6 changes: 2 additions & 4 deletions src/mod/externals/ViewerSettings.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#pragma once

#include "il2cpp-api.h"
#include "externals/SmartPoint/Components/PlayerPrefsProvider_ViewerSettings_.h"
#include "UnityEngine/Color.h"
#include "System/String.h"

using namespace SmartPoint::Components;
#include "externals/SmartPoint/Components/PlayerPrefsProvider.h"

struct ViewerSettings : ILClass<ViewerSettings> {
struct Fields : PlayerPrefsProvider_ViewerSettings_::Fields {
struct Fields : SmartPoint::Components::PlayerPrefsProvider<ViewerSettings>::Fields {
float _cameraFov;
float _focalLength;
float _farDepth;
Expand Down
1 change: 0 additions & 1 deletion src/mod/features/save_data/box_expansion.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "exlaunch.hpp"
#include "save/save.h"
#include "logger/logger.h"
#include "externals/SmartPoint/Components/PlayerPrefsProvider_ViewerSettings_.h"
#include "externals/Dpr/UI/BoxListPanel.h"

/* Hooks */
Expand Down
10 changes: 0 additions & 10 deletions src/mod/save/data/box/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@

static const int64_t VANILLA_BOXSIZE = 40;
static const uint64_t INIT_WALLPAPER_OFFSET = 8;
static const nn::vector<const char*> boxDefaultStrings {
"Box 1", "Box 2", "Box 3", "Box 4", "Box 5", "Box 6", "Box 7", "Box 8", "Box 9", "Box 10",
"Box 11", "Box 12", "Box 13", "Box 14", "Box 15", "Box 16", "Box 17", "Box 18", "Box 19", "Box 20",
"Box 21", "Box 22", "Box 23", "Box 24", "Box 25", "Box 26", "Box 27", "Box 28", "Box 29", "Box 30",
"Box 31", "Box 32", "Box 33", "Box 34", "Box 35", "Box 36", "Box 37", "Box 38", "Box 39", "Box 40",
"Box 41", "Box 42", "Box 43", "Box 44", "Box 45", "Box 46", "Box 47", "Box 48", "Box 49", "Box 50",
"Box 51", "Box 52", "Box 53", "Box 54", "Box 55", "Box 56", "Box 57", "Box 58", "Box 59", "Box 60",
"Box 61", "Box 62", "Box 63", "Box 64", "Box 65", "Box 66", "Box 67", "Box 68", "Box 69", "Box 70",
"Box 71", "Box 72", "Box 73", "Box 74", "Box 75", "Box 76", "Box 77", "Box 78", "Box 79", "Box 80"
};

template <int32_t size>
struct BoxSaveData {
Expand Down
9 changes: 8 additions & 1 deletion src/mod/save/migration/vanilla_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ void migrateFromVanilla(PlayerWork::Object* playerWork) {

auto spfCls = Pml::PokePara::SerializedPokemonFull_array_TypeInfo();

const nn::vector<const char*> boxDefaultStrings {
"Box 41", "Box 42", "Box 43", "Box 44", "Box 45", "Box 46", "Box 47", "Box 48", "Box 49", "Box 50",
"Box 51", "Box 52", "Box 53", "Box 54", "Box 55", "Box 56", "Box 57", "Box 58", "Box 59", "Box 60",
"Box 61", "Box 62", "Box 63", "Box 64", "Box 65", "Box 66", "Box 67", "Box 68", "Box 69", "Box 70",
"Box 71", "Box 72", "Box 73", "Box 74", "Box 75", "Box 76", "Box 77", "Box 78", "Box 79", "Box 80"
};

// Initializes boxes 41-80, 1-40 are copied directly from Vanilla.
for (uint64_t i=VANILLA_BOXSIZE; i < BoxCount; i++) {
save->boxes.boxNames[i].fields.str = System::String::Create(boxDefaultStrings[i]);
save->boxes.boxNames[i].fields.str = System::String::Create(boxDefaultStrings[i-VANILLA_BOXSIZE]);
save->boxes.wallpapers[i] = save->boxes.wallpapers[i-VANILLA_BOXSIZE+INIT_WALLPAPER_OFFSET]; // Follows exact pattern of Vanilla 1-40
auto serializedPokemon = (Pml::PokePara::SerializedPokemonFull::Array*) system_array_new(spfCls, 30);
save->boxes.pokemonParams[i].fields.pokemonParam = serializedPokemon;
Expand Down
12 changes: 7 additions & 5 deletions src/mod/save/save_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "save/save.h"
#include "save/migration/save_migration.h"

#include "externals/ViewerSettings.h"
#include "externals/SmartPoint/Components/PlayerPrefsProvider.h"

static CustomSaveData* gCustomSaveData = nullptr;
static bool onLoadInjection; // Flag to ensure injection doesn't happen more than once.
static bool isBackup; // Stores backup status during initialization to pass into post-load PlayerWork injection.
static bool migrationRequired; // Controls where LoadBoxes() and LinkBoxes() are called.

using namespace SmartPoint::Components;

CustomSaveData* getCustomSaveData() {
if (gCustomSaveData == nullptr)
gCustomSaveData = (CustomSaveData*)nn_malloc(sizeof(CustomSaveData));
Expand Down Expand Up @@ -71,9 +72,10 @@ HOOK_DEFINE_TRAMPOLINE(PatchExistingSaveData__Load) {
};

void injectPlayerWork() {
auto method = PlayerPrefsProvider_PlayerWork_::
Method$SmartPoint_Components_PlayerPrefsProvider_PlayerWork_get_instance;
auto playerWork = (PlayerWork::Object*) PlayerPrefsProvider_ViewerSettings_::get_Instance(method);
auto method = SmartPoint::Components::PlayerPrefsProvider<PlayerWork>
::Method$SmartPoint_Components_PlayerPrefsProvider_PlayerWork_get_instance;
auto playerWork = (PlayerWork::Object*) SmartPoint::Components::PlayerPrefsProvider<ViewerSettings>
VeryTwistedSpoon marked this conversation as resolved.
Show resolved Hide resolved
::get_Instance(method);
loadBoxes(isBackup);
linkBoxes(playerWork);
onLoadInjection = true; // Safeguard to prevent further injection until game is relaunched.
Expand Down