* Fix botched commit (forgot -a)

This commit is contained in:
Antidote 2013-07-20 20:57:20 -07:00
parent 8f550d3a5e
commit e86d64e7bb
56 changed files with 3213 additions and 1741 deletions

View File

@ -16,6 +16,8 @@
#ifndef __ALTTP_ENUMS_HPP__
#define __ALTTP_ENUMS_HPP__
#ifndef __DOXYGEN_IGNORE__
#include "Types.hpp"
enum BowType : char
@ -103,4 +105,5 @@ enum ALTTPTagAlong
AfterBoss
};
#endif // __DOXYGEN_IGNORE__
#endif // __ALTTP_ENUMS_HPP__

View File

@ -19,10 +19,13 @@
#include <Types.hpp>
#include <vector>
namespace zelda
{
class ALTTPQuest;
/*! \class ALTTPFile
* \brief A Link to the Past data container class
* \brief A Link to the Past data container class class
*
* Contains all relevant data for an A Link to the Past
* SRM file.
@ -84,4 +87,5 @@ private:
std::vector<ALTTPQuest*> m_backup;
};
} // zelda
#endif // __ALTTP_FILE_HPP__

View File

@ -21,14 +21,38 @@
#include "BinaryReader.hpp"
#include "ALTTPQuest.hpp"
namespace zelda
{
/*! \class ALTTPFileReader
* \brief A Link to the Past save data reader class
*
* A Class for reading binary data from an ALTTP Save File,
* all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader
*/
class ALTTPFile;
class ALTTPFileReader : public BinaryReader
class ALTTPFileReader : public io::BinaryReader
{
public:
/*! \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileReader(Uint8*, Uint64);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileReader(const std::string&);
/*! \brief Reads the SRAM data from the buffer
*
* \return ALTTPFile* SRAM data
*/
ALTTPFile* readFile();
private:
ALTTPRoomFlags* readRoomFlags();
@ -36,4 +60,5 @@ private:
ALTTPDungeonItemFlags readDungeonFlags();
};
} // zelda
#endif // __ALTTP_FILE_READER_HPP__

View File

@ -21,15 +21,40 @@
#include <BinaryWriter.hpp>
#include "ALTTPQuest.hpp"
namespace zelda
{
class ALTTPFile;
class ALTTPFileWriter : public BinaryWriter
/*! \class ALTTPFileWriter
* \brief A Link to the Past save data writer class
*
* A Class for writing binary data to an ALTTP Save File,
* all work is done using a memory buffer, and not written directly to the disk.
* \sa BinaryReader
*/
class ALTTPFileWriter : public io::BinaryWriter
{
public:
/*! \brief This constructor takes an existing buffer to write to.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileWriter(Uint8*, Uint64);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileWriter(const std::string&);
/*! \brief Writes the given SRAM data to a file on disk
*
* \param file SRAM data to right
*/
void writeFile(ALTTPFile* file);
private:
void writeRoomFlags(ALTTPRoomFlags*);
void writeOverworldEvent(ALTTPOverworldEvent*);
@ -37,4 +62,6 @@ private:
Uint16 calculateChecksum(Uint32 game);
};
} // zelda
#endif // __ALTTP_FILE_WRITER_HPP__

View File

@ -22,6 +22,9 @@
#include "ALTTPStructs.hpp"
#include "ALTTPEnums.hpp"
namespace zelda
{
/*! \class ALTTPQuest
* \brief A Link to the Past Quest container class
*
@ -31,146 +34,607 @@
class ALTTPQuest
{
public:
/*!
* \brief ALTTPQuest
*/
ALTTPQuest();
~ALTTPQuest();
/*!
* \brief setRoomFlags
* \param flags
*/
void setRoomFlags(std::vector<ALTTPRoomFlags*> flags);
/*!
* \brief setRoomFlags
* \param rf
* \param id
*/
void setRoomFlags(ALTTPRoomFlags* rf, Uint32 id);
/*!
* \brief roomFlags
* \return
*/
std::vector<ALTTPRoomFlags*> roomFlags();
/*!
* \brief roomFlags
* \param id
* \return
*/
ALTTPRoomFlags* roomFlags(Uint32 id);
/*!
* \brief setOverworldEvents
* \param events
*/
void setOverworldEvents(std::vector<ALTTPOverworldEvent*> events);
/*!
* \brief setOverworldEvents
* \param ow
* \param id
*/
void setOverworldEvents(ALTTPOverworldEvent* ow, Uint32 id);
/*!
* \brief overworldEvents
* \return
*/
std::vector<ALTTPOverworldEvent*> overworldEvents() const;
/*!
* \brief overworldEvent
* \param id
* \return
*/
ALTTPOverworldEvent* overworldEvent(Uint32 id) const;
/*!
* \brief setInventory
* \param inv
*/
void setInventory(ALTTPInventory* inv);
/*!
* \brief inventory
* \return
*/
ALTTPInventory* inventory() const;
/*!
* \brief setRupeeMax
* \param val
*/
void setRupeeMax(Uint16 val);
/*!
* \brief rupeeMax
* \return
*/
Uint16 rupeeMax() const;
/*!
* \brief setRupeeCurrent
* \param val
*/
void setRupeeCurrent(Uint16 val);
/*!
* \brief rupeeCurrent
* \return
*/
Uint16 rupeeCurrent() const;
/*!
* \brief setCompasses
* \param flags
*/
void setCompasses(ALTTPDungeonItemFlags flags);
/*!
* \brief compasses
* \return
*/
ALTTPDungeonItemFlags compasses() const;
/*!
* \brief setBigKeys
* \param flags
*/
void setBigKeys(ALTTPDungeonItemFlags flags);
/*!
* \brief bigKeys
* \return
*/
ALTTPDungeonItemFlags bigKeys() const;
/*!
* \brief setDungeonMaps
* \param flags
*/
void setDungeonMaps(ALTTPDungeonItemFlags flags);
/*!
* \brief dungeonMaps
* \return
*/
ALTTPDungeonItemFlags dungeonMaps() const;
/*!
* \brief setWishingPond
* \param val
*/
void setWishingPond(Uint16 val);
/*!
* \brief wishingPond
* \return
*/
Uint16 wishingPond() const;
/*!
* \brief setHealthMax
* \param val
*/
void setHealthMax(Uint8 val);
/*!
* \brief healthMax
* \return
*/
Uint8 healthMax() const;
/*!
* \brief setHealth
* \param val
*/
void setHealth(Uint8 val);
/*!
* \brief health
* \return
*/
Uint8 health() const;
/*!
* \brief setMagicPower
* \param val
*/
void setMagicPower(Uint8 val);
/*!
* \brief magicPower
* \return
*/
Uint8 magicPower() const;
/*!
* \brief setKeys
* \param val
*/
void setKeys(Uint8 val);
/*!
* \brief keys
* \return
*/
Uint8 keys() const;
/*!
* \brief setBombUpgrades
* \param val
*/
void setBombUpgrades(Uint8 val);
/*!
* \brief bombUpgrades
* \return
*/
Uint8 bombUpgrades() const;
/*!
* \brief setArrowUpgrades
* \param val
*/
void setArrowUpgrades(Uint8 val);
/*!
* \brief arrowUpgrades
* \return
*/
Uint8 arrowUpgrades() const;
/*!
* \brief setHealthFiller
* \param val
*/
void setHealthFiller(Uint8 val);
/*!
* \brief healthFiller
* \return
*/
Uint8 healthFiller() const;
/*!
* \brief setMagicFiller
* \param val
*/
void setMagicFiller(Uint8 val);
/*!
* \brief magicFiller
* \return
*/
Uint8 magicFiller() const;
/*!
* \brief setPendants
* \param val
*/
void setPendants(ALTTPPendants val);
/*!
* \brief pendants
* \return
*/
ALTTPPendants pendants() const;
/*!
* \brief setBombFiller
* \param val
*/
void setBombFiller(Uint8 val);
/*!
* \brief bombFiller
* \return
*/
Uint8 bombFiller() const;
/*!
* \brief setArrowFiller
* \param val
*/
void setArrowFiller(Uint8 val);
/*!
* \brief arrowFiller
* \return
*/
Uint8 arrowFiller() const;
/*!
* \brief setArrows
* \param val
*/
void setArrows(Uint8 val);
/*!
* \brief arrows
* \return
*/
Uint8 arrows() const;
/*!
* \brief setAbilityFlags
* \param val
*/
void setAbilityFlags(ALTTPAbilities val);
/*!
* \brief abilityFlags
* \return
*/
ALTTPAbilities abilityFlags() const;
void setCrystals(ALTTPCrystals val);
/*!
* \brief setCrystals
* \param val
*/
void setCrystals(ALTTPCrystals val);\
/*!
* \brief crystals
* \return
*/
ALTTPCrystals crystals() const;
/*!
* \brief setMagicUsage
* \param val
*/
void setMagicUsage(ALTTPMagicUsage val);
/*!
* \brief magicUsage
* \return
*/
ALTTPMagicUsage magicUsage() const;
/*!
* \brief setDungeonKeys
* \param val
*/
void setDungeonKeys(std::vector<Uint8> val);
/*!
* \brief setDungeonKeys
* \param id
* \param val
*/
void setDungeonKeys(Uint32 id, Uint8 val);
/*!
* \brief dungeonKeys
* \param id
* \return
*/
Uint8 dungeonKeys(Uint32 id) const;
/*!
* \brief dungeonCount
* \return
*/
Uint32 dungeonCount() const;
/*!
* \brief setProgressIndicator
* \param val
*/
void setProgressIndicator(ALTTPProgressIndicator val);
/*!
* \brief progressIndicator
* \return
*/
ALTTPProgressIndicator progressIndicator() const;
/*!
* \brief setProgressFlags1
* \param val
*/
void setProgressFlags1(ALTTPProgressFlags1 val);
/*!
* \brief progressFlags1
* \return
*/
ALTTPProgressFlags1 progressFlags1() const;
/*!
* \brief setMapIcon
* \param val
*/
void setMapIcon(ALTTPMapIcon val);
/*!
* \brief mapIcon
* \return
*/
ALTTPMapIcon mapIcon() const;
/*!
* \brief setStartLocation
* \param val
*/
void setStartLocation(ALTTPStartLocation val);
/*!
* \brief startLocation
* \return
*/
ALTTPStartLocation startLocation() const;
/*!
* \brief setProgressFlags2
* \param val
*/
void setProgressFlags2(ALTTPProgressFlags2 val);
/*!
* \brief progressFlags2
* \return
*/
ALTTPProgressFlags2 progressFlags2() const;
/*!
* \brief setLightDarkWorldIndicator
* \param val
*/
void setLightDarkWorldIndicator(ALTTPLightDarkWorldIndicator val);
/*!
* \brief lightDarkWorldIndicator
* \return
*/
ALTTPLightDarkWorldIndicator lightDarkWorldIndicator() const;
/*!
* \brief setTagAlong
* \param val
*/
void setTagAlong(ALTTPTagAlong val);
/*!
* \brief tagAlong
* \return
*/
ALTTPTagAlong tagAlong() const;
/*!
* \brief setOldManFlags
* \param flags
*/
void setOldManFlags(std::vector<Uint8> flags);
/*!
* \brief setOldManFlag
* \param id
* \param val
*/
void setOldManFlag(Uint32 id, Uint8 val);
/*!
* \brief oldManFlag
* \param id
* \return
*/
Uint8 oldManFlag(Uint32 id);
/*!
* \brief oldManFlagCount
* \return
*/
Uint32 oldManFlagCount() const;
/*!
* \brief setBombFlag
* \param flag
*/
void setBombFlag(Uint8 flag);
/*!
* \brief bombFlag
* \return
*/
Uint8 bombFlag() const;
/*!
* \brief setUnknown1
* \param flags
*/
void setUnknown1(std::vector<Uint8> flags);
/*!
* \brief setUnknown1
* \param id
* \param val
*/
void setUnknown1(Uint32 id, Uint8 val);
/*!
* \brief unknown1
* \param id
* \return
*/
Uint8 unknown1(Uint32 id);
/*!
* \brief unknown1Count
* \return
*/
Uint32 unknown1Count() const;
/*!
* \brief setPlayerName
* \param playerName
*/
void setPlayerName(std::vector<Uint16> playerName);
/*!
* \brief setPlayerName
* \param playerName
*/
void setPlayerName(const std::string& playerName);
/*!
* \brief playerName
* \return
*/
std::vector<Uint16> playerName() const;
/*!
* \brief playerNameToString
* \return
*/
std::string playerNameToString() const;
/*!
* \brief setValid
* \param val
*/
void setValid(bool val);
/*!
* \brief valid
* \return
*/
bool valid();
/*!
* \brief setDungeonDeathTotals
* \param val
*/
void setDungeonDeathTotals(std::vector<Uint16> val);
/*!
* \brief setDungeonDeathTotal
* \param id
* \param val
*/
void setDungeonDeathTotal(Uint32 id, Uint16 val);
/*!
* \brief dungeonDeathTotal
* \param id
* \return
*/
Uint16 dungeonDeathTotal(Uint32 id) const;
/*!
* \brief dungeonDeathTotalCount
* \return
*/
Uint16 dungeonDeathTotalCount() const;
/*!
* \brief setUnknown2
* \param val
*/
void setUnknown2(Uint16 val);
/*!
* \brief unknown2
* \return
*/
Uint16 unknown2() const;
/*!
* \brief setDeathSaveCount
* \param val
*/
void setDeathSaveCount(Uint16 val);
/*!
* \brief deathSaveCount
* \return
*/
Uint16 deathSaveCount() const;
/*!
* \brief setPostGameDeathCounter
* \param val
*/
void setPostGameDeathCounter(Int16 val);
/*!
* \brief postGameDeathCounter
* \return
*/
Int16 postGameDeathCounter() const;
/*!
* \brief setChecksum
* \param checksum
*/
void setChecksum(Uint16 checksum);
/*!
* \brief checksum
* \return
*/
Uint16 checksum() const;
private:
std::vector<ALTTPRoomFlags*> m_roomFlags;
@ -217,5 +681,6 @@ private:
Uint16 m_checksum;
};
} // zelda
#endif // __ALTTP_QUEST_HPP__

View File

@ -16,11 +16,14 @@
#ifndef __ALTTP_STRUCTS_HPP__
#define __ALTTP_STRUCTS_HPP__
#ifndef __DOXYGEN_IGNORE__
#include <string>
#include "Types.hpp"
/*! \struct ALTTPRoomFlags
*/
namespace zelda
{
struct ALTTPRoomFlags
{
bool Chest1:1;
@ -41,8 +44,6 @@ struct ALTTPRoomFlags
bool ChestOrTile:1;
};
/*! \struct ALTTPOverworldEvent
*/
struct ALTTPOverworldEvent
{
bool Unused1:1;
@ -55,8 +56,6 @@ struct ALTTPOverworldEvent
bool Unused5:1;
};
/*! \struct ALTTPInventory
*/
struct ALTTPInventory
{
char Bow;
@ -88,12 +87,6 @@ struct ALTTPInventory
char Shield;
char Armor;
char BottleTypes[4];
std::string bowType();
std::string boomerangType();
std::string magicType();
std::string armorType();
std::string bottleType(Uint32);
};
/*! \struct ALTTPLightDarkWorldIndicator
@ -204,4 +197,7 @@ struct ALTTPProgressFlags2
bool SmithsHaveSword:1;
};
}
#endif // __DOXYGEN_IGNORE__
#endif // __ALTTP_STRUCTS_HPP__

View File

@ -12,12 +12,17 @@
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#ifndef __BINARYREADER_HPP__
#define __BINARYREADER_HPP__
#include "Stream.hpp"
#include <string>
namespace zelda
{
namespace io
{
/*! \class BinaryReader
* \brief A Stream class for reading binary data
*
@ -139,6 +144,13 @@ public:
*/
std::string readUnicode();
/*! \brief Reads a string and advances the position in the file
*
* \return std::string The value at the current address
* \throw IOException when address is out of range
*/
std::string readString();
protected:
/*! \brief Overload of isOpenForWriting in Stream
*
@ -155,7 +167,14 @@ protected:
* \throw IOException
*/
void writeBytes(Int8*, Int64);
std::string m_filepath;
std::string m_filepath; //!< Path to the target file
};
}
}
#endif
#ifndef BINARYREADER_BASE
#define BINARYREADER_BASE \
private: \
typedef zelda::io::BinaryReader base;
#endif // BINARYREADER_BASE
#endif // __BINARYREADER_HPP__

View File

@ -19,6 +19,11 @@
#include "Stream.hpp"
#include <string>
namespace zelda
{
namespace io
{
/*! \class BinaryWriter
* \brief A Stream class for writing binary data
*
@ -136,8 +141,15 @@ public:
protected:
Int8 readByte();
Int8* readBytes(Int64);
bool isOpenForReading();
std::string m_filepath;
bool isOpenForReading(); //!< Overridden from \sa Stream
std::string m_filepath; //!< Path to the target file
};
}
}
#endif
#ifndef BINARYWRITER_BASE
#define BINARYWRITER_BASE \
private: \
typedef zelda::io::BinaryWriter base;
#endif // BINARYWRITER_BASE
#endif // __BINARY_WRITER_HPP__

View File

@ -18,6 +18,9 @@
#include <string>
namespace zelda
{
/*! \class Exception
* \brief The baseclass for all Exceptions.
*
@ -33,7 +36,7 @@ public:
inline Exception(const std::string& message) :
m_message(message)
{
};
}
/*! \brief Returns the Error message of the exception
* \return std::string The error message
@ -41,9 +44,10 @@ public:
inline std::string message() const
{
return m_message;
};
}
protected:
std::string m_message;
std::string m_message; //!< The error message string
};
} // zelda
#endif

View File

@ -18,6 +18,9 @@
#include "Exception.hpp"
namespace zelda
{
/*! \class FileNotFoundException
* \brief An excpeption thrown when a file could not be found at the given path.
*
@ -45,4 +48,6 @@ private:
std::string m_filename;
};
} // zelda
#endif

View File

@ -19,6 +19,9 @@
#include "Exception.hpp"
namespace zelda
{
/*! \class IOException
* \brief An excpeption thrown on inappropriate IO calls.
*
@ -40,4 +43,5 @@ public:
{};
};
} // zelda
#endif

View File

@ -17,7 +17,10 @@
#define __INVALID_OPERATION_EXCEPTION_HPP__
#include <string>
#include <Exception.hpp>
#include "Exception.hpp"
namespace zelda
{
/*! \class InvalidOperationException
* \brief An excpeption thrown on Invalid Operations calls.
@ -39,4 +42,7 @@ public:
{
}
};
} // zelda
#endif // __INVALID_OPERATION_EXCEPTION_HPP__

36
include/MCFile.hpp Normal file
View File

@ -0,0 +1,36 @@
// This file is part of libZelda.
//
// libZelda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libZelda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#ifndef __MCFILE_HPP__
#define __MCFILE_HPP__
namespace zelda
{
/*! \class MCFile
* \brief The Minish Cap data container class class
*
* Contains all relevant data for a The Minish Cap save,
* file.
*/
class MCFile
{
public:
MCFile();
private:
};
} // zelda
#endif // __MCFILE_HPP__

62
include/MCFileReader.hpp Normal file
View File

@ -0,0 +1,62 @@
// This file is part of libZelda.
//
// libZelda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libZelda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#ifndef __MCFILEREADER_HPP__
#define __MCFILEREADER_HPP__
#include "Types.hpp"
#include "BinaryReader.hpp"
namespace zelda
{
class MCFile;
/*! \class MCFileReader
* \brief The Minish Cap Save save data reader class
*
* A Class for reading binary data from a The Minish Cap Save File,
* all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader
*/
class MCFileReader : public io::BinaryReader
{
public:
/*!
* \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MCFileReader(Uint8*, Uint64);
/*!
* \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MCFileReader(const std::string&);
/*!
* \brief Reads the save data from the buffer
*
* \return MCFile* SRAM data
*/
MCFile* readFile();
};
} // zelda
#endif // __MCFILEREADER_HPP__

68
include/MCFileWriter.hpp Normal file
View File

@ -0,0 +1,68 @@
// This file is part of libZelda.
//
// libZelda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libZelda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#ifndef __MCFILEWRITER_HPP__
#define __MCFILEWRITER_HPP__
#include "Types.hpp"
#include "BinaryWriter.hpp"
namespace zelda
{
class MCFile;
/*! \class MCFileWriter
* \brief The Minish Cap Save save data writer class
*
* A Class for writing binary data to a The Minish Cap Save File,
* all work is done using a memory buffer, and not written directly from the disk.
* \sa BinaryWriter
*/
class MCFileWriter : public io::BinaryWriter
{
public:
/*!
* \brief This constructor takes an existing buffer to write to.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MCFileWriter(Uint8*, Uint64);
/*!
* \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MCFileWriter(const std::string&);
/*!
* \brief Writes the given save data to a file on disk
*
* \param file Save data to write
*/
void writeFile(MCFile* file);
private:
Uint16 calculateSlotChecksum(Uint32 game);
Uint16 calculateChecksum(Uint8* data, Uint32 length);
Uint8* reverse(Uint8* data, Uint32 length);
void unscramble();
};
} // zelda
#endif // __MCFILEWRITER_HPP__

View File

@ -12,6 +12,7 @@
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#ifndef __MAINPAGE_HPP__
#define __MAINPAGE_HPP__
@ -22,7 +23,7 @@
* <br />
* libZelda provides several basic classes that can be used to read from
* and write to files, and memory, classes such as Stream, BinaryReader, BinaryWriter,
* and the currently work in progress TextStream.
* and TextStream.
* \section example_sec BinaryWriter example
* \code
* #include "BinaryWriter.hpp"

View File

@ -17,6 +17,11 @@
#include "Types.hpp"
namespace zelda
{
namespace io
{
/*! \class Stream
* \brief Stream is the main class all streams inherit from
*
@ -35,17 +40,6 @@ public:
//! \brief Default buffer block size.
static const Uint32 BLOCKSZ;
/*! \enum Endian
* \brief Allows the user to specify the Endianness of the stream buffer.<br />
* The proper actions are automatically taken depending on platform and
* buffer settings
*/
enum Endian
{
LittleEndian, //!< Specifies that the Stream is Little Endian (LSB)
BigEndian //!< Specifies that the Stream is Big Endian (MSB)
};
/*! \enum SeekOrigin
* \brief Specifies how to seek in a stream.
*/
@ -56,7 +50,6 @@ public:
End //!< Tells the Stream to seek from the End of the buffer.
};
/*! \brief The default constructor
*/
Stream();
@ -87,6 +80,11 @@ public:
* \throw IOException
*/
virtual void writeBit(bool val);
/*! \brief Writes a byte at the current position and advances the position by one byte.
* \param byte The value to write
* \throw IOException
*/
virtual void writeUByte(Uint8 byte);
/*! \brief Writes a byte at the current position and advances the position by one byte.
* \param byte The value to write
@ -94,6 +92,15 @@ public:
*/
virtual void writeByte(Int8 byte);
/*! \brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
*
* \param data The buffer to write
* \param length The amount to write
* \throw IOException
*/
virtual void writeUBytes(Uint8* data, Int64 length);
/*! \brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
*
@ -212,7 +219,7 @@ public:
*
* \return Endian The current Stream Endianess
*/
Endian endianness() const;
Endian endian() const;
/*! \brief Returns whether the stream is BigEndian
@ -235,5 +242,6 @@ protected:
Uint8* m_data; //!< The Stream buffer
bool m_autoResize; //!< Whether the stream is autoresizing
};
} // io
} // zelda
#endif // __STREAM_HPP__

View File

@ -20,6 +20,10 @@
#include <vector>
namespace zelda
{
namespace io
{
// TODO (Phil#1#): Need to actually use AccessMode
/*! \class TextStream
* \brief A Class for reading or writing Text data.
@ -154,5 +158,6 @@ private:
Uint32 m_currentLine;
Uint32 m_startLength;
};
} // io
} // zelda
#endif

View File

@ -17,6 +17,17 @@
#include <limits.h>
/*! \enum Endian
* \brief Allows the user to specify the Endianness of data.<br />
* The proper actions are automatically taken depending on platform and
* buffer settings
*/
enum Endian
{
LittleEndian, //!< Specifies that the Stream is Little Endian (LSB)
BigEndian //!< Specifies that the Stream is Big Endian (MSB)
};
// 8 bits integer types
#if UCHAR_MAX == 0xFF
typedef signed char Int8;
@ -56,4 +67,12 @@
typedef signed long long Int64;
typedef unsigned long long Uint64;
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else // __cplusplus
#define NULL (void*)0
#endif
#endif // NULL
#endif

View File

@ -20,22 +20,67 @@
#include <string>
#include <Types.hpp>
namespace zelda
{
/*!
* \brief The WiiImage class
*/
class WiiImage
{
public:
/*!
* \brief WiiImage
*/
WiiImage();
/*!
* \brief WiiImage
* \param width
* \param height
* \param data
*/
WiiImage(Uint32 width, Uint32 height, Uint8* data);
~WiiImage();
/*!
* \brief setWidth
* \param width
*/
void setWidth(const Uint32 width);
/*!
* \brief width
* \return
*/
Uint32 width() const;
/*!
* \brief setHeight
* \param height
*/
void setHeight(const Uint32 height);
/*!
* \brief height
* \return
*/
Uint32 height() const;
/*!
* \brief setData
* \param data
*/
void setData(const Uint8* data);
/*!
* \brief data
* \return
*/
Uint8* data();
/*!
* \brief toRGBA32 DOES NOT WORK!!! DO NOT USE!!!
* \return
*/
Uint8* toRGBA32();
private:
@ -44,41 +89,156 @@ private:
Uint8* m_data;
};
/*! \class WiiBanner
* \brief Wii banner container class
*
* Contains all relevant data for a Wii banner.
*/
class WiiBanner
{
public:
enum { NoCopy = 0x00000001, Bounce = 0x00000010, NoCopyBounce = NoCopy | Bounce };
enum
{
NoCopy = 0x00000001,
Bounce = 0x00000010,
NoCopyBounce = NoCopy | Bounce
};
/*!
* \brief WiiBanner
*/
WiiBanner();
/*!
* \brief WiiBanner
* \param gameId
* \param title
* \param subtitle
* \param m_banner
* \param icons
*/
WiiBanner(Uint32 gameId, const std::string& title, const std::string& subtitle, WiiImage* m_banner, std::vector<WiiImage*> icons);
virtual ~WiiBanner();
/*!
* \brief setGameID
* \param id
*/
void setGameID(Uint64 id);
/*!
* \brief gameID
* \return
*/
Uint64 gameID() const;
/*!
* \brief setBannerImage
* \param banner
*/
void setBannerImage(WiiImage* banner);
/*!
* \brief bannerImage
* \return
*/
WiiImage* bannerImage() const;
/*!
* \brief setBannerSize
* \param size
*/
void setBannerSize(Uint32 size);
/*!
* \brief bannerSize
* \return
*/
Uint32 bannerSize() const;
/*!
* \brief setTitle
* \param title
*/
void setTitle(const std::string& title);
/*!
* \brief title
* \return
*/
std::string title() const;
/*!
* \brief setSubtitle
* \param subtitle
*/
void setSubtitle(const std::string& subtitle);
/*!
* \brief subtitle
* \return
*/
std::string subtitle() const;
/*!
* \brief addIcon
* \param icon
*/
void addIcon(WiiImage* icon);
/*!
* \brief setIcon
* \param id
* \param icon
*/
void setIcon(Uint32 id, WiiImage* icon);
/*!
* \brief getIcon
* \param id
* \return
*/
WiiImage* getIcon(Uint32 id) const;
/*!
* \brief icons
* \return
*/
std::vector<WiiImage*> icons() const;
/*!
* \brief setAnimationSpeed
* \param animSpeed
*/
void setAnimationSpeed(Uint16 animSpeed);
/*!
* \brief animationSpeed
* \return
*/
Uint16 animationSpeed() const;
/*!
* \brief setPermissions
* \param permissions
*/
void setPermissions(Uint8 permissions);
/*!
* \brief permissions
* \return
*/
Uint8 permissions() const;
/*!
* \brief setFlags
* \param flags
*/
void setFlags(Uint32 flags);
/*!
* \brief flags
* \return
*/
Uint32 flags() const;
protected:
private:
@ -92,5 +252,6 @@ private:
std::string m_title;
std::string m_subtitle;
};
} // zelda
#endif // WIIBANNER_H

View File

@ -19,9 +19,22 @@
#include <map>
#include <Types.hpp>
namespace zelda
{
/*! \class WiiFile
* \brief Wii file container class
*
* Contains all relevant data for a file in a data.bin file.
*/
class WiiFile
{
public:
/*! \enum Permission
* \brief The Wii uses a bastardized unix permissions system so these flags
* reflect the file's individual permissions.
*/
enum Permission
{
OtherRead = 0x01,
@ -32,11 +45,14 @@ public:
OwnerWrite = 0x20,
// Mask values;
OtherRW = (OtherRead|OtherWrite),
OtherRW = (OtherRead|OtherWrite), //!< Mask to get the Other group permissions
GroupRW = (GroupRead|GroupWrite),
OwnerRW = (OwnerRead|OwnerWrite)
};
/*!
* \brief The Type enum
*/
enum Type
{
File = 0x01,
@ -44,29 +60,104 @@ public:
};
WiiFile();
/*!
* \brief WiiFile
* \param filename
*/
WiiFile(const std::string& filename);
/*!
* \brief WiiFile
* \param filename
* \param permissions
* \param data
* \param length
*/
WiiFile(const std::string& filename, Uint8 permissions, const Uint8* data, Uint32 length);
virtual ~WiiFile();
/*!
* \brief setFilename
* \param filename
*/
void setFilename(const std::string& filename);
/*!
* \brief filename
* \return
*/
std::string filename() const;
/*!
* \brief setData
* \param data
*/
void setData(const Uint8* data);
/*!
* \brief data
* \return
*/
Uint8* data() const;
/*!
* \brief setLength
* \param len
*/
void setLength(const int len);
/*!
* \brief length
* \return
*/
int length() const;
/*!
* \brief setPermissions
* \param permissions
*/
void setPermissions(const Uint8 permissions);
/*!
* \brief permissions
* \return
*/
Uint8 permissions() const;
/*!
* \brief setAttributes
* \param attr
*/
void setAttributes(const Uint8 attr);
/*!
* \brief attributes
* \return
*/
Uint8 attributes() const;
/*!
* \brief setType
* \param type
*/
void setType(Type type);
/*!
* \brief type
* \return
*/
Type type() const;
/*!
* \brief isDirectory
* \return
*/
bool isDirectory() const;
/*!
* \brief isFile
* \return
*/
bool isFile() const;
protected:
@ -79,4 +170,5 @@ private:
Uint8* m_fileData;
};
} // zelda
#endif // WIIFILE_H

View File

@ -19,25 +19,67 @@
#include <string>
#include <Types.hpp>
namespace zelda
{
class WiiFile;
class WiiBanner;
class WiiImage;
class BinaryReader;
class BinaryWriter;
/*! \class WiiSave
* \brief Wii data.bin container class
*
* Contains all relevant data for a Wii data.bin file.
*/
class WiiSave
{
public:
/*!
* \brief FileIterator
*/
typedef std::unordered_map<std::string, WiiFile*>::const_iterator FileIterator;
/*!
* \brief WiiSave
*/
WiiSave();
/*!
* \brief ~WiiSave
*/
virtual ~WiiSave();
/*!
* \brief addFile
* \param filename
* \param file
*/
void addFile(const std::string& filename, WiiFile* file);
/*!
* \brief file
* \param filename
* \return
*/
WiiFile* file(const std::string& filename) const;
/*!
* \brief fileList
* \return
*/
std::unordered_map<std::string, WiiFile*>& fileList();
/*!
* \brief setBanner
* \param banner
*/
void setBanner(WiiBanner* banner);
/*!
* \brief banner
* \return
*/
WiiBanner* banner() const;
protected:
@ -48,4 +90,5 @@ private:
};
} // zelda
#endif // __WII__SAVE_HPP__

View File

@ -19,17 +19,41 @@
#include <utility.hpp>
#include <BinaryReader.hpp>
namespace zelda
{
class WiiSave;
class WiiBanner;
class WiiFile;
class WiiImage;
class WiiSaveReader : public BinaryReader
/*! \class WiiSaveReader
* \brief Wii data.bin reader class
*
* A Class for reading binary data from a wii data.bin file,
* all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader
*/
class WiiSaveReader : public io::BinaryReader
{
public:
/*! \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
WiiSaveReader(const Uint8*, Uint64);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
WiiSaveReader(const std::string&);
/*!
* \brief readSave
* \return
*/
WiiSave* readSave();
private:
WiiBanner* readBanner();
@ -37,4 +61,6 @@ private:
WiiImage* readImage(Uint32 width, Uint32 height);
void readCerts(Uint32 totalSize);
};
} // zelda
#endif // __WII_SAVE_READER_HPP__

View File

@ -12,23 +12,49 @@
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#ifndef __WII_SAVE_WRITER_HPP__
#define __WII_SAVE_WRITER_HPP__
#include <Types.hpp>
#include <utility.hpp>
#include <BinaryWriter.hpp>
#include "Types.hpp"
#include "utility.hpp"
#include "BinaryWriter.hpp"
namespace zelda
{
class WiiSave;
class WiiBanner;
class WiiFile;
class WiiImage;
class WiiSaveWriter : public BinaryWriter
/*! \class WiiSaveWriter
* \brief Wii data.bin writer class
*
* A Class for writing binary data to a wii data.bin file,
* all work is done using a memory buffer, and not written directly to the disk.
* \sa BinaryReader
*/
class WiiSaveWriter : public io::BinaryWriter
{
public:
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
WiiSaveWriter(const std::string&);
/*!
* \brief writeSave
* \param save
* \param macAddress
* \param ngId
* \param ngPriv
* \param ngSig
* \param ngKeyId
* \param filepath
* \return
*/
bool writeSave(WiiSave* save, Uint8* macAddress, Uint32 ngId, Uint8* ngPriv, Uint8* ngSig, Uint32 ngKeyId, const std::string& filepath = "");
private:
@ -38,4 +64,5 @@ private:
void writeCerts(Uint32 filesSize, Uint32 ngId, Uint8* ngPriv, Uint8* ngSig, Uint32 ngKeyId);
};
} // zelda
#endif // __WII_SAVE_WRITER_HPP__

View File

@ -16,5 +16,3 @@ void aes_set_key(const Uint8 *key );
#endif
#endif //__AES_H_

View File

@ -1,6 +1,8 @@
#ifndef BN_H
#define BN_H
#ifndef __DOXYGEN_IGNORE__
#include <Types.hpp>
int bn_compare(Uint8 *a, Uint8 *b, Uint32 n);
@ -10,4 +12,5 @@ void bn_mul(Uint8 *d, Uint8 *a, Uint8 *b, Uint8 *N, Uint32 n);
void bn_exp(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n, Uint8 *e, Uint32 en);
void bn_inv(Uint8 *d, Uint8 *a, Uint8 *N, Uint32 n);
#endif // __DOXYGEN_IGNORE__
#endif // BN_H

View File

@ -1,6 +1,8 @@
#ifndef MD5_H
#define MD5_H
#ifndef __DOXYGEN_IGNORE__
#ifdef __cplusplus
extern "C"
{
@ -238,4 +240,5 @@ extern "C"
#ifdef __cplusplus
}
#endif
#endif // __DOXYGEN_IGNORE__
#endif /* AUTH_MD5_H */

View File

@ -1,9 +1,9 @@
#ifndef _SHA1_H_
#define _SHA1_H_
#include <Types.hpp>
#ifndef __DOXYGEN_IGNORE__
#ifdef __cplusplus
extern "C" {
#endif
@ -43,4 +43,5 @@ Uint8* getSha1( Uint8 * stuff, Uint32 stuff_size );
}
#endif
#endif // __DOXYGEN_IGNORE__
#endif

View File

@ -34,5 +34,6 @@ bool isSystemBigEndian();
void fillRandom(Uint8 * rndArea, Uint8 count);
void yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize);
#endif

View File

@ -61,7 +61,7 @@ OUTPUT_DIRECTORY = doc
# source files, where putting all generated files in the same directory would
# otherwise cause performance problems for the file system.
CREATE_SUBDIRS = NO
CREATE_SUBDIRS = Yes
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
# documentation generated by doxygen is written. Doxygen will use this
@ -1586,7 +1586,7 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
PREDEFINED =
PREDEFINED = __DOXYGEN_IGNORE__
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.

View File

@ -1,7 +1,7 @@
CONFIG += staticlib
TEMPLATE=lib
TARGET=zelda
QMAKE_CXXFLAGS = -std=c++11
QMAKE_CXXFLAGS += -std=c++0x
INCLUDEPATH += include
HEADERS += \
@ -35,7 +35,13 @@ HEADERS += \
include/ALTTPFileWriter.hpp \
include/ALTTPFileReader.hpp \
include/ALTTPFile.hpp \
include/ALTTPEnums.hpp
include/ALTTPEnums.hpp \
include/MCFileReader.hpp \
include/MCFile.hpp \
include/MCFileWriter.hpp \
include/ZQuestFileWriter.hpp \
include/ZQuestFileReader.hpp \
include/ZQuest.hpp
SOURCES += \
src/utility.cpp \
@ -53,12 +59,19 @@ SOURCES += \
src/ec.cpp \
src/md5.c \
src/sha1.cpp \
src/ALTTPStructs.cpp \
src/ALTTPQuest.cpp \
src/ALTTPFileWriter.cpp \
src/ALTTPFileReader.cpp \
src/ALTTPFile.cpp
src/ALTTPFile.cpp \
src/MCFileReader.cpp \
src/MCFile.cpp \
src/MCFileWriter.cpp \
src/RARCFileReader.cpp \
src/RARCFileEntry.cpp \
src/ZQuestFileWriter.cpp \
src/ZQuestFileReader.cpp \
src/ZQuest.cpp
system("exec doxygen libzelda.conf")
system("cd doc/latex && make")
#system("cd doc/latex && make")
system("cd ../../")

View File

@ -16,8 +16,10 @@
#include "ALTTPFile.hpp"
#include "ALTTPQuest.hpp"
#include <InvalidOperationException.hpp>
#include "InvalidOperationException.hpp"
namespace zelda
{
ALTTPFile::ALTTPFile()
{}
@ -51,3 +53,4 @@ Uint32 ALTTPFile::questCount() const
{
return m_quests.size();
}
} // zelda

View File

@ -18,6 +18,9 @@
#include "ALTTPQuest.hpp"
#include <iostream>
namespace zelda
{
ALTTPFileReader::ALTTPFileReader(Uint8* data, Uint64 length)
: BinaryReader(data, length)
{
@ -35,6 +38,7 @@ ALTTPFile* ALTTPFileReader::readFile()
for (Uint32 i = 0; i < 6; i++)
{
// Temporary values to use for each save
ALTTPQuest* quest = new ALTTPQuest();
std::vector<ALTTPRoomFlags*> roomFlags;
std::vector<ALTTPOverworldEvent*> owEvents;
@ -224,3 +228,5 @@ ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags()
return flags;
}
} // zelda

View File

@ -18,6 +18,9 @@
#include "ALTTPQuest.hpp"
#include <iostream>
namespace zelda
{
ALTTPFileWriter::ALTTPFileWriter(Uint8* data, Uint64 length)
: BinaryWriter(data, length)
{
@ -180,9 +183,36 @@ void ALTTPFileWriter::writeDungeonItems(ALTTPDungeonItemFlags flags)
Uint16 ALTTPFileWriter::calculateChecksum(Uint32 game)
{
Uint16 sum = 0x5a5a;
for (Uint32 i = 0; i < 0x4FE; i += 2)
sum -= *(Uint16*)(m_data + (i + (0x500 * game)));
/*
* ALTTP's checksum is very basic
* It adds each word up and then subtracts the sum from 0x5a5a
* The number seems pretty arbitrary, but it enables the game to differentiate
* it from a number that just happens to equal the sum outright, preventing "false positives."
*
* Ignoring the algorithm for figuring out it's position in the buffer the equation is basically:
* s = s + w
* s = (0x5a5a - s);
* s == sum
* w == current word
*
* For those who don't know a word is a two byte pair, i.e 0xFF and 0xFE constitutes a word.
*/
return sum;
// First we start at 0
Uint16 sum = 0;
for (Uint32 i = 0; i < 0x4FE; i += 2)
// Add each word one by one
sum += *(Uint16*)(m_data + (i + (0x500 * game)));
// Subtract it from 0x5a5a to get our true checksum
return (0x5a5a - sum);
/*
* There is one caveat to this algorithm however,
* It makes it difficult to manually edit this in a hex editor since it's not a common
* algorithm and most hexeditor with built in checksum calculators won't have it, however it's
* it's extremely basic, making it a non-issue really.
*/
}
} // zelda

View File

@ -17,6 +17,9 @@
#include "InvalidOperationException.hpp"
#include <iostream>
namespace zelda
{
ALTTPQuest::ALTTPQuest()
{
}
@ -676,3 +679,5 @@ Uint16 ALTTPQuest::checksum() const
{
return m_checksum;
}
} // zelda

View File

@ -24,6 +24,11 @@
#include <vector>
#include <iostream>
namespace zelda
{
namespace io
{
BinaryReader::BinaryReader(const Stream& stream) :
Stream(stream)
{
@ -85,7 +90,6 @@ void BinaryReader::writeBytes(Int8*, Int64)
throw IOException("BinaryReader::writeBytes() -> Stream not open for writing");
}
Int16 BinaryReader::readInt16()
{
if (m_bitPosition > 0)
@ -99,7 +103,7 @@ Int16 BinaryReader::readInt16()
Int16 ret = *(Int16*)(m_data + m_position);
m_position += 2;
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
ret = swap16(ret);
return ret;
}
@ -116,7 +120,7 @@ Uint16 BinaryReader::readUInt16()
Uint16 ret = *(Uint16*)(m_data + m_position);
m_position += 2;
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
ret = swapU16(ret);
return ret;
@ -134,7 +138,7 @@ Int32 BinaryReader::readInt32()
Int32 ret = *(Int32*)(m_data + m_position);
m_position += 4;
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
ret = swap32(ret);
return ret;
}
@ -152,7 +156,7 @@ Uint32 BinaryReader::readUInt32()
Uint32 ret = *(Uint32*)(m_data + m_position);
m_position += 4;
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
ret = swapU32(ret);
return ret;
}
@ -170,7 +174,7 @@ Int64 BinaryReader::readInt64()
Int64 ret = *(Int64*)(m_data + m_position);
m_position += 8;
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
ret = swap64(ret);
return ret;
}
@ -187,7 +191,7 @@ Uint64 BinaryReader::readUInt64()
Uint64 ret = *(Uint64*)(m_data + m_position);
m_position += 8;
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
ret = swap64(ret);
return ret;
}
@ -205,7 +209,7 @@ float BinaryReader::readFloat()
float ret = *(float*)(m_data + m_position);
m_position += 4;
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
ret = swapFloat(ret);
return ret;
}
@ -223,7 +227,7 @@ double BinaryReader::readDouble()
double ret = *(double*)(m_data + m_position);
m_position += 8;
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
ret = swapDouble(ret);
return ret;
@ -262,8 +266,23 @@ std::string BinaryReader::readUnicode()
return ret;
}
std::string BinaryReader::readString()
{
std::string ret = "";
Uint8 chr = readByte();
while (chr != 0)
{
ret += chr;
chr = readByte();
}
return ret;
}
bool BinaryReader::isOpenForWriting()
{
return false;
}
}
}

View File

@ -24,6 +24,10 @@
#include <vector>
#include <iostream>
namespace zelda
{
namespace io
{
BinaryWriter::BinaryWriter(const Uint8* data, Uint64 length)
: Stream(data, length)
@ -72,7 +76,6 @@ void BinaryWriter::save(const std::string& filename)
break;
done += blocksize;
std::cout << "Wrote " << done << " bytes" << std::endl;
}while (done < m_length);
fclose(out);
@ -101,7 +104,7 @@ void BinaryWriter::writeInt16(Int16 val)
else if (m_position > m_length)
throw IOException("BinaryWriter::WriteInt16() -> Position outside stream bounds");
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
val = swap16(val);
*(Int16*)(m_data + m_position) = val;
@ -122,7 +125,7 @@ void BinaryWriter::writeUInt16(Uint16 val)
throw IOException("BinaryWriter::WriteUInt16() -> Position outside stream bounds");
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
val = swapU16(val);
*(Uint16*)(m_data + m_position) = val;
@ -142,7 +145,7 @@ void BinaryWriter::writeInt32(Int32 val)
else if (m_position > m_length)
throw IOException("BinaryWriter::WriteInt32() -> Position outside stream bounds");
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
val = swap32(val);
*(Int32*)(m_data + m_position) = val;
@ -162,7 +165,7 @@ void BinaryWriter::writeUInt32(Uint32 val)
else if (m_position > m_length)
throw IOException("BinaryWriter::WriteUInt32() -> Position outside stream bounds");
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
val = swap32(val);
*(Uint32*)(m_data + m_position) = val;
@ -183,7 +186,7 @@ void BinaryWriter::writeInt64(Int64 val)
throw IOException("BinaryWriter::WriteInt64() -> Position outside stream bounds");
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
val = swap64(val);
*(Int64*)(m_data + m_position) = val;
@ -203,7 +206,7 @@ void BinaryWriter::writeUInt64(Uint64 val)
else if (m_position > m_length)
throw IOException("BinaryWriter::WriteUInt64() -> Position outside stream bounds");
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
val = swap64(val);
*(Uint64*)(m_data + m_position) = val;
@ -223,7 +226,7 @@ void BinaryWriter::writeFloat(float val)
else if (m_position > m_length)
throw IOException("BinaryWriter::WriteFloat() -> Position outside stream bounds");
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
val = swapFloat(val);
*(float*)(m_data + m_position) = val;
@ -243,7 +246,7 @@ void BinaryWriter::writeDouble(double val)
else if (m_position > m_length)
throw IOException("BinaryWriter::WriteDouble() -> Position outside stream bounds");
if ((!isSystemBigEndian() && m_endian == Stream::BigEndian) || (isSystemBigEndian() && m_endian == Stream::LittleEndian))
if ((!isSystemBigEndian() && m_endian == BigEndian) || (isSystemBigEndian() && m_endian == LittleEndian))
val = swapDouble(val);
*(double*)(m_data + m_position)= val;
@ -287,4 +290,5 @@ bool BinaryWriter::isOpenForReading()
{
return false;
}
} // io
} // zelda

25
src/MCFile.cpp Normal file
View File

@ -0,0 +1,25 @@
// This file is part of libZelda.
//
// libZelda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libZelda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#include "MCFile.hpp"
namespace zelda
{
MCFile::MCFile()
{
}
} // zelda

31
src/MCFileReader.cpp Normal file
View File

@ -0,0 +1,31 @@
// This file is part of libZelda.
//
// libZelda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libZelda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#include "MCFileReader.hpp"
namespace zelda
{
MCFileReader::MCFileReader(Uint8* data, Uint64 length)
: BinaryReader(data, length)
{
}
MCFileReader::MCFileReader(const std::string& filename)
: BinaryReader(filename)
{
}
} // zelda

96
src/MCFileWriter.cpp Normal file
View File

@ -0,0 +1,96 @@
// This file is part of libZelda.
//
// libZelda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libZelda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libZelda. If not, see <http://www.gnu.org/licenses/>
#include "MCFileWriter.hpp"
namespace zelda
{
MCFileWriter::MCFileWriter(Uint8* data, Uint64 length)
: io::BinaryWriter(data, length)
{
}
MCFileWriter::MCFileWriter(const std::string& filename)
: io::BinaryWriter(filename)
{
}
// TODO: Check the implementation, it seems to work fine, however it's not exactly correct,
// looking at the disassembly, MC seems to do some weird checking that isn't being done with this solution
// need to figure out what it's doing and whether it's relevant to the checksum.
Uint16 MCFileWriter::calculateSlotChecksum(Uint32 game)
{
Uint16 first = calculateChecksum((m_data + 0x34 + (0x10 * game)), 4);
Uint16 second = calculateChecksum((m_data + 0x80 + (0x500 * game)), 0x500);
first = (first + second) & 0xFFFF;
Uint16 result = first << 16;
second = ~first&0xFFFF;
second += 1;
result += second;
return result;
}
Uint16 MCFileWriter::calculateChecksum(Uint8 *data, Uint32 length)
{
Uint16 sum = 0;
int i = length;
for (Uint32 j = 0; j < length; j += 2)
{
sum += *(Uint16*)(data + j) ^ i;
i -= 2;
}
sum &= 0xFFFF;
return sum;
}
// TODO: Rewrite this to be more optimized, the current solution takes quite a few cycles
Uint8* MCFileWriter::reverse(Uint8* data, Uint32 length)
{
Uint32 a = 0;
Uint32 swap;
for (;a<--length; a++)
{
swap = data[a];
data[a] = data[length];
data[length] = swap;
}
return data;
}
// TODO: Rewrite this to be more optimized, unroll more??
void MCFileWriter::unscramble()
{
if (!m_data)
return;
for (Uint32 i = 0; i < m_length; i += 4)
{
Uint32 block1 = *(Uint32*)reverse((m_data + i), 4);
Uint32 block2 = *(Uint32*)reverse((m_data + i + 4), 4);
*(Uint32*)(m_data + i) = block2;
*(Uint32*)(m_data + i + 4) = block1;
}
}
} // zelda

View File

@ -19,6 +19,10 @@
#include <string.h>
#include <sstream>
namespace zelda
{
namespace io
{
const Uint32 Stream::BLOCKSZ = 512;
@ -26,7 +30,7 @@ Stream::Stream() :
m_bitPosition(0),
m_position(0),
m_length(0),
m_endian(Stream::LittleEndian),
m_endian(LittleEndian),
m_data(NULL),
m_autoResize(true)
{}
@ -34,7 +38,7 @@ Stream::Stream() :
Stream::Stream(const Uint8* data, Uint64 length) :
m_bitPosition(0),
m_position(0),
m_endian(Stream::LittleEndian),
m_endian(LittleEndian),
m_autoResize(true)
{
if (length <= 0)
@ -97,6 +101,11 @@ void Stream::writeBit(bool val)
}
}
void Stream::writeUByte(Uint8 byte)
{
writeByte((Int8)byte);
}
void Stream::writeByte(Int8 byte)
{
if (m_bitPosition > 0)
@ -113,6 +122,11 @@ void Stream::writeByte(Int8 byte)
m_position++;
}
void Stream::writeUBytes(Uint8* data, Int64 length)
{
writeBytes((Int8*)data, length);
}
void Stream::writeBytes(Int8* data, Int64 length)
{
if (m_bitPosition > 0)
@ -302,7 +316,10 @@ void Stream::setEndianess(Endian endian)
m_endian = endian;
}
Stream::Endian Stream::endianness() const
Endian Stream::endian() const
{
return m_endian;
}
} // io
} // zelda

View File

@ -19,6 +19,10 @@
#include "InvalidOperationException.hpp"
#include "IOException.hpp"
namespace zelda
{
namespace io
{
TextStream::TextStream(const std::string& filename, TextMode fileMode, AccessMode accessMode) :
m_filename(filename),
m_textmode(fileMode),
@ -256,3 +260,7 @@ void TextStream::loadLines()
m_lines.push_back(line);
}
}
} // io
} // zelda

View File

@ -17,6 +17,9 @@
#include <utility.hpp>
#include <string.h>
namespace zelda
{
WiiImage::WiiImage(Uint32 width, Uint32 height, Uint8* data) :
m_width(width),
m_height(height),
@ -178,3 +181,4 @@ Uint32 WiiBanner::flags() const
return m_flags;
}
} // zelda

View File

@ -15,6 +15,11 @@
#include "WiiFile.hpp"
namespace zelda
{
//! TODO: Remove this?
WiiFile::WiiFile() :
m_permissions(WiiFile::GroupRW|WiiFile::OtherRW|WiiFile::OwnerRW),
m_attributes(0),
@ -128,3 +133,4 @@ bool WiiFile::isFile() const
return (m_type == WiiFile::File);
}
} // zelda

View File

@ -21,7 +21,7 @@
#include "IOException.hpp"
#include "aes.h"
#include "ec.h"
#include <utility.hpp>
#include "utility.hpp"
#include "md5.h"
#include "sha1.h"
@ -33,6 +33,9 @@
#include <iomanip>
namespace zelda
{
WiiSave::WiiSave()
: m_banner(NULL)
{
@ -79,3 +82,5 @@ WiiBanner* WiiSave::banner() const
{
return m_banner;
}
} // zelda

View File

@ -27,6 +27,8 @@
#include <IOException.hpp>
#include <string.h>
namespace zelda
{
const Uint8 SD_KEY[16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08, 0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d};
const Uint8 SD_IV[16] = {0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f, 0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98};
@ -288,3 +290,5 @@ void WiiSaveReader::readCerts(Uint32 totalSize)
check_ec(ngCert, apCert, sig, hash2);
}
} // zelda

View File

@ -36,6 +36,9 @@
#include <iomanip>
namespace zelda
{
const Uint8 SD_KEY[16] = {0xab, 0x01, 0xb9, 0xd8, 0xe1, 0x62, 0x2b, 0x08, 0xaf, 0xba, 0xd8, 0x4d, 0xbf, 0xc2, 0xa5, 0x5d};
const Uint8 SD_IV[16] = {0x21, 0x67, 0x12, 0xe6, 0xaa, 0x1f, 0x68, 0x9f, 0x95, 0xc5, 0xa2, 0x23, 0x24, 0xdc, 0x6a, 0x98};
const Uint8 MD5_BLANKER[16] = {0x0e, 0x65, 0x37, 0x81, 0x99, 0xbe, 0x45, 0x17, 0xab, 0x06, 0xec, 0x22, 0x45, 0x1a, 0x57, 0x93};
@ -44,7 +47,7 @@ WiiSaveWriter::WiiSaveWriter(const std::string &filename)
: BinaryWriter(filename)
{
this->setAutoResizing(true);
this->setEndianess(Stream::BigEndian);
this->setEndianess(BigEndian);
}
@ -89,7 +92,7 @@ bool WiiSaveWriter::writeSave(WiiSave *save, Uint8 *macAddress, Uint32 ngId, Uin
void WiiSaveWriter::writeBanner(WiiBanner *banner)
{
this->setEndianess(Stream::BigEndian);
this->setEndianess(BigEndian);
this->setAutoResizing(true);
this->writeInt64(banner->gameID());
this->writeInt32((0x60a0+0x1200)*banner->icons().size());
@ -249,3 +252,5 @@ void WiiSaveWriter::writeCerts(Uint32 filesSize, Uint32 ngId, Uint8 *ngPriv, Uin
this->writeBytes((Int8*)ngCert, 0x180);
this->writeBytes((Int8*)apCert, 0x180);
}
} // zelda

View File

@ -2,6 +2,11 @@
// Licensed under the terms of the GNU GPL, version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
// TODO: Clean this code up and prune
// NOTE: It's pretty much been gutted from it's original form, does the original license even apply anymore?
// Not all of these headers are necessary, figure out which ones are actually used and prune those that are irrelevant.
#include <string.h>
#include <iostream>
#include <time.h>
@ -316,6 +321,8 @@ static void point_mul(Uint8 *d, Uint8 *a, Uint8 *b) // a is bignum
}
}
// DUPE FUNCTION! NUKE IT!!
void sillyRandom(Uint8 * rndArea, Uint8 count)
{
for(Uint16 i = 0; i < count; i++)

View File

@ -95,10 +95,70 @@ double swapDouble(double val)
retFloat[1] = convFloat[6];
retFloat[2] = convFloat[5];
retFloat[3] = convFloat[4];
retFloat[0] = convFloat[3];
retFloat[1] = convFloat[2];
retFloat[2] = convFloat[1];
retFloat[3] = convFloat[0];
retFloat[4] = convFloat[3];
retFloat[5] = convFloat[2];
retFloat[6] = convFloat[1];
retFloat[7] = convFloat[0];
return (double)((Uint64)retVal);
}
//src points to the yaz0 source data (to the "real" source data, not at the header!)
//dst points to a buffer uncompressedSize bytes large (you get uncompressedSize from
//the second 4 bytes in the Yaz0 header).
void yaz0Decode(Uint8* src, Uint8* dst, Uint32 uncompressedSize)
{
Uint32 srcPlace = 0, dstPlace = 0; //current read/write positions
Int32 validBitCount = 0; //number of valid bits left in "code" byte
Uint8 currCodeByte;
while(dstPlace < uncompressedSize)
{
//read new "code" byte if the current one is used up
if(validBitCount == 0)
{
currCodeByte = src[srcPlace];
++srcPlace;
validBitCount = 8;
}
if((currCodeByte & 0x80) != 0)
{
//straight copy
dst[dstPlace] = src[srcPlace];
dstPlace++;
srcPlace++;
}
else
{
//RLE part
Uint8 byte1 = src[srcPlace];
Uint8 byte2 = src[srcPlace + 1];
srcPlace += 2;
Uint32 dist = ((byte1 & 0xF) << 8) | byte2;
Uint32 copySource = dstPlace - (dist + 1);
Uint32 numBytes = byte1 >> 4;
if(numBytes == 0)
{
numBytes = src[srcPlace] + 0x12;
srcPlace++;
}
else
numBytes += 2;
//copy run
for(Uint32 i = 0; i < numBytes; ++i)
{
dst[dstPlace] = dst[copySource];
copySource++;
dstPlace++;
}
}
//use next bit from "code" byte
currCodeByte <<= 1;
validBitCount-=1;
}
}