/// Loads data for testing the 'testFileName' file. void loadTestFileData(const char* testFileName) { fileName = getTestFileFullPath(SAMPLE_FILES_DIR, testFileName); const char* fileContent = loadTestFile(SAMPLE_FILES_DIR, testFileName, true); // must be binary mode! int fileSize = (int)fgetsize(fileName.c_str()); const WCHAR* wtestFileName = toWideChar(testFileName); FileData fileData; fileData.setName(wtestFileName); fileData.setSize(fileSize); fileData.setBody(fileContent, fileSize); unsigned long tstamp = getFileModTime(fileName); StringBuffer modTime = unixTimeToString(tstamp, true); // file's mod time is already in UTC WString wmodTime; wmodTime = modTime; fileData.setModified(wmodTime); fileDataContent = fileData.format(); fileDataSize = (int)strlen(fileDataContent); delete [] wtestFileName; delete [] fileContent; }
bool CLevel::loadGraal(CString& pFileName) { CPacket levelData; CString version; char* dataFile = getDataFile(pFileName.text()); if(!strlen(dataFile)) return false; if(!levelData.load(dataFile)) return false; fileName = pFileName; modTime = getFileModTime(dataFile); version = levelData.readChars(8); bool v0 = (version == "GR-V1.00"); bool v1 = (version == "GR-V1.01"); bool v2 = (version == "GR-V1.02"); bool v3 = (version == "GR-V1.03"); //printf("Loading map %s\n", pFileName.text()); //printf("Loading tiles..\n"); loadTiles(levelData, version); //printf("Loading links..\n"); loadLinks(levelData); //printf("Loading baddies..\n"); loadBaddies(levelData); if (v0 || v1 || v2 || v3) { //printf("Loading npcs..\n"); loadNpcs(levelData); } if (v1 || v2 || v3) { //printf("Loading chests..\n"); loadChests(levelData); } //printf("Loading signs..\n"); loadSigns(levelData); //Find our map id for(int i = 0; i < CMap::mapList.count(); i++) { CMap* m = (CMap*)CMap::mapList[i]; if((levelIndex = m->getLevelpos(pFileName)) >= 0) { map = m; break; } } return true; }
bool CLevel::loadZelda(CString& pFileName) { CPacket levelData; CString version; char* dataFile = getDataFile(pFileName.text()); if(!strlen(dataFile)) return false; if(!levelData.load(dataFile)) return false; fileName = pFileName; modTime = getFileModTime(dataFile); version = levelData.readChars(8); // Some clients will actually save .zelda levels as .graal. // If this is the case, parse it through the .graal loader. if (version.copy(0, 2) == "GR") return loadGraal(pFileName); bool v0 = (version == "unknown"); bool v1 = (version == "unknown"); bool v2 = (version == "unknown"); bool v3 = (version == "Z3-V1.03"); bool v4 = (version == "Z3-V1.04"); // If we encountered an unknown version, ask the user to send it in so we can add support for it. if (!v3 && !v4) { errorOut("errorlog.txt", CString() << "Level " << fileName << " is of version " << version << ". That version is unknown. Please send us the level so we may add support for it.", true); return false; } loadTiles(levelData, version); loadLinks(levelData); loadBaddies(levelData); loadSigns(levelData); //Find our map id for(int i = 0; i < CMap::mapList.count(); i++) { CMap* m = (CMap*)CMap::mapList[i]; if((levelIndex = m->getLevelpos(pFileName)) >= 0) { map = m; break; } } return true; }
bool CLevel::loadGraal(CString& pFileName) { CPacket levelData; CString version; char* dataFile = getDataFile(pFileName.text()); if(!strlen(dataFile)) return false; if(!levelData.load(dataFile)) return false; fileName = pFileName; modTime = getFileModTime(dataFile); version = levelData.readChars(8); bool v0 = (version == "GR-V1.00"); bool v1 = (version == "GR-V1.01"); bool v2 = (version == "GR-V1.02"); bool v3 = (version == "GR-V1.03"); //printf("Loading map %s\n", pFileName.text()); //printf("Loading tiles..\n"); loadTiles(levelData, version); //printf("Loading links..\n"); loadLinks(levelData); //printf("Loading baddies..\n"); loadBaddies(levelData); if (v0 || v1 || v2 || v3) { //printf("Loading npcs..\n"); loadNpcs(levelData); } if (v1 || v2 || v3) { //printf("Loading chests..\n"); loadChests(levelData); } //printf("Loading signs..\n"); loadSigns(levelData); return true; }
bool CLevel::loadNW(CString& pFileName) { CStringList levelData; CString version; char* dataFile = getDataFile(pFileName.text()); if(!strlen(dataFile)) return false; if(!levelData.load(dataFile)) return false; if(levelData.count() < 1) return false; version = levelData[0]; modTime = getFileModTime(dataFile); fileName = pFileName; if(version == "GLEVNW01" || version == "GSERVL01") { for(int i = 1; i < levelData.count(); i ++) { CStringList words; words.load(levelData[i].text(), " "); if(words.count() <= 0) continue; if(words[0] == "BOARD") { if(words.count() <= 5) continue; int x = atoi(words[1].text()); int y = atoi(words[2].text()); int w = atoi(words[3].text()); CString& data = words[5]; if(x >= 0 && x <= 64 && y >= 0 && y <= 64 && w > 0 && x + w <= 64) { if(data.length() >= w*2) { for(int ii = x; ii < x + w; ii++) { char left = data.readChar(); char top = data.readChar(); short tile = base64.find(left) << 6; tile += base64.find(top); tiles[ii + y*64] = tile; } } } } else if(words[0] == "LINK") { if(words.count() <= 7) continue; if(strlen(getDataFile(words[1].text()))) { links.add(new CLink(words[1], atoi(words[2].text()), atoi(words[3].text()), atoi(words[4].text()), atoi(words[5].text()), words[6], words[7])); } } else if(words[0] == "CHEST") { if(words.count() <= 4) continue; for(int ii = 0; ii < itemcount; ii++) { if(words[3] == itemNames[ii]) { chests.add(new CChest(atoi(words[1].text()), atoi(words[2].text()), atoi(words[4].text()), ii)); break; } } } else if(words[0] == "NPC") { if(words.count() <= 3) continue; CString image, code, code2; float x, y; if(words[1] != "-") image = words[1]; x = (float)atof(words[2].text()); y = (float)atof(words[3].text()); for(i++; i < levelData.count() && levelData[i] != "NPCEND"; i++) code << levelData[i] << "\xa7"; // Create the new NPC. Do this before parsing the join commands. // The CNpc constructor will remove all comments. CNpc* jnpc = new CNpc( image, code, x, y, this, true ); // Now filter out the join commands. CStringList npcData; npcData.load( jnpc->clientCode.text(), "\xa7" ); for ( int j = 0; j < npcData.count(); ++j ) code2 << processNpcLine( npcData[j] ) << "\xa7"; jnpc->clientCode = code2; // Now, add all the joined files to the code. if ( joinList.count() > 0 ) { CString* file = 0; while ( (file = (CString*)joinList[0]) != 0 ) { // Load the source file into memory. CString dataFile = getDataFile(file->text()); if(dataFile.length()) { // Append to the end of the script. CString retVal; retVal.load(dataFile.text()); retVal.replaceAll("\r\n", "\xa7"); retVal.replaceAll("\n", "\xa7"); jnpc->clientCode << retVal << "\xa7"; } delete (CString*)joinList[0]; joinList.remove(0); } } joinList.clear(); npcs.add( jnpc ); } else if(words[0] == "BADDY") { if(words.count() <= 3) continue; int x = atoi(words[1].text()); int y = atoi(words[2].text()); int type = atoi(words[3].text()); CBaddy* baddy = new CBaddy(x, y, type); int baddyId = createBaddyId(baddy); baddy->id = baddyId; for(i++; i < levelData.count() && levelData[i] != "BADDYEND"; i++) baddy->verses.add(levelData[i].text()); if(baddies.count() < 50) baddies.add(baddy); else delete baddy; } else if(words[0] == "SIGN") { if(words.count() <= 2) continue; CString sign; int x = atoi(words[1].text()); int y = atoi(words[2].text()); sign.writeChar(x+32); sign.writeChar(y+32); for (i++; i < levelData.count() && levelData[i] != "SIGNEND"; i++) sign << getSignCode(CString() << levelData[i] << "\n"); signs.add(sign); } else if(words[0] == "REPLACENPC") { int npcId = atoi(words[1].text()); CNpc* npc = (CNpc*)npcs[npcId]; if(npc == NULL) continue; for(i++; i < levelData.count() && levelData[i] != "REPLACENPCEND"; i++) npc->setProps((CPacket&)levelData[i]); } } } else return false; return true; }