diff --git a/Src/data_store.cpp b/Src/data_store.cpp index baff79e..c14a8e9 100644 --- a/Src/data_store.cpp +++ b/Src/data_store.cpp @@ -24,6 +24,7 @@ struct ds_data *DataStore::registerNetworkData(uint32_t key, uint32_t metadata, out = (struct ds_data *)xmalloc(sizeof(struct ds_data) + data_sz); out->key = key; out->metadata = metadata; + out->sz = data_sz; memcpy(out->data, data, data_sz); diff --git a/Src/data_store.hh b/Src/data_store.hh index 95eec35..129831e 100644 --- a/Src/data_store.hh +++ b/Src/data_store.hh @@ -9,6 +9,7 @@ struct ds_data { uint32_t key; uint32_t metadata; /* Type etc */ + size_t sz; uint8_t data[]; }; diff --git a/Src/gui/game_info.cpp b/Src/gui/game_info.cpp index d9dfa81..9ee866e 100644 --- a/Src/gui/game_info.cpp +++ b/Src/gui/game_info.cpp @@ -216,7 +216,6 @@ struct game_info *GameInfo::dump() bool GameInfo::fromDump(struct game_info *gi) { struct game_info *p = gi; - SDL_RWops *rw; /* Demarshal */ switch (ntohs(p->version_magic)) @@ -239,13 +238,8 @@ bool GameInfo::fromDump(struct game_info *gi) this->score = p->score; this->year = p->year; - rw = SDL_RWFromMem(p->data + p->screenshot_off, + this->screenshot = sdl_surface_from_data(p->data + p->screenshot_off, p->sz - p->screenshot_off); - if (!rw) - goto bail_out; - - this->screenshot = IMG_Load_RW(rw, 0); - SDL_FreeRW(rw); if (!this->screenshot) goto bail_out; free(p); diff --git a/Src/utils.cpp b/Src/utils.cpp index ba485bf..7bc8da3 100644 --- a/Src/utils.cpp +++ b/Src/utils.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -270,6 +271,21 @@ void *sdl_surface_to_png(SDL_Surface *surf, size_t *out_sz) return out.data; } +SDL_Surface *sdl_surface_from_data(void *data, size_t sz) +{ + SDL_RWops *rw; + SDL_Surface *out; + + rw = SDL_RWFromMem(data, sz); + if (!rw) + return NULL; + + out = IMG_Load_RW(rw, 0); + SDL_FreeRW(rw); + + return out; +} + void highlight_background(SDL_Surface *where, Font *font, SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right, int x, int y, int w, int h) diff --git a/Src/utils.hh b/Src/utils.hh index 504d01e..883c2a7 100644 --- a/Src/utils.hh +++ b/Src/utils.hh @@ -78,6 +78,8 @@ const char **get_file_list(const char *base_dir, const char *exts[]); void *sdl_surface_to_png(SDL_Surface *src, size_t *out_sz); +SDL_Surface *sdl_surface_from_data(void *data, size_t sz); + void highlight_background(SDL_Surface *where, Font *font, SDL_Surface *bg_left, SDL_Surface *bg_middle, SDL_Surface *bg_right, int x, int y, int w, int h);