develop
Petr Mrázek 2010-04-26 18:12:00 +02:00
parent 51f6dbd981
commit 96c2effab6
5 changed files with 127 additions and 8 deletions

@ -29,6 +29,7 @@ distribution.
#include <errno.h>
#include <DFError.h>
#include <sys/ptrace.h>
#include <stdio.h>
using namespace DFHack;
class WineProcess::Private
@ -454,12 +455,14 @@ void WineProcess::writeDWord (uint32_t offset, uint32_t data)
void WineProcess::writeWord (uint32_t offset, uint16_t data)
{
uint32_t orig = readDWord(offset);
/*;
uint16_t & zz = (uint16_t&) orig;
zz = data;
*/
orig &= 0xFFFF0000;
orig |= data;
/*
orig |= 0x0000FFFF;
orig &= data;
*/
ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig);
}
@ -468,16 +471,14 @@ void WineProcess::writeByte (uint32_t offset, uint8_t data)
uint32_t orig = readDWord(offset);
orig &= 0xFFFFFF00;
orig |= data;
/*
orig |= 0x000000FF;
orig &= data;
*/
ptrace(PTRACE_POKEDATA,d->my_handle, offset, orig);
}
// blah. I hate the kernel devs for crippling /proc/PID/mem. THIS IS RIDICULOUS
void WineProcess::write (uint32_t offset, uint32_t size, uint8_t *source)
{
printf("0x%x, size %d\n", source, size);
uint32_t count = 0;
uint32_t indexptr = 0;
while (size > 0)
{
@ -488,6 +489,7 @@ void WineProcess::write (uint32_t offset, uint32_t size, uint8_t *source)
offset +=4;
indexptr +=4;
size -=4;
count +=4;
}
// last is either three or 2 bytes
else if(size >= 2)
@ -496,14 +498,17 @@ void WineProcess::write (uint32_t offset, uint32_t size, uint8_t *source)
offset +=2;
indexptr +=2;
size -=2;
count +=2;
}
// finishing move
else if(size == 1)
{
writeByte(offset, *(uint8_t *) (source + indexptr));
count ++;
return;
}
}
printf("written %d\n", count);
}
const std::string WineProcess::readCString (uint32_t offset)

@ -348,6 +348,10 @@ namespace DFHack
t_blockflags &blockflags);
bool WriteBlockFlags(uint32_t blockx, uint32_t blocky, uint32_t blockz,
t_blockflags blockflags);
/// read/write features
bool ReadFeatures(uint32_t blockx, uint32_t blocky, uint32_t blockz, int16_t & local, int16_t & global);
bool WriteLocalFeature(uint32_t blockx, uint32_t blocky, uint32_t blockz, int16_t local = -1);
bool WriteGlobalFeature(uint32_t blockx, uint32_t blocky, uint32_t blockz, int16_t local = -1);
/// read region offsets of a block - used for determining layer stone matgloss
bool ReadRegionOffsets(uint32_t blockx, uint32_t blocky, uint32_t blockz,

@ -443,6 +443,43 @@ bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices4
return false;
}
bool Maps::ReadFeatures(uint32_t x, uint32_t y, uint32_t z, int16_t & local, int16_t & global)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
Process * p = d->owner;
p->readWord(addr + d->offsets.global_feature_offset, (uint16_t&) global);
p->readWord(addr + d->offsets.local_feature_offset, (uint16_t&)local);
return true;
}
return false;
}
bool Maps::WriteLocalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t local)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
Process * p = d->owner;
p->writeWord(addr + d->offsets.local_feature_offset, (uint16_t&)local);
return true;
}
return false;
}
bool Maps::WriteGlobalFeature(uint32_t x, uint32_t y, uint32_t z, int16_t global)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
Process * p = d->owner;
p->writeWord(addr + d->offsets.global_feature_offset, (uint16_t&)global);
return true;
}
return false;
}
/*
* Block events
*/

@ -249,6 +249,19 @@ int main (int numargs, const char ** args)
cout << "smooth?" << endl;
uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation);
printf("designation offset: 0x%x\n", designato);
if(des.light)
cout << "L";
else
cout << " ";
if(des.skyview)
cout << "S";
else
cout << " ";
if(des.subterranean)
cout << "U";
else
cout << " ";
cout << endl;
/*
block.designation[tx][ty].bits.moss = 1;
block.designation[tx][ty].bits.geolayer_index = 15;

@ -86,6 +86,14 @@ int main (void)
{
mode = "column";
}
else if(command == "starruby")
{
mode = "starruby";
}
else if(command == "darkhide")
{
mode = "darkhide";
}
else if(command == "w")
{
mode = "water";
@ -177,6 +185,58 @@ int main (void)
zzz++;
}
}
// quick hack, do not use for serious stuff
else if(mode == "starruby")
{
if(Maps->isValidBlock((x/16),(y/16),z))
{
Maps->ReadTileTypes((x/16),(y/16),z, &tiles);
Maps->ReadDesignations((x/16),(y/16),z, &designations);
Maps->ReadTemperatures((x/16),(y/16),z, &temp1, &temp2);
cout << "sizeof(designations) = " << sizeof(designations) << endl;
cout << "sizeof(tiletypes) = " << sizeof(tiles) << endl;
for(uint32_t xx = 0; xx < 16; xx++) for(uint32_t yy = 0; yy < 16; yy++)
{
cout<< xx << " " << yy <<": " << tiles[xx][yy] << endl;
tiles[xx][yy] = 335;// 45
DFHack::naked_designation & des = designations[xx][yy].bits;
des.feature_local = true;
des.feature_global = false;
des.flow_size = 0;
des.skyview = 0;
des.light = 0;
des.subterranean = 1;
temp1[xx][yy] = 10015;
temp2[xx][yy] = 10015;
}
Maps->WriteTemperatures((x/16),(y/16),z, &temp1, &temp2);
Maps->WriteDesignations((x/16),(y/16),z, &designations);
Maps->WriteTileTypes((x/16),(y/16),z, &tiles);
Maps->WriteLocalFeature((x/16),(y/16),z, 36);
}
}
else if(mode == "darkhide")
{
int16_t zzz = z;
while ( zzz >=0 )
{
if(Maps->isValidBlock((x/16),(y/16),zzz))
{
int xx = x %16;
int yy = y %16;
Maps->ReadDesignations((x/16),(y/16),zzz, &designations);
designations[xx][yy].bits.skyview = 0;
designations[xx][yy].bits.light = 0;
designations[xx][yy].bits.subterranean = 1;
Maps->WriteDesignations((x/16),(y/16),zzz, &designations);
}
zzz --;
}
}
else
{
// place the magma