Code: Select all
612369f106bdc4d79c4f8727e68484bf046f5c11
 win32/win32.cpp |   26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/win32/win32.cpp b/win32/win32.cpp
index 7d4a52f..3492280 100644
--- a/win32/win32.cpp
+++ b/win32/win32.cpp
@@ -611,16 +611,28 @@ void S9xSyncSpeed( void)
 
 const char *S9xBasename (const char *f)
 {
-    const char *p;
-    if ((p = strrchr (f, '/')) != NULL || (p = strrchr (f, '\\')) != NULL)
-	return (p + 1);
+	const char *p = f;
+	const char *last = p;
+	const char *slash;
 
-#ifdef __DJGPP
-    if (p = _tcsrchr (f, SLASH_CHAR))
-	return (p + 1);
+	// search rightmost separator
+	while ((slash = strchr (p, '/')) != NULL || (slash = strchr (p, '\\')) != NULL)
+	{
+		p = slash + 1;
+
+#ifdef UNICODE
+		// update always; UTF-8 doesn't have a problem between ASCII character and multi-byte character.
+		last = p;
+#else
+		// update if it's not a trailer byte of a double-byte character.
+		if (CharPrev(f, p) == slash)
+		{
+			last = p;
+		}
 #endif
+	}
 
-    return (f);
+	return last;
 }
 
 bool8 S9xReadMousePosition (int which, int &x, int &y, uint32 &buttons)
Code: Select all
a1a3cfc986062cacc72ac158f13e1d01bf64a6e5
 win32/wsnes9x.cpp |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp
index 694338f..66c794b 100644
--- a/win32/wsnes9x.cpp
+++ b/win32/wsnes9x.cpp
@@ -9613,16 +9613,7 @@ INT_PTR CALLBACK DlgCheatSearch(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPara
 					}
 					cht.format=val_type;
 					//invoke dialog
-					if(!DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHEAT_FROM_SEARCH), hDlg, DlgCheatSearchAdd, (LPARAM)&cht))
-					{
-						int p;
-						for(p=0; p<cht.size; p++)
-						{
-							S9xAddCheat(TRUE, cht.saved, cht.address +p, ((cht.new_val>>(8*p))&0xFF));
-							//add cheat
-							strcpy(Cheat.c[Cheat.num_cheats-1].name, cht.name);
-						}
-					}
+					DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHEAT_FROM_SEARCH), hDlg, DlgCheatSearchAdd, (LPARAM)&cht);
 				}
 				break;
 			case IDC_C_RESET:
@@ -10132,8 +10123,11 @@ INT_PTR CALLBACK DlgCheatSearchAdd(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP
 						strncpy(new_cheat->name,_tToChar(tempBuf),22);
 
 						new_cheat->enabled=TRUE;
-						S9xAddCheat(new_cheat->enabled,new_cheat->saved_val,new_cheat->address,new_cheat->new_val);
-						strcpy(Cheat.c[Cheat.num_cheats-1].name,new_cheat->name);
+						for(int byteIndex = 0; byteIndex < new_cheat->size; byteIndex++)
+						{
+							S9xAddCheat(new_cheat->enabled,new_cheat->saved_val,new_cheat->address+byteIndex,(new_cheat->new_val>>(8*byteIndex))&0xFF);
+							strcpy(Cheat.c[Cheat.num_cheats-1].name,new_cheat->name);
+						}
 						ret=0;
 					}
 				}
