Skip to content

Commit

Permalink
Make GameCube searcher better line up with generator
Browse files Browse the repository at this point in the history
Fixes #323
Fixes #324
  • Loading branch information
Admiral-Fish committed Aug 7, 2023
1 parent 53e84af commit 8afac47
Show file tree
Hide file tree
Showing 5 changed files with 748 additions and 1,358 deletions.
13 changes: 5 additions & 8 deletions Source/Core/Gen3/Generators/GameCubeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ std::vector<GeneratorState> GameCubeGenerator::generateColoShadow(u32 seed, cons
}
}

ability &= info->getAbility(0) != info->getAbility(1);

u32 pid = (high << 16) | low;
std::array<u8, 6> ivs;
ivs[0] = iv1 & 31;
Expand Down Expand Up @@ -251,16 +253,11 @@ std::vector<GeneratorState> GameCubeGenerator::generateGalesShadow(u32 seed, con
}
}

if (shadowTemplate->getType() == ShadowType::SecondShadow || shadowTemplate->getType() == ShadowType::Salamence)
// Check for shiny lock with unset
if ((shadowTemplate->getType() == ShadowType::SecondShadow || shadowTemplate->getType() == ShadowType::Salamence) && unset)
{
go.advance(5); // Set and Unset start the same

// Check for shiny lock with unset
if (unset)
while (isShiny(go.nextUShort(), go.nextUShort(), tsv))
{
while (isShiny(go.nextUShort(), go.nextUShort(), tsv))
{
}
}
}

Expand Down
80 changes: 64 additions & 16 deletions Source/Core/Gen3/ShadowLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static inline u32 getPIDForward(XDRNG &rng)

namespace ShadowLock
{
bool coloShadow(u32 seed, const ShadowTemplate *shadowTemplate)
bool coloShadow(u32 &seed, const ShadowTemplate *shadowTemplate)
{
XDRNGR backward(seed);
backward.advance(1);
Expand Down Expand Up @@ -91,10 +91,16 @@ namespace ShadowLock
}

// Check if we end on the same PID as first non-shadow going backwards
return pidOriginal == pid;
if (pidOriginal == pid)
{
seed = backward.advance(8);
return true;
}

return false;
}

bool ereader(u32 seed, u32 readerPID, const ShadowTemplate *shadowTemplate)
bool ereader(u32 &seed, u32 readerPID, const ShadowTemplate *shadowTemplate)
{
// Check if PID is even valid for E-Reader
// E-Reader have set nature/gender
Expand Down Expand Up @@ -136,10 +142,15 @@ namespace ShadowLock
}

// Checks if PID matches original
return pid == readerPID;
if (pid == readerPID)
{
seed = backward.advance(8);
return true;
}
return false;
}

bool firstShadowNormal(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate)
bool firstShadowNormal(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate)
{
XDRNGR backward(seed);
backward.advance(1);
Expand Down Expand Up @@ -184,10 +195,16 @@ namespace ShadowLock
}

// Check if we end on the same PID as first non-shadow going backwards
return pidOriginal == pid;
if (pidOriginal == pid)
{
seed = backward.advance(8);
return true;
}

return false;
}

bool firstShadowSet(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate)
bool firstShadowSet(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate)
{
XDRNGR backward(seed);
backward.advance(6);
Expand Down Expand Up @@ -232,10 +249,16 @@ namespace ShadowLock
}

// Check if we end on the same PID as first non-shadow going backwards
return pidOriginal == pid;
if (pidOriginal == pid)
{
seed = backward.advance(8);
return true;
}

return false;
}

bool firstShadowUnset(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate)
bool firstShadowUnset(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate)
{
XDRNGR backward(seed);
backward.advance(3);
Expand Down Expand Up @@ -291,21 +314,34 @@ namespace ShadowLock
}

// Check if we end on the same PID as first non-shadow going backwards
return pidOriginal == pid;
if (pidOriginal == pid)
{
seed = backward.advance(8);
return true;
}

return false;
}

bool salamenceSet(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate)
bool salamenceSet(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate)
{
XDRNGR backward(seed);
backward.advance(6);

// Build PID of non-shadow
u32 pid = getPIDBackward(backward);

return shadowTemplate->getLock(0).compare(pid) && !isShiny(pid, tsv);
// Backwards nature lock check
if (shadowTemplate->getLock(0).compare(pid) && !isShiny(pid, tsv))
{
seed = backward.advance(8);
return true;
}

return false;
}

bool salamenceUnset(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate)
bool salamenceUnset(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate)
{
XDRNGR backward(seed);
backward.advance(3);
Expand All @@ -325,10 +361,16 @@ namespace ShadowLock
u32 pid = getPIDBackward(backward);

// Backwards nature lock check
return shadowTemplate->getLock(0).compare(pid) && !isShiny(pid, tsv);
if (shadowTemplate->getLock(0).compare(pid) && !isShiny(pid, tsv))
{
seed = backward.advance(8);
return true;
}

return false;
}

bool singleNL(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate)
bool singleNL(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate)
{
XDRNGR backward(seed);
backward.advance(1);
Expand All @@ -337,6 +379,12 @@ namespace ShadowLock
u32 pid = getPIDBackward(backward);

// Backwards nature lock check
return shadowTemplate->getLock(0).compare(pid) && !isShiny(pid, tsv);
if (shadowTemplate->getLock(0).compare(pid) && !isShiny(pid, tsv))
{
seed = backward.advance(8);
return true;
}

return false;
}
}
16 changes: 8 additions & 8 deletions Source/Core/Gen3/ShadowLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace ShadowLock
* @return true Seed matches the lock criteria
* @return false Seed does not match the lock criteria
*/
bool coloShadow(u32 seed, const ShadowTemplate *shadowTemplate);
bool coloShadow(u32 &seed, const ShadowTemplate *shadowTemplate);

/**
* @brief Determines whether the \p seed matches the lock criteria for Colosseum E-Reader
Expand All @@ -54,7 +54,7 @@ namespace ShadowLock
* @return true Seed matches the lock criteria
* @return false Seed does not match the lock criteria
*/
bool ereader(u32 seed, u32 readerPID, const ShadowTemplate *shadowTemplate);
bool ereader(u32 &seed, u32 readerPID, const ShadowTemplate *shadowTemplate);

/**
* @brief firstShadowNormal
Expand All @@ -68,7 +68,7 @@ namespace ShadowLock
* @return true Seed matches the lock criteria
* @return false Seed does not match the lock criteria
*/
bool firstShadowNormal(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate);
bool firstShadowNormal(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate);

/**
* @brief firstShadowSet
Expand All @@ -80,7 +80,7 @@ namespace ShadowLock
* @return true Seed matches the lock criteria
* @return false Seed does not match the lock criteria
*/
bool firstShadowSet(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate);
bool firstShadowSet(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate);

/**
* @brief firstShadowUnset
Expand All @@ -92,7 +92,7 @@ namespace ShadowLock
* @return true Seed matches the lock criteria
* @return false Seed does not match the lock criteria
*/
bool firstShadowUnset(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate);
bool firstShadowUnset(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate);

/**
* @brief salamenceSet
Expand All @@ -104,7 +104,7 @@ namespace ShadowLock
* @return true Seed matches the lock criteria
* @return false Seed does not match the lock criteria
*/
bool salamenceSet(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate);
bool salamenceSet(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate);

/**
* @brief salamenceUnset
Expand All @@ -116,7 +116,7 @@ namespace ShadowLock
* @return true Seed matches the lock criteria
* @return false Seed does not match the lock criteria
*/
bool salamenceUnset(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate);
bool salamenceUnset(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate);

/**
* @brief singleNL
Expand All @@ -128,7 +128,7 @@ namespace ShadowLock
* @return true Seed matches the lock criteria
* @return false Seed does not match the lock criteria
*/
bool singleNL(u32 seed, u16 tsv, const ShadowTemplate *shadowTemplate);
bool singleNL(u32 &seed, u16 tsv, const ShadowTemplate *shadowTemplate);
};

#endif // SHADOWLOCK_HPP
Loading

0 comments on commit 8afac47

Please sign in to comment.