void tech_fix(dbref player, void *data, char *buffer) { MECH *mech = data; int n = atoi(buffer); int low, high; int isds; skipws(buffer); TECHCOMMANDC; if (unit_is_fixable(mech)) make_damage_table(mech); else make_scrap_table(mech); DOCHECK(!damage_last && MechType(mech) == CLASS_MECH, "The 'mech is in pristine condition!"); DOCHECK(!damage_last, "It's in pristine condition!"); if (sscanf(buffer, "%d-%d", &low, &high) == 2) { DOCHECK(low < 1 || low > damage_last, "Invalid low #!"); DOCHECK(high < 1 || high > damage_last, "Invalid high #!"); for (n = low; n <= high; n++) fix_entry(player, mech, n); return; } DOCHECK(n < 1 || n > damage_last, "Invalid #!"); fix_entry(player, mech, n); }
static bool get_entry(const char* file_path, index_tbl_entry* entry) { bool ret = false; char buf[BLOCK_SIZE]; resource_ptn_header header; if (!StorageReadLba(get_ptn_offset(), buf, 1)) { LOGE("Failed to read header!"); goto end; } memcpy(&header, buf, sizeof(header)); if (memcmp(header.magic, RESOURCE_PTN_HDR_MAGIC, sizeof(header.magic))) { LOGE("Not a resource image(%s)!", image_path); goto end; } //test on pc, switch for be. fix_header(&header); //TODO: support header_size & tbl_entry_size if (header.resource_ptn_version != RESOURCE_PTN_VERSION || header.header_size != RESOURCE_PTN_HDR_SIZE || header.index_tbl_version != INDEX_TBL_VERSION || header.tbl_entry_size != INDEX_TBL_ENTR_SIZE) { LOGE("Not supported in this version!"); goto end; } int i; for (i = 0; i < header.tbl_entry_num; i++) { //TODO: support tbl_entry_size if (!StorageReadLba(get_ptn_offset() + header.header_size + i * header.tbl_entry_size, buf, 1)) { LOGE("Failed to read index entry:%d!", i); goto end; } memcpy(entry, buf, sizeof(*entry)); if (memcmp(entry->tag, INDEX_TBL_ENTR_TAG, sizeof(entry->tag))) { LOGE("Something wrong with index entry:%d!", i); goto end; } if (!strncmp(entry->path, file_path, sizeof(entry->path))) break; } if (i == header.tbl_entry_num) { LOGE("Cannot find %s!", file_path); goto end; } //test on pc, switch for be. fix_entry(entry); printf("Found entry:\n\tpath:%s\n\toffset:%d\tsize:%d\n", entry->path, entry->content_offset, entry->content_size); ret = true; end: return ret; }