Skip to content

Commit

Permalink
Merge pull request #50 from AnalogMan151/random-spawner
Browse files Browse the repository at this point in the history
New: Random Spawner, Shiny chance editor, bugfixes
  • Loading branch information
AnalogMan151 authored Jan 22, 2017
2 parents bf0d65a + 0a669e4 commit 0eff3e5
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 287 deletions.
131 changes: 71 additions & 60 deletions Sources/battle_modifiers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "cheats.h"
#include "hid.h"
#include "hook.h"

/********************************
* *
Expand All @@ -13,14 +12,14 @@
u32 o_noencounters = 0x0807A28C,
o_alwayscritical[2] = {0x0595AD0, 0x08085D1C},
o_showopponentinfo = 0x080AE178,
o_battlestats1 = 0x0029A048,
o_battlestats2 = 0x00595A00,
o_battlestats[2] = {0x00595A00, 0x0029A048},
o_shiny = 0x003183EC,
o_catch100 = 0x0048F1E0,
o_zmoves1 = 0x00595900,
o_zmoves2 = 0x00313DC0;
o_catch100 = 0x0803528C,
o_zmoves[2] = {0x00595900, 0x00313DC0},
o_infzmoves = 0x08031100;

u32 catch100_jump = 0;
int shinyChanceValue = 4096;

// Battle menu entry
void battleMenu(void) {
Expand All @@ -33,27 +32,29 @@ void battleMenu(void) {
o_alwayscritical[0] += 0x1F00;
o_alwayscritical[1] += 0x03BC;
o_showopponentinfo += 0x0480;
o_battlestats1 += 0x0120;
o_battlestats2 += 0x1F00;
o_battlestats[0] += 0x1F00;
o_battlestats[1] += 0x0120;
o_shiny += 0x0704;
o_catch100 += 0x1C60;
o_zmoves1 += 0x1F00;
o_zmoves2 += 0x0540;
o_catch100 -= 0x01D0;
o_zmoves[0] += 0x1F00;
o_zmoves[1] += 0x0540;
break;
}

// Creates spoiler and cheat entries

new_spoiler("Battle");
new_entry_managed_note("No Wild Encounters", "Hold START to temporarily enable encounters", noEncounters, NOENCOUNTERS, 0);
new_entry_arg("100% Capture Rate", catch100, 0, CATCH100, TOGGLE);
new_entry_arg("Wild Pokemon Shiny", shinyPokemon, 0, SHINYPOKEMON, TOGGLE);
new_entry("100% Capture Rate", catch100);
new_entry_managed("Shiny Chance: XXXXXX", decreaseShinyChance, DECREASESHINYCHANCE, AUTO_DISABLE);
new_entry_managed_note("View Opponent's Info", "Tap Opponent's icon on battle screen to see HP, Ability & Held Item", showOpponentInfo, SHOWOPPONENTINFO, 0);
// new_entry("Always Critical Hit", alwaysCritical);
new_entry_arg("Stat Stages +6", maxBattleStats, 0, MAXBATTLESTATS, TOGGLE);
new_entry_arg("Use Z-Moves w/o Z-Crystal", zMoves, 0, ZMOVES, TOGGLE);
new_entry("Infinite Z-Moves", infZMoves);
new_line();
exit_spoiler();
updateShiny();
}

// No wild encounters unless START is held
Expand Down Expand Up @@ -120,7 +121,7 @@ void maxBattleStats(u32 state) {
if (state) {

// Stores original value in memory
original = READU32(o_battlestats1);
original = READU32(o_battlestats[1]);

static const u8 buffer[] =
{
Expand Down Expand Up @@ -152,51 +153,63 @@ void maxBattleStats(u32 state) {
0xF8, 0x09, 0xF4, 0xEA, 0x80, 0x96
};

memcpy((void *)(o_battlestats2), buffer, 0x90);
memcpy((void *)(o_battlestats[0]), buffer, 0x90);
switch(gameVer) {
case 10:
memcpy((void *)(o_battlestats2 + 0x84), buffer10, 0x06);
WRITEU32(o_battlestats1, 0xEA0BEE6C);
memcpy((void *)(o_battlestats[0] + 0x84), buffer10, 0x06);
WRITEU32(o_battlestats[1], 0xEA0BEE6C);
break;
case 11:
memcpy((void *)(o_battlestats2 + 0x84), buffer11, 0x06);
WRITEU32(o_battlestats1, 0xEA0BF5E4);
memcpy((void *)(o_battlestats[0] + 0x84), buffer11, 0x06);
WRITEU32(o_battlestats[1], 0xEA0BF5E4);
break;
}
} else {

// Sets value back to original when cheat is disabled
WRITEU32(o_battlestats1, original);
WRITEU32(o_battlestats[1], original);
}
}


// 100% Catch rate for Pokemon
void hooked_catch100(void);
void catch100(u32 state) {
static t_hook hook = {0};
void catch100(void) {
if (!checkAddress(o_catch100))
return;
if (READU32(o_catch100) == 0x0A000004)
WRITEU32(o_catch100, 0xEA000004);
}

switch(gameVer) {
case 10:
catch100_jump = 0x006D839C;
break;
case 11:
catch100_jump = 0x006DA1CC;
break;
}
if (state) {
if (!hook.is_initialized)
init_hook(&hook, o_catch100, (u32)hooked_catch100);
enable_hook(&hook);
} else {
disable_hook(&hook);
}
//
void updateShiny(void) {
char buf[7];
xsprintf(buf, ": 1/%-4d", shinyChanceValue);
replace_pattern(": ******", (shinyChanceValue == 4096) ? ": Normal" : buf, DECREASESHINYCHANCE);
}


//
void decreaseShinyChance(void) {
if (shinyChanceValue == 4096)
shinyChanceValue = 1;
else
shinyChanceValue *= 2;
updateShiny();
}


// Make wild Pokemon shiny
void shinyPokemon(u32 state) {
WRITEU32(o_shiny, (state) ? 0xEA00001C : 0x0A00001C);
void shinyPokemon(void) {
if (shinyChanceValue == 4096) {
WRITEU32(o_shiny, 0x0A00001C);
return;
} else {
int r = randomNum(1, shinyChanceValue);
if (r == 1)
WRITEU32(o_shiny, 0xEA00001C);
else
WRITEU32(o_shiny, 0x0A00001C);
}
}


Expand All @@ -212,32 +225,32 @@ void zMoves(u32 state) {
0x00, 0x10, 0xA0, 0x11, 0x05, 0x80, 0xBD, 0xE8
};

memcpy((void *)(o_zmoves1), buffer, 0x28);
memcpy((void *)(o_zmoves[0]), buffer, 0x28);

switch(gameVer) {
case 10:
WRITEU32(o_zmoves1 + 0x28, 0x0078BA28);
WRITEU32(o_zmoves2 + 0x00, 0xEB0A06CE);
WRITEU32(o_zmoves2 + 0x70, 0xEB0A06B5);
WRITEU32(o_zmoves2 + 0x5932C, 0xE3A00001);
WRITEU32(o_zmoves[0] + 0x28, 0x0078BA28);
WRITEU32(o_zmoves[1] + 0x00, 0xEB0A06CE);
WRITEU32(o_zmoves[1] + 0x70, 0xEB0A06B5);
WRITEU32(o_zmoves[1] + 0x5932C, 0xE3A00001);
break;
case 11:
WRITEU32(o_zmoves1 + 0x28, 0x0078BF60);
WRITEU32(o_zmoves2 + 0x00, 0xEB0A0D3E);
WRITEU32(o_zmoves2 + 0x70, 0xEB0A0D25);
WRITEU32(o_zmoves2 + 0x59CF4, 0xE3A00001);
WRITEU32(o_zmoves[0] + 0x28, 0x0078BF60);
WRITEU32(o_zmoves[1] + 0x00, 0xEB0A0D3E);
WRITEU32(o_zmoves[1] + 0x70, 0xEB0A0D25);
WRITEU32(o_zmoves[1] + 0x59CF4, 0xE3A00001);
break;
}

} else {
WRITEU32(o_zmoves2 + 0x00, 0xE1D510B4);
WRITEU32(o_zmoves2 + 0x70, 0xE1D510B4);
WRITEU32(o_zmoves[1] + 0x00, 0xE1D510B4);
WRITEU32(o_zmoves[1] + 0x70, 0xE1D510B4);
switch(gameVer) {
case 10:
WRITEU32(o_zmoves2 + 0x5932C, 0xE3A00000);
WRITEU32(o_zmoves[1] + 0x5932C, 0xE3A00000);
break;
case 11:
WRITEU32(o_zmoves2 + 0x59CF4, 0xE3A00000);
WRITEU32(o_zmoves[1] + 0x59CF4, 0xE3A00000);
break;
}
}
Expand All @@ -246,15 +259,13 @@ void zMoves(u32 state) {

// Inifinite Z-Moves
void infZMoves(void) {
static u32 data = 0;

if (!checkAddress(0x080311DC))
if (!checkAddress(o_infzmoves + 0xDC))
return;
else {
if (READU32(0x80311DC) == 0xE320F000) {
WRITEU32(0x080311D4, 0xE3A00000);
WRITEU32(0x080311D8, 0xE5C30005);
WRITEU32(0x080311DC, 0xE1500000);
if (READU32(o_infzmoves + 0xDC) == 0xE320F000) {
WRITEU32(o_infzmoves + 0xD4, 0xE3A00000);
WRITEU32(o_infzmoves + 0xD8, 0xE5C30005);
WRITEU32(o_infzmoves + 0xDC, 0xE1500000);
}
}
}
16 changes: 13 additions & 3 deletions Sources/cheats.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ enum {
INCREASEID1,
INCREASEID10,
INCREASEID100,
RANDOMID,
INCREASELVL1,
INCREASELVL10,
PASSTHRULEVEL,
INCREASETIME,
DECREASETIME,
SETFORM,
Expand All @@ -63,7 +65,8 @@ enum {
CAMERAZOOM,
NOENCOUNTERS,
VIEWIVEV,
SHOWOPPONENTINFO
SHOWOPPONENTINFO,
DECREASESHINYCHANCE
} e_identifiers;

// Helpers
Expand All @@ -84,6 +87,7 @@ bool isinArray(int val, int *arr, int size);
void memset32(void *dst, unsigned int value, unsigned int size);
void protect_region(u32 addr);
bool checkAddress(u32 address);
int randomNum(int start, int end);

// Offsets
void getVersion(void);
Expand All @@ -94,9 +98,13 @@ void updateSpawn(void);
void increaseID1(void);
void increaseID10(void);
void increaseID100(void);
void randomID(u32 state);
void setRandomID(void);
void increaseLVL1(void);
void increaseLVL10(void);
void passthruLevel(u32 state);
void activateSpawn(u32 state);
void generateSpawn(void);
void getForms(u32 id);
void setForm(void);

Expand Down Expand Up @@ -132,8 +140,10 @@ void noEncounters(void);
void alwaysCritical(void);
void showOpponentInfo(void);
void maxBattleStats(u32 state);
void catch100(u32 state);
void shinyPokemon(u32 state);
void catch100(void);
void updateShiny(void);
void decreaseShinyChance(void);
void shinyPokemon(void);
void zMoves(u32 state);
void infZMoves(void);

Expand Down
15 changes: 7 additions & 8 deletions Sources/exp_multipliers.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
static char currentEXP[40] = "Undefined";
u8 exp_rate = 1;

u32 o_exp1 = 0x00595800,
o_exp2 = 0x0048F1EC;
u32 o_exp[2] = {0x00595800, 0x0048F1EC};

// EXP menu entry
void expMenu(void) {
Expand All @@ -22,8 +21,8 @@ void expMenu(void) {
case 10:
break;
case 11:
o_exp1 += 0x1F00;
o_exp2 += 0x1C60;
o_exp[0] += 0x1F00;
o_exp[1] += 0x1C60;
break;
}

Expand All @@ -49,14 +48,14 @@ void updateEXP(void) {
0x90, 0x01, 0x00, 0xE0,
0x02, 0x80, 0xBD, 0xE8
};
memcpy((void *)(o_exp1), buffer, 0x14);
WRITEU8(o_exp1 + 0x08, exp_rate);
memcpy((void *)(o_exp[0]), buffer, 0x14);
WRITEU8(o_exp[0] + 0x08, exp_rate);
switch(gameVer) {
case 10:
WRITEU32(o_exp2, 0xEB041983);
WRITEU32(o_exp[1], 0xEB041983);
break;
case 11:
WRITEU32(o_exp2, 0xEB041A2B);
WRITEU32(o_exp[1], 0xEB041A2B);
break;
}
xsprintf(currentEXP, "Current EXP rate: %3dx", exp_rate);
Expand Down
10 changes: 9 additions & 1 deletion Sources/helpers/helpers.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cheats.h"
#include "manager.h"
#include <stdlib.h>

t_entry_data g_entry_data[MAX_STORAGE] = {0};
int g_current_data_count = 0;
Expand Down Expand Up @@ -43,7 +44,14 @@ bool checkAddress(u32 address) {
return false;
}


int randomNum(int start, int end) {
srand(svcGetSystemTick());
int r[20];
for (int i = 0; i < 20; i++) {
r[i] = rand()%(end - start + 1) + start;
}
return r[rand()%20];
}

bool isinArray(int val, int *arr, int size) {
for (int i = 0; i < (size / 4); i++) {
Expand Down
48 changes: 0 additions & 48 deletions Sources/helpers/hook.c

This file was deleted.

Loading

0 comments on commit 0eff3e5

Please sign in to comment.