Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to load items using dat file from spr #3159

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,6 @@ metricsPrometheusAddress = "0.0.0.0:9464"
--- OStream
metricsEnableOstream = false
metricsOstreamInterval = 1000

-- NOTE: load items using dat file from old spr and dat cip files, or use default protobuff file if this false
loadItemsFromSprDat = true
Comment on lines +592 to +593
Copy link
Contributor

@murilo09 murilo09 Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- NOTE: load items using dat file from old spr and dat cip files, or use default protobuff file if this false
loadItemsFromSprDat = true
-- NOTE: load items using dat file from old spr and dat cip files, or use default protobuf file if false
loadItemsFromSprDat = false

Binary file added data/items/Tibia.dat
Binary file not shown.
3 changes: 2 additions & 1 deletion src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,6 @@ enum ConfigKey_t : uint16_t {
WHEEL_POINTS_PER_LEVEL,
WHITE_SKULL_TIME,
WORLD_TYPE,
XP_DISPLAY_MODE
XP_DISPLAY_MODE,
LOAD_ITEMS_FROM_SPR_DAT
};
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ bool ConfigManager::load() {
loadBoolConfig(L, VIP_SYSTEM_ENABLED, "vipSystemEnabled", false);
loadBoolConfig(L, WARN_UNSAFE_SCRIPTS, "warnUnsafeScripts", true);
loadBoolConfig(L, XP_DISPLAY_MODE, "experienceDisplayRates", true);
loadBoolConfig(L, LOAD_ITEMS_FROM_SPR_DAT, "loadItemsFromSprDat", false);

loadFloatConfig(L, BESTIARY_RATE_CHARM_SHOP_PRICE, "bestiaryRateCharmShopPrice", 1.0);
loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_AXE, "combatChainSkillFormulaAxe", 0.9);
Expand Down
7 changes: 6 additions & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,12 @@ FILELOADER_ERRORS Game::loadAppearanceProtobuf(const std::string &file) {
}

// Parsing all items into ItemType
Item::items.loadFromProtobuf();
if (g_configManager().getBoolean(LOAD_ITEMS_FROM_SPR_DAT)) {
Item::items.loadFromDat();
}
else {
Item::items.loadFromProtobuf();
}

// Only iterate other objects if necessary
if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS)) {
Expand Down
28 changes: 28 additions & 0 deletions src/io/fileloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ class PropStream {
return true;
}

template <typename T>
T read() {
T ret;
if (size() < sizeof(T)) {
return false;
}

memcpy(&ret, p, sizeof(T));
p += sizeof(T);
return ret;
}

bool readString(std::string &ret) {
uint16_t strLen;
if (!read<uint16_t>(strLen)) {
Expand All @@ -107,6 +119,22 @@ class PropStream {
return true;
}

std::string readString() {
std::string ret;
uint16_t strLen;

if (read<uint16_t>(strLen) && size() >= strLen) {
char* str = new char[strLen + 1];
memcpy(str, p, strLen);
str[strLen] = 0;
ret.assign(str, strLen);
delete[] str;
p += strLen;
}

return ret;
}

bool skip(size_t n) {
if (size() < n) {
return false;
Expand Down
Loading
Loading