From 69e7bb57d4c4eba2cdf8b2b2bd165f59043dade7 Mon Sep 17 00:00:00 2001
From: "alexey.lysiuk" <alexey.lysiuk@gmail.com>
Date: Fri, 18 Aug 2017 11:25:33 +0300
Subject: [PATCH] Fixed VM abort with null activator for SecretTrigger object

https://forum.zdoom.org/viewtopic.php?t=57612
---
 src/p_spec.cpp                                 | 10 ++++++++++
 wadsrc/static/zscript/base.txt                 |  1 +
 wadsrc/static/zscript/shared/secrettrigger.txt |  2 +-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/p_spec.cpp b/src/p_spec.cpp
index 35ed13306..d0d972448 100644
--- a/src/p_spec.cpp
+++ b/src/p_spec.cpp
@@ -602,6 +602,16 @@ DEFINE_ACTION_FUNCTION(AActor, GiveSecret)
 	return 0;
 }
 
+DEFINE_ACTION_FUNCTION(FLevelLocals, GiveSecret)
+{
+	PARAM_PROLOGUE;
+	PARAM_OBJECT(activator, AActor);
+	PARAM_BOOL_DEF(printmessage);
+	PARAM_BOOL_DEF(playsound);
+	P_GiveSecret(activator, printmessage, playsound, -1);
+	return 0;
+}
+
 //============================================================================
 //
 // P_PlayerOnSpecialFlat
diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt
index 4be135118..e3f453fca 100644
--- a/wadsrc/static/zscript/base.txt
+++ b/wadsrc/static/zscript/base.txt
@@ -530,6 +530,7 @@ struct LevelLocals native
 	native int GetUDMFInt(int type, int index, Name key);
 	native double GetUDMFFloat(int type, int index, Name key);
 	native bool ExecuteSpecial(int special, Actor activator, line linedef, bool lineside, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0, int arg5 = 0);
+	native static void GiveSecret(Actor activator, bool printmsg = true, bool playsound = true);
 	native static void StartSlideshow(Name whichone = 'none');
 	native static void WorldDone();
 	native static void RemoveAllBots(bool fromlist);
diff --git a/wadsrc/static/zscript/shared/secrettrigger.txt b/wadsrc/static/zscript/shared/secrettrigger.txt
index c60399600..7a2a78ef4 100644
--- a/wadsrc/static/zscript/shared/secrettrigger.txt
+++ b/wadsrc/static/zscript/shared/secrettrigger.txt
@@ -17,7 +17,7 @@ class SecretTrigger : Actor
 
 	override void Activate (Actor activator)
 	{
-		activator.GiveSecret(args[0] <= 1, (args[0] == 0 || args[0] == 2));
+		Level.GiveSecret(activator, args[0] <= 1, (args[0] == 0 || args[0] == 2));
 		Destroy ();
 	}