From 1cbb927533a69c04b81aeea77dd0560ac6c3a7b4 Mon Sep 17 00:00:00 2001
From: D-AIRY <admin@ds-servers.com>
Date: Sat, 1 Mar 2025 23:10:03 +0300
Subject: [PATCH] Decal system

---
 docs/gen-entity.js                        |   2 +
 proj/sxanim/vs2013/sxanim.vcxproj         |   2 +
 proj/sxanim/vs2013/sxanim.vcxproj.filters |   6 +
 proj/sxgame/vs2013/sxgame.vcxproj         |   2 +
 proj/sxgame/vs2013/sxgame.vcxproj.filters |   6 +
 proj/terrax/vs2013/terrax.vcxproj         |   2 +
 proj/terrax/vs2013/terrax.vcxproj.filters |   6 +
 source/anim/AnimatedModelProvider.cpp     |   5 +
 source/anim/AnimatedModelProvider.h       |   2 +
 source/anim/Decal.cpp                     | 106 ++++--
 source/anim/Decal.h                       |  10 +-
 source/anim/DecalProvider.cpp             |  28 ++
 source/anim/DecalProvider.h               |  10 +
 source/anim/DynamicModel.cpp              |  10 +-
 source/anim/DynamicModel.h                |   2 +
 source/anim/DynamicModelProvider.cpp      |   5 +
 source/anim/DynamicModelProvider.h        |   3 +
 source/anim/ModelOverlay.cpp              |   7 +
 source/anim/ModelOverlay.h                |   1 +
 source/anim/StaticModelProvider.cpp       |  20 ++
 source/anim/StaticModelProvider.h         |  18 ++
 source/anim/plugin_main.cpp               |  43 ++-
 source/common                             |   2 +-
 source/core/Config.cpp                    | 357 ++++++++++-----------
 source/core/Config.h                      |  10 +
 source/core/Core.cpp                      |   1 -
 source/core/JSON.cpp                      |  76 ++++-
 source/core/JSON.h                        |  81 +++--
 source/game/BaseEntity.h                  |   4 +
 source/game/BaseMover.cpp                 |   2 +-
 source/game/Editable.cpp                  |  15 +-
 source/game/Editable.h                    |   2 +
 source/game/EditorObject.cpp              |  25 +-
 source/game/EntityFactory.h               |   3 +
 source/game/EntityManager.cpp             |  12 +-
 source/game/GameData.cpp                  |   5 +-
 source/game/InfoOverlay.cpp               | 372 ++++++++++++++++++++++
 source/game/InfoOverlay.h                 |  71 +++++
 source/game/proptable.cpp                 |  53 +--
 source/game/proptable.h                   |  33 +-
 source/gdefines.h                         |   6 +
 source/render/Scene.cpp                   |  10 +
 source/render/Scene.h                     |   2 +
 source/render/plugin_main.cpp             |  35 ++
 source/terrax/CommandBuildModel.cpp       |   2 +-
 source/terrax/CommandCreate.cpp           |  84 ++++-
 source/terrax/CommandCreate.h             |   6 +-
 source/terrax/Editor.cpp                  |   2 +
 source/terrax/Editor.h                    |   1 +
 source/terrax/GroupObject.cpp             |   4 +-
 source/terrax/PropertyWindow.cpp          |   3 +-
 source/terrax/PropertyWindow.h            |   8 +-
 source/terrax/ResourceBrowser.cpp         |  26 ++
 source/terrax/ResourceBrowser.h           |  46 +++
 source/terrax/mainWindow.cpp              | 106 +++---
 source/terrax/terrax.cpp                  |   2 +-
 source/xParticles/Editable.h              |   5 +
 source/xUI/UIViewport.cpp                 |   2 +-
 source/xUI/UIWindow.cpp                   |  17 +-
 source/xcommon/XEvents.h                  |   2 +
 source/xcommon/editor/IXEditable.h        |   3 +-
 source/xcommon/editor/IXEditorObject.h    |   1 +
 source/xcommon/resource/IXDecal.h         |   8 +-
 source/xcommon/resource/IXDecalProvider.h |   2 +-
 source/xcsg/Editable.h                    |   5 +
 source/xcsg/EditorObject.cpp              |   2 +-
 66 files changed, 1388 insertions(+), 422 deletions(-)
 create mode 100644 source/anim/StaticModelProvider.cpp
 create mode 100644 source/anim/StaticModelProvider.h
 create mode 100644 source/game/InfoOverlay.cpp
 create mode 100644 source/game/InfoOverlay.h
 create mode 100644 source/terrax/ResourceBrowser.cpp
 create mode 100644 source/terrax/ResourceBrowser.h

diff --git a/docs/gen-entity.js b/docs/gen-entity.js
index 95ba19a92..6641926e0 100644
--- a/docs/gen-entity.js
+++ b/docs/gen-entity.js
@@ -19,6 +19,7 @@ g_mFieldTypes = {
 	"DEFINE_FIELD_STRING": "string",
 	"DEFINE_FIELD_ANGLES": "angles",
 	"DEFINE_FIELD_INT": "int",
+	"DEFINE_FIELD_UINT": "uint",
 	"DEFINE_FIELD_ENUM": null,
 	"DEFINE_FIELD_FLOAT": "float",
 	"DEFINE_FIELD_BOOL": "bool",
@@ -29,6 +30,7 @@ g_mFieldTypes = {
 g_mInputTypes = {
 	"PDF_NONE": "none",
 	"PDF_INT": "int",
+	"PDF_UINT": "uint",
 	"PDF_FLOAT": "float",
 	"PDF_VECTOR": "float3",
 	"PDF_VECTOR4": "float4",
diff --git a/proj/sxanim/vs2013/sxanim.vcxproj b/proj/sxanim/vs2013/sxanim.vcxproj
index 07d961364..e20becf01 100644
--- a/proj/sxanim/vs2013/sxanim.vcxproj
+++ b/proj/sxanim/vs2013/sxanim.vcxproj
@@ -191,6 +191,7 @@
     <ClCompile Include="..\..\..\source\anim\plugin_main.cpp" />
     <ClCompile Include="..\..\..\source\anim\Renderable.cpp" />
     <ClCompile Include="..\..\..\source\anim\RenderableVisibility.cpp" />
+    <ClCompile Include="..\..\..\source\anim\StaticModelProvider.cpp" />
     <ClCompile Include="..\..\..\source\anim\Updatable.cpp" />
   </ItemGroup>
   <ItemGroup>
@@ -205,6 +206,7 @@
     <ClInclude Include="..\..\..\source\anim\ModelOverlay.h" />
     <ClInclude Include="..\..\..\source\anim\Renderable.h" />
     <ClInclude Include="..\..\..\source\anim\RenderableVisibility.h" />
+    <ClInclude Include="..\..\..\source\anim\StaticModelProvider.h" />
     <ClInclude Include="..\..\..\source\anim\Updatable.h" />
     <ClInclude Include="..\..\..\source\xcommon\IXScene.h" />
     <ClInclude Include="..\..\..\source\xcommon\resource\IXDecal.h" />
diff --git a/proj/sxanim/vs2013/sxanim.vcxproj.filters b/proj/sxanim/vs2013/sxanim.vcxproj.filters
index 0a83dc43d..e907c6c64 100644
--- a/proj/sxanim/vs2013/sxanim.vcxproj.filters
+++ b/proj/sxanim/vs2013/sxanim.vcxproj.filters
@@ -58,6 +58,9 @@
     <ClCompile Include="..\..\..\source\anim\Decal.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\source\anim\StaticModelProvider.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\source\anim\Renderable.h">
@@ -108,5 +111,8 @@
     <ClInclude Include="..\..\..\source\anim\Decal.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\source\anim\StaticModelProvider.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/proj/sxgame/vs2013/sxgame.vcxproj b/proj/sxgame/vs2013/sxgame.vcxproj
index 6b2bc8d73..8ab0fd8f3 100644
--- a/proj/sxgame/vs2013/sxgame.vcxproj
+++ b/proj/sxgame/vs2013/sxgame.vcxproj
@@ -210,6 +210,7 @@
     <ClCompile Include="..\..\..\source\game\GUICraftController.cpp" />
     <ClCompile Include="..\..\..\source\game\GUIInventoryController.cpp" />
     <ClCompile Include="..\..\..\source\game\HUDcontroller.cpp" />
+    <ClCompile Include="..\..\..\source\game\InfoOverlay.cpp" />
     <ClCompile Include="..\..\..\source\game\InfoParticlePlayer.cpp" />
     <ClCompile Include="..\..\..\source\game\LadderMovementController.cpp" />
     <ClCompile Include="..\..\..\source\game\LightDirectional.cpp" />
@@ -297,6 +298,7 @@
     <ClInclude Include="..\..\..\source\game\HUDcontroller.h" />
     <ClInclude Include="..\..\..\source\game\IGameState.h" />
     <ClInclude Include="..\..\..\source\game\IMovementController.h" />
+    <ClInclude Include="..\..\..\source\game\InfoOverlay.h" />
     <ClInclude Include="..\..\..\source\game\InfoParticlePlayer.h" />
     <ClInclude Include="..\..\..\source\game\LadderMovementController.h" />
     <ClInclude Include="..\..\..\source\game\LightSun.h" />
diff --git a/proj/sxgame/vs2013/sxgame.vcxproj.filters b/proj/sxgame/vs2013/sxgame.vcxproj.filters
index ad313030c..01a241c50 100644
--- a/proj/sxgame/vs2013/sxgame.vcxproj.filters
+++ b/proj/sxgame/vs2013/sxgame.vcxproj.filters
@@ -381,6 +381,9 @@
     <ClCompile Include="..\..\..\source\game\NarrowPassageMovementController.cpp">
       <Filter>Source Files\character_movement</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\source\game\InfoOverlay.cpp">
+      <Filter>Source Files\ents\info</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\source\game\sxgame.h">
@@ -665,6 +668,9 @@
     <ClInclude Include="..\..\..\source\game\NarrowPassageMovementController.h">
       <Filter>Header Files\character_movement</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\source\game\InfoOverlay.h">
+      <Filter>Header Files\ents\info</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="..\..\..\source\game\sxgame.rc">
diff --git a/proj/terrax/vs2013/terrax.vcxproj b/proj/terrax/vs2013/terrax.vcxproj
index fad89107a..461cd9771 100644
--- a/proj/terrax/vs2013/terrax.vcxproj
+++ b/proj/terrax/vs2013/terrax.vcxproj
@@ -244,6 +244,7 @@
     <ClCompile Include="..\..\..\source\terrax\MaterialEditor.cpp" />
     <ClCompile Include="..\..\..\source\terrax\PropertyWindow.cpp" />
     <ClCompile Include="..\..\..\source\terrax\ProxyObject.cpp" />
+    <ClCompile Include="..\..\..\source\terrax\ResourceBrowser.cpp" />
     <ClCompile Include="..\..\..\source\terrax\SceneTreeWindow.cpp" />
     <ClCompile Include="..\..\..\source\terrax\ScrollBar.cpp" />
     <ClCompile Include="..\..\..\source\terrax\terrax.cpp" />
@@ -303,6 +304,7 @@
     <ClInclude Include="..\..\..\source\terrax\MaterialEditor.h" />
     <ClInclude Include="..\..\..\source\terrax\PropertyWindow.h" />
     <ClInclude Include="..\..\..\source\terrax\ProxyObject.h" />
+    <ClInclude Include="..\..\..\source\terrax\ResourceBrowser.h" />
     <ClInclude Include="..\..\..\source\terrax\SceneTreeWindow.h" />
     <ClInclude Include="..\..\..\source\terrax\ScrollBar.h" />
     <ClInclude Include="..\..\..\source\terrax\TextureViewGraphNode.h" />
diff --git a/proj/terrax/vs2013/terrax.vcxproj.filters b/proj/terrax/vs2013/terrax.vcxproj.filters
index 919fa263e..71fef577f 100644
--- a/proj/terrax/vs2013/terrax.vcxproj.filters
+++ b/proj/terrax/vs2013/terrax.vcxproj.filters
@@ -213,6 +213,9 @@
     <ClCompile Include="..\..\..\source\terrax\CommandUngroup.cpp">
       <Filter>Source Files\cmd</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\source\terrax\ResourceBrowser.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="..\..\..\source\terrax\terrax.rc">
@@ -415,6 +418,9 @@
     <ClInclude Include="..\..\..\source\terrax\CommandUngroup.h">
       <Filter>Header Files\cmd</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\source\terrax\ResourceBrowser.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Image Include="..\..\..\source\terrax\resource\new.bmp">
diff --git a/source/anim/AnimatedModelProvider.cpp b/source/anim/AnimatedModelProvider.cpp
index 7265f05af..9147e9e89 100644
--- a/source/anim/AnimatedModelProvider.cpp
+++ b/source/anim/AnimatedModelProvider.cpp
@@ -202,6 +202,11 @@ void CAnimatedModelProvider::bindVertexFormat()
 	m_pMaterialSystem->bindVS(m_pVertexShaderHandler);
 }
 
+bool CAnimatedModelProvider::hasPendingOps()
+{
+	return(!m_queueGPUinitModel.empty() || !m_queueGPUinitShared.empty());
+}
+
 void CAnimatedModelProvider::render(CRenderableVisibility *pVisibility)
 {
 	XPROFILE_FUNCTION();
diff --git a/source/anim/AnimatedModelProvider.h b/source/anim/AnimatedModelProvider.h
index a9242e635..4789f1b64 100644
--- a/source/anim/AnimatedModelProvider.h
+++ b/source/anim/AnimatedModelProvider.h
@@ -37,6 +37,8 @@ public:
 
 	void bindVertexFormat();
 
+	bool hasPendingOps();
+
 protected:
 	AssotiativeArray<IXResourceModelAnimated*, Array<CAnimatedModelShared*>> m_mModels;
 
diff --git a/source/anim/Decal.cpp b/source/anim/Decal.cpp
index 57b7c5506..18c808f59 100644
--- a/source/anim/Decal.cpp
+++ b/source/anim/Decal.cpp
@@ -86,9 +86,48 @@ SMAABB XMETHODCALLTYPE CDecal::getLocalBound() const
 	return(SMAABB(getLocalBoundMin(), getLocalBoundMax()));
 }
 
-bool XMETHODCALLTYPE CDecal::rayTest(const float3 &vStart, const float3 &vEnd, float3 *pvOut, float3 *pvNormal, bool isRayInWorldSpace, bool bReturnNearestPoint)
+bool XMETHODCALLTYPE CDecal::rayTest(const float3 &vStart, const float3 &vEnd, float3 *pvOut, float3 *pvNormal)
 {
-	TODO("Implement me!");
+	fora(i, m_aOverlays)
+	{
+		const Overlay &overlay = m_aOverlays[i];
+		const Array<XResourceModelStaticVertex> &aVertices = overlay.pOverlay->getVertices();
+
+		float3 vRayStart = vStart;
+		float3 vRayEnd = vEnd;
+
+		if(!overlay.pModel->isStatic())
+		{
+			// transform ray to local space
+			float3 vPos = overlay.pModel->getPosition();
+			SMQuaternion qRot = overlay.pModel->getOrientation();
+
+			vRayStart = qRot.Conjugate() * vRayStart - vPos;
+			vRayEnd = qRot.Conjugate() * vRayEnd - vPos;
+		}
+
+		for(UINT j = 0, jl = aVertices.size(); j < jl; j += 4)
+		{
+			// 012 213
+			if(SMTriangleIntersectLine(aVertices[j].vPos, aVertices[j + 1].vPos, aVertices[j + 2].vPos, vRayStart, vRayEnd, pvOut))
+			{
+				if(pvNormal)
+				{
+					*pvNormal = SMVector3Normalize(SMVector3Cross(aVertices[j + 1].vPos - aVertices[j].vPos, aVertices[j + 2].vPos - aVertices[j].vPos));
+				}
+				return(true);
+			}
+
+			if(!SMIsZero(SMVector3Length2(aVertices[j + 3].vPos - aVertices[j + 2].vPos)) && SMTriangleIntersectLine(aVertices[j + 2].vPos, aVertices[j + 1].vPos, aVertices[j + 3].vPos, vRayStart, vRayEnd, pvOut))
+			{
+				if(pvNormal)
+				{
+					*pvNormal = SMVector3Normalize(SMVector3Cross(aVertices[j + 1].vPos - aVertices[j + 2].vPos, aVertices[j + 3].vPos - aVertices[j + 2].vPos));
+				}
+				return(true);
+			}
+		}
+	}
 	return(false);
 }
 
@@ -130,13 +169,23 @@ float2_t XMETHODCALLTYPE CDecal::getTextureRangeV()
 	return(m_vTexRangeV);
 }
 
+void XMETHODCALLTYPE CDecal::setMaterial(const char *szMaterial)
+{
+	mem_release(m_pMaterial);
+	m_pProvider->getMaterialSystem()->loadMaterial(szMaterial, &m_pMaterial);
+
+	setDirty();
+}
+
 void CDecal::setMaterial(IXMaterial *pMaterial)
 {
 	mem_release(m_pMaterial);
 	m_pMaterial = pMaterial;
 	add_ref(m_pMaterial);
+
+	setDirty();
 }
-void CDecal::setCorner(UINT uCorner, const float2_t &vCorner)
+void XMETHODCALLTYPE CDecal::setCorner(UINT uCorner, const float2_t &vCorner)
 {
 	assert(uCorner < DECAL_POINTS);
 	if(uCorner < DECAL_POINTS)
@@ -374,6 +423,8 @@ void CDecal::spawnOverlayForModel(CDynamicModel *pModel, IXFrustum *pFrustum
 
 	Array<XResourceModelStaticVertex> aOverlayVertices;
 
+	float fCosThreshold = m_isLeakAllowed ? -0.1f : 0.2f;
+
 	UINT uSubsets = pResource->getSubsetCount(0);
 	for(UINT uSubset = 0; uSubset < uSubsets; ++uSubset)
 	{
@@ -385,7 +436,10 @@ void CDecal::spawnOverlayForModel(CDynamicModel *pModel, IXFrustum *pFrustum
 			float3_t &b = pSubset->pVertices[pSubset->pIndices[i + 1]].vPos;
 			float3_t &c = pSubset->pVertices[pSubset->pIndices[i + 2]].vPos;
 
-			if(pFrustum->polyInFrustum(a, b, c))
+			float3 vTriN = SMVector3Normalize(SMVector3Cross(b - a, c - a));
+			float fCos = SMVector3Dot(vN, vTriN);
+
+			if(fCos > fCosThreshold && pFrustum->polyInFrustum(a, b, c))
 			{
 				aTempVertices[0] = a;
 				aTempVertices[1] = b;
@@ -465,40 +519,39 @@ void CDecal::spawnOverlayForModel(CDynamicModel *pModel, IXFrustum *pFrustum
 				// put into overlay
 				if(uVertexCount >= 3)
 				{
-					//if(pModel->isStatic())
-					//{
-					//	// transform to world pos
-					//	float3 vPos = pModel->getPosition();
-					//	SMQuaternion qRot = pModel->getOrientation();
-					//	for(UINT j = 0; j < uVertexCount; ++j)
-					//	{
-					//		aTempVertices[j] = qRot * aTempVertices[j] + vPos;
-					//	}
-					//}
+					if(pModel->isStatic())
+					{
+						// transform to world pos
+						float3 vPos = pModel->getPosition();
+						SMQuaternion qRot = pModel->getOrientation();
+						for(UINT j = 0; j < uVertexCount; ++j)
+						{
+							aTempVertices[j] = qRot * aTempVertices[j] + vPos;
+						}
+					}
 
 					UINT uStartVtx = aOverlayVertices.size();
-					for(UINT b = 0, e = uVertexCount - 1; b + 1 <= e - 1; ++b, --e)
+					for(UINT begin = 0, end = uVertexCount - 1; begin + 1 <= end - 1; ++begin, --end)
 					{
-						vtx.vPos = aTempVertices[e];
+						vtx.vPos = aTempVertices[end];
 						aOverlayVertices.push_back(vtx);
 
-						vtx.vPos = aTempVertices[b];
+						vtx.vPos = aTempVertices[begin];
 						aOverlayVertices.push_back(vtx);
 
-						vtx.vPos = aTempVertices[e - 1];
+						vtx.vPos = aTempVertices[end - 1];
 						aOverlayVertices.push_back(vtx);
 
-						vtx.vPos = aTempVertices[b + 1];
+						vtx.vPos = aTempVertices[begin + 1];
 						aOverlayVertices.push_back(vtx);
 					}
 
-					float3 vTriN = SMVector3Normalize(SMVector3Cross(b - a, c - a));
 					float3 vTriS = vS;
 					float3 vTriT = vT;
-					float fCos = SMVector3Dot(vN, vTriN);
+
 					if(fCos < 0.2f)
 					{
-						float3 vRotAxis = SMVector3Cross(vN, vTriN);
+						float3 vRotAxis = SMVector3Cross(vTriN, vN);
 
 						float fTempS = SMVector3Dot(vRotAxis, vS);
 						float fTempT = SMVector3Dot(vRotAxis, vT);
@@ -593,3 +646,12 @@ void CDecal::setDirty()
 		m_pProvider->updateDecal(this);
 	}
 }
+
+void XMETHODCALLTYPE CDecal::setLeakAllowed(bool yesNo)
+{
+	if(!!yesNo != !!m_isLeakAllowed)
+	{
+		m_isLeakAllowed = yesNo;
+		setDirty();
+	}
+}
diff --git a/source/anim/Decal.h b/source/anim/Decal.h
index cccb6c73e..da5016ff7 100644
--- a/source/anim/Decal.h
+++ b/source/anim/Decal.h
@@ -32,7 +32,7 @@ public:
 	float3 XMETHODCALLTYPE getLocalBoundMax() const override;
 	SMAABB XMETHODCALLTYPE getLocalBound() const override;
 
-	bool XMETHODCALLTYPE rayTest(const float3 &vStart, const float3 &vEnd, float3 *pvOut = NULL, float3 *pvNormal = NULL, bool isRayInWorldSpace = true, bool bReturnNearestPoint = false) override;
+	bool XMETHODCALLTYPE rayTest(const float3 &vStart, const float3 &vEnd, float3 *pvOut = NULL, float3 *pvNormal = NULL) override;
 
 	void XMETHODCALLTYPE setLayer(UINT uLayer) override;
 	UINT XMETHODCALLTYPE getLayer() override;
@@ -46,8 +46,12 @@ public:
 	void XMETHODCALLTYPE setTextureRangeV(const float2_t &vRange) override;
 	float2_t XMETHODCALLTYPE getTextureRangeV() override;
 
+	void XMETHODCALLTYPE setMaterial(const char *szMaterial) override;
+
 	void setMaterial(IXMaterial *pMaterial);
-	void setCorner(UINT uCorner, const float2_t &vCorner);
+	void XMETHODCALLTYPE setCorner(UINT uCorner, const float2_t &vCorner) override;
+
+	void XMETHODCALLTYPE setLeakAllowed(bool yesNo) override;
 
 	void update(
 #ifdef DECAL_DEBUG_DRAW
@@ -88,6 +92,8 @@ private:
 
 	bool m_isDirty = false;
 
+	bool m_isLeakAllowed = true;
+
 private:
 	void XMETHODCALLTYPE FinalRelease() override;
 	void spawnOverlayForModel(CDynamicModel *pModel, IXFrustum *pFrustum
diff --git a/source/anim/DecalProvider.cpp b/source/anim/DecalProvider.cpp
index e9f8fd2ab..1aaec25f9 100644
--- a/source/anim/DecalProvider.cpp
+++ b/source/anim/DecalProvider.cpp
@@ -27,11 +27,14 @@ CDecalProvider::CDecalProvider(IXCore *pCore, CDynamicModelProvider *pProviderDy
 	m_pRenderUtils->newGizmoRenderer(&m_pDebugRenderer);
 #endif
 
+	m_pMaterialSystem->loadMaterial("dev_null", &m_pNullMaterial);
+
 	loadDecals();
 }
 
 CDecalProvider::~CDecalProvider()
 {
+	mem_release(m_pNullMaterial);
 	fora(i, m_aTempDecals)
 	{
 		mem_release(m_aTempDecals[i]);
@@ -109,6 +112,16 @@ void CDecalProvider::render(CRenderableVisibility *pVisibility)
 #endif
 }
 
+bool XMETHODCALLTYPE CDecalProvider::newDecal(IXDecal **ppDecal)
+{
+	CDecal *pDecal = allocDecal();
+	pDecal->setMaterial(m_pNullMaterial);
+
+	*ppDecal = pDecal;
+
+	return(true);
+}
+
 void XMETHODCALLTYPE CDecalProvider::shootDecal(XDECAL_TYPE type, const float3 &vWorldPos, const float3 &vNormal, float fScale, const float3 *pvSAxis)
 {
 	//type = XDT_GLASS;
@@ -403,6 +416,11 @@ void CDecalProvider::updateDecal(CDecal *pDecal)
 
 void CDecalProvider::update()
 {
+	if(!m_isEnabled)
+	{
+		return;
+	}
+
 	CDecal *pDecal;
 	while(m_qDecalsForUpdate.pop(&pDecal))
 	{
@@ -432,6 +450,16 @@ void CDecalProvider::freeOverlay(CModelOverlay *pOverlay)
 	m_memOverlays.Delete(pOverlay);
 }
 
+IXMaterialSystem* CDecalProvider::getMaterialSystem()
+{
+	return(m_pMaterialSystem);
+}
+
+void CDecalProvider::setEnabled(bool yesNo)
+{
+	m_isEnabled = yesNo;
+}
+
 void CDecalProvider::loadDecals()
 {
 	IXConfig *pConfig = m_pCore->newConfig();
diff --git a/source/anim/DecalProvider.h b/source/anim/DecalProvider.h
index cc1565b62..58580748f 100644
--- a/source/anim/DecalProvider.h
+++ b/source/anim/DecalProvider.h
@@ -21,6 +21,8 @@ public:
 
 	void render(CRenderableVisibility *pVisibility);
 
+	bool XMETHODCALLTYPE newDecal(IXDecal **ppDecal) override;
+
 	void XMETHODCALLTYPE shootDecal(XDECAL_TYPE type, const float3 &vWorldPos, const float3 &vNormal, float fScale = 1.0f, const float3 *pvSAxis = NULL) override;
 
 	void computeVisibility(const float3 &vHintDir, CRenderableVisibility *pVisibility);
@@ -38,6 +40,10 @@ public:
 	CModelOverlay* allocOverlay(CDecal *pDecal, IXMaterial *pMaterial, Array<XResourceModelStaticVertex> &aVertices, const float3_t &vNormal);
 	void freeOverlay(CModelOverlay *pOverlay);
 
+	IXMaterialSystem* getMaterialSystem();
+
+	void setEnabled(bool yesNo);
+
 private:
 	struct DecalTexRange
 	{
@@ -68,6 +74,8 @@ private:
 	IXRenderUtils *m_pRenderUtils = NULL;
 	IXSceneQuery *m_pQuery = NULL;
 
+	IXMaterial *m_pNullMaterial = NULL;
+
 	IGXConstantBuffer *m_pWorldBuffer = NULL;
 
 	IGXBlendState *m_pBlendState = NULL;
@@ -89,6 +97,8 @@ private:
 
 	Queue<CDecal*> m_qDecalsForUpdate;
 
+	bool m_isEnabled = true;
+
 private:
 	void loadDecals();
 
diff --git a/source/anim/DynamicModel.cpp b/source/anim/DynamicModel.cpp
index 4aaf08f7a..85ad2e562 100644
--- a/source/anim/DynamicModel.cpp
+++ b/source/anim/DynamicModel.cpp
@@ -82,7 +82,7 @@ IXDynamicModel * XMETHODCALLTYPE CDynamicModel::asDynamicModel()
 }
 IXStaticModel * XMETHODCALLTYPE CDynamicModel::asStaticModel()
 {
-	return(NULL);
+	return(isStatic() ? this : NULL);
 }
 
 float3 XMETHODCALLTYPE CDynamicModel::getPosition() const
@@ -479,8 +479,12 @@ void CDynamicModel::setOverlay(CModelOverlay *pOverlay)
 	m_pOverlay = pOverlay;
 }
 
+void CDynamicModel::setStatic(bool yesNo)
+{
+	m_isStatic = yesNo;
+}
+
 bool CDynamicModel::isStatic()
 {
-	TODO("Implement me");
-	return(false);
+	return(m_isStatic);
 }
diff --git a/source/anim/DynamicModel.h b/source/anim/DynamicModel.h
index 1cb519e96..97612f254 100644
--- a/source/anim/DynamicModel.h
+++ b/source/anim/DynamicModel.h
@@ -63,6 +63,7 @@ public:
 	CModelOverlay* getOverlay();
 	void setOverlay(CModelOverlay *pOverlay);
 
+	void setStatic(bool yesNo);
 	bool isStatic();
 
 private:
@@ -82,6 +83,7 @@ private:
 	UINT m_uSkin = 0;
 	float4_t m_vColor{1.0f, 1.0f, 1.0f, 1.0f};
 	bool m_isEnabled = true;
+	bool m_isStatic = false;
 	float m_fScale = 1.0f;
 
 	mutable bool m_isLocalAABBvalid = false;
diff --git a/source/anim/DynamicModelProvider.cpp b/source/anim/DynamicModelProvider.cpp
index 6faeecb85..36af3b00e 100644
--- a/source/anim/DynamicModelProvider.cpp
+++ b/source/anim/DynamicModelProvider.cpp
@@ -808,3 +808,8 @@ void CDynamicModelProvider::enqueueModelDelete(CDynamicModel* pModel)
 {
 	m_qModelDelete.push(pModel);
 }
+
+bool CDynamicModelProvider::hasPendingOps()
+{
+	return(!m_queueGPUinitModel.empty() || !m_queueGPUinitShared.empty());
+}
diff --git a/source/anim/DynamicModelProvider.h b/source/anim/DynamicModelProvider.h
index 3b126cae9..ce66cf3ea 100644
--- a/source/anim/DynamicModelProvider.h
+++ b/source/anim/DynamicModelProvider.h
@@ -70,6 +70,9 @@ public:
 	IXSceneFeature* getFeature(XMODEL_FEATURE bmFeature);
 
 	void enqueueModelDelete(CDynamicModel* pModel);
+
+	bool hasPendingOps();
+
 protected:
 	void onMaterialEmissivityChanged(const IXMaterial *pMaterial);
 	void onMaterialTransparencyChanged(const IXMaterial *pMaterial);
diff --git a/source/anim/ModelOverlay.cpp b/source/anim/ModelOverlay.cpp
index 4514a00bb..ead204899 100644
--- a/source/anim/ModelOverlay.cpp
+++ b/source/anim/ModelOverlay.cpp
@@ -7,8 +7,15 @@ CModelOverlay::CModelOverlay(CDecal *pDecal, IXMaterial *pMaterial, Array<XResou
 	m_vNormal(vNormal)
 {
 	m_aVertices.swap(aVertices);
+	add_ref(m_pMaterial);
 }
 
+CModelOverlay::~CModelOverlay()
+{
+	mem_release(m_pMaterial);
+}
+
+
 const Array<XResourceModelStaticVertex>& CModelOverlay::getVertices()
 {
 	return(m_aVertices);
diff --git a/source/anim/ModelOverlay.h b/source/anim/ModelOverlay.h
index f16fb7c13..4404a20c1 100644
--- a/source/anim/ModelOverlay.h
+++ b/source/anim/ModelOverlay.h
@@ -12,6 +12,7 @@ class CModelOverlay final
 {
 public:
 	CModelOverlay(CDecal *pDecal, IXMaterial *pMaterial, Array<XResourceModelStaticVertex> &aVertices, const float3_t &vNormal);
+	~CModelOverlay();
 
 	const Array<XResourceModelStaticVertex>& getVertices();
 
diff --git a/source/anim/StaticModelProvider.cpp b/source/anim/StaticModelProvider.cpp
new file mode 100644
index 000000000..99cbb517a
--- /dev/null
+++ b/source/anim/StaticModelProvider.cpp
@@ -0,0 +1,20 @@
+#include "StaticModelProvider.h"
+
+CStaticModelProvider::CStaticModelProvider(CDynamicModelProvider *pDynamicModelProvider):
+	m_pDynamicModelProvider(pDynamicModelProvider)
+{
+}
+
+bool XMETHODCALLTYPE CStaticModelProvider::createModel(IXResourceModelStatic *pResource, IXStaticModel **ppModel)
+{
+	IXDynamicModel *pModel;
+	if(m_pDynamicModelProvider->createModel(pResource, &pModel))
+	{
+		((CDynamicModel*)pModel)->setStatic(true);
+
+		*ppModel = pModel;
+		return(true);
+	}
+
+	return(false);
+}
diff --git a/source/anim/StaticModelProvider.h b/source/anim/StaticModelProvider.h
new file mode 100644
index 000000000..37fd0b319
--- /dev/null
+++ b/source/anim/StaticModelProvider.h
@@ -0,0 +1,18 @@
+#ifndef __STATICMODELPROVIDER_H
+#define __STATICMODELPROVIDER_H
+
+#include <xcommon/resource/IXModelProvider.h>
+#include "DynamicModelProvider.h"
+
+class CStaticModelProvider final: public IXUnknownImplementation<IXStaticModelProvider>
+{
+public:
+	CStaticModelProvider(CDynamicModelProvider *pDynamicModelProvider);
+
+	bool XMETHODCALLTYPE createModel(IXResourceModelStatic *pResource, IXStaticModel **ppModel) override;
+
+private:
+	CDynamicModelProvider *m_pDynamicModelProvider;
+};
+
+#endif
diff --git a/source/anim/plugin_main.cpp b/source/anim/plugin_main.cpp
index d5dfadd46..c0c068c21 100644
--- a/source/anim/plugin_main.cpp
+++ b/source/anim/plugin_main.cpp
@@ -4,6 +4,7 @@
 #include "Updatable.h"
 #include "AnimatedModelProvider.h"
 #include "DynamicModelProvider.h"
+#include "StaticModelProvider.h"
 #include "DecalProvider.h"
 
 class CLevelSizeEventListener final: public IEventListener<XEventLevelSize>
@@ -28,8 +29,11 @@ protected:
 class CLoadLevelEventListener final: public IEventListener<XEventLevel>
 {
 public:
-	CLoadLevelEventListener(CRenderable *pRenderable):
-		m_pRenderable(pRenderable)
+	CLoadLevelEventListener(CRenderable *pRenderable, CAnimatedModelProvider *pAnimatedModelProvider, CDynamicModelProvider *pDynamicModelProvider, CDecalProvider *pDecalProvider):
+		m_pRenderable(pRenderable),
+		m_pAnimatedModelProvider(pAnimatedModelProvider),
+		m_pDynamicModelProvider(pDynamicModelProvider),
+		m_pDecalProvider(pDecalProvider)
 	{}
 	void onEvent(const XEventLevel *pData)
 	{
@@ -37,9 +41,18 @@ public:
 		{
 		case XEventLevel::TYPE_LOAD_BEGIN:
 			m_pRenderable->setEnabled(false);
+			m_pDecalProvider->setEnabled(false);
 			break;
 		case XEventLevel::TYPE_LOAD_END:
 			m_pRenderable->setEnabled(true);
+			m_pDecalProvider->setEnabled(true);
+			break;
+
+		case XEventLevel::TYPE_LOAD_WAIT_ASYNC_TASKS:
+			while(m_pAnimatedModelProvider->hasPendingOps() && m_pDynamicModelProvider->hasPendingOps())
+			{
+				Sleep(100);
+			}
 			break;
 
 		default:
@@ -49,6 +62,9 @@ public:
 
 protected:
 	CRenderable *m_pRenderable;
+	CAnimatedModelProvider *m_pAnimatedModelProvider;
+	CDynamicModelProvider *m_pDynamicModelProvider;
+	CDecalProvider *m_pDecalProvider;
 };
 
 class CDSEPlugin: public IXUnknownImplementation<IXPlugin>
@@ -58,11 +74,12 @@ public:
 	{
 		m_pAnimatedModelProvider = new CAnimatedModelProvider(m_pCore);
 		m_pDynamicModelProvider = new CDynamicModelProvider(m_pCore);
+		m_pStaticModelProvider = new CStaticModelProvider(m_pDynamicModelProvider);
 		m_pDecalProvider = new CDecalProvider(m_pCore, m_pDynamicModelProvider);
 		m_pRenderable = new CRenderable(getID(), m_pAnimatedModelProvider, m_pDynamicModelProvider, m_pDecalProvider);
 		m_pUpdatable = new CUpdatable(m_pAnimatedModelProvider, m_pDynamicModelProvider, m_pDecalProvider);
 		m_pLevelSizeEventListener = new CLevelSizeEventListener(m_pAnimatedModelProvider, m_pDynamicModelProvider);
-		m_pLevelLoadEventListener = new CLoadLevelEventListener(m_pRenderable);
+		m_pLevelLoadEventListener = new CLoadLevelEventListener(m_pRenderable, m_pAnimatedModelProvider, m_pDynamicModelProvider, m_pDecalProvider);
 
 		m_pCore->getEventChannel<XEventLevelSize>(EVENT_LEVEL_GET_SIZE_GUID)->addListener(m_pLevelSizeEventListener);
 		m_pCore->getEventChannel<XEventLevel>(EVENT_LEVEL_GUID)->addListener(m_pLevelLoadEventListener);
@@ -79,17 +96,22 @@ public:
 		{
 			m_pCore->getEventChannel<XEventLevelSize>(EVENT_LEVEL_GET_SIZE_GUID)->removeListener(m_pLevelSizeEventListener);
 		}
+		if(m_pLevelLoadEventListener)
+		{
+			m_pCore->getEventChannel<XEventLevel>(EVENT_LEVEL_GUID)->removeListener(m_pLevelLoadEventListener);
+		}
 		mem_delete(m_pLevelSizeEventListener);
 		mem_delete(m_pRenderable);
 		mem_delete(m_pUpdatable);
 		mem_delete(m_pAnimatedModelProvider);
+		mem_delete(m_pStaticModelProvider);
 		mem_delete(m_pDynamicModelProvider);
 //		mem_delete(m_pDecalProvider);
 	}
 
 	UINT XMETHODCALLTYPE getInterfaceCount() override
 	{
-		return(5);
+		return(6);
 	}
 	const XGUID* XMETHODCALLTYPE getInterfaceGUID(UINT id) override
 	{
@@ -111,6 +133,9 @@ public:
 		case 4:
 			s_guid = IXDECALPROVIDER_GUID;
 			break;
+		case 5:
+			s_guid = IXSTATICMODELPROVIDER_GUID;
+			break;
 		default:
 			return(NULL);
 		}
@@ -164,6 +189,15 @@ public:
 			add_ref(m_pDecalProvider);
 			*ppOut = m_pDecalProvider;
 			break;
+
+		case 5:
+			if(!m_pStaticModelProvider)
+			{
+				init();
+			}
+			add_ref(m_pStaticModelProvider);
+			*ppOut = m_pStaticModelProvider;
+			break;
 		
 		default:
 			*ppOut = NULL;
@@ -176,6 +210,7 @@ protected:
 	IXCore *m_pCore = NULL;
 	CAnimatedModelProvider *m_pAnimatedModelProvider = NULL;
 	CDynamicModelProvider *m_pDynamicModelProvider = NULL;
+	CStaticModelProvider *m_pStaticModelProvider = NULL;
 	CDecalProvider *m_pDecalProvider = NULL;
 	CLevelSizeEventListener *m_pLevelSizeEventListener = NULL;
 	CLoadLevelEventListener *m_pLevelLoadEventListener = NULL;
diff --git a/source/common b/source/common
index ef2606734..bcaae2907 160000
--- a/source/common
+++ b/source/common
@@ -1 +1 @@
-Subproject commit ef2606734c2075678c992d5806d952d4c835d853
+Subproject commit bcaae290724afea7b115514dd8e7b9e75bb67726
diff --git a/source/core/Config.cpp b/source/core/Config.cpp
index 2f336a608..d8a5b37a5 100644
--- a/source/core/Config.cpp
+++ b/source/core/Config.cpp
@@ -479,275 +479,243 @@ void CConfig::set(const char * sectionp, const char * key, const char * val)
 
 int CConfig::save()
 {
-	static const bool *s_pbDebug = GET_PCVAR_BOOL("dbg_config_save");
-	if(*s_pbDebug)
-	{
-		printf(COLOR_GRAY "====== " COLOR_CYAN "CConfig::save() " COLOR_GRAY "======" COLOR_RESET "\n");
-	}
 	int terror = 0;
 	for(AssotiativeArray<CConfigString, CSection>::Iterator i = m_mSections.begin(); i; ++i)
 	{
-		if(*s_pbDebug)
-		{
-			printf("Testing section: " COLOR_LGREEN "%s" COLOR_RESET "...", i.first->c_str());
-		}
 		if(i.second->isModified)
 		{
-			if(*s_pbDebug)
-			{
-				printf(COLOR_YELLOW " modified" COLOR_RESET "\n");
-			}
 			for(AssotiativeArray<CConfigString, CValue>::Iterator j = i.second->mValues.begin(); j; ++j)
 			{
-				if(*s_pbDebug)
-				{
-					printf("  testing key: " COLOR_LGREEN "%s" COLOR_RESET "...", j.first->c_str());
-				}
 				if(j.second->isModified)
 				{
-					if(*s_pbDebug)
-					{
-						printf(COLOR_YELLOW " modified" COLOR_RESET "\n");
-					}
 					if(i.second->native) // Write to BaseFile
 					{
-						if(*s_pbDebug)
-						{
-							printf("    writing to base file " COLOR_CYAN "%s" COLOR_RESET "...\n", BaseFile.c_str());
-						}
 						terror = writeFile(BaseFile, *i.first, *j.first, j.second->val);
 						if(terror != 0)
 							goto end;
 					}
 					else // Write to i.second->Include
 					{
-						if(*s_pbDebug)
-						{
-							printf("    writing to include file " COLOR_CYAN "%s" COLOR_RESET "...\n", i.second->Include.c_str());
-						}
 						terror = writeFile(i.second->Include, *i.first, *j.first, j.second->val);
 						if(terror != 0)
 							goto end;
 					}
 				}
-				else
-				{
-					if(*s_pbDebug)
-					{
-						printf(COLOR_GRAY " not modified" COLOR_RESET "\n");
-					}
-				}
-			}
-		}
-		else
-		{
-			if(*s_pbDebug)
-			{
-				printf(COLOR_GRAY " not modified" COLOR_RESET "\n");
 			}
 		}
 	}
+
+	terror = commitFiles();
 end:
-	if(*s_pbDebug)
-	{
-		printf(COLOR_GRAY "=============================" COLOR_RESET "\n");
-	}
 	return(terror);
 }
 
 int CConfig::writeFile(const CConfigString & name, CConfigString section, CConfigString key, const CConfigString & val)
 {
-	static const bool *s_pbDebug = GET_PCVAR_BOOL("dbg_config_save");
-	//printf("W: %s\t[%s]: %s = %s\n", name.c_str(), section.c_str(), key.c_str(), val.c_str());
-	FILE * pF = fopen(name.c_str(), "rb");
-	if(pF)
+	const AssotiativeArray<String, String>::Node *pUncommittedNode;
+	
+	if(!m_mapUncommitted.KeyExists(name, &pUncommittedNode))
 	{
-		if(*s_pbDebug)
-		{
-			printf("    file opened\n");
-		}
+		pUncommittedNode = m_mapUncommitted.insert(name, "");
 
-		fseek(pF, 0, SEEK_END);
-		UINT fl = ftell(pF);
-		fseek(pF, 0, SEEK_SET);
-		char * szData = new char[fl + 1];
-		if(!szData)
+		// read file
+		IFile *pFile = m_pFS->openFile(name.c_str());
+		if(pFile)
 		{
-			printf(COLOR_LRED "Unable to allocate memory (%d) in CConfig::writeFile()" COLOR_RESET "\n", fl + 1);
-			fclose(pF);
-			return(-1);
+			size_t sizeFile = pFile->getSize();
+
+			pUncommittedNode->Val->resize(sizeFile);
+			char *szPtr = &((*(pUncommittedNode->Val))[0]);
+			pFile->readBin(szPtr, sizeFile);
+			szPtr[sizeFile] = 0;
+
+			mem_release(pFile);
 		}
-		fread(szData, 1, fl, pF);
-		szData[fl] = 0;
-		fclose(pF);
-		UINT sl = section.length();
-		UINT kl = key.length();
-		bool sf = false;
-		bool kf = false;
-		bool se = false;
-		UINT sp = 0;
-		for(UINT i = 0; i < fl; ++i)
+	}
+
+	String &sFileData = *(pUncommittedNode->Val);
+	
+
+	UINT fl = sFileData.length();
+	UINT sl = section.length();
+	UINT kl = key.length();
+	bool sf = false;
+	bool kf = false;
+	bool se = false;
+	UINT sp = 0;
+	const char *szData = sFileData.c_str();
+	for(UINT i = 0; i < fl; ++i)
+	{
+		if(szData[i] == '[' && ((i > 0 && (szData[i - 1] == '\r' || szData[i - 1] == '\n')) || i == 0))
 		{
-			if(szData[i] == '[' && ((i > 0 && (szData[i - 1] == '\r' || szData[i - 1] == '\n')) || i == 0))
+			bool cmp = true;
+			UINT j;
+			for(j = i + 1; j < fl - 1 && j - i - 1 < sl; ++j)
+			{
+				if(szData[j] != section[j - i - 1])
+				{
+					cmp = false;
+					break;
+				}
+			}
+			if(cmp && szData[j] == ']')//Section Found!
 			{
-				bool cmp = true;
-				UINT j;
-				for(j = i + 1; j < fl - 1 && j - i - 1 < sl; ++j)
+				sf = true;
+				i = j;
+				for(; i < fl; ++i)
 				{
-					if(szData[j] != section[j - i - 1])
+					if(szData[i] == '\r' || szData[i] == '\n')
 					{
-						cmp = false;
 						break;
 					}
 				}
-				if(cmp && szData[j] == ']')//Section Found!
+				while(i < fl && (szData[i] == '\r' || szData[i] == '\n'))
 				{
-					sf = true;
-					i = j;
-					for(; i < fl; ++i)
+					++i;
+				}
+				sp = i;
+				//We are inside the section
+				//So, let's find the key
+				while(i < fl)
+				{
+					if(szData[i] == '[') // New section begin. There is no our key, so, add it!
 					{
-						if(szData[i] == '\r' || szData[i] == '\n')
-						{
-							break;
-						}
+						kf = false;
+						se = true;
+						break;
 					}
-					while(i < fl && (szData[i] == '\r' || szData[i] == '\n'))
+					while(i < fl && (szData[i] == ' ' || szData[i] == '\t'))
 					{
 						++i;
 					}
-					sp = i;
-					//We are inside the section
-					//So, let's find the key
-					while(i < fl)
+					bool f = true;
+					for(j = i; j < fl && j - i < kl; ++j)
 					{
-						if(szData[i] == '[') // New section begin. There is no our key, so, add it!
+						if(szData[j] != key[j - i])
 						{
-							kf = false;
-							se = true;
+							f = false;
 							break;
 						}
-						while(i < fl && (szData[i] == ' ' || szData[i] == '\t'))
-						{
-							++i;
-						}
-						bool f = true;
-						for(j = i; j < fl && j - i < kl; ++j)
+					}
+					if(f && (isspace((unsigned char)szData[j]) || szData[j] == '='))//KeyFound!
+					{
+						i = j;
+						kf = true;
+						for(j = i; j < fl; ++j)
 						{
-							if(szData[j] != key[j - i])
+							if(szData[j] == '\n' || szData[j] == '\r' || szData[j] == ';')
 							{
-								f = false;
+								//f = false;
 								break;
 							}
 						}
-						if(f && (isspace((unsigned char)szData[j]) || szData[j] == '='))//KeyFound!
+						//while(szData[j] == '\r' || szData[j] == '\n')
+						//{
+						//	++j;
+						//}
+						//Let's write the file
+
+						if(i != j)
 						{
-							i = j;
-							kf = true;
-							for(j = i; j < fl; ++j)
-							{
-								if(szData[j] == '\n' || szData[j] == '\r' || szData[j] == ';')
-								{
-									//f = false;
-									break;
-								}
-							}
-							//while(szData[j] == '\r' || szData[j] == '\n')
-							//{
-							//	++j;
-							//}
-							//Let's write the file
-							FILE * pF = fopen(name.c_str(), "wb");
-							if(!pF)
-							{
-								ErrorFile = name;
-								mem_delete_a(szData);
-								return -1;
-							}
-							fwrite(szData, 1, i, pF); // First file part, including key
-							fwrite(" = ", 1, 3, pF);
-							fwrite(val.c_str(), 1, val.length(), pF);
-							//fwrite("\n", 1, 1, pF);
-							fwrite(&szData[j], 1, fl - j, pF);
-							fclose(pF);
+							sFileData.remove(i, j - i);
+						}
+
+						sFileData.insert(i, String(" = ") + val);
+
+						/*
+						FILE * pF = fopen(name.c_str(), "wb");
+						if(!pF)
+						{
+							ErrorFile = name;
 							mem_delete_a(szData);
-							return 0;
+							return -1;
 						}
-						else // Skip current row
+						fwrite(szData, 1, i, pF); // First file part, including key
+						fwrite(" = ", 1, 3, pF);
+						fwrite(val.c_str(), 1, val.length(), pF);
+						//fwrite("\n", 1, 1, pF);
+						fwrite(&szData[j], 1, fl - j, pF);
+						fclose(pF);
+						mem_delete_a(szData);*/
+						return 0;
+					}
+					else // Skip current row
+					{
+						for(; i < fl; ++i)
 						{
-							for(; i < fl; ++i)
-							{
-								if(szData[i] == '\n' || szData[i] == '\r')
-								{
-									//f = false;
-									break;
-								}
-							}
-							while(i < fl && (szData[i] == '\r' || szData[i] == '\n'))
+							if(szData[i] == '\n' || szData[i] == '\r')
 							{
-								++i;
+								//f = false;
+								break;
 							}
 						}
-					}
-					//
-					if(se)
-					{
-						break;
+						while(i < fl && (szData[i] == '\r' || szData[i] == '\n'))
+						{
+							++i;
+						}
 					}
 				}
+				//
+				if(se)
+				{
+					break;
+				}
 			}
 		}
-		if(sf && !kf)
-		{
-			if(*s_pbDebug)
-			{
-				printf("    adding key to section(sp=" COLOR_LCYAN "%d" COLOR_RESET ")\n", sp);
-			}
-			FILE * pF = fopen(name.c_str(), "wb");
-			if(!pF)
-			{
-				ErrorFile = name;
-				mem_delete_a(szData);
-				return -1;
-			}
-			fwrite(szData, 1, sp, pF); // First file part
-			fwrite(key.c_str(), 1, key.length(), pF);
-			fwrite(" = ", 1, 3, pF);
-			fwrite(val.c_str(), 1, val.length(), pF);
-			fwrite("\n", 1, 1, pF);
-			fwrite(&szData[sp], 1, fl - sp, pF);
-			fclose(pF);
-			mem_delete_a(szData);
-			return 0;
-		}
-		if(!sf)//!(Section found) == Add new
-		{
-			FILE * pF = fopen(name.c_str(), "ab");
-			if(!pF)
-			{
-				ErrorFile = name;
-				return -1;
-			}
-			fwrite((CConfigString("\n[") + section + "]\n" + key + " = " + val + "\n").c_str(), sizeof(char), section.length() + key.length() + val.length() + 8, pF);
-			fclose(pF);
-			mem_delete_a(szData);
-			return 0;
-		}
 	}
-	else
+	if(sf && !kf)
 	{
-		FILE * pF = fopen(name.c_str(), "wb");
-		if(!pF)
-		{
-			ErrorFile = name;
-			return -1;
-		}
-		fwrite((CConfigString("[") + section + "]\n" + key + " = " + val + "\n").c_str(), sizeof(char), section.length() + key.length() + val.length() + 7, pF);
-		fclose(pF);
+		sFileData.insert(sp, key + " = " + val + '\n');
+
+		return 0;
+	}
+	if(!sf)//!(Section found) == Add new
+	{
+		sFileData += '\n';
+		sFileData += '[';
+		sFileData += section;
+		sFileData += ']';
+		sFileData += '\n';
+		sFileData += key;
+		sFileData += " = ";
+		sFileData += val;
+		sFileData += '\n';
+
 		return 0;
 	}
+	
 	return 0;
 }
 
+int CConfig::commitFiles()
+{
+	for(AssotiativeArray<String, String>::Iterator i = m_mapUncommitted.begin(); i; ++i)
+	{
+		//String sTempName = (*i.first) + ".new";
+		const String &sName = (*i.first);
+		IFile *pFile = m_pFS->openFile(sName.c_str(), FILE_MODE_WRITE);
+		if(!pFile)
+		{
+			ErrorFile = sName;
+			return(-1);
+		}
+
+		if(i.second->length() != pFile->writeBin(i.second->c_str(), i.second->length()))
+		{
+			ErrorFile = sName;
+			pFile->close();
+			return(-2);
+		}
+		pFile->close();
+
+		//m_pFS->rename
+	}
+
+	m_mapUncommitted.clear();
+	
+	return(0);
+}
+
 int CConfig::getSectionCount()
 {
 	return(m_mSections.Size());
@@ -804,7 +772,6 @@ void CConfig::clear()
 	for(int i = 0; i < size; ++i)
 	{
 		mem_release(m_vIncludes[i].pParser);
-		mem_delete(m_vIncludes[i].pParser);
 	}
 	m_vIncludes.clear();
 	m_mFinalValues.clear();
diff --git a/source/core/Config.h b/source/core/Config.h
index a921ce2ca..a2455e858 100644
--- a/source/core/Config.h
+++ b/source/core/Config.h
@@ -37,6 +37,8 @@ public:
 	}
 };
 
+//##########################################################################
+
 class CConfig: public ISXConfig
 {
 public:
@@ -117,8 +119,16 @@ protected:
 	CConfigString baseName(CConfigString dir);
 
 	void modify(AssotiativeArray<CConfigString, CSection> & sections, AssotiativeArray<CConfigString, CValue> & values, CConfigString IncName);
+
+private:
+	int commitFiles();
+
+private:
+	AssotiativeArray<String, String> m_mapUncommitted;
 };
 
+//##########################################################################
+
 class CXConfig: public IXUnknownImplementation<IXConfig>
 {
 public:
diff --git a/source/core/Core.cpp b/source/core/Core.cpp
index 701dbefd9..567a43d4b 100644
--- a/source/core/Core.cpp
+++ b/source/core/Core.cpp
@@ -35,7 +35,6 @@ CCore::CCore(const char *szName)
 
 	Core_0RegisterCVarBool("g_time_run", true, "Запущено ли игровое время?", FCVAR_NOTIFY_OLD);
 	Core_0RegisterCVarFloat("g_time_speed", 1.f, "Скорость/соотношение течения игрового времени", FCVAR_NOTIFY_OLD);
-	Core_0RegisterCVarBool("dbg_config_save", false, "Отладочный вывод процесса сохранения конфига");
 	Core_0RegisterCVarInt("r_stats", 0, "Показывать ли статистику? 0 - нет, 1 - fps и игровое время, 2 - показать полностью");
 
 	Core_0RegisterConcmd("on_g_time_run_change", []()
diff --git a/source/core/JSON.cpp b/source/core/JSON.cpp
index 01cf57087..c25acd44e 100644
--- a/source/core/JSON.cpp
+++ b/source/core/JSON.cpp
@@ -1,5 +1,9 @@
 #include "JSON.h"
 
+MemAlloc<CJSONValue> CJSON::ms_memValues;
+MemAlloc<CJSONArray> CJSON::ms_memArrays;
+MemAlloc<CJSONObject> CJSON::ms_memObjects;
+SpinLock CJSON::ms_slMem;
 
 bool XMETHODCALLTYPE CJSON::parse(const char *szString, IXJSONItem **ppOut, void *pReserved) const
 {
@@ -25,7 +29,7 @@ bool CJSON::Parse(const char **str, IXJSONItem **ppOut)
 
 	if(**str == '{')
 	{
-		CJSONObject *o = new CJSONObject();
+		CJSONObject *o = AllocObject();
 		if(!o->load(str))
 		{
 			mem_release(o);
@@ -35,7 +39,7 @@ bool CJSON::Parse(const char **str, IXJSONItem **ppOut)
 	}
 	else if(**str == '[')
 	{
-		CJSONArray *o = new CJSONArray();
+		CJSONArray *o = AllocArray();
 		if(!o->load(str))
 		{
 			mem_release(o);
@@ -45,7 +49,7 @@ bool CJSON::Parse(const char **str, IXJSONItem **ppOut)
 	}
 	else
 	{
-		CJSONValue *o = new CJSONValue();
+		CJSONValue *o = AllocValue();
 		if(!o->load(str))
 		{
 			mem_release(o);
@@ -56,16 +60,40 @@ bool CJSON::Parse(const char **str, IXJSONItem **ppOut)
 	return(true);
 }
 
-//##########################################################################
+CJSONValue* CJSON::AllocValue()
+{
+	ScopedSpinLock lock(ms_slMem);
+	return(ms_memValues.Alloc());
+}
+CJSONArray* CJSON::AllocArray()
+{
+	ScopedSpinLock lock(ms_slMem);
+	return(ms_memArrays.Alloc());
+}
+CJSONObject* CJSON::AllocObject()
+{
+	ScopedSpinLock lock(ms_slMem);
+	return(ms_memObjects.Alloc());
+}
 
-CJSONArray::~CJSONArray()
+void CJSON::ReleaseItem(CJSONValue *pItem)
 {
-	for(UINT i = 0, l = m_aItems.size(); i < l; ++i)
-	{
-		mem_release(m_aItems[i]);
-	}
+	ScopedSpinLock lock(ms_slMem);
+	ms_memValues.Delete(pItem);
+}
+void CJSON::ReleaseItem(CJSONArray *pItem)
+{
+	ScopedSpinLock lock(ms_slMem);
+	ms_memArrays.Delete(pItem);
+}
+void CJSON::ReleaseItem(CJSONObject *pItem)
+{
+	ScopedSpinLock lock(ms_slMem);
+	ms_memObjects.Delete(pItem);
 }
 
+//##########################################################################
+
 UINT XMETHODCALLTYPE CJSONArray::size() const
 {
 	return(m_aItems.size());
@@ -122,16 +150,18 @@ bool CJSONArray::loadArr(const char **str)
 	return(true);
 }
 
-//##########################################################################
-
-CJSONObject::~CJSONObject()
+void XMETHODCALLTYPE CJSONArray::FinalRelease()
 {
-	for(UINT i = 0, l = m_aPairs.size(); i < l; ++i)
+	for(UINT i = 0, l = m_aItems.size(); i < l; ++i)
 	{
-		mem_release(m_aPairs[i].pVal);
+		mem_release(m_aItems[i]);
 	}
+
+	CJSON::ReleaseItem(this);
 }
 
+//##########################################################################
+
 UINT XMETHODCALLTYPE CJSONObject::size() const
 {
 	return(m_aPairs.size());
@@ -216,3 +246,21 @@ bool CJSONObject::loadObj(const char **str)
 	++*str;
 	return(true);
 }
+
+void XMETHODCALLTYPE CJSONObject::FinalRelease()
+{
+	for(UINT i = 0, l = m_aPairs.size(); i < l; ++i)
+	{
+		mem_release(m_aPairs[i].pVal);
+	}
+
+	CJSON::ReleaseItem(this);
+}
+
+//##########################################################################
+
+void XMETHODCALLTYPE CJSONValue::FinalRelease()
+{
+	CJSON::ReleaseItem(this);
+}
+
diff --git a/source/core/JSON.h b/source/core/JSON.h
index 0e04ec2ec..92b7d5f53 100644
--- a/source/core/JSON.h
+++ b/source/core/JSON.h
@@ -195,8 +195,10 @@ public:
 private:
 	bool loadString(const char **prm)
 	{
+		m_sVal = "";
+
 		m_type = XJI_STRING;
-		Array<char> tmp;
+		//Array<char> tmp;
 		++*prm;
 		while(**prm && **prm != '"')
 		{
@@ -208,22 +210,22 @@ private:
 				case L'"':
 				case L'\\':
 				case L'/':
-					tmp.push_back(**prm);
+					m_sVal += **prm;
 					break;
 				case L'b':
-					tmp.push_back('\b');
+					m_sVal += '\b';
 					break;
 				case L'f':
-					tmp.push_back('\f');
+					m_sVal += '\f';
 					break;
 				case L'n':
-					tmp.push_back('\n');
+					m_sVal += '\n';
 					break;
 				case L'r':
-					tmp.push_back('\r');
+					m_sVal += '\r';
 					break;
 				case L't':
-					tmp.push_back('\t');
+					m_sVal += '\t';
 					break;
 				case L'u':
 				{
@@ -249,7 +251,7 @@ private:
 							return(false);
 						}
 					}
-					writeChar(code, &tmp);
+					writeChar(code);
 				}
 				break;
 				default:
@@ -258,7 +260,7 @@ private:
 			}
 			else
 			{
-				tmp.push_back(**prm);
+				m_sVal += **prm;
 			}
 			++*prm;
 		}
@@ -267,8 +269,6 @@ private:
 			return(false);
 		}
 		++*prm;
-		tmp.push_back(0);
-		m_sVal = tmp;
 		return(true);
 	}
 	bool loadNum(const char **prm)
@@ -399,7 +399,7 @@ private:
 		return(false);
 	}
 
-	void writeChar(UINT c, Array<char> *pOut)
+	void writeChar(UINT c)
 	{
 		UINT codepoint = 0;
 		short *in = (short*)&c;
@@ -422,28 +422,28 @@ private:
 
 				if(codepoint <= 0x7f)
 				{
-					pOut->push_back(codepoint);
+					m_sVal += (char)codepoint;
 					break;
 				}
 				else if(codepoint <= 0x7ff)
 				{
-					pOut->push_back(0xc0 | ((codepoint >> 6) & 0x1f));
-					pOut->push_back(0x80 | (codepoint & 0x3f));
+					m_sVal += (char)(0xc0 | ((codepoint >> 6) & 0x1f));
+					m_sVal += (char)(0x80 | (codepoint & 0x3f));
 					break;
 				}
 				else if(codepoint <= 0xffff)
 				{
-					pOut->push_back(0xe0 | ((codepoint >> 12) & 0x0f));
-					pOut->push_back(0x80 | ((codepoint >> 6) & 0x3f));
-					pOut->push_back(0x80 | (codepoint & 0x3f));
+					m_sVal += (char)(0xe0 | ((codepoint >> 12) & 0x0f));
+					m_sVal += (char)(0x80 | ((codepoint >> 6) & 0x3f));
+					m_sVal += (char)(0x80 | (codepoint & 0x3f));
 					break;
 				}
 				else
 				{
-					pOut->push_back(0xf0 | ((codepoint >> 18) & 0x07));
-					pOut->push_back(0x80 | ((codepoint >> 12) & 0x3f));
-					pOut->push_back(0x80 | ((codepoint >> 6) & 0x3f));
-					pOut->push_back(0x80 | (codepoint & 0x3f));
+					m_sVal += (char)(0xf0 | ((codepoint >> 18) & 0x07));
+					m_sVal += (char)(0x80 | ((codepoint >> 12) & 0x3f));
+					m_sVal += (char)(0x80 | ((codepoint >> 6) & 0x3f));
+					m_sVal += (char)(0x80 | (codepoint & 0x3f));
 					break;
 				}
 			}
@@ -458,15 +458,19 @@ protected:
 	mutable String m_sVal;
 };
 
+//##########################################################################
+
 class CJSONValue: public CJSONItem<IXJSONItem>
 {
+private:
+	void XMETHODCALLTYPE FinalRelease() override;
 };
 
+//##########################################################################
+
 class CJSONArray: public CJSONItem<IXJSONArray>
 {
 public:
-	~CJSONArray();
-
 	UINT XMETHODCALLTYPE size() const override;
 	IXJSONItem* XMETHODCALLTYPE at(UINT idx) const override;
 
@@ -481,16 +485,18 @@ public:
 
 private:
 	bool loadArr(const char **str) override;
+	
+	void XMETHODCALLTYPE FinalRelease() override;
 
 private:
 	Array<IXJSONItem*> m_aItems;
 };
 
+//##########################################################################
+
 class CJSONObject: public CJSONItem<IXJSONObject>
 {
 public:
-	~CJSONObject();
-
 	UINT XMETHODCALLTYPE size() const override;
 	IXJSONItem* XMETHODCALLTYPE at(UINT idx) const override;
 	
@@ -509,7 +515,10 @@ public:
 
 private:
 	bool loadObj(const char **str) override;
-	
+
+	void XMETHODCALLTYPE FinalRelease() override;
+
+private:
 	struct KeyValue
 	{
 		String sKey;
@@ -519,12 +528,30 @@ private:
 	Array<KeyValue> m_aPairs;
 };
 
+//##########################################################################
+
 class CJSON: public IXUnknownImplementation<IXJSON>
 {
 public:
 	bool XMETHODCALLTYPE parse(const char *szString, IXJSONItem **ppOut, void *pReserved = NULL) const override;
 
 	static bool Parse(const char **str, IXJSONItem **ppOut);
+
+	static void ReleaseItem(CJSONValue *pItem);
+	static void ReleaseItem(CJSONArray *pItem);
+	static void ReleaseItem(CJSONObject *pItem);
+
+private:
+	static MemAlloc<CJSONValue> ms_memValues;
+	static MemAlloc<CJSONArray> ms_memArrays;
+	static MemAlloc<CJSONObject> ms_memObjects;
+	
+	static SpinLock ms_slMem;
+
+private:
+	static CJSONValue* AllocValue();
+	static CJSONArray* AllocArray();
+	static CJSONObject* AllocObject();
 };
 
 #endif
diff --git a/source/game/BaseEntity.h b/source/game/BaseEntity.h
index ffc345177..a6bee1963 100644
--- a/source/game/BaseEntity.h
+++ b/source/game/BaseEntity.h
@@ -172,6 +172,10 @@ public:
 		return(false);
 	}
 
+	virtual void setSize(const float3_t &vSize)
+	{
+	}
+
 private:
 	void setClassName(const char *name);
 	void setDefaults();
diff --git a/source/game/BaseMover.cpp b/source/game/BaseMover.cpp
index d1eed1100..0008c78b6 100644
--- a/source/game/BaseMover.cpp
+++ b/source/game/BaseMover.cpp
@@ -31,7 +31,7 @@ BEGIN_PROPTABLE(CBaseMover)
 	DEFINE_FLAG(MOVER_NO_AUTOMOUNT, "Disable automount")
 END_PROPTABLE()
 
-REGISTER_ENTITY(CBaseMover, base_mover);
+REGISTER_ENTITY_NOLISTING(CBaseMover, base_mover);
 
 IEventChannel<XEventPhysicsStep> *CBaseMover::m_pTickEventChannel = NULL;
 
diff --git a/source/game/Editable.cpp b/source/game/Editable.cpp
index d9484c671..dc3239c24 100644
--- a/source/game/Editable.cpp
+++ b/source/game/Editable.cpp
@@ -110,14 +110,15 @@ void CEditable::onSelectionChanged(CEditorObject *pObject)
 
 bool XMETHODCALLTYPE CEditable::canUseModel(const char *szClass)
 {
-	IEntityFactory *pFactory = CEntityFactoryMap::GetInstance()->getFactory(szClass);
+	return(getClassKV(szClass, "model_field") != NULL);
+}
+
+const char* XMETHODCALLTYPE CEditable::getClassKV(const char *szClassName, const char *szKey)
+{
+	IEntityFactory *pFactory = CEntityFactoryMap::GetInstance()->getFactory(szClassName);
 	if(pFactory)
 	{
-		const char *szModelField = pFactory->getKV("model_field");
-		if(szModelField)
-		{
-			return(true);
-		}
+		return(pFactory->getKV(szKey));
 	}
-	return(false);
+	return(NULL);
 }
diff --git a/source/game/Editable.h b/source/game/Editable.h
index 3db86f3e5..b2f66e355 100644
--- a/source/game/Editable.h
+++ b/source/game/Editable.h
@@ -80,6 +80,8 @@ public:
 		return(m_pDevice);
 	}
 
+	const char* XMETHODCALLTYPE getClassKV(const char *szClassName, const char *szKey) override;
+
 protected:
 	IGXDevice *m_pDevice = NULL;
 	IXCore *m_pCore = NULL;
diff --git a/source/game/EditorObject.cpp b/source/game/EditorObject.cpp
index 944656b71..83da6cb47 100644
--- a/source/game/EditorObject.cpp
+++ b/source/game/EditorObject.cpp
@@ -71,6 +71,8 @@ void CEditorObject::_iniFieldList()
 				&& pField->editor.type != PDE_NONE
 				)
 			{
+				xField.pEditorData = NULL;
+
 				switch(pField->editor.type)
 				{
 				case PDE_COMBOBOX:
@@ -79,27 +81,30 @@ void CEditorObject::_iniFieldList()
 					break;
 				case PDE_FILEFIELD:
 					xField.editorType = XPET_FILE;
-					xField.pEditorData = NULL;
 					{
-						editor_kv *pKV = (editor_kv*)pField->editor.pData;
-						if(pKV && pKV[0].value)
+						kv_t *pKV = (kv_t*)pField->editor.pData;
+						if(pKV && pKV[0].szValue)
 						{
-							if(!fstrcmp(pKV[0].value, "dse"))
+							if(!fstrcmp(pKV[0].szValue, "dse"))
 							{
 								xField.pEditorData = "model";
 							}
-							else if(!fstrcmp(pKV[0].value, "ogg"))
+							else if(!fstrcmp(pKV[0].szValue, "ogg"))
 							{
 								xField.pEditorData = "sound";
 							}
-							else if(!fstrcmp(pKV[0].value, "dds"))
+							else if(!fstrcmp(pKV[0].szValue, "dds"))
 							{
 								xField.pEditorData = "texture";
 							}
-							else if(!fstrcmp(pKV[0].value, "eff"))
+							else if(!fstrcmp(pKV[0].szValue, "eff"))
 							{
 								xField.pEditorData = "effect";
 							}
+							else if(!fstrcmp(pKV[0].szValue, "mtl"))
+							{
+								xField.pEditorData = "material";
+							}
 						}
 						//xField.pEditorData
 					}
@@ -119,6 +124,7 @@ void CEditorObject::_iniFieldList()
 					break;
 				case PDE_POINTCOORD:
 					xField.editorType = XPET_POINTCOORD;
+					xField.pEditorData = pField->editor.pData;
 					break;
 				case PDE_RADIUS:
 					xField.editorType = XPET_RADIUS;
@@ -129,6 +135,9 @@ void CEditorObject::_iniFieldList()
 				case PDE_HDRCOLOR:
 					xField.editorType = XPET_HDRCOLOR;
 					break;
+				case PDE_SIZE:
+					xField.editorType = XPET_SIZE;
+					break;
 				}
 				xField.szHelp = "";
 				xField.szKey = pField->szKey;
@@ -218,8 +227,8 @@ void CEditorObject::setPos(const float3_t &pos, bool isSeparate)
 
 void XMETHODCALLTYPE CEditorObject::setSize(const float3_t &vSize)
 {
-	// TODO Implement me
 	//m_vScale = vScale;
+	m_pEntity->setSize(vSize);
 }
 
 /*void CEditorObject::setScale(const float3_t &vScale, bool isSeparate)
diff --git a/source/game/EntityFactory.h b/source/game/EntityFactory.h
index 46ff5c91c..1ec3331aa 100644
--- a/source/game/EntityFactory.h
+++ b/source/game/EntityFactory.h
@@ -203,6 +203,9 @@ private:
 #define REC_ICON(s) REC_KV("icon", s)
 #define REC_MODEL(s) REC_KV("model", s)
 #define REC_MODEL_FIELD(s) REC_KV("model_field", s)
+#define REC_NO_HEIGHT_ADJUST() REC_KV("no_height_adj", "1")
+#define REC_ALIGN_WITH_NORMAL(axis) REC_KV("align_with_norm", axis)
+#define REC_MATERIAL_FIELD(s) REC_KV("material_field", s)
 
 #define REGISTER_ENTITY(cls, name, ...) \
 	CEntityFactory<cls> ent_ ## name ## _factory(#name, {__VA_ARGS__})
diff --git a/source/game/EntityManager.cpp b/source/game/EntityManager.cpp
index f7bdfed35..f7a14bf63 100644
--- a/source/game/EntityManager.cpp
+++ b/source/game/EntityManager.cpp
@@ -400,14 +400,14 @@ bool CEntityManager::exportList(const char * file)
 	int ic = 0;
 
 	//if(m_isOldImported)
-	{
+	/*{
 		FILE *fp = fopen(file, "w");
 		if(fp)
 		{
 			fclose(fp);
 		}
 		m_isOldImported = false;
-	}
+	}*/
 
 	// conf->set("meta", "count", "0");
 
@@ -463,13 +463,7 @@ bool CEntityManager::import(const char * file, bool shouldSendProgress)
 	CBaseEntity *pEnt = NULL;
 	Array<CBaseEntity*> tmpList;
 
-	char szFullPath[1024];
-	if(!Core_GetIXCore()->getFileSystem()->resolvePath(file, szFullPath, sizeof(szFullPath)))
-	{
-		goto err;
-	}
-
-	if(conf->open(szFullPath))
+	if(conf->open(file))
 	{
 		goto err;
 	}
diff --git a/source/game/GameData.cpp b/source/game/GameData.cpp
index ed4c74755..1f6d4ed04 100644
--- a/source/game/GameData.cpp
+++ b/source/game/GameData.cpp
@@ -347,9 +347,12 @@ void XMETHODCALLTYPE CLevelLoadTask::exec()
 	evLevel.szLevelName = m_szLevelName;
 
 	g_levelProgressListener.onLoadBegin();
-	
+
 	evLevel.type = XEventLevel::TYPE_LOAD;
 	g_pLevelChannel->broadcastEvent(&evLevel);
+
+	evLevel.type = XEventLevel::TYPE_LOAD_WAIT_ASYNC_TASKS;
+	g_pLevelChannel->broadcastEvent(&evLevel);
 }
 
 void XMETHODCALLTYPE CLevelLoadTask::onFinished()
diff --git a/source/game/InfoOverlay.cpp b/source/game/InfoOverlay.cpp
new file mode 100644
index 000000000..d53418554
--- /dev/null
+++ b/source/game/InfoOverlay.cpp
@@ -0,0 +1,372 @@
+#include "InfoOverlay.h"
+
+BEGIN_PROPTABLE(CInfoOverlay)
+	//! Значение по умолчанию
+	DEFINE_FIELD_STRINGFN(m_szMaterial, PDFF_NONE, "material", "Overlay material", setMaterial, EDITOR_MATERIAL)
+
+	//! Высота объема декали
+	DEFINE_FIELD_FLOATFN(m_fHeight, PDFF_NONE, "height", "Height", setHeight, EDITOR_TEXTFIELD)
+
+	//! Угол 1
+	DEFINE_FIELD_VECTORFN(m_vCorner0, PDFF_USE_GIZMO, "point0", "Point 1", setCorner0, EDITOR_POINTCOORDEX)
+		EDITOR_KV("lock", "plane")
+		EDITOR_KV("axis", "z")
+		EDITOR_KV("local", "1")
+	EDITOR_END()
+	//! Угол 2
+	DEFINE_FIELD_VECTORFN(m_vCorner1, PDFF_USE_GIZMO, "point1", "Point 2", setCorner1, EDITOR_POINTCOORDEX)
+		EDITOR_KV("lock", "plane")
+		EDITOR_KV("axis", "z")
+		EDITOR_KV("local", "1")
+	EDITOR_END()
+	//! Угол 3
+	DEFINE_FIELD_VECTORFN(m_vCorner2, PDFF_USE_GIZMO, "point2", "Point 3", setCorner2, EDITOR_POINTCOORDEX)
+		EDITOR_KV("lock", "plane")
+		EDITOR_KV("axis", "z")
+		EDITOR_KV("local", "1")
+	EDITOR_END()
+	//! Угол 4
+	DEFINE_FIELD_VECTORFN(m_vCorner3, PDFF_USE_GIZMO, "point3", "Point 4", setCorner3, EDITOR_POINTCOORDEX)
+		EDITOR_KV("lock", "plane")
+		EDITOR_KV("axis", "z")
+		EDITOR_KV("local", "1")
+	EDITOR_END()
+
+	//! Разрешить перетекание на перпендикулярные поверхности
+	DEFINE_FIELD_BOOLFN(m_isLeakAllowed, PDFF_NONE, "allow_leak", "Allow leak to perpendicular surface", setLeakAllowed, EDITOR_YESNO)
+
+	//! Угол 4
+	//DEFINE_FIELD_VECTORFN(m_vSize, PDFF_USE_GIZMO, "size", "Size", setSize, EDITOR_SIZE)
+
+	//! Включает
+	//DEFINE_INPUT(turnOn, "turnOn", "Turn on", PDF_NONE)
+	//! Выключает
+	//DEFINE_INPUT(turnOff, "turnOff", "Turn off", PDF_NONE)
+	//! Переключает состояние
+	//DEFINE_INPUT(toggle, "toggle", "Toggle", PDF_NONE)
+
+	
+
+	//! Изначально выключена
+	//DEFINE_FLAG(MOVER_INITIALLY_DISABLED, "Start disabled")
+	//! Отключить автомонтирование (требуется нажать кнопку взаимодействия)
+	//DEFINE_FLAG(MOVER_NO_AUTOMOUNT, "Disable automount")
+END_PROPTABLE()
+
+REGISTER_ENTITY(CInfoOverlay, info_overlay, REC_NO_HEIGHT_ADJUST(), REC_ALIGN_WITH_NORMAL("z"), REC_MATERIAL_FIELD("material"));
+
+CInfoOverlay::CInfoOverlay()
+{
+	float2_t vSize(1.0f, 1.0f);
+
+	float2_t sBound(-vSize.x * 0.5f, vSize.x * 0.5f);
+	float2_t tBound(-vSize.y * 0.5f, vSize.y * 0.5f);
+
+	m_vCorner0 = float3_t(sBound.x, tBound.x, 0.0f);
+	m_vCorner1 = float3_t(sBound.x, tBound.y, 0.0f);
+	m_vCorner2 = float3_t(sBound.y, tBound.y, 0.0f);
+	m_vCorner3 = float3_t(sBound.y, tBound.x, 0.0f);
+
+	m_fHeight = min(vSize.x, vSize.y) * 0.25f;
+
+	GetDecalProvider()->newDecal(&m_pDecal);
+
+	m_pDecal->setHeight(m_fHeight);
+	
+	m_pDecal->setCorner(0, float2(m_vCorner0));
+	m_pDecal->setCorner(1, float2(m_vCorner1));
+	m_pDecal->setCorner(2, float2(m_vCorner2));
+	m_pDecal->setCorner(3, float2(m_vCorner3));
+
+	updateSize();
+}
+
+CInfoOverlay::~CInfoOverlay()
+{
+	mem_release(m_pDecal);
+}
+
+void CInfoOverlay::setCorner0(const float3 &v)
+{
+	m_vCorner0 = v;
+	m_pDecal->setCorner(0, float2(v));
+	updateSize();
+}
+void CInfoOverlay::setCorner1(const float3 &v)
+{
+	m_vCorner1 = v;
+	m_pDecal->setCorner(1, float2(v));
+	updateSize();
+}
+void CInfoOverlay::setCorner2(const float3 &v)
+{
+	m_vCorner2 = v;
+	m_pDecal->setCorner(2, float2(v));
+	updateSize();
+}
+void CInfoOverlay::setCorner3(const float3 &v)
+{
+	m_vCorner3 = v;
+	m_pDecal->setCorner(3, float2(v));
+	updateSize();
+}
+
+void CInfoOverlay::setPos(const float3 &vPos)
+{
+	BaseClass::setPos(vPos);
+
+	m_pDecal->setPosition(vPos);
+}
+
+void CInfoOverlay::setOrient(const SMQuaternion &qRot)
+{
+	BaseClass::setOrient(qRot);
+
+	m_pDecal->setOrientation(qRot);
+}
+
+void CInfoOverlay::setMaterial(const char *szValue)
+{
+	_setStrVal(&m_szMaterial, szValue);
+
+	m_pDecal->setMaterial(szValue);
+}
+
+void CInfoOverlay::setHeight(float fHeight)
+{
+	m_fHeight = fHeight;
+	m_pDecal->setHeight(fHeight);
+}
+
+void CInfoOverlay::renderEditor(bool is3D, bool bRenderSelection, IXGizmoRenderer *pRenderer)
+{
+	if(pRenderer)
+	{
+		pRenderer->setLineWidth(is3D ? 0.01f : 1.0f);
+
+		pRenderer->setColor(float4(1.0f, 0.0f, 0.0f, 1.0f));
+		pRenderer->jumpTo(getPos());
+		pRenderer->lineTo(getPos() + getOrient() * float3(0.1f, 0.0f, 0.0f));
+
+		pRenderer->setColor(float4(0.0f, 1.0f, 0.0f, 1.0f));
+		pRenderer->jumpTo(getPos());
+		pRenderer->lineTo(getPos() + getOrient() * float3(0.0f, 0.1f, 0.0f));
+
+		pRenderer->setColor(float4(0.0f, 0.0f, 1.0f, 1.0f));
+		pRenderer->jumpTo(getPos());
+		pRenderer->lineTo(getPos() + getOrient() * float3(0.0f, 0.0f, 0.2f));
+
+		if(bRenderSelection || !is3D)
+		{
+			pRenderer->setLineWidth(is3D ? 0.005f : 1.0f);
+			const float4 c_vLineColor = bRenderSelection ? float4(1.0f, 0.0f, 0.0f, 1.0f) : float4(1.0f, 0.0f, 1.0f, 1.0f);
+			pRenderer->setColor(c_vLineColor);
+
+			float3 vS = getOrient() * float3(1.0f, 0.0f, 0.0f);
+			float3 vT = getOrient() * float3(0.0f, 1.0f, 0.0f);
+			float3 vN = getOrient() * float3(0.0f, 0.0f, 1.0f);
+
+			float3_t vPt0 = getPos() + m_vCorner0.x * vS + m_vCorner0.y * vT;
+			float3_t vPt1 = getPos() + m_vCorner1.x * vS + m_vCorner1.y * vT;
+			float3_t vPt2 = getPos() + m_vCorner2.x * vS + m_vCorner2.y * vT;
+			float3_t vPt3 = getPos() + m_vCorner3.x * vS + m_vCorner3.y * vT;
+
+			float3 vTopOffset = vN * m_fHeight;
+
+			pRenderer->jumpTo(vPt0 - vTopOffset);
+			pRenderer->lineTo(vPt1 - vTopOffset);
+			pRenderer->lineTo(vPt2 - vTopOffset);
+			pRenderer->lineTo(vPt3 - vTopOffset);
+			pRenderer->lineTo(vPt0 - vTopOffset);
+			pRenderer->lineTo(vPt0 + vTopOffset);
+			pRenderer->lineTo(vPt1 + vTopOffset);
+			pRenderer->lineTo(vPt2 + vTopOffset);
+			pRenderer->lineTo(vPt3 + vTopOffset);
+			pRenderer->lineTo(vPt0 + vTopOffset);
+
+			pRenderer->jumpTo(vPt1 - vTopOffset);
+			pRenderer->lineTo(vPt1 + vTopOffset);
+
+			pRenderer->jumpTo(vPt2 - vTopOffset);
+			pRenderer->lineTo(vPt2 + vTopOffset);
+
+			pRenderer->jumpTo(vPt3 - vTopOffset);
+			pRenderer->lineTo(vPt3 + vTopOffset);
+		}
+	}
+}
+
+void CInfoOverlay::getMinMax(float3 *min, float3 *max)
+{
+	float3 vS = getOrient() * float3(1.0f, 0.0f, 0.0f);
+	float3 vT = getOrient() * float3(0.0f, 1.0f, 0.0f);
+	float3 vN = getOrient() * float3(0.0f, 0.0f, 1.0f);
+
+	float3 vTopOffset = vN * m_fHeight;
+
+	float3_t vPt0 = m_vCorner0.x * vS + m_vCorner0.y * vT;
+	float3_t vPt1 = m_vCorner1.x * vS + m_vCorner1.y * vT;
+	float3_t vPt2 = m_vCorner2.x * vS + m_vCorner2.y * vT;
+	float3_t vPt3 = m_vCorner3.x * vS + m_vCorner3.y * vT;
+
+	float3_t vPt10 = vPt0 + vTopOffset;
+	float3_t vPt11 = vPt1 + vTopOffset;
+	float3_t vPt12 = vPt2 + vTopOffset;
+	float3_t vPt13 = vPt3 + vTopOffset;
+
+	vPt0 = vPt0 - vTopOffset;
+	vPt1 = vPt1 - vTopOffset;
+	vPt2 = vPt2 - vTopOffset;
+	vPt3 = vPt3 - vTopOffset;
+
+	if(min)
+	{
+		*min = SMVectorMin(
+			SMVectorMin(SMVectorMin(vPt0, vPt1), SMVectorMin(vPt2, vPt3)),
+			SMVectorMin(SMVectorMin(vPt10, vPt11), SMVectorMin(vPt12, vPt13))
+		);
+	}
+
+	if(max)
+	{
+		*max = SMVectorMax(
+			SMVectorMax(SMVectorMax(vPt0, vPt1), SMVectorMax(vPt2, vPt3)),
+			SMVectorMax(SMVectorMax(vPt10, vPt11), SMVectorMax(vPt12, vPt13))
+		);
+	}
+}
+
+void CInfoOverlay::setSize(const float3_t &vSize)
+{
+	float3 vMin, vMax;
+	getMinMax(&vMin, &vMax);
+	BaseClass::setSize(vSize);
+
+	float3 vRelativeSize = vSize / (vMax - vMin);
+
+	float3 vS = getOrient() * float3(1.0f, 0.0f, 0.0f);
+	float3 vT = getOrient() * float3(0.0f, 1.0f, 0.0f);
+	float3 vN = getOrient() * float3(0.0f, 0.0f, 1.0f);
+
+	float3_t vPt0 = (m_vCorner0.x * vS + m_vCorner0.y * vT) * vRelativeSize;
+	float3_t vPt1 = (m_vCorner1.x * vS + m_vCorner1.y * vT) * vRelativeSize;
+	float3_t vPt2 = (m_vCorner2.x * vS + m_vCorner2.y * vT) * vRelativeSize;
+	float3_t vPt3 = (m_vCorner3.x * vS + m_vCorner3.y * vT) * vRelativeSize;
+
+	m_vCorner0 = float3_t(SMVector3Dot(vPt0, vS), SMVector3Dot(vPt0, vT), 0.0f);
+	m_vCorner1 = float3_t(SMVector3Dot(vPt1, vS), SMVector3Dot(vPt1, vT), 0.0f);
+	m_vCorner2 = float3_t(SMVector3Dot(vPt2, vS), SMVector3Dot(vPt2, vT), 0.0f);
+	m_vCorner3 = float3_t(SMVector3Dot(vPt3, vS), SMVector3Dot(vPt3, vT), 0.0f);
+
+	m_pDecal->setCorner(0, float2(m_vCorner0));
+	m_pDecal->setCorner(1, float2(m_vCorner1));
+	m_pDecal->setCorner(2, float2(m_vCorner2));
+	m_pDecal->setCorner(3, float2(m_vCorner3));
+
+	m_fHeight *= SMVector3Dot(vN, vRelativeSize);
+	m_pDecal->setHeight(m_fHeight);
+
+	updateSize();
+}
+
+bool CInfoOverlay::rayTest(const float3 &vStart, const float3 &vEnd, float3 *pvOut, float3 *pvNormal, bool isRayInWorldSpace, bool bReturnNearestPoint)
+{
+	if(!isRayInWorldSpace)
+	{
+		float3 vPos = getPos();
+		SMQuaternion qRot = getOrient().Conjugate();
+
+		float3 vRayStart = qRot * vStart - vPos;
+		float3 vRayEnd = qRot * vEnd - vPos;
+		return(m_pDecal->rayTest(vRayStart, vRayEnd, pvOut, pvNormal));
+	}
+
+	return(m_pDecal->rayTest(vStart, vEnd, pvOut, pvNormal));
+}
+
+void CInfoOverlay::updateSize()
+{
+	float3 vMin = SMVectorMin(SMVectorMin(m_vCorner0, m_vCorner1), SMVectorMin(m_vCorner2, m_vCorner3));
+	float3 vMax = SMVectorMax(SMVectorMax(m_vCorner0, m_vCorner1), SMVectorMax(m_vCorner2, m_vCorner3));
+
+	m_vSize = vMax - vMin;
+	m_vSize.z = m_fHeight * 2.0f;
+}
+
+void CInfoOverlay::setSize(const float3 &v)
+{
+}
+
+void CInfoOverlay::setLeakAllowed(bool yesNo)
+{
+	m_isLeakAllowed = yesNo;
+	m_pDecal->setLeakAllowed(yesNo);
+}
+
+#if 0
+
+void CInfoOverlay::updateFlags()
+{
+	BaseClass::updateFlags();
+
+	if(getFlags() & MOVER_INITIALLY_DISABLED)
+	{
+		disable();
+	}
+	else
+	{
+		enable();
+	}
+}
+
+void CInfoOverlay::turnOn(inputdata_t *pInputdata)
+{
+	enable();
+}
+
+void CInfoOverlay::turnOff(inputdata_t *pInputdata)
+{
+	disable();
+}
+
+void CInfoOverlay::toggle(inputdata_t *pInputdata)
+{
+	if(m_isEnabled)
+	{
+		turnOff(pInputdata);
+	}
+	else
+	{
+		turnOn(pInputdata);
+	}
+}
+
+
+
+void CInfoOverlay::enable()
+{
+	if(!m_isEnabled)
+	{
+		if(m_pGhostObject)
+		{
+			GetPhysWorld()->addCollisionObject(m_pGhostObject, CG_LADDER, CG_CHARACTER);
+		}
+		m_pTickEventChannel->addListener(&m_physicsTicker);
+		m_isEnabled = true;
+	}
+}
+
+void CInfoOverlay::disable()
+{
+	if(m_isEnabled)
+	{
+		if(m_pGhostObject)
+		{
+			GetPhysWorld()->removeCollisionObject(m_pGhostObject);
+		}
+		m_pTickEventChannel->removeListener(&m_physicsTicker);
+		m_isEnabled = false;
+	}
+}
+
+#endif
diff --git a/source/game/InfoOverlay.h b/source/game/InfoOverlay.h
new file mode 100644
index 000000000..ca46e39c5
--- /dev/null
+++ b/source/game/InfoOverlay.h
@@ -0,0 +1,71 @@
+#ifndef __INFO_OVERLAY_H
+#define __INFO_OVERLAY_H
+
+#include "PointEntity.h"
+
+//#define MOVER_INITIALLY_DISABLED ENT_FLAG_0
+//#define MOVER_NO_AUTOMOUNT ENT_FLAG_1
+
+class CInfoOverlay: public CPointEntity
+{
+	DECLARE_CLASS(CInfoOverlay, CPointEntity);
+	DECLARE_PROPTABLE();
+public:
+	DECLARE_CONSTRUCTOR();
+	~CInfoOverlay();
+
+	void setPos(const float3 &vPos) override;
+	void setOrient(const SMQuaternion &qRot) override;
+
+	void renderEditor(bool is3D, bool bRenderSelection, IXGizmoRenderer *pRenderer) override;
+
+	void getMinMax(float3 *min, float3 *max) override;
+
+	
+
+	bool rayTest(const float3 &vStart, const float3 &vEnd, float3 *pvOut = NULL, float3 *pvNormal = NULL, bool isRayInWorldSpace = true, bool bReturnNearestPoint = false) override;
+
+	void setHeight(float fHeight);
+	void setMaterial(const char *szValue);
+
+	void setSize(const float3_t &vSize) override;
+
+	void setLeakAllowed(bool yesNo);
+
+private:
+	void setCorner0(const float3 &v);
+	void setCorner1(const float3 &v);
+	void setCorner2(const float3 &v);
+	void setCorner3(const float3 &v);
+
+	void setSize(const float3 &v);
+	//void updateFlags() override;
+
+	//void turnOn(inputdata_t *pInputdata);
+	//void turnOff(inputdata_t *pInputdata);
+	//void toggle(inputdata_t *pInputdata);
+	//void enable();
+	//void disable();
+
+	//SMAABB getBound();
+	void updateSize();
+
+private:
+	IXDecal *m_pDecal = NULL;
+	const char *m_szMaterial = NULL;
+
+	float3_t m_vCorner0;
+	float3_t m_vCorner1;
+	float3_t m_vCorner2;
+	float3_t m_vCorner3;
+	
+	float m_fHeight = 0.1f;
+
+	float3_t m_vSize;
+
+	bool m_isLeakAllowed = true;
+
+	//bool m_isEnabled = false;
+};
+
+#endif
diff --git a/source/game/proptable.cpp b/source/game/proptable.cpp
index 619cba20a..57723b117 100644
--- a/source/game/proptable.cpp
+++ b/source/game/proptable.cpp
@@ -11,14 +11,14 @@ See the license in LICENSE
 
 #include "BaseEntity.h"
 
-prop_editor_t _GetEditorCombobox(int start, ...)
+prop_editor_t _GetEditor(PDE_TYPE type, ...)
 {
 	prop_editor_t out;
-	out.type = PDE_COMBOBOX;
-	editor_kv kvs[ED_COMBO_MAXELS];
+	out.type = type;
+	kv_t kvs[ED_COMBO_MAXELS];
 
 	va_list va;
-	va_start(va, start);
+	va_start(va, type);
 
 	const char * el;
 	int i = 0;
@@ -28,56 +28,21 @@ prop_editor_t _GetEditorCombobox(int start, ...)
 		{
 			break;
 		}
-		kvs[i].key = el;
+		kvs[i].szKey = el;
 		if(!(el = va_arg(va, const char *)))
 		{
 			break;
 		}
-		kvs[i].value = el;
+		kvs[i].szValue = el;
 		++i;
 	}
-	kvs[i].value = kvs[i].key = 0;
+	kvs[i].szValue = kvs[i].szKey = 0;
 	++i;
 
 	va_end(va);
 
-	out.pData = new editor_kv[i];
-	memcpy(out.pData, kvs, sizeof(editor_kv)* i);
-	return(out);
-}
-
-prop_editor_t _GetEditorFilefield(int start, ...)
-{
-	prop_editor_t out;
-	out.type = PDE_FILEFIELD;
-	editor_kv kvs[ED_COMBO_MAXELS];
-
-	va_list va;
-	va_start(va, start);
-
-	const char * el;
-	int i = 0;
-	while(i < ED_COMBO_MAXELS)
-	{
-		if(!(el = va_arg(va, const char *)))
-		{
-			break;
-		}
-		kvs[i].key = el;
-		if(!(el = va_arg(va, const char *)))
-		{
-			break;
-		}
-		kvs[i].value = el;
-		++i;
-	}
-	kvs[i].value = kvs[i].key = 0;
-	++i;
-
-	va_end(va);
-
-	out.pData = new editor_kv[i];
-	memcpy(out.pData, kvs, sizeof(editor_kv)* i);
+	out.pData = new kv_t[i];
+	memcpy(out.pData, kvs, sizeof(kv_t)* i);
 	return(out);
 }
 
diff --git a/source/game/proptable.h b/source/game/proptable.h
index b73c430f9..3f97ecba7 100644
--- a/source/game/proptable.h
+++ b/source/game/proptable.h
@@ -74,7 +74,8 @@ enum PDE_TYPE
 	PDE_POINTCOORD,
 	PDE_RADIUS,
 	PDE_COLOR,
-	PDE_HDRCOLOR
+	PDE_HDRCOLOR,
+	PDE_SIZE
 };
 
 enum PDF_FLAG
@@ -170,12 +171,6 @@ union PFNFIELDSET
 	int __;
 };
 
-struct editor_kv
-{
-	const char * key;
-	const char * value;
-};
-
 struct prop_editor_t
 {
 	PDE_TYPE type;
@@ -367,8 +362,7 @@ struct proptable_t
 
 #define ED_COMBO_MAXELS 256
 
-prop_editor_t _GetEditorCombobox(int start, ...);
-prop_editor_t _GetEditorFilefield(int start, ...);
+prop_editor_t _GetEditor(PDE_TYPE type, ...);
 
 #define DECLARE_PROPTABLE() \
 	\
@@ -454,6 +448,10 @@ void cls::InitPropData() \
 
 const char * GetEmptyString();
 
+#define EDITOR_BEGIN(type) _GetEditor(type
+#define EDITOR_KV(name, value) , name, value
+#define EDITOR_END() , NULL)}
+
 #define EDITOR_NONE {PDE_NONE, NULL}}
 #define EDITOR_TEXTFIELD {PDE_TEXTFIELD, NULL}}
 #define EDITOR_TIMEFIELD {PDE_TIME, NULL}}
@@ -463,19 +461,24 @@ const char * GetEmptyString();
 #define EDITOR_FLAGS {PDE_FLAGS, NULL}}
 #define EDITOR_COLOR {PDE_COLOR, NULL}}
 #define EDITOR_HDRCOLOR {PDE_HDRCOLOR, NULL}}
+#define EDITOR_SIZE {PDE_SIZE, NULL}}
+
+#define EDITOR_POINTCOORDEX EDITOR_BEGIN(PDE_POINTCOORD)
+
 
-#define EDITOR_COMBOBOX _GetEditorCombobox(0
-#define COMBO_OPTION(name, value) , name, value
-#define EDITOR_COMBO_END() , NULL)}
+#define EDITOR_COMBOBOX EDITOR_BEGIN(PDE_COMBOBOX)
+#define COMBO_OPTION(name, value) EDITOR_KV(name, value)
+#define EDITOR_COMBO_END() EDITOR_END()
 
-#define EDITOR_FILEFIELD _GetEditorFilefield(0
-#define FILE_OPTION(name, value) , name, value
-#define EDITOR_FILE_END() , NULL)}
+#define EDITOR_FILEFIELD EDITOR_BEGIN(PDE_FILEFIELD)
+#define FILE_OPTION(name, value) EDITOR_KV(name, value)
+#define EDITOR_FILE_END() EDITOR_END()
 
 #define EDITOR_YESNO EDITOR_COMBOBOX COMBO_OPTION("Yes", "1") COMBO_OPTION("No", "0") EDITOR_COMBO_END()
 #define EDITOR_MODEL EDITOR_FILEFIELD FILE_OPTION("Select model", "dse") EDITOR_FILE_END()
 #define EDITOR_SOUND EDITOR_FILEFIELD FILE_OPTION("Select sound", "ogg") EDITOR_FILE_END()
 #define EDITOR_TEXTURE EDITOR_FILEFIELD FILE_OPTION("Select texture", "dds") EDITOR_FILE_END()
+#define EDITOR_MATERIAL EDITOR_FILEFIELD FILE_OPTION("Select material", "mtl") EDITOR_FILE_END()
 #define EDITOR_EFFECT EDITOR_FILEFIELD FILE_OPTION("Select effect", "eff") EDITOR_FILE_END()
 
 #define DEFINE_FIELD_STRING(field, flags, keyname, edname, editor)              , {propdata_t::ToFieldType<const char* DataClass::*>(&DataClass::field),          PDF_STRING,  flags, keyname, edname, editor
diff --git a/source/gdefines.h b/source/gdefines.h
index 30f4bac0d..bc8b37e1f 100644
--- a/source/gdefines.h
+++ b/source/gdefines.h
@@ -221,6 +221,12 @@ typedef void(*report_func) (int iLevel, const char *szLibName, const char *szMes
 #define GET_Y_LPARAM(lp)                        ((int)(short)HIWORD(lp))
 #endif
 
+struct kv_t
+{
+	const char *szKey;
+	const char *szValue;
+};
+
 /** \name Уровни критичности сообщений для функции репортов */
 //! @{
 #define REPORT_MSG_LEVEL_NOTICE		0	/*!< заметка */
diff --git a/source/render/Scene.cpp b/source/render/Scene.cpp
index 42e5ad8a8..46d10cb9c 100644
--- a/source/render/Scene.cpp
+++ b/source/render/Scene.cpp
@@ -1287,6 +1287,11 @@ public:
 		return(m_pEditorExt->getRenderer());
 	}
 
+	const char* XMETHODCALLTYPE getClassKV(const char *szClassName, const char *szKey) override
+	{
+		return(NULL);
+	}
+
 private:
 	CEditorExt *m_pEditorExt = NULL;
 };
@@ -1696,3 +1701,8 @@ void CScene::print()
 	m_pRootNode->print(0, &uNodesCount, &uObjectsCount, &uMaxDepth);
 	printf("Total objects: %u, Total nodes: %u, Max depth: %u, avg objects per node: %f\n", uObjectsCount, uNodesCount, uMaxDepth, (float)uObjectsCount / (float)uNodesCount);
 }
+
+bool CScene::hasPendingOps()
+{
+	return(!m_qUpdate.empty());
+}
diff --git a/source/render/Scene.h b/source/render/Scene.h
index 4d810b09a..7b42aeff7 100644
--- a/source/render/Scene.h
+++ b/source/render/Scene.h
@@ -275,6 +275,8 @@ public:
 	bool validate();
 	void print();
 
+	bool hasPendingOps();
+
 protected:
 	void addObject(CSceneObject *pObject);
 	void removeObject(CSceneObject *pObject);
diff --git a/source/render/plugin_main.cpp b/source/render/plugin_main.cpp
index 0e510908d..01d6d6743 100644
--- a/source/render/plugin_main.cpp
+++ b/source/render/plugin_main.cpp
@@ -15,6 +15,33 @@
 #pragma comment(lib, "sxgame.lib")
 #endif
 
+class CLoadLevelEventListener final: public IEventListener<XEventLevel>
+{
+public:
+	CLoadLevelEventListener(CScene *pScene):
+		m_pScene(pScene)
+	{
+	}
+	void onEvent(const XEventLevel *pData)
+	{
+		switch(pData->type)
+		{
+		case XEventLevel::TYPE_LOAD_WAIT_ASYNC_TASKS:
+			while(m_pScene->hasPendingOps())
+			{
+				Sleep(100);
+			}
+			break;
+
+		default:
+			break;
+		}
+	}
+
+protected:
+	CScene *m_pScene;
+};
+
 class CRenderPlugin: public IXUnknownImplementation<IXPlugin>
 {
 public:
@@ -25,6 +52,10 @@ public:
 
 	void XMETHODCALLTYPE shutdown() override
 	{
+		if(m_pLevelLoadEventListener)
+		{
+			m_pCore->getEventChannel<XEventLevel>(EVENT_LEVEL_GUID)->removeListener(m_pLevelLoadEventListener);
+		}
 	}
 
 	UINT XMETHODCALLTYPE getInterfaceCount() override
@@ -68,6 +99,9 @@ public:
 			if(!m_pScene)
 			{
 				m_pScene = new CScene(m_pCore);
+				m_pLevelLoadEventListener = new CLoadLevelEventListener(m_pScene);
+
+				m_pCore->getEventChannel<XEventLevel>(EVENT_LEVEL_GUID)->addListener(m_pLevelLoadEventListener);
 			}
 			*ppOut = m_pScene;
 			break;
@@ -144,6 +178,7 @@ protected:
 	CScene *m_pScene = NULL;
 	CUpdatable *m_pUpdatable = NULL;
 	CRender *m_pRender = NULL;
+	CLoadLevelEventListener *m_pLevelLoadEventListener = NULL;
 };
 
 DECLARE_XPLUGIN(CRenderPlugin);
diff --git a/source/terrax/CommandBuildModel.cpp b/source/terrax/CommandBuildModel.cpp
index f3ff59d42..30484344f 100644
--- a/source/terrax/CommandBuildModel.cpp
+++ b/source/terrax/CommandBuildModel.cpp
@@ -5,7 +5,7 @@ extern AssotiativeArray<AAString, IXEditable*> g_mEditableSystems;
 
 CCommandBuildModel::CCommandBuildModel(const char *szTypeName, const char *szClassName)
 {
-	m_pCommandCreate = new CCommandCreate(float3_t(), szTypeName, szClassName);
+	m_pCommandCreate = new CCommandCreate(float3_t(), float3_t(), szTypeName, szClassName);
 }
 
 CCommandBuildModel::~CCommandBuildModel()
diff --git a/source/terrax/CommandCreate.cpp b/source/terrax/CommandCreate.cpp
index 7dac8882c..df0279c18 100644
--- a/source/terrax/CommandCreate.cpp
+++ b/source/terrax/CommandCreate.cpp
@@ -3,15 +3,15 @@
 
 extern AssotiativeArray<AAString, IXEditable*> g_mEditableSystems;
 
-CCommandCreate::CCommandCreate(const float3_t &vPos, const char *szTypeName, const char *szClassName, bool useRandomScaleYaw)
+CCommandCreate::CCommandCreate(const float3_t &vPos, const float3_t &vNorm, const char *szTypeName, const char *szClassName, bool useRandomScaleYaw):
+	m_vPos(vPos),
+	m_vNorm(vNorm),
+	m_sClassName(szClassName)
 {
-	m_vPos = vPos;
-	m_sClassName = szClassName;
-
 	if(useRandomScaleYaw)
 	{
 		m_fScale = randf(0.7, 1.3);
-		m_qOrient = SMQuaternion(randf(0, SM_2PI), 'y');
+		m_fRotAngle = randf(0, SM_2PI);
 	}
 
 	const AssotiativeArray<AAString, IXEditable*>::Node *pNode;
@@ -42,10 +42,82 @@ bool XMETHODCALLTYPE CCommandCreate::exec()
 	m_pObject->setPos(m_vPos);
 	//! @TODO Implement random scale?
 	//m_pObject->setScale(float3(m_fScale));
-	m_pObject->setOrient(m_qOrient);
+	const char *szNormalAlign = m_pEditable->getClassKV(m_sClassName.c_str(), "align_with_norm");
+	if(!SMIsZero(SMVector3Length2(m_vNorm)) && szNormalAlign)
+	{
+		char cAxis = szNormalAlign[0];
+		float fVal = 1.0f;
+		if(cAxis == '-')
+		{
+			cAxis = szNormalAlign[1];
+			float fVal = -1.0f;
+		}
+		float3_t vFrom;
+		switch(tolower(cAxis))
+		{
+		case 'x':
+			vFrom.x = fVal;
+			break;
+		case 'y':
+			vFrom.y = fVal;
+			break;
+		case 'z':
+			vFrom.z = fVal;
+			break;
+		}
+		SMQuaternion qRot(vFrom, m_vNorm);
+		m_pObject->setOrient(qRot * SMQuaternion(m_vNorm, m_fRotAngle));
+	}
+	else
+	{
+		m_pObject->setOrient(SMQuaternion(m_fRotAngle, 'y'));
+	}
 	m_pObject->setSelected(true);
 	m_pObject->create();
 
+	if(!SMIsZero(SMVector3Length2(m_vNorm)) && !m_pEditable->getClassKV(m_sClassName.c_str(), "no_height_adj"))
+	{
+		float3 vMin, vMax;
+		m_pObject->getBound(&vMin, &vMax);
+
+		float3 avPoints[] = {
+			float3(vMin),
+			float3(vMin.x, vMin.y, vMax.z),
+			float3(vMin.x, vMax.y, vMin.z),
+			float3(vMin.x, vMax.y, vMax.z),
+			float3(vMax.x, vMin.y, vMin.z),
+			float3(vMax.x, vMin.y, vMax.z),
+			float3(vMax.x, vMax.y, vMin.z),
+			float3(vMax),
+		};
+		//printf("%.2f, %.2f, %.2f\n", vNorm.x, vNorm.y, vNorm.z);
+
+		float fProj = FLT_MAX;
+		for(UINT i = 0, l = ARRAYSIZE(avPoints); i < l; ++i)
+		{
+			float fTmp = SMVector3Dot(avPoints[i], m_vNorm);
+			//printf("%.2f\n", fTmp);
+			if(fTmp < fProj)
+			{
+				fProj = fTmp;
+			}
+		}
+
+		fProj = SMVector3Dot(m_vPos, m_vNorm) - fProj;
+		//printf("%.2f, %.2f, %.2f\n%.2f, %.2f, %.2f\n%.2f, %.2f, %.2f\n%f\n\n", vPos.x, vPos.y, vPos.z, vMin.x, vMin.y, vMin.z, vMax.x, vMax.y, vMax.z, fProj);
+		if(fProj > 0)
+		{
+			m_pObject->setPos((float3)(m_vPos + m_vNorm * fProj));
+		}
+	}
+
+	const char *szMaterialField = m_pEditable->getClassKV(m_sClassName.c_str(), "material_field");
+	if(szMaterialField)
+	{
+		m_sMaterial = g_pEditor->getMaterialBrowser()->getCurrentMaterial();
+		m_pObject->setKV(szMaterialField, m_sMaterial.c_str());
+	}
+
 	g_pEditor->addObject(m_pObject);
 
 	XUpdatePropWindow();
diff --git a/source/terrax/CommandCreate.h b/source/terrax/CommandCreate.h
index 7b72e90d6..ba0b86dee 100644
--- a/source/terrax/CommandCreate.h
+++ b/source/terrax/CommandCreate.h
@@ -11,7 +11,7 @@
 class CCommandCreate final: public IXUnknownImplementation<IXEditorCommand>
 {
 public:
-	CCommandCreate(const float3_t &vPos, const char *szTypeName, const char *szClassName, bool useRandomScaleYaw=false);
+	CCommandCreate(const float3_t &vPos, const float3_t &vNorm, const char *szTypeName, const char *szClassName, bool useRandomScaleYaw = false);
 	~CCommandCreate();
 
 	bool XMETHODCALLTYPE exec() override;
@@ -34,11 +34,13 @@ public:
 
 protected:
 	float3_t m_vPos;
-	SMQuaternion m_qOrient;
+	float3_t m_vNorm;
+	float m_fRotAngle = 0.0f;
 	float m_fScale = 1.0f;
 	String m_sClassName;
 	IXEditable *m_pEditable = NULL;
 	IXEditorObject *m_pObject = NULL;
+	String m_sMaterial;
 };
 
 #endif
diff --git a/source/terrax/Editor.cpp b/source/terrax/Editor.cpp
index e17b7ce2a..51185b827 100644
--- a/source/terrax/Editor.cpp
+++ b/source/terrax/Editor.cpp
@@ -38,6 +38,8 @@ CEditor::CEditor(IXCore *pCore):
 	pCore->getPluginManager()->registerInterface(IXCOLORPICKER_GUID, &m_colorPicker);
 
 	m_pSceneTreeWindow = new CSceneTreeWindow(this, pCore);
+
+	registerResourceBrowser(new CResourceBrowser());
 }
 
 CEditor::~CEditor()
diff --git a/source/terrax/Editor.h b/source/terrax/Editor.h
index fb18b38d0..3f15126b8 100644
--- a/source/terrax/Editor.h
+++ b/source/terrax/Editor.h
@@ -15,6 +15,7 @@
 #include "ColorGradientEditorDialog.h"
 #include "ColorPicker.h"
 #include "SceneTreeWindow.h"
+#include "ResourceBrowser.h"
 
 #define GIZMO_TYPES() \
 	GTO(Handle)\
diff --git a/source/terrax/GroupObject.cpp b/source/terrax/GroupObject.cpp
index 5beb78e13..5fa1a1aa1 100644
--- a/source/terrax/GroupObject.cpp
+++ b/source/terrax/GroupObject.cpp
@@ -303,7 +303,7 @@ void CGroupObject::addChildObject(IXEditorObject *pObject)
 
 	ICompoundObject *pOldContainer = XTakeObject(pObject, this);
 	assert(pOldContainer == NULL);
-	//add_ref(pObject);
+	add_ref(pObject);
 	m_aObjects.push_back({pObject, m_qOrient.Conjugate() * (pObject->getPos() - m_vPos), pObject->getOrient() * m_qOrient.Conjugate()});
 	
 	g_pEditor->onObjectAdded(pObject);
@@ -323,7 +323,7 @@ void CGroupObject::removeChildObject(IXEditorObject *pObject)
 
 		g_pEditor->onObjectRemoved(pObject);
 
-		//mem_release(pObject);
+		mem_release(pObject);
 
 		if(!m_aObjects.size())
 		{
diff --git a/source/terrax/PropertyWindow.cpp b/source/terrax/PropertyWindow.cpp
index 75896547e..475f2471c 100644
--- a/source/terrax/PropertyWindow.cpp
+++ b/source/terrax/PropertyWindow.cpp
@@ -63,6 +63,7 @@ static UINT g_uEditorDlgIds[] = {
 	IDD_PROPEDIT_TEXT,
 	IDD_PROPEDIT_TEXT,
 	IDD_PROPEDIT_TEXT,
+	IDD_PROPEDIT_TEXT,
 };
 
 static_assert(ARRAYSIZE(g_uEditorDlgIds) == XPET__LAST, "g_uEditorDlgIds must match X_PROP_EDITOR_TYPE");
@@ -819,7 +820,7 @@ void CPropertyWindow::initEditor(X_PROP_EDITOR_TYPE type, const void *pData, con
 		{
 			HWND hCombo = GetDlgItem(hEditorDlg, IDC_OPE_COMBO);
 			ComboBox_ResetContent(hCombo);
-			edt_kv *pKV = (edt_kv*)pData;
+			kv_t *pKV = (kv_t*)pData;
 			while(pKV->szKey)
 			{
 				ComboBox_AddString(hCombo, pKV->szKey);
diff --git a/source/terrax/PropertyWindow.h b/source/terrax/PropertyWindow.h
index 9047f29ce..2f8db9f81 100644
--- a/source/terrax/PropertyWindow.h
+++ b/source/terrax/PropertyWindow.h
@@ -105,13 +105,7 @@ protected:
 		X_PROP_FIELD field;
 		String sValue;
 	};
-
-	struct edt_kv
-	{
-		const char *szKey;
-		const char *szValue;
-	};
-
+	
 	AssotiativeArray<AAString, prop_s> m_aPropFields;
 	X_PROP_EDITOR_TYPE m_editorActive = XPET__LAST;
 
diff --git a/source/terrax/ResourceBrowser.cpp b/source/terrax/ResourceBrowser.cpp
new file mode 100644
index 000000000..5f0be58de
--- /dev/null
+++ b/source/terrax/ResourceBrowser.cpp
@@ -0,0 +1,26 @@
+#include "ResourceBrowser.h"
+#include "terrax.h"
+
+UINT XMETHODCALLTYPE CResourceBrowser::getResourceTypeCount()
+{
+	return(1);
+}
+const char* XMETHODCALLTYPE CResourceBrowser::getResourceType(UINT uId)
+{
+	if(uId == 0)
+	{
+		return("material");
+	}
+
+	return(NULL);
+}
+
+void XMETHODCALLTYPE CResourceBrowser::browse(const char *szType, const char *szOldValue, IXEditorResourceBrowserCallback *pCallback)
+{
+	m_callback.init(pCallback);
+	g_pMaterialBrowser->browse(&m_callback);
+}
+void XMETHODCALLTYPE CResourceBrowser::cancel()
+{
+	g_pMaterialBrowser->abort();
+}
diff --git a/source/terrax/ResourceBrowser.h b/source/terrax/ResourceBrowser.h
new file mode 100644
index 000000000..04b530571
--- /dev/null
+++ b/source/terrax/ResourceBrowser.h
@@ -0,0 +1,46 @@
+#ifndef __RESOURCEBROWSER_H
+#define __RESOURCEBROWSER_H
+
+#include <xcommon/editor/IXEditorExtension.h>
+#include "MaterialBrowser.h"
+
+class CResourceMaterialBrowserCallback: public IMaterialBrowserCallback
+{
+public:
+	void init(IXEditorResourceBrowserCallback *pCallback)
+	{
+		SAFE_CALL(m_pCallback, onCancelled);
+		m_pCallback = pCallback;
+	}
+	void onSelected(const char *szName) override
+	{
+		SAFE_CALL(m_pCallback, onSelected, szName);
+		m_pCallback = NULL;
+	}
+	void onCancel() override
+	{
+		SAFE_CALL(m_pCallback, onCancelled);
+		m_pCallback = NULL;
+	}
+
+
+private:
+	IXEditorResourceBrowserCallback *m_pCallback = NULL;
+};
+
+//#############################################################################
+
+class CResourceBrowser: public IXUnknownImplementation<IXEditorResourceBrowser>
+{
+public:
+	UINT XMETHODCALLTYPE getResourceTypeCount() override;
+	const char* XMETHODCALLTYPE getResourceType(UINT uId) override;
+
+	void XMETHODCALLTYPE browse(const char *szType, const char *szOldValue, IXEditorResourceBrowserCallback *pCallback) override;
+	void XMETHODCALLTYPE cancel() override;
+
+private:
+	CResourceMaterialBrowserCallback m_callback;
+};
+
+#endif
diff --git a/source/terrax/mainWindow.cpp b/source/terrax/mainWindow.cpp
index ab6b56873..763ed59df 100644
--- a/source/terrax/mainWindow.cpp
+++ b/source/terrax/mainWindow.cpp
@@ -972,7 +972,7 @@ guid = {9D7D2E62-24C7-42B7-8D83-8448FC4604F0}
 	mem_release(pConfig);
 }
 
-static CCommandCreate* CreateObjectAtPosition(const float3 &vPos, bool bDeselectAll)
+static CCommandCreate* CreateObjectAtPosition(const float3 &vPos, const float3 &vNorm, bool bDeselectAll)
 {
 	int iSel1 = ComboBox_GetCurSel(g_hComboTypesWnd);
 	int iLen1 = ComboBox_GetLBTextLen(g_hComboTypesWnd, iSel1);
@@ -989,7 +989,7 @@ static CCommandCreate* CreateObjectAtPosition(const float3 &vPos, bool bDeselect
 		SendMessage(g_hWndMain, WM_COMMAND, MAKEWPARAM(ID_EDIT_CLEARSELECTION, 0), (LPARAM)0);
 	}
 
-	CCommandCreate *pCmd = new CCommandCreate(vPos, szTypeName, szClassName, Button_GetCheck(g_hCheckboxRandomScaleYawWnd));
+	CCommandCreate *pCmd = new CCommandCreate(vPos, vNorm, szTypeName, szClassName, Button_GetCheck(g_hCheckboxRandomScaleYawWnd));
 	g_pUndoManager->execCommand(pCmd);
 
 	return(pCmd);
@@ -1947,7 +1947,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 		case IDC_CTRL_RETURN:
 			if(g_xState.bCreateMode)
 			{
-				CreateObjectAtPosition(g_xState.vCreateOrigin, GetKeyState(VK_CONTROL) >= 0);
+				CreateObjectAtPosition(g_xState.vCreateOrigin, float3(0.0f), GetKeyState(VK_CONTROL) >= 0);
 
 				g_xState.bCreateMode = false;
 			}
@@ -3285,40 +3285,8 @@ LRESULT CALLBACK RenderWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP
 					vPos = s_aRaytracedItems[0].vPos;
 					vNorm = SMVector3Normalize(s_aRaytracedItems[0].vNorm);
 
-					IXEditorObject *pObj = CreateObjectAtPosition(vPos, GetKeyState(VK_CONTROL) >= 0)->getObject();
-					float3 vMin, vMax;
-					pObj->getBound(&vMin, &vMax);
-
-					float3 avPoints[] = {
-						float3(vMin),
-						float3(vMin.x, vMin.y, vMax.z),
-						float3(vMin.x, vMax.y, vMin.z),
-						float3(vMin.x, vMax.y, vMax.z),
-						float3(vMax.x, vMin.y, vMin.z),
-						float3(vMax.x, vMin.y, vMax.z),
-						float3(vMax.x, vMax.y, vMin.z),
-						float3(vMax),
-					};
-					//printf("%.2f, %.2f, %.2f\n", vNorm.x, vNorm.y, vNorm.z);
-
-					float fProj = FLT_MAX;
-					for(UINT i = 0, l = ARRAYSIZE(avPoints); i < l; ++i)
-					{
-						float fTmp = SMVector3Dot(avPoints[i], vNorm);
-						//printf("%.2f\n", fTmp);
-						if(fTmp < fProj)
-						{
-							fProj = fTmp;
-						}
-					}
-
-					fProj = SMVector3Dot(vPos, vNorm) - fProj;
-					//printf("%.2f, %.2f, %.2f\n%.2f, %.2f, %.2f\n%.2f, %.2f, %.2f\n%f\n\n", vPos.x, vPos.y, vPos.z, vMin.x, vMin.y, vMin.z, vMax.x, vMax.y, vMax.z, fProj);
-					if(fProj > 0)
-					{
-						pObj->setPos((float3)(vPos + vNorm * fProj));
-					}
-
+					IXEditorObject *pObj = CreateObjectAtPosition(vPos, vNorm, GetKeyState(VK_CONTROL) >= 0)->getObject();
+					
 					s_aRaytracedItems.clearFast();
 				}
 			}
@@ -4499,7 +4467,7 @@ case editor_type:
 		if(pItem->m_pObj == pObj && !fstrcmp(pItem->m_field.szKey, pField->szKey))       \
 		{                                                                                \
 			pItem->m_uUpdateRevision = g_uPropGizmoUpdateRevision;                       \
-			pItem->init();                                                               \
+			pItem->init(pField->pEditorData);                                            \
 			return;                                                                      \
 		}                                                                                \
 	}                                                                                    \
@@ -4508,7 +4476,7 @@ case editor_type:
 		pCb->m_pObj = pObj;                                                              \
 		pCb->m_field = *pField;                                                          \
 		pCb->m_uUpdateRevision = g_uPropGizmoUpdateRevision;                             \
-		pCb->init();                                                                     \
+		pCb->init(pField->pEditorData);                                                  \
 		g_aPropGizmo##gizmo##Items.push_back(pCb);                                       \
 	}                                                                                    \
 	break
@@ -4531,7 +4499,7 @@ XDECLARE_PROP_GIZMO(Radius, void XMETHODCALLTYPE onChange(float fNewRadius, IXEd
 	char tmp[16];
 	sprintf(tmp, "%f", fNewRadius);
 	m_pCommand->setKV(m_field.szKey, tmp);
-}, void init()
+}, void init(const void *pEditorData)
 {
 	m_pGizmo->setPos(m_pObj->getPos());
 	float fRadius;
@@ -4548,13 +4516,69 @@ XDECLARE_PROP_GIZMO(Handle, void XMETHODCALLTYPE moveTo(const float3 &vNewPos, I
 	char tmp[64];
 	sprintf(tmp, "%f %f %f", vTmp.x, vTmp.y, vTmp.z);
 	m_pCommand->setKV(m_field.szKey, tmp);
-}, void init()
+}, void init(const void *pEditorData)
 {
 	float3_t vec;
 	if(sscanf(m_pObj->getKV(m_field.szKey), "%f %f %f", &vec.x, &vec.y, &vec.z))
 	{
 		m_pGizmo->setPos(m_pObj->getOrient() * vec + m_pObj->getPos());
 	}
+
+	if(pEditorData)
+	{
+		kv_t *pKV = (kv_t*)pEditorData;
+		bool bLockPlane = false;
+		bool bLockAxis = false;
+		bool bLockLocal = true;
+		char axis = 0;
+		while(pKV->szKey)
+		{
+			if(!strcmp(pKV->szKey, "lock"))
+			{
+				if(!strcmp(pKV->szValue, "plane"))
+				{
+					bLockPlane = true;
+				}
+				else if(!strcmp(pKV->szValue, "axis"))
+				{
+					bLockAxis = true;
+				}
+			}
+			else if(!strcmp(pKV->szKey, "axis"))
+			{
+				axis = pKV->szValue[0];
+			}
+			else if(!strcmp(pKV->szKey, "local"))
+			{
+				if(pKV->szValue[0] != '0')
+				{
+					bLockLocal = true;
+				}
+			}
+			++pKV;
+		}
+
+		if((bLockPlane || bLockAxis) && axis)
+		{
+			float3_t vAxis(axis == 'x' ? 1.0f : 0.0, axis == 'y' ? 1.0f : 0.0, axis == 'z' ? 1.0f : 0.0);
+			if(bLockLocal)
+			{
+				vAxis = m_pObj->getOrient() * vAxis;
+			}
+			if(bLockPlane)
+			{
+				m_pGizmo->lockInPlane(vAxis);
+			}
+			else
+			{
+				m_pGizmo->lockInDir(vAxis);
+			}
+		}
+		else
+		{
+			m_pGizmo->unLock();
+		}
+	}
 });
 
 UINT g_uPropGizmoUpdateRevision = 0;
diff --git a/source/terrax/terrax.cpp b/source/terrax/terrax.cpp
index fe5e84fee..3a73567ac 100644
--- a/source/terrax/terrax.cpp
+++ b/source/terrax/terrax.cpp
@@ -827,7 +827,7 @@ int main(int argc, char **argv)
 						g_pEditor->registerResourceBrowser(pResourceBrowser);
 						mem_release(pResourceBrowser);
 						// XInitTool(pResourceBrowser, pEditable);
-			}
+					}
 				}
 			}
 
diff --git a/source/xParticles/Editable.h b/source/xParticles/Editable.h
index af162845f..bbfe486f4 100644
--- a/source/xParticles/Editable.h
+++ b/source/xParticles/Editable.h
@@ -79,6 +79,11 @@ public:
 		return(false);
 	}
 
+	const char* XMETHODCALLTYPE getClassKV(const char *szClassName, const char *szKey) override
+	{
+		return(NULL);
+	}
+
 private:
 	CEditorObject* getObjectByGUID(const XGUID &guid);
 
diff --git a/source/xUI/UIViewport.cpp b/source/xUI/UIViewport.cpp
index 989921e9b..495b9560f 100644
--- a/source/xUI/UIViewport.cpp
+++ b/source/xUI/UIViewport.cpp
@@ -46,5 +46,5 @@ void XMETHODCALLTYPE CUIViewport::setSize(float fSizeX, float fSizeY)
 {
 	BaseClass::setSize(fSizeX, fSizeY);
 
-	m_pRenderTarget->resize((UINT)fSizeX, (UINT)fSizeY);
+	m_pRenderTarget->resize(fSizeX > 1.0f ? (UINT)fSizeX : 1, fSizeY > 1.0f ? (UINT)fSizeY : 1);
 }
diff --git a/source/xUI/UIWindow.cpp b/source/xUI/UIWindow.cpp
index 4fa6863ed..a6ae35a5e 100644
--- a/source/xUI/UIWindow.cpp
+++ b/source/xUI/UIWindow.cpp
@@ -108,9 +108,22 @@ CUIWindow::CUIWindow(CXUI *pXUI, const XWINDOW_DESC *pWindowDesc, IUIWindow *pPa
 	m_pXWindowCallback = new CWindowCallback(this, m_pDesktopStack);
 	m_pXWindow = pXUI->getWindowSystem()->createWindow(pWindowDesc, m_pXWindowCallback, pXParent);
 
-	createSwapChain((UINT)pWindowDesc->iSizeX, (UINT)pWindowDesc->iSizeY);
+	float fScale = m_pXWindow->getScale();
+
+	if(fScale != 1.0f)
+	{
+		XWINDOW_DESC newDesc = *pWindowDesc;
+		newDesc.iSizeX *= fScale;
+		newDesc.iSizeY *= fScale;
+		m_pXWindow->update(&newDesc);
+		createSwapChain((UINT)newDesc.iSizeX, (UINT)newDesc.iSizeY);
+	}
+	else
+	{
+		createSwapChain((UINT)pWindowDesc->iSizeX, (UINT)pWindowDesc->iSizeY);
+	}
 
-	m_pDesktopStack->setScale(m_pXWindow->getScale());
+	m_pDesktopStack->setScale(fScale);
 
 	m_pControl = new CUIWindowControl(this, 0);
 }
diff --git a/source/xcommon/XEvents.h b/source/xcommon/XEvents.h
index fc7387097..09b2ae9f8 100644
--- a/source/xcommon/XEvents.h
+++ b/source/xcommon/XEvents.h
@@ -95,6 +95,8 @@ struct XEventLevel
 		TYPE_LOAD_END, //!< Уровень полностью загружен
 		TYPE_UNLOAD_BEGIN, //!< До начала выгрузки уровня
 		TYPE_UNLOAD_END, //!< Уровень полностью выгружен
+
+		TYPE_LOAD_WAIT_ASYNC_TASKS, //!< Ожидание завершения асинхронных задач
 	} type;
 	const char *szLevelName;
 };
diff --git a/source/xcommon/editor/IXEditable.h b/source/xcommon/editor/IXEditable.h
index 17cd062da..abcd208fa 100644
--- a/source/xcommon/editor/IXEditable.h
+++ b/source/xcommon/editor/IXEditable.h
@@ -58,7 +58,7 @@ public:
 	virtual const char* XMETHODCALLTYPE getName() = 0;
 	virtual UINT XMETHODCALLTYPE getClassCount() = 0;
 	virtual const char* XMETHODCALLTYPE getClass(UINT id) = 0;
-
+	
 	virtual void XMETHODCALLTYPE startup(IGXDevice *pDevice) = 0;
 	virtual void XMETHODCALLTYPE shutdown() = 0;
 
@@ -72,6 +72,7 @@ public:
 
 	virtual bool XMETHODCALLTYPE canUseModel(const char *szClass) = 0;
 
+	virtual const char* XMETHODCALLTYPE getClassKV(const char *szClassName, const char *szKey) = 0;
 };
 
 
diff --git a/source/xcommon/editor/IXEditorObject.h b/source/xcommon/editor/IXEditorObject.h
index b1643d970..156c7e2dd 100644
--- a/source/xcommon/editor/IXEditorObject.h
+++ b/source/xcommon/editor/IXEditorObject.h
@@ -16,6 +16,7 @@ enum X_PROP_EDITOR_TYPE
 	XPET_RADIUS,
 	XPET_COLOR,
 	XPET_HDRCOLOR,
+	XPET_SIZE,
 	//XPET_YESNO,
 
 	XPET__LAST
diff --git a/source/xcommon/resource/IXDecal.h b/source/xcommon/resource/IXDecal.h
index f46c3df89..67038ed8f 100644
--- a/source/xcommon/resource/IXDecal.h
+++ b/source/xcommon/resource/IXDecal.h
@@ -20,7 +20,7 @@ public:
 	virtual bool XMETHODCALLTYPE isEnabled() const = 0;
 	virtual void XMETHODCALLTYPE enable(bool yesNo) = 0;
 
-	virtual bool XMETHODCALLTYPE rayTest(const float3 &vStart, const float3 &vEnd, float3 *pvOut = NULL, float3 *pvNormal = NULL, bool isRayInWorldSpace = true, bool bReturnNearestPoint = false) = 0;
+	virtual bool XMETHODCALLTYPE rayTest(const float3 &vStart, const float3 &vEnd, float3 *pvOut = NULL, float3 *pvNormal = NULL) = 0;
 
 	virtual void XMETHODCALLTYPE setLayer(UINT uLayer) = 0;
 	virtual UINT XMETHODCALLTYPE getLayer() = 0;
@@ -33,6 +33,12 @@ public:
 
 	virtual void XMETHODCALLTYPE setTextureRangeV(const float2_t &vRange) = 0;
 	virtual float2_t XMETHODCALLTYPE getTextureRangeV() = 0;
+
+	virtual void XMETHODCALLTYPE setMaterial(const char *szMaterial) = 0;
+
+	virtual void XMETHODCALLTYPE setCorner(UINT uCorner, const float2_t &vCorner) = 0;
+
+	virtual void XMETHODCALLTYPE setLeakAllowed(bool yesNo) = 0;
 };
 
 #endif
diff --git a/source/xcommon/resource/IXDecalProvider.h b/source/xcommon/resource/IXDecalProvider.h
index c594d3028..384202588 100644
--- a/source/xcommon/resource/IXDecalProvider.h
+++ b/source/xcommon/resource/IXDecalProvider.h
@@ -25,7 +25,7 @@ class IXDecalProvider: public IXUnknown
 {
 public:
 	// create custom decal
-	//virtual bool XMETHODCALLTYPE newDecal(IXDecal **ppDecal) = 0;
+	virtual bool XMETHODCALLTYPE newDecal(IXDecal **ppDecal) = 0;
 	
 	// create temporal standard decal at point/normal
 	virtual void XMETHODCALLTYPE shootDecal(XDECAL_TYPE type, const float3 &vWorldPos, const float3 &vNormal, float fScale = 1.0f, const float3 *pvSAxis = NULL) = 0;
diff --git a/source/xcsg/Editable.h b/source/xcsg/Editable.h
index 8d88c2d9b..6df39e2be 100644
--- a/source/xcsg/Editable.h
+++ b/source/xcsg/Editable.h
@@ -103,6 +103,11 @@ public:
 	void onModelDestroy(CEditorModel *pModel);
 	void onModelRestored(CEditorModel *pModel);
 
+	const char* XMETHODCALLTYPE getClassKV(const char *szClassName, const char *szKey) override
+	{
+		return(NULL);
+	}
+
 	SX_ALIGNED_OP_MEM();
 
 	CVertexTool* getVertexTool();
diff --git a/source/xcsg/EditorObject.cpp b/source/xcsg/EditorObject.cpp
index e168c533c..1ff892343 100644
--- a/source/xcsg/EditorObject.cpp
+++ b/source/xcsg/EditorObject.cpp
@@ -144,7 +144,7 @@ bool XMETHODCALLTYPE CEditorObject::rayTest(const float3 &vStart, const float3 &
 		if(bReturnNearestPoint)
 		{
 			float3 vOut, vMinOut, vNormal, *pNormal = NULL;
-			if(pNormal)
+			if(pvNormal)
 			{
 				pNormal = &vNormal;
 			}
-- 
GitLab