Skip to content

Commit

Permalink
Started 1050 implementation and fix ups:
Browse files Browse the repository at this point in the history
* Dat now loads (new animations aren't yet functional).
* Fixed the way we reference client versions.

TODO: Write new animation functionality & find out protocol changes.
  • Loading branch information
BenDol committed Aug 2, 2014
1 parent fe585d2 commit d7429c2
Show file tree
Hide file tree
Showing 31 changed files with 316 additions and 121 deletions.
6 changes: 3 additions & 3 deletions modules/client_entergame/entergame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end

local function onCharacterList(protocol, characters, account, otui)
-- Try add server to the server list
ServerList.add(G.host, G.port, g_game.getProtocolVersion())
ServerList.add(G.host, G.port, g_game.getClientVersion())

if enterGame:getChildById('rememberPasswordBox'):isChecked() then
local account = g_crypt.encrypt(G.account)
Expand Down Expand Up @@ -82,7 +82,7 @@ local function onUpdateNeeded(protocol, signature)
local cancelFunc = EnterGame.show
EnterGame.updateFunc(signature, continueFunc, cancelFunc)
else
local errorBox = displayErrorBox(tr('Update needed'), tr('Your client needs update, try redownloading it.'))
local errorBox = displayErrorBox(tr('Update needed'), tr('Your client needs updating, try redownloading it.'))
connect(errorBox, { onOk = EnterGame.show })
end
end
Expand Down Expand Up @@ -242,7 +242,7 @@ function EnterGame.doLogin()

g_game.chooseRsa(G.host)
g_game.setClientVersion(clientVersion)
g_game.setProtocolVersion(g_game.getProtocolVersionForClient(clientVersion))
g_game.setProtocolVersion(g_game.getClientProtocolVersion(clientVersion))

if modules.game_things.isLoaded() then
protocolLogin:login(G.host, G.port, G.account, G.password)
Expand Down
6 changes: 3 additions & 3 deletions modules/game_console/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ end

function openHelp()
local helpChannel = 9
if g_game.getProtocolVersion() <= 810 then
if g_game.getClientVersion() <= 810 then
helpChannel = 8
end
g_game.joinChannel(helpChannel)
Expand Down Expand Up @@ -1236,7 +1236,7 @@ function online()
defaultTab = addTab(tr('Default'), true)
serverTab = addTab(tr('Server Log'), false)

if g_game.getProtocolVersion() < 862 then
if g_game.getClientVersion() < 862 then
g_keyboard.bindKeyDown('Ctrl+R', openPlayerReportRuleViolationWindow)
end
-- open last channels
Expand All @@ -1259,7 +1259,7 @@ function online()
end

function offline()
if g_game.getProtocolVersion() < 862 then
if g_game.getClientVersion() < 862 then
g_keyboard.unbindKeyDown('Ctrl+R')
end
clear()
Expand Down
10 changes: 5 additions & 5 deletions modules/game_hotkeys/hotkeys_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ function doKeyCombo(keyCombo)
modules.game_console.setTextEditText(hotKey.value)
end
elseif hotKey.useType == HOTKEY_MANAGER_USE then
if g_game.getProtocolVersion() < 780 or hotKey.subType then
if g_game.getClientVersion() < 780 or hotKey.subType then
local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if item then
g_game.use(item)
Expand All @@ -391,7 +391,7 @@ function doKeyCombo(keyCombo)
g_game.useInventoryItem(hotKey.itemId)
end
elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
if g_game.getProtocolVersion() < 780 or hotKey.subType then
if g_game.getClientVersion() < 780 or hotKey.subType then
local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if item then
g_game.useWith(item, g_game.getLocalPlayer())
Expand All @@ -403,7 +403,7 @@ function doKeyCombo(keyCombo)
local attackingCreature = g_game.getAttackingCreature()
if not attackingCreature then
local item = Item.create(hotKey.itemId)
if g_game.getProtocolVersion() < 780 or hotKey.subType then
if g_game.getClientVersion() < 780 or hotKey.subType then
local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if not tmpItem then return end
item = tmpItem
Expand All @@ -414,7 +414,7 @@ function doKeyCombo(keyCombo)
end

if not attackingCreature:getTile() then return end
if g_game.getProtocolVersion() < 780 or hotKey.subType then
if g_game.getClientVersion() < 780 or hotKey.subType then
local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if item then
g_game.useWith(item, attackingCreature)
Expand All @@ -424,7 +424,7 @@ function doKeyCombo(keyCombo)
end
elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
local item = Item.create(hotKey.itemId)
if g_game.getProtocolVersion() < 780 or hotKey.subType then
if g_game.getClientVersion() < 780 or hotKey.subType then
local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
if not tmpItem then return true end
item = tmpItem
Expand Down
4 changes: 2 additions & 2 deletions modules/game_market/marketprotocol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ end
-- parsing protocols
local function parseMarketEnter(protocol, msg)
local balance
if g_game.getProtocolVersion() >= 973 then
if g_game.getClientVersion() >= 981 then
balance = msg:getU64()
else
balance = msg:getU32()
end

local vocation = -1
if g_game.getProtocolVersion() < 950 then
if g_game.getClientVersion() < 950 then
vocation = msg:getU8() -- get vocation id
end
local offers = msg:getU8()
Expand Down
11 changes: 6 additions & 5 deletions modules/game_minimap/minimap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ oldZoom = nil
oldPos = nil

function init()
minimapButton = modules.client_topmenu.addRightGameToggleButton('minimapButton', tr('Minimap') .. ' (Ctrl+M)', '/images/topbuttons/minimap', toggle)
minimapButton = modules.client_topmenu.addRightGameToggleButton('minimapButton',
tr('Minimap') .. ' (Ctrl+M)', '/images/topbuttons/minimap', toggle)
minimapButton:setOn(true)

minimapWindow = g_ui.loadUI('minimap', modules.game_interface.getRightPanel())
Expand Down Expand Up @@ -95,7 +96,7 @@ function offline()
end

function loadMap(clean)
local protocolVersion = g_game.getProtocolVersion()
local clientVersion = g_game.getClientVersion()

if clean then
g_minimap.clean()
Expand All @@ -107,7 +108,7 @@ function loadMap(clean)
g_minimap.loadOtmm(minimapFile)
end
else
local minimapFile = '/minimap_' .. protocolVersion .. '.otcm'
local minimapFile = '/minimap_' .. clientVersion .. '.otcm'
if g_resources.fileExists(minimapFile) then
g_map.loadOtcm(minimapFile)
end
Expand All @@ -116,12 +117,12 @@ function loadMap(clean)
end

function saveMap()
local protocolVersion = g_game.getProtocolVersion()
local clientVersion = g_game.getClientVersion()
if otmm then
local minimapFile = '/minimap.otmm'
g_minimap.saveOtmm(minimapFile)
else
local minimapFile = '/minimap_' .. protocolVersion .. '.otcm'
local minimapFile = '/minimap_' .. clientVersion .. '.otcm'
g_map.saveOtcm(minimapFile)
end
minimapWidget:save()
Expand Down
2 changes: 1 addition & 1 deletion modules/game_spelllist/spelllist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function online()
end

-- Vocation is only send in newer clients
if g_game.getProtocolVersion() >= 950 then
if g_game.getClientVersion() >= 950 then
spelllistWindow:getChildById('buttonFilterVocation'):setVisible(true)
else
spelllistWindow:getChildById('buttonFilterVocation'):setVisible(false)
Expand Down
9 changes: 5 additions & 4 deletions modules/game_things/things.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ filename = nil
loaded = false

function init()
connect(g_game, { onProtocolVersionChange = load })
connect(g_game, { onClientVersionChange = load })
end

function terminate()
disconnect(g_game, { onProtocolVersionChange = load })
disconnect(g_game, { onClientVersionChange = load })
end

function setFileName(name)
Expand Down Expand Up @@ -43,8 +43,9 @@ function load()
local messageBox = displayErrorBox(tr('Error'), errorMessage)
addEvent(function() messageBox:raise() messageBox:focus() end)

disconnect(g_game, { onProtocolVersionChange = load })
disconnect(g_game, { onClientVersionChange = load })
g_game.setClientVersion(0)
g_game.setProtocolVersion(0)
connect(g_game, { onProtocolVersionChange = load })
connect(g_game, { onClientVersionChange = load })
end
end
37 changes: 28 additions & 9 deletions modules/gamelib/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,40 @@ function g_game.getSupportedClients()
1012, 1013, 1020, 1021, 1022,
1030, 1031, 1032, 1033, 1034,
1035, 1036, 1037, 1038, 1039,
1040, 1041
1040, 1041, 1050, 1051
}
end

function g_game.getProtocolVersionForClient(client)
clients = {
-- The client version and protocol version where
-- unsynchronized for some releases, not sure if this
-- will be the normal standard.

-- Client Version: Publicly given version when
-- downloading Cipsoft client.

-- Protocol Version: Previously was the same as
-- the client version, but was unsychronized in some
-- releases, now it needs to be verified and added here
-- if it does not match the client version.

-- Reason for defining both: The server now requires a
-- Client version and Protocol version from the client.

-- Important: Use getClientVersion for specific protocol
-- features to ensure we are using the proper version.

function g_game.getClientProtocolVersion(client)
local clients = {
[980] = 971,
[981] = 973,
[982] = 974,
[983] = 975,
[984] = 976,
[985] = 977,
[986] = 978,
[1001] = 979,
[1002] = 980,
[983] = 975,
[984] = 976,
[985] = 977,
[986] = 978,
[1001] = 979,
[1002] = 980,
[1051] = 1000 -- no idea what protocol version is required (1051 doesn't work)
}
return clients[client] or client
end
Expand Down
14 changes: 7 additions & 7 deletions modules/gamelib/protocollogin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ function ProtocolLogin:sendLoginPacket()

msg:addU16(g_game.getProtocolVersion())

if g_game.getProtocolVersion() >= 971 then
if g_game.getClientVersion() >= 980 then
msg:addU32(g_game.getClientVersion())
end

msg:addU32(g_things.getDatSignature())
msg:addU32(g_sprites.getSprSignature())
msg:addU32(PIC_SIGNATURE)

if g_game.getProtocolVersion() >= 971 then
if g_game.getClientVersion() >= 980 then
msg:addU8(0) -- clientType
end

local offset = msg:getMessageSize()

if g_game.getProtocolVersion() >= 770 then
if g_game.getClientVersion() >= 770 then
-- first RSA byte must be 0
msg:addU8(0)
-- xtea key
Expand Down Expand Up @@ -74,7 +74,7 @@ function ProtocolLogin:sendLoginPacket()
local paddingBytes = g_crypt.rsaGetSize() - (msg:getMessageSize() - offset)
assert(paddingBytes >= 0)
msg:addPaddingBytes(paddingBytes, 0)
if g_game.getProtocolVersion() >= 770 then
if g_game.getClientVersion() >= 770 then
msg:encryptRsa()
end

Expand All @@ -83,7 +83,7 @@ function ProtocolLogin:sendLoginPacket()
end

self:send(msg)
if g_game.getProtocolVersion() >= 770 then
if g_game.getClientVersion() >= 770 then
self:enableXteaEncryption()
end
self:recv()
Expand Down Expand Up @@ -131,7 +131,7 @@ end
function ProtocolLogin:parseCharacterList(msg)
local characters = {}

if g_game.getProtocolVersion() > 1010 then
if g_game.getClientVersion() > 1010 then
local worlds = {}

local worldsCount = msg:getU8()
Expand Down Expand Up @@ -165,7 +165,7 @@ function ProtocolLogin:parseCharacterList(msg)
character.worldIp = iptostring(msg:getU32())
character.worldPort = msg:getU16()

if g_game.getProtocolVersion() >= 971 then
if g_game.getClientVersion() >= 980 then
character.unknown = msg:getU8()
end

Expand Down
1 change: 1 addition & 0 deletions src/client/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ namespace Otc
GameSpritesAlphaChannel = 56,
GamePremiumExpiration = 57,
GameBrowseField = 58,
GameEnhancedAnimations = 59,

LastGameFeature = 101
};
Expand Down
4 changes: 2 additions & 2 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,11 +846,11 @@ int Creature::getStepDuration(bool ignoreDiagonal, Otc::Direction dir)
else
interval /= speed;

if(g_game.getProtocolVersion() >= 900)
if(g_game.getClientVersion() >= 900)
interval = (interval / g_game.getServerBeat()) * g_game.getServerBeat();

float factor = 3;
if(g_game.getProtocolVersion() <= 810)
if(g_game.getClientVersion() <= 810)
factor = 2;

interval = std::max<int>(interval, g_game.getServerBeat());
Expand Down
42 changes: 23 additions & 19 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1475,9 +1475,27 @@ void Game::setProtocolVersion(int version)
if(isOnline())
stdext::throw_exception("Unable to change protocol version while online");

if(version != 0 && (version < 740 || version > 1041))
if(version != 0 && (version < 740 || version > 1051))
stdext::throw_exception(stdext::format("Protocol version %d not supported", version));

m_protocolVersion = version;

Proto::buildMessageModesMap(version);

g_lua.callGlobalField("g_game", "onProtocolVersionChange", version);
}

void Game::setClientVersion(int version)
{
if(m_clientVersion == version)
return;

if(isOnline())
stdext::throw_exception("Unable to change client version while online");

if(version != 0 && (version < 740 || version > 1051))
stdext::throw_exception(stdext::format("Client version %d not supported", version));

m_features.reset();
enableFeature(Otc::GameFormatCreatureName);

Expand Down Expand Up @@ -1585,28 +1603,14 @@ void Game::setProtocolVersion(int version)
enableFeature(Otc::GameCreatureIcons);
enableFeature(Otc::GameHideNpcNames);
}

if(version >= 1038) {
enableFeature(Otc::GamePremiumExpiration);
}

m_protocolVersion = version;

Proto::buildMessageModesMap(version);

g_lua.callGlobalField("g_game", "onProtocolVersionChange", version);
}

void Game::setClientVersion(int version)
{
if(m_clientVersion == version)
return;

if(isOnline())
stdext::throw_exception("Unable to change client version while online");

if(version != 0 && (version < 740 || version > 1041))
stdext::throw_exception(stdext::format("Client version %d not supported", version));
if(version >= 1050) {
enableFeature(Otc::GameEnhancedAnimations);
}

m_clientVersion = version;

Expand Down
2 changes: 1 addition & 1 deletion src/client/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ int Item::getSubType()
{
if(isSplash() || isFluidContainer())
return m_countOrSubType;
if(g_game.getProtocolVersion() > 862)
if(g_game.getClientVersion() > 862)
return 0;
return 1;
}
Expand Down

4 comments on commit d7429c2

@iLeet
Copy link

@iLeet iLeet commented on d7429c2 Aug 12, 2014

Choose a reason for hiding this comment

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

Awesome work man! Just a quick question, I have a 10.31 custom and im going to try to import the faster animations without going to the newer version, what triggers the faster animations? Thanks!

@BenDol
Copy link
Collaborator Author

@BenDol BenDol commented on d7429c2 Aug 12, 2014

Choose a reason for hiding this comment

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

you need to use the same dat structure as the 1050 dat file. It has new animation data:

structure:

struct Animation {
    Animation() { startIndex = 0; loopCount = 0; async = false; }
    int startIndex;
    int loopCount;
    bool async;
    std::vector<std::tuple<int, int> > frames;
};

parser:

if(g_game.getFeature(Otc::GameEnhancedAnimations)) {
    if(m_animationPhases > 1) {
        m_animation.async = fin->getU8() == 0;
        m_animation.loopCount = fin->get32();
        m_animation.startIndex = fin->getU8();
        for(int i = 0; i < m_animationPhases; i++) {
            int minDuration = fin->getU32();
            int maxDuration = fin->getU32();
            m_animation.frames.push_back(std::make_tuple(minDuration, maxDuration));
        }
    }
}

So your dat would have to be update to that structure. But the new animation system is coming soon when me or someone has more time to implement it.

@jollejkpg
Copy link

Choose a reason for hiding this comment

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

Any news about the animation system?

@djblah
Copy link

@djblah djblah commented on d7429c2 Oct 25, 2017

Choose a reason for hiding this comment

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

compile for 10.31

if(version >= 1031) {

  •    enableFeature(Otc::GameEnhancedAnimations);
    
  • Proto::buildMessageModesMap(version);
  • }

Please sign in to comment.