Skip to content

Commit

Permalink
feat: compatibility with 13.20 and 13.21
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosvf132 authored Sep 16, 2023
1 parent 9b903f1 commit 2e8ac80
Show file tree
Hide file tree
Showing 17 changed files with 353 additions and 147 deletions.
2 changes: 1 addition & 1 deletion data/setup.otml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
game
sprite-size: 32
last-supported-version: 1316
last-supported-version: 1321

map
viewport: 8 6
Expand Down
16 changes: 16 additions & 0 deletions modules/game_features/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ controller:registerEvents(g_game, {

if version >= 1094 then
g_game.enableFeature(GameAdditionalSkills);
g_game.enableFeature(GameLeechAmount);
end

if version >= 1200 then
Expand Down Expand Up @@ -217,5 +218,20 @@ controller:registerEvents(g_game, {
g_game.disableFeature(GameTournamentPackets);
g_game.enableFeature(GameDynamicForgeVariables);
end

if version >= 1320 then
g_game.enableFeature(GameEffectU16);
g_game.enableFeature(GameContainerTypes);
g_game.enableFeature(GameBosstiaryTracker);
g_game.enableFeature(GamePlayerStateCounter);
g_game.disableFeature(GameLeechAmount);
g_game.enableFeature(GameItemAugment);
g_game.enableFeature(GameDynamicBugReporter);
end

if version >= 1321 then
g_game.enableFeature(GameWrapKit);
g_game.enableFeature(GameContainerFilter);
end
end
})
9 changes: 9 additions & 0 deletions modules/gamelib/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ GameItemShader = 101
GameCreatureShader = 102
GameCreatureAttachedEffect = 103
GameCountU16 = 104
GameEffectU16 = 105
GameContainerTypes = 106
GameBosstiaryTracker = 107
GamePlayerStateCounter = 108
GameLeechAmount = 109
GameItemAugment = 110
GameDynamicBugReporter = 111
GameWrapKit = 112
GameContainerFilter = 113

TextColors = {
red = '#f55e5e', -- '#c83200'
Expand Down
2 changes: 1 addition & 1 deletion modules/gamelib/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function g_game.getSupportedClients()
1012, 1013, 1020, 1021, 1022, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1050,
1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1070, 1071, 1072, 1073,
1074, 1075, 1076, 1080, 1081, 1082, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1281, 1285,
1286, 1287, 1291, 1300, 1314, 1316 }
1286, 1287, 1291, 1300, 1314, 1316, 1320, 1321 }
end

-- The client version and protocol version where
Expand Down
30 changes: 16 additions & 14 deletions modules/gamelib/market.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ MarketItemDescription = {
Charges = 13,
WeaponName = 14,
Weight = 15,
ImbuingSlots = 16,
MagicShield = 17,
Cleave = 18,
Reflection = 19,
Perfect = 20,
UpgradeClassification = 21,
CurrentTier = 22
Augment = 16,
ImbuingSlots = 17,
MagicShield = 18,
Cleave = 19,
Reflection = 20,
Perfect = 21,
UpgradeClassification = 22,
CurrentTier = 23
}

MarketItemDescription.First = MarketItemDescription.Armor
Expand All @@ -169,13 +170,14 @@ MarketItemDescriptionStrings = {
[13] = 'Charges',
[14] = 'Weapon Type',
[15] = 'Weight',
[16] = 'Imbuing Slots',
[17] = 'Magic Shield',
[18] = 'Cleave',
[19] = 'Reflection',
[20] = 'Perfect Show',
[21] = 'Upgrade Classification',
[22] = 'Tier'
[16] = 'Augment',
[17] = 'Imbuing Slots',
[18] = 'Magic Shield',
[19] = 'Cleave',
[20] = 'Reflection',
[21] = 'Perfect Show',
[22] = 'Upgrade Classification',
[23] = 'Tier'
}

function getMarketDescriptionName(id)
Expand Down
26 changes: 18 additions & 8 deletions src/client/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,16 @@ namespace Otc
GameCreatureShader = 102,
GameCreatureAttachedEffect = 103,
GameCountU16 = 104,
LastGameFeature = 105
GameEffectU16 = 105,
GameContainerTypes = 106,
GameBosstiaryTracker = 107,
GamePlayerStateCounter = 108,
GameLeechAmount = 109,
GameItemAugment = 110,
GameDynamicBugReporter = 111,
GameWrapKit = 112,
GameContainerFilter = 113,
LastGameFeature = 114
};

enum MagicEffectsType_t : uint8_t
Expand Down Expand Up @@ -668,13 +677,14 @@ namespace Otc
ITEM_DESC_CHARGES = 13,
ITEM_DESC_WEAPONTYPE = 14,
ITEM_DESC_WEIGHT = 15,
ITEM_DESC_IMBUINGSLOTS = 16,
ITEM_DESC_MAGICSHIELD = 17,
ITEM_DESC_CLEAVE = 18,
ITEM_DESC_REFLECTION = 19,
ITEM_DESC_PERFECT = 20,
ITEM_DESC_UPGRADECLASS = 21,
ITEM_DESC_CURRENTTIER = 22,
ITEM_DESC_AUGMENT = 16,
ITEM_DESC_IMBUINGSLOTS = 17,
ITEM_DESC_MAGICSHIELD = 18,
ITEM_DESC_CLEAVE = 19,
ITEM_DESC_REFLECTION = 20,
ITEM_DESC_PERFECT = 21,
ITEM_DESC_UPGRADECLASS = 22,
ITEM_DESC_CURRENTTIER = 23,

ITEM_DESC_FIRST = ITEM_DESC_ARMOR,
ITEM_DESC_LAST = ITEM_DESC_CURRENTTIER,
Expand Down
2 changes: 1 addition & 1 deletion src/client/gameconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class GameConfig

// Game
uint8_t m_spriteSize{ 32 };
uint16_t m_lastSupportedVersion{ 1291 };
uint16_t m_lastSupportedVersion{ 1321 };

// Map
Size m_mapViewPort{ 8,6 };
Expand Down
1 change: 1 addition & 0 deletions src/client/protocolcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Proto
GameServerLoginSuccess = 23,
GameServerSessionEnd = 24,
GameServerStoreButtonIndicators = 25, // 1097
GameServerBugReport = 26,
GameServerPingBack = 29,
GameServerPing = 30,
GameServerChallenge = 31,
Expand Down
1 change: 1 addition & 0 deletions src/client/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class ProtocolGame : public Protocol
void parseCreatureType(const InputMessagePtr& msg);
void parsePlayerHelpers(const InputMessagePtr& msg) const;
void parseMessage(const InputMessagePtr& msg);
void parseBugReport(const InputMessagePtr& msg);
void parsePendingGame(const InputMessagePtr& msg);
void parseEnterGame(const InputMessagePtr& msg);
void parseLogin(const InputMessagePtr& msg) const;
Expand Down
103 changes: 91 additions & 12 deletions src/client/protocolgameparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg)
else
parseLogin(msg);
break;
case Proto::GameServerBugReport:
parseBugReport(msg);
break;
case Proto::GameServerGMActions:
parseGMActions(msg);
break;
Expand Down Expand Up @@ -583,7 +586,10 @@ void ProtocolGame::parseLogin(const InputMessagePtr& msg) const
Creature::speedC = msg->getDouble();
}

const bool canReportBugs = msg->getU8();
bool canReportBugs = false;
if (!g_game.getFeature(Otc::GameDynamicBugReporter)) {
canReportBugs = msg->getU8() > 0;
}

if (g_game.getClientVersion() >= 1054)
msg->getU8(); // can change pvp frame option
Expand Down Expand Up @@ -616,6 +622,12 @@ void ProtocolGame::parseLogin(const InputMessagePtr& msg) const
Game::processLogin();
}

void ProtocolGame::parseBugReport(const InputMessagePtr& msg)
{
const bool canReportBugs = msg->getU8() > 0;
g_game.setCanReportBugs(canReportBugs);
}

void ProtocolGame::parsePendingGame(const InputMessagePtr&)
{
//set player to pending game state
Expand Down Expand Up @@ -1109,6 +1121,15 @@ void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg)
for (int_fast32_t i = -1; ++i < itemCount;)
items[i] = getItem(msg);

if (g_game.getFeature(Otc::GameContainerFilter)) {
msg->getU8();
const uint8_t listSize = msg->getU8();
for (int_fast8_t i = -1; ++i < listSize;) {
msg->getU8();
msg->getString();
}
}

g_game.processOpenContainer(containerId, containerItem, name, capacity, hasParent, items, isUnlocked, hasPages, containerSize, firstIndex);
}

Expand Down Expand Up @@ -1292,7 +1313,12 @@ void ProtocolGame::parseMagicEffect(const InputMessagePtr& msg)

case Otc::MAGIC_EFFECTS_CREATE_DISTANCEEFFECT:
case Otc::MAGIC_EFFECTS_CREATE_DISTANCEEFFECT_REVERSED: {
const uint8_t shotId = msg->getU8();
uint16_t shotId;
if (g_game.getFeature(Otc::GameEffectU16)) {
shotId = msg->getU16();
} else {
shotId = msg->getU8();
}
const int8_t offsetX = static_cast<int8_t>(msg->getU8());
const int8_t offsetY = static_cast<int8_t>(msg->getU8());
if (!g_things.isValidDatId(shotId, ThingCategoryMissile)) {
Expand All @@ -1313,7 +1339,12 @@ void ProtocolGame::parseMagicEffect(const InputMessagePtr& msg)
}

case Otc::MAGIC_EFFECTS_CREATE_EFFECT: {
const uint8_t effectId = msg->getU8();
uint16_t effectId;
if (g_game.getFeature(Otc::GameEffectU16)) {
effectId = msg->getU16();
} else {
effectId = msg->getU8();
}
if (!g_things.isValidDatId(effectId, ThingCategoryEffect)) {
g_logger.traceError(stdext::format("invalid effect id %d", effectId));
continue;
Expand Down Expand Up @@ -1833,6 +1864,12 @@ void ProtocolGame::parsePlayerSkills(const InputMessagePtr& msg) const

const uint8_t lastSkill = g_game.getClientVersion() >= 1281 ? Otc::LastSkill : Otc::ManaLeechAmount + 1;
for (int_fast32_t skill = Otc::CriticalChance; skill < lastSkill; ++skill) {
if (!g_game.getFeature(Otc::GameLeechAmount)) {
if (skill == Otc::LifeLeechAmount || skill == Otc::ManaLeechAmount) {
continue;
}
}

const uint16_t level = msg->getU16();
const uint16_t baseLevel = msg->getU16();
m_localPlayer->setSkill(static_cast<Otc::Skill>(skill), level, 0);
Expand All @@ -1855,6 +1892,8 @@ void ProtocolGame::parsePlayerState(const InputMessagePtr& msg) const

if (g_game.getClientVersion() >= 1281) {
states = msg->getU32();
if (g_game.getFeature(Otc::GamePlayerStateCounter))
msg->getU8();
} else {
if (g_game.getFeature(Otc::GamePlayerStateU16))
states = msg->getU16();
Expand Down Expand Up @@ -2886,17 +2925,43 @@ ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id)
}

if (item->isContainer()) {
if (g_game.getFeature(Otc::GameThingQuickLoot)) {
const bool hasQuickLootFlags = msg->getU8() != 0;
if (hasQuickLootFlags) {
msg->getU32(); // quick loot flags
if (g_game.getFeature(Otc::GameContainerTypes)) {
const uint8_t type = msg->getU8();
switch (type) {
case 0: // Empty
break;
case 1: {
if (g_game.getFeature(Otc::GameThingQuickLoot)) {
msg->getU32(); // quick loot flags
}
break;
}
case 2: {
if (g_game.getFeature(Otc::GameThingQuiver)) {
msg->getU32(); // ammoTotal
}
break;
}
case 4: // Empty (Loot highlight boolean)
break;
default: {
throw Exception("unknown container type %d", type);
break;
}
}
} else {
if (g_game.getFeature(Otc::GameThingQuickLoot)) {
const bool hasQuickLootFlags = msg->getU8() != 0;
if (hasQuickLootFlags) {
msg->getU32(); // quick loot flags
}
}
}

if (g_game.getFeature(Otc::GameThingQuiver)) {
const uint8_t hasQuiverAmmoCount = msg->getU8();
if (hasQuiverAmmoCount) {
msg->getU32(); // ammoTotal
if (g_game.getFeature(Otc::GameThingQuiver)) {
const uint8_t hasQuiverAmmoCount = msg->getU8();
if (hasQuiverAmmoCount) {
msg->getU32(); // ammoTotal
}
}
}
}
Expand All @@ -2921,6 +2986,12 @@ ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id)
}
}

if (g_game.getFeature(Otc::GameWrapKit)) {
if (item->isDecoKit()) {
msg->getU16();
}
}

if (g_game.getFeature(Otc::GameItemAnimationPhase)) {
if (item->getAnimationPhases() > 1) {
// 0x00 => automatic phase
Expand Down Expand Up @@ -2982,6 +3053,10 @@ void ProtocolGame::parseShowDescription(const InputMessagePtr& msg)

void ProtocolGame::parseBestiaryTracker(const InputMessagePtr& msg)
{
if (g_game.getFeature(Otc::GameBosstiaryTracker)) {
msg->getU8(); // is bestiary boolean
}

const uint8_t size = msg->getU8();
for (uint8_t i = 0; i < size; i++) {
msg->getU16(); // RaceID
Expand Down Expand Up @@ -3613,6 +3688,10 @@ void ProtocolGame::parseMarketDetail(const InputMessagePtr& msg)
lastAttribute = Otc::ITEM_DESC_LAST;

for (int_fast32_t i = Otc::ITEM_DESC_FIRST; i <= lastAttribute; i++) {
if (i == Otc::ITEM_DESC_AUGMENT && !g_game.getFeature(Otc::GameItemAugment)) {
continue;
}

if (msg->peekU16() != 0x00) {
const auto& sentString = msg->getString();
descriptions.try_emplace(i, sentString);
Expand Down
3 changes: 3 additions & 0 deletions src/client/protocolgamesend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,9 @@ void ProtocolGame::sendSeekInContainer(int cid, int index)
msg->addU8(Proto::ClientSeekInContainer);
msg->addU8(cid);
msg->addU16(index);
if (g_game.getFeature(Otc::GameContainerFilter)) {
msg->addU8(0); // Filter
}
send(msg);
}

Expand Down
1 change: 1 addition & 0 deletions src/client/thing.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Thing : public LuaObject
bool hasExpire() const { return m_thingType->hasExpire(); }
bool hasExpireStop() const { return m_thingType->hasExpireStop(); }
bool hasAnimationPhases() const { return m_thingType->getAnimationPhases() > 1; }
bool isDecoKit() const { return m_thingType->isDecoKit(); }

PLAYER_ACTION getDefaultAction() { return m_thingType->getDefaultAction(); }

Expand Down
Loading

0 comments on commit 2e8ac80

Please sign in to comment.