sramfile.hh

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

Generated on Sun Jan 27 09:41:43 2008 for Secret of Evermore SRAM Editor by  doxygen 1.5.4