Friedslick6

CrashEditExportScript

Sep 27th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;This script automates the export of all items in all model/animation/scenery entries, in each NSF archive in the script's directory, for each game.
  2. #SingleInstance Force ;Disable running more than one instance of the script
  3. #MaxThreadsPerHotkey, 2 ;Set an additional thread for pause detection
  4. #NoEnv ;Disable checking if variables are environment variables
  5. DllCall("QueryPerformanceFrequency","Int64*",Frequency) ;Retrieve the performance counter frequency
  6. FSO:=ComObjCreate("Scripting.FileSystemObject") ;Call the FileSystemObject
  7. SetBatchLines -1 ;Remove the command delay
  8. SetControlDelay -1 ;Remove the control input delay
  9. SendMode InputThenPlay ;Make the script's inputs a higher priority than the user's inputs
  10. Multiplier:=1 ;Set the specific command delay multiplier
  11. SetWorkingDir % A_ScriptDir ;Set the working directory relative to the script's directory
  12. CrashEdit:="ahk_exe CrashEdit.exe" ;Simplify the CrashEdit window checking commands
  13. If !FileExist("CrashEdit.exe") ;If CrashEdit is missing:
  14. {
  15.     MsgBox 48,Error,"CrashEdit.exe" was not found.`nThe script will now exit. ;Wait for confirmation
  16.     Gosub Exit ;Stop the script (line 417)
  17. }
  18. If !FileExist("Entry IDs") ;If the "Entry IDs" directory is missing:
  19. {
  20.     MsgBox 48,Error,The "Entry IDs" directory was not found.`nThe script will now exit. ;Wait for confirmation
  21.     Gosub Exit ;Stop the script (line 417)
  22. }
  23. Suspend ;Disable the pause key
  24. MsgBox 1,CrashEdit Multi-Export Script,Input can be paused by pressing the P key. ;Wait for confirmation
  25.     IfMsgBox Cancel ;If the user clicks the "Cancel" button or closes the message box,
  26.         Gosub Exit ;Stop the script (line 417)
  27. BlockInput On ;Disable input
  28. Input:=!Input ;Toggle the input status
  29. Suspend ;Enable the pause key
  30. FileCreateDir % "Archives" ;Create the "Archives" directory (if it does not already exist)
  31. If WinExist(CrashEdit) ;If any CrashEdit instances exist,
  32.     Loop ;For each CrashEdit instance:
  33.         Process Close,CrashEdit.exe ;Force close the most recent one,
  34.     Until !WinExist(CrashEdit) ;Until none remain
  35. Gosub Start ;Start CrashEdit (line 301)
  36. Loop Files,%A_WorkingDir%\*.NSF,F ;For each archive:
  37. {
  38.     Loop 3 ;For each game version:
  39.         If SubStr(A_LoopFileName,3,3)="CB" . A_Index ;If the archive name contains the game,
  40.             Game:=9-A_Index ;Set the appropriate game choice variable
  41.     If Game=8 ;If the game is CB1,
  42.         Loop Parse,% "Beta|Demo",| ;For each sub-version:
  43.             If InStr(A_LoopFileName,A_LoopField) ;If the archive name contains a sub-version,
  44.                 Game:=6-A_Index ;Set the appropriate game choice variable
  45.     If Game=7&&InStr(A_LoopFileName,"Beta") ;If the game is CB2 and the archive name contains the Beta sub-version,
  46.         Game:=3 ;Set the appropriate game choice variable
  47.     Gosub Open ;Open the current archive (line 317)
  48.     Loop Parse,% "T1 Entry|Model Entry|Scenery Entry",| ;For each query:
  49.     {
  50.         Subsystem:=(A_LoopField="T1 Entry")?"SVTX":(A_LoopField="Model Entry")?"TGEO":(A_LoopField="Scenery Entry")?"WGEO": ;Set the subsystem according to the current query
  51.         Type:=(Subsystem="SVTX")?"frame":"item" ;Depending on the subsystem, set the item type to "frame" or "item"
  52.         startingEntry:=1 ;Reset the skipped entry count
  53.         startingItem:=0 ;Reset the skipped item count
  54.         Find:
  55.         ControlClick x203 y32,,,,,NA ; Click CrashEdit's "Find" button
  56.         DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  57.         While ((currentCounter-Counter)/Frequency)*1000<(2000*Multiplier) ;For at least ~2s:
  58.         {
  59.             Check:=WinActive(CrashEdit,,CrashEdit) ;Check whether CrashEdit's find form is active
  60.             If Check ;If CrashEdit's find form is active,
  61.                 Break ;Stop the loop
  62.             If !WinExist("CrashEdit " . CrashEdit) ;If no CrashEdit instances exist:
  63.             {
  64.                 Gosub Restart ;Restart CrashEdit (line 294)
  65.                 Goto Find ;Restart the query (line 54)
  66.             }
  67.             DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  68.         }
  69.         If !Check ;If CrashEdit's find form doesn't exist:
  70.         {
  71.             Gosub Restart ;Restart CrashEdit (line 294)
  72.             Goto Find ;Restart the query (line 54)
  73.         }
  74.         WinWaitActive % CrashEdit,,,CrashEdit ;Wait for CrashEdit's find form to be active
  75.         ControlSetText % "WindowsForms10.EDIT" . Instance . "1",% A_LoopField ;Set the current search query in CrashEdit's find form
  76.         ControlSend,,{Enter} ;Send the search query
  77.         DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  78.         While ((currentCounter-Counter)/Frequency)*1000<(200*Multiplier) ;For at least ~200ms:
  79.         {
  80.             If !WinActive(CrashEdit,,"CrashEdit") ;If CrashEdit's find form isn't active,
  81.                 Break ;Stop the loop
  82.             DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  83.         }
  84.         If startingEntry=1 ;If the skipped entry count isn't set:
  85.         {
  86.             DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  87.             While ((currentCounter-Counter)/Frequency)*1000<(250*Multiplier) ;For at least ~250ms:
  88.             {
  89.                 If WinActive(CrashEdit,,"CrashEdit") ;If the "No results found." message is active:
  90.                 {
  91.                     WinGetText Text ;Retrieve all visible text
  92.                     If !InStr(Text,"No results found.") ;If the specified string doesn't exist in the visible text:
  93.                     {
  94.                         Gosub Restart ;Restart CrashEdit (line 294)
  95.                         Goto Find ;Restart the query (line 54)
  96.                     }
  97.                     ControlSend,,{Enter} ;Close the "No results found." message
  98.                     WinWaitActive % "CrashEdit " . CrashEdit ;Wait for CrashEdit to be active
  99.                     Continue ;Move onto the next query
  100.                 }
  101.                 DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  102.             }
  103.         }
  104.         WinWaitActive % "CrashEdit " . CrashEdit ;Wait for CrashEdit to be active
  105.         Loop ;For each entry:
  106.         {
  107.             Entry:=A_Index ;Store the loop number for nested use
  108.             If startingEntry>1&&Entry<startingEntry ;If the skipped entry count is set, and the current entry is lesser than the skipped entry count,
  109.                 Goto nextEntry ;Skip the entry (line 245)
  110.             Else ;Otherwise,
  111.                 startingEntry:=1 ;Reset the skipped entry count
  112.             Parent:=A_WorkingDir . "\Entries\" . SubStr(A_LoopFileName,1,-4) . "," . Subsystem . "," . Format("{:03}",Entry) ;Set the parent to a concatenation of the "Entries" folder in the script's directory, the archive's name, the current subsystem and current entry
  113.             If FileExist(Parent . ",*") ;If the directory already exists and its name contains an Entry ID:
  114.             {
  115.                 Loop Files,% Parent . ",*",D ;For the directory that contains that Entry ID:
  116.                     Parent:=A_LoopFilePath ;Set the parent to that directory
  117.                 If Subsystem="TGEO" ;If the subsystem is of a model entry,
  118.                     If FSO.GetFolder(Parent).Files.Count=6 ;If the file count matches the maximum of the model entry's directory's,
  119.                         Goto nextEntry ;Skip the entry (line 245)
  120.                 If Subsystem="WGEO" ;If the subsystem is of a scenery entry,
  121.                     If FSO.GetFolder(Parent).Files.Count=7 ;If the file count matches the complete scenery entry's directory's,
  122.                         Goto nextEntry ;Skip the entry (line 245)
  123.             }
  124.             Else ;Otherwise,
  125.                 FileCreateDir % Parent ;Create the current directory
  126.             ControlSend % "WindowsForms10.SysTreeView32" . Instance . "1",{NumpadMult} ;Open the current entry
  127.             Loop ;For each item:
  128.             {
  129.                 Item:=A_Index-1 ;Store the loop number for nested use
  130.                 ;Start Special Cases - If the following conditions are met:
  131.                 If SubStr(A_LoopFileName,1,-4="1,CB3,NTSC,29,0D"&&Subsystem="SVTX"&&Entry=126&&Item=3) ;1,CB3,NTSC,29,0D,SVTX,126/frame3
  132.                     Break ;Move onto the next entry
  133.                 If SubStr(A_LoopFileName,1,-4="1,CB3,NTSC,39,21"&&Subsystem="SVTX"&&Entry=110&&Item=3) ;1,CB3,NTSC,39,21,SVTX,110/frame3
  134.                     Break ;Move onto the next entry
  135.                 If SubStr(A_LoopFileName,1,-4="1,CB3,NTSC,42,27"&&Subsystem="SVTX"&&Entry=115&&Item=3) ;1,CB3,NTSC,42,27,SVTX,115/frame3
  136.                     Break ;Move onto the next entry
  137.                 If SubStr(A_LoopFileName,1,-4="2,CB3,NTSC-J,42,27"&&Subsystem="SVTX"&&Entry=115&&Item=3) ;2,CB3,NTSC-J,42,27,SVTX,115/frame3
  138.                     Break ;Move onto the next entry
  139.                 If SubStr(A_LoopFileName,1,-4="3,CB3,PAL,29,0D"&&Subsystem="SVTX"&&Entry=126&&Item=7) ;3,CB3,PAL,29,0D,SVTX,126/frame7
  140.                     Break ;Move onto the next entry
  141.                 If SubStr(A_LoopFileName,1,-4="3,CB3,PAL,39,21"&&Subsystem="SVTX"&&Entry=110&&Item=7) ;3,CB3,PAL,39,21,SVTX,110/frame7
  142.                     Break ;Move onto the next entry
  143.                 If SubStr(A_LoopFileName,1,-4="3,CB3,PAL,42,27"&&Subsystem="SVTX"&&Entry=115&&Item=7) ;3,CB3,PAL,42,27,SVTX,115/frame7
  144.                     Break ;Move onto the next entry
  145.                 ;End Special Cases
  146.                 If Subsystem="TGEO"&&Item=6 ;If the maximum item count for the model entry has been met,
  147.                     Break ;Move onto the next entry
  148.                 If Subsystem="WGEO"&&Item=7 ;If the scenery entry is complete,
  149.                     Break ;Move onto the next entry
  150.                 ControlSend % "WindowsForms10.SysTreeView32" . Instance . "1",{Down} ;Select the current item
  151.                 Sleep (50*Multiplier) ;Wait at least ~50ms
  152.                 If startingItem>0&&Item<startingItem ;If the skipped item count is set, and the current item is lesser than the skipped item count,
  153.                     Continue ;Skip the item
  154.                 Else
  155.                     startingItem:=0 ;Reset the skipped item count
  156.                 If FileExist(Parent . "\" . Type . Item) ;If the current item in the current directory exists,
  157.                     Continue ;Skip the item
  158.                 MouseMove 228,92 ;Move the cursor onto the potential "Export" button
  159.                 DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  160.                 While ((currentCounter-Counter)/Frequency)*100<(50*Multiplier) ;For at least ~50ms:
  161.                 {
  162.                     ControlGet Check,Hwnd,,% "WindowsForms10.Window.8" . Instance . "7" ;Retrieve the potential export button container's identifier
  163.                     If Check ;If the potential export button container exists:
  164.                     {
  165.                         ControlGet Style,Style,,% "WindowsForms10.Window.8" . Instance . "7" ;Retrieve the potential export button container's style
  166.                         ControlGet ExStyle,ExStyle,,% "WindowsForms10.Window.8" . Instance . "7" ;Retrieve the potential export button container's additional style
  167.                         If Style="0x56010000"&&ExStyle="0x00000000" ;If the export button container exists:
  168.                         {
  169.                             PixelGetColor Color,228,92 ;Retrieve the "Export" button's colour
  170.                             If Color="0xD77800"||Color="0xFF9933" ;If the "Export" button is highlighted:
  171.                             {
  172.                                 If WinActive("CrashEdit " . CrashEdit,"Unhandled exception") ;If an unhandled exception occured:
  173.                                 {
  174.                                     ControlSend,,{Tab}{Enter}, ;Ignore the unhandled exception
  175.                                     WinWaitActive % "CrashEdit " . CrashEdit ;Wait for CrashEdit to become active
  176.                                 }
  177.                                 ControlClick x228 y92,,,,,NA ;Click the "Export" button
  178.                                 MouseMove 227,92 ;Move the cursor off of the "Export" button
  179.                                 DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  180.                                 While ((currentCounter-Counter)/Frequency)*1000<(15000*Multiplier) ;For at least ~15s:
  181.                                 {
  182.                                     Check:=WinActive("Save As " . CrashEdit) ;Check whether the file export dialog is active
  183.                                     If Check ;If the file export dialog is active,
  184.                                         Break ;Stop the loop
  185.                                     If !WinExist("CrashEdit " . CrashEdit) ;If no CrashEdit instances exist:
  186.                                     {
  187.                                         Gosub Restart ;Restart CrashEdit (line 294)
  188.                                         Goto Find ;Restart the query (line 54)
  189.                                     }
  190.                                     DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  191.                                 }
  192.                                 If !Check ;If the find form doesn't exist:
  193.                                 {
  194.                                     Gosub Restart ;Restart CrashEdit (line 294)
  195.                                     Goto Find ;Restart the query (line 54)
  196.                                 }
  197.                                 WinGetText Text ;Retrieve all visible text
  198.                                 If !InStr(Text,"All Files") ;If the string is missing from the visible text:
  199.                                 {
  200.                                     Gosub Restart ;Restart CrashEdit (line 294)
  201.                                     Goto Find ;Restart the query (line 54)
  202.                                 }
  203.                                 ControlSetText Edit1,% Parent . "\" . Type . Item ;Set the item export path
  204.                                 ControlSend,,{Enter} ;Export the item
  205.                                 ;FileAppend % Parent . "\" . Type . Item . "`n",_Exported.txt ;Record the item
  206.                                 WinWaitActive % "CrashEdit " . CrashEdit ;Wait for CrashEdit to be active
  207.                                 Loop ;Indefinitely:
  208.                                     PixelGetColor Color,228,92 ;Retrieve the "Export" button's colour,
  209.                                 Until (Color!="0xD77800"&&Color!="0xFF9933") ;Until it isn't highlighted
  210.                                 Continue 2 ;Move onto the next item
  211.                             }
  212.                         }
  213.                     }
  214.                     DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  215.                 }
  216.                 PixelGetColor Color,228,92 ;Retrieve the potential entity viewer panel's colour,
  217.                 If Color="0xABABAB" ;If the entity viewer is loading,
  218.                     Loop ;Indefinitely:
  219.                         PixelGetColor Color,228,92 ;Retrieve the entity view panel's colour,
  220.                     Until Color!="0xABABAB" ;Until the entity viewer has loaded
  221.                 If Color="0x000000"||SubStr(Color,3,2)!=SubStr(Color,5,2)||SubStr(Color,3,2)!=SubStr(Color,7,2)||SubStr(Color,5,2)!=SubStr(Color,7,2) ;If the entity viewer has loaded,
  222.                     Break ;Move onto the next entry
  223.                 If !WinExist("CrashEdit " . CrashEdit) ;If no CrashEdit instances exist:
  224.                 {
  225.                     Item:=0 ;Reset the item count
  226.                     Gosub Restart ;Restart CrashEdit (line 294)
  227.                     Goto Find ;Restart the query (line 54)
  228.                 }
  229.                 WinGetText Text ;Retrieve all visible text
  230.                 Loop Parse,% "No options available|Monochrome 8",| ;For each sub-version:
  231.                 {
  232.                     If !InStr(Text,A_LoopField) ;If the current string is missing:
  233.                     {
  234.                         If A_Index=2 ;If all strings are missing:
  235.                         {
  236.                             Item:=0 ;Reset the item count
  237.                             Gosub Restart ;Restart CrashEdit (line 294)
  238.                             Goto Find ;Restart the query (line 54)
  239.                         }
  240.                     }
  241.                     Else ;Otherwise,
  242.                         Break 2 ;Move onto the next entry
  243.                 }
  244.             }
  245.             nextEntry:
  246.             Item:=0 ;Reset the item count
  247.             If Subsystem="SVTX"&&InStr(Parent,",",,,8)&&SubStr(Parent,InStr(Parent,",",,,8)-StrLen(Parent)+1)!=FSO.GetFolder(Parent).Files.Count ;If the animation entry directory name contains an incorrect frame count,
  248.                 FileMoveDir % Parent,% SubStr(Parent,1,InStr(Parent,",",,,8)) . FSO.GetFolder(Parent).Files.Count,R ;Rename the directory with the correct frame count
  249.             ControlClick x237 y32,,,,,NA ;Click the "Find Next" button
  250.             Sleep (50*Multiplier) ;Wait at least ~50ms
  251.             If Entry>=startingEntry ;If the current entry is greater than or equal to the skipped entry count:
  252.             {
  253.                 DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  254.                 While ((currentCounter-Counter)/Frequency)*1000<(250*Multiplier) ;For at least ~250ms:
  255.                 {
  256.                     If WinActive(CrashEdit,,"CrashEdit") ;If the "No results found." message is active:
  257.                     {
  258.                         WinGetText Text ;Retrieve all visible text
  259.                         If !InStr(Text,"No results found.") ;If the specified string doesn't exist in the visible text:
  260.                         {
  261.                             Gosub Restart ;Restart CrashEdit (line 294)
  262.                             Goto Find ;Restart the query (line 54)
  263.                         }
  264.                         ControlSend,,{Enter} ;Close the "No results found." message
  265.                         WinWaitActive % "CrashEdit " . CrashEdit ;Wait for CrashEdit to be active
  266.                         Entry:=1 ;Reset the entry count
  267.                         Loop Read,% "Entry IDs\" . SubStr(A_LoopFileName,1,-4) . "," . Subsystem . ".txt" ;For each entry ID of the current archive and subsystem:
  268.                         {
  269.                             Source:="Entries\" . SubStr(A_LoopFileName,1,-4) . "," . Subsystem . "," . Format("{:03}",A_Index) ;Set the source entry directory name
  270.                             If FileExist(Source) ;If the source entry folder exists:
  271.                             {
  272.                                 If Subsystem="SVTX" ;If it is an animation entry,
  273.                                     FileMoveDir % Source,% Source . "," . A_LoopReadLine . "," . FSO.GetFolder(Source).Files.Count,R ;Append the Entry ID and frame count to the directory name
  274.                                 Else ;Otherwise,
  275.                                     FileMoveDir % Source,% Source . "," . A_LoopReadLine,R ;Append the Entry ID to the directory name
  276.                             }
  277.                         }
  278.                         Break 2 ;Move onto the next query
  279.                     }
  280.                     DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  281.                 }
  282.             }
  283.         }
  284.     }
  285.     ControlClick x157 y32,,,,,NA ;Click the "Close" button
  286.     Loop Parse,% ".NSF|.NSD",| ;For each archive's NSF and NSD file:
  287.         FileMove % SubStr(A_LoopFileName,1,-4) . A_LoopField,% "Archives" ;Move that file to the "Archives" directory
  288. }
  289. BlockInput Off ;Enable input
  290. DllCall("kernel32\Beep",Int,800,Int,500) ;Audibly announce the script's completion
  291. MsgBox % "Complete!" ;Visually announce the script's completion
  292. Gosub Exit ;Stop the script (line 417)
  293.  
  294. Restart:
  295.     Process Close,CrashEdit.exe ;Force close the most recent CrashEdit instance
  296.     WinWaitClose % "CrashEdit " . CrashEdit ;Wait for CrashEdit to close
  297.     startingEntry:=Entry ;Store the current entry
  298.     startingItem:=Item ;Store the current item
  299.     Start:=2 ;Indicate the restart sub-routine has occured
  300.  
  301. Start:
  302.     Run CrashEdit.exe ;Start CrashEdit
  303.     WinWaitActive % "CrashEdit " . CrashEdit ;Wait for CrashEdit to open
  304.     Process Priority,CrashEdit.exe,H ;Set CrashEdit's priority to High
  305.     WinGetPos,,,WindowWidth,WindowHeight ;Retrieve the CrashEdit window's width and height
  306.     WinMove,,,(A_ScreenWidth/2)-(WindowWidth/2),(A_ScreenHeight/2)-(WindowHeight/2) ;Move the CrashEdit window to the centre of the screen
  307.     WinGetClass Instance ;Retrieve the window's class
  308.     Instance:=SubStr(Instance,-13) ;Retrieve the window's unique instance
  309.     If Start=2 ;If the restart sub-routine has occurred:
  310.     {
  311.         Gosub Open ;Reopen the previous archive (line 317)
  312.         Return ;Stop this sub-routine
  313.     }
  314.     Start:=1 ;Indicate the start sub-routine has occured
  315.     Return ;Stop this sub-routine
  316.  
  317. Open:
  318.     ControlClick x15 y32,,,,,NA ;Click the "Open" button
  319.     If !Start ;If the start sub-routine has already occurred:
  320.     {
  321.         DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  322.         While ((currentCounter-Counter)/Frequency)*1000<(2000*Multiplier) ;For at least ~2s:
  323.         {
  324.             Check:=WinActive("Open " . CrashEdit) ;Check Whether CrashEdit's file open dialog is active
  325.             If Check ;If CrashEdit's file open dialog is active,
  326.                 Break ;Stop the loop
  327.             If !WinExist("CrashEdit " . CrashEdit) ;If no CrashEdit instances exist:
  328.             {
  329.                 Gosub Restart ;Restart CrashEdit (line 294)
  330.                 Return ;Stop this sub-routine
  331.             }
  332.             DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  333.         }
  334.     }
  335.     Else ;Otherwise,
  336.         WinWaitActive % "Open " . CrashEdit ;Wait for CrashEdit's file open dialog to be active
  337.     If !Start ;If the start sub-routine has already occurred:
  338.     {
  339.         WinGetText Text ;Retrieve all visible text
  340.         If !InStr(Text,"NSF Files") ;If the string doesn't exist in the visible text:
  341.         {
  342.             Gosub Restart ;Restart CrashEdit (line 294)
  343.             Return ;Stop this sub-routine
  344.         }
  345.     }
  346.     ControlSetText Edit1,% A_LoopFileFullPath ;Input the current archive's path into CrashEdit's file open dialog
  347.     ControlSend,,{Enter} ;Open the current archive
  348.     If !Start ;If the start sub-routine has already occurred:
  349.     {
  350.         DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  351.         While ((currentCounter-Counter)/Frequency)*1000<(2000*Multiplier) ;For at least ~2s:
  352.         {
  353.             If !WinExist("CrashEdit " . CrashEdit) ;If no CrashEdit instances exist:
  354.             {
  355.                 Gosub Restart ;Restart CrashEdit (line 294)
  356.                 Return ;Stop this sub-routine
  357.             }
  358.             DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  359.         }
  360.     }
  361.     WinWaitActive % "CrashEdit Game Version Selection " . CrashEdit ;Wait for CrashEdit's game version selection form to be active
  362.     If !Start ;If the start sub-routine has already occurred:
  363.     {
  364.         WinGetText Text ;Retrieve all visible text
  365.         If !InStr(Text,"OK") ;If the specified string doesn't exist in the visible text:
  366.         {
  367.             Gosub Restart ;Restart CrashEdit (line 294)
  368.             Return ;Stop this sub-routine
  369.         }
  370.     }
  371.     ControlClick,% "WindowsForms10.BUTTON" . Instance . Game,,,,,NA ;Select the current game option from CrashEdit's game version selection form
  372.     ControlSend,,{Enter} ;Send the selection
  373.     If SubStr(A_LoopFileName,InStr(A_LoopFileName,",",,,2)+1,InStr(A_LoopFileName,",",,,3)-1-InStr(A_LoopFileName,",",,,2))="NTSC-J" ;If the archive is of Japanese region:
  374.     {
  375.         DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  376.         While ((currentCounter-Counter)/Frequency)*1000<(400*Multiplier) ;For at least ~400ms:
  377.         {
  378.             If WinActive("Error Reporter " . CrashEdit) ;If CrashEdit's error reporter window is active:
  379.             {
  380.                 If !Start ;If the start sub-routine has already occurred:
  381.                 {
  382.                     WinGetText Text ;Retrieve all visible text
  383.                     If !InStr(Text,"OK") ;If the specified string doesn't exist in the visible text:
  384.                     {
  385.                         Gosub Restart ;Restart CrashEdit (line 294)
  386.                         Return ;Stop this sub-routine
  387.                     }
  388.                 }
  389.                 ControlSend,,{Enter} ;Close CrashEdit's error reporter window
  390.                 WinWaitClose ;Wait for CrashEdit's error reporter window to close
  391.                 DllCall("QueryPerformanceCounter","Int64*",Counter) ;Restart the counter
  392.             }
  393.             DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  394.         }
  395.     }
  396.     If !Start ;If the start sub-routine has already occurred:
  397.     {
  398.         DllCall("QueryPerformanceCounter","Int64*",Counter) ;Start the counter
  399.         While ((currentCounter-Counter)/Frequency)*1000<(2000*Multiplier) ;For at least ~2s:
  400.         {
  401.             If !WinExist("CrashEdit " . CrashEdit) ;If no CrashEdit instances exist:
  402.             {
  403.                 Gosub Restart ;Restart CrashEdit (line 294)
  404.                 Return ;Stop this sub-routine
  405.             }
  406.             DllCall("QueryPerformanceCounter", "Int64*", currentCounter) ;Increment the counter
  407.         }
  408.     }
  409.     WinActivate % "CrashEdit " . CrashEdit ;Activate the main CrashEdit window
  410.     WinWaitActive % "CrashEdit " . CrashEdit ;Wait for the main CrashEdit window to be active
  411.     Loop ;Indefinitely:
  412.         ControlGet Check,Visible,,% "WindowsForms10.STATIC" . Instance . "1",% "CrashEdit " . CrashEdit ;Check the visibility of the last loaded control,
  413.     Until Check ;Until it is visible
  414.     If Start ;If the start sub-routine has occurred,
  415.         Start:=0 ;Indicate the start sub-routine has finished
  416.     Return ;Stop this sub-routine
  417.  
  418. Exit:
  419.     If A_Paused ;If the script is paused,
  420.         Pause ;Resume the script
  421.     If WinExist("CrashEdit " . CrashEdit) ;If any CrashEdit instances exist,
  422.         Loop ;Indefinitely:
  423.             Process Close,CrashEdit.exe ;Force close the most recent one,
  424.         Until !WinExist("CrashEdit " . CrashEdit) ;Until none remain
  425.     ExitApp ;Exit the script
  426.  
  427. #UseHook ;Monitor the following keystrokes:
  428. p:: ;Upon pressing the 'P' key:
  429.     BlockInput % (Input:=!Input)?"On":"Off" ;Toggle input blocking
  430.     WinActivate % CrashEdit ;Activate CrashEdit
  431.     Pause ;Pause the script
  432.     Return ;Stop this sub-routine
  433. #UseHook Off ;Do not monitor the following keystrokes:
Advertisement
Add Comment
Please, Sign In to add comment