Skip to content

Commit

Permalink
Shiny Charm JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltContainer committed Oct 10, 2023
1 parent 011647b commit 43c77ff
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/mod/features/shiny_rates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "externals/Pml/Local/RandomGenerator.h"
#include "externals/Pml/PokePara/CalcTool.h"
#include "externals/Pml/PokePara/InitialSpec.h"
#include "romdata/romdata.h"

uint32_t ShinyRolls(Pml::PokePara::InitialSpec::Object* pFixSpec, Pml::Local::RandomGenerator::Object* rng)
{
Expand All @@ -16,13 +17,13 @@ uint32_t ShinyRolls(Pml::PokePara::InitialSpec::Object* pFixSpec, Pml::Local::Ra
uint32_t id = pFixSpec->fields.id;

// Base rolls
rareTryCount += 8;
rareTryCount += GetShinyRates().baseRolls;

// Shiny charm rolls
Dpr::Item::ItemInfo::Object* item = ItemWork::GetItemInfo(array_index(ITEMS, "Shiny Charm"));
if (item != nullptr && item->get_count() > 0)
{
rareTryCount += 2;
rareTryCount += GetShinyRates().charmRolls;
}

for (uint32_t i=0; i<rareTryCount; i++)
Expand Down Expand Up @@ -59,6 +60,12 @@ HOOK_DEFINE_INLINE(Shiny_GetRand) {
}
};

HOOK_DEFINE_INLINE(Shiny_Masuda) {
static void Callback(exl::hook::nx64::InlineCtx* ctx) {
ctx->W[8] = GetShinyRates().masudaRolls;
}
};

void exl_shiny_rates_main() {
// != 0xffffffffffffffff
Shiny_GetValue::InstallAtOffset(0x0205393c);
Expand All @@ -80,13 +87,14 @@ void exl_shiny_rates_main() {
Shiny_GetValue::InstallAtOffset(0x02053a08);
Shiny_GetRand::InstallAtOffset(0x020539a0);

Shiny_Masuda::InstallAtOffset(0x02050874);

// Assembly Patches
using namespace exl::armv8::inst;
using namespace exl::armv8::reg;
exl::patch::CodePatcher p(0);
auto inst = nn::vector<exl::patch::Instruction> {
{ 0x02050880, AddImmediate(W9, W8, 0) }, // Remove shiny charm effect from egg-only methods
{ 0x02050874, Movz(W8, 6) }, // Change amount of masuda rolls for eggs (6 in vanilla)
};
p.WriteInst(inst);
}
31 changes: 31 additions & 0 deletions src/mod/romdata/data/ShinyRates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "externals/il2cpp-api.h"
#include "memory/json.h"
#include "memory/vector.h"

namespace RomData
{
struct ShinyRates
{
uint32_t baseRolls;
uint32_t charmRolls;
uint32_t masudaRolls;
};

JSON_TEMPLATE
void to_json(GENERIC_JSON& j, const ShinyRates& s) {
j = nn::json {
{"baseRolls", s.baseRolls},
{"charmRolls", s.charmRolls},
{"masudaRolls", s.masudaRolls},
};
}

JSON_TEMPLATE
void from_json(const GENERIC_JSON& j, ShinyRates& s) {
j.at("baseRolls").get_to(s.baseRolls);
j.at("charmRolls").get_to(s.charmRolls);
j.at("masudaRolls").get_to(s.masudaRolls);
}
}
6 changes: 5 additions & 1 deletion src/mod/romdata/romdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "romdata/data/ColorSet.h"
#include "romdata/data/FormHeldItemMon.h"
#include "romdata/data/HoneyTreeEncounters.h"
#include "romdata/data/ShinyRates.h"
#include "romdata/data/Starter.h"
#include "romdata/data/TMLearnset.h"
#include "romdata/data/UnbreakablePokeItem.h"
Expand Down Expand Up @@ -38,4 +39,7 @@ RomData::TMLearnset GetTMLearnset(int32_t monsno, int32_t formno);
bool CanLearnTM(int32_t monsno, int32_t formno, int32_t tm);

// Returns the starter data at the given index.
RomData::Starter GetStarter(int32_t index);
RomData::Starter GetStarter(int32_t index);

// Returns the shiny rates data.
RomData::ShinyRates GetShinyRates();
48 changes: 48 additions & 0 deletions src/mod/romdata/shiny_rates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "exlaunch.hpp"

#include "helpers.h"
#include "memory/json.h"
#include "memory/string.h"

#include "romdata/data/ShinyRates.h"

#include "logger/logger.h"

static RomData::ShinyRates shinyRatesData;
static bool isShinyRatesDataLoaded = false;

const char* shinyRatesFolderPath = "rom:/Data/ExtraData/ShinyRates/";

void LoadShinyRates()
{
nn::string filePath(shinyRatesFolderPath);
filePath.append("shiny_rates.json");
Logger::log("Checking Shiny Rates for %s!\n", filePath.c_str());

nn::json j = FsHelper::loadJsonFileFromPath(filePath.c_str());
if (j != nullptr && !j.is_discarded())
{
Logger::log("Parsed Shiny Rates for %s!\n", filePath.c_str());
shinyRatesData = j.get<RomData::ShinyRates>();
isShinyRatesDataLoaded = true;
}
else
{
Logger::log("Error when parsing Shiny Rates data!\n");
// Default - Lumi odds
shinyRatesData = {
.baseRolls = 8,
.charmRolls = 2,
.masudaRolls = 6,
};
isShinyRatesDataLoaded = true;
}
}

RomData::ShinyRates GetShinyRates()
{
if (!isShinyRatesDataLoaded)
LoadShinyRates();

return shinyRatesData;
}
2 changes: 1 addition & 1 deletion src/mod/romdata/starters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RomData::Starter GetStarter(int32_t index)
Logger::log("Error when parsing Starter data!\n");
}

// Default - No TMs learned
// Default - Oddish
return {
.monsNo = 43,
.formNo = 0,
Expand Down

0 comments on commit 43c77ff

Please sign in to comment.