CELL * p_rotate(CELL * params) { CELL * cell; CELL * list; CELL * previous; CELL * last = NULL; size_t length, index; size_t count; cell = params; if(cell->next != nilCell) getInteger(cell->next, (UINT *)&count); else count = 1; getEvalDefault(params, &list); if(symbolCheck && isProtected(symbolCheck->flags)) return(errorProcExt2(ERR_SYMBOL_PROTECTED, stuffSymbol(symbolCheck))); if(list->type == CELL_STRING) { length = list->aux - 1; if((count = adjustCount(count, length)) == 0) { pushResultFlag = FALSE; return(list); } cell = copyCell(list); memcpy((char*)cell->contents, (char *)(list->contents + length - count), count); memcpy((char*)(cell->contents + count), (char *)list->contents, length - count); memcpy((char*)list->contents, (char*)cell->contents, length); deleteList(cell); pushResultFlag = FALSE; return(list); } if(!isList(list->type)) return(errorProcExt(ERR_LIST_EXPECTED, cell)); list->aux = (UINT)nilCell; /* undo last element optimization */ cell = (CELL *)list->contents; length = 0; while(cell != nilCell) { ++length; last = cell; cell = cell->next; } if((count = adjustCount(count, length))== 0) { pushResultFlag = FALSE; return(list); } index = length - count; previous = cell = (CELL *)list->contents; while(index--) { previous = cell; cell = cell->next; } previous->next = nilCell; last->next = (CELL *)list->contents; list->contents = (UINT)cell; pushResultFlag = FALSE; return(list); }
ReturnValue Combat::canDoCombat(const Creature* attacker, const Creature* target, bool isAggressive) { if(!attacker) return RET_NOERROR; bool success = true; CreatureEventList combatEvents = const_cast<Creature*>(attacker)->getCreatureEvents(CREATURE_EVENT_COMBAT); for(CreatureEventList::iterator it = combatEvents.begin(); it != combatEvents.end(); ++it) { if(!(*it)->executeCombat(const_cast<Creature*>(attacker), const_cast<Creature*>(target), isAggressive) && success) success = false; } if(!success) return RET_NOTPOSSIBLE; bool checkZones = false; if(const Player* targetPlayer = target->getPlayer()) { if(!targetPlayer->isAttackable()) return RET_YOUMAYNOTATTACKTHISPLAYER; const Player* attackerPlayer = NULL; if((attackerPlayer = attacker->getPlayer()) || (attackerPlayer = attacker->getPlayerMaster())) { checkZones = true; if((g_game.getWorldType() == WORLDTYPE_OPTIONAL && !Combat::isInPvpZone(attacker, target) && !attackerPlayer->isEnemy(targetPlayer)) || isProtected(const_cast<Player*>(attackerPlayer), const_cast<Player*>(targetPlayer)) || (g_config.getBool(ConfigManager::CANNOT_ATTACK_SAME_LOOKFEET) && attackerPlayer->getDefaultOutfit().lookFeet == targetPlayer->getDefaultOutfit().lookFeet) || !attackerPlayer->canSeeCreature(targetPlayer)) return RET_YOUMAYNOTATTACKTHISPLAYER; } } else if(target->getMonster()) { if(!target->isAttackable()) return RET_YOUMAYNOTATTACKTHISCREATURE; const Player* attackerPlayer = NULL; if((attackerPlayer = attacker->getPlayer()) || (attackerPlayer = attacker->getPlayerMaster())) { if(attackerPlayer->hasFlag(PlayerFlag_CannotAttackMonster)) return RET_YOUMAYNOTATTACKTHISCREATURE; if(target->isPlayerSummon()) { checkZones = true; if(g_game.getWorldType() == WORLDTYPE_OPTIONAL && !Combat::isInPvpZone(attacker, target) && !attackerPlayer->isEnemy(target->getPlayerMaster())) return RET_YOUMAYNOTATTACKTHISCREATURE; } } } else if(target->getNpc() && !target->isAttackable()) return RET_YOUMAYNOTATTACKTHISCREATURE; return checkZones && (target->getTile()->hasFlag(TILESTATE_OPTIONALZONE) || (attacker->getTile()->hasFlag(TILESTATE_OPTIONALZONE) && !target->getTile()->hasFlag(TILESTATE_OPTIONALZONE) && !target->getTile()->hasFlag(TILESTATE_PROTECTIONZONE))) ? RET_ACTIONNOTPERMITTEDINANOPVPZONE : RET_NOERROR; }
CELL * p_replace(CELL * params) { CELL * keyCell; CELL * repCell; CELL * funcCell = NULL; CELL * list; CELL * cell; CELL * newList; char * keyStr; char * buff; char * newBuff; UINT cnt; size_t newLen; long options; UINT * resultIdxSave; SYMBOL * refSymbol; keyCell = copyCell(evaluateExpression(params)); pushResult(keyCell); params = getEvalDefault(params->next, &cell); newList = cell; refSymbol = symbolCheck; if(symbolCheck && (isProtected(symbolCheck->flags) || isBuiltin(symbolCheck->flags))) return(errorProcExt2(ERR_SYMBOL_PROTECTED, stuffSymbol(symbolCheck))); cnt = 0; resultIdxSave = resultStackIdx; if(isList(cell->type)) { cell->aux = (UINT)nilCell; /* undo last element optimization */ list = (CELL *)cell->contents; if(params != nilCell) { repCell = params; if(params->next != nilCell) funcCell = evaluateExpression(params->next); } else repCell = NULL; COMPARE_START: if(compareFunc(keyCell, list, funcCell) == 0) { if(repCell != NULL) { /* take out usage of sysSymbol0] in 10.2 should only be used for regex replacements then $it doesn't need to be a copy */ deleteList((CELL*)sysSymbol[0]->contents); itSymbol->contents = (UINT)copyCell(list); sysSymbol[0]->contents = itSymbol->contents; cell->contents = (UINT)copyCell(evaluateExpression(repCell)); cell = (CELL*)cell->contents; cell->next = list->next; } else /* remove mode */ cell->contents = (UINT)list->next; list->next = nilCell; deleteList(list); cnt++; if(repCell != NULL) list = cell; else /* remove mode */ { list = (CELL*)cell->contents; if(list != nilCell) goto COMPARE_START; } } while(list->next != nilCell) { if(compareFunc(keyCell, list->next, funcCell) == 0) { cell = list->next; /* cell = old elmnt */ if(repCell != NULL) { /* take out usage of sysSymbol0] in 10.2 should only be used for regex replacements */ deleteList((CELL*)sysSymbol[0]->contents); itSymbol->contents = (UINT)copyCell(cell); sysSymbol[0]->contents = itSymbol->contents; list->next = copyCell(evaluateExpression(repCell)); list = list->next; } list->next = cell->next; cell->next = nilCell; deleteList(cell); cnt++; } else list = list->next; cleanupResults(resultIdxSave); } deleteList((CELL*)sysSymbol[0]->contents); /* sysSymbol[0] should not be used here, introduce $count */ sysSymbol[0]->contents = (UINT)stuffInteger(cnt); itSymbol->contents = (UINT)nilCell; symbolCheck = refSymbol; pushResultFlag = FALSE; return(newList); } if(cell->type == CELL_STRING) { if(keyCell->type != CELL_STRING) return(errorProc(ERR_STRING_EXPECTED)); keyStr = (char *)keyCell->contents; buff = (char *)cell->contents; repCell = params; if(repCell == nilCell) return(errorProc(ERR_MISSING_ARGUMENT)); options = -1; if(repCell->next != nilCell) getInteger(repCell->next, (UINT*)&options); newBuff = replaceString(keyStr, keyCell->aux - 1, buff, (size_t)cell->aux -1, repCell, &cnt, options, &newLen); if(newBuff != NULL) { freeMemory(buff); cell->contents = (UINT)newBuff; cell->aux = newLen + 1; } deleteList((CELL*)sysSymbol[0]->contents); sysSymbol[0]->contents = (UINT)stuffInteger(cnt); symbolCheck = refSymbol; pushResultFlag = FALSE; return(cell); } return(errorProcExt(ERR_LIST_OR_STRING_EXPECTED, cell)); }
/** * Return the Protected setting for a method object. * * @return .true if the method is protected. .false otherwise. */ RexxObject *MethodClass::isProtectedRexx( ) { return booleanObject(isProtected()); }
void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const { ATRACE_CALL(); if (CC_UNLIKELY(mActiveBuffer == 0)) { // the texture has not been created yet, this Layer has // in fact never been drawn into. This happens frequently with // SurfaceView because the WindowManager can't know when the client // has drawn the first time. // If there is nothing under us, we paint the screen in black, otherwise // we just skip this update. // figure out if there is something below us Region under; const SurfaceFlinger::LayerVector& drawingLayers( mFlinger->mDrawingState.layersSortedByZ); const size_t count = drawingLayers.size(); for (size_t i=0 ; i<count ; ++i) { const sp<Layer>& layer(drawingLayers[i]); if (layer.get() == static_cast<Layer const*>(this)) break; under.orSelf( hw->getTransform().transform(layer->visibleRegion) ); } // if not everything below us is covered, we plug the holes! Region holes(clip.subtract(under)); if (!holes.isEmpty()) { clearWithOpenGL(hw, holes, 0, 0, 0, 1); } return; } // Bind the current buffer to the GL texture, and wait for it to be // ready for us to draw into. status_t err = mSurfaceFlingerConsumer->bindTextureImage(); if (err != NO_ERROR) { ALOGW("onDraw: bindTextureImage failed (err=%d)", err); // Go ahead and draw the buffer anyway; no matter what we do the screen // is probably going to have something visibly wrong. } bool canAllowGPU = false; #ifdef QCOM_BSP if(isProtected()) { char property[PROPERTY_VALUE_MAX]; if ((property_get("persist.gralloc.cp.level3", property, NULL) > 0) && (atoi(property) == 1)) { canAllowGPU = true; } } #endif bool blackOutLayer = isProtected() || (isSecure() && !hw->isSecure()); RenderEngine& engine(mFlinger->getRenderEngine()); if (!blackOutLayer || (canAllowGPU)) { // TODO: we could be more subtle with isFixedSize() const bool useFiltering = getFiltering() || needsFiltering(hw) || isFixedSize(); // Query the texture matrix given our current filtering mode. float textureMatrix[16]; mSurfaceFlingerConsumer->setFilteringEnabled(useFiltering); mSurfaceFlingerConsumer->getTransformMatrix(textureMatrix); if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) { /* * the code below applies the display's inverse transform to the texture transform */ // create a 4x4 transform matrix from the display transform flags const mat4 flipH(-1,0,0,0, 0,1,0,0, 0,0,1,0, 1,0,0,1); const mat4 flipV( 1,0,0,0, 0,-1,0,0, 0,0,1,0, 0,1,0,1); const mat4 rot90( 0,1,0,0, -1,0,0,0, 0,0,1,0, 1,0,0,1); mat4 tr; uint32_t transform = hw->getOrientationTransform(); if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) tr = tr * rot90; if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H) tr = tr * flipH; if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V) tr = tr * flipV; // calculate the inverse tr = inverse(tr); // and finally apply it to the original texture matrix const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr); memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix)); } // Set things up for texturing. mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight()); mTexture.setFiltering(useFiltering); mTexture.setMatrix(textureMatrix); engine.setupLayerTexturing(mTexture); } else { engine.setupLayerBlackedOut(); } drawWithOpenGL(hw, clip); engine.disableTexturing(); }
bool MapFile::SaveFile(bool SaveAs) { if ( isProtected() ) MessageBox(NULL, "Cannot save protected maps!", "Error!", MB_OK|MB_ICONEXCLAMATION); else { if ( SaveAs || filePath[0] == '\0' ) // SaveAs specified or filePath not yet determined { OPENFILENAME ofn = GetScSaveOfn(filePath); if ( GetSaveFileName(&ofn) ) { SaveType = (u8)ofn.nFilterIndex; char* ext = std::strrchr(filePath, '.'); // Find the last occurrence of '.' if ( ext == nullptr ) // No extension specified, need to add { if ( SaveType == 1 || SaveType == 2 ) std::strcat(filePath, ".scm"); else if ( SaveType == 3 || SaveType == 7 ) std::strcat(filePath, ".scx"); else if ( SaveType >= 4 && SaveType <= 6 ) std::strcat(filePath, ".chk"); } else // Extension specified, give it precedence over filterIndex { if ( std::strcmp(ext, ".chk") == 0 && SaveType < 4 ) SaveType = 5; else if ( std::strcmp(ext, ".scm") == 0 && SaveType > 1 ) SaveType = 2; else if ( std::strcmp(ext, ".scx") == 0 ) SaveType = 3; else if ( SaveType == 7 ) SaveType = 3; } } } if ( filePath[0] != '\0' ) // Map for sure has a path { FILE* pFile(nullptr); if ( SaveType == 1 || SaveType == 4 ) // StarCraft Map, edit to match { TYPE().overwrite("RAWS", 4); VER ().overwrite(";\0", 2); IVER().overwrite("\12\0", 2); IVE2().overwrite("\13\0", 2); if ( MRGN().size() > 1280 ) // If there's over 64 locations MRGN().delRange(1280, MRGN().size()); // Remove the extras } else if ( SaveType == 2 || SaveType == 5 ) // Hybrid Map, edit to match { TYPE().overwrite("RAWS", 4); VER ().overwrite("?\0", 2); IVER().overwrite("\12\0", 2); IVE2().overwrite("\13\0", 2); if ( MRGN().size() < 5100 ) // If there's < 255 locations MRGN().add<u8>(0, 5100-MRGN().size()); // Add space for 255 } else if ( SaveType == 3 || SaveType == 6 || SaveType == 7 ) // BroodWar Map, edit to match { TYPE().overwrite("RAWB", 4); VER ().overwrite("Í\0", 2); RemoveSection(SectionId::IVER); IVE2().overwrite("\13\0", 2); if ( MRGN().size() < 5100 ) // If there's < 255 locations MRGN().add<u8>(0, 5100-MRGN().size()); // Add space for 255 } if ( (SaveType > 0 && SaveType <= 3) || SaveType == 7 ) // Must be packed into an MPQ { pFile = std::fopen(filePath, "wb"); if ( pFile != nullptr ) { std::fclose(pFile); HANDLE hMpq = NULL; DeleteFileA("chk.tmp"); // Remove any existing chk.tmp files pFile = std::fopen("chk.tmp", "wb"); WriteFile(pFile); std::fclose(pFile); hMpq = MpqOpenArchiveForUpdate(filePath, MOAU_OPEN_ALWAYS|MOAU_MAINTAIN_LISTFILE, 16); if ( hMpq != NULL && hMpq != INVALID_HANDLE_VALUE ) { BOOL addedFile = MpqAddFileToArchive(hMpq, "chk.tmp", "staredit\\scenario.chk", MAFA_COMPRESS | MAFA_REPLACE_EXISTING); MpqCloseUpdatedArchive(hMpq, 0); if ( addedFile == TRUE ) { DeleteFileA("chk.tmp"); return true; } else MessageBox(NULL, "Failed to add file!", "Error!", MB_OK|MB_ICONEXCLAMATION); } else MessageBox(NULL, "Failed to open for updates!", "Error!", MB_OK|MB_ICONEXCLAMATION); DeleteFileA("chk.tmp"); } else MessageBox(NULL, "Failed to open file!\n\nThe file may be in use elsewhere.", "Error!", MB_OK|MB_ICONEXCLAMATION); } else // Is a chk file or unrecognized format, write out chk file { DeleteFileA(filePath); // Remove any existing files of the same name pFile = std::fopen(filePath, "wb"); WriteFile(pFile); std::fclose(pFile); return true; } } } return false; }
void Layer::onDraw(const Region& clip) const { if (CC_UNLIKELY(mActiveBuffer == 0)) { // the texture has not been created yet, this Layer has // in fact never been drawn into. This happens frequently with // SurfaceView because the WindowManager can't know when the client // has drawn the first time. // If there is nothing under us, we paint the screen in black, otherwise // we just skip this update. // figure out if there is something below us Region under; const SurfaceFlinger::LayerVector& drawingLayers( mFlinger->mDrawingState.layersSortedByZ); const size_t count = drawingLayers.size(); for (size_t i=0 ; i<count ; ++i) { const sp<LayerBase>& layer(drawingLayers[i]); if (layer.get() == static_cast<LayerBase const*>(this)) break; under.orSelf(layer->visibleRegionScreen); } // if not everything below us is covered, we plug the holes! Region holes(clip.subtract(under)); if (!holes.isEmpty()) { clearWithOpenGL(holes, 0, 0, 0, 1); } return; } if (!isGPUSupportedFormat(mActiveBuffer->format)) { clearWithOpenGL(clip, 0, 0, 0, 1); return; } if (!isProtected()) { glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName); GLenum filter = GL_NEAREST; if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) { // TODO: we could be more subtle with isFixedSize() filter = GL_LINEAR; } glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter); glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter); glMatrixMode(GL_TEXTURE); glLoadMatrixf(mTextureMatrix); glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_EXTERNAL_OES); } else { glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName()); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_EXTERNAL_OES); glEnable(GL_TEXTURE_2D); } if(needsDithering()) { glEnable(GL_DITHER); } int composeS3DFormat = mQCLayer->needsS3DCompose(); if (composeS3DFormat) drawS3DUIWithOpenGL(clip); else drawWithOpenGL(clip); glDisable(GL_TEXTURE_EXTERNAL_OES); glDisable(GL_TEXTURE_2D); if(needsDithering()) { glDisable(GL_DITHER); } }
void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const { ATRACE_CALL(); if (CC_UNLIKELY(mActiveBuffer == 0)) { // the texture has not been created yet, this Layer has // in fact never been drawn into. This happens frequently with // SurfaceView because the WindowManager can't know when the client // has drawn the first time. // If there is nothing under us, we paint the screen in black, otherwise // we just skip this update. // figure out if there is something below us Region under; const SurfaceFlinger::LayerVector& drawingLayers( mFlinger->mDrawingState.layersSortedByZ); const size_t count = drawingLayers.size(); for (size_t i=0 ; i<count ; ++i) { const sp<LayerBase>& layer(drawingLayers[i]); if (layer.get() == static_cast<LayerBase const*>(this)) break; under.orSelf( hw->getTransform().transform(layer->visibleRegion) ); } // if not everything below us is covered, we plug the holes! Region holes(clip.subtract(under)); if (!holes.isEmpty()) { clearWithOpenGL(hw, holes, 0, 0, 0, 1); } return; } status_t err = mSurfaceTexture->doGLFenceWait(); if (err != OK) { ALOGE("onDraw: failed waiting for fence: %d", err); // Go ahead and draw the buffer anyway; no matter what we do the screen // is probably going to have something visibly wrong. } bool blackOutLayer = isProtected() || (isSecure() && !hw->isSecure()); if (!blackOutLayer) { // TODO: we could be more subtle with isFixedSize() const bool useFiltering = getFiltering() || needsFiltering(hw) || isFixedSize(); // Query the texture matrix given our current filtering mode. float textureMatrix[16]; mSurfaceTexture->setFilteringEnabled(useFiltering); mSurfaceTexture->getTransformMatrix(textureMatrix); // Set things up for texturing. glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName); GLenum filter = GL_NEAREST; if (useFiltering) { filter = GL_LINEAR; } glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter); glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter); glMatrixMode(GL_TEXTURE); glLoadMatrixf(textureMatrix); glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_EXTERNAL_OES); } else { glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName()); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_EXTERNAL_OES); glEnable(GL_TEXTURE_2D); } drawWithOpenGL(hw, clip); glDisable(GL_TEXTURE_EXTERNAL_OES); glDisable(GL_TEXTURE_2D); }
bool MapFile::SaveFile(bool SaveAs) { if ( isProtected() ) MessageBox(NULL, "Cannot save protected maps!", "Error!", MB_OK|MB_ICONEXCLAMATION); else { if ( SaveAs || filePath[0] == '\0' ) // SaveAs specified or filePath not yet determined { OPENFILENAME ofn = GetScSaveOfn(filePath); if ( GetSaveFileName(&ofn) ) { saveType = (SaveType)ofn.nFilterIndex; char* ext = std::strrchr(filePath, '.'); // Find the last occurrence of '.' if ( ext == nullptr ) // No extension specified, need to add { if ( saveType == SaveType::StarCraftScm || saveType == SaveType::HybridScm ) std::strcat(filePath, ".scm"); else if ( saveType == SaveType::ExpansionScx || saveType == SaveType::AllMaps ) std::strcat(filePath, ".scx"); else if ( saveType == SaveType::StarCraftChk || saveType == SaveType::HybridChk || saveType == SaveType::ExpansionChk ) { std::strcat(filePath, ".chk"); } } else // Extension specified, give it precedence over filterIndex { if ( std::strcmp(ext, ".chk") == 0 && (saveType == SaveType::StarCraftScm || saveType == SaveType::HybridScm || saveType == SaveType::ExpansionScx) ) { saveType = SaveType::HybridChk; } else if ( std::strcmp(ext, ".scm") == 0 && saveType != SaveType::StarCraftScm ) saveType = SaveType::HybridScm; else if ( std::strcmp(ext, ".scx") == 0 ) saveType = SaveType::ExpansionScx; else if ( saveType == SaveType::AllMaps ) saveType = SaveType::ExpansionScx; } } } if ( filePath[0] != '\0' ) // Map for sure has a path { FILE* pFile(nullptr); if ( saveType == SaveType::StarCraftScm || saveType == SaveType::StarCraftChk ) // StarCraft Map, edit to match ChangeToScOrig(); else if ( saveType == SaveType::HybridScm || saveType == SaveType::HybridChk ) // Hybrid Map, edit to match ChangeToHybrid(); else if ( saveType == SaveType::ExpansionScx || saveType == SaveType::ExpansionChk || saveType == SaveType::AllMaps ) // BroodWar Map, edit to match { ChangeToScExp(); } if ( (saveType == SaveType::StarCraftScm || saveType == SaveType::HybridScm || saveType == SaveType::ExpansionScx) || saveType == SaveType::AllMaps ) // Must be packed into an MPQ { pFile = std::fopen(filePath, "wb"); if ( pFile != nullptr ) { std::fclose(pFile); HANDLE hMpq = NULL; DeleteFileA("chk.tmp"); // Remove any existing chk.tmp files pFile = std::fopen("chk.tmp", "wb"); WriteFile(pFile); std::fclose(pFile); hMpq = MpqOpenArchiveForUpdate(filePath, MOAU_OPEN_ALWAYS|MOAU_MAINTAIN_LISTFILE, 16); if ( hMpq != NULL && hMpq != INVALID_HANDLE_VALUE ) { BOOL addedFile = MpqAddFileToArchive(hMpq, "chk.tmp", "staredit\\scenario.chk", MAFA_COMPRESS | MAFA_REPLACE_EXISTING); MpqCloseUpdatedArchive(hMpq, 0); if ( addedFile == TRUE ) { DeleteFileA("chk.tmp"); return true; } else MessageBox(NULL, "Failed to add file!", "Error!", MB_OK|MB_ICONEXCLAMATION); } else MessageBox(NULL, "Failed to open for updates!", "Error!", MB_OK|MB_ICONEXCLAMATION); DeleteFileA("chk.tmp"); } else MessageBox(NULL, "Failed to open file!\n\nThe file may be in use elsewhere.", "Error!", MB_OK|MB_ICONEXCLAMATION); } else // Is a chk file or unrecognized format, write out chk file { DeleteFileA(filePath); // Remove any existing files of the same name pFile = std::fopen(filePath, "wb"); WriteFile(pFile); std::fclose(pFile); return true; } } } return false; }
ReturnValue Combat::canDoCombat(const Creature* attacker, const Creature* target) { if (attacker) { if (const Player* targetPlayer = target->getPlayer()) { if (targetPlayer->hasFlag(PlayerFlag_CannotBeAttacked)) { return RET_YOUMAYNOTATTACKTHISPLAYER; } if (const Player* attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlag_CannotAttackPlayer)) { return RET_YOUMAYNOTATTACKTHISPLAYER; } if (isProtected(attackerPlayer, targetPlayer)) { return RET_YOUMAYNOTATTACKTHISPLAYER; } //nopvp-zone const Tile* targetPlayerTile = targetPlayer->getTile(); if (targetPlayerTile->hasFlag(TILESTATE_NOPVPZONE)) { return RET_ACTIONNOTPERMITTEDINANOPVPZONE; } else if (attackerPlayer->getTile()->hasFlag(TILESTATE_NOPVPZONE) && !targetPlayerTile->hasFlag(TILESTATE_NOPVPZONE) && !targetPlayerTile->hasFlag(TILESTATE_PROTECTIONZONE)) { return RET_ACTIONNOTPERMITTEDINANOPVPZONE; } } if (attacker->isSummon()) { if (const Player* masterAttackerPlayer = attacker->getMaster()->getPlayer()) { if (masterAttackerPlayer->hasFlag(PlayerFlag_CannotAttackPlayer)) { return RET_YOUMAYNOTATTACKTHISPLAYER; } if (targetPlayer->getTile()->hasFlag(TILESTATE_NOPVPZONE)) { return RET_ACTIONNOTPERMITTEDINANOPVPZONE; } if (isProtected(masterAttackerPlayer, targetPlayer)) { return RET_YOUMAYNOTATTACKTHISPLAYER; } } } } else if (target->getMonster()) { if (const Player* attackerPlayer = attacker->getPlayer()) { if (attackerPlayer->hasFlag(PlayerFlag_CannotAttackMonster)) { return RET_YOUMAYNOTATTACKTHISCREATURE; } if (target->isSummon() && target->getMaster()->getPlayer() && target->getZone() == ZONE_NOPVP) { return RET_ACTIONNOTPERMITTEDINANOPVPZONE; } } else if (attacker->getMonster()) { const Creature* targetMaster = target->getMaster(); if (!targetMaster || !targetMaster->getPlayer()) { const Creature* attackerMaster = attacker->getMaster(); if (!attackerMaster || !attackerMaster->getPlayer()) { return RET_YOUMAYNOTATTACKTHISCREATURE; } } } } if (g_game.getWorldType() == WORLD_TYPE_NO_PVP) { if (attacker->getPlayer() || (attacker->isSummon() && attacker->getMaster()->getPlayer())) { if (target->getPlayer()) { if (!isInPvpZone(attacker, target)) { return RET_YOUMAYNOTATTACKTHISPLAYER; } } if (target->isSummon() && target->getMaster()->getPlayer()) { if (!isInPvpZone(attacker, target)) { return RET_YOUMAYNOTATTACKTHISCREATURE; } } } } } return RET_NOERROR; }