diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index f948c506..7c0a0023 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -290,6 +290,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) @@ -365,7 +367,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 294c9215..990dacc1 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -796,9 +796,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/EngineUtils.cpp b/sfall/FalloutEngine/EngineUtils.cpp index 2071a615..bd18c3b8 100644 --- a/sfall/FalloutEngine/EngineUtils.cpp +++ b/sfall/FalloutEngine/EngineUtils.cpp @@ -102,7 +102,6 @@ bool CheckProtoID(DWORD pid) { if (pid == 0) return false; long type = pid >> 24; if (type > fo::ObjType::OBJ_TYPE_MISC) return false; - return (static_cast(pid & 0xFFFF) < fo::var::protoLists[type].totalCount); } diff --git a/sfall/Modules/Scripting/Handlers/Metarule.cpp b/sfall/Modules/Scripting/Handlers/Metarule.cpp index 0c517ec6..513d70e5 100644 --- a/sfall/Modules/Scripting/Handlers/Metarule.cpp +++ b/sfall/Modules/Scripting/Handlers/Metarule.cpp @@ -121,7 +121,6 @@ static const SfallMetarule metarules[] = { {"obj_under_cursor", mf_obj_under_cursor, 2, 2, 0, {ARG_INT, ARG_INT}}, {"objects_in_radius", mf_objects_in_radius, 3, 4, 0, {ARG_INT, ARG_INT, ARG_INT, ARG_INT}}, {"outlined_object", mf_outlined_object, 0, 0}, - {"proto_exists", mf_proto_exists, 1, 1, 0, {ARG_INT}}, {"real_dude_obj", mf_real_dude_obj, 0, 0}, {"remove_timer_event", mf_remove_timer_event, 0, 1, -1, {ARG_INT}}, {"set_can_rest_on_map", mf_set_rest_on_map, 3, 3, -1, {ARG_INT, ARG_INT, ARG_INT}}, diff --git a/sfall/Modules/Scripting/Handlers/Objects.cpp b/sfall/Modules/Scripting/Handlers/Objects.cpp index a554dbc4..6990e725 100644 --- a/sfall/Modules/Scripting/Handlers/Objects.cpp +++ b/sfall/Modules/Scripting/Handlers/Objects.cpp @@ -446,17 +446,13 @@ void mf_get_loot_object(OpcodeContext& ctx) { ctx.setReturn((GetLoopFlags() & INTFACELOOT) ? fo::var::target_stack[fo::var::target_curr_stack] : 0); } -void mf_proto_exists(OpcodeContext& ctx) { - ctx.setReturn(fo::CheckProtoID(ctx.arg(0).rawValue())); -} - static bool protoMaxLimitPatch = false; void op_get_proto_data(OpcodeContext& ctx) { + long result = -1; fo::Proto* protoPtr; int pid = ctx.arg(0).rawValue(); - int result = fo::func::proto_ptr(pid, &protoPtr); - if (result != -1) { + if (fo::CheckProtoID(pid) && fo::func::proto_ptr(pid, &protoPtr) != result) { result = *(long*)((BYTE*)protoPtr + ctx.arg(1).rawValue()); } else { ctx.printOpcodeError(protoFailedLoad, ctx.getOpcodeName(), pid); @@ -466,7 +462,7 @@ void op_get_proto_data(OpcodeContext& ctx) { void op_set_proto_data(OpcodeContext& ctx) { int pid = ctx.arg(0).rawValue(); - if (CritterStats::SetProtoData(pid, ctx.arg(1).rawValue(), ctx.arg(2).rawValue()) != -1) { + if (fo::CheckProtoID(pid) && CritterStats::SetProtoData(pid, ctx.arg(1).rawValue(), ctx.arg(2).rawValue()) != -1) { if (!protoMaxLimitPatch) { Objects::LoadProtoAutoMaxLimit(); protoMaxLimitPatch = true; diff --git a/sfall/Modules/Scripting/Handlers/Objects.h b/sfall/Modules/Scripting/Handlers/Objects.h index a3b43f18..ba1d8d7e 100644 --- a/sfall/Modules/Scripting/Handlers/Objects.h +++ b/sfall/Modules/Scripting/Handlers/Objects.h @@ -89,8 +89,6 @@ void mf_obj_under_cursor(OpcodeContext&); void mf_get_loot_object(OpcodeContext&); -void mf_proto_exists(OpcodeContext&); - void op_get_proto_data(OpcodeContext&); void op_set_proto_data(OpcodeContext&);