Skip to content

Commit

Permalink
Merge pull request #481 from KrahJohlito/miniOPL
Browse files Browse the repository at this point in the history
Parse launch args to auto boot games from HDDOSD
  • Loading branch information
AKuHAK authored Aug 8, 2021
2 parents 823472d + 5c8543f commit 17c3a5c
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 27 deletions.
3 changes: 1 addition & 2 deletions include/hddsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ int hddDeleteHDLGame(hdl_game_info_t *ginfo);
void hddInit();
item_list_t *hddGetObject(int initOnly);
void hddLoadModules(void);

extern char gOPLPart[128];
void hddLaunchGame(int id, config_set_t *configSet);

#endif
7 changes: 6 additions & 1 deletion include/opl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <ps2smb.h>
#include "config.h"

#include "include/hddsupport.h"

// Last Played Auto Start
#include <time.h>

Expand Down Expand Up @@ -167,7 +169,6 @@ extern int gDefaultDevice;

extern int gEnableWrite;

extern char *gHDDPrefix;
// These prefixes are relative to the device's name (meaning that they do not include the device name).
extern char gBDMPrefix[32];
extern char gETHPrefix[32];
Expand All @@ -185,6 +186,10 @@ extern unsigned char gDefaultTextColor[3];
extern unsigned char gDefaultSelTextColor[3];
extern unsigned char gDefaultUITextColor[3];

extern hdl_game_info_t *gAutoLaunchGame;
extern char *gHDDPrefix;
extern char gOPLPart[128];

void setDefaultColors(void);

#define MENU_ITEM_HEIGHT 19
Expand Down
77 changes: 55 additions & 22 deletions src/hddsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "include/cheatman.h"
#include "modules/iopcore/common/cdvd_config.h"

#ifdef PADEMU
#include <libds34bt.h>
#include <libds34usb.h>
#endif

#define NEWLIB_PORT_AWARE
#include <fileXio_rpc.h> // fileXioFormat, fileXioMount, fileXioUmount, fileXioDevctl
#include <io_common.h> // FIO_MT_RDWR
Expand All @@ -28,8 +33,6 @@ static unsigned char hddModulesLoaded = 0;
static char *hddPrefix = "pfs0:";
static hdl_games_list_t hddGames;

char gOPLPart[128];

// forward declaration
static item_list_t hddGameList;

Expand Down Expand Up @@ -128,7 +131,6 @@ static void hddFindOPLPartition(void)
configFree(config);
close(fd);

fileXioUmount(hddPrefix);
return;
}

Expand All @@ -148,7 +150,6 @@ static void hddFindOPLPartition(void)
}

snprintf(gOPLPart, sizeof(gOPLPart), "hdd0:+OPL");
fileXioUmount(hddPrefix);

return;
}
Expand Down Expand Up @@ -228,7 +229,10 @@ void hddLoadModules(void)

LOG("HDDSUPPORT modules loaded\n");

hddFindOPLPartition();
if (gOPLPart[0] == '\0')
hddFindOPLPartition();

fileXioUmount(hddPrefix);

ret = fileXioMount(hddPrefix, gOPLPart, FIO_MT_RDWR);
if (ret == -ENOENT) {
Expand Down Expand Up @@ -326,16 +330,21 @@ static void hddRenameGame(int id, char *newName)
hddForceUpdate = 1;
}

static void hddLaunchGame(int id, config_set_t *configSet)
void hddLaunchGame(int id, config_set_t *configSet)
{
int i, size_irx = 0;
int EnablePS2Logo = 0;
int result;
void **irx = NULL;
char filename[32];
hdl_game_info_t *game = &hddGames.games[id];
hdl_game_info_t *game;
struct cdvdman_settings_hdd *settings;

if (gAutoLaunchGame == NULL)
game = &hddGames.games[id];
else
game = gAutoLaunchGame;

apa_sub_t parts[APA_MAXSUB + 1];
char vmc_name[2][32];
int part_valid = 0, size_mcemu_irx = 0, nparts;
Expand Down Expand Up @@ -395,13 +404,16 @@ static void hddLaunchGame(int id, config_set_t *configSet)
}

if (have_error) {
char error[256];
if (have_error == 2) // VMC file is fragmented
snprintf(error, sizeof(error), _l(_STR_ERR_VMC_FRAGMENTED_CONTINUE), vmc_name[vmc_id], (vmc_id + 1));
else
snprintf(error, sizeof(error), _l(_STR_ERR_VMC_CONTINUE), vmc_name[vmc_id], (vmc_id + 1));
if (!guiMsgBox(error, 1, NULL))
return;
if (gAutoLaunchGame == NULL) {
char error[256];
if (have_error == 2) // VMC file is fragmented
snprintf(error, sizeof(error), _l(_STR_ERR_VMC_FRAGMENTED_CONTINUE), vmc_name[vmc_id], (vmc_id + 1));
else
snprintf(error, sizeof(error), _l(_STR_ERR_VMC_CONTINUE), vmc_name[vmc_id], (vmc_id + 1));
if (!guiMsgBox(error, 1, NULL))
return;
} else
LOG("VMC error\n");
}

for (i = 0; i < size_hdd_mcemu_irx; i++) {
Expand Down Expand Up @@ -448,13 +460,16 @@ static void hddLaunchGame(int id, config_set_t *configSet)
sbPrepare(NULL, configSet, size_irx, irx, &i);

if ((result = sbLoadCheats(gHDDPrefix, game->startup)) < 0) {
switch (result) {
case -ENOENT:
guiWarning(_l(_STR_NO_CHEATS_FOUND), 10);
break;
default:
guiWarning(_l(_STR_ERR_CHEATS_LOAD_FAILED), 10);
}
if (gAutoLaunchGame == NULL) {
switch (result) {
case -ENOENT:
guiWarning(_l(_STR_NO_CHEATS_FOUND), 10);
break;
default:
guiWarning(_l(_STR_ERR_CHEATS_LOAD_FAILED), 10);
}
} else
LOG("Cheats error\n");
}

settings = (struct cdvdman_settings_hdd *)((u8 *)irx + i);
Expand All @@ -471,7 +486,25 @@ static void hddLaunchGame(int id, config_set_t *configSet)
if (gPS2Logo)
EnablePS2Logo = CheckPS2Logo(0, game->start_sector + OPL_HDD_MODE_PS2LOGO_OFFSET);

deinit(NO_EXCEPTION, HDD_MODE); // CAREFUL: deinit will call hddCleanUp, so hddGames/game will be freed
if (gAutoLaunchGame == NULL) {
deinit(NO_EXCEPTION, HDD_MODE); // CAREFUL: deinit will call hddCleanUp, so hddGames/game will be freed
} else {
ioBlockOps(1);
#ifdef PADEMU
ds34usb_reset();
ds34bt_reset();
#endif
configFree(configSet);

free(gAutoLaunchGame);
gAutoLaunchGame = NULL;

fileXioUmount("pfs0:");
fileXioDevctl("pfs:", PDIOC_CLOSEALL, NULL, 0, NULL, 0);

ioEnd();
configEnd();
}

sysLaunchLoaderElf(filename, "HDD_MODE", size_irx, irx, size_mcemu_irx, &hdd_mcemu_irx, EnablePS2Logo, compatMode);
}
Expand Down
67 changes: 65 additions & 2 deletions src/opl.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ static opl_io_module_t list_support[MODE_COUNT];

// Global data
char *gBaseMCDir;
char *gHDDPrefix;
int ps2_ip_use_dhcp;
int ps2_ip[4];
int ps2_netmask[4];
Expand Down Expand Up @@ -189,6 +188,9 @@ unsigned char gDefaultBgColor[3];
unsigned char gDefaultTextColor[3];
unsigned char gDefaultSelTextColor[3];
unsigned char gDefaultUITextColor[3];
hdl_game_info_t *gAutoLaunchGame;
char gOPLPart[128];
char *gHDDPrefix;

void moduleUpdateMenu(int mode, int themeChanged, int langChanged)
{
Expand Down Expand Up @@ -1534,8 +1536,10 @@ static void setDefaults(void)
clearIOModuleT(&list_support[HDD_MODE]);
clearIOModuleT(&list_support[APP_MODE]);

gBaseMCDir = "mc?:OPL";
gAutoLaunchGame = NULL;
gOPLPart[0] = '\0';
gHDDPrefix = "pfs0:";
gBaseMCDir = "mc?:OPL";

ps2_ip_use_dhcp = 1;
gETHOpMode = ETH_OP_MODE_AUTO;
Expand Down Expand Up @@ -1671,6 +1675,54 @@ static void deferredAudioInit(void)
LOG("sfxInit: %d samples loaded.\n", ret);
}

static void autoLaunchHDDGame(char *argv[])
{
int ret;
char path[256];
config_set_t *configSet;

setDefaults();

gAutoLaunchGame = malloc(sizeof(hdl_game_info_t));
if (gAutoLaunchGame == NULL) {
PREINIT_LOG("Failed to allocate memory. Loading GUI\n");
return;
}

memset(gAutoLaunchGame, 0, sizeof(hdl_game_info_t));

snprintf(gAutoLaunchGame->startup, sizeof(gAutoLaunchGame->startup), argv[1]);
gAutoLaunchGame->start_sector = strtoul(argv[2], NULL, 0);
snprintf(gOPLPart, sizeof(gOPLPart), "hdd0:%s", argv[3]);

configInit(NULL);

ioInit();
LOG_ENABLE();

hddLoadModules();

ret = configReadMulti(CONFIG_ALL);
if (CONFIG_ALL & CONFIG_OPL) {
if (!(ret & CONFIG_OPL))
ret = checkLoadConfigHDD(CONFIG_ALL);

if (ret & CONFIG_OPL) {
config_set_t *configOPL = configGetByType(CONFIG_OPL);

configGetInt(configOPL, CONFIG_OPL_PS2LOGO, &gPS2Logo);
configGetStrCopy(configOPL, CONFIG_OPL_EXIT_PATH, gExitPath, sizeof(gExitPath));
configGetInt(configOPL, CONFIG_OPL_HDD_SPINDOWN, &gHDDSpindown);
}
}

snprintf(path, sizeof(path), "%sCFG/%s.cfg", gHDDPrefix, gAutoLaunchGame->startup);
configSet = configAlloc(0, NULL, path);
configRead(configSet);

hddLaunchGame(-1, configSet);
}

// --------------------- Main --------------------
int main(int argc, char *argv[])
{
Expand All @@ -1685,6 +1737,17 @@ int main(int argc, char *argv[])

// reset, load modules
reset();

/* argv[0] boot path
argv[1] game->startup
argv[2] str to u32 game->start_sector
argv[3] opl partition read from hdd0:__common/OPL/conf_hdd.cfg
argv[4] "mini" */
if (argc >= 5) {
if (!strcmp(argv[4], "mini"))
autoLaunchHDDGame(argv);
}

init();

// until this point in the code is reached, only PREINIT_LOG macro should be used
Expand Down

0 comments on commit 17c3a5c

Please sign in to comment.