Use ld --wrap to intercept time() by bsnes core

This allows games using S-RTC to be rerecorded.
This commit is contained in:
Ilari Liusvaara 2011-09-25 02:13:50 +03:00
parent 5509cb2893
commit 847519c961
5 changed files with 22 additions and 6 deletions

View file

@ -10,7 +10,7 @@ OBJECTS = $(patsubst %.cpp,%.$(OBJECT_SUFFIX),$(wildcard generic/*.cpp)) $(patsu
GENERIC_LIBS = -ldl -lboost_iostreams -lboost_filesystem -lboost_system -lz
CFLAGS = $(USER_CFLAGS)
HOSTCCFLAGS = $(USER_HOSTCCFLAGS)
LDFLAGS = $(GENERIC_LIBS) $(USER_LDFLAGS)
LDFLAGS = -Wl,--wrap,time $(GENERIC_LIBS) $(USER_LDFLAGS)
PLATFORM = SDL
PLATFORM_CFLAGS = $(CFLAGS)
PLATFORM_LDFLAGS = $(LDFLAGS)

View file

@ -1077,7 +1077,7 @@ void window::init()
#endif
init_keys();
system_log.open("lsnes.log", std::ios_base::out | std::ios_base::app);
time_t curtime = time(NULL);
time_t curtime = __real_time(NULL);
struct tm* tm = localtime(&curtime);
char buffer[1024];
strftime(buffer, 1023, "%Y-%m-%d %H:%M:%S %Z", tm);

View file

@ -23,7 +23,7 @@ namespace
std::string get_random_hexstring_64(size_t index)
{
std::ostringstream str;
str << rseed << " " << time(NULL) << " " << (rcounter++) << " " << index;
str << rseed << " " << __real_time(NULL) << " " << (rcounter++) << " " << index;
std::string s = str.str();
std::vector<char> x;
x.resize(s.length());
@ -35,13 +35,13 @@ namespace
{
//TODO: Collect as much identifying information as possible.
std::ostringstream str;
time_t told = time(NULL);
time_t told = __real_time(NULL);
time_t tnew;
uint64_t loops = 0;
uint64_t base = 0;
int cnt = 0;
while(cnt < 3) {
tnew = time(NULL);
tnew = __real_time(NULL);
if(tnew > told) {
told = tnew;
cnt++;
@ -84,7 +84,7 @@ void set_random_seed() throw(std::bad_alloc)
}
//Fall back to time.
std::ostringstream str;
str << collect_identifying_information() << " " << time(NULL);
str << collect_identifying_information() << " " << __real_time(NULL);
set_random_seed(str.str());
}

View file

@ -5,6 +5,11 @@
#include <vector>
#include <boost/lexical_cast.hpp>
extern "C"
{
time_t __real_time(time_t* t);
}
/**
* \brief Get random hexes
*

View file

@ -17,6 +17,17 @@ struct loaded_rom* our_rom;
bool system_corrupt;
movie_logic movb;
extern "C"
{
time_t __wrap_time(time_t* t)
{
time_t v = static_cast<time_t>(our_movie.rtc_second);
if(t)
*t = v;
return v;
}
}
std::vector<char>& get_host_memory()
{
return our_movie.host_memory;