2009-09-13 18:02:46 -06:00
/*
www . sourceforge . net / projects / dfhack
Copyright ( c ) 2009 Petr Mr á zek ( peterix ) , Kenneth Ferland ( Impaler [ WrG ] ) , dorf
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 .
*/
2009-11-10 20:37:28 -07:00
# include "DFCommonInternal.h"
2010-04-04 16:48:19 -06:00
# include "DFProcess.h"
# include "DFProcessEnumerator.h"
# include "DFHackAPI.h"
# include "DFError.h"
2010-03-28 09:22:15 -06:00
# include <shms.h>
# include <mod-core.h>
# include <mod-maps.h>
# include <mod-creature40d.h>
2010-04-02 19:52:46 -06:00
# include "private/APIPrivate.h"
2010-03-08 10:27:19 -07:00
2010-04-04 16:48:19 -06:00
# include "modules/Maps.h"
# include "modules/Materials.h"
# include "modules/Position.h"
# include "modules/Gui.h"
# include "modules/Creatures.h"
2010-04-06 17:17:03 -06:00
# include "modules/Translation.h"
2010-04-07 04:49:37 -06:00
# include "modules/Vegetation.h"
2010-04-09 06:44:00 -06:00
# include "modules/Buildings.h"
2010-04-09 16:24:41 -06:00
# include "modules/Constructions.h"
2010-04-04 16:48:19 -06:00
using namespace DFHack ;
2009-12-12 16:56:28 -07:00
API : : API ( const string path_to_xml )
2010-04-02 19:52:46 -06:00
: d ( new APIPrivate ( ) )
2009-10-04 07:08:20 -06:00
{
2009-12-12 16:56:28 -07:00
d - > xml = QUOT ( MEMXML_DATA_PATH ) ;
2009-11-10 20:37:28 -07:00
d - > xml + = " / " ;
d - > xml + = path_to_xml ;
d - > pm = NULL ;
2010-04-10 22:50:43 -06:00
d - > p = 0 ;
2010-03-04 16:05:01 -07:00
d - > shm_start = 0 ;
2009-10-04 07:08:20 -06:00
}
2009-11-10 20:37:28 -07:00
API : : ~ API ( )
2009-09-13 18:02:46 -06:00
{
2010-03-16 15:12:05 -06:00
Detach ( ) ;
2009-11-10 20:37:28 -07:00
delete d ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
bool API : : Attach ( )
2009-09-13 18:02:46 -06:00
{
2010-04-25 03:05:11 -06:00
if ( d - > p ! = NULL )
{
return d - > p - > suspend ( ) ;
}
2010-04-02 19:52:46 -06:00
// detach all processes, destroy manager
if ( d - > pm = = 0 )
2010-03-04 16:05:01 -07:00
{
2010-04-02 19:52:46 -06:00
d - > pm = new ProcessEnumerator ( d - > xml ) ; // FIXME: handle bad XML better
2010-03-04 16:05:01 -07:00
}
2010-04-02 19:52:46 -06:00
else
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
d - > pm - > purge ( ) ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
// find a process (ProcessManager can find multiple when used properly)
if ( ! d - > pm - > findProcessess ( ) )
2009-11-18 14:27:13 -07:00
{
2010-04-02 19:52:46 -06:00
throw Error : : NoProcess ( ) ;
//cerr << "couldn't find a suitable process" << endl;
2010-02-27 18:37:05 -07:00
//return false;
2009-11-18 14:27:13 -07:00
}
2010-04-02 19:52:46 -06:00
d - > p = ( * d - > pm ) [ 0 ] ;
if ( ! d - > p - > attach ( ) )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
throw Error : : CantAttach ( ) ;
//cerr << "couldn't attach to process" << endl;
//return false; // couldn't attach to process, no go
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
d - > shm_start = d - > p - > getSHMStart ( ) ;
d - > offset_descriptor = d - > p - > getDescriptor ( ) ;
// process is attached, everything went just fine... hopefully
2009-09-13 18:02:46 -06:00
return true ;
}
2009-10-04 07:08:20 -06:00
2010-04-02 19:52:46 -06:00
bool API : : Detach ( )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
if ( ! d - > p )
2010-02-17 18:10:39 -07:00
return false ;
2010-04-02 19:52:46 -06:00
if ( ! d - > p - > detach ( ) )
2010-03-04 16:05:01 -07:00
{
return false ;
}
2010-04-02 19:52:46 -06:00
if ( d - > pm ! = NULL )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
delete d - > pm ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
d - > pm = NULL ;
d - > p = NULL ;
d - > shm_start = 0 ;
d - > offset_descriptor = NULL ;
2010-04-19 06:14:37 -06:00
// invalidate all modules
if ( d - > creatures )
{
delete d - > creatures ;
d - > creatures = 0 ;
}
if ( d - > creatures )
{
delete d - > creatures ;
d - > creatures = 0 ;
}
if ( d - > maps )
{
delete d - > maps ;
d - > maps = 0 ;
}
if ( d - > gui )
{
delete d - > gui ;
d - > gui = 0 ;
}
if ( d - > position )
{
delete d - > position ;
d - > position = 0 ;
}
if ( d - > materials )
{
delete d - > materials ;
d - > materials = 0 ;
}
if ( d - > gui )
{
delete d - > gui ;
d - > gui = 0 ;
}
if ( d - > translation )
{
delete d - > translation ;
d - > translation = 0 ;
}
if ( d - > vegetation )
{
delete d - > vegetation ;
d - > vegetation = 0 ;
}
if ( d - > constructions )
{
delete d - > constructions ;
d - > constructions = 0 ;
}
if ( d - > translation )
{
delete d - > translation ;
d - > translation = 0 ;
}
2009-12-12 12:52:30 -07:00
return true ;
}
2009-09-13 18:02:46 -06:00
2010-04-02 19:52:46 -06:00
bool API : : isAttached ( )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
return d - > p ! = NULL ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
bool API : : Suspend ( )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
return d - > p - > suspend ( ) ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
bool API : : AsyncSuspend ( )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
return d - > p - > asyncSuspend ( ) ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
bool API : : Resume ( )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
return d - > p - > resume ( ) ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
bool API : : ForceResume ( )
2009-09-18 05:31:56 -06:00
{
2010-04-02 19:52:46 -06:00
return d - > p - > forceresume ( ) ;
2009-09-18 05:31:56 -06:00
}
2010-04-02 19:52:46 -06:00
bool API : : isSuspended ( )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
return d - > p - > isSuspended ( ) ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
void API : : ReadRaw ( const uint32_t offset , const uint32_t size , uint8_t * target )
2009-09-13 18:02:46 -06:00
{
2010-04-18 13:30:02 -06:00
d - > p - > read ( offset , size , target ) ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
void API : : WriteRaw ( const uint32_t offset , const uint32_t size , uint8_t * source )
2009-09-13 18:02:46 -06:00
{
2010-04-18 13:30:02 -06:00
d - > p - > write ( offset , size , source ) ;
2009-12-31 19:14:41 -07:00
}
2010-04-02 19:52:46 -06:00
memory_info * API : : getMemoryInfo ( )
2009-12-31 19:14:41 -07:00
{
2010-04-02 19:52:46 -06:00
return d - > offset_descriptor ;
2009-09-13 18:02:46 -06:00
}
2010-04-02 19:52:46 -06:00
Process * API : : getProcess ( )
2009-10-22 19:39:19 -06:00
{
2010-04-02 19:52:46 -06:00
return d - > p ;
2009-10-22 19:39:19 -06:00
}
2010-04-02 19:52:46 -06:00
DFWindow * API : : getWindow ( )
2009-09-13 18:02:46 -06:00
{
2010-04-02 19:52:46 -06:00
return d - > p - > getWindow ( ) ;
2009-09-13 18:02:46 -06:00
}
2010-04-04 16:48:19 -06:00
/*******************************************************************************
M O D U L E S
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Creatures * API : : getCreatures ( )
{
if ( ! d - > creatures )
d - > creatures = new Creatures ( d ) ;
return d - > creatures ;
}
Maps * API : : getMaps ( )
{
if ( ! d - > maps )
d - > maps = new Maps ( d ) ;
return d - > maps ;
}
Gui * API : : getGui ( )
{
if ( ! d - > gui )
d - > gui = new Gui ( d ) ;
return d - > gui ;
}
Position * API : : getPosition ( )
{
if ( ! d - > position )
d - > position = new Position ( d ) ;
return d - > position ;
}
Materials * API : : getMaterials ( )
{
if ( ! d - > materials )
d - > materials = new Materials ( d ) ;
return d - > materials ;
}
2010-04-06 17:17:03 -06:00
Translation * API : : getTranslation ( )
{
if ( ! d - > translation )
d - > translation = new Translation ( d ) ;
return d - > translation ;
}
2010-04-07 04:49:37 -06:00
Vegetation * API : : getVegetation ( )
{
if ( ! d - > vegetation )
d - > vegetation = new Vegetation ( d ) ;
return d - > vegetation ;
}
2010-04-09 06:44:00 -06:00
Buildings * API : : getBuildings ( )
2009-09-13 18:02:46 -06:00
{
2010-04-09 06:44:00 -06:00
if ( ! d - > buildings )
d - > buildings = new Buildings ( d ) ;
return d - > buildings ;
2009-09-13 18:02:46 -06:00
}
2010-04-09 16:24:41 -06:00
Constructions * API : : getConstructions ( )
{
if ( ! d - > constructions )
d - > constructions = new Constructions ( d ) ;
return d - > constructions ;
}
2010-04-09 06:44:00 -06:00
/*
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
2009-09-13 18:02:46 -06:00
2010-03-20 10:30:13 -06:00
bool API : : InitReadEffects ( uint32_t & numeffects )
{
if ( d - > effectsInited )
FinishReadEffects ( ) ;
2010-03-22 17:35:23 -06:00
int effects = 0 ;
try
{
effects = d - > offset_descriptor - > getAddress ( " effects_vector " ) ;
}
catch ( Error : : MissingMemoryDefinition )
{
return false ;
}
2010-03-20 10:30:13 -06:00
d - > effectsInited = true ;
2010-04-18 06:56:09 -06:00
d - > p_effect = new DfVector ( d - > p , effects ) ;
2010-03-20 10:30:13 -06:00
numeffects = d - > p_effect - > getSize ( ) ;
return true ;
}
2010-03-26 06:38:49 -06:00
bool API : : ReadEffect ( const uint32_t index , t_effect_df40d & effect )
2010-03-20 10:30:13 -06:00
{
if ( ! d - > effectsInited )
return false ;
if ( index > = d - > p_effect - > getSize ( ) )
return false ;
// read pointer from vector at position
2010-04-18 06:56:09 -06:00
uint32_t temp = d - > p_effect - > at ( index ) ;
2010-03-20 10:30:13 -06:00
//read effect from memory
2010-04-18 13:30:02 -06:00
d - > p - > read ( temp , sizeof ( t_effect_df40d ) , ( uint8_t * ) & effect ) ;
2010-03-20 10:30:13 -06:00
return true ;
}
// use with care!
2010-03-26 06:38:49 -06:00
bool API : : WriteEffect ( const uint32_t index , const t_effect_df40d & effect )
2010-03-20 10:30:13 -06:00
{
if ( ! d - > effectsInited )
return false ;
if ( index > = d - > p_effect - > getSize ( ) )
return false ;
// read pointer from vector at position
2010-04-18 06:56:09 -06:00
uint32_t temp = d - > p_effect - > at ( index ) ;
2010-03-20 10:30:13 -06:00
// write effect to memory
2010-04-18 13:30:02 -06:00
d - > p - > write ( temp , sizeof ( t_effect_df40d ) , ( uint8_t * ) & effect ) ;
2010-03-20 10:30:13 -06:00
return true ;
}
void API : : FinishReadEffects ( )
{
if ( d - > p_effect )
{
delete d - > p_effect ;
d - > p_effect = NULL ;
}
d - > effectsInited = false ;
}
2010-04-02 19:52:46 -06:00
*/
/*
2010-02-17 16:33:08 -07:00
bool API : : InitReadNotes ( uint32_t & numnotes )
{
2010-02-27 19:34:54 -07:00
try
2010-02-17 16:33:08 -07:00
{
2010-02-27 19:34:54 -07:00
memory_info * minfo = d - > offset_descriptor ;
int notes = minfo - > getAddress ( " notes " ) ;
d - > note_foreground_offset = minfo - > getOffset ( " note_foreground " ) ;
d - > note_background_offset = minfo - > getOffset ( " note_background " ) ;
d - > note_name_offset = minfo - > getOffset ( " note_name " ) ;
d - > note_xyz_offset = minfo - > getOffset ( " note_xyz " ) ;
2010-04-18 06:56:09 -06:00
d - > p_notes = new DfVector ( d - > p , notes ) ;
2010-02-17 16:33:08 -07:00
d - > notesInited = true ;
numnotes = d - > p_notes - > getSize ( ) ;
return true ;
}
2010-02-27 19:34:54 -07:00
catch ( Error : : MissingMemoryDefinition & )
2010-02-17 16:33:08 -07:00
{
d - > notesInited = false ;
numnotes = 0 ;
2010-02-27 19:34:54 -07:00
throw ;
2010-02-17 16:33:08 -07:00
}
}
2010-02-27 17:25:04 -07:00
bool API : : ReadNote ( const int32_t index , t_note & note )
2010-02-17 16:33:08 -07:00
{
2010-02-27 17:25:04 -07:00
if ( ! d - > notesInited ) return false ;
2010-02-17 16:33:08 -07:00
// read pointer from vector at position
2010-04-18 06:56:09 -06:00
uint32_t temp = d - > p_notes - > at ( index ) ;
2010-04-18 13:30:02 -06:00
note . symbol = d - > p - > readByte ( temp ) ;
note . foreground = d - > p - > readWord ( temp + d - > note_foreground_offset ) ;
note . background = d - > p - > readWord ( temp + d - > note_background_offset ) ;
2010-02-18 10:06:32 -07:00
d - > p - > readSTLString ( temp + d - > note_name_offset , note . name , 128 ) ;
2010-04-18 13:30:02 -06:00
d - > p - > read ( temp + d - > note_xyz_offset , 3 * sizeof ( uint16_t ) , ( uint8_t * ) & note . x ) ;
2010-02-18 10:06:32 -07:00
return true ;
2010-02-17 16:33:08 -07:00
}
2010-02-22 19:25:57 -07:00
bool API : : InitReadSettlements ( uint32_t & numsettlements )
{
2010-03-22 17:37:35 -06:00
if ( ! d - > InitReadNames ( ) ) return false ;
2010-02-27 19:34:54 -07:00
try
2010-02-22 19:25:57 -07:00
{
2010-03-22 17:37:35 -06:00
2010-02-27 19:34:54 -07:00
memory_info * minfo = d - > offset_descriptor ;
int allSettlements = minfo - > getAddress ( " settlements " ) ;
int currentSettlement = minfo - > getAddress ( " settlement_current " ) ;
d - > settlement_name_offset = minfo - > getOffset ( " settlement_name " ) ;
d - > settlement_world_xy_offset = minfo - > getOffset ( " settlement_world_xy " ) ;
d - > settlement_local_xy_offset = minfo - > getOffset ( " settlement_local_xy " ) ;
2010-04-18 06:56:09 -06:00
d - > p_settlements = new DfVector ( d - > p , allSettlements ) ;
d - > p_current_settlement = new DfVector ( d - > p , currentSettlement ) ;
2010-02-22 19:25:57 -07:00
d - > settlementsInited = true ;
numsettlements = d - > p_settlements - > getSize ( ) ;
return true ;
}
2010-02-27 19:34:54 -07:00
catch ( Error : : MissingMemoryDefinition & )
2010-02-22 19:25:57 -07:00
{
d - > settlementsInited = false ;
numsettlements = 0 ;
2010-02-27 19:34:54 -07:00
throw ;
2010-02-22 19:25:57 -07:00
}
2010-02-25 09:37:40 -07:00
}
2010-02-27 17:25:04 -07:00
bool API : : ReadSettlement ( const int32_t index , t_settlement & settlement )
2010-02-22 19:25:57 -07:00
{
2010-02-27 17:25:04 -07:00
if ( ! d - > settlementsInited ) return false ;
if ( ! d - > p_settlements - > getSize ( ) ) return false ;
2010-02-22 19:25:57 -07:00
// read pointer from vector at position
2010-04-18 06:56:09 -06:00
uint32_t temp = d - > p_settlements - > at ( index ) ;
2010-02-25 09:37:40 -07:00
settlement . origin = temp ;
2010-03-16 15:12:05 -06:00
d - > readName ( settlement . name , temp + d - > settlement_name_offset ) ;
2010-04-18 13:30:02 -06:00
d - > p - > read ( temp + d - > settlement_world_xy_offset , 2 * sizeof ( int16_t ) , ( uint8_t * ) & settlement . world_x ) ;
d - > p - > read ( temp + d - > settlement_local_xy_offset , 4 * sizeof ( int16_t ) , ( uint8_t * ) & settlement . local_x1 ) ;
2010-02-22 19:25:57 -07:00
return true ;
}
2010-02-27 19:34:54 -07:00
2010-02-22 19:25:57 -07:00
bool API : : ReadCurrentSettlement ( t_settlement & settlement )
{
2010-02-27 17:25:04 -07:00
if ( ! d - > settlementsInited ) return false ;
if ( ! d - > p_current_settlement - > getSize ( ) ) return false ;
2010-04-18 06:56:09 -06:00
uint32_t temp = d - > p_current_settlement - > at ( 0 ) ;
2010-02-25 09:37:40 -07:00
settlement . origin = temp ;
2010-03-16 15:12:05 -06:00
d - > readName ( settlement . name , temp + d - > settlement_name_offset ) ;
2010-04-18 13:30:02 -06:00
d - > p - > read ( temp + d - > settlement_world_xy_offset , 2 * sizeof ( int16_t ) , ( uint8_t * ) & settlement . world_x ) ;
d - > p - > read ( temp + d - > settlement_local_xy_offset , 4 * sizeof ( int16_t ) , ( uint8_t * ) & settlement . local_x1 ) ;
2010-02-22 19:25:57 -07:00
return true ;
}
void API : : FinishReadSettlements ( )
{
2010-02-27 17:25:04 -07:00
if ( d - > p_settlements )
{
delete d - > p_settlements ;
d - > p_settlements = NULL ;
}
if ( d - > p_current_settlement )
{
delete d - > p_current_settlement ;
d - > p_current_settlement = NULL ;
}
2010-02-22 19:25:57 -07:00
d - > settlementsInited = false ;
}
2010-02-27 17:25:04 -07:00
bool API : : getItemIndexesInBox ( vector < uint32_t > & indexes ,
const uint16_t x1 , const uint16_t y1 , const uint16_t z1 ,
const uint16_t x2 , const uint16_t y2 , const uint16_t z2 )
2009-12-31 18:49:32 -07:00
{
2010-02-27 17:25:04 -07:00
if ( ! d - > itemsInited ) return false ;
2009-12-31 18:49:32 -07:00
indexes . clear ( ) ;
uint32_t size = d - > p_itm - > getSize ( ) ;
struct temp2 {
uint16_t coords [ 3 ] ;
uint32_t flags ;
} ;
temp2 temp2 ;
2010-02-21 16:18:44 -07:00
for ( uint32_t i = 0 ; i < size ; i + + ) {
2010-04-18 06:56:09 -06:00
uint32_t temp = d - > p_itm - > at ( i ) ;
2010-04-18 13:30:02 -06:00
d - > p - > read ( temp + sizeof ( uint32_t ) , 5 * sizeof ( uint16_t ) , ( uint8_t * ) & temp2 ) ;
2009-12-31 18:49:32 -07:00
if ( temp2 . flags & ( 1 < < 0 ) ) {
if ( temp2 . coords [ 0 ] > = x1 & & temp2 . coords [ 0 ] < x2 )
{
if ( temp2 . coords [ 1 ] > = y1 & & temp2 . coords [ 1 ] < y2 )
{
if ( temp2 . coords [ 2 ] > = z1 & & temp2 . coords [ 2 ] < z2 )
{
indexes . push_back ( i ) ;
}
}
}
}
}
2010-02-27 18:50:16 -07:00
return true ;
2009-12-31 18:49:32 -07:00
}
2010-04-02 19:52:46 -06:00
*/
/*
2010-02-17 16:33:08 -07:00
void API : : FinishReadNotes ( )
{
2010-02-27 17:25:04 -07:00
if ( d - > p_notes )
{
delete d - > p_notes ;
d - > p_notes = 0 ;
}
2010-02-17 16:33:08 -07:00
d - > notesInited = false ;
}
2010-02-25 05:41:57 -07:00
*/
2009-12-22 14:19:39 -07:00
2010-04-02 19:52:46 -06:00
/*
2010-02-11 14:08:39 -07:00
bool API : : InitReadItems ( uint32_t & numitems )
2009-11-17 07:52:47 -07:00
{
2010-02-27 19:34:54 -07:00
try
2010-02-11 14:08:39 -07:00
{
2010-02-27 19:34:54 -07:00
int items = d - > offset_descriptor - > getAddress ( " items " ) ;
d - > item_material_offset = d - > offset_descriptor - > getOffset ( " item_materials " ) ;
2010-04-18 06:56:09 -06:00
d - > p_itm = new DfVector ( d - > p , items ) ;
2010-02-11 14:08:39 -07:00
d - > itemsInited = true ;
numitems = d - > p_itm - > getSize ( ) ;
return true ;
}
2010-02-27 19:34:54 -07:00
catch ( Error : : MissingMemoryDefinition & )
2010-02-11 14:08:39 -07:00
{
d - > itemsInited = false ;
numitems = 0 ;
2010-02-27 19:34:54 -07:00
throw ;
2010-02-11 14:08:39 -07:00
}
2009-11-17 07:52:47 -07:00
}
2010-02-27 17:25:04 -07:00
bool API : : ReadItem ( const uint32_t index , t_item & item )
2009-11-17 07:52:47 -07:00
{
2010-02-27 17:25:04 -07:00
if ( ! d - > itemsInited ) return false ;
2009-11-17 07:52:47 -07:00
t_item_df40d item_40d ;
// read pointer from vector at position
2010-04-18 06:56:09 -06:00
uint32_t temp = d - > p_itm - > at ( index ) ;
2009-12-12 16:56:28 -07:00
2009-11-17 07:52:47 -07:00
//read building from memory
2010-04-18 13:30:02 -06:00
d - > p - > read ( temp , sizeof ( t_item_df40d ) , ( uint8_t * ) & item_40d ) ;
2009-11-17 20:35:43 -07:00
2009-11-17 07:52:47 -07:00
// transform
int32_t type = - 1 ;
2010-02-25 05:41:57 -07:00
d - > offset_descriptor - > resolveObjectToClassID ( temp , type ) ;
2009-11-17 07:52:47 -07:00
item . origin = temp ;
item . vtable = item_40d . vtable ;
item . x = item_40d . x ;
item . y = item_40d . y ;
item . z = item_40d . z ;
item . type = type ;
item . ID = item_40d . ID ;
2010-01-18 09:44:24 -07:00
item . flags . whole = item_40d . flags ;
2009-12-12 16:56:28 -07:00
2009-11-17 20:35:43 -07:00
//TODO certain item types (creature based, threads, seeds, bags do not have the first matType byte, instead they have the material index only located at 0x68
2010-04-18 13:30:02 -06:00
d - > p - > read ( temp + d - > item_material_offset , sizeof ( t_matglossPair ) , ( uint8_t * ) & item . material ) ;
2009-11-17 20:35:43 -07:00
//for(int i = 0; i < 0xCC; i++){ // used for item research
// uint8_t byte = MreadByte(temp+i);
// item.bytes.push_back(byte);
2009-12-12 16:56:28 -07:00
//}
2009-11-17 07:52:47 -07:00
return true ;
}
void API : : FinishReadItems ( )
{
2010-02-27 17:25:04 -07:00
if ( d - > p_itm )
{
delete d - > p_itm ;
d - > p_itm = NULL ;
}
2009-11-17 07:52:47 -07:00
d - > itemsInited = false ;
2009-12-12 12:52:30 -07:00
}
2010-04-02 19:52:46 -06:00
*/
/*
2009-12-31 19:14:41 -07:00
bool API : : ReadItemTypes ( vector < vector < t_itemType > > & itemTypes )
{
memory_info * minfo = d - > offset_descriptor ;
int matgloss_address = minfo - > getAddress ( " matgloss " ) ;
int matgloss_skip = minfo - > getHexValue ( " matgloss_skip " ) ;
int item_type_name_offset = minfo - > getOffset ( " item_type_name " ) ;
2010-02-27 17:25:04 -07:00
for ( int i = 8 ; i < 20 ; i + + )
{
2010-04-18 06:56:09 -06:00
DfVector p_temp ( d - > p , matgloss_address + i * matgloss_skip ) ;
2009-12-31 19:14:41 -07:00
vector < t_itemType > typesForVec ;
for ( uint32_t j = 0 ; j < p_temp . getSize ( ) ; j + + )
{
t_itemType currType ;
uint32_t temp = * ( uint32_t * ) p_temp [ j ] ;
// Mread(temp+40,sizeof(name),(uint8_t *) name);
2010-02-15 16:04:15 -07:00
d - > p - > readSTLString ( temp + 4 , currType . id , 128 ) ;
d - > p - > readSTLString ( temp + item_type_name_offset , currType . name , 128 ) ;
2009-12-31 19:14:41 -07:00
//stringsForVec.push_back(string(name));
typesForVec . push_back ( currType ) ;
}
itemTypes . push_back ( typesForVec ) ;
}
return true ;
2010-04-02 19:52:46 -06:00
}
*/