Reveal and prospector tools work. Basic inorganic matgloss works. Basic map reading works.
							parent
							
								
									021fb1e0e9
								
							
						
					
					
						commit
						7d48ea49ae
					
				| @ -0,0 +1,35 @@ | ||||
| #include "DFCommonInternal.h" | ||||
| #include <shms.h> | ||||
| #include <mod-core.h> | ||||
| #include <mod-maps.h> | ||||
| #include <mod-creature40d.h> | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| #include "private/APIPrivate.h" | ||||
| 
 | ||||
| APIPrivate::APIPrivate() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| bool APIPrivate::InitReadNames() | ||||
| { | ||||
|     try | ||||
|     { | ||||
|         name_firstname_offset = offset_descriptor->getOffset("name_firstname"); | ||||
|         name_nickname_offset = offset_descriptor->getOffset("name_nickname"); | ||||
|         name_words_offset = offset_descriptor->getOffset("name_words"); | ||||
|     } | ||||
|     catch(Error::MissingMemoryDefinition) | ||||
|     { | ||||
|         return false; | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void APIPrivate::readName(t_name & name, uint32_t address) | ||||
| { | ||||
|     g_pProcess->readSTLString(address + name_firstname_offset , name.first_name, 128); | ||||
|     g_pProcess->readSTLString(address + name_nickname_offset , name.nickname, 128); | ||||
|     g_pProcess->read(address + name_words_offset ,48, (uint8_t *) name.words); | ||||
| } | ||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -1,18 +1 @@ | ||||
| # main project file. use it from a build sub-folder, see COMPILE for details | ||||
| PROJECT (dfhack-md5) | ||||
| cmake_minimum_required(VERSION 2.6) | ||||
| 
 | ||||
| # disable warning, autosearch | ||||
| if(COMMAND cmake_policy) | ||||
|   cmake_policy(SET CMP0003 NEW) | ||||
| endif(COMMAND cmake_policy) | ||||
| 
 | ||||
| if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") | ||||
|    message(SEND_ERROR "In-source builds are not allowed.") | ||||
| endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") | ||||
| 
 | ||||
| IF(NOT DEFINED CMAKE_BUILD_TYPE) | ||||
|   SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") | ||||
| ENDIF(NOT DEFINED CMAKE_BUILD_TYPE) | ||||
| 
 | ||||
| ADD_LIBRARY(dfhack-md5 SHARED md5.cpp md5wrapper.cpp) | ||||
|  | ||||
| @ -1,18 +1 @@ | ||||
| # main project file. use it from a build sub-folder, see COMPILE for details | ||||
| PROJECT (dfhack-tixml) | ||||
| cmake_minimum_required(VERSION 2.6) | ||||
| 
 | ||||
| # disable warning, autosearch | ||||
| if(COMMAND cmake_policy) | ||||
|   cmake_policy(SET CMP0003 NEW) | ||||
| endif(COMMAND cmake_policy) | ||||
| 
 | ||||
| if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") | ||||
|    message(SEND_ERROR "In-source builds are not allowed.") | ||||
| endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") | ||||
| 
 | ||||
| IF(NOT DEFINED CMAKE_BUILD_TYPE) | ||||
|   SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") | ||||
| ENDIF(NOT DEFINED CMAKE_BUILD_TYPE) | ||||
| 
 | ||||
| ADD_LIBRARY(tixml-static SHARED tinystr.cpp tinyxml.cpp tinyxmlerror.cpp tinyxmlparser.cpp) | ||||
| ADD_LIBRARY(dfhack-tixml SHARED tinystr.cpp tinyxml.cpp tinyxmlerror.cpp tinyxmlparser.cpp) | ||||
| @ -0,0 +1,206 @@ | ||||
| /*
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "../private/APIPrivate.h" | ||||
| 
 | ||||
| #define SHMCREATURESHDR ((Creatures::shm_creature_hdr *)d->shm_start) | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| /*
 | ||||
| bool API::InitReadCreatures( uint32_t &numcreatures ) | ||||
| { | ||||
|     if(!d->InitReadNames()) return false; | ||||
|     try | ||||
|     { | ||||
|         memory_info * minfo = d->offset_descriptor; | ||||
|         Creatures::creature_offsets & off = d->creatures; | ||||
|         off.creature_vector = minfo->getAddress ("creatures"); | ||||
|         off.creature_pos_offset = minfo->getOffset ("creature_position"); | ||||
|         off.creature_type_offset = minfo->getOffset ("creature_race"); | ||||
|         off.creature_flags1_offset = minfo->getOffset ("creature_flags1"); | ||||
|         off.creature_flags2_offset = minfo->getOffset ("creature_flags2"); | ||||
|         off.creature_name_offset = minfo->getOffset ("creature_name"); | ||||
|         off.creature_custom_profession_offset = minfo->getOffset ("creature_custom_profession"); | ||||
|         off.creature_profession_offset = minfo->getOffset ("creature_profession"); | ||||
|         off.creature_sex_offset = minfo->getOffset ("creature_sex"); | ||||
|         off.creature_id_offset = minfo->getOffset ("creature_id"); | ||||
|         off.creature_squad_name_offset = minfo->getOffset ("creature_squad_name"); | ||||
|         off.creature_squad_leader_id_offset = minfo->getOffset ("creature_squad_leader_id"); | ||||
|         off.creature_money_offset = minfo->getOffset ("creature_money"); | ||||
|         off.creature_current_job_offset = minfo->getOffset ("creature_current_job"); | ||||
|         off.creature_current_job_id_offset = minfo->getOffset ("current_job_id"); | ||||
|         off.creature_strength_offset = minfo->getOffset ("creature_strength"); | ||||
|         off.creature_agility_offset = minfo->getOffset ("creature_agility"); | ||||
|         off.creature_toughness_offset = minfo->getOffset ("creature_toughness"); | ||||
|         off.creature_skills_offset = minfo->getOffset ("creature_skills"); | ||||
|         off.creature_labors_offset = minfo->getOffset ("creature_labors"); | ||||
|         off.creature_happiness_offset = minfo->getOffset ("creature_happiness"); | ||||
|         off.creature_traits_offset = minfo->getOffset ("creature_traits"); | ||||
|         off.creature_likes_offset = minfo->getOffset("creature_likes"); | ||||
|         off.creature_artifact_name_offset = minfo->getOffset("creature_artifact_name"); | ||||
|         off.creature_mood_offset = minfo->getOffset("creature_mood"); | ||||
|          | ||||
|         off.creature_pregnancy_offset = minfo->getOffset("creature_pregnancy"); | ||||
|         off.creature_blood_max_offset = minfo->getOffset("creature_blood_max"); | ||||
|         off.creature_blood_current_offset = minfo->getOffset("creature_blood_current"); | ||||
|         off.creature_bleed_offset = minfo->getOffset("creature_bleed"); | ||||
|          | ||||
|         // name offsets for the creature module
 | ||||
|         off.name_firstname_offset = minfo->getOffset("name_firstname"); | ||||
|         off.name_nickname_offset = minfo->getOffset("name_nickname"); | ||||
|         off.name_words_offset = minfo->getOffset("name_words"); | ||||
|          | ||||
|         // HACK: vector correction. No longer relevant.
 | ||||
|         off.vector_correct = 0; | ||||
|          | ||||
|         d->p_cre = new DfVector (d->p, off.creature_vector, 4); | ||||
|         d->creaturesInited = true; | ||||
|         numcreatures =  d->p_cre->getSize(); | ||||
| 
 | ||||
|         // --> SHM initialization (if possible) <--
 | ||||
|         g_pProcess->getModuleIndex("Creatures40d",1,d->creature_module); | ||||
|          | ||||
|         if(d->creature_module) | ||||
|         { | ||||
|             // supply the module with offsets so it can work with them
 | ||||
|             memcpy(SHMDATA(Creatures::creature_offsets),&d->creatures,sizeof(Creatures::creature_offsets)); | ||||
|             const uint32_t cmd = Creatures::CREATURE_INIT + (d->creature_module << 16); | ||||
|             g_pProcess->SetAndWait(cmd); | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|     catch (Error::MissingMemoryDefinition&) | ||||
|     { | ||||
|         d->creaturesInited = false; | ||||
|         numcreatures = 0; | ||||
|         throw; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| bool API::ReadCreature (const int32_t index, t_creature & furball) | ||||
| { | ||||
|     if(!d->creaturesInited) return false; | ||||
|     if(d->creature_module) | ||||
|     { | ||||
|         // supply the module with offsets so it can work with them
 | ||||
|         SHMCREATURESHDR->index = index; | ||||
|         const uint32_t cmd = Creatures::CREATURE_AT_INDEX + (d->creature_module << 16); | ||||
|         g_pProcess->SetAndWait(cmd); | ||||
|         memcpy(&furball,SHMDATA(t_creature),sizeof(t_creature)); | ||||
|         // cerr << "creature read from SHM!" << endl;
 | ||||
|         return true; | ||||
|     } | ||||
|     // read pointer from vector at position
 | ||||
|     uint32_t temp = * (uint32_t *) d->p_cre->at (index); | ||||
|     furball.origin = temp; | ||||
|     Creatures::creature_offsets &offs = d->creatures; | ||||
|     //read creature from memory
 | ||||
|     g_pProcess->read (temp + offs.creature_pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
 | ||||
|     g_pProcess->readDWord (temp + offs.creature_type_offset, furball.type); | ||||
|     g_pProcess->readDWord (temp + offs.creature_flags1_offset, furball.flags1.whole); | ||||
|     g_pProcess->readDWord (temp + offs.creature_flags2_offset, furball.flags2.whole); | ||||
|     // names
 | ||||
|     d->readName(furball.name,temp + offs.creature_name_offset); | ||||
|     d->readName(furball.squad_name, temp + offs.creature_squad_name_offset); | ||||
|     d->readName(furball.artifact_name, temp + offs.creature_artifact_name_offset); | ||||
|     // custom profession
 | ||||
|     fill_char_buf (furball.custom_profession, d->p->readSTLString (temp + offs.creature_custom_profession_offset)); | ||||
| 
 | ||||
|     // labors
 | ||||
|     g_pProcess->read (temp + offs.creature_labors_offset, NUM_CREATURE_LABORS, furball.labors); | ||||
|     // traits
 | ||||
|     g_pProcess->read (temp + offs.creature_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.traits); | ||||
|     // learned skills
 | ||||
|     DfVector skills (d->p, temp + offs.creature_skills_offset, 4 ); | ||||
|     furball.numSkills = skills.getSize(); | ||||
|     for (uint32_t i = 0; i < furball.numSkills;i++) | ||||
|     { | ||||
|         uint32_t temp2 = * (uint32_t *) skills[i]; | ||||
|         //skills.read(i, (uint8_t *) &temp2);
 | ||||
|         // a byte: this gives us 256 skills maximum.
 | ||||
|         furball.skills[i].id = g_pProcess->readByte (temp2); | ||||
|         furball.skills[i].rating = g_pProcess->readByte (temp2 + 4); | ||||
|         furball.skills[i].experience = g_pProcess->readWord (temp2 + 8); | ||||
|     } | ||||
|     // profession
 | ||||
|     furball.profession = g_pProcess->readByte (temp + offs.creature_profession_offset); | ||||
|     // current job HACK: the job object isn't cleanly represented here
 | ||||
|     uint32_t jobIdAddr = g_pProcess->readDWord (temp + offs.creature_current_job_offset); | ||||
| 
 | ||||
|     if (jobIdAddr) | ||||
|     { | ||||
|         furball.current_job.active = true; | ||||
|         furball.current_job.jobId = g_pProcess->readByte (jobIdAddr + offs.creature_current_job_id_offset); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         furball.current_job.active = false; | ||||
|     } | ||||
| 
 | ||||
|     //likes
 | ||||
|     DfVector likes(d->p, temp + offs.creature_likes_offset, 4); | ||||
|     furball.numLikes = likes.getSize(); | ||||
|     for(uint32_t i = 0;i<furball.numLikes;i++) | ||||
|     { | ||||
|         uint32_t temp2 = *(uint32_t *) likes[i]; | ||||
|         g_pProcess->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]); | ||||
|     } | ||||
| 
 | ||||
|     furball.mood = (int16_t) g_pProcess->readWord (temp + offs.creature_mood_offset); | ||||
| 
 | ||||
| 
 | ||||
|     g_pProcess->readDWord (temp + offs.creature_happiness_offset, furball.happiness); | ||||
|     g_pProcess->readDWord (temp + offs.creature_id_offset, furball.id); | ||||
|     g_pProcess->readDWord (temp + offs.creature_agility_offset, furball.agility); | ||||
|     g_pProcess->readDWord (temp + offs.creature_strength_offset, furball.strength); | ||||
|     g_pProcess->readDWord (temp + offs.creature_toughness_offset, furball.toughness); | ||||
|     g_pProcess->readDWord (temp + offs.creature_money_offset, furball.money); | ||||
|     furball.squad_leader_id = (int32_t) g_pProcess->readDWord (temp + offs.creature_squad_leader_id_offset); | ||||
|     g_pProcess->readByte (temp + offs.creature_sex_offset, furball.sex); | ||||
| 
 | ||||
|     g_pProcess->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer); | ||||
|     furball.blood_max = (int32_t) g_pProcess->readDWord(temp + offs.creature_blood_max_offset); | ||||
|     furball.blood_current = (int32_t) g_pProcess->readDWord(temp + offs.creature_blood_current_offset); | ||||
|     g_pProcess->readDWord(temp + offs.creature_bleed_offset, furball.bleed_rate); | ||||
| 
 | ||||
| 
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool API::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]) | ||||
| { | ||||
|     if(!d->creaturesInited) return false; | ||||
|     uint32_t temp = * (uint32_t *) d->p_cre->at (index); | ||||
|     WriteRaw(temp + d->creatures.creature_labors_offset, NUM_CREATURE_LABORS, labors); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| bool API::getCurrentCursorCreature(uint32_t & creature_index) | ||||
| { | ||||
|     if(!d->cursorWindowInited) return false; | ||||
|     creature_index = g_pProcess->readDWord(d->current_cursor_creature_offset); | ||||
|     return true; | ||||
| } | ||||
| */ | ||||
| @ -0,0 +1,59 @@ | ||||
| /*
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "../private/APIPrivate.h" | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| bool API::ReadPauseState() | ||||
| { | ||||
|     // replace with an exception
 | ||||
|     if(!d->cursorWindowInited) return false; | ||||
| 
 | ||||
|     uint32_t pauseState = g_pProcess->readDWord (d->pause_state_offset); | ||||
|     return pauseState & 1; | ||||
| } | ||||
| 
 | ||||
| uint32_t API::ReadMenuState() | ||||
| { | ||||
|     if(d->cursorWindowInited) | ||||
|         return(g_pProcess->readDWord(d->current_menu_state_offset)); | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| bool API::ReadViewScreen (t_viewscreen &screen) | ||||
| { | ||||
|     if (!d->cursorWindowInited) return false; | ||||
|      | ||||
|     uint32_t last = g_pProcess->readDWord (d->view_screen_offset); | ||||
|     uint32_t screenAddr = g_pProcess->readDWord (last); | ||||
|     uint32_t nextScreenPtr = g_pProcess->readDWord (last + 4); | ||||
|     while (nextScreenPtr != 0) | ||||
|     { | ||||
|         last = nextScreenPtr; | ||||
|         screenAddr = g_pProcess->readDWord (nextScreenPtr); | ||||
|         nextScreenPtr = g_pProcess->readDWord (nextScreenPtr + 4); | ||||
|     } | ||||
|     return d->offset_descriptor->resolveObjectToClassID (last, screen.type); | ||||
| } | ||||
| @ -0,0 +1,442 @@ | ||||
| /*
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "../private/APIPrivate.h" | ||||
| 
 | ||||
| #define SHMMAPSHDR ((Maps::shm_maps_hdr *)d->shm_start) | ||||
| 
 | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| /*-----------------------------------*
 | ||||
|  *  Init the mapblock pointer array  * | ||||
|  *-----------------------------------*/ | ||||
| bool API::InitMap() | ||||
| { | ||||
|     uint32_t map_offset = d->offset_descriptor->getAddress ("map_data"); | ||||
|     uint32_t x_count_offset = d->offset_descriptor->getAddress ("x_count_block"); | ||||
|     uint32_t y_count_offset = d->offset_descriptor->getAddress ("y_count_block"); | ||||
|     uint32_t z_count_offset = d->offset_descriptor->getAddress ("z_count_block"); | ||||
| 
 | ||||
|     // get the offsets once here
 | ||||
|     d->tile_type_offset = d->offset_descriptor->getOffset ("type"); | ||||
|     d->designation_offset = d->offset_descriptor->getOffset ("designation"); | ||||
|     //d->occupancy_offset = d->offset_descriptor->getOffset ("occupancy");
 | ||||
|     //d->biome_stuffs = d->offset_descriptor->getOffset ("biome_stuffs");
 | ||||
| 
 | ||||
|     d->veinvector = d->offset_descriptor->getOffset ("v_vein"); | ||||
|      | ||||
|     // these can fail and will be found when looking at the actual veins later
 | ||||
|     // basically a cache
 | ||||
|     d->vein_ice_vptr = 0; | ||||
|     d->offset_descriptor->resolveClassnameToVPtr("block_square_event_frozen_liquid", d->vein_ice_vptr); | ||||
|     d->vein_mineral_vptr = 0; | ||||
|     d->offset_descriptor->resolveClassnameToVPtr("block_square_event_mineral",d->vein_mineral_vptr); | ||||
|      | ||||
|     /*
 | ||||
|      * --> SHM initialization (if possible) <-- | ||||
|      */ | ||||
|     g_pProcess->getModuleIndex("Maps2010",1,d->maps_module); | ||||
|      | ||||
|     if(d->maps_module) | ||||
|     { | ||||
|         // supply the module with offsets so it can work with them
 | ||||
|         Maps::maps_offsets *off = SHMDATA(Maps::maps_offsets); | ||||
|         off->designation_offset = d->designation_offset; | ||||
|         off->map_offset = map_offset; | ||||
|         off->tile_type_offset = d->tile_type_offset; | ||||
|         off->vein_ice_vptr = d->vein_ice_vptr; // FIXME: not necessarily true, the shm server side needs a class lookup >_<
 | ||||
|         off->vein_mineral_vptr = d->vein_mineral_vptr; // FIXME: not necessarily true, the shm server side needs a class lookup >_<
 | ||||
|         off->veinvector = d->veinvector; | ||||
|         off->x_count_offset = x_count_offset; | ||||
|         off->y_count_offset = y_count_offset; | ||||
|         off->z_count_offset = z_count_offset; | ||||
|         full_barrier | ||||
|         const uint32_t cmd = Maps::MAP_INIT + (d->maps_module << 16); | ||||
|         g_pProcess->SetAndWait(cmd); | ||||
|         //cerr << "Map acceleration enabled!" << endl;
 | ||||
|     } | ||||
|      | ||||
|     // get the map pointer
 | ||||
|     uint32_t x_array_loc = g_pProcess->readDWord (map_offset); | ||||
|     if (!x_array_loc) | ||||
|     { | ||||
|         return false; | ||||
|         // FIXME: only throw this due to programmer error, in the other map functions
 | ||||
|         //throw Error::NoMapLoaded();
 | ||||
|     } | ||||
|      | ||||
|     // get the size
 | ||||
|     uint32_t mx, my, mz; | ||||
|     mx = d->x_block_count = g_pProcess->readDWord (x_count_offset); | ||||
|     my = d->y_block_count = g_pProcess->readDWord (y_count_offset); | ||||
|     mz = d->z_block_count = g_pProcess->readDWord (z_count_offset); | ||||
| 
 | ||||
|     // test for wrong map dimensions
 | ||||
|     if (mx == 0 || mx > 48 || my == 0 || my > 48 || mz == 0) | ||||
|     { | ||||
|         throw Error::BadMapDimensions(mx, my); | ||||
|         //return false;
 | ||||
|     } | ||||
| 
 | ||||
|     // alloc array for pointers to all blocks
 | ||||
|     d->block = new uint32_t[mx*my*mz]; | ||||
|     uint32_t *temp_x = new uint32_t[mx]; | ||||
|     uint32_t *temp_y = new uint32_t[my]; | ||||
|     uint32_t *temp_z = new uint32_t[mz]; | ||||
| 
 | ||||
|     g_pProcess->read (x_array_loc, mx * sizeof (uint32_t), (uint8_t *) temp_x); | ||||
|     for (uint32_t x = 0; x < mx; x++) | ||||
|     { | ||||
|         g_pProcess->read (temp_x[x], my * sizeof (uint32_t), (uint8_t *) temp_y); | ||||
|         // y -> map column
 | ||||
|         for (uint32_t y = 0; y < my; y++) | ||||
|         { | ||||
|             g_pProcess->read (temp_y[y], | ||||
|                    mz * sizeof (uint32_t), | ||||
|                    (uint8_t *) (d->block + x*my*mz + y*mz)); | ||||
|         } | ||||
|     } | ||||
|     delete [] temp_x; | ||||
|     delete [] temp_y; | ||||
|     delete [] temp_z; | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool API::DestroyMap() | ||||
| { | ||||
|     if (d->block != NULL) | ||||
|     { | ||||
|         delete [] d->block; | ||||
|         d->block = NULL; | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool API::isValidBlock (uint32_t x, uint32_t y, uint32_t z) | ||||
| { | ||||
|     if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count) | ||||
|         return false; | ||||
|     return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z] != 0; | ||||
| } | ||||
| 
 | ||||
| uint32_t API::getBlockPtr (uint32_t x, uint32_t y, uint32_t z) | ||||
| { | ||||
|     if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count) | ||||
|         return 0; | ||||
|     return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
| } | ||||
| 
 | ||||
| bool API::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer) | ||||
| { | ||||
|     if(d->shm_start && d->maps_module) // ACCELERATE!
 | ||||
|     { | ||||
|         SHMMAPSHDR->x = x; | ||||
|         SHMMAPSHDR->y = y; | ||||
|         SHMMAPSHDR->z = z; | ||||
|         volatile uint32_t cmd = Maps::MAP_READ_BLOCK_BY_COORDS + (d->maps_module << 16); | ||||
|         if(!g_pProcess->SetAndWait(cmd)) | ||||
|             return false; | ||||
|         memcpy(buffer,SHMDATA(mapblock40d),sizeof(mapblock40d)); | ||||
|         return true; | ||||
|     } | ||||
|     else // plain old block read
 | ||||
|     { | ||||
|         uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|         if (addr) | ||||
|         { | ||||
|             g_pProcess->read (addr + d->tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes); | ||||
|             buffer->origin = addr; | ||||
|             uint32_t addr_of_struct = g_pProcess->readDWord(addr); | ||||
|             buffer->blockflags.whole = g_pProcess->readDWord(addr_of_struct); | ||||
|             return true; | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // 256 * sizeof(uint16_t)
 | ||||
| bool API::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if (addr) | ||||
|     { | ||||
|         g_pProcess->read (addr + d->tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| bool API::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if(addr) | ||||
|     { | ||||
|         uint32_t addr_of_struct = g_pProcess->readDWord(addr); | ||||
|         dirtybit = g_pProcess->readDWord(addr_of_struct) & 1; | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| bool API::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if (addr) | ||||
|     { | ||||
|         uint32_t addr_of_struct = g_pProcess->readDWord(addr); | ||||
|         uint32_t dirtydword = g_pProcess->readDWord(addr_of_struct); | ||||
|         dirtydword &= 0xFFFFFFFE; | ||||
|         dirtydword |= (uint32_t) dirtybit; | ||||
|         g_pProcess->writeDWord (addr_of_struct, dirtydword); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| /// read/write the block flags
 | ||||
| bool API::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &blockflags) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if(addr) | ||||
|     { | ||||
|         uint32_t addr_of_struct = g_pProcess->readDWord(addr); | ||||
|         blockflags.whole = g_pProcess->readDWord(addr_of_struct); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| bool API::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags blockflags) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if (addr) | ||||
|     { | ||||
|         uint32_t addr_of_struct = g_pProcess->readDWord(addr); | ||||
|         g_pProcess->writeDWord (addr_of_struct, blockflags.whole); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| bool API::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if (addr) | ||||
|     { | ||||
|         g_pProcess->read (addr + d->designation_offset, sizeof (designations40d), (uint8_t *) buffer); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| // 256 * sizeof(uint16_t)
 | ||||
| bool API::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if (addr) | ||||
|     { | ||||
|         g_pProcess->write (addr + d->tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // 256 * sizeof(uint32_t)
 | ||||
| bool API::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if (addr) | ||||
|     { | ||||
|         g_pProcess->write (addr + d->designation_offset, sizeof (designations40d), (uint8_t *) buffer); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| // FIXME: this is bad. determine the real size!
 | ||||
| //16 of them? IDK... there's probably just 7. Reading more doesn't cause errors as it's an array nested inside a block
 | ||||
| // 16 * sizeof(uint8_t)
 | ||||
| /*
 | ||||
| bool API::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     if (addr) | ||||
|     { | ||||
|         g_pProcess->read (addr + d->biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| */ | ||||
| 
 | ||||
| // veins of a block, expects empty vein vectors
 | ||||
| bool API::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein> & veins, vector <t_frozenliquidvein>& ices) | ||||
| { | ||||
|     uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; | ||||
|     veins.clear(); | ||||
|     ices.clear(); | ||||
|     if (addr && d->veinvector) | ||||
|     { | ||||
|         // veins are stored as a vector of pointers to veins
 | ||||
|         /*pointer is 4 bytes! we work with a 32bit program here, no matter what architecture we compile khazad for*/ | ||||
|         DfVector p_veins (d->p, addr + d->veinvector, 4); | ||||
|         uint32_t size = p_veins.getSize(); | ||||
|         veins.reserve (size); | ||||
| 
 | ||||
|         // read all veins
 | ||||
|         for (uint32_t i = 0; i < size;i++) | ||||
|         { | ||||
|             t_vein v; | ||||
|             t_frozenliquidvein fv; | ||||
| 
 | ||||
|             // read the vein pointer from the vector
 | ||||
|             uint32_t temp = * (uint32_t *) p_veins[i]; | ||||
|             uint32_t type = g_pProcess->readDWord(temp); | ||||
| try_again: | ||||
|             if(type == d->vein_mineral_vptr) | ||||
|             { | ||||
|                 // read the vein data (dereference pointer)
 | ||||
|                 g_pProcess->read (temp, sizeof(t_vein), (uint8_t *) &v); | ||||
|                 v.address_of = temp; | ||||
|                 // store it in the vector
 | ||||
|                 veins.push_back (v); | ||||
|             } | ||||
|             else if(type == d->vein_ice_vptr) | ||||
|             { | ||||
|                 // read the ice vein data (dereference pointer)
 | ||||
|                 g_pProcess->read (temp, sizeof(t_frozenliquidvein), (uint8_t *) &fv); | ||||
|                 // store it in the vector
 | ||||
|                 ices.push_back (fv); | ||||
|             } | ||||
|             else if(g_pProcess->readClassName(type) == "block_square_event_frozen_liquid") | ||||
|             { | ||||
|                 d->vein_ice_vptr = type; | ||||
|                 goto try_again; | ||||
|             } | ||||
|             else if(g_pProcess->readClassName(type) == "block_square_event_mineral") | ||||
|             { | ||||
|                 d->vein_mineral_vptr = type; | ||||
|                 goto try_again; | ||||
|             } | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // getter for map size
 | ||||
| void API::getSize (uint32_t& x, uint32_t& y, uint32_t& z) | ||||
| { | ||||
|     x = d->x_block_count; | ||||
|     y = d->y_block_count; | ||||
|     z = d->z_block_count; | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
| //vector<uint16_t> v_geology[eBiomeCount];
 | ||||
| bool API::ReadGeology (vector < vector <uint16_t> >& assign) | ||||
| { | ||||
|     memory_info * minfo = d->offset_descriptor; | ||||
|     // get needed addresses and offsets. Now this is what I call crazy.
 | ||||
|     int region_x_offset = minfo->getAddress ("region_x"); | ||||
|     int region_y_offset = minfo->getAddress ("region_y"); | ||||
|     int region_z_offset =  minfo->getAddress ("region_z"); | ||||
|     int world_offset =  minfo->getAddress ("world"); | ||||
|     int world_regions_offset =  minfo->getOffset ("w_regions_arr"); | ||||
|     int region_size =  minfo->getHexValue ("region_size"); | ||||
|     int region_geo_index_offset =  minfo->getOffset ("region_geo_index_off"); | ||||
|     int world_geoblocks_offset =  minfo->getOffset ("w_geoblocks"); | ||||
|     int world_size_x = minfo->getOffset ("world_size_x"); | ||||
|     int world_size_y = minfo->getOffset ("world_size_y"); | ||||
|     int geolayer_geoblock_offset = minfo->getOffset ("geolayer_geoblock_offset"); | ||||
| 
 | ||||
|     uint32_t regionX, regionY, regionZ; | ||||
|     uint16_t worldSizeX, worldSizeY; | ||||
| 
 | ||||
|     // read position of the region inside DF world
 | ||||
|     g_pProcess->readDWord (region_x_offset, regionX); | ||||
|     g_pProcess->readDWord (region_y_offset, regionY); | ||||
|     g_pProcess->readDWord (region_z_offset, regionZ); | ||||
| 
 | ||||
|     // get world size
 | ||||
|     g_pProcess->readWord (world_offset + world_size_x, worldSizeX); | ||||
|     g_pProcess->readWord (world_offset + world_size_y, worldSizeY); | ||||
| 
 | ||||
|     // get pointer to first part of 2d array of regions
 | ||||
|     uint32_t regions = g_pProcess->readDWord (world_offset + world_regions_offset); | ||||
| 
 | ||||
|     // read the geoblock vector
 | ||||
|     DfVector geoblocks (d->p, world_offset + world_geoblocks_offset, 4); | ||||
| 
 | ||||
|     // iterate over 8 surrounding regions + local region
 | ||||
|     for (int i = eNorthWest; i < eBiomeCount; i++) | ||||
|     { | ||||
|         // check bounds, fix them if needed
 | ||||
|         int bioRX = regionX / 16 + (i % 3) - 1; | ||||
|         if (bioRX < 0) bioRX = 0; | ||||
|         if (bioRX >= worldSizeX) bioRX = worldSizeX - 1; | ||||
|         int bioRY = regionY / 16 + (i / 3) - 1; | ||||
|         if (bioRY < 0) bioRY = 0; | ||||
|         if (bioRY >= worldSizeY) bioRY = worldSizeY - 1; | ||||
| 
 | ||||
|         // get pointer to column of regions
 | ||||
|         uint32_t geoX; | ||||
|         g_pProcess->readDWord (regions + bioRX*4, geoX); | ||||
| 
 | ||||
|         // get index into geoblock vector
 | ||||
|         uint16_t geoindex; | ||||
|         g_pProcess->readWord (geoX + bioRY*region_size + region_geo_index_offset, geoindex); | ||||
| 
 | ||||
|         // get the geoblock from the geoblock vector using the geoindex
 | ||||
|         // read the matgloss pointer from the vector into temp
 | ||||
|         uint32_t geoblock_off = * (uint32_t *) geoblocks[geoindex]; | ||||
| 
 | ||||
|         // get the vector with pointer to layers
 | ||||
|         DfVector geolayers (d->p, geoblock_off + geolayer_geoblock_offset , 4); // let's hope
 | ||||
|         // make sure we don't load crap
 | ||||
|         assert (geolayers.getSize() > 0 && geolayers.getSize() <= 16); | ||||
| 
 | ||||
|         d->v_geology[i].reserve (geolayers.getSize()); | ||||
|         // finally, read the layer matgloss
 | ||||
|         for (uint32_t j = 0;j < geolayers.getSize();j++) | ||||
|         { | ||||
|             // read pointer to a layer
 | ||||
|             uint32_t geol_offset = * (uint32_t *) geolayers[j]; | ||||
|             // read word at pointer + 2, store in our geology vectors
 | ||||
|             d->v_geology[i].push_back (g_pProcess->readWord (geol_offset + 2)); | ||||
|         } | ||||
|     } | ||||
|     assign.clear(); | ||||
|     assign.reserve (eBiomeCount); | ||||
| //     // TODO: clean this up
 | ||||
|     for (int i = 0; i < eBiomeCount;i++) | ||||
|     { | ||||
|         assign.push_back (d->v_geology[i]); | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
| */ | ||||
| @ -0,0 +1,188 @@ | ||||
| /*
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "../private/APIPrivate.h" | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| bool API::ReadWoodMaterials (vector<t_matgloss> & woods) | ||||
| { | ||||
| /*
 | ||||
|     int matgloss_address = d->offset_descriptor->getAddress ("matgloss"); | ||||
|     int matgloss_wood_name_offset = d->offset_descriptor->getOffset("matgloss_wood_name"); | ||||
|     // TODO: find flag for autumnal coloring?
 | ||||
|     DfVector p_matgloss(d->p, matgloss_address, 4); | ||||
| 
 | ||||
|     woods.clear(); | ||||
| 
 | ||||
|     t_matgloss mat; | ||||
|     // TODO: use brown?
 | ||||
|     mat.fore = 7; | ||||
|     mat.back = 0; | ||||
|     mat.bright = 0; | ||||
|     uint32_t size = p_matgloss.getSize(); | ||||
|     for (uint32_t i = 0; i < size ;i++) | ||||
|     { | ||||
|         // read the matgloss pointer from the vector into temp
 | ||||
|         uint32_t temp = * (uint32_t *) p_matgloss[i]; | ||||
|         // read the string pointed at by
 | ||||
|         d->p->readSTLString (temp, mat.id, 128); | ||||
|         d->p->readSTLString (temp+matgloss_wood_name_offset, mat.name, 128); | ||||
|         woods.push_back (mat); | ||||
|     } | ||||
|     */ | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool API::ReadInorganicMaterials (vector<t_matgloss> & inorganic) | ||||
| { | ||||
|     memory_info * minfo = d->offset_descriptor; | ||||
|     int matgloss_address = minfo->getAddress ("mat_inorganics"); | ||||
|     //int matgloss_colors = minfo->getOffset ("material_color");
 | ||||
|     //int matgloss_stone_name_offset = minfo->getOffset("matgloss_stone_name");
 | ||||
| 
 | ||||
|     DfVector p_matgloss (d->p, matgloss_address, 4); | ||||
| 
 | ||||
|     uint32_t size = p_matgloss.getSize(); | ||||
|     inorganic.resize (0); | ||||
|     inorganic.reserve (size); | ||||
|     for (uint32_t i = 0; i < size;i++) | ||||
|     { | ||||
|         // read the matgloss pointer from the vector into temp
 | ||||
|         uint32_t temp = * (uint32_t *) p_matgloss[i]; | ||||
|         // read the string pointed at by
 | ||||
|         t_matgloss mat; | ||||
|         //fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address
 | ||||
|         d->p->readSTLString (temp, mat.id, 128); | ||||
|         /*
 | ||||
|         d->p->readSTLString (temp+matgloss_stone_name_offset, mat.name, 128); | ||||
|         mat.fore = (uint8_t) g_pProcess->readWord (temp + matgloss_colors); | ||||
|         mat.back = (uint8_t) g_pProcess->readWord (temp + matgloss_colors + 2); | ||||
|         mat.bright = (uint8_t) g_pProcess->readWord (temp + matgloss_colors + 4); | ||||
|         */ | ||||
|         inorganic.push_back (mat); | ||||
|     } | ||||
|     return true; | ||||
|      | ||||
| } | ||||
| 
 | ||||
| bool API::ReadPlantMaterials (vector<t_matgloss> & plants) | ||||
| { | ||||
|     /*
 | ||||
|     memory_info * minfo = d->offset_descriptor; | ||||
|     int matgloss_address = minfo->getAddress ("matgloss"); | ||||
|     int matgloss_offset = minfo->getHexValue ("matgloss_skip"); | ||||
|     int matgloss_plant_name_offset = minfo->getOffset("matgloss_plant_name"); | ||||
|     DfVector p_matgloss(d->p, matgloss_address + matgloss_offset * 2, 4); | ||||
| 
 | ||||
|     plants.clear(); | ||||
| 
 | ||||
|     // TODO: use green?
 | ||||
|     t_matgloss mat; | ||||
|     mat.fore = 7; | ||||
|     mat.back = 0; | ||||
|     mat.bright = 0; | ||||
|     for (uint32_t i = 0; i < p_matgloss.getSize();i++) | ||||
|     { | ||||
|         // read the matgloss pointer from the vector into temp
 | ||||
|         uint32_t temp = * (uint32_t *) p_matgloss[i]; | ||||
|         // read the string pointed at by
 | ||||
|         //fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address
 | ||||
|         d->p->readSTLString (temp, mat.id, 128); | ||||
|         d->p->readSTLString (temp+matgloss_plant_name_offset, mat.name, 128); | ||||
|         plants.push_back (mat); | ||||
|     } | ||||
|     */ | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool API::ReadPlantMaterials (vector<t_matglossPlant> & plants) | ||||
| { | ||||
|     /*
 | ||||
|     memory_info * minfo = d->offset_descriptor; | ||||
|     int matgloss_address = minfo->getAddress ("matgloss"); | ||||
|     int matgloss_offset = minfo->getHexValue ("matgloss_skip"); | ||||
|     int matgloss_plant_name_offset = minfo->getOffset("matgloss_plant_name"); | ||||
|     int matgloss_plant_drink_offset = minfo->getOffset("matgloss_plant_drink"); | ||||
|     int matgloss_plant_food_offset = minfo->getOffset("matgloss_plant_food"); | ||||
|     int matgloss_plant_extract_offset = minfo->getOffset("matgloss_plant_extract"); | ||||
|     DfVector p_matgloss(d->p, matgloss_address + matgloss_offset * 2, 4); | ||||
| 
 | ||||
|     plants.clear(); | ||||
| 
 | ||||
|     // TODO: use green?
 | ||||
|     t_matglossPlant mat; | ||||
|     mat.fore = 7; | ||||
|     mat.back = 0; | ||||
|     mat.bright = 0; | ||||
|     for (uint32_t i = 0; i < p_matgloss.getSize();i++) | ||||
|     { | ||||
|         // read the matgloss pointer from the vector into temp
 | ||||
|         uint32_t temp = * (uint32_t *) p_matgloss[i]; | ||||
|         // read the string pointed at by
 | ||||
|         //fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address
 | ||||
|         d->p->readSTLString (temp, mat.id, 128); | ||||
|         d->p->readSTLString (temp+matgloss_plant_name_offset, mat.name, 128); | ||||
|         d->p->readSTLString (temp+matgloss_plant_drink_offset, mat.drink_name, 128); | ||||
|         d->p->readSTLString (temp+matgloss_plant_food_offset, mat.food_name, 128); | ||||
|         d->p->readSTLString (temp+matgloss_plant_extract_offset, mat.extract_name, 128); | ||||
|          | ||||
|         //d->p->readSTLString (temp
 | ||||
|         plants.push_back (mat); | ||||
|     } | ||||
|     */ | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool API::ReadCreatureTypes (vector<t_matgloss> & creatures) | ||||
| { | ||||
|     /*
 | ||||
|     memory_info * minfo = d->offset_descriptor; | ||||
|     int matgloss_address = minfo->getAddress ("matgloss"); | ||||
|     int matgloss_offset = minfo->getHexValue ("matgloss_skip"); | ||||
|     int matgloss_creature_name_offset = minfo->getOffset("matgloss_creature_name"); | ||||
|     DfVector p_matgloss (d->p, matgloss_address + matgloss_offset * 6, 4); | ||||
| 
 | ||||
|     creatures.clear(); | ||||
| 
 | ||||
|     // TODO: use green?
 | ||||
|     t_matgloss mat; | ||||
|     mat.fore = 7; | ||||
|     mat.back = 0; | ||||
|     mat.bright = 0; | ||||
|     for (uint32_t i = 0; i < p_matgloss.getSize();i++) | ||||
|     { | ||||
|         // read the matgloss pointer from the vector into temp
 | ||||
|         uint32_t temp = * (uint32_t *) p_matgloss[i]; | ||||
|         // read the string pointed at by
 | ||||
|         //fill_char_buf(mat.id, d->p->readSTLString(temp)); // reads a C string given an address
 | ||||
|         d->p->readSTLString (temp, mat.id, 128); | ||||
|         d->p->readSTLString (temp+matgloss_creature_name_offset, mat.name, 128); | ||||
|         creatures.push_back (mat); | ||||
|     } | ||||
|     */ | ||||
|     return true; | ||||
| } | ||||
| @ -0,0 +1,103 @@ | ||||
| /*
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| #include "DFCommonInternal.h" | ||||
| #include "../private/APIPrivate.h" | ||||
| using namespace DFHack; | ||||
| 
 | ||||
| bool API::InitViewAndCursor() | ||||
| { | ||||
|     try | ||||
|     { | ||||
|         d->window_x_offset = d->offset_descriptor->getAddress ("window_x"); | ||||
|         d->window_y_offset = d->offset_descriptor->getAddress ("window_y"); | ||||
|         d->window_z_offset = d->offset_descriptor->getAddress ("window_z"); | ||||
|         d->cursor_xyz_offset = d->offset_descriptor->getAddress ("cursor_xyz"); | ||||
|         d->current_cursor_creature_offset = d->offset_descriptor->getAddress ("current_cursor_creature"); | ||||
|         d->window_dims_offset = d->offset_descriptor->getAddress ("window_dims"); | ||||
|          | ||||
|         d->current_menu_state_offset = d->offset_descriptor->getAddress("current_menu_state"); | ||||
|         d->pause_state_offset = d->offset_descriptor->getAddress ("pause_state"); | ||||
|         d->view_screen_offset = d->offset_descriptor->getAddress ("view_screen"); | ||||
| 
 | ||||
|         d->cursorWindowInited = true; | ||||
|         return true; | ||||
|     } | ||||
|     catch (Error::MissingMemoryDefinition&) | ||||
|     { | ||||
|         d->cursorWindowInited = false; | ||||
|         throw; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| bool API::getViewCoords (int32_t &x, int32_t &y, int32_t &z) | ||||
| { | ||||
|     if (!d->cursorWindowInited) return false; | ||||
|     g_pProcess->readDWord (d->window_x_offset, (uint32_t &) x); | ||||
|     g_pProcess->readDWord (d->window_y_offset, (uint32_t &) y); | ||||
|     g_pProcess->readDWord (d->window_z_offset, (uint32_t &) z); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| //FIXME: confine writing of coords to map bounds?
 | ||||
| bool API::setViewCoords (const int32_t x, const int32_t y, const int32_t z) | ||||
| { | ||||
|     if (!d->cursorWindowInited) return false; | ||||
|     g_pProcess->writeDWord (d->window_x_offset, (uint32_t) x); | ||||
|     g_pProcess->writeDWord (d->window_y_offset, (uint32_t) y); | ||||
|     g_pProcess->writeDWord (d->window_z_offset, (uint32_t) z); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool API::getCursorCoords (int32_t &x, int32_t &y, int32_t &z) | ||||
| { | ||||
|     if(!d->cursorWindowInited) return false; | ||||
|     int32_t coords[3]; | ||||
|     g_pProcess->read (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords); | ||||
|     x = coords[0]; | ||||
|     y = coords[1]; | ||||
|     z = coords[2]; | ||||
|     if (x == -30000) return false; | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| //FIXME: confine writing of coords to map bounds?
 | ||||
| bool API::setCursorCoords (const int32_t x, const int32_t y, const int32_t z) | ||||
| { | ||||
|     if (!d->cursorWindowInited) return false; | ||||
|     int32_t coords[3] = {x, y, z}; | ||||
|     g_pProcess->write (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords); | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| bool API::getWindowSize (int32_t &width, int32_t &height) | ||||
| { | ||||
|     if(! d->cursorWindowInited) return false; | ||||
|      | ||||
|     int32_t coords[2]; | ||||
|     g_pProcess->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords); | ||||
|     width = coords[0]; | ||||
|     height = coords[1]; | ||||
|     return true; | ||||
| } | ||||
| @ -0,0 +1,113 @@ | ||||
| /*
 | ||||
| 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. | ||||
| */ | ||||
| 
 | ||||
| /*
 | ||||
| * WARNING: Only include from API modules | ||||
| */ | ||||
| 
 | ||||
| #ifndef APIPRIVATE_H_INCLUDED | ||||
| #define APIPRIVATE_H_INCLUDED | ||||
| 
 | ||||
| // we connect to those
 | ||||
| #include <shms.h> | ||||
| #include <mod-core.h> | ||||
| #include <mod-maps.h> | ||||
| #include <mod-creature40d.h> | ||||
| 
 | ||||
| #define SHMCMD(num) ((shm_cmd *)d->shm_start)[num]->pingpong | ||||
| #define SHMHDR ((shm_core_hdr *)d->shm_start) | ||||
| #define SHMDATA(type) ((type *)(d->shm_start + SHM_HEADER)) | ||||
| 
 | ||||
| namespace DFHack | ||||
| { | ||||
| 
 | ||||
| class APIPrivate | ||||
| { | ||||
| public: | ||||
|     APIPrivate(); | ||||
|     void readName(t_name & name, uint32_t address); | ||||
|     // get the name offsets
 | ||||
|     bool InitReadNames(); | ||||
|      | ||||
|     #include "../modules/Creatures-data.h" | ||||
|     #include "../modules/Maps-data.h" | ||||
|     #include "../modules/Position-data.h" | ||||
|     #include "../modules/Gui-data.h" | ||||
|     #include "../modules/Materials-data.h" | ||||
|      | ||||
|     uint32_t name_firstname_offset; | ||||
|     uint32_t name_nickname_offset; | ||||
|     uint32_t name_words_offset; | ||||
|      | ||||
|     ProcessEnumerator* pm; | ||||
|     Process* p; | ||||
|     char * shm_start; | ||||
|     memory_info* offset_descriptor; | ||||
|     string xml; | ||||
| 
 | ||||
|     /*
 | ||||
|     uint32_t item_material_offset; | ||||
| 
 | ||||
|     uint32_t note_foreground_offset; | ||||
|     uint32_t note_background_offset; | ||||
|     uint32_t note_name_offset; | ||||
|     uint32_t note_xyz_offset; | ||||
|     uint32_t hotkey_start; | ||||
|     uint32_t hotkey_mode_offset; | ||||
|     uint32_t hotkey_xyz_offset; | ||||
|     uint32_t hotkey_size; | ||||
| 
 | ||||
|     uint32_t settlement_name_offset; | ||||
|     uint32_t settlement_world_xy_offset; | ||||
|     uint32_t settlement_local_xy_offset; | ||||
|      | ||||
|     uint32_t dwarf_lang_table_offset; | ||||
| 
 | ||||
|     bool constructionsInited; | ||||
|     bool buildingsInited; | ||||
|     bool effectsInited; | ||||
|     bool vegetationInited; | ||||
|      | ||||
|      | ||||
|     bool itemsInited; | ||||
|     bool notesInited; | ||||
|     bool namesInited; | ||||
|     bool hotkeyInited; | ||||
|     bool settlementsInited; | ||||
|     bool nameTablesInited; | ||||
| 
 | ||||
|     uint32_t tree_offset; | ||||
|      | ||||
|     DfVector *p_cons; | ||||
|     DfVector *p_bld; | ||||
|     DfVector *p_effect; | ||||
|     DfVector *p_veg; | ||||
|     DfVector *p_itm; | ||||
|     DfVector *p_notes; | ||||
|     DfVector *p_settlements; | ||||
|     DfVector *p_current_settlement; | ||||
|     */ | ||||
| }; | ||||
| } | ||||
| #endif | ||||
		Loading…
	
		Reference in New Issue