int Audio_SDL::playSound(void) { // NOTE: DirectSound only - what is this function used for? #if 0 HRESULT rval; if (Sound_Is_Playing) return 1; rval = lpDSBuffer->Play (0, 0, DSBPLAY_LOOPING); Clear_Sound_Buffer (); if (rval != DS_OK) return 0; #endif m_soundIsPlaying = true; return 1; }
FILE* GetMP3TrackFile(int trackIndex, int* pDontLeaveFileOpen, int* pWhere_read) { FILE* decodedFile = Tracks[trackIndex].F_decoded; int usePartiallyDecodedFile = 0; char str [1024]; int curTrack = LBA_to_Track(SCD.Cur_LBA); int lbaOffset = SCD.Cur_LBA - Track_to_LBA(curTrack); int lba = lbaOffset; int outRead = 0; int forceNoDecode = 0; int& where_read = *pWhere_read; where_read = (lba) * 588*4 + 16; if(where_read < 0) where_read = 0; #ifdef _WIN32 if(!decodedFile) { Waiting_For_Preload_MP3_Synchronous = true; Preload_MP3(&Tracks[trackIndex].F_decoded, trackIndex); DWORD tgtime = timeGetTime(); //Modif N - give frame advance sound: bool soundCleared = false; sprintf(str, "%s/" PRELOADED_MP3_DIRECTORY PRELOADED_MP3_FILENAME, Gens_Path, trackIndex+1); while(!usePartiallyDecodedFile) { if(!decodedFile) decodedFile = fopen(str, "rb"); if(decodedFile) { int decodedSize; fseek(decodedFile, 0, SEEK_END); decodedSize = ftell(decodedFile); if(decodedSize >= where_read + 588*4) usePartiallyDecodedFile = 1; } if(!usePartiallyDecodedFile && noTracksQueued) { if(decodedFile) fclose(decodedFile); decodedFile = NULL; break; } #ifdef _WIN32 if(!usePartiallyDecodedFile) Sleep(5); #endif // win32 if(!soundCleared && timeGetTime() - tgtime >= 125) //eliminate stutter { int Clear_Sound_Buffer(void); Clear_Sound_Buffer(); soundCleared = true; } } if(!decodedFile) decodedFile = Tracks[trackIndex].F_decoded; Waiting_For_Preload_MP3_Synchronous = false; } #endif // threaded *pDontLeaveFileOpen = usePartiallyDecodedFile; return decodedFile; }
LRESULT CALLBACK PromptWatchNameProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) //Gets the description of a watched address { RECT r; RECT r2; int dx1, dy1, dx2, dy2; switch(uMsg) { case WM_INITDIALOG: Clear_Sound_Buffer(); if (Full_Screen) { while (ShowCursor(false) >= 0); while (ShowCursor(true) < 0); } GetWindowRect(HWnd, &r); dx1 = (r.right - r.left) / 2; dy1 = (r.bottom - r.top) / 2; GetWindowRect(hDlg, &r2); dx2 = (r2.right - r2.left) / 2; dy2 = (r2.bottom - r2.top) / 2; //SetWindowPos(hDlg, NULL, max(0, r.left + (dx1 - dx2)), max(0, r.top + (dy1 - dy2)), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); strcpy(Str_Tmp,"Enter a name for this RAM address."); SendDlgItemMessage(hDlg,IDC_PROMPT_TEXT,WM_SETTEXT,0,(LPARAM)Str_Tmp); strcpy(Str_Tmp,""); SendDlgItemMessage(hDlg,IDC_PROMPT_TEXT2,WM_SETTEXT,0,(LPARAM)Str_Tmp); return true; break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: { if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } GetDlgItemText(hDlg,IDC_PROMPT_EDIT,Str_Tmp,80); InsertWatch(rswatches[WatchCount],Str_Tmp,WatchCount); DialogsOpen--; EndDialog(hDlg, true); return true; break; } case ID_CANCEL: case IDCANCEL: if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } DialogsOpen--; EndDialog(hDlg, false); return false; break; } break; case WM_CLOSE: if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } DialogsOpen--; EndDialog(hDlg, false); return false; break; } return false; }
LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT r; RECT r2; int dx1, dy1, dx2, dy2; static int watchIndex=0; switch(uMsg) { case WM_MOVE: { RECT wrect; GetWindowRect(hDlg,&wrect); ramw_x = wrect.left; ramw_y = wrect.top; break; }; case WM_INITDIALOG: { if (Full_Screen) { while (ShowCursor(false) >= 0); while (ShowCursor(true) < 0); } GetWindowRect(HWnd, &r); //Ramwatch window dx1 = (r.right - r.left) / 2; dy1 = (r.bottom - r.top) / 2; GetWindowRect(hDlg, &r2); // Gens window dx2 = (r2.right - r2.left) / 2; dy2 = (r2.bottom - r2.top) / 2; // push it away from the main window if we can const int width = (r.right-r.left); const int height = (r.bottom - r.top); const int width2 = (r2.right-r2.left); if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN)) { r.right += width; r.left += width; } else if((int)r.left - (int)width2 > 0) { r.right -= width2; r.left -= width2; } //----------------------------------------------------------------------------------- //If user has Save Window Pos selected, override default positioning if (RWSaveWindowPos) { //If ramwindow is for some reason completely off screen, use default instead if (ramw_x > (-width*2) || ramw_x < (width*2 + GetSystemMetrics(SM_CYSCREEN)) ) r.left = ramw_x; //This also ignores cases of windows -32000 error codes //If ramwindow is for some reason completely off screen, use default instead if (ramw_y > (0-height*2) ||ramw_y < (height*2 + GetSystemMetrics(SM_CYSCREEN)) ) r.top = ramw_y; //This also ignores cases of windows -32000 error codes } //------------------------------------------------------------------------------------- SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); ramwatchmenu=GetMenu(hDlg); rwrecentmenu=CreateMenu(); UpdateRW_RMenu(rwrecentmenu, RAMMENU_FILE_RECENT, RW_MENU_FIRST_RECENT_FILE); const char* names[3] = {"Address","Value","Notes"}; int widths[3] = {62,64,64+51+53}; init_list_box(GetDlgItem(hDlg,IDC_WATCHLIST),names,3,widths); if (!ResultCount) reset_address_info(); else signal_new_frame(); ListView_SetItemCount(GetDlgItem(hDlg,IDC_WATCHLIST),WatchCount); if (!noMisalign) SendDlgItemMessage(hDlg, IDC_MISALIGN, BM_SETCHECK, BST_CHECKED, 0); if (littleEndian) SendDlgItemMessage(hDlg, IDC_ENDIAN, BM_SETCHECK, BST_CHECKED, 0); RamWatchAccels = LoadAccelerators(ghInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1)); // due to some bug in windows, the arrow button width from the resource gets ignored, so we have to set it here SetWindowPos(GetDlgItem(hDlg,ID_WATCHES_UPDOWN), 0,0,0, 30,60, SWP_NOMOVE); Update_RAM_Watch(); DragAcceptFiles(hDlg, TRUE); RefreshWatchListSelectedCountControlStatus(hDlg); return true; break; } case WM_INITMENU: CheckMenuItem(ramwatchmenu, RAMMENU_FILE_AUTOLOAD, AutoRWLoad ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(ramwatchmenu, RAMMENU_FILE_SAVEWINDOW, RWSaveWindowPos ? MF_CHECKED : MF_UNCHECKED); break; case WM_MENUSELECT: case WM_ENTERSIZEMOVE: Clear_Sound_Buffer(); break; case WM_NOTIFY: { LPNMHDR lP = (LPNMHDR) lParam; switch (lP->code) { case LVN_ITEMCHANGED: // selection changed event { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lP; if(pNMListView->uNewState & LVIS_FOCUSED || (pNMListView->uNewState ^ pNMListView->uOldState) & LVIS_SELECTED) { // disable buttons that we don't have the right number of selected items for RefreshWatchListSelectedCountControlStatus(hDlg); } } break; case LVN_GETDISPINFO: { LV_DISPINFO *Item = (LV_DISPINFO *)lParam; Item->item.mask = LVIF_TEXT; Item->item.state = 0; Item->item.iImage = 0; const unsigned int iNum = Item->item.iItem; static char num[11]; switch (Item->item.iSubItem) { case 0: sprintf(num,"%08X",rswatches[iNum].Address); Item->item.pszText = num; return true; case 1: { int i = rswatches[iNum].CurValue; int t = rswatches[iNum].Type; int size = rswatches[iNum].Size; const char* formatString = ((t=='s') ? "%d" : (t=='u') ? "%u" : (size=='d' ? "%08X" : size=='w' ? "%04X" : "%02X")); switch (size) { case 'b': default: sprintf(num, formatString, t=='s' ? (char)(i&0xff) : (unsigned char)(i&0xff)); break; case 'w': sprintf(num, formatString, t=='s' ? (short)(i&0xffff) : (unsigned short)(i&0xffff)); break; case 'd': sprintf(num, formatString, t=='s' ? (long)(i&0xffffffff) : (unsigned long)(i&0xffffffff)); break; } Item->item.pszText = num; } return true; case 2: Item->item.pszText = rswatches[iNum].comment ? rswatches[iNum].comment : ""; return true; default: return false; } } case LVN_ODFINDITEM: { // disable search by keyboard typing, // because it interferes with some of the accelerators // and it isn't very useful here anyway SetWindowLong(hDlg, DWL_MSGRESULT, ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST))); return 1; } } } break; case WM_COMMAND: switch(LOWORD(wParam)) { case RAMMENU_FILE_SAVE: QuickSaveWatches(); break; case RAMMENU_FILE_SAVEAS: //case IDC_C_SAVE: return Save_Watches(); case RAMMENU_FILE_OPEN: return Load_Watches(true); case RAMMENU_FILE_APPEND: //case IDC_C_LOAD: return Load_Watches(false); case RAMMENU_FILE_NEW: //case IDC_C_RESET: ResetWatches(); return true; case IDC_C_WATCH_REMOVE: { HWND watchListControl = GetDlgItem(hDlg, IDC_WATCHLIST); watchIndex = ListView_GetNextItem(watchListControl, -1, LVNI_ALL | LVNI_SELECTED); while (watchIndex >= 0) { RemoveWatch(watchIndex); ListView_DeleteItem(watchListControl, watchIndex); watchIndex = ListView_GetNextItem(watchListControl, -1, LVNI_ALL | LVNI_SELECTED); } RWfileChanged=true; SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST)); return true; } case IDC_C_WATCH_EDIT: watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST)); DialogBoxParam(ghInstance, MAKEINTRESOURCE(IDD_EDITWATCH), hDlg, (DLGPROC) EditWatchProc,(LPARAM) watchIndex); SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST)); return true; case IDC_C_WATCH: rswatches[WatchCount].Address = rswatches[WatchCount].WrongEndian = 0; rswatches[WatchCount].Size = 'b'; rswatches[WatchCount].Type = 's'; DialogBoxParam(ghInstance, MAKEINTRESOURCE(IDD_EDITWATCH), hDlg, (DLGPROC) EditWatchProc,(LPARAM) WatchCount); SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST)); return true; case IDC_C_WATCH_DUPLICATE: watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST)); rswatches[WatchCount].Address = rswatches[watchIndex].Address; rswatches[WatchCount].WrongEndian = rswatches[watchIndex].WrongEndian; rswatches[WatchCount].Size = rswatches[watchIndex].Size; rswatches[WatchCount].Type = rswatches[watchIndex].Type; DialogBoxParam(ghInstance, MAKEINTRESOURCE(IDD_EDITWATCH), hDlg, (DLGPROC) EditWatchProc,(LPARAM) WatchCount); SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST)); return true; case IDC_C_WATCH_SEPARATE: AddressWatcher separator; separator.Address = 0; separator.WrongEndian = false; separator.Size = 'S'; separator.Type = 'S'; InsertWatch(separator, "----------------------------",WatchCount); SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST)); return true; case IDC_C_WATCH_UP: { watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST)); if (watchIndex == 0 || watchIndex == -1) return true; void *tmp = malloc(sizeof(AddressWatcher)); memcpy(tmp,&(rswatches[watchIndex]),sizeof(AddressWatcher)); memcpy(&(rswatches[watchIndex]),&(rswatches[watchIndex - 1]),sizeof(AddressWatcher)); memcpy(&(rswatches[watchIndex - 1]),tmp,sizeof(AddressWatcher)); free(tmp); ListView_SetItemState(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex,0,LVIS_FOCUSED|LVIS_SELECTED); ListView_SetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex-1); ListView_SetItemState(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex-1,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED); ListView_SetItemCount(GetDlgItem(hDlg,IDC_WATCHLIST),WatchCount); RWfileChanged=true; return true; } case IDC_C_WATCH_DOWN: { watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST)); if (watchIndex >= WatchCount - 1 || watchIndex == -1) return true; void *tmp = malloc(sizeof(AddressWatcher)); memcpy(tmp,&(rswatches[watchIndex]),sizeof(AddressWatcher)); memcpy(&(rswatches[watchIndex]),&(rswatches[watchIndex + 1]),sizeof(AddressWatcher)); memcpy(&(rswatches[watchIndex + 1]),tmp,sizeof(AddressWatcher)); free(tmp); ListView_SetItemState(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex,0,LVIS_FOCUSED|LVIS_SELECTED); ListView_SetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex+1); ListView_SetItemState(GetDlgItem(hDlg,IDC_WATCHLIST),watchIndex+1,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED); ListView_SetItemCount(GetDlgItem(hDlg,IDC_WATCHLIST),WatchCount); RWfileChanged=true; return true; } case ID_WATCHES_UPDOWN: { int delta = ((LPNMUPDOWN)lParam)->iDelta; SendMessage(hDlg, WM_COMMAND, delta<0 ? IDC_C_WATCH_UP : IDC_C_WATCH_DOWN,0); break; } case RAMMENU_FILE_AUTOLOAD: { AutoRWLoad ^= 1; CheckMenuItem(ramwatchmenu, RAMMENU_FILE_AUTOLOAD, AutoRWLoad ? MF_CHECKED : MF_UNCHECKED); break; } case RAMMENU_FILE_SAVEWINDOW: { RWSaveWindowPos ^=1; CheckMenuItem(ramwatchmenu, RAMMENU_FILE_SAVEWINDOW, RWSaveWindowPos ? MF_CHECKED : MF_UNCHECKED); break; } case IDC_C_ADDCHEAT: { // watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST)) | (1 << 24); // DialogBoxParam(ghInstance, MAKEINTRESOURCE(IDD_EDITCHEAT), hDlg, (DLGPROC) EditCheatProc,(LPARAM) searchIndex); } case IDOK: case IDCANCEL: if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } DialogsOpen--; RamWatchHWnd = NULL; DragAcceptFiles(hDlg, FALSE); EndDialog(hDlg, true); return true; default: if (LOWORD(wParam) >= RW_MENU_FIRST_RECENT_FILE && LOWORD(wParam) < RW_MENU_FIRST_RECENT_FILE+MAX_RECENT_WATCHES) OpenRWRecentFile(LOWORD(wParam) - RW_MENU_FIRST_RECENT_FILE); } break; case WM_KEYDOWN: // handle accelerator keys { SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST)); MSG msg; msg.hwnd = hDlg; msg.message = uMsg; msg.wParam = wParam; msg.lParam = lParam; if(RamWatchAccels && TranslateAccelerator(hDlg, RamWatchAccels, &msg)) return true; } break; case WM_CLOSE: if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } DialogsOpen--; RamWatchHWnd = NULL; DragAcceptFiles(hDlg, FALSE); EndDialog(hDlg, true); return true; case WM_DROPFILES: { HDROP hDrop = (HDROP)wParam; DragQueryFile(hDrop, 0, Str_Tmp, 1024); DragFinish(hDrop); return Load_Watches(true, Str_Tmp); } break; } return false; }
//Gets info for a RAM Watch (or multiple watches using a range or steps), and then inserts it into the Watch List LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT r; RECT r2; int dx1, dy1, dx2, dy2; static int index; static char s,t = s = 0; //s: data size (byte/word/doubleword). t=display type (signed/unsigned/hex) switch(uMsg) { case WM_INITDIALOG: Clear_Sound_Buffer(); if (Full_Screen) { while (ShowCursor(false) >= 0); while (ShowCursor(true) < 0); } GetWindowRect(HWnd, &r); dx1 = (r.right - r.left) / 2; dy1 = (r.bottom - r.top) / 2; GetWindowRect(hDlg, &r2); dx2 = (r2.right - r2.left) / 2; dy2 = (r2.bottom - r2.top) / 2; //SetWindowPos(hDlg, NULL, max(0, r.left + (dx1 - dx2)), max(0, r.top + (dy1 - dy2)), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); index = (int)lParam; if (index < WatchCount) // disable range and step input when editing an existing watch { EnableWindow(GetDlgItem(hDlg, (int)IDC_EDIT_COMPAREADDRESSRANGE), FALSE); EnableWindow(GetDlgItem(hDlg, (int)IDC_EDIT_COMPAREADDRESSSTEP), FALSE); EnableWindow(GetDlgItem(hDlg, (int)IDC_EDIT_COMPAREADDRESSSTEPCOUNT), FALSE); } sprintf(Str_Tmp,"%08X",rswatches[index].Address); SetDlgItemText(hDlg,IDC_EDIT_COMPAREADDRESS,Str_Tmp); if (rswatches[index].comment != NULL) SetDlgItemText(hDlg,IDC_PROMPT_EDIT,rswatches[index].comment); s = rswatches[index].Size; t = rswatches[index].Type; switch (s) // data size { case 'b': SendDlgItemMessage(hDlg, IDC_1_BYTE, BM_SETCHECK, BST_CHECKED, 0); break; case 'w': SendDlgItemMessage(hDlg, IDC_2_BYTES, BM_SETCHECK, BST_CHECKED, 0); break; case 'd': SendDlgItemMessage(hDlg, IDC_4_BYTES, BM_SETCHECK, BST_CHECKED, 0); break; default: s = 0; break; } switch (t) // display type { case 's': SendDlgItemMessage(hDlg, IDC_SIGNED, BM_SETCHECK, BST_CHECKED, 0); break; case 'u': SendDlgItemMessage(hDlg, IDC_UNSIGNED, BM_SETCHECK, BST_CHECKED, 0); break; case 'h': SendDlgItemMessage(hDlg, IDC_HEX, BM_SETCHECK, BST_CHECKED, 0); break; default: t = 0; break; } return true; break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_SIGNED: t='s'; return true; case IDC_UNSIGNED: t='u'; return true; case IDC_HEX: t='h'; return true; case IDC_1_BYTE: s = 'b'; return true; case IDC_2_BYTES: s = 'w'; return true; case IDC_4_BYTES: s = 'd'; return true; case IDC_BTN_HELP: MessageBox(hDlg, "Edit Watch Help\n" "-----------------\n" "Basic Usage:\n" "Enter an Address to watch. Example: FF1234. " "Select the size of the data: 1, 2, or 4 bytes. Select the display type of the data: signed, unsigned, or hexadecimal. Optionally, add a note.\n" "\n" "Advanced Usage:\n" "Note that all the advanced options are specified in decimal values, not hexadecimal.\n" "There are 3 other ways to add watches.\n" "1) Specify an Offset, and a watch will be created for the address at Address+Offset.\n" "2) Specify a Range Length, and multiple watches will be created, covering all memory from Address to Address+Length-1.\n" "3) Specify a Step, Step Count, and (optionally) an Offset, and Step Count watches will be created, the first at Address+Offset+(1*Step), the second at Address+Offset+(2*Step), and so on. This is useful for watching arrays of structures." ,"Help",MB_OK | MB_ICONINFORMATION); return true; case IDOK: { if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } if (s && t) { AddressWatcher Temp; Temp.Size = s; Temp.Type = t; Temp.WrongEndian = false; //replace this when I get little endian working properly unsigned int watchAddress = 0; int rangeSize = 0; // use int (signed) so we can protect against negatives int offset = 0; int step = 0; int stepCount = 0; unsigned int sval; // byte = 1, word = 2, doubleword = 4 int tmp; watchAddress = GetDlgItemTextAsInt(hDlg, IDC_EDIT_COMPAREADDRESS, 8, 'h'); rangeSize = GetDlgItemTextAsInt(hDlg, IDC_EDIT_COMPAREADDRESSRANGE, 4, 'd'); offset = GetDlgItemTextAsInt(hDlg, IDC_EDIT_COMPAREADDRESSOFFSET, 4, 'd'); step = GetDlgItemTextAsInt(hDlg, IDC_EDIT_COMPAREADDRESSSTEP, 4, 'd'); stepCount = GetDlgItemTextAsInt(hDlg, IDC_EDIT_COMPAREADDRESSSTEPCOUNT, 4, 'd'); GetDlgItemText(hDlg,IDC_PROMPT_EDIT,Str_Tmp,80); switch(Temp.Size) { case 'b': sval = 1; break; case 'w': sval = 2; break; case 'd': sval = 4; break; } /* * Three different methods: * 1. single address: base address + offset(optional) * 2. range: base address to base address + range size - 1 * 3. step: base address + offset + step * (for 0 to stepcount-1) * which method to use is decided based on what parameters were supplied with non-zero values. */ if (!rangeSize && !step) { watchAddress += offset; if (!ValidateAndAddWatch(hDlg, watchAddress, Temp, Str_Tmp, index)) { sprintf(Str_Tmp, "Invalid Address: %X", watchAddress); MessageBox(hDlg,Str_Tmp,"ERROR",MB_OK | MB_ICONSTOP); } } else if (rangeSize) { for (int rangeval = 0; rangeval < rangeSize; rangeval += sval) { tmp = strlen(Str_Tmp); sprintf(Str_Tmp, "%s [%d]", Str_Tmp, rangeval); if (!ValidateAndAddWatch(hDlg, watchAddress + rangeval, Temp, Str_Tmp, index)) { sprintf(Str_Tmp, "Invalid Address: %X (%#X in range)", watchAddress + rangeval, rangeval); MessageBox(hDlg,Str_Tmp,"ERROR",MB_OK | MB_ICONSTOP); break; } index++; Str_Tmp[tmp] = '\0'; } } else // step method { watchAddress += offset; for (int stepval = 0; stepval < stepCount; stepval++) { tmp = strlen(Str_Tmp); sprintf(Str_Tmp, "%s [step %d]", Str_Tmp, stepval); if (!ValidateAndAddWatch(hDlg, watchAddress + step*stepval, Temp, Str_Tmp, index)) { sprintf(Str_Tmp, "Invalid Address: %X (step number %d)", watchAddress + step*stepval, stepval); MessageBox(hDlg,Str_Tmp,"ERROR",MB_OK | MB_ICONSTOP); break; } index++; Str_Tmp[tmp] = '\0'; } } /* Even if something goes wrong (Invalid Address error), we will close the dialog. * This way, if the error happens after part of a range or stepping is completed, the user can see how far things got before the error by seeing the watches that got added. * Better ways this could be handled: If the first watch added fails, we don't close the dialog (need a way to track this). * Or maybe remove all the newly added watches, show user which address was bad, and leave dialog open.. */ DialogsOpen--; EndDialog(hDlg, true); } else { strcpy(Str_Tmp,"Error:"); if (!s) strcat(Str_Tmp," Size must be specified."); if (!t) strcat(Str_Tmp," Type must be specified."); MessageBox(hDlg,Str_Tmp,"ERROR",MB_OK); } RWfileChanged=true; return true; break; } case ID_CANCEL: case IDCANCEL: if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } DialogsOpen--; EndDialog(hDlg, false); return false; break; } break; case WM_CLOSE: if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } DialogsOpen--; EndDialog(hDlg, false); return false; break; } return false; }
LRESULT CALLBACK LuaScriptProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT r; RECT r2; int dx1, dy1, dx2, dy2; switch(uMsg) { case WM_INITDIALOG: { if(std::find(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg) == LuaScriptHWnds.end()) { LuaScriptHWnds.push_back(hDlg); Build_Main_Menu(); } if (Full_Screen) { while (ShowCursor(false) >= 0); while (ShowCursor(true) < 0); } HANDLE hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_LUA)); SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); // remove the 30000 character limit from the console control SendMessage(GetDlgItem(hDlg, IDC_LUACONSOLE),EM_LIMITTEXT,0,0); GetWindowRect(HWnd, &r); dx1 = (r.right - r.left) / 2; dy1 = (r.bottom - r.top) / 2; GetWindowRect(hDlg, &r2); dx2 = (r2.right - r2.left) / 2; dy2 = (r2.bottom - r2.top) / 2; int windowIndex = std::find(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg) - LuaScriptHWnds.begin(); int staggerOffset = windowIndex * 24; r.left += staggerOffset; r.right += staggerOffset; r.top += staggerOffset; r.bottom += staggerOffset; // push it away from the main window if we can const int width = (r.right-r.left); const int width2 = (r2.right-r2.left); if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN)) { r.right += width; r.left += width; } else if((int)r.left - (int)width2 > 0) { r.right -= width2; r.left -= width2; } SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); LuaPerWindowInfo info; { RECT r3; GetClientRect(hDlg, &r3); info.width = r3.right - r3.left; info.height = r3.bottom - r3.top; } LuaWindowInfo[hDlg] = info; RegisterWatcherThread(hDlg); OpenLuaContext((int)hDlg, PrintToWindowConsole, OnStart, OnStop); DragAcceptFiles(hDlg, TRUE); return true; } break; case WM_MENUSELECT: case WM_ENTERSIZEMOVE: Clear_Sound_Buffer(); break; case WM_SIZING: { // enforce a minimum window size LPRECT r = (LPRECT) lParam; int minimumWidth = 333; int minimumHeight = 117; if(r->right - r->left < minimumWidth) if(wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT || wParam == WMSZ_BOTTOMLEFT) r->left = r->right - minimumWidth; else r->right = r->left + minimumWidth; if(r->bottom - r->top < minimumHeight) if(wParam == WMSZ_TOP || wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOPRIGHT) r->top = r->bottom - minimumHeight; else r->bottom = r->top + minimumHeight; } return TRUE; case WM_SIZE: { // resize or move controls in the window as necessary when the window is resized LuaPerWindowInfo& windowInfo = LuaWindowInfo[hDlg]; int prevDlgWidth = windowInfo.width; int prevDlgHeight = windowInfo.height; int dlgWidth = LOWORD(lParam); int dlgHeight = HIWORD(lParam); int deltaWidth = dlgWidth - prevDlgWidth; int deltaHeight = dlgHeight - prevDlgHeight; for(int i = 0; i < numControlLayoutInfos; i++) { ControlLayoutInfo layoutInfo = controlLayoutInfos[i]; ControlLayoutState& layoutState = windowInfo.layoutState[i]; HWND hCtrl = GetDlgItem(hDlg,layoutInfo.controlID); int x,y,width,height; if(layoutState.valid) { x = layoutState.x; y = layoutState.y; width = layoutState.width; height = layoutState.height; } else { RECT r; GetWindowRect(hCtrl, &r); POINT p = {r.left, r.top}; ScreenToClient(hDlg, &p); x = p.x; y = p.y; width = r.right - r.left; height = r.bottom - r.top; } switch(layoutInfo.horizontalLayout) { case ControlLayoutInfo::RESIZE_END: width += deltaWidth; break; case ControlLayoutInfo::MOVE_START: x += deltaWidth; break; default: break; } switch(layoutInfo.verticalLayout) { case ControlLayoutInfo::RESIZE_END: height += deltaHeight; break; case ControlLayoutInfo::MOVE_START: y += deltaHeight; break; default: break; } SetWindowPos(hCtrl, 0, x,y, width,height, 0); layoutState.x = x; layoutState.y = y; layoutState.width = width; layoutState.height = height; layoutState.valid = true; } windowInfo.width = dlgWidth; windowInfo.height = dlgHeight; RedrawWindow(hDlg, NULL, NULL, RDW_INVALIDATE); } break; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDC_BUTTON_LUABROWSE: { LuaPerWindowInfo& info = LuaWindowInfo[hDlg]; char Str_Tmp [1024]; // shadow added because the global one is unreliable strcpy(Str_Tmp,info.filename.c_str()); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_GETTEXT,(WPARAM)512,(LPARAM)Str_Tmp); char* bar = strchr(Str_Tmp, '|'); if(bar) *bar = '\0'; DialogsOpen++; Clear_Sound_Buffer(); if(Change_File_L(Str_Tmp, Lua_Dir, "Load Lua Script", "Gens Lua Script\0*.lua*\0All Files\0*.*\0\0", "lua", hDlg)) { SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)Str_Tmp); } DialogsOpen--; } break; case IDC_BUTTON_LUAEDIT: { LuaPerWindowInfo& info = LuaWindowInfo[hDlg]; char Str_Tmp [1024]; // shadow added because the global one is unreliable strcpy(Str_Tmp,info.filename.c_str()); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_GETTEXT,(WPARAM)512,(LPARAM)Str_Tmp); char LogicalName[1024], PhysicalName[1024]; bool exists = ObtainFile(Str_Tmp, LogicalName, PhysicalName, "luaview", s_nonLuaExtensions, sizeof(s_nonLuaExtensions)/sizeof(*s_nonLuaExtensions)); bool created = false; if(!exists) { FILE* file = fopen(Str_Tmp, "r"); if(!file) { file = fopen(Str_Tmp, "w"); if(file) { created = true; exists = true; strcpy(PhysicalName, Str_Tmp); } } if(file) fclose(file); } if(exists) { // tell the OS to open the file with its associated editor, // without blocking on it or leaving a command window open. if((int)ShellExecute(NULL, "edit", PhysicalName, NULL, NULL, SW_SHOWNORMAL) == SE_ERR_NOASSOC) if((int)ShellExecute(NULL, "open", PhysicalName, NULL, NULL, SW_SHOWNORMAL) == SE_ERR_NOASSOC) ShellExecute(NULL, NULL, "notepad", PhysicalName, NULL, SW_SHOWNORMAL); } if(created) { UpdateFileEntered(hDlg); } } break; case IDC_EDIT_LUAPATH: { switch(HIWORD(wParam)) { case EN_CHANGE: { UpdateFileEntered(hDlg); } break; } } break; case IDC_BUTTON_LUARUN: { HWND focus = GetFocus(); HWND textbox = GetDlgItem(hDlg, IDC_EDIT_LUAPATH); if(focus != textbox) SetActiveWindow(HWnd); LuaPerWindowInfo& info = LuaWindowInfo[hDlg]; char Str_Tmp [1024]; // shadow added because the global one is completely unreliable strcpy(Str_Tmp,info.filename.c_str()); char LogicalName[1024], PhysicalName[1024]; bool exists = ObtainFile(Str_Tmp, LogicalName, PhysicalName, "luarun", s_nonLuaExtensions, sizeof(s_nonLuaExtensions)/sizeof(*s_nonLuaExtensions)); Update_Recent_Script(LogicalName, info.subservient); RunLuaScriptFile((int)hDlg, PhysicalName); } break; case IDC_BUTTON_LUASTOP: { PrintToWindowConsole((int)hDlg, "user clicked stop button\r\n"); SetActiveWindow(HWnd); StopLuaScript((int)hDlg); } break; case IDC_NOTIFY_SUBSERVIENT: { LuaPerWindowInfo& info = LuaWindowInfo[hDlg]; info.subservient = lParam ? true : false; } break; //case IDOK: case IDCANCEL: { LuaPerWindowInfo& info = LuaWindowInfo[hDlg]; if(info.filename.empty()) { if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } DialogsOpen--; DragAcceptFiles(hDlg, FALSE); KillWatcherThread(hDlg); LuaScriptHWnds.erase(remove(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg), LuaScriptHWnds.end()); LuaWindowInfo.erase(hDlg); CloseLuaContext((int)hDlg); Build_Main_Menu(); EndDialog(hDlg, true); } } return true; } return false; } break; case WM_CLOSE: { LuaPerWindowInfo& info = LuaWindowInfo[hDlg]; PrintToWindowConsole((int)hDlg, "user closed script window\r\n"); StopLuaScript((int)hDlg); if(info.started) { // not stopped yet, wait to close until we are, otherwise we'll crash info.closeOnStop = true; return false; } if (Full_Screen) { while (ShowCursor(true) < 0); while (ShowCursor(false) >= 0); } DialogsOpen--; DragAcceptFiles(hDlg, FALSE); KillWatcherThread(hDlg); LuaScriptHWnds.erase(remove(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg), LuaScriptHWnds.end()); LuaWindowInfo.erase(hDlg); CloseLuaContext((int)hDlg); Build_Main_Menu(); EndDialog(hDlg, true); } return true; case WM_DROPFILES: { HDROP hDrop = (HDROP)wParam; DragQueryFile(hDrop, 0, Str_Tmp, 1024); DragFinish(hDrop); SendDlgItemMessage(hDlg,IDC_EDIT_LUAPATH,WM_SETTEXT,0,(LPARAM)Str_Tmp ); UpdateFileEntered(hDlg); } return true; } return false; }