Header changes/cleanup.
parent
1284b30f79
commit
9db20bd84d
@ -1,6 +1,6 @@
|
||||
#include "Internal.h"
|
||||
#include "dfhack/DataDefs.h"
|
||||
#include "dfhack/MiscUtils.h"
|
||||
#include "DataDefs.h"
|
||||
#include "MiscUtils.h"
|
||||
|
||||
// Object constructors
|
||||
#include "dfhack/df/static.ctors.inc"
|
||||
#include "df/static.ctors.inc"
|
||||
|
@ -0,0 +1,104 @@
|
||||
/*
|
||||
https://github.com/peterix/dfhack
|
||||
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product documentation
|
||||
would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "Export.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <climits>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
void print_bits ( T val, DFHack::Console& out )
|
||||
{
|
||||
stringstream strs;
|
||||
T n_bits = sizeof ( val ) * CHAR_BIT;
|
||||
int cnt;
|
||||
for ( unsigned i = 0; i < n_bits; ++i )
|
||||
{
|
||||
cnt = i/10;
|
||||
strs << cnt << " ";
|
||||
}
|
||||
strs << endl;
|
||||
for ( unsigned i = 0; i < n_bits; ++i )
|
||||
{
|
||||
cnt = i%10;
|
||||
strs << cnt << " ";
|
||||
}
|
||||
strs << endl;
|
||||
for ( unsigned i = 0; i < n_bits; ++i )
|
||||
{
|
||||
strs << "--";
|
||||
}
|
||||
strs << endl;
|
||||
for ( unsigned i = 0; i < n_bits; ++i )
|
||||
{
|
||||
strs<< !!( val & 1 ) << " ";
|
||||
val >>= 1;
|
||||
}
|
||||
strs << endl;
|
||||
out.print(strs.str().c_str());
|
||||
}
|
||||
|
||||
//FIXME: Error 8 error C4519: default template arguments are only allowed on a class template
|
||||
template <typename CT, typename FT, typename AT/* = FT*/>
|
||||
CT *binsearch_in_vector(std::vector<CT*> &vec, FT CT::*field, AT value)
|
||||
{
|
||||
int min = -1, max = (int)vec.size();
|
||||
CT **p = vec.data();
|
||||
FT key = (FT)value;
|
||||
for (;;)
|
||||
{
|
||||
int mid = (min + max)>>1;
|
||||
if (mid == min)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
FT midv = p[mid]->*field;
|
||||
if (midv == key)
|
||||
{
|
||||
return p[mid];
|
||||
}
|
||||
else if (midv < key)
|
||||
{
|
||||
min = mid;
|
||||
}
|
||||
else
|
||||
{
|
||||
max = mid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of milliseconds elapsed since the UNIX epoch.
|
||||
* Works on both windows and linux.
|
||||
* source: http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c
|
||||
*/
|
||||
DFHACK_EXPORT uint64_t GetTimeMs64();
|
@ -1,269 +0,0 @@
|
||||
/*
|
||||
https://github.com/peterix/dfhack
|
||||
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product documentation
|
||||
would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <climits>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
#include <dfhack/Process.h>
|
||||
#include <dfhack/VersionInfo.h>
|
||||
#include <dfhack/Vector.h>
|
||||
|
||||
void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
|
||||
{
|
||||
cout << "----==== " << name << " ====----" << endl;
|
||||
DFHack::DfVector <uint32_t> vect(p,addr);
|
||||
for(uint32_t i = 0; i < vect.size();i++)
|
||||
{
|
||||
uint32_t addr = vect[i];
|
||||
cout << p->readSTLString(addr) << endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
void DumpObjVtables (const char * name, DFHack::Process *p, uint32_t addr)
|
||||
{
|
||||
cout << "----==== " << name << " ====----" << endl;
|
||||
DFHack::DfVector <uint32_t> vect(p,addr);
|
||||
for(uint32_t i = 0; i < vect.size();i++)
|
||||
{
|
||||
uint32_t addr = vect[i];
|
||||
uint32_t vptr = p->readDWord(addr);
|
||||
cout << p->readClassName(vptr) << endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr)
|
||||
{
|
||||
cout << "----==== " << name << " ====----" << endl;
|
||||
DFHack::DfVector <uint32_t> vect(p,addr);
|
||||
for(uint32_t i = 0; i < vect.size();i++)
|
||||
{
|
||||
uint32_t number = vect[i];
|
||||
cout << number << endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
address = absolute address of dump start
|
||||
length = length in lines. 1 line = 16 bytes
|
||||
*/
|
||||
/*
|
||||
void hexdump (DFHack::Context *DF, uint32_t address, uint32_t length)
|
||||
{
|
||||
char *buf = new char[length];
|
||||
DF->ReadRaw(address, length, (uint8_t *) buf);
|
||||
uint32_t i = 0;
|
||||
while (i < length)
|
||||
{
|
||||
// leading offset
|
||||
if(i%16 == 0)
|
||||
cout << "0x" << hex << setw(8) << address + i << "| ";
|
||||
// bytes
|
||||
for(int k = 0; k < 4; k++)
|
||||
{
|
||||
cout << hex << setw(2) << int(static_cast<unsigned char>(buf[i])) << " ";
|
||||
i++;
|
||||
if(i == length) break;
|
||||
}
|
||||
if(i%16 == 0 || i>= length)
|
||||
{
|
||||
cout << endl;
|
||||
}
|
||||
else if(i%4 == 0)
|
||||
{
|
||||
cout << " ";
|
||||
}
|
||||
}
|
||||
delete buf;
|
||||
}
|
||||
|
||||
void interleave_hex (DFHack::Context* DF, vector < uint32_t > & addresses, uint32_t length)
|
||||
{
|
||||
vector <char * > bufs;
|
||||
|
||||
for(uint32_t counter = 0; counter < addresses.size(); counter ++)
|
||||
{
|
||||
char * buf = new char[length * 16];
|
||||
DF->ReadRaw(addresses[counter], length * 16, (uint8_t *) buf);
|
||||
bufs.push_back(buf);
|
||||
}
|
||||
cout << setfill('0');
|
||||
|
||||
// output a header
|
||||
cout << "line offset ";
|
||||
for (uint32_t obj = 0; obj < addresses.size(); obj++)
|
||||
{
|
||||
cout << "0x" << hex << setw(9) << addresses[obj] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
for(uint32_t offs = 0 ; offs < length * 16; offs += 4)
|
||||
{
|
||||
if((!(offs % 16)) && offs != 0)
|
||||
{
|
||||
cout << endl;
|
||||
}
|
||||
cout << setfill(' ');
|
||||
cout << dec << setw(4) << offs/4 << " ";
|
||||
cout << setfill('0');
|
||||
cout << "0x" << hex << setw(4) << offs << " ";
|
||||
for (uint32_t object = 0; object < bufs.size(); object++)
|
||||
{
|
||||
// bytes
|
||||
for(int k = 0; k < 4; k++)
|
||||
{
|
||||
uint8_t data = bufs[object][offs + k];
|
||||
cout << hex << setw(2) << int(static_cast<unsigned char>(data)) << " ";
|
||||
}
|
||||
cout << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
for(uint32_t counter = 0; counter < addresses.size(); counter ++)
|
||||
{
|
||||
delete bufs[counter];
|
||||
}
|
||||
}
|
||||
*/
|
||||
template <typename T>
|
||||
void print_bits ( T val, DFHack::Console& out )
|
||||
{
|
||||
stringstream strs;
|
||||
T n_bits = sizeof ( val ) * CHAR_BIT;
|
||||
int cnt;
|
||||
for ( unsigned i = 0; i < n_bits; ++i )
|
||||
{
|
||||
cnt = i/10;
|
||||
strs << cnt << " ";
|
||||
}
|
||||
strs << endl;
|
||||
for ( unsigned i = 0; i < n_bits; ++i )
|
||||
{
|
||||
cnt = i%10;
|
||||
strs << cnt << " ";
|
||||
}
|
||||
strs << endl;
|
||||
for ( unsigned i = 0; i < n_bits; ++i )
|
||||
{
|
||||
strs << "--";
|
||||
}
|
||||
strs << endl;
|
||||
for ( unsigned i = 0; i < n_bits; ++i )
|
||||
{
|
||||
strs<< !!( val & 1 ) << " ";
|
||||
val >>= 1;
|
||||
}
|
||||
strs << endl;
|
||||
out.print(strs.str().c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
// this is probably completely bogus
|
||||
std::string PrintSplatterType (int16_t mat1, int32_t mat2, vector<DFHack::t_matgloss> &creature_types)
|
||||
{
|
||||
std::string ret;
|
||||
switch (mat1)
|
||||
{
|
||||
case 0:
|
||||
return "Rock";
|
||||
case 1:
|
||||
return "Amber";
|
||||
case 2:
|
||||
return "Coral";
|
||||
case 3:
|
||||
return "Green Glass";
|
||||
case 4:
|
||||
return "Clear Glass";
|
||||
case 5:
|
||||
return "Crystal Glass";
|
||||
case 6:
|
||||
return "Water";
|
||||
case 7:
|
||||
return "Coal";
|
||||
case 8:
|
||||
return "Potash";
|
||||
case 9:
|
||||
return "Ash";
|
||||
case 10:
|
||||
return "Pearlash";
|
||||
case 11:
|
||||
return "Lye";
|
||||
case 12:
|
||||
return "Mud";
|
||||
case 13:
|
||||
return "Vomit";
|
||||
case 14:
|
||||
return "Salt";
|
||||
case 15:
|
||||
return "Filth";
|
||||
case 16:
|
||||
return "Frozen? Filth";
|
||||
case 18:
|
||||
return "Grime";
|
||||
case 0xF2:
|
||||
return "Very Specific Blood (references a named creature)";
|
||||
case 0x2A:
|
||||
case 0x2B:
|
||||
if(mat2 != -1)
|
||||
{
|
||||
ret += creature_types[mat2].id;
|
||||
ret += " ";
|
||||
}
|
||||
ret += "Blood";
|
||||
return ret;
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//FIXME: Error 8 error C4519: default template arguments are only allowed on a class template
|
||||
template <typename CT, typename FT, typename AT/* = FT*/>
|
||||
CT *binsearch_in_vector(std::vector<CT*> &vec, FT CT::*field, AT value) {
|
||||
int min = -1, max = (int)vec.size();
|
||||
CT **p = vec.data();
|
||||
FT key = (FT)value;
|
||||
for (;;) {
|
||||
int mid = (min + max)>>1;
|
||||
if (mid == min)
|
||||
return NULL;
|
||||
FT midv = p[mid]->*field;
|
||||
if (midv == key)
|
||||
return p[mid];
|
||||
else if (midv < key)
|
||||
min = mid;
|
||||
else
|
||||
max = mid;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
// Returns the amount of milliseconds elapsed since the UNIX epoch.
|
||||
// Works on both windows and linux.
|
||||
// source: http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c
|
||||
|
||||
#ifndef LINUX_BUILD
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <ctime>
|
||||
#endif
|
||||
|
||||
#ifdef LINUX_BUILD // Linux
|
||||
uint64_t GetTimeMs64()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
uint64_t ret = tv.tv_usec;
|
||||
|
||||
// Convert from micro seconds (10^-6) to milliseconds (10^-3)
|
||||
ret /= 1000;
|
||||
// Adds the seconds (10^0) after converting them to milliseconds (10^-3)
|
||||
ret += (tv.tv_sec * 1000);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#else // Windows
|
||||
uint64_t GetTimeMs64()
|
||||
{
|
||||
FILETIME ft;
|
||||
LARGE_INTEGER li;
|
||||
|
||||
// Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC)
|
||||
// and copy it to a LARGE_INTEGER structure.
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
li.LowPart = ft.dwLowDateTime;
|
||||
li.HighPart = ft.dwHighDateTime;
|
||||
|
||||
uint64_t ret = li.QuadPart;
|
||||
// Convert from file time to UNIX epoch time.
|
||||
ret -= 116444736000000000LL;
|
||||
// From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals
|
||||
ret /= 10000;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
https://github.com/peterix/dfhack
|
||||
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product documentation
|
||||
would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifndef TERMUTIL_H
|
||||
#define TERMUTIL_H
|
||||
|
||||
#ifdef LINUX_BUILD
|
||||
// FIXME: is this ever true?
|
||||
bool TemporaryTerminal ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
bool TemporaryTerminal ()
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
HANDLE hStdOutput;
|
||||
hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (!GetConsoleScreenBufferInfo(hStdOutput, &csbi))
|
||||
{
|
||||
printf("GetConsoleScreenBufferInfo failed: %d\n", GetLastError());
|
||||
return false;
|
||||
}
|
||||
return ((!csbi.dwCursorPosition.X) && (!csbi.dwCursorPosition.Y));
|
||||
};
|
||||
|
||||
#endif // LINUX_BUILD
|
||||
|
||||
#endif
|
@ -1,194 +1,194 @@
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
#include <dfhack/Process.h>
|
||||
#include <dfhack/extra/stopwatch.h>
|
||||
#include <../depends/tthread/tinythread.h> //not sure if correct
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using namespace DFHack;
|
||||
|
||||
uint64_t timeLast=0;
|
||||
static tthread::mutex* mymutex=0;
|
||||
|
||||
struct memory_data
|
||||
{
|
||||
size_t addr;
|
||||
size_t len;
|
||||
size_t refresh;
|
||||
int state;
|
||||
uint8_t *buf,*lbuf;
|
||||
vector<t_memrange> ranges;
|
||||
}memdata;
|
||||
enum HEXVIEW_STATES
|
||||
{
|
||||
STATE_OFF,STATE_ON
|
||||
};
|
||||
DFhackCExport command_result memview (Core * c, vector <string> & parameters);
|
||||
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "memview";
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("memview","Shows memory in real time. Params: adrr length refresh_rate. If addr==0 then stop viewing",memview));
|
||||
memdata.state=STATE_OFF;
|
||||
mymutex=new tthread::mutex;
|
||||
return CR_OK;
|
||||
}
|
||||
size_t convert(const std::string& p,bool ishex=false)
|
||||
{
|
||||
size_t ret;
|
||||
std::stringstream conv;
|
||||
if(ishex)
|
||||
conv<<std::hex;
|
||||
conv<<p;
|
||||
conv>>ret;
|
||||
return ret;
|
||||
}
|
||||
bool isAddr(uint32_t *trg,vector<t_memrange> & ranges)
|
||||
{
|
||||
if(trg[0]%4==0)
|
||||
for(size_t i=0;i<ranges.size();i++)
|
||||
if(ranges[i].isInRange(trg[0]))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
void outputHex(uint8_t *buf,uint8_t *lbuf,size_t len,size_t start,Core *c,vector<t_memrange> & ranges)
|
||||
{
|
||||
#include "Core.h"
|
||||
#include "Console.h"
|
||||
#include "PluginManager.h"
|
||||
#include "MemAccess.h"
|
||||
#include "MiscUtils.h"
|
||||
#include <../depends/tthread/tinythread.h> //not sure if correct
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using namespace DFHack;
|
||||
|
||||
uint64_t timeLast=0;
|
||||
static tthread::mutex* mymutex=0;
|
||||
|
||||
struct memory_data
|
||||
{
|
||||
size_t addr;
|
||||
size_t len;
|
||||
size_t refresh;
|
||||
int state;
|
||||
uint8_t *buf,*lbuf;
|
||||
vector<t_memrange> ranges;
|
||||
}memdata;
|
||||
enum HEXVIEW_STATES
|
||||
{
|
||||
STATE_OFF,STATE_ON
|
||||
};
|
||||
DFhackCExport command_result memview (Core * c, vector <string> & parameters);
|
||||
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "memview";
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("memview","Shows memory in real time. Params: adrr length refresh_rate. If addr==0 then stop viewing",memview));
|
||||
memdata.state=STATE_OFF;
|
||||
mymutex=new tthread::mutex;
|
||||
return CR_OK;
|
||||
}
|
||||
size_t convert(const std::string& p,bool ishex=false)
|
||||
{
|
||||
size_t ret;
|
||||
std::stringstream conv;
|
||||
if(ishex)
|
||||
conv<<std::hex;
|
||||
conv<<p;
|
||||
conv>>ret;
|
||||
return ret;
|
||||
}
|
||||
bool isAddr(uint32_t *trg,vector<t_memrange> & ranges)
|
||||
{
|
||||
if(trg[0]%4==0)
|
||||
for(size_t i=0;i<ranges.size();i++)
|
||||
if(ranges[i].isInRange(trg[0]))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
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();
|
||||
|
||||
for(size_t i=0;i<len;i+=page_size)
|
||||
const size_t page_size=16;
|
||||
con.clear();
|
||||
|
||||
for(size_t i=0;i<len;i+=page_size)
|
||||
{
|
||||
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.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))
|
||||
|
||||
if(isAddr((uint32_t *)(buf+j+i),ranges))
|
||||
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("*%02X",buf[j+i]); //if modfied show a star
|
||||
else
|
||||
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]>31)&&(buf[j+i]<128)) //only printable ascii
|
||||
con.print("%c",buf[j+i]);
|
||||
else
|
||||
con.print(".");
|
||||
//con.print("\n");
|
||||
//TODO make something better?
|
||||
}
|
||||
if(lbuf[j+i]!=buf[j+i])
|
||||
con.print("*%02X",buf[j+i]); //if modfied show a star
|
||||
else
|
||||
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]>31)&&(buf[j+i]<128)) //only printable ascii
|
||||
con.print("%c",buf[j+i]);
|
||||
else
|
||||
con.print(".");
|
||||
//con.print("\n");
|
||||
}
|
||||
con.print("\n");
|
||||
con.flush();
|
||||
|
||||
}
|
||||
void Deinit()
|
||||
{
|
||||
if(memdata.state==STATE_ON)
|
||||
{
|
||||
memdata.state=STATE_OFF;
|
||||
delete [] memdata.buf;
|
||||
delete [] memdata.lbuf;
|
||||
}
|
||||
}
|
||||
DFhackCExport command_result plugin_onupdate ( Core * c )
|
||||
{
|
||||
|
||||
mymutex->lock();
|
||||
if(memdata.state==STATE_OFF)
|
||||
{
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
//Console &con=c->con;
|
||||
uint64_t time2 = GetTimeMs64();
|
||||
uint64_t delta = time2-timeLast;
|
||||
|
||||
if(memdata.refresh!=0)
|
||||
if(delta<memdata.refresh)
|
||||
{
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
timeLast = time2;
|
||||
|
||||
c->p->read(memdata.addr,memdata.len,memdata.buf);
|
||||
outputHex(memdata.buf,memdata.lbuf,memdata.len,memdata.addr,c,memdata.ranges);
|
||||
memcpy(memdata.lbuf, memdata.buf, memdata.len);
|
||||
if(memdata.refresh==0)
|
||||
Deinit();
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
|
||||
}
|
||||
DFhackCExport command_result memview (Core * c, vector <string> & parameters)
|
||||
{
|
||||
mymutex->lock();
|
||||
c->p->getMemRanges(memdata.ranges);
|
||||
memdata.addr=convert(parameters[0],true);
|
||||
if(memdata.addr==0)
|
||||
{
|
||||
Deinit();
|
||||
memdata.state=STATE_OFF;
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
Deinit();
|
||||
bool isValid=false;
|
||||
for(size_t i=0;i<memdata.ranges.size();i++)
|
||||
if(memdata.ranges[i].isInRange(memdata.addr))
|
||||
isValid=true;
|
||||
if(!isValid)
|
||||
{
|
||||
c->con.printerr("Invalid address:%x\n",memdata.addr);
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
memdata.state=STATE_ON;
|
||||
}
|
||||
if(parameters.size()>1)
|
||||
memdata.len=convert(parameters[1]);
|
||||
else
|
||||
memdata.len=20*16;
|
||||
|
||||
if(parameters.size()>2)
|
||||
memdata.refresh=convert(parameters[2]);
|
||||
else
|
||||
memdata.refresh=0;
|
||||
|
||||
|
||||
uint8_t *buf,*lbuf;
|
||||
memdata.buf=new uint8_t[memdata.len];
|
||||
memdata.lbuf=new uint8_t[memdata.len];
|
||||
c->p->getMemRanges(memdata.ranges);
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
mymutex->lock();
|
||||
Deinit();
|
||||
delete mymutex;
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
con.print("\n");
|
||||
con.flush();
|
||||
|
||||
}
|
||||
void Deinit()
|
||||
{
|
||||
if(memdata.state==STATE_ON)
|
||||
{
|
||||
memdata.state=STATE_OFF;
|
||||
delete [] memdata.buf;
|
||||
delete [] memdata.lbuf;
|
||||
}
|
||||
}
|
||||
DFhackCExport command_result plugin_onupdate ( Core * c )
|
||||
{
|
||||
|
||||
mymutex->lock();
|
||||
if(memdata.state==STATE_OFF)
|
||||
{
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
//Console &con=c->con;
|
||||
uint64_t time2 = GetTimeMs64();
|
||||
uint64_t delta = time2-timeLast;
|
||||
|
||||
if(memdata.refresh!=0)
|
||||
if(delta<memdata.refresh)
|
||||
{
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
timeLast = time2;
|
||||
|
||||
c->p->read(memdata.addr,memdata.len,memdata.buf);
|
||||
outputHex(memdata.buf,memdata.lbuf,memdata.len,memdata.addr,c,memdata.ranges);
|
||||
memcpy(memdata.lbuf, memdata.buf, memdata.len);
|
||||
if(memdata.refresh==0)
|
||||
Deinit();
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
|
||||
}
|
||||
DFhackCExport command_result memview (Core * c, vector <string> & parameters)
|
||||
{
|
||||
mymutex->lock();
|
||||
c->p->getMemRanges(memdata.ranges);
|
||||
memdata.addr=convert(parameters[0],true);
|
||||
if(memdata.addr==0)
|
||||
{
|
||||
Deinit();
|
||||
memdata.state=STATE_OFF;
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
Deinit();
|
||||
bool isValid=false;
|
||||
for(size_t i=0;i<memdata.ranges.size();i++)
|
||||
if(memdata.ranges[i].isInRange(memdata.addr))
|
||||
isValid=true;
|
||||
if(!isValid)
|
||||
{
|
||||
c->con.printerr("Invalid address:%x\n",memdata.addr);
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
memdata.state=STATE_ON;
|
||||
}
|
||||
if(parameters.size()>1)
|
||||
memdata.len=convert(parameters[1]);
|
||||
else
|
||||
memdata.len=20*16;
|
||||
|
||||
if(parameters.size()>2)
|
||||
memdata.refresh=convert(parameters[2]);
|
||||
else
|
||||
memdata.refresh=0;
|
||||
|
||||
|
||||
uint8_t *buf,*lbuf;
|
||||
memdata.buf=new uint8_t[memdata.len];
|
||||
memdata.lbuf=new uint8_t[memdata.len];
|
||||
c->p->getMemRanges(memdata.ranges);
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
mymutex->lock();
|
||||
Deinit();
|
||||
delete mymutex;
|
||||
mymutex->unlock();
|
||||
return CR_OK;
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 8ffad51635ceeae55870106a75f3dd84b044ea5a
|
||||
Subproject commit 355674a508d72349983455f04791b4481b6c1515
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue