void PropertiesWindow::saveAttributesPanel() { edit_item->clearAllAttributes(); for(int32_t rowIndex = 0; rowIndex < attributesGrid->GetNumberRows(); ++rowIndex) { ItemAttribute attr; wxString type = attributesGrid->GetCellValue(rowIndex, 1); if(type == "String") { attr.set(nstr(attributesGrid->GetCellValue(rowIndex, 2))); } else if(type == "Float") { double value; if(attributesGrid->GetCellValue(rowIndex, 2).ToDouble(&value)) { attr.set(value); } } else if(type == "Number") { long value; if(attributesGrid->GetCellValue(rowIndex, 2).ToLong(&value)) { attr.set(static_cast<int32_t>(value)); } } else if(type == "Boolean") { attr.set(attributesGrid->GetCellValue(rowIndex, 2) == "1"); } else { continue; } edit_item->setAttribute(nstr(attributesGrid->GetCellValue(rowIndex, 0)), attr); } }
void LiveServer::BroadcastChat(wxString speaker, wxString message) { for(PeerList::iterator citer = connected_clients.begin(); citer != connected_clients.end(); ++citer) { NetworkMessage* nmsg = AllocMessage(); nmsg->AddByte(PACKET_SERVER_TALK); nmsg->AddString(nstr(speaker)); nmsg->AddString(nstr(message)); (*citer)->Send(nmsg); } log->Chat(name, message); }
static config_t* new_config(TSFile fh) { char buffer[STR_BUFFER_SIZE]; config_t* config = NULL; config = (config_t*)TSmalloc(sizeof(config_t)); config->stats_path = 0; config->stats_path_len = 0; config->allowIps = 0; config->ipCount = 0; config->allowIps6 = 0; config->ip6Count = 0; config->recordTypes = DEFAULT_RECORD_TYPES; // TSmalloc(6); if(!fh) { config->stats_path = nstr("_astats"); config->stats_path_len = strlen(config->stats_path); TSDebug(PLUGIN_TAG, "No config, using defaults"); return config; } while (TSfgets(fh, buffer, STR_BUFFER_SIZE - 1)) { if (*buffer == '#') { continue; /* # Comments, only at line beginning */ } char* p = 0; if((p = strstr(buffer, "path="))) { p+=strlen("path="); config->stats_path = nstr(strtok_r(p, " \n", &p)); config->stats_path_len = strlen(config->stats_path); } else if((p = strstr(buffer, "record_types="))) { p+=strlen("record_types="); config->recordTypes = strtol(strtok_r(p, " \n", &p), NULL, 16); } else if((p = strstr(buffer, "allow_ip="))) { p+=strlen("allow_ip="); parseIps(config, p); } else if((p = strstr(buffer, "allow_ip6="))) { p+=strlen("allow_ip6="); parseIps6(config, p); } } if(!config->ipCount) { parseIps(config, NULL); } if(config->ip6Count) { parseIps6(config, NULL); } TSDebug(PLUGIN_TAG, "config path=%s", config->stats_path); return config; }
//config file processing int rpc::read_config(std::string sparams) { sconfig=sparams; std::replace( sparams.begin(), sparams.end(),';', '\n' ); std::istrstream fconfig(sparams.c_str()); //assure(fconfig,fname_config.c_str()); char buf[200]; while (fconfig.getline(buf,200)) { std::string nstr(buf); if ((nstr.size()>0) and (nstr.at(0)!='/')) { int ind1=nstr.find('='); int ind2=nstr.length()-1; std::string pname=nstr.substr(0,ind1); std::string pvalue=nstr.substr(ind1+1,ind2-ind1-2); std::string ptype=nstr.substr(ind2); if (ptype.length()>0){ switch (ptype.at(0)){ case 'd':case 'f': set_param(pname,atof(pvalue.c_str())); break; case 'c': set_param(pname,pvalue.at(0)); break; case 'i': set_param(pname,atoi(pvalue.c_str())); break; case 's': set_param(pname,pvalue); break; };}; }; }; return 0; }
void Application::FixVersionDiscrapencies() { // Here the registry should be fixed, if the version has been changed if(settings.getInteger(Config::VERSION_ID) < MAKE_VERSION_ID(1, 0, 5)) { settings.setInteger(Config::USE_MEMCACHED_SPRITES_TO_SAVE, 0); } if(settings.getInteger(Config::VERSION_ID) < __RME_VERSION_ID__ && ClientVersion::getLatestVersion() != nullptr) { settings.setInteger(Config::DEFAULT_CLIENT_VERSION, ClientVersion::getLatestVersion()->getID()); } wxString ss = wxstr(settings.getString(Config::SCREENSHOT_DIRECTORY)); if(ss.empty()) { ss = wxStandardPaths::Get().GetDocumentsDir(); #ifdef __WINDOWS__ ss += wxT("/My Pictures/RME/"); #endif } settings.setString(Config::SCREENSHOT_DIRECTORY, nstr(ss)); // Set registry to newest version settings.setInteger(Config::VERSION_ID, __RME_VERSION_ID__); }
void gdb_set_show_print_expand_aggregates(void) { complex_type complx = { 3, { 3L }, &complx }; complex_type complx_array[2] = { { 4, { 4L }, &complx_array[1] }, { 5, { 5 }, &complx_array[0] } }; not_str nstr('a', 0); // BP_gdb_set_show_print_expand_aggregates }
static config_holder_t* new_config_holder(const char* path) { char default_config_file[1024]; config_holder_t* config_holder = TSmalloc(sizeof(config_holder_t)); config_holder->config_path = 0; config_holder->config = 0; config_holder->last_load = 0; // TSmalloc(32); // if(path) { config_holder->config_path = nstr(path); } else { /* Default config file of plugins/cacheurl.config */ // sprintf(default_config_file, "%s/astats.config", TSPluginDirGet()); sprintf(default_config_file, "%s/"DEFAULT_CONFIG_NAME, TSConfigDirGet()); config_holder->config_path = nstr(default_config_file); } load_config_file(config_holder); return config_holder; }
void LiveServer::StartOperation(wxString msg) { for(PeerList::iterator citer = connected_clients.begin(); citer != connected_clients.end(); ++citer) { NetworkMessage* nmsg = AllocMessage(); nmsg->AddByte(PACKET_START_OPERATION); nmsg->AddString(nstr(msg)); (*citer)->Send(nmsg); } }
void GUI::SavePerspective() { g_settings.setInteger(Config::WINDOW_MAXIMIZED, root->IsMaximized()); g_settings.setInteger(Config::WINDOW_WIDTH, root->GetSize().GetWidth()); g_settings.setInteger(Config::WINDOW_HEIGHT, root->GetSize().GetHeight()); g_settings.setInteger(Config::MINIMAP_VISIBLE, minimap? 1: 0); wxString pinfo; for(PaletteList::iterator piter = palettes.begin(); piter != palettes.end(); ++piter) { if(aui_manager->GetPane(*piter).IsShown()) pinfo << aui_manager->SavePaneInfo(aui_manager->GetPane(*piter)) << wxT("|"); } g_settings.setString(Config::PALETTE_LAYOUT, nstr(pinfo)); if(minimap) { wxString s = aui_manager->SavePaneInfo(aui_manager->GetPane(minimap)); g_settings.setString(Config::MINIMAP_LAYOUT, nstr(s)); } }
bool match(const char* text, nvec& vmatch) const{ cmatch m; if(regex_match(text, m, *regex_)){ for(size_t i = 0; i < m.size(); ++i){ vmatch.push_back(nstr(m[i].first, m[i].second)); } return true; } return false; }
bool IOMapOTMM::loadMap(Map& map, const FileName& identifier, bool showdialog) { if(showdialog) gui.CreateLoadBar(wxT("Loading OTMM map...")); DiskNodeFileReadHandle f(nstr(identifier.GetFullPath())); if(f.isOk() == false) { error(wxT("Couldn't open file for reading\nThe error reported was: ") + wxstr(f.getErrorMessage())); return false; } bool ret = loadMap(map, f, identifier, showdialog); if(showdialog) gui.DestroyLoadBar(); return ret; }
void ClientVersion::saveVersions() { json::Array vers_obj; for(VersionMap::iterator i = client_versions.begin(); i != client_versions.end(); ++i) { ClientVersion* version = i->second; json::Object ver_obj; ver_obj.push_back(json::Pair("id", version->getName())); ver_obj.push_back(json::Pair("path", nstr(version->getClientPath().GetFullPath()))); vers_obj.push_back(ver_obj); } std::ostringstream out; json::write(vers_obj, out); g_settings.setString(Config::TIBIA_DATA_DIRS, out.str()); }
static int showdrec(int fd, int fmt, void *x) { Drec *d = (Drec *)x; int namelen; int syslen; if(d->reclen == 0) return 0; fprint(fd, "%d %d %ld %ld ", d->reclen, d->attrlen, l32(d->addr), l32(d->size)); fprint(fd, "%s 0x%2.2x %d %d %ld ", rdate(d->date, fmt), (fmt=='z' ? d->flags : d->r_flags), d->unitsize, d->gapsize, l16(d->vseqno)); fprint(fd, "%d %s", d->namelen, nstr(d->name, d->namelen)); if(fmt != 'J'){ namelen = d->namelen + (1-(d->namelen&1)); syslen = d->reclen - 33 - namelen; if(syslen != 0) fprint(fd, " %s", nstr(&d->name[namelen], syslen)); } fprint(fd, "\n"); return d->reclen + (d->reclen&1); }
void EditHouseDialog::OnClickOK(wxCommandEvent& WXUNUSED(event)) { if(Validate() && TransferDataFromWindow()) { // Verify the newd information long new_house_rent; house_rent.ToLong(&new_house_rent); if(new_house_rent < 0) { gui.PopupDialog(this, wxT("Error"), wxT("House rent cannot be less than 0."), wxOK); return; } if(house_name.length() == 0) { gui.PopupDialog(this, wxT("Error"), wxT("House name cannot be nil."), wxOK); return; } if(settings.getInteger(Config::WARN_FOR_DUPLICATE_ID)) { Houses& houses = map->houses; for(HouseMap::const_iterator house_iter = houses.begin(); house_iter != houses.end(); ++house_iter) { House* house = house_iter->second; ASSERT(house); if(wxstr(house->name) == house_name && house->id != what_house->id) { int ret = gui.PopupDialog(this, wxT("Warning"), wxT("This house name is already in use, are you sure you want to continue?"), wxYES | wxNO); if(ret == wxID_NO) { return; } } } } // Transfer to house what_house->name = nstr(house_name); what_house->rent = new_house_rent; what_house->guildhall = guildhall_field->GetValue(); EndModal(1); } }
//config file processing int rpc::load_config() { std::ifstream fconfig(fname_config.c_str()); //assure(fconfig,fname_config.c_str()); char buf[200]; while (fconfig.getline(buf,200)) { std::string nstr(buf); if ((nstr.size()>0) and (nstr.at(0)!='/')) { int ind1=nstr.find('='); int ind2=nstr.rfind(' '); std::string pname=nstr.substr(0,ind1); std::string pvalue=nstr.substr(ind1+1,ind2-ind1-1); std::string ptype=nstr.substr(ind2+1); parameter new_param; new_param.pname=pname; switch (ptype.at(0)){ case 'd':case 'f': new_param.ptype=1; new_param.dvalue=atof(pvalue.c_str()); break; case 'c': new_param.ptype=2; new_param.cvalue=pvalue.at(0); break; case 'i': new_param.ptype=3; new_param.ivalue=atoi(pvalue.c_str()); break; case 's': new_param.ptype=5; new_param.strvalue=pvalue; break; }; vparams.push_back(new_param); }; }; if (sconfig.length()>0) read_config(sconfig); return 0; }
void PropertiesWindow::OnGridValueChanged(wxGridEvent& event) { if(event.GetCol() == 1) { wxString newType = attributesGrid->GetCellValue(event.GetRow(), 1); if(newType == event.GetString()) { return; } ItemAttribute attr; if(newType == "String") { attr.set(""); } else if(newType == "Float") { attr.set(0.0f); } else if(newType == "Number") { attr.set(0); } else if(newType == "Boolean") { attr.set(false); } SetGridValue(attributesGrid, event.GetRow(), nstr(attributesGrid->GetCellValue(event.GetRow(), 0)), attr); } }
bool GraphicManager::loadSpriteData(const FileName& datafile, wxString& error, wxArrayString& warnings) { FileReadHandle fh(nstr(datafile.GetFullPath())); if(!fh.isOk()) { error = "Failed to open file for reading"; return false; } #define safe_get(func, ...) do {\ if(!fh.get##func(__VA_ARGS__)) {\ error = wxstr(fh.getErrorMessage()); \ return false; \ } \ } while(false) uint32_t sprSignature; safe_get(U32, sprSignature); uint32_t total_pics = 0; if(is_extended) { safe_get(U32, total_pics); } else { uint16_t u16 = 0; safe_get(U16, u16); total_pics = u16; } if(!g_settings.getInteger(Config::USE_MEMCACHED_SPRITES)) { spritefile = nstr(datafile.GetFullPath()); unloaded = false; return true; } std::vector<uint32_t> sprite_indexes; for(uint32_t i = 0; i < total_pics; ++i) { uint32_t index; safe_get(U32, index); sprite_indexes.push_back(index); } // Now read individual sprites int id = 1; for(std::vector<uint32_t>::iterator sprite_iter = sprite_indexes.begin(); sprite_iter != sprite_indexes.end(); ++sprite_iter, ++id) { uint32_t index = *sprite_iter + 3; fh.seek(index); uint16_t size; safe_get(U16, size); ImageMap::iterator it = image_space.find(id); if(it != image_space.end()) { GameSprite::NormalImage* spr = dynamic_cast<GameSprite::NormalImage*>(it->second); if(spr && size > 0) { if(spr->size > 0) { wxString ss; ss << "items.spr: Duplicate GameSprite id " << id; warnings.push_back(ss); fh.seekRelative(size); } else { spr->id = id; spr->size = size; spr->dump = newd uint8_t[size]; if(!fh.getRAW(spr->dump, size)) { error = wxstr(fh.getErrorMessage()); \ return false; } } } } else { fh.seekRelative(size); } } #undef safe_get unloaded = false; return true; }
bool GraphicManager::loadSpriteMetadata(const FileName& datafile, wxString& error, wxArrayString& warnings) { // items.otb has most of the info we need. This only loads the GameSprite metadata FileReadHandle file(nstr(datafile.GetFullPath())); if(!file.isOk()) { error += "Failed to open " + datafile.GetFullPath() + " for reading\nThe error reported was:" + wxstr(file.getErrorMessage()); return false; } uint16_t effect_count, distance_count; uint32_t datSignature; file.getU32(datSignature); //get max id file.getU16(item_count); file.getU16(creature_count); file.getU16(effect_count); file.getU16(distance_count); uint32_t minclientID = 100; // tibia.dat start with id 100 // We don't load distance/effects, if we would, just add effect_count & distance_count here uint32_t maxclientID = item_count + creature_count; dat_format = client_version->getDatFormatForSignature(datSignature); if(!otfi_found) { is_extended = dat_format >= DAT_FORMAT_96; has_frame_durations = dat_format >= DAT_FORMAT_1050; has_frame_groups = dat_format >= DAT_FORMAT_1057; } uint16_t id = minclientID; // loop through all ItemDatabase until we reach the end of file while(id <= maxclientID) { GameSprite* sType = newd GameSprite(); sprite_space[id] = sType; sType->id = id; // Load the sprite flags if(!loadSpriteMetadataFlags(file, sType, error, warnings)) { wxString msg; msg << "Failed to load flags for sprite " << sType->id; warnings.push_back(msg); } // Reads the group count uint8_t group_count = 1; if(has_frame_groups && id > item_count) { file.getU8(group_count); } for(uint32_t k = 0; k < group_count; ++k) { // Skipping the group type if(has_frame_groups && id > item_count) { file.skip(1); } // Size and GameSprite data file.getByte(sType->width); file.getByte(sType->height); // Skipping the exact size if((sType->width > 1) || (sType->height > 1)){ file.skip(1); } file.getU8(sType->layers); // Number of blendframes (some sprites consist of several merged sprites) file.getU8(sType->pattern_x); file.getU8(sType->pattern_y); if(dat_format <= DAT_FORMAT_74) sType->pattern_z = 1; else file.getU8(sType->pattern_z); file.getU8(sType->frames); // Length of animation if(sType->frames > 1) { uint8_t async = 0; int loop_count = 0; int8_t start_frame = 0; if(has_frame_durations) { file.getByte(async); file.get32(loop_count); file.getSByte(start_frame); } sType->animator = newd Animator(sType->frames, start_frame, loop_count, async == 1); if(has_frame_durations) { for(int i = 0; i < sType->frames; i++) { uint32_t min; uint32_t max; file.getU32(min); file.getU32(max); FrameDuration* frame_duration = sType->animator->getFrameDuration(i); frame_duration->setValues(int(min), int(max)); } sType->animator->reset(); } } sType->numsprites = (int)sType->width * (int)sType->height * (int)sType->layers * (int)sType->pattern_x * (int)sType->pattern_y * sType->pattern_z * (int)sType->frames; // Read the sprite ids for(uint32_t i = 0; i < sType->numsprites; ++i) { uint32_t sprite_id; if(is_extended) { file.getU32(sprite_id); } else { uint16_t u16 = 0; file.getU16(u16); sprite_id = u16; } if(image_space[sprite_id] == nullptr) { GameSprite::NormalImage* img = newd GameSprite::NormalImage(); img->id = sprite_id; image_space[sprite_id] = img; } sType->spriteList.push_back(static_cast<GameSprite::NormalImage*>(image_space[sprite_id])); } } ++id; } return true; }
void PreferencesWindow::Apply() { bool must_restart = false; // General g_settings.setInteger(Config::ALWAYS_MAKE_BACKUP, always_make_backup_chkbox->GetValue()); g_settings.setInteger(Config::CREATE_MAP_ON_STARTUP, create_on_startup_chkbox->GetValue()); g_settings.setInteger(Config::USE_UPDATER, update_check_on_startup_chkbox->GetValue()); g_settings.setInteger(Config::ONLY_ONE_INSTANCE, only_one_instance_chkbox->GetValue()); g_settings.setInteger(Config::UNDO_SIZE, undo_size_spin->GetValue()); g_settings.setInteger(Config::UNDO_MEM_SIZE, undo_mem_size_spin->GetValue()); g_settings.setInteger(Config::WORKER_THREADS, worker_threads_spin->GetValue()); g_settings.setInteger(Config::REPLACE_SIZE, replace_size_spin->GetValue()); g_settings.setInteger(Config::COPY_POSITION_FORMAT, position_format->GetSelection()); // Editor g_settings.setInteger(Config::GROUP_ACTIONS, group_actions_chkbox->GetValue()); g_settings.setInteger(Config::WARN_FOR_DUPLICATE_ID, duplicate_id_warn_chkbox->GetValue()); g_settings.setInteger(Config::HOUSE_BRUSH_REMOVE_ITEMS, house_remove_chkbox->GetValue()); g_settings.setInteger(Config::AUTO_ASSIGN_DOORID, auto_assign_doors_chkbox->GetValue()); g_settings.setInteger(Config::ERASER_LEAVE_UNIQUE, eraser_leave_unique_chkbox->GetValue()); g_settings.setInteger(Config::DOODAD_BRUSH_ERASE_LIKE, doodad_erase_same_chkbox->GetValue()); g_settings.setInteger(Config::AUTO_CREATE_SPAWN, auto_create_spawn_chkbox->GetValue()); g_settings.setInteger(Config::RAW_LIKE_SIMONE, allow_multiple_orderitems_chkbox->GetValue()); g_settings.setInteger(Config::MERGE_MOVE, merge_move_chkbox->GetValue()); g_settings.setInteger(Config::MERGE_PASTE, merge_paste_chkbox->GetValue()); // Graphics g_settings.setInteger(Config::USE_GUI_SELECTION_SHADOW, icon_selection_shadow_chkbox->GetValue()); if(g_settings.getBoolean(Config::USE_MEMCACHED_SPRITES) != use_memcached_chkbox->GetValue()) { must_restart = true; } g_settings.setInteger(Config::USE_MEMCACHED_SPRITES_TO_SAVE, use_memcached_chkbox->GetValue()); if(icon_background_choice->GetSelection() == 0) { if(g_settings.getInteger(Config::ICON_BACKGROUND) != 0) { g_gui.gfx.cleanSoftwareSprites(); } g_settings.setInteger(Config::ICON_BACKGROUND, 0); } else if(icon_background_choice->GetSelection() == 1) { if(g_settings.getInteger(Config::ICON_BACKGROUND) != 88) { g_gui.gfx.cleanSoftwareSprites(); } g_settings.setInteger(Config::ICON_BACKGROUND, 88); } else if(icon_background_choice->GetSelection() == 2) { if(g_settings.getInteger(Config::ICON_BACKGROUND) != 255) { g_gui.gfx.cleanSoftwareSprites(); } g_settings.setInteger(Config::ICON_BACKGROUND, 255); } // Screenshots g_settings.setString(Config::SCREENSHOT_DIRECTORY, nstr(screenshot_directory_picker->GetPath())); std::string new_format = nstr(screenshot_format_choice->GetStringSelection()); if(new_format == "PNG") { g_settings.setString(Config::SCREENSHOT_FORMAT, "png"); } else if(new_format == "TGA") { g_settings.setString(Config::SCREENSHOT_FORMAT, "tga"); } else if(new_format == "JPG") { g_settings.setString(Config::SCREENSHOT_FORMAT, "jpg"); } else if(new_format == "BMP") { g_settings.setString(Config::SCREENSHOT_FORMAT, "bmp"); } wxColor clr = cursor_color_pick->GetColour(); g_settings.setInteger(Config::CURSOR_RED, clr.Red()); g_settings.setInteger(Config::CURSOR_GREEN, clr.Green()); g_settings.setInteger(Config::CURSOR_BLUE, clr.Blue()); //g_settings.setInteger(Config::CURSOR_ALPHA, clr.Alpha()); clr = cursor_alt_color_pick->GetColour(); g_settings.setInteger(Config::CURSOR_ALT_RED, clr.Red()); g_settings.setInteger(Config::CURSOR_ALT_GREEN, clr.Green()); g_settings.setInteger(Config::CURSOR_ALT_BLUE, clr.Blue()); //g_settings.setInteger(Config::CURSOR_ALT_ALPHA, clr.Alpha()); g_settings.setInteger(Config::HIDE_ITEMS_WHEN_ZOOMED, hide_items_when_zoomed_chkbox->GetValue()); /* g_settings.setInteger(Config::TEXTURE_MANAGEMENT, texture_managment_chkbox->GetValue()); g_settings.setInteger(Config::TEXTURE_CLEAN_PULSE, clean_interval_spin->GetValue()); g_settings.setInteger(Config::TEXTURE_LONGEVITY, texture_longevity_spin->GetValue()); g_settings.setInteger(Config::TEXTURE_CLEAN_THRESHOLD, texture_threshold_spin->GetValue()); g_settings.setInteger(Config::SOFTWARE_CLEAN_THRESHOLD, software_threshold_spin->GetValue()); g_settings.setInteger(Config::SOFTWARE_CLEAN_SIZE, software_clean_amount_spin->GetValue()); */ // Interface SetPaletteStyleChoice(terrain_palette_style_choice, Config::PALETTE_TERRAIN_STYLE); SetPaletteStyleChoice(doodad_palette_style_choice, Config::PALETTE_DOODAD_STYLE); SetPaletteStyleChoice(item_palette_style_choice, Config::PALETTE_ITEM_STYLE); SetPaletteStyleChoice(raw_palette_style_choice, Config::PALETTE_RAW_STYLE); g_settings.setInteger(Config::USE_LARGE_TERRAIN_TOOLBAR, large_terrain_tools_chkbox->GetValue()); g_settings.setInteger(Config::USE_LARGE_DOODAD_SIZEBAR, large_doodad_sizebar_chkbox->GetValue()); g_settings.setInteger(Config::USE_LARGE_ITEM_SIZEBAR, large_item_sizebar_chkbox->GetValue()); g_settings.setInteger(Config::USE_LARGE_HOUSE_SIZEBAR, large_house_sizebar_chkbox->GetValue()); g_settings.setInteger(Config::USE_LARGE_RAW_SIZEBAR, large_raw_sizebar_chkbox->GetValue()); g_settings.setInteger(Config::USE_LARGE_CONTAINER_ICONS, large_container_icons_chkbox->GetValue()); g_settings.setInteger(Config::USE_LARGE_CHOOSE_ITEM_ICONS, large_pick_item_icons_chkbox->GetValue()); g_settings.setInteger(Config::SWITCH_MOUSEBUTTONS, switch_mousebtn_chkbox->GetValue()); g_settings.setInteger(Config::DOUBLECLICK_PROPERTIES, doubleclick_properties_chkbox->GetValue()); float scroll_mul = 1.0; if(inversed_scroll_chkbox->GetValue()) { scroll_mul = -1.0; } g_settings.setFloat(Config::SCROLL_SPEED, scroll_mul * scroll_speed_slider->GetValue()/10.f); g_settings.setFloat(Config::ZOOM_SPEED, zoom_speed_slider->GetValue()/10.f); // Client ClientVersionList versions = ClientVersion::getAllVisible(); int version_counter = 0; for(ClientVersionList::iterator version_iter = versions.begin(); version_iter != versions.end(); ++version_iter) { ClientVersion* version = *version_iter; wxString dir = version_dir_pickers[version_counter]->GetPath(); if(dir.Length() > 0 && dir.Last() != '/' && dir.Last() != '\\') dir.Append("/"); version->setClientPath(FileName(dir)); if(version->getName() == default_version_choice->GetStringSelection()) g_settings.setInteger(Config::DEFAULT_CLIENT_VERSION, version->getID()); version_counter++; } g_settings.setInteger(Config::CHECK_SIGNATURES, check_sigs_chkbox->GetValue()); // Make sure to reload client paths ClientVersion::saveVersions(); ClientVersion::loadVersions(); g_settings.save(); if(must_restart) { g_gui.PopupDialog(this, "Notice", "You must restart the editor for the changes to take effect.", wxOK); } g_gui.RebuildPalettes(); }
bool ItemDatabase::loadFromOtb(const FileName& datafile, wxString& error, wxArrayString& warnings) { std::string filename = nstr((datafile.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + datafile.GetFullName())); DiskNodeFileReadHandle f(filename, StringVector(1, "OTBI")); if(!f.isOk()) { error = wxT("Couldn't open file \"") + wxstr(filename) + wxT("\":") + wxstr(f.getErrorMessage()); return false; } BinaryNode* root = f.getRootNode(); #define safe_get(node, func, ...) do {\ if(!node->get##func(__VA_ARGS__)) {\ error = wxstr(f.getErrorMessage()); \ return false; \ } \ } while(false) // Read root flags root->skip(1); // Type info //uint32_t flags = root->skip(4); // Unused? uint8_t attr; safe_get(root, U8, attr); if(attr == ROOT_ATTR_VERSION) { uint16_t datalen; if(!root->getU16(datalen) || datalen != 4 + 4 + 4 + 1*128) { error = wxT("items.otb: Size of version header is invalid, updated .otb version?"); return false; } safe_get(root, U32, MajorVersion); // items otb format file version safe_get(root, U32, MinorVersion); // client version safe_get(root, U32, BuildNumber); // revision std::string csd; csd.resize(128); if(!root->getRAW((uint8_t*)csd.data(), 128)) { // CSDVersion ?? error = wxstr(f.getErrorMessage()); return false; } } else { error = wxT("Expected ROOT_ATTR_VERSION as first node of items.otb!"); } if(settings.getInteger(Config::CHECK_SIGNATURES)) { if(gui.GetCurrentVersion().getOTBVersion().format_version != MajorVersion) { error = wxT("Unsupported items.otb version (version ") + i2ws(MajorVersion) + wxT(")"); return false; } } BinaryNode* itemNode = root->getChild(); switch(MajorVersion) { case 1: return loadFromOtbVer1(itemNode, error, warnings); case 2: return loadFromOtbVer2(itemNode, error, warnings); case 3: return loadFromOtbVer3(itemNode, error, warnings); } return true; }
bool Application::OnInit() { #if defined __DEBUG_MODE__ && defined __WINDOWS__ _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif std::cout << "This is free software: you are free to change and redistribute it." << std::endl; std::cout << "There is NO WARRANTY, to the extent permitted by law." << std::endl; std::cout << "Review COPYING in RME distribution for details." << std::endl; mt_seed(time(nullptr)); srand(time(nullptr)); // Discover data directory gui.discoverDataDirectory("clients.xml"); // Tell that we are the real thing wxAppConsole::SetInstance(this); // Load some internal stuff settings.load(); FixVersionDiscrapencies(); gui.LoadHotkeys(); ClientVersion::loadVersions(); #ifdef _USE_PROCESS_COM proc_server = nullptr; // Setup inter-process communice! if(settings.getInteger(Config::ONLY_ONE_INSTANCE)) { { // Prevents WX from complaining 'bout there being no server. wxLogNull nolog; RMEProcessClient client; wxConnectionBase* n_connection = client.MakeConnection(wxT("localhost"), wxT("rme_host"), wxT("rme_talk")); if(n_connection) { RMEProcessConnection* connection = dynamic_cast<RMEProcessConnection*>(n_connection); ASSERT(connection); std::pair<bool, FileName> ff = ParseCommandLineMap(); if(ff.first) { connection->AskToLoad(ff.second); connection->Disconnect(); #if defined __DEBUG_MODE__ && defined __WINDOWS__ gui.SaveHotkeys(); settings.save(true); #endif return false; } connection->Disconnect(); } } // We act as server then proc_server = newd RMEProcessServer(); if(!proc_server->Create(wxT("rme_host"))) { // Another instance running! delete proc_server; proc_server = nullptr; } } #endif // Image handlers //wxImage::AddHandler(newd wxBMPHandler); wxImage::AddHandler(newd wxPNGHandler); wxImage::AddHandler(newd wxJPEGHandler); wxImage::AddHandler(newd wxTGAHandler); gui.gfx.loadEditorSprites(); #ifndef __DEBUG_MODE__ //wxHandleFatalExceptions(true); #endif // Load all the dependency files std::string error; StringVector warnings; gui.root = newd MainFrame(wxT("Remere's Map Editor"), wxDefaultPosition, wxSize(700,500) ); SetTopWindow(gui.root); gui.SetTitle(wxT("")); gui.root->LoadRecentFiles(); // Load palette gui.LoadPerspective(); // Show all windows gui.root->Show(true); // Set idle event handling mode wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED); // Goto RME website? if(settings.getInteger(Config::GOTO_WEBSITE_ON_BOOT) == 1) { ::wxLaunchDefaultBrowser(wxT("http://www.remeresmapeditor.com/"), wxBROWSER_NEW_WINDOW); settings.setInteger(Config::GOTO_WEBSITE_ON_BOOT, 0); } // Check for updates #ifdef _USE_UPDATER_ if(settings.getInteger(Config::USE_UPDATER) == -1) { int ret = gui.PopupDialog( wxT("Notice"), wxT("Do you want the editor to automatically check for updates?\n") wxT("It will connect to the internet if you choose yes.\n") wxT("You can change this setting in the preferences later."), wxYES | wxNO); if(ret == wxID_YES) { settings.setInteger(Config::USE_UPDATER, 1); } else { settings.setInteger(Config::USE_UPDATER, 0); } } if(settings.getInteger(Config::USE_UPDATER) == 1) { UpdateChecker updater; updater.connect(gui.root); } #endif FileName save_failed_file = gui.GetLocalDataDirectory(); save_failed_file.SetName(wxT(".saving.txt")); if(save_failed_file.FileExists()) { std::ifstream f(nstr(save_failed_file.GetFullPath()).c_str(), std::ios::in); std::string backup_otbm, backup_house, backup_spawn; getline(f, backup_otbm); getline(f, backup_house); getline(f, backup_spawn); // Remove the file f.close(); std::remove(nstr(save_failed_file.GetFullPath()).c_str()); // Query file retrieval if possible if(!backup_otbm.empty()) { int ret = gui.PopupDialog( wxT("Editor Crashed"), wxString( wxT("IMPORTANT! THE EDITOR CRASHED WHILE SAVING!\n\n") wxT("Do you want to recover the lost map? (it will be opened immedietely):\n")) << wxstr(backup_otbm) << wxT("\n") << wxstr(backup_house) << wxT("\n") << wxstr(backup_spawn) << wxT("\n"), wxYES | wxNO); if(ret == wxID_YES) { // Recover if the user so wishes std::remove(backup_otbm.substr(0, backup_otbm.size() - 1).c_str()); std::rename(backup_otbm.c_str(), backup_otbm.substr(0, backup_otbm.size() - 1).c_str()); if(backup_house.size()) { std::remove(backup_house.substr(0, backup_house.size() - 1).c_str()); std::rename(backup_house.c_str(), backup_house.substr(0, backup_house.size() - 1).c_str()); } if(backup_spawn.size()) { std::remove(backup_spawn.substr(0, backup_spawn.size() - 1).c_str()); std::rename(backup_spawn.c_str(), backup_spawn.substr(0, backup_spawn.size() - 1).c_str()); } // Load the map gui.LoadMap(wxstr(backup_otbm.substr(0, backup_otbm.size() - 1))); return true; } } } // Keep track of first event loop entry startup = true; return true; }
bool Map::exportMinimap(FileName filename, int floor /*= 7*/, bool displaydialog) { uint8_t* pic = nullptr; try { int min_x = 0x10000, min_y = 0x10000; int max_x = 0x00000, max_y = 0x00000; if(size() == 0) return true; for(MapIterator mit = begin(); mit != end(); ++mit) { if((*mit)->get() == nullptr || (*mit)->empty()) continue; Position pos = (*mit)->getPosition(); if(pos.x < min_x) min_x = pos.x; if(pos.y < min_y) min_y = pos.y; if(pos.x > max_x) max_x = pos.x; if(pos.y > max_y) max_y = pos.y; } int minimap_width = max_x - min_x+1; int minimap_height = max_y - min_y+1; pic = newd uint8_t[minimap_width*minimap_height]; // 1 byte per pixel memset(pic, 0, minimap_width*minimap_height); int tiles_iterated = 0; for(MapIterator mit = begin(); mit != end(); ++mit) { Tile* tile = (*mit)->get(); ++tiles_iterated; if(tiles_iterated % 8192 == 0 && displaydialog) gui.SetLoadDone(int(tiles_iterated / double(tilecount) * 90.0)); if(tile->empty() || tile->getZ() != floor) continue; //std::cout << "Pixel : " << (tile->getY() - min_y) * width + (tile->getX() - min_x) << std::endl; uint32_t pixelpos = (tile->getY() - min_y) * minimap_width + (tile->getX() - min_x); uint8_t& pixel = pic[pixelpos]; for(ItemVector::const_reverse_iterator item_iter = tile->items.rbegin(); item_iter != tile->items.rend(); ++item_iter) { if((*item_iter)->getMiniMapColor()) { pixel = (*item_iter)->getMiniMapColor(); break; } } if(pixel == 0) // check ground too if(tile->hasGround()) pixel = tile->ground->getMiniMapColor(); } // Create a file for writing FileWriteHandle fh(nstr(filename.GetFullPath())); if(!fh.isOpen()) { delete[] pic; return false; } // Store the magic number fh.addRAW("BM"); // Store the file size // We need to predict how large it will be uint32_t file_size = 14 // header +40 // image data header +256*4 // color palette +((minimap_width + 3) / 4 * 4) * height; // pixels fh.addU32(file_size); // Two values reserved, must always be 0. fh.addU16(0); fh.addU16(0); // Bitmapdata offset fh.addU32(14 + 40 + 256*4); // Header size fh.addU32(40); // Header width/height fh.addU32(minimap_width); fh.addU32(minimap_height); // Color planes fh.addU16(1); // bits per pixel, OT map format is 8 fh.addU16(8); // compression type, 0 is no compression fh.addU32(0); // image size, 0 is valid if we use no compression fh.addU32(0); // horizontal/vertical resolution in pixels / meter fh.addU32(4000); fh.addU32(4000); // Number of colors fh.addU32(256); // Important colors, 0 is all fh.addU32(0); // Write the color palette for(int i = 0; i < 256; ++i) fh.addU32(uint32_t(minimap_color[i])); // Bitmap width must be divisible by four, calculate how much padding we need int padding = ((minimap_width & 3) != 0? 4-(minimap_width & 3) : 0); // Bitmap rows are saved in reverse order for(int y = minimap_height-1; y >= 0; --y) { fh.addRAW(pic + y*minimap_width, minimap_width); for(int i = 0; i < padding; ++i) { fh.addU8(0); } if(y % 100 == 0 && displaydialog) { gui.SetLoadDone(90 + int((minimap_height-y) / double(minimap_height) * 10.0)); } } delete[] pic; //fclose(file); fh.close(); } catch(...) { delete[] pic; } return true; }
CreatureType* CreatureType::loadFromOTXML(const FileName& filename, pugi::xml_document& doc, wxArrayString& warnings) { ASSERT(doc != nullptr); bool isNpc; pugi::xml_node node; if ((node = doc.child("monster"))) { isNpc = false; } else if ((node = doc.child("npc"))) { isNpc = true; } else { warnings.push_back(wxT("This file is not a monster/npc file")); return nullptr; } pugi::xml_attribute attribute; if (!(attribute = node.attribute("name"))) { warnings.push_back(wxT("Couldn't read name tag of creature node.")); return nullptr; } CreatureType* ct = newd CreatureType(); if (isNpc) { ct->name = nstr(filename.GetName()); } else { ct->name = attribute.as_string(); } ct->isNpc = isNpc; for (pugi::xml_node optionNode = node.first_child(); optionNode; optionNode = optionNode.next_sibling()) { if (as_lower_str(optionNode.name()) != "look") { continue; } if ((attribute = optionNode.attribute("type"))) { ct->outfit.lookType = pugi::cast<int32_t>(attribute.value()); } if ((attribute = optionNode.attribute("item")) || (attribute = optionNode.attribute("lookex")) || (attribute = optionNode.attribute("typeex"))) { ct->outfit.lookItem = pugi::cast<int32_t>(attribute.value()); } if ((attribute = optionNode.attribute("addon"))) { ct->outfit.lookAddon = pugi::cast<int32_t>(attribute.value()); } if ((attribute = optionNode.attribute("head"))) { ct->outfit.lookHead = pugi::cast<int32_t>(attribute.value()); } if ((attribute = optionNode.attribute("body"))) { ct->outfit.lookBody = pugi::cast<int32_t>(attribute.value()); } if ((attribute = optionNode.attribute("legs"))) { ct->outfit.lookLegs = pugi::cast<int32_t>(attribute.value()); } if ((attribute = optionNode.attribute("feet"))) { ct->outfit.lookFeet = pugi::cast<int32_t>(attribute.value()); } } return ct; }