Skip to content

Commit eca704b

Browse files
author
Alex Dunn
committed
#1 Fix bug on items with negative counts showing up
Also fix release build settings, Remove unused ExtraContainerInfo functions, Add DEBUG-only logging
1 parent c3af214 commit eca704b

File tree

5 files changed

+38
-84
lines changed

5 files changed

+38
-84
lines changed

skaar_skse_plugin/common/common.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
5050
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
5151
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
52-
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release VC9\</OutDir>
53-
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release VC9\</IntDir>
52+
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
53+
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
5454
</PropertyGroup>
5555
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
5656
<ClCompile>

skaar_skse_plugin/skaar_skse_plugin/SkaarSpecialInventoryCrafting.cpp

Lines changed: 22 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "skse/GameObjects.h"
1010
#include "skse/GameExtraData.h"
1111
#include "skse/GameData.h"
12+
#include "skse/PapyrusForm.h"
1213

1314
#include <vector>
1415
#include <map>
@@ -38,47 +39,14 @@ class ExtraContainerInfo {
3839
return true;
3940
}
4041

41-
// returns the count of items left in the vector
42-
UInt32 CountItems() {
43-
UInt32 count = 0;
44-
ExtraDataVec::iterator itEnd = m_vec.end();
45-
ExtraDataVec::iterator it = m_vec.begin();
46-
while (it != itEnd) {
47-
ExtraContainerChanges::EntryData* extraData = (*it);
48-
if (extraData && (extraData->countDelta > 0)) {
49-
count++;
50-
//if (IsConsoleMode()) {
51-
// PrintItemType(extraData->type);
52-
//}
53-
}
54-
++it;
55-
}
56-
return count;
57-
}
58-
59-
// returns the weight of items left in the vector
60-
float GetTotalWeight() {
61-
float weight = 0.0;
62-
ExtraDataVec::iterator itEnd = m_vec.end();
63-
ExtraDataVec::iterator it = m_vec.begin();
64-
while (it != itEnd) {
65-
ExtraContainerChanges::EntryData* extraData = (*it);
66-
if (extraData && (extraData->countDelta > 0)) {
67-
weight += papyrusForm::GetWeight(extraData->type);
68-
}
69-
++it;
70-
}
71-
return weight;
72-
}
73-
7442
// 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
7543
ExtraContainerChanges::EntryDataList *SkaarEntryDataListWithExistingItemCounts(ExtraContainerChanges::EntryDataList *givenItemsList) {
7644
ExtraContainerChanges::EntryDataList *newEntryList = ExtraContainerChanges::EntryDataList::Create();
7745
for (size_t i = 0; i < givenItemsList->Count(); i++) {
7846
ExtraContainerChanges::EntryData *currentEntry = givenItemsList->GetNthItem(i);
7947
TESForm *currentForm = currentEntry->type;
8048
UInt32 currentCount = currentEntry->countDelta;
81-
_MESSAGE("Starting search for FormID %d", currentForm->formID);
49+
_DMESSAGE("Starting search for FormID %d, name %s", currentForm->formID, papyrusForm::GetName(currentForm));
8250

8351
// See if this list already has this TESForm
8452
ExtraContainerMap::iterator it = m_map.find(currentForm);
@@ -87,13 +55,13 @@ class ExtraContainerInfo {
8755
UInt32 index = it->second;
8856
ExtraContainerChanges::EntryData* pXData = m_vec[index];
8957
if (pXData) {
90-
_MESSAGE("EXISTING FormID %d", pXData->type->formID);
91-
ExtraContainerChanges::EntryData *newData = ExtraContainerChanges::EntryData::Create(pXData->type, pXData->countDelta+currentCount);
58+
_DMESSAGE("EXISTING FormID %d, name %s", pXData->type->formID, papyrusForm::GetName(currentForm));
59+
ExtraContainerChanges::EntryData *newData = ExtraContainerChanges::EntryData::Create(pXData->type, pXData->countDelta + currentCount);
9260
newEntryList->Push(newData);
9361
}
9462
}
9563
else { // If not, create a new EntryData object and add it to m_vec
96-
_MESSAGE("NEW FormID %d, count %d", currentForm->formID, currentCount);
64+
_DMESSAGE("NEW FormID %d, name %s, count %d", currentForm->formID, papyrusForm::GetName(currentForm), currentCount);
9765
ExtraContainerChanges::EntryData *newData = ExtraContainerChanges::EntryData::Create(currentForm, currentCount);
9866
newEntryList->Push(newData);
9967
}
@@ -108,49 +76,29 @@ class ExtraContainerInfo {
10876
ExtraDataVec::iterator iteratorEnd = m_vec.end();
10977
while (iteratorPosition != iteratorEnd) {
11078
ExtraContainerChanges::EntryData* entryData = (*iteratorPosition);
111-
if (entryData && entryData->countDelta > 0) {
112-
if (entryData->type->GetFormType() == type || type == kFormType_None) {
113-
_MESSAGE("EXISTING PLAYER %d", entryData->type->formID);
114-
bool alreadyThere = SkaarSpecialInventoryCrafting::SkaarEntryDataListContainsEntryData(currentEntries, entryData);
115-
if (!alreadyThere) {
116-
currentEntries->Push(entryData);
117-
}
79+
if (entryData) { // && entryData->countDelta > 0
80+
_DMESSAGE("EXISTING PLAYER %d", entryData->type->formID);
81+
bool alreadyThere = SkaarSpecialInventoryCrafting::SkaarEntryDataListContainsEntryData(currentEntries, entryData);
82+
if (!alreadyThere) {
83+
currentEntries->Push(entryData);
11884
}
11985
}
12086
++iteratorPosition;
12187
}
12288
return currentEntries;
12389
}
124-
125-
ExtraContainerChanges::EntryData* GetNth(UInt32 n, UInt32 count) {
126-
ExtraDataVec::iterator itEnd = m_vec.end();
127-
ExtraDataVec::iterator it = m_vec.begin();
128-
while (it != itEnd) {
129-
ExtraContainerChanges::EntryData* extraData = (*it);
130-
if (extraData && (extraData->countDelta > 0)) {
131-
if (count == n)
132-
{
133-
return extraData;
134-
}
135-
count++;
136-
}
137-
++it;
138-
}
139-
return NULL;
140-
}
14190
};
14291

14392

14493
namespace SkaarSpecialInventoryCrafting {
145-
14694
ExtraContainerInfo SkaarItemInfoForObjectReference(TESObjectREFR* pContainerRef);
14795
ExtraContainerChanges::EntryDataList *SkaarAddRemainingItems(ExtraContainerChanges::EntryDataList *currentItems, TESObjectREFR *pContainerRef, FormType type);
14896
bool SkaarEntryDataListContainsEntryData(ExtraContainerChanges::EntryDataList *entryDataList, ExtraContainerChanges::EntryData *entry);
14997
ExtraContainerChanges::EntryDataList *SkaarGetAllItems(TESObjectREFR* container, FormType type);
15098

15199
// Create a new list of all items of the given type that are in the given container
152100
ExtraContainerChanges::EntryDataList *SkaarGetAllItems(TESObjectREFR* container, FormType type) {
153-
_MESSAGE("SkaarGetAllItems called");
101+
_DMESSAGE("SkaarGetAllItems called");
154102
ExtraContainerChanges* containerChanges = static_cast<ExtraContainerChanges*>(container->extraData.GetByType(kExtraData_ContainerChanges));
155103
if (!containerChanges) {
156104
return NULL;
@@ -160,24 +108,25 @@ namespace SkaarSpecialInventoryCrafting {
160108
if (!itemsList || !containerItems || containerItems->Count() <= 0) {
161109
return NULL;
162110
}
163-
_MESSAGE("SkaarGetAllItems about to loop");
111+
_DMESSAGE("SkaarGetAllItems about to loop");
164112
for (size_t i = 0; i < containerItems->Count(); i++) {
165113
ExtraContainerChanges::EntryData *currentEntry = containerItems->GetNthItem(i);
166-
if (currentEntry && currentEntry->countDelta > 0) {
114+
if (currentEntry) {
167115
if (currentEntry->type->GetFormType() == type || type == kFormType_None) {
168-
_MESSAGE("Found TESForm %d", currentEntry->type->formID);
116+
_DMESSAGE("Found TESForm %d", currentEntry->type->formID);
169117
itemsList->Push(currentEntry);
170118
}
171119
}
172120
}
173-
_MESSAGE("SkaarGetAllItems about to return");
121+
_DMESSAGE("SkaarGetAllItems about to return");
174122
return itemsList;
175123
}
176124

177125
// For each item in a given source container, add the same number of every item to the destination container
126+
// In the case of the workbench containers mod, the source container is the workbench's container and the destination container is the player
178127
void SkaarAddItemsFromContainerToContainer(StaticFunctionTag *base, TESObjectREFR* pSourceContainerRef, TESObjectREFR* pDestContainerRef, UInt32 typeID) {
179128
FormType type = static_cast <FormType>(typeID);
180-
_MESSAGE("SkaarAddItemsFromContainerToContainer() called");
129+
_DMESSAGE("SkaarAddItemsFromContainerToContainer() called");
181130

182131
if (!pDestContainerRef || !pSourceContainerRef) {
183132
return;
@@ -198,12 +147,10 @@ namespace SkaarSpecialInventoryCrafting {
198147
// Put into the list those items that were already on the destination but not in the source so they aren't lost
199148
newEntryDataList = SkaarAddRemainingItems(newEntryDataList, pDestContainerRef, type);
200149

150+
_DMESSAGE("About to add ExtraContainerChanges to the player that has %d items in it", newEntryDataList->Count());
201151
ExtraContainerChanges* pXDestContainerChanges = static_cast<ExtraContainerChanges*>(pDestContainerRef->extraData.GetByType(kExtraData_ContainerChanges));
202152
pXDestContainerChanges->data->objList = newEntryDataList;
203-
_MESSAGE("About to add ExtraContainerChanges to the player that has %d items in it", newEntryDataList->Count());
204-
pDestContainerRef->extraData.Add(kExtraData_ContainerChanges, pXDestContainerChanges);
205-
206-
_MESSAGE("SkaarAddItemsFromContainerToContainer() finished");
153+
_DMESSAGE("SkaarAddItemsFromContainerToContainer() finished");
207154
}
208155

209156
void SkaarRemoveItemsInContainerFromContainer(StaticFunctionTag *base, TESObjectREFR* pInContainerRef, TESObjectREFR* pFromContainerRef, UInt32 typeID) {
@@ -218,15 +165,15 @@ namespace SkaarSpecialInventoryCrafting {
218165
}
219166

220167
ExtraContainerChanges::EntryDataList *fromContainerItems = SkaarGetAllItems(pFromContainerRef, type);
221-
_MESSAGE("About to remove ExtraContainerChanges from the player that has %d items in it", inContainerItems->Count());
168+
_DMESSAGE("About to remove ExtraContainerChanges from the player that has %d items in it", inContainerItems->Count());
222169
for (size_t i = 0; i < inContainerItems->Count(); i++) {
223170
ExtraContainerChanges::EntryData *currentInEntry = inContainerItems->GetNthItem(i);
224171
if (!currentInEntry) {
225172
continue;
226173
}
227174
for (size_t j = 0; j < fromContainerItems->Count(); j++) {
228175
ExtraContainerChanges::EntryData *currentFromEntry = fromContainerItems->GetNthItem(j);
229-
if (currentFromEntry && currentFromEntry->type == currentInEntry->type && currentInEntry->countDelta > 0) {
176+
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
230177
UINT32 delta = currentFromEntry->countDelta - currentInEntry->countDelta;
231178
if (delta >= 0) {
232179
currentFromEntry->countDelta = delta;
@@ -280,4 +227,4 @@ namespace SkaarSpecialInventoryCrafting {
280227

281228
return true;
282229
}
283-
}
230+
}

skaar_skse_plugin/skaar_skse_plugin/main.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@ extern "C" {
1212
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
1313
gLog.OpenRelative(CSIDL_MYDOCUMENTS, "\\My Games\\Skyrim\\SKSE\\Skaar.log");
1414
gLog.SetPrintLevel(IDebugLog::kLevel_Error);
15+
#ifdef _DEBUG
1516
gLog.SetLogLevel(IDebugLog::kLevel_DebugMessage);
17+
#else
18+
gLog.SetLogLevel(IDebugLog::kLevel_Message);
19+
#endif
1620

1721
_MESSAGE("SkaarSpecialInventoryCrafting");
1822

1923
// populate info structure
20-
info->infoVersion = PluginInfo::kInfoVersion;
21-
info->name = "SkaarSpecialInventoryCrafting";
22-
info->version = 1;
24+
info->infoVersion = PluginInfo::kInfoVersion;
25+
info->name = "SkaarSpecialInventoryCrafting";
26+
info->version = 1;
2327

2428
// store plugin handle so we can identify ourselves later
2529
g_pluginHandle = skse->GetPluginHandle();
2630

27-
if(skse->isEditor)
31+
if (skse->isEditor)
2832
{
2933
_MESSAGE("loaded in editor, marking as incompatible");
3034

3135
return false;
3236
}
33-
else if(skse->runtimeVersion != RUNTIME_VERSION_1_9_32_0)
37+
else if (skse->runtimeVersion != RUNTIME_VERSION_1_9_32_0)
3438
{
3539
_MESSAGE("unsupported runtime version %08X", skse->runtimeVersion);
3640

skaar_skse_plugin/skaar_skse_plugin/skaar_skse_plugin.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<OptimizeReferences>true</OptimizeReferences>
9999
<EnableCOMDATFolding>true</EnableCOMDATFolding>
100100
<TargetMachine>MachineX86</TargetMachine>
101-
<AdditionalDependencies>skse.lib;%(AdditionalDependencies)</AdditionalDependencies>
101+
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
102102
</Link>
103103
</ItemDefinitionGroup>
104104
<ItemGroup>

skaar_skse_plugin/skse/skse.vcxproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</PropertyGroup>
2626
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2727
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
28-
<ConfigurationType>DynamicLibrary</ConfigurationType>
28+
<ConfigurationType>StaticLibrary</ConfigurationType>
2929
<CharacterSet>MultiByte</CharacterSet>
3030
<WholeProgramOptimization>true</WholeProgramOptimization>
3131
<PlatformToolset>v120</PlatformToolset>
@@ -54,6 +54,9 @@
5454
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
5555
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
5656
</PropertyGroup>
57+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
58+
<TargetExt>.lib</TargetExt>
59+
</PropertyGroup>
5760
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
5861
<ClCompile>
5962
<Optimization>Disabled</Optimization>

0 commit comments

Comments
 (0)