diff --git a/artifacts/scripting/headers/define_extra.h b/artifacts/scripting/headers/define_extra.h index 26ef0cb6..cfb758ad 100644 --- a/artifacts/scripting/headers/define_extra.h +++ b/artifacts/scripting/headers/define_extra.h @@ -267,4 +267,21 @@ #define WPN_ANIM_MINIGUN (0x09) // (L) #define WPN_ANIM_ROCKET_LAUNCHER (0x0A) // (M) +// common object data offsets +#define OBJ_DATA_TILENUM (0x04) +#define OBJ_DATA_CUR_FRM (0x18) // current frame number +#define OBJ_DATA_ROTATION (0x1C) +#define OBJ_DATA_FID (0x20) +#define OBJ_DATA_ELEVATION (0x28) +#define OBJ_DATA_PID (0x64) +#define OBJ_DATA_CID (0x68) +#define OBJ_DATA_SID (0x78) +// items +#define OBJ_DATA_CUR_CHARGES (0x3C) +// critters +#define OBJ_DATA_COMBAT_STATE (0x3C) // flags: 1 - combat, 2 - target is out of range, 4 - flee +#define OBJ_DATA_CUR_ACTION_POINT (0x40) +#define OBJ_DATA_DAMAGE_LAST_TURN (0x48) +#define OBJ_DATA_WHO_HIT_ME (0x54) + #endif // DEFINE_EXTRA_H diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index 482b179b..f1a8cb9c 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -217,6 +217,7 @@ #define get_cursor_mode sfall_func0("get_cursor_mode") #define get_flags(obj) sfall_func1("get_flags", obj) #define get_map_enter_position sfall_func0("get_map_enter_position") +#define get_object_data(obj, offset) sfall_func2("get_object_data", obj, offset) #define get_outline(obj) sfall_func1("get_outline", obj) #define intface_hide sfall_func0("intface_hide") #define intface_is_hidden sfall_func0("intface_is_hidden") @@ -231,6 +232,7 @@ #define set_flags(obj, flags) sfall_func2("set_flags", obj, flags) #define set_ini_setting(setting, value) sfall_func2("set_ini_setting", setting, value) #define set_map_enter_position(tile, elev, rot) sfall_func3("set_map_enter_position", tile, elev, rot) +#define set_object_data(obj, offset, value) sfall_func3("set_object_data", obj, offset, value) #define set_outline(obj, color) sfall_func2("set_outline", obj, color) #define spatial_radius(obj) sfall_func1("spatial_radius", obj) #define tile_refresh_display sfall_func0("tile_refresh_display") diff --git a/artifacts/scripting/hookscripts.txt b/artifacts/scripting/hookscripts.txt index eae50533..98b2b7f8 100644 --- a/artifacts/scripting/hookscripts.txt +++ b/artifacts/scripting/hookscripts.txt @@ -166,7 +166,7 @@ int arg5 - The special effect flags for the target (use bwand DAM_* to chec int arg6 - The special effect flags for the attacker (use bwand DAM_* to check specific flags) int arg7 - The weapon used in the attack int arg8 - The bodypart that was struck -int arg9 - Damage Multiplier (this is divided by 2, so a value of 3 does 1.5x damage, and 8 does 4x damage. Usually it's 2, but with Silent Death perk and the corresponding attack conditions, it's 4; for critical hits, the value is taken from the critical table) +int arg9 - Damage Multiplier (this is divided by 2, so a value of 3 does 1.5x damage, and 8 does 4x damage. Usually it's 2; for critical hits, the value is taken from the critical table; with Silent Death perk and the corresponding attack conditions, the value will be doubled) int arg10 - Number of bullets actually hit the target (1 for melee attacks) int arg11 - The amount of knockback to the target int arg12 - Attack Type (see ATKTYPE_* constants) @@ -432,7 +432,7 @@ HOOK_INVENWIELD (hs_invenwield.int) Runs before wielding or unwielding an armor or a weapon by a critter (except when using inventory by PC). An example usage would be to change critter art depending on armor being used or to dynamically customize weapon animations. NOTE: when replacing a previously wielded armor or weapon, the unwielding hook will not be executed. -If you need to rely on this, try checking if armor/weapon already equipped when wielding hook is executed. +If you need to rely on this, try checking if armor/weapon is already equipped when wielding hook is executed. Critter arg1 - critter Obj arg2 - item being wielded or unwielded (weapon/armor), may be 0 when unwielding (object is valid only if the item is unwielded by move_obj_inven_to_obj() or rm_obj_from_inven()) diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index c0e2ccf9..efc2a3de 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -461,6 +461,12 @@ Some utility/math functions are available: - crSwitch: True - only checks critters and ignores their cover (roof tiles, walls, scenery, etc.), False - checks all objects (can't check critters under objects) - passing False to the inclDude argument will ignore dude_obj +> int sfall_func2("get_object_data", object, int offset) +- returns the data at the specified offset of an object (see OBJ_DATA_* constants in define_extra.h for offsets) + +> void sfall_func3("set_object_data", object, int offset, int data) +- sets the data at the specified offset of an object + ------------------------ ------ MORE INFO ------- ------------------------ diff --git a/artifacts/scripting/sfall opcode list.txt b/artifacts/scripting/sfall opcode list.txt index d13bb8e1..4f4c0b04 100644 --- a/artifacts/scripting/sfall opcode list.txt +++ b/artifacts/scripting/sfall opcode list.txt @@ -1,8 +1,8 @@ -*0x8156 - int read_byte(int address) -*0x8157 - int read_short(int address) -*0x8158 - int read_int(int address) -*0x8159 - string read_string(int address) +0x8156 - int read_byte(int address) +0x8157 - int read_short(int address) +0x8158 - int read_int(int address) +0x8159 - string read_string(int address) *0x81cf - void write_byte(int address, int value) *0x81d0 - void write_short(int address, int value) diff --git a/sfall/ScriptExtender.cpp b/sfall/ScriptExtender.cpp index 6e76e9b0..ecadd492 100644 --- a/sfall/ScriptExtender.cpp +++ b/sfall/ScriptExtender.cpp @@ -386,6 +386,7 @@ static const SfallOpcodeMetadata opcodeMetaArray[] = { {sf_critter_inven_obj2, "critter_inven_obj2", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT}}, {sf_get_current_inven_size, "get_current_inven_size", {DATATYPE_MASK_VALID_OBJ}}, {sf_get_flags, "get_flags", {DATATYPE_MASK_VALID_OBJ}}, + {sf_get_object_data, "get_object_data", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT}}, {sf_get_outline, "get_outline", {DATATYPE_MASK_VALID_OBJ}}, {sf_inventory_redraw, "inventory_redraw", {DATATYPE_MASK_INT}}, {sf_item_weight, "item_weight", {DATATYPE_MASK_VALID_OBJ}}, @@ -395,6 +396,7 @@ static const SfallOpcodeMetadata opcodeMetaArray[] = { {sf_set_flags, "set_flags", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT}}, {sf_set_ini_setting, "set_ini_setting", {DATATYPE_MASK_STR, DATATYPE_MASK_INT | DATATYPE_MASK_STR}}, {sf_set_map_enter_position, "set_map_enter_position", {DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT}}, + {sf_set_object_data, "set_object_data", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT, DATATYPE_MASK_INT}}, {sf_set_outline, "set_outline", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT}}, {sf_spatial_radius, "spatial_radius", {DATATYPE_MASK_VALID_OBJ}}, {sf_unjam_lock, "unjam_lock", {DATATYPE_MASK_VALID_OBJ}}, @@ -1334,12 +1336,10 @@ void ScriptExtenderSetup() { SafeWrite32(0x46ce6c, (DWORD)opcodes); //call that actually jumps to the opcode SafeWrite32(0x46e390, (DWORD)opcodes); //mov that writes to the opcode - if (AllowUnsafeScripting) { - opcodes[0x156] = ReadByte; - opcodes[0x157] = ReadShort; - opcodes[0x158] = ReadInt; - opcodes[0x159] = ReadString; - } + opcodes[0x156] = ReadByte; + opcodes[0x157] = ReadShort; + opcodes[0x158] = ReadInt; + opcodes[0x159] = ReadString; opcodes[0x15a] = SetPCBaseStat; opcodes[0x15b] = SetPCExtraStat; opcodes[0x15c] = GetPCBaseStat; diff --git a/sfall/ScriptOps/MetaruleOp.hpp b/sfall/ScriptOps/MetaruleOp.hpp index d3412c4e..0fc4066f 100644 --- a/sfall/ScriptOps/MetaruleOp.hpp +++ b/sfall/ScriptOps/MetaruleOp.hpp @@ -114,6 +114,7 @@ static const SfallMetarule metaruleArray[] = { {"get_flags", sf_get_flags, 1, 1}, {"get_map_enter_position", sf_get_map_enter_position, 0, 0}, {"get_metarule_table", sf_get_metarule_table, 0, 0}, + {"get_object_data", sf_get_object_data, 2, 2}, {"get_outline", sf_get_outline, 1, 1}, {"intface_hide", sf_intface_hide, 0, 0}, {"intface_is_hidden", sf_intface_is_hidden, 0, 0}, @@ -128,6 +129,7 @@ static const SfallMetarule metaruleArray[] = { {"set_flags", sf_set_flags, 2, 2}, {"set_ini_setting", sf_set_ini_setting, 2, 2}, {"set_map_enter_position", sf_set_map_enter_position, 3, 3}, + {"set_object_data", sf_set_object_data, 3, 3}, {"set_outline", sf_set_outline, 2, 2}, {"spatial_radius", sf_spatial_radius, 1, 1}, {"tile_refresh_display", sf_tile_refresh_display, 0, 0}, diff --git a/sfall/ScriptOps/ObjectsOps.hpp b/sfall/ScriptOps/ObjectsOps.hpp index 4e6ace60..3e5ab3a0 100644 --- a/sfall/ScriptOps/ObjectsOps.hpp +++ b/sfall/ScriptOps/ObjectsOps.hpp @@ -618,3 +618,13 @@ static void sf_unjam_lock() { static void sf_get_current_inven_size() { opHandler.setReturn(sf_item_total_size(opHandler.arg(0).asObject()), DATATYPE_INT); } + +static void sf_get_object_data() { + BYTE* object_ptr = (BYTE*)opHandler.arg(0).asObject(); + opHandler.setReturn(*(long*)(object_ptr + opHandler.arg(1).asInt()), DATATYPE_INT); +} + +static void sf_set_object_data() { + BYTE* object_ptr = (BYTE*)opHandler.arg(0).asObject(); + *(long*)(object_ptr + opHandler.arg(1).asInt()) = opHandler.arg(2).asInt(); +}