BGE LibLoad: Allow the user to disable loading text datablocks if they want to attempt to increase security by not loading potential Python scripts.
This commit is contained in:
@@ -172,7 +172,7 @@ General functions
|
||||
|
||||
Restarts the current game by reloading the .blend file (the last saved version, not what is currently running).
|
||||
|
||||
.. function:: LibLoad(blend, type, data, load_actions=False, verbose=False)
|
||||
.. function:: LibLoad(blend, type, data, load_actions=False, verbose=False, load_scripts=True)
|
||||
|
||||
Converts the all of the datablocks of the given type from the given blend.
|
||||
|
||||
@@ -186,6 +186,8 @@ General functions
|
||||
:type load_actions: bool
|
||||
:arg verbose: Whether or not to print debugging information (e.g., "SceneName: Scene")
|
||||
:type verbose: bool
|
||||
:arg load_scripts: Whether or not to load text datablocks as well (can be disabled for some extra security)
|
||||
:type load_scripts: bool
|
||||
|
||||
.. function:: LibNew(name, type, data)
|
||||
|
||||
|
@@ -988,8 +988,7 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha
|
||||
|
||||
load_datablocks(main_newlib, bpy_openlib, path, idcode);
|
||||
|
||||
if (idcode==ID_SCE) {
|
||||
/* assume we want text blocks too */
|
||||
if (idcode==ID_SCE && options & LIB_LOAD_LOAD_SCRIPTS) {
|
||||
load_datablocks(main_newlib, bpy_openlib, path, ID_TXT);
|
||||
}
|
||||
|
||||
@@ -1045,8 +1044,8 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha
|
||||
}
|
||||
|
||||
/* Handle any text datablocks */
|
||||
|
||||
addImportMain(main_newlib);
|
||||
if (options & LIB_LOAD_LOAD_SCRIPTS)
|
||||
addImportMain(main_newlib);
|
||||
|
||||
/* Now handle all the actions */
|
||||
if (options & LIB_LOAD_LOAD_ACTIONS) {
|
||||
|
@@ -182,6 +182,7 @@ public:
|
||||
{
|
||||
LIB_LOAD_LOAD_ACTIONS = 1,
|
||||
LIB_LOAD_VERBOSE = 2,
|
||||
LIB_LOAD_LOAD_SCRIPTS = 4,
|
||||
};
|
||||
|
||||
|
||||
|
@@ -676,12 +676,12 @@ static PyObject *gLibLoad(PyObject*, PyObject* args, PyObject* kwds)
|
||||
char *err_str= NULL;
|
||||
|
||||
short options=0;
|
||||
int load_actions=0, verbose=0;
|
||||
int load_actions=0, verbose=0, load_scripts=1;
|
||||
|
||||
static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", NULL};
|
||||
static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", "load_scripts", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*ii:LibLoad", const_cast<char**>(kwlist),
|
||||
&path, &group, &py_buffer, &load_actions, &verbose))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*iii:LibLoad", const_cast<char**>(kwlist),
|
||||
&path, &group, &py_buffer, &load_actions, &verbose, &load_scripts))
|
||||
return NULL;
|
||||
|
||||
/* setup options */
|
||||
@@ -689,6 +689,8 @@ static PyObject *gLibLoad(PyObject*, PyObject* args, PyObject* kwds)
|
||||
options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_ACTIONS;
|
||||
if (verbose != 0)
|
||||
options |= KX_BlenderSceneConverter::LIB_LOAD_VERBOSE;
|
||||
if (load_scripts != 0)
|
||||
options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_SCRIPTS;
|
||||
|
||||
if (!py_buffer.buf)
|
||||
{
|
||||
|
Reference in New Issue
Block a user