Added "get/set_object_data" script functions (from Mr.Stalin)

Changed read_byte, read_short, read_int, and read_string functions to not require AllowUnsafeScripting.
This commit is contained in:
NovaRain
2018-12-05 10:17:26 +08:00
parent 0a21e4abfa
commit d7d8de5e1a
8 changed files with 49 additions and 12 deletions
@@ -267,4 +267,21 @@
#define WPN_ANIM_MINIGUN (0x09) // (L) #define WPN_ANIM_MINIGUN (0x09) // (L)
#define WPN_ANIM_ROCKET_LAUNCHER (0x0A) // (M) #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 #endif // DEFINE_EXTRA_H
+2
View File
@@ -217,6 +217,7 @@
#define get_cursor_mode sfall_func0("get_cursor_mode") #define get_cursor_mode sfall_func0("get_cursor_mode")
#define get_flags(obj) sfall_func1("get_flags", obj) #define get_flags(obj) sfall_func1("get_flags", obj)
#define get_map_enter_position sfall_func0("get_map_enter_position") #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 get_outline(obj) sfall_func1("get_outline", obj)
#define intface_hide sfall_func0("intface_hide") #define intface_hide sfall_func0("intface_hide")
#define intface_is_hidden sfall_func0("intface_is_hidden") #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_flags(obj, flags) sfall_func2("set_flags", obj, flags)
#define set_ini_setting(setting, value) sfall_func2("set_ini_setting", setting, value) #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_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 set_outline(obj, color) sfall_func2("set_outline", obj, color)
#define spatial_radius(obj) sfall_func1("spatial_radius", obj) #define spatial_radius(obj) sfall_func1("spatial_radius", obj)
#define tile_refresh_display sfall_func0("tile_refresh_display") #define tile_refresh_display sfall_func0("tile_refresh_display")
+2 -2
View File
@@ -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 arg6 - The special effect flags for the attacker (use bwand DAM_* to check specific flags)
int arg7 - The weapon used in the attack int arg7 - The weapon used in the attack
int arg8 - The bodypart that was struck 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 arg10 - Number of bullets actually hit the target (1 for melee attacks)
int arg11 - The amount of knockback to the target int arg11 - The amount of knockback to the target
int arg12 - Attack Type (see ATKTYPE_* constants) 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). 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. 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. 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 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()) 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())
@@ -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) - 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 - 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 ------- ------ MORE INFO -------
------------------------ ------------------------
+4 -4
View File
@@ -1,8 +1,8 @@
*0x8156 - int read_byte(int address) 0x8156 - int read_byte(int address)
*0x8157 - int read_short(int address) 0x8157 - int read_short(int address)
*0x8158 - int read_int(int address) 0x8158 - int read_int(int address)
*0x8159 - string read_string(int address) 0x8159 - string read_string(int address)
*0x81cf - void write_byte(int address, int value) *0x81cf - void write_byte(int address, int value)
*0x81d0 - void write_short(int address, int value) *0x81d0 - void write_short(int address, int value)
+6 -6
View File
@@ -386,6 +386,7 @@ static const SfallOpcodeMetadata opcodeMetaArray[] = {
{sf_critter_inven_obj2, "critter_inven_obj2", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT}}, {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_current_inven_size, "get_current_inven_size", {DATATYPE_MASK_VALID_OBJ}},
{sf_get_flags, "get_flags", {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_get_outline, "get_outline", {DATATYPE_MASK_VALID_OBJ}},
{sf_inventory_redraw, "inventory_redraw", {DATATYPE_MASK_INT}}, {sf_inventory_redraw, "inventory_redraw", {DATATYPE_MASK_INT}},
{sf_item_weight, "item_weight", {DATATYPE_MASK_VALID_OBJ}}, {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_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_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_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_set_outline, "set_outline", {DATATYPE_MASK_VALID_OBJ, DATATYPE_MASK_INT}},
{sf_spatial_radius, "spatial_radius", {DATATYPE_MASK_VALID_OBJ}}, {sf_spatial_radius, "spatial_radius", {DATATYPE_MASK_VALID_OBJ}},
{sf_unjam_lock, "unjam_lock", {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(0x46ce6c, (DWORD)opcodes); //call that actually jumps to the opcode
SafeWrite32(0x46e390, (DWORD)opcodes); //mov that writes to the opcode SafeWrite32(0x46e390, (DWORD)opcodes); //mov that writes to the opcode
if (AllowUnsafeScripting) { opcodes[0x156] = ReadByte;
opcodes[0x156] = ReadByte; opcodes[0x157] = ReadShort;
opcodes[0x157] = ReadShort; opcodes[0x158] = ReadInt;
opcodes[0x158] = ReadInt; opcodes[0x159] = ReadString;
opcodes[0x159] = ReadString;
}
opcodes[0x15a] = SetPCBaseStat; opcodes[0x15a] = SetPCBaseStat;
opcodes[0x15b] = SetPCExtraStat; opcodes[0x15b] = SetPCExtraStat;
opcodes[0x15c] = GetPCBaseStat; opcodes[0x15c] = GetPCBaseStat;
+2
View File
@@ -114,6 +114,7 @@ static const SfallMetarule metaruleArray[] = {
{"get_flags", sf_get_flags, 1, 1}, {"get_flags", sf_get_flags, 1, 1},
{"get_map_enter_position", sf_get_map_enter_position, 0, 0}, {"get_map_enter_position", sf_get_map_enter_position, 0, 0},
{"get_metarule_table", sf_get_metarule_table, 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}, {"get_outline", sf_get_outline, 1, 1},
{"intface_hide", sf_intface_hide, 0, 0}, {"intface_hide", sf_intface_hide, 0, 0},
{"intface_is_hidden", sf_intface_is_hidden, 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_flags", sf_set_flags, 2, 2},
{"set_ini_setting", sf_set_ini_setting, 2, 2}, {"set_ini_setting", sf_set_ini_setting, 2, 2},
{"set_map_enter_position", sf_set_map_enter_position, 3, 3}, {"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}, {"set_outline", sf_set_outline, 2, 2},
{"spatial_radius", sf_spatial_radius, 1, 1}, {"spatial_radius", sf_spatial_radius, 1, 1},
{"tile_refresh_display", sf_tile_refresh_display, 0, 0}, {"tile_refresh_display", sf_tile_refresh_display, 0, 0},
+10
View File
@@ -618,3 +618,13 @@ static void sf_unjam_lock() {
static void sf_get_current_inven_size() { static void sf_get_current_inven_size() {
opHandler.setReturn(sf_item_total_size(opHandler.arg(0).asObject()), DATATYPE_INT); 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();
}