From dcc9da3f5e5d31180d7deff243df252bd8a42c33 Mon Sep 17 00:00:00 2001
From: Connor McLaughlin <stenzek@gmail.com>
Date: Sun, 16 Feb 2020 00:15:09 +0900
Subject: [PATCH] HostInterface: Don't try to resume system without game code

---
 src/core/host_interface.cpp | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp
index 652b5ca84..8cacd8c08 100644
--- a/src/core/host_interface.cpp
+++ b/src/core/host_interface.cpp
@@ -487,23 +487,34 @@ bool HostInterface::ResumeSystemFromState(const char* filename, bool boot_on_fai
     return false;
 
   const bool global = m_system->GetRunningCode().empty();
-  const std::string path =
-    global ? GetGlobalSaveStateFileName(-1) : GetGameSaveStateFileName(m_system->GetRunningCode().c_str(), -1);
-  if (FileSystem::FileExists(path.c_str()))
+  if (m_system->GetRunningCode().empty())
   {
-    if (!LoadState(path.c_str()) && !boot_on_failure)
+    ReportFormattedError("Cannot resume system with undetectable game code from '%s'.", filename);
+    if (!boot_on_failure)
     {
       DestroySystem();
+      return true;
+    }
+  }
+  else
+  {
+    const std::string path = GetGameSaveStateFileName(m_system->GetRunningCode().c_str(), -1);
+    if (FileSystem::FileExists(path.c_str()))
+    {
+      if (!LoadState(path.c_str()) && !boot_on_failure)
+      {
+        DestroySystem();
+        return false;
+      }
+    }
+    else if (!boot_on_failure)
+    {
+      ReportFormattedError("Resume save state not found for '%s' ('%s').", m_system->GetRunningCode().c_str(),
+                           m_system->GetRunningTitle().c_str());
+      DestroySystem();
       return false;
     }
   }
-  else if (!boot_on_failure)
-  {
-    ReportFormattedError("Resume save state not found for '%s' ('%s').", m_system->GetRunningCode().c_str(),
-                         m_system->GetRunningTitle().c_str());
-    DestroySystem();
-    return false;
-  }
 
   return true;
 }