bool block_transactions::from_data(uint32_t version, reader& source) { reset(); block_hash_ = source.read_hash(); const auto count = source.read_size_little_endian(); // Guard against potential for arbitrary memory allocation. if (count > max_block_size) source.invalidate(); else transactions_.resize(count); // Order is required. for (auto& tx: transactions_) if (!tx.from_data(source, true)) break; if (version < block_transactions::version_minimum) source.invalidate(); if (!source) reset(); return source; }
bool point::from_data(reader& source, bool wire) { reset(); valid_ = true; hash_ = source.read_hash(); if (wire) { index_ = source.read_4_bytes_little_endian(); } else { index_ = source.read_2_bytes_little_endian(); // Convert 16 bit sentinel to 32 bit sentinel. if (index_ == max_uint16) index_ = null_index; } if (!source) reset(); return source; }
bool alert::from_data(reader& source) { reset(); auto size = source.read_variable_uint_little_endian(); BITCOIN_ASSERT(size <= bc::max_size_t); const auto payload_size = static_cast<size_t>(size); size_t signature_size = 0; auto result = static_cast<bool>(source); if (result) { payload = source.read_data(payload_size); result = source && (payload.size() == payload_size); } if (result) { size = source.read_variable_uint_little_endian(); BITCOIN_ASSERT(size <= bc::max_size_t); signature_size = static_cast<size_t>(size); result = source; } if (result) { signature = source.read_data(signature_size); result = source && (signature.size() == signature_size); } if (!result) reset(); return result; }
void handle_sent_chat_message(vector<char> packet, reader r){ Bot* my_bot = Bot::instance(); string message; r.read(U); r.read(message); // create stream with message stringstream stream; stream.str(message); // process string command; stream >> command; if (command == "/start"){ my_bot->state = E_STATE_NOENEMY; // store star coords to save starting coords my_bot->start_X = my_bot->X; my_bot->start_Y = my_bot->Y; //GET FIRST PARAMETER //int whatever; //stream >> whatever; //cout << "Started with parameter " << whatever << endl; } else if (command == "/stop"){ my_bot->state = E_STATE_STOPPED; } else if (command == "/monsters"){ cout << "MONSTERS:" << endl; for each(auto mob in my_bot->monsters){ cout << "Mob ID:" << mob.second.ID << ", coords: [" << mob.second.X << ", " << mob.second.Y << "]" << endl; } }
static void handle_rgb(reader& io) { bool src_rgb = io.get_color_type() & (color_mask_rgb | color_mask_palette); bool dst_rgb = traits::get_color_type() & color_mask_rgb; if (src_rgb && !dst_rgb) { #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED io.set_rgb_to_gray(/*rgb_to_gray_error*/); #else throw error("grayscale data expected;" " recompile with" " PNG_READ_RGB_TO_GRAY_SUPPORTED"); #endif } if (!src_rgb && dst_rgb) { #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED io.set_gray_to_rgb(); #else throw error("expected RGB data;" " recompile with" " PNG_READ_GRAY_TO_RGB_SUPPORTED"); #endif } }
bool merkle_block::from_data(reader& source) { reset(); bool result = header.from_data(source, true); uint64_t hash_count = 0; if (result) { hash_count = source.read_variable_uint_little_endian(); result = source; } for (uint64_t i = 0; (i < hash_count) && result; ++i) { hashes.push_back(source.read_hash()); result = source; } if (result) { auto size = source.read_variable_uint_little_endian(); BITCOIN_ASSERT(size <= bc::max_size_t); const auto flag_count = static_cast<size_t>(size); flags = source.read_data(flag_count); result = source && (flags.size() == flag_count); } if (!result) reset(); return result; }
int match(vector<DMatch> &match, frame &f1, frame &f2) { vector<DMatch> matches; FlannBasedMatcher matcher; matcher.match(f1.desp, f2.desp, matches); static reader pd("../config/config.ini"); double min_distance = 9999; double match_threshold = atof(pd.get("match_threshold").c_str()); for (int i = 0; i < matches.size(); ++i) { if (matches[i].distance < min_distance) { min_distance = matches[i].distance; } } for (int i = 0; i < matches.size(); ++i) { if (matches[i].distance < (min_distance * match_threshold)) { match.push_back(matches[i]); } } return match.size(); }
bool operation::from_data(reader& source) { reset(); const auto byte = source.read_byte(); auto result = static_cast<bool>(source); auto op_code = static_cast<opcode>(byte); if (byte == 0 && op_code != opcode::zero) return false; code = ((0 < byte && byte <= 75) ? opcode::special : op_code); if (operation::must_read_data(code)) { uint32_t size; read_opcode_data_size(size, code, byte, source); data = source.read_data(size); result = (source && (data.size() == size)); } if (!result) reset(); return result; }
void handle_rest_packet(vector<char> packet, reader r){ byte param; r.read(U); r.read(param); cout << "Rest packet sent with param: " << dec << (int)param << endl; }
void handle_load_player(vector<char> packet, reader r){ DWORD player_ID, p1, p2; r.read(U); r.read(player_ID); r.read(p1); r.read(p2); //cout << "Selected player ID = " << player_ID << endl; }
void handle_use_item_packet(vector<char> packet, reader r){ DWORD param; r.read(U); r.read(param); cout << "used item ID: " << hex << (int)param << endl; }
void handle_skill_attack(vector<char> packet, reader r){ DWORD monster_ID; byte skill_ID, p1; r.read(U); r.read(skill_ID); r.read(p1); r.read(monster_ID); cout << dec << "sent: Attack with Skill: skill_id=" << (int)skill_ID << ", p1 = " << (int)p1 << ", monster_id = " << (int)monster_ID << "time: " << GetTickCount() << endl; }
void handle_attack(vector<char> packet, reader r){ DWORD monster_ID, p2; byte p1; r.read(U); r.read(p1); r.read(monster_ID); r.read(p2); cout << dec << "sent: Attack, p1=" << (int)p1 << ", monster_id=" << (int)monster_ID << ", p3=" << (int)p2 << "time: " << GetTickCount() << endl; }
void handle_preskill(vector<char> packet, reader r){ DWORD monster_id; byte skill_id; r.read(U); r.read(skill_id); r.read(monster_id); cout << dec << "sent: Preskill with skill_id = " << (int)skill_id << ", monster_id = " << (int)monster_id << "time: " << GetTickCount() << endl; }
void operator()(reader& io) const { handle_16(io); handle_alpha(io, alpha_traits::get_alpha_filler()); handle_palette(io); handle_rgb(io); handle_gray(io); io.set_color_type(traits::get_color_type()); io.set_bit_depth(traits::get_bit_depth()); }
bool heading::from_data(reader& source) { reset(); magic = source.read_4_bytes_little_endian(); command = source.read_fixed_string(command_size); payload_size = source.read_4_bytes_little_endian(); checksum = source.read_4_bytes_little_endian(); if (!source) reset(); return source; }
void assembler::error(const char * format, ...) { if (error_on_line) return; fprintf(stderr, "line %d: %s\n", rdr.getlinenumber(), rdr.getwholeline().c_str()); va_list args; va_start(args, format); fprintf(stderr, "**** bad! "); vfprintf(stderr, format, args); fprintf(stderr, "\n"); va_end(args); error_on_line=true; error_count+=1; }
bool point::from_data(reader& source) { auto result = true; reset(); hash = source.read_hash(); index = source.read_4_bytes_little_endian(); result = source; if (!result) reset(); return result; }
void handle_move_end_packet(vector<char> packet, reader r){ Bot* my_bot = Bot::instance(); signed char dX, dY, dZ; r.read(U); r.read(dX); r.read(dY); r.read(dZ); my_bot->X += dX; my_bot->Y += dY; my_bot->Z += dZ; cout << "sent move end packet" << endl; }
bool alert::from_data(uint32_t , reader& source) { reset(); payload_ = source.read_bytes(source.read_size_little_endian()); signature_ = source.read_bytes(source.read_size_little_endian()); if (!source) reset(); return source; }
bool stealth_record::from_data(reader& source, bool wire) { if (!wire) return from_data(source, 0, {}); reset(); unsigned_ephemeral_ = source.read_hash(); public_key_hash_ = source.read_short_hash(); transaction_hash_ = source.read_hash(); if (!source) reset(); return source; }
bool header::from_data(uint32_t version, reader& source) { if (!chain::header::from_data(source)) return false; // The header message must trail a zero byte (yes, it's stoopid). // bitcoin.org/en/developer-reference#headers if (version != version::level::canonical && source.read_byte() != 0x00) source.invalidate(); if (!source) reset(); return source; }
void assembler::start_pass(int n) { pass=n; if (pass>1) rdr.rewind(); location=0; if (output_type==0) output_type='O'; }
static void handle_gray(reader& io) { if ((io.get_color_type() & ~color_mask_alpha) == color_type_gray) { if (io.get_bit_depth() < 8 && traits::get_bit_depth() >= 8) { #ifdef PNG_READ_EXPAND_SUPPORTED io.set_gray_1_2_4_to_8(); #else throw error("convert_color_space: expected 8-bit data;" " recompile with" " PNG_READ_EXPAND_SUPPORTED"); #endif } } }
static void handle_palette(reader& io) { if (io.get_color_type() == color_type_palette) { #ifdef PNG_READ_EXPAND_SUPPORTED io.set_palette_to_rgb(); if (traits::get_color_type() != color_type_palette) { io.get_info().drop_palette(); } #else throw error("indexed colors unexpected;" " recompile with PNG_READ_EXPAND_SUPPORTED"); #endif } }
// Avoid point reuse due to affect on store tx serialization. bool payment_record::from_data(reader& source, bool wire) { valid_ = true; output_ = (source.read_byte() == 1); if (wire) { height_ = source.read_4_bytes_little_endian(); link_ = unlinked; hash_ = source.read_hash(); index_ = source.read_4_bytes_little_endian(); } else { height_ = 0; link_ = source.read_8_bytes_little_endian(); hash_ = null_hash; index_ = source.read_2_bytes_little_endian(); // Convert 16 bit sentinel to 32 bit sentinel. if (index_ == max_uint16) index_ = point::null_index; } data_ = source.read_8_bytes_little_endian(); if (!source) reset(); return source; }
bool version::from_data(reader& source) { reset(); value = source.read_4_bytes_little_endian(); services = source.read_8_bytes_little_endian(); timestamp = source.read_8_bytes_little_endian(); auto result = static_cast<bool>(source); if (result) result = address_me.from_data(source, false); if (result && (value >= 106)) { result = address_you.from_data(source, false); nonce = source.read_8_bytes_little_endian(); user_agent = source.read_string(); if (value >= 209) start_height = source.read_4_bytes_little_endian(); // The satoshi client treats 209 as the "initial protocol version" // and disconnects peers below 31800 (for getheaders support). if (value >= 70001) relay = (source.read_byte() != 0); result &= source; } if (!result) reset(); return result; }
// Optimize reads by short-circuiting what is unnecessary. // Invalid returns are conflated with skipped, but are store only. bool stealth_record::from_data(reader& source, size_t start_height, const binary& filter) { height_ = source.read_4_bytes_little_endian(); if (height_ < start_height) { reset(); source.skip(serialized_size(false) - sizeof(uint32_t)); return false; } prefix_ = source.read_4_bytes_little_endian(); if (!filter.is_prefix_of(prefix_)) { reset(); source.skip(serialized_size(false) - 2 * sizeof(uint32_t)); return false; } unsigned_ephemeral_ = source.read_hash(); public_key_hash_ = source.read_short_hash(); transaction_hash_ = source.read_hash(); if (!source) reset(); return source; }
bool transaction::from_data(reader& source) { auto result = true; reset(); version = source.read_4_bytes_little_endian(); result = source; if (result) { uint64_t tx_in_count = source.read_variable_uint_little_endian(); result = source; for (uint64_t i = 0; (i < tx_in_count) && result; ++i) { inputs.emplace_back(); result = inputs.back().from_data(source); } } if (result) { auto tx_out_count = source.read_variable_uint_little_endian(); result = source; for (uint64_t i = 0; (i < tx_out_count) && result; ++i) { outputs.emplace_back(); result = outputs.back().from_data(source); } } if (result) { locktime = source.read_4_bytes_little_endian(); result = source; } if (!result) reset(); return result; }
bool nonce_::from_data(reader& source) { reset(); nonce = source.read_8_bytes_little_endian(); if (!source) reset(); return source; }