//initializes video graphics mode void *vg_init(unsigned short mode) { /* Allow memory mapping */ vbe_mode_info_t info; if(vbe_get_mode_info(mode, &info)) return NULL; unsigned long vram_base ;/*= VRAM_PHYS_ADDR;*/ unsigned long vram_size; h_res = info.XResolution; v_res = info.YResolution; bits_per_pixel = (unsigned) info.BitsPerPixel; bytes_per_pixel = bits_per_pixel/8; vram_phys_addr = (void*)info.PhysBasePtr; vram_base = (unsigned long) info.PhysBasePtr; vram_size=(h_res * v_res * bits_per_pixel )/8; secondary_buf = malloc(vram_size); if(secondary_buf== NULL) { printf("Not enough memory for secondary buffer\n"); return NULL; } map_virtual_memory(vram_base, vram_size, (void**)&video_mem); if(set_video_mode(mode)) return NULL; return video_mem; }
bool DFInstanceLinux::find_running_copy(bool connect_anyway) { // find PID of DF TRACE << "attempting to find running copy of DF by executable name"; QProcess *proc = new QProcess(this); QStringList args; args << "dwarfort.exe"; // 0.31.04 and earlier args << "Dwarf_Fortress"; // 0.31.05+ proc->start("pidof", args); proc->waitForFinished(1000); if (proc->exitCode() == 0) { //found it QByteArray out = proc->readAllStandardOutput(); QStringList str_pids = QString(out).split(" "); str_pids.sort(); if(str_pids.count() > 1){ m_pid = QInputDialog::getItem(0, tr("Warning"),tr("Multiple Dwarf Fortress processes found, please choose the process to use."),str_pids,str_pids.count()-1,false).toInt(); }else{ m_pid = str_pids.at(0).toInt(); } m_memory_file.setFileName(QString("/proc/%1/mem").arg(m_pid)); TRACE << "USING PID:" << m_pid; } else { QMessageBox::warning(0, tr("Warning"), tr("Unable to locate a running copy of Dwarf " "Fortress, are you sure it's running?")); LOGW << "can't find running copy"; m_is_ok = false; return m_is_ok; } m_inject_addr = unsigned(-1); m_alloc_start = 0; m_alloc_end = 0; map_virtual_memory(); //qDebug() << "LOWEST ADDR:" << hex << lowest_addr; //DUMP LIST OF MEMORY RANGES /* QPair<uint, uint> tmp_pair; foreach(tmp_pair, m_regions) { LOGD << "RANGE start:" << hex << tmp_pair.first << "end:" << tmp_pair.second; }*/ VIRTADDR m_base_addr = read_addr(m_lowest_address + 0x18); LOGD << "base_addr:" << m_base_addr << "HEX" << hex << m_base_addr; m_is_ok = m_base_addr > 0; uint checksum = calculate_checksum(); LOGD << "DF's checksum is" << hexify(checksum); if (m_is_ok) { m_layout = get_memory_layout(hexify(checksum).toLower(), !connect_anyway); } //Get dwarf fortress directory m_df_dir = QDir(QFileInfo(QString("/proc/%1/cwd").arg(m_pid)).symLinkTarget()); LOGI << "Dwarf fortress path:" << m_df_dir.absolutePath(); return m_is_ok || connect_anyway; }