Merge remote-tracking branch 'jjyg/master'

develop
Kelly Martin 2012-07-11 14:37:19 -05:00
commit 79ca632f64
20 changed files with 269 additions and 59 deletions

5
.gitignore vendored

@ -35,6 +35,7 @@ build/library
build/tools
build/plugins
build/depends
build/install_manifest.txt
#ignore Kdevelop stuff
.kdev4
@ -49,6 +50,10 @@ dfhack/python/PyDFHack.egg-info
dfhack/python/build
dfhack/python/dist
# Ruby binding binaries
plugins/ruby/libruby*
plugins/ruby/ruby-autogen.rb
# CPack stuff
build/CPack*Config.cmake

@ -139,9 +139,6 @@ include_directories(depends/tinyxml)
include_directories(depends/tthread)
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(depends/clsocket/src)
if(APPLE)
include_directories(${CMAKE_INSTALL_PREFIX}/libs/SDL.framework/Headers)
endif()
add_subdirectory(depends)

@ -1 +1 @@
Subproject commit c85e9fb35d3510c5dcc367056cda3237d77a7add
Subproject commit d0b2d0750dc2d529a152eba4f3f519f69ff7eab0

@ -8,8 +8,8 @@ IF(UNIX)
OPTION(CONSOLE_NO_CATCH "Make the console not catch 'CTRL+C' events for easier debugging." OFF)
ENDIF()
include_directories (include)
include_directories (proto)
include_directories (include)
SET(PERL_EXECUTABLE "perl" CACHE FILEPATH "This is the perl executable to run in the codegen step. Tweak it if you need to run a specific one.")
@ -267,8 +267,11 @@ SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
IF(APPLE)
SET(SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework)
SET(CXX_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/libstdc++.6.dylib)
SET(ZIP_LIBRARY /usr/lib/libz.dylib)
TARGET_LINK_LIBRARIES(dfhack ${SDL_LIBRARY})
# TARGET_LINK_LIBRARIES(dfhack /usr/lib/libc++.dylib)
TARGET_LINK_LIBRARIES(dfhack ${CXX_LIBRARY})
TARGET_LINK_LIBRARIES(dfhack ${ZIP_LIBRARY})
SET_TARGET_PROPERTIES(dfhack PROPERTIES VERSION 1.0.0)
SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0)
ENDIF()

@ -752,6 +752,7 @@ Core::Core()
misc_data_mutex=0;
last_world_data_ptr = NULL;
last_local_map_ptr = NULL;
last_pause_state = false;
top_viewscreen = NULL;
screen_window = NULL;
server = NULL;
@ -1116,6 +1117,15 @@ int Core::Update()
}
}
if (df::global::pause_state)
{
if (*df::global::pause_state != last_pause_state)
{
onStateChange(out, last_pause_state ? SC_UNPAUSED : SC_PAUSED);
last_pause_state = *df::global::pause_state;
}
}
// Execute per-frame handlers
onUpdate(out);

@ -38,11 +38,11 @@ distribution.
#include <string>
#include <map>
/*typedef struct interpose_s
typedef struct interpose_s
{
void *new_func;
void *orig_func;
} interpose_t;*/
} interpose_t;
#include "DFHack.h"
#include "Core.h"
@ -58,11 +58,18 @@ distribution.
};*/
#define DYLD_INTERPOSE(_replacment,_replacee) __attribute__((used)) static struct{ const void* replacment; const void* replacee; } _interpose_##_replacee __attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacment, (const void*)(unsigned long)&_replacee };
DYLD_INTERPOSE(DFH_SDL_Init,SDL_Init);
DYLD_INTERPOSE(DFH_SDL_PollEvent,SDL_PollEvent);
DYLD_INTERPOSE(DFH_SDL_Quit,SDL_Quit);
DYLD_INTERPOSE(DFH_SDL_NumJoysticks,SDL_NumJoysticks);
/*******************************************************************************
* SDL part starts here *
*******************************************************************************/
// hook - called for each game tick (or more often)
DFhackCExport int SDL_NumJoysticks(void)
DFhackCExport int DFH_SDL_NumJoysticks(void)
{
DFHack::Core & c = DFHack::Core::getInstance();
return c.Update();
@ -70,7 +77,7 @@ DFhackCExport int SDL_NumJoysticks(void)
// hook - called at program exit
static void (*_SDL_Quit)(void) = 0;
DFhackCExport void SDL_Quit(void)
DFhackCExport void DFH_SDL_Quit(void)
{
DFHack::Core & c = DFHack::Core::getInstance();
c.Shutdown();
@ -79,16 +86,16 @@ DFhackCExport void SDL_Quit(void)
_SDL_Quit();
}*/
_SDL_Quit();
SDL_Quit();
}
// called by DF to check input events
static int (*_SDL_PollEvent)(SDL_Event* event) = 0;
DFhackCExport int SDL_PollEvent(SDL_Event* event)
static int (*_SDL_PollEvent)(SDL::Event* event) = 0;
DFhackCExport int DFH_SDL_PollEvent(SDL::Event* event)
{
pollevent_again:
// if SDL returns 0 here, it means there are no more events. return 0
int orig_return = _SDL_PollEvent(event);
int orig_return = SDL_PollEvent(event);
if(!orig_return)
return 0;
// otherwise we have an event to filter
@ -128,7 +135,7 @@ DFhackCExport int wgetch(WINDOW *win)
// hook - called at program start, initialize some stuffs we'll use later
static int (*_SDL_Init)(uint32_t flags) = 0;
DFhackCExport int SDL_Init(uint32_t flags)
DFhackCExport int DFH_SDL_Init(uint32_t flags)
{
// reroute stderr
fprintf(stderr,"dfhack: attempting to hook in\n");
@ -140,7 +147,7 @@ DFhackCExport int SDL_Init(uint32_t flags)
fprintf(stderr,"dfhack: saving real SDL functions\n");
_SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init");
_SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit");
_SDL_PollEvent = (int (*)(SDL_Event*))dlsym(RTLD_NEXT,"SDL_PollEvent");
_SDL_PollEvent = (int (*)(SDL::Event*))dlsym(RTLD_NEXT,"SDL_PollEvent");
fprintf(stderr,"dfhack: saved real SDL functions\n");
// check if we got them
@ -158,6 +165,7 @@ DFhackCExport int SDL_Init(uint32_t flags)
DFHack::Core & c = DFHack::Core::getInstance();
//c.Init();
int ret = _SDL_Init(flags);
//int ret = _SDL_Init(flags);
int ret = SDL_Init(flags);
return ret;
}

@ -124,34 +124,99 @@ string Process::doReadClassName (void * vptr)
return raw.substr(start,end-start);
}
//FIXME: cross-reference with ELF segment entries?
#include <mach/mach.h>
#include <mach/mach_vm.h>
#include <mach/vm_region.h>
#include <mach/vm_statistics.h>
#include <dlfcn.h>
const char *
inheritance_strings[] = {
"SHARE", "COPY", "NONE", "DONATE_COPY",
};
const char *
behavior_strings[] = {
"DEFAULT", "RANDOM", "SEQUENTIAL", "RESQNTL", "WILLNEED", "DONTNEED",
};
void Process::getMemRanges( vector<t_memrange> & ranges )
{
char buffer[1024];
char permissions[5]; // r/-, w/-, x/-, p/s, 0
FILE *mapFile = ::fopen("/proc/self/maps", "r");
size_t start, end, offset, device1, device2, node;
kern_return_t kr;
task_t the_task;
while (fgets(buffer, 1024, mapFile))
{
t_memrange temp;
temp.name[0] = 0;
sscanf(buffer, "%zx-%zx %s %zx %2zx:%2zx %zu %[^\n]",
&start,
&end,
(char*)&permissions,
&offset, &device1, &device2, &node,
(char*)temp.name);
temp.start = (void *) start;
temp.end = (void *) end;
temp.read = permissions[0] == 'r';
temp.write = permissions[1] == 'w';
temp.execute = permissions[2] == 'x';
temp.shared = permissions[3] == 's';
temp.valid = true;
ranges.push_back(temp);
}
the_task = mach_task_self();
vm_size_t vmsize;
vm_address_t address;
vm_region_basic_info_data_t info;
mach_msg_type_number_t info_count;
vm_region_flavor_t flavor;
memory_object_name_t object;
kr = KERN_SUCCESS;
address = 0;
do {
flavor = VM_REGION_BASIC_INFO;
info_count = VM_REGION_BASIC_INFO_COUNT;
kr = vm_region(the_task, &address, &vmsize, flavor,
(vm_region_info_t)&info, &info_count, &object);
if (kr == KERN_SUCCESS) {
if (info.reserved==1) {
address += vmsize;
continue;
}
Dl_info dlinfo;
int dlcheck;
dlcheck = dladdr((const void*)address, &dlinfo);
if (dlcheck==0) {
dlinfo.dli_fname = "";
}
t_memrange temp;
strncpy( temp.name, dlinfo.dli_fname, 1023 );
temp.name[1023] = 0;
temp.start = (void *) address;
temp.end = (void *) (address+vmsize);
temp.read = (info.protection & VM_PROT_READ);
temp.write = (info.protection & VM_PROT_WRITE);
temp.execute = (info.protection & VM_PROT_EXECUTE);
temp.shared = info.shared;
temp.valid = true;
ranges.push_back(temp);
fprintf(stderr,
"%08x-%08x %8uK %c%c%c/%c%c%c %11s %6s %10s uwir=%hu sub=%u dlname: %s\n",
address, (address + vmsize), (vmsize >> 10),
(info.protection & VM_PROT_READ) ? 'r' : '-',
(info.protection & VM_PROT_WRITE) ? 'w' : '-',
(info.protection & VM_PROT_EXECUTE) ? 'x' : '-',
(info.max_protection & VM_PROT_READ) ? 'r' : '-',
(info.max_protection & VM_PROT_WRITE) ? 'w' : '-',
(info.max_protection & VM_PROT_EXECUTE) ? 'x' : '-',
inheritance_strings[info.inheritance],
(info.shared) ? "shared" : "-",
behavior_strings[info.behavior],
info.user_wired_count,
info.reserved,
dlinfo.dli_fname);
address += vmsize;
} else if (kr != KERN_INVALID_ADDRESS) {
/*if (the_task != MACH_PORT_NULL) {
mach_port_deallocate(mach_task_self(), the_task);
}*/
return;
}
} while (kr != KERN_INVALID_ADDRESS);
/* if (the_task != MACH_PORT_NULL) {
mach_port_deallocate(mach_task_self(), the_task);
}*/
}
uint32_t Process::getBase()

@ -105,6 +105,12 @@ void VersionInfoFactory::ParseVersion (TiXmlElement* entry, VersionInfo* mem)
// this is wrong... I'm not going to do base image relocation on linux though.
mem->setBase(0x0);
}
else if(os == "darwin")
{
mem->setOS(OS_APPLE);
// this is wrong... I'm not going to do base image relocation on linux though.
mem->setBase(0x0);
}
else
{
return; // ignore it if it's invalid

@ -65,20 +65,20 @@ namespace DFHack
bool save (const char * filename)
{
std::ofstream outfile (filename);
fprintf(stderr,"Save: Initialized stream\n");
//fprintf(stderr,"Save: Initialized stream\n");
if(outfile.bad())
return false;
fprintf(stderr,"Save: Iterating...\n");
//fprintf(stderr,"Save: Iterating...\n");
for(auto iter = history.begin();iter < history.end(); iter++)
{
fprintf(stderr,"Save: Dumping %s\n",(*iter).c_str());
//fprintf(stderr,"Save: Dumping %s\n",(*iter).c_str());
outfile << *iter << std::endl;
fprintf(stderr,"Save: Flushing\n");
//fprintf(stderr,"Save: Flushing\n");
outfile.flush();
}
fprintf(stderr,"Save: Closing\n");
//fprintf(stderr,"Save: Closing\n");
outfile.close();
fprintf(stderr,"Save: Done\n");
//fprintf(stderr,"Save: Done\n");
return true;
}
/// add a command to the history

@ -75,7 +75,9 @@ namespace DFHack
SC_MAP_UNLOADED = 3,
SC_VIEWSCREEN_CHANGED = 4,
SC_CORE_INITIALIZED = 5,
SC_BEGIN_UNLOAD = 6
SC_BEGIN_UNLOAD = 6,
SC_PAUSED = 7,
SC_UNPAUSED = 8
};
// Core is a singleton. Why? Because it is closely tied to SDL calls. It tracks the global state of DF.
@ -83,10 +85,17 @@ namespace DFHack
// Better than tracking some weird variables all over the place.
class DFHACK_EXPORT Core
{
#ifdef _DARWIN
friend int ::DFH_SDL_NumJoysticks(void);
friend void ::DFH_SDL_Quit(void);
friend int ::DFH_SDL_PollEvent(SDL::Event *);
friend int ::DFH_SDL_Init(uint32_t flags);
#else
friend int ::SDL_NumJoysticks(void);
friend void ::SDL_Quit(void);
friend int ::SDL_PollEvent(SDL::Event *);
friend int ::SDL_Init(uint32_t flags);
#endif
friend int ::wgetch(WINDOW * w);
friend int ::egg_init(void);
friend int ::egg_shutdown(void);
@ -221,6 +230,7 @@ namespace DFHack
// for state change tracking
void *last_local_map_ptr;
df::viewscreen *top_viewscreen;
bool last_pause_state;
// Very important!
bool started;

@ -44,6 +44,12 @@ namespace SDL
// these functions are here because they call into DFHack::Core and therefore need to
// be declared as friend functions/known
#ifdef _DARWIN
DFhackCExport int DFH_SDL_NumJoysticks(void);
DFhackCExport void DFH_SDL_Quit(void);
DFhackCExport int DFH_SDL_PollEvent(SDL::Event* event);
DFhackCExport int DFH_SDL_Init(uint32_t flags);
#endif
DFhackCExport int SDL_NumJoysticks(void);
DFhackCExport void SDL_Quit(void);
DFhackCExport int SDL_PollEvent(SDL::Event* event);

@ -39,6 +39,8 @@ if dfhack.is_core_context then
SC_MAP_UNLOADED = 3
SC_VIEWSCREEN_CHANGED = 4
SC_CORE_INITIALIZED = 5
SC_PAUSED = 7
SC_UNPAUSED = 8
end
-- Error handling

@ -0,0 +1,15 @@
#!/bin/sh
PWD=`dirname "${0}"`
#thanks to Iriel for figuring this out
OSREV=`uname -r | cut -d. -f1`
if [ "$OSREV" -ge 11 ] ; then
export DYLD_INSERT_LIBRARIES=./hack/libdfhack.dylib
export DYLD_LIBRARY_PATH=${PWD}/hack:${PWD}/libs
export DYLD_FRAMEWORK_PATH=${PWD}/hack:${PWD}/libs
else
export DYLD_INSERT_LIBRARIES=./hack/libdfhack.dylib
export DYLD_FALLBACK_LIBRARY_PATH=${PWD}/hack:${PWD}/libs
export DYLD_FALLBACK_FRAMEWORK_PATH=${PWD}/hack:${PWD}/libs
fi
export DYLD_FORCE_FLAT_NAMESPACE=1
cd "${PWD}"; ./dwarfort.exe

@ -0,0 +1,9 @@
#!/bin/sh
DF_DIR=$(dirname "$0")
cd "${DF_DIR}"
export DYLD_LIBRARY_PATH=${PWD}/hack:${PWD}/libs
export DYLD_FRAMEWORK_PATH=${PWD}/hack${PWD}/libs
exec hack/dfhack-run "$@"

@ -36,7 +36,7 @@ if (BUILD_DWARFEXPORT)
add_subdirectory (dwarfexport)
endif()
OPTION(BUILD_RUBY "Build ruby binding." OFF)
OPTION(BUILD_RUBY "Build ruby binding." ON)
if (BUILD_RUBY)
add_subdirectory (ruby)
endif()

@ -7,8 +7,8 @@ ENDIF()
include_directories("${dfhack_SOURCE_DIR}/library/include")
include_directories("${dfhack_SOURCE_DIR}/library/proto")
include_directories("${dfhack_SOURCE_DIR}/library/depends/xgetopt")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/proto")
include_directories("${dfhack_SOURCE_DIR}/library/depends/xgetopt")
MACRO(CAR var)
SET(${var} ${ARGV1})

@ -354,7 +354,9 @@ module DFHack
end
def empty? ; length == 0 ; end
def flatten ; map { |e| e.respond_to?(:flatten) ? e.flatten : e }.flatten ; end
def index(elem=nil, &b) ; (0...length).find { |i| b ? b[self[i]] : self[i] == elem } ; end
def index(e=nil, &b) ; (0...length).find { |i| b ? b[self[i]] : self[i] == e } ; end
def first ; self[0] ; end
def last ; self[length-1] ; end
end
class StaticArray < MemStruct
attr_accessor :_tglen, :_length, :_indexenum, :_tg
@ -378,12 +380,18 @@ module DFHack
def [](i)
i = _indexenum.int(i) if _indexenum
i += @_length if i < 0
_tgat(i)._get
if t = _tgat(i)
t._get
end
end
def []=(i, v)
i = _indexenum.int(i) if _indexenum
i += @_length if i < 0
_tgat(i)._set(v)
if t = _tgat(i)
t._set(v)
else
raise 'index out of bounds'
end
end
include Enumerable
@ -442,7 +450,7 @@ module DFHack
if idx >= length
insert_at(idx, 0)
elsif idx < 0
raise 'invalid idx'
raise 'index out of bounds'
end
@_tg._at(valueptr_at(idx))._set(v)
end
@ -528,7 +536,7 @@ module DFHack
if idx >= length
insert_at(idx, v)
elsif idx < 0
raise 'invalid idx'
raise 'index out of bounds'
else
DFHack.memory_vectorbool_setat(@_memaddr, idx, v)
end
@ -580,7 +588,7 @@ module DFHack
idx = _indexenum.int(idx) if _indexenum
idx += length if idx < 0
if idx >= length or idx < 0
raise 'invalid idx'
raise 'index out of bounds'
else
DFHack.memory_bitarray_set(@_memaddr, idx, v)
end
@ -606,11 +614,17 @@ module DFHack
end
def [](i)
i += _length if i < 0
_tgat(i)._get
if t = _tgat(i)
t._get
end
end
def []=(i, v)
i += _length if i < 0
_tgat(i)._set(v)
if t = _tgat(i)
t._set(v)
else
raise 'index out of bounds'
end
end
def _set(a)
a.each_with_index { |v, i| self[i] = v }

@ -194,6 +194,8 @@ DFhackCExport command_result plugin_onstatechange ( color_ostream &out, state_ch
// if we go through plugin_eval at BEGIN_UNLOAD, it'll
// try to get the suspend lock and deadlock at df exit
case SC_BEGIN_UNLOAD : return CR_OK;
SCASE(PAUSED);
SCASE(UNPAUSED);
#undef SCASE
}

@ -1 +1 @@
Subproject commit 17b653665567a5f1df628217820f76bb0b9c70a5
Subproject commit 5d4f06d785f8a9933679fe3caa12c18215e9674d

@ -0,0 +1,58 @@
function fixnaked()
local total_fixed = 0
local total_uncovered = 0
local total_noshirt = 0
local total_noshoes = 0
for fnUnitCount,fnUnit in ipairs(df.global.world.units.all) do
if fnUnit.race == df.global.ui.race_id then
local listEvents = fnUnit.status.recent_events
--for lkey,lvalue in pairs(listEvents) do
-- print(df.unit_thought_type[lvalue.type],lvalue.type,lvalue.age,lvalue.subtype,lvalue.severity)
--end
local found = 1
local fixed = 0
while found == 1 do
local events = fnUnit.status.recent_events
found = 0
for k,v in pairs(events) do
if v.type == 109 then
events:erase(k)
found = 1
total_uncovered = total_uncovered + 1
fixed = 1
break
end
if v.type == 110 then
events:erase(k)
found = 1
total_noshirt = total_noshirt + 1
fixed = 1
break
end
if v.type == 111 then
events:erase(k)
found = 1
total_noshoes = total_noshoes + 1
fixed = 1
break
end
end
end
if fixed == 1 then
total_fixed = total_fixed + 1
print(total_fixed, total_uncovered+total_noshirt+total_noshoes,dfhack.TranslateName(dfhack.units.getVisibleName(fnUnit)))
end
end
end
print("thought 109 = "..df.unit_thought_type[109])
print("thought 110 = "..df.unit_thought_type[110])
print("thought 111 = "..df.unit_thought_type[111])
print("Total Fixed: "..total_fixed)
print("Total thoughts removed: "..total_uncovered)
print("Total thoughts removed: "..total_noshirt)
print("Total thoughts removed: "..total_noshoes)
end
fixnaked()