Last active
August 29, 2015 14:07
-
-
Save egocarib/5000d6dc6872ae22f55d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//EnchantmentFrameworkAPI.h (Shared by both dlls) | |
struct EnchantmentFrameworkInterface | |
{ | |
enum { kInterfaceVersion = 1 }; | |
UInt32 version; | |
std::vector<EnchantmentItem*> (* GetAllCraftedEnchantments)(); //get all player-created persistent enchantments | |
bool (* GetCraftedEnchantmentParents)(EnchantmentItem* customEnchantment, std::vector<EnchantmentItem*> &baseList); //get base enchantments that were originally combined to craft this custom enchantment | |
}; | |
//EnchantmentInfo.h (EnchantmentFramework.dll) | |
extern EnchantmentFrameworkInterface g_enchantmentFrameworkInterface; | |
typedef std::vector<EnchantmentItem*> EnchantmentVec; | |
//EnchantmentInfo.cpp (EnchantmentFramework.dll) | |
namespace EnchantmentFramework | |
{ | |
EnchantmentVec GetAllCraftedEnchantments() | |
{ | |
struct | |
{ | |
EnchantmentVec eVec; | |
bool Accept(EnchantmentItem* e, EnchantmentInfoEntry ei) | |
{ | |
eVec.push_back(e); | |
return true; | |
} | |
} persistentEnchantments; | |
g_enchantTracker.Visit(&persistentEnchantments); | |
return persistentEnchantments.eVec; | |
} | |
bool GetCraftedEnchantmentParents(EnchantmentItem* customEnchantment, std::vector<EnchantmentItem*> &baseList) | |
{ | |
return g_enchantTracker.GetParents(customEnchantment, baseList); | |
} | |
}; | |
EnchantmentFrameworkInterface g_enchantmentFrameworkInterface = | |
{ | |
EnchantmentFrameworkInterface::kInterfaceVersion, | |
EnchantmentFramework::GetAllCraftedEnchantments, | |
EnchantmentFramework::GetCraftedEnchantmentParents | |
}; | |
//main.cpp (EnchantmentFramework.dll) | |
else if (msg->type == SKSEMessagingInterface::kMessage_PostPostLoad) | |
{ | |
_MESSAGE("Broadcasting interface to other plugins..."); | |
g_messageInterface->Dispatch(g_pluginHandle, 'Itfc', (void*)&g_enchantmentFrameworkInterface, sizeof(void*), NULL); | |
} | |
//main.cpp (EnchantingAwakened.dll) | |
if (msg->type == 'Itfc') | |
{ | |
_MESSAGE("Recieved Interface from Enchantment Framework"); | |
g_enchantmentFramework = reinterpret_cast<EnchantmentFrameworkInterface*>(msg->data); | |
} | |
//Events.cpp (EnchantingAwakened.dll) | |
//If I put this line by itself, it causes an immediate crash. (And when I debug GetCraftedEnchantmentParents, | |
//every line in that function runs successfully and it appears to return the value back to this thread.) | |
g_enchantmentFramework->GetCraftedEnchantmentParents(enchantment, baseEnchantments); | |
//But if I embed it in an if statement the program runs until the outer if statement ends, then it crashes | |
if (enchantment->formID >= 0xFF000000) | |
{ | |
std::vector<EnchantmentItem*> baseEnchantments; | |
if (g_enchantmentFramework->GetCraftedEnchantmentParents(enchantment, baseEnchantments)) | |
_MESSAGE("enchantment framework returned true"); //this prints, and the data in baseEnchantments is correctly populated and returned | |
for (UInt32 i = 0; i < baseEnchantments.size(); i++) | |
g_learnedExperienceMap.AdvanceLearning(baseEnchantments[i]); | |
_MESSAGE("in"); //prints every time | |
} | |
_MESSAGE("out"); //never prints |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment