Merge branch 'bartavelle' of git://bigbox.banquise.net/dfhack

develop
Petr Mrázek 2010-04-20 20:27:45 +02:00
commit 14895378d8
11 changed files with 144 additions and 9 deletions

@ -704,6 +704,25 @@ void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
val = D_SHMHDR->value;
}
float SHMProcess::readFloat (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
gcc_barrier
d->SetAndWait(CORE_READ_DWORD);
return D_SHMHDR->value;
}
void SHMProcess::readFloat (const uint32_t offset, float &val)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
gcc_barrier
d->SetAndWait(CORE_READ_DWORD);
val = D_SHMHDR->value;
}
/*
* WRITING
*/
@ -890,4 +909,4 @@ bool SHMProcess::Private::Aux_Core_Attach(bool & versionOK, pid_t & PID)
if(useYield) cerr << "Using Yield!" << endl;
#endif
return true;
}
}

@ -430,6 +430,17 @@ void WineProcess::readDWord (const uint32_t offset, uint32_t &val)
read(offset, 4, (uint8_t *) &val);
}
float WineProcess::readFloat (const uint32_t offset)
{
float val;
read(offset, 4, (uint8_t *) &val);
return val;
}
void WineProcess::readFloat (const uint32_t offset, float &val)
{
read(offset, 4, (uint8_t *) &val);
}
/*
* WRITING
*/
@ -588,4 +599,4 @@ string WineProcess::readClassName (uint32_t vptr)
string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 2);// trim @@ from end
return raw;
}
}

@ -417,6 +417,17 @@ void NormalProcess::readDWord (const uint32_t offset, uint32_t &val)
read(offset, 4, (uint8_t *) &val);
}
float NormalProcess::readFloat (const uint32_t offset)
{
float val;
read(offset, 4, (uint8_t *) &val);
return val;
}
void NormalProcess::readFloat (const uint32_t offset, float &val)
{
read(offset, 4, (uint8_t *) &val);
}
/*
* WRITING
*/
@ -540,4 +551,4 @@ string NormalProcess::readClassName (uint32_t vptr)
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length();
return raw.substr(start,end-start);
}
}

@ -762,6 +762,26 @@ void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
val = D_SHMHDR->value;
}
float SHMProcess::readFloat (const uint32_t offset)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
d->SetAndWait(CORE_READ_DWORD);
return D_SHMHDR->value;
}
void SHMProcess::readFloat (const uint32_t offset, float &val)
{
if(!d->locked) throw Error::MemoryAccessDenied();
D_SHMHDR->address = offset;
full_barrier
d->SetAndWait(CORE_READ_DWORD);
val = D_SHMHDR->value;
}
/*
* WRITING
*/
@ -944,4 +964,4 @@ bool SHMProcess::Private::Aux_Core_Attach(bool & versionOK, uint32_t & PID)
if(useYield) cerr << "Using Yield!" << endl;
#endif
return true;
}
}

@ -365,6 +365,20 @@ void NormalProcess::readDWord (const uint32_t offset, uint32_t &result)
throw Error::MemoryAccessDenied();
}
float NormalProcess::readFloat (const uint32_t offset)
{
float result;
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(float), NULL))
throw Error::MemoryAccessDenied();
return result;
}
void NormalProcess::readFloat (const uint32_t offset, float &result)
{
if(!ReadProcessMemory(d->my_handle, (int*) offset, &result, sizeof(float), NULL))
throw Error::MemoryAccessDenied();
}
void NormalProcess::read (const uint32_t offset, uint32_t size, uint8_t *target)
{
if(!ReadProcessMemory(d->my_handle, (int*) offset, target, size, NULL))
@ -489,4 +503,4 @@ string NormalProcess::readClassName (uint32_t vptr)
string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 2);// trim @@ from end
return raw;
}
}

@ -81,7 +81,9 @@ namespace DFHack
virtual bool forceresume() = 0;
virtual uint32_t readDWord(const uint32_t address) = 0;
virtual float readFloat(const uint32_t address) = 0;
virtual void readDWord(const uint32_t address, uint32_t & value) = 0;
virtual void readFloat(const uint32_t address, float & value) = 0;
virtual uint16_t readWord(const uint32_t address) = 0;
virtual void readWord(const uint32_t address, uint16_t & value) = 0;
virtual uint8_t readByte(const uint32_t address) = 0;
@ -150,7 +152,9 @@ namespace DFHack
bool forceresume();
uint32_t readDWord(const uint32_t address);
float readFloat(const uint32_t address);
void readDWord(const uint32_t address, uint32_t & value);
void readFloat(const uint32_t address, float & value);
uint16_t readWord(const uint32_t address);
void readWord(const uint32_t address, uint16_t & value);
uint8_t readByte(const uint32_t address);
@ -213,7 +217,9 @@ namespace DFHack
bool forceresume();
uint32_t readDWord(const uint32_t address);
float readFloat(const uint32_t address);
void readDWord(const uint32_t address, uint32_t & value);
void readFloat(const uint32_t address, float & value);
uint16_t readWord(const uint32_t address);
void readWord(const uint32_t address, uint16_t & value);
uint8_t readByte(const uint32_t address);
@ -275,7 +281,9 @@ namespace DFHack
bool forceresume();
uint32_t readDWord(const uint32_t address);
float readFloat(const uint32_t address);
void readDWord(const uint32_t address, uint32_t & value);
void readFloat(const uint32_t address, float & value);
uint16_t readWord(const uint32_t address);
void readWord(const uint32_t address, uint16_t & value);
uint8_t readByte(const uint32_t address);

@ -17,6 +17,15 @@ namespace DFHack
char name[128]; //this is the name displayed ingame
};
struct t_descriptor_color
{
char id[128]; // id in the raws
float r;
float v;
float b;
char name[128]; //displayed name
};
struct t_matglossPlant
{
char id[128]; //the id in the raws
@ -67,6 +76,8 @@ namespace DFHack
// TODO: maybe move to creatures?
bool ReadCreatureTypes (std::vector<t_matgloss> & output);
bool ReadCreatureTypesEx (vector<t_creaturetype> & creatures);
bool ReadDescriptorColors(std::vector<t_descriptor_color> & output);
private:
class Private;
Private* d;

@ -223,6 +223,26 @@ bool Materials::ReadCreatureTypes (vector<t_matgloss> & creatures)
return true;
}
bool Materials::ReadDescriptorColors (vector<t_descriptor_color> & color)
{
Process * p = d->owner;
DfVector <uint32_t> p_colors (p, p->getDescriptor()->getAddress ("descriptor_colors_vector"));
uint32_t size = p_colors.size();
color.clear();
color.reserve(size);
for (uint32_t i = 0; i < size;i++)
{
t_descriptor_color col;
p->readSTLString (p_colors[i] + p->getDescriptor()->getOffset ("descriptor_rawname"), col.id, 128);
p->readSTLString (p_colors[i] + p->getDescriptor()->getOffset ("descriptor_name"), col.name, 128);
col.r = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_r") );
col.v = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_v") );
col.b = p->readFloat( p_colors[i] + p->getDescriptor()->getOffset ("descriptor_color_b") );
color.push_back(col);
}
}
bool Materials::ReadCreatureTypesEx (vector<t_creaturetype> & creatures)
{
Process *p = d->owner;

@ -87,6 +87,17 @@ int main (int numargs, const char ** args)
}
cout << endl;
}
cout << endl << "----==== Color descriptors ====----" << endl;
vector<DFHack::t_descriptor_color> colors;
Materials->ReadDescriptorColors(colors);
for(uint32_t i = 0; i < colors.size();i++)
{
cout << i << ": " << colors[i].id << " - " << colors[i].name << "["
<< (unsigned int) (colors[i].r*255) << ":"
<< (unsigned int) (colors[i].v*255) << ":"
<< (unsigned int) (colors[i].b*255) << ":"
<< "]" << endl;
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -159,16 +159,16 @@ int main (int numargs, const char ** args)
int32_t idx = p->readDWord(block.origin + block_feature1);
if(idx != -1)
{
uint64_t region_x_local = cursorX / 48 + regionX;
uint64_t bigblock_x = cursorX / 48 + regionX;
// blah, dumb disassembly. too tired to think
uint16_t v12 = ((region_x_local % 16) + region_x_local) / 16;
uint16_t v12 = ((bigblock_x % 16) + bigblock_x) / 16;
uint64_t region_y_local = (cursorY / 48 + regionY) / 16;
// deref pointer to the humongo-structure
uint32_t base = p->readDWord(feature1_start_ptr);
// this is just a few pointers to arrays of 16B (4 DWORD) structs
uint32_t array_elem = p->readDWord(base + (v12 / 16) * 4);
// second element of the struct is a pointer
uint32_t wtf = p->readDWord(array_elem + (16*(region_y_local/16)) + 4);
uint32_t wtf = p->readDWord(array_elem + (16*(region_y_local/16)) + 4); // rounding!
if(wtf)
{
uint32_t feat_vector = wtf + 24 * (region_y_local % 16);

@ -1457,7 +1457,17 @@ map_data_1b60_offset 0x1B9c
WORLD + 0x5D610
<Address name="custom_workshop_vector">0x16B97E0</Address>
<Offset name="custom_workshop_name">0x4</Offset>
<Offset name="custom_workshop_type">0x20</Offset>
<Offset name="custom_workshop_type">0x20</Offset>
Descriptor colors
=================
<Address name="descriptor_shape_vector">0x16B9780</Address>
<Offset name="descriptor_rawname">0x0</Offset>
<Offset name="descriptor_name">0x4C</Offset>
<Address name="descriptor_colors_vector">0x16B9768</Address>
<Offset name="descriptor_color_r">0x6C</Offset> floats !
<Offset name="descriptor_color_v">0x70</Offset>
<Offset name="descriptor_color_b">0x74</Offset>
</Entry>
.-"""-.