Loki CivCTP function wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 1: Hex-Edit the civctp.dynamic executable | |
// - Rename the libSDL import to point to SDL 1.2 | |
// - Rename all the functions below in the import tables: | |
// - __builtin_new → x_builtin_new (etc.) | |
// - {mem,str,strn}cpy → {mem,str,strn}cpx | |
// - Make sure you have libttf and libsmpeg in the current directory | |
// - Build this with: | |
// cc -shared -m32 -fPIC -o libcivctp_wrapper.so civctp_wrapper.c | |
// - Run CivCTP with: | |
// LD_PRELOAD=libcivctp_wrapper.so LD_LIBRARY_PATH=. ./civctp.dynamic | |
// - Beware of bugs: | |
// - It'll probably corrupt memory and crash all the time. :/ | |
// (Changing the malloc(x) → calloc(x, 2) fixes some of these, I think, but…) | |
// - It doesn't work properly with sdl12-compat yet | |
// - Multiplayer likely still won't work. | |
// - Sound does, but CD-audio doesn't without some further hacks. | |
#include <stdlib.h> | |
#include <string.h> | |
void *x_builtin_new(unsigned int size) | |
{ | |
return malloc(size); | |
} | |
void x_builtin_delete(void *ptr) | |
{ | |
return free(ptr); | |
} | |
void *x_builtin_vec_new(unsigned int size) | |
{ | |
return malloc(size); | |
} | |
void x_builtin_vec_delete(void *ptr) | |
{ | |
return free(ptr); | |
} | |
/* Placement new */ | |
void *x_nw__FUiPv(int size, void *p) | |
{ | |
return p; | |
} | |
/* CivCTP overlaps all the time in memcpy, strcpy, and strncpy. */ | |
void *memcpx(void *dest, const void *src, size_t n) | |
{ | |
return memmove(dest, src, n); | |
} | |
char *strcpx(char *dest, const char *src) | |
{ | |
size_t len = strlen(src); | |
char *ret = memmove(dest, src, len); | |
dest[len] = '\0'; | |
return ret; | |
} | |
char *strncpx(char *dest, const char *src, size_t n) | |
{ | |
/* Taken from 'man strncpy' */ | |
size_t i; | |
for (i = 0; i < n && src[i] != '\0'; i++) | |
dest[i] = src[i]; | |
for ( ; i < n; i++) | |
dest[i] = '\0'; | |
return dest; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment