diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 368dddd5b..d6cbd81f4 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -412,6 +412,7 @@ extern bool allowBackgroundInput; std::vector LuaScriptHWnds; LRESULT CALLBACK LuaScriptProc(HWND, UINT, WPARAM, LPARAM); +bool autoLoadLua; #define MAX_RECENT_SCRIPTS 15 // must match value in luaconsole.cpp (belongs in a header, but I didn't want to create one just for this) extern char Recent_Scripts[MAX_RECENT_SCRIPTS][1024]; @@ -2653,6 +2654,7 @@ int _main() GetPrivateProfileString("Watches", str, "", &rw_recent_files[i][0], 1024, IniName); } + autoLoadLua = GetPrivateProfileBool("Scripting", "AutoLoad", false, IniName); for(int i = 0; i < MAX_RECENT_SCRIPTS; i++) { @@ -3466,6 +3468,30 @@ static BOOL OpenCore(const char* filename) start_paused = 0; } + if(autoLoadLua) + { + string luaScript; + luaScript.append(path.pathToLua); + if(!Path::IsPathRooted(luaScript)) + { + luaScript.clear(); + luaScript.append(path.pathToModule); + luaScript.append(path.pathToLua); + } + luaScript.append("\\"); + luaScript.append(path.GetRomNameWithoutExtension()); + luaScript.append(".lua"); + + FILE* file; + file = fopen(luaScript.c_str(), "rb"); + if(file) + { + fclose(file); + HWND hDlg = CreateDialogW(hAppInst, MAKEINTRESOURCEW(IDD_LUA), MainWindow->getHWnd(), (DLGPROC) LuaScriptProc); + SendDlgItemMessage(hDlg, IDC_EDIT_LUAPATH, WM_SETTEXT, (WPARAM) 512, (LPARAM) luaScript.c_str()); + } + } + // Update the toolbar MainWindowToolbar->EnableButton(IDM_PAUSE, true); MainWindowToolbar->EnableButton(IDM_CLOSEROM, true); diff --git a/desmume/src/windows/pathsettings.cpp b/desmume/src/windows/pathsettings.cpp index bb1306353..2ebfaa348 100644 --- a/desmume/src/windows/pathsettings.cpp +++ b/desmume/src/windows/pathsettings.cpp @@ -28,6 +28,8 @@ #include "path.h" #include "pathsettings.h" +extern bool autoLoadLua; + #define HANDLE_DLGMSG(hwnd, message, fn) \ case (message): return (SetDlgMsgResult(hDlg, uMsg, \ HANDLE_##message( (hwnd), (wParam), (lParam), (fn) ) ) ) @@ -119,6 +121,8 @@ void WritePathSettings() WritePrivateProfileInt(SECTION, LASTVISITKEY, path.savelastromvisit, IniName); WritePrivateProfileInt(SECTION, ASSOCIATEKEY, associate, IniName); + WritePrivateProfileBool("Scripting", "AutoLoad", autoLoadLua, IniName); + // WritePrivateProfileInt(SECTION, DEFAULTFORMATKEY, defaultFormat, IniName); // WritePrivateProfileInt(SECTION, NEEDSSAVINGKEY, needsSaving, IniName); } @@ -142,6 +146,7 @@ BOOL PathSettings_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam) CheckDlgButton(hDlg, IDC_USELASTVISIT, (path.savelastromvisit) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_ASSOCIATE, (associate) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hDlg, IDC_AUTOLOADLUA, (autoLoadLua) ? BST_CHECKED : BST_UNCHECKED); CheckRadioButton(hDlg, IDC_PNG, IDC_BMP, (int)path.imageformat()); CheckRadioButton(hDlg, IDC_R4TYPE1, IDC_R4TYPE2, (int)path.r4Format); @@ -315,6 +320,9 @@ void PathSettings_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify) } } break; + case IDC_AUTOLOADLUA: + autoLoadLua = !autoLoadLua; + break; case IDOK: GetDlgItemText(hDlg, IDC_ROMPATHEDIT, path.pathToRoms, MAX_PATH); diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index b42702fda..1cb6a0b9f 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -998,6 +998,7 @@ #define IDM_RENDER_LQ2X 60082 #define IDM_RENDER_LQ2XS 60083 #define IDC_SAVETYPE 64000 +#define IDC_AUTOLOADLUA 64001 // Next default values for new objects // diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index 35b399e0e..2b12aff10 100644 Binary files a/desmume/src/windows/resources.rc and b/desmume/src/windows/resources.rc differ