From 043d790a755e9d0620154d5458af8ca07adc0047 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 26 May 2021 08:48:06 +0800 Subject: [PATCH] Removed "proto_exists" function in previous commit Added macro for checking pid. --- artifacts/scripting/headers/sfall.h | 3 ++- artifacts/scripting/sfall function notes.txt | 3 --- sfall/FalloutEngine.cpp | 1 - sfall/ScriptOps/MetaruleOps.hpp | 1 - sfall/ScriptOps/ObjectsOps.hpp | 17 +++-------------- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index ba8b4e67..f243b7d4 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -264,6 +264,8 @@ // clears the keyboard input buffer, use it in the HOOK_KEYPRESS hook to clear keyboard events before calling functions that are waiting for keyboard input #define clear_keyboard_buffer metarule3(201, 0, 0, 0) +// checks if the specified PID number exists in the list of registered protos +#define check_pid(pid) (get_proto_data(pid, 0) != -1) /* sfall_funcX macros */ #define add_extra_msg_file(name) sfall_func1("add_extra_msg_file", name) @@ -332,7 +334,6 @@ #define overlay_clear(winType) sfall_func2("interface_overlay", winType, 2) #define overlay_clear_rectangle(winType, x, y, w, h) sfall_func6("interface_overlay", winType, 2, x, y, w, h) #define overlay_destroy(winType) sfall_func2("interface_overlay", winType, 0) -#define proto_exists(pid) sfall_func1("proto_exists", pid) #define real_dude_obj sfall_func0("real_dude_obj") #define remove_all_timer_events sfall_func0("remove_timer_event") #define remove_timer_event(fixedParam) sfall_func1("remove_timer_event", fixedParam) diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index c02e7392..ef12cfcf 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -742,9 +742,6 @@ optional arguments: - gvarNumber: the number of the global variable controlling the quest - thresholdValue: the value of the global variable at which the quest is counted as a failure -> bool sfall_func1("proto_exists", int pid) -- returns True if the specified PID number exists in the list of registered protos - ------------------------ ------ MORE INFO ------- ------------------------ diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index c63beca0..242532d9 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -580,7 +580,6 @@ bool CheckProtoID(DWORD pid) { if (pid == 0) return false; long type = pid >> 24; if (type > OBJ_TYPE_MISC) return false; - return (static_cast(pid & 0xFFFF) < ptr_protoLists[type].totalCount); } diff --git a/sfall/ScriptOps/MetaruleOps.hpp b/sfall/ScriptOps/MetaruleOps.hpp index 398bbb88..cb409101 100644 --- a/sfall/ScriptOps/MetaruleOps.hpp +++ b/sfall/ScriptOps/MetaruleOps.hpp @@ -164,7 +164,6 @@ static const SfallMetarule metaruleArray[] = { {"obj_under_cursor", mf_obj_under_cursor, 2, 2}, {"objects_in_radius", mf_objects_in_radius, 3, 4}, {"outlined_object", mf_outlined_object, 0, 0}, - {"proto_exists", mf_proto_exists, 1, 1}, {"real_dude_obj", mf_real_dude_obj, 0, 0}, {"remove_timer_event", mf_remove_timer_event, 0, 1}, {"set_car_intface_art", mf_set_car_intface_art, 1, 1}, diff --git a/sfall/ScriptOps/ObjectsOps.hpp b/sfall/ScriptOps/ObjectsOps.hpp index fe50226d..d056a135 100644 --- a/sfall/ScriptOps/ObjectsOps.hpp +++ b/sfall/ScriptOps/ObjectsOps.hpp @@ -596,17 +596,6 @@ static void mf_get_loot_object() { opHandler.setReturn((GetLoopFlags() & INTFACELOOT) ? ptr_target_stack[*ptr_target_curr_stack] : 0); } -static void mf_proto_exists() { - const ScriptValue &pidArg = opHandler.arg(0); - - if (pidArg.isInt()) { - opHandler.setReturn(CheckProtoID(pidArg.rawValue())); - } else { - OpcodeInvalidArgs("proto_exists"); - opHandler.setReturn(0); - } -} - static bool protoMaxLimitPatch = false; static void __stdcall op_get_proto_data2() { @@ -614,10 +603,10 @@ static void __stdcall op_get_proto_data2() { &offsetArg = opHandler.arg(1); if (pidArg.isInt() && offsetArg.isInt()) { + long result = -1; sProto* protoPtr; int pid = pidArg.rawValue(); - int result = fo_proto_ptr(pid, &protoPtr); - if (result != -1) { + if (CheckProtoID(pid) && fo_proto_ptr(pid, &protoPtr) != result) { result = *(long*)((BYTE*)protoPtr + offsetArg.rawValue()); } else { opHandler.printOpcodeError(protoFailedLoad, "get_proto_data", pid); @@ -641,7 +630,7 @@ static void __stdcall op_set_proto_data2() { if (pidArg.isInt() && offsetArg.isInt() && valueArg.isInt()) { sProto* protoPtr; int pid = pidArg.rawValue(); - if (fo_proto_ptr(pid, &protoPtr) != -1) { + if (CheckProtoID(pid) && fo_proto_ptr(pid, &protoPtr) != -1) { *(long*)((BYTE*)protoPtr + offsetArg.rawValue()) = valueArg.rawValue(); if (!protoMaxLimitPatch) { Objects_LoadProtoAutoMaxLimit();