CPolygonPathKey::CPolygonPathKey(const CStringW& str, double scalex, double scaley) : m_str(str) , m_scalex(scalex) , m_scaley(scaley) { UpdateHash(); }
void SwapHole(Pos new_hole_pos) { std::swap(a[IndexOf(hole)], a[IndexOf(new_hole_pos)]); hole = new_hole_pos; UpdateHash(); }
COutlineKey::COutlineKey(const CWord* word, CPoint org) : CTextDimsKey(word->m_str, word->m_style) , m_scalex(word->m_scalex) , m_scaley(word->m_scaley) , m_org(org) { UpdateHash(); }
CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), fOverwintered(tx.fOverwintered), nVersionGroupId(tx.nVersionGroupId), nExpiryHeight(tx.nExpiryHeight), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), valueBalance(tx.valueBalance), vShieldedSpend(tx.vShieldedSpend), vShieldedOutput(tx.vShieldedOutput), vjoinsplit(tx.vjoinsplit), joinSplitPubKey(tx.joinSplitPubKey), joinSplitSig(tx.joinSplitSig), bindingSig(tx.bindingSig) { UpdateHash(); }
CGovernanceVote::CGovernanceVote(const COutPoint& outpointMasternodeIn, const uint256& nParentHashIn, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) : fValid(true), fSynced(false), nVoteSignal(eVoteSignalIn), masternodeOutpoint(outpointMasternodeIn), nParentHash(nParentHashIn), nVoteOutcome(eVoteOutcomeIn), nTime(GetAdjustedTime()), vchSig() { UpdateHash(); }
State(std::initializer_list<int> l) { if (l.size() != N) { throw std::runtime_error("State initialized with bad list length"); } int i = 0; for (auto e : l) { a[i++] = e; if (e == 0) { hole = PosOf(i - 1); } } UpdateHash(); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t W i z a r d M a g i c k % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetWizardMagick() produces a unique signature useful for verifying that a % structure or file is in fact Wizard related. % % The format of the GetWizardMagick method is: % % StringInfo GetWizardMagick(const char *signature,const size_t length) % % A description of each parameter follows: % % o signature: Derive the magick from this signature. % % */ WizardExport StringInfo *GetWizardMagick(const unsigned char *signature, const size_t length) { HashInfo *hash_info; StringInfo *magick, *tag; hash_info=AcquireHashInfo(SHA2256Hash); InitializeHash(hash_info); tag=AcquireStringInfo(length); SetStringInfoDatum(tag,signature); UpdateHash(hash_info,tag); tag=DestroyStringInfo(tag); FinalizeHash(hash_info); magick=CloneStringInfo(GetHashDigest(hash_info)); hash_info=DestroyHashInfo(hash_info); return(magick); }
CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) { UpdateHash(); }
bool SavedataParam::Save(SceUtilitySavedataParam* param, int saveId) { if (!param) { return false; } std::string dirPath = GetSaveFilePath(param, saveId); if (!pspFileSystem.GetFileInfo(dirPath).exists) pspFileSystem.MkDir(dirPath); u8* cryptedData = 0; int cryptedSize = 0; u8 cryptedHash[0x10]; memset(cryptedHash,0,0x10); // Encrypt save. if(param->dataBuf != 0 && g_Config.bEncryptSave) { cryptedSize = param->dataSize; if(cryptedSize == 0 || (SceSize)cryptedSize > param->dataBufSize) cryptedSize = param->dataBufSize; // fallback, should never use this u8* data_ = (u8*)Memory::GetPointer(param->dataBuf); int aligned_len = align16(cryptedSize); cryptedData = new u8[aligned_len + 0x10]; memcpy(cryptedData, data_, cryptedSize); int decryptMode = 1; if(param->key[0] != 0) { decryptMode = (GetSDKMainVersion(sceKernelGetCompiledSdkVersion()) >= 4 ? 5 : 3); } if(EncryptData(decryptMode, cryptedData, &cryptedSize, &aligned_len, cryptedHash, ((param->key[0] != 0)?param->key:0)) == 0) { } else { ERROR_LOG(HLE,"Save encryption failed. This save won't work on real PSP"); delete[] cryptedData; cryptedData = 0; } } // SAVE PARAM.SFO ParamSFOData sfoFile; std::string sfopath = dirPath+"/"+sfoName; PSPFileInfo sfoInfo = pspFileSystem.GetFileInfo(sfopath); if(sfoInfo.exists) // Read old sfo if exist { u8 *sfoData = new u8[(size_t)sfoInfo.size]; size_t sfoSize = (size_t)sfoInfo.size; if(ReadPSPFile(sfopath,&sfoData,sfoSize, NULL)) { sfoFile.ReadSFO(sfoData,sfoSize); delete[] sfoData; } } // Update values sfoFile.SetValue("TITLE",param->sfoParam.title,128); sfoFile.SetValue("SAVEDATA_TITLE",param->sfoParam.savedataTitle,128); sfoFile.SetValue("SAVEDATA_DETAIL",param->sfoParam.detail,1024); sfoFile.SetValue("PARENTAL_LEVEL",param->sfoParam.parentalLevel,4); sfoFile.SetValue("CATEGORY","MS",4); sfoFile.SetValue("SAVEDATA_DIRECTORY",GetSaveDir(param,saveId),64); // For each file, 13 bytes for filename, 16 bytes for file hash (0 in PPSSPP), 3 byte for padding const int FILE_LIST_ITEM_SIZE = 13 + 16 + 3; const int FILE_LIST_COUNT_MAX = 99; const int FILE_LIST_TOTAL_SIZE = FILE_LIST_ITEM_SIZE * FILE_LIST_COUNT_MAX; u32 tmpDataSize = 0; u8* tmpDataOrig = sfoFile.GetValueData("SAVEDATA_FILE_LIST", &tmpDataSize); u8* tmpData = new u8[FILE_LIST_TOTAL_SIZE]; if (tmpDataOrig != NULL) memcpy(tmpData, tmpDataOrig, tmpDataSize > FILE_LIST_TOTAL_SIZE ? FILE_LIST_TOTAL_SIZE : tmpDataSize); else memset(tmpData, 0, FILE_LIST_TOTAL_SIZE); if (param->dataBuf != 0) { char *fName = (char*)tmpData; for(int i = 0; i < FILE_LIST_COUNT_MAX; i++) { if(fName[0] == 0) break; // End of list if(strncmp(fName,GetFileName(param).c_str(),20) == 0) break; fName += FILE_LIST_ITEM_SIZE; } if (fName + 13 <= (char*)tmpData + FILE_LIST_TOTAL_SIZE) snprintf(fName, 13, "%s",GetFileName(param).c_str()); if (fName + 13 + 16 <= (char*)tmpData + FILE_LIST_TOTAL_SIZE) memcpy(fName+13, cryptedHash, 16); } sfoFile.SetValue("SAVEDATA_FILE_LIST", tmpData, FILE_LIST_TOTAL_SIZE, FILE_LIST_TOTAL_SIZE); delete[] tmpData; // Init param with 0. This will be used to detect crypted save or not on loading tmpData = new u8[128]; memset(tmpData, 0, 128); sfoFile.SetValue("SAVEDATA_PARAMS", tmpData, 128, 128); delete[] tmpData; u8 *sfoData; size_t sfoSize; sfoFile.WriteSFO(&sfoData,&sfoSize); // Calc SFO hash for PSP. if(cryptedData != 0) { int offset = sfoFile.GetDataOffset(sfoData,"SAVEDATA_PARAMS"); if(offset >= 0) UpdateHash(sfoData, sfoSize, offset, (param->key[0]?3:1)); } WritePSPFile(sfopath, sfoData, (SceSize)sfoSize); delete[] sfoData; if(param->dataBuf != 0) // Can launch save without save data in mode 13 { std::string filePath = dirPath+"/"+GetFileName(param); u8* data_ = 0; SceSize saveSize = 0; if(cryptedData == 0) // Save decrypted data { saveSize = param->dataSize; if(saveSize == 0 || saveSize > param->dataBufSize) saveSize = param->dataBufSize; // fallback, should never use this data_ = (u8*)Memory::GetPointer(param->dataBuf); } else { data_ = cryptedData; saveSize = cryptedSize; } INFO_LOG(HLE,"Saving file with size %u in %s",saveSize,filePath.c_str()); // copy back save name in request strncpy(param->saveName,GetSaveDirName(param, saveId).c_str(),20); if (!WritePSPFile(filePath, data_, saveSize)) { ERROR_LOG(HLE,"Error writing file %s",filePath.c_str()); if(cryptedData != 0) { delete[] cryptedData; } return false; } delete[] cryptedData; } // SAVE ICON0 if (param->icon0FileData.buf) { u8* data_ = (u8*)Memory::GetPointer(param->icon0FileData.buf); std::string icon0path = dirPath+"/"+icon0Name; WritePSPFile(icon0path, data_, param->icon0FileData.bufSize); } // SAVE ICON1 if (param->icon1FileData.buf) { u8* data_ = (u8*)Memory::GetPointer(param->icon1FileData.buf); std::string icon1path = dirPath+"/"+icon1Name; WritePSPFile(icon1path, data_, param->icon1FileData.bufSize); } // SAVE PIC1 if (param->pic1FileData.buf) { u8* data_ = (u8*)Memory::GetPointer(param->pic1FileData.buf); std::string pic1path = dirPath+"/"+pic1Name; WritePSPFile(pic1path, data_, param->pic1FileData.bufSize); } // Save SND if (param->snd0FileData.buf) { u8* data_ = (u8*)Memory::GetPointer(param->snd0FileData.buf); std::string snd0path = dirPath+"/"+snd0Name; WritePSPFile(snd0path, data_, param->snd0FileData.bufSize); } // Save Encryption Data { EncryptFileInfo encryptInfo; SceSize dataSize = sizeof(encryptInfo); // version + key + sdkVersion memset(&encryptInfo,0,dataSize); encryptInfo.fileVersion = 1; encryptInfo.sdkVersion = sceKernelGetCompiledSdkVersion(); if(param->size > 1500) memcpy(encryptInfo.key,param->key,16); std::string encryptInfoPath = dirPath+"/"+"ENCRYPT_INFO.BIN"; WritePSPFile(encryptInfoPath, (u8*)&encryptInfo, dataSize); } return true; }
CTextDimsKey::CTextDimsKey(const CStringW& str, const STSStyle& style) : m_str(str) , m_style(DEBUG_NEW STSStyle(style)) { UpdateHash(); }
COverlayKey::COverlayKey(const CWord* word, CPoint p, CPoint org) : COutlineKey(word, CPoint(org.x - p.x, org.y - p.y)) , m_subp(p.x & 7, p.y & 7) { UpdateHash(); }
/* Aggiorna la scacchiera e le altre strutture dati eseguendo la mossa La verifica di legalita' viene effettuata quando: -la mossa è una mossa di re -il re è sotto scacco -il re è sotto attacco x-ray */ int makemove(const MOVE m, const unsigned char s) { unsigned char from=0; /*da dove parte il pezzo*/ unsigned char to=0; /*dove copiare il pezzo*/ char was=0; /*cosa era il pezzo?*/ char wh=0; unsigned char del=0; /*dove cancellare*/ assert(Name(WHITE,0)==king); assert(Name(BLACK,0)==king); if (Piece(m.ms.to)==king) return 0; /*copia la chiave hash per l'unmake()*/ BHash(N_moves) = Hash; /*copia la castle_exe per l'unmake()*/ BCste(N_moves) = Cste; /*copia la bitboard per l'unmake()*/ BBitb(N_moves, Side) = Bitboard(Side); /*Controlla che l'arrocco sia legale e sposta la torre */ if (m.ms.flag & (M_OO | M_OOO)) { if (tree.check[Side][Ply]) return 0; switch (m.ms.to) { case C8: if (attacked(C8, WHITE) || attacked(D8, WHITE)) return 0; from = A8; to = D8; Cste |= cas_booo; break; case G8: if (attacked(F8, WHITE) || attacked(G8, WHITE)) return 0; from = H8; to = F8; Cste |= cas_boo; break; case C1: if (attacked(C1, BLACK) || attacked(D1, BLACK)) return 0; from = A1; to = D1; Cste |= cas_wooo; break; case G1: if (attacked(F1, BLACK) || attacked(G1, BLACK)) return 0; from = H1; to = F1; Cste |= cas_woo; break; default: puts("Bad castle request."); assert(0); } /*sposta torre aggiornando la chiave hash*/ UpdateHash(from); Piece(to) = Piece(from); Color(to) = Color(from); Plist(to) = Plist(from); Position((Color(to)), (Plist(to))) = to; Piece(from) = no_piece; Color(from) = EMPTY; Plist(from) = no_list; UpdateHash(to); SetBB(Side, to); DelBB(Side, from); } /*sposta il pezzo*/ from = m.ms.from; to = m.ms.to; was = Piece(from); wh = Plist(from); assert(was>=0); assert(was<=king); assert(Name(Side,0)==king); assert(Name(Xside,0)==king); if (wh>0){ assert(Name(Side,wh)!=king); } /*Se la mossa e' una cattura cancella il pezzo dalla casella di arrivo*/ if (m.ms.flag & M_CAP) { del = to; /*se è una cattura en passant aggiustiamo casella*/ if (m.ms.flag & M_ENP) { if (Side) del += DOWN; else del += UP; } BCapP(N_moves) = Piece(del); BCapPos(N_moves) = Plist(del); BCapC(N_moves) = Xside; BBitb(N_moves, Xside) = Bitboard(Xside); Active(Xside, (Plist(del))) = CAPTURED; Piece(del) = no_piece; Color(del) = EMPTY; Plist(del) = no_list; DelBB(Xside, del); } Piece(to) = Piece(from); if (m.ms.piece!=was)Piece(to)=m.ms.piece; Color(to) = Side; Plist(to) = wh; Position((Side), (wh)) = to; Piece(from) = no_piece; Color(from) = EMPTY; Plist(from) = no_list; SetBB(Side, to); DelBB(Side, from); /*effettuato il minimo indispensabile verifica, se opportuno, la legalità della mossa*/ assert(Name(Side,0)==king); assert(Name(Xside,0)==king); if (wh>0){ assert(Name(Side,wh)!=king); } if ( tree.verify[Ply] || tree.check[Side][Ply] || (m.ms.flag & M_KNG) ||(m.ms.flag & M_ENP)) { if (in_check(Side)) { /*unmake() locale*/ Piece(from) = Piece(to); if (Piece(from)!=was)Piece(from)=was; Color(from) = Side; Plist(from) = wh; Position((Side), (wh)) = from; Piece(to) = no_piece; Color(to) = EMPTY; Plist(to) = no_list; Bitboard(Side) = BBitb(N_moves, Side); if (m.ms.flag & M_CAP) { Piece(del) = BCapP(N_moves); Color(del) = BCapC(N_moves); Plist(del) = BCapPos(N_moves); Active((Xside), (Plist(del))) = FREE; Position((Xside), (Plist(del))) = del; Bitboard(Xside) = BBitb(N_moves, Xside); assert(Name(Side,0)==king); assert(Name(Xside,0)==king); if (Plist(del)>0){ assert(Name(Xside,Plist(del))!=king); } } assert(Name(Side,0)==king); assert(Name(Xside,0)==king); if (wh>0){ assert(Name(Side,wh)!=king); } return 0; } } /*Selectivity*/ if (s && ((!in_check(Xside)) || ((m.ms.flag& M_CAP)==0))) { /*unmake() locale*/ Piece(from) = Piece(to); if (Piece(from)!=was)Piece(from)=was; Color(from) = Side; Plist(from) = wh; Position((Side), (wh)) = from; Piece(to) = no_piece; Color(to) = EMPTY; Plist(to) = no_list; Bitboard(Side) = BBitb(N_moves, Side); if (m.ms.flag & M_CAP) { Piece(del) = BCapP(N_moves); Color(del) = BCapC(N_moves); Plist(del) = BCapPos(N_moves); Active((Xside), (Plist(del))) = FREE; Position((Xside), (Plist(del))) = del; Bitboard(Xside) = BBitb(N_moves, Xside); assert(Name(Side,0)==king); assert(Name(Xside,0)==king); if (Plist(del)>0){ assert(Name(Xside,Plist(del))!=king); } } assert(Name(Side,0)==king); assert(Name(Xside,0)==king); if (wh>0){ assert(Name(Side,wh)!=king); } return 0; } /*back up per l'unmakemove() i dati per la cattura e la hash della posizione sono gia' memorizzati*/ tree.history[N_moves].m.mi = m.mi; tree.history[N_moves].cast.castle_right = Cstr; tree.history[N_moves].enp = Enp; tree.history[N_moves].fifty = tree.fifty; tree.history[N_moves].was = was; tree.history[N_moves].material[Side] = Material(Side); tree.history[N_moves].material[Xside] = Material(Xside); BPBitb(N_moves, Side) = Pbitboard(Side); BPBitb(N_moves, Xside) = Pbitboard(Xside); /*aggiorna diritti arrocco*/ UpdateHashCastle(Cstr); Cstr &= castle_mask[b256to64[from]] & castle_mask[b256to64[to]]; UpdateHashCastle(Cstr); Hash ^= zobrist_enp[b256to64[Enp]]; Enp = 0; tree.fifty++; /*se irreversibile...*/ if (m.ms.flag&(M_PAW | M_CAP)) { tree.fifty = 0; if (m.ms.flag&M_DBP) { if (Side) Enp = to + DOWN; else Enp = to + UP; } if (m.ms.flag&M_PAW) { DelPBB(Side, from); if ((m.ms.flag&M_PRO) == 0) SetPBB(Side, to); } if (m.ms.flag&M_CAP) { tree.history[N_moves].del = del; Hash ^= zobrist[Xside][BCapP(N_moves)][b256to64[del]]; Material(Xside) -= piece_value[BCapP(N_moves)]; Num_piece(Xside, BCapP(N_moves))--; Pbitboard(Xside) &= (~(bit_square[del])); } Material(Side) -= piece_value[was]; Material(Side) += piece_value[m.ms.piece]; Num_piece(Side, was)--; Num_piece(Side, m.ms.piece)++; } Hash ^= zobrist_enp[b256to64[Enp]]; Hash ^= zobrist[Side][was][b256to64[from]]; Hash ^= zobrist[Side][m.ms.piece][b256to64[to]]; Hash ^= zobrist_side; Ply++; N_moves++; Change(Side); Change(Xside); assert(Name(WHITE,0)==king); assert(Name(BLACK,0)==king); return 1; }