From eca704b5fcb8824a9818420d0f2679d53c3111f9 Mon Sep 17 00:00:00 2001 From: Alex Dunn Date: Sun, 24 Aug 2014 22:59:52 -0700 Subject: [PATCH] #1 Fix bug on items with negative counts showing up Also fix release build settings, Remove unused ExtraContainerInfo functions, Add DEBUG-only logging --- skaar_skse_plugin/common/common.vcxproj | 4 +- .../SkaarSpecialInventoryCrafting.cpp | 97 +++++-------------- skaar_skse_plugin/skaar_skse_plugin/main.cpp | 14 ++- .../skaar_skse_plugin.vcxproj | 2 +- skaar_skse_plugin/skse/skse.vcxproj | 5 +- 5 files changed, 38 insertions(+), 84 deletions(-) diff --git a/skaar_skse_plugin/common/common.vcxproj b/skaar_skse_plugin/common/common.vcxproj index 241b00a..b12fd3e 100644 --- a/skaar_skse_plugin/common/common.vcxproj +++ b/skaar_skse_plugin/common/common.vcxproj @@ -49,8 +49,8 @@ <_ProjectFileVersion>10.0.40219.1 $(SolutionDir)$(Configuration)\ $(Configuration)\ - Release VC9\ - Release VC9\ + $(SolutionDir)$(Configuration)\ + $(Configuration)\ diff --git a/skaar_skse_plugin/skaar_skse_plugin/SkaarSpecialInventoryCrafting.cpp b/skaar_skse_plugin/skaar_skse_plugin/SkaarSpecialInventoryCrafting.cpp index 3aced13..e72c3c9 100644 --- a/skaar_skse_plugin/skaar_skse_plugin/SkaarSpecialInventoryCrafting.cpp +++ b/skaar_skse_plugin/skaar_skse_plugin/SkaarSpecialInventoryCrafting.cpp @@ -9,6 +9,7 @@ #include "skse/GameObjects.h" #include "skse/GameExtraData.h" #include "skse/GameData.h" +#include "skse/PapyrusForm.h" #include #include @@ -38,39 +39,6 @@ class ExtraContainerInfo { return true; } - // returns the count of items left in the vector - UInt32 CountItems() { - UInt32 count = 0; - ExtraDataVec::iterator itEnd = m_vec.end(); - ExtraDataVec::iterator it = m_vec.begin(); - while (it != itEnd) { - ExtraContainerChanges::EntryData* extraData = (*it); - if (extraData && (extraData->countDelta > 0)) { - count++; - //if (IsConsoleMode()) { - // PrintItemType(extraData->type); - //} - } - ++it; - } - return count; - } - - // returns the weight of items left in the vector - float GetTotalWeight() { - float weight = 0.0; - ExtraDataVec::iterator itEnd = m_vec.end(); - ExtraDataVec::iterator it = m_vec.begin(); - while (it != itEnd) { - ExtraContainerChanges::EntryData* extraData = (*it); - if (extraData && (extraData->countDelta > 0)) { - weight += papyrusForm::GetWeight(extraData->type); - } - ++it; - } - return weight; - } - // Create an EntryDataList that includes all of the items in the given EntryDataList, taking into account that some items may already exist on this container ExtraContainerChanges::EntryDataList *SkaarEntryDataListWithExistingItemCounts(ExtraContainerChanges::EntryDataList *givenItemsList) { ExtraContainerChanges::EntryDataList *newEntryList = ExtraContainerChanges::EntryDataList::Create(); @@ -78,7 +46,7 @@ class ExtraContainerInfo { ExtraContainerChanges::EntryData *currentEntry = givenItemsList->GetNthItem(i); TESForm *currentForm = currentEntry->type; UInt32 currentCount = currentEntry->countDelta; - _MESSAGE("Starting search for FormID %d", currentForm->formID); + _DMESSAGE("Starting search for FormID %d, name %s", currentForm->formID, papyrusForm::GetName(currentForm)); // See if this list already has this TESForm ExtraContainerMap::iterator it = m_map.find(currentForm); @@ -87,13 +55,13 @@ class ExtraContainerInfo { UInt32 index = it->second; ExtraContainerChanges::EntryData* pXData = m_vec[index]; if (pXData) { - _MESSAGE("EXISTING FormID %d", pXData->type->formID); - ExtraContainerChanges::EntryData *newData = ExtraContainerChanges::EntryData::Create(pXData->type, pXData->countDelta+currentCount); + _DMESSAGE("EXISTING FormID %d, name %s", pXData->type->formID, papyrusForm::GetName(currentForm)); + ExtraContainerChanges::EntryData *newData = ExtraContainerChanges::EntryData::Create(pXData->type, pXData->countDelta + currentCount); newEntryList->Push(newData); } } else { // If not, create a new EntryData object and add it to m_vec - _MESSAGE("NEW FormID %d, count %d", currentForm->formID, currentCount); + _DMESSAGE("NEW FormID %d, name %s, count %d", currentForm->formID, papyrusForm::GetName(currentForm), currentCount); ExtraContainerChanges::EntryData *newData = ExtraContainerChanges::EntryData::Create(currentForm, currentCount); newEntryList->Push(newData); } @@ -108,41 +76,21 @@ class ExtraContainerInfo { ExtraDataVec::iterator iteratorEnd = m_vec.end(); while (iteratorPosition != iteratorEnd) { ExtraContainerChanges::EntryData* entryData = (*iteratorPosition); - if (entryData && entryData->countDelta > 0) { - if (entryData->type->GetFormType() == type || type == kFormType_None) { - _MESSAGE("EXISTING PLAYER %d", entryData->type->formID); - bool alreadyThere = SkaarSpecialInventoryCrafting::SkaarEntryDataListContainsEntryData(currentEntries, entryData); - if (!alreadyThere) { - currentEntries->Push(entryData); - } + if (entryData) { // && entryData->countDelta > 0 + _DMESSAGE("EXISTING PLAYER %d", entryData->type->formID); + bool alreadyThere = SkaarSpecialInventoryCrafting::SkaarEntryDataListContainsEntryData(currentEntries, entryData); + if (!alreadyThere) { + currentEntries->Push(entryData); } } ++iteratorPosition; } return currentEntries; } - - ExtraContainerChanges::EntryData* GetNth(UInt32 n, UInt32 count) { - ExtraDataVec::iterator itEnd = m_vec.end(); - ExtraDataVec::iterator it = m_vec.begin(); - while (it != itEnd) { - ExtraContainerChanges::EntryData* extraData = (*it); - if (extraData && (extraData->countDelta > 0)) { - if (count == n) - { - return extraData; - } - count++; - } - ++it; - } - return NULL; - } }; namespace SkaarSpecialInventoryCrafting { - ExtraContainerInfo SkaarItemInfoForObjectReference(TESObjectREFR* pContainerRef); ExtraContainerChanges::EntryDataList *SkaarAddRemainingItems(ExtraContainerChanges::EntryDataList *currentItems, TESObjectREFR *pContainerRef, FormType type); bool SkaarEntryDataListContainsEntryData(ExtraContainerChanges::EntryDataList *entryDataList, ExtraContainerChanges::EntryData *entry); @@ -150,7 +98,7 @@ namespace SkaarSpecialInventoryCrafting { // Create a new list of all items of the given type that are in the given container ExtraContainerChanges::EntryDataList *SkaarGetAllItems(TESObjectREFR* container, FormType type) { - _MESSAGE("SkaarGetAllItems called"); + _DMESSAGE("SkaarGetAllItems called"); ExtraContainerChanges* containerChanges = static_cast(container->extraData.GetByType(kExtraData_ContainerChanges)); if (!containerChanges) { return NULL; @@ -160,24 +108,25 @@ namespace SkaarSpecialInventoryCrafting { if (!itemsList || !containerItems || containerItems->Count() <= 0) { return NULL; } - _MESSAGE("SkaarGetAllItems about to loop"); + _DMESSAGE("SkaarGetAllItems about to loop"); for (size_t i = 0; i < containerItems->Count(); i++) { ExtraContainerChanges::EntryData *currentEntry = containerItems->GetNthItem(i); - if (currentEntry && currentEntry->countDelta > 0) { + if (currentEntry) { if (currentEntry->type->GetFormType() == type || type == kFormType_None) { - _MESSAGE("Found TESForm %d", currentEntry->type->formID); + _DMESSAGE("Found TESForm %d", currentEntry->type->formID); itemsList->Push(currentEntry); } } } - _MESSAGE("SkaarGetAllItems about to return"); + _DMESSAGE("SkaarGetAllItems about to return"); return itemsList; } // For each item in a given source container, add the same number of every item to the destination container + // In the case of the workbench containers mod, the source container is the workbench's container and the destination container is the player void SkaarAddItemsFromContainerToContainer(StaticFunctionTag *base, TESObjectREFR* pSourceContainerRef, TESObjectREFR* pDestContainerRef, UInt32 typeID) { FormType type = static_cast (typeID); - _MESSAGE("SkaarAddItemsFromContainerToContainer() called"); + _DMESSAGE("SkaarAddItemsFromContainerToContainer() called"); if (!pDestContainerRef || !pSourceContainerRef) { return; @@ -198,12 +147,10 @@ namespace SkaarSpecialInventoryCrafting { // Put into the list those items that were already on the destination but not in the source so they aren't lost newEntryDataList = SkaarAddRemainingItems(newEntryDataList, pDestContainerRef, type); + _DMESSAGE("About to add ExtraContainerChanges to the player that has %d items in it", newEntryDataList->Count()); ExtraContainerChanges* pXDestContainerChanges = static_cast(pDestContainerRef->extraData.GetByType(kExtraData_ContainerChanges)); pXDestContainerChanges->data->objList = newEntryDataList; - _MESSAGE("About to add ExtraContainerChanges to the player that has %d items in it", newEntryDataList->Count()); - pDestContainerRef->extraData.Add(kExtraData_ContainerChanges, pXDestContainerChanges); - - _MESSAGE("SkaarAddItemsFromContainerToContainer() finished"); + _DMESSAGE("SkaarAddItemsFromContainerToContainer() finished"); } void SkaarRemoveItemsInContainerFromContainer(StaticFunctionTag *base, TESObjectREFR* pInContainerRef, TESObjectREFR* pFromContainerRef, UInt32 typeID) { @@ -218,7 +165,7 @@ namespace SkaarSpecialInventoryCrafting { } ExtraContainerChanges::EntryDataList *fromContainerItems = SkaarGetAllItems(pFromContainerRef, type); - _MESSAGE("About to remove ExtraContainerChanges from the player that has %d items in it", inContainerItems->Count()); + _DMESSAGE("About to remove ExtraContainerChanges from the player that has %d items in it", inContainerItems->Count()); for (size_t i = 0; i < inContainerItems->Count(); i++) { ExtraContainerChanges::EntryData *currentInEntry = inContainerItems->GetNthItem(i); if (!currentInEntry) { @@ -226,7 +173,7 @@ namespace SkaarSpecialInventoryCrafting { } for (size_t j = 0; j < fromContainerItems->Count(); j++) { ExtraContainerChanges::EntryData *currentFromEntry = fromContainerItems->GetNthItem(j); - if (currentFromEntry && currentFromEntry->type == currentInEntry->type && currentInEntry->countDelta > 0) { + if (currentFromEntry && currentFromEntry->type == currentInEntry->type && currentInEntry->countDelta > 0) { // I do actually want to ignore items with a negative count here because I do not want to add back items that were removed from the InContainer UINT32 delta = currentFromEntry->countDelta - currentInEntry->countDelta; if (delta >= 0) { currentFromEntry->countDelta = delta; @@ -280,4 +227,4 @@ namespace SkaarSpecialInventoryCrafting { return true; } -} +} diff --git a/skaar_skse_plugin/skaar_skse_plugin/main.cpp b/skaar_skse_plugin/skaar_skse_plugin/main.cpp index 91a3279..d1ab09a 100644 --- a/skaar_skse_plugin/skaar_skse_plugin/main.cpp +++ b/skaar_skse_plugin/skaar_skse_plugin/main.cpp @@ -12,25 +12,29 @@ extern "C" { bool SKSEPlugin_Query(const SKSEInterface * skse, PluginInfo * info) { // Called by SKSE to learn about this plugin and check that it's safe to load it gLog.OpenRelative(CSIDL_MYDOCUMENTS, "\\My Games\\Skyrim\\SKSE\\Skaar.log"); gLog.SetPrintLevel(IDebugLog::kLevel_Error); +#ifdef _DEBUG gLog.SetLogLevel(IDebugLog::kLevel_DebugMessage); +#else + gLog.SetLogLevel(IDebugLog::kLevel_Message); +#endif _MESSAGE("SkaarSpecialInventoryCrafting"); // populate info structure - info->infoVersion = PluginInfo::kInfoVersion; - info->name = "SkaarSpecialInventoryCrafting"; - info->version = 1; + info->infoVersion = PluginInfo::kInfoVersion; + info->name = "SkaarSpecialInventoryCrafting"; + info->version = 1; // store plugin handle so we can identify ourselves later g_pluginHandle = skse->GetPluginHandle(); - if(skse->isEditor) + if (skse->isEditor) { _MESSAGE("loaded in editor, marking as incompatible"); return false; } - else if(skse->runtimeVersion != RUNTIME_VERSION_1_9_32_0) + else if (skse->runtimeVersion != RUNTIME_VERSION_1_9_32_0) { _MESSAGE("unsupported runtime version %08X", skse->runtimeVersion); diff --git a/skaar_skse_plugin/skaar_skse_plugin/skaar_skse_plugin.vcxproj b/skaar_skse_plugin/skaar_skse_plugin/skaar_skse_plugin.vcxproj index 0acdc2a..5ac8a4d 100644 --- a/skaar_skse_plugin/skaar_skse_plugin/skaar_skse_plugin.vcxproj +++ b/skaar_skse_plugin/skaar_skse_plugin/skaar_skse_plugin.vcxproj @@ -98,7 +98,7 @@ true true MachineX86 - skse.lib;%(AdditionalDependencies) + %(AdditionalDependencies) diff --git a/skaar_skse_plugin/skse/skse.vcxproj b/skaar_skse_plugin/skse/skse.vcxproj index 0ac0894..a2f8c55 100644 --- a/skaar_skse_plugin/skse/skse.vcxproj +++ b/skaar_skse_plugin/skse/skse.vcxproj @@ -25,7 +25,7 @@ - DynamicLibrary + StaticLibrary MultiByte true v120 @@ -54,6 +54,9 @@ $(Configuration)\ false + + .lib + Disabled