00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _DWSRAME_SRAMFILE_HH_
00025 #define _DWSRAME_SRAMFILE_HH_
00026
00027 #include <utility>
00028
00029 #include "exception/invalidsramfileexception.hh"
00030
00031 namespace dwsrame {
00032
00033 const int ARMOR_MASK = 0x1C;
00034
00035
00036 const int CHECKSUM_OFFSET = 0x1E;
00037
00038
00039 const int EQUIPMENT_OFFSET = 0xA;
00040
00041
00042 const int EXP_OFFSET = 0x0;
00043
00044
00045 const int GAME_OFFSET = 0x68;
00046
00047
00048 const int GAME_SIZE = 0x140;
00049
00050
00051 const int GOLD_OFFSET = 0x2;
00052
00053
00054 const int HERBS_OFFSET = 0x9;
00055
00056
00057 const int HP_OFFSET = 0x17;
00058
00059
00060 const int ITEM_OFFSET = 0x4;
00061
00062
00063 const int KENMASUTA_OFFSET = 0x3B;
00064
00065
00066 const int KEYS_OFFSET = 0x8;
00067
00068
00069 const char MAGIC_NUMBER = '\xC8';
00070
00071
00072 const int MP_OFFSET = 0x18;
00073
00074
00075 const int NAME_OFFSET = 0xE;
00076
00077
00078 const int SHIELD_MASK = 0x3;
00079
00080
00081 const int SLOT_OFFSET = 0x35;
00082
00083
00084 const int SRAM_SIZE = 0x2000;
00085
00086
00087 const int WEAPON_MASK = 0xE0;
00088
00089
00090 enum dw_armor {
00091 DW_NOARMOR, DW_CLOTHES = 0x4, DW_LEATHERARMOR = 0x8, DW_CHAINMAIL = 0xC,
00092 DW_HALFPLATE = 0x10, DW_FULLPLATE = 0x14, DW_MAGICARMOR = 0x18,
00093 DW_ERDRICKSARMOR = 0x1C
00094 };
00095
00096
00097 enum dw_item {
00098 DW_NOITEM, DW_TORCH, DW_FAIRYWATER, DW_WINGS, DW_DRAGONSSCALE,
00099 DW_FAIRYFLUTE, DW_FIGHTERSRING, DW_ERDRICKSTOKEN, DW_GWAELINSLOVE,
00100 DW_CURSEDBELT, DW_SILVERHARP, DW_DEATHNECKLACE, DW_STONESOFSUNLIGHT,
00101 DW_STAFFOFRAIN, DW_RAINBOWDROP
00102 };
00103
00104
00105 enum dw_quest {
00106 DW_HIDDENSTAIRS, DW_RAINBOWBRIDGE, DW_USINGDRAGONSSCALE,
00107 DW_USINGFIGHTERSRING, DW_USINGCURSEDBELT, DW_USINGDEATHNECKLACE,
00108 DW_HOLDINGGWAELIN, DW_GWAELINONTHRONE, DW_LORIKSCHAMBER, DW_GOLEMDEAD,
00109 DW_DRAGONLORDDEAD, DW_GREENDRAGONDEAD
00110 };
00111
00112
00113 enum dw_shield {
00114 DW_NOSHIELD, DW_SMALLSHIELD, DW_LARGESHIELD, DW_SILVERSHIELD
00115 };
00116
00117
00118 enum dw_weapon {
00119 DW_NOWEAPON, DW_BAMBOOPOLE = 0x20, DW_CLUB = 0x40,
00120 DW_COPPERSWORD = 0x60, DW_HANDAXE = 0x80, DW_BROADSWORD = 0xA0,
00121 DW_FLAMESWORD = 0xC0, DW_ERDRICKSSWORD = 0xE0
00122 };
00123
00124
00125 class SRAMFile {
00126 private:
00127 int game;
00128 char sram[SRAM_SIZE];
00129 unsigned char *offset;
00130 bool valid[3], modified;
00131
00132
00133 static const std::pair<int, int> QUEST_OFFSETS[];
00134
00135
00136
00137
00138
00139
00140
00141
00142 wxUint16 checksum(int game) const;
00143
00144
00145
00146
00147 char fromASCII(char asciiChar) const;
00148
00149
00150
00151
00152
00153
00154
00155
00156 char toASCII(char dwChar) const;
00157
00158
00159
00160
00161
00162
00163
00164
00165 wxUint16 getChecksum(int game) const;
00166
00167
00168
00169
00170
00171
00172
00173 void setChecksum(int game, wxUint16 checksum);
00174
00175 public:
00176
00177
00178
00179
00180
00181
00182
00183
00184 SRAMFile(const wxString &filename) throw(InvalidSRAMFileException);
00185
00186
00187
00188
00189
00190
00191
00192
00193 bool save(const wxString &filename);
00194
00195
00196
00197
00198
00199
00200 enum dw_armor getArmor() const;
00201
00202
00203
00204
00205
00206
00207 void setArmor(enum dw_armor armor);
00208
00209
00210
00211
00212
00213
00214 wxUint16 getExperience() const;
00215
00216
00217
00218
00219
00220
00221 void setExperience(wxUint16 experience);
00222
00223
00224
00225
00226
00227
00228 int getGame() const;
00229
00230
00231
00232
00233
00234
00235 void setGame(int game);
00236
00237
00238
00239
00240
00241
00242 wxUint16 getGold() const;
00243
00244
00245
00246
00247
00248
00249 void setGold(wxUint16 gold);
00250
00251
00252
00253
00254
00255
00256 int getHerbs() const;
00257
00258
00259
00260
00261
00262
00263 void setHerbs(int herbs);
00264
00265
00266
00267
00268
00269
00270 unsigned int getHP() const;
00271
00272
00273
00274
00275
00276
00277 void setHP(unsigned int hp);
00278
00279
00280
00281
00282
00283
00284
00285
00286 enum dw_item getItem(int number) const;
00287
00288
00289
00290
00291
00292
00293
00294 void setItem(dw_item item, int number);
00295
00296
00297
00298
00299
00300
00301 int getKeys() const;
00302
00303
00304
00305
00306
00307
00308 void setKeys(int keys);
00309
00310
00311
00312
00313
00314
00315 bool isModified() const;
00316
00317
00318
00319
00320
00321
00322 unsigned int getMP() const;
00323
00324
00325
00326
00327
00328
00329 void setMP(unsigned int mp);
00330
00331
00332
00333
00334
00335
00336 wxString getName() const;
00337
00338
00339
00340
00341
00342
00343 void setName(const wxString &name);
00344
00345
00346
00347
00348
00349
00350
00351
00352 bool getQuestMarker(enum dw_quest marker) const;
00353
00354
00355
00356
00357
00358
00359
00360 void setQuestMarker(enum dw_quest marker, bool set = true);
00361
00362
00363
00364
00365
00366
00367 enum dw_shield getShield() const;
00368
00369
00370
00371
00372
00373
00374 void setShield(dw_shield shield);
00375
00376
00377
00378
00379
00380
00381
00382
00383 bool isValid(int game) const;
00384
00385
00386
00387
00388
00389
00390 enum dw_weapon getWeapon() const;
00391
00392
00393
00394
00395
00396
00397 void setWeapon(enum dw_weapon weapon);
00398 };
00399
00400 inline enum dw_armor SRAMFile::getArmor() const
00401 {
00402 return static_cast<enum dw_armor>
00403 (offset[EQUIPMENT_OFFSET] & ARMOR_MASK);
00404 }
00405
00406 inline int SRAMFile::getGame() const
00407 { return game; }
00408
00409 inline int SRAMFile::getHerbs() const
00410 { return offset[HERBS_OFFSET]; }
00411
00412 inline unsigned int SRAMFile::getHP() const
00413 { return offset[HP_OFFSET]; }
00414
00415 inline int SRAMFile::getKeys() const
00416 { return offset[KEYS_OFFSET]; }
00417
00418 inline bool SRAMFile::isModified() const
00419 { return modified; }
00420
00421 inline unsigned int SRAMFile::getMP() const
00422 { return offset[MP_OFFSET]; }
00423
00424 inline bool SRAMFile::getQuestMarker(enum dw_quest marker) const
00425 {
00426 return offset[QUEST_OFFSETS[marker].first] &
00427 QUEST_OFFSETS[marker].second;
00428 }
00429
00430 inline enum dw_shield SRAMFile::getShield() const
00431 {
00432 return static_cast<enum dw_shield>
00433 (offset[EQUIPMENT_OFFSET] & SHIELD_MASK);
00434 }
00435
00436 inline bool SRAMFile::isValid(int game) const
00437 {
00438 wxASSERT((game >= 0) && (game < 3));
00439 return valid[game];
00440 }
00441
00442 inline enum dw_weapon SRAMFile::getWeapon() const
00443 {
00444 return static_cast<enum dw_weapon>
00445 (offset[EQUIPMENT_OFFSET] & WEAPON_MASK);
00446 }
00447 }
00448
00449 #endif
00450