const ADGameDescription *SciMetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { bool foundResMap = false; bool foundRes000 = false; // Set some defaults s_fallbackDesc.extra = ""; s_fallbackDesc.language = Common::EN_ANY; s_fallbackDesc.flags = ADGF_NO_FLAGS; s_fallbackDesc.platform = Common::kPlatformPC; // default to PC platform s_fallbackDesc.gameid = "sci"; s_fallbackDesc.guioptions = GUIO3(GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_FB01_MIDI); if (allFiles.contains("resource.map") || allFiles.contains("Data1") || allFiles.contains("resmap.001") || allFiles.contains("resmap.001")) { foundResMap = true; } // Determine if we got a CD version and set the CD flag accordingly, by checking for // resource.aud for SCI1.1 CD games, or audio001.002 for SCI1 CD games. We assume that // the file should be over 10MB, as it contains all the game speech and is usually // around 450MB+. The size check is for some floppy game versions like KQ6 floppy, which // also have a small resource.aud file if (allFiles.contains("resource.aud") || allFiles.contains("audio001.002")) { Common::FSNode file = allFiles.contains("resource.aud") ? allFiles["resource.aud"] : allFiles["audio001.002"]; Common::SeekableReadStream *tmpStream = file.createReadStream(); if (tmpStream->size() > 10 * 1024 * 1024) { // We got a CD version, so set the CD flag accordingly s_fallbackDesc.flags |= ADGF_CD; } delete tmpStream; } if (allFiles.contains("resource.000") || allFiles.contains("resource.001") || allFiles.contains("ressci.000") || allFiles.contains("ressci.001")) foundRes000 = true; // Data1 contains both map and volume for SCI1.1+ Mac games if (allFiles.contains("Data1")) { foundResMap = foundRes000 = true; s_fallbackDesc.platform = Common::kPlatformMacintosh; } // Determine the game platform // The existence of any of these files indicates an Amiga game if (allFiles.contains("9.pat") || allFiles.contains("spal") || allFiles.contains("patch.005") || allFiles.contains("bank.001")) s_fallbackDesc.platform = Common::kPlatformAmiga; // The existence of 7.pat or patch.200 indicates a Mac game if (allFiles.contains("7.pat") || allFiles.contains("patch.200")) s_fallbackDesc.platform = Common::kPlatformMacintosh; // The data files for Atari ST versions are the same as their DOS counterparts // If these files aren't found, it can't be SCI if (!foundResMap && !foundRes000) { return 0; } ResourceManager resMan; resMan.addAppropriateSources(fslist); resMan.init(true); // TODO: Add error handling. #ifndef ENABLE_SCI32 // Is SCI32 compiled in? If not, and this is a SCI32 game, // stop here if (getSciVersion() >= SCI_VERSION_2) { return (const ADGameDescription *)&s_fallbackDesc; } #endif ViewType gameViews = resMan.getViewType(); // Have we identified the game views? If not, stop here // Can't be SCI (or unsupported SCI views). Pinball Creep by sierra also uses resource.map/resource.000 files // but doesnt share sci format at all, if we dont return 0 here we will detect this game as SCI if (gameViews == kViewUnknown) { return 0; } // Set the platform to Amiga if the game is using Amiga views if (gameViews == kViewAmiga) s_fallbackDesc.platform = Common::kPlatformAmiga; // Determine the game id Common::String sierraGameId = resMan.findSierraGameId(); // If we don't have a game id, the game is not SCI if (sierraGameId.empty()) { return 0; } Common::String gameId = convertSierraGameId(sierraGameId, &s_fallbackDesc.flags, resMan); strncpy(s_fallbackGameIdBuf, gameId.c_str(), sizeof(s_fallbackGameIdBuf) - 1); s_fallbackGameIdBuf[sizeof(s_fallbackGameIdBuf) - 1] = 0; // Make sure string is NULL terminated s_fallbackDesc.gameid = s_fallbackGameIdBuf; // Try to determine the game language // Load up text 0 and start looking for "#" characters // Non-English versions contain strings like XXXX#YZZZZ // Where XXXX is the English string, #Y a separator indicating the language // (e.g. #G for German) and ZZZZ is the translated text // NOTE: This doesn't work for games which use message instead of text resources // (like, for example, Eco Quest 1 and all SCI1.1 games and newer, e.g. Freddy Pharkas). // As far as we know, these games store the messages of each language in separate // resources, and it's not possible to detect that easily // Also look for "%J" which is used in japanese games Resource *text = resMan.findResource(ResourceId(kResourceTypeText, 0), 0); uint seeker = 0; if (text) { while (seeker < text->size) { if (text->data[seeker] == '#') { if (seeker + 1 < text->size) s_fallbackDesc.language = charToScummVMLanguage(text->data[seeker + 1]); break; } if (text->data[seeker] == '%') { if ((seeker + 1 < text->size) && (text->data[seeker + 1] == 'J')) { s_fallbackDesc.language = charToScummVMLanguage(text->data[seeker + 1]); break; } } seeker++; } } // Fill in "extra" field // Is this an EGA version that might have a VGA pendant? Then we want // to mark it as such in the "extra" field. const bool markAsEGA = (gameViews == kViewEga && s_fallbackDesc.platform != Common::kPlatformAmiga && getSciVersion() > SCI_VERSION_1_EGA_ONLY); const bool isDemo = (s_fallbackDesc.flags & ADGF_DEMO); const bool isCD = (s_fallbackDesc.flags & ADGF_CD); if (!isCD) s_fallbackDesc.guioptions = GUIO4(GUIO_NOSPEECH, GAMEOPTION_PREFER_DIGITAL_SFX, GAMEOPTION_ORIGINAL_SAVELOAD, GAMEOPTION_FB01_MIDI); if (gameId.hasSuffix("sci")) { s_fallbackDesc.extra = "SCI"; // Differentiate EGA versions from the VGA ones, where needed if (markAsEGA) s_fallbackDesc.extra = "SCI/EGA"; // Mark as demo. // Note: This overwrites the 'EGA' info, if it was previously set. if (isDemo) s_fallbackDesc.extra = "SCI/Demo"; } else { if (markAsEGA) s_fallbackDesc.extra = "EGA"; // Set "CD" and "Demo" as appropriate. // Note: This overwrites the 'EGA' info, if it was previously set. if (isDemo && isCD) s_fallbackDesc.extra = "CD Demo"; else if (isDemo) s_fallbackDesc.extra = "Demo"; else if (isCD) s_fallbackDesc.extra = "CD"; } return &s_fallbackDesc; }
int run_haggle() { #ifdef ENABLE_DEBUG_MANAGER DebugManager *db = NULL; #endif ApplicationManager *am = NULL; DataManager *dm = NULL; NodeManager *nm = NULL; ProtocolManager *pm = NULL; ForwardingManager *fm = NULL; SecurityManager *sm = NULL; ConnectivityManager *cm = NULL; #ifdef BENCHMARK BenchmarkManager *bm = NULL; //recreateDataStore = true; #endif ResourceManager *rm = NULL; ProtocolSocket *p = NULL; #ifdef OS_WINDOWS_MOBILE // For testing we force the deletion of the data store //recreateDataStore = true; #endif int retval = EXIT_FAILURE; if (!create_path(HAGGLE_DEFAULT_STORAGE_PATH)) { HAGGLE_ERR("Could not create Haggle storage path : %s\n", HAGGLE_DEFAULT_STORAGE_PATH); return -1; } retval = write_pid_file(getpid()); if (retval != HAGGLE_PROCESS_NO_ERROR) { switch (retval) { case HAGGLE_PROCESS_BAD_PID: HAGGLE_ERR("Cannot read PID file %s.\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_CANNOT_WRITE_PID: HAGGLE_ERR("Cannot write PID file %s\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_ALREADY_RUNNING: HAGGLE_ERR("PID file %s indicates that Haggle is already running.\n", PID_FILE.c_str()); break; default: HAGGLE_ERR("Unknown PID file error\n"); } shouldCleanupPidFile = false; return -1; } #if defined(OS_UNIX) && !defined(OS_ANDROID) setrawtty(); #endif /* Seed the random number generator */ prng_init(); kernel = new HaggleKernel(new SQLDataStore(recreateDataStore)); if (!kernel || !kernel->init()) { fprintf(stderr, "Kernel initialization error!\n"); return -1; } // Build a Haggle configuration am = new ApplicationManager(kernel); if (!am || !am->init()) { HAGGLE_ERR("Could not initialize application manager\n"); goto finish; } dm = new DataManager(kernel, setCreateTimeOnBloomfilterUpdate); if (!dm || !dm->init()) { HAGGLE_ERR("Could not initialize data manager\n"); goto finish; } nm = new NodeManager(kernel); if (!nm || !nm->init()) { HAGGLE_ERR("Could not initialize node manager\n"); goto finish; } pm = new ProtocolManager(kernel); if (!pm || !pm->init()) { HAGGLE_ERR("Could not initialize protocol manager\n"); goto finish; } fm = new ForwardingManager(kernel); if (!fm || !fm->init()) { HAGGLE_ERR("Could not initialize forwarding manager\n"); goto finish; } sm = new SecurityManager(kernel, securityLevel); if (!sm || !sm->init()) { HAGGLE_ERR("Could not initialize security manager\n"); goto finish; } #ifdef USE_UNIX_APPLICATION_SOCKET p = new ProtocolLOCAL(kernel->getStoragePath() + "/" + HAGGLE_LOCAL_SOCKET, pm); if (!p || !p->init()) { HAGGLE_ERR("Could not initialize LOCAL protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); #endif p = new ProtocolUDP("127.0.0.1", HAGGLE_SERVICE_DEFAULT_PORT, pm); /* Add ConnectivityManager last since it will start to * discover interfaces and generate events. At that * point the other managers should already be * running. */ if (!p || !p->init()) { HAGGLE_ERR("Could not initialize UDP Application protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); rm = new ResourceManager(kernel); if (!rm || !rm->init()) { HAGGLE_ERR("Could not initialize resource manager\n"); goto finish; } #ifdef BENCHMARK if (!isBenchmarking) { #endif cm = new ConnectivityManager(kernel); if (!cm || !cm->init()) { HAGGLE_ERR("Could not initialize connectivity manager\n"); goto finish; } #ifdef BENCHMARK } else { bm = new BenchmarkManager(kernel, Benchmark_DataObjects_Attr, Benchmark_Nodes_Attr, Benchmark_Attr_Num, Benchmark_DataObjects_Num, Benchmark_Test_Num); if (!bm || !bm->init()) { HAGGLE_ERR("Could not initialize benchmark manager\n"); goto finish; } } #endif #if defined(ENABLE_DEBUG_MANAGER) // It seems as if there can be only one accept() per // thread... we need to make the DebugManager register // protocol or something with the ProtocolTCPServer // somehow db = new DebugManager(kernel, runAsInteractive); if (!db || !db->init()) { HAGGLE_ERR("Could not initialize debug manager\n"); /* Treat as non critical error. */ } #endif HAGGLE_DBG("Starting Haggle...\n"); #ifdef OS_WINDOWS_MOBILE if (platform_type(current_platform()) == platform_windows_mobile_professional) tray_notification_add(g_hInstance, kernel); #endif kernel->run(); retval = EXIT_SUCCESS; HAGGLE_DBG("Haggle finished...\n"); finish: #ifdef BENCHMARK if (bm) delete bm; #endif if (cm) delete cm; if (sm) delete sm; if (fm) delete fm; if (pm) delete pm; if (nm) delete nm; if (dm) delete dm; if (am) delete am; #if defined(ENABLE_DEBUG_MANAGER) if (db) delete db; #endif if (rm) delete rm; #ifdef OS_WINDOWS_MOBILE tray_notification_remove(); #endif delete kernel; kernel = NULL; return retval; }