* Initial cleanup.

Will now need to cleanup includes, which will take a while ...
This commit is contained in:
iProgramInCpp
2023-08-05 14:21:40 +03:00
parent 3268f0aafc
commit 8b92eced31
10 changed files with 2169 additions and 2318 deletions

View File

@@ -1,280 +0,0 @@
#include "Inventory.hpp"
#include "Item.hpp"
Inventory::Inventory(Player* pPlayer)
{
m_pPlayer = pPlayer;
m_SelectedHotbarSlot = 0;
for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++)
m_hotbar[i] = -1;
}
void Inventory::prepareCreativeInventory()
{
m_bIsSurvival = false;
m_items.clear();
addCreativeItem(Tile::rock->m_ID);
addCreativeItem(Tile::stoneBrick->m_ID);
addCreativeItem(Tile::sandStone->m_ID);
addCreativeItem(Tile::wood->m_ID);
addCreativeItem(Tile::treeTrunk->m_ID);
addCreativeItem(Tile::goldBlock->m_ID);
addCreativeItem(Tile::ironBlock->m_ID);
addCreativeItem(Tile::emeraldBlock->m_ID);
addCreativeItem(Tile::redBrick->m_ID);
addCreativeItem(Tile::leaves->m_ID);
addCreativeItem(Tile::cloth_10->m_ID);
addCreativeItem(Tile::cloth_20->m_ID);
addCreativeItem(Tile::cloth_30->m_ID);
addCreativeItem(Tile::cloth_40->m_ID);
addCreativeItem(Tile::cloth_50->m_ID);
addCreativeItem(Tile::cloth_60->m_ID);
addCreativeItem(Tile::cloth_70->m_ID);
addCreativeItem(Tile::glass->m_ID);
addCreativeItem(Tile::cloth_01->m_ID);
addCreativeItem(Tile::cloth_11->m_ID);
addCreativeItem(Tile::cloth_21->m_ID);
addCreativeItem(Tile::cloth_31->m_ID);
addCreativeItem(Tile::cloth_41->m_ID);
addCreativeItem(Tile::stairs_wood->m_ID);
addCreativeItem(Tile::stairs_stone->m_ID);
addCreativeItem(Tile::stoneSlabHalf->m_ID);
addCreativeItem(Tile::sand->m_ID);
addCreativeItem(Tile::ladder->m_ID);
addCreativeItem(Tile::torch->m_ID);
addCreativeItem(Tile::flower->m_ID);
addCreativeItem(Tile::rose->m_ID);
addCreativeItem(Tile::mushroom1->m_ID);
addCreativeItem(Tile::mushroom2->m_ID);
addCreativeItem(Tile::reeds->m_ID);
addCreativeItem(Tile::obsidian->m_ID);
addCreativeItem(Tile::dirt->m_ID);
addCreativeItem(Tile::tnt->m_ID);
addCreativeItem(Tile::gravel->m_ID);
addCreativeItem(Tile::cloth->m_ID);
addCreativeItem(Tile::mossStone->m_ID);
addCreativeItem(Tile::bookshelf->m_ID);
addCreativeItem(Tile::sponge->m_ID);
addCreativeItem(Tile::sapling->m_ID);
addCreativeItem(Tile::water->m_ID);
addCreativeItem(Tile::lava->m_ID);
addCreativeItem(Tile::fire->m_ID);
addCreativeItem(Item::camera->m_itemID);
addCreativeItem(Item::door_wood->m_itemID);
addCreativeItem(Item::door_iron->m_itemID);
for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++)
m_hotbar[i] = i;
}
void Inventory::prepareSurvivalInventory()
{
m_bIsSurvival = true;
m_items.clear();
m_items.resize(C_NUM_SURVIVAL_SLOTS);
// Add some items for testing
addTestItem(Item::stick->m_itemID, 64);
addTestItem(Item::wheat->m_itemID, 64);
addTestItem(Item::sugar->m_itemID, 64);
addTestItem(Item::camera->m_itemID, 64);
for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++)
m_hotbar[i] = i;
}
int Inventory::getNumSlots()
{
if (m_bIsSurvival)
return C_NUM_SURVIVAL_SLOTS;
return getNumItems();
}
int Inventory::getNumItems()
{
return int(m_items.size());
}
void Inventory::addCreativeItem(int itemID, int auxValue)
{
m_items.emplace_back(ItemInstance(itemID, 1, auxValue));
}
void Inventory::clear()
{
m_items.clear();
m_items.resize(C_NUM_SURVIVAL_SLOTS);
}
void Inventory::addItem(ItemInstance* pInst)
{
if (!m_bIsSurvival)
{
// Just get rid of the item.
pInst->m_amount = 0;
return;
}
// look for an item with the same ID
for (int i = 0; i < getNumItems(); i++)
{
if (m_items[i].m_itemID != pInst->m_itemID)
continue;
int maxStackSize = m_items[i].getMaxStackSize();
bool bIsStackedByData = Item::items[pInst->m_itemID]->isStackedByData();
if (bIsStackedByData && m_items[i].m_auxValue != pInst->m_auxValue)
continue;
// try to collate.
int combinedItemAmount = pInst->m_amount + m_items[i].m_amount;
int leftover = combinedItemAmount - maxStackSize;
if (leftover < 0)
leftover = 0;
else
combinedItemAmount = C_MAX_AMOUNT;
m_items[i].m_amount = combinedItemAmount;
pInst->m_amount = leftover;
if (!bIsStackedByData)
m_items[i].m_auxValue = 0;
}
// If there's nothing leftover:
if (!pInst->m_amount)
return;
// try to add it to an empty slot
for (int i = 0; i < getNumItems(); i++)
{
if (m_items[i].m_itemID != 0)
continue;
m_items[i] = *pInst;
pInst->m_amount = 0;
return;
}
}
void Inventory::addTestItem(int itemID, int amount, int auxValue)
{
ItemInstance inst(itemID, amount, auxValue);
addItem(&inst);
if (inst.m_amount != 0)
{
LogMsg("AddTestItem: Couldn't add all %d of %s, only gave %d",
amount, Item::items[itemID]->m_DescriptionID.c_str(), amount - inst.m_amount);
}
}
ItemInstance* Inventory::getItem(int slotNo)
{
if (slotNo < 0 || slotNo >= int(m_items.size()))
return nullptr;
if (m_items[slotNo].m_amount <= 0)
m_items[slotNo].m_itemID = 0;
return &m_items[slotNo];
}
int Inventory::getQuickSlotItemId(int slotNo)
{
if (slotNo < 0 || slotNo >= C_MAX_HOTBAR_ITEMS)
return -1;
int idx = m_hotbar[slotNo];
ItemInstance* pInst = getItem(idx);
if (!pInst)
return -1;
return pInst->m_itemID;
}
ItemInstance* Inventory::getQuickSlotItem(int slotNo)
{
if (slotNo < 0 || slotNo >= C_MAX_HOTBAR_ITEMS)
return nullptr;
return getItem(m_hotbar[slotNo]);
}
ItemInstance* Inventory::getSelectedItem()
{
return getQuickSlotItem(m_SelectedHotbarSlot);
}
int Inventory::getSelectedItemId()
{
return getQuickSlotItemId(m_SelectedHotbarSlot);
}
void Inventory::selectItem(int slotNo)
{
if (slotNo < 0 || slotNo >= getNumItems())
return;
// look for it in the hotbar
for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++)
{
if (m_hotbar[i] == slotNo)
{
m_SelectedHotbarSlot = i;
return;
}
}
for (int i = C_MAX_HOTBAR_ITEMS - 2; i >= 0; i--)
m_hotbar[i + 1] = m_hotbar[i];
m_hotbar[0] = slotNo;
m_SelectedHotbarSlot = 0;
}
void Inventory::selectSlot(int slotNo)
{
if (slotNo < 0 || slotNo >= C_MAX_HOTBAR_ITEMS)
return;
m_SelectedHotbarSlot = slotNo;
}
void Inventory::setQuickSlotIndexByItemId(int slotNo, int itemID)
{
if (slotNo < 0 || slotNo >= C_MAX_HOTBAR_ITEMS)
return;
if (m_bIsSurvival)
return; // TODO
for (int i = 0; i < getNumItems(); i++)
{
if (m_items[i].m_itemID == itemID)
{
m_hotbar[slotNo] = i;
return;
}
}
m_hotbar[slotNo] = -1;
}
void Inventory::selectItemById(int itemID)
{
for (int i = 0; i < getNumItems(); i++)
{
if (m_items[i].m_itemID != itemID)
continue;
selectItem(i);
return;
}
}

View File

@@ -1,53 +0,0 @@
#pragma once
#include "Player.hpp"
#include "ItemInstance.hpp"
class Player; // in case we're included from Player.hpp
#define C_MAX_HOTBAR_ITEMS (9)
#define C_NUM_SURVIVAL_SLOTS (36)
#define C_MAX_AMOUNT (64)
class Inventory
{
public:
Inventory(Player*);
void prepareCreativeInventory();
void prepareSurvivalInventory();
int getNumSlots();
int getNumItems();
void addCreativeItem(int itemID, int auxValue = 0);
void addTestItem(int itemID, int amount, int auxValue = 0);
void clear();
void addItem(ItemInstance* pInst);
ItemInstance* getItem(int slotNo);
ItemInstance* getQuickSlotItem(int slotNo);
ItemInstance* getSelectedItem();
int getQuickSlotItemId(int slotNo);
int getSelectedItemId();
void selectItem(int slotNo); // selects an item by slot number and puts it in the quick slots if needed
void selectSlot(int slotNo);
void setQuickSlotIndexByItemId(int slotNo, int itemID);
void selectItemById(int itemID);
int getSelectedSlotNo() const
{
return m_SelectedHotbarSlot;
}
public:
int m_SelectedHotbarSlot = 0;
private:
Player* m_pPlayer = nullptr;
bool m_bIsSurvival = false;
int m_hotbar[C_MAX_HOTBAR_ITEMS];
std::vector<ItemInstance> m_items;
};

View File

@@ -1,169 +0,0 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "Options.hpp"
#include "Util.hpp"
#include "compat/AKeyCodes.hpp"
#include "Minecraft.hpp"
Options::Option
Options::Option::MUSIC (0, "options.music", true, false),
Options::Option::SOUND (1, "options.sound", true, false),
Options::Option::INVERT_MOUSE (2, "options.invertMouse", false, true),
Options::Option::SENSITIVITY (3, "options.sensitivity", true, false),
Options::Option::RENDER_DISTANCE (4, "options.renderDistance", false, false),
Options::Option::VIEW_BOBBING (5, "options.viewBobbing", false, true),
Options::Option::ANAGLYPH (6, "options.anaglyph", false, true),
Options::Option::LIMIT_FRAMERATE (7, "options.limitFramerate", false, true),
Options::Option::DIFFICULTY (8, "options.difficulty", false, false),
Options::Option::GRAPHICS (9, "options.graphics", false, false),
Options::Option::AMBIENT_OCCLUSION(10, "options.ao", false, true),
Options::Option::GUI_SCALE (11, "options.guiScale", false, false);
void Options::initDefaultValues()
{
field_238 = 2;
field_244 = 1.0f;
field_23C = 0;
field_248 = 1.0f;
field_23D = 0; // @NOTE: third person?
field_0 = 1.0f;
field_23E = 0;
field_4 = 1.0f;
m_bFlyCheat = false;
field_241 = 0;
field_8 = 0.5f;
field_24C = 0;
m_bInvertMouse = false;
m_bAnaglyphs = false;
field_16 = 0;
#ifdef ORIGINAL_CODE
field_18 = 0;
#else
field_18 = Minecraft::useAmbientOcclusion;
#endif
field_240 = 1;
field_10 = 2;
field_14 = 1;
m_bFancyGraphics = true;
field_19 = 1;
field_1C = "Default";
m_playerName = "Steve";
m_bServerVisibleDefault = true;
m_keyBinds[0] = { "key.forward", 'W' };
m_keyBinds[1] = { "key.left", 'A' };
m_keyBinds[2] = { "key.back", 'S' };
m_keyBinds[3] = { "key.right", 'D' };
m_keyBinds[4] = { "key.jump", ' ' };
m_keyBinds[5] = { "key.inventory", 'E' };
m_keyBinds[6] = { "key.drop", 'Q' };
m_keyBinds[7] = { "key.chat", 'T' };
m_keyBinds[8] = { "key.fog", 'F' };
m_keyBinds[9] = { "key.sneak", '\n' };
m_keyBinds[10] = { "key.destroy", 'X' };
m_keyBinds[11] = { "key.place", 'C' };
m_keyBinds[12] = { "key.menu.next", '(' };
m_keyBinds[13] = { "key.menu.previous", '&' };
m_keyBinds[14] = { "key.menu.ok", '\r' };
m_keyBinds[15] = { "key.menu.cancel", '\b' };
#ifdef ORIGINAL_CODE
field_10 = 2;
field_23D = 0;
field_19 = 0;
#endif
m_bFancyGraphics = 1;
// keybind now reprograms some the keybinds.
// For the restoration, we don't actually need them
m_keyBinds[0].value = AKEYCODE_DPAD_UP;
m_keyBinds[1].value = AKEYCODE_DPAD_LEFT;
m_keyBinds[2].value = AKEYCODE_DPAD_DOWN;
m_keyBinds[3].value = AKEYCODE_DPAD_RIGHT;
m_keyBinds[4].value = AKEYCODE_DPAD_CENTER; // lmao, how stupid.
m_keyBinds[10].value = AKEYCODE_BUTTON_L1;
m_keyBinds[11].value = AKEYCODE_BUTTON_R1;
m_keyBinds[12].value = AKEYCODE_DPAD_DOWN;
m_keyBinds[13].value = AKEYCODE_DPAD_UP;
m_keyBinds[14].value = AKEYCODE_DPAD_CENTER;
m_keyBinds[15].value = AKEYCODE_BACK;
#ifndef ORIGINAL_CODE
m_keyBinds[9].value = AKEYCODE_SHIFT_LEFT;
#endif
}
Options::Options()
{
initDefaultValues();
}
std::string getMessage(const Options::Option& option)
{
return "Options::getMessage - Not implemented";
}
void Options::load()
{
// stub
}
void Options::save()
{
// stub
}
std::string Options::getMessage(const Options::Option& option)
{
return "Options::getMessage - Not implemented";
}
bool Options::readBool(const std::string& str)
{
std::string trimmed = Util::stringTrim(str);
if (trimmed == "true" || trimmed == "1")
return true;
if (trimmed == "false" || trimmed == "0")
return false;
return false;
}
#ifndef ORIGINAL_CODE
int Options::readInt(const std::string& str)
{
int f;
if (!sscanf(str.c_str(), "%d", &f))
f = 0;
return f;
}
#endif
void Options::update(const std::vector<std::string>& strings)
{
for (int i = 0; i<int(strings.size()); i += 2)
{
std::string key = strings[i], value = strings[i + 1];
if (key == "mp_username")
m_playerName = value;
else if (key == "ctrl_invertmouse")
m_bInvertMouse = readBool(value);
else if (key == "gfx_fancygraphics")
m_bFancyGraphics = readBool(value);
else if (key == "mp_server_visible_default")
m_bServerVisibleDefault = readBool(value);
#ifndef ORIGINAL_CODE
else if (key == "gfx_smoothlighting")
Minecraft::useAmbientOcclusion = field_18 = readBool(value);
else if (key == "gfx_viewdistance")
field_10 = readInt(value);
#endif
}
}

View File

@@ -1,110 +0,0 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#pragma once
#include <string>
#include <vector>
class Options
{
public:
struct Option;
struct KeyBind;
public:
Options();
void initDefaultValues();
void load();
void save();
std::string getMessage(const Options::Option&);
void update(const std::vector<std::string>& string);
public:
static bool readBool(const std::string& str);
#ifndef ORIGINAL_CODE
static int readInt(const std::string& str);
#endif
public:
enum KeyBindIndex
{
FORWARD,
LEFT,
BACK,
RIGHT,
JUMP,
INVENTORY,
DROP,
CHAT,
FOG,
SNEAK,
DESTROY,
PLACE,
MENU_NEXT,
MENU_PREVIOUS,
MENU_OK,
MENU_CANCEL,
};
struct KeyBind {
std::string key;
int value;
};
struct Option
{
bool field_0;
bool field_1;
std::string str;
int field_1C;
Option(int i, const std::string& str, bool b1, bool b2) : field_0(b1), field_1(b2), str(str), field_1C(i) {}
static Option MUSIC;
static Option SOUND;
static Option INVERT_MOUSE;
static Option SENSITIVITY;
static Option RENDER_DISTANCE;
static Option VIEW_BOBBING;
static Option ANAGLYPH;
static Option LIMIT_FRAMERATE;
static Option DIFFICULTY;
static Option GRAPHICS;
static Option AMBIENT_OCCLUSION;
static Option GUI_SCALE;
};
public:
float field_0;
float field_4;
float field_8;
bool m_bInvertMouse;
int field_10; // @NOTE: Render distance?
bool field_14;
bool m_bAnaglyphs;
uint8_t field_16;
bool m_bFancyGraphics;
uint8_t field_18; // @NOTE: Ambient occlusion?
uint8_t field_19;
std::string field_1C;
KeyBind m_keyBinds[16];
int field_238;
uint8_t field_23C;
uint8_t field_23D; // @NOTE: Third person mode?
uint8_t field_23E;
bool m_bFlyCheat;
uint8_t field_240;
uint8_t field_241;
float field_244;
float field_248;
int field_24C;
std::string m_playerName;
bool m_bServerVisibleDefault;
};