diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index b7c38593..25e6ee76 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -398,7 +398,6 @@ BEGIN_MESSAGE_MAP(MainWnd, CWnd) ON_WM_ENTERSIZEMOVE() ON_COMMAND(ID_AUDIO_CORE_SETTINGS, &MainWnd::OnAudioCoreSettings) ON_UPDATE_COMMAND_UI(ID_AUDIO_CORE_SETTINGS, &MainWnd::OnUpdateAudioCoreSettings) - ON_COMMAND(ID_FILE_QUICKOPENROM, &MainWnd::OnFileQuickopenrom) END_MESSAGE_MAP() @@ -983,30 +982,32 @@ bool MainWnd::fileOpenSelect( int system ) { theApp.dir = _T(""); CString initialDir; + int selectedFilter = 0; LPCTSTR exts[] = { _T(""), _T(""), _T(""), _T("") }; CString filter; CString title; switch( system ) { - case 100: - // Quick Open File - initialDir = regQueryStringValue( _T("QuickOpenFileLastDir"), _T(".") ); - filter = winLoadFilter( IDS_FILTER_ALLROM ); - break; case 0: // GBA initialDir = regQueryStringValue( _T("romdir"), _T(".") ); + selectedFilter = regQueryDwordValue( _T("selectedFilter"), 0); + if( (selectedFilter < 0) || (selectedFilter > 2) ) { + selectedFilter = 0; + } filter = winLoadFilter( IDS_FILTER_GBAROM ); break; case 1: // GBC initialDir = regQueryStringValue( _T("gbcromdir"), _T(".") ); + // TODO: memorize selected filter for GBC as well filter = winLoadFilter( IDS_FILTER_GBCROM ); break; case 2: // GB initialDir = regQueryStringValue( _T("gbromdir"), _T(".") ); + // TODO: memorize selected filter for GB as well filter = winLoadFilter( IDS_FILTER_GBROM ); break; } @@ -1022,18 +1023,19 @@ bool MainWnd::fileOpenSelect( int system ) theApp.szFile = _T(""); - FileDlg dlg( this, _T(""), filter, 0, _T(""), exts, theApp.dir, title, false); + FileDlg dlg( this, _T(""), filter, selectedFilter, _T(""), exts, theApp.dir, title, false); if( dlg.DoModal() == IDOK ) { + if( system == 0 ) { + regSetDwordValue( _T("selectedFilter"), dlg.m_ofn.nFilterIndex ); + } theApp.szFile = dlg.GetPathName(); theApp.dir = theApp.szFile.Left( dlg.m_ofn.nFileOffset ); if( (theApp.dir.GetLength() > 3) && (theApp.dir[theApp.dir.GetLength()-1] == _T('\\')) ) { theApp.dir = theApp.dir.Left( theApp.dir.GetLength() - 1 ); } SetCurrentDirectory( theApp.dir ); - if( system == 100 ) { - regSetStringValue( _T("QuickOpenFileLastDir"), theApp.dir ); - } + regSetStringValue( _T("lastDir"), theApp.dir ); return true; } return false; diff --git a/src/win32/MainWnd.h b/src/win32/MainWnd.h index 353bf73d..2e7edec0 100644 --- a/src/win32/MainWnd.h +++ b/src/win32/MainWnd.h @@ -63,7 +63,6 @@ protected: afx_msg void OnClose(); afx_msg void OnHelpAbout(); afx_msg void OnHelpFaq(); - afx_msg void OnFileQuickopenrom(); afx_msg void OnFileOpenGBA(); afx_msg void OnFileOpenGBC(); afx_msg void OnFileOpenGB(); diff --git a/src/win32/MainWndFile.cpp b/src/win32/MainWndFile.cpp index 181d3646..89042423 100644 --- a/src/win32/MainWndFile.cpp +++ b/src/win32/MainWndFile.cpp @@ -21,13 +21,6 @@ extern void remoteCleanUp(); extern void InterframeCleanup(); -void MainWnd::OnFileQuickopenrom() -{ - if( fileOpenSelect( 100 ) ) { - FileRun(); - } -} - void MainWnd::OnFileOpenGBA() { if( fileOpenSelect( 0 ) ) { diff --git a/src/win32/VBA.rc b/src/win32/VBA.rc index a1379c15..39f84b34 100644 --- a/src/win32/VBA.rc +++ b/src/win32/VBA.rc @@ -1612,8 +1612,6 @@ IDR_MENU MENU BEGIN POPUP "&File" BEGIN - MENUITEM "Quick Open ROM...", ID_FILE_QUICKOPENROM - MENUITEM SEPARATOR MENUITEM "Open GBA...", ID_FILE_OPEN_GBA MENUITEM "Open GBC...", ID_FILE_OPEN_GBC MENUITEM "Open GB...", ID_FILE_OPEN_GB @@ -2212,7 +2210,6 @@ BEGIN IDS_TOOLTIP_ENHANCE_SOUND "Enable the following sound enhancements." IDS_TOOLTIP_SURROUND "Inverts the phase of some channels, making it sound as if sound is coming from behind." IDS_TOOLTIP_DECLICKING "When enabled, clicks are reduced by using GBA sound hardware. Note that clicks are normal for GB and GBC sound hardware." - IDS_FILTER_ALLROM "All ROMs (*.GBA;*.AGB;*.BIN;*.ELF;*.MB;*.GBC;*.CGB;*.GB;*.SGB;*.ZIP;*.7Z;*.Z;*.GZ)_*.GBA;*.AGB;*.BIN;*.ELF;*.MB;*.GBC;*.CGB;*.GB;*.SGB;*.ZIP;*.7Z;*.Z;*.GZ_All Files (*.*)_*.*__" END STRINGTABLE diff --git a/src/win32/protect.c b/src/win32/protect.c deleted file mode 100644 index 9f9dec59..00000000 --- a/src/win32/protect.c +++ /dev/null @@ -1,155 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "protect.h" - -char *unprotect_buffer(unsigned char *buffer, size_t buffer_len) -{ - unsigned char *p = buffer, *end_p = p+buffer_len-1, previous = 0x11; - while (p < end_p) - { - unsigned char current = *p; - *p ^= previous; - previous = current; - *p -= 25; - *p ^= 0x87; - ++p; - } - return((char *)buffer); -} - -#ifdef _DEBUG - -//For building debug builds, no security ever -int ExecutableValid(const char *executable_filename) -{ - return(0); -} - -#else - -SET_FN_PTR(fopen, 0x01301100); -SET_FN_PTR(fread, 0x01301200); -SET_FN_PTR(malloc, 0x01301300); - -typedef FILE * (*p_fopen)(const char *path, const char *mode); -typedef size_t (*p_fread)(void *ptr, size_t size, size_t nmemb, FILE *stream); -typedef void * (*p_malloc)(size_t size); - -static uint8_t *memmem(const uint8_t *haystack, size_t haystacklen, const uint8_t *needle, size_t needlelen) -{ - if (needlelen) - { - if (needlelen <= haystacklen) - { - haystacklen -= needlelen-1; - while (haystacklen--) - { - if (!memcmp(haystack, needle, needlelen)) - { - return((uint8_t *)haystack); - } - ++haystack; - } - } - } - else - { - return((uint8_t *)haystack); - } - return(0); -} - -static volatile uint32_t data[] = { - 0x00000000, - 0x0C097E1B, - 0x00000000, - 0xABCEFDCA, - 0x6876ABDC, - 0x12345678, - 0x9ABCDEF0, - 0xFEDCBA98, - 0x76543210, - 0xDEADBEEF, - 0xFEEDFACE, - 0xDEADBABE, - 0x00000000, - 0xFFFFFFFF, - 0x3AB5F60E, - 0xCCCCCCCC, - 0xA55AA55A, - 0x43570C13, - 0x74372984 -}; - -int ExecutableValid(const char *executable_filename) -{ - FILE *fp; - int retval = 1; //Invalid - - if ((fp = ((p_fopen)GET_FN_PTR(fopen))(executable_filename, "rb"))) - { - size_t file_size; - uint8_t *buffer; - - fseek(fp, 0, SEEK_END); - file_size = ftell(fp); - - if ((buffer = ((p_malloc)GET_FN_PTR(malloc))(file_size))) //Mallocing the whole file? Oh Noes! - { - const uint8_t *p; - - rewind(fp); - ((p_fread)GET_FN_PTR(fread))(buffer, 1, file_size, fp); - - if ((p = memmem(buffer, file_size, (const uint8_t *)data, sizeof(data)))) - { - size_t length_till_data = p-buffer; - uint32_t crc1, crc2, crc3, crc4; - - crc1 = crc2 = crc3 = crc4 = crc32(0L, Z_NULL, 0); - crc1 = crc32(crc1, (const Bytef *)buffer, length_till_data); - crc2 = crc32(crc1, (const Bytef *)data, sizeof(data)); - crc3 = crc32(crc3, (const Bytef *)p+sizeof(data), file_size-(length_till_data+sizeof(data))); - crc4 = crc32(crc4, (const Bytef *)(data+1), sizeof(data)-sizeof(uint32_t)); - - crc1 = crc32_combine(crc1, crc3, file_size-(length_till_data+sizeof(data))); - crc2 = crc32_combine(crc2, crc3, file_size-(length_till_data+sizeof(data))); - - crc3 = adler32(0L, Z_NULL, 0); - crc3 = adler32(crc3, (const Bytef *)buffer, length_till_data); - crc3 = adler32(crc3, (const Bytef *)p+sizeof(data), file_size-(length_till_data+sizeof(data))); - - if ((data[sizeof(data)/sizeof(uint32_t)-4] == crc1) && - (data[sizeof(data)/sizeof(uint32_t)-3] == crc3) && - (data[sizeof(data)/sizeof(uint32_t)-2] == crc2) && - (data[sizeof(data)/sizeof(uint32_t)-1] == crc4) && - (file_size == data[2]) && - (data[3] == ((uint32_t *)(buffer+file_size))[-2]) && - (data[4] == ((uint32_t *)(buffer+file_size))[-1])) - { - retval = data[12]; //Valid - } - - free(buffer); - } - } - else - { - retval = -2; //Error Occured - Memory - } - - fclose(fp); - } - else - { - retval = -1; //Error Occured - File - } - - return(retval); -} - -#endif diff --git a/src/win32/protect.h b/src/win32/protect.h deleted file mode 100644 index 6dbd5072..00000000 --- a/src/win32/protect.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#if defined(__cplusplus) -extern "C" { -#endif - -//Returns 0 on success, 1 on failure, and <0 when an error occured -//Note, can only be called once per execution -int ExecutableValid(const char *executable_filename); -char *unprotect_buffer(unsigned char *buffer, size_t buffer_len); - -#pragma optimize("", off) -#define SET_FN_PTR(func, num) \ - static __inline void *get_##func(void) { \ - volatile int i, j = num / 4; \ - long ptr = (long)func + num; \ - for (i = 0; i < 2; i++) { ptr -= j; } \ - return (void *)(ptr - (j * 2)); \ - } -#pragma optimize("", on) - -#define GET_FN_PTR(func) get_##func() - -#if defined(__cplusplus) -} -#endif diff --git a/src/win32/resource.h b/src/win32/resource.h index aa4cff93..890f6914 100644 --- a/src/win32/resource.h +++ b/src/win32/resource.h @@ -867,16 +867,15 @@ #define ID_OUTPUTAPI_XAUDIO2CONFIG 40364 #define ID_AUDIO_CORE_SETTINGS 40365 #define ID_FILE_OPEN_GBA 40366 -#define ID_FILE_QUICKOPENROM 40367 -#define ID_OPTIONS_VIDEO_LAYERS_RESET 40368 -#define ID_LOADGAME_DONOTCHANGECHEATLIST 40370 +#define ID_OPTIONS_VIDEO_LAYERS_RESET 40367 +#define ID_LOADGAME_DONOTCHANGECHEATLIST 40371 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 165 -#define _APS_NEXT_COMMAND_VALUE 40371 +#define _APS_NEXT_COMMAND_VALUE 40372 #define _APS_NEXT_CONTROL_VALUE 1297 #define _APS_NEXT_SYMED_VALUE 103 #endif