Added "add_trait" script function

Replaced some C-style casting with pre-defined ptr_* variables.
This commit is contained in:
NovaRain
2019-10-20 19:31:08 +08:00
parent ac10bce231
commit 3ef6056a77
12 changed files with 45 additions and 20 deletions
+1
View File
@@ -224,6 +224,7 @@
#define ADD_PERK_MODE_REMOVE (4) // remove from the list of selectable perks #define ADD_PERK_MODE_REMOVE (4) // remove from the list of selectable perks
// sfall_funcX macros // sfall_funcX macros
#define add_trait(traitId) sfall_func1("add_trait", traitId)
#define art_cache_clear sfall_func0("art_cache_clear") #define art_cache_clear sfall_func0("art_cache_clear")
#define attack_is_aimed sfall_func0("attack_is_aimed") #define attack_is_aimed sfall_func0("attack_is_aimed")
#define create_win(winName, x, y, w, h) sfall_func5("create_win", winName, x, y, w, h) #define create_win(winName, x, y, w, h) sfall_func5("create_win", winName, x, y, w, h)
@@ -512,6 +512,9 @@ Some utility/math functions are available:
- can take off player's equipped item when the inventory is opened, or the player is in the barter screen - can take off player's equipped item when the inventory is opened, or the player is in the barter screen
- slot: 0 - armor slot, 1 - right slot, 2 - left slot (see INVEN_TYPE_* in define.h) - slot: 0 - armor slot, 1 - right slot, 2 - left slot (see INVEN_TYPE_* in define.h)
> void sfall_func1("add_trait", int traitId)
- adds the specified trait to the player
------------------------ ------------------------
------ MORE INFO ------- ------ MORE INFO -------
------------------------ ------------------------
+1 -1
View File
@@ -75,7 +75,7 @@ DWORD* ptr_gdBarterMod = reinterpret_cast<DWORD*>(_gdBarterMod);
DWORD* ptr_gdNumOptions = reinterpret_cast<DWORD*>(_gdNumOptions); DWORD* ptr_gdNumOptions = reinterpret_cast<DWORD*>(_gdNumOptions);
DWORD* ptr_gIsSteal = reinterpret_cast<DWORD*>(_gIsSteal); DWORD* ptr_gIsSteal = reinterpret_cast<DWORD*>(_gIsSteal);
DWORD* ptr_glblmode = reinterpret_cast<DWORD*>(_glblmode); DWORD* ptr_glblmode = reinterpret_cast<DWORD*>(_glblmode);
DWORD* ptr_gmouse_current_cursor = reinterpret_cast<DWORD*>(_gmouse_current_cursor); long* ptr_gmouse_current_cursor = reinterpret_cast<long*>(_gmouse_current_cursor);
DWORD* ptr_gmovie_played_list = reinterpret_cast<DWORD*>(_gmovie_played_list); DWORD* ptr_gmovie_played_list = reinterpret_cast<DWORD*>(_gmovie_played_list);
BYTE* ptr_GreenColor = reinterpret_cast<BYTE*>(_GreenColor); BYTE* ptr_GreenColor = reinterpret_cast<BYTE*>(_GreenColor);
DWORD* ptr_gsound_initialized = reinterpret_cast<DWORD*>(_gsound_initialized); DWORD* ptr_gsound_initialized = reinterpret_cast<DWORD*>(_gsound_initialized);
+1 -1
View File
@@ -317,7 +317,7 @@ extern DWORD* ptr_gdBarterMod;
extern DWORD* ptr_gdNumOptions; extern DWORD* ptr_gdNumOptions;
extern DWORD* ptr_gIsSteal; extern DWORD* ptr_gIsSteal;
extern DWORD* ptr_glblmode; extern DWORD* ptr_glblmode;
extern DWORD* ptr_gmouse_current_cursor; extern long* ptr_gmouse_current_cursor;
extern DWORD* ptr_gmovie_played_list; extern DWORD* ptr_gmovie_played_list;
extern BYTE* ptr_GreenColor; extern BYTE* ptr_GreenColor;
extern DWORD* ptr_gsound_initialized; extern DWORD* ptr_gsound_initialized;
+1 -1
View File
@@ -107,7 +107,7 @@ static void _stdcall ResetState(DWORD onLoad) {
} }
void GetSavePath(char* buf, char* ftype) { void GetSavePath(char* buf, char* ftype) {
sprintf(buf, "%s\\savegame\\slot%.2d\\sfall%s.sav", *(char**)_patches, *(DWORD*)_slot_cursor + 1 + LSPageOffset, ftype); //add SuperSave Page offset sprintf(buf, "%s\\savegame\\slot%.2d\\sfall%s.sav", *(char**)_patches, *ptr_slot_cursor + 1 + LSPageOffset, ftype); //add SuperSave Page offset
} }
static char SaveSfallDataFailMsg[128]; static char SaveSfallDataFailMsg[128];
+1 -1
View File
@@ -58,7 +58,7 @@ static DWORD real_perkLevelDataList[PERK_count];
static int real_tag_skill[4]; static int real_tag_skill[4];
//static DWORD real_bbox_sneak; //static DWORD real_bbox_sneak;
static const DWORD* list_com = (DWORD*)_list_com; static const DWORD* list_com = ptr_list_com;
static bool _stdcall IsInPidList(TGameObj* obj) { static bool _stdcall IsInPidList(TGameObj* obj) {
int pid = obj->pid & 0xFFFFFF; int pid = obj->pid & 0xFFFFFF;
+4 -4
View File
@@ -365,10 +365,10 @@ static DWORD _stdcall HandleFakeTraits(int isSelect) {
} }
if (a && !isSelect) { if (a && !isSelect) {
isSelect = 1; isSelect = 1;
*(DWORD*)_folder_card_fid = fakeTraits[i].Image; *ptr_folder_card_fid = fakeTraits[i].Image;
*(DWORD*)_folder_card_title = (DWORD)fakeTraits[i].Name; *ptr_folder_card_title = (DWORD)fakeTraits[i].Name;
*(DWORD*)_folder_card_title2 = 0; *ptr_folder_card_title2 = 0;
*(DWORD*)_folder_card_desc = (DWORD)fakeTraits[i].Desc; *ptr_folder_card_desc = (DWORD)fakeTraits[i].Desc;
} }
} }
return isSelect; return isSelect;
+1
View File
@@ -391,6 +391,7 @@ static void OpcodeInvalidArgs(const char* opcodeName) {
If you don't include opcode in this array, you should take care of all argument validation inside handler itself. If you don't include opcode in this array, you should take care of all argument validation inside handler itself.
*/ */
static const SfallOpcodeMetadata opcodeMetaArray[] = { static const SfallOpcodeMetadata opcodeMetaArray[] = {
{sf_add_trait, "add_trait", {DATATYPE_MASK_INT}},
{sf_create_win, "create_win", {DATATYPE_MASK_STR, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT}}, {sf_create_win, "create_win", {DATATYPE_MASK_STR, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT, DATATYPE_MASK_INT}},
{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}},
+2 -1
View File
@@ -118,10 +118,11 @@ static void sf_metarule_exist() {
- minArgs/maxArgs - minimum and maximum number of arguments allowed for this function (max 6) - minArgs/maxArgs - minimum and maximum number of arguments allowed for this function (max 6)
*/ */
static const SfallMetarule metaruleArray[] = { static const SfallMetarule metaruleArray[] = {
{"add_trait", sf_add_trait, 1, 1},
{"art_cache_clear", sf_art_cache_flush, 0, 0}, {"art_cache_clear", sf_art_cache_flush, 0, 0},
{"attack_is_aimed", sf_attack_is_aimed, 0, 0}, {"attack_is_aimed", sf_attack_is_aimed, 0, 0},
{"critter_inven_obj2", sf_critter_inven_obj2, 2, 2},
{"create_win", sf_create_win, 5, 6}, {"create_win", sf_create_win, 5, 6},
{"critter_inven_obj2", sf_critter_inven_obj2, 2, 2},
{"dialog_obj", sf_get_dialog_object, 0, 0}, {"dialog_obj", sf_get_dialog_object, 0, 0},
{"display_stats", sf_display_stats, 0, 0}, // refresh {"display_stats", sf_display_stats, 0, 0}, // refresh
{"exec_map_update_scripts", sf_exec_map_update_scripts, 0, 0}, {"exec_map_update_scripts", sf_exec_map_update_scripts, 0, 0},
+8 -8
View File
@@ -462,14 +462,14 @@ static void __declspec(naked) op_tile_get_objects() {
} }
static void _stdcall op_get_party_members2() { static void _stdcall op_get_party_members2() {
DWORD obj, mode = opHandler.arg(0).asInt(), isDead; DWORD mode = opHandler.arg(0).asInt(), isDead;
int i, actualCount = *(DWORD*)_partyMemberCount; int actualCount = *ptr_partyMemberCount;
DWORD arrayId = TempArray(0, 4); DWORD arrayId = TempArray(0, 4);
DWORD* partyMemberList = *(DWORD**)_partyMemberList; DWORD* partyMemberList = *ptr_partyMemberList;
for (i = 0; i < actualCount; i++) { for (int i = 0; i < actualCount; i++) {
obj = partyMemberList[i*4]; TGameObj* obj = reinterpret_cast<TGameObj*>(partyMemberList[i * 4]);
if (mode == 0) { // mode 0 will act just like op_party_member_count in fallout2 if (mode == 0) { // mode 0 will act just like op_party_member_count in fallout2
if ((*(DWORD*)(obj + 100) >> 24) != OBJ_TYPE_CRITTER) // obj type != critter if (obj->pid >> 24 != OBJ_TYPE_CRITTER) // obj type != critter
continue; continue;
__asm { __asm {
mov eax, obj; mov eax, obj;
@@ -478,7 +478,7 @@ static void _stdcall op_get_party_members2() {
} }
if (isDead) if (isDead)
continue; continue;
if (*(DWORD*)(obj + 36) & 1) // no idea.. if (obj->flags & 1) // Mouse_3d flag
continue; continue;
} }
arrays[arrayId].push_back((long)obj); arrays[arrayId].push_back((long)obj);
@@ -646,7 +646,7 @@ static void sf_get_loot_object() {
opHandler.setReturn((GetLoopFlags() & INTFACELOOT) ? LoadGameHook_LootTarget : 0, DATATYPE_INT); opHandler.setReturn((GetLoopFlags() & INTFACELOOT) ? LoadGameHook_LootTarget : 0, DATATYPE_INT);
} }
static const char* failedLoad = "%s() - failed to load a prototype id: %d"; static const char* failedLoad = "%s() - failed to load a prototype ID: %d";
static bool protoMaxLimitPatch = false; static bool protoMaxLimitPatch = false;
static void _stdcall get_proto_data2() { static void _stdcall get_proto_data2() {
+19
View File
@@ -625,3 +625,22 @@ end:
retn; retn;
} }
} }
static void sf_add_trait() {
if (*(DWORD*)(*(DWORD*)_obj_dude + 0x64) != PID_Player) {
opHandler.printOpcodeError("add_trait() - traits can be added only to the player.");
return;
}
long traitId = opHandler.arg(0).rawValue();
if (traitId >= TRAIT_fast_metabolism && traitId <= TRAIT_gifted) {
if (ptr_pc_traits[0] == -1) {
ptr_pc_traits[0] = traitId;
} else if (ptr_pc_traits[0] != traitId && ptr_pc_traits[1] == -1) {
ptr_pc_traits[1] = traitId;
} else {
opHandler.printOpcodeError("add_trait() - cannot add the trait ID: %d", traitId);
}
} else {
opHandler.printOpcodeError("add_trait() - invalid trait ID.");
}
}
+2 -2
View File
@@ -208,7 +208,7 @@ public:
if (UseScrollWheel) { if (UseScrollWheel) {
int count = 1; int count = 1;
if (MouseState.lZ > 0) { if (MouseState.lZ > 0) {
if (*(DWORD*)_gmouse_current_cursor == 2 || *(DWORD*)_gmouse_current_cursor == 3) { if (*ptr_gmouse_current_cursor == 2 || *ptr_gmouse_current_cursor == 3) {
__asm { __asm {
call display_scroll_up_; call display_scroll_up_;
} }
@@ -218,7 +218,7 @@ public:
while (count--) TapKey(DIK_UP); while (count--) TapKey(DIK_UP);
} }
} else if (MouseState.lZ < 0) { } else if (MouseState.lZ < 0) {
if (*(DWORD*)_gmouse_current_cursor == 2 || *(DWORD*)_gmouse_current_cursor == 3) { if (*ptr_gmouse_current_cursor == 2 || *ptr_gmouse_current_cursor == 3) {
__asm { __asm {
call display_scroll_down_; call display_scroll_down_;
} }