Skip to content

Commit

Permalink
Exposed the bizhawk DiscStructure object
Browse files Browse the repository at this point in the history
  • Loading branch information
Asnivor committed Oct 10, 2017
1 parent 4d5bbb9 commit 9f3839a
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 4 deletions.
1 change: 1 addition & 0 deletions DiscTools/DiscInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class DiscInspector
{
public string CuePath { get; set; }
public DiscData Data { get; set; }
public DiscStructure DiscStructure { get; set; }
public DetectedDiscType DetectedDiscType { get; set; }
public string DiscTypeString { get; set; }
public string DiscViewString { get; set; }
Expand Down
1 change: 1 addition & 0 deletions DiscTools/DiscToolsNET20.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Compile Include="Inspection\Statics\Sony.cs" />
<Compile Include="Inspection\Statics\SonyMethods\SFO.cs" />
<Compile Include="Inspection\TextConverters.cs" />
<Compile Include="Objects\IOFunctions.cs" />
<Compile Include="Objects\ISOData.cs" />
<Compile Include="Objects\CDiData.cs" />
<Compile Include="Objects\PSPData.cs" />
Expand Down
1 change: 1 addition & 0 deletions DiscTools/DiscToolsNET35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<Compile Include="Inspection\Statics\SonyMethods\SFO.cs" />
<Compile Include="Inspection\TextConverters.cs" />
<Compile Include="Objects\CDiData.cs" />
<Compile Include="Objects\IOFunctions.cs" />
<Compile Include="Objects\ISOData.cs" />
<Compile Include="Objects\PSPData.cs" />
<Compile Include="OtherFormats\CDi.cs" />
Expand Down
1 change: 1 addition & 0 deletions DiscTools/DiscToolsNET452.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Compile Include="Inspection\Statics\SonyMethods\SFO.cs" />
<Compile Include="Inspection\TextConverters.cs" />
<Compile Include="Objects\CDiData.cs" />
<Compile Include="Objects\IOFunctions.cs" />
<Compile Include="Objects\ISOData.cs" />
<Compile Include="Objects\PSPData.cs" />
<Compile Include="OtherFormats\CDi.cs" />
Expand Down
3 changes: 3 additions & 0 deletions DiscTools/Inspection/InterroCDi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using System.Linq;
using System.Text.RegularExpressions;
using DiscTools.Objects;

namespace DiscTools.Inspection
{
Expand All @@ -27,6 +28,8 @@ public bool GetCDiData(string lbaString)
{
if (lbaString.ToLower().Contains("cd-rtos"))
{
CDiVolumeDescriptor cdv = new CDiVolumeDescriptor(currSector);

discI.Data.ManufacturerID = System.Text.Encoding.Default.GetString(currSector.ToList().Skip(1).Take(4).ToArray());
discI.Data.OtherData = System.Text.Encoding.Default.GetString(currSector.ToList().Skip(8).Take(16).ToArray()).Trim();
int start = 190;
Expand Down
2 changes: 2 additions & 0 deletions DiscTools/Inspection/Interrogator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public DiscInspector Start(DetectedDiscType detectedDiscType)
discI.Data.TotalDataTracks = dataTracks;
discI.Data.TotalTracks = audioTracks + dataTracks;

discI.DiscStructure = disc.Structure;

// do actual interrogation
switch (detectedDiscType)
{
Expand Down
4 changes: 3 additions & 1 deletion DiscTools/Inspection/Statics/Sony.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace DiscTools.Inspection.Statics
{
public class Sony
{

/*
public Dictionary<string, string> PSPRegion { get; set; }
Expand Down Expand Up @@ -83,5 +83,7 @@ public Sony()
{ "0010", "Central / South America" }
};
}
*/
}
}
213 changes: 212 additions & 1 deletion DiscTools/Objects/CDiData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DiscTools.Inspection.Statics.SonyMethods;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiscTools.Objects
Expand All @@ -25,9 +26,219 @@ public static void ParseCDiData(DiscInspector di, SFO sfo)
{

}


}

public class CDiVolumeDescriptor
{
/* BP Size in Bytes Description
1 1 Disc Label Record Type
2 5 Volume Structure Standard ID
7 1 Volume Structure Version number
8 1 Volume flags
9 32 System identifier
41 32 Volume identifier
73 12 Reserved
85 4 Volume space size
89 32 Coded Character Set identifier
121 2 Reserved
123 2 Number of Volumes in Album
125 2 Reserved
127 2 Album Set Sequence number
129 2 Reserved
131 2 Logical Block size
133 4 Reserved
137 4 Path Table size
141 8 Reserved
149 4 Address of Path Table
153 38 Reserved
191 128 Album identifier
319 128 Publisher identifier
447 128 Data Preparer identifier
575 128 Application identifier
703 32 Copyright file name
735 5 Reserved
740 32 Abstract file name
772 5 Reserved
777 32 Bibliographic file name
809 5 Reserved
814 16 Creation date and time
830 1 Reserved
831 16 Modification date and time
847 1 Reserved
848 16 Expiration date and time
864 1 Reserved
865 16 Effective date and time
881 1 Reserved
882 1 File Structure Standard Version number
883 1 Reserved
884 512 Application use
1396 653 Reserved */

public int? DiscLabelRecordType { get; set; }
public string VolumeStructureStandardID { get; set; }
public int? VolumeStructureVersionNumber { get; set; }
public int? VolumeFlags { get; set; }
public string SystemIdentifier { get; set; }
public string VolumeIdentifier { get; set; }
public int? VolumeSpaceSize { get; set; }
public string CodedCharSetIndent { get; set; }
public int? NumberOfVolumesInAlbum { get; set; }
public int? AlbumSetSequenceNumber { get; set; }
public int? LogicalBlockSize { get; set; }
public int? PathTableSize { get; set; }
public int? AddressOfPathTable { get; set; }
public string AlbumIdentifier { get; set; }
public string PublisherIdentifier { get; set; }
public string DataPreparerIdentifier { get; set; }
public string ApplicationIdentifier { get; set; }
public string CopyrightFileName { get; set; }
public string AbstractFileName { get; set; }
public string BibliographicFileName { get; set; }
public string CreationDateAndTime { get; set; }
public string ModificationDateAndTime { get; set; }
public string ExpirationDateAndTime { get; set; }
public string EffectiveDateAndTime { get; set; }
public int? FileStructureStandardVersionNumber { get; set; }
public string ApplicationUse { get; set; }

public byte[] _Data { get; set; }
public string _DataString { get; set; }


public void ParseData()
{
DiscLabelRecordType = ReadIntValueLE(0, 1);
VolumeStructureStandardID = Encoding.ASCII.GetString(ReadBytes(1, 5)).TrimEnd();
VolumeStructureVersionNumber = ReadIntValueLE(6, 1);
VolumeFlags = ReadIntValueLE(7, 1);
SystemIdentifier = Encoding.ASCII.GetString(ReadBytes(8, 32)).TrimEnd();
VolumeIdentifier = Encoding.ASCII.GetString(ReadBytes(40, 32)).TrimEnd();
VolumeSpaceSize = ReadIntValueLE(84, 4);
CodedCharSetIndent = Encoding.ASCII.GetString(ReadBytes(88, 32)).TrimEnd();
NumberOfVolumesInAlbum = ReadIntValueLE(122, 2);
AlbumSetSequenceNumber = ReadIntValueLE(128, 2);
LogicalBlockSize = ReadIntValueLE(130, 2);
PathTableSize = ReadIntValueLE(126, 4);
AddressOfPathTable = ReadIntValueLE(148, 4);
AlbumIdentifier = Encoding.ASCII.GetString(ReadBytes(190, 128)).TrimEnd();
PublisherIdentifier = Encoding.ASCII.GetString(ReadBytes(318, 128)).TrimEnd();
DataPreparerIdentifier = Encoding.ASCII.GetString(ReadBytes(446, 128)).TrimEnd();
ApplicationIdentifier = Encoding.ASCII.GetString(ReadBytes(574, 128)).TrimEnd();
CopyrightFileName = Encoding.ASCII.GetString(ReadBytes(702, 32)).TrimEnd();
AbstractFileName = Encoding.ASCII.GetString(ReadBytes(739, 32)).TrimEnd();
BibliographicFileName = Encoding.ASCII.GetString(ReadBytes(776, 32)).TrimEnd();
CreationDateAndTime = Encoding.ASCII.GetString(ReadBytes(813, 16)).TrimEnd();
ModificationDateAndTime = Encoding.ASCII.GetString(ReadBytes(830, 16)).TrimEnd();
ExpirationDateAndTime = Encoding.ASCII.GetString(ReadBytes(847, 16)).TrimEnd();
EffectiveDateAndTime = Encoding.ASCII.GetString(ReadBytes(864, 16)).TrimEnd();
FileStructureStandardVersionNumber = ReadIntValueLE(881, 1);
ApplicationUse = Encoding.ASCII.GetString(ReadBytes(883, 512)).TrimEnd();
}

public CDiVolumeDescriptor(byte[] sector)
{
_DataString = Encoding.Default.GetString(sector);
_Data = sector;

ParseData();
}

public CDiVolumeDescriptor(string sectorString)
{
_DataString = sectorString;
_Data = Encoding.ASCII.GetBytes(sectorString);

ParseData();
}



public string ReadHexString(int offset, int length)
{
var bytes = _Data.Skip(offset).Take(length).ToArray();
string hex = "";
foreach (byte b in bytes)
{
hex += b.ToString("X2");
}
return hex;
}

public string ReadHexStringLE(int offset, int length)
{
var bytes = _Data.Skip(offset).Take(length).ToArray();
Array.Reverse(bytes);
string hex = "";
foreach (byte b in bytes)
{
hex += b.ToString("X2");
}
return hex;
}

public byte[] ReadBytes(int offset, int length)
{
var bytes = _Data.Skip(offset).Take(length).ToArray();
return bytes;
}

public int[] ReadInts(int offset, int length)
{
var bytes = _Data.Skip(offset).Take(length).ToArray();
List<int> list = new List<int>();
foreach (byte b in bytes)
{
list.Add(Convert.ToInt32(b));
}

return list.ToArray();
}

public int ReadIntValueLE(int offset, int length)
{
var bytes = _Data.Skip(offset).Take(length).ToArray();
Array.Reverse(bytes);
if (length == 1)
return bytes.FirstOrDefault();

if (length == 2)
return BitConverter.ToInt16(bytes, 0);

int result = BitConverter.ToInt32(bytes, 0);
return result;
}

public int ReadIntValue(int offset, int length)
{
var bytes = _Data.Skip(offset).Take(length).ToArray();
//Array.Reverse(bytes);

if (length == 1)
return bytes.FirstOrDefault();

if (length == 2)
return BitConverter.ToInt16(bytes, 0);

int result = BitConverter.ToInt32(bytes, 0);
return result;
}

public int ReadInt16ValueLE(int offset, int length)
{
var bytes = _Data.Skip(offset).Take(length).ToArray();
Array.Reverse(bytes);
int result = BitConverter.ToInt16(bytes, 0);
return result;
}

public int ReadInt16Value(int offset, int length)
{
var bytes = _Data.Skip(offset).Take(length).ToArray();
//Array.Reverse(bytes);
int result = BitConverter.ToInt16(bytes, 0);
return result;
}
}

}
11 changes: 11 additions & 0 deletions DiscTools/Objects/IOFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace DiscTools.Objects
{
public class IOFunctions
{

}
}
4 changes: 2 additions & 2 deletions TestAppNET20/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void Main(string[] args)
//string dcPath = @"G:\_Emulation\Sega Saturn\disks\ws-gals_panic.cue";
//string dcPath = @"G:\_Emulation\NeoGeo CD\discs\Metal Slug (1996)(SNK)(Jp-US)[!].cue";
//string dcPath = @"G:\_Emulation\NeoGeo CD\discs\Breakers (1997)(Visco)(Jp)[!].cue";
string dcPath = @"G:\_Emulation\Philips CD-i\discs\Hotel Mario.cue";
//string dcPath = @"G:\_Emulation\Philips CD-i\discs\Hotel Mario.cue";
//string dcPath = @"G:\_Emulation\Sega Megadrive - 32x - SegaCD\discs\segacd\Shining Force CD (Sega CD) (U)-redump.cue";
//string dcPath = @"G:\_Emulation\Sega Saturn\disks\Primal Rage (Europe) (En,Fr,De,Es,It,Pt)\Primal Rage (Europe) (En,Fr,De,Es,It,Pt).cue";
//string dcPath = @"G:\_Emulation\PCFX\Games\Battle Heat\Battle Heat.cue";
Expand All @@ -42,7 +42,7 @@ static void Main(string[] args)
//var dreamcast = DiscInspector.ScanDreamcast(@"G:\_Emulation\Dreamcast\games\Daytona_USA_USA_DC-ECHELON\E-DAYUSA.cue1");

//string dcPath = @"G:\_Emulation\PSX\iso\Alien Trilogy (E) [SLES-00101]\Alien Trilogy (E) [SLES-00101]\Alien Trilogy (E) [SLES-00101].cue";
//string dcPath = @"G:\_Emulation\PC Engine\discs\L-Dis (1991)(Masaya - NCS)(JP).ccd";
string dcPath = @"G:\_Emulation\PC Engine\discs\L-Dis (1991)(Masaya - NCS)(JP).ccd";

//DiscInspector.UnknownTest();

Expand Down

0 comments on commit 9f3839a

Please sign in to comment.