Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.67 KB | None | 0 0
  1. #include "nvse/PluginAPI.h"
  2. #include "nvse/CommandTable.h"
  3. #include "nvse/GameAPI.h"
  4. #include "nvse/ParamInfos.h"
  5. #include "nvse/GameObjects.h"
  6. #include <string>
  7. #include <nvse/SafeWrite.h>
  8. #include "nvse/GameUI.h"
  9. #include "nvse/Utilities.h"
  10. #include "detours/detours.h"
  11.  
  12. IDebugLog       gLog("nvse_aaafyty_pipboy_remover.log");
  13.  
  14. PluginHandle    g_pluginHandle = kPluginHandle_Invalid;
  15.  
  16. NVSEMessagingInterface* g_msg;
  17. NVSEInterface * SaveNVSE;
  18. NVSECommandTableInterface * g_cmdTable;
  19. const CommandInfo * g_TFC;
  20. NVSEScriptInterface* g_script;
  21.  
  22. PlayerCharacter* ThePlayer;
  23. TESForm* itemPimpboy;
  24. TESForm* itemPipboy;
  25. TESForm* itemPipboyGlove;
  26. UInt32 iPimpboyFormID = 0x0011BACB;
  27. UInt32 iPipboyFormID = 0x00015038;
  28. UInt32 iPipboyGloveFormID = 0x00025B83;
  29.  
  30. std::string strTranquilityLaneEDID = "TranquilityLane";
  31.  
  32. UInt32 iaddr_MainUILoop_TryToOpenPipboy = 0x0070E913;
  33. UInt32* call_MainUILoop_TryToOpenPipboy = *(UInt32**)iaddr_MainUILoop_TryToOpenPipboy;
  34.  
  35. void EquipPlayerPipboy();
  36.  
  37. void InitializeGlobals()
  38. {
  39.     itemPimpboy = LookupFormByID(iPimpboyFormID);
  40.     itemPipboy = LookupFormByID(iPipboyFormID);
  41.     itemPipboyGlove = LookupFormByID(iPipboyGloveFormID);
  42. }
  43.  
  44. void EquipPlayerPipboy()
  45. {
  46.     std::string stringWorldspaceName = ThePlayer->parentCell->worldSpace->GetName();
  47.     if (stringWorldspaceName != strTranquilityLaneEDID)
  48.     {
  49.         if (ThePlayer->GetItemCount(itemPimpboy) > 0)
  50.         {
  51.             ThePlayer->EquipItem(itemPimpboy);
  52.             ThePlayer->EquipItem(itemPipboyGlove);
  53.         }
  54.  
  55.         if (ThePlayer->GetItemCount(itemPipboy) > 0)
  56.         {
  57.             ThePlayer->EquipItem(itemPipboy);
  58.             ThePlayer->EquipItem(itemPipboyGlove);
  59.         }
  60.     }
  61. }
  62.  
  63. void UnequipPlayerPipboy()
  64. {
  65.     if (ThePlayer->GetItemCount(itemPimpboy) > 0)
  66.     {
  67.         ThePlayer->UnequipItem(itemPimpboy);
  68.         ThePlayer->UnequipItem(itemPipboyGlove);
  69.     }
  70.  
  71.     if (ThePlayer->GetItemCount(itemPipboy) > 0)
  72.     {
  73.         ThePlayer->UnequipItem(itemPipboy);
  74.         ThePlayer->UnequipItem(itemPipboyGlove);
  75.     }
  76. }
  77.  
  78. void __fastcall Patch_MainUILoop_TryToOpenPipboy(InterfaceManager* intman, void* dummyEDX, void* a2, int MenuCode)
  79. {
  80.     EquipPlayerPipboy();
  81.     ThisStdCall((UInt32) call_MainUILoop_TryToOpenPipboy, intman, a2, MenuCode);
  82. }
  83.  
  84. void MessageHandler(NVSEMessagingInterface::Message* msg)
  85. {
  86.     switch (msg->type)
  87.     {
  88.         case NVSEMessagingInterface::kMessage_PostLoad:
  89.             _MESSAGE("Received post load plugins message");
  90.             InitializeGlobals();
  91.             DetourTransactionBegin();
  92.             DetourUpdateThread(GetCurrentThread);
  93.             DetourAttach(&(PVOID&)iaddr_MainUILoop_TryToOpenPipboy, call_MainUILoop_TryToOpenPipboy);
  94.             DetourTransactionCommit();
  95.         break;
  96.  
  97.         case NVSEMessagingInterface::kMessage_PreLoadGame:
  98.             _MESSAGE("Received pre load game message with file path %s", msg->data);
  99.             ThePlayer = PlayerCharacter::GetSingleton();
  100.             break;
  101.     }
  102. }
  103.  
  104. extern "C" {
  105.  
  106. bool NVSEPlugin_Query(const NVSEInterface * nvse, PluginInfo * info)
  107. {
  108.     _MESSAGE("query");
  109.  
  110.     // fill out the info structure
  111.     info->infoVersion = PluginInfo::kInfoVersion;
  112.     info->name = "nvse_plugin_example";
  113.     info->version = 2;
  114.  
  115.     // version checks
  116.     if(nvse->nvseVersion < NVSE_VERSION_INTEGER)
  117.     {
  118.         _ERROR("NVSE version too old (got %08X expected at least %08X)", nvse->nvseVersion, NVSE_VERSION_INTEGER);
  119.         return false;
  120.     }
  121.  
  122.     if(!nvse->isEditor)
  123.     {
  124.         if(nvse->runtimeVersion < RUNTIME_VERSION_1_4_0_525)
  125.         {
  126.             _ERROR("incorrect runtime version (got %08X need at least %08X)", nvse->runtimeVersion, RUNTIME_VERSION_1_4_0_525);
  127.             return false;
  128.         }
  129.  
  130. #ifdef NOGORE
  131.         if(!nvse->isNogore)
  132.         {
  133.             _ERROR("incorrect runtime edition (got %08X need %08X (nogore))", nvse->isNogore, 1);
  134.             return false;
  135.         }
  136. #else
  137.         if(nvse->isNogore)
  138.         {
  139.             _ERROR("incorrect runtime edition (got %08X need %08X (standard))", nvse->isNogore, 0);
  140.             return false;
  141.         }
  142. #endif
  143.     }
  144.     else
  145.     {
  146.         if(nvse->editorVersion < CS_VERSION_1_4_0_518)
  147.         {
  148.             _ERROR("incorrect editor version (got %08X need at least %08X)", nvse->editorVersion, CS_VERSION_1_4_0_518);
  149.             return false;
  150.         }
  151. #ifdef NOGORE
  152.         _ERROR("Editor only uses standard edition, closing.");
  153.         return false;
  154. #endif
  155.     }
  156.  
  157.     // version checks pass
  158.  
  159.     return true;
  160. }
  161.  
  162. bool NVSEPlugin_Load(const NVSEInterface * nvse)
  163. {
  164.     _MESSAGE("load");
  165.  
  166.     g_pluginHandle = nvse->GetPluginHandle();
  167.  
  168.     // save the NVSEinterface in cas we need it later
  169.     SaveNVSE = (NVSEInterface *)nvse;
  170.  
  171.     ThePlayer = PlayerCharacter::GetSingleton();
  172.  
  173.     // register to receive messages from NVSE
  174.     NVSEMessagingInterface* msgIntfc = (NVSEMessagingInterface*)nvse->QueryInterface(kInterface_Messaging);
  175.     msgIntfc->RegisterListener(g_pluginHandle, "NVSE", MessageHandler);
  176.     g_msg = msgIntfc;
  177.  
  178.     g_script = (NVSEScriptInterface*)nvse->QueryInterface(kInterface_Script);
  179.  
  180.     return true;
  181. }
  182.  
  183. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement