Petr Mrázek 2011-08-27 15:05:33 +02:00
commit a3552301a8
3 changed files with 35 additions and 19 deletions

@ -1,6 +1,6 @@
function friendship_in.patch()
pos=GetTextRegion().start
local crace=add_race --offsets.getEx("CurrentRace")
local crace=VersionInfo.getGroup("Creatures"):getAddress("current_race")
hits={}
i=1
repeat

@ -129,7 +129,11 @@ static int GetMod(lua_State *L)
st.push(pos);
return 1;
}
#ifdef LINUX_BUILD
static size_t __attribute__((stdcall)) PushValue(size_t ret,uint32_t eax,uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t edi,uint32_t esi,uint32_t esp,uint32_t ebp)
#else
static size_t __stdcall PushValue(size_t ret,uint32_t eax,uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t edi,uint32_t esi,uint32_t esp,uint32_t ebp)
#endif
{
lua::state st=lua::glua::Get();
st.getglobal("OnFunction");

@ -62,36 +62,43 @@ bool isAddr(uint32_t *trg,vector<t_memrange> & ranges)
return false;
}
void outputHex(uint8_t *buf,uint8_t *lbuf,size_t len,size_t start,Console &con,vector<t_memrange> & ranges)
void outputHex(uint8_t *buf,uint8_t *lbuf,size_t len,size_t start,Core *c,vector<t_memrange> & ranges)
{
Console &con=c->con;
const size_t page_size=16;
con.clear();
const size_t page_size=16;
for(size_t i=0;i<len;i+=page_size)
{
con.print("%8x ",i+start);
con.gotoxy(1,i/page_size+1);
con.print("0x%08X ",i+start);
for(size_t j=0;(j<page_size) && (i+j<len);j++)
{
if(j%4==0)
{
con.reset_color();
if(isAddr((uint32_t *)(buf+j+i),ranges))
con.color(Console::COLOR_LIGHTRED);
con.color(Console::COLOR_LIGHTRED); //coloring in the middle does not work
//TODO make something better?
}
if(lbuf[j+i]!=buf[j+i])
con.print("*%2x",buf[j+i]);
con.print("*%02X",buf[j+i]); //if modfied show a star
else
con.print(" %2x",buf[j+i]);
con.print(" %02X",buf[j+i]);
}
con.reset_color();
con.print(" | ");
for(size_t j=0;(j<page_size) && (i+j<len);j++)
if(buf[j+i]>20)
if((buf[j+i]>31)&&(buf[j+i]<128)) //only printable ascii
con.print("%c",buf[j+i]);
else
con.print(".");
con.print("\n");
//con.print("\n");
}
con.print("\n");
con.flush();
}
void Deinit()
{
@ -104,15 +111,17 @@ void Deinit()
}
DFhackCExport command_result plugin_onupdate ( Core * c )
{
mymutex->lock();
if(memdata.state==STATE_OFF)
{
mymutex->unlock();
return CR_OK;
}
Console &con=c->con;
//Console &con=c->con;
uint64_t time2 = GetTimeMs64();
uint64_t delta = time2-timeLast;
if(memdata.refresh!=0)
if(delta<memdata.refresh)
{
@ -122,7 +131,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
timeLast = time2;
c->p->read(memdata.addr,memdata.len,memdata.buf);
outputHex(memdata.buf,memdata.lbuf,memdata.len,memdata.addr,con,memdata.ranges);
outputHex(memdata.buf,memdata.lbuf,memdata.len,memdata.addr,c,memdata.ranges);
memcpy(memdata.lbuf, memdata.buf, memdata.len);
if(memdata.refresh==0)
Deinit();
@ -137,6 +146,7 @@ DFhackCExport command_result memview (Core * c, vector <string> & parameters)
memdata.addr=convert(parameters[0],true);
if(memdata.addr==0)
{
Deinit();
memdata.state=STATE_OFF;
mymutex->unlock();
return CR_OK;
@ -176,7 +186,9 @@ DFhackCExport command_result memview (Core * c, vector <string> & parameters)
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
mymutex->lock();
Deinit();
return CR_OK;
delete mymutex;
mymutex->unlock();
return CR_OK;
}