mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-05 14:10:27 -04:00
hotpatching of global map DAT file, fix bugs
This commit is contained in:
parent
4fa01c46aa
commit
66edc652a1
11 changed files with 127 additions and 68 deletions
|
@ -1,6 +1,8 @@
|
|||
|
||||
|
||||
extern "C" {
|
||||
#include "map_file.h"
|
||||
#include "../error.h"
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -9,6 +11,8 @@ extern "C" {
|
|||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
// Funkce pro mapování souboru do paměti
|
||||
void* map_file_to_memory(const char *name, size_t *sz) {
|
||||
|
@ -19,14 +23,14 @@ void* map_file_to_memory(const char *name, size_t *sz) {
|
|||
// Otevření souboru pro čtení
|
||||
int fd = open(name, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("Chyba při otevírání souboru");
|
||||
display_error("Failed to open file: %s %s", name, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Získání velikosti souboru
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) == -1) {
|
||||
perror("Chyba při získávání velikosti souboru");
|
||||
display_error("Failed to fstat file: %s %s", name, strerror(errno));
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -35,7 +39,7 @@ void* map_file_to_memory(const char *name, size_t *sz) {
|
|||
// Namapování souboru do paměti
|
||||
void *mapped = mmap(NULL, *sz, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (mapped == MAP_FAILED) {
|
||||
perror("Chyba při mapování souboru");
|
||||
display_error("Failed to map file: %s %s", name, strerror(errno));
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue