Advertisement
Guest User

AltTabFix.c

a guest
Aug 2nd, 2017
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "PluginAPI.h"
  3. #include "SafeWrite.h"
  4. #include <stdio.h>
  5. #include <intrin.h>
  6.  
  7. BOOL APIENTRY DllMain( HMODULE hModule,
  8. DWORD ul_reason_for_call,
  9. LPVOID lpReserved
  10. )
  11. {
  12. return TRUE;
  13. }
  14.  
  15. extern "C"
  16. {
  17. // the alt+tab crash usually happens because the two funcs below get null class pointers passed to them somehow
  18. // 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)
  19. // these functions are pretty much 1:1 with the originals, with the addition of the NULL check
  20. static const UInt32 kAltTabFixXAddr = 0x004C9A80;
  21. static const UInt32 kAltTabFixYAddr = 0x004C9AA0;
  22.  
  23. typedef void(*_Console_Print)(const char * buf, ...);
  24. const _Console_Print Console_Print = (_Console_Print)0x00579B9B;
  25.  
  26. int __fastcall AltTabFixXHook(uint8_t *thisPtr, void* unused)
  27. {
  28. if (!thisPtr) // NULL check
  29. {
  30. Console_Print("(AltTabFix) !! Prevented X-coord crash !!");
  31. return 0;
  32. }
  33.  
  34. int* data = *(int**)(thisPtr + 0x3C);
  35. if (*(uint8_t*)(thisPtr + 0x24) & 1)
  36. return 0;
  37.  
  38. if (data == 0)
  39. return 0;
  40.  
  41. return *data;
  42. }
  43.  
  44. int __fastcall AltTabFixYHook(uint8_t *thisPtr, void* unused)
  45. {
  46. if (!thisPtr) // NULL check
  47. {
  48. Console_Print("(AltTabFix) !! Prevented Y-coord crash !!");
  49. return 0;
  50. }
  51.  
  52. int* data = *(int**)(thisPtr + 0x3C);
  53. if (*(uint8_t*)(thisPtr + 0x24) & 1)
  54. return 0;
  55.  
  56. if (data == 0)
  57. return 0;
  58.  
  59. return *(data + 1);
  60. }
  61.  
  62. bool __declspec(dllexport) OBSEPlugin_Query(const OBSEInterface * obse, PluginInfo * info)
  63. {
  64. // fill out the info structure
  65. if (info)
  66. {
  67. info->infoVersion = PluginInfo::kInfoVersion;
  68. info->name = "alt_tab_fix";
  69. info->version = 1;
  70. }
  71.  
  72. // version checks
  73. if (obse->isEditor)
  74. return false;
  75.  
  76. if (obse->oblivionVersion != 0x010201A0) // 1.2.416
  77. return false;
  78.  
  79. return true;
  80. }
  81.  
  82. bool __declspec(dllexport) OBSEPlugin_Load(const OBSEInterface * obse)
  83. {
  84. if (!OBSEPlugin_Query(obse, 0))
  85. return false;
  86.  
  87. WriteRelJump(kAltTabFixXAddr, (UInt32)&AltTabFixXHook);
  88. WriteRelJump(kAltTabFixYAddr, (UInt32)&AltTabFixYHook);
  89.  
  90. return true;
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement