mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-05 06:00:33 -04:00
fix buffer overflow in chargen + CRT effect
This commit is contained in:
parent
f169aa5071
commit
ebcd71ece8
5 changed files with 48 additions and 5 deletions
|
@ -454,7 +454,7 @@ static char select_xicht(int id,int xa,int ya,int xr,int yr)
|
||||||
def_handle(H_XICHTY+cur_edited,s,pcx_8bit_decomp,SR_BGRAFIKA);
|
def_handle(H_XICHTY+cur_edited,s,pcx_8bit_decomp,SR_BGRAFIKA);
|
||||||
sprintf(s,CHAR_NAME,k);
|
sprintf(s,CHAR_NAME,k);
|
||||||
def_handle(H_POSTAVY+cur_edited,s,pcx_8bit_decomp,SR_BGRAFIKA);
|
def_handle(H_POSTAVY+cur_edited,s,pcx_8bit_decomp,SR_BGRAFIKA);
|
||||||
for(j=0;j<MAX_XICHTS;j++) if (postavy[j].used) disable[postavy[j].xicht]=1;
|
for(j=0;j<POCET_POSTAV;j++) if (postavy[j].used) disable[postavy[j].xicht]=1;
|
||||||
error_text=NULL;
|
error_text=NULL;
|
||||||
bott_draw(1);
|
bott_draw(1);
|
||||||
redraw_generator(1);
|
redraw_generator(1);
|
||||||
|
|
|
@ -567,7 +567,7 @@ static int enum_all_status(FILE *f, ENUM_ALL_STATUS_CALLBACK_RESULT (*cb)(FILE *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ENUM_ALL_STATUS_CALLBACK_RESULT unpack_status_callback(FILE *f, const char *name, size_t datasize, void *) {
|
static ENUM_ALL_STATUS_CALLBACK_RESULT unpack_status_callback(FILE *f, const char *name, size_t datasize, void *_) {
|
||||||
void *buff = getmem(datasize);
|
void *buff = getmem(datasize);
|
||||||
if (fread(buff, 1, datasize, f) != datasize) {
|
if (fread(buff, 1, datasize, f) != datasize) {
|
||||||
free(buff);
|
free(buff);
|
||||||
|
|
|
@ -200,7 +200,7 @@ void load_spells_legacy_format(void **p, int32_t *s) {
|
||||||
k = (*p);
|
k = (*p);
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
char *b = (char *)k;
|
char *b = (char *)k;
|
||||||
char traceon = k->spellname[-1]; //traceon was there;
|
char traceon = *(k->spellname-1); //traceon was there;
|
||||||
size_t bofs = offsetof(TKOUZLO, traceon);
|
size_t bofs = offsetof(TKOUZLO, traceon);
|
||||||
size_t eofs = offsetof(TKOUZLO, spellname)-1;
|
size_t eofs = offsetof(TKOUZLO, spellname)-1;
|
||||||
memmove(b+bofs+1, b+bofs, eofs-bofs);\
|
memmove(b+bofs+1, b+bofs, eofs-bofs);\
|
||||||
|
|
|
@ -48,6 +48,35 @@ SDLContext::SDLContext() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLContext::generateCRTTexture(SDL_Renderer* renderer, SDL_Texture** texture, int width, int height) {
|
||||||
|
|
||||||
|
// Vytvoř novou texturu ve správné velikosti
|
||||||
|
*texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||||
|
SDL_SetTextureBlendMode(*texture, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
|
// Zamkni texturu pro přímý přístup k pixelům
|
||||||
|
void* pixels;
|
||||||
|
int pitch;
|
||||||
|
SDL_LockTexture(*texture, nullptr, &pixels, &pitch);
|
||||||
|
|
||||||
|
// Vyplň texturu patternem (liché řádky tmavší)
|
||||||
|
Uint32* pixelArray = (Uint32*)pixels;
|
||||||
|
Uint32 darkPixel = 0x00000080; // Černá s částečnou průhledností
|
||||||
|
Uint32 transparentPixel = 0x00000000;
|
||||||
|
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
Uint32 color = (y % 3 == 0) ? darkPixel : transparentPixel;
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
pixelArray[y * (pitch / 4) + x] = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Odemkni texturu
|
||||||
|
SDL_UnlockTexture(*texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SDLContext::init_screen(DisplayMode mode, const char *title) {
|
void SDLContext::init_screen(DisplayMode mode, const char *title) {
|
||||||
char buff[256];
|
char buff[256];
|
||||||
static Uint32 update_request_event = SDL_RegisterEvents(1);
|
static Uint32 update_request_event = SDL_RegisterEvents(1);
|
||||||
|
@ -78,6 +107,7 @@ void SDLContext::init_screen(DisplayMode mode, const char *title) {
|
||||||
snprintf(buff, sizeof(buff), "SDL Error create window: %s\n", SDL_GetError());
|
snprintf(buff, sizeof(buff), "SDL Error create window: %s\n", SDL_GetError());
|
||||||
throw std::runtime_error(buff);
|
throw std::runtime_error(buff);
|
||||||
}
|
}
|
||||||
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
||||||
|
|
||||||
_window.reset(window);
|
_window.reset(window);
|
||||||
SDL_Renderer *renderer = SDL_CreateRenderer(_window.get(), -1, 0);
|
SDL_Renderer *renderer = SDL_CreateRenderer(_window.get(), -1, 0);
|
||||||
|
@ -151,7 +181,11 @@ void SDLContext::event_loop(std::stop_token stp) {
|
||||||
update_screen();
|
update_screen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.type == SDL_KEYDOWN) {
|
if (e.type == SDL_WINDOWEVENT) {
|
||||||
|
if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
||||||
|
_crt_effect.reset();
|
||||||
|
}
|
||||||
|
} else if (e.type == SDL_KEYDOWN) {
|
||||||
_key_capslock = e.key.keysym.mod & KMOD_CAPS;
|
_key_capslock = e.key.keysym.mod & KMOD_CAPS;
|
||||||
_key_shift =e.key.keysym.mod & KMOD_SHIFT;
|
_key_shift =e.key.keysym.mod & KMOD_SHIFT;
|
||||||
_key_control =e.key.keysym.mod & KMOD_CTRL;
|
_key_control =e.key.keysym.mod & KMOD_CTRL;
|
||||||
|
@ -320,6 +354,14 @@ void SDLContext::update_screen() {
|
||||||
SDL_SetTextureAlphaMod(_visible_texture, 255);
|
SDL_SetTextureAlphaMod(_visible_texture, 255);
|
||||||
SDL_RenderCopy(_renderer.get(), _visible_texture, NULL, &winrc);
|
SDL_RenderCopy(_renderer.get(), _visible_texture, NULL, &winrc);
|
||||||
}
|
}
|
||||||
|
if (winrc.w > 1280 && winrc.h > 960) {
|
||||||
|
if (!_crt_effect) {
|
||||||
|
SDL_Texture *txt;
|
||||||
|
generateCRTTexture(_renderer.get(), &txt, 128, std::min<int>(1440, winrc.h));
|
||||||
|
_crt_effect.reset(txt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SDL_RenderCopy(_renderer.get(), _crt_effect.get(), NULL, &winrc);
|
||||||
SDL_RenderPresent(_renderer.get());
|
SDL_RenderPresent(_renderer.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ protected:
|
||||||
std::unique_ptr<SDL_Renderer, SDL_Deleter> _renderer;
|
std::unique_ptr<SDL_Renderer, SDL_Deleter> _renderer;
|
||||||
std::unique_ptr<SDL_Texture, SDL_Deleter> _texture;
|
std::unique_ptr<SDL_Texture, SDL_Deleter> _texture;
|
||||||
std::unique_ptr<SDL_Texture, SDL_Deleter> _texture2;
|
std::unique_ptr<SDL_Texture, SDL_Deleter> _texture2;
|
||||||
|
std::unique_ptr<SDL_Texture, SDL_Deleter> _crt_effect;
|
||||||
SDL_Texture *_visible_texture;
|
SDL_Texture *_visible_texture;
|
||||||
SDL_Texture *_hidden_texture;
|
SDL_Texture *_hidden_texture;
|
||||||
|
|
||||||
|
@ -136,7 +137,7 @@ protected:
|
||||||
static SDL_Point to_source_point(const SDL_Rect &win_rec, const SDL_Point &win_pt) ;
|
static SDL_Point to_source_point(const SDL_Rect &win_rec, const SDL_Point &win_pt) ;
|
||||||
static SDL_Rect transition_rect(const SDL_Rect &beg, const SDL_Rect &end, float phase);
|
static SDL_Rect transition_rect(const SDL_Rect &beg, const SDL_Rect &end, float phase);
|
||||||
static int transition_int(int beg, int end, float phase);
|
static int transition_int(int beg, int end, float phase);
|
||||||
|
void generateCRTTexture(SDL_Renderer* renderer, SDL_Texture** texture, int width, int height);
|
||||||
void signal_push();
|
void signal_push();
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue