sramfile.hh

Go to the documentation of this file.
00001 /*
00002  * Secret of Evermore SRAM Editor
00003  * Copyright (C) 2006 emuWorks
00004  * http://games.technoplaza.net/
00005  *
00006  * This file is part of Secret of Evermore SRAM Editor.
00007  *
00008  * Secret of Evermore SRAM Editor is free software; you can redistribute it
00009  * and/or modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the License,
00011  * or (at your option) any later version.
00012  *
00013  * Secret of Evermore SRAM Editor is distributed in the hope that it will be
00014  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Secret of Evermore SRAM Editor; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021  */
00022  
00023 // $Id: sramfile.hh,v 1.18 2006/09/02 16:24:45 technoplaza Exp $
00024 
00025 #ifndef _SOESRAME_SRAMFILE_HH_
00026 #define _SOESRAME_SRAMFILE_HH_
00027 
00028 #include <utility>
00029 
00030 #include <QString>
00031 
00032 #include "exceptions/invalidsramfileexception.hh"
00033 
00034 namespace soesrame {
00035     /// base major alchemy levels offset
00036     const int SRAM_ALCHEMYMAJORLEVELS_OFFSET = 0x19B;
00037     
00038     /// base minor alchemy levels offset
00039     const int SRAM_ALCHEMYMINORLEVELS_OFFSET = 0x155;
00040     
00041     /// offset of the boy's current HP
00042     const int SRAM_BOY_CURRENTHP_OFFSET = 0x6E;
00043     
00044     /// offset of the boy's experience
00045     const int SRAM_BOY_EXPERIENCE_OFFSET = 0x9A;
00046     
00047     /// offset of the boy's level
00048     const int SRAM_BOY_LEVEL_OFFSET = 0x9D;
00049     
00050     /// offset of the boy's max HP
00051     const int SRAM_BOY_MAXHP_OFFSET = 0x8E;
00052     
00053     /// offset of the boy's name
00054     const int SRAM_BOY_NAME_OFFSET = 0x26;
00055     
00056     /// offset of the game's checksum
00057     const int SRAM_CHECKSUM_OFFSET = 0x0;
00058     
00059     /// offset of the dog's current HP
00060     const int SRAM_DOG_CURRENTHP_OFFSET = 0xAF;
00061     
00062     /// offset of the dog's experience
00063     const int SRAM_DOG_EXPERIENCE_OFFSET = 0xDB;
00064     
00065     /// offset of the dog's level
00066     const int SRAM_DOG_LEVEL_OFFSET = 0xDE;
00067     
00068     /// offset of the dog's max HP
00069     const int SRAM_DOG_MAXHP_OFFSET = 0xCF;
00070     
00071     /// offset of the dog's name
00072     const int SRAM_DOG_NAME_OFFSET = 0x4A;
00073     
00074     /// offset of the dog's attack level
00075     const int SRAM_DOG_ATTACKLEVEL_OFFSET = 0x13D;
00076     
00077     /// size of the SRAM file
00078     const int SRAM_FILE_SIZE = 0x2000;
00079     
00080     /// base offset of the game data in the SRAM
00081     const int SRAM_GAME_OFFSET = 0x2;
00082     
00083     /// individual save game size
00084     const int SRAM_GAME_SIZE = 0x331;
00085     
00086     /// base alchemy ingredient offset
00087     const int SRAM_INGREDIENTS_OFFSET = 0x289;
00088     
00089     /// base item offset
00090     const int SRAM_ITEMS_OFFSET = 0x29F;
00091     
00092     /// base money offset
00093     const int SRAM_MONEY_OFFSET = 0xFC;
00094     
00095     /// base tradegood offset
00096     const int SRAM_TRADEGOODS_OFFSET = 0x315;
00097     
00098     /// base weapon levels offset
00099     const int SRAM_WEAPONLEVELS_OFFSET = 0x115;
00100     
00101     /// the alchemys
00102     enum sf_alchemy {
00103         SF_ACIDRAIN, SF_ATLAS, SF_BARRIER, SF_CALLUP, SF_CORROSION, SF_CRUSH,
00104         SF_CURE, SF_DEFEND, SF_DOUBLEDRAIN, SF_DRAIN, SF_ENERGIZE, SF_ESCAPE,
00105         SF_EXPLOSION, SF_FIREBALL, SF_FIREPOWER, SF_FLASH, SF_FORCEFIELD,
00106         SF_HARDBALL, SF_HEAL, SF_LANCEALCHEMY, SF_LASERDUMMY, SF_LEVITATE,
00107         SF_LIGHTNINGSTORM, SF_MIRACLECURE, SF_NITRO, SF_ONEUP, SF_REFLECT,
00108         SF_REGROWTH, SF_REVEALER, SF_REVIVE, SF_SLOWBURN, SF_SPEED, SF_STING,
00109         SF_STOP, SF_SUPERHEAL
00110     };
00111     
00112     /// the charms
00113     enum sf_charm {
00114         SF_ARMORPOLISH, SF_CHOCOBOEGG, SF_INSECTINCENSE, SF_JADEDISK,
00115         SF_JAGUARRING, SF_MAGICGOURD, SF_MOXASTICK, SF_ORACLEBONE, SF_RUBYHEART,
00116         SF_SILVERSHEATH, SF_STAFFOFLIFE, SF_SUNSTONE, SF_THUGSCLOAK,
00117         SF_WIZARDSCOIN
00118     };
00119     
00120     /// the heros
00121     enum sf_hero {
00122         SF_BOY, SF_DOG
00123     };
00124     
00125     /// the alchemy ingredients
00126     enum sf_ingredient {
00127         SF_WAX, SF_WATER, SF_VINEGAR, SF_ROOT, SF_OIL, SF_MUSHROOM,
00128         SF_MUDPEPPER, SF_METEORITE, SF_LIMESTONE, SF_IRON, SF_GUNPOWDER,
00129         SF_GREASE, SF_FEATHER, SF_ETHANOL, SF_DRYICE, SF_CRYSTAL, SF_CLAY,
00130         SF_BRIMSTONE, SF_BONE, SF_ATLASMEDALLION, SF_ASH, SF_ACORN
00131     };
00132     
00133     /// the items
00134     enum sf_item {
00135         SF_PETAL, SF_NECTAR, SF_HONEY, SF_DOGBISCUIT, SF_WINGS, SF_ESSENCE,
00136         SF_PIXIEDUST, SF_CALLBEAD, SF_GRASSVEST, SF_SHELLPLATE, SF_DINOSKIN,
00137         SF_BRONZEARMOR, SF_STONEVEST, SF_CENTURIONCAPE, SF_SILVERMAIL,
00138         SF_GOLDPLATEDVEST, SF_SHININGARMOR, SF_MAGNAMAIL, SF_TITANIUMVEST,
00139         SF_VIRTUALVEST, SF_GRASSHAT, SF_SHELLHAT, SF_DINOHELM, SF_BRONZEHELMET,
00140         SF_OBSIDIANHELM, SF_CENTURIONHELM, SF_TITANSCROWN, SF_DRAGONHELM,
00141         SF_KNIGHTSHELM, SF_LIGHTNINGHELM, SF_OLDRELIABLE, SF_BRAINSTORM,
00142         SF_VINEBRACELET, SF_MAMMOTHGUARD, SF_CLAWGUARD, SF_SERPENTBRACER,
00143         SF_BRONZEGAUNTLET, SF_GLOVESOFRA, SF_IRONBRACER, SF_MAGICIANSRING,
00144         SF_DRAGONSCLAW, SF_CYBERGLOVE, SF_PROTECTORRING, SF_VIRTUALGLOVE,
00145         SF_LEATHERCOLLAR, SF_SPIKYCOLLAR, SF_DEFENDERCOLLAR, SF_SPOTSCOLLAR,
00146         SF_THUNDERBALL, SF_PARTICLEBOMB, SF_CRYOBLAST
00147     };
00148     
00149     /// the money types
00150     enum sf_money {
00151         SF_TALONS, SF_JEWELS, SF_GOLDCOINS, SF_CREDITS
00152     };
00153     
00154     /// the market trading goods
00155     enum sf_tradegood {
00156         SF_ANNIHILATIONAMULET, SF_BEADS, SF_CERAMICPOT, SF_CHICKEN,
00157         SF_GOLDENJACKAL, SF_JEWELEDSCARAB, SF_LIMESTONETABLET, SF_PERFUME,
00158         SF_RICE, SF_SPICE, SF_SOUVENIRSPOON, SF_TAPESTRY, SF_TICKETFOREXHIBITION
00159     };
00160     
00161     /// the boy's weapons
00162     enum sf_weapon {
00163         SF_BONECRUSHER, SF_GLADIATORSWORD, SF_CRUSADERSWORD, SF_NEUTRONBLADE,
00164         SF_SPIDERSCLAW, SF_BRONZEAXE, SF_KNIGHTBASHER, SF_ATOMSMASHER,
00165         SF_HORNSPEAR, SF_BRONZESPEAR, SF_LANCEWEAPON, SF_LASERLANCE, SF_BAZOOKA
00166     };
00167     
00168     class SRAMFile {
00169     private:
00170         int game;
00171         unsigned char *offset;
00172         unsigned char sram[SRAM_FILE_SIZE];
00173         bool modified, valid[4];
00174         
00175         /// the alchemy have/have not offsets
00176         static const std::pair<int, int> SRAM_ALCHEMY_OFFSETS[];
00177         
00178         /// the charm have/have not offsets
00179         static const std::pair<int, int> SRAM_CHARM_OFFSETS[];
00180         
00181         /// the weapon have/have not offsets
00182         static const std::pair<int, int> SRAM_WEAPON_OFFSETS[];
00183         
00184         /**
00185          * Calculates the checksum for one of the save games.
00186          *
00187          * @param game The game to calculate the checksum for.
00188          *
00189          * @return The checksum.
00190          */
00191         quint16 checksum(int game) const;
00192         
00193         /**
00194          * Gets the checksum value.
00195          *
00196          * @param game The game to get the checksum for.
00197          *
00198          * @return The checksum.
00199          */
00200         quint16 getChecksum(int game) const;
00201         
00202         /**
00203          * Sets the game's checksum value.
00204          *
00205          * @param game The game to set the checksum for.
00206          * @param checksum The new checksum.
00207          */
00208         void setChecksum(int game, quint16 checksum);
00209         
00210     public:
00211         /**
00212          * Creates a new SRAMFile.
00213          *
00214          * @param filename The SRAM file to load.
00215          *
00216          * @throws InvalidSRAMFileException if the file is not a valid Secret of
00217          *         Evermore SRAM file.
00218          */
00219         SRAMFile(const QString &filename) throw(InvalidSRAMFileException);
00220         
00221         /**
00222          * Saves this SRAMFile back to disk.
00223          *
00224          * @param filename The filename to save to.
00225          *
00226          * @return true on success; false otherwise.
00227          */
00228         bool save(const QString &filename);
00229         
00230         /**
00231          * Checks whether the boy knows a particular alchemy.
00232          *
00233          * @param alchemy The alchemy to check for.
00234          *
00235          * @return true if the boy knows the alchemy; false otherwise.
00236          */
00237         bool hasAlchemy(enum sf_alchemy alchemy) const;
00238         
00239         /**
00240          * Sets whether the boy knows a particular alchemy.
00241          *
00242          * @param alchemy The alchemy to set.
00243          * @param have true to give; false to take away.
00244          */
00245         void setAlchemy(enum sf_alchemy alchemy, bool have = true);
00246         
00247         /**
00248          * Gets the alchemy level.
00249          *
00250          * @param alchemy The alchemy.
00251          *
00252          * @return The level.
00253          */
00254         std::pair<int, int> getAlchemyLevel(enum sf_alchemy alchemy) const;
00255             
00256         /**
00257          * Sets the alchemy level.
00258          *
00259          * @param alchemy The alchemy.
00260          * @param level The new level.
00261          */
00262         void setAlchemyLevel(enum sf_alchemy alchemy,
00263                              std::pair<int, int> level);
00264         
00265         /**
00266          * Gets the dog's attack level.
00267          *
00268          * @return The attack level (major, progress to next).
00269          */
00270         std::pair<int, int> getAttackLevel() const;
00271         
00272         /**
00273          * Sets the dog's attack level.
00274          *
00275          * @param level The new level.
00276          */
00277         void setAttackLevel(std::pair<int, int> level);
00278         
00279         /**
00280          * Checks whether the heros have a particular charm.
00281          *
00282          * @param charm The charm to check for.
00283          *
00284          * @return true if they have the charm; false otherwise.
00285          */
00286         bool hasCharm(enum sf_charm charm) const;
00287         
00288         /**
00289          * Sets whether the heros have a particular charm.
00290          *
00291          * @param charm The charm to set.
00292          * @param have true to give; false to take away.
00293          */
00294         void setCharm(enum sf_charm charm, bool have = true);
00295         
00296         /**
00297          * Gets the current HP of one of the heros.
00298          *
00299          * @param hero Which hero's current HP to get.
00300          *
00301          * @return The hero's current HP.
00302          */
00303         quint16 getCurrentHP(enum sf_hero hero) const;
00304         
00305         /**
00306          * Sets the current HP of one of the heros.
00307          *
00308          * @param hero Which hero to set.
00309          * @param hp The new current HP.
00310          */
00311         void setCurrentHP(enum sf_hero hero, quint16 hp);
00312         
00313         /**
00314          * Gets the experience of one of the heros.
00315          *
00316          * @param hero Which hero's experience to get.
00317          *
00318          * @return The hero's experience.
00319          */
00320         quint32 getExperience(enum sf_hero hero) const;
00321         
00322         /**
00323          * Sets the experience of one of the heros.
00324          *
00325          * @param hero Which hero to set.
00326          * @param experience The new experience.
00327          */
00328         void setExperience(enum sf_hero hero, quint32 experience);
00329         
00330         /**
00331          * Gets the current game.
00332          *
00333          * @return The game.
00334          */
00335         int getGame() const;
00336         
00337         /**
00338          * Sets the current game.
00339          *
00340          * @param game The new game.
00341          */
00342         void setGame(int game = 0);
00343         
00344         /**
00345          * Gets the inventory count for a particular alchemy ingredient.
00346          *
00347          * @param ingredient The ingredient.
00348          *
00349          * @return The inventory count.
00350          */
00351         int getIngredient(enum sf_ingredient ingredient) const;
00352         
00353         /**
00354          * Sets the inventory count for a particular alchemy ingredient.
00355          *
00356          * @param ingredient The ingredient.
00357          * @param count The new inventory count.
00358          */
00359         void setIngredient(enum sf_ingredient ingredient, int count);
00360         
00361         /**
00362          * Gets the inventory count for a particular item.
00363          *
00364          * @param item The item.
00365          *
00366          * @return The inventory count.
00367          */
00368         int getItem(enum sf_item item) const;
00369         
00370         /**
00371          * Sets the inventory count for a particular item.
00372          *
00373          * @param item The item.
00374          * @param count The new inventory count.
00375          */
00376         void setItem(enum sf_item item, int count);
00377         
00378         /**
00379          * Gets the level of one of the heros.
00380          *
00381          * @param hero Which hero's level to get.
00382          *
00383          * @return The hero's level.
00384          */
00385         int getLevel(enum sf_hero hero) const;
00386         
00387         /**
00388          * Sets the level of one of the heros.
00389          *
00390          * @param hero Which hero's level to set.
00391          * @param level The new level.
00392          */
00393         void setLevel(enum sf_hero hero, int level);
00394         
00395         /**
00396          * Gets the max HP of one of the heros.
00397          *
00398          * @param hero Which hero's max HP to get.
00399          *
00400          * @return The hero's max HP.
00401          */
00402         quint16 getMaxHP(enum sf_hero hero) const;
00403         
00404         /**
00405          * Sets the max HP of one of the heros.
00406          *
00407          * @param hero Which heros' max HP to set.
00408          * @param hp The new max HP.
00409          */
00410         void setMaxHP(enum sf_hero hero, quint16 hp);
00411         
00412         /**
00413          * Checks whether this SRAMFile has been modified.
00414          *
00415          * @return true if modified; false otherwise.
00416          */
00417         bool isModified() const;
00418         
00419         /**
00420          * Gets the money count.
00421          *
00422          * @param money The money type.
00423          *
00424          * @return The money count.
00425          */
00426         quint32 getMoney(enum sf_money money) const;
00427         
00428         /**
00429          * Sets the money count.
00430          *
00431          * @param money The money type.
00432          * @param count The new money count.
00433          */
00434         void setMoney(enum sf_money money, quint32 count);
00435         
00436         /**
00437          * Gets the name of one of the heros.
00438          *
00439          * @param hero Which hero's name to get.
00440          *
00441          * @return The name.
00442          */
00443         QString getName(enum sf_hero hero) const;
00444         
00445         /**
00446          * Sets the name of one of the heros.
00447          *
00448          * @param hero Which hero's name to set.
00449          * @param name The new name.
00450          */
00451         void setName(enum sf_hero hero, const QString &name);
00452         
00453         /**
00454          * Gets the inventory count for one of the trade goods.
00455          *
00456          * @param tradegood The trade good.
00457          *
00458          * @return The inventory count.
00459          */
00460         quint16 getTradeGood(enum sf_tradegood tradegood) const;
00461         
00462         /**
00463          * Sets the inventory count for one of the trade goods.
00464          *
00465          * @param tradegood The trade good.
00466          * @param count The new inventory count.
00467          */
00468         void setTradeGood(enum sf_tradegood tradegood, quint16 count);
00469         
00470         /**
00471          * Checks whether the boy has a particular weapon.
00472          *
00473          * @param weapon The weapon to check for.
00474          *
00475          * @return true if the boy has the weapon; false otherwise.
00476          */
00477         bool hasWeapon(enum sf_weapon weapon) const;
00478         
00479         /**
00480          * Sets whether the boy has a particular weapon.
00481          *
00482          * @param weapon The weapon to set.
00483          * @param have true to give; false to take away.
00484          */
00485         void setWeapon(enum sf_weapon weapon, bool have = true);
00486         
00487         /**
00488          * Gets the weapon level for one of the weapons.
00489          *
00490          * @param weapon The weapon.
00491          *
00492          * @return The weapon level (major level, progress to next).
00493          */
00494         std::pair<int, int> getWeaponLevel(enum sf_weapon weapon) const;
00495         
00496         /**
00497          * Sets the weapon level for one of the weapons.
00498          *
00499          * @param weapon The weapon.
00500          * @param level The new level.
00501          */
00502         void setWeaponLevel(enum sf_weapon weapon, std::pair<int, int> level);
00503         
00504         /**
00505          * Checks if a save game is a valid save.
00506          *
00507          * @param game The game to check (0-3).
00508          *
00509          * @return true if the game is valid; false otherwise.
00510          */
00511         bool isValid(int game) const;
00512     };
00513     
00514     inline int SRAMFile::getGame() const
00515         { return game; }
00516         
00517     inline bool SRAMFile::isModified() const
00518         { return modified; }
00519         
00520     inline bool SRAMFile::isValid(int game) const
00521         {
00522             Q_ASSERT((game >= 0) && (game < 4));
00523             return valid[game];
00524         }
00525 }
00526 
00527 #endif
00528 

Generated on Sun Sep 10 01:49:26 2006 for Secret of Evermore SRAM Editor by  doxygen 1.4.7