Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "nvse/PluginAPI.h"
- #include "nvse/CommandTable.h"
- #include "nvse/GameAPI.h"
- #include "nvse/ParamInfos.h"
- #include "nvse/GameObjects.h"
- #include <string>
- #include <nvse/SafeWrite.h>
- #include "nvse/GameUI.h"
- #include "nvse/Utilities.h"
- #include "detours/detours.h"
- IDebugLog gLog("nvse_aaafyty_pipboy_remover.log");
- PluginHandle g_pluginHandle = kPluginHandle_Invalid;
- NVSEMessagingInterface* g_msg;
- NVSEInterface * SaveNVSE;
- NVSECommandTableInterface * g_cmdTable;
- const CommandInfo * g_TFC;
- NVSEScriptInterface* g_script;
- PlayerCharacter* ThePlayer;
- TESForm* itemPimpboy;
- TESForm* itemPipboy;
- TESForm* itemPipboyGlove;
- UInt32 iPimpboyFormID = 0x0011BACB;
- UInt32 iPipboyFormID = 0x00015038;
- UInt32 iPipboyGloveFormID = 0x00025B83;
- std::string strTranquilityLaneEDID = "TranquilityLane";
- UInt32 iaddr_MainUILoop_TryToOpenPipboy = 0x0070E913;
- UInt32* call_MainUILoop_TryToOpenPipboy = *(UInt32**)iaddr_MainUILoop_TryToOpenPipboy;
- void EquipPlayerPipboy();
- void InitializeGlobals()
- {
- itemPimpboy = LookupFormByID(iPimpboyFormID);
- itemPipboy = LookupFormByID(iPipboyFormID);
- itemPipboyGlove = LookupFormByID(iPipboyGloveFormID);
- }
- void EquipPlayerPipboy()
- {
- std::string stringWorldspaceName = ThePlayer->parentCell->worldSpace->GetName();
- if (stringWorldspaceName != strTranquilityLaneEDID)
- {
- if (ThePlayer->GetItemCount(itemPimpboy) > 0)
- {
- ThePlayer->EquipItem(itemPimpboy);
- ThePlayer->EquipItem(itemPipboyGlove);
- }
- if (ThePlayer->GetItemCount(itemPipboy) > 0)
- {
- ThePlayer->EquipItem(itemPipboy);
- ThePlayer->EquipItem(itemPipboyGlove);
- }
- }
- }
- void UnequipPlayerPipboy()
- {
- if (ThePlayer->GetItemCount(itemPimpboy) > 0)
- {
- ThePlayer->UnequipItem(itemPimpboy);
- ThePlayer->UnequipItem(itemPipboyGlove);
- }
- if (ThePlayer->GetItemCount(itemPipboy) > 0)
- {
- ThePlayer->UnequipItem(itemPipboy);
- ThePlayer->UnequipItem(itemPipboyGlove);
- }
- }
- void __fastcall Patch_MainUILoop_TryToOpenPipboy(InterfaceManager* intman, void* dummyEDX, void* a2, int MenuCode)
- {
- EquipPlayerPipboy();
- ThisStdCall((UInt32) call_MainUILoop_TryToOpenPipboy, intman, a2, MenuCode);
- }
- void MessageHandler(NVSEMessagingInterface::Message* msg)
- {
- switch (msg->type)
- {
- case NVSEMessagingInterface::kMessage_PostLoad:
- _MESSAGE("Received post load plugins message");
- InitializeGlobals();
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread);
- DetourAttach(&(PVOID&)iaddr_MainUILoop_TryToOpenPipboy, call_MainUILoop_TryToOpenPipboy);
- DetourTransactionCommit();
- break;
- case NVSEMessagingInterface::kMessage_PreLoadGame:
- _MESSAGE("Received pre load game message with file path %s", msg->data);
- ThePlayer = PlayerCharacter::GetSingleton();
- break;
- }
- }
- extern "C" {
- bool NVSEPlugin_Query(const NVSEInterface * nvse, PluginInfo * info)
- {
- _MESSAGE("query");
- // fill out the info structure
- info->infoVersion = PluginInfo::kInfoVersion;
- info->name = "nvse_plugin_example";
- info->version = 2;
- // version checks
- if(nvse->nvseVersion < NVSE_VERSION_INTEGER)
- {
- _ERROR("NVSE version too old (got %08X expected at least %08X)", nvse->nvseVersion, NVSE_VERSION_INTEGER);
- return false;
- }
- if(!nvse->isEditor)
- {
- if(nvse->runtimeVersion < RUNTIME_VERSION_1_4_0_525)
- {
- _ERROR("incorrect runtime version (got %08X need at least %08X)", nvse->runtimeVersion, RUNTIME_VERSION_1_4_0_525);
- return false;
- }
- #ifdef NOGORE
- if(!nvse->isNogore)
- {
- _ERROR("incorrect runtime edition (got %08X need %08X (nogore))", nvse->isNogore, 1);
- return false;
- }
- #else
- if(nvse->isNogore)
- {
- _ERROR("incorrect runtime edition (got %08X need %08X (standard))", nvse->isNogore, 0);
- return false;
- }
- #endif
- }
- else
- {
- if(nvse->editorVersion < CS_VERSION_1_4_0_518)
- {
- _ERROR("incorrect editor version (got %08X need at least %08X)", nvse->editorVersion, CS_VERSION_1_4_0_518);
- return false;
- }
- #ifdef NOGORE
- _ERROR("Editor only uses standard edition, closing.");
- return false;
- #endif
- }
- // version checks pass
- return true;
- }
- bool NVSEPlugin_Load(const NVSEInterface * nvse)
- {
- _MESSAGE("load");
- g_pluginHandle = nvse->GetPluginHandle();
- // save the NVSEinterface in cas we need it later
- SaveNVSE = (NVSEInterface *)nvse;
- ThePlayer = PlayerCharacter::GetSingleton();
- // register to receive messages from NVSE
- NVSEMessagingInterface* msgIntfc = (NVSEMessagingInterface*)nvse->QueryInterface(kInterface_Messaging);
- msgIntfc->RegisterListener(g_pluginHandle, "NVSE", MessageHandler);
- g_msg = msgIntfc;
- g_script = (NVSEScriptInterface*)nvse->QueryInterface(kInterface_Script);
- return true;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement