本文整理汇总了C++中PropStream::readStruct方法的典型用法代码示例。如果您正苦于以下问题:C++ PropStream::readStruct方法的具体用法?C++ PropStream::readStruct怎么用?C++ PropStream::readStruct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropStream
的用法示例。
在下文中一共展示了PropStream::readStruct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadMap
bool IOMap::loadMap(Map* map, const std::string& identifier)
{
int64_t start = OTSYS_TIME();
FileLoader f;
if (!f.openFile(identifier.c_str(), "OTBM")) {
std::ostringstream ss;
ss << "Could not open the file " << identifier << '.';
setLastErrorString(ss.str());
return false;
}
uint32_t type;
PropStream propStream;
NODE root = f.getChildNode(nullptr, type);
if (!f.getProps(root, propStream)) {
setLastErrorString("Could not read root property.");
return false;
}
const OTBM_root_header* root_header;
if (!propStream.readStruct(root_header)) {
setLastErrorString("Could not read header.");
return false;
}
uint32_t headerVersion = root_header->version;
if (headerVersion <= 0) {
//In otbm version 1 the count variable after splashes/fluidcontainers and stackables
//are saved as attributes instead, this solves alot of problems with items
//that is changed (stackable/charges/fluidcontainer/splash) during an update.
setLastErrorString("This map need to be upgraded by using the latest map editor version to be able to load correctly.");
return false;
}
if (headerVersion > 2) {
setLastErrorString("Unknown OTBM version detected.");
return false;
}
if (root_header->majorVersionItems < 3) {
setLastErrorString("This map need to be upgraded by using the latest map editor version to be able to load correctly.");
return false;
}
if (root_header->majorVersionItems > Items::dwMajorVersion) {
setLastErrorString("The map was saved with a different items.otb version, an upgraded items.otb is required.");
return false;
}
if (root_header->minorVersionItems < CLIENT_VERSION_810) {
setLastErrorString("This map needs to be updated.");
return false;
}
if (root_header->minorVersionItems > Items::dwMinorVersion) {
std::cout << "[Warning - IOMap::loadMap] This map needs an updated items.otb." << std::endl;
}
std::cout << "> Map size: " << root_header->width << "x" << root_header->height << '.' << std::endl;
map->width = root_header->width;
map->height = root_header->height;
NODE nodeMap = f.getChildNode(root, type);
if (type != OTBM_MAP_DATA) {
setLastErrorString("Could not read data node.");
return false;
}
if (!f.getProps(nodeMap, propStream)) {
setLastErrorString("Could not read map data attributes.");
return false;
}
std::string mapDescription;
std::string tmp;
uint8_t attribute;
while (propStream.read<uint8_t>(attribute)) {
switch (attribute) {
case OTBM_ATTR_DESCRIPTION:
if (!propStream.readString(mapDescription)) {
setLastErrorString("Invalid description tag.");
return false;
}
break;
case OTBM_ATTR_EXT_SPAWN_FILE:
if (!propStream.readString(tmp)) {
setLastErrorString("Invalid spawn tag.");
return false;
}
map->spawnfile = identifier.substr(0, identifier.rfind('/') + 1);
map->spawnfile += tmp;
break;
case OTBM_ATTR_EXT_HOUSE_FILE:
if (!propStream.readString(tmp)) {
//.........这里部分代码省略.........
示例2: loadFromOtb
FILELOADER_ERRORS Items::loadFromOtb(const std::string& file)
{
FileLoader f;
if (!f.openFile(file.c_str(), "OTBI")) {
return f.getError();
}
uint32_t type;
NODE node = f.getChildNode(NO_NODE, type);
PropStream props;
if (f.getProps(node, props)) {
//4 byte flags
//attributes
//0x01 = version data
uint32_t flags;
if (!props.read<uint32_t>(flags)) {
return ERROR_INVALID_FORMAT;
}
uint8_t attr;
if (!props.read<uint8_t>(attr)) {
return ERROR_INVALID_FORMAT;
}
if (attr == ROOT_ATTR_VERSION) {
uint16_t datalen;
if (!props.read<uint16_t>(datalen)) {
return ERROR_INVALID_FORMAT;
}
if (datalen != sizeof(VERSIONINFO)) {
return ERROR_INVALID_FORMAT;
}
const VERSIONINFO* vi;
if (!props.readStruct(vi)) {
return ERROR_INVALID_FORMAT;
}
Items::dwMajorVersion = vi->dwMajorVersion; //items otb format file version
Items::dwMinorVersion = vi->dwMinorVersion; //client version
Items::dwBuildNumber = vi->dwBuildNumber; //revision
}
}
if (Items::dwMajorVersion == 0xFFFFFFFF) {
std::cout << "[Warning - Items::loadFromOtb] items.otb using generic client version." << std::endl;
} else if (Items::dwMajorVersion != 3) {
std::cout << "Old version detected, a newer version of items.otb is required." << std::endl;
return ERROR_INVALID_FORMAT;
} else if (Items::dwMinorVersion < CLIENT_VERSION_1076) {
std::cout << "A newer version of items.otb is required." << std::endl;
return ERROR_INVALID_FORMAT;
}
node = f.getChildNode(node, type);
while (node != NO_NODE) {
PropStream stream;
if (!f.getProps(node, stream)) {
return f.getError();
}
uint32_t flags;
if (!stream.read<uint32_t>(flags)) {
return ERROR_INVALID_FORMAT;
}
uint16_t serverId = 0;
uint16_t clientId = 0;
uint16_t speed = 0;
uint16_t wareId = 0;
uint8_t lightLevel = 0;
uint8_t lightColor = 0;
uint8_t alwaysOnTopOrder = 0;
uint8_t attrib;
while (stream.read<uint8_t>(attrib)) {
uint16_t datalen;
if (!stream.read<uint16_t>(datalen)) {
return ERROR_INVALID_FORMAT;
}
switch (attrib) {
case ITEM_ATTR_SERVERID: {
if (datalen != sizeof(uint16_t)) {
return ERROR_INVALID_FORMAT;
}
if (!stream.read<uint16_t>(serverId)) {
return ERROR_INVALID_FORMAT;
}
if (serverId > 30000 && serverId < 30100) {
serverId -= 30000;
}
break;
}
case ITEM_ATTR_CLIENTID: {
//.........这里部分代码省略.........