Skip to content

Commit

Permalink
Merge pull request #694 from UPBGE/experimental-component-security
Browse files Browse the repository at this point in the history
UPBGE: Add the option to disable component execution on game start
  • Loading branch information
lordloki authored May 27, 2018
2 parents 96567f2 + c80501f commit a8f9cf3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
12 changes: 12 additions & 0 deletions source/blender/editors/space_logic/logic_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include "BKE_main.h"
#include "BKE_sca.h"
#include "BKE_python_component.h"
#include "BKE_global.h"
#include "BKE_report.h"

#include "ED_logic.h"
#include "ED_object.h"
Expand Down Expand Up @@ -746,6 +748,11 @@ static int component_add_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C);
char import[MAX_NAME];

if ((G.f & G_SCRIPT_AUTOEXEC) == 0) {
BKE_report(op->reports, RPT_WARNING, "Python script/component auto-execution disable, look in the userpref to activate...");
return OPERATOR_CANCELLED;
}

if (!ob) {
return OPERATOR_CANCELLED;
}
Expand Down Expand Up @@ -836,6 +843,11 @@ static int component_reload_exec(bContext *C, wmOperator *op)
PythonComponent *pc = NULL, *prev_pc = NULL;
int index = RNA_int_get(op->ptr, "index");

if ((G.f & G_SCRIPT_AUTOEXEC) == 0) {
BKE_report(op->reports, RPT_WARNING, "Python script/component auto-execution disable, look in the userpref to activate...");
return OPERATOR_CANCELLED;
}

if(!ob) {
return OPERATOR_CANCELLED;
}
Expand Down
2 changes: 1 addition & 1 deletion source/blender/makesrna/intern/rna_userdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -4036,7 +4036,7 @@ static void rna_def_userdef_system(BlenderRNA *brna)

prop = RNA_def_property(srna, "use_scripts_auto_execute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", USER_SCRIPT_AUTOEXEC_DISABLE);
RNA_def_property_ui_text(prop, "Auto Run Python Scripts",
RNA_def_property_ui_text(prop, "Auto Run Python Scripts and Components",
"Allow any .blend file to run scripts automatically "
"(unsafe with blend files from an untrusted source)");
RNA_def_property_update(prop, 0, "rna_userdef_script_autoexec_update");
Expand Down
23 changes: 14 additions & 9 deletions source/gameengine/Converter/BL_BlenderDataConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,18 +1730,23 @@ void BL_ConvertBlenderObjects(struct Main *maggie,
gameobj->ResetState();
}

// Convert the python components of each object.
for (KX_GameObject *gameobj : sumolist) {
Object *blenderobj = gameobj->GetBlenderObject();
BL_ConvertComponentsObject(gameobj, blenderobj);
}
// Convert the python components of each object if the component execution is available.
if (G.f & G_SCRIPT_AUTOEXEC) {
for (KX_GameObject *gameobj : sumolist) {
Object *blenderobj = gameobj->GetBlenderObject();
BL_ConvertComponentsObject(gameobj, blenderobj);
}

for (KX_GameObject *gameobj : objectlist) {
if (gameobj->GetComponents()) {
// Register object for component update.
kxscene->GetPythonComponentManager().RegisterObject(gameobj);
for (KX_GameObject *gameobj : objectlist) {
if (gameobj->GetComponents()) {
// Register object for component update.
kxscene->GetPythonComponentManager().RegisterObject(gameobj);
}
}
}
else {
CM_Warning("Python components auto-execution disabled");
}

// Cleanup converted set of group objects.
convertedlist->Release();
Expand Down

0 comments on commit a8f9cf3

Please sign in to comment.