@@ -134,8 +134,32 @@ private static void CreateCommandScript(string protocolName)
134134 " if not \" %%B\" ==\" \" set \" cmdline=!cmdline!%%B\" " ,
135135 " )" ,
136136 " echo [%date% %time%] Raw command line: !cmdline! >> \" %LOG_PATH%\" " ,
137+ " REM Try multiple path formats to handle Unity's various command line formats" ,
138+ " set \" MATCH_FOUND=0\" " ,
139+ " " ,
140+ " REM Try 1: Exact match with backslashes" ,
137141 " echo !cmdline! | findstr /I /C:\" -projectPath\" | findstr /I /C:\" %PROJECT_PATH%\" >nul" ,
138- " if not errorlevel 1 (" ,
142+ " if not errorlevel 1 set \" MATCH_FOUND=1\" " ,
143+ " " ,
144+ " REM Try 2: Forward slashes if backslashes didn't match" ,
145+ " if \" !MATCH_FOUND!\" ==\" 0\" (" ,
146+ " set \" PROJECT_PATH_FORWARD=%PROJECT_PATH:\\ =/%\" " ,
147+ " echo [%date% %time%] Trying forward slash path: !PROJECT_PATH_FORWARD! >> \" %LOG_PATH%\" " ,
148+ " echo !cmdline! | findstr /I /C:\" -projectPath\" | findstr /I /C:\" !PROJECT_PATH_FORWARD!\" >nul" ,
149+ " if not errorlevel 1 set \" MATCH_FOUND=1\" " ,
150+ " )" ,
151+ " " ,
152+ " REM Try 3: With quotes around paths" ,
153+ " if \" !MATCH_FOUND!\" ==\" 0\" (" ,
154+ " echo [%date% %time%] Trying quoted paths >> \" %LOG_PATH%\" " ,
155+ " echo !cmdline! | findstr /I /C:\" -projectPath \\ \" !PROJECT_PATH!\\ \" \" >nul" ,
156+ " if not errorlevel 1 set \" MATCH_FOUND=1\" " ,
157+ " if \" !MATCH_FOUND!\" ==\" 0\" (" ,
158+ " echo !cmdline! | findstr /I /C:\" -projectPath \\ \" !PROJECT_PATH_FORWARD!\\ \" \" >nul" ,
159+ " if not errorlevel 1 set \" MATCH_FOUND=1\" " ,
160+ " )" ,
161+ " )" ,
162+ " if \" !MATCH_FOUND!\" ==\" 1\" (" ,
139163 " echo [%date% %time%] Found matching Unity process ID: %%A >> \" %LOG_PATH%\" " ,
140164 " echo [%date% %time%] Command line: !cmdline! >> \" %LOG_PATH%\" " ,
141165 " powershell -NoProfile -ExecutionPolicy Bypass -Command ^" ,
@@ -161,7 +185,7 @@ private static void CreateCommandScript(string protocolName)
161185 $ "echo [%date% %time%] Starting new Unity instance >> \" %LOG_PATH%\" ",
162186 $ "start \" \" \" { unityExe } \" -projectPath \" %PROJECT_PATH%\" >nul 2>&1"
163187 } ;
164-
188+
165189 File . WriteAllLines ( cmdPath , scriptLines ) ;
166190 PassportLogger . Debug ( $ "Writing script to { cmdPath } ") ;
167191 PassportLogger . Debug ( $ "Writing logs to { logPath } ") ;
@@ -198,7 +222,7 @@ private static void CreateCommandScript(string protocolName)
198222 private static void RegisterProtocol ( string protocolName )
199223 {
200224 PassportLogger . Debug ( $ "Register protocol: { protocolName } ") ;
201-
225+
202226 UIntPtr hKey ;
203227 uint disposition ;
204228 // Create registry key for the protocol
@@ -214,14 +238,14 @@ private static void RegisterProtocol(string protocolName)
214238 out disposition ) ;
215239
216240 if ( result != 0 )
217- {
241+ {
218242 throw new Exception ( $ "Failed to create PKCE registry key. Error code: { result } ") ;
219243 }
220244
221245 // Set the default value for the protocol key to Application.productName
222246 // This is often used by Windows as the display name for the protocol
223247 var appProductName = Application . productName ;
224- var productNameDataSize = ( uint ) ( ( appProductName . Length + 1 ) * Marshal . SystemDefaultCharSize ) ;
248+ var productNameDataSize = ( uint ) ( ( appProductName . Length + 1 ) * Marshal . SystemDefaultCharSize ) ;
225249 var setDefaultResult = RegSetValueEx ( hKey , null , 0 , REG_SZ , appProductName , productNameDataSize ) ;
226250
227251 if ( setDefaultResult != 0 )
@@ -230,7 +254,7 @@ private static void RegisterProtocol(string protocolName)
230254 }
231255
232256 // Set URL Protocol value
233- RegSetValueEx ( hKey , "URL Protocol" , 0 , REG_SZ , string . Empty , ( uint ) ( 1 * Marshal . SystemDefaultCharSize ) ) ;
257+ RegSetValueEx ( hKey , "URL Protocol" , 0 , REG_SZ , string . Empty , ( uint ) ( 1 * Marshal . SystemDefaultCharSize ) ) ;
234258
235259 // Create command subkey
236260 UIntPtr commandKey ;
@@ -246,7 +270,7 @@ private static void RegisterProtocol(string protocolName)
246270 out disposition ) ;
247271
248272 if ( result != 0 )
249- {
273+ {
250274 RegCloseKey ( hKey ) ;
251275 throw new Exception ( $ "Failed to create PKCE command registry key. Error code: { result } ") ;
252276 }
@@ -255,7 +279,7 @@ private static void RegisterProtocol(string protocolName)
255279 var scriptLocation = GetGameExecutablePath ( ".cmd" ) ;
256280 string command = $ "\" { scriptLocation } \" \" %1\" ";
257281 uint commandSize = ( uint ) ( ( command . Length + 1 ) * 2 ) ;
258-
282+
259283 result = RegSetValueEx ( commandKey , "" , 0 , REG_SZ , command , commandSize ) ;
260284 if ( result != 0 )
261285 {
@@ -268,7 +292,7 @@ private static void RegisterProtocol(string protocolName)
268292 RegCloseKey ( commandKey ) ;
269293 RegCloseKey ( hKey ) ;
270294 }
271-
295+
272296 private static string GetGameExecutablePath ( string suffix )
273297 {
274298#if ! UNITY_EDITOR_WIN
0 commit comments