Skip to content

Commit

Permalink
Reworked the way to activate features
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltContainer committed Jan 16, 2024
1 parent c3e476f commit 917d9f1
Show file tree
Hide file tree
Showing 16 changed files with 486 additions and 111 deletions.
78 changes: 78 additions & 0 deletions src/mod/data/features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#pragma once

static constexpr const char* FEATURES[] = {
"Ability Changes",
"Alt Starters",
"Area/Zone Codes",
"Badge Check",
"New Poké Balls",
"Battle Escape Flag",
"Battle Revolver",
"Battle Camera Fix",
"Color Variations",
"Commands",
"Encounter Slots",
"EV/IV in Summary",
"Evolution Methods",
"Extended TM Learnsets",
"Form Change Held Items",
"Gender Neutral Boutique",
"Hidden Power UI",
"Language Select",
"Level Cap",
"NPC Collision Audio",
"Outfit Neutral UI",
"Party Context Menu",
"Poké Radar Fixes",
"Two-Button Pokétch",
"Relearn TMs",
"Controls Remap",
"New Settings",
"Shiny Rates",
"Sound Encounters",
"Swarm Forms",
"Turn Counter",
"Underground Forms",
"Wild Forms",
"Wild Held Item Rates",
};

constexpr int FEATURE_COUNT = sizeof(FEATURES) / sizeof(FEATURES[0]);

static constexpr const char* DEBUG_FEATURES[] = {
"Battle Bundles in UI",
"Boutique Models",
"IL2CPP Logging",
"PokemonInfo Logging",
"Unity Logging",
};

constexpr int DEBUG_FEATURE_COUNT = sizeof(DEBUG_FEATURES) / sizeof(DEBUG_FEATURES[0]);

static constexpr const char* ITEM_FEATURES[] = {
"Ability Patch",
"Everlasting Candies",
"Exp. Share",
"Infinite TMs",
"Leek",
"Infinite Repel",
};

constexpr int ITEM_FEATURE_COUNT = sizeof(ITEM_FEATURES) / sizeof(ITEM_FEATURES[0]);

static constexpr const char* KEY_ITEM_FEATURES[] = {
"Clothing Trunk",
"Incense Burner",
"Infinite Repel",
};

constexpr int KEY_ITEM_FEATURE_COUNT = sizeof(KEY_ITEM_FEATURES) / sizeof(KEY_ITEM_FEATURES[0]);


static constexpr const char* SMALL_PATCH_FEATURES[] = {
"Affection Toggle",
"Global Exp. Share Toggle",
"Catch Rate Fix",
};

constexpr int SMALL_PATCH_FEATURE_COUNT = sizeof(SMALL_PATCH_FEATURES) / sizeof(SMALL_PATCH_FEATURES[0]);
2 changes: 2 additions & 0 deletions src/mod/data/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <cstdint>
#include <array>
#include <string_view>
#include "common.hpp"

template <int N>
consteval bool array_contains(const char* const (&arr)[N], const char* element) {
Expand Down
4 changes: 4 additions & 0 deletions src/mod/externals/ItemWork.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ struct ItemWork : ILClass<ItemWork> {
static inline Dpr::Item::ItemInfo::Object* GetItemInfo(int32_t itemno) {
return external<Dpr::Item::ItemInfo::Object*>(0x01aea5b0, itemno);
}

static inline bool IsWazaMachine(int32_t itemno) {
return external<bool>(0x01aeb380, itemno);
}
};
89 changes: 89 additions & 0 deletions src/mod/features/activated_features.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "features/activated_features.h"

#include "data/features.h"

static bool ACTIVATED_FEATURES[FEATURE_COUNT];
static bool ACTIVATED_DEBUG_FEATURES[DEBUG_FEATURE_COUNT];
static bool ACTIVATED_ITEM_FEATURES[ITEM_FEATURE_COUNT];
static bool ACTIVATED_KEY_ITEM_FEATURES[KEY_ITEM_FEATURE_COUNT];
static bool ACTIVATED_SMALL_PATCH_FEATURES[SMALL_PATCH_FEATURE_COUNT];

void DisableFeatures()
{
for (bool & i : ACTIVATED_FEATURES)
i = false;
}

void DisableDebugFeatures()
{
for (bool & i : ACTIVATED_DEBUG_FEATURES)
i = false;
}

void DisableItemFeatures()
{
for (bool & i : ACTIVATED_ITEM_FEATURES)
i = false;
}

void DisableKeyItemFeatures()
{
for (bool & i : ACTIVATED_KEY_ITEM_FEATURES)
i = false;
}

void DisableSmallPatchFeatures()
{
for (bool & i : ACTIVATED_SMALL_PATCH_FEATURES)
i = false;
}

void SetActivatedFeature(int feature)
{
ACTIVATED_FEATURES[feature] = true;
}

void SetActivatedDebugFeature(int feature)
{
ACTIVATED_DEBUG_FEATURES[feature] = true;
}

void SetActivatedItemFeature(int feature)
{
ACTIVATED_ITEM_FEATURES[feature] = true;
}

void SetActivatedKeyItemFeature(int feature)
{
ACTIVATED_KEY_ITEM_FEATURES[feature] = true;
}

void SetActivatedSmallPatchFeature(int feature)
{
ACTIVATED_SMALL_PATCH_FEATURES[feature] = true;
}

bool IsActivatedFeature(int feature)
{
return ACTIVATED_FEATURES[feature];
}

bool IsActivatedDebugFeature(int feature)
{
return ACTIVATED_DEBUG_FEATURES[feature];
}

bool IsActivatedItemFeature(int feature)
{
return ACTIVATED_ITEM_FEATURES[feature];
}

bool IsActivatedKeyItemFeature(int feature)
{
return ACTIVATED_KEY_ITEM_FEATURES[feature];
}

bool IsActivatedSmallPatchFeature(int feature)
{
return ACTIVATED_SMALL_PATCH_FEATURES[feature];
}
48 changes: 48 additions & 0 deletions src/mod/features/activated_features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

// Disables all features.
void DisableFeatures();

// Disables all debug features.
void DisableDebugFeatures();

// Disables all items.
void DisableItemFeatures();

// Disables all key items.
void DisableKeyItemFeatures();

// Disables all small patches.
void DisableSmallPatchFeatures();


// Activate a given feature.
void SetActivatedFeature(int feature);

// Activate a given debug feature.
void SetActivatedDebugFeature(int feature);

// Activate a given item.
void SetActivatedItemFeature(int feature);

// Activate a given key item.
void SetActivatedKeyItemFeature(int feature);

// Activate a given small patch.
void SetActivatedSmallPatchFeature(int feature);


// Check if a given feature is enabled.
bool IsActivatedFeature(int feature);

// Check if a given debug feature is enabled.
bool IsActivatedDebugFeature(int feature);

// Check if a given item is enabled.
bool IsActivatedItemFeature(int feature);

// Check if a given key item is enabled.
bool IsActivatedKeyItemFeature(int feature);

// Check if a given small patch is enabled.
bool IsActivatedSmallPatchFeature(int feature);
19 changes: 14 additions & 5 deletions src/mod/features/debug.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#include "data/features.h"
#include "data/utils.h"

#include "features/activated_features.h"
#include "features/debug/debug.h"

void exl_debug_features_main() {
exl_battle_bundles_in_ui_main();
exl_boutique_model_main();
//exl_il2cpp_log_main();
exl_pokemoninfo_hooks_main();
//exl_unity_log_main();
if (IsActivatedDebugFeature(array_index(DEBUG_FEATURES, "Battle Bundles in UI")))
exl_battle_bundles_in_ui_main();
if (IsActivatedDebugFeature(array_index(DEBUG_FEATURES, "Boutique Models")))
exl_boutique_model_main();
if (IsActivatedDebugFeature(array_index(DEBUG_FEATURES, "IL2CPP Logging")))
exl_il2cpp_log_main();
if (IsActivatedDebugFeature(array_index(DEBUG_FEATURES, "PokemonInfo Logging")))
exl_pokemoninfo_hooks_main();
if (IsActivatedDebugFeature(array_index(DEBUG_FEATURES, "Unity Logging")))
exl_unity_log_main();
};
15 changes: 3 additions & 12 deletions src/mod/features/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void exl_battle_escape_flag_main();
// Makes the battle menu scroll instead of the cursor.
void exl_battle_revolver_main();

// Forces battle camera transition direct from Wait camera to Attack camera
// Removes the automatic switch to the default battle camera on certain actions.
void exl_battle_camera_fix_main();

// Adds support for custom color variations for player and NPCs.
Expand All @@ -42,15 +42,12 @@ void exl_debug_features_main();
// Defaults to changing slots how Luminescent does it.
void exl_encounter_slots_main();

// Adds EV/IV to Summary UI with number based color gradient
// Adds EV/IV to Summary UI with number based color gradient.
void exl_ev_iv_ui_main();

// Rewrites the methods that deal with checking level up evolution methods.
// Rewrites the methods that deal with checking level up evolution methods and adds new ones.
void exl_evolution_methods_main();

// Adds functionality to the Exp. Share item.
void exl_exp_share_main();

// Redirects TM learnsets to external JSON files that contain more data.
void exl_extended_tm_learnsets_main();

Expand Down Expand Up @@ -101,9 +98,6 @@ void exl_relearn_tms_main();
// Remaps the controls.
void exl_remap_main();

// Adds support for integration between the Infinite Repel and normal repels.
void exl_repel_fix_main();

// Applies patches to support the expansion of many things in the save data.
void exl_save_data_expansion();

Expand All @@ -119,9 +113,6 @@ void exl_sounds_main();
// Adds support for alternate forms for the field swarm models.
void exl_swarm_forms_main();

// Makes TMs infinite use.
void exl_tms_main();

// Assigns a work value to be used as a total turn counter for the last battle. By default, this is work value 449.
void exl_turn_counter_main();

Expand Down
17 changes: 5 additions & 12 deletions src/mod/features/infinite_tms.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#include "exlaunch.hpp"
#include "externals/Dpr/UI/UIBag.h"

HOOK_DEFINE_REPLACE(SkipTMBreak) {
HOOK_DEFINE_REPLACE(UseWazaMachine_SkipTMBreak) {
static void Callback(Dpr::UI::UIBag::__c__DisplayClass134_0* __this) {
// Return to UseWazaMachine proc
// Skip the text that mentions single-use TMs
__this->_UseWazaMachine_b__3(0);
}
};

HOOK_DEFINE_REPLACE(DoNothing) {
static void Callback() { }
};

void exl_tms_main() {
SkipTMBreak::InstallAtOffset(0x01be0d40);

DoNothing::InstallAtOffset(0x01be1220); // Dpr.UI.UIBag.<>c__DisplayClass134_0$$<UseWazaMachine>b__5
DoNothing::InstallAtOffset(0x01be1460); // Dpr.UI.UIBag.<>c__DisplayClass134_0$$<UseWazaMachine>b__6
void exl_items_infinite_tms_main() {
UseWazaMachine_SkipTMBreak::InstallAtOffset(0x01be0d40);

// Skip closing of text popup for reusing
// Skip Dpr.UI.UIMsgWindowController$$CloseMsgWindow call in _UseWazaMachine_b__3
exl::patch::CodePatcher p(0x01be0fec);
p.WriteInst(exl::armv8::inst::Nop());
}
47 changes: 44 additions & 3 deletions src/mod/features/items.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
#include "externals/ItemWork.h"

#include "data/features.h"
#include "data/items.h"
#include "data/utils.h"

#include "features/activated_features.h"
#include "features/items/items.h"

HOOK_DEFINE_INLINE(Infinite_Items) {
static void Callback(exl::hook::nx64::InlineCtx* ctx) {
auto itemno = (int32_t)ctx->W[0];
auto num = (int32_t)ctx->W[1];

if (IsActivatedItemFeature(array_index(ITEM_FEATURES, "Everlasting Candies"))) {
if (itemno == array_index(ITEMS, "Everlasting Candy")) {
ctx->W[0] = 0;
return;
}
}

if (IsActivatedItemFeature(array_index(ITEM_FEATURES, "Infinite TMs"))) {
if (ItemWork::IsWazaMachine(itemno)) {
ctx->W[0] = 0;
return;
}
}

ctx->W[0] = (uint32_t)ItemWork::SubItem(itemno, num);
}
};

void exl_items_changes_main() {
exl_items_ability_patch_main();
exl_items_everlasting_candies_main();
exl_items_leek_main();
if (IsActivatedItemFeature(array_index(ITEM_FEATURES, "Ability Patch")))
exl_items_ability_patch_main();
if (IsActivatedItemFeature(array_index(ITEM_FEATURES, "Everlasting Candies")))
exl_items_everlasting_candies_main();
if (IsActivatedItemFeature(array_index(ITEM_FEATURES, "Exp. Share")))
exl_items_exp_share_main();
if (IsActivatedItemFeature(array_index(ITEM_FEATURES, "Infinite TMs")))
exl_items_infinite_tms_main();
if (IsActivatedItemFeature(array_index(ITEM_FEATURES, "Leek")))
exl_items_leek_main();
if (IsActivatedItemFeature(array_index(ITEM_FEATURES, "Infinite Repel")))
exl_items_repel_main();

Infinite_Items::InstallAtOffset(0x0185eb8c);
};
Loading

0 comments on commit 917d9f1

Please sign in to comment.