예제 #1
0
파일: appinfo.c 프로젝트: dotfloat/Vapour
int appinfo_entry(struct appinfo info, struct appinfo_common *common)
{
    int entry_id;
    char section_id;
    char str[128];
    struct app_header header;
    long pos = ftell(info.ai_fp);

    if (fread(&entry_id, sizeof(entry_id), 1, info.ai_fp) != 1 || entry_id == 0) {
        return 0;
    }

    if (fread(&header, sizeof(header), 1, info.ai_fp) != 1) {
        return 0;
    }

    if (!fgetc(info.ai_fp))
        goto end;

    fgetc(info.ai_fp);

    if (!read_zstring(info.ai_fp, str, sizeof(str))) {
        return 0;
    }

    if (!strcmp(str, "common")) {
        read_common(info.ai_fp, common);
    }

    end:
    fseek(info.ai_fp, pos + header.size + 8, SEEK_SET);

//    for (;;) {
//        section_id = (char) fgetc(info.ai_fp);
//
//        if (section_id == 0)
//            break;
//
//        /*if (fread(&section_id, sizeof(section_id), 1, info.ai_fp) != 1 || section_id == 0) {
//            printf("EOS\n");
//            return 0;
//        }*/
//
//        fgetc(info.ai_fp);
//
//        if (!read_zstring(info.ai_fp, str, sizeof(str))) {
//            return 0;
//        }
//
//        break;
//    }

    return 1;
}
예제 #2
0
파일: g_save.c 프로젝트: Jenco420/q2pro
static void read_field(FILE *f, const save_field_t *field, void *base)
{
    void *p = (byte *)base + field->ofs;
    int i;

    switch (field->type) {
    case F_BYTE:
        read_data(p, field->size, f);
        break;
    case F_SHORT:
        for (i = 0; i < field->size; i++) {
            ((short *)p)[i] = read_short(f);
        }
        break;
    case F_INT:
        for (i = 0; i < field->size; i++) {
            ((int *)p)[i] = read_int(f);
        }
        break;
    case F_FLOAT:
        for (i = 0; i < field->size; i++) {
            ((float *)p)[i] = read_float(f);
        }
        break;
    case F_VECTOR:
        read_vector(f, (vec_t *)p);
        break;

    case F_LSTRING:
        *(char **)p = read_string(f);
        break;
    case F_ZSTRING:
        read_zstring(f, (char *)p, field->size);
        break;

    case F_EDICT:
        *(edict_t **)p = read_index(f, sizeof(edict_t), g_edicts, game.maxentities - 1);
        break;
    case F_CLIENT:
        *(gclient_t **)p = read_index(f, sizeof(gclient_t), game.clients, game.maxclients - 1);
        break;
    case F_ITEM:
        *(gitem_t **)p = read_index(f, sizeof(gitem_t), itemlist, game.num_items - 1);
        break;

    case F_POINTER:
        *(void **)p = read_pointer(f, field->size);
        break;

    default:
        gi.error("%s: unknown field type", __func__);
    }
}
예제 #3
0
파일: appinfo.c 프로젝트: dotfloat/Vapour
static void read_common(FILE *file, struct appinfo_common *common)
{
    char key[128];
    char val[128];

    if (common->name) {
        free(common->name);
    }

    memset(common, 0, sizeof(*common));

    /* Default to windows for apps that don't have a 'oslist' key. */
    common->os = APPOS_WINDOWS;

    for (; ;) {
        int type = fgetc(file);
        uint32_t u32 = 0;
        uint64_t u64;

        if (type == 0x08) {
            fgetc(file);
            break;
        }

        if (!read_zstring(file, key, sizeof(key))) {
            return;
        }

        switch (type) {
        case T_SUBSECTION:
            skip_subsection(file);
            break;
        case T_INT32:
            fread(&u32, sizeof(u32), 1, file);
            break;

        case T_INT64:
            fread(&u64, sizeof(u64), 1, file);
            break;

        case T_STRING:
            read_zstring(file, val, sizeof(val));
            break;

        default:
            break;
        }

        if (!strcasecmp(key, "name")) {
            common->name = strdup(val);
        }
        else if (!strcasecmp(key, "type")) {
            if (!strcasecmp(val, "config")) {
                common->type = APPTYPE_CONFIG;
            }
            else if (!strcasecmp(val, "game")) {
                common->type = APPTYPE_GAME;
            }
            else if (!strcasecmp(val, "tool")) {
                common->type = APPTYPE_TOOL;
            }
            else if (!strcasecmp(val, "dlc")) {
                common->type = APPTYPE_DLC;
            }
            else if (!strcasecmp(val, "application")) {
                common->type = APPTYPE_APPLICATION;
            }
            else if (!strcasecmp(val, "demo")) {
                common->type = APPTYPE_DEMO;
            }
            else {
                fprintf(stderr, "libvapour: Unknown appinfo type: %s\n", val);
                common->type = APPTYPE_UNKNOWN;
            }
        }
        else if (!strcasecmp(key, "oslist")) {
            common->os = APPOS_NONE;

            if (strstr(val, "windows")) {
                common->os |= APPOS_WINDOWS;
            }
            if (strstr(val, "macos")) {
                common->os |= APPOS_MACOS;
            }
            if (strstr(val, "linux")) {
                common->os |= APPOS_LINUX;
            }
        }
        else if (!strcasecmp(key, "gameid")) {
            common->appid = u32;
        }
    }
}