Linux compatibilty run, not sure if windows is not broken...

develop
Warmist 2011-08-08 22:17:11 +03:00
parent bead6cd350
commit 71dc85d35a
6 changed files with 30 additions and 21 deletions

@ -98,9 +98,9 @@ ENDMACRO(DFHACK_PLUGIN)
#RECURSE_DIRS() #RECURSE_DIRS()
# Dfusion plugin (Windows only right now) # Dfusion plugin
OPTION(BUILD_DFUSION "Build DFusion." ON) OPTION(BUILD_DFUSION "Build DFusion." ON)
if(NOT UNIX AND BUILD_DFUSION) if(BUILD_DFUSION)
add_subdirectory (Dfusion) add_subdirectory (Dfusion)
endif() endif()

@ -1,5 +1,6 @@
#ifndef LUA_VERSIONINFO_H #ifndef LUA_VERSIONINFO_H
#define LUA_VERSIONINFO_H #define LUA_VERSIONINFO_H
#include <dfhack/Core.h>
#include <dfhack/VersionInfo.h> #include <dfhack/VersionInfo.h>
namespace lua namespace lua

@ -249,7 +249,7 @@ private:
static int index_T(lua_State *L) // calls with (table, key), return value static int index_T(lua_State *L) // calls with (table, key), return value
{ {
lua::state st(L); lua::state st(L);
string key=st.as<string>(-1); std::string key=st.as<std::string>(-1);
T *p=check(L,1); T *p=check(L,1);
GetTable(L,p); GetTable(L,p);
st.insert(-2); st.insert(-2);

@ -1,5 +1,11 @@
#include "functioncall.h" #include "functioncall.h"
#define __F_TDEF(CONV,CONV_,tag) typedef int(CONV_ *F_TYPE##CONV##tag)
#ifdef LINUX_BUILD
#define __F_TDEF(CONV,CONV_,tag) typedef int(__attribute__ ( (CONV_) ) *F_TYPE##CONV##tag)
#else
#define __F_TDEF(CONV,CONV_,tag) typedef int(__ ## CONV_ *F_TYPE##CONV##tag)
#endif
#define __F_T(CONV,tag) F_TYPE##CONV##tag #define __F_T(CONV,tag) F_TYPE##CONV##tag
#define __F_TYPEDEFS(CONV,CONV_) __F_TDEF(CONV,CONV_,1)(int);\ #define __F_TYPEDEFS(CONV,CONV_) __F_TDEF(CONV,CONV_,1)(int);\
__F_TDEF(CONV,CONV_,2)(int,int);\ __F_TDEF(CONV,CONV_,2)(int,int);\
@ -57,7 +63,7 @@
(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8],arguments[9]);}*/ (arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8],arguments[9]);}*/
int FunctionCaller::CallF(size_t count,callconv conv,void* f,const vector<int> &arguments)//more complex but not more error safe /*int FunctionCaller::CallF(size_t count,callconv conv,void* f,const vector<int> &arguments)//more complex but not more error safe
{ {
__F_TYPEDEFS(STD_CALL,__stdcall); __F_TYPEDEFS(STD_CALL,__stdcall);
__F_TYPEDEFS(FAST_CALL,__fastcall); __F_TYPEDEFS(FAST_CALL,__fastcall);
@ -69,13 +75,13 @@ int FunctionCaller::CallF(size_t count,callconv conv,void* f,const vector<int> &
__FCALLEX(THIS_CALL,__thiscall); __FCALLEX(THIS_CALL,__thiscall);
__FCALLEX(CDECL_CALL,__cdecl); __FCALLEX(CDECL_CALL,__cdecl);
} }
} }*/
int FunctionCaller::CallFunction(size_t func_ptr,callconv conv,const vector<int> &arguments) int FunctionCaller::CallFunction(size_t func_ptr,callconv conv,const vector<int> &arguments)
{ {
//nasty nasty code... //nasty nasty code...
#ifdef LINUX_BUILD //quick fix #ifdef LINUX_BUILD //quick fix
if(conv==THIS_CALL) if(conv==THIS_CALL)
conv=STD_CALL conv=STD_CALL;
#endif #endif
void* f= reinterpret_cast<void*>(func_ptr+base_); void* f= reinterpret_cast<void*>(func_ptr+base_);
size_t count=arguments.size(); size_t count=arguments.size();
@ -83,15 +89,15 @@ int FunctionCaller::CallFunction(size_t func_ptr,callconv conv,const vector<int>
return (reinterpret_cast<int (*)()>(f))(); //does not matter how we call it... return (reinterpret_cast<int (*)()>(f))(); //does not matter how we call it...
int ret=0; int ret=0;
//typedefs //typedefs
__F_TYPEDEFS(STD_CALL,__stdcall); __F_TYPEDEFS(STD_CALL,stdcall);
__F_TYPEDEFS(FAST_CALL,__fastcall); __F_TYPEDEFS(FAST_CALL,fastcall);
__F_TYPEDEFS(THIS_CALL,__thiscall); __F_TYPEDEFS(THIS_CALL,thiscall);
__F_TYPEDEFS(CDECL_CALL,__cdecl); __F_TYPEDEFS(CDECL_CALL,cdecl);
//calls //calls
__FCALL(STD_CALL,__stdcall); __FCALL(STD_CALL,stdcall);
__FCALL(FAST_CALL,__fastcall); __FCALL(FAST_CALL,fastcall);
__FCALL(THIS_CALL,__thiscall); __FCALL(THIS_CALL,thiscall);
__FCALL(CDECL_CALL,__cdecl); __FCALL(CDECL_CALL,cdecl);
return -1; //incorect type. Should probably throw... return -1; //incorect type. Should probably throw...
//return CallF(count,conv,f,arguments); //return CallF(count,conv,f,arguments);
/*//testing part{ worked some time ago..., put where DFHack::Core is accesible /*//testing part{ worked some time ago..., put where DFHack::Core is accesible

@ -49,7 +49,7 @@ LUNE_METHODS_START(lua::Hexsearch)
method(lua::Hexsearch,findall), method(lua::Hexsearch,findall),
method(lua::Hexsearch,reset), method(lua::Hexsearch,reset),
LUNE_METHODS_END(); LUNE_METHODS_END();
#define __ADDCONST(name) st.push(::Hexsearch:: ## name); st.setglobal(#name) #define __ADDCONST(name) st.push(::Hexsearch:: name); st.setglobal(#name)
void lua::RegisterHexsearch(lua::state &st) void lua::RegisterHexsearch(lua::state &st)
{ {

@ -1,5 +1,7 @@
#include "lua_Offsets.h" #include "lua_Offsets.h"
#include <string.h>
//TODO make a seperate module with peeks/pokes and page permisions (linux/windows spec) //TODO make a seperate module with peeks/pokes and page permisions (linux/windows spec)
//TODO maybe remove alltogether- use DFHack::Process instead?
unsigned char peekb(size_t offset) unsigned char peekb(size_t offset)
{ {
return *((unsigned char*)(offset)); return *((unsigned char*)(offset));
@ -18,7 +20,7 @@ void peekarb(size_t offset, void *mem,size_t size)
} }
void peekstr(size_t offset, char* buf, size_t maxsize) void peekstr(size_t offset, char* buf, size_t maxsize)
{ {
strcpy_s(buf,maxsize,(char*)offset); strncpy(buf,(char*)offset,maxsize);
} }
void pokeb(size_t offset,unsigned char val) void pokeb(size_t offset,unsigned char val)
{ {
@ -38,7 +40,7 @@ void pokearb(size_t offset, void *mem,size_t size)
} }
void pokestr(size_t offset, char* buf, size_t maxsize) void pokestr(size_t offset, char* buf, size_t maxsize)
{ {
strcpy_s((char*)offset,maxsize,buf); strncpy((char*)offset,buf,maxsize);
} }
template <typename T> template <typename T>
T peek(size_t offset) //prob lower performance T peek(size_t offset) //prob lower performance