ddnet/src/engine/shared/map.h
Robert Müller 7acf2c1573 Add functions for reading/writing strings from/to datafile
Simplify the usage of datafile reader and writer by adding utility functions to read and write zero-terminated UTF-8 strings.

Improve validation of string data read from datafiles. It is ensure that string data is null-terminated, has no internal NUL-characters and is valid UTF-8.

Fix loading of external sounds in the editor. The wrong path variable was being used, so the sound files would not be loaded from correct folder.

Add tests for new datafile reader/writer functions.
2023-10-03 16:07:15 +02:00

47 lines
1.3 KiB
C++

/* (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. */
#ifndef ENGINE_SHARED_MAP_H
#define ENGINE_SHARED_MAP_H
#include <base/system.h>
#include "datafile.h"
#include <engine/map.h>
class CMap : public IEngineMap
{
CDataFileReader m_DataFile;
public:
CMap();
CDataFileReader *GetReader() { return &m_DataFile; }
int GetDataSize(int Index) const override;
void *GetData(int Index) override;
void *GetDataSwapped(int Index) override;
const char *GetDataString(int Index) override;
void UnloadData(int Index) override;
int NumData() const override;
int GetItemSize(int Index) override;
void *GetItem(int Index, int *pType = nullptr, int *pID = nullptr) override;
void GetType(int Type, int *pStart, int *pNum) override;
int FindItemIndex(int Type, int ID) override;
void *FindItem(int Type, int ID) override;
int NumItems() const override;
bool Load(const char *pMapName) override;
void Unload() override;
bool IsLoaded() const override;
IOHANDLE File() const override;
SHA256_DIGEST Sha256() const override;
unsigned Crc() const override;
int MapSize() const override;
static void ExtractTiles(class CTile *pDest, size_t DestSize, const class CTile *pSrc, size_t SrcSize);
};
#endif