Browse Source

Update item OTBM attributes reader

* Fix some lua errors generated by playMusic
* Fix possible crash when starting otcliet without dat loaded
Eduardo Bart 8 years ago
parent
commit
b0e6b3b8fb

+ 1
- 1
modules/game_tibiafiles/tibiafiles.lua View File

@@ -10,4 +10,4 @@ function TibiaFiles.init()
10 10
 end
11 11
 
12 12
 function TibiaFiles.terminate()
13
-end
13
+end

+ 14
- 6
src/framework/sound/soundmanager.cpp View File

@@ -107,8 +107,10 @@ void SoundManager::poll()
107 107
     }
108 108
 }
109 109
 
110
-void SoundManager::preload(const std::string& filename)
110
+void SoundManager::preload(std::string filename)
111 111
 {
112
+    filename = g_resources.resolvePath(filename);
113
+
112 114
     auto it = m_buffers.find(filename);
113 115
     if(it != m_buffers.end())
114 116
         return;
@@ -130,11 +132,13 @@ void SoundManager::enableSound(bool enable)
130 132
         return;
131 133
 }
132 134
 
133
-void SoundManager::play(const std::string& filename)
135
+void SoundManager::play(std::string filename)
134 136
 {
135
-    if(!m_soundEnabled)
137
+    if(!m_soundEnabled || filename.empty())
136 138
         return;
137 139
 
140
+    filename = g_resources.resolvePath(filename);
141
+
138 142
     SoundSourcePtr soundSource = createSoundSource(filename);
139 143
     if(!soundSource) {
140 144
         g_logger.error(stdext::format("unable to play '%s'", filename));
@@ -154,17 +158,21 @@ void SoundManager::enableMusic(bool enable)
154 158
 
155 159
     m_musicEnabled = enable;
156 160
 
157
-    if(enable)
161
+    if(enable && !m_currentMusic.empty())
158 162
         playMusic(m_currentMusic, 3.0f);
159 163
     else
160 164
         m_musicSource = nullptr;
161 165
 }
162 166
 
163
-void SoundManager::playMusic(const std::string& filename, float fadetime)
167
+void SoundManager::playMusic(std::string filename, float fadetime)
164 168
 {
169
+    if(filename.empty())
170
+        return;
171
+
172
+    filename = g_resources.resolvePath(filename);
173
+
165 174
     if(m_currentMusic == filename && m_musicSource)
166 175
         return;
167
-    m_currentMusic = g_resources.resolvePath(filename);
168 176
 
169 177
     if(!m_musicEnabled)
170 178
         return;

+ 3
- 3
src/framework/sound/soundmanager.h View File

@@ -38,12 +38,12 @@ public:
38 38
     void terminate();
39 39
     void poll();
40 40
 
41
-    void preload(const std::string& filename);
41
+    void preload(std::string filename);
42 42
     void enableSound(bool enable);
43
-    void play(const std::string& filename);
43
+    void play(std::string filename);
44 44
 
45 45
     void enableMusic(bool enable);
46
-    void playMusic(const std::string& filename, float fadetime);
46
+    void playMusic(std::string filename, float fadetime);
47 47
     void stopMusic(float fadetime = 0);
48 48
 
49 49
     bool isMusicEnabled() { return m_musicEnabled; }

+ 58
- 69
src/otclient/item.cpp View File

@@ -199,78 +199,67 @@ bool Item::isValid()
199 199
 
200 200
 void Item::unserializeItem(const BinaryTreePtr &in)
201 201
 {
202
-    while (in->canRead()) {
203
-        uint8 attrType = in->getU8();
204
-        if(attrType == 0)
205
-            break;
206
-
207
-        // fugly switch yes?
208
-        switch ((AttrTypes_t)attrType) {
209
-            case ATTR_COUNT:
210
-                setSubType(in->getU8());
211
-                break;
212
-            case ATTR_CHARGES:
213
-                setSubType(in->getU16());
214
-                break;
215
-            case ATTR_ACTION_ID:
216
-                setActionId(in->getU16());
217
-                break;
218
-            case ATTR_UNIQUE_ID:
219
-                setUniqueId(in->getU16());
220
-                break;
221
-            case ATTR_NAME:
222
-                m_attribs.set(ATTR_NAME, in->getString());
223
-                break;
224
-            case ATTR_TEXT:
225
-                m_attribs.set(ATTR_TEXT, in->getString());
226
-                break;
227
-            case ATTR_DESC:
228
-                m_attribs.set(ATTR_DESC, in->getString());
229
-                break;
230
-            case ATTR_CONTAINER_ITEMS:
231
-                m_attribs.set(ATTR_CONTAINER_ITEMS, in->getU32());
232
-                break;
233
-            case ATTR_HOUSEDOORID:
234
-                m_attribs.set(ATTR_HOUSEDOORID, in->getU8());
235
-                break;
236
-            case ATTR_DEPOT_ID:
237
-                m_attribs.set(ATTR_DEPOT_ID, in->getU16());
238
-                break;
239
-            case ATTR_TELE_DEST: {
240
-                Position teleportDestination;
241
-                teleportDestination.x = in->getU16();
242
-                teleportDestination.y = in->getU16();
243
-                teleportDestination.z = in->getU8();
244
-                m_attribs.set(ATTR_TELE_DEST, teleportDestination);
202
+    try {
203
+        while(in->canRead()) {
204
+            int attrib = in->getU8();
205
+            if(attrib == 0)
245 206
                 break;
207
+
208
+            switch(attrib) {
209
+                case ATTR_COUNT:
210
+                case ATTR_RUNE_CHARGES:
211
+                    setCount(in->getU8());
212
+                    break;
213
+                case ATTR_CHARGES:
214
+                    setCount(in->getU16());
215
+                    break;
216
+                case ATTR_HOUSEDOORID:
217
+                case ATTR_SCRIPTPROTECTED:
218
+                case ATTR_DUALWIELD:
219
+                case ATTR_DECAYING_STATE:
220
+                    m_attribs.set(attrib, in->getU8());
221
+                    break;
222
+                case ATTR_ACTION_ID:
223
+                case ATTR_UNIQUE_ID:
224
+                case ATTR_DEPOT_ID:
225
+                    m_attribs.set(attrib, in->getU16());
226
+                    break;
227
+                case ATTR_CONTAINER_ITEMS:
228
+                case ATTR_ATTACK:
229
+                case ATTR_EXTRAATTACK:
230
+                case ATTR_DEFENSE:
231
+                case ATTR_EXTRADEFENSE:
232
+                case ATTR_ARMOR:
233
+                case ATTR_ATTACKSPEED:
234
+                case ATTR_HITCHANCE:
235
+                case ATTR_DURATION:
236
+                case ATTR_WRITTENDATE:
237
+                case ATTR_SLEEPERGUID:
238
+                case ATTR_SLEEPSTART:
239
+                case ATTR_ATTRIBUTE_MAP:
240
+                    m_attribs.set(attrib, in->getU32());
241
+                    break;
242
+                case ATTR_TELE_DEST: {
243
+                    Position pos;
244
+                    pos.x = in->getU16();
245
+                    pos.y = in->getU16();
246
+                    pos.z = in->getU8();
247
+                    m_attribs.set(attrib, pos);
248
+                    break;
249
+                }
250
+                case ATTR_NAME:
251
+                case ATTR_TEXT:
252
+                case ATTR_DESC:
253
+                case ATTR_ARTICLE:
254
+                case ATTR_WRITTENBY:
255
+                    m_attribs.set(attrib, in->getString());
256
+                    break;
257
+                default:
258
+                    stdext::throw_exception(stdext::format("invalid item attribute %d", attrib));
246 259
             }
247
-            case ATTR_ARTICLE:
248
-            case ATTR_WRITTENBY:
249
-                in->getString();
250
-                break;
251
-            case ATTR_ATTACK:
252
-            case ATTR_EXTRAATTACK:
253
-            case ATTR_DEFENSE:
254
-            case ATTR_EXTRADEFENSE:
255
-            case ATTR_ARMOR:
256
-            case ATTR_ATTACKSPEED:
257
-            case ATTR_HITCHANCE:
258
-            case ATTR_DURATION:
259
-            case ATTR_WRITTENDATE:
260
-            case ATTR_SLEEPERGUID:
261
-            case ATTR_SLEEPSTART:
262
-            case ATTR_ATTRIBUTE_MAP:
263
-                in->skip(4);
264
-                break;
265
-            case ATTR_SCRIPTPROTECTED:
266
-            case ATTR_DUALWIELD:
267
-            case ATTR_DECAYING_STATE:
268
-            case ATTR_RUNE_CHARGES:
269
-                in->skip(1);
270
-                break;
271
-            default:
272
-                stdext::throw_exception(stdext::format("invalid item attribute %d", (int)attrType));
273 260
         }
261
+    } catch(stdext::exception& e) {
262
+        g_logger.error(stdext::format("Failed to unserialize OTBM item: %s", e.what()));
274 263
     }
275 264
 }
276 265
 

+ 4
- 0
src/otclient/item.h View File

@@ -31,6 +31,8 @@
31 31
 enum AttrTypes_t
32 32
 {
33 33
     ATTR_END = 0,
34
+    //ATTR_DESCRIPTION = 1,
35
+    //ATTR_EXT_FILE = 2,
34 36
     ATTR_TILE_FLAGS = 3,
35 37
     ATTR_ACTION_ID = 4,
36 38
     ATTR_UNIQUE_ID = 5,
@@ -39,7 +41,9 @@ enum AttrTypes_t
39 41
     ATTR_TELE_DEST = 8,
40 42
     ATTR_ITEM = 9,
41 43
     ATTR_DEPOT_ID = 10,
44
+    //ATTR_EXT_SPAWN_FILE = 11,
42 45
     ATTR_RUNE_CHARGES = 12,
46
+    //ATTR_EXT_HOUSE_FILE = 13,
43 47
     ATTR_HOUSEDOORID = 14,
44 48
     ATTR_COUNT = 15,
45 49
     ATTR_DURATION = 16,

+ 3
- 0
src/otclient/thingtypemanager.cpp View File

@@ -43,6 +43,9 @@ void ThingTypeManager::init()
43 43
     m_datLoaded = false;
44 44
     m_xmlLoaded = false;
45 45
     m_otbLoaded = false;
46
+    for(int i = 0; i < DatLastCategory; ++i)
47
+        m_datTypes[i].resize(1, m_nullDatType);
48
+    m_otbTypes.resize(1, m_nullOtbType);
46 49
 }
47 50
 
48 51
 void ThingTypeManager::terminate()

Loading…
Cancel
Save