Browse Source

Started 1050 implementation and fix ups:

* 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.
BenDol 6 years ago
parent
commit
d7429c201c

+ 3
- 3
modules/client_entergame/entergame.lua View File

@@ -35,7 +35,7 @@ end
35 35
 
36 36
 local function onCharacterList(protocol, characters, account, otui)
37 37
   -- Try add server to the server list
38
-  ServerList.add(G.host, G.port, g_game.getProtocolVersion())
38
+  ServerList.add(G.host, G.port, g_game.getClientVersion())
39 39
 
40 40
   if enterGame:getChildById('rememberPasswordBox'):isChecked() then
41 41
     local account = g_crypt.encrypt(G.account)
@@ -82,7 +82,7 @@ local function onUpdateNeeded(protocol, signature)
82 82
     local cancelFunc = EnterGame.show
83 83
     EnterGame.updateFunc(signature, continueFunc, cancelFunc)
84 84
   else
85
-    local errorBox = displayErrorBox(tr('Update needed'), tr('Your client needs update, try redownloading it.'))
85
+    local errorBox = displayErrorBox(tr('Update needed'), tr('Your client needs updating, try redownloading it.'))
86 86
     connect(errorBox, { onOk = EnterGame.show })
87 87
   end
88 88
 end
@@ -242,7 +242,7 @@ function EnterGame.doLogin()
242 242
 
243 243
   g_game.chooseRsa(G.host)
244 244
   g_game.setClientVersion(clientVersion)
245
-  g_game.setProtocolVersion(g_game.getProtocolVersionForClient(clientVersion))
245
+  g_game.setProtocolVersion(g_game.getClientProtocolVersion(clientVersion))
246 246
 
247 247
   if modules.game_things.isLoaded() then
248 248
     protocolLogin:login(G.host, G.port, G.account, G.password)

+ 3
- 3
modules/game_console/console.lua View File

@@ -324,7 +324,7 @@ end
324 324
 
325 325
 function openHelp()
326 326
   local helpChannel = 9
327
-  if g_game.getProtocolVersion() <= 810 then
327
+  if g_game.getClientVersion() <= 810 then
328 328
     helpChannel = 8
329 329
   end
330 330
   g_game.joinChannel(helpChannel)
@@ -1236,7 +1236,7 @@ function online()
1236 1236
   defaultTab = addTab(tr('Default'), true)
1237 1237
   serverTab = addTab(tr('Server Log'), false)
1238 1238
 
1239
-  if g_game.getProtocolVersion() < 862 then
1239
+  if g_game.getClientVersion() < 862 then
1240 1240
     g_keyboard.bindKeyDown('Ctrl+R', openPlayerReportRuleViolationWindow)
1241 1241
   end
1242 1242
   -- open last channels
@@ -1259,7 +1259,7 @@ function online()
1259 1259
 end
1260 1260
 
1261 1261
 function offline()
1262
-  if g_game.getProtocolVersion() < 862 then
1262
+  if g_game.getClientVersion() < 862 then
1263 1263
     g_keyboard.unbindKeyDown('Ctrl+R')
1264 1264
   end
1265 1265
   clear()

+ 5
- 5
modules/game_hotkeys/hotkeys_manager.lua View File

@@ -382,7 +382,7 @@ function doKeyCombo(keyCombo)
382 382
       modules.game_console.setTextEditText(hotKey.value)
383 383
     end
384 384
   elseif hotKey.useType == HOTKEY_MANAGER_USE then
385
-    if g_game.getProtocolVersion() < 780 or hotKey.subType then
385
+    if g_game.getClientVersion() < 780 or hotKey.subType then
386 386
       local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
387 387
       if item then
388 388
         g_game.use(item)
@@ -391,7 +391,7 @@ function doKeyCombo(keyCombo)
391 391
       g_game.useInventoryItem(hotKey.itemId)
392 392
     end
393 393
   elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
394
-    if g_game.getProtocolVersion() < 780 or hotKey.subType then
394
+    if g_game.getClientVersion() < 780 or hotKey.subType then
395 395
       local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
396 396
       if item then
397 397
         g_game.useWith(item, g_game.getLocalPlayer())
@@ -403,7 +403,7 @@ function doKeyCombo(keyCombo)
403 403
     local attackingCreature = g_game.getAttackingCreature()
404 404
     if not attackingCreature then
405 405
       local item = Item.create(hotKey.itemId)
406
-      if g_game.getProtocolVersion() < 780 or hotKey.subType then
406
+      if g_game.getClientVersion() < 780 or hotKey.subType then
407 407
         local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
408 408
         if not tmpItem then return end
409 409
         item = tmpItem
@@ -414,7 +414,7 @@ function doKeyCombo(keyCombo)
414 414
     end
415 415
 
416 416
     if not attackingCreature:getTile() then return end
417
-    if g_game.getProtocolVersion() < 780 or hotKey.subType then
417
+    if g_game.getClientVersion() < 780 or hotKey.subType then
418 418
       local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
419 419
       if item then
420 420
         g_game.useWith(item, attackingCreature)
@@ -424,7 +424,7 @@ function doKeyCombo(keyCombo)
424 424
     end
425 425
   elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
426 426
     local item = Item.create(hotKey.itemId)
427
-    if g_game.getProtocolVersion() < 780 or hotKey.subType then
427
+    if g_game.getClientVersion() < 780 or hotKey.subType then
428 428
       local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
429 429
       if not tmpItem then return true end
430 430
       item = tmpItem

+ 2
- 2
modules/game_market/marketprotocol.lua View File

@@ -39,14 +39,14 @@ end
39 39
 -- parsing protocols
40 40
 local function parseMarketEnter(protocol, msg)
41 41
   local balance
42
-  if g_game.getProtocolVersion() >= 973 then
42
+  if g_game.getClientVersion() >= 981 then
43 43
     balance = msg:getU64()
44 44
   else
45 45
     balance = msg:getU32()
46 46
   end
47 47
 
48 48
   local vocation = -1
49
-  if g_game.getProtocolVersion() < 950 then
49
+  if g_game.getClientVersion() < 950 then
50 50
     vocation = msg:getU8() -- get vocation id
51 51
   end
52 52
   local offers = msg:getU8()

+ 6
- 5
modules/game_minimap/minimap.lua View File

@@ -8,7 +8,8 @@ oldZoom = nil
8 8
 oldPos = nil
9 9
 
10 10
 function init()
11
-  minimapButton = modules.client_topmenu.addRightGameToggleButton('minimapButton', tr('Minimap') .. ' (Ctrl+M)', '/images/topbuttons/minimap', toggle)
11
+  minimapButton = modules.client_topmenu.addRightGameToggleButton('minimapButton', 
12
+    tr('Minimap') .. ' (Ctrl+M)', '/images/topbuttons/minimap', toggle)
12 13
   minimapButton:setOn(true)
13 14
 
14 15
   minimapWindow = g_ui.loadUI('minimap', modules.game_interface.getRightPanel())
@@ -95,7 +96,7 @@ function offline()
95 96
 end
96 97
 
97 98
 function loadMap(clean)
98
-  local protocolVersion = g_game.getProtocolVersion()
99
+  local clientVersion = g_game.getClientVersion()
99 100
 
100 101
   if clean then
101 102
     g_minimap.clean()
@@ -107,7 +108,7 @@ function loadMap(clean)
107 108
       g_minimap.loadOtmm(minimapFile)
108 109
     end
109 110
   else
110
-    local minimapFile = '/minimap_' .. protocolVersion .. '.otcm'
111
+    local minimapFile = '/minimap_' .. clientVersion .. '.otcm'
111 112
     if g_resources.fileExists(minimapFile) then
112 113
       g_map.loadOtcm(minimapFile)
113 114
     end
@@ -116,12 +117,12 @@ function loadMap(clean)
116 117
 end
117 118
 
118 119
 function saveMap()
119
-  local protocolVersion = g_game.getProtocolVersion()
120
+  local clientVersion = g_game.getClientVersion()
120 121
   if otmm then
121 122
     local minimapFile = '/minimap.otmm'
122 123
     g_minimap.saveOtmm(minimapFile)
123 124
   else
124
-    local minimapFile = '/minimap_' .. protocolVersion .. '.otcm'
125
+    local minimapFile = '/minimap_' .. clientVersion .. '.otcm'
125 126
     g_map.saveOtcm(minimapFile)
126 127
   end
127 128
   minimapWidget:save()

+ 1
- 1
modules/game_spelllist/spelllist.lua View File

@@ -83,7 +83,7 @@ function online()
83 83
   end
84 84
 
85 85
   -- Vocation is only send in newer clients
86
-  if g_game.getProtocolVersion() >= 950 then
86
+  if g_game.getClientVersion() >= 950 then
87 87
     spelllistWindow:getChildById('buttonFilterVocation'):setVisible(true)
88 88
   else
89 89
     spelllistWindow:getChildById('buttonFilterVocation'):setVisible(false)

+ 5
- 4
modules/game_things/things.lua View File

@@ -2,11 +2,11 @@ filename =  nil
2 2
 loaded = false
3 3
 
4 4
 function init()
5
-  connect(g_game, { onProtocolVersionChange = load })
5
+  connect(g_game, { onClientVersionChange = load })
6 6
 end
7 7
 
8 8
 function terminate()
9
-  disconnect(g_game, { onProtocolVersionChange = load })
9
+  disconnect(g_game, { onClientVersionChange = load })
10 10
 end
11 11
 
12 12
 function setFileName(name)
@@ -43,8 +43,9 @@ function load()
43 43
     local messageBox = displayErrorBox(tr('Error'), errorMessage)
44 44
     addEvent(function() messageBox:raise() messageBox:focus() end)
45 45
 
46
-    disconnect(g_game, { onProtocolVersionChange = load })
46
+    disconnect(g_game, { onClientVersionChange = load })
47
+    g_game.setClientVersion(0)
47 48
     g_game.setProtocolVersion(0)
48
-    connect(g_game, { onProtocolVersionChange = load })
49
+    connect(g_game, { onClientVersionChange = load })
49 50
   end
50 51
 end

+ 28
- 9
modules/gamelib/game.lua View File

@@ -66,21 +66,40 @@ function g_game.getSupportedClients()
66 66
     1012, 1013, 1020, 1021, 1022, 
67 67
     1030, 1031, 1032, 1033, 1034, 
68 68
     1035, 1036, 1037, 1038, 1039, 
69
-    1040, 1041
69
+    1040, 1041, 1050, 1051
70 70
   }
71 71
 end
72 72
 
73
-function g_game.getProtocolVersionForClient(client)
74
-  clients = {
73
+-- The client version and protocol version where
74
+-- unsynchronized for some releases, not sure if this 
75
+-- will be the normal standard.
76
+
77
+-- Client Version: Publicly given version when 
78
+-- downloading Cipsoft client.
79
+
80
+-- Protocol Version: Previously was the same as 
81
+-- the client version, but was unsychronized in some
82
+-- releases, now it needs to be verified and added here
83
+-- if it does not match the client version.
84
+
85
+-- Reason for defining both: The server now requires a
86
+-- Client version and Protocol version from the client.
87
+
88
+-- Important: Use getClientVersion for specific protocol 
89
+-- features to ensure we are using the proper version.
90
+
91
+function g_game.getClientProtocolVersion(client)
92
+  local clients = {
75 93
     [980] = 971,
76 94
     [981] = 973,
77 95
     [982] = 974,
78
-	  [983] = 975,
79
-	  [984] = 976,
80
-	  [985] = 977,
81
-	  [986] = 978,
82
-	  [1001] = 979,
83
-	  [1002] = 980,
96
+    [983] = 975,
97
+    [984] = 976,
98
+    [985] = 977,
99
+    [986] = 978,
100
+    [1001] = 979,
101
+    [1002] = 980,
102
+    [1051] = 1000 -- no idea what protocol version is required (1051 doesn't work)
84 103
   }
85 104
   return clients[client] or client
86 105
 end

+ 7
- 7
modules/gamelib/protocollogin.lua View File

@@ -32,7 +32,7 @@ function ProtocolLogin:sendLoginPacket()
32 32
 
33 33
   msg:addU16(g_game.getProtocolVersion())
34 34
 
35
-  if g_game.getProtocolVersion() >= 971 then
35
+  if g_game.getClientVersion() >= 980 then
36 36
     msg:addU32(g_game.getClientVersion())
37 37
   end
38 38
 
@@ -40,13 +40,13 @@ function ProtocolLogin:sendLoginPacket()
40 40
   msg:addU32(g_sprites.getSprSignature())
41 41
   msg:addU32(PIC_SIGNATURE)
42 42
 
43
-  if g_game.getProtocolVersion() >= 971 then
43
+  if g_game.getClientVersion() >= 980 then
44 44
     msg:addU8(0) -- clientType
45 45
   end
46 46
 
47 47
   local offset = msg:getMessageSize()
48 48
 
49
-  if g_game.getProtocolVersion() >= 770 then
49
+  if g_game.getClientVersion() >= 770 then
50 50
     -- first RSA byte must be 0
51 51
     msg:addU8(0)
52 52
     -- xtea key
@@ -74,7 +74,7 @@ function ProtocolLogin:sendLoginPacket()
74 74
   local paddingBytes = g_crypt.rsaGetSize() - (msg:getMessageSize() - offset)
75 75
   assert(paddingBytes >= 0)
76 76
   msg:addPaddingBytes(paddingBytes, 0)
77
-  if g_game.getProtocolVersion() >= 770 then
77
+  if g_game.getClientVersion() >= 770 then
78 78
     msg:encryptRsa()
79 79
   end
80 80
 
@@ -83,7 +83,7 @@ function ProtocolLogin:sendLoginPacket()
83 83
   end
84 84
 
85 85
   self:send(msg)
86
-  if g_game.getProtocolVersion() >= 770 then
86
+  if g_game.getClientVersion() >= 770 then
87 87
     self:enableXteaEncryption()
88 88
   end
89 89
   self:recv()
@@ -131,7 +131,7 @@ end
131 131
 function ProtocolLogin:parseCharacterList(msg)
132 132
   local characters = {}
133 133
 
134
-  if g_game.getProtocolVersion() > 1010 then
134
+  if g_game.getClientVersion() > 1010 then
135 135
     local worlds = {}
136 136
 
137 137
     local worldsCount = msg:getU8()
@@ -165,7 +165,7 @@ function ProtocolLogin:parseCharacterList(msg)
165 165
       character.worldIp = iptostring(msg:getU32())
166 166
       character.worldPort = msg:getU16()
167 167
 
168
-      if g_game.getProtocolVersion() >= 971 then
168
+      if g_game.getClientVersion() >= 980 then
169 169
         character.unknown = msg:getU8()
170 170
       end
171 171
 

+ 1
- 0
src/client/const.h View File

@@ -389,6 +389,7 @@ namespace Otc
389 389
         GameSpritesAlphaChannel = 56,
390 390
         GamePremiumExpiration = 57,
391 391
         GameBrowseField = 58,
392
+        GameEnhancedAnimations = 59,
392 393
 
393 394
         LastGameFeature = 101
394 395
     };

+ 2
- 2
src/client/creature.cpp View File

@@ -846,11 +846,11 @@ int Creature::getStepDuration(bool ignoreDiagonal, Otc::Direction dir)
846 846
     else
847 847
         interval /= speed;
848 848
 
849
-    if(g_game.getProtocolVersion() >= 900)
849
+    if(g_game.getClientVersion() >= 900)
850 850
         interval = (interval / g_game.getServerBeat()) * g_game.getServerBeat();
851 851
 
852 852
     float factor = 3;
853
-    if(g_game.getProtocolVersion() <= 810)
853
+    if(g_game.getClientVersion() <= 810)
854 854
         factor = 2;
855 855
 
856 856
     interval = std::max<int>(interval, g_game.getServerBeat());

+ 23
- 19
src/client/game.cpp View File

@@ -1475,9 +1475,27 @@ void Game::setProtocolVersion(int version)
1475 1475
     if(isOnline())
1476 1476
         stdext::throw_exception("Unable to change protocol version while online");
1477 1477
 
1478
-    if(version != 0 && (version < 740 || version > 1041))
1478
+    if(version != 0 && (version < 740 || version > 1051))
1479 1479
         stdext::throw_exception(stdext::format("Protocol version %d not supported", version));
1480 1480
 
1481
+    m_protocolVersion = version;
1482
+
1483
+    Proto::buildMessageModesMap(version);
1484
+
1485
+    g_lua.callGlobalField("g_game", "onProtocolVersionChange", version);
1486
+}
1487
+
1488
+void Game::setClientVersion(int version)
1489
+{
1490
+    if(m_clientVersion == version)
1491
+        return;
1492
+
1493
+    if(isOnline())
1494
+        stdext::throw_exception("Unable to change client version while online");
1495
+
1496
+    if(version != 0 && (version < 740 || version > 1051))
1497
+        stdext::throw_exception(stdext::format("Client version %d not supported", version));
1498
+
1481 1499
     m_features.reset();
1482 1500
     enableFeature(Otc::GameFormatCreatureName);
1483 1501
 
@@ -1585,28 +1603,14 @@ void Game::setProtocolVersion(int version)
1585 1603
         enableFeature(Otc::GameCreatureIcons);
1586 1604
         enableFeature(Otc::GameHideNpcNames);
1587 1605
     }
1588
-    
1606
+
1589 1607
     if(version >= 1038) {
1590 1608
         enableFeature(Otc::GamePremiumExpiration);
1591 1609
     }
1592 1610
 
1593
-    m_protocolVersion = version;
1594
-
1595
-    Proto::buildMessageModesMap(version);
1596
-
1597
-    g_lua.callGlobalField("g_game", "onProtocolVersionChange", version);
1598
-}
1599
-
1600
-void Game::setClientVersion(int version)
1601
-{
1602
-    if(m_clientVersion == version)
1603
-        return;
1604
-
1605
-    if(isOnline())
1606
-        stdext::throw_exception("Unable to change client version while online");
1607
-
1608
-    if(version != 0 && (version < 740 || version > 1041))
1609
-        stdext::throw_exception(stdext::format("Client version %d not supported", version));
1611
+    if(version >= 1050) {
1612
+        enableFeature(Otc::GameEnhancedAnimations);
1613
+    }
1610 1614
 
1611 1615
     m_clientVersion = version;
1612 1616
 

+ 1
- 1
src/client/item.cpp View File

@@ -241,7 +241,7 @@ int Item::getSubType()
241 241
 {
242 242
     if(isSplash() || isFluidContainer())
243 243
         return m_countOrSubType;
244
-    if(g_game.getProtocolVersion() > 862)
244
+    if(g_game.getClientVersion() > 862)
245 245
         return 0;
246 246
     return 1;
247 247
 }

+ 1
- 1
src/client/itemtype.cpp View File

@@ -51,7 +51,7 @@ void ItemType::unserialize(const BinaryTreePtr& node)
51 51
         switch(attr) {
52 52
             case ItemTypeAttrServerId: {
53 53
                 uint16 serverId = node->getU16();
54
-                if(g_game.getProtocolVersion() < 960) {
54
+                if(g_game.getClientVersion() < 960) {
55 55
                     if(serverId > 20000 && serverId < 20100) {
56 56
                         serverId -= 20000;
57 57
                     } else if(lastId > 99 && lastId != serverId - 1) {

+ 1
- 1
src/client/mapio.cpp View File

@@ -491,7 +491,7 @@ void Map::saveOtcm(const std::string& fileName)
491 491
         // version 1 header
492 492
         fin->addString("OTCM 1.0"); // map description
493 493
         fin->addU32(g_things.getDatSignature());
494
-        fin->addU16(g_game.getProtocolVersion());
494
+        fin->addU16(g_game.getClientVersion());
495 495
         fin->addString(g_game.getWorldName());
496 496
 
497 497
         // go back and rewrite where the map data starts

+ 1
- 1
src/client/protocolgame.cpp View File

@@ -56,7 +56,7 @@ void ProtocolGame::onRecv(const InputMessagePtr& inputMessage)
56 56
     if(m_firstRecv) {
57 57
         m_firstRecv = false;
58 58
 
59
-        if(g_game.getProtocolVersion() >= 841) { // not sure since which version this is, but it seems to be after 8.40
59
+        if(g_game.getClientVersion() >= 841) { // not sure since which version this is, but it seems to be after 8.40
60 60
             int size = inputMessage->getU16();
61 61
             if(size != inputMessage->getUnreadSize()) {
62 62
                 g_logger.traceError("invalid message size");

+ 11
- 11
src/client/protocolgameparse.cpp View File

@@ -410,9 +410,9 @@ void ProtocolGame::parseGMActions(const InputMessagePtr& msg)
410 410
 
411 411
     int numViolationReasons;
412 412
 
413
-    if(g_game.getProtocolVersion() >= 850)
413
+    if(g_game.getClientVersion() >= 850)
414 414
         numViolationReasons = 20;
415
-    else if(g_game.getProtocolVersion() >= 840)
415
+    else if(g_game.getClientVersion() >= 840)
416 416
         numViolationReasons = 23;
417 417
     else
418 418
         numViolationReasons = 32;
@@ -562,7 +562,7 @@ void ProtocolGame::parseTileAddThing(const InputMessagePtr& msg)
562 562
     Position pos = getPosition(msg);
563 563
     int stackPos = -1;
564 564
 
565
-    if(g_game.getProtocolVersion() >= 841)
565
+    if(g_game.getClientVersion() >= 841)
566 566
         stackPos = msg->getU8();
567 567
 
568 568
     ThingPtr thing = getThing(msg);
@@ -722,7 +722,7 @@ void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg)
722 722
 
723 723
     int listCount;
724 724
 
725
-    if(g_game.getProtocolVersion() >= 900)
725
+    if(g_game.getClientVersion() >= 900)
726 726
         listCount = msg->getU16();
727 727
     else
728 728
         listCount = msg->getU8();
@@ -749,7 +749,7 @@ void ProtocolGame::parsePlayerGoods(const InputMessagePtr& msg)
749 749
     std::vector<std::tuple<ItemPtr, int>> goods;
750 750
 
751 751
     int money;
752
-    if(g_game.getProtocolVersion() >= 973)
752
+    if(g_game.getClientVersion() >= 973)
753 753
         money = msg->getU64();
754 754
     else
755 755
         money = msg->getU32();
@@ -992,7 +992,7 @@ void ProtocolGame::parseEditText(const InputMessagePtr& msg)
992 992
     uint id = msg->getU32();
993 993
 
994 994
     int itemId;
995
-    if(g_game.getProtocolVersion() >= 1010) {
995
+    if(g_game.getClientVersion() >= 1010) {
996 996
         // TODO: processEditText with ItemPtr as parameter
997 997
         ItemPtr item = getItem(msg);
998 998
         itemId = item->getId();
@@ -1640,7 +1640,7 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg)
1640 1640
     }
1641 1641
 
1642 1642
     int enterButton, escapeButton;
1643
-    if(g_game.getProtocolVersion() > 970) {
1643
+    if(g_game.getClientVersion() > 970) {
1644 1644
         escapeButton = msg->getU8();
1645 1645
         enterButton = msg->getU8();
1646 1646
     }
@@ -1685,7 +1685,7 @@ void ProtocolGame::parseChangeMapAwareRange(const InputMessagePtr& msg)
1685 1685
 void ProtocolGame::parseCreaturesMark(const InputMessagePtr& msg)
1686 1686
 {
1687 1687
     int len;
1688
-    if (g_game.getProtocolVersion() >= 1035) {
1688
+    if (g_game.getClientVersion() >= 1035) {
1689 1689
         len = 1;
1690 1690
     } else {
1691 1691
         len = msg->getU8();
@@ -1895,7 +1895,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
1895 1895
             uint id = msg->getU32();
1896 1896
 
1897 1897
             int creatureType;
1898
-            if(g_game.getProtocolVersion() >= 910)
1898
+            if(g_game.getClientVersion() >= 910)
1899 1899
                 creatureType = msg->getU8();
1900 1900
             else {
1901 1901
                 if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
@@ -1973,7 +1973,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
1973 1973
             }
1974 1974
         }
1975 1975
 
1976
-        if(g_game.getProtocolVersion() >= 854)
1976
+        if(g_game.getClientVersion() >= 854)
1977 1977
             unpass = msg->getU8();
1978 1978
 
1979 1979
         if(creature) {
@@ -2004,7 +2004,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
2004 2004
         if(creature)
2005 2005
             creature->turn(direction);
2006 2006
 
2007
-        if(g_game.getProtocolVersion() >= 953) {
2007
+        if(g_game.getClientVersion() >= 953) {
2008 2008
             bool unpass = msg->getU8();
2009 2009
 
2010 2010
             if(creature)

+ 4
- 4
src/client/protocolgamesend.cpp View File

@@ -65,7 +65,7 @@ void ProtocolGame::sendLoginPacket(uint challengeTimestamp, uint8 challengeRando
65 65
 
66 66
     msg->addU8(0); // first RSA byte must be 0
67 67
 
68
-    if(g_game.getProtocolVersion() >= 770)
68
+    if(g_game.getClientVersion() >= 770)
69 69
     {
70 70
         // xtea key
71 71
         generateXteaKey();
@@ -99,7 +99,7 @@ void ProtocolGame::sendLoginPacket(uint challengeTimestamp, uint8 challengeRando
99 99
     msg->addPaddingBytes(paddingBytes);
100 100
 
101 101
     // encrypt with RSA
102
-    if(g_game.getProtocolVersion() >= 770)
102
+    if(g_game.getClientVersion() >= 770)
103 103
         msg->encryptRsa();
104 104
 
105 105
     if(g_game.getFeature(Otc::GameProtocolChecksum))
@@ -107,7 +107,7 @@ void ProtocolGame::sendLoginPacket(uint challengeTimestamp, uint8 challengeRando
107 107
 
108 108
     send(msg);
109 109
 
110
-    if(g_game.getProtocolVersion() >= 770)
110
+    if(g_game.getClientVersion() >= 770)
111 111
         enableXteaEncryption();
112 112
 }
113 113
 
@@ -642,7 +642,7 @@ void ProtocolGame::sendShareExperience(bool active)
642 642
     msg->addU8(Proto::ClientShareExperience);
643 643
     msg->addU8(active ? 0x01 : 0x00);
644 644
 
645
-    if(g_game.getProtocolVersion() < 910)
645
+    if(g_game.getClientVersion() < 910)
646 646
         msg->addU8(0);
647 647
 
648 648
     send(msg);

+ 42
- 11
src/client/thingtype.cpp View File

@@ -53,12 +53,12 @@ void ThingType::serialize(const FileStreamPtr& fin)
53 53
             continue;
54 54
 
55 55
         int attr = i;
56
-        if(g_game.getProtocolVersion() >= 780) {
56
+        if(g_game.getClientVersion() >= 780) {
57 57
             if(attr == ThingAttrChargeable)
58 58
                 attr = ThingAttrWritable;
59 59
             else if(attr >= ThingAttrWritable)
60 60
                 attr += 1;
61
-        } else if(g_game.getProtocolVersion() >= 1010) {
61
+        } else if(g_game.getClientVersion() >= 1010) {
62 62
             if(attr == ThingAttrNoMoveAnimation)
63 63
                 attr = 16;
64 64
             else if(attr >= ThingAttrPickupable)
@@ -116,6 +116,19 @@ void ThingType::serialize(const FileStreamPtr& fin)
116 116
     fin->addU8(m_numPatternZ);
117 117
     fin->addU8(m_animationPhases);
118 118
 
119
+    if(g_game.getFeature(Otc::GameEnhancedAnimations)) {
120
+        if(m_animationPhases > 1) {
121
+            fin->addU8(m_animation.async ? 0 : 1);
122
+            fin->add32(m_animation.loopCount);
123
+            fin->addU8(m_animation.startIndex);
124
+
125
+            for(std::tuple<int, int> frame : m_animation.frames) {
126
+                fin->addU32(std::get<0>(frame));
127
+                fin->addU32(std::get<1>(frame));
128
+            }
129
+        }
130
+    }
131
+
119 132
     for(uint i = 0; i < m_spritesIndex.size(); i++) {
120 133
         if(g_game.getFeature(Otc::GameSpritesU32))
121 134
             fin->addU32(m_spritesIndex[i]);
@@ -130,15 +143,17 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
130 143
     m_id = clientId;
131 144
     m_category = category;
132 145
 
146
+    int count = 0, attr = -1;
133 147
     bool done = false;
134 148
     for(int i = 0 ; i < ThingLastAttr;++i) {
135
-        int attr = fin->getU8();
149
+        count++;
150
+        attr = fin->getU8();
136 151
         if(attr == ThingLastAttr) {
137 152
             done = true;
138 153
             break;
139 154
         }
140 155
 
141
-        if(g_game.getProtocolVersion() >= 1010) {
156
+        if(g_game.getClientVersion() >= 1010) {
142 157
             /* In 10.10+ all attributes from 16 and up were
143 158
              * incremented by 1 to make space for 16 as
144 159
              * "No Movement Animation" flag.
@@ -147,12 +162,12 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
147 162
                 attr = ThingAttrNoMoveAnimation;
148 163
             else if(attr > 16)
149 164
                 attr -= 1;
150
-        } else if(g_game.getProtocolVersion() >= 860) {
165
+        } else if(g_game.getClientVersion() >= 860) {
151 166
             /* Default attribute values follow
152 167
              * the format of 8.6-9.86.
153 168
              * Therefore no changes here.
154 169
              */
155
-        } else if(g_game.getProtocolVersion() >= 780) {
170
+        } else if(g_game.getClientVersion() >= 780) {
156 171
             /* In 7.80-8.54 all attributes from 8 and higher were
157 172
              * incremented by 1 to make space for 8 as
158 173
              * "Item Charges" flag.
@@ -162,11 +177,11 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
162 177
                 continue;
163 178
             } else if(attr > 8)
164 179
                 attr -= 1;
165
-        } else if(g_game.getProtocolVersion() >= 755) {
180
+        } else if(g_game.getClientVersion() >= 755) {
166 181
             /* In 7.55-7.72 attributes 23 is "Floor Change". */
167 182
             if(attr == 23)
168 183
                 attr = ThingAttrFloorChange;
169
-        } else if(g_game.getProtocolVersion() >= 740) {
184
+        } else if(g_game.getClientVersion() >= 740) {
170 185
             /* In 7.4-7.5 attribute "Ground Border" did not exist
171 186
              * attributes 1-15 have to be adjusted.
172 187
              * Several other changes in the format.
@@ -207,7 +222,7 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
207 222
 
208 223
         switch(attr) {
209 224
             case ThingAttrDisplacement: {
210
-                if(g_game.getProtocolVersion() >= 755) {
225
+                if(g_game.getClientVersion() >= 755) {
211 226
                     m_displacement.x = fin->getU16();
212 227
                     m_displacement.y = fin->getU16();
213 228
                 } else {
@@ -256,7 +271,8 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
256 271
     }
257 272
 
258 273
     if(!done)
259
-        stdext::throw_exception("corrupt data");
274
+        stdext::throw_exception(stdext::format("corrupt data (id: %d, category: %d, count: %d, lastAttr: %d)",
275
+            m_id, m_category, count, attr));
260 276
 
261 277
     uint8 width = fin->getU8();
262 278
     uint8 height = fin->getU8();
@@ -271,12 +287,27 @@ void ThingType::unserialize(uint16 clientId, ThingCategory category, const FileS
271 287
     m_layers = fin->getU8();
272 288
     m_numPatternX = fin->getU8();
273 289
     m_numPatternY = fin->getU8();
274
-    if(g_game.getProtocolVersion() >= 755)
290
+    if(g_game.getClientVersion() >= 755)
275 291
         m_numPatternZ = fin->getU8();
276 292
     else
277 293
         m_numPatternZ = 1;
278 294
     m_animationPhases = fin->getU8();
279 295
 
296
+    if(g_game.getFeature(Otc::GameEnhancedAnimations)) {
297
+        if(m_animationPhases > 1) {
298
+            m_animation.async = fin->getU8() == 0;
299
+            m_animation.loopCount = fin->get32();
300
+            m_animation.startIndex = fin->getU8();
301
+
302
+            for(int i = 0; i < m_animationPhases; i++) {
303
+                int minDuration = fin->getU32();
304
+                int maxDuration = fin->getU32();
305
+
306
+                m_animation.frames.push_back(std::make_tuple(minDuration, maxDuration));
307
+            }
308
+        }
309
+    }
310
+
280 311
     int totalSprites = m_size.area() * m_layers * m_numPatternX * m_numPatternY * m_numPatternZ * m_animationPhases;
281 312
 
282 313
     // if(totalSprites == 0)

+ 12
- 1
src/client/thingtype.h View File

@@ -110,6 +110,15 @@ struct Light {
110 110
     uint8 color;
111 111
 };
112 112
 
113
+struct Animation {
114
+    Animation() { startIndex = 0; loopCount = 0; async = false; }
115
+
116
+    int startIndex;
117
+    int loopCount;
118
+    bool async;
119
+    std::vector<std::tuple<int, int> > frames;
120
+};
121
+
113 122
 class ThingType : public LuaObject
114 123
 {
115 124
 public:
@@ -138,6 +147,7 @@ public:
138 147
     int getNumPatternY() { return m_numPatternY; }
139 148
     int getNumPatternZ() { return m_numPatternZ; }
140 149
     int getAnimationPhases() { return m_animationPhases; }
150
+    Animation getAnimation() { return m_animation; }
141 151
     Point getDisplacement() { return m_displacement; }
142 152
     int getDisplacementX() { return getDisplacement().x; }
143 153
     int getDisplacementY() { return getDisplacement().y; }
@@ -204,10 +214,11 @@ private:
204 214
 
205 215
     Size m_size;
206 216
     Point m_displacement;
217
+    Animation m_animation;
218
+    int m_animationPhases;
207 219
     int m_exactSize;
208 220
     int m_realSize;
209 221
     int m_numPatternX, m_numPatternY, m_numPatternZ;
210
-    int m_animationPhases;
211 222
     int m_layers;
212 223
     int m_elevation;
213 224
     float m_opacity;

+ 1
- 1
src/client/thingtypemanager.cpp View File

@@ -276,7 +276,7 @@ void ThingTypeManager::parseItemType(uint16 serverId, TiXmlElement* elem)
276 276
     bool s;
277 277
     int d;
278 278
 
279
-    if(g_game.getProtocolVersion() < 960) {
279
+    if(g_game.getClientVersion() < 960) {
280 280
         s = serverId > 20000 && serverId < 20100;
281 281
         d = 20000;
282 282
     } else {

+ 1
- 1
src/client/tile.cpp View File

@@ -217,7 +217,7 @@ void Tile::addThing(const ThingPtr& thing, int stackPos)
217 217
                 append = (priority <= 3);
218 218
 
219 219
                 // newer protocols does not store creatures in reverse order
220
-                if(g_game.getProtocolVersion() >= 854 && priority == 4)
220
+                if(g_game.getClientVersion() >= 854 && priority == 4)
221 221
                     append = !append;
222 222
             }
223 223
 

+ 5
- 5
src/framework/core/binarytree.cpp View File

@@ -132,7 +132,7 @@ uint16 BinaryTree::getU16()
132 132
     unserialize();
133 133
     if(m_pos+2 > m_buffer.size())
134 134
         stdext::throw_exception("BinaryTree: getU16 failed");
135
-    uint16 v = stdext::readLE16(&m_buffer[m_pos]);
135
+    uint16 v = stdext::readULE16(&m_buffer[m_pos]);
136 136
     m_pos += 2;
137 137
     return v;
138 138
 }
@@ -142,7 +142,7 @@ uint32 BinaryTree::getU32()
142 142
     unserialize();
143 143
     if(m_pos+4 > m_buffer.size())
144 144
         stdext::throw_exception("BinaryTree: getU32 failed");
145
-    uint32 v = stdext::readLE32(&m_buffer[m_pos]);
145
+    uint32 v = stdext::readULE32(&m_buffer[m_pos]);
146 146
     m_pos += 4;
147 147
     return v;
148 148
 }
@@ -152,7 +152,7 @@ uint64 BinaryTree::getU64()
152 152
     unserialize();
153 153
     if(m_pos+8 > m_buffer.size())
154 154
         stdext::throw_exception("BinaryTree: getU64 failed");
155
-    uint64 v = stdext::readLE64(&m_buffer[m_pos]);
155
+    uint64 v = stdext::readULE64(&m_buffer[m_pos]);
156 156
     m_pos += 8;
157 157
     return v;
158 158
 }
@@ -193,14 +193,14 @@ void OutputBinaryTree::addU8(uint8 v)
193 193
 void OutputBinaryTree::addU16(uint16 v)
194 194
 {
195 195
     uint8 data[2];
196
-    stdext::writeLE16(data, v);
196
+    stdext::writeULE16(data, v);
197 197
     write(data, 2);
198 198
 }
199 199
 
200 200
 void OutputBinaryTree::addU32(uint32 v)
201 201
 {
202 202
     uint8 data[4];
203
-    stdext::writeLE32(data, v);
203
+    stdext::writeULE32(data, v);
204 204
     write(data, 4);
205 205
 }
206 206
 

+ 116
- 6
src/framework/core/filestream.cpp View File

@@ -206,7 +206,7 @@ uint16 FileStream::getU16()
206 206
         if(m_pos+2 > m_data.size())
207 207
             throwError("read failed");
208 208
 
209
-        v = stdext::readLE16(&m_data[m_pos]);
209
+        v = stdext::readULE16(&m_data[m_pos]);
210 210
         m_pos += 2;
211 211
     }
212 212
     return v;
@@ -222,7 +222,7 @@ uint32 FileStream::getU32()
222 222
         if(m_pos+4 > m_data.size())
223 223
             throwError("read failed");
224 224
 
225
-        v = stdext::readLE32(&m_data[m_pos]);
225
+        v = stdext::readULE32(&m_data[m_pos]);
226 226
         m_pos += 4;
227 227
     }
228 228
     return v;
@@ -237,7 +237,70 @@ uint64 FileStream::getU64()
237 237
     } else {
238 238
         if(m_pos+8 > m_data.size())
239 239
             throwError("read failed");
240
-        v = stdext::readLE64(&m_data[m_pos]);
240
+        v = stdext::readULE64(&m_data[m_pos]);
241
+        m_pos += 8;
242
+    }
243
+    return v;
244
+}
245
+
246
+int8 FileStream::get8()
247
+{
248
+    int8 v = 0;
249
+    if(!m_caching) {
250
+        if(PHYSFS_read(m_fileHandle, &v, 1, 1) != 1)
251
+            throwError("read failed", true);
252
+    } else {
253
+        if(m_pos+1 > m_data.size())
254
+            throwError("read failed");
255
+
256
+        v = m_data[m_pos];
257
+        m_pos += 1;
258
+    }
259
+    return v;
260
+}
261
+
262
+int16 FileStream::get16()
263
+{
264
+    int16 v = 0;
265
+    if(!m_caching) {
266
+        if(PHYSFS_readSLE16(m_fileHandle, &v) == 0)
267
+            throwError("read failed", true);
268
+    } else {
269
+        if(m_pos+2 > m_data.size())
270
+            throwError("read failed");
271
+
272
+        v = stdext::readSLE16(&m_data[m_pos]);
273
+        m_pos += 2;
274
+    }
275
+    return v;
276
+}
277
+
278
+int32 FileStream::get32()
279
+{
280
+    int32 v = 0;
281
+    if(!m_caching) {
282
+        if(PHYSFS_readSLE32(m_fileHandle, &v) == 0)
283
+            throwError("read failed", true);
284
+    } else {
285
+        if(m_pos+4 > m_data.size())
286
+            throwError("read failed");
287
+
288
+        v = stdext::readSLE32(&m_data[m_pos]);
289
+        m_pos += 4;
290
+    }
291
+    return v;
292
+}
293
+
294
+int64 FileStream::get64()
295
+{
296
+    int64 v = 0;
297
+    if(!m_caching) {
298
+        if(PHYSFS_readSLE64(m_fileHandle, (PHYSFS_sint64*)&v) == 0)
299
+            throwError("read failed", true);
300
+    } else {
301
+        if(m_pos+8 > m_data.size())
302
+            throwError("read failed");
303
+        v = stdext::readSLE64(&m_data[m_pos]);
241 304
         m_pos += 8;
242 305
     }
243 306
     return v;
@@ -306,7 +369,7 @@ void FileStream::addU16(uint16 v)
306 369
             throwError("write failed", true);
307 370
     } else {
308 371
         m_data.grow(m_pos + 2);
309
-        stdext::writeLE16(&m_data[m_pos], v);
372
+        stdext::writeULE16(&m_data[m_pos], v);
310 373
         m_pos += 2;
311 374
     }
312 375
 }
@@ -318,7 +381,7 @@ void FileStream::addU32(uint32 v)
318 381
             throwError("write failed", true);
319 382
     } else {
320 383
         m_data.grow(m_pos + 4);
321
-        stdext::writeLE32(&m_data[m_pos], v);
384
+        stdext::writeULE32(&m_data[m_pos], v);
322 385
         m_pos += 4;
323 386
     }
324 387
 }
@@ -330,7 +393,54 @@ void FileStream::addU64(uint64 v)
330 393
             throwError("write failed", true);
331 394
     } else {
332 395
         m_data.grow(m_pos + 8);
333
-        stdext::writeLE64(&m_data[m_pos], v);
396
+        stdext::writeULE64(&m_data[m_pos], v);
397
+        m_pos += 8;
398
+    }
399
+}
400
+
401
+void FileStream::add8(int8 v)
402
+{
403
+    if(!m_caching) {
404
+        if(PHYSFS_write(m_fileHandle, &v, 1, 1) != 1)
405
+            throwError("write failed", true);
406
+    } else {
407
+        m_data.add(v);
408
+        m_pos++;
409
+    }
410
+}
411
+
412
+void FileStream::add16(int16 v)
413
+{
414
+    if(!m_caching) {
415
+        if(PHYSFS_writeSLE16(m_fileHandle, v) == 0)
416
+            throwError("write failed", true);
417
+    } else {
418
+        m_data.grow(m_pos + 2);
419
+        stdext::writeSLE16(&m_data[m_pos], v);
420
+        m_pos += 2;
421
+    }
422
+}
423
+
424
+void FileStream::add32(int32 v)
425
+{
426
+    if(!m_caching) {
427
+        if(PHYSFS_writeSLE32(m_fileHandle, v) == 0)
428
+            throwError("write failed", true);
429
+    } else {
430
+        m_data.grow(m_pos + 4);
431
+        stdext::writeSLE32(&m_data[m_pos], v);
432
+        m_pos += 4;
433
+    }
434
+}
435
+
436
+void FileStream::add64(int64 v)
437
+{
438
+    if(!m_caching) {
439
+        if(PHYSFS_writeSLE64(m_fileHandle, v) == 0)
440
+            throwError("write failed", true);
441
+    } else {
442
+        m_data.grow(m_pos + 8);
443
+        stdext::writeSLE64(&m_data[m_pos], v);
334 444
         m_pos += 8;
335 445
     }
336 446
 }

+ 8
- 0
src/framework/core/filestream.h View File

@@ -54,6 +54,10 @@ public:
54 54
     uint16 getU16();
55 55
     uint32 getU32();
56 56
     uint64 getU64();
57
+    int8 get8();
58
+    int16 get16();
59
+    int32 get32();
60
+    int64 get64();
57 61
     std::string getString();
58 62
     BinaryTreePtr getBinaryTree();
59 63
 
@@ -63,6 +67,10 @@ public:
63 67
     void addU16(uint16 v);
64 68
     void addU32(uint32 v);
65 69
     void addU64(uint64 v);
70
+    void add8(int8 v);
71
+    void add16(int16 v);
72
+    void add32(int32 v);
73
+    void add64(int64 v);
66 74
     void addString(const std::string& v);
67 75
     void addPos(uint16 x, uint16 y, uint8 z) { addU16(x); addU16(y); addU8(z); }
68 76
     void addPoint(const Point& p) { addU8(p.x); addU8(p.y); }

+ 1
- 0
src/framework/luafunctions.cpp View File

@@ -195,6 +195,7 @@ void Application::registerLuaFunctions()
195 195
     g_lua.bindSingletonFunction("g_resources", "getFileTime", &ResourceManager::getFileTime, &g_resources);
196 196
     g_lua.bindSingletonFunction("g_resources", "makeDir", &ResourceManager::makeDir, &g_resources);
197 197
     g_lua.bindSingletonFunction("g_resources", "deleteFile", &ResourceManager::deleteFile, &g_resources);
198
+    g_lua.bindSingletonFunction("g_resources", "resolvePath", &ResourceManager::resolvePath, &g_resources);
198 199
 
199 200
     // Config
200 201
     g_lua.registerClass<Config>();

+ 3
- 3
src/framework/net/inputmessage.cpp View File

@@ -56,7 +56,7 @@ uint8 InputMessage::getU8()
56 56
 uint16 InputMessage::getU16()
57 57
 {
58 58
     checkRead(2);
59
-    uint16 v = stdext::readLE16(m_buffer + m_readPos);
59
+    uint16 v = stdext::readULE16(m_buffer + m_readPos);
60 60
     m_readPos += 2;
61 61
     return v;
62 62
 }
@@ -64,7 +64,7 @@ uint16 InputMessage::getU16()
64 64
 uint32 InputMessage::getU32()
65 65
 {
66 66
     checkRead(4);
67
-    uint32 v = stdext::readLE32(m_buffer + m_readPos);
67
+    uint32 v = stdext::readULE32(m_buffer + m_readPos);
68 68
     m_readPos += 4;
69 69
     return v;
70 70
 }
@@ -72,7 +72,7 @@ uint32 InputMessage::getU32()
72 72
 uint64 InputMessage::getU64()
73 73
 {
74 74
     checkRead(8);
75
-    uint64 v = stdext::readLE64(m_buffer + m_readPos);
75
+    uint64 v = stdext::readULE64(m_buffer + m_readPos);
76 76
     m_readPos += 8;
77 77
     return v;
78 78
 }

+ 5
- 5
src/framework/net/outputmessage.cpp View File

@@ -46,7 +46,7 @@ void OutputMessage::addU8(uint8 value)
46 46
 void OutputMessage::addU16(uint16 value)
47 47
 {
48 48
     checkWrite(2);
49
-    stdext::writeLE16(m_buffer + m_writePos, value);
49
+    stdext::writeULE16(m_buffer + m_writePos, value);
50 50
     m_writePos += 2;
51 51
     m_messageSize += 2;
52 52
 }
@@ -54,7 +54,7 @@ void OutputMessage::addU16(uint16 value)
54 54
 void OutputMessage::addU32(uint32 value)
55 55
 {
56 56
     checkWrite(4);
57
-    stdext::writeLE32(m_buffer + m_writePos, value);
57
+    stdext::writeULE32(m_buffer + m_writePos, value);
58 58
     m_writePos += 4;
59 59
     m_messageSize += 4;
60 60
 }
@@ -62,7 +62,7 @@ void OutputMessage::addU32(uint32 value)
62 62
 void OutputMessage::addU64(uint64 value)
63 63
 {
64 64
     checkWrite(8);
65
-    stdext::writeLE64(m_buffer + m_writePos, value);
65
+    stdext::writeULE64(m_buffer + m_writePos, value);
66 66
     m_writePos += 8;
67 67
     m_messageSize += 8;
68 68
 }
@@ -104,7 +104,7 @@ void OutputMessage::writeChecksum()
104 104
     uint32 checksum = stdext::adler32(m_buffer + m_headerPos, m_messageSize);
105 105
     assert(m_headerPos - 4 >= 0);
106 106
     m_headerPos -= 4;
107
-    stdext::writeLE32(m_buffer + m_headerPos, checksum);
107
+    stdext::writeULE32(m_buffer + m_headerPos, checksum);
108 108
     m_messageSize += 4;
109 109
 }
110 110
 
@@ -112,7 +112,7 @@ void OutputMessage::writeMessageSize()
112 112
 {
113 113
     assert(m_headerPos - 2 >= 0);
114 114
     m_headerPos -= 2;
115
-    stdext::writeLE16(m_buffer + m_headerPos, m_messageSize);
115
+    stdext::writeULE16(m_buffer + m_headerPos, m_messageSize);
116 116
     m_messageSize += 2;
117 117
 }
118 118
 

+ 1
- 1
src/framework/platform/win32window.cpp View File

@@ -798,7 +798,7 @@ int WIN32Window::internalLoadMouseCursor(const ImagePtr& image, const Point& hot
798 798
     std::vector<uchar> xorMask(numbytes, 0);
799 799
 
800 800
     for(int i=0;i<numbits;++i) {
801
-        uint32 rgba = stdext::readLE32(image->getPixelData() + i*4);
801
+        uint32 rgba = stdext::readULE32(image->getPixelData() + i*4);
802 802
         if(rgba == 0xffffffff) { //white
803 803
             HSB_BIT_SET(xorMask, i);
804 804
         } else if(rgba == 0x00000000) { //alpha

+ 14
- 6
src/framework/stdext/math.h View File

@@ -31,13 +31,21 @@ namespace stdext {
31 31
 inline bool is_power_of_two(size_t v) { return ((v != 0) && !(v & (v - 1))); }
32 32
 inline size_t to_power_of_two(size_t v) { if(v == 0) return 0; size_t r = 1; while(r < v && r != 0xffffffff) r <<= 1; return r; }
33 33
 
34
-inline uint16_t readLE16(const uchar *addr) { return (uint16_t)addr[1] << 8 | addr[0]; }
35
-inline uint32_t readLE32(const uchar *addr) { return (uint32_t)readLE16(addr + 2) << 16 | readLE16(addr); }
36
-inline uint64_t readLE64(const uchar *addr) { return (uint64_t)readLE32(addr + 4) << 32 | readLE32(addr); }
34
+inline uint16_t readULE16(const uchar *addr) { return (uint16_t)addr[1] << 8 | addr[0]; }
35
+inline uint32_t readULE32(const uchar *addr) { return (uint32_t)readULE16(addr + 2) << 16 | readULE16(addr); }
36
+inline uint64_t readULE64(const uchar *addr) { return (uint64_t)readULE32(addr + 4) << 32 | readULE32(addr); }
37 37
 
38
-inline void writeLE16(uchar *addr, uint16_t value) { addr[1] = value >> 8; addr[0] = (uint8_t)value; }
39
-inline void writeLE32(uchar *addr, uint32_t value) { writeLE16(addr + 2, value >> 16); writeLE16(addr, (uint16_t)value); }
40
-inline void writeLE64(uchar *addr, uint64_t value) { writeLE32(addr + 4, value >> 32); writeLE32(addr, (uint32_t)value); }
38
+inline void writeULE16(uchar *addr, uint16_t value) { addr[1] = value >> 8; addr[0] = (uint8_t)value; }
39
+inline void writeULE32(uchar *addr, uint32_t value) { writeULE16(addr + 2, value >> 16); writeULE16(addr, (uint16_t)value); }
40
+inline void writeULE64(uchar *addr, uint64_t value) { writeULE32(addr + 4, value >> 32); writeULE32(addr, (uint32_t)value); }
41
+
42
+inline int16_t readSLE16(const uchar *addr) { return (int16_t)addr[1] << 8 | addr[0]; }
43
+inline int32_t readSLE32(const uchar *addr) { return (int32_t)readSLE16(addr + 2) << 16 | readSLE16(addr); }
44
+inline int64_t readSLE64(const uchar *addr) { return (int64_t)readSLE32(addr + 4) << 32 | readSLE32(addr); }
45
+
46
+inline void writeSLE16(uchar *addr, int16_t value) { addr[1] = value >> 8; addr[0] = (int8_t)value; }
47
+inline void writeSLE32(uchar *addr, int32_t value) { writeSLE16(addr + 2, value >> 16); writeSLE16(addr, (int16_t)value); }
48
+inline void writeSLE64(uchar *addr, int64_t value) { writeSLE32(addr + 4, value >> 32); writeSLE32(addr, (int32_t)value); }
41 49
 
42 50
 uint32_t adler32(const uint8_t *buffer, size_t size);
43 51
 

+ 2
- 2
src/framework/util/crypt.cpp View File

@@ -201,7 +201,7 @@ std::string Crypt::_encrypt(const std::string& decrypted_string, bool useMachine
201 201
 {
202 202
     std::string tmp = "0000" + decrypted_string;
203 203
     uint32 sum = stdext::adler32((const uint8*)decrypted_string.c_str(), decrypted_string.size());
204
-    stdext::writeLE32((uint8*)&tmp[0], sum);
204
+    stdext::writeULE32((uint8*)&tmp[0], sum);
205 205
     std::string encrypted = base64Encode(xorCrypt(tmp, getCryptKey(useMachineUUID)));
206 206
     return encrypted;
207 207
 }
@@ -211,7 +211,7 @@ std::string Crypt::_decrypt(const std::string& encrypted_string, bool useMachine
211 211
     std::string decoded = base64Decode(encrypted_string);
212 212
     std::string tmp = xorCrypt(base64Decode(encrypted_string), getCryptKey(useMachineUUID));
213 213
     if(tmp.length() >= 4) {
214
-        uint32 readsum = stdext::readLE32((const uint8*)tmp.c_str());
214
+        uint32 readsum = stdext::readULE32((const uint8*)tmp.c_str());
215 215
         std::string decrypted_string = tmp.substr(4);
216 216
         uint32 sum = stdext::adler32((const uint8*)decrypted_string.c_str(), decrypted_string.size());
217 217
         if(readsum == sum)

Loading…
Cancel
Save