sramfile.hh

Go to the documentation of this file.
00001 /*
00002  * lozsrame - Legend of Zelda SRAM Editor
00003  * Copyright (C) 2007-2008 emuWorks
00004  * http://games.technoplaza.net/
00005  *
00006  * This file is part of lozsrame.
00007  *
00008  * lozsrame 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  * lozsrame 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  * lozsrame; 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.10 2008/02/01 13:21:44 technoplaza Exp $
00023 
00024 #ifndef LOZSRAME_SRAMFILE_HH_
00025 #define LOZSRAME_SRAMFILE_HH_
00026 
00027 #include <QString>
00028 
00029 #include "exceptions/invalidsramfileexception.hh"
00030 
00031 namespace lozsrame {
00032     /// offset of the arrow data
00033     const int ARROWS_OFFSET = 0x2;
00034     
00035     /// offset of link's bomb carrying capacity
00036     const int BOMBCAPACITY_OFFSET = 0x25;
00037     
00038     /// offset of bomb count data
00039     const int BOMBS_OFFSET = 0x1;
00040     
00041     /// offset of the candle data
00042     const int CANDLE_OFFSET = 0x4;
00043     
00044     /// starting offset of the checksum data
00045     const int CHECKSUM_OFFSET = 0x524;
00046     
00047     /// offset of the compass data
00048     const int COMPASS_OFFSET = 0x10;
00049     
00050     /// offset of the compass data for level 9
00051     const int COMPASS9_OFFSET = 0x12;
00052     
00053     /// offset of the heart container data
00054     const int HEARTCONTAINERS_OFFSET = 0x18;
00055     
00056     /// starting offset of the inventory data
00057     const int INVENTORY_DATA = 0x1A;
00058     
00059     /// size of the inventory data
00060     const int INVENTORY_DATA_SIZE = 0x28;
00061     
00062     /// offset of the keys
00063     const int KEYS_OFFSET = 0x17;
00064     
00065     /// starting offset of the map data
00066     const int MAP_DATA = 0x92;
00067     
00068     /// size of the map data
00069     const int MAP_DATA_SIZE = 0x180;
00070     
00071     /// offset of the level map data
00072     const int MAP_OFFSET = 0x11;
00073     
00074     /// offset of the level map data for level 9
00075     const int MAP9_OFFSET = 0x13;
00076     
00077     /// starting offset of the misc data
00078     const int MISC_DATA = 0x512;
00079     
00080     /// size of the misc data
00081     const int MISC_DATA_SIZE = 0x4;
00082     
00083     /// starting offset of the name data
00084     const int NAME_DATA = 0x2;
00085     
00086     /// size of the name data
00087     const int NAME_DATA_SIZE = 0x8;
00088     
00089     /// offset of the note data
00090     const int NOTE_OFFSET = 0xF;
00091     
00092     /// offset of the quest data
00093     const int QUEST_OFFSET = 0x9;
00094     
00095     /// offset of the play count
00096     const int PLAYCOUNT_OFFSET = 0x6;
00097     
00098     /// offset of the potion data
00099     const int POTION_OFFSET = 0x7;
00100     
00101     /// offset of the ring data
00102     const int RING_OFFSET = 0xB;
00103     
00104     /// offset of the rupees
00105     const int RUPEES_OFFSET = 0x16;
00106     
00107     /// size of the SRAM data
00108     const int SRAM_SIZE = 0x2000;
00109     
00110     /// offset of sword data
00111     const int SWORD_OFFSET = 0x0;
00112     
00113     /// offset of the triforce data
00114     const int TRIFORCE_OFFSET = 0x1A;
00115     
00116     /// the types of arrows
00117     enum sf_arrow {
00118         ARROW_NONE, ARROW_WOODEN, ARROW_SILVER
00119     };
00120     
00121     /// the types of candles
00122     enum sf_candle {
00123         CANDLE_NONE, CANDLE_BLUE, CANDLE_RED
00124     };
00125     
00126     /// the game items
00127     enum sf_item {
00128         ITEM_BOW = 3, ITEM_WHISTLE = 5, ITEM_BAIT, ITEM_WAND = 8, ITEM_RAFT,
00129         ITEM_BOOK, ITEM_LADDER = 12, ITEM_MAGICKEY, ITEM_POWERBRACELET,
00130         ITEM_BOOMERANG = 29, ITEM_MAGICBOOMERANG, ITEM_MAGICSHIELD
00131     };
00132     
00133     /// locations of the potion note
00134     enum sf_note {
00135         NOTE_OLDMAN, NOTE_LINK, NOTE_OLDWOMAN
00136     };
00137     
00138     /// the types of potions
00139     enum sf_potion {
00140         POTION_NONE, POTION_BLUE, POTION_RED
00141     };
00142     
00143     /// the types of quests
00144     enum sf_quest {
00145         QUEST_FIRST, QUEST_SECOND
00146     };
00147     
00148     /// the types of rings
00149     enum sf_ring {
00150         RING_NONE, RING_BLUE, RING_RED
00151     };
00152     
00153     /// the types of swords
00154     enum sf_sword {
00155         SWORD_NONE, SWORD_WOODEN, SWORD_WHITE, SWORD_MASTER
00156     };
00157     
00158     /**
00159      * A model of the SRAM data used by The Legend of Zelda.
00160      */
00161     class SRAMFile {
00162     private:
00163         int game;
00164         char sram[SRAM_SIZE];
00165         bool modified, valid[3];
00166         
00167         /**
00168          * Calculates the checksum for one of the games.
00169          *
00170          * @param game The game to checksum.
00171          *
00172          * @return The checksum.
00173          */
00174         quint16 checksum(int game) const;
00175         
00176         /**
00177          * Gets the checksum value for one of the games.
00178          *
00179          * @param game The game.
00180          *
00181          * @return The checksum.
00182          */
00183         quint16 getChecksum(int game) const;
00184         
00185         /**
00186          * Sets the checksum value for one of the games.
00187          *
00188          * @param game The game.
00189          * @param checksum The new checksum.
00190          */
00191         void setChecksum(int game, quint16 checksum);
00192 
00193     public:
00194         /**
00195          * Creates an SRAMFile object from an SRAM file.
00196          *
00197          * @param filename The SRAM filename.
00198          *
00199          * @return The new SRAMFile object.
00200          *
00201          * @throw InvalidSRAMFileException if the file is not a valid SRAM file.
00202          */
00203         SRAMFile(const QString &filename) throw(InvalidSRAMFileException);
00204         
00205         /**
00206          * Saves the SRAM data to a file.
00207          *
00208          * @param filename The file to save to.
00209          *
00210          * @return true if the save succeeded; false otherwise.
00211          */
00212         bool save(const QString &filename);
00213         
00214         /**
00215          * Gets the kind of arrows Link is carrying.
00216          *
00217          * @return The kind of arrows.
00218          */
00219         enum sf_arrow getArrows() const;
00220         
00221         /**
00222          * Sets the kind of arrows Link is carrying.
00223          *
00224          * @param arrows The new kind of arrows.
00225          */
00226         void setArrows(sf_arrow arrows);
00227         
00228         /**
00229          * Gets Link's bomb capacity.
00230          *
00231          * @return The bomb capacity.
00232          */
00233         int getBombCapacity() const;
00234         
00235         /**
00236          * Sets Link's bomb capacity.
00237          *
00238          * @param capacity The new bomb capacity.
00239          */
00240         void setBombCapacity(int capacity);
00241         
00242         /**
00243          * Gets the number of bombs Link is carrying.
00244          *
00245          * @return The bomb count.
00246          */
00247         int getBombs() const;
00248         
00249         /**
00250          * Sets the number of bombs Link is carrying.
00251          *
00252          * @param bombs The new bomb count.
00253          */
00254         void setBombs(int bombs);
00255         
00256         /**
00257          * Gets the candle Link is carrying.
00258          *
00259          * @return The candle.
00260          */
00261         enum sf_candle getCandle() const;
00262         
00263         /**
00264          * Sets the candle Link is carrying.
00265          *
00266          * @param candle The new candle.
00267          */
00268         void setCandle(enum sf_candle candle);
00269         
00270         /**
00271          * Checks if Link has the compass for a level.
00272          *
00273          * @param level The level to check.
00274          *
00275          * @return true if Link has the compass; false otherwise.
00276          */
00277         bool hasCompass(int level) const;
00278         
00279         /**
00280          * Sets whether Link has the compass for a level.
00281          *
00282          * @param level The level to check.
00283          * @param give true to give the compass; false to take away.
00284          */
00285         void setCompass(int level, bool give);
00286         
00287         /**
00288          * Gets the game slot being edited.
00289          *
00290          * @return The game slot (0 - 2).
00291          */
00292         int getGame() const;
00293         
00294         /**
00295          * Sets the game slot (0 - 2) being edited.
00296          *
00297          * @param game The new game.
00298          */
00299         void setGame(int game);
00300         
00301         /**
00302          * Gets the number of heart containers Link has.
00303          *
00304          * @return The number of heart containers.
00305          */
00306         int getHeartContainers() const;
00307         
00308         /**
00309          * Sets the number of heart containers Link has.
00310          *
00311          * @param containers The new number of heart containers.
00312          */
00313         void setHeartContainers(int containers);
00314         
00315         /**
00316          * Checks if Link has a particular item or not.
00317          *
00318          * @param item The item to check.
00319          *
00320          * @return true if Link has the item; false otherwise.
00321          */
00322         bool hasItem(sf_item item) const;
00323         
00324         /**
00325          * Sets whether Link has a particular item or not.
00326          *
00327          * @param item The item to set.
00328          * @param give true to give; false to take away.
00329          */
00330         void setItem(sf_item item, bool give);
00331         
00332         /**
00333          * Gets the number of keys Link has.
00334          *
00335          * @return The number of keys.
00336          */
00337         int getKeys() const;
00338         
00339         /**
00340          * Sets the number of keys Link has.
00341          *
00342          * @param keys The new number of keys.
00343          */
00344         void setKeys(int keys);
00345         
00346         /**
00347          * Checks if Link has the map for a level.
00348          *
00349          * @param level The level to check.
00350          *
00351          * @return true if Link has the map; false otherwise.
00352          */
00353         bool hasMap(int level) const;
00354         
00355         /**
00356          * Sets whether Link has the map for a level.
00357          *
00358          * @param level The level to set.
00359          * @param give true to give the map; false to take away.
00360          */
00361         void setMap(int level, bool give);
00362         
00363         /**
00364          * Checks if this SRAMFile has been modified or not.
00365          *
00366          * @return true if modified; false otherwise.
00367          */
00368         bool isModified() const;
00369         
00370         /**
00371          * Gets the name of the hero.
00372          *
00373          * @return The name.
00374          */
00375         QString getName() const;
00376         
00377         /**
00378          * Sets the name of the hero.
00379          *
00380          * @param name The new name.
00381          */
00382         void setName(const QString &name);
00383         
00384         /**
00385          * Gets the location of the potion note.
00386          *
00387          * @return The location.
00388          */
00389         enum sf_note getNote() const;
00390         
00391         /**
00392          * Sets the location of the potion note.
00393          *
00394          * @param note The new location.
00395          */
00396         void setNote(enum sf_note note);
00397         
00398         /**
00399          * Gets the game's play count.
00400          *
00401          * @return The play count.
00402          */
00403         int getPlayCount() const;
00404         
00405         /**
00406          * Sets the game's play count.
00407          *
00408          * @param count The new play count.
00409          */
00410         void setPlayCount(int count);
00411         
00412         /**
00413          * Gets the potion Link is carrying.
00414          *
00415          * @return The potion.
00416          */
00417         enum sf_potion getPotion() const;
00418         
00419         /**
00420          * Sets the potion Link is carrying.
00421          *
00422          * @param potion The new potion.
00423          */
00424         void setPotion(enum sf_potion potion);
00425         
00426         /**
00427          * Gets the quest Link is on.
00428          *
00429          * @return The current quest.
00430          */
00431         enum sf_quest getQuest() const;
00432         
00433         /**
00434          * Sets the quest Link is on.
00435          *
00436          * @param quest The new quest.
00437          */
00438         void setQuest(enum sf_quest quest);
00439         
00440         /**
00441          * Gets the ring Link is wearing.
00442          *
00443          * @return The ring.
00444          */
00445         enum sf_ring getRing() const;
00446         
00447         /**
00448          * Sets the ring Link is wearing.
00449          *
00450          * @param ring The new ring.
00451          */
00452         void setRing(enum sf_ring ring);
00453         
00454         /**
00455          * Gets how many rupees Link is carrying.
00456          *
00457          * @return The rupees.
00458          */
00459         int getRupees() const;
00460         
00461         /**
00462          * Sets how many rupees Link is carrying.
00463          *
00464          * @param rupees The new rupees.
00465          */
00466         void setRupees(int rupees);
00467         
00468         /**
00469          * Gets the sword Link has.
00470          *
00471          * @return The sword.
00472          */
00473         enum sf_sword getSword() const;
00474         
00475         /**
00476          * Sets the sword Link has.
00477          *
00478          * @param sword The new sword.
00479          */
00480         void setSword(enum sf_sword sword);
00481         
00482         /**
00483          * Checks if Link has a piece of the triforce.
00484          *
00485          * @param piece The piece to check.
00486          *
00487          * @return true if Link has the piece; false otherwise.
00488          */
00489         bool hasTriforce(int piece) const;
00490         
00491         /**
00492          * Sets whether Link has a piece of the triforce.
00493          *
00494          * @param piece The piece to set.
00495          * @param give true to give; false to take away.
00496          */
00497         void setTriforce(int piece, bool give);
00498         
00499         /**
00500          * Returns true if a game slot is valid; false otherwise.
00501          *
00502          * @param game The game slot to check.
00503          *
00504          * @return true if valid; false otherwise.
00505          */
00506         bool isValid(int game) const;
00507     };
00508     
00509     inline int SRAMFile::getGame() const
00510         {
00511             return game;
00512         }
00513     
00514     inline void SRAMFile::setGame(int game)
00515         {
00516             Q_ASSERT(isValid(game));
00517             
00518             this->game = game;
00519         }
00520         
00521     inline bool SRAMFile::isModified() const
00522         {
00523             return modified;
00524         }
00525         
00526     inline bool SRAMFile::isValid(int game) const
00527         {
00528             Q_ASSERT((game >= 0) && (game <= 2));
00529             
00530             return valid[game];
00531         }
00532 }
00533 
00534 #endif
00535 

Generated on Mon Dec 29 00:56:06 2008 for Legend of Zelda SRAM Editor by  doxygen 1.5.4