Rpcs3

slashin8r

Member
RL Member
Removed the code to check for game window. The previous code breaks if you remove FPS from title of game window in your RPCS3 settings.

Cleaned up the fade screen. Hopefully it works much smoother with the added progress bars.

Module is now capable of "updating" the archived PPU and DATA files. If it notices a change in the new files, it will overwrite the old archive with a new one. Also capable of archiving DATA files in multiple folders. Some games produce multiple DATA folders.

Code:
MEmu := "RPCS3"
MEmuV := "v0.0.7-9165-8ca53f9c Alpha"
MURL := ["https://rpcs3.net"]
MAuthor := ["slashin8r", "wallmachine", "jviegas", "brolly", "aurel102001"]
MVersion := "1.1.1"
MDate := "2019-11-24"
MCRC := ""
iCRC := ""
MID := ""
MSystem := ["Sony Playstation 3"]
;----------------------------------------------------------------------------
; Notes:
; [IMPORTANT]
; There are three methods for using this module.
; 
; METHOD 1: Use Archives
; 1) Archive your game folders, rename them to the title of the game, place them all within the same folder, then add that folder as a romPath in RocketLauncher.
; 2) Add the archive's extension ("7z", "rar", "zip", etc.) for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 2: Use Shortcuts
; 1) Create shortcuts of your EBOOT.BIN files, rename them to the title of the game, place them all within the same folder, then add that folder as a romPath in RocketLauncher.
; 2) Add the "lnk" (LNK) extension for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 3: Use Text Files
; 1) Place game folders all within the same folder. It is best to not rename these folders. They will have names such as "BLES#####", "BCUS#####", "NPUB#####", etc.
; 2) Create a text file for every game, named as the title of the game. Open the text file and add the name of the game folder on the first line. ("BLES#####", "BCUS#####", "NPUB#####", etc.)
; 3) Place these text files within the folder storing your games. If you wish to have the text files in a separate folder, then you must include the full path to folder storing your games in the "textGameFolder" variable found below.
; 4) Add the folder containing your text files as a romPath in RocketLauncher.
; 5) Add the "txt" extension for the RPCS3 emulator within RocketLauncher.
; 6) Generate a new database based on the new rom path.
; 7) Audit all games for the system and enjoy.
; [IMPORTANT]
; 
; 
; 
; To save additional space, this module now automatically compresses each game's PPU folder and Game Data folder (if exists) as long as 7z is enabled.
; PPU file saved in: %romPath%\cache\%romName%_%A_ComputerName%.7z
; Game Data file saved in: %romPath%\data\%romName%_data.7z
; 
; Example:
; Rom File = "D:\PS3\PS3 Test Game.rar"
; A_ComputerName = "PC001"
; 
; PPU File = "D:\PS3\cache\PS3 Test Game_PC001.7z")
; Game Data File = "D:\PS3\data\PS3 Test Game_data.7z")
; 
; 
; 
; Known Issues:
; None
; 
; 
; 
; Coming Soon:
; Please make requests
;----------------------------------------------------------------------------

StartModule()
BezelGUI()
FadeInStart()

primaryExe := new Emulator(emuPath . "\" . executable)
primaryWindowClassName := "Qt5QWindowIcon"
emuPrimaryWindow := new Window(new WindowTitle(,primaryWindowClassName, executable))

; Finding emulator config file
Rpcs3config := new File(emuPath . "\config.yml")
Rpcs3config.CheckFile("Could not find RPCS3 config.yml! Run your emulator, go to Settings and save them.")

; Finding emulator games file
Rpcs3games := new File(emuPath . "\games.yml")
Rpcs3games.CheckFile("Could not find RPCS3 games.yml! Update this file with your list of game serials and game installation directories.")

textGameFolder := moduleIni.Read("Settings", "GamesDirectory","",,1)
archivePPU := moduleIni.Read("Settings", "ArchivePPU","false",,1)
archiveDATA := moduleIni.Read("Settings", "ArchiveDATA","false",,1)
removePPU := moduleIni.Read("Settings", "RemovePPU","false",,1)
removeDATA := moduleIni.Read("Settings", "RemoveDATA","false",,1)

BezelStart()

hideEmuObj := Object(emuPrimaryWindow,1)
HideAppStart(hideEmuObj,hideEmu)

; Set variables
gameSevenZEnabled := sevenZEnabled
gameType := ""
gameSerial := ""
gameDirectoryJunction := "false"
gamePPU := "false"
gamePPUarchive := romPath . "\cache\" . romName . "_" . A_ComputerName . ".7z"
gamePPUromPath := romPath . "\cache"
gamePPUromName := romName . "_" . A_ComputerName
gamePPUromExtension := ".7z"
gamePPUemuPath := emuPath . "\cache"
gameDATA := "false"
gameDATAarchive := romPath . "\data\" . romName . "_data.7z"
gameDATAromPath := romPath . "\data"
gameDATAromName := romName . "_data"
gameDATAromExtension := "7z"
gameDATAemuPath := emuPath . "\dev_hdd0\game"
textRomFolder := ""

If (romExtension = ".txt")
{
  FileReadLine, textRomFolder, %romPath%\%romName%%romExtension%, 1
  If (textGameFolder = "")
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(romPath . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . textRomFolder . "\""")
      }
    }
  }
  Else
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(textGameFolder . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . textRomFolder . "\""")
      }
    }
  }
}
Else If (romExtension = ".lnk" && Fileexist(romPath . "\" . romName . romExtension))
{
  FileGetShortCut, %romPath%\%romName%%romExtension%, shortcutTarget
  StringReplace, romPath, shortcutTarget, \EBOOT.BIN
}
Else If (InStr(sevenZFormats, romExtension)) {
  gameSerial := RLObject.getZipRootFolder(romPath . "\" . romName . romExtension)
}

; Store old values for later
originalRomPath := romPath
originalRomName := romName
originalRomExtension := romExtension
originalSevenZRomPath := sevenZRomPath
originalGameName := gameInfo["Name"].Value

; Find game location
gameFolder := romPath
If (sevenZEnabled = "true" && InStr(sevenZFormats, romExtension))
{
  gameFolder := sevenZExtractPath . "\" . romName
  If (sevenZAttachSystemName = "true")
  {
    gameFolder := sevenZExtractPath . "\" . systemName . "\" . romName
  }
}
Else If (romExtension = ".lnk" || romExtension = ".txt")
{
  StringReplace, gameFolder, gameFolder, \USRDIR
  StringReplace, gameFolder, gameFolder, \PS3_GAME
}

;MsgBox, gamePPUarchive: %gamePPUarchive%`ngamePPUemuPath: %gamePPUemuPath%`ngameDATAarchive: %gameDATAarchive%`ngameDATAemuPath: %gameDATAemuPath%

; Extract PPU files if they exist
If (archivePPU = "true" && Fileexist(gamePPUarchive))
{
  gameInfo["Name"].Value := "EXTRACTING COMPILED PPU FILES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gamePPUarchive)
  romExSize := RLObject.getZipExtractedSize(gamePPUarchive)
  sevenZRomPath := gamePPUemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gamePPUromPath, gamePPUromName, gamePPUromExtension, gamePPUemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gamePPUarchive%" -aos -o"%gamePPUemuPath%", sevenZPID, Hide
  gamePPU := "true"
}

; Extract Game Data files if they exist
If (archiveDATA = "true" && Fileexist(gameDATAarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME DATA"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameDATAarchive)
  romExSize := RLObject.getZipExtractedSize(gameDATAarchive)
  sevenZRomPath := gameDATAemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameDATAromPath, gameDATAromName, gameDATAromExtension, gameDATAemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameDATAarchive%" -aos -o"%gameDATAemuPath%", sevenZPID, Hide
  gameDATA := "true"
}

If (gamePPU := "true" || gameDATA := "true")
{
  sevenZRomPath := originalSevenZRomPath
  gameInfo["Name"].Value := originalGameName
  Gdip_GraphicsClear(Fade_G5)
}
romPath := originalRomPath
romName := originalRomName
romExtension := originalRomExtension
romExPercentage := 0
layer3Percentage := 0
romExSize := 1000000000
use7zAnimation := "true"
Gosub, UpdateFadeFor7z

7z(romPath, romName, romExtension, sevenZExtractPath)

romFolder := romPath

IfInString, romPath, \USRDIR
{
  FoundPos := InStr(romPath, "\USRDIR") + 6
  StringLeft, romPath, romPath, %FoundPos%
}

; Find the game location and determine the type of game (disc or hdd)
StringRight, stringTest, romFolder, 6
If (stringTest = "USRDIR")
{
  gameType := "game"
  StringReplace, romFolder, romFolder, \USRDIR
  StringRight, stringTest, romFolder, 8
  If (stringTest = "PS3_GAME")
  {
    gameType := "disc"
    StringReplace, romFolder, romFolder, \PS3_GAME
  }
  If (romExtension = ".lnk" || (romExtension = ".txt" && textRomFolder != "") || (gameSerial != "" && gameType != ""))
  {
    If (romExtension = ".lnk" || romExtension = ".bin")
    {
      StringRight, gameSerial, romFolder, 9
    }
    
    ; Create the directory junction
    If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
    {
      If (gameSerial != "" && gameType != "")
      {
        RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
        gameDirectoryJunction := "true"
      }
      Else
      {
        ScriptError("Game serial not found. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
      }
    }
  }
}
Else If (sevenZEnabled = "true" && (romPath = originalRomPath || romPath = "") && InStr(sevenZFormats, romExtension))
{
  ScriptError("Rom was not found in the USRDIR directory. Please make sure ""bin"" is an RPCS3 extension and also verify the folder structure of your rom.")
}

;MsgBox, romPath: %romPath%`nromName: %romName%`nromExtension: %romExtension%`ngameType: %gameType%`ngameSerial: %gameSerial%`ngameDirectoryJunction: %gameDirectoryJunction%`ngamePPU: %gamePPU%`ngameDATA: %gameDATA%`nsevenZEnabled: %sevenZEnabled%`ngameSevenZEnabled: %gameSevenZEnabled%

; Run the game
If (gameType = "game")
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\" . romName . ".BIN"))
{
  primaryExe.Run(" """ . romPath . "\" . romName . ".BIN""")
}
Else If (Fileexist(romPath . "\" . romName . romExtension))
{
  primaryExe.Run(" """ . romPath . "\" . romName . romExtension . """")
}
Else
{
  ScriptError("Unable to find EBOOT.BIN file. Please make sure ""bin"" (and ""lnk"" [LNK] if you are loading from shortcuts) is an RPCS3 extension and also verify the folder structure of your rom.")
}

; Waiting for main emulator window
emuPrimaryWindow.Wait()
emuPrimaryWindow.Active()
emuPrimaryWindow.WaitActive()

If (gameSerial = "" && ((sevenZEnabled = "true" && InStr(sevenZFormats, romExtension)) || romExtension = ".txt"))
{
  ; Find the game serial
  If (Fileexist(emuPath . "\games.yml") && (gameSerial = "" || textRomFolder = ""))
  {
    Loop, read, %emuPath%\games.yml
    {
      StringReplace, gameLine, A_LoopReadLine, /, \, All
      IfInString, gameLine, %gameFolder%
      {
        StringLeft, gameSerial, gameLine, 9
        break
      }
    }
  }

  ; Create the directory junction
  If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
  {
    If (gameSerial != "" && gameType != "")
    {
      RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
      gameDirectoryJunction := "true"
    }
    Else
    {
      ScriptError("Game serial not found in your RPCS3 games.yml file. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
    }
  }
}

; Waiting 3 seconds to see if compiling window appears
If (gameSerial != "" && gamePPU != "true")
{
  WinWait, Compiling, , 3
  If (!ErrorLevel)
  {
    gameInfo["Name"].Value := "COMPILING PPU FILES"
    use7zAnimation := "true"
    Gdip_GraphicsClear(Fade_G5)
    Gosub, UpdateFadeFor7z
    WinWaitClose, Compiling
    gameInfo["Name"].Value := originalGameName
    use7zAnimation := "true"
    Gdip_GraphicsClear(Fade_G5)
    Gosub, UpdateFadeFor7z
  }
}

BezelDraw()
HideAppEnd(hideEmuObj,hideEmu)
FadeInExit()
primaryExe.Process("WaitClose")

; Remove the PPU files if they were extracted or creates PPU archive file if needed
If ((archivePPU = "true" || removePPU = "true") && gameSerial != "")
{
  IfExist, %gamePPUemuPath%\%gameSerial%
  {
    If (archivePPU = "true")
    {
      IfNotExist, %gamePPUarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
        FadeInExit()
      }
      Else
      {
        MostRecentTime := 0
        Loop, %gamePPUemuPath%\%gameSerial%\*, 2
        {
          If (A_LoopFileTimeModified > MostRecentTime)
          {
            MostRecentTime := A_LoopFileTimeModified
          }
        }
        FileGetTime, gamePPUtime, %gamePPUarchive%, M
        If (MostRecentTime > gamePPUtime)
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
          FadeInExit()
        }
      }
    }
    If (removePPU = "true")
    {
      FileRemoveDir, %gamePPUemuPath%\%gameSerial%, 1
    }
  }
  Else
  {
    MostRecentTime := 0
    MostRecentFile := ""
    MostRecentName := ""
    Loop, %gamePPUemuPath%\*, 2
    {
      If (A_LoopFileTimeModified > MostRecentTime)
      {
        MostRecentTime := A_LoopFileTimeModified
        MostRecentFile := A_LoopFileLongPath
        MostRecentName := A_LoopFileName
      }
    }
    If (StrLen(MostRecentName) = 9)
    {
      If (archivePPU = "true")
      {
        IfNotExist, %gamePPUarchive%
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
          FadeInExit()
        }
        Else
        {
          MostRecentTime := 0
          Loop, %gamePPUemuPath%\%MostRecentName%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gamePPUtime, %gamePPUarchive%, M
          If (MostRecentTime > gamePPUtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
            FadeInExit()
          }
        }
      }
      If (removePPU = "true")
      {
        FileRemoveDir, %MostRecentFile%, 1
      }
    }
  }
}

; Remove the Game Data files if they were extracted or creates Game Data archive file if needed
If ((archiveDATA = "true" || removeDATA = "true") && gameSerial != "" && gameType = "disc")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameDATAemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameDATAemuPath%\*, 2
  {
    If (A_LoopFileTimeCreated > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeCreated
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  fileOne := MostRecentFile . "\ICON0.PNG"
  fileTwo := emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\ICON0.PNG"
  FileGetSize, dataSizeOne, %fileOne%
  FileGetSize, dataSizeTwo, %fileTwo%
  FileGetVersion, dataVersionOne, %fileOne%
  FileGetVersion, dataVersionTwo, %fileTwo%
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (dataSizeOne = dataSizeTwo && dataVersionOne = dataVersionTwo && MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    archiveFileCount := archiveFileCount + 1
    archiveFileArray[archiveFileCount] := MostRecentFile
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveDATA = "true")
    {
      IfNotExist, %gameDATAarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameDATAtime, %gameDATAarchive%, M
          FileGetTime, gameDATAarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameDATAtime || gameDATAarchiveTime > gameDATAtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeDATA = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the directory junction
If (gameDirectoryJunction = "true")
{
  RunWait, %ComSpec% /c "rmdir "%emuPath%\dev_hdd0\%gameType%\%gameSerial%", , Hide
}

7zCleanUp()
BezelExit()
FadeOutExit()
ExitModule()

CloseProcess:
  FadeOutStart()
  emuPrimaryWindow.Close()
  Process, Close, %executable%
Return

BezelLabel:
  disableHideBorder := "true"
  disableHideTitleBar := "true"
  disableHideToggleMenu := "true"
Return

Edit: Quick fix to text file method.
 
Last edited:

slashin8r

Member
RL Member
Just updated the Notes area with more detailed instructions.

Code:
MEmu := "RPCS3"
MEmuV := "v0.0.7-9165-8ca53f9c Alpha"
MURL := ["https://rpcs3.net"]
MAuthor := ["slashin8r", "wallmachine", "jviegas", "brolly", "aurel102001"]
MVersion := "1.1.1"
MDate := "2019-11-27"
MCRC := ""
iCRC := ""
MID := ""
MSystem := ["Sony Playstation 3"]
;----------------------------------------------------------------------------
; Notes:
; [IMPORTANT]
; There are three methods for using this module.
; 
; METHOD 1: Archives: Use this method if you will be compressing your games to save space.
; 1) Archive your game folders, rename the archive to the title of the game, place all the archives within the same folder, and then add that folder as a romPath in RocketLauncher.
; 2) Add the archive's extension ("7z", "rar", "zip", etc.) for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 2: Shortcuts: Use this method if you will be installing your games directly into RPCS3. Can also be used if you will be storing your non-archive games outside of the RPCS3 installation directories.
; 1) Create shortcuts of your EBOOT.BIN files, rename them to the title of the game, place them all within the same folder, then add that folder as a romPath in RocketLauncher.
; 2) Add the "lnk" (LNK) extension for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 3: Text Files: Use this method if you are converting over from a RPCS3 module prior to version 1.0.2.
; 1) Place game folders all within the same folder. It is best to not rename these folders. (They will have names such as "BLES#####", "BCUS#####", "NPUB#####", etc.)
; 2) Create a text file for every game, named as the title of the game. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; [You can skip step 3 for DISC games as long as the name of the text file matches the name of the game folder]
; [This makes converting from an older RPCS3 module much easier, but it is still recommended to complete this step]
; [HDD games (gameID usually starts with "N") must have step 3 completed]
; 3) Open the text file and add the name of the game folder on the first line. ("BLES#####", "BCUS#####", "NPUB#####", etc.)
; 4) Place these text files within the folder storing your games.
; [If you wish to have the text files in a separate folder, edit the "GamesDirectory" variable, found within your RPCS3.ini file, to match the full path of the folder storing your games]
; 5) Add the folder containing your text files as a romPath in RocketLauncher.
; 6) Add the "txt" extension for the RPCS3 emulator within RocketLauncher.
; 7) Generate a new database based on the new rom path.
; 8) Audit all games for the system and enjoy.
; [IMPORTANT]
; 
; 
; 
; To save additional space, this module now automatically compresses each game's PPU folder and Game Data folder (if exists) as long as it is enabled in your RPCS3.ini file.
; PPU file saved in: %romPath%\cache\%romName%_%A_ComputerName%.7z (PPU files are hardware specific, so the computer name is added to the end of the filename)
; Game Data file saved in: %romPath%\data\%romName%_data.7z ("_data" added to the end of the filename so there is no conflict with the rom name)
; 
; Example:
; Rom File = "D:\PS3\PS3 Test Game.rar"
; A_ComputerName = "PC001"
; 
; PPU File = "D:\PS3\cache\PS3 Test Game_PC001.7z")
; Game Data File = "D:\PS3\data\PS3 Test Game_data.7z")
; 
; 
; 
; Known Issues:
; None
; 
; 
; 
; Coming Soon:
; Please make requests
;----------------------------------------------------------------------------

StartModule()
BezelGUI()
FadeInStart()

primaryExe := new Emulator(emuPath . "\" . executable)
primaryWindowClassName := "Qt5QWindowIcon"
emuPrimaryWindow := new Window(new WindowTitle(,primaryWindowClassName, executable))

; Finding emulator config file
Rpcs3config := new File(emuPath . "\config.yml")
Rpcs3config.CheckFile("Could not find RPCS3 config.yml! Run your emulator, go to Settings and save them.")

; Finding emulator games file
Rpcs3games := new File(emuPath . "\games.yml")
Rpcs3games.CheckFile("Could not find RPCS3 games.yml! Update this file with your list of game serials and game installation directories.")

textGameFolder := moduleIni.Read("Settings", "GamesDirectory","",,1)
archivePPU := moduleIni.Read("Settings", "ArchivePPU","false",,1)
archiveDATA := moduleIni.Read("Settings", "ArchiveDATA","false",,1)
removePPU := moduleIni.Read("Settings", "RemovePPU","false",,1)
removeDATA := moduleIni.Read("Settings", "RemoveDATA","false",,1)

BezelStart()

hideEmuObj := Object(emuPrimaryWindow,1)
HideAppStart(hideEmuObj,hideEmu)

; Set variables
gameSevenZEnabled := sevenZEnabled
gameType := ""
gameSerial := ""
gameDirectoryJunction := "false"
gamePPU := "false"
gamePPUarchive := romPath . "\cache\" . romName . "_" . A_ComputerName . ".7z"
gamePPUromPath := romPath . "\cache"
gamePPUromName := romName . "_" . A_ComputerName
gamePPUromExtension := ".7z"
gamePPUemuPath := emuPath . "\cache"
gameDATA := "false"
gameDATAarchive := romPath . "\data\" . romName . "_data.7z"
gameDATAromPath := romPath . "\data"
gameDATAromName := romName . "_data"
gameDATAromExtension := "7z"
gameDATAemuPath := emuPath . "\dev_hdd0\game"
textRomFolder := ""

If (romExtension = ".txt")
{
  FileReadLine, textRomFolder, %romPath%\%romName%%romExtension%, 1
  If (textGameFolder = "")
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(romPath . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . textRomFolder . "\""")
      }
    }
  }
  Else
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(textGameFolder . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . textRomFolder . "\""")
      }
    }
  }
}
Else If (romExtension = ".lnk" && Fileexist(romPath . "\" . romName . romExtension))
{
  FileGetShortCut, %romPath%\%romName%%romExtension%, shortcutTarget
  StringReplace, romPath, shortcutTarget, \EBOOT.BIN
}
Else If (InStr(sevenZFormats, romExtension)) {
  gameSerial := RLObject.getZipRootFolder(romPath . "\" . romName . romExtension)
}

; Store old values for later
originalRomPath := romPath
originalRomName := romName
originalRomExtension := romExtension
originalSevenZRomPath := sevenZRomPath
originalGameName := gameInfo["Name"].Value

; Find game location
gameFolder := romPath
If (sevenZEnabled = "true" && InStr(sevenZFormats, romExtension))
{
  gameFolder := sevenZExtractPath . "\" . romName
  If (sevenZAttachSystemName = "true")
  {
    gameFolder := sevenZExtractPath . "\" . systemName . "\" . romName
  }
}
Else If (romExtension = ".lnk" || romExtension = ".txt")
{
  StringReplace, gameFolder, gameFolder, \USRDIR
  StringReplace, gameFolder, gameFolder, \PS3_GAME
}

;MsgBox, gamePPUarchive: %gamePPUarchive%`ngamePPUemuPath: %gamePPUemuPath%`ngameDATAarchive: %gameDATAarchive%`ngameDATAemuPath: %gameDATAemuPath%

; Extract PPU files if they exist
If (archivePPU = "true" && Fileexist(gamePPUarchive))
{
  gameInfo["Name"].Value := "EXTRACTING COMPILED PPU FILES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gamePPUarchive)
  romExSize := RLObject.getZipExtractedSize(gamePPUarchive)
  sevenZRomPath := gamePPUemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gamePPUromPath, gamePPUromName, gamePPUromExtension, gamePPUemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gamePPUarchive%" -aos -o"%gamePPUemuPath%", sevenZPID, Hide
  gamePPU := "true"
}

; Extract Game Data files if they exist
If (archiveDATA = "true" && Fileexist(gameDATAarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME DATA"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameDATAarchive)
  romExSize := RLObject.getZipExtractedSize(gameDATAarchive)
  sevenZRomPath := gameDATAemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameDATAromPath, gameDATAromName, gameDATAromExtension, gameDATAemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameDATAarchive%" -aos -o"%gameDATAemuPath%", sevenZPID, Hide
  gameDATA := "true"
}

If (gamePPU := "true" || gameDATA := "true")
{
  sevenZRomPath := originalSevenZRomPath
  gameInfo["Name"].Value := originalGameName
  Gdip_GraphicsClear(Fade_G5)
}
romPath := originalRomPath
romName := originalRomName
romExtension := originalRomExtension
romExPercentage := 0
layer3Percentage := 0
romExSize := 1000000000
use7zAnimation := "true"
Gosub, UpdateFadeFor7z

7z(romPath, romName, romExtension, sevenZExtractPath)

romFolder := romPath

IfInString, romPath, \USRDIR
{
  FoundPos := InStr(romPath, "\USRDIR") + 6
  StringLeft, romPath, romPath, %FoundPos%
}

; Find the game location and determine the type of game (disc or hdd)
StringRight, stringTest, romFolder, 6
If (stringTest = "USRDIR")
{
  gameType := "game"
  StringReplace, romFolder, romFolder, \USRDIR
  StringRight, stringTest, romFolder, 8
  If (stringTest = "PS3_GAME")
  {
    gameType := "disc"
    StringReplace, romFolder, romFolder, \PS3_GAME
  }
  If (romExtension = ".lnk" || (romExtension = ".txt" && textRomFolder != "") || (gameSerial != "" && gameType != ""))
  {
    If (romExtension = ".lnk" || romExtension = ".bin")
    {
      StringRight, gameSerial, romFolder, 9
    }
    
    ; Create the directory junction
    If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
    {
      If (gameSerial != "" && gameType != "")
      {
        RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
        gameDirectoryJunction := "true"
      }
      Else
      {
        ScriptError("Game serial not found. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
      }
    }
  }
}
Else If (sevenZEnabled = "true" && (romPath = originalRomPath || romPath = "") && InStr(sevenZFormats, romExtension))
{
  ScriptError("Rom was not found in the USRDIR directory. Please make sure ""bin"" is an RPCS3 extension and also verify the folder structure of your rom.")
}

;MsgBox, romPath: %romPath%`nromName: %romName%`nromExtension: %romExtension%`ngameType: %gameType%`ngameSerial: %gameSerial%`ngameDirectoryJunction: %gameDirectoryJunction%`ngamePPU: %gamePPU%`ngameDATA: %gameDATA%`nsevenZEnabled: %sevenZEnabled%`ngameSevenZEnabled: %gameSevenZEnabled%

; Run the game
If (gameType = "game")
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\" . romName . ".BIN"))
{
  primaryExe.Run(" """ . romPath . "\" . romName . ".BIN""")
}
Else If (Fileexist(romPath . "\" . romName . romExtension))
{
  primaryExe.Run(" """ . romPath . "\" . romName . romExtension . """")
}
Else
{
  ScriptError("Unable to find EBOOT.BIN file. Please make sure ""bin"" (and ""lnk"" [LNK] if you are loading from shortcuts) is an RPCS3 extension and also verify the folder structure of your rom.")
}

; Waiting for main emulator window
emuPrimaryWindow.Wait()
emuPrimaryWindow.Active()
emuPrimaryWindow.WaitActive()

If (gameSerial = "" && ((sevenZEnabled = "true" && InStr(sevenZFormats, romExtension)) || romExtension = ".txt"))
{
  ; Find the game serial
  If (Fileexist(emuPath . "\games.yml") && (gameSerial = "" || textRomFolder = ""))
  {
    Loop, read, %emuPath%\games.yml
    {
      StringReplace, gameLine, A_LoopReadLine, /, \, All
      IfInString, gameLine, %gameFolder%
      {
        StringLeft, gameSerial, gameLine, 9
        break
      }
    }
  }

  ; Create the directory junction
  If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
  {
    If (gameSerial != "" && gameType != "")
    {
      RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
      gameDirectoryJunction := "true"
    }
    Else
    {
      ScriptError("Game serial not found in your RPCS3 games.yml file. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
    }
  }
}

; Waiting 3 seconds to see if compiling window appears
If (gameSerial != "" && gamePPU != "true")
{
  WinWait, Compiling, , 3
  If (!ErrorLevel)
  {
    gameInfo["Name"].Value := "COMPILING PPU FILES"
    use7zAnimation := "true"
    Gdip_GraphicsClear(Fade_G5)
    Gosub, UpdateFadeFor7z
    WinWaitClose, Compiling
    gameInfo["Name"].Value := originalGameName
    use7zAnimation := "true"
    Gdip_GraphicsClear(Fade_G5)
    Gosub, UpdateFadeFor7z
  }
}

BezelDraw()
HideAppEnd(hideEmuObj,hideEmu)
FadeInExit()
primaryExe.Process("WaitClose")

; Remove the PPU files if they were extracted or creates PPU archive file if needed
If ((archivePPU = "true" || removePPU = "true") && gameSerial != "")
{
  IfExist, %gamePPUemuPath%\%gameSerial%
  {
    If (archivePPU = "true")
    {
      IfNotExist, %gamePPUarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
        FadeInExit()
      }
      Else
      {
        MostRecentTime := 0
        Loop, %gamePPUemuPath%\%gameSerial%\*, 2
        {
          If (A_LoopFileTimeModified > MostRecentTime)
          {
            MostRecentTime := A_LoopFileTimeModified
          }
        }
        FileGetTime, gamePPUtime, %gamePPUarchive%, M
        If (MostRecentTime > gamePPUtime)
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
          FadeInExit()
        }
      }
    }
    If (removePPU = "true")
    {
      FileRemoveDir, %gamePPUemuPath%\%gameSerial%, 1
    }
  }
  Else
  {
    MostRecentTime := 0
    MostRecentFile := ""
    MostRecentName := ""
    Loop, %gamePPUemuPath%\*, 2
    {
      If (A_LoopFileTimeModified > MostRecentTime)
      {
        MostRecentTime := A_LoopFileTimeModified
        MostRecentFile := A_LoopFileLongPath
        MostRecentName := A_LoopFileName
      }
    }
    If (StrLen(MostRecentName) = 9)
    {
      If (archivePPU = "true")
      {
        IfNotExist, %gamePPUarchive%
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
          FadeInExit()
        }
        Else
        {
          MostRecentTime := 0
          Loop, %gamePPUemuPath%\%MostRecentName%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gamePPUtime, %gamePPUarchive%, M
          If (MostRecentTime > gamePPUtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
            FadeInExit()
          }
        }
      }
      If (removePPU = "true")
      {
        FileRemoveDir, %MostRecentFile%, 1
      }
    }
  }
}

; Remove the Game Data files if they were extracted or creates Game Data archive file if needed
If ((archiveDATA = "true" || removeDATA = "true") && gameSerial != "" && gameType = "disc")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameDATAemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameDATAemuPath%\*, 2
  {
    If (A_LoopFileTimeCreated > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeCreated
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  fileOne := MostRecentFile . "\ICON0.PNG"
  fileTwo := emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\ICON0.PNG"
  FileGetSize, dataSizeOne, %fileOne%
  FileGetSize, dataSizeTwo, %fileTwo%
  FileGetVersion, dataVersionOne, %fileOne%
  FileGetVersion, dataVersionTwo, %fileTwo%
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (dataSizeOne = dataSizeTwo && dataVersionOne = dataVersionTwo && MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    archiveFileCount := archiveFileCount + 1
    archiveFileArray[archiveFileCount] := MostRecentFile
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveDATA = "true")
    {
      IfNotExist, %gameDATAarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameDATAtime, %gameDATAarchive%, M
          FileGetTime, gameDATAarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameDATAtime || gameDATAarchiveTime > gameDATAtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeDATA = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the directory junction
If (gameDirectoryJunction = "true")
{
  RunWait, %ComSpec% /c "rmdir "%emuPath%\dev_hdd0\%gameType%\%gameSerial%", , Hide
}

7zCleanUp()
BezelExit()
FadeOutExit()
ExitModule()

CloseProcess:
  FadeOutStart()
  emuPrimaryWindow.Close()
  Process, Close, %executable%
Return

BezelLabel:
  disableHideBorder := "true"
  disableHideTitleBar := "true"
  disableHideToggleMenu := "true"
Return
 

slashin8r

Member
RL Member
GamesDirectory variable within the RPCS3.ini file can now utilize relative paths (".\" and any number of "..\"). The path is relative to your rom path (the folder storing all your text files).

Code:
MEmu := "RPCS3"
MEmuV := "v0.0.7-9186-5b9df53c Alpha"
MURL := ["https://rpcs3.net"]
MAuthor := ["slashin8r", "wallmachine", "jviegas", "brolly", "aurel102001"]
MVersion := "1.1.2"
MDate := "2019-11-29"
MCRC := ""
iCRC := ""
MID := ""
MSystem := ["Sony Playstation 3"]
;----------------------------------------------------------------------------
; Notes:
; [IMPORTANT]
; There are three methods for using this module.
; 
; METHOD 1: Archives: Use this method if you will be compressing your games to save space.
; 1) Archive your game folders, rename the archive to the title of the game, place all the archives within the same folder, and then add that folder as a romPath in RocketLauncher.
; 2) Add the archive's extension ("7z", "rar", "zip", etc.) for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 2: Shortcuts: Use this method if you will be installing your games directly into RPCS3. Can also be used if you will be storing your non-archive games outside of the RPCS3 installation directories.
; 1) Create shortcuts of your EBOOT.BIN files, rename them to the title of the game, place them all within the same folder, then add that folder as a romPath in RocketLauncher.
; 2) Add the "lnk" (LNK) extension for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 3: Text Files: Use this method if you are converting over from a RPCS3 module prior to version 1.0.2.
; 1) Place game folders all within the same folder. It is best to not rename these folders. (They will have names such as "BLES#####", "BCUS#####", "NPUB#####", etc.)
; 2) Create a text file for every game, named as the title of the game. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; [You can skip step 3 for DISC games as long as the name of the text file matches the name of the game folder]
; [This makes converting from an older RPCS3 module much easier, but it is still recommended to complete this step]
; [HDD games (gameID usually starts with "N") must have step 3 completed]
; 3) Open the text file and add the name of the game folder on the first line. ("BLES#####", "BCUS#####", "NPUB#####", etc.)
; 4) Place these text files within the folder storing your games.
; [If you wish to have the text files in a separate folder, edit the "GamesDirectory" variable, found within your RPCS3.ini file, to match the full path of the folder storing your games]
; 5) Add the folder containing your text files as a romPath in RocketLauncher.
; 6) Add the "txt" extension for the RPCS3 emulator within RocketLauncher.
; 7) Generate a new database based on the new rom path.
; 8) Audit all games for the system and enjoy.
; [IMPORTANT]
; 
; 
; 
; To save additional space, this module now automatically compresses each game's PPU folder and Game Data folder (if exists) as long as it is enabled in your RPCS3.ini file.
; PPU file saved in: %romPath%\cache\%romName%_%A_ComputerName%.7z (PPU files are hardware specific, so the computer name is added to the end of the filename)
; Game Data file saved in: %romPath%\data\%romName%_data.7z ("_data" added to the end of the filename so there is no conflict with the rom name)
; 
; Example:
; Rom File = "D:\PS3\PS3 Test Game.rar"
; A_ComputerName = "PC001"
; 
; PPU File = "D:\PS3\cache\PS3 Test Game_PC001.7z")
; Game Data File = "D:\PS3\data\PS3 Test Game_data.7z")
; 
; 
; 
; Known Issues:
; 1) Additional progress bar appears just before the game is extracted/loaded (after the PPU and/or DATA archives are extracted).
; 
; 
; 
; Coming Soon:
; 1) More data files to archive found within "dev_hdd1\caches" folder.
;----------------------------------------------------------------------------

StartModule()
BezelGUI()
FadeInStart()

primaryExe := new Emulator(emuPath . "\" . executable)
primaryWindowClassName := "Qt5QWindowIcon"
emuPrimaryWindow := new Window(new WindowTitle(,primaryWindowClassName, executable))

; Finding emulator config file
Rpcs3config := new File(emuPath . "\config.yml")
Rpcs3config.CheckFile("Could not find RPCS3 config.yml! Run your emulator, go to Settings and save them.")

; Finding emulator games file
Rpcs3games := new File(emuPath . "\games.yml")
Rpcs3games.CheckFile("Could not find RPCS3 games.yml! Update this file with your list of game serials and game installation directories.")

textGameFolder := moduleIni.Read("Settings", "GamesDirectory","",,1)
archivePPU := moduleIni.Read("Settings", "ArchivePPU","false",,1)
archiveDATA := moduleIni.Read("Settings", "ArchiveDATA","false",,1)
removePPU := moduleIni.Read("Settings", "RemovePPU","false",,1)
removeDATA := moduleIni.Read("Settings", "RemoveDATA","false",,1)

; Check if "GamesDirectory" variable is using a relative path and set it to the correct full path.
StringLeft, stringTest, textGameFolder, 2
If (stringTest = ".\")
{
  StringTrimLeft, textGameFolder, textGameFolder, 1
  textGameFolder := romPath . textGameFolder
}
Else If (stringTest = "..")
{
  StringSplit, textGameFolders, textGameFolder, "\"
  textGameFoldersCount := 0
  tempPath := ""
  Loop, %textGameFolders0%
  {
    element := textGameFolders%A_Index%
    If (element = "..")
    {
      textGameFoldersCount := textGameFoldersCount + 1
    }
    Else
    {
      tempPath := tempPath . element
      If (A_Index != textGameFolders0)
      {
        tempPath := tempPath . "\"
      }
    }
  }
  textGameFolder := tempPath
  StringSplit, romPathFolders, romPath, "\"
  romGameFoldersCount := romPathFolders0 - textGameFoldersCount
  If (romGameFoldersCount > 0)
  {
    tempPath := ""
    Loop, %romGameFoldersCount%
    {
      element := romPathFolders%A_Index%
      tempPath := tempPath . element . "\"
    }
    textGameFolder := tempPath . textGameFolder
  }
}

BezelStart()

hideEmuObj := Object(emuPrimaryWindow,1)
HideAppStart(hideEmuObj,hideEmu)

; Set variables
gameSevenZEnabled := sevenZEnabled
gameType := ""
gameSerial := ""
gameDirectoryJunction := "false"
gamePPU := "false"
gamePPUarchive := romPath . "\cache\" . romName . "_" . A_ComputerName . ".7z"
gamePPUromPath := romPath . "\cache"
gamePPUromName := romName . "_" . A_ComputerName
gamePPUromExtension := ".7z"
gamePPUemuPath := emuPath . "\cache"
gameDATA := "false"
gameDATAarchive := romPath . "\data\" . romName . "_data.7z"
gameDATAromPath := romPath . "\data"
gameDATAromName := romName . "_data"
gameDATAromExtension := "7z"
gameDATAemuPath := emuPath . "\dev_hdd0\game"
textRomFolder := ""

If (romExtension = ".txt")
{
  FileReadLine, textRomFolder, %romPath%\%romName%%romExtension%, 1
  If (textGameFolder = "")
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(romPath . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . textRomFolder . "\""")
      }
    }
  }
  Else
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(textGameFolder . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . textRomFolder . "\""")
      }
    }
  }
}
Else If (romExtension = ".lnk" && Fileexist(romPath . "\" . romName . romExtension))
{
  FileGetShortCut, %romPath%\%romName%%romExtension%, shortcutTarget
  StringReplace, romPath, shortcutTarget, \EBOOT.BIN
}
Else If (InStr(sevenZFormats, romExtension)) {
  gameSerial := RLObject.getZipRootFolder(romPath . "\" . romName . romExtension)
}

; Store old values for later
originalRomPath := romPath
originalRomName := romName
originalRomExtension := romExtension
originalSevenZRomPath := sevenZRomPath
originalGameName := gameInfo["Name"].Value

; Find game location
gameFolder := romPath
If (sevenZEnabled = "true" && InStr(sevenZFormats, romExtension))
{
  gameFolder := sevenZExtractPath . "\" . romName
  If (sevenZAttachSystemName = "true")
  {
    gameFolder := sevenZExtractPath . "\" . systemName . "\" . romName
  }
}
Else If (romExtension = ".lnk" || romExtension = ".txt")
{
  StringReplace, gameFolder, gameFolder, \USRDIR
  StringReplace, gameFolder, gameFolder, \PS3_GAME
}

;MsgBox, gamePPUarchive: %gamePPUarchive%`ngamePPUemuPath: %gamePPUemuPath%`ngameDATAarchive: %gameDATAarchive%`ngameDATAemuPath: %gameDATAemuPath%

; Extract PPU files if they exist
If (archivePPU = "true" && Fileexist(gamePPUarchive))
{
  gameInfo["Name"].Value := "EXTRACTING COMPILED PPU FILES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gamePPUarchive)
  romExSize := RLObject.getZipExtractedSize(gamePPUarchive)
  sevenZRomPath := gamePPUemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gamePPUromPath, gamePPUromName, gamePPUromExtension, gamePPUemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gamePPUarchive%" -aos -o"%gamePPUemuPath%", sevenZPID, Hide
  gamePPU := "true"
}

; Extract Game Data files if they exist
If (archiveDATA = "true" && Fileexist(gameDATAarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME DATA"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameDATAarchive)
  romExSize := RLObject.getZipExtractedSize(gameDATAarchive)
  sevenZRomPath := gameDATAemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameDATAromPath, gameDATAromName, gameDATAromExtension, gameDATAemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameDATAarchive%" -aos -o"%gameDATAemuPath%", sevenZPID, Hide
  gameDATA := "true"
}

If (gamePPU := "true" || gameDATA := "true")
{
  sevenZRomPath := originalSevenZRomPath
  gameInfo["Name"].Value := originalGameName
  Gdip_GraphicsClear(Fade_G5)
}
romPath := originalRomPath
romName := originalRomName
romExtension := originalRomExtension
romExPercentage := 0
layer3Percentage := 0
romExSize := 1000000000
use7zAnimation := "true"
Gosub, UpdateFadeFor7z

7z(romPath, romName, romExtension, sevenZExtractPath)

romFolder := romPath

IfInString, romPath, \USRDIR
{
  FoundPos := InStr(romPath, "\USRDIR") + 6
  StringLeft, romPath, romPath, %FoundPos%
}

; Find the game location and determine the type of game (disc or hdd)
StringRight, stringTest, romFolder, 6
If (stringTest = "USRDIR")
{
  gameType := "game"
  StringReplace, romFolder, romFolder, \USRDIR
  StringRight, stringTest, romFolder, 8
  If (stringTest = "PS3_GAME")
  {
    gameType := "disc"
    StringReplace, romFolder, romFolder, \PS3_GAME
  }
  If (romExtension = ".lnk" || (romExtension = ".txt" && textRomFolder != "") || (gameSerial != "" && gameType != ""))
  {
    If (romExtension = ".lnk" || romExtension = ".bin")
    {
      StringRight, gameSerial, romFolder, 9
    }
    
    ; Create the directory junction
    If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
    {
      If (gameSerial != "" && gameType != "")
      {
        RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
        gameDirectoryJunction := "true"
      }
      Else
      {
        ScriptError("Game serial not found. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
      }
    }
  }
}
Else If (sevenZEnabled = "true" && (romPath = originalRomPath || romPath = "") && InStr(sevenZFormats, romExtension))
{
  ScriptError("Rom was not found in the USRDIR directory. Please make sure ""bin"" is an RPCS3 extension and also verify the folder structure of your rom.")
}

;MsgBox, romPath: %romPath%`nromName: %romName%`nromExtension: %romExtension%`ngameType: %gameType%`ngameSerial: %gameSerial%`ngameDirectoryJunction: %gameDirectoryJunction%`ngamePPU: %gamePPU%`ngameDATA: %gameDATA%`nsevenZEnabled: %sevenZEnabled%`ngameSevenZEnabled: %gameSevenZEnabled%

; Run the game
If (gameType = "game")
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\" . romName . ".BIN"))
{
  primaryExe.Run(" """ . romPath . "\" . romName . ".BIN""")
}
Else If (Fileexist(romPath . "\" . romName . romExtension))
{
  primaryExe.Run(" """ . romPath . "\" . romName . romExtension . """")
}
Else
{
  ScriptError("Unable to find EBOOT.BIN file. Please make sure ""bin"" (and ""lnk"" [LNK] if you are loading from shortcuts) is an RPCS3 extension and also verify the folder structure of your rom.")
}

; Waiting for main emulator window
emuPrimaryWindow.Wait()
emuPrimaryWindow.Active()
emuPrimaryWindow.WaitActive()

If (gameSerial = "" && ((sevenZEnabled = "true" && InStr(sevenZFormats, romExtension)) || romExtension = ".txt"))
{
  ; Find the game serial
  If (Fileexist(emuPath . "\games.yml") && (gameSerial = "" || textRomFolder = ""))
  {
    Loop, read, %emuPath%\games.yml
    {
      StringReplace, gameLine, A_LoopReadLine, /, \, All
      IfInString, gameLine, %gameFolder%
      {
        StringLeft, gameSerial, gameLine, 9
        break
      }
    }
  }

  ; Create the directory junction
  If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
  {
    If (gameSerial != "" && gameType != "")
    {
      RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
      gameDirectoryJunction := "true"
    }
    Else
    {
      ScriptError("Game serial not found in your RPCS3 games.yml file. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
    }
  }
}

; Waiting 3 seconds to see if compiling window appears
If (gameSerial != "" && gamePPU != "true")
{
  WinWait, Compiling, , 3
  If (!ErrorLevel)
  {
    gameInfo["Name"].Value := "COMPILING PPU FILES"
    use7zAnimation := "true"
    Gdip_GraphicsClear(Fade_G5)
    Gosub, UpdateFadeFor7z
    WinWaitClose, Compiling
    gameInfo["Name"].Value := originalGameName
    use7zAnimation := "true"
    Gdip_GraphicsClear(Fade_G5)
    Gosub, UpdateFadeFor7z
  }
}

BezelDraw()
HideAppEnd(hideEmuObj,hideEmu)
FadeInExit()
primaryExe.Process("WaitClose")

; Remove the PPU files if they were extracted or creates PPU archive file if needed
If ((archivePPU = "true" || removePPU = "true") && gameSerial != "")
{
  IfExist, %gamePPUemuPath%\%gameSerial%
  {
    If (archivePPU = "true")
    {
      IfNotExist, %gamePPUarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
        FadeInExit()
      }
      Else
      {
        MostRecentTime := 0
        Loop, %gamePPUemuPath%\%gameSerial%\*, 2
        {
          If (A_LoopFileTimeModified > MostRecentTime)
          {
            MostRecentTime := A_LoopFileTimeModified
          }
        }
        FileGetTime, gamePPUtime, %gamePPUarchive%, M
        If (MostRecentTime > gamePPUtime)
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
          FadeInExit()
        }
      }
    }
    If (removePPU = "true")
    {
      FileRemoveDir, %gamePPUemuPath%\%gameSerial%, 1
    }
  }
  Else
  {
    MostRecentTime := 0
    MostRecentFile := ""
    MostRecentName := ""
    Loop, %gamePPUemuPath%\*, 2
    {
      If (A_LoopFileTimeModified > MostRecentTime)
      {
        MostRecentTime := A_LoopFileTimeModified
        MostRecentFile := A_LoopFileLongPath
        MostRecentName := A_LoopFileName
      }
    }
    If (StrLen(MostRecentName) = 9)
    {
      If (archivePPU = "true")
      {
        IfNotExist, %gamePPUarchive%
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
          FadeInExit()
        }
        Else
        {
          MostRecentTime := 0
          Loop, %gamePPUemuPath%\%MostRecentName%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gamePPUtime, %gamePPUarchive%, M
          If (MostRecentTime > gamePPUtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
            FadeInExit()
          }
        }
      }
      If (removePPU = "true")
      {
        FileRemoveDir, %MostRecentFile%, 1
      }
    }
  }
}

; Remove the Game Data files if they were extracted or creates Game Data archive file if needed
If ((archiveDATA = "true" || removeDATA = "true") && gameSerial != "" && gameType = "disc")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameDATAemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameDATAemuPath%\*, 2
  {
    If (A_LoopFileTimeCreated > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeCreated
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  fileOne := MostRecentFile . "\ICON0.PNG"
  fileTwo := emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\ICON0.PNG"
  FileGetSize, dataSizeOne, %fileOne%
  FileGetSize, dataSizeTwo, %fileTwo%
  FileGetVersion, dataVersionOne, %fileOne%
  FileGetVersion, dataVersionTwo, %fileTwo%
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (dataSizeOne = dataSizeTwo && dataVersionOne = dataVersionTwo && MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    archiveFileCount := archiveFileCount + 1
    archiveFileArray[archiveFileCount] := MostRecentFile
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveDATA = "true")
    {
      IfNotExist, %gameDATAarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameDATAtime, %gameDATAarchive%, M
          FileGetTime, gameDATAarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameDATAtime || gameDATAarchiveTime > gameDATAtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeDATA = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the directory junction
If (gameDirectoryJunction = "true")
{
  RunWait, %ComSpec% /c "rmdir "%emuPath%\dev_hdd0\%gameType%\%gameSerial%", , Hide
}

7zCleanUp()
BezelExit()
FadeOutExit()
ExitModule()

CloseProcess:
  FadeOutStart()
  emuPrimaryWindow.Close()
  Process, Close, %executable%
Return

BezelLabel:
  disableHideBorder := "true"
  disableHideTitleBar := "true"
  disableHideToggleMenu := "true"
Return
 

oldhag270

Member
RL Member
Games load fine with the new update,is there a way to not show the emulator at all like in previous versions.Keep up the good work.
 

slashin8r

Member
RL Member
Games load fine with the new update,is there a way to not show the emulator at all like in previous versions.Keep up the good work.

It does hide the emulator if you have "Hide Emulator" option enabled or if you use fade screens.

Edit: Do you mean the Compiling PPU window?
 
Last edited:

slashin8r

Member
RL Member
Compiling PPU window is now hidden again. Module now archives the additional game data caches found within the "dev_hdd1\caches" folder. New variables added to the RPCS3.ini file.

RPCS3.ahk:
Code:
MEmu := "RPCS3"
MEmuV := "v0.0.7-9186-5b9df53c Alpha"
MURL := ["https://rpcs3.net"]
MAuthor := ["slashin8r", "wallmachine", "jviegas", "brolly", "aurel102001"]
MVersion := "1.1.3"
MDate := "2019-11-29"
MCRC := ""
iCRC := ""
MID := ""
MSystem := ["Sony Playstation 3"]
;----------------------------------------------------------------------------
; Notes:
; [IMPORTANT]
; There are three methods for using this module.
; 
; METHOD 1: Archives: Use this method if you will be compressing your games to save space.
; 1) Archive your game folders, rename the archive to the title of the game, place all the archives within the same folder, and then add that folder as a romPath in RocketLauncher.
; 2) Add the archive's extension ("7z", "rar", "zip", etc.) for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 2: Shortcuts: Use this method if you will be installing your games directly into RPCS3. Can also be used if you will be storing your non-archive games outside of the RPCS3 installation directories.
; 1) Create shortcuts of your EBOOT.BIN files, rename them to the title of the game, place them all within the same folder, then add that folder as a romPath in RocketLauncher.
; 2) Add the "lnk" (LNK) extension for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 3: Text Files: Use this method if you are converting over from a RPCS3 module prior to version 1.0.2.
; 1) Place game folders all within the same folder. It is best to not rename these folders. (They will have names such as "BLES#####", "BCUS#####", "NPUB#####", etc.)
; 2) Create a text file for every game, named as the title of the game. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; [You can skip step 3 for DISC games as long as the name of the text file matches the name of the game folder]
; [This makes converting from an older RPCS3 module much easier, but it is still recommended to complete this step]
; [HDD games (gameID usually starts with "N") must have step 3 completed]
; 3) Open the text file and add the name of the game folder on the first line. ("BLES#####", "BCUS#####", "NPUB#####", etc.)
; 4) Place these text files within the folder storing your games.
; [If you wish to have the text files in a separate folder, edit the "GamesDirectory" variable, found within your RPCS3.ini file, to match the full path of the folder storing your games]
; 5) Add the folder containing your text files as a romPath in RocketLauncher.
; 6) Add the "txt" extension for the RPCS3 emulator within RocketLauncher.
; 7) Generate a new database based on the new rom path.
; 8) Audit all games for the system and enjoy.
; [IMPORTANT]
; 
; 
; 
; To save additional space, this module now automatically compresses each game's PPU folder and Game Data folder (if exists) as long as it is enabled in your RPCS3.ini file.
; PPU file saved in: %romPath%\cache\%romName%_%A_ComputerName%.7z (PPU files are hardware specific, so the computer name is added to the end of the filename)
; Game Data file saved in: %romPath%\data\%romName%_data.7z ("_data" added to the end of the filename so there is no conflict with the rom name)
; 
; Example:
; Rom File = "D:\PS3\PS3 Test Game.rar"
; A_ComputerName = "PC001"
; 
; PPU File = "D:\PS3\cache\PS3 Test Game_PC001.7z")
; Game Data File = "D:\PS3\data\PS3 Test Game_data.7z")
; 
; 
; 
; Known Issues:
; 1) Additional progress bar appears just before the game is extracted/loaded (after the PPU and/or DATA archives are extracted). This problem is not specific to this module.
; 
; 
; 
; Coming Soon:
; 1) Custom paths for storing archived PPU, DATA and CACHES files.
;----------------------------------------------------------------------------

StartModule()
BezelGUI()
FadeInStart()

primaryExe := new Emulator(emuPath . "\" . executable)
primaryWindowClassName := "Qt5QWindowIcon"
emuPrimaryWindow := new Window(new WindowTitle(,primaryWindowClassName, executable))

; Finding emulator config file
Rpcs3config := new File(emuPath . "\config.yml")
Rpcs3config.CheckFile("Could not find RPCS3 config.yml! Run your emulator, go to Settings and save them.")

; Finding emulator games file
Rpcs3games := new File(emuPath . "\games.yml")
Rpcs3games.CheckFile("Could not find RPCS3 games.yml! Update this file with your list of game serials and game installation directories.")

textGameFolder := moduleIni.Read("Settings", "GamesDirectory","",,1)
archivePPU := moduleIni.Read("Settings", "ArchivePPU","false",,1)
archiveDATA := moduleIni.Read("Settings", "ArchiveDATA","false",,1)
archiveCACHES := moduleIni.Read("Settings", "ArchiveCACHES","false",,1)
removePPU := moduleIni.Read("Settings", "RemovePPU","false",,1)
removeDATA := moduleIni.Read("Settings", "RemoveDATA","false",,1)
removeCACHES := moduleIni.Read("Settings", "RemoveCACHES","false",,1)

; Check if "GamesDirectory" variable is using a relative path and set it to the correct full path.
StringLeft, stringTest, textGameFolder, 2
If (stringTest = ".\")
{
  StringTrimLeft, textGameFolder, textGameFolder, 1
  textGameFolder := romPath . textGameFolder
}
Else If (stringTest = "..")
{
  StringSplit, textGameFolders, textGameFolder, "\"
  textGameFoldersCount := 0
  tempPath := ""
  Loop, %textGameFolders0%
  {
    element := textGameFolders%A_Index%
    If (element = "..")
    {
      textGameFoldersCount := textGameFoldersCount + 1
    }
    Else
    {
      tempPath := tempPath . element
      If (A_Index != textGameFolders0)
      {
        tempPath := tempPath . "\"
      }
    }
  }
  textGameFolder := tempPath
  StringSplit, romPathFolders, romPath, "\"
  romGameFoldersCount := romPathFolders0 - textGameFoldersCount
  If (romGameFoldersCount > 0)
  {
    tempPath := ""
    Loop, %romGameFoldersCount%
    {
      element := romPathFolders%A_Index%
      tempPath := tempPath . element . "\"
    }
    textGameFolder := tempPath . textGameFolder
  }
}

BezelStart()

hideEmuObj := Object(emuPrimaryWindow,1)
HideAppStart(hideEmuObj,hideEmu)

; Set variables
gameSevenZEnabled := sevenZEnabled
gameType := ""
gameSerial := ""
gameDirectoryJunction := "false"
gamePPU := "false"
gamePPUarchive := romPath . "\cache\" . romName . "_" . A_ComputerName . ".7z"
gamePPUromPath := romPath . "\cache"
gamePPUromName := romName . "_" . A_ComputerName
gamePPUromExtension := ".7z"
gamePPUemuPath := emuPath . "\cache"
gameDATA := "false"
gameDATAarchive := romPath . "\data\" . romName . "_data.7z"
gameDATAromPath := romPath . "\data"
gameDATAromName := romName . "_data"
gameDATAromExtension := "7z"
gameDATAemuPath := emuPath . "\dev_hdd0\game"
gameCACHES := "false"
gameCACHESarchive := romPath . "\data\caches\" . romName . "_hdd1.7z"
gameCACHESromPath := romPath . "\data\caches"
gameCACHESromName := romName . "_hdd1"
gameCACHESromExtension := "7z"
gameCACHESemuPath := emuPath . "\dev_hdd1\caches"
textRomFolder := ""

If (romExtension = ".txt")
{
  FileReadLine, textRomFolder, %romPath%\%romName%%romExtension%, 1
  If (textGameFolder = "")
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(romPath . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . textRomFolder . "\""")
      }
    }
  }
  Else
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(textGameFolder . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . textRomFolder . "\""")
      }
    }
  }
}
Else If (romExtension = ".lnk" && Fileexist(romPath . "\" . romName . romExtension))
{
  FileGetShortCut, %romPath%\%romName%%romExtension%, shortcutTarget
  StringReplace, romPath, shortcutTarget, \EBOOT.BIN
}
Else If (InStr(sevenZFormats, romExtension)) {
  gameSerial := RLObject.getZipRootFolder(romPath . "\" . romName . romExtension)
}

; Store old values for later
originalRomPath := romPath
originalRomName := romName
originalRomExtension := romExtension
originalSevenZRomPath := sevenZRomPath
originalGameName := gameInfo["Name"].Value

; Find game location
gameFolder := romPath
If (sevenZEnabled = "true" && InStr(sevenZFormats, romExtension))
{
  gameFolder := sevenZExtractPath . "\" . romName
  If (sevenZAttachSystemName = "true")
  {
    gameFolder := sevenZExtractPath . "\" . systemName . "\" . romName
  }
}
Else If (romExtension = ".lnk" || romExtension = ".txt")
{
  StringReplace, gameFolder, gameFolder, \USRDIR
  StringReplace, gameFolder, gameFolder, \PS3_GAME
}

;MsgBox, gamePPUarchive: %gamePPUarchive%`ngamePPUemuPath: %gamePPUemuPath%`ngameDATAarchive: %gameDATAarchive%`ngameDATAemuPath: %gameDATAemuPath%

; Extract PPU files if they exist
If (archivePPU = "true" && Fileexist(gamePPUarchive))
{
  gameInfo["Name"].Value := "EXTRACTING COMPILED PPU FILES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gamePPUarchive)
  romExSize := RLObject.getZipExtractedSize(gamePPUarchive)
  sevenZRomPath := gamePPUemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gamePPUromPath, gamePPUromName, gamePPUromExtension, gamePPUemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gamePPUarchive%" -aos -o"%gamePPUemuPath%", sevenZPID, Hide
  gamePPU := "true"
}

; Extract Game Data files if they exist
If (archiveDATA = "true" && Fileexist(gameDATAarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME DATA"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameDATAarchive)
  romExSize := RLObject.getZipExtractedSize(gameDATAarchive)
  sevenZRomPath := gameDATAemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameDATAromPath, gameDATAromName, gameDATAromExtension, gameDATAemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameDATAarchive%" -aos -o"%gameDATAemuPath%", sevenZPID, Hide
  gameDATA := "true"
}

; Extract Game Data files if they exist
If (archiveCACHES = "true" && Fileexist(gameCACHESarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME CACHES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameCACHESarchive)
  romExSize := RLObject.getZipExtractedSize(gameCACHESarchive)
  sevenZRomPath := gameCACHESemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameCACHESromPath, gameCACHESromName, gameCACHESromExtension, gameCACHESemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameCACHESarchive%" -aos -o"%gameCACHESemuPath%", sevenZPID, Hide
  gameCACHES := "true"
}

If (gamePPU := "true" || gameDATA := "true" || gameCACHES := "true")
{
  sevenZRomPath := originalSevenZRomPath
  gameInfo["Name"].Value := originalGameName
  Gdip_GraphicsClear(Fade_G5)
}
romPath := originalRomPath
romName := originalRomName
romExtension := originalRomExtension
romExPercentage := 0
layer3Percentage := 0
romExSize := 1000000000
use7zAnimation := "true"
Gosub, UpdateFadeFor7z

7z(romPath, romName, romExtension, sevenZExtractPath)

romFolder := romPath

IfInString, romPath, \USRDIR
{
  FoundPos := InStr(romPath, "\USRDIR") + 6
  StringLeft, romPath, romPath, %FoundPos%
}

; Find the game location and determine the type of game (disc or hdd)
StringRight, stringTest, romFolder, 6
If (stringTest = "USRDIR")
{
  gameType := "game"
  StringReplace, romFolder, romFolder, \USRDIR
  StringRight, stringTest, romFolder, 8
  If (stringTest = "PS3_GAME")
  {
    gameType := "disc"
    StringReplace, romFolder, romFolder, \PS3_GAME
  }
  If (romExtension = ".lnk" || (romExtension = ".txt" && textRomFolder != "") || (gameSerial != "" && gameType != "" && romExtension != ".txt"))
  {
    If (romExtension = ".lnk" || romExtension = ".bin")
    {
      StringRight, gameSerial, romFolder, 9
    }
    
    ; Create the directory junction
    If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
    {
      If (gameSerial != "" && gameType != "")
      {
        RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
        gameDirectoryJunction := "true"
      }
      Else
      {
        ScriptError("Game serial not found. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
      }
    }
  }
}
Else If (sevenZEnabled = "true" && (romPath = originalRomPath || romPath = "") && InStr(sevenZFormats, romExtension))
{
  ScriptError("Rom was not found in the USRDIR directory. Please make sure ""bin"" is an RPCS3 extension and also verify the folder structure of your rom.")
}

If (romExtension = ".txt" && gameSerial = originalRomName)
{
  ; Find the game serial
  If (Fileexist(emuPath . "\games.yml") && (gameSerial = "" || textRomFolder = ""))
  {
    Loop, read, %emuPath%\games.yml
    {
      StringReplace, gameLine, A_LoopReadLine, /, \, All
      IfInString, gameLine, %gameFolder%
      {
        StringLeft, gameSerial, gameLine, 9
        break
      }
    }
  }

  ; Create the directory junction
  If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
  {
    If (gameSerial != "" && gameType != "")
    {
      RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
      gameDirectoryJunction := "true"
    }
    Else
    {
      ScriptError("Game serial not found in your RPCS3 games.yml file. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
    }
  }
}

;MsgBox, romPath: %romPath%`nromName: %romName%`nromExtension: %romExtension%`ngameType: %gameType%`ngameSerial: %gameSerial%`ngameDirectoryJunction: %gameDirectoryJunction%`ngamePPU: %gamePPU%`ngameDATA: %gameDATA%`nsevenZEnabled: %sevenZEnabled%`ngameSevenZEnabled: %gameSevenZEnabled%

; Run the game
If (gameType = "game")
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\" . romName . ".BIN"))
{
  primaryExe.Run(" """ . romPath . "\" . romName . ".BIN""")
}
Else If (Fileexist(romPath . "\" . romName . romExtension))
{
  primaryExe.Run(" """ . romPath . "\" . romName . romExtension . """")
}
Else
{
  ScriptError("Unable to find EBOOT.BIN file. Please make sure ""bin"" (and ""lnk"" [LNK] if you are loading from shortcuts) is an RPCS3 extension and also verify the folder structure of your rom.")
}

; Waiting for main emulator window
emuPrimaryWindow.Wait()
emuPrimaryWindow.Active()
emuPrimaryWindow.WaitActive()

If (gameSerial = "" && (sevenZEnabled = "true" && InStr(sevenZFormats, romExtension)))
{
  ; Find the game serial
  If (Fileexist(emuPath . "\games.yml") && (gameSerial = "" || textRomFolder = ""))
  {
    Loop, read, %emuPath%\games.yml
    {
      StringReplace, gameLine, A_LoopReadLine, /, \, All
      IfInString, gameLine, %gameFolder%
      {
        StringLeft, gameSerial, gameLine, 9
        break
      }
    }
  }

  ; Create the directory junction
  If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
  {
    If (gameSerial != "" && gameType != "")
    {
      RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%gameFolder%", , Hide
      gameDirectoryJunction := "true"
    }
    Else
    {
      ScriptError("Game serial not found in your RPCS3 games.yml file. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
    }
  }
}

; Waiting 3 seconds to see if compiling window appears
If (gameSerial != "" && gamePPU != "true")
{
  WinWait, Compiling, , 3
  If (!ErrorLevel)
  {
    gameInfo["Name"].Value := "COMPILING PPU FILES"
    use7zAnimation := "true"
    Gdip_GraphicsClear(Fade_G5)
    Gosub, UpdateFadeFor7z
    WinHide, Compiling
    WinWaitClose, Compiling
    gameInfo["Name"].Value := originalGameName
    use7zAnimation := "true"
    Gdip_GraphicsClear(Fade_G5)
    Gosub, UpdateFadeFor7z
  }
}

BezelDraw()
HideAppEnd(hideEmuObj,hideEmu)
FadeInExit()
primaryExe.Process("WaitClose")

; Remove the PPU files if they were extracted or creates PPU archive file if needed
If ((archivePPU = "true" || removePPU = "true") && gameSerial != "")
{
  IfExist, %gamePPUemuPath%\%gameSerial%
  {
    If (archivePPU = "true")
    {
      IfNotExist, %gamePPUarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
        FadeInExit()
      }
      Else
      {
        MostRecentTime := 0
        Loop, %gamePPUemuPath%\%gameSerial%\*, 2
        {
          If (A_LoopFileTimeModified > MostRecentTime)
          {
            MostRecentTime := A_LoopFileTimeModified
          }
        }
        FileGetTime, gamePPUtime, %gamePPUarchive%, M
        If (MostRecentTime > gamePPUtime)
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
          FadeInExit()
        }
      }
    }
    If (removePPU = "true")
    {
      FileRemoveDir, %gamePPUemuPath%\%gameSerial%, 1
    }
  }
  Else
  {
    MostRecentTime := 0
    MostRecentFile := ""
    MostRecentName := ""
    Loop, %gamePPUemuPath%\*, 2
    {
      If (A_LoopFileTimeModified > MostRecentTime)
      {
        MostRecentTime := A_LoopFileTimeModified
        MostRecentFile := A_LoopFileLongPath
        MostRecentName := A_LoopFileName
      }
    }
    If (StrLen(MostRecentName) = 9)
    {
      If (archivePPU = "true")
      {
        IfNotExist, %gamePPUarchive%
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
          FadeInExit()
        }
        Else
        {
          MostRecentTime := 0
          Loop, %gamePPUemuPath%\%MostRecentName%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gamePPUtime, %gamePPUarchive%, M
          If (MostRecentTime > gamePPUtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
            FadeInExit()
          }
        }
      }
      If (removePPU = "true")
      {
        FileRemoveDir, %MostRecentFile%, 1
      }
    }
  }
}

; Remove the Game Data files if they were extracted or creates Game Data archive file if needed
If ((archiveDATA = "true" || removeDATA = "true") && gameSerial != "" && gameType = "disc")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameDATAemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameDATAemuPath%\*, 2
  {
    If (A_LoopFileTimeModified > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeModified
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  fileOne := MostRecentFile . "\ICON0.PNG"
  fileTwo := emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\ICON0.PNG"
  FileGetSize, dataSizeOne, %fileOne%
  FileGetSize, dataSizeTwo, %fileTwo%
  FileGetVersion, dataVersionOne, %fileOne%
  FileGetVersion, dataVersionTwo, %fileTwo%
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (dataSizeOne = dataSizeTwo && dataVersionOne = dataVersionTwo && MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    If !HasVal(archiveFileArray, MostRecentFile)
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := MostRecentFile
    }
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveDATA = "true")
    {
      IfNotExist, %gameDATAarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameDATAtime, %gameDATAarchive%, M
          FileGetTime, gameDATAarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameDATAtime || gameDATAarchiveTime > gameDATAtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeDATA = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the Game Caches if they were extracted or creates Game Caches archive file if needed
If ((archiveCACHES = "true" || removeCACHES = "true") && gameSerial != "")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameCACHESemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameCACHESemuPath%\*, 2
  {
    If (A_LoopFileTimeModified > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeModified
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    If !HasVal(archiveFileArray, MostRecentFile)
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := MostRecentFile
    }
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveCACHES = "true")
    {
      IfNotExist, %gameCACHESarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME CACHES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameCACHESarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameCACHEStime, %gameCACHESarchive%, M
          FileGetTime, gameCACHESarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameCACHEStime || gameCACHESarchiveTime > gameCACHEStime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME CACHES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameCACHESarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeCACHES = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the directory junction
If (gameDirectoryJunction = "true")
{
  RunWait, %ComSpec% /c "rmdir "%emuPath%\dev_hdd0\%gameType%\%gameSerial%", , Hide
}

7zCleanUp()
BezelExit()
FadeOutExit()
ExitModule()

CloseProcess:
  FadeOutStart()
  emuPrimaryWindow.Close()
  Process, Close, %executable%
Return

BezelLabel:
  disableHideBorder := "true"
  disableHideTitleBar := "true"
  disableHideToggleMenu := "true"
Return

HasVal(haystack, needle) {
  for index, value in haystack
    if (value = needle)
      return index
  if !(IsObject(haystack))
    throw Exception("Bad haystack!", -1, haystack)
  return 0
}

;archiveFile := "C:\Users\User\Desktop\Test\BLUS31554"
;folderSize := 0
;Loop, %archiveFile%\*.*, 1, 1
;{
;  folderSize += %A_LoopFileSize%
;}
;Progress, b w420, , ARCHIVING COMPILED PPU FILES
;Progress, 0
;Run, %ComSpec% /c ""C:\Games\RocketLauncher\Utilities\7-Zip\7z.exe" a "%archiveFile%.7z" "%archiveFile%", , Hide
;Sleep, 500
;Loop
;{
;  FileGetSize, archiveSize, %archiveFile%.7z
;  romArchivePercentage := Floor((archiveSize/folderSize)*100)
;  Progress, %romArchivePercentage%
;  Process, Exist, 7z.exe
;  ToolTip, %archiveSize%/%folderSize%
;  If (!ErrorLevel)
;  {
;    Break
;  }
;  Sleep, 100
;}
;Progress, Off

RPCS3.ini:
Code:
# GamesDirectory: Path to PS3 game folders (relative to rom path). Only used with text file method when you wish to store your games and dummy text files in separate folders. (Default: "")
# ArchivePPU: If true, the module will archive your games' PPU files, found within the RPCS3 "cache" folder, to save space and for quicker loading. (Default: "false")
# ArchiveDATA: If true, the module will archive your games' additional data, found within the RPCS3 "dev_hdd0\game" folder, to save space and for quicker loading. (Default: "false")
# ArchiveCACHES: If true, the module will archive your games' additional caches, found within the RPCS3 "dev_hdd1\caches" folder, to save space and for quicker loading. (Default: "false")
# RemovePPU: If true, the module will remove your games' PPU files, found within the RPCS3 "cache" folder, to save space. (Default: "false")
# RemoveDATA: If true, the module will remove your games' additional data, found within the RPCS3 "dev_hdd0\game" folder, to save space. (Default: "false")
# RemoveCACHES: If true, the module will remove your games' additional caches, found within the RPCS3 "dev_hdd1\caches" folder, to save space. (Default: "false")

[Settings]
#GamesDirectory=.\Games
#ArchivePPU=true
#ArchiveDATA=true
#ArchiveCACHES=true
#RemovePPU=true
#RemoveDATA=true
#RemoveCACHES=true

Custom paths for storing your archived PPU, DATA and CACHES files will be coming soon.
 

Yardley

Member
Supporter
RL Member
Haven't tested these new modules yet but can you explain what the archiving feature does? I'm not really understanding. Thanks for your work on this.
 

slashin8r

Member
RL Member
Haven't tested these new modules yet but can you explain what the archiving feature does? I'm not really understanding. Thanks for your work on this.

The emulator creates additional files for every game. All games compile PPU files, which are hardware specific, so essentially everyone will have unique files for this. Some games require additional game data to be installed once the game is first loaded. This data can range from a few hundred MB up to 5GB and beyond. Finally, some games also create an additional game data cache. All of these can be archived and stored with your roms (custom paths coming soon) to save space. You would usually use this if you store your games on an external/network drive.
 

Yardley

Member
Supporter
RL Member
The emulator creates additional files for every game. All games compile PPU files, which are hardware specific, so essentially everyone will have unique files for this. Some games require additional game data to be installed once the game is first loaded. This data can range from a few hundred MB up to 5GB and beyond. Finally, some games also create an additional game data cache. All of these can be archived and stored with your roms (custom paths coming soon) to save space. You would usually use this if you store your games on an external/network drive.

I was aware of the extra files but was unsure what the module does with them. So essentially your archiving feature will let you define a custom path where these files will get stored instead of letting RPCS3 decide where to put them? It doesn't reduce the size of the files just relocates them?
 

slashin8r

Member
RL Member
I was aware of the extra files but was unsure what the module does with them. So essentially your archiving feature will let you define a custom path where these files will get stored instead of letting RPCS3 decide where to put them? It doesn't reduce the size of the files just relocates them?

It will reduce the size of the PPU files (compressed to about 25% of its original size), but the other files do not compress well, so they are archived without compression. Most of those files, even using the best compression, will only result in up to 5% space savings, but drastically increase how long it takes to extract it. Extracting an uncompressed archive is essentially the same thing as copying the files.

I am also looking into further methods of storing these files, such as not archiving at all, but relocating the files and then creating a shortcut to their original location. Personally, I prefer to have the files stored locally when being used, but then archived on my server and deleted from the local drive when not in use.
 

pupop

New member
RL Member
Try the module , with false in the ini, it's working even it's the first time you launch the game :))
 

slashin8r

Member
RL Member
Major changes made and thorough testing will be needed.

Module now finds the gameSerial by reading the PARAM.SFO file. This is much faster and more accurate so it will work for all types of setups.

Custom paths for the archive files have been added. Update your RPCS3.ini file if you wish to customize your paths.

Cleaned up a lot of useless code, mostly the old methods for finding the gameSerial. This is where the module may break as I may have removed necessary code.

I tested each of the 3 methods (Archives, Shortcuts and Text Files) and have had no problems so far. Most of my files are in archive format and only tested 2 games using text files and 1 game using shortcuts.

RPCS3.ahk:
Code:
MEmu := "RPCS3"
MEmuV := "v0.0.7-9248-baf9a20c Alpha"
MURL := ["https://rpcs3.net"]
MAuthor := ["slashin8r", "wallmachine", "jviegas", "brolly", "aurel102001"]
MVersion := "1.1.4"
MDate := "2019-12-23"
MCRC := ""
iCRC := ""
MID := ""
MSystem := ["Sony Playstation 3"]
;----------------------------------------------------------------------------
; Notes:
; [IMPORTANT]
; There are three methods for using this module.
; 
; METHOD 1: Archives: Use this method if you will be compressing your games to save space.
; 1) Archive your game folders, rename the archive to the title of the game, place all the archives within the same folder, and then add that folder as a romPath in RocketLauncher.
; 2) Add the archive's extension ("7z", "rar", "zip", etc.) for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 2: Shortcuts: Use this method if you will be installing your games directly into RPCS3. Can also be used if you will be storing your non-archive games outside of the RPCS3 installation directories.
; 1) Create shortcuts of your EBOOT.BIN files, rename them to the title of the game, place them all within the same folder, then add that folder as a romPath in RocketLauncher.
; 2) Add the "lnk" (LNK) extension for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 3: Text Files: Use this method if you are converting over from a RPCS3 module prior to version 1.0.2.
; 1) Place game folders all within the same folder. You can rename these folders to whatever you like, usually the title of the game. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; 2) Create a text file for every game with the same name as its game folder. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; 3) Place these text files within the folder storing your games.
; [If you wish to have the text files in a separate folder, edit the "GamesDirectory" variable, found within your RPCS3.ini file, to match the full path of the folder storing your games]
; 4) Add the folder containing your text files as a romPath in RocketLauncher.
; 5) Add the "txt" extension for the RPCS3 emulator within RocketLauncher.
; 6) Generate a new database based on the new rom path.
; 7) Audit all games for the system and enjoy.
; [IMPORTANT]
; 
; 
; 
; To save additional space, this module now automatically compresses each game's PPU folder and Game Data folder (if exists) as long as it is enabled in your RPCS3.ini file.
; PPU file saved in: %romPath%\cache\%romName%_%A_ComputerName%.7z (PPU files are hardware specific, so the computer name is added to the end of the filename)
; Game Data file saved in: %romPath%\data\%romName%_data.7z ("_data" added to the end of the filename so there is no conflict with the rom name)
; 
; Example:
; Rom File = "D:\PS3\PS3 Test Game.rar"
; A_ComputerName = "PC001"
; 
; PPU File = "D:\PS3\cache\PS3 Test Game_PC001.7z")
; Game Data File = "D:\PS3\data\PS3 Test Game_data.7z")
; 
; 
; 
; Known Issues:
; 1) Additional progress bar appears just before the game is extracted/loaded (after the PPU and/or DATA archives are extracted). This problem is not specific to this module.
; 
; 
; 
; Coming Soon:
; Please test for bugs and make suggestions.
;----------------------------------------------------------------------------

StartModule()
BezelGUI()
FadeInStart()

primaryExe := new Emulator(emuPath . "\" . executable)
primaryWindowClassName := "Qt5QWindowIcon"
emuPrimaryWindow := new Window(new WindowTitle(,primaryWindowClassName, executable))

; Finding emulator config file
Rpcs3config := new File(emuPath . "\config.yml")
Rpcs3config.CheckFile("Could not find RPCS3 config.yml! Run your emulator, go to Settings and save them.")

; Finding emulator games file
Rpcs3games := new File(emuPath . "\games.yml")
Rpcs3games.CheckFile("Could not find RPCS3 games.yml! Update this file with your list of game serials and game installation directories.")

textGameFolder := moduleIni.Read("Settings", "GamesDirectory","",,1)
archivePPUFolder := moduleIni.Read("Settings", "PPUDirectory",".\cache",,1)
archiveDATAFolder := moduleIni.Read("Settings", "DATADirectory",".\data",,1)
archiveCACHESFolder := moduleIni.Read("Settings", "CACHESDirectory",".\data\caches",,1)
archivePPU := moduleIni.Read("Settings", "ArchivePPU","false",,1)
archiveDATA := moduleIni.Read("Settings", "ArchiveDATA","false",,1)
archiveCACHES := moduleIni.Read("Settings", "ArchiveCACHES","false",,1)
removePPU := moduleIni.Read("Settings", "RemovePPU","false",,1)
removeDATA := moduleIni.Read("Settings", "RemoveDATA","false",,1)
removeCACHES := moduleIni.Read("Settings", "RemoveCACHES","false",,1)

; Convert relative paths into full paths.
textGameFolder := RelativeToFull(textGameFolder, romPath)
archivePPUFolder := RelativeToFull(archivePPUFolder, romPath)
archiveDATAFolder := RelativeToFull(archiveDATAFolder, romPath)
archiveCACHESFolder := RelativeToFull(archiveCACHESFolder, romPath)

BezelStart()

hideEmuObj := Object(emuPrimaryWindow,1)
HideAppStart(hideEmuObj,hideEmu)

; Set variables
gameType := ""
gameSerial := ""
gameDirectoryJunction := "false"
gamePPU := "false"
gamePPUarchive := archivePPUFolder . "\" . romName . "_" . A_ComputerName . ".7z"
gamePPUromPath := archivePPUFolder
gamePPUromName := romName . "_" . A_ComputerName
gamePPUromExtension := ".7z"
gamePPUemuPath := emuPath . "\cache"
gameDATA := "false"
gameDATAarchive := archiveDATAFolder . "\" . romName . "_data.7z"
gameDATAromPath := archiveDATAFolder
gameDATAromName := romName . "_data"
gameDATAromExtension := "7z"
gameDATAemuPath := emuPath . "\dev_hdd0\game"
gameCACHES := "false"
gameCACHESarchive := archiveCACHESFolder . "\" . romName . "_hdd1.7z"
gameCACHESromPath := archiveCACHESFolder
gameCACHESromName := romName . "_hdd1"
gameCACHESromExtension := "7z"
gameCACHESemuPath := emuPath . "\dev_hdd1\caches"
textRomFolder := ""

If (romExtension = ".txt")
{
  FileReadLine, textRomFolder, %romPath%\%romName%%romExtension%, 1
  If (textGameFolder = "")
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(romPath . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . textRomFolder . "\""")
      }
    }
  }
  Else
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(textGameFolder . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . textRomFolder . "\""")
      }
    }
  }
}
Else If (romExtension = ".lnk" && Fileexist(romPath . "\" . romName . romExtension))
{
  FileGetShortCut, %romPath%\%romName%%romExtension%, shortcutTarget
  StringReplace, romPath, shortcutTarget, \EBOOT.BIN
}
Else If (InStr(sevenZFormats, romExtension)) {
  gameSerial := RLObject.getZipRootFolder(romPath . "\" . romName . romExtension)
}

; Store old values for later
originalRomPath := romPath
originalRomName := romName
originalRomExtension := romExtension
originalSevenZRomPath := sevenZRomPath
originalGameName := gameInfo["Name"].Value

; Extract PPU files if they exist
If (archivePPU = "true" && Fileexist(gamePPUarchive))
{
  gameInfo["Name"].Value := "EXTRACTING COMPILED PPU FILES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gamePPUarchive)
  romExSize := RLObject.getZipExtractedSize(gamePPUarchive)
  sevenZRomPath := gamePPUemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gamePPUromPath, gamePPUromName, gamePPUromExtension, gamePPUemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gamePPUarchive%" -aos -o"%gamePPUemuPath%", sevenZPID, Hide
  gamePPU := "true"
}

; Extract Game Data files if they exist
If (archiveDATA = "true" && Fileexist(gameDATAarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME DATA"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameDATAarchive)
  romExSize := RLObject.getZipExtractedSize(gameDATAarchive)
  sevenZRomPath := gameDATAemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameDATAromPath, gameDATAromName, gameDATAromExtension, gameDATAemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameDATAarchive%" -aos -o"%gameDATAemuPath%", sevenZPID, Hide
  gameDATA := "true"
}

; Extract Game Data files if they exist
If (archiveCACHES = "true" && Fileexist(gameCACHESarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME CACHES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameCACHESarchive)
  romExSize := RLObject.getZipExtractedSize(gameCACHESarchive)
  sevenZRomPath := gameCACHESemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameCACHESromPath, gameCACHESromName, gameCACHESromExtension, gameCACHESemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameCACHESarchive%" -aos -o"%gameCACHESemuPath%", sevenZPID, Hide
  gameCACHES := "true"
}

If (gamePPU := "true" || gameDATA := "true" || gameCACHES := "true")
{
  sevenZRomPath := originalSevenZRomPath
  gameInfo["Name"].Value := originalGameName
  Gdip_GraphicsClear(Fade_G5)
}
romPath := originalRomPath
romName := originalRomName
romExtension := originalRomExtension
romExPercentage := 0
layer3Percentage := 0
romExSize := 1000000000
use7zAnimation := "true"
Gosub, UpdateFadeFor7z

7z(romPath, romName, romExtension, sevenZExtractPath)

IfInString, romPath, \USRDIR
{
  FoundPos := InStr(romPath, "\USRDIR") + 6
  StringLeft, romPath, romPath, %FoundPos%
}

romFolder := romPath

; Find the game location and determine the type of game (disc or hdd)
StringRight, stringTest, romFolder, 6
If (stringTest = "USRDIR")
{
  StringReplace, romFolder, romFolder, \USRDIR
  paramFile := romFolder . "\PARAM.SFO"
  FileRead, data, *c %paramFile%
  offset := StrLen(data)-24
  SetFormat, IntegerFast, hex
  offset += 0
  offset .= ""
  SetFormat, IntegerFast, d
  gameSerial := StrGet(&data + offset, "UTF-8")
  StringLeft, stringTest, gameSerial, 2
  If (stringTest = "NP")
  {
    gameType := "game"
  }
  Else
  {
    gameType := "disc"
  }
  
  ; Create the directory junction
  If (gameSerial != "" && gameType != "")
  {
    If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
    {
      StringReplace, romFolder, romFolder, \PS3_GAME
      RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%romFolder%", , Hide
      gameDirectoryJunction := "true"
    }
    Else
    {
      ScriptError("Game serial not found. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.")
    }
  }
}
Else
{
  ScriptError("Rom was not found in the USRDIR directory. Please make sure ""bin"" is an RPCS3 extension and also verify the folder structure of your rom.")
}

;MsgBox, romPath: %romPath%`nromName: %romName%`nromExtension: %romExtension%`ngameType: %gameType%`ngameSerial: %gameSerial%`ngameDirectoryJunction: %gameDirectoryJunction%`ngamePPU: %gamePPU%`ngameDATA: %gameDATA%`nsevenZEnabled: %sevenZEnabled%

; Run the game
If (gameType = "game")
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\" . romName . ".BIN"))
{
  primaryExe.Run(" """ . romPath . "\" . romName . ".BIN""")
}
Else If (Fileexist(romPath . "\" . romName . romExtension))
{
  primaryExe.Run(" """ . romPath . "\" . romName . romExtension . """")
}
Else
{
  ScriptError("Unable to find EBOOT.BIN file. Please make sure ""bin"" (and ""lnk"" [LNK] if you are loading from shortcuts) is an RPCS3 extension and also verify the folder structure of your rom.")
}

; Waiting for main emulator window
emuPrimaryWindow.Wait()
emuPrimaryWindow.Active()
emuPrimaryWindow.WaitActive()

; Waiting up to 5 seconds to see if compiling window appears
If (gameSerial != "" && gamePPU != "true")
{
  Loop, 5
  {
    WinHide, Compiling
    WinWait, Compiling, , 1
    If (!ErrorLevel)
    {
      gameInfo["Name"].Value := "COMPILING PPU FILES"
      use7zAnimation := "true"
      Gdip_GraphicsClear(Fade_G5)
      Gosub, UpdateFadeFor7z
      WinHide, Compiling
      WinWaitClose, Compiling
      gameInfo["Name"].Value := originalGameName
      use7zAnimation := "true"
      Gdip_GraphicsClear(Fade_G5)
      Gosub, UpdateFadeFor7z
      Break
    }
  }
}

BezelDraw()
HideAppEnd(hideEmuObj,hideEmu)
FadeInExit()
primaryExe.Process("WaitClose")

; Remove the PPU files if they were extracted or creates PPU archive file if needed
If ((archivePPU = "true" || removePPU = "true") && gameSerial != "")
{
  IfExist, %gamePPUemuPath%\%gameSerial%
  {
    If (archivePPU = "true")
    {
      IfNotExist, %gamePPUarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
        FadeInExit()
      }
      Else
      {
        MostRecentTime := 0
        Loop, %gamePPUemuPath%\%gameSerial%\*, 2
        {
          If (A_LoopFileTimeModified > MostRecentTime)
          {
            MostRecentTime := A_LoopFileTimeModified
          }
        }
        FileGetTime, gamePPUtime, %gamePPUarchive%, M
        If (MostRecentTime > gamePPUtime)
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
          FadeInExit()
        }
      }
    }
    If (removePPU = "true")
    {
      FileRemoveDir, %gamePPUemuPath%\%gameSerial%, 1
    }
  }
  Else
  {
    MostRecentTime := 0
    MostRecentFile := ""
    MostRecentName := ""
    Loop, %gamePPUemuPath%\*, 2
    {
      If (A_LoopFileTimeModified > MostRecentTime)
      {
        MostRecentTime := A_LoopFileTimeModified
        MostRecentFile := A_LoopFileLongPath
        MostRecentName := A_LoopFileName
      }
    }
    If (StrLen(MostRecentName) = 9)
    {
      If (archivePPU = "true")
      {
        IfNotExist, %gamePPUarchive%
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
          FadeInExit()
        }
        Else
        {
          MostRecentTime := 0
          Loop, %gamePPUemuPath%\%MostRecentName%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gamePPUtime, %gamePPUarchive%, M
          If (MostRecentTime > gamePPUtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
            FadeInExit()
          }
        }
      }
      If (removePPU = "true")
      {
        FileRemoveDir, %MostRecentFile%, 1
      }
    }
  }
}

; Remove the Game Data files if they were extracted or creates Game Data archive file if needed
If ((archiveDATA = "true" || removeDATA = "true") && gameSerial != "" && gameType = "disc")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameDATAemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameDATAemuPath%\*, 2
  {
    If (A_LoopFileTimeModified > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeModified
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  fileOne := MostRecentFile . "\ICON0.PNG"
  fileTwo := emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\ICON0.PNG"
  FileGetSize, dataSizeOne, %fileOne%
  FileGetSize, dataSizeTwo, %fileTwo%
  FileGetVersion, dataVersionOne, %fileOne%
  FileGetVersion, dataVersionTwo, %fileTwo%
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (dataSizeOne = dataSizeTwo && dataVersionOne = dataVersionTwo && MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    If !HasVal(archiveFileArray, MostRecentFile)
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := MostRecentFile
    }
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveDATA = "true")
    {
      IfNotExist, %gameDATAarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameDATAtime, %gameDATAarchive%, M
          FileGetTime, gameDATAarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameDATAtime || gameDATAarchiveTime > gameDATAtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeDATA = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the Game Caches if they were extracted or creates Game Caches archive file if needed
If ((archiveCACHES = "true" || removeCACHES = "true") && gameSerial != "")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameCACHESemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameCACHESemuPath%\*, 2
  {
    If (A_LoopFileTimeModified > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeModified
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    If !HasVal(archiveFileArray, MostRecentFile)
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := MostRecentFile
    }
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveCACHES = "true")
    {
      IfNotExist, %gameCACHESarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME CACHES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameCACHESarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameCACHEStime, %gameCACHESarchive%, M
          FileGetTime, gameCACHESarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameCACHEStime || gameCACHESarchiveTime > gameCACHEStime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME CACHES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameCACHESarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeCACHES = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the directory junction
If (gameDirectoryJunction = "true")
{
  RunWait, %ComSpec% /c "rmdir "%emuPath%\dev_hdd0\%gameType%\%gameSerial%", , Hide
}

7zCleanUp()
BezelExit()
FadeOutExit()
ExitModule()

CloseProcess:
  FadeOutStart()
  emuPrimaryWindow.Close()
  Process, Close, %executable%
Return

BezelLabel:
  disableHideBorder := "true"
  disableHideTitleBar := "true"
  disableHideToggleMenu := "true"
Return

HasVal(haystack, needle) {
  for index, value in haystack
    if (value = needle)
      return index
  if !(IsObject(haystack))
    throw Exception("Bad haystack!", -1, haystack)
  return 0
}

RelativeToFull(relativePath, relativeOf) {
  StringLeft, stringTest, relativePath, 2
  If (stringTest = ".\")
  {
    StringTrimLeft, relativePath, relativePath, 1
    relativePath := relativeOf . relativePath
  }
  Else If (stringTest = "..")
  {
    StringSplit, relativePaths, relativePath, "\"
    relativePathsCount := 0
    tempPath := ""
    Loop, %relativePaths0%
    {
      element := relativePaths%A_Index%
      If (element = "..")
      {
        relativePathsCount := relativePathsCount + 1
      }
      Else
      {
        tempPath := tempPath . element
        If (A_Index != relativePaths0)
        {
          tempPath := tempPath . "\"
        }
      }
    }
    relativePath := tempPath
    StringSplit, relativeOfFolders, relativeOf, "\"
    romGameFoldersCount := relativeOfFolders0 - relativePathsCount
    If (romGameFoldersCount > 0)
    {
      tempPath := ""
      Loop, %romGameFoldersCount%
      {
        element := relativeOfFolders%A_Index%
        tempPath := tempPath . element . "\"
      }
      relativePath := tempPath . relativePath
    }
  }
  return relativePath
}

RPCS3.ini:
Code:
# GamesDirectory: Path to PS3 game folders (relative to rom path). Only used with text file method when you wish to store your games and dummy text files in separate folders. (Default: "")
# PPUDirectory: Path to PPU archives (relative to rom path). (Default: ".\cache")
# DATADirectory: Path to DATA archives (relative to rom path). (Default: ".\data")
# CACHESDirectory: Path to CACHES archives (relative to rom path). (Default: ".\data\caches")
# ArchivePPU: If true, the module will archive your games' PPU files, found within the RPCS3 "cache" folder, to save space and for quicker loading. (Default: "false")
# ArchiveDATA: If true, the module will archive your games' additional data, found within the RPCS3 "dev_hdd0\game" folder, to save space and for quicker loading. (Default: "false")
# ArchiveCACHES: If true, the module will archive your games' additional caches, found within the RPCS3 "dev_hdd1\caches" folder, to save space and for quicker loading. (Default: "false")
# RemovePPU: If true, the module will remove your games' PPU files, found within the RPCS3 "cache" folder, to save space. (Default: "false")
# RemoveDATA: If true, the module will remove your games' additional data, found within the RPCS3 "dev_hdd0\game" folder, to save space. (Default: "false")
# RemoveCACHES: If true, the module will remove your games' additional caches, found within the RPCS3 "dev_hdd1\caches" folder, to save space. (Default: "false")

[Settings]
#GamesDirectory=.\Games
#PPUDirectory=.\archives\ppu
#DATADirectory=.\archives\data
#CACHESDirectory=.\archives\caches
#ArchivePPU=true
#ArchiveDATA=true
#ArchiveCACHES=true
#RemovePPU=true
#RemoveDATA=true
#RemoveCACHES=true

Edit: Updated the Notes section.
 
Last edited:

Yardley

Member
Supporter
RL Member
Just tested the latest module, I am getting the following error:

ScriptError - Game serial not found. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.

EDIT: I took a look at the games.yml file in the RPCS3 folder and noticed that in only contains paths for disc based games but there's no data for HDD games. I then confirmed that launching a disc game with the new module works but I get the above error with an HDD based game. The older module works with either one.
 
Last edited:

slashin8r

Member
RL Member
Just tested the latest module, I am getting the following error:

ScriptError - Game serial not found. If this is your first time loading this game, please check that its game serial and path were added to the games.yml file and try running again.

EDIT: I took a look at the games.yml file in the RPCS3 folder and noticed that in only contains paths for disc based games but there's no data for HDD games. I then confirmed that launching a disc game with the new module works but I get the above error with an HDD based game. The older module works with either one.

The games.yml file is no longer used in this latest version. I cleaned up a lot of the useless code from previous versions. Hopefully this latest one works for you.

Code:
MEmu := "RPCS3"
MEmuV := "v0.0.8-9342-ad845861 Alpha"
MURL := ["https://rpcs3.net"]
MAuthor := ["slashin8r", "wallmachine", "jviegas", "brolly", "aurel102001"]
MVersion := "1.1.5"
MDate := "2020-01-07"
MCRC := ""
iCRC := ""
MID := ""
MSystem := ["Sony Playstation 3"]
;----------------------------------------------------------------------------
; Notes:
; [IMPORTANT]
; There are three methods for using this module.
; 
; METHOD 1: Archives: Use this method if you will be compressing your games to save space.
; 1) Archive your game folders, rename the archive to the title of the game, place all the archives within the same folder, and then add that folder as a romPath in RocketLauncher.
; 2) Add the archive's extension ("7z", "rar", "zip", etc.) for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 2: Shortcuts: Use this method if you will be installing your games directly into RPCS3. Can also be used if you will be storing your non-archive games outside of the RPCS3 installation directories.
; 1) Create shortcuts of your EBOOT.BIN files, rename them to the title of the game, place them all within the same folder, then add that folder as a romPath in RocketLauncher.
; 2) Add the "lnk" (LNK) extension for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 3: Text Files: Use this method if you are converting over from a RPCS3 module prior to version 1.0.2.
; 1) Place game folders all within the same folder. You can rename these folders to whatever you like, usually the title of the game. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; 2) Create a text file for every game with the same name as its game folder. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; 3) Place these text files within the folder storing your games.
; [If you wish to have the text files in a separate folder, edit the "GamesDirectory" variable, found within your RPCS3.ini file, to match the full path of the folder storing your games]
; 4) Add the folder containing your text files as a romPath in RocketLauncher.
; 5) Add the "txt" extension for the RPCS3 emulator within RocketLauncher.
; 6) Generate a new database based on the new rom path.
; 7) Audit all games for the system and enjoy.
; [IMPORTANT]
; 
; 
; 
; To save additional space, this module now automatically compresses each game's PPU folder and Game Data folder (if exists) as long as it is enabled in your RPCS3.ini file.
; PPU file saved in: %romPath%\cache\%romName%_%A_ComputerName%.7z (PPU files are hardware specific, so the computer name is added to the end of the filename)
; Game Data file saved in: %romPath%\data\%romName%_data.7z ("_data" added to the end of the filename so there is no conflict with the rom name)
; 
; Example:
; Rom File = "D:\PS3\PS3 Test Game.rar"
; A_ComputerName = "PC001"
; 
; PPU File = "D:\PS3\cache\PS3 Test Game_PC001.7z")
; Game Data File = "D:\PS3\data\PS3 Test Game_data.7z")
; 
; 
; 
; Known Issues:
; 1) Additional progress bar appears just before the game is extracted/loaded (after the PPU and/or DATA archives are extracted). This problem is not specific to this module.
; 2) Unable to run PSN games with the emulator stored on a network drive.
; 
; 
; 
; Coming Soon:
; 1) Allow PSN games to run from the installed path.
;----------------------------------------------------------------------------

StartModule()
BezelGUI()
FadeInStart()

primaryExe := new Emulator(emuPath . "\" . executable)
primaryWindowClassName := "Qt5QWindowIcon"
emuPrimaryWindow := new Window(new WindowTitle(,primaryWindowClassName, executable))

; Finding emulator config file
Rpcs3config := new File(emuPath . "\config.yml")
Rpcs3config.CheckFile("Could not find RPCS3 config.yml! Run your emulator, go to Settings and save them.")

textGameFolder := moduleIni.Read("Settings", "GamesDirectory","",,1)
archivePPUFolder := moduleIni.Read("Settings", "PPUDirectory",".\cache",,1)
archiveDATAFolder := moduleIni.Read("Settings", "DATADirectory",".\data",,1)
archiveCACHESFolder := moduleIni.Read("Settings", "CACHESDirectory",".\data\caches",,1)
archivePPU := moduleIni.Read("Settings", "ArchivePPU","false",,1)
archiveDATA := moduleIni.Read("Settings", "ArchiveDATA","false",,1)
archiveCACHES := moduleIni.Read("Settings", "ArchiveCACHES","false",,1)
removePPU := moduleIni.Read("Settings", "RemovePPU","false",,1)
removeDATA := moduleIni.Read("Settings", "RemoveDATA","false",,1)
removeCACHES := moduleIni.Read("Settings", "RemoveCACHES","false",,1)

; Convert relative paths into full paths.
textGameFolder := RelativeToFull(textGameFolder, romPath)
archivePPUFolder := RelativeToFull(archivePPUFolder, romPath)
archiveDATAFolder := RelativeToFull(archiveDATAFolder, romPath)
archiveCACHESFolder := RelativeToFull(archiveCACHESFolder, romPath)

BezelStart()

hideEmuObj := Object(emuPrimaryWindow,1)
HideAppStart(hideEmuObj,hideEmu)

; Set variables
gameType := ""
gameSerial := ""
gameDirectoryJunction := "false"
gamePPU := "false"
gamePPUarchive := archivePPUFolder . "\" . romName . "_" . A_ComputerName . ".7z"
gamePPUromPath := archivePPUFolder
gamePPUromName := romName . "_" . A_ComputerName
gamePPUromExtension := ".7z"
gamePPUemuPath := emuPath . "\cache"
gameDATA := "false"
gameDATAarchive := archiveDATAFolder . "\" . romName . "_data.7z"
gameDATAromPath := archiveDATAFolder
gameDATAromName := romName . "_data"
gameDATAromExtension := "7z"
gameDATAemuPath := emuPath . "\dev_hdd0\game"
gameCACHES := "false"
gameCACHESarchive := archiveCACHESFolder . "\" . romName . "_hdd1.7z"
gameCACHESromPath := archiveCACHESFolder
gameCACHESromName := romName . "_hdd1"
gameCACHESromExtension := "7z"
gameCACHESemuPath := emuPath . "\dev_hdd1\caches"
textRomFolder := ""

If (romExtension = ".txt")
{
  FileReadLine, textRomFolder, %romPath%\%romName%%romExtension%, 1
  If (textGameFolder = "")
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(romPath . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . textRomFolder . "\""")
      }
    }
  }
  Else
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(textGameFolder . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . textRomFolder . "\""")
      }
    }
  }
}
Else If (romExtension = ".lnk" && Fileexist(romPath . "\" . romName . romExtension))
{
  FileGetShortCut, %romPath%\%romName%%romExtension%, shortcutTarget
  StringReplace, romPath, shortcutTarget, \EBOOT.BIN
}
Else If (InStr(sevenZFormats, romExtension)) {
  gameSerial := RLObject.getZipRootFolder(romPath . "\" . romName . romExtension)
}

; Store old values for later
originalRomPath := romPath
originalRomName := romName
originalRomExtension := romExtension
originalSevenZRomPath := sevenZRomPath
originalGameName := gameInfo["Name"].Value

; Extract PPU files if they exist
If (archivePPU = "true" && Fileexist(gamePPUarchive))
{
  gameInfo["Name"].Value := "EXTRACTING COMPILED PPU FILES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gamePPUarchive)
  romExSize := RLObject.getZipExtractedSize(gamePPUarchive)
  sevenZRomPath := gamePPUemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gamePPUromPath, gamePPUromName, gamePPUromExtension, gamePPUemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gamePPUarchive%" -aos -o"%gamePPUemuPath%", sevenZPID, Hide
  gamePPU := "true"
}

; Extract Game Data files if they exist
If (archiveDATA = "true" && Fileexist(gameDATAarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME DATA"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameDATAarchive)
  romExSize := RLObject.getZipExtractedSize(gameDATAarchive)
  sevenZRomPath := gameDATAemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameDATAromPath, gameDATAromName, gameDATAromExtension, gameDATAemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameDATAarchive%" -aos -o"%gameDATAemuPath%", sevenZPID, Hide
  gameDATA := "true"
}

; Extract Game Data files if they exist
If (archiveCACHES = "true" && Fileexist(gameCACHESarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME CACHES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameCACHESarchive)
  romExSize := RLObject.getZipExtractedSize(gameCACHESarchive)
  sevenZRomPath := gameCACHESemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameCACHESromPath, gameCACHESromName, gameCACHESromExtension, gameCACHESemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameCACHESarchive%" -aos -o"%gameCACHESemuPath%", sevenZPID, Hide
  gameCACHES := "true"
}

If (gamePPU := "true" || gameDATA := "true" || gameCACHES := "true")
{
  sevenZRomPath := originalSevenZRomPath
  gameInfo["Name"].Value := originalGameName
  Gdip_GraphicsClear(Fade_G5)
}
romPath := originalRomPath
romName := originalRomName
romExtension := originalRomExtension
romExPercentage := 0
layer3Percentage := 0
romExSize := 1000000000
use7zAnimation := "true"
Gosub, UpdateFadeFor7z

7z(romPath, romName, romExtension, sevenZExtractPath)

IfInString, romPath, \USRDIR
{
  FoundPos := InStr(romPath, "\USRDIR") + 6
  StringLeft, romPath, romPath, %FoundPos%
}

romFolder := romPath

; Find the game location and determine the type of game (disc or hdd)
StringRight, stringTest, romFolder, 6
If (stringTest = "USRDIR")
{
  StringReplace, romFolder, romFolder, \USRDIR
  paramFile := romFolder . "\PARAM.SFO"
  FileRead, data, *c %paramFile%
  offset := StrLen(data)-24
  SetFormat, IntegerFast, hex
  offset += 0
  offset .= ""
  SetFormat, IntegerFast, d
  gameSerial := StrGet(&data + offset, "UTF-8")
  StringLeft, stringTest, gameSerial, 2
  If (stringTest = "NP")
  {
    gameType := "game"
  }
  Else
  {
    gameType := "disc"
  }
  
  ; Create the directory junction
  If (gameSerial != "" && gameType != "")
  {
    If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
    {
      StringReplace, romFolder, romFolder, \PS3_GAME
      RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%romFolder%", , Hide
      RunWait, %ComSpec% /c "mklink /D "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%romFolder%", , Hide
      gameDirectoryJunction := "true"
    }
    Else
    {
      ScriptError("Game serial not found.")
    }
  }
}
Else
{
  ScriptError("Rom was not found in the USRDIR directory. Please make sure ""bin"" is an RPCS3 extension and also verify the folder structure of your rom.")
}

;MsgBox, romPath: %romPath%`nromName: %romName%`nromExtension: %romExtension%`ngameType: %gameType%`ngameSerial: %gameSerial%`ngameDirectoryJunction: %gameDirectoryJunction%`ngamePPU: %gamePPU%`ngameDATA: %gameDATA%`nsevenZEnabled: %sevenZEnabled%

; Run the game
If (gameType = "game")
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\" . romName . ".BIN"))
{
  primaryExe.Run(" """ . romPath . "\" . romName . ".BIN""")
}
Else If (Fileexist(romPath . "\" . romName . romExtension))
{
  primaryExe.Run(" """ . romPath . "\" . romName . romExtension . """")
}
Else
{
  ScriptError("Unable to find EBOOT.BIN file. Please make sure ""bin"" (and ""lnk"" [LNK] if you are loading from shortcuts) is an RPCS3 extension and also verify the folder structure of your rom.")
}

; Waiting for main emulator window
emuPrimaryWindow.Wait()
emuPrimaryWindow.Active()
emuPrimaryWindow.WaitActive()

; Waiting up to 5 seconds to see if compiling window appears
If (gameSerial != "" && gamePPU != "true")
{
  Loop, 5
  {
    WinHide, Compiling
    WinWait, Compiling, , 1
    If (!ErrorLevel)
    {
      gameInfo["Name"].Value := "COMPILING PPU FILES"
      use7zAnimation := "true"
      Gdip_GraphicsClear(Fade_G5)
      Gosub, UpdateFadeFor7z
      WinHide, Compiling
      WinWaitClose, Compiling
      gameInfo["Name"].Value := originalGameName
      use7zAnimation := "true"
      Gdip_GraphicsClear(Fade_G5)
      Gosub, UpdateFadeFor7z
      Break
    }
  }
}

BezelDraw()
HideAppEnd(hideEmuObj,hideEmu)
FadeInExit()
primaryExe.Process("WaitClose")

; Remove the PPU files if they were extracted or creates PPU archive file if needed
If ((archivePPU = "true" || removePPU = "true") && gameSerial != "")
{
  IfExist, %gamePPUemuPath%\%gameSerial%
  {
    If (archivePPU = "true")
    {
      IfNotExist, %gamePPUarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
        FadeInExit()
      }
      Else
      {
        MostRecentTime := 0
        Loop, %gamePPUemuPath%\%gameSerial%\*, 2
        {
          If (A_LoopFileTimeModified > MostRecentTime)
          {
            MostRecentTime := A_LoopFileTimeModified
          }
        }
        FileGetTime, gamePPUtime, %gamePPUarchive%, M
        If (MostRecentTime > gamePPUtime)
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
          FadeInExit()
        }
      }
    }
    If (removePPU = "true")
    {
      FileRemoveDir, %gamePPUemuPath%\%gameSerial%, 1
    }
  }
  Else
  {
    MostRecentTime := 0
    MostRecentFile := ""
    MostRecentName := ""
    Loop, %gamePPUemuPath%\*, 2
    {
      If (A_LoopFileTimeModified > MostRecentTime)
      {
        MostRecentTime := A_LoopFileTimeModified
        MostRecentFile := A_LoopFileLongPath
        MostRecentName := A_LoopFileName
      }
    }
    If (StrLen(MostRecentName) = 9)
    {
      If (archivePPU = "true")
      {
        IfNotExist, %gamePPUarchive%
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
          FadeInExit()
        }
        Else
        {
          MostRecentTime := 0
          Loop, %gamePPUemuPath%\%MostRecentName%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gamePPUtime, %gamePPUarchive%, M
          If (MostRecentTime > gamePPUtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
            FadeInExit()
          }
        }
      }
      If (removePPU = "true")
      {
        FileRemoveDir, %MostRecentFile%, 1
      }
    }
  }
}

; Remove the Game Data files if they were extracted or creates Game Data archive file if needed
If ((archiveDATA = "true" || removeDATA = "true") && gameSerial != "" && gameType = "disc")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameDATAemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameDATAemuPath%\*, 2
  {
    If (A_LoopFileTimeModified > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeModified
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  fileOne := MostRecentFile . "\ICON0.PNG"
  fileTwo := emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\ICON0.PNG"
  FileGetSize, dataSizeOne, %fileOne%
  FileGetSize, dataSizeTwo, %fileTwo%
  FileGetVersion, dataVersionOne, %fileOne%
  FileGetVersion, dataVersionTwo, %fileTwo%
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (dataSizeOne = dataSizeTwo && dataVersionOne = dataVersionTwo && MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    If !HasVal(archiveFileArray, MostRecentFile)
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := MostRecentFile
    }
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveDATA = "true")
    {
      IfNotExist, %gameDATAarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameDATAtime, %gameDATAarchive%, M
          FileGetTime, gameDATAarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameDATAtime || gameDATAarchiveTime > gameDATAtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeDATA = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the Game Caches if they were extracted or creates Game Caches archive file if needed
If ((archiveCACHES = "true" || removeCACHES = "true") && gameSerial != "")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameCACHESemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameCACHESemuPath%\*, 2
  {
    If (A_LoopFileTimeModified > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeModified
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    If !HasVal(archiveFileArray, MostRecentFile)
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := MostRecentFile
    }
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveCACHES = "true")
    {
      IfNotExist, %gameCACHESarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME CACHES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameCACHESarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameCACHEStime, %gameCACHESarchive%, M
          FileGetTime, gameCACHESarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameCACHEStime || gameCACHESarchiveTime > gameCACHEStime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME CACHES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameCACHESarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeCACHES = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the directory junction
If (gameDirectoryJunction = "true")
{
  RunWait, %ComSpec% /c "rmdir "%emuPath%\dev_hdd0\%gameType%\%gameSerial%", , Hide
}

7zCleanUp()
BezelExit()
FadeOutExit()
ExitModule()

CloseProcess:
  FadeOutStart()
  emuPrimaryWindow.Close()
  Process, Close, %executable%
Return

BezelLabel:
  disableHideBorder := "true"
  disableHideTitleBar := "true"
  disableHideToggleMenu := "true"
Return

HasVal(haystack, needle) {
  for index, value in haystack
    if (value = needle)
      return index
  if !(IsObject(haystack))
    throw Exception("Bad haystack!", -1, haystack)
  return 0
}

RelativeToFull(relativePath, relativeOf) {
  StringLeft, stringTest, relativePath, 2
  If (stringTest = ".\")
  {
    StringTrimLeft, relativePath, relativePath, 1
    relativePath := relativeOf . relativePath
  }
  Else If (stringTest = "..")
  {
    StringSplit, relativePaths, relativePath, "\"
    relativePathsCount := 0
    tempPath := ""
    Loop, %relativePaths0%
    {
      element := relativePaths%A_Index%
      If (element = "..")
      {
        relativePathsCount := relativePathsCount + 1
      }
      Else
      {
        tempPath := tempPath . element
        If (A_Index != relativePaths0)
        {
          tempPath := tempPath . "\"
        }
      }
    }
    relativePath := tempPath
    StringSplit, relativeOfFolders, relativeOf, "\"
    romGameFoldersCount := relativeOfFolders0 - relativePathsCount
    If (romGameFoldersCount > 0)
    {
      tempPath := ""
      Loop, %romGameFoldersCount%
      {
        element := relativeOfFolders%A_Index%
        tempPath := tempPath . element . "\"
      }
      relativePath := tempPath . relativePath
    }
  }
  return relativePath
}
 

slashin8r

Member
RL Member
Getting a "Game serial not found" error with this one.

Hmmmm.... I think I can simply remove this error now. Try the code below.

Code:
MEmu := "RPCS3"
MEmuV := "v0.0.8-9342-ad845861 Alpha"
MURL := ["https://rpcs3.net"]
MAuthor := ["slashin8r", "wallmachine", "jviegas", "brolly", "aurel102001"]
MVersion := "1.1.6"
MDate := "2020-01-07"
MCRC := ""
iCRC := ""
MID := ""
MSystem := ["Sony Playstation 3"]
;----------------------------------------------------------------------------
; Notes:
; [IMPORTANT]
; There are three methods for using this module.
; 
; METHOD 1: Archives: Use this method if you will be compressing your games to save space.
; 1) Archive your game folders, rename the archive to the title of the game, place all the archives within the same folder, and then add that folder as a romPath in RocketLauncher.
; 2) Add the archive's extension ("7z", "rar", "zip", etc.) for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 2: Shortcuts: Use this method if you will be installing your games directly into RPCS3. Can also be used if you will be storing your non-archive games outside of the RPCS3 installation directories.
; 1) Create shortcuts of your EBOOT.BIN files, rename them to the title of the game, place them all within the same folder, then add that folder as a romPath in RocketLauncher.
; 2) Add the "lnk" (LNK) extension for the RPCS3 emulator within RocketLauncher.
; 3) Generate a new database based on the new rom path.
; 4) Audit all games for the system and enjoy.
; 
; METHOD 3: Text Files: Use this method if you are converting over from a RPCS3 module prior to version 1.0.2.
; 1) Place game folders all within the same folder. You can rename these folders to whatever you like, usually the title of the game. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; 2) Create a text file for every game with the same name as its game folder. (e.g. "Rune Factory - Oceans (Europe) [BLES01550]")
; 3) Place these text files within the folder storing your games.
; [If you wish to have the text files in a separate folder, edit the "GamesDirectory" variable, found within your RPCS3.ini file, to match the full path of the folder storing your games]
; 4) Add the folder containing your text files as a romPath in RocketLauncher.
; 5) Add the "txt" extension for the RPCS3 emulator within RocketLauncher.
; 6) Generate a new database based on the new rom path.
; 7) Audit all games for the system and enjoy.
; [IMPORTANT]
; 
; 
; 
; To save additional space, this module now automatically compresses each game's PPU folder and Game Data folder (if exists) as long as it is enabled in your RPCS3.ini file.
; PPU file saved in: %romPath%\cache\%romName%_%A_ComputerName%.7z (PPU files are hardware specific, so the computer name is added to the end of the filename)
; Game Data file saved in: %romPath%\data\%romName%_data.7z ("_data" added to the end of the filename so there is no conflict with the rom name)
; 
; Example:
; Rom File = "D:\PS3\PS3 Test Game.rar"
; A_ComputerName = "PC001"
; 
; PPU File = "D:\PS3\cache\PS3 Test Game_PC001.7z")
; Game Data File = "D:\PS3\data\PS3 Test Game_data.7z")
; 
; 
; 
; Known Issues:
; 1) Additional progress bar appears just before the game is extracted/loaded (after the PPU and/or DATA archives are extracted). This problem is not specific to this module.
; 2) Unable to run PSN games with the emulator stored on a network drive.
; 
; 
; 
; Coming Soon:
; 1) Allow PSN games to run from the installed path.
;----------------------------------------------------------------------------

StartModule()
BezelGUI()
FadeInStart()

primaryExe := new Emulator(emuPath . "\" . executable)
primaryWindowClassName := "Qt5QWindowIcon"
emuPrimaryWindow := new Window(new WindowTitle(,primaryWindowClassName, executable))

; Finding emulator config file
Rpcs3config := new File(emuPath . "\config.yml")
Rpcs3config.CheckFile("Could not find RPCS3 config.yml! Run your emulator, go to Settings and save them.")

textGameFolder := moduleIni.Read("Settings", "GamesDirectory","",,1)
archivePPUFolder := moduleIni.Read("Settings", "PPUDirectory",".\cache",,1)
archiveDATAFolder := moduleIni.Read("Settings", "DATADirectory",".\data",,1)
archiveCACHESFolder := moduleIni.Read("Settings", "CACHESDirectory",".\data\caches",,1)
archivePPU := moduleIni.Read("Settings", "ArchivePPU","false",,1)
archiveDATA := moduleIni.Read("Settings", "ArchiveDATA","false",,1)
archiveCACHES := moduleIni.Read("Settings", "ArchiveCACHES","false",,1)
removePPU := moduleIni.Read("Settings", "RemovePPU","false",,1)
removeDATA := moduleIni.Read("Settings", "RemoveDATA","false",,1)
removeCACHES := moduleIni.Read("Settings", "RemoveCACHES","false",,1)

; Convert relative paths into full paths.
textGameFolder := RelativeToFull(textGameFolder, romPath)
archivePPUFolder := RelativeToFull(archivePPUFolder, romPath)
archiveDATAFolder := RelativeToFull(archiveDATAFolder, romPath)
archiveCACHESFolder := RelativeToFull(archiveCACHESFolder, romPath)

BezelStart()

hideEmuObj := Object(emuPrimaryWindow,1)
HideAppStart(hideEmuObj,hideEmu)

; Set variables
gameType := ""
gameSerial := ""
gameDirectoryJunction := "false"
gamePPU := "false"
gamePPUarchive := archivePPUFolder . "\" . romName . "_" . A_ComputerName . ".7z"
gamePPUromPath := archivePPUFolder
gamePPUromName := romName . "_" . A_ComputerName
gamePPUromExtension := ".7z"
gamePPUemuPath := emuPath . "\cache"
gameDATA := "false"
gameDATAarchive := archiveDATAFolder . "\" . romName . "_data.7z"
gameDATAromPath := archiveDATAFolder
gameDATAromName := romName . "_data"
gameDATAromExtension := "7z"
gameDATAemuPath := emuPath . "\dev_hdd0\game"
gameCACHES := "false"
gameCACHESarchive := archiveCACHESFolder . "\" . romName . "_hdd1.7z"
gameCACHESromPath := archiveCACHESFolder
gameCACHESromName := romName . "_hdd1"
gameCACHESromExtension := "7z"
gameCACHESemuPath := emuPath . "\dev_hdd1\caches"
textRomFolder := ""

If (romExtension = ".txt")
{
  FileReadLine, textRomFolder, %romPath%\%romName%%romExtension%, 1
  If (textGameFolder = "")
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(romPath . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := romPath . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(romPath . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := romPath . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . romPath . "\" . textRomFolder . "\""")
      }
    }
  }
  Else
  {
    If (textRomFolder = "")
    {
      gameSerial := romName
      If (Fileexist(textGameFolder . "\" . romName . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . romName . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . romName . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . romName . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . romName . "\""")
      }
    }
    Else
    {
      gameSerial := textRomFolder
      If (Fileexist(textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR\EBOOT.BIN"))
      {
        gameType := "disc"
        romPath := textGameFolder . "\" . textRomFolder . "\PS3_GAME\USRDIR"
      }
      Else If (Fileexist(textGameFolder . "\" . textRomFolder . "\USRDIR\EBOOT.BIN"))
      {
        gameType := "game"
        romPath := textGameFolder . "\" . textRomFolder . "\USRDIR"
      }
      Else
      {
        ScriptError("Unable to find EBOOT.BIN within the folder: """ . textGameFolder . "\" . textRomFolder . "\""")
      }
    }
  }
}
Else If (romExtension = ".lnk" && Fileexist(romPath . "\" . romName . romExtension))
{
  FileGetShortCut, %romPath%\%romName%%romExtension%, shortcutTarget
  StringReplace, romPath, shortcutTarget, \EBOOT.BIN
}
Else If (InStr(sevenZFormats, romExtension)) {
  gameSerial := RLObject.getZipRootFolder(romPath . "\" . romName . romExtension)
}

; Store old values for later
originalRomPath := romPath
originalRomName := romName
originalRomExtension := romExtension
originalSevenZRomPath := sevenZRomPath
originalGameName := gameInfo["Name"].Value

; Extract PPU files if they exist
If (archivePPU = "true" && Fileexist(gamePPUarchive))
{
  gameInfo["Name"].Value := "EXTRACTING COMPILED PPU FILES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gamePPUarchive)
  romExSize := RLObject.getZipExtractedSize(gamePPUarchive)
  sevenZRomPath := gamePPUemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gamePPUromPath, gamePPUromName, gamePPUromExtension, gamePPUemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gamePPUarchive%" -aos -o"%gamePPUemuPath%", sevenZPID, Hide
  gamePPU := "true"
}

; Extract Game Data files if they exist
If (archiveDATA = "true" && Fileexist(gameDATAarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME DATA"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameDATAarchive)
  romExSize := RLObject.getZipExtractedSize(gameDATAarchive)
  sevenZRomPath := gameDATAemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameDATAromPath, gameDATAromName, gameDATAromExtension, gameDATAemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameDATAarchive%" -aos -o"%gameDATAemuPath%", sevenZPID, Hide
  gameDATA := "true"
}

; Extract Game Data files if they exist
If (archiveCACHES = "true" && Fileexist(gameCACHESarchive))
{
  gameInfo["Name"].Value := "EXTRACTING ADDITIONAL GAME CACHES"
  romExPercentage := 0
  layer3Percentage := 0
  rootFolder := RLObject.getZipRootFolder(gameCACHESarchive)
  romExSize := RLObject.getZipExtractedSize(gameCACHESarchive)
  sevenZRomPath := gameCACHESemuPath . "\" . rootFolder
  use7zAnimation := "true"
  Gdip_GraphicsClear(Fade_G5)
  Gosub, UpdateFadeFor7z
;  7z(gameCACHESromPath, gameCACHESromName, gameCACHESromExtension, gameCACHESemuPath)
  RunWait, %ComSpec% /c ""%sevenZPath%" x "%gameCACHESarchive%" -aos -o"%gameCACHESemuPath%", sevenZPID, Hide
  gameCACHES := "true"
}

If (gamePPU := "true" || gameDATA := "true" || gameCACHES := "true")
{
  sevenZRomPath := originalSevenZRomPath
  gameInfo["Name"].Value := originalGameName
  Gdip_GraphicsClear(Fade_G5)
}
romPath := originalRomPath
romName := originalRomName
romExtension := originalRomExtension
romExPercentage := 0
layer3Percentage := 0
romExSize := 1000000000
use7zAnimation := "true"
Gosub, UpdateFadeFor7z

7z(romPath, romName, romExtension, sevenZExtractPath)

IfInString, romPath, \USRDIR
{
  FoundPos := InStr(romPath, "\USRDIR") + 6
  StringLeft, romPath, romPath, %FoundPos%
}

romFolder := romPath

; Find the game location and determine the type of game (disc or hdd)
StringRight, stringTest, romFolder, 6
If (stringTest = "USRDIR")
{
  StringReplace, romFolder, romFolder, \USRDIR
  paramFile := romFolder . "\PARAM.SFO"
  FileRead, data, *c %paramFile%
  offset := StrLen(data)-24
  SetFormat, IntegerFast, hex
  offset += 0
  offset .= ""
  SetFormat, IntegerFast, d
  gameSerial := StrGet(&data + offset, "UTF-8")
  StringLeft, stringTest, gameSerial, 2
  If (stringTest = "NP")
  {
    gameType := "game"
  }
  Else
  {
    gameType := "disc"
  }
  
  ; Create the directory junction
  If (gameSerial != "" && gameType != "")
  {
    If (!Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial))
    {
      StringReplace, romFolder, romFolder, \PS3_GAME
      RunWait, %ComSpec% /c "mklink /J "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%romFolder%", , Hide
      RunWait, %ComSpec% /c "mklink /D "%emuPath%\dev_hdd0\%gameType%\%gameSerial%" "%romFolder%", , Hide
      gameDirectoryJunction := "true"
    }
  }
}
Else
{
  ScriptError("Rom was not found in the USRDIR directory. Please make sure ""bin"" is an RPCS3 extension and also verify the folder structure of your rom.")
}

;MsgBox, romPath: %romPath%`nromName: %romName%`nromExtension: %romExtension%`ngameType: %gameType%`ngameSerial: %gameSerial%`ngameDirectoryJunction: %gameDirectoryJunction%`ngamePPU: %gamePPU%`ngameDATA: %gameDATA%`nsevenZEnabled: %sevenZEnabled%

; Run the game
If (gameType = "game")
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\PS3_GAME\USRDIR\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\PS3_GAME\USRDIR\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\EBOOT.BIN"))
{
  primaryExe.Run(" """ . romPath . "\EBOOT.BIN""")
}
Else If (Fileexist(romPath . "\" . romName . ".BIN"))
{
  primaryExe.Run(" """ . romPath . "\" . romName . ".BIN""")
}
Else If (Fileexist(romPath . "\" . romName . romExtension))
{
  primaryExe.Run(" """ . romPath . "\" . romName . romExtension . """")
}
Else
{
  ScriptError("Unable to find EBOOT.BIN file. Please make sure ""bin"" (and ""lnk"" [LNK] if you are loading from shortcuts) is an RPCS3 extension and also verify the folder structure of your rom.")
}

; Waiting for main emulator window
emuPrimaryWindow.Wait()
emuPrimaryWindow.Active()
emuPrimaryWindow.WaitActive()

; Waiting up to 5 seconds to see if compiling window appears
If (gameSerial != "" && gamePPU != "true")
{
  Loop, 5
  {
    WinHide, Compiling
    WinWait, Compiling, , 1
    If (!ErrorLevel)
    {
      gameInfo["Name"].Value := "COMPILING PPU FILES"
      use7zAnimation := "true"
      Gdip_GraphicsClear(Fade_G5)
      Gosub, UpdateFadeFor7z
      WinHide, Compiling
      WinWaitClose, Compiling
      gameInfo["Name"].Value := originalGameName
      use7zAnimation := "true"
      Gdip_GraphicsClear(Fade_G5)
      Gosub, UpdateFadeFor7z
      Break
    }
  }
}

BezelDraw()
HideAppEnd(hideEmuObj,hideEmu)
FadeInExit()
primaryExe.Process("WaitClose")

; Remove the PPU files if they were extracted or creates PPU archive file if needed
If ((archivePPU = "true" || removePPU = "true") && gameSerial != "")
{
  IfExist, %gamePPUemuPath%\%gameSerial%
  {
    If (archivePPU = "true")
    {
      IfNotExist, %gamePPUarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
        FadeInExit()
      }
      Else
      {
        MostRecentTime := 0
        Loop, %gamePPUemuPath%\%gameSerial%\*, 2
        {
          If (A_LoopFileTimeModified > MostRecentTime)
          {
            MostRecentTime := A_LoopFileTimeModified
          }
        }
        FileGetTime, gamePPUtime, %gamePPUarchive%, M
        If (MostRecentTime > gamePPUtime)
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%gamePPUemuPath%\%gameSerial%", , Hide
          FadeInExit()
        }
      }
    }
    If (removePPU = "true")
    {
      FileRemoveDir, %gamePPUemuPath%\%gameSerial%, 1
    }
  }
  Else
  {
    MostRecentTime := 0
    MostRecentFile := ""
    MostRecentName := ""
    Loop, %gamePPUemuPath%\*, 2
    {
      If (A_LoopFileTimeModified > MostRecentTime)
      {
        MostRecentTime := A_LoopFileTimeModified
        MostRecentFile := A_LoopFileLongPath
        MostRecentName := A_LoopFileName
      }
    }
    If (StrLen(MostRecentName) = 9)
    {
      If (archivePPU = "true")
      {
        IfNotExist, %gamePPUarchive%
        {
          FadeInStart()
          gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
          romExPercentage := 0
          layer3Percentage := 0
          use7zAnimation := "true"
          Gdip_GraphicsClear(Fade_G5)
          Gosub, UpdateFadeFor7z
          RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
          FadeInExit()
        }
        Else
        {
          MostRecentTime := 0
          Loop, %gamePPUemuPath%\%MostRecentName%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gamePPUtime, %gamePPUarchive%, M
          If (MostRecentTime > gamePPUtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING COMPILED PPU FILES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a "%gamePPUarchive%" "%MostRecentFile%", , Hide
            FadeInExit()
          }
        }
      }
      If (removePPU = "true")
      {
        FileRemoveDir, %MostRecentFile%, 1
      }
    }
  }
}

; Remove the Game Data files if they were extracted or creates Game Data archive file if needed
If ((archiveDATA = "true" || removeDATA = "true") && gameSerial != "" && gameType = "disc")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameDATAemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameDATAemuPath%\*, 2
  {
    If (A_LoopFileTimeModified > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeModified
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  fileOne := MostRecentFile . "\ICON0.PNG"
  fileTwo := emuPath . "\dev_hdd0\" . gameType . "\" . gameSerial . "\PS3_GAME\ICON0.PNG"
  FileGetSize, dataSizeOne, %fileOne%
  FileGetSize, dataSizeTwo, %fileTwo%
  FileGetVersion, dataVersionOne, %fileOne%
  FileGetVersion, dataVersionTwo, %fileTwo%
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (dataSizeOne = dataSizeTwo && dataVersionOne = dataVersionTwo && MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    If !HasVal(archiveFileArray, MostRecentFile)
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := MostRecentFile
    }
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveDATA = "true")
    {
      IfNotExist, %gameDATAarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameDATAtime, %gameDATAarchive%, M
          FileGetTime, gameDATAarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameDATAtime || gameDATAarchiveTime > gameDATAtime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME DATA"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameDATAarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeDATA = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the Game Caches if they were extracted or creates Game Caches archive file if needed
If ((archiveCACHES = "true" || removeCACHES = "true") && gameSerial != "")
{
  archiveFileArray := []
  archiveFileCount := 0
  Loop, %gameCACHESemuPath%\*, 2
  {
    IfInString, A_LoopFileName, %gameSerial%
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := A_LoopFileLongPath
    }
  }
  MostRecentTime := 0
  MostRecentFile := ""
  MostRecentName := ""
  Loop, %gameCACHESemuPath%\*, 2
  {
    If (A_LoopFileTimeModified > MostRecentTime)
    {
      MostRecentTime := A_LoopFileTimeModified
      MostRecentFile := A_LoopFileLongPath
      MostRecentName := A_LoopFileName
    }
  }
  StringLeft, testRecentFour, MostRecentName, 4
  StringLeft, testSerialFour, gameSerial, 4
  If (MostRecentName != ".locks" && MostRecentName != "TEST12345" && testRecentFour = testSerialFour)
  {
    If !HasVal(archiveFileArray, MostRecentFile)
    {
      archiveFileCount := archiveFileCount + 1
      archiveFileArray[archiveFileCount] := MostRecentFile
    }
  }
  If (archiveFileCount > 0)
  {
    archiveFileString := ""
    Loop % archiveFileCount
    {
      If (archiveFileString != "")
      {
        archiveFileString := archiveFileString . " "
      }
      archiveFileString := archiveFileString . """" . archiveFileArray[A_Index] . """"
    }
    If (archiveCACHES = "true")
    {
      IfNotExist, %gameCACHESarchive%
      {
        FadeInStart()
        gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME CACHES"
        romExPercentage := 0
        layer3Percentage := 0
        use7zAnimation := "true"
        Gdip_GraphicsClear(Fade_G5)
        Gosub, UpdateFadeFor7z
        RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameCACHESarchive%" %archiveFileString%, , Hide
        FadeInExit()
      }
      Else
      {
        Loop % archiveFileCount
        {
          archiveElement := archiveFileArray[A_Index]
          MostRecentTime := 0
          Loop, %archiveElement%\*, 2
          {
            If (A_LoopFileTimeModified > MostRecentTime)
            {
              MostRecentTime := A_LoopFileTimeModified
            }
          }
          FileGetTime, gameCACHEStime, %gameCACHESarchive%, M
          FileGetTime, gameCACHESarchiveTime, %archiveElement%, M
          If (MostRecentTime > gameCACHEStime || gameCACHESarchiveTime > gameCACHEStime)
          {
            FadeInStart()
            gameInfo["Name"].Value := "ARCHIVING ADDITIONAL GAME CACHES"
            romExPercentage := 0
            layer3Percentage := 0
            use7zAnimation := "true"
            Gdip_GraphicsClear(Fade_G5)
            Gosub, UpdateFadeFor7z
            RunWait, %ComSpec% /c ""%sevenZPath%" a -mx=0 "%gameCACHESarchive%" %archiveFileString%, , Hide
            FadeInExit()
            Break
          }
        }
      }
    }
    If (removeCACHES = "true")
    {
      Loop % archiveFileCount
      {
        archiveElement := archiveFileArray[A_Index]
        FileRemoveDir, %archiveElement%, 1
      }
    }
  }
}

; Remove the directory junction
If (gameDirectoryJunction = "true")
{
  RunWait, %ComSpec% /c "rmdir "%emuPath%\dev_hdd0\%gameType%\%gameSerial%", , Hide
}

7zCleanUp()
BezelExit()
FadeOutExit()
ExitModule()

CloseProcess:
  FadeOutStart()
  emuPrimaryWindow.Close()
  Process, Close, %executable%
Return

BezelLabel:
  disableHideBorder := "true"
  disableHideTitleBar := "true"
  disableHideToggleMenu := "true"
Return

HasVal(haystack, needle) {
  for index, value in haystack
    if (value = needle)
      return index
  if !(IsObject(haystack))
    throw Exception("Bad haystack!", -1, haystack)
  return 0
}

RelativeToFull(relativePath, relativeOf) {
  StringLeft, stringTest, relativePath, 2
  If (stringTest = ".\")
  {
    StringTrimLeft, relativePath, relativePath, 1
    relativePath := relativeOf . relativePath
  }
  Else If (stringTest = "..")
  {
    StringSplit, relativePaths, relativePath, "\"
    relativePathsCount := 0
    tempPath := ""
    Loop, %relativePaths0%
    {
      element := relativePaths%A_Index%
      If (element = "..")
      {
        relativePathsCount := relativePathsCount + 1
      }
      Else
      {
        tempPath := tempPath . element
        If (A_Index != relativePaths0)
        {
          tempPath := tempPath . "\"
        }
      }
    }
    relativePath := tempPath
    StringSplit, relativeOfFolders, relativeOf, "\"
    romGameFoldersCount := relativeOfFolders0 - relativePathsCount
    If (romGameFoldersCount > 0)
    {
      tempPath := ""
      Loop, %romGameFoldersCount%
      {
        element := relativeOfFolders%A_Index%
        tempPath := tempPath . element . "\"
      }
      relativePath := tempPath . relativePath
    }
  }
  return relativePath
}
 

Yardley

Member
Supporter
RL Member
Hmmmm.... I think I can simply remove this error now. Try the code below.

This works great. The only improvement I would suggest, and I don't know if this is possible, is to have the fade loading bar reflect the PPU compiling progress. As it stands, the progress bar reaches 100% and just sits there while the PPU compiling takes place almost making it seem like it's frozen.
 
All works fine for me too, except when loading a game it keeps repeating LOADING numerous times before it starts instead of just once. Any fix for this ?
I am using it to load PSN HDD games if that makes any difference. Does same thing using txt and lnk options.
 

mccorkled

Member
RL Member
All works fine for me too, except when loading a game it keeps repeating LOADING numerous times before it starts instead of just once. Any fix for this ?
I am using it to load PSN HDD games if that makes any difference. Does same thing using txt and lnk options.

That's a bug that hasn't been figured out yet.
 
Top