static void HookMain(void * retAddr) { if(hookInstalled) return; else hookInstalled = true; _MESSAGE("HookMain: thread = %d retaddr = %016I64X", GetCurrentThreadId(), retAddr); std::string runtimePath = GetRuntimePath(); _MESSAGE("runtimePath = %s", runtimePath.c_str()); bool isEditor = false; // check version etc std::string dllSuffix; ProcHookInfo procHookInfo; if(!IdentifyEXE(runtimePath.c_str(), isEditor, &dllSuffix, &procHookInfo)) { _ERROR("unknown exe"); return; } const char * dllPrefix = (isEditor == false) ? "\\skse64_" : "\\skse64_editor_"; g_dllPath = GetRuntimeDirectory() + dllPrefix + dllSuffix + ".dll"; _MESSAGE("dll = %s", g_dllPath.c_str()); LoadLibrary(g_dllPath.c_str()); }
std::string GetRuntimeName() { std::string appPath = GetRuntimePath(); std::string::size_type slashOffset = appPath.rfind('\\'); if(slashOffset == std::string::npos) return appPath; return appPath.substr(slashOffset + 1); }
const std::string & GetRuntimeDirectory() { static std::string s_runtimeDirectory; if(s_runtimeDirectory.empty()) { std::string runtimePath = GetRuntimePath(); // truncate at last slash std::string::size_type lastSlash = runtimePath.rfind('\\'); if(lastSlash != std::string::npos) // if we don't find a slash something is VERY WRONG { s_runtimeDirectory = runtimePath.substr(0, lastSlash + 1); } else { _WARNING("no slash in runtime path? (%s)", runtimePath.c_str()); } } return s_runtimeDirectory; }