static void ListPluginType( _In_ PLUGIN_TYPE const *type ) { HANDLE dir = NULL; WIN32_FIND_DATA fileData = { 0 }; TCHAR path[MAX_PATH] = { 0 }; size_t size = 0; DWORD count = 0; LPTSTR ext = NULL; PLUGIN_HEAD plugin = { 0 }; LOG(Bypass, _T("Plugins of type <%s> :"), type->name); PLUGIN_SET_TYPE(&plugin, type); size = _stprintf_s(path, _countof(path), "%s/*.%s", type->directory, PLUGINS_FILE_EXTENSION); if (size == -1) { FATAL(_T("Cannot construct path for plugin type <%s> (directory is <%s>)"), type->name, type->directory); } dir = FindFirstFile(path, &fileData); if (dir == INVALID_HANDLE_VALUE) { if (GetLastError() == ERROR_FILE_NOT_FOUND) { LOG(Succ, SUB_LOG(_T("None"))); return; } else { FATAL(_T("Cannot open path <%s> to list <%s> : <%u>"), path, type->name, GetLastError()); } } do { if (!(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { ext = _tcsrchr(fileData.cFileName, '.'); if (ext) { *ext = '\0'; PLUGIN_SET_NAME(&plugin, fileData.cFileName); PluginLoadGenericSingle(&plugin); LOG(Bypass, SUB_LOG(_T("[%s] %s : %s")), plugin.vars.keyword, plugin.name, PLUGIN_GET_DESCRIPTION(&plugin)); PluginUnload(&plugin); count++; } } } while (FindNextFile(dir, &fileData)); LOG(Bypass, SUB_LOG(_T("Count : %u\r\n")), count); FindClose(dir); }
int main(int argc, char *argv[]) { int i; printf(" __ __ __ _ _ ____ _ \n"); printf("| \\/ |_ _ _ __ ___ _ __ / /_ | || | | _ \\| |_ _ ___ \n"); printf("| |\\/| | | | | '_ \\ / _ \\ '_ \\| '_ \\| || |_| |_) | | | | / __| \n"); printf("| | | | |_| | |_) | __/ | | | (_) |__ _| __/| | |_| \\__ \\ \n"); printf("|_| |_|\\__,_| .__/ \\___|_| |_|\\___/ |_| |_| |_|\\__,_|___/ \n"); printf(" |_| http://code.google.com/p/mupen64plus/ \n"); printf("%s Version %i.%i.%i\n\n", CONSOLE_UI_NAME, VERSION_PRINTF_SPLIT(CONSOLE_UI_VERSION)); /* bootstrap some special parameters from the command line */ if (ParseCommandLineInitial(argc, (const char **) argv) != 0) return 1; /* load the Mupen64Plus core library */ if (AttachCoreLib(l_CoreLibPath) != M64ERR_SUCCESS) return 2; /* start the Mupen64Plus core library, load the configuration file */ m64p_error rval = (*CoreStartup)(CORE_API_VERSION, l_ConfigDirPath, l_DataDirPath, "Core", DebugCallback, NULL, CALLBACK_FUNC); if (rval != M64ERR_SUCCESS) { DebugMessage(M64MSG_ERROR, "couldn't start Mupen64Plus core library."); DetachCoreLib(); return 3; } /* Open configuration sections */ rval = OpenConfigurationHandles(); if (rval != M64ERR_SUCCESS) { (*CoreShutdown)(); DetachCoreLib(); return 4; } /* parse command-line options */ rval = ParseCommandLineFinal(argc, (const char **) argv); if (rval != M64ERR_SUCCESS) { (*CoreShutdown)(); DetachCoreLib(); return 5; } /* Handle the core comparison feature */ if (l_CoreCompareMode != 0 && !(g_CoreCapabilities & M64CAPS_CORE_COMPARE)) { DebugMessage(M64MSG_ERROR, "can't use --core-compare feature with this Mupen64Plus core library."); DetachCoreLib(); return 6; } compare_core_init(l_CoreCompareMode); /* save the given command-line options in configuration file if requested */ if (l_SaveOptions) SaveConfigurationOptions(); /* load ROM image */ FILE *fPtr = fopen(l_ROMFilepath, "rb"); if (fPtr == NULL) { DebugMessage(M64MSG_ERROR, "couldn't open ROM file '%s' for reading.", l_ROMFilepath); (*CoreShutdown)(); DetachCoreLib(); return 7; } /* get the length of the ROM, allocate memory buffer, load it from disk */ long romlength = 0; fseek(fPtr, 0L, SEEK_END); romlength = ftell(fPtr); fseek(fPtr, 0L, SEEK_SET); unsigned char *ROM_buffer = (unsigned char *) malloc(romlength); if (ROM_buffer == NULL) { DebugMessage(M64MSG_ERROR, "couldn't allocate %li-byte buffer for ROM image file '%s'.", romlength, l_ROMFilepath); fclose(fPtr); (*CoreShutdown)(); DetachCoreLib(); return 8; } else if (fread(ROM_buffer, 1, romlength, fPtr) != romlength) { DebugMessage(M64MSG_ERROR, "couldn't read %li bytes from ROM image file '%s'.", romlength, l_ROMFilepath); free(ROM_buffer); fclose(fPtr); (*CoreShutdown)(); DetachCoreLib(); return 9; } fclose(fPtr); /* Try to load the ROM image into the core */ if ((*CoreDoCommand)(M64CMD_ROM_OPEN, (int) romlength, ROM_buffer) != M64ERR_SUCCESS) { DebugMessage(M64MSG_ERROR, "core failed to open ROM image file '%s'.", l_ROMFilepath); free(ROM_buffer); (*CoreShutdown)(); DetachCoreLib(); return 10; } free(ROM_buffer); /* the core copies the ROM image, so we can release this buffer immediately */ /* handle the cheat codes */ CheatStart(l_CheatMode, l_CheatNumList); if (l_CheatMode == CHEAT_SHOW_LIST) { (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); (*CoreShutdown)(); DetachCoreLib(); return 11; } /* search for and load plugins */ rval = PluginSearchLoad(l_ConfigUI); if (rval != M64ERR_SUCCESS) { (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); (*CoreShutdown)(); DetachCoreLib(); return 12; } /* attach plugins to core */ for (i = 0; i < 4; i++) { if ((*CoreAttachPlugin)(g_PluginMap[i].type, g_PluginMap[i].handle) != M64ERR_SUCCESS) { DebugMessage(M64MSG_ERROR, "core error while attaching %s plugin.", g_PluginMap[i].name); (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); (*CoreShutdown)(); DetachCoreLib(); return 13; } } /* set up Frame Callback if --testshots or --savestate is enabled */ if (l_TestShotList != NULL || l_SaveStatePath != NULL) { if ((*CoreDoCommand)(M64CMD_SET_FRAME_CALLBACK, 0, FrameCallback) != M64ERR_SUCCESS) { DebugMessage(M64MSG_WARNING, "couldn't set frame callback, --testshots and/or --savestate will not work."); } } /* run the game */ (*CoreDoCommand)(M64CMD_EXECUTE, 0, NULL); /* detach plugins from core and unload them */ for (i = 0; i < 4; i++) (*CoreDetachPlugin)(g_PluginMap[i].type); PluginUnload(); /* close the ROM image */ (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); /* save the configuration file again if --nosaveoptions was not specified, to keep any updated parameters from the core/plugins */ if (l_SaveOptions) SaveConfigurationOptions(); /* Shut down and release the Core library */ (*CoreShutdown)(); DetachCoreLib(); /* free allocated memory */ if (l_TestShotList != NULL) free(l_TestShotList); return 0; }
int main(int argc, char** argv) { const unsigned short PORT = 8888; Selector selector; #if defined(HAVE_POSIX) Listener unixListener; #endif Listener inetListener; char sockfileBuf[MAX_PATH_SIZE]; #if defined(ENABLE_PIDFILE) int pidfile; char pidfileBuf[MAX_PATH_SIZE]; #endif /* defined(ENABLE_PIDFILE) */ arg0 = argv[0]; ErrSetArg0(arg0); /* Set the default options */ memset(&g_options, 0, sizeof(Options)); g_options.sockfile = MakePath(ID_SOCKFILE, sockfileBuf); g_options.port = PORT; /* Set the default options */ #if defined(ENABLE_ROLES) /* Load roles.conf */ { char buf[MAX_PATH_SIZE]; char err[128]; if (RolesLoad(MakePath(ID_ROLES_CONF, buf), err, sizeof(err)) != 0) Err("%s", err); } #endif /* defined(ENABLE_ROLES) */ /* Set the default options */ /* Process the configuration file before the command-line options */ _GetConfFileOptions(); /* Get command line options */ _GetOptions(&g_options, &argc, argv); /* Dump the paths? */ if (g_options.paths) { DumpPaths(); exit(0); } /* Dump the roles */ if (g_options.roles) { RoleDump(); exit(0); } #if defined(ENABLE_PAM_AUTH) /* Check that the PAM plugin is installed */ if (access("/etc/pam.d/phit", R_OK) != 0) { fprintf(stderr, "%s: /etc/pam.d/phit not found\n\n", arg0); exit(1); } #endif /* Stop the server? */ if (g_options.stop) { #if defined(ENABLE_PIDFILE) _StopServer(); #else Err("use kill (-s option is diabled)"); #endif /* defined(ENABLE_PIDFILE) */ } /* Check arguments */ if (argc != 1) { fprintf(stderr, "Use -h for help\n"); exit(1); } #if defined(ENABLE_PIDFILE) /* Bail out if server is already running */ if (PIDFileIsRunning() == 0) { Err("already running: %s", MakePath(ID_PIDFILE, pidfileBuf)); } #endif /* defined(ENABLE_PIDFILE) */ /* Load the plugins file */ { char error[128]; if (PluginLoad(error, PHIT_ARRAY_SIZE(error)) != 0) Err("%s", error); } /* Initialize the selector */ SelectorInit(&selector); /* Handle SIGTERM */ signal(SIGTERM, _HandleSIGTERM); /* Ignore SIGPIPE */ #if defined(HAVE_POSIX) signal(SIGPIPE, SIG_IGN); #endif /* Initialize the sockets layer */ { int r = SockStart(); (void)r; DEBUG_ASSERT(r == 0); } #if defined(HAVE_POSIX) /* Create listener for Unix-domain sockets */ if (ListenerInit(&unixListener, &selector, g_options.sockfile, 0) != 0) { char buf[MAX_PATH_SIZE]; Err("listen failed (uds): %s", MakePath(ID_SOCKFILE, buf)); } #endif /* defined(HAVE_POSIX) */ /* Create listener for internet sockets */ if (ListenerInit(&inetListener, &selector, NULL, g_options.port) != 0) { Err("listen failed (inet): port %u", g_options.port); } /* Daemonize */ #if defined(HAVE_POSIX) if (!g_options.nodaemonize) ProcessDaemonize(); #endif #if defined(ENABLE_PIDFILE) /* Create PID file (after daemonize) */ if ((pidfile = PIDFileCreate()) == -1) { Err("failed to create %s", MakePath(ID_PIDFILE, pidfileBuf)); } #endif /* defined(ENABLE_PIDFILE) */ /* Run the selector */ while (!_terminated) { SelectorRun(&selector, 1, 0); } /* Unload the plugins */ PluginUnload(); /* Close and delete the PID file */ #if defined(ENABLE_PIDFILE) { close(pidfile); if (PIDFileDelete() != 0) { Err("delete failed: %s\n", MakePath(ID_PIDFILE, pidfileBuf)); } } #endif /* defined(ENABLE_PIDFILE) */ /* Release the selector (and any surviving handlers) */ SelectorDestroy(&selector); /* Remove the socket file */ #if defined(ENABLE_EXEC_PROVIDERS) unlink(MakePath(ID_SOCKFILE, sockfileBuf)); #endif /* Shutdown the sockets layer */ SockStop(); LOGI(("Terminated")); /* Call all cleanup handlers */ Cleanup(); #if defined(ENABLE_ALLOCATOR) /* Print allocation statistics */ AllocPrintStatsAssert(); #endif #if defined(ENABLE_SOCKTRACE) printf("Bytes sent: %llu\n", SockGetBytesSent()); printf("Bytes recv: %llu\n", SockGetBytesRecv()); #endif /* ENABLE_SOCKTRACE */ return 0; }
int main(int argc, char *argv[]) { int i; printf(" __ __ __ _ _ ____ _ \n"); printf("| \\/ |_ _ _ __ ___ _ __ / /_ | || | | _ \\| |_ _ ___ \n"); printf("| |\\/| | | | | '_ \\ / _ \\ '_ \\| '_ \\| || |_| |_) | | | | / __| \n"); printf("| | | | |_| | |_) | __/ | | | (_) |__ _| __/| | |_| \\__ \\ \n"); printf("|_| |_|\\__,_| .__/ \\___|_| |_|\\___/ |_| |_| |_|\\__,_|___/ \n"); printf(" |_| https://mupen64plus.org/ \n"); printf("%s Version %i.%i.%i\n\n", CONSOLE_UI_NAME, VERSION_PRINTF_SPLIT(CONSOLE_UI_VERSION)); /* bootstrap some special parameters from the command line */ if (ParseCommandLineInitial(argc, (const char **) argv) != 0) return 1; /* load the Mupen64Plus core library */ if (AttachCoreLib(l_CoreLibPath) != M64ERR_SUCCESS) return 2; /* start the Mupen64Plus core library, load the configuration file */ m64p_error rval = (*CoreStartup)(CORE_API_VERSION, l_ConfigDirPath, l_DataDirPath, "Core", DebugCallback, NULL, CALLBACK_FUNC); if (rval != M64ERR_SUCCESS) { DebugMessage(M64MSG_ERROR, "couldn't start Mupen64Plus core library."); DetachCoreLib(); return 3; } #ifdef VIDEXT_HEADER rval = CoreOverrideVidExt(&vidExtFunctions); if (rval != M64ERR_SUCCESS) { DebugMessage(M64MSG_ERROR, "couldn't start VidExt library."); DetachCoreLib(); return 14; } #endif /* Open configuration sections */ rval = OpenConfigurationHandles(); if (rval != M64ERR_SUCCESS) { (*CoreShutdown)(); DetachCoreLib(); return 4; } /* parse command-line options */ rval = ParseCommandLineFinal(argc, (const char **) argv); if (rval != M64ERR_SUCCESS) { (*CoreShutdown)(); DetachCoreLib(); return 5; } /* Ensure that the core supports comparison feature if necessary */ if (l_CoreCompareMode != 0 && !(g_CoreCapabilities & M64CAPS_CORE_COMPARE)) { DebugMessage(M64MSG_ERROR, "can't use --core-compare feature with this Mupen64Plus core library."); DetachCoreLib(); return 6; } compare_core_init(l_CoreCompareMode); /* Ensure that the core supports the debugger if necessary */ if (l_LaunchDebugger && !(g_CoreCapabilities & M64CAPS_DEBUGGER)) { DebugMessage(M64MSG_ERROR, "can't use --debug feature with this Mupen64Plus core library."); DetachCoreLib(); return 6; } /* save the given command-line options in configuration file if requested */ if (l_SaveOptions) SaveConfigurationOptions(); /* load ROM image */ FILE *fPtr = fopen(l_ROMFilepath, "rb"); if (fPtr == NULL) { DebugMessage(M64MSG_ERROR, "couldn't open ROM file '%s' for reading.", l_ROMFilepath); (*CoreShutdown)(); DetachCoreLib(); return 7; } /* get the length of the ROM, allocate memory buffer, load it from disk */ long romlength = 0; fseek(fPtr, 0L, SEEK_END); romlength = ftell(fPtr); fseek(fPtr, 0L, SEEK_SET); unsigned char *ROM_buffer = (unsigned char *) malloc(romlength); if (ROM_buffer == NULL) { DebugMessage(M64MSG_ERROR, "couldn't allocate %li-byte buffer for ROM image file '%s'.", romlength, l_ROMFilepath); fclose(fPtr); (*CoreShutdown)(); DetachCoreLib(); return 8; } else if (fread(ROM_buffer, 1, romlength, fPtr) != romlength) { DebugMessage(M64MSG_ERROR, "couldn't read %li bytes from ROM image file '%s'.", romlength, l_ROMFilepath); free(ROM_buffer); fclose(fPtr); (*CoreShutdown)(); DetachCoreLib(); return 9; } fclose(fPtr); /* Try to load the ROM image into the core */ if ((*CoreDoCommand)(M64CMD_ROM_OPEN, (int) romlength, ROM_buffer) != M64ERR_SUCCESS) { DebugMessage(M64MSG_ERROR, "core failed to open ROM image file '%s'.", l_ROMFilepath); free(ROM_buffer); (*CoreShutdown)(); DetachCoreLib(); return 10; } free(ROM_buffer); /* the core copies the ROM image, so we can release this buffer immediately */ /* handle the cheat codes */ CheatStart(l_CheatMode, l_CheatNumList); if (l_CheatMode == CHEAT_SHOW_LIST) { (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); (*CoreShutdown)(); DetachCoreLib(); return 11; } /* search for and load plugins */ rval = PluginSearchLoad(l_ConfigUI); if (rval != M64ERR_SUCCESS) { (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); (*CoreShutdown)(); DetachCoreLib(); return 12; } /* attach plugins to core */ for (i = 0; i < 4; i++) { if ((*CoreAttachPlugin)(g_PluginMap[i].type, g_PluginMap[i].handle) != M64ERR_SUCCESS) { DebugMessage(M64MSG_ERROR, "core error while attaching %s plugin.", g_PluginMap[i].name); (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); (*CoreShutdown)(); DetachCoreLib(); return 13; } } /* set up Frame Callback if --testshots is enabled */ if (l_TestShotList != NULL) { if ((*CoreDoCommand)(M64CMD_SET_FRAME_CALLBACK, 0, FrameCallback) != M64ERR_SUCCESS) { DebugMessage(M64MSG_WARNING, "couldn't set frame callback, --testshots will not work."); } } /* set gb cart loader */ if ((*CoreDoCommand)(M64CMD_SET_MEDIA_LOADER, sizeof(l_media_loader), &l_media_loader) != M64ERR_SUCCESS) { DebugMessage(M64MSG_WARNING, "Couldn't set media loader, transferpak and GB carts will not work."); } /* load savestate at startup */ if (l_SaveStatePath != NULL) { if ((*CoreDoCommand)(M64CMD_STATE_LOAD, 0, (void *) l_SaveStatePath) != M64ERR_SUCCESS) { DebugMessage(M64MSG_WARNING, "couldn't load state, rom will run normally."); } } /* Setup debugger */ if (l_LaunchDebugger) { if (debugger_setup_callbacks()) { DebugMessage(M64MSG_ERROR, "couldn't setup debugger callbacks."); (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); (*CoreShutdown)(); DetachCoreLib(); return 14; } /* Set Core config parameter to enable debugger */ int bEnableDebugger = 1; (*ConfigSetParameter)(l_ConfigCore, "EnableDebugger", M64TYPE_BOOL, &bEnableDebugger); /* Fork the debugger input thread. */ #if SDL_VERSION_ATLEAST(2,0,0) SDL_CreateThread(debugger_loop, "DebugLoop", NULL); #else SDL_CreateThread(debugger_loop, NULL); #endif } /* run the game */ (*CoreDoCommand)(M64CMD_EXECUTE, 0, NULL); /* detach plugins from core and unload them */ for (i = 0; i < 4; i++) (*CoreDetachPlugin)(g_PluginMap[i].type); PluginUnload(); /* close the ROM image */ (*CoreDoCommand)(M64CMD_ROM_CLOSE, 0, NULL); /* save the configuration file again if --nosaveoptions was not specified, to keep any updated parameters from the core/plugins */ if (l_SaveOptions) SaveConfigurationOptions(); /* Shut down and release the Core library */ (*CoreShutdown)(); DetachCoreLib(); /* free allocated memory */ if (l_TestShotList != NULL) free(l_TestShotList); return 0; }