mirror of
https://github.com/risingPhil/PokeMe64.git
synced 2026-04-24 23:17:12 -05:00
Various changes
- Upgrade libpokemegb to commit c47f8b3 - [Korean gen II games]: Make the UI show Trainer and Pokémon instead of the actual trainer name and pokémon name. This is needed because our font does not include the necessary characters for the Korean games. And while I could attempt to add them, I don't sufficiently care to do so. - Attempt to randomize random values. This is needed for random IVs and shininess chances. It's not entirely clear to me whether the rand() function would actually return random values in previous versions of PokeMe64. While libdragon does gather entropy at bootup and implements a getentropy() function, I don't see this function referenced anywhere. That being said, it DOES look like libstdc++ would call a getentropy() function, so perhaps this is a way in which getentropy() from libdragon would get called. But I'm not using libstdc++'s functionality to obtain random values, I'm using libc's rand() function. And I don't see any reference from libc (for rand()) to getentropy(), so... At the very least we might need to use values from getentropy() to seed with srand(). But because I have trust issues with randomizing pseudo-random values in a system that doesn't have a system clock, I also added trainerID, trainerName and the number of elapsed cpu cycles until we are going to the main menu to the seed. I might consider adding the RTC values for gen II games to the seed as well later.
This commit is contained in:
parent
87c59c8279
commit
c0638e8d69
|
|
@ -38,6 +38,8 @@ private:
|
|||
DialogData diagData_;
|
||||
TextRenderSettings pokeMe64TextSettings_;
|
||||
const char* gameTypeString_;
|
||||
// build up a random seed for srand(). I'm doing this in an attempt to truly randomize IVs and shininess.
|
||||
unsigned int randomSeed_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit d6f34233dbc67c4b486b43afbaa810e2a2a4006c
|
||||
Subproject commit c47f8b3d661404c09837c25db0b5c919d39ac476
|
||||
|
|
@ -8,8 +8,11 @@
|
|||
#include "gen2/Gen2GameReader.h"
|
||||
#include "menu/MenuEntries.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
static const Rectangle tpakDetectWidgetBounds = {60, 44, 200, 116};
|
||||
|
||||
|
||||
static void dialogFinishedCallback(void* context)
|
||||
{
|
||||
InitTransferPakScene* scene = (InitTransferPakScene*)context;
|
||||
|
|
@ -41,6 +44,7 @@ InitTransferPakScene::~InitTransferPakScene()
|
|||
|
||||
void InitTransferPakScene::init()
|
||||
{
|
||||
uint8_t systemEntropy[4];
|
||||
menu9SliceSprite_ = sprite_load("rom://menu-bg-9slice.sprite");
|
||||
|
||||
SceneWithDialogWidget::init();
|
||||
|
|
@ -53,6 +57,14 @@ void InitTransferPakScene::init()
|
|||
.fontStyleId = fontStyleWhiteId_,
|
||||
.halign = ALIGN_CENTER
|
||||
};
|
||||
|
||||
// add some entropy for our rand() function.
|
||||
// we'll apply this later. Right before we go to the main menu.
|
||||
getentropy(systemEntropy, sizeof(systemEntropy));
|
||||
for(uint8_t i=0; i < sizeof(systemEntropy); ++i)
|
||||
{
|
||||
randomSeed_ += static_cast<unsigned int>(systemEntropy[i]) << (i * 8);
|
||||
}
|
||||
}
|
||||
|
||||
void InitTransferPakScene::destroy()
|
||||
|
|
@ -124,6 +136,11 @@ void InitTransferPakScene::onDialogDone()
|
|||
return;
|
||||
}
|
||||
|
||||
// add the number of ticks it took before we got to this point to our random seed
|
||||
randomSeed_ += static_cast<uint32_t>(get_ticks());
|
||||
// Now apply random seed to srand() before we get to the main menu.
|
||||
srand(randomSeed_);
|
||||
|
||||
deps_.sceneManager.switchScene(SceneType::MENU, deleteMenuSceneContext, menuContext);
|
||||
}
|
||||
|
||||
|
|
@ -266,6 +283,7 @@ void InitTransferPakScene::loadSaveMetadata()
|
|||
TransferPakSaveManager saveManager(deps_.tpakManager);
|
||||
Gen1GameType gen1Type;
|
||||
Gen2GameType gen2Type;
|
||||
uint16_t trainerID = 0;
|
||||
|
||||
tpakDetectWidget_.retrieveGameType(gen1Type, gen2Type);
|
||||
|
||||
|
|
@ -275,6 +293,7 @@ void InitTransferPakScene::loadSaveMetadata()
|
|||
|
||||
Gen1GameReader gameReader(romReader, saveManager, gen1Type, language);
|
||||
const char* trainerName = gameReader.getTrainerName();
|
||||
trainerID = gameReader.getTrainerID();
|
||||
deps_.localization = static_cast<uint8_t>(language);
|
||||
strncpy(deps_.playerName, trainerName, sizeof(deps_.playerName) - 1);
|
||||
}
|
||||
|
|
@ -284,7 +303,23 @@ void InitTransferPakScene::loadSaveMetadata()
|
|||
|
||||
Gen2GameReader gameReader(romReader, saveManager, gen2Type, language);
|
||||
const char* trainerName = gameReader.getTrainerName();
|
||||
trainerID = gameReader.getTrainerID();
|
||||
deps_.localization = static_cast<uint8_t>(language);
|
||||
strncpy(deps_.playerName, trainerName, sizeof(deps_.playerName) - 1);
|
||||
if(language != Gen2LocalizationLanguage::KOREAN)
|
||||
{
|
||||
strncpy(deps_.playerName, trainerName, sizeof(deps_.playerName) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char fakePlayerName[] = "Trainer";
|
||||
memcpy(deps_.playerName, fakePlayerName, sizeof(fakePlayerName));
|
||||
}
|
||||
}
|
||||
|
||||
// add to our random seed to make sure our random numbers will be randomized.
|
||||
randomSeed_ += trainerID;
|
||||
for(uint8_t i=0; i < strlen(deps_.playerName); ++i)
|
||||
{
|
||||
randomSeed_ += deps_.playerName[i];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ void StatsScene::init()
|
|||
move2Str = getMoveString(static_cast<Move>(context_->poke_g2.index_move2));
|
||||
move3Str = getMoveString(static_cast<Move>(context_->poke_g2.index_move3));
|
||||
move4Str = getMoveString(static_cast<Move>(context_->poke_g2.index_move4));
|
||||
pokeName = gen2GameReader_.getPokemonName(pokeIndex);
|
||||
pokeName = (deps_.localization != (uint8_t)Gen2LocalizationLanguage::KOREAN) ? gen2GameReader_.getPokemonName(pokeIndex) : "Pokémon";
|
||||
shiny = gen2_isPokemonShiny(context_->poke_g2);
|
||||
snprintf(pokeStatsString_, sizeof(pokeStatsString_), "ATK: %u\nDEF: %u\nSPEC. ATK: %u\nSPEC. DEF: %u\nSPEED: %u", atk, def, specAtk, specDef, speed);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user