Skip to content

Commit

Permalink
Completion of extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
TBirdSoars committed Jul 31, 2019
1 parent e67388e commit 1826151
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions WiiuVcExtractor/RomExtractors/DsVcExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public class DsVcExtractor : IRomExtractor
// Location of output file
private string finalPath;

// VC and DS names
private string vcName;
private string dsName;

private bool hasName;

private bool verbose = false;

// Constructor - set verbosity, path to srl file, and rom dictionary
Expand All @@ -77,7 +83,12 @@ public DsVcExtractor(SrlFile srlFile, bool verbose)
dsGameTitles = (from rom in dataFile.Descendants("game")
select (string)rom.Attribute("name")).ToArray();

finalPath = srlFile.Path.Substring(0, srlFile.Path.Length - 3) + "nds";
finalPath = Path.GetFileNameWithoutExtension(srlFile.Path) + "nds";

vcName = Path.GetFileNameWithoutExtension(srlFile.Path);
dsName = vcName;

hasName = false;
}

// Check for the Nintendo logo at offsets 0xC0 to 0x15B
Expand Down Expand Up @@ -107,10 +118,12 @@ public bool IsValidRom()
{
if (nintenLogo[i] != br.ReadByte())
{
Console.WriteLine("Not a valid DS VC Title");
return false;
}
}

Console.WriteLine("DS Rom Detected!");
return true;
}
}
Expand All @@ -134,6 +147,7 @@ public string ExtractRom()
}
}

Console.WriteLine("Overwriting junk data...");
// Overwrites junk data with zeroes
for (int i = startJunkOffset; i < startGameOffset; i++)
{
Expand All @@ -159,8 +173,6 @@ public string ExtractRom()

}

// TODO - get names for both encrypted and decrypted roms
//
// Identify name of file using MD5 hash and set as output path
MD5 md5Hash = MD5.Create();
byte[] data = md5Hash.ComputeHash(game);
Expand All @@ -171,6 +183,8 @@ public string ExtractRom()
}
string hashString = sBuilder.ToString();

Console.WriteLine("MD5 of overwritten file is " + hashString);

// Attempt to find matching MD5 and then gametitle
// IF this fails, the SRL file name is used instead
for(int i = 0; i < dsMD5.Length; i++)
Expand All @@ -181,10 +195,24 @@ public string ExtractRom()
Path.GetFileName(finalPath).Length);
finalPath += dsGameTitles[i] + ".nds";

dsName = Path.GetFileNameWithoutExtension(finalPath);
hasName = true;

i = dsMD5.Length;
}
}

Console.WriteLine("Virtual Console Title: " + vcName);
if(hasName)
{
Console.WriteLine("DS Title: " + dsName);
}
else
{
Console.WriteLine("DS title not found");
}

Console.WriteLine("Writing game data...");
// Ouputs final game file
using (FileStream fs = new FileStream(finalPath, FileMode.Create))
{
Expand All @@ -194,8 +222,11 @@ public string ExtractRom()
}
}

Console.WriteLine("DS rom has been created successfully at " +
Path.GetFileName(finalPath));

// Return location of final game file to Program.cs
return finalPath;
return Path.GetFileName(finalPath);
}
}
}

0 comments on commit 1826151

Please sign in to comment.