Added "Play Game with Disk" option

This commit is contained in:
luigiblood 2016-01-25 20:58:57 +01:00
parent 82779033d3
commit 39a1c9f407
13 changed files with 362 additions and 29 deletions

View File

@ -96,6 +96,7 @@
#212# "Edit Game Settings"
#213# "Edit Cheats"
#214# "Graphics Plugin"
#215# "Play Game with Disk"
//Alternate Name to save Slot
#220# "Save Slot - Default"

View File

@ -125,6 +125,7 @@ enum LanguageStringID{
POPUP_SETTINGS = 212,
POPUP_CHEATS = 213,
POPUP_GFX_PLUGIN = 214,
POPUP_PLAYDISK = 215,
//selecting save slot
SAVE_SLOT_DEFAULT = 220,

View File

@ -133,6 +133,7 @@ void CLanguage::LoadDefaultStrings(void)
DEF_STR(POPUP_SETTINGS, "Edit Game Settings");
DEF_STR(POPUP_CHEATS, "Edit Cheats");
DEF_STR(POPUP_GFX_PLUGIN, "Graphics Plugin");
DEF_STR(POPUP_PLAYDISK, "Play Game with Disk");
//Alternate Name to save Slot
DEF_STR(SAVE_SLOT_DEFAULT, "Save Slot - Default");

View File

@ -217,18 +217,7 @@ bool CN64System::RunFileImage(const char * FileLoc)
{
//64DD IPL
g_DDRom = g_Rom;
}
if (g_Disk == NULL)
{
g_Disk = new CN64Disk();
}
if (!g_Disk->LoadDiskImage(g_Settings->LoadStringVal(SupportFile_DiskTest).c_str()))
{
g_Notify->DisplayError(g_Disk->GetError());
delete g_Disk;
g_Disk = NULL;
g_Settings->SaveString(File_DiskIPLPath, FileLoc);
}
g_System->RefreshGameSettings();
@ -257,6 +246,107 @@ bool CN64System::RunFileImage(const char * FileLoc)
return true;
}
bool CN64System::RunFileImageIPL(const char * FileLoc)
{
CloseSystem();
if (g_Settings->LoadBool(GameRunning_LoadingInProgress))
{
return false;
}
//Mark the rom as loading
WriteTrace(TraceN64System, TraceDebug, "Mark DDRom as loading");
//g_Settings->SaveString(Game_File, "");
g_Settings->SaveBool(GameRunning_LoadingInProgress, true);
//Try to load the passed N64 DDrom
if (g_DDRom == NULL)
{
WriteTrace(TraceN64System, TraceDebug, "Allocating global DDrom object");
g_DDRom = new CN64Rom();
}
else
{
WriteTrace(TraceN64System, TraceDebug, "Use existing global DDrom object");
}
WriteTrace(TraceN64System, TraceDebug, "Loading \"%s\"", FileLoc);
if (g_DDRom->LoadN64ImageIPL(FileLoc))
{
if (g_DDRom->CicChipID() != CIC_NUS_8303)
{
//If not 64DD IPL then it's wrong
WriteTrace(TraceN64System, TraceError, "LoadN64ImageIPL failed (\"%s\")", FileLoc);
g_Notify->DisplayError(g_DDRom->GetError());
delete g_DDRom;
g_DDRom = NULL;
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
return false;
}
g_System->RefreshGameSettings();
g_Settings->SaveString(File_DiskIPLPath, FileLoc);
//g_Settings->SaveString(Game_File, FileLoc);
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
}
else
{
WriteTrace(TraceN64System, TraceError, "LoadN64ImageIPL failed (\"%s\")", FileLoc);
g_Notify->DisplayError(g_DDRom->GetError());
delete g_DDRom;
g_DDRom = NULL;
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
return false;
}
return true;
}
bool CN64System::RunDiskImage(const char * FileLoc)
{
CloseSystem();
if (g_Settings->LoadBool(GameRunning_LoadingInProgress))
{
return false;
}
//Mark the rom as loading
WriteTrace(TraceN64System, TraceDebug, "Mark Disk as loading");
//g_Settings->SaveString(Game_File, "");
g_Settings->SaveBool(GameRunning_LoadingInProgress, true);
//Try to load the passed N64 Disk
if (g_Disk == NULL)
{
WriteTrace(TraceN64System, TraceDebug, "Allocating global Disk object");
g_Disk = new CN64Disk();
}
else
{
WriteTrace(TraceN64System, TraceDebug, "Use existing global Disk object");
}
WriteTrace(TraceN64System, TraceDebug, "Loading \"%s\"", FileLoc);
if (g_Disk->LoadDiskImage(FileLoc))
{
g_System->RefreshGameSettings();
//g_Settings->SaveString(Game_File, FileLoc);
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
}
else
{
WriteTrace(TraceN64System, TraceError, "LoadDiskImage failed (\"%s\")", FileLoc);
g_Notify->DisplayError(g_Disk->GetError());
delete g_Disk;
g_Disk = NULL;
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
return false;
}
return true;
}
void CN64System::CloseSystem()
{
if (g_BaseSystem)

View File

@ -56,6 +56,8 @@ public:
//Methods
static bool RunFileImage(const char * FileLoc);
static bool RunFileImageIPL(const char * FileLoc);
static bool RunDiskImage(const char * FileLoc);
static void CloseSystem(void);
void CloseCpu();

View File

@ -579,6 +579,183 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
return true;
}
bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
{
UnallocateRomImage();
m_ErrorMsg = EMPTY_STRING;
stdstr ext = CPath(FileLoc).GetExtension();
bool Loaded7zFile = false;
if (strstr(FileLoc, "?") != NULL || _stricmp(ext.c_str(), "7z") == 0)
{
stdstr FullPath = FileLoc;
//this should be a 7zip file
char * SubFile = strstr(const_cast<char*>(FullPath.c_str()), "?");
if (SubFile == NULL)
{
//Pop up a dialog and select file
//allocate memory for sub name and copy selected file name to var
return false; //remove once dialog is done
}
else
{
*SubFile = '\0';
SubFile += 1;
}
C7zip ZipFile(FullPath.c_str());
ZipFile.SetNotificationCallback((C7zip::LP7ZNOTIFICATION)NotificationCB, this);
for (int i = 0; i < ZipFile.NumFiles(); i++)
{
CSzFileItem * f = ZipFile.FileItem(i);
if (f->IsDir)
{
continue;
}
stdstr ZipFileName;
ZipFileName.FromUTF16(ZipFile.FileNameIndex(i).c_str());
if (SubFile != NULL)
{
if (_stricmp(ZipFileName.c_str(), SubFile) != 0)
{
continue;
}
}
//Get the size of the rom and try to allocate the memory needed.
uint32_t RomFileSize = (uint32_t)f->Size;
//if loading boot code then just load the first 0x1000 bytes
if (LoadBootCodeOnly) { RomFileSize = 0x1000; }
if (!AllocateRomImage(RomFileSize))
{
return false;
}
//Load the n64 rom to the allocated memory
g_Notify->DisplayMessage(5, MSG_LOADING);
if (!ZipFile.GetFile(i, m_ROMImage, RomFileSize))
{
SetError(MSG_FAIL_IMAGE);
return false;
}
if (!IsValidRomImage(m_ROMImage))
{
SetError(MSG_FAIL_IMAGE);
return false;
}
g_Notify->DisplayMessage(5, MSG_BYTESWAP);
ByteSwapRom();
//Protect the memory so that it can not be written to.
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READONLY);
Loaded7zFile = true;
break;
}
if (!Loaded7zFile)
{
SetError(MSG_7Z_FILE_NOT_FOUND);
return false;
}
}
//Try to open the file as a zip file
if (!Loaded7zFile)
{
if (!AllocateAndLoadZipImage(FileLoc, LoadBootCodeOnly))
{
if (m_ErrorMsg != EMPTY_STRING)
{
return false;
}
if (!AllocateAndLoadN64Image(FileLoc, LoadBootCodeOnly))
{
return false;
}
}
}
char RomName[260];
int count;
//Get the header from the rom image
memcpy(&RomName[0], (void *)(m_ROMImage + 0x20), 20);
for (count = 0; count < 20; count += 4)
{
RomName[count] ^= RomName[count + 3];
RomName[count + 3] ^= RomName[count];
RomName[count] ^= RomName[count + 3];
RomName[count + 1] ^= RomName[count + 2];
RomName[count + 2] ^= RomName[count + 1];
RomName[count + 1] ^= RomName[count + 2];
}
//truncate all the spaces at the end of the string
for (count = 19; count >= 0; count--)
{
if (RomName[count] == ' ')
{
RomName[count] = '\0';
}
else if (RomName[count] == '\0')
{
}
else
{
count = -1;
}
}
RomName[20] = '\0';
if (strlen(RomName) == 0)
{
strcpy(RomName, CPath(FileLoc).GetName().c_str());
}
//remove all /,\,: from the string
for (count = 0; count < (int)strlen(RomName); count++)
{
switch (RomName[count])
{
case '/': case '\\': RomName[count] = '-'; break;
case ':': RomName[count] = ';'; break;
}
}
WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName);
m_RomName = RomName;
m_FileName = FileLoc;
m_MD5 = "";
if (!LoadBootCodeOnly)
{
//Calculate files MD5
m_MD5 = MD5((const unsigned char *)m_ROMImage, m_RomFileSize).hex_digest();
WriteTrace(TraceN64System, TraceDebug, "MD5: %s", m_MD5.c_str());
}
m_Country = (Country)m_ROMImage[0x3D];
m_RomIdent.Format("%08X-%08X-C:%X", *(uint32_t *)(&m_ROMImage[0x10]), *(uint32_t *)(&m_ROMImage[0x14]), m_ROMImage[0x3D]);
WriteTrace(TraceN64System, TraceDebug, "Ident: %s", m_RomIdent.c_str());
CalculateCicChip();
if (!LoadBootCodeOnly && g_DDRom == this)
{
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
SaveRomSettingID(false);
}
if (g_Settings->LoadBool(Game_CRC_Recalc))
{
//Calculate ROM Header CRC
CalculateRomCrc();
}
return true;
}
//Save the settings of the loaded rom, so all loaded settings about rom will be identified with
//this rom
void CN64Rom::SaveRomSettingID(bool temp)

View File

@ -21,6 +21,7 @@ public:
~CN64Rom();
bool LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly = false);
bool LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly = false);
static bool IsValidRomImage(uint8_t Test[4]);
void SaveRomSettingID(bool temp);
void ClearRomSettingID();

View File

@ -48,8 +48,6 @@ enum SettingID
SupportFile_RomListCacheDefault,
SupportFile_7zipCache,
SupportFile_7zipCacheDefault,
//64DD TEST
SupportFile_DiskTest,
//Settings
Setting_ApplicationName,
@ -226,6 +224,7 @@ enum SettingID
//File Info
File_RecentGameFileCount,
File_RecentGameFileIndex,
File_DiskIPLPath,
//Debugger
Debugger_Enabled,

View File

@ -114,8 +114,6 @@ void CSettings::AddHowToHandleSetting()
AddHandler(SupportFile_7zipCache, new CSettingTypeApplicationPath("", "7zipCache", SupportFile_7zipCacheDefault));
AddHandler(SupportFile_7zipCacheDefault, new CSettingTypeRelativePath("Config", "Project64.zcache"));
AddHandler(SupportFile_DiskTest, new CSettingTypeRelativePath("Config", "DMPJ.ndd"));
//AddHandler(SyncPluginDir, new CSettingTypeRelativePath("SyncPlugin",""));
//Settings location
@ -311,6 +309,7 @@ void CSettings::AddHowToHandleSetting()
AddHandler(File_RecentGameFileCount, new CSettingTypeApplication("", "Remembered Rom Files", (uint32_t)10));
AddHandler(File_RecentGameFileIndex, new CSettingTypeApplicationIndex("Recent File", "Recent Rom", Default_None));
AddHandler(File_DiskIPLPath, new CSettingTypeApplicationPath("", "Disk IPL ROM Path", Default_None));
AddHandler(Debugger_Enabled, new CSettingTypeApplication("Debugger", "Debugger", false));
AddHandler(Debugger_ShowTLBMisses, new CSettingTypeApplication("Debugger", "Show TLB Misses", false));

View File

@ -979,6 +979,64 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
switch (LOWORD(wParam)) {
case ID_POPUPMENU_PLAYGAME: g_BaseSystem->RunFileImage(_this->CurrentedSelectedRom()); break;
case ID_POPUPMENU_PLAYGAMEWITHDISK:
if (!g_BaseSystem->RunFileImageIPL(g_Settings->LoadStringVal(File_DiskIPLPath).c_str()))
{
// Open DDROM
OPENFILENAME openfilename;
char FileName[_MAX_PATH], Directory[_MAX_PATH];
memset(&FileName, 0, sizeof(FileName));
memset(&openfilename, 0, sizeof(openfilename));
strcpy(Directory, g_Settings->LoadStringVal(Directory_Game).c_str());
openfilename.lStructSize = sizeof(openfilename);
openfilename.hwndOwner = (HWND)hWnd;
openfilename.lpstrFilter = "64DD IPL ROM Image (*.zip, *.7z, *.?64, *.rom, *.usa, *.jap, *.pal, *.bin)\0*.?64;*.zip;*.7z;*.bin;*.rom;*.usa;*.jap;*.pal\0All files (*.*)\0*.*\0";
openfilename.lpstrFile = FileName;
openfilename.lpstrInitialDir = Directory;
openfilename.nMaxFile = MAX_PATH;
openfilename.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if (GetOpenFileName(&openfilename))
{
g_BaseSystem->RunFileImageIPL(FileName);
// Open Disk
openfilename.lpstrFilter = "N64DD Disk Image (*.ndd)\0*.ndd\0All files (*.*)\0*.*\0";
if (GetOpenFileName(&openfilename))
{
g_BaseSystem->RunDiskImage(FileName);
g_BaseSystem->RunFileImage(_this->CurrentedSelectedRom());
}
}
}
else
{
// Open Disk
OPENFILENAME openfilename;
char FileName[_MAX_PATH], Directory[_MAX_PATH];
memset(&FileName, 0, sizeof(FileName));
memset(&openfilename, 0, sizeof(openfilename));
strcpy(Directory, g_Settings->LoadStringVal(Directory_Game).c_str());
openfilename.lStructSize = sizeof(openfilename);
openfilename.hwndOwner = (HWND)hWnd;
openfilename.lpstrFilter = "N64DD Disk Image (*.ndd)\0*.ndd\0All files (*.*)\0*.*\0";
openfilename.lpstrFile = FileName;
openfilename.lpstrInitialDir = Directory;
openfilename.nMaxFile = MAX_PATH;
openfilename.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if (GetOpenFileName(&openfilename))
{
g_BaseSystem->RunDiskImage(FileName);
g_BaseSystem->RunFileImage(_this->CurrentedSelectedRom());
}
}
break;
case ID_POPUPMENU_ROMDIRECTORY: _this->SelectRomDir(); break;
case ID_POPUPMENU_REFRESHROMLIST: _this->RefreshRomBrowser(); break;
case ID_POPUPMENU_ROMINFORMATION:

View File

@ -1502,21 +1502,23 @@ void CRomBrowser::RomList_PopupMenu(uint32_t /*pnmh*/)
//Fix up menu
MenuSetText(hPopupMenu, 0, wGS(POPUP_PLAY).c_str(), NULL);
MenuSetText(hPopupMenu, 2, wGS(MENU_REFRESH).c_str(), NULL);
MenuSetText(hPopupMenu, 3, wGS(MENU_CHOOSE_ROM).c_str(), NULL);
MenuSetText(hPopupMenu, 5, wGS(POPUP_INFO).c_str(), NULL);
MenuSetText(hPopupMenu, 6, wGS(POPUP_GFX_PLUGIN).c_str(), NULL);
MenuSetText(hPopupMenu, 8, wGS(POPUP_SETTINGS).c_str(), NULL);
MenuSetText(hPopupMenu, 9, wGS(POPUP_CHEATS).c_str(), NULL);
MenuSetText(hPopupMenu, 1, wGS(POPUP_PLAYDISK).c_str(), NULL);
MenuSetText(hPopupMenu, 3, wGS(MENU_REFRESH).c_str(), NULL);
MenuSetText(hPopupMenu, 4, wGS(MENU_CHOOSE_ROM).c_str(), NULL);
MenuSetText(hPopupMenu, 6, wGS(POPUP_INFO).c_str(), NULL);
MenuSetText(hPopupMenu, 7, wGS(POPUP_GFX_PLUGIN).c_str(), NULL);
MenuSetText(hPopupMenu, 9, wGS(POPUP_SETTINGS).c_str(), NULL);
MenuSetText(hPopupMenu, 10, wGS(POPUP_CHEATS).c_str(), NULL);
if (m_SelectedRom.size() == 0)
{
DeleteMenu(hPopupMenu, 10, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 9, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 8, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 7, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 6, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 5, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 4, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 2, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 1, MF_BYPOSITION);
DeleteMenu(hPopupMenu, 0, MF_BYPOSITION);
}
@ -1524,17 +1526,17 @@ void CRomBrowser::RomList_PopupMenu(uint32_t /*pnmh*/)
{
bool inBasicMode = g_Settings->LoadDword(UserInterface_BasicMode) != 0;
bool CheatsRemembered = g_Settings->LoadDword(Setting_RememberCheats) != 0;
if (!CheatsRemembered) { DeleteMenu(hPopupMenu, 9, MF_BYPOSITION); }
if (inBasicMode) { DeleteMenu(hPopupMenu, 8, MF_BYPOSITION); }
if (inBasicMode && !CheatsRemembered) { DeleteMenu(hPopupMenu, 7, MF_BYPOSITION); }
DeleteMenu(hPopupMenu, 6, MF_BYPOSITION);
if (!CheatsRemembered) { DeleteMenu(hPopupMenu, 10, MF_BYPOSITION); }
if (inBasicMode) { DeleteMenu(hPopupMenu, 9, MF_BYPOSITION); }
if (inBasicMode && !CheatsRemembered) { DeleteMenu(hPopupMenu, 8, MF_BYPOSITION); }
DeleteMenu(hPopupMenu, 7, MF_BYPOSITION);
if (!inBasicMode && g_Plugins && g_Plugins->Gfx() && g_Plugins->Gfx()->GetRomBrowserMenu != NULL)
{
HMENU GfxMenu = (HMENU)g_Plugins->Gfx()->GetRomBrowserMenu();
if (GfxMenu)
{
MENUITEMINFO lpmii;
InsertMenuW(hPopupMenu, 6, MF_POPUP | MF_BYPOSITION, (uint32_t)GfxMenu, wGS(POPUP_GFX_PLUGIN).c_str());
InsertMenuW(hPopupMenu, 7, MF_POPUP | MF_BYPOSITION, (uint32_t)GfxMenu, wGS(POPUP_GFX_PLUGIN).c_str());
lpmii.cbSize = sizeof(MENUITEMINFO);
lpmii.fMask = MIIM_STATE;
lpmii.fState = 0;

View File

@ -895,6 +895,7 @@ BEGIN
POPUP "PopupMenu"
BEGIN
MENUITEM "Play Game", ID_POPUPMENU_PLAYGAME
MENUITEM "Play Game with Disk", ID_POPUPMENU_PLAYGAMEWITHDISK
MENUITEM SEPARATOR
MENUITEM "Refresh Rom List", ID_POPUPMENU_REFRESHROMLIST
MENUITEM "Choose Rom Directory...", ID_POPUPMENU_ROMDIRECTORY

View File

@ -329,6 +329,7 @@
#define IDC_NOTES_TEXT 1208
#define IDC_LANG_SEL 1219
#define ID_POPUP_SHOWINMEMORYVIEWER 40005
#define ID_POPUPMENU_PLAYGAMEWITHDISK 40008
#define ID_POPUPMENU_ROMDIRECTORY 40137
#define ID_POPUPMENU_REFRESHROMLIST 40138
#define ID_POPUPMENU_PLAYGAME 40152
@ -344,7 +345,7 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 150
#define _APS_NEXT_COMMAND_VALUE 40008
#define _APS_NEXT_COMMAND_VALUE 40009
#define _APS_NEXT_CONTROL_VALUE 1100
#define _APS_NEXT_SYMED_VALUE 101
#endif