Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "PluginAPI.h"
- #include "SafeWrite.h"
- #include <stdio.h>
- #include <intrin.h>
- BOOL APIENTRY DllMain( HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
- {
- return TRUE;
- }
- extern "C"
- {
- // the alt+tab crash usually happens because the two funcs below get null class pointers passed to them somehow
- // we just reimplement those functions, but add a check to make sure it's not NULL first, and if it is then we just return 0 (which is fine, doesn't seem to break anything)
- // these functions are pretty much 1:1 with the originals, with the addition of the NULL check
- static const UInt32 kAltTabFixXAddr = 0x004C9A80;
- static const UInt32 kAltTabFixYAddr = 0x004C9AA0;
- typedef void(*_Console_Print)(const char * buf, ...);
- const _Console_Print Console_Print = (_Console_Print)0x00579B9B;
- int __fastcall AltTabFixXHook(uint8_t *thisPtr, void* unused)
- {
- if (!thisPtr) // NULL check
- {
- Console_Print("(AltTabFix) !! Prevented X-coord crash !!");
- return 0;
- }
- int* data = *(int**)(thisPtr + 0x3C);
- if (*(uint8_t*)(thisPtr + 0x24) & 1)
- return 0;
- if (data == 0)
- return 0;
- return *data;
- }
- int __fastcall AltTabFixYHook(uint8_t *thisPtr, void* unused)
- {
- if (!thisPtr) // NULL check
- {
- Console_Print("(AltTabFix) !! Prevented Y-coord crash !!");
- return 0;
- }
- int* data = *(int**)(thisPtr + 0x3C);
- if (*(uint8_t*)(thisPtr + 0x24) & 1)
- return 0;
- if (data == 0)
- return 0;
- return *(data + 1);
- }
- bool __declspec(dllexport) OBSEPlugin_Query(const OBSEInterface * obse, PluginInfo * info)
- {
- // fill out the info structure
- if (info)
- {
- info->infoVersion = PluginInfo::kInfoVersion;
- info->name = "alt_tab_fix";
- info->version = 1;
- }
- // version checks
- if (obse->isEditor)
- return false;
- if (obse->oblivionVersion != 0x010201A0) // 1.2.416
- return false;
- return true;
- }
- bool __declspec(dllexport) OBSEPlugin_Load(const OBSEInterface * obse)
- {
- if (!OBSEPlugin_Query(obse, 0))
- return false;
- WriteRelJump(kAltTabFixXAddr, (UInt32)&AltTabFixXHook);
- WriteRelJump(kAltTabFixYAddr, (UInt32)&AltTabFixYHook);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement