sramfile.hh

Go to the documentation of this file.
00001 /*
00002  * dwsrame - Dragon Warrior SRAM Editor
00003  * Copyright (C) 2006-2007 emuWorks
00004  * http://games.technoplaza.net/
00005  *
00006  * This file is part of dwsrame.
00007  *
00008  * dwsrame is free software; you can redistribute it and/or modify it under the
00009  * terms of the GNU General Public License as published by the Free Software
00010  * Foundation; either version 2 of the License, or (at your option) any later
00011  * version.
00012  *
00013  * dwsrame is distributed in the hope that it will be useful, but WITHOUT ANY
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00015  * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * dwsrame; if not, write to the Free Software Foundation, Inc.,
00019  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 // $Id: sramfile.hh,v 1.9 2007/02/03 02:09:00 technoplaza Exp $
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     /// the armor bits of the equipment byte
00033     const int ARMOR_MASK = 0x1C;
00034     
00035     /// the checksum offset
00036     const int CHECKSUM_OFFSET = 0x1E;
00037     
00038     /// the equipment offset
00039     const int EQUIPMENT_OFFSET = 0xA;
00040     
00041     /// the experience offset
00042     const int EXP_OFFSET = 0x0;
00043     
00044     /// the starting offset of the games
00045     const int GAME_OFFSET = 0x68;
00046     
00047     /// the size of a save game
00048     const int GAME_SIZE = 0x140;
00049     
00050     /// the gold offset
00051     const int GOLD_OFFSET = 0x2;
00052     
00053     /// the medical herbs offset
00054     const int HERBS_OFFSET = 0x9;
00055     
00056     /// the hit points offset
00057     const int HP_OFFSET = 0x17;
00058     
00059     /// the starting item offset
00060     const int ITEM_OFFSET = 0x4;
00061     
00062     /// the offset of the KEN MASUTA string
00063     const int KENMASUTA_OFFSET = 0x3B;
00064     
00065     /// the magic keys offset
00066     const int KEYS_OFFSET = 0x8;
00067     
00068     /// the magic number appears many times in the SRAM
00069     const char MAGIC_NUMBER = '\xC8';
00070     
00071     /// the magic points offset
00072     const int MP_OFFSET = 0x18;
00073     
00074     /// the name offset
00075     const int NAME_OFFSET = 0xE;
00076     
00077     /// the shield bits of the equipment byte
00078     const int SHIELD_MASK = 0x3;
00079     
00080     /// the starting offset of the game slot usage bytes
00081     const int SLOT_OFFSET = 0x35;
00082     
00083     /// the size of an SRAM file
00084     const int SRAM_SIZE = 0x2000;
00085     
00086     /// the weapon bits of the equipment byte
00087     const int WEAPON_MASK = 0xE0;
00088     
00089     /// the armors
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     /// the items
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     /// the quest markers
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     /// the shields
00113     enum dw_shield {
00114         DW_NOSHIELD, DW_SMALLSHIELD, DW_LARGESHIELD, DW_SILVERSHIELD
00115     };
00116     
00117     /// the weapons
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     /// class to interface with an SRAM file
00125     class SRAMFile {
00126     private:
00127         int game;
00128         char sram[SRAM_SIZE];
00129         unsigned char *offset;
00130         bool valid[3], modified;
00131         
00132         /// the various quest offsets
00133         static const std::pair<int, int> QUEST_OFFSETS[];
00134         
00135         /**
00136          * Calculates the checksum for one of the save games.
00137          *
00138          * @param game The game to checksum.
00139          *
00140          * @return The checksum.
00141          */
00142         wxUint16 checksum(int game) const;
00143         
00144         /**
00145          * Converts an ASCII character to the Dragon Warrior alphabet.
00146          */
00147         char fromASCII(char asciiChar) const;
00148         
00149         /**
00150          * Converts a Dragon Warrior alphabetic character to ASCII.
00151          *
00152          * @param dwChar The Dragon Warrior character.
00153          *
00154          * @return The ASCII character.
00155          */
00156         char toASCII(char dwChar) const;
00157         
00158         /**
00159          * Gets the checksum for one of the save games.
00160          *
00161          * @param game The game.
00162          *
00163          * @return The checksum.
00164          */
00165         wxUint16 getChecksum(int game) const;
00166         
00167         /**
00168          * Sets the checksum for one of the save games.
00169          *
00170          * @param game The game.
00171          * @param checksum The new checksum.
00172          */
00173         void setChecksum(int game, wxUint16 checksum);
00174         
00175     public:
00176         /**
00177          * Creates a new SRAMFile.
00178          *
00179          * @param filename The SRAM filename.
00180          *
00181          * @throws InvalidSRAMFileException if the filename is not a valid
00182          *     Dragon Warrior SRAM file.
00183          */
00184         SRAMFile(const wxString &filename) throw(InvalidSRAMFileException);
00185         
00186         /**
00187          * Saves this SRAMfile back to disk.
00188          *
00189          * @param filename The filename to write the data to.
00190          *
00191          * @return true on success; false otherwise.
00192          */
00193         bool save(const wxString &filename);
00194         
00195         /**
00196          * Gets the hero's armor.
00197          *
00198          * @return The armor.
00199          */
00200         enum dw_armor getArmor() const;
00201         
00202         /**
00203          * Sets the hero's armor.
00204          *
00205          * @param armor The new armor.
00206          */
00207         void setArmor(enum dw_armor armor);
00208         
00209         /**
00210          * Gets the hero's experience.
00211          *
00212          * @return The experience.
00213          */
00214         wxUint16 getExperience() const;
00215         
00216         /**
00217          * Sets the hero's experience.
00218          *
00219          * @param experience The new experience.
00220          */
00221         void setExperience(wxUint16 experience);
00222         
00223         /**
00224          * Gets the current game.
00225          *
00226          * @return The game.
00227          */
00228         int getGame() const;
00229         
00230         /**
00231          * Sets the game currently being edited.
00232          *
00233          * @param game The game.
00234          */
00235         void setGame(int game);
00236         
00237         /**
00238          * Gets the hero's gold.
00239          *
00240          * @return The gold.
00241          */
00242         wxUint16 getGold() const;
00243         
00244         /**
00245          * Sets the hero's gold.
00246          *
00247          * @param gold The new gold.
00248          */
00249         void setGold(wxUint16 gold);
00250         
00251         /**
00252          * Gets the hero's herbs.
00253          *
00254          * @return The herbs.
00255          */
00256         int getHerbs() const;
00257         
00258         /**
00259          * Sets the hero's herbs.
00260          *
00261          * @param herbs The new herbs.
00262          */
00263         void setHerbs(int herbs);
00264         
00265         /**
00266          * Gets the hero's current HP.
00267          *
00268          * @return The current HP.
00269          */
00270         unsigned int getHP() const;
00271         
00272         /**
00273          * Sets the hero's current HP.
00274          *
00275          * @param hp The new current HP.
00276          */
00277         void setHP(unsigned int hp);
00278         
00279         /**
00280          * Gets one of the hero's items.
00281          *
00282          * @param number The item number.
00283          *
00284          * @return The item.
00285          */
00286         enum dw_item getItem(int number) const;
00287         
00288         /**
00289          * Sets one of the hero's items.
00290          *
00291          * @param item The new item.
00292          * @param number The item number.
00293          */
00294         void setItem(dw_item item, int number);
00295         
00296         /**
00297          * Gets the hero's keys.
00298          *
00299          * @return The keys.
00300          */
00301         int getKeys() const;
00302         
00303         /**
00304          * Sets the hero's keys.
00305          *
00306          * @param keys The new keys.
00307          */
00308         void setKeys(int keys);
00309         
00310         /**
00311          * Checks whether this SRAMFile has been modified or not.
00312          *
00313          * @return true if modified; false otherwise.
00314          */
00315         bool isModified() const;
00316         
00317         /**
00318          * Gets the hero's current MP.
00319          *
00320          * @return The current MP.
00321          */
00322         unsigned int getMP() const;
00323         
00324         /**
00325          * Sets the hero's current MP.
00326          *
00327          * @param mp The new current MP.
00328          */
00329         void setMP(unsigned int mp);
00330         
00331         /**
00332          * Gets the hero's name.
00333          *
00334          * @return The name.
00335          */
00336         wxString getName() const;
00337         
00338         /**
00339          * Sets the hero's name.
00340          *
00341          * @param name The new name.
00342          */
00343         void setName(const wxString &name);
00344         
00345         /**
00346          * Checks one of the quest markers.
00347          *
00348          * @param marker The quest marker to check.
00349          *
00350          * @return true if the quest marker is set, false otherwise.
00351          */
00352         bool getQuestMarker(enum dw_quest marker) const;
00353         
00354         /**
00355          * Sets one of the quest markers.
00356          *
00357          * @param marker The quest marker to set.
00358          * @param set true to set, false to clear.
00359          */
00360         void setQuestMarker(enum dw_quest marker, bool set = true);
00361         
00362         /**
00363          * Gets the hero's shield.
00364          *
00365          * @return The shield.
00366          */
00367         enum dw_shield getShield() const;
00368         
00369         /**
00370          * Sets the hero's shield.
00371          *
00372          * @param shield The new shield.
00373          */
00374         void setShield(dw_shield shield);
00375         
00376         /**
00377          * Checks whether a game is valid or not.
00378          *
00379          * @param game The game to check.
00380          *
00381          * @return true if valid; false otherwise.
00382          */
00383         bool isValid(int game) const;
00384         
00385         /**
00386          * Gets the hero's weapon.
00387          *
00388          * @return The weapon.
00389          */
00390         enum dw_weapon getWeapon() const;
00391         
00392         /**
00393          * Sets the hero's weapon.
00394          *
00395          * @param weapon The new weapon.
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 

Generated on Fri Feb 2 21:09:24 2007 for dwsrame by  doxygen 1.5.1-p1