diff --git a/BizHawk.Client.Common/Api/Interfaces/IMemEvents.cs b/BizHawk.Client.Common/Api/Interfaces/IMemEvents.cs
index 73f831751e..07a1dd2aaa 100644
--- a/BizHawk.Client.Common/Api/Interfaces/IMemEvents.cs
+++ b/BizHawk.Client.Common/Api/Interfaces/IMemEvents.cs
@@ -1,6 +1,4 @@
-using System;
-
-using BizHawk.Emulation.Common;
+using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs
index 7206daaa4a..b8a19175ec 100644
--- a/BizHawk.Client.Common/BinarySaveStates.cs
+++ b/BizHawk.Client.Common/BinarySaveStates.cs
@@ -242,8 +242,7 @@ namespace BizHawk.Client.Common
/// stream not found and is
public bool GetLump(BinaryStateLump lump, bool abort, Action callback)
{
- ZipEntry e;
- if (_entriesByName.TryGetValue(lump.ReadName, out e))
+ if (_entriesByName.TryGetValue(lump.ReadName, out var e))
{
using (var zs = _zip.GetInputStream(e))
{
diff --git a/BizHawk.Client.Common/FirmwareManager.cs b/BizHawk.Client.Common/FirmwareManager.cs
index 90ad436077..a07be24879 100644
--- a/BizHawk.Client.Common/FirmwareManager.cs
+++ b/BizHawk.Client.Common/FirmwareManager.cs
@@ -53,14 +53,13 @@ namespace BizHawk.Client.Common
public ResolutionInfo Resolve(FirmwareDatabase.FirmwareRecord record, bool forbidScan = false)
{
- // purpose of forbidScan: sometimes this is called from a loop in Scan(). we dont want to repeatedly DoScanAndResolve in that case, its already been done.
+ // purpose of forbidScan: sometimes this is called from a loop in Scan(). we don't want to repeatedly DoScanAndResolve in that case, its already been done.
bool first = true;
RETRY:
- ResolutionInfo resolved;
- _resolutionDictionary.TryGetValue(record, out resolved);
+ _resolutionDictionary.TryGetValue(record, out var resolved);
- // couldnt find it! do a scan and resolve to try harder
+ // couldn't find it! do a scan and resolve to try harder
// NOTE: this could result in bad performance in some cases if the scanning happens repeatedly..
if (resolved == null && first)
{
@@ -76,7 +75,7 @@ namespace BizHawk.Client.Common
return resolved;
}
- // Requests the spcified firmware. tries really hard to scan and resolve as necessary
+ // Requests the specified firmware. tries really hard to scan and resolve as necessary
public string Request(string sysId, string firmwareId)
{
var resolved = Resolve(sysId, firmwareId);
@@ -138,16 +137,14 @@ namespace BizHawk.Client.Common
return false;
// weed out filesizes first to reduce the unnecessary overhead of a hashing operation
- if (FirmwareDatabase.FirmwareFiles.Where(a => a.Size == fi.Length).FirstOrDefault() == null)
+ if (FirmwareDatabase.FirmwareFiles.FirstOrDefault(a => a.Size == fi.Length) == null)
return false;
// check the hash
- using (var reader = new RealFirmwareReader())
- {
- reader.Read(fi);
- if (FirmwareDatabase.FirmwareFiles.Where(a => a.Hash == reader.Dict.FirstOrDefault().Value.Hash).FirstOrDefault() != null)
- return true;
- }
+ using var reader = new RealFirmwareReader();
+ reader.Read(fi);
+ if (FirmwareDatabase.FirmwareFiles.FirstOrDefault(a => a.Hash == reader.Dict.FirstOrDefault().Value.Hash) != null)
+ return true;
}
catch { }
@@ -157,133 +154,127 @@ namespace BizHawk.Client.Common
public void DoScanAndResolve()
{
// build a list of file sizes. Only those will be checked during scanning
- HashSet sizes = new HashSet();
+ var sizes = new HashSet();
foreach (var ff in FirmwareDatabase.FirmwareFiles)
{
sizes.Add(ff.Size);
}
- using (var reader = new RealFirmwareReader())
- {
- // build a list of files under the global firmwares path, and build a hash for each of them while we're at it
- var todo = new Queue();
- todo.Enqueue(new DirectoryInfo(PathManager.MakeAbsolutePath(Global.Config.PathEntries.FirmwaresPathFragment, null)));
+ using var reader = new RealFirmwareReader();
+ // build a list of files under the global firmwares path, and build a hash for each of them while we're at it
+ var todo = new Queue();
+ todo.Enqueue(new DirectoryInfo(PathManager.MakeAbsolutePath(Global.Config.PathEntries.FirmwaresPathFragment, null)));
- while (todo.Count != 0)
- {
- var di = todo.Dequeue();
+ while (todo.Count != 0)
+ {
+ var di = todo.Dequeue();
- if (!di.Exists)
+ if (!di.Exists)
+ {
+ continue;
+ }
+
+ // we're going to allow recursing into subdirectories, now. its been verified to work OK
+ foreach (var disub in di.GetDirectories())
+ {
+ todo.Enqueue(disub);
+ }
+
+ foreach (var fi in di.GetFiles())
+ {
+ if (sizes.Contains(fi.Length))
{
+ reader.Read(fi);
+ }
+ }
+ }
+
+ // now, for each firmware record, try to resolve it
+ foreach (var fr in FirmwareDatabase.FirmwareRecords)
+ {
+ // clear previous resolution results
+ _resolutionDictionary.Remove(fr);
+
+ // get all options for this firmware (in order)
+ var fr1 = fr;
+ var options =
+ from fo in FirmwareDatabase.FirmwareOptions
+ where fo.SystemId == fr1.SystemId && fo.FirmwareId == fr1.FirmwareId && fo.IsAcceptableOrIdeal
+ select fo;
+
+ // try each option
+ foreach (var fo in options)
+ {
+ var hash = fo.Hash;
+
+ // did we find this firmware?
+ if (reader.Dict.ContainsKey(hash))
+ {
+ // rad! then we can use it
+ var ri = new ResolutionInfo
+ {
+ FilePath = reader.Dict[hash].FileInfo.FullName,
+ KnownFirmwareFile = FirmwareDatabase.FirmwareFilesByHash[hash],
+ Hash = hash,
+ Size = fo.Size
+ };
+ _resolutionDictionary[fr] = ri;
+ goto DONE_FIRMWARE;
+ }
+ }
+
+ DONE_FIRMWARE: ;
+ }
+
+ // apply user overrides
+ foreach (var fr in FirmwareDatabase.FirmwareRecords)
+ {
+ // do we have a user specification for this firmware record?
+ if (Global.Config.FirmwareUserSpecifications.TryGetValue(fr.ConfigKey, out var userSpec))
+ {
+ // flag it as user specified
+ if (!_resolutionDictionary.TryGetValue(fr, out ResolutionInfo ri))
+ {
+ ri = new ResolutionInfo();
+ _resolutionDictionary[fr] = ri;
+ }
+
+ ri.UserSpecified = true;
+ ri.KnownFirmwareFile = null;
+ ri.FilePath = userSpec;
+ ri.Hash = null;
+
+ // check whether it exists
+ var fi = new FileInfo(userSpec);
+ if (!fi.Exists)
+ {
+ ri.Missing = true;
continue;
}
- // we're going to allow recursing into subdirectories, now. its been verified to work OK
- foreach (var disub in di.GetDirectories())
+ // compute its hash
+ var rff = reader.Read(fi);
+ ri.Size = fi.Length;
+ ri.Hash = rff.Hash;
+
+ // check whether it was a known file anyway, and go ahead and bind to the known file, as a perk (the firmwares config doesnt really use this information right now)
+ if (FirmwareDatabase.FirmwareFilesByHash.TryGetValue(rff.Hash, out var ff))
{
- todo.Enqueue(disub);
- }
-
- foreach (var fi in di.GetFiles())
- {
- if (sizes.Contains(fi.Length))
+ ri.KnownFirmwareFile = ff;
+
+ // if the known firmware file is for a different firmware, flag it so we can show a warning
+ var option =
+ (from fo in FirmwareDatabase.FirmwareOptions
+ where fo.Hash == rff.Hash && fo.ConfigKey != fr.ConfigKey
+ select fr).FirstOrDefault();
+
+ if (option != null)
{
- reader.Read(fi);
+ ri.KnownMismatching = true;
}
}
}
-
- // now, for each firmware record, try to resolve it
- foreach (var fr in FirmwareDatabase.FirmwareRecords)
- {
- // clear previous resolution results
- _resolutionDictionary.Remove(fr);
-
- // get all options for this firmware (in order)
- var fr1 = fr;
- var options =
- from fo in FirmwareDatabase.FirmwareOptions
- where fo.SystemId == fr1.SystemId && fo.FirmwareId == fr1.FirmwareId && fo.IsAcceptableOrIdeal
- select fo;
-
- // try each option
- foreach (var fo in options)
- {
- var hash = fo.Hash;
-
- // did we find this firmware?
- if (reader.Dict.ContainsKey(hash))
- {
- // rad! then we can use it
- var ri = new ResolutionInfo
- {
- FilePath = reader.Dict[hash].FileInfo.FullName,
- KnownFirmwareFile = FirmwareDatabase.FirmwareFilesByHash[hash],
- Hash = hash,
- Size = fo.Size
- };
- _resolutionDictionary[fr] = ri;
- goto DONE_FIRMWARE;
- }
- }
-
- DONE_FIRMWARE: ;
- }
-
- // apply user overrides
- foreach (var fr in FirmwareDatabase.FirmwareRecords)
- {
- string userSpec;
-
- // do we have a user specification for this firmware record?
- if (Global.Config.FirmwareUserSpecifications.TryGetValue(fr.ConfigKey, out userSpec))
- {
- // flag it as user specified
- ResolutionInfo ri;
- if (!_resolutionDictionary.TryGetValue(fr, out ri))
- {
- ri = new ResolutionInfo();
- _resolutionDictionary[fr] = ri;
- }
-
- ri.UserSpecified = true;
- ri.KnownFirmwareFile = null;
- ri.FilePath = userSpec;
- ri.Hash = null;
-
- // check whether it exists
- var fi = new FileInfo(userSpec);
- if (!fi.Exists)
- {
- ri.Missing = true;
- continue;
- }
-
- // compute its hash
- var rff = reader.Read(fi);
- ri.Size = fi.Length;
- ri.Hash = rff.Hash;
-
- // check whether it was a known file anyway, and go ahead and bind to the known file, as a perk (the firmwares config doesnt really use this information right now)
- FirmwareDatabase.FirmwareFile ff;
- if (FirmwareDatabase.FirmwareFilesByHash.TryGetValue(rff.Hash, out ff))
- {
- ri.KnownFirmwareFile = ff;
-
- // if the known firmware file is for a different firmware, flag it so we can show a warning
- var option =
- (from fo in FirmwareDatabase.FirmwareOptions
- where fo.Hash == rff.Hash && fo.ConfigKey != fr.ConfigKey
- select fr).FirstOrDefault();
-
- if (option != null)
- {
- ri.KnownMismatching = true;
- }
- }
- }
- } // foreach(firmware record)
- } // using(new RealFirmwareReader())
+ } // foreach(firmware record)
} // DoScanAndResolve()
} // class FirmwareManager
} // namespace
\ No newline at end of file
diff --git a/BizHawk.Client.Common/FrameworkFastZipWriter.cs b/BizHawk.Client.Common/FrameworkFastZipWriter.cs
index b7317afc50..c55058aad3 100644
--- a/BizHawk.Client.Common/FrameworkFastZipWriter.cs
+++ b/BizHawk.Client.Common/FrameworkFastZipWriter.cs
@@ -2,9 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
-using System.Linq;
using System.Text;
-using System.Threading.Tasks;
namespace BizHawk.Client.Common
{
diff --git a/BizHawk.Client.Common/NESGameGenieEncoderDecoder.cs b/BizHawk.Client.Common/NESGameGenieEncoderDecoder.cs
index bbc94f6e61..2314cfbeb2 100644
--- a/BizHawk.Client.Common/NESGameGenieEncoderDecoder.cs
+++ b/BizHawk.Client.Common/NESGameGenieEncoderDecoder.cs
@@ -46,9 +46,8 @@ namespace BizHawk.Client.Common
// maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|5|E|F|G|
Value = 0;
Address = 0x8000;
- int x;
- _gameGenieTable.TryGetValue(_code[0], out x);
+ _gameGenieTable.TryGetValue(_code[0], out var x);
Value |= x & 0x07;
Value |= (x & 0x08) << 4;
@@ -79,9 +78,8 @@ namespace BizHawk.Client.Common
Value = 0;
Address = 0x8000;
Compare = 0;
- int x;
- _gameGenieTable.TryGetValue(_code[0], out x);
+ _gameGenieTable.TryGetValue(_code[0], out var x);
Value |= x & 0x07;
Value |= (x & 0x08) << 4;
diff --git a/BizHawk.Client.Common/OpenAdvanced.cs b/BizHawk.Client.Common/OpenAdvanced.cs
index 2250fcf2dd..bd20343924 100644
--- a/BizHawk.Client.Common/OpenAdvanced.cs
+++ b/BizHawk.Client.Common/OpenAdvanced.cs
@@ -1,10 +1,5 @@
using System;
-using System.Text;
using System.IO;
-using System.Collections.Generic;
-
-using BizHawk.Emulation.Cores;
-
using Newtonsoft.Json;
//this file contains some cumbersome self-"serialization" in order to gain a modicum of control over what the serialized output looks like
@@ -47,7 +42,7 @@ namespace BizHawk.Client.Common
{
if (text.StartsWith("*"))
return Deserialize(text.Substring(1));
- else return new OpenAdvanced_OpenRom { Path = text };
+ return new OpenAdvanced_OpenRom { Path = text };
}
private static IOpenAdvanced Deserialize(string text)
@@ -106,11 +101,11 @@ namespace BizHawk.Client.Common
{
public string Path, CorePath;
}
- public Token token = new Token();
+ public Token token;
- public string TypeName { get { return "Libretro"; } }
- public string DisplayName { get { return $"{Path.GetFileNameWithoutExtension(token.CorePath)}: {token.Path}"; } }
- public string SimplePath { get { return token.Path; } }
+ public string TypeName => "Libretro";
+ public string DisplayName => $"{Path.GetFileNameWithoutExtension(token.CorePath)}: {token.Path}";
+ public string SimplePath => token.Path;
public void Deserialize(string str)
{
@@ -131,27 +126,26 @@ namespace BizHawk.Client.Common
public class OpenAdvanced_LibretroNoGame : IOpenAdvanced, IOpenAdvancedLibretro
{
- //you might think ideally we'd fetch the libretro core name from the core info inside it
- //but that would involve spinning up excess libretro core instances, which probably isnt good for stability, no matter how much we wish otherwise, not to mention slow.
- //moreover it's kind of complicated here,
- //and finally, I think the Displayname should really be file-based in all cases, since the user is going to be loading cores by filename and
- //this is related to the recent roms filename management.
- //so, leave it.
-
+ // you might think ideally we'd fetch the libretro core name from the core info inside it
+ // but that would involve spinning up excess libretro core instances, which probably isn't good for stability, no matter how much we wish otherwise, not to mention slow.
+ // moreover it's kind of complicated here,
+ // and finally, I think the DisplayName should really be file-based in all cases, since the user is going to be loading cores by filename and
+ // this is related to the recent roms filename management.
+ // so, leave it.
public OpenAdvanced_LibretroNoGame()
{
}
- public OpenAdvanced_LibretroNoGame(string corepath)
+ public OpenAdvanced_LibretroNoGame(string corePath)
{
- _corePath = corepath;
+ _corePath = corePath;
}
string _corePath;
- public string TypeName { get { return "LibretroNoGame"; } }
- public string DisplayName { get { return Path.GetFileName(_corePath); } } //assume we like the filename of the core
- public string SimplePath { get { return ""; } } //effectively a signal to not use a game
+ public string TypeName => "LibretroNoGame";
+ public string DisplayName => Path.GetFileName(_corePath); // assume we like the filename of the core
+ public string SimplePath => ""; // effectively a signal to not use a game
public void Deserialize(string str)
{
@@ -177,9 +171,9 @@ namespace BizHawk.Client.Common
public string Path;
- public string TypeName { get { return "OpenRom"; } }
- public string DisplayName { get { return Path; } }
- public string SimplePath { get { return Path; } }
+ public string TypeName => "OpenRom";
+ public string DisplayName => Path;
+ public string SimplePath => Path;
public void Deserialize(string str)
{
@@ -199,9 +193,9 @@ namespace BizHawk.Client.Common
public string Path;
- public string TypeName { get { return "MAME"; } }
- public string DisplayName { get { return $"{TypeName}: {Path}"; } }
- public string SimplePath { get { return Path; } }
+ public string TypeName => "MAME";
+ public string DisplayName => $"{TypeName}: {Path}";
+ public string SimplePath => Path;
public void Deserialize(string str)
{
diff --git a/BizHawk.Client.Common/RomGame.cs b/BizHawk.Client.Common/RomGame.cs
index 51cc595c0c..ee94c2a899 100644
--- a/BizHawk.Client.Common/RomGame.cs
+++ b/BizHawk.Client.Common/RomGame.cs
@@ -16,10 +16,6 @@ namespace BizHawk.Client.Common
private const int BankSize = 1024;
- public RomGame()
- {
- }
-
public RomGame(HawkFile file)
: this(file, null)
{
@@ -39,7 +35,7 @@ namespace BizHawk.Client.Common
int fileLength = (int)stream.Length;
// read the entire contents of the file into memory.
- // unfortunate in the case of large files, but thats what we've got to work with for now.
+ // unfortunate in the case of large files, but that's what we've got to work with for now.
// if we're offset exactly 512 bytes from a 1024-byte boundary,
// assume we have a header of that size. Otherwise, assume it's just all rom.
@@ -70,14 +66,14 @@ namespace BizHawk.Client.Common
else if (file.Extension == ".DSK" || file.Extension == ".TAP" || file.Extension == ".TZX" ||
file.Extension == ".PZX" || file.Extension == ".CSW" || file.Extension == ".WAV" || file.Extension == ".CDT")
{
- // these are not roms. unforunately if treated as such there are certain edge-cases
+ // these are not roms. unfortunately if treated as such there are certain edge-cases
// where a header offset is detected. This should mitigate this issue until a cleaner solution is found
// (-Asnivor)
RomData = FileData;
}
else
{
- // if there was a header offset, read the whole file into FileData and then copy it into RomData (this is unfortunate, in case RomData isnt needed)
+ // if there was a header offset, read the whole file into FileData and then copy it into RomData (this is unfortunate, in case RomData isn't needed)
int romLength = fileLength - headerOffset;
RomData = new byte[romLength];
Buffer.BlockCopy(FileData, headerOffset, RomData, 0, romLength);
@@ -96,7 +92,7 @@ namespace BizHawk.Client.Common
// note: this will be taking several hashes, of a potentially large amount of data.. yikes!
GameInfo = Database.GetGameInfo(RomData, file.Name);
- if (GameInfo.NotInDatabase && headerOffset==128 && file.Extension == ".A78")
+ if (GameInfo.NotInDatabase && headerOffset == 128 && file.Extension == ".A78")
{
// if the game is not in the DB, add the header back in so the core can use it
// for now only .A78 games, but probably should be for other systems as well
@@ -107,13 +103,11 @@ namespace BizHawk.Client.Common
if (patch != null)
{
- using (var patchFile = new HawkFile(patch))
+ using var patchFile = new HawkFile(patch);
+ patchFile.BindFirstOf("IPS");
+ if (patchFile.IsBound)
{
- patchFile.BindFirstOf("IPS");
- if (patchFile.IsBound)
- {
- RomData = IPS.Patch(RomData, patchFile.GetStream());
- }
+ RomData = IPS.Patch(RomData, patchFile.GetStream());
}
}
}
diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs
index 0db14d1659..6e35d5d839 100644
--- a/BizHawk.Client.Common/RomLoader.cs
+++ b/BizHawk.Client.Common/RomLoader.cs
@@ -259,236 +259,169 @@ namespace BizHawk.Client.Common
return false;
}
- using (var file = new HawkFile())
+ using var file = new HawkFile();
+ // only try mounting a file if a filename was given
+ if (!string.IsNullOrEmpty(path))
{
- // only try mounting a file if a filename was given
- if (!string.IsNullOrEmpty(path))
+ // MAME uses these extensions for arcade ROMs, but also accepts all sorts of variations of archives, folders, and files. if we let archive loader handle this, it won't know where to stop, since it'd require MAME's ROM database (which contains ROM names and blob hashes) to look things up, and even then it might be confused by archive/folder structure
+ // so assume the user provides the proper ROM directly, and handle possible errors later
+ if (OpenAdvanced is OpenAdvanced_MAME)
{
- // MAME uses these extensions for arcade ROMs, but also accepts all sorts of variations of archives, folders, and files. if we let archive loader handle this, it won't know where to stop, since it'd require MAME's ROM database (which contains ROM names and blob hashes) to look things up, and even then it might be confused by archive/folder structure
- // so assume the user provides the proper ROM directly, and handle possible errors later
- if (OpenAdvanced is OpenAdvanced_MAME)
+ file.NonArchiveExtensions = new[] { ".zip", ".7z" };
+ }
+
+ file.Open(path);
+
+ // if the provided file doesn't even exist, give up!
+ if (!file.Exists)
+ {
+ return false;
+ }
+ }
+
+ CanonicalFullPath = file.CanonicalFullPath;
+
+ IEmulator nextEmulator = null;
+ RomGame rom = null;
+ GameInfo game = null;
+
+ try
+ {
+ string ext = null;
+
+ if (OpenAdvanced is OpenAdvanced_Libretro)
+ {
+ string codePathPart = Path.GetFileNameWithoutExtension(nextComm.LaunchLibretroCore);
+
+ var retro = new LibretroCore(nextComm, nextComm.LaunchLibretroCore);
+ nextEmulator = retro;
+
+ // kind of dirty.. we need to stash this, and then we can unstash it in a moment, in case the core doesn't fail
+ var oldGame = Global.Game;
+
+ if (retro.Description.SupportsNoGame && string.IsNullOrEmpty(path))
{
- file.NonArchiveExtensions = new[] { ".zip", ".7z" };
+ // must be done before LoadNoGame (which triggers retro_init and the paths to be consumed by the core)
+ // game name == name of core
+ var gameName = codePathPart;
+ Global.Game = game = new GameInfo { Name = gameName, System = "Libretro" };
+
+ // if we are allowed to run NoGame and we don't have a game, boot up the core that way
+ bool ret = retro.LoadNoGame();
+
+ Global.Game = oldGame;
+
+ if (!ret)
+ {
+ DoLoadErrorCallback("LibretroNoGame failed to load. This is weird", "Libretro");
+ retro.Dispose();
+ return false;
+ }
+ }
+ else
+ {
+ bool ret;
+
+ // must be done before LoadNoGame (which triggers retro_init and the paths to be consumed by the core)
+ // game name == name of core + extensionless_game_filename
+ var gameName = Path.Combine(codePathPart, Path.GetFileNameWithoutExtension(file.Name));
+ Global.Game = game = new GameInfo { Name = gameName, System = "Libretro" };
+
+ // if the core requires an archive file, then try passing the filename of the archive
+ // (but do we ever need to actually load the contents of the archive file into ram?)
+ if (retro.Description.NeedsArchives)
+ {
+ if (file.IsArchiveMember)
+ {
+ throw new InvalidOperationException("Should not have bound file member for libretro block_extract core");
+ }
+
+ ret = retro.LoadPath(file.FullPathWithoutMember);
+ }
+ else
+ {
+ // otherwise load the data or pass the filename, as requested. but..
+ if (retro.Description.NeedsRomAsPath && file.IsArchiveMember)
+ {
+ throw new InvalidOperationException("Cannot pass archive member to libretro needs_fullpath core");
+ }
+
+ if (retro.Description.NeedsRomAsPath)
+ {
+ ret = retro.LoadPath(file.FullPathWithoutMember);
+ }
+ else
+ {
+ ret = HandleArchiveBinding(file);
+ if (ret)
+ {
+ ret = retro.LoadData(file.ReadAllBytes(), file.Name);
+ }
+ }
+ }
+
+ Global.Game = oldGame;
+
+ if (!ret)
+ {
+ DoLoadErrorCallback("Libretro failed to load the given file. This is probably due to a core/content mismatch. Moreover, the process is now likely to be hosed. We suggest you restart the program.", "Libretro");
+ retro.Dispose();
+ return false;
+ }
+ }
+ }
+ else
+ {
+ // at this point, file is either assigned to the ROM path, if it exists,
+ // or is empty and CoreComm is not a libretro core
+ // so, we still need to check path here before continuing
+ if (string.IsNullOrEmpty(path))
+ {
+ Console.WriteLine("No ROM to Load");
+ return false;
}
- file.Open(path);
+ // if not libretro:
+ // do extension checking
+ ext = file.Extension.ToLowerInvariant();
- // if the provided file doesn't even exist, give up!
- if (!file.Exists)
+ // do the archive binding we had to skip
+ if (!HandleArchiveBinding(file))
{
return false;
}
}
- CanonicalFullPath = file.CanonicalFullPath;
-
- IEmulator nextEmulator = null;
- RomGame rom = null;
- GameInfo game = null;
-
- try
+ if (string.IsNullOrEmpty(ext))
{
- string ext = null;
-
- if (OpenAdvanced is OpenAdvanced_Libretro)
+ }
+ else if (ext == ".m3u")
+ {
+ // HACK ZONE - currently only psx supports m3u
+ M3U_File m3u;
+ using (var sr = new StreamReader(path))
{
- string codePathPart = Path.GetFileNameWithoutExtension(nextComm.LaunchLibretroCore);
-
- var retro = new LibretroCore(nextComm, nextComm.LaunchLibretroCore);
- nextEmulator = retro;
-
- // kind of dirty.. we need to stash this, and then we can unstash it in a moment, in case the core doesn't fail
- var oldGame = Global.Game;
-
- if (retro.Description.SupportsNoGame && string.IsNullOrEmpty(path))
- {
- // must be done before LoadNoGame (which triggers retro_init and the paths to be consumed by the core)
- // game name == name of core
- var gameName = codePathPart;
- Global.Game = game = new GameInfo { Name = gameName, System = "Libretro" };
-
- // if we are allowed to run NoGame and we don't have a game, boot up the core that way
- bool ret = retro.LoadNoGame();
-
- Global.Game = oldGame;
-
- if (!ret)
- {
- DoLoadErrorCallback("LibretroNoGame failed to load. This is weird", "Libretro");
- retro.Dispose();
- return false;
- }
- }
- else
- {
- bool ret;
-
- // must be done before LoadNoGame (which triggers retro_init and the paths to be consumed by the core)
- // game name == name of core + extensionless_game_filename
- var gameName = Path.Combine(codePathPart, Path.GetFileNameWithoutExtension(file.Name));
- Global.Game = game = new GameInfo { Name = gameName, System = "Libretro" };
-
- // if the core requires an archive file, then try passing the filename of the archive
- // (but do we ever need to actually load the contents of the archive file into ram?)
- if (retro.Description.NeedsArchives)
- {
- if (file.IsArchiveMember)
- {
- throw new InvalidOperationException("Should not have bound file member for libretro block_extract core");
- }
-
- ret = retro.LoadPath(file.FullPathWithoutMember);
- }
- else
- {
- // otherwise load the data or pass the filename, as requested. but..
- if (retro.Description.NeedsRomAsPath && file.IsArchiveMember)
- {
- throw new InvalidOperationException("Cannot pass archive member to libretro needs_fullpath core");
- }
-
- if (retro.Description.NeedsRomAsPath)
- {
- ret = retro.LoadPath(file.FullPathWithoutMember);
- }
- else
- {
- ret = HandleArchiveBinding(file);
- if (ret)
- {
- ret = retro.LoadData(file.ReadAllBytes(), file.Name);
- }
- }
- }
-
- Global.Game = oldGame;
-
- if (!ret)
- {
- DoLoadErrorCallback("Libretro failed to load the given file. This is probably due to a core/content mismatch. Moreover, the process is now likely to be hosed. We suggest you restart the program.", "Libretro");
- retro.Dispose();
- return false;
- }
- }
- }
- else
- {
- // at this point, file is either assigned to the ROM path, if it exists,
- // or is empty and CoreComm is not a libretro core
- // so, we still need to check path here before continuing
- if (string.IsNullOrEmpty(path))
- {
- Console.WriteLine("No ROM to Load");
- return false;
- }
-
- // if not libretro:
- // do extension checking
- ext = file.Extension.ToLowerInvariant();
-
- // do the archive binding we had to skip
- if (!HandleArchiveBinding(file))
- {
- return false;
- }
+ m3u = M3U_File.Read(sr);
}
- if (string.IsNullOrEmpty(ext))
+ if (m3u.Entries.Count == 0)
{
+ throw new InvalidOperationException("Can't load an empty M3U");
}
- else if (ext == ".m3u")
+
+ // load discs for all the m3u
+ m3u.Rebase(Path.GetDirectoryName(path));
+ var discs = new List();
+ var discNames = new List();
+ var sw = new StringWriter();
+ foreach (var e in m3u.Entries)
{
- // HACK ZONE - currently only psx supports m3u
- M3U_File m3u;
- using (var sr = new StreamReader(path))
- {
- m3u = M3U_File.Read(sr);
- }
-
- if (m3u.Entries.Count == 0)
- {
- throw new InvalidOperationException("Can't load an empty M3U");
- }
-
- // load discs for all the m3u
- m3u.Rebase(Path.GetDirectoryName(path));
- var discs = new List();
- var discNames = new List();
- var sw = new StringWriter();
- foreach (var e in m3u.Entries)
- {
- string discPath = e.Path;
-
- //--- load the disc in a context which will let us abort if it's going to take too long
- var discMountJob = new DiscMountJob { IN_FromPath = discPath, IN_SlowLoadAbortThreshold = 8 };
- discMountJob.Run();
- var disc = discMountJob.OUT_Disc;
-
- if (discMountJob.OUT_SlowLoadAborted)
- {
- DoLoadErrorCallback("This disc would take too long to load. Run it through DiscoHawk first, or find a new rip because this one is probably junk", "", LoadErrorType.DiscError);
- return false;
- }
-
- if (discMountJob.OUT_ErrorLevel)
- {
- throw new InvalidOperationException($"\r\n{discMountJob.OUT_Log}");
- }
-
- if (disc == null)
- {
- throw new InvalidOperationException("Can't load one of the files specified in the M3U");
- }
-
- var discName = Path.GetFileNameWithoutExtension(discPath);
- discNames.Add(discName);
- discs.Add(disc);
-
- var discType = new DiscIdentifier(disc).DetectDiscType();
- sw.WriteLine("{0}", Path.GetFileName(discPath));
- if (discType == DiscType.SonyPSX)
- {
- string discHash = new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8");
- game = Database.CheckDatabase(discHash);
- if (game == null || game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
- {
- sw.WriteLine("Disc could not be identified as known-good. Look for a better rip.");
- }
- else
- {
- sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
- sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
- sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
- sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
- sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
- }
- }
- else
- {
- sw.WriteLine("Not a PSX disc");
- }
-
- sw.WriteLine("-------------------------");
- }
-
- nextEmulator = new Octoshock(nextComm, discs, discNames, null, GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
- game = new GameInfo
- {
- Name = Path.GetFileNameWithoutExtension(file.Name),
- System = "PSX"
- };
- }
- else if (ext == ".iso" || ext == ".cue" || ext == ".ccd" || ext == ".mds")
- {
- if (file.IsArchive)
- {
- throw new InvalidOperationException("Can't load CD files from archives!");
- }
+ string discPath = e.Path;
//--- load the disc in a context which will let us abort if it's going to take too long
- var discMountJob = new DiscMountJob { IN_FromPath = path, IN_SlowLoadAbortThreshold = 8 };
+ var discMountJob = new DiscMountJob { IN_FromPath = discPath, IN_SlowLoadAbortThreshold = 8 };
discMountJob.Run();
+ var disc = discMountJob.OUT_Disc;
if (discMountJob.OUT_SlowLoadAborted)
{
@@ -501,131 +434,197 @@ namespace BizHawk.Client.Common
throw new InvalidOperationException($"\r\n{discMountJob.OUT_Log}");
}
- var disc = discMountJob.OUT_Disc;
-
- // -----------
- // TODO - use more sophisticated IDer
- var discType = new DiscIdentifier(disc).DetectDiscType();
- var discHash = discType == DiscType.SonyPSX
- ? new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8")
- : new DiscHasher(disc).OldHash();
-
- game = Database.CheckDatabase(discHash);
- if (game == null)
+ if (disc == null)
{
- // try to use our wizard methods
- game = new GameInfo { Name = Path.GetFileNameWithoutExtension(file.Name), Hash = discHash };
-
- var dt = new DiscIdentifier(disc).DetectDiscType();
-
- switch (dt)
- {
- case DiscType.SegaSaturn:
- game.System = "SAT";
- break;
- case DiscType.SonyPSP:
- game.System = "PSP";
- break;
- default:
- case DiscType.SonyPSX:
- game.System = "PSX";
- break;
- case DiscType.MegaCD:
- game.System = "GEN";
- break;
- case DiscType.PCFX:
- game.System = "PCFX";
- break;
- case DiscType.TurboCD:
- game.System = "PCECD";
- break;
-
- case DiscType.Amiga:
- case DiscType.CDi:
- case DiscType.Dreamcast:
- case DiscType.GameCube:
- case DiscType.NeoGeoCD:
- case DiscType.Panasonic3DO:
- case DiscType.Playdia:
- case DiscType.Wii:
- // no supported emulator core for these (yet)
- game.System = dt.ToString();
- throw new NoAvailableCoreException(dt.ToString());
-
- case DiscType.AudioDisc:
- case DiscType.UnknownCDFS:
- case DiscType.UnknownFormat:
- game.System = PreferredPlatformIsDefined(ext)
- ? Global.Config.PreferredPlatformsForExtensions[ext]
- : "NULL";
- break;
- }
+ throw new InvalidOperationException("Can't load one of the files specified in the M3U");
}
- switch (game.System)
- {
- case "NULL":
- nextEmulator = null;
- break;
- case "GEN":
- var genesis = new GPGX(nextComm, null, new[] { disc }, GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator = genesis;
- break;
- case "SAT":
- nextEmulator = new Saturnus(nextComm, new[] { disc }, Deterministic,
- (Saturnus.Settings)GetCoreSettings(), (Saturnus.SyncSettings)GetCoreSyncSettings());
- break;
- case "PSP":
- nextEmulator = new PSP(nextComm, file.Name);
- break;
- case "PSX":
- nextEmulator = new Octoshock(nextComm, new List(new[] { disc }), new List(new[] { Path.GetFileNameWithoutExtension(path) }), null, GetCoreSettings(), GetCoreSyncSettings());
- if (game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
- {
- nextEmulator.CoreComm.RomStatusDetails = "Disc could not be identified as known-good. Look for a better rip.";
- }
- else
- {
- var sw = new StringWriter();
- sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
- sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
- sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
- sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
- sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
- nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
- }
+ var discName = Path.GetFileNameWithoutExtension(discPath);
+ discNames.Add(discName);
+ discs.Add(disc);
+ var discType = new DiscIdentifier(disc).DetectDiscType();
+ sw.WriteLine("{0}", Path.GetFileName(discPath));
+ if (discType == DiscType.SonyPSX)
+ {
+ string discHash = new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8");
+ game = Database.CheckDatabase(discHash);
+ if (game == null || game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
+ {
+ sw.WriteLine("Disc could not be identified as known-good. Look for a better rip.");
+ }
+ else
+ {
+ sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
+ sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
+ sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
+ sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
+ sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
+ }
+ }
+ else
+ {
+ sw.WriteLine("Not a PSX disc");
+ }
+
+ sw.WriteLine("-------------------------");
+ }
+
+ nextEmulator = new Octoshock(nextComm, discs, discNames, null, GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
+ game = new GameInfo
+ {
+ Name = Path.GetFileNameWithoutExtension(file.Name),
+ System = "PSX"
+ };
+ }
+ else if (ext == ".iso" || ext == ".cue" || ext == ".ccd" || ext == ".mds")
+ {
+ if (file.IsArchive)
+ {
+ throw new InvalidOperationException("Can't load CD files from archives!");
+ }
+
+ //--- load the disc in a context which will let us abort if it's going to take too long
+ var discMountJob = new DiscMountJob { IN_FromPath = path, IN_SlowLoadAbortThreshold = 8 };
+ discMountJob.Run();
+
+ if (discMountJob.OUT_SlowLoadAborted)
+ {
+ DoLoadErrorCallback("This disc would take too long to load. Run it through DiscoHawk first, or find a new rip because this one is probably junk", "", LoadErrorType.DiscError);
+ return false;
+ }
+
+ if (discMountJob.OUT_ErrorLevel)
+ {
+ throw new InvalidOperationException($"\r\n{discMountJob.OUT_Log}");
+ }
+
+ var disc = discMountJob.OUT_Disc;
+
+ // -----------
+ // TODO - use more sophisticated IDer
+ var discType = new DiscIdentifier(disc).DetectDiscType();
+ var discHash = discType == DiscType.SonyPSX
+ ? new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8")
+ : new DiscHasher(disc).OldHash();
+
+ game = Database.CheckDatabase(discHash);
+ if (game == null)
+ {
+ // try to use our wizard methods
+ game = new GameInfo { Name = Path.GetFileNameWithoutExtension(file.Name), Hash = discHash };
+
+ var dt = new DiscIdentifier(disc).DetectDiscType();
+
+ switch (dt)
+ {
+ case DiscType.SegaSaturn:
+ game.System = "SAT";
break;
- case "PCFX":
- nextEmulator = new Tst(nextComm, new[] { disc },
- (Tst.Settings)GetCoreSettings(), (Tst.SyncSettings)GetCoreSyncSettings());
+ case DiscType.SonyPSP:
+ game.System = "PSP";
break;
- case "PCE":
- case "PCECD":
- nextEmulator = new PCEngine(nextComm, game, disc, GetCoreSettings(), GetCoreSyncSettings());
+ default:
+ case DiscType.SonyPSX:
+ game.System = "PSX";
+ break;
+ case DiscType.MegaCD:
+ game.System = "GEN";
+ break;
+ case DiscType.PCFX:
+ game.System = "PCFX";
+ break;
+ case DiscType.TurboCD:
+ game.System = "PCECD";
+ break;
+
+ case DiscType.Amiga:
+ case DiscType.CDi:
+ case DiscType.Dreamcast:
+ case DiscType.GameCube:
+ case DiscType.NeoGeoCD:
+ case DiscType.Panasonic3DO:
+ case DiscType.Playdia:
+ case DiscType.Wii:
+ // no supported emulator core for these (yet)
+ game.System = dt.ToString();
+ throw new NoAvailableCoreException(dt.ToString());
+
+ case DiscType.AudioDisc:
+ case DiscType.UnknownCDFS:
+ case DiscType.UnknownFormat:
+ game.System = PreferredPlatformIsDefined(ext)
+ ? Global.Config.PreferredPlatformsForExtensions[ext]
+ : "NULL";
break;
}
}
- else if (file.Extension.ToLowerInvariant() == ".xml")
+
+ switch (game.System)
{
- try
- {
- var xmlGame = XmlGame.Create(file); // if load fails, are we supposed to retry as a bsnes XML????????
- game = xmlGame.GI;
-
- switch (game.System)
+ case "NULL":
+ nextEmulator = null;
+ break;
+ case "GEN":
+ var genesis = new GPGX(nextComm, null, new[] { disc }, GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator = genesis;
+ break;
+ case "SAT":
+ nextEmulator = new Saturnus(nextComm, new[] { disc }, Deterministic,
+ (Saturnus.Settings)GetCoreSettings(), (Saturnus.SyncSettings)GetCoreSyncSettings());
+ break;
+ case "PSP":
+ nextEmulator = new PSP(nextComm, file.Name);
+ break;
+ case "PSX":
+ nextEmulator = new Octoshock(nextComm, new List(new[] { disc }), new List(new[] { Path.GetFileNameWithoutExtension(path) }), null, GetCoreSettings(), GetCoreSyncSettings());
+ if (game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
{
- case "GB":
- case "DGB":
- // adelikat: remove need for tags to be hardcoded to left and right, we should clean this up, also maybe the DGB core should just take the xml file and handle it itself
- var leftBytes = xmlGame.Assets.First().Value;
- var rightBytes = xmlGame.Assets.Skip(1).First().Value;
+ nextEmulator.CoreComm.RomStatusDetails = "Disc could not be identified as known-good. Look for a better rip.";
+ }
+ else
+ {
+ var sw = new StringWriter();
+ sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
+ sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
+ sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
+ sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
+ sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
+ nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
+ }
- var left = Database.GetGameInfo(leftBytes, "left.gb");
- var right = Database.GetGameInfo(rightBytes, "right.gb");
- if (Global.Config.GbUseGbHawk)
- {
- nextEmulator = new GBHawkLink(
+ break;
+ case "PCFX":
+ nextEmulator = new Tst(nextComm, new[] { disc },
+ (Tst.Settings)GetCoreSettings(), (Tst.SyncSettings)GetCoreSyncSettings());
+ break;
+ case "PCE":
+ case "PCECD":
+ nextEmulator = new PCEngine(nextComm, game, disc, GetCoreSettings(), GetCoreSyncSettings());
+ break;
+ }
+ }
+ else if (file.Extension.ToLowerInvariant() == ".xml")
+ {
+ try
+ {
+ var xmlGame = XmlGame.Create(file); // if load fails, are we supposed to retry as a bsnes XML????????
+ game = xmlGame.GI;
+
+ switch (game.System)
+ {
+ case "GB":
+ case "DGB":
+ // adelikat: remove need for tags to be hardcoded to left and right, we should clean this up, also maybe the DGB core should just take the xml file and handle it itself
+ var leftBytes = xmlGame.Assets.First().Value;
+ var rightBytes = xmlGame.Assets.Skip(1).First().Value;
+
+ var left = Database.GetGameInfo(leftBytes, "left.gb");
+ var right = Database.GetGameInfo(rightBytes, "right.gb");
+ if (Global.Config.GbUseGbHawk)
+ {
+ nextEmulator = new GBHawkLink(
nextComm,
left,
leftBytes,
@@ -633,10 +632,10 @@ namespace BizHawk.Client.Common
rightBytes,
GetCoreSettings(),
GetCoreSyncSettings());
- }
- else
- {
- nextEmulator = new GambatteLink(
+ }
+ else
+ {
+ nextEmulator = new GambatteLink(
nextComm,
left,
leftBytes,
@@ -645,20 +644,20 @@ namespace BizHawk.Client.Common
GetCoreSettings(),
GetCoreSyncSettings(),
Deterministic);
- }
+ }
- // other stuff todo
- break;
- case "GB3x":
- var leftBytes3x = xmlGame.Assets.First().Value;
- var centerBytes3x = xmlGame.Assets.Skip(1).First().Value;
- var rightBytes3x = xmlGame.Assets.Skip(2).First().Value;
+ // other stuff todo
+ break;
+ case "GB3x":
+ var leftBytes3x = xmlGame.Assets.First().Value;
+ var centerBytes3x = xmlGame.Assets.Skip(1).First().Value;
+ var rightBytes3x = xmlGame.Assets.Skip(2).First().Value;
- var left3x = Database.GetGameInfo(leftBytes3x, "left.gb");
- var center3x = Database.GetGameInfo(centerBytes3x, "center.gb");
- var right3x = Database.GetGameInfo(rightBytes3x, "right.gb");
+ var left3x = Database.GetGameInfo(leftBytes3x, "left.gb");
+ var center3x = Database.GetGameInfo(centerBytes3x, "center.gb");
+ var right3x = Database.GetGameInfo(rightBytes3x, "right.gb");
- nextEmulator = new GBHawkLink3x(
+ nextEmulator = new GBHawkLink3x(
nextComm,
left3x,
leftBytes3x,
@@ -669,19 +668,19 @@ namespace BizHawk.Client.Common
GetCoreSettings(),
GetCoreSyncSettings());
- break;
- case "GB4x":
- var A_Bytes4x = xmlGame.Assets.First().Value;
- var B_Bytes4x = xmlGame.Assets.Skip(1).First().Value;
- var C_Bytes4x = xmlGame.Assets.Skip(2).First().Value;
- var D_Bytes4x = xmlGame.Assets.Skip(3).First().Value;
+ break;
+ case "GB4x":
+ var A_Bytes4x = xmlGame.Assets.First().Value;
+ var B_Bytes4x = xmlGame.Assets.Skip(1).First().Value;
+ var C_Bytes4x = xmlGame.Assets.Skip(2).First().Value;
+ var D_Bytes4x = xmlGame.Assets.Skip(3).First().Value;
- var A_4x = Database.GetGameInfo(A_Bytes4x, "A.gb");
- var B_4x = Database.GetGameInfo(B_Bytes4x, "B.gb");
- var C_4x = Database.GetGameInfo(C_Bytes4x, "C.gb");
- var D_4x = Database.GetGameInfo(D_Bytes4x, "D.gb");
+ var A_4x = Database.GetGameInfo(A_Bytes4x, "A.gb");
+ var B_4x = Database.GetGameInfo(B_Bytes4x, "B.gb");
+ var C_4x = Database.GetGameInfo(C_Bytes4x, "C.gb");
+ var D_4x = Database.GetGameInfo(D_Bytes4x, "D.gb");
- nextEmulator = new GBHawkLink4x(
+ nextEmulator = new GBHawkLink4x(
nextComm,
A_4x,
A_Bytes4x,
@@ -694,162 +693,162 @@ namespace BizHawk.Client.Common
GetCoreSettings(),
GetCoreSyncSettings());
- break;
- case "AppleII":
- var assets = xmlGame.Assets.Select(a => Database.GetGameInfo(a.Value, a.Key));
- var roms = xmlGame.Assets.Select(a => a.Value);
- nextEmulator = new AppleII(
- nextComm,
- assets,
- roms,
- (AppleII.Settings)GetCoreSettings());
- break;
- case "C64":
- nextEmulator = new C64(
- nextComm,
- xmlGame.Assets.Select(a => a.Value),
- GameInfo.NullInstance,
- (C64.C64Settings)GetCoreSettings(),
- (C64.C64SyncSettings)GetCoreSyncSettings());
- break;
- case "ZXSpectrum":
+ break;
+ case "AppleII":
+ var assets = xmlGame.Assets.Select(a => Database.GetGameInfo(a.Value, a.Key));
+ var roms = xmlGame.Assets.Select(a => a.Value);
+ nextEmulator = new AppleII(
+ nextComm,
+ assets,
+ roms,
+ (AppleII.Settings)GetCoreSettings());
+ break;
+ case "C64":
+ nextEmulator = new C64(
+ nextComm,
+ xmlGame.Assets.Select(a => a.Value),
+ GameInfo.NullInstance,
+ (C64.C64Settings)GetCoreSettings(),
+ (C64.C64SyncSettings)GetCoreSyncSettings());
+ break;
+ case "ZXSpectrum":
- var zxGI = new List();
- foreach (var a in xmlGame.Assets)
+ var zxGI = new List();
+ foreach (var a in xmlGame.Assets)
+ {
+ zxGI.Add(new GameInfo { Name = Path.GetFileNameWithoutExtension(a.Key) });
+ }
+
+ nextEmulator = new ZXSpectrum(
+ nextComm,
+ xmlGame.Assets.Select(a => a.Value),
+ zxGI,
+ (ZXSpectrum.ZXSpectrumSettings)GetCoreSettings(),
+ (ZXSpectrum.ZXSpectrumSyncSettings)GetCoreSyncSettings(),
+ Deterministic);
+ break;
+ case "AmstradCPC":
+
+ var cpcGI = new List();
+ foreach (var a in xmlGame.Assets)
+ {
+ cpcGI.Add(new GameInfo { Name = Path.GetFileNameWithoutExtension(a.Key) });
+ }
+
+ nextEmulator = new AmstradCPC(
+ nextComm,
+ xmlGame.Assets.Select(a => a.Value), //.First(),
+ cpcGI, // GameInfo.NullInstance,
+ (AmstradCPC.AmstradCPCSettings)GetCoreSettings(),
+ (AmstradCPC.AmstradCPCSyncSettings)GetCoreSyncSettings());
+ break;
+ case "PSX":
+ var entries = xmlGame.AssetFullPaths;
+ var discs = new List();
+ var discNames = new List();
+ var sw = new StringWriter();
+ foreach (var e in entries)
+ {
+ string discPath = e;
+
+ //--- load the disc in a context which will let us abort if it's going to take too long
+ var discMountJob = new DiscMountJob { IN_FromPath = discPath, IN_SlowLoadAbortThreshold = 8 };
+ discMountJob.Run();
+ var disc = discMountJob.OUT_Disc;
+
+ if (discMountJob.OUT_SlowLoadAborted)
{
- zxGI.Add(new GameInfo { Name = Path.GetFileNameWithoutExtension(a.Key) });
+ DoLoadErrorCallback("This disc would take too long to load. Run it through DiscoHawk first, or find a new rip because this one is probably junk", "PSX", LoadErrorType.DiscError);
+ return false;
}
- nextEmulator = new ZXSpectrum(
- nextComm,
- xmlGame.Assets.Select(a => a.Value),
- zxGI,
- (ZXSpectrum.ZXSpectrumSettings)GetCoreSettings(),
- (ZXSpectrum.ZXSpectrumSyncSettings)GetCoreSyncSettings(),
- Deterministic);
- break;
- case "AmstradCPC":
-
- var cpcGI = new List();
- foreach (var a in xmlGame.Assets)
+ if (discMountJob.OUT_ErrorLevel)
{
- cpcGI.Add(new GameInfo { Name = Path.GetFileNameWithoutExtension(a.Key) });
+ throw new InvalidOperationException($"\r\n{discMountJob.OUT_Log}");
}
- nextEmulator = new AmstradCPC(
- nextComm,
- xmlGame.Assets.Select(a => a.Value), //.First(),
- cpcGI, // GameInfo.NullInstance,
- (AmstradCPC.AmstradCPCSettings)GetCoreSettings(),
- (AmstradCPC.AmstradCPCSyncSettings)GetCoreSyncSettings());
- break;
- case "PSX":
- var entries = xmlGame.AssetFullPaths;
- var discs = new List();
- var discNames = new List();
- var sw = new StringWriter();
- foreach (var e in entries)
+ if (disc == null)
{
- string discPath = e;
+ throw new InvalidOperationException("Can't load one of the files specified in the M3U");
+ }
- //--- load the disc in a context which will let us abort if it's going to take too long
- var discMountJob = new DiscMountJob { IN_FromPath = discPath, IN_SlowLoadAbortThreshold = 8 };
- discMountJob.Run();
- var disc = discMountJob.OUT_Disc;
+ var discName = Path.GetFileNameWithoutExtension(discPath);
+ discNames.Add(discName);
+ discs.Add(disc);
- if (discMountJob.OUT_SlowLoadAborted)
+ var discType = new DiscIdentifier(disc).DetectDiscType();
+ sw.WriteLine("{0}", Path.GetFileName(discPath));
+ if (discType == DiscType.SonyPSX)
+ {
+ string discHash = new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8");
+ game = Database.CheckDatabase(discHash);
+ if (game == null || game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
{
- DoLoadErrorCallback("This disc would take too long to load. Run it through DiscoHawk first, or find a new rip because this one is probably junk", "PSX", LoadErrorType.DiscError);
- return false;
- }
-
- if (discMountJob.OUT_ErrorLevel)
- {
- throw new InvalidOperationException($"\r\n{discMountJob.OUT_Log}");
- }
-
- if (disc == null)
- {
- throw new InvalidOperationException("Can't load one of the files specified in the M3U");
- }
-
- var discName = Path.GetFileNameWithoutExtension(discPath);
- discNames.Add(discName);
- discs.Add(disc);
-
- var discType = new DiscIdentifier(disc).DetectDiscType();
- sw.WriteLine("{0}", Path.GetFileName(discPath));
- if (discType == DiscType.SonyPSX)
- {
- string discHash = new DiscHasher(disc).Calculate_PSX_BizIDHash().ToString("X8");
- game = Database.CheckDatabase(discHash);
- if (game == null || game.IsRomStatusBad() || game.Status == RomStatus.NotInDatabase)
- {
- sw.WriteLine("Disc could not be identified as known-good. Look for a better rip.");
- }
- else
- {
- sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
- sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
- sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
- sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
- sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
- }
+ sw.WriteLine("Disc could not be identified as known-good. Look for a better rip.");
}
else
{
- sw.WriteLine("Not a PSX disc");
+ sw.WriteLine("Disc was identified (99.99% confidently) as known good with disc id hash CRC32:{0:X8}", discHash);
+ sw.WriteLine("Nonetheless it could be an unrecognized romhack or patched version.");
+ sw.WriteLine("According to redump.org, the ideal hash for entire disc is: CRC32:{0:X8}", game.GetStringValue("dh"));
+ sw.WriteLine("The file you loaded hasn't been hashed entirely (it would take too long)");
+ sw.WriteLine("Compare it with the full hash calculated by the PSX menu's Hash Discs tool");
}
-
- sw.WriteLine("-------------------------");
+ }
+ else
+ {
+ sw.WriteLine("Not a PSX disc");
}
- // todo: copy pasta from PSX .cue section
- nextEmulator = new Octoshock(nextComm, discs, discNames, null, GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
- game = new GameInfo
- {
- Name = Path.GetFileNameWithoutExtension(file.Name),
- System = "PSX"
- };
- break;
- case "SAT":
- var saturnDiscs = DiscsFromXml(xmlGame, "SAT", DiscType.SegaSaturn);
- if (!saturnDiscs.Any())
- {
- return false;
- }
+ sw.WriteLine("-------------------------");
+ }
- nextEmulator = new Saturnus(nextComm, saturnDiscs, Deterministic,
+ // todo: copy pasta from PSX .cue section
+ nextEmulator = new Octoshock(nextComm, discs, discNames, null, GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator.CoreComm.RomStatusDetails = sw.ToString();
+ game = new GameInfo
+ {
+ Name = Path.GetFileNameWithoutExtension(file.Name),
+ System = "PSX"
+ };
+ break;
+ case "SAT":
+ var saturnDiscs = DiscsFromXml(xmlGame, "SAT", DiscType.SegaSaturn);
+ if (!saturnDiscs.Any())
+ {
+ return false;
+ }
+
+ nextEmulator = new Saturnus(nextComm, saturnDiscs, Deterministic,
(Saturnus.Settings)GetCoreSettings(), (Saturnus.SyncSettings)GetCoreSyncSettings());
- break;
- case "PCFX":
- var pcfxDiscs = DiscsFromXml(xmlGame, "PCFX", DiscType.PCFX);
- if (!pcfxDiscs.Any())
- {
- return false;
- }
+ break;
+ case "PCFX":
+ var pcfxDiscs = DiscsFromXml(xmlGame, "PCFX", DiscType.PCFX);
+ if (!pcfxDiscs.Any())
+ {
+ return false;
+ }
- nextEmulator = new Tst(nextComm, pcfxDiscs,
- (Tst.Settings)GetCoreSettings(), (Tst.SyncSettings)GetCoreSyncSettings());
- break;
- case "GEN":
- // We are assuming discs only, for now
- var genDiscs = DiscsFromXml(xmlGame, "GEN", DiscType.MegaCD);
- if (!genDiscs.Any())
- {
- return false;
- }
- nextEmulator = new GPGX(nextComm, null, genDiscs, GetCoreSettings(), GetCoreSyncSettings());
- break;
- case "Game Gear":
- var leftBytesGG = xmlGame.Assets.First().Value;
- var rightBytesGG = xmlGame.Assets.Skip(1).First().Value;
+ nextEmulator = new Tst(nextComm, pcfxDiscs,
+ (Tst.Settings)GetCoreSettings(), (Tst.SyncSettings)GetCoreSyncSettings());
+ break;
+ case "GEN":
+ // We are assuming discs only, for now
+ var genDiscs = DiscsFromXml(xmlGame, "GEN", DiscType.MegaCD);
+ if (!genDiscs.Any())
+ {
+ return false;
+ }
+ nextEmulator = new GPGX(nextComm, null, genDiscs, GetCoreSettings(), GetCoreSyncSettings());
+ break;
+ case "Game Gear":
+ var leftBytesGG = xmlGame.Assets.First().Value;
+ var rightBytesGG = xmlGame.Assets.Skip(1).First().Value;
- var leftGG = Database.GetGameInfo(leftBytesGG, "left.gg");
- var rightGG = Database.GetGameInfo(rightBytesGG, "right.gg");
+ var leftGG = Database.GetGameInfo(leftBytesGG, "left.gg");
+ var rightGG = Database.GetGameInfo(rightBytesGG, "right.gg");
- nextEmulator = new GGHawkLink(
+ nextEmulator = new GGHawkLink(
nextComm,
leftGG,
leftBytesGG,
@@ -857,367 +856,366 @@ namespace BizHawk.Client.Common
rightBytesGG,
GetCoreSettings(),
GetCoreSyncSettings());
- break;
- default:
- return false;
+ break;
+ default:
+ return false;
+ }
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ // need to get rid of this hack at some point
+ rom = new RomGame(file);
+ ((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", "")); // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename
+ byte[] romData = null;
+ byte[] xmlData = rom.FileData;
+
+ game = rom.GameInfo;
+ game.System = "SNES";
+
+ var snes = new LibsnesCore(game, romData, xmlData, nextComm, GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator = snes;
+ }
+ catch
+ {
+ DoLoadErrorCallback(ex.ToString(), "DGB", LoadErrorType.Xml);
+ return false;
+ }
+ }
+ }
+ else if (file.Extension.ToLowerInvariant() == ".psf" || file.Extension.ToLowerInvariant() == ".minipsf")
+ {
+ Func cbDeflater = (Stream instream, int size) =>
+ {
+ var inflater = new ICSharpCode.SharpZipLib.Zip.Compression.Inflater(false);
+ var iis = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(instream, inflater);
+ MemoryStream ret = new MemoryStream();
+ iis.CopyTo(ret);
+ return ret.ToArray();
+ };
+ PSF psf = new PSF();
+ psf.Load(path, cbDeflater);
+ nextEmulator = new Octoshock(nextComm, psf, GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator.CoreComm.RomStatusDetails = "It's a PSF, what do you want. Oh, tags maybe?";
+
+ // total garbage, this
+ rom = new RomGame(file);
+ game = rom.GameInfo;
+ }
+ else if (ext != null) // most extensions
+ {
+ rom = new RomGame(file);
+
+ // hacky for now
+ if (file.Extension.ToLowerInvariant() == ".exe")
+ {
+ rom.GameInfo.System = "PSX";
+ }
+ else if (file.Extension.ToLowerInvariant() == ".nsf")
+ {
+ rom.GameInfo.System = "NES";
+ }
+
+ Console.WriteLine(rom.GameInfo.System);
+
+ if (string.IsNullOrEmpty(rom.GameInfo.System))
+ {
+ // Has the user picked a preference for this extension?
+ if (PreferredPlatformIsDefined(rom.Extension.ToLowerInvariant()))
+ {
+ rom.GameInfo.System = Global.Config.PreferredPlatformsForExtensions[rom.Extension.ToLowerInvariant()];
+ }
+ else if (ChoosePlatform != null)
+ {
+ var result = ChoosePlatform(rom);
+ if (!string.IsNullOrEmpty(result))
+ {
+ rom.GameInfo.System = result;
+ }
+ else
+ {
+ cancel = true;
}
}
- catch (Exception ex)
- {
- try
+ }
+
+ game = rom.GameInfo;
+
+ var isXml = false;
+
+ // other xml has already been handled
+ if (file.Extension.ToLowerInvariant() == ".xml")
+ {
+ game.System = "SNES";
+ isXml = true;
+ }
+
+ CoreInventory.Core core = null;
+
+ switch (game.System)
+ {
+ default:
+ core = CoreInventory.Instance[game.System];
+ break;
+
+ case null:
+ // The user picked nothing in the Core picker
+ break;
+ case "83P":
+ var ti83Bios = ((CoreFileProvider)nextComm.CoreFileProvider).GetFirmware("TI83", "Rom", true);
+ var ti83BiosPath = ((CoreFileProvider)nextComm.CoreFileProvider).GetFirmwarePath("TI83", "Rom", true);
+ using (var ti83AsHawkFile = new HawkFile())
+ {
+ ti83AsHawkFile.Open(ti83BiosPath);
+ var ti83BiosAsRom = new RomGame(ti83AsHawkFile);
+ var ti83 = new TI83(nextComm, ti83BiosAsRom.GameInfo, ti83Bios, GetCoreSettings());
+ ti83.LinkPort.SendFileToCalc(File.OpenRead(path), false);
+ nextEmulator = ti83;
+ }
+
+ break;
+ case "SNES":
+ bool useSnes9x = Global.Config.SnesInSnes9x;
+ if (Global.Config.CoreForcingViaGameDb && !string.IsNullOrEmpty(game.ForcedCore))
+ {
+ if (game.ForcedCore.ToLower() == "snes9x")
+ {
+ useSnes9x = true;
+ }
+ else if (game.ForcedCore.ToLower() == "bsnes")
+ {
+ useSnes9x = false;
+ }
+ }
+
+ if (useSnes9x)
+ {
+ core = CoreInventory.Instance["SNES", "Snes9x"];
+ }
+ else
{
// need to get rid of this hack at some point
- rom = new RomGame(file);
((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", "")); // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename
- byte[] romData = null;
- byte[] xmlData = rom.FileData;
-
- game = rom.GameInfo;
- game.System = "SNES";
-
+ var romData = isXml ? null : rom.FileData;
+ var xmlData = isXml ? rom.FileData : null;
var snes = new LibsnesCore(game, romData, xmlData, nextComm, GetCoreSettings(), GetCoreSyncSettings());
nextEmulator = snes;
}
- catch
+
+ break;
+ case "NES":
+ {
+ // apply main spur-of-the-moment switcheroo as lowest priority
+ string preference = "neshawk";
+ if (Global.Config.NesInQuickNes)
{
- DoLoadErrorCallback(ex.ToString(), "DGB", LoadErrorType.Xml);
- return false;
+ preference = "quicknes";
}
- }
- }
- else if (file.Extension.ToLowerInvariant() == ".psf" || file.Extension.ToLowerInvariant() == ".minipsf")
- {
- Func cbDeflater = (Stream instream, int size) =>
- {
- var inflater = new ICSharpCode.SharpZipLib.Zip.Compression.Inflater(false);
- var iis = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(instream, inflater);
- MemoryStream ret = new MemoryStream();
- iis.CopyTo(ret);
- return ret.ToArray();
- };
- PSF psf = new PSF();
- psf.Load(path, cbDeflater);
- nextEmulator = new Octoshock(nextComm, psf, GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator.CoreComm.RomStatusDetails = "It's a PSF, what do you want. Oh, tags maybe?";
- // total garbage, this
- rom = new RomGame(file);
- game = rom.GameInfo;
- }
- else if (ext != null) // most extensions
- {
- rom = new RomGame(file);
-
- // hacky for now
- if (file.Extension.ToLowerInvariant() == ".exe")
- {
- rom.GameInfo.System = "PSX";
- }
- else if (file.Extension.ToLowerInvariant() == ".nsf")
- {
- rom.GameInfo.System = "NES";
- }
-
- Console.WriteLine(rom.GameInfo.System);
-
- if (string.IsNullOrEmpty(rom.GameInfo.System))
- {
- // Has the user picked a preference for this extension?
- if (PreferredPlatformIsDefined(rom.Extension.ToLowerInvariant()))
+ // if user has saw fit to override in gamedb, apply that
+ if (Global.Config.CoreForcingViaGameDb && !string.IsNullOrEmpty(game.ForcedCore))
{
- rom.GameInfo.System = Global.Config.PreferredPlatformsForExtensions[rom.Extension.ToLowerInvariant()];
+ preference = game.ForcedCore;
}
- else if (ChoosePlatform != null)
+
+ // but only neshawk is accurate
+ if (forceAccurateCore)
{
- var result = ChoosePlatform(rom);
- if (!string.IsNullOrEmpty(result))
- {
- rom.GameInfo.System = result;
- }
- else
- {
- cancel = true;
- }
+ preference = "neshawk";
+ }
+
+ if (preference == "neshawk")
+ {
+ core = Global.Config.UseSubNESHawk
+ ? CoreInventory.Instance["NES", "SubNESHawk"]
+ : CoreInventory.Instance["NES", "NesHawk"];
+ }
+ else
+ {
+ core = CoreInventory.Instance["NES", "QuickNes"];
}
}
- game = rom.GameInfo;
+ break;
- var isXml = false;
-
- // other xml has already been handled
- if (file.Extension.ToLowerInvariant() == ".xml")
- {
- game.System = "SNES";
- isXml = true;
- }
-
- CoreInventory.Core core = null;
-
- switch (game.System)
- {
- default:
- core = CoreInventory.Instance[game.System];
- break;
-
- case null:
- // The user picked nothing in the Core picker
- break;
- case "83P":
- var ti83Bios = ((CoreFileProvider)nextComm.CoreFileProvider).GetFirmware("TI83", "Rom", true);
- var ti83BiosPath = ((CoreFileProvider)nextComm.CoreFileProvider).GetFirmwarePath("TI83", "Rom", true);
- using (var ti83AsHawkFile = new HawkFile())
+ case "GB":
+ if (!Global.Config.GbAsSgb)
+ {
+ core = Global.Config.GbUseGbHawk
+ ? CoreInventory.Instance["GB", "GBHawk"]
+ : CoreInventory.Instance["GB", "Gambatte"];
+ }
+ else
+ {
+ if (Global.Config.SgbUseBsnes)
{
- ti83AsHawkFile.Open(ti83BiosPath);
- var ti83BiosAsRom = new RomGame(ti83AsHawkFile);
- var ti83 = new TI83(nextComm, ti83BiosAsRom.GameInfo, ti83Bios, GetCoreSettings());
- ti83.LinkPort.SendFileToCalc(File.OpenRead(path), false);
- nextEmulator = ti83;
- }
-
- break;
- case "SNES":
- bool useSnes9x = Global.Config.SnesInSnes9x;
- if (Global.Config.CoreForcingViaGameDb && !string.IsNullOrEmpty(game.ForcedCore))
- {
- if (game.ForcedCore.ToLower() == "snes9x")
- {
- useSnes9x = true;
- }
- else if (game.ForcedCore.ToLower() == "bsnes")
- {
- useSnes9x = false;
- }
- }
-
- if (useSnes9x)
- {
- core = CoreInventory.Instance["SNES", "Snes9x"];
- }
- else
- {
- // need to get rid of this hack at some point
- ((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", "")); // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename
- var romData = isXml ? null : rom.FileData;
- var xmlData = isXml ? rom.FileData : null;
- var snes = new LibsnesCore(game, romData, xmlData, nextComm, GetCoreSettings(), GetCoreSyncSettings());
+ game.System = "SNES";
+ game.AddOption("SGB");
+ var snes = new LibsnesCore(game, rom.FileData, null, nextComm, GetCoreSettings(), GetCoreSyncSettings());
nextEmulator = snes;
}
-
- break;
- case "NES":
+ else
{
- // apply main spur-of-the-moment switcheroo as lowest priority
- string preference = "neshawk";
- if (Global.Config.NesInQuickNes)
- {
- preference = "quicknes";
- }
-
- // if user has saw fit to override in gamedb, apply that
- if (Global.Config.CoreForcingViaGameDb && !string.IsNullOrEmpty(game.ForcedCore))
- {
- preference = game.ForcedCore;
- }
-
- // but only neshawk is accurate
- if (forceAccurateCore)
- {
- preference = "neshawk";
- }
-
- if (preference == "neshawk")
- {
- core = Global.Config.UseSubNESHawk
- ? CoreInventory.Instance["NES", "SubNESHawk"]
- : CoreInventory.Instance["NES", "NesHawk"];
- }
- else
- {
- core = CoreInventory.Instance["NES", "QuickNes"];
- }
+ core = CoreInventory.Instance["SGB", "SameBoy"];
}
-
- break;
-
- case "GB":
- if (!Global.Config.GbAsSgb)
+ }
+ break;
+ case "GBC":
+ if (!Global.Config.GbAsSgb)
+ {
+ core = Global.Config.GbUseGbHawk
+ ? CoreInventory.Instance["GBC", "GBHawk"]
+ : CoreInventory.Instance["GBC", "Gambatte"];
+ }
+ else
+ {
+ if (Global.Config.SgbUseBsnes)
{
- core = Global.Config.GbUseGbHawk
- ? CoreInventory.Instance["GB", "GBHawk"]
- : CoreInventory.Instance["GB", "Gambatte"];
+ game.System = "SNES";
+ game.AddOption("SGB");
+ var snes = new LibsnesCore(game, rom.FileData, null, nextComm, GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator = snes;
}
else
{
- if (Global.Config.SgbUseBsnes)
- {
- game.System = "SNES";
- game.AddOption("SGB");
- var snes = new LibsnesCore(game, rom.FileData, null, nextComm, GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator = snes;
- }
- else
- {
- core = CoreInventory.Instance["SGB", "SameBoy"];
- }
+ core = CoreInventory.Instance["SGB", "SameBoy"];
}
- break;
- case "GBC":
- if (!Global.Config.GbAsSgb)
- {
- core = Global.Config.GbUseGbHawk
- ? CoreInventory.Instance["GBC", "GBHawk"]
- : CoreInventory.Instance["GBC", "Gambatte"];
- }
- else
- {
- if (Global.Config.SgbUseBsnes)
- {
- game.System = "SNES";
- game.AddOption("SGB");
- var snes = new LibsnesCore(game, rom.FileData, null, nextComm, GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator = snes;
- }
- else
- {
- core = CoreInventory.Instance["SGB", "SameBoy"];
- }
- }
- break;
- case "A78":
- var gameDbPath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb_a7800.csv");
- nextEmulator = new A7800Hawk(nextComm, game, rom.RomData, gameDbPath, GetCoreSettings(), GetCoreSyncSettings());
- break;
- case "C64":
- var c64 = new C64(nextComm, Enumerable.Repeat(rom.FileData, 1), rom.GameInfo, GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator = c64;
- break;
- case "ZXSpectrum":
- var zx = new ZXSpectrum(nextComm,
- Enumerable.Repeat(rom.RomData, 1),
- Enumerable.Repeat(rom.GameInfo, 1).ToList(),
- GetCoreSettings(),
- GetCoreSyncSettings(),
- Deterministic);
- nextEmulator = zx;
- break;
- case "ChannelF":
- nextEmulator = new ChannelF(nextComm, game, rom.FileData, GetCoreSettings(), GetCoreSyncSettings());
- break;
- case "AmstradCPC":
- var cpc = new AmstradCPC(nextComm, Enumerable.Repeat(rom.RomData, 1), Enumerable.Repeat(rom.GameInfo, 1).ToList(), GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator = cpc;
- break;
- case "GBA":
- core = Global.Config.GbaUsemGba
- ? CoreInventory.Instance["GBA", "mGBA"]
- : CoreInventory.Instance["GBA", "VBA-Next"];
- break;
- case "PSX":
- nextEmulator = new Octoshock(nextComm, null, null, rom.FileData, GetCoreSettings(), GetCoreSyncSettings());
- nextEmulator.CoreComm.RomStatusDetails = "PSX etc.";
- break;
- case "Arcade":
- nextEmulator = new MAME(nextComm, file.Directory, file.CanonicalName, GetCoreSyncSettings(), out var gameName);
- rom.GameInfo.Name = gameName;
- break;
- case "GEN":
- if (Global.Config.CoreForcingViaGameDb && game.ForcedCore?.ToLower() == "pico")
- {
- core = CoreInventory.Instance["GEN", "PicoDrive"];
- }
- else
- {
- core = CoreInventory.Instance["GEN", "Genplus-gx"];
- }
-
- break;
- case "32X":
+ }
+ break;
+ case "A78":
+ var gameDbPath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "gamedb_a7800.csv");
+ nextEmulator = new A7800Hawk(nextComm, game, rom.RomData, gameDbPath, GetCoreSettings(), GetCoreSyncSettings());
+ break;
+ case "C64":
+ var c64 = new C64(nextComm, Enumerable.Repeat(rom.FileData, 1), rom.GameInfo, GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator = c64;
+ break;
+ case "ZXSpectrum":
+ var zx = new ZXSpectrum(nextComm,
+ Enumerable.Repeat(rom.RomData, 1),
+ Enumerable.Repeat(rom.GameInfo, 1).ToList(),
+ GetCoreSettings(),
+ GetCoreSyncSettings(),
+ Deterministic);
+ nextEmulator = zx;
+ break;
+ case "ChannelF":
+ nextEmulator = new ChannelF(nextComm, game, rom.FileData, GetCoreSettings(), GetCoreSyncSettings());
+ break;
+ case "AmstradCPC":
+ var cpc = new AmstradCPC(nextComm, Enumerable.Repeat(rom.RomData, 1), Enumerable.Repeat(rom.GameInfo, 1).ToList(), GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator = cpc;
+ break;
+ case "GBA":
+ core = Global.Config.GbaUsemGba
+ ? CoreInventory.Instance["GBA", "mGBA"]
+ : CoreInventory.Instance["GBA", "VBA-Next"];
+ break;
+ case "PSX":
+ nextEmulator = new Octoshock(nextComm, null, null, rom.FileData, GetCoreSettings(), GetCoreSyncSettings());
+ nextEmulator.CoreComm.RomStatusDetails = "PSX etc.";
+ break;
+ case "Arcade":
+ nextEmulator = new MAME(nextComm, file.Directory, file.CanonicalName, GetCoreSyncSettings(), out var gameName);
+ rom.GameInfo.Name = gameName;
+ break;
+ case "GEN":
+ if (Global.Config.CoreForcingViaGameDb && game.ForcedCore?.ToLower() == "pico")
+ {
core = CoreInventory.Instance["GEN", "PicoDrive"];
- break;
- case "VEC":
- core = CoreInventory.Instance["VEC", "VectrexHawk"];
- break;
- case "O2":
- core = CoreInventory.Instance["O2", "O2Hawk"];
- break;
- }
+ }
+ else
+ {
+ core = CoreInventory.Instance["GEN", "Genplus-gx"];
+ }
- if (core != null)
- {
- // use CoreInventory
- nextEmulator = core.Create(nextComm, game, rom.RomData, rom.FileData, Deterministic, GetCoreSettings(core.Type), GetCoreSyncSettings(core.Type));
- }
+ break;
+ case "32X":
+ core = CoreInventory.Instance["GEN", "PicoDrive"];
+ break;
+ case "VEC":
+ core = CoreInventory.Instance["VEC", "VectrexHawk"];
+ break;
+ case "O2":
+ core = CoreInventory.Instance["O2", "O2Hawk"];
+ break;
}
- if (nextEmulator == null)
+ if (core != null)
{
- if (!cancel)
- {
- DoLoadErrorCallback("No core could load the rom.", null);
- }
-
- return false;
+ // use CoreInventory
+ nextEmulator = core.Create(nextComm, game, rom.RomData, rom.FileData, Deterministic, GetCoreSettings(core.Type), GetCoreSyncSettings(core.Type));
}
}
- catch (Exception ex)
+
+ if (nextEmulator == null)
{
- string system = null;
- if (game != null)
+ if (!cancel)
{
- system = game.System;
- }
-
- // all of the specific exceptions we're trying to catch here aren't expected to have inner exceptions,
- // so drill down in case we got a TargetInvocationException or something like that
- while (ex.InnerException != null)
- {
- ex = ex.InnerException;
- }
-
- // Specific hack here, as we get more cores of the same system, this isn't scalable
- if (ex is UnsupportedGameException)
- {
- if (system == "NES")
- {
- DoMessageCallback("Unable to use quicknes, using NESHawk instead");
- }
-
- return LoadRom(path, nextComm, true, recursiveCount + 1);
- }
-
- if (ex is MissingFirmwareException)
- {
- DoLoadErrorCallback(ex.Message, system, path, Deterministic, LoadErrorType.MissingFirmware);
- }
- else if (ex is CGBNotSupportedException)
- {
- // failed to load SGB bios or game does not support SGB mode.
- // To avoid catch-22, disable SGB mode
- Global.Config.GbAsSgb = false;
- DoMessageCallback("Failed to load a GB rom in SGB mode. Disabling SGB Mode.");
- return LoadRom(path, nextComm, false, recursiveCount + 1);
- }
-
- // handle exceptions thrown by the new detected systems that BizHawk does not have cores for
- else if (ex is NoAvailableCoreException)
- {
- DoLoadErrorCallback($"{ex.Message}\n\n{ex}", system);
- }
-
- else
- {
- DoLoadErrorCallback($"A core accepted the rom, but threw an exception while loading it:\n\n{ex}", system);
+ DoLoadErrorCallback("No core could load the rom.", null);
}
return false;
}
-
- Rom = rom;
- LoadedEmulator = nextEmulator;
- Game = game;
- return true;
}
+ catch (Exception ex)
+ {
+ string system = null;
+ if (game != null)
+ {
+ system = game.System;
+ }
+
+ // all of the specific exceptions we're trying to catch here aren't expected to have inner exceptions,
+ // so drill down in case we got a TargetInvocationException or something like that
+ while (ex.InnerException != null)
+ {
+ ex = ex.InnerException;
+ }
+
+ // Specific hack here, as we get more cores of the same system, this isn't scalable
+ if (ex is UnsupportedGameException)
+ {
+ if (system == "NES")
+ {
+ DoMessageCallback("Unable to use quicknes, using NESHawk instead");
+ }
+
+ return LoadRom(path, nextComm, true, recursiveCount + 1);
+ }
+
+ if (ex is MissingFirmwareException)
+ {
+ DoLoadErrorCallback(ex.Message, system, path, Deterministic, LoadErrorType.MissingFirmware);
+ }
+ else if (ex is CGBNotSupportedException)
+ {
+ // failed to load SGB bios or game does not support SGB mode.
+ // To avoid catch-22, disable SGB mode
+ Global.Config.GbAsSgb = false;
+ DoMessageCallback("Failed to load a GB rom in SGB mode. Disabling SGB Mode.");
+ return LoadRom(path, nextComm, false, recursiveCount + 1);
+ }
+
+ // handle exceptions thrown by the new detected systems that BizHawk does not have cores for
+ else if (ex is NoAvailableCoreException)
+ {
+ DoLoadErrorCallback($"{ex.Message}\n\n{ex}", system);
+ }
+
+ else
+ {
+ DoLoadErrorCallback($"A core accepted the rom, but threw an exception while loading it:\n\n{ex}", system);
+ }
+
+ return false;
+ }
+
+ Rom = rom;
+ LoadedEmulator = nextEmulator;
+ Game = game;
+ return true;
}
}
}
diff --git a/BizHawk.Client.Common/SharpCompressArchiveHandler.cs b/BizHawk.Client.Common/SharpCompressArchiveHandler.cs
index 802ac38201..b0340554c1 100644
--- a/BizHawk.Client.Common/SharpCompressArchiveHandler.cs
+++ b/BizHawk.Client.Common/SharpCompressArchiveHandler.cs
@@ -37,21 +37,21 @@ namespace BizHawk.Client.Common
offset = 0;
isExecutable = false;
- var pathExt = Path.GetExtension(fileName).ToLower();
+ var pathExt = Path.GetExtension(fileName)?.ToLower();
if (!ArchiveExtensions.Contains(pathExt))
return false;
try
{
- using (var arcTest = ArchiveFactory.Open(fileName))
- switch (arcTest.Type)
- {
- case ArchiveType.Zip:
- case ArchiveType.SevenZip:
- return true;
- }
+ using var arcTest = ArchiveFactory.Open(fileName);
+ switch (arcTest.Type)
+ {
+ case ArchiveType.Zip:
+ case ArchiveType.SevenZip:
+ return true;
+ }
}
- catch (Exception _)
+ catch (Exception)
{
// ignored
}
@@ -80,8 +80,8 @@ namespace BizHawk.Client.Common
public void ExtractFile(int index, Stream stream)
{
- using (var entryStream = _archive.Entries.Where(e => !e.IsDirectory).ElementAt(index).OpenEntryStream())
- entryStream.CopyTo(stream);
+ using var entryStream = _archive.Entries.Where(e => !e.IsDirectory).ElementAt(index).OpenEntryStream();
+ entryStream.CopyTo(stream);
}
}
}
\ No newline at end of file
diff --git a/BizHawk.Client.Common/config/ConfigService.cs b/BizHawk.Client.Common/config/ConfigService.cs
index ebea720774..b47b0fecd9 100644
--- a/BizHawk.Client.Common/config/ConfigService.cs
+++ b/BizHawk.Client.Common/config/ConfigService.cs
@@ -40,11 +40,9 @@ namespace BizHawk.Client.Common
var file = new FileInfo(filepath);
if (file.Exists)
{
- using (var reader = file.OpenText())
- {
- var r = new JsonTextReader(reader);
- config = (T)Serializer.Deserialize(r, typeof(T));
- }
+ using var reader = file.OpenText();
+ var r = new JsonTextReader(reader);
+ config = (T)Serializer.Deserialize(r, typeof(T));
}
}
catch (Exception ex)
@@ -65,11 +63,9 @@ namespace BizHawk.Client.Common
var file = new FileInfo(filepath);
try
{
- using (var writer = file.CreateText())
- {
- var w = new JsonTextWriter(writer) { Formatting = Formatting.Indented };
- Serializer.Serialize(w, config);
- }
+ using var writer = file.CreateText();
+ var w = new JsonTextWriter(writer) { Formatting = Formatting.Indented };
+ Serializer.Serialize(w, config);
}
catch
{
@@ -85,27 +81,23 @@ namespace BizHawk.Client.Common
public static object LoadWithType(string serialized)
{
- using (TextReader tr = new StringReader(serialized))
- using (JsonTextReader jr = new JsonTextReader(tr))
- {
- TypeNameEncapsulator tne = (TypeNameEncapsulator)Serializer.Deserialize(jr, typeof(TypeNameEncapsulator));
+ using TextReader tr = new StringReader(serialized);
+ using JsonTextReader jr = new JsonTextReader(tr);
+ TypeNameEncapsulator tne = (TypeNameEncapsulator)Serializer.Deserialize(jr, typeof(TypeNameEncapsulator));
- // in the case of trying to deserialize nothing, tne will be nothing
- // we want to return nothing
- return tne?.o;
- }
+ // in the case of trying to deserialize nothing, tne will be nothing
+ // we want to return nothing
+ return tne?.o;
}
public static string SaveWithType(object o)
{
- using (StringWriter sw = new StringWriter())
- using (JsonTextWriter jw = new JsonTextWriter(sw) { Formatting = Formatting.None })
- {
- TypeNameEncapsulator tne = new TypeNameEncapsulator { o = o };
- Serializer.Serialize(jw, tne, typeof(TypeNameEncapsulator));
- sw.Flush();
- return sw.ToString();
- }
+ using StringWriter sw = new StringWriter();
+ using JsonTextWriter jw = new JsonTextWriter(sw) { Formatting = Formatting.None };
+ TypeNameEncapsulator tne = new TypeNameEncapsulator { o = o };
+ Serializer.Serialize(jw, tne, typeof(TypeNameEncapsulator));
+ sw.Flush();
+ return sw.ToString();
}
}
}
diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Genesis.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Genesis.cs
index 724d88fa4e..8a6cab3f4b 100644
--- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Genesis.cs
+++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Genesis.cs
@@ -2,8 +2,6 @@
using System.ComponentModel;
using NLua;
-
-using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Sega.gpgx;
// ReSharper disable UnusedMember.Global
diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.MemorySavestate.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.MemorySavestate.cs
index df61af309d..f856e3e748 100644
--- a/BizHawk.Client.Common/lua/EmuLuaLibrary.MemorySavestate.cs
+++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.MemorySavestate.cs
@@ -1,11 +1,6 @@
using System;
-using System.Collections.Generic;
-using System.IO;
-
using NLua;
-using BizHawk.Emulation.Common;
-
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedAutoPropertyAccessor.Local
namespace BizHawk.Client.Common
diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs
index d2e74e55db..5a3a4a3475 100644
--- a/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs
+++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.UserData.cs
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using NLua;
-using BizHawk.Client.Common;
// ReSharper disable UnusedMember.Global
namespace BizHawk.Client.Common
diff --git a/BizHawk.Client.Common/lua/LuaSandbox.cs b/BizHawk.Client.Common/lua/LuaSandbox.cs
index 315360d3ee..e366027e59 100644
--- a/BizHawk.Client.Common/lua/LuaSandbox.cs
+++ b/BizHawk.Client.Common/lua/LuaSandbox.cs
@@ -1,6 +1,4 @@
using System;
-using System.Runtime.InteropServices;
-
using BizHawk.Common;
using NLua;
diff --git a/BizHawk.Client.Common/miniz/LibMiniz.cs b/BizHawk.Client.Common/miniz/LibMiniz.cs
index 106d3a5444..201a5f58d5 100644
--- a/BizHawk.Client.Common/miniz/LibMiniz.cs
+++ b/BizHawk.Client.Common/miniz/LibMiniz.cs
@@ -1,9 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
namespace BizHawk.Client.Common.Miniz
{
diff --git a/BizHawk.Client.Common/miniz/MinizZipWriter.cs b/BizHawk.Client.Common/miniz/MinizZipWriter.cs
index 9b999f25c7..938b16128a 100644
--- a/BizHawk.Client.Common/miniz/MinizZipWriter.cs
+++ b/BizHawk.Client.Common/miniz/MinizZipWriter.cs
@@ -1,10 +1,6 @@
using System;
-using System.Collections.Generic;
using System.IO;
-using System.Linq;
using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
namespace BizHawk.Client.Common.Miniz
{
diff --git a/BizHawk.Client.Common/movie/import/BkmImport.cs b/BizHawk.Client.Common/movie/import/BkmImport.cs
index 8c51cf7ea4..6d28194619 100644
--- a/BizHawk.Client.Common/movie/import/BkmImport.cs
+++ b/BizHawk.Client.Common/movie/import/BkmImport.cs
@@ -1,6 +1,4 @@
-using BizHawk.Client.Common.MovieConversionExtensions;
-
-namespace BizHawk.Client.Common.movie.import
+namespace BizHawk.Client.Common.movie.import
{
// ReSharper disable once UnusedMember.Global
[ImporterFor("BizHawk", ".bkm")]
diff --git a/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs b/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs
index 4421b81251..6ff8155b74 100644
--- a/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs
+++ b/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs
@@ -15,8 +15,7 @@ namespace BizHawk.Client.Common
{
get
{
- bool lag;
- var result = _lagLog.TryGetValue(frame, out lag);
+ var result = _lagLog.TryGetValue(frame, out var lag);
if (result)
{
return lag;
diff --git a/BizHawk.Client.Common/tools/Watch/Watch.cs b/BizHawk.Client.Common/tools/Watch/Watch.cs
index b70b7707a8..b5b3348a0d 100644
--- a/BizHawk.Client.Common/tools/Watch/Watch.cs
+++ b/BizHawk.Client.Common/tools/Watch/Watch.cs
@@ -100,9 +100,7 @@ namespace BizHawk.Client.Common
return null;
}
- long address;
-
- if (long.TryParse(parts[0], NumberStyles.HexNumber, CultureInfo.CurrentCulture, out address))
+ if (long.TryParse(parts[0], NumberStyles.HexNumber, CultureInfo.CurrentCulture, out var address))
{
WatchSize size = SizeFromChar(parts[1][0]);
DisplayType type = DisplayTypeFromChar(parts[2][0]);
diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings
index 7272d47f55..a1a212884c 100644
--- a/BizHawk.sln.DotSettings
+++ b/BizHawk.sln.DotSettings
@@ -265,6 +265,7 @@
True
True
True
+ True
True
True
True