static void OnAttach(void) { gLog.SetPrintLevel(IDebugLog::kLevel_Error); gLog.SetLogLevel(IDebugLog::kLevel_DebugMessage); std::string dllSuffix; bool steamVersion; // paranoia check if(!TestChecksum("oblivion.exe", &dllSuffix, &steamVersion)) { _ERROR("checksum not found"); return; } // /extreme/ paranoia check if(!steamVersion) { _ERROR("not a steam version!?"); return; } // build full path to our dll std::string dllPath; dllPath = GetCWD() + "\\obse_" + dllSuffix + ".dll"; _MESSAGE("dll = %s", dllPath.c_str()); // load it if(!LoadLibrary(dllPath.c_str())) { _ERROR("couldn't load dll"); } }
bool OBSEPlugin_Load(const OBSEInterface * obse) { g_pluginHandle = obse->GetPluginHandle(); _MESSAGE("RuntimeEditorIDs Initializing..."); gLog.Indent(); if(!obse->isEditor) { for (int i = 0; i < VTBLTableSize; i++) { UInt32 PatchAddress = g_VTBLTable[i].Address + kTESForm_SetEditorID_VTBLOffset; SafeWrite32(PatchAddress, (UInt32)TESForm_HandleEditorID); _MESSAGE("Patched '%s' VTBL offset 0x%08X", g_VTBLTable[i].Class, PatchAddress); } } obse->SetOpcodeBase(0x2740); // 0x2740 - 0x274F obse->RegisterTypedCommand(&kCommandInfo_GetRuntimeEditorID, kRetnType_String); g_msgIntfc->RegisterListener(g_pluginHandle, "OBSE", OBSEMessageHandler); gLog.Outdent(); _MESSAGE("RuntimeEditorIDs Initialized!\n\n"); return true; }
static void OnAttach(void) { gLog.OpenRelative(CSIDL_MYDOCUMENTS, "\\My Games\\Skyrim\\SKSE\\skse_steam_loader.log"); gLog.SetPrintLevel(IDebugLog::kLevel_Error); gLog.SetLogLevel(IDebugLog::kLevel_DebugMessage); FILETIME now; GetSystemTimeAsFileTime(&now); _MESSAGE("skse loader %08X (steam) %08X%08X %s", PACKED_SKSE_VERSION, now.dwHighDateTime, now.dwLowDateTime, GetOSInfoStr().c_str()); _MESSAGE("base addr = %08X", g_dllHandle); UInt32 oldProtect; _GetSystemTimeAsFileTime_IAT = (_GetSystemTimeAsFileTime *)GetIATAddr((UInt8 *)GetModuleHandle(NULL), "kernel32.dll", "GetSystemTimeAsFileTime"); if(_GetSystemTimeAsFileTime_IAT) { _MESSAGE("GetSystemTimeAsFileTime IAT = %08X", _GetSystemTimeAsFileTime_IAT); VirtualProtect((void *)_GetSystemTimeAsFileTime_IAT, 4, PAGE_EXECUTE_READWRITE, &oldProtect); _MESSAGE("original GetSystemTimeAsFileTime = %08X", *_GetSystemTimeAsFileTime_IAT); GetSystemTimeAsFileTime_Original = *_GetSystemTimeAsFileTime_IAT; *_GetSystemTimeAsFileTime_IAT = GetSystemTimeAsFileTime_Hook; _MESSAGE("patched GetSystemTimeAsFileTime = %08X", *_GetSystemTimeAsFileTime_IAT); UInt32 junk; VirtualProtect((void *)_GetSystemTimeAsFileTime_IAT, 4, oldProtect, &junk); } else { _ERROR("couldn't read IAT"); } // win8 automatically initializes the stack cookie, so the previous hook doesn't get hit _GetStartupInfoA_IAT = (_GetStartupInfoA *)GetIATAddr((UInt8 *)GetModuleHandle(NULL), "kernel32.dll", "GetStartupInfoA"); if(_GetStartupInfoA_IAT) { _MESSAGE("GetStartupInfoA IAT = %08X", _GetStartupInfoA_IAT); VirtualProtect((void *)_GetStartupInfoA_IAT, 4, PAGE_EXECUTE_READWRITE, &oldProtect); _MESSAGE("original GetStartupInfoA = %08X", *_GetStartupInfoA_IAT); GetStartupInfoA_Original = *_GetStartupInfoA_IAT; *_GetStartupInfoA_IAT = GetStartupInfoA_Hook; _MESSAGE("patched GetStartupInfoA = %08X", *_GetStartupInfoA_IAT); UInt32 junk; VirtualProtect((void *)_GetStartupInfoA_IAT, 4, oldProtect, &junk); } }
static void OnAttach(void) { gLog.OpenRelative(CSIDL_MYDOCUMENTS, "\\My Games\\Skyrim Special Edition\\SKSE\\skse64_steam_loader.log"); gLog.SetPrintLevel(IDebugLog::kLevel_Error); gLog.SetLogLevel(IDebugLog::kLevel_DebugMessage); FILETIME now; GetSystemTimeAsFileTime(&now); _MESSAGE("skse64 loader %08X (steam) %08X%08X %s", PACKED_SKSE_VERSION, now.dwHighDateTime, now.dwLowDateTime, GetOSInfoStr().c_str()); _MESSAGE("loader base addr = %016I64X", g_dllHandle); _MESSAGE("exe base addr = %016I64X", GetModuleHandle(NULL)); // hook an imported function early so we can inject our code HookIAT(); }
bool SKSEPlugin_Query(const SKSEInterface * skse, PluginInfo * info) { gLog.OpenRelative(CSIDL_MYDOCUMENTS, kLogPath); _MESSAGE("EnchantReloadFix SKSE Plugin\nby egocarib\n\n" "{ Fixes player-enchanted items having inflated gold value }\n" "{ and draining higher amounts of charge after game reload }\n"); //Populate plugin info structure info->infoVersion = PluginInfo::kInfoVersion; info->name = "EnchantReloadFix Plugin"; info->version = 1; //Store plugin handle so we can identify ourselves later g_pluginHandle = skse->GetPluginHandle(); if(skse->isEditor) { _MESSAGE("Loaded In Editor, Marking As Incompatible"); return false; } else if(skse->runtimeVersion != RUNTIME_VERSION_1_9_32_0) { _MESSAGE("Unsupported Runtime Version %08X", skse->runtimeVersion); return false; } //Get the serialization interface and query its version g_serialization = (SKSESerializationInterface *)skse->QueryInterface(kInterface_Serialization); if(!g_serialization) { _MESSAGE("Couldn't Get Serialization Interface"); return false; } if(g_serialization->version < SKSESerializationInterface::kVersion) { _MESSAGE("Serialization Interface Too Old (%d Expected %d)", g_serialization->version, SKSESerializationInterface::kVersion); return false; } return true; }
/// <summary> /// Adds the default patches for this module (automatically enabled). /// </summary> /// <param name="patches">The patches.</param> /// <param name="hooks">The hooks.</param> /// <returns>The created & enabled patchset</returns> PatchSet* AddModulePatches(const PatchSetInitializerListType& patches, const PatchSetHookInitializerListType& hooks = {}) { modulePatches = this->patches->AddPatchSet(moduleName, patches, hooks); if (!modulePatches) { logger->Log(LogSeverity::Error, moduleName, "Failed to add module patches?!"); return nullptr; } // toggle/enable the patch set this->patches->TogglePatchSet(modulePatches); return modulePatches; }
bool OBSEPlugin_Load(const OBSEInterface * obse) { g_pluginHandle = obse->GetPluginHandle(); _MESSAGE("RuntimeScriptProfiler Initializing..."); gLog.Indent(); gLog.SetAutoFlush(false); g_AppPath = obse->GetOblivionDirectory(); g_INIPath = g_AppPath + "Data\\OBSE\\Plugins\\RuntimeScriptProfiler.ini"; g_INIManager->SetINIPath(g_INIPath); g_INIManager->Initialize(); PatchScriptRunnerPerformanceCounter(); PatchTESExecuteScriptsMainLoop(); gLog.Outdent(); _MESSAGE("RuntimeScriptProfiler Initialized!\n\n"); _MESSAGE("Script\t\t\t\t\t\t\t\t\t\tElapsed Time\n"); return true; }
void SKSE_Initialize(void) { if(isInit) return; isInit = true; gLog.OpenRelative(CSIDL_MYDOCUMENTS, kLogPath); #ifndef _DEBUG __try { #endif FILETIME now; GetSystemTimeAsFileTime(&now); #if RUNTIME _MESSAGE("SKSE runtime: initialize (version = %d.%d.%d %08X %08X%08X, os = %s)", SKSE_VERSION_INTEGER, SKSE_VERSION_INTEGER_MINOR, SKSE_VERSION_INTEGER_BETA, RUNTIME_VERSION, now.dwHighDateTime, now.dwLowDateTime, GetOSInfoStr().c_str()); #else _MESSAGE("SKSE editor: initialize (version = %d.%d.%d %08X %08X%08X, os = %s)", SKSE_VERSION_INTEGER, SKSE_VERSION_INTEGER_MINOR, SKSE_VERSION_INTEGER_BETA, EDITOR_VERSION, now.dwHighDateTime, now.dwLowDateTime, GetOSInfoStr().c_str()); #endif _MESSAGE("imagebase = %08X", GetModuleHandle(NULL)); #ifdef _DEBUG SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); WaitForDebugger(); #endif // Commands_Dump(); Hooks_Debug_Init(); Hooks_ObScript_Init(); Hooks_Papyrus_Init(); Hooks_NetImmerse_Init(); Hooks_Threads_Init(); Hooks_Handlers_Init(); g_pluginManager.Init(); Hooks_Debug_Commit(); Hooks_Threads_Commit(); Hooks_Handlers_Commit(); Hooks_Scaleform_Commit(); Hooks_Gameplay_Commit(); Hooks_ObScript_Commit(); Hooks_Papyrus_Commit(); Hooks_UI_Commit(); Hooks_Camera_Commit(); Hooks_NetImmerse_Commit(); Hooks_Data_Commit(); Hooks_SaveLoad_Commit(); Init_CoreSerialization_Callbacks(); Hooks_DirectInput_Commit(); Hooks_Event_Commit(); Hooks_Diagnostics_Commit(); FlushInstructionCache(GetCurrentProcess(), NULL, 0); #ifndef _DEBUG } __except(EXCEPTION_EXECUTE_HANDLER) { _ERROR("exception"); } #endif _MESSAGE("init complete"); }
void SKSE64_Initialize(void) { if(isInit) return; isInit = true; gLog.OpenRelative(CSIDL_MYDOCUMENTS, "\\My Games\\Skyrim Special Edition\\SKSE\\skse64.log"); #ifndef _DEBUG __try { #endif FILETIME now; GetSystemTimeAsFileTime(&now); _MESSAGE("SKSE64 runtime: initialize (version = %d.%d.%d %08X %08X%08X, os = %s)", SKSE_VERSION_INTEGER, SKSE_VERSION_INTEGER_MINOR, SKSE_VERSION_INTEGER_BETA, RUNTIME_VERSION, now.dwHighDateTime, now.dwLowDateTime, GetOSInfoStr().c_str()); _MESSAGE("imagebase = %016I64X", GetModuleHandle(NULL)); _MESSAGE("reloc mgr imagebase = %016I64X", RelocationManager::s_baseAddr); #ifdef _DEBUG SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); WaitForDebugger(); #endif if(!g_branchTrampoline.Create(1024 * 64)) { _ERROR("couldn't create branch trampoline. this is fatal. skipping remainder of init process."); return; } if(!g_localTrampoline.Create(1024 * 64, g_moduleHandle)) { _ERROR("couldn't create codegen buffer. this is fatal. skipping remainder of init process."); return; } // Add Hooks_XXX_Init calls here Hooks_Debug_Init(); Hooks_ObScript_Init(); Hooks_Papyrus_Init(); Hooks_NetImmerse_Init(); Hooks_Threads_Init(); Hooks_Handlers_Init(); g_pluginManager.Init(); // Add Hooks_XXX_Commit calls here in the same order Hooks_Debug_Commit(); Hooks_ObScript_Commit(); Hooks_Papyrus_Commit(); Hooks_UI_Commit(); Hooks_Camera_Commit(); Hooks_NetImmerse_Commit(); Hooks_Threads_Commit(); Hooks_Handlers_Commit(); Hooks_Scaleform_Commit(); Hooks_Gameplay_Commit(); Hooks_Event_Commit(); Hooks_SaveLoad_Commit(); Hooks_Data_Commit(); Init_CoreSerialization_Callbacks(); Hooks_DirectInput_Commit(); FlushInstructionCache(GetCurrentProcess(), NULL, 0); #ifndef _DEBUG } __except(EXCEPTION_EXECUTE_HANDLER) { _ERROR("exception thrown during startup"); } #endif _MESSAGE("init complete"); }
int main(int argc, char ** argv) { gLog.SetPrintLevel(IDebugLog::kLevel_Error); gLog.SetLogLevel(IDebugLog::kLevel_DebugMessage); if(!g_options.Read(argc, argv)) { PrintError("Couldn't read arguments."); g_options.PrintUsage(); return -1; } if(g_options.m_optionsOnly) { g_options.PrintUsage(); return 0; } if(g_options.m_launchCS) _MESSAGE("launching editor"); if(g_options.m_loadOldblivion) _MESSAGE("loading oldblivion"); // create the process STARTUPINFO startupInfo = { 0 }; PROCESS_INFORMATION procInfo = { 0 }; bool dllHasFullPath = false; startupInfo.cb = sizeof(startupInfo); const char * procName = g_options.m_launchCS ? "TESConstructionSet.exe" : "Oblivion.exe"; const char * baseDllName = g_options.m_launchCS ? "obse_editor" : "obse"; if(g_options.m_altEXE.size()) { procName = g_options.m_altEXE.c_str(); _MESSAGE("launching alternate exe (%s)", procName); } if(g_options.m_altDLL.size()) { baseDllName = g_options.m_altDLL.c_str(); _MESSAGE("launching alternate dll (%s)", baseDllName); dllHasFullPath = true; } std::string dllSuffix; ProcHookInfo procHookInfo; if(!TestChecksum(procName, &dllSuffix, &procHookInfo)) { _ERROR("checksum not found"); return -1; } if(procHookInfo.steamVersion) { // ### maybe check for the loader DLL and just CreateProcess("oblivion.exe") if we can? PrintError("You are trying to use a Steam version of Oblivion. Steam users should launch the game through Steam, not by running obse_loader.exe. If OBSE fails to load, go to Steam > Settings > In Game and check the box marked \"Enable Steam community in game\". Please see the instructions in obse_readme.txt for more information."); return 0; } if(g_options.m_crcOnly) return 0; // build dll path std::string dllPath; if(dllHasFullPath) { dllPath = baseDllName; } else { dllPath = GetCWD() + "\\" + baseDllName + "_" + dllSuffix + ".dll"; } _MESSAGE("dll = %s", dllPath.c_str()); // check to make sure the dll exists { IFileStream tempFile; if(!tempFile.Open(dllPath.c_str())) { PrintError("Couldn't find OBSE DLL (%s). Please make sure you have installed OBSE correctly and are running it from your Oblivion folder.", dllPath.c_str()); return -1; } } bool result = CreateProcess( procName, NULL, // no args NULL, // default process security NULL, // default thread security TRUE, // don't inherit handles CREATE_SUSPENDED, NULL, // no new environment NULL, // no new cwd &startupInfo, &procInfo) != 0; // check for Vista failing to create the process due to elevation requirements if(!result && (GetLastError() == ERROR_ELEVATION_REQUIRED)) { // in theory we could figure out how to UAC-prompt for this process and then run CreateProcess again, but I have no way to test code for that PrintError("Vista has decided that launching Oblivion requires UAC privilege elevation. There is no good reason for this to happen, but to fix it, right-click on obse_loader.exe, go to Properties, pick the Compatibility tab, then turn on \"Run this program as an administrator\"."); return -1; } ASSERT_STR_CODE(result, "Launching Oblivion failed", GetLastError()); if(g_options.m_setPriority) { if(!SetPriorityClass(procInfo.hProcess, g_options.m_priority)) _WARNING("couldn't set process priority"); } result = false; if(g_options.m_launchCS) { if(g_options.m_oldInject) { _MESSAGE("using old editor injection method"); // start the process ResumeThread(procInfo.hThread); // CS needs to run its crt0 code before the DLL is attached, this delays until the message pump is running // note that this method makes it impossible to patch the startup code // this is better than Sleep(1000) but still ugly WaitForInputIdle(procInfo.hProcess, 1000 * 10); // too late if this fails result = InjectDLL(&procInfo, dllPath.c_str(), !g_options.m_noSync); if(!result) PrintError("Couldn't inject dll."); } else { _MESSAGE("using new editor injection method"); result = DoInjectDLL_New(&procInfo, dllPath.c_str(), &procHookInfo); if(!result) PrintError("Couldn't inject dll."); // start the process either way ResumeThread(procInfo.hThread); } } else { result = InjectDLL(&procInfo, dllPath.c_str(), !g_options.m_noSync); if(result) { // try to load oldblivion if requested if(g_options.m_loadOldblivion) { result = LoadOldblivion(&procInfo); if(!result) PrintError("Couldn't load oldblivion."); } } else PrintError("Couldn't inject dll."); if(result) { _MESSAGE("launching oblivion"); // start the process ResumeThread(procInfo.hThread); } else { _ERROR("terminating oblivion process"); // kill the partially-created process TerminateProcess(procInfo.hProcess, 0); g_options.m_waitForClose = false; } } // wait for the process to close if requested if(g_options.m_waitForClose) { WaitForSingleObject(procInfo.hProcess, INFINITE); } // clean up CloseHandle(procInfo.hProcess); CloseHandle(procInfo.hThread); return 0; }