|
|
@ -214,17 +214,13 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
|
|
|
if (!onupdate_active)
|
|
|
|
if (!onupdate_active)
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
|
|
|
|
using namespace df::global;
|
|
|
|
if (df::global::cur_year && *df::global::cur_year < onupdate_minyear)
|
|
|
|
|
|
|
|
|
|
|
|
if (cur_year && (*cur_year < onupdate_minyear))
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
if (cur_year && cur_year_tick && onupdate_minyeartick >= 0 &&
|
|
|
|
if (df::global::cur_year_tick && onupdate_minyeartick >= 0 &&
|
|
|
|
(*cur_year == onupdate_minyear &&
|
|
|
|
*df::global::cur_year_tick < onupdate_minyeartick)
|
|
|
|
*cur_year_tick < onupdate_minyeartick))
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
if (cur_year && cur_year_tick_advmode && onupdate_minyeartickadv >= 0 &&
|
|
|
|
if (df::global::cur_year_tick_advmode && onupdate_minyeartickadv >= 0 &&
|
|
|
|
(*cur_year == onupdate_minyear &&
|
|
|
|
*df::global::cur_year_tick_advmode < onupdate_minyeartickadv)
|
|
|
|
*cur_year_tick_advmode < onupdate_minyeartickadv))
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
|
|
|
|
return plugin_eval_ruby(out, "DFHack.onupdate");
|
|
|
|
return plugin_eval_ruby(out, "DFHack.onupdate");
|
|
|
@ -283,21 +279,13 @@ static command_result df_rubyeval(color_ostream &out, std::vector <std::string>
|
|
|
|
// - ruby.h with gcc -m32 on linux 64 is broken
|
|
|
|
// - ruby.h with gcc -m32 on linux 64 is broken
|
|
|
|
// so we dynamically load libruby with dlopen/LoadLibrary
|
|
|
|
// so we dynamically load libruby with dlopen/LoadLibrary
|
|
|
|
// lib path is hardcoded here, and by default downloaded by cmake
|
|
|
|
// lib path is hardcoded here, and by default downloaded by cmake
|
|
|
|
// this code should work with ruby1.9, but ruby1.9 doesn't like running
|
|
|
|
|
|
|
|
// in a dedicated non-main thread, so use ruby1.8 binaries only for now
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef uintptr_t VALUE;
|
|
|
|
typedef uintptr_t VALUE;
|
|
|
|
typedef uintptr_t ID;
|
|
|
|
typedef uintptr_t ID;
|
|
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
static VALUE Qfalse = 0;
|
|
|
|
int major;
|
|
|
|
static VALUE Qtrue = 2;
|
|
|
|
int minor;
|
|
|
|
static VALUE Qnil = 4;
|
|
|
|
int teeny;
|
|
|
|
|
|
|
|
} libruby_version;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static VALUE Qfalse;
|
|
|
|
|
|
|
|
static VALUE Qtrue;
|
|
|
|
|
|
|
|
static VALUE Qnil;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define INT2FIX(i) ((VALUE)((((intptr_t)i) << 1) | 1))
|
|
|
|
#define INT2FIX(i) ((VALUE)((((intptr_t)i) << 1) | 1))
|
|
|
|
#define FIX2INT(i) (((intptr_t)i) >> 1)
|
|
|
|
#define FIX2INT(i) (((intptr_t)i) >> 1)
|
|
|
@ -345,26 +333,6 @@ static int df_loadruby(void)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *ruby_version = (const char*)LookupPlugin(libruby_handle, "ruby_version");
|
|
|
|
|
|
|
|
if (!ruby_version)
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sscanf(ruby_version, "%d.%d.%d",
|
|
|
|
|
|
|
|
&libruby_version.major, &libruby_version.minor, &libruby_version.teeny);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (libruby_version.major >= 2 && sizeof(VALUE) >= sizeof(double))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// USE_FLONUM defined on x64
|
|
|
|
|
|
|
|
Qfalse = (VALUE)0;
|
|
|
|
|
|
|
|
Qtrue = (VALUE)0x14;
|
|
|
|
|
|
|
|
Qnil = (VALUE)0x08;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Qfalse = (VALUE)0;
|
|
|
|
|
|
|
|
Qtrue = (VALUE)2;
|
|
|
|
|
|
|
|
Qnil = (VALUE)4;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ruby_sysinit is optional (ruby1.9 only)
|
|
|
|
// ruby_sysinit is optional (ruby1.9 only)
|
|
|
|
ruby_sysinit = (decltype(ruby_sysinit))LookupPlugin(libruby_handle, "ruby_sysinit");
|
|
|
|
ruby_sysinit = (decltype(ruby_sysinit))LookupPlugin(libruby_handle, "ruby_sysinit");
|
|
|
|
#define rbloadsym(s) if (!(s = (decltype(s))LookupPlugin(libruby_handle, #s))) return 0
|
|
|
|
#define rbloadsym(s) if (!(s = (decltype(s))LookupPlugin(libruby_handle, #s))) return 0
|
|
|
@ -465,6 +433,11 @@ static void df_rubythread(void *p)
|
|
|
|
r_result = CR_OK;
|
|
|
|
r_result = CR_OK;
|
|
|
|
r_type = RB_IDLE;
|
|
|
|
r_type = RB_IDLE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// initialize ruby constants (may depend on libruby compilation flags/version)
|
|
|
|
|
|
|
|
Qnil = rb_eval_string_protect("nil", &state);
|
|
|
|
|
|
|
|
Qtrue = rb_eval_string_protect("true", &state);
|
|
|
|
|
|
|
|
Qfalse = rb_eval_string_protect("false", &state);
|
|
|
|
|
|
|
|
|
|
|
|
// load the default ruby-level definitions in the background
|
|
|
|
// load the default ruby-level definitions in the background
|
|
|
|
state=0;
|
|
|
|
state=0;
|
|
|
|
rb_eval_string_protect("require './hack/ruby/ruby'", &state);
|
|
|
|
rb_eval_string_protect("require './hack/ruby/ruby'", &state);
|
|
|
@ -1085,8 +1058,8 @@ static VALUE rb_dfmemory_set_clear(VALUE self, VALUE set)
|
|
|
|
|
|
|
|
|
|
|
|
/* call an arbitrary object virtual method */
|
|
|
|
/* call an arbitrary object virtual method */
|
|
|
|
#if defined(_WIN32) && !defined(_WIN64)
|
|
|
|
#if defined(_WIN32) && !defined(_WIN64)
|
|
|
|
__declspec(naked) static int raw_vcall(void *that, void *fptr, unsigned long a0,
|
|
|
|
__declspec(naked) static intptr_t raw_vcall(void *that, void *fptr, uintptr_t a0,
|
|
|
|
unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5)
|
|
|
|
uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// __thiscall requires that the callee cleans up the stack
|
|
|
|
// __thiscall requires that the callee cleans up the stack
|
|
|
|
// here we dont know how many arguments it will take, so
|
|
|
|
// here we dont know how many arguments it will take, so
|
|
|
@ -1112,11 +1085,11 @@ __declspec(naked) static int raw_vcall(void *that, void *fptr, unsigned long a0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
static int raw_vcall(void *that, void *fptr, unsigned long a0,
|
|
|
|
static intptr_t raw_vcall(void *that, void *fptr, uintptr_t a0,
|
|
|
|
unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5)
|
|
|
|
uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int (*t_fptr)(void *me, unsigned long, unsigned long, unsigned long,
|
|
|
|
intptr_t (*t_fptr)(void *me, uintptr_t, uintptr_t, uintptr_t,
|
|
|
|
unsigned long, unsigned long, unsigned long);
|
|
|
|
uintptr_t, uintptr_t, uintptr_t);
|
|
|
|
t_fptr = (decltype(t_fptr))fptr;
|
|
|
|
t_fptr = (decltype(t_fptr))fptr;
|
|
|
|
return t_fptr(that, a0, a1, a2, a3, a4, a5);
|
|
|
|
return t_fptr(that, a0, a1, a2, a3, a4, a5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|