diff --git a/CMakeLists.txt b/CMakeLists.txt
index db8b519db..ef980c629 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -819,6 +819,7 @@ set_glob(TOOLS GLOB src/tools
fake_server.cpp
map_diff.cpp
map_extract.cpp
+ map_replace_image.cpp
map_resave.cpp
map_version.cpp
packetgen.cpp
@@ -833,7 +834,7 @@ foreach(ABS_T ${TOOLS})
if(T MATCHES "\\.cpp$")
string(REGEX REPLACE "\\.cpp$" "" TOOL "${T}")
set(EXTRA_TOOL_SRC)
- if(TOOL MATCHES "^(tileset_|dilate|map_extract$)")
+ if(TOOL MATCHES "^(tileset_|dilate|map_extract|map_replace_image$)")
list(APPEND EXTRA_TOOL_SRC ${DEP_PNG})
endif()
if(TOOL MATCHES "^config_")
diff --git a/src/engine/shared/datafile.cpp b/src/engine/shared/datafile.cpp
index d48b3f1ad..61ed34db6 100644
--- a/src/engine/shared/datafile.cpp
+++ b/src/engine/shared/datafile.cpp
@@ -356,10 +356,11 @@ void CDataFileReader::UnloadData(int Index)
int CDataFileReader::GetItemSize(int Index)
{
- if(!m_pDataFile) { return 0; }
+ if(!m_pDataFile)
+ return 0;
if(Index == m_pDataFile->m_Header.m_NumItems-1)
- return m_pDataFile->m_Header.m_ItemSize-m_pDataFile->m_Info.m_pItemOffsets[Index];
- return m_pDataFile->m_Info.m_pItemOffsets[Index+1]-m_pDataFile->m_Info.m_pItemOffsets[Index];
+ return m_pDataFile->m_Header.m_ItemSize-m_pDataFile->m_Info.m_pItemOffsets[Index] - sizeof(CDatafileItem);
+ return m_pDataFile->m_Info.m_pItemOffsets[Index+1]-m_pDataFile->m_Info.m_pItemOffsets[Index] - sizeof(CDatafileItem);
}
void *CDataFileReader::GetItem(int Index, int *pType, int *pID)
diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp
index b798acc40..ab52d59c8 100644
--- a/src/game/editor/io.cpp
+++ b/src/game/editor/io.cpp
@@ -612,7 +612,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
DataFile.GetType(MAPITEMTYPE_INFO, &Start, &Num);
for(int i = Start; i < Start + Num; i++)
{
- int ItemSize = DataFile.GetItemSize(Start) - 8;
+ int ItemSize = DataFile.GetItemSize(Start);
int ItemID;
CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)DataFile.GetItem(i, 0, &ItemID);
if(!pItem || ItemID != 0)
diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp
index 289fe51c7..b83c27eb9 100644
--- a/src/game/server/gamecontext.cpp
+++ b/src/game/server/gamecontext.cpp
@@ -2708,8 +2708,7 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
int TypeID;
int ItemID;
int *pData = (int *)Reader.GetItem(i, &TypeID, &ItemID);
- // GetItemSize returns item size including header, remove that.
- int Size = Reader.GetItemSize(i) - sizeof(int) * 2;
+ int Size = Reader.GetItemSize(i);
CMapItemInfoSettings MapInfo;
if(TypeID == MAPITEMTYPE_INFO && ItemID == 0)
{
@@ -2804,7 +2803,7 @@ void CGameContext::LoadMapSettings()
{
int ItemID;
CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)pMap->GetItem(i, 0, &ItemID);
- int ItemSize = pMap->GetItemSize(i) - 8;
+ int ItemSize = pMap->GetItemSize(i);
if(!pItem || ItemID != 0)
continue;
diff --git a/src/tools/config_retrieve.cpp b/src/tools/config_retrieve.cpp
index abdbe68aa..76c4eace0 100644
--- a/src/tools/config_retrieve.cpp
+++ b/src/tools/config_retrieve.cpp
@@ -18,7 +18,7 @@ void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
{
int ItemID;
CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)Map.GetItem(i, 0, &ItemID);
- int ItemSize = Map.GetItemSize(i) - 8;
+ int ItemSize = Map.GetItemSize(i);
if(!pItem || ItemID != 0)
continue;
diff --git a/src/tools/config_store.cpp b/src/tools/config_store.cpp
index be88e7caa..e80d06e72 100644
--- a/src/tools/config_store.cpp
+++ b/src/tools/config_store.cpp
@@ -54,8 +54,7 @@ void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
int TypeID;
int ItemID;
int *pData = (int *)Reader.GetItem(i, &TypeID, &ItemID);
- // GetItemSize returns item size including header, remove that.
- int Size = Reader.GetItemSize(i) - sizeof(int) * 2;
+ int Size = Reader.GetItemSize(i);
CMapItemInfoSettings MapInfo;
if(TypeID == MAPITEMTYPE_INFO && ItemID == 0)
{
diff --git a/src/tools/map_replace_image.cpp b/src/tools/map_replace_image.cpp
new file mode 100644
index 000000000..4361a18f4
--- /dev/null
+++ b/src/tools/map_replace_image.cpp
@@ -0,0 +1,165 @@
+/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a
+complete release at teeworlds.com. */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/*
+ Usage: map_replace_image