Skip to content

Commit

Permalink
fixes: make choice to load nand hacks in the menu, not the function
Browse files Browse the repository at this point in the history
  • Loading branch information
DacoTaco committed Jan 26, 2025
1 parent 0ce6736 commit 882526a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 34 deletions.
67 changes: 33 additions & 34 deletions src/priiloader/source/hacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
std::vector<system_hack> system_hacks;
std::vector<u8> states_hash;

u32 file_size = 0;
FILE* fat_file_handler = NULL;
s32 nand_file_handler = -1;

Expand Down Expand Up @@ -72,7 +71,7 @@ std::string trim(const std::string& str)

//we use our own GetLine instead of ifstream because ifstream would increase priiloader's size with 300KB...
//and eventhough not perfect, this works fine too
bool GetLine(bool reading_nand, std::string& line)
bool GetLine(bool reading_nand, std::string& line, u32 fileSize)
{
char* buf = NULL;
std::string read_line;
Expand Down Expand Up @@ -106,8 +105,8 @@ bool GetLine(bool reading_nand, std::string& line)

//read untill we have a newline or reach EOF
while (
file_pos < file_size &&
file_pos+read_cnt < file_size &&
file_pos < fileSize &&
file_pos+read_cnt < fileSize &&
strstr(buf, "\n") == NULL &&
strstr(buf, "\r") == NULL
)
Expand All @@ -117,7 +116,7 @@ bool GetLine(bool reading_nand, std::string& line)
throw "line to long";

u32 addr = read_cnt + (u32)buf;
u32 len = (file_pos+BLOCK_SIZE < file_size) ? BLOCK_SIZE : file_size-(file_pos+read_cnt);
u32 len = (file_pos+BLOCK_SIZE < fileSize) ? BLOCK_SIZE : fileSize-(file_pos+read_cnt);
s32 ret = 0;

if (reading_nand)
Expand Down Expand Up @@ -422,38 +421,38 @@ s8 LoadSystemHacks(StorageDevice source)
}

//read the hacks file size
if (source != StorageDevice::NAND)
STACK_ALIGN(fstats, status, sizeof(fstats), 32);
u32 fileSize = 0;
switch(source)
{
fat_file_handler = fopen(BuildPath("/apps/priiloader/hacks_hash.ini", source).c_str(),"rb");
if(!fat_file_handler)
{
gprintf("fopen error : %s", strerror(errno));
}
else
{
fseek( fat_file_handler, 0, SEEK_END );
file_size = ftell(fat_file_handler);
fseek( fat_file_handler, 0, SEEK_SET);
}
}

//no file opened from FAT device, so lets open the nand file
if (!fat_file_handler)
{
source = StorageDevice::NAND;
nand_file_handler = ISFS_Open("/title/00000001/00000002/data/hackshas.ini", 1);
if (nand_file_handler < 0)
{
gprintf("LoadHacks : hacks_hash.ini not on FAT or Nand. ISFS_Open error %d", nand_file_handler);
return 0;
}
case StorageDevice::Auto:
default:
fat_file_handler = fopen(BuildPath("/apps/priiloader/hacks_hash.ini", source).c_str(),"rb");
if(!fat_file_handler)
{
gprintf("fopen error : %s", strerror(errno));
}
else
{
fseek( fat_file_handler, 0, SEEK_END );
fileSize = ftell(fat_file_handler);
fseek( fat_file_handler, 0, SEEK_SET);
}
break;
case StorageDevice::NAND:
nand_file_handler = ISFS_Open("/title/00000001/00000002/data/hackshas.ini", 1);
if (nand_file_handler < 0)
{
gprintf("LoadHacks : hacks_hash.ini not on FAT or Nand. ISFS_Open error %d", nand_file_handler);
break;
}

STACK_ALIGN(fstats, status, sizeof(fstats), 32);
ISFS_GetFileStats(nand_file_handler, status);
file_size = status->file_length;
ISFS_GetFileStats(nand_file_handler, status);
fileSize = status->file_length;
break;
}

if (file_size == 0)
if (fileSize == 0)
{
if (source != StorageDevice::NAND)
gprintf("Error \"hacks_hash.ini\" is 0 byte!");
Expand All @@ -477,7 +476,7 @@ s8 LoadSystemHacks(StorageDevice source)
std::string line;
system_hack new_hack;

while (GetLine(source == StorageDevice::NAND, line))
while (GetLine(source == StorageDevice::NAND, line, fileSize))
{
//Specs of this loop/function :
// - read the line and put it in the correct part of the hack
Expand Down
14 changes: 14 additions & 0 deletions src/priiloader/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ void SysHackHashSettings( void )
s32 fd = 0;
bool redraw=true;
bool reload=true;
u8 mountedFlags = GetMountedFlags();
StorageDevice device = StorageDevice::Auto;
if (!HAS_SD_FLAG(mountedFlags) && !HAS_USB_FLAG(mountedFlags))
device = StorageDevice::NAND;

while(1)
{
Expand All @@ -140,6 +143,10 @@ void SysHackHashSettings( void )
ClearScreen();
PrintFormat(1, TEXT_OFFSET("Reloading Hacks..."), 208, "Reloading Hacks...");
sleep(1);
mountedFlags = GetMountedFlags();
device = StorageDevice::Auto;
if (!HAS_SD_FLAG(mountedFlags) && !HAS_USB_FLAG(mountedFlags))
device = StorageDevice::NAND;
reload = true;
min_pos = 0;
max_pos = 0;
Expand Down Expand Up @@ -196,6 +203,13 @@ void SysHackHashSettings( void )
reload = 1;
continue;
}
else if (device != StorageDevice::NAND)
{
device = StorageDevice::NAND;
gprintf("switching to NAND...");
reload = 1;
continue;
}

PrintFormat(1, TEXT_OFFSET("Couldn't find any hacks for"), 208, "Couldn't find any hacks for");
PrintFormat(1, TEXT_OFFSET("System Menu version:vxxx"), 228, "System Menu version:v%d", SysVersion);
Expand Down

0 comments on commit 882526a

Please sign in to comment.