Skip to content

Commit

Permalink
Version 0.3
Browse files Browse the repository at this point in the history
Tonnes of new stuff!
Check the ReadMe.MD -> Version History
  • Loading branch information
Kippykip committed Nov 7, 2018
1 parent d3aefbc commit e079766
Show file tree
Hide file tree
Showing 228 changed files with 395 additions and 127 deletions.
4 changes: 4 additions & 0 deletions CUE2CCD.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
cd "%~dp0"
sbitools -cue2ccd %1
pause
Binary file added LSD Patches/Actua Ice Hockey 2 (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Anstoss - Premier Manager (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Ape Escape (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Ape Escape (France).lsd
Binary file not shown.
Binary file added LSD Patches/Ape Escape (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Ape Escape (Italy).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/BDFL Manager 2001 (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/BDFL Manager 2002 (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Aventure Equestre (France).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Race & Ride (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Race & Ride (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Race & Ride (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Race & Ride (Spain).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Sports Extreme (France).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Super Sport (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Super Sports (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Super Sports (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Barbie - Super Sports (Spain).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Cochons de Guerre, Les (France).lsd
Binary file not shown.
Binary file added LSD Patches/Crash Bash (Europe) (En,Fr,De,Es,It).lsd
Binary file not shown.
Binary file added LSD Patches/Dino Crisis (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Dino Crisis (France).lsd
Binary file not shown.
Binary file added LSD Patches/Dino Crisis (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Dino Crisis (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Dino Crisis (Spain).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Disney Tarzan (France).lsd
Binary file not shown.
Binary file added LSD Patches/Disney Tarzan (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Disney Tarzan (Spain).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Disney's Tarzan (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Disney's Tarzan (Netherlands).lsd
Binary file not shown.
Binary file added LSD Patches/Disney's Tarzan (Sweden).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Disneyn Tarzan (Finland).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Disneys Tarzan (Denmark).lsd
Binary file not shown.
Binary file added LSD Patches/Disneys Tarzan (Germany).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Esto es Futbol (Spain).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/F1 2000 (Europe) (En,Es,Sv,Da,Fi).lsd
Binary file not shown.
Binary file added LSD Patches/F1 2000 (Europe) (En,Fr,De,Nl).lsd
Binary file not shown.
Binary file added LSD Patches/F1 2000 (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Europe) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Europe) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Europe) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Europe) (Disc 4).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (France) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (France) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (France) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (France) (Disc 4).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Germany) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Germany) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Germany) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Germany) (Disc 4).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Italy) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Italy) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Italy) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Italy) (Disc 4).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Spain) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Spain) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Spain) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy IX (Spain) (Disc 4).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (France) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (France) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (France) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (France) (Disc 4).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (Italy) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (Italy) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (Italy) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (Italy) (Disc 4).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (Spain) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (Spain) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (Spain) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Final Fantasy VIII (Spain) (Disc 4).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Formula One 99 (Europe) (En,Es,Fi).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Frontschweine (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Fussball Live (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Fussball Manager 2001 (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (Europe) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (Europe) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (Europe) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (France) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (France) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (France) (Disc 3).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (Germany) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (Germany) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Galerians (Germany) (Disc 3).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Hogs of War (Europe).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Italian Job, The (Europe) (Fr,De,Es).lsd
Binary file not shown.
Binary file added LSD Patches/Italian Job, The (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Italian Job, The (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Jackie Chan Stuntmaster (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/LMA Manager 2001 (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/LMA Manager 2002 (Europe).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Legacy of Kain - Soul Reaver (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Legacy of Kain - Soul Reaver (Spain).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Manager de Liga 2001 (Spain).lsd
Binary file not shown.
Binary file added LSD Patches/Manager de Liga 2002 (Spain).lsd
Binary file not shown.
Binary file added LSD Patches/Marranos en Guerra (Spain).lsd
Binary file not shown.
Binary file added LSD Patches/MediEvil (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/MediEvil (France).lsd
Binary file not shown.
Binary file added LSD Patches/MediEvil (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/MediEvil (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/MediEvil (Spain).lsd
Binary file not shown.
Binary file added LSD Patches/MediEvil 2 (Europe) (En,Fr,De).lsd
Binary file not shown.
Binary file added LSD Patches/MediEvil 2 (Europe) (Es,It,Pt).lsd
Binary file not shown.
Binary file added LSD Patches/MediEvil 2 (Russia).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/MoHo (Europe) (En,Fr,De,Es,It).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (Europe) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (Europe) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (France) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (France) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (Germany) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (Germany) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (Italy) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (Italy) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (Spain) (Disc 1).lsd
Binary file not shown.
Binary file added LSD Patches/Parasite Eve II (Spain) (Disc 2).lsd
Binary file not shown.
Binary file added LSD Patches/Premier Manager 2000 (Europe).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/RC Revenge (Europe) (En,Fr,De,Es).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Resident Evil 3 - Nemesis (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Resident Evil 3 - Nemesis (France).lsd
Binary file not shown.
Binary file added LSD Patches/Resident Evil 3 - Nemesis (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Resident Evil 3 - Nemesis (Ireland).lsd
Binary file not shown.
Binary file added LSD Patches/Resident Evil 3 - Nemesis (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Resident Evil 3 - Nemesis (Spain).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/SaGa Frontier 2 (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/SaGa Frontier 2 (France).lsd
Binary file not shown.
Binary file added LSD Patches/SaGa Frontier 2 (Germany).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Space Debris (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Space Debris (France).lsd
Binary file not shown.
Binary file added LSD Patches/Space Debris (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Space Debris (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Space Debris (Spain).lsd
Binary file not shown.
Binary file added LSD Patches/Speed Freaks (Europe).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Sydney 2000 (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Sydney 2000 (France).lsd
Binary file not shown.
Binary file added LSD Patches/Sydney 2000 (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/Sydney 2000 (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/Sydney 2000 (Spain).lsd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/This Is Football (Europe) (Fr,Nl).lsd
Binary file not shown.
Binary file added LSD Patches/This Is Football (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/This Is Football (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/UEFA Euro 2000 (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/UEFA Euro 2000 (France).lsd
Binary file not shown.
Binary file added LSD Patches/UEFA Euro 2000 (Germany).lsd
Binary file not shown.
Binary file added LSD Patches/UEFA Euro 2000 (Italy).lsd
Binary file not shown.
Binary file added LSD Patches/UEFA Euro 2000 (Spain).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Urban Chaos (Europe) (En,Es,It).lsd
Binary file not shown.
Binary file added LSD Patches/Urban Chaos (France).lsd
Binary file not shown.
Binary file added LSD Patches/Urban Chaos (Germany).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Vagrant Story (Europe).lsd
Binary file not shown.
Binary file added LSD Patches/Vagrant Story (France).lsd
Binary file not shown.
Binary file added LSD Patches/Vagrant Story (Germany).lsd
Binary file not shown.
Binary file not shown.
Binary file added LSD Patches/Wip3out (Europe) (En,Fr,De,Es,It).lsd
Binary file not shown.
61 changes: 33 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@



# SBITools
SBITools v0.2.1 - http://kippykip.com
SBITools v0.3 - http://kippykip.com

**Description:**
This is a small set of conversion tools written in BlitzMax to reconstruct .SUB files using .SBI/.LSD files, and can even convert a full BIN/CUE/SBI emulator setup into a IMG/CCD/SUB setup which can be put into popular CD Burning programs such as CloneCD.
Expand All @@ -16,57 +17,61 @@ SBITools v0.2.1 - http://kippykip.com
https://github.com/Kippykip/SBITools/releases

**Arguments:**
> SBITools.exe -sbi cuefile subchannel.sbi
>
> SBITools.exe -lsd cuefile subchannel.lsd
>
> SBITools.exe -cue2ccd cuefile

>SBITools.exe -cue2ccd cuefile.cue
>SBITools.exe -lsd2sub cuefile.cue subchannel.lsd
>SBITools.exe -lsd2sbi subchannel.lsd
>SBITools.exe -sbi2sub cuefile.cue subchannel.sbi
>SBITools.exe -sbi2lsd subchannel.sbi
>SBITools.exe -singletrack cuefile
**Argument Definitions:**

-sbi: Patches an images subchannel with a .SBI file.
-lsd: Patches an images subchannel with a .LSD file.
Both -sbi and -lsd export the patched .SUB file to:
\SUB\GAMENAME\GAMENAME.SUB
-cue2ccd: Converts a 'BIN/CUE/SBI|LSD' setup into a 'IMG/CCD/CUE/SUB' setup.


-cue2ccd: Converts a 'BIN/CUE/SBI|LSD' setup into a 'IMG/CCD/CUE/SUB' setup.
This makes burning LibCrypt games easily possible with software such
as CloneCD. SBI/LSD files are loaded from the same directory as the .CUE
file under the same name.
It exports the converted files to the "\CCD\GAMENAME\" directory,
remember to burn/launch the game from the .CCD file and not the .CUE file!
file under the same name.
-lsd2sub: Creates a patched .SUB subchannel with a .LSD file.
-lsd2sbi: Converts a .SBI subchannel patch to a .LSD subchannel patch.
-sbi2sub: Creates a patched .SUB subchannel with a .SBI file.
-sbi2lsd: Converts a .SBI subchannel patch to a .LSD subchannel patch.
NOTE: This cannot perfectly reconstruct the missing CRC16 bytes!
-singletrack: Converts a seperate track BIN/CUE setup into a single track BIN/CUE setup.

**Notes:**
It's ***very important*** to note, SBI files do not contain the CRC16 bytes, which is needed for certain games such as V-Rally 2: Championship Edition, MediEvil and most likely a few others. Most LibCrypt games I've tested don't check for these two bytes though.

~~Regardless, SBITools v0.2 now partially reconstructs the CRC16 using a XOR of $0080 although it's not a perfect reconstruction for the whole SubChannel in anyway (as that's impossible).
Until I find a way to recreate it enough to be playable, some games may not work (I know MediEvil is one of them!)~~
SBITools v0.2.1 now creates a CRC16 the same way Mednafen does by making a false CRC16 hash with "bitwise exclusive or", as LibCrypt only checks if it's the wrong hash in order to start the game. Every LibCrypt game I own that I've tested now works fine with SBITool's SBI functions, including MediEvil mentioned above.
.SBI files do not actually contain the **CRC16** needed for some LibCrypt games, however since SBITools v0.2.1, the conversion functions recreate a CRC16 the same way **Mednafen** does by making a false CRC16 hash with "bitwise exclusive or", as LibCrypt only checks if it's the wrong hash in order to start the game.
Every LibCrypt game I own that I've tested now works fine with SBITool's SBI functions.

While this is enough to start a LibCrypt game, if you're a purist like me and want the original CRC16 bytes anyway, definitely go for .LSD files instead. They're the superior format (and I'm not sure why they weren't the standard instead of .SBI)
They can be easily found on http://redump.org/disc/DISCID#/lsd
Or you can get them all on the [releases page](https://github.com/Kippykip/SBITools/releases).
They can be found on http://redump.org/disc/DISCID#/lsd
I've bundled them all on the [releases page](https://github.com/Kippykip/SBITools/releases) and in the repository.

Remember to ***ALWAYS*** test games converted with the **-cue2ccd** function on an emulator before you burn! I personally recommend using BizHawk (which uses Mednafen) and opening the converted game from the .CCD file.
Do ***NOT*** run the game in BizHawk from a .CUE file! The LibCrypt copy protection will kick in if you do that!

**Upcoming**
- Add a -**cdd2cue** function to reverse the process, just in case.
- Add support for image files that have the tracks seperated (Such as "CoolGame (Track 1).bin, CoolGame (Track 2).bin, CoolGame (Track 3).bin") etc.
- Maybe even remove the need for psxt001z too as it's only used for
generating blank .SUB subchannel, although it is a very useful tool to have in combination with SBITools.
- Add a .LSD to .SBI converter, maybe the inverse too if I find a way to perfectly recreate it.
- Add full XOR support for SBI CRC16 recreation.
generating blank .SUB subchannels, although it is a very useful tool to have in combination with SBITools.

**Version History**

Version 0.3
- BIN/CUE setups with seperated tracks are now fully supported!
- Renamed -SBI & -LSD to -SBI2SUB & -LSD2SUB
- Added -singletrack conversion command, -CUE2CCD uses this automatically if necessary.
- Added drag and drop .BAT files for -SINGLETRACK and -CUE2CCD, since they will be used the most.
- Added -SBI2LSD and -LSD2SBI conversion functions
- -SBI2SUB & -LSD2SUB no longer export in subfolders (since it only exports 1 file anyways.)
- SBITools now includes all known LibCrypt LSD patches in the "LSD Patches" directory
Version 0.2.1
- SBI Patching functions were modified to now work with every game.
- Cleaned up a tiny bit of code in CRC16.bmx
Version 0.2
- .SUB patch functions now also add the CD Audio track data to the subchannel.
Although this change now requires you to specify a .CUE file instead of a Binary
file for -SBI and -LSD functions. SUB files are now exported to the \SUB directory
Although this change now requires you to specify a .CUE file instead of a Binary file for -SBI and -LSD functions. SUB files are now exported to the \SUB directory
in these functions too.
- The -SBI function now recreates some of the CRC16 bytes required for handful of games,
although still not 100% compatible.
Expand Down
4 changes: 4 additions & 0 deletions SINGLETRACK.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
cd "%~dp0"
sbitools -singletrack %1
pause
177 changes: 141 additions & 36 deletions functions.bmx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'PS1 Discs are stored in MODE2, meaning they have 2352 bytes per sector.
'PS1 Discs are stored in MODE2, meaning they have 2352 bytes per Sector.
Function GetSectorsBySize(Size:Int)
Return Size / 2352
End Function
Expand Down Expand Up @@ -31,6 +31,16 @@ Function NumberToHexMSF:Byte(Number:Int)
Return Byte(HexStr.ToInt())
End Function

Function NumberToStrMSF:String(Number:Int)
Local HexStr:String
If(Number:Int <= 9)
HexStr:String = HexStr:String + "0" + Number
Else
HexStr:String = HexStr:String + Number
EndIf
Return HexStr:String
End Function

'Converts a Sector to a byte offset for a .SUB file
Function SectorToSUBOffset:Int(Sector:Int)
'.SUB files have 96 bytes in each sector, with a 12 byte FF'd header at the beginning.
Expand Down Expand Up @@ -284,43 +294,91 @@ Function GenSub(FileName:String, Sectors:Int)
'If the subchannel already exists, delete it.
'Psxt001z doesn't override it
If(FileType(FileName:String)) Then DeleteFile(FileName:String)
Local psxtoolz:TProcess = CreateProcess:TProcess("cmd /c psxt001z --sub " + Chr(34) + FileName:String + Chr(34) + " " + Sectors:Int)
Local psxtoolz:TProcess = CreateProcess:TProcess("cmd.exe /c psxt001z --sub " + Chr(34) + FileName:String + Chr(34) + " " + Sectors:Int)

While(ProcessStatus(psxtoolz:TProcess) = 1)
Delay 1000
Wend
End Function

'Open a directory
Function OpenDir(Directory:String)
Local Explorer:TProcess = CreateProcess:TProcess("explorer.exe " + Chr(34) + Directory:String + Chr(34))
DetachProcess(Explorer)
End Function

'Cue Type
Type CUE
Global List:TList = CreateList()
Global BinaryFN:String
Global BinPath:String
Global IsMultiTrack:Byte = False
Global FDRPath:String[]
Global MultiSectorCount:Int = 0'Total sectors counted for multiple sector tracks
Field Track:Int
Field TrackType:String
Field Index:Int
Field TrackFN:String
Field MSF:Int[3]
Field Sector:Int

'Add a track index
Function AddListing(Track:Int, TrackType:String, Index:Int, Minutes:Int, Seconds:Int, Frames:Int)
Function AddListing(Track:Int, TrackType:String, Index:Int, Minutes:Int, Seconds:Int, Frames:Int, FileName:String)
Local CUETrack:CUE = New CUE
CUETrack.Track = Track
CUETrack.TrackType = TrackType
CUETrack.Index = Index
CUETrack.MSF[0] = Minutes
CUETrack.MSF[1] = Seconds
CUETrack.MSF[2] = Frames
CUETrack.TrackFN = FileName
CUETrack.Sector = MSFToSector(Minutes, Seconds, Frames)

'Alright, lets get the path of the CUE/Bin file(s)
Local TrackPath:String
For Local x = 0 To Len(CUE.FDRPath) - 2 'Take 1 so it doesn't overflow, take another 1 so get rid of the CUE filename in this path
TrackPath = TrackPath + CUE.FDRPath[x] + "\"
Next

'Honestly whoever made multitrack BIN/CUE's the ReDump standard are fr*cking frI*ks!!1
If(CUE.IsMultiTrack)
'BIN file exists?
If(FileType(TrackPath + FileName) <> 1) Then RuntimeError("BIN Track '" + TrackPath + FileName + "' is missing!")
If(FileType(TrackPath + BinaryFN) <> 1) Then RuntimeError("BIN Track '" + TrackPath + BinaryFN + "' is missing!") 'Check for Track 1

'Start counting!
If(Index = 0)
CUETrack.Sector = MultiSectorCount
ElseIf(Index = 1)
CUETrack.Sector = MultiSectorCount + 150 '2 Second LeadIn on Index 1's
'Add the sector count of the next track
MultiSectorCount = MultiSectorCount + GetSectorsBySize(Int(FileSize(TrackPath + FileName)))
Else 'Umm, Index 3? uhhhh
RuntimeError("Invalid Index in CUE!")
EndIf
'Recalculate MSF
CUETrack.MSF = SectorToMSF(CUETrack.Sector)
Else 'Single track BIN
CUETrack.MSF[0] = Minutes
CUETrack.MSF[1] = Seconds
CUETrack.MSF[2] = Frames

'Alrighty so because the IsMultiTrack function only changes when it sees more than 1 FILE parameter, we better count the sectors of Track 1!
'But if it can't find it, ignore it. We'll also add the sector count here
if(FileType(TrackPath + BinaryFN) = 1)
MultiSectorCount = GetSectorsBySize(Int(FileSize(TrackPath + BinaryFN)))
EndIf
EndIf
ListAddLast(List:TList, CUETrack)
EndFunction
Function AddCue(CuePath:String)
'Open the file
'Open the file, fix the slashes
CuePath = CuePath.Replace("/", "\")
'Set the path and read the CUE
CUE.FDRPath = CuePath.Split("\")
Local CueFile:TStream = ReadFile(CuePath:String)
'Did it load?
If(CueFile)
Local CurrentTrack:Int = 0
Local CurrentTrackType:String
Local CurrentTrackFN:String

'Barry: What? What is this...?
'Jill: What is it?
Expand All @@ -343,23 +401,29 @@ Type CUE

'This is the header
If(Line.StartsWith("FILE"))
'Check for Multi BIN, cuesheets
'Is a standard single track BIN file
If(BinaryFN = Null)
Local Split:String[] = Line.Split(Chr(34)) 'Split the quotes
BinaryFN = Split[1] 'Set the filename the CUE links to in our global
Else
RuntimeError("SBITools currently doesn't support multi track .BIN files") 'TODO
CurrentTrackFN = Split[1] 'Add it to the array afterwards
Else 'Oh ok so it's one of THOSE multi bin ones, nice. Lets fix it.
Local Split:String[] = Line.Split(Chr(34)) 'Split the quotes
CurrentTrackFN = Split[1] 'Add it to the array afterwards
'Oooh this is a seperated track image!
If(IsMultiTrack = False)
CUE.IsMultiTrack = True
Print "Split Track CUE image detected! Merging..."
EndIf
EndIf
ElseIf(Line.StartsWith("TRACK"))
Local Split:String[] = Line.Replace(" ", " ").Split(" ") 'Split the spaces, get rid of most duplicate spaces if there are any
'Set the current track and track type for when the next loop happens
CurrentTrack = Int(Split[1])
CurrentTrackType = Split[2]
'AddListing
ElseIf(Line.StartsWith("INDEX"))
Local Split:String[] = Line.Split(" ") 'Split the spaces
Local MSF:String[] = Split[2].Split(":") 'Split the colons from the MSF XX:XX:XX
AddListing(CurrentTrack, CurrentTrackType, Int(Split[1]), Int(MSF[0]), Int(MSF[1]), Int(MSF[2]))
AddListing(CurrentTrack, CurrentTrackType, Int(Split[1]), Int(MSF[0]), Int(MSF[1]), Int(MSF[2]), CurrentTrackFN)
EndIf
Wend
'Done using this file
Expand All @@ -378,31 +442,51 @@ Type CUE
Next
Return TrackCount:Int
End Function
Function EditBinPath(CuePath:String, NewBinPath:String, ExportPath:String)
Local NewCueFile:TStream = WriteFile(ExportPath:String)
Local CueFile:TStream = ReadFile(CuePath:String)
'Did it work?
If(NewCueFile)
If(CueFile)
While Not(Eof(CueFile))
Local Line:String = Upper(ReadLine(CueFile))
'Is it the FILE header?
If(Line.StartsWith("FILE"))
'Change the path
WriteLine(NewCueFile:TStream, "FILE " + Chr(34) + NewBinPath:String + Chr(34) + " BINARY")
Else 'Otherwise just write what was on the old one
WriteLine(NewCueFile:TStream, Line:String)
EndIf
Wend
'Free them from memory
CloseFile(CueFile)
CloseFile(NewCueFile)
Else
RuntimeError("Couldn't find .CUE file")
Function MergeImage(ExportPath:String)
Local MergedImage:TStream = WriteFile(ExportPath)
Local TrackNum = 1
For Local CueFile:CUE = EachIn CUE.List:TList
If(CueFile.Index = 1)
'Alright, lets get the path of the bin file(s) then
Local TrackPath:String
For Local x = 0 To Len(CUE.FDRPath) - 2 'Take 1 so it doesn't overflow, take another 1 so get rid of the CUE filename in this path
TrackPath = TrackPath + CUE.FDRPath[x] + "\"
Next
'Verification to check the track numbers are correct
'That way it doesn't stitch the .BINs in a wacky order!
If(CueFile.Track = TrackNum)
Print "Stitching '" + CueFile.TrackFN + "'."
'File doesn't exist?
If(FileType(TrackPath + CueFile.TrackFN) <> 1) Then RuntimeError("BIN Track '" + TrackPath + CueFile.TrackFN + "' is missing!")
'If we got this far, then it exists
Local ImageTrack:TStream = ReadFile(TrackPath + CueFile.TrackFN)
If Not(ImageTrack) Then RuntimeError("Unknown read error!")
'Still made it? Alright good! Copy the data now!
CopyStream(ImageTrack, MergedImage)

Else 'Wait what? well uHHH just cycle through the whole thing until you find it
For Local OrderedCueFile:CUE = EachIn CUE.List:TList
If(OrderedCueFile.Index = 1 And OrderedCueFile.Track = TrackNum)
Print "Warning! CUE sheet is out of order!"
Print "Expected Track: " + TrackNum + ", got Track: " + CueFile.Track + " instead!"
Print "Stitching '" + OrderedCueFile.TrackFN + "'."

'File doesn't exist?
If(FileType(TrackPath + OrderedCueFile.TrackFN) <> 1) Then RuntimeError("BIN Track '" + TrackPath + OrderedCueFile.TrackFN + "' is missing!")
'If we got this far, then it exists
Local ImageTrack:TStream = ReadFile(TrackPath + OrderedCueFile.TrackFN)
If Not(ImageTrack) Then RuntimeError("Unknown read error!")
'Still made it? Alright good! Copy the data now!
CopyStream(ImageTrack, MergedImage)
EndIf
Next
EndIf
'Go to next track
TrackNum = TrackNum + 1
EndIf
Else
RuntimeError("Error creating new .CUE file")
EndIf
Next
CloseFile(MergedImage)
Print "Finished merging split track image!"
End Function

'Lets get the path to the .BIN file, or .IMG, whatever using the CUE's BaseName + FDRPath array, or by any means possible.
Expand Down Expand Up @@ -434,10 +518,31 @@ Type CUE
Return BaseName 'Return the BaseName because it's very useful
EndFunction

'Exports the CUE array into a real CUE file
Function ExportCue(ExportPath:String, BinaryPath:String)
Local ExportFile:TStream = WriteFile(ExportPath)
If Not(ExportPath) Then RuntimeError("Error writing to '" + ExportPath + "'!")

'Write the first track
WriteLine(ExportFile, "FILE " + Chr(34) + BinaryPath + Chr(34) + " BINARY")
WriteLine(ExportFile, " TRACK 1 MODE2/2352")

For Local CueFile:CUE = EachIn CUE.List:TList
'Hasn't written the track before it
If(CueFile.Index = 0)
WriteLine(ExportFile, " TRACK " + CueFile.Track + " " + CueFile.TrackType)
EndIf
WriteLine(ExportFile, " INDEX " + CueFile.Index + " " + NumberToStrMSF(CueFile.MSF[0]) + ":" + NumberToStrMSF(CueFile.MSF[1]) + ":" + NumberToStrMSF(CueFile.MSF[2]))
Next
CloseFile(ExportFile)
End Function

'Resets everything
Function Clean()
BinaryFN:String = Null
BinPath:String = Null
IsMultiTrack:Byte = False
MultiSectorCount:Int = 0
ClearList(List:TList)
End Function
EndType
Loading

0 comments on commit e079766

Please sign in to comment.