Skip to content

Commit

Permalink
Merge pull request #10 from mckyle099/master
Browse files Browse the repository at this point in the history
Ores no longer turn to fake notes
  • Loading branch information
nooperation authored Aug 4, 2023
2 parents d3d0c28 + 4684fd8 commit 0c4cb54
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 148 deletions.
150 changes: 17 additions & 133 deletions D2Hackit/Modules/autoOre/AutoOre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ void AutoOre::SetState(State newState)
"DropNextItemToDrop",
"PickupNextOre",
"DropNextOreToCube",
"FirstTransmute",
"WaitForFirstTransmuteResults",
"PickupGemFromFirstTransmute",
"DropGemFromFirstTransmute",
"SecondTransmute",
"WaitForSecondTransmuteResults",
"Transmute",
"WaitForTransmuteResults",
"RunEmptyCube",
"RunAutoStocker",
};
Expand Down Expand Up @@ -71,15 +67,20 @@ void AutoOre::Start(bool useChat)
server->GameCommandLine("load emptycube");
}

dropFakeNotes = GetPrivateProfileInt("AutoOre", "DropFakeNotes", 0, CONFIG_FILE);
this->oreIds.clear();
me->EnumStorageItems(STORAGE_INVENTORY, enumFindOre, (LPARAM)this);
if (this->oreIds.empty())
{
Abort();
return;
}

StartAutoOre();
}

void AutoOre::StartAutoOre()
{
this->itemsToDrop.clear();
this->oreIds.clear();
this->currentItemToDrop = 0;
this->currentOreId = 0;
this->expectedItemToHand = 0;
Expand All @@ -103,13 +104,6 @@ void AutoOre::StartAutoOre()
return;
}

me->EnumStorageItems(STORAGE_INVENTORY, enumFindOre, (LPARAM)this);
if (this->oreIds.empty())
{
Abort();
return;
}

this->PickupNextOre();
}

Expand Down Expand Up @@ -187,19 +181,7 @@ void AutoOre::OnItemPickedUpFromInventory(DWORD itemId)

void AutoOre::OnItemPickedUpFromCube(DWORD itemId)
{
if (this->currentState == State::PickupGemFromFirstTransmute)
{
if (itemId != this->expectedItemToHand)
{
server->GameStringf("ÿc5AutoOreÿc0: Expected item id %d to hand, but got item id %d (State = PickupGemFromFirstTransmute)", expectedItemToHand, itemId);
Abort();
return;
}

SetState(State::DropGemFromFirstTransmute);
me->DropCursorItemToStorage(STORAGE_INVENTORY);
}
else if (this->currentState == State::PickupNextItemToDrop)
if (this->currentState == State::PickupNextItemToDrop)
{
if (itemId != this->currentItemToDrop)
{
Expand All @@ -212,21 +194,6 @@ void AutoOre::OnItemPickedUpFromCube(DWORD itemId)
}
}

void AutoOre::OnItemDroppedToInventory(const ITEM &item)
{
if (this->currentState == State::DropGemFromFirstTransmute)
{
if (item.dwItemID != expectedItemToHand)
{
server->GameStringf("ÿc5AutoOreÿc0: Expected item id %d to inventory, but got item id %d (State = DropGemFromFirstTransmute)", expectedItemToHand, item.dwItemID);
Abort();
return;
}

SetState(State::SecondTransmute);
}
}

void AutoOre::OnItemDroppedToCube(const ITEM &itemDroppedToCube)
{
if (this->currentState == State::DropNextOreToCube)
Expand All @@ -238,94 +205,20 @@ void AutoOre::OnItemDroppedToCube(const ITEM &itemDroppedToCube)

// NOTE: We cannot run extractor yet. If we do then it will also see this item 'to cube' and
// will think it was part of its extraction process
SetState(State::FirstTransmute);
}
else if (this->currentState == State::WaitForFirstTransmuteResults)
{
numTransmuteResults++;
if (numTransmuteResults != numExpectedTransmuteResults)
{
return;
}

HandleFirstStageTransmuteResults();
SetState(State::Transmute);
}
else if (this->currentState == State::WaitForSecondTransmuteResults)
else if (this->currentState == State::WaitForTransmuteResults)
{
numTransmuteResults++;
if (numTransmuteResults != numExpectedTransmuteResults)
{
return;
}

HandleSecondStageTransmuteResults();
SetState(State::RunEmptyCube);
server->GameCommandLine("emptycube start chat");
}
}

void AutoOre::HandleFirstStageTransmuteResults()
{
// We should now have the ore and gem in our inventory. Move the gem to our inventory and transmute again
std::vector<ITEM> itemsInTheCube;
me->EnumStorageItems(STORAGE_CUBE, enumGetAllCubeItems, (LPARAM)&itemsInTheCube);
if (itemsInTheCube.size() != 2)
{
server->GameStringf("ÿc5AutoOreÿc0: Expected %d items in the cube after the transmute, but we got %d (State = WaitForFirstTransmuteResults)", itemsInTheCube.size());
Abort();
return;
}

if (strstr(itemsInTheCube[0].szItemCode, "fkn") != 0 && strstr(itemsInTheCube[1].szItemCode, "fkn") != 0)
{
// Whoops, this was actually an already extracted ore and we're actually on the second transmute step
HandleSecondStageTransmuteResults();
return;
}

for (const auto& item : itemsInTheCube)
{
// Don't care about the ore. We'll transmute that again during the next stage
if (strstr(item.szItemCode, "ore") != 0)
{
continue;
}

SetState(State::PickupGemFromFirstTransmute);
expectedItemToHand = item.dwItemID;
me->PickStorageItemToCursor(item.dwItemID);
return;
}

server->GameStringf("ÿc5AutoOreÿc0: We got %d items as a transmute result, but I didn't see any ore", itemsInTheCube.size());
Abort();
return;
}

void AutoOre::HandleSecondStageTransmuteResults()
{
// We should now have two fake notes in the cube
std::vector<ITEM> itemsInTheCube;
me->EnumStorageItems(STORAGE_CUBE, enumGetAllCubeItems, (LPARAM)&itemsInTheCube);
if (itemsInTheCube.size() != 2)
{
server->GameStringf("ÿc5AutoOreÿc0: Expected %d items in the cube after the transmute, but we got %d", itemsInTheCube.size());
Abort();
return;
}

auto numFreeSpaces = me->GetNumberOfFreeStorageSlots(STORAGE_INVENTORY);
if (numFreeSpaces < 2 || dropFakeNotes)
{
itemsToDrop.clear();
for (const auto& item : itemsInTheCube)
{
itemsToDrop.push_back(item.dwItemID);
}
PickupNextItemToDrop();
return;
}

SetState(State::RunEmptyCube);
server->GameCommandLine("emptycube start chat");
}

void AutoOre::DropNextOreToCube()
Expand All @@ -342,20 +235,11 @@ void AutoOre::DropNextOreToCube()

void AutoOre::OnTick()
{
if (currentState == State::FirstTransmute)
{
// HACK: AE must be delayed a full tick so the autoextract module does not process the item we
// just put in the cube as a transmute result
SetState(State::WaitForFirstTransmuteResults);
numTransmuteResults = 0;
numExpectedTransmuteResults = 2;
me->Transmute();
}
else if (currentState == State::SecondTransmute)
if (currentState == State::Transmute)
{
// HACK: AE must be delayed a full tick so the autoextract module does not process the item we
// just put in the cube as a transmute result
SetState(State::WaitForSecondTransmuteResults);
SetState(State::WaitForTransmuteResults);
numTransmuteResults = 0;
numExpectedTransmuteResults = 2;
me->Transmute();
Expand Down Expand Up @@ -444,7 +328,7 @@ BOOL CALLBACK enumFindCubeItems(LPCITEM item, LPARAM lParam)
{
(*cubeItemCount)++;
}

return TRUE;
}

Expand Down
10 changes: 2 additions & 8 deletions D2Hackit/Modules/autoOre/AutoOre.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ enum class State
DropNextItemToDrop,
PickupNextOre,
DropNextOreToCube,
FirstTransmute,
WaitForFirstTransmuteResults,
PickupGemFromFirstTransmute,
DropGemFromFirstTransmute,

SecondTransmute,
WaitForSecondTransmuteResults,

Transmute,
WaitForTransmuteResults,
RunEmptyCube,
RunAutoStocker,
};
Expand Down
2 changes: 0 additions & 2 deletions D2Hackit/Modules/autoOre/Resources/ore.ini

This file was deleted.

6 changes: 1 addition & 5 deletions D2Hackit/Modules/autoOre/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,12 @@ VOID EXPORT OnUnitMessage(UINT nMessage, LPCGAMEUNIT lpUnit, WPARAM wParam, LPAR

if(wParam == ITEM_ACTION_TO_STORAGE && item.iStorageID == 0x04)
{
autoOre.OnItemDroppedToCube(item);
autoOre.OnItemDroppedToCube(item);
}
else if(wParam == ITEM_ACTION_FROM_STORAGE && item.iStorageID == 0x01)
{
autoOre.OnItemPickedUpFromInventory(item.dwItemID);
}
else if(wParam == ITEM_ACTION_TO_STORAGE && item.iStorageID == 0x01)
{
autoOre.OnItemDroppedToInventory(item);
}
else if(wParam == ITEM_ACTION_FROM_STORAGE && item.iStorageID == 0x04)
{
autoOre.OnItemPickedUpFromCube(item.dwItemID);
Expand Down

0 comments on commit 0c4cb54

Please sign in to comment.