Use mt19937_xorcode helper function

This commit is contained in:
kichikuou
2023-12-17 09:01:28 +09:00
parent 05d2ad8600
commit c3f39aeb96
4 changed files with 4 additions and 13 deletions
+1 -4
View File
@@ -95,10 +95,7 @@ static uint8_t *chr_get(int id)
free(data);
data = NULL;
} else {
struct mt19937 mt;
mt19937_init(&mt, 12753);
for (size_t i = 4; i < size; i++)
data[i] ^= mt19937_genrand(&mt);
mt19937_xorcode(data + 4, size - 4, 12753);
slot->value = data;
}
free(path);
+1 -4
View File
@@ -274,10 +274,7 @@ static int DataFile_Open(int link)
uint8_t *compressed_data = xmalloc(compressed_size);
buffer_read_bytes(&r, compressed_data, compressed_size);
archive_free_data(dfile);
struct mt19937 mt;
mt19937_init(&mt, 4588163);
for (size_t i = 0; i < compressed_size; i++)
compressed_data[i] ^= mt19937_genrand(&mt);
mt19937_xorcode(compressed_data, compressed_size, 4588163);
uint8_t *raw = xmalloc(uncompressed_size);
int rv = uncompress(raw, &uncompressed_size, compressed_data, compressed_size);
+1 -4
View File
@@ -95,10 +95,7 @@ static bool MapLoader_Load(int map_no)
free(map_data);
map_data = NULL;
} else {
struct mt19937 mt;
mt19937_init(&mt, 12753);
for (size_t i = 4; i < map_size; i++)
map_data[i] ^= mt19937_genrand(&mt);
mt19937_xorcode(map_data + 4, map_size - 4, 12753);
}
free(path);
return !!map_data;