the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#pragma once
2using namespace std;
3
4#ifdef _LARGE_WORLDS
5// 51 maps per player (7x7 overworld, 1 nether, 1 end) * 100 players rounded up to power of 2
6#define MAXIMUM_MAP_SAVE_DATA 8192//65536
7
8// 4J Stu - These are special map slots that are used on local machines. They will never be an actual map,
9// but are placeholders for when we get updated with the correct id
10#define MAP_OVERWORLD_DEFAULT_INDEX 65535
11#define MAP_NETHER_DEFAULT_INDEX 65534
12#define MAP_END_DEFAULT_INDEX 65533
13#else
14#define MAXIMUM_MAP_SAVE_DATA 256
15
16// 4J Stu - These are special map slots that are used on local machines. They will never be an actual map,
17// but are placeholders for when we get updated with the correct id
18#define MAP_OVERWORLD_DEFAULT_INDEX 255
19#define MAP_NETHER_DEFAULT_INDEX 254
20#define MAP_END_DEFAULT_INDEX 253
21#endif
22
23// The save file version in which we added the End dimension map mappings
24#define END_DIMENSION_MAP_MAPPINGS_SAVE_VERSION 5
25
26#include "File.h"
27#include "LevelStorage.h"
28#include "PlayerIO.h"
29
30#include "ConsoleSavePath.h"
31class ConsoleSaveFile;
32
33// 4J Stu - Added this which we will write out as a file. Map id's are stored in itemInstances
34// as the auxValue, so we can have at most 65536 maps. As we currently have a limit of 80 players
35// with 3 maps each we should not hit this limit.
36typedef struct _MapDataMappings
37{
38 PlayerUID xuids[MAXIMUM_MAP_SAVE_DATA];
39 byte dimensions[MAXIMUM_MAP_SAVE_DATA/4];
40
41 _MapDataMappings();
42 int getDimension(int id);
43 void setMapping(int id, PlayerUID xuid, int dimension);
44} MapDataMappings;
45
46// Old version the only used 1 bit for dimension indexing
47typedef struct _MapDataMappings_old
48{
49 PlayerUID xuids[MAXIMUM_MAP_SAVE_DATA];
50 byte dimensions[MAXIMUM_MAP_SAVE_DATA/8];
51
52 _MapDataMappings_old();
53 int getDimension(int id);
54 void setMapping(int id, PlayerUID xuid, int dimension);
55} MapDataMappings_old;
56
57class DirectoryLevelStorage : public LevelStorage, public PlayerIO
58{
59private:
60 /* 4J Jev, Probably no need for this as theres no exceptions being thrown.
61 static const Logger *logger = Logger::getLogger("Minecraft"); */
62
63 const File dir;
64 //const File playerDir;
65 const ConsoleSavePath playerDir;
66 //const File dataDir;
67 const ConsoleSavePath dataDir;
68 const __int64 sessionId;
69 const wstring levelId;
70
71 static const wstring sc_szPlayerDir;
72 // 4J Added
73#ifdef _LARGE_WORLDS
74 class PlayerMappings
75 {
76 friend class DirectoryLevelStorage;
77 private:
78 unordered_map<__int64, short> m_mappings;
79
80 public:
81 void addMapping(int id, int centreX, int centreZ, int dimension, int scale);
82 bool getMapping(int &id, int centreX, int centreZ, int dimension, int scale);
83 void writeMappings(DataOutputStream *dos);
84 void readMappings(DataInputStream *dis);
85 };
86#if defined(__PS3__) || defined(__ORBIS__) || defined(__PSVITA__) || defined(_DURANGO)
87 unordered_map<PlayerUID, PlayerMappings, PlayerUID::Hash> m_playerMappings;
88#else
89 unordered_map<PlayerUID, PlayerMappings> m_playerMappings;
90#endif
91 byteArray m_usedMappings;
92#else
93 MapDataMappings m_mapDataMappings;
94 MapDataMappings m_saveableMapDataMappings;
95#endif
96 bool m_bHasLoadedMapDataMappings;
97
98 unordered_map<wstring, ByteArrayOutputStream *> m_cachedSaveData;
99 vector<short> m_mapFilesToDelete; // Temp list of files that couldn't be deleted immediately due to saving being disabled
100
101protected:
102 ConsoleSaveFile *m_saveFile;
103
104public:
105 virtual ConsoleSaveFile *getSaveFile() { return m_saveFile; }
106 virtual void flushSaveFile(bool autosave);
107
108public:
109 DirectoryLevelStorage(ConsoleSaveFile *saveFile, const File dir, const wstring& levelId, bool createPlayerDir);
110 ~DirectoryLevelStorage();
111
112private:
113 void initiateSession();
114
115protected:
116 File getFolder();
117
118public:
119 void checkSession();
120 virtual ChunkStorage *createChunkStorage(Dimension *dimension);
121 LevelData *prepareLevel();
122 virtual void saveLevelData(LevelData *levelData, vector<shared_ptr<Player> > *players);
123 virtual void saveLevelData(LevelData *levelData);
124 virtual void save(shared_ptr<Player> player);
125 virtual CompoundTag *load(shared_ptr<Player> player); // 4J Changed return val to bool to check if new player or loaded player
126 virtual CompoundTag *loadPlayerDataTag(PlayerUID xuid);
127 virtual void clearOldPlayerFiles(); // 4J Added
128 PlayerIO *getPlayerIO();
129 virtual void closeAll();
130 ConsoleSavePath getDataFile(const wstring& id);
131 wstring getLevelId();
132
133 // 4J Added
134 virtual int getAuxValueForMap(PlayerUID xuid, int dimension, int centreXC, int centreZC, int scale);
135 virtual void saveMapIdLookup();
136 virtual void deleteMapFilesForPlayer(shared_ptr<Player> player);
137 virtual void saveAllCachedData();
138 void resetNetherPlayerPositions(); // 4J Added
139 static wstring getPlayerDir() { return sc_szPlayerDir; }
140
141private:
142 void dontSaveMapMappingForPlayer(PlayerUID xuid);
143 void deleteMapFilesForPlayer(PlayerUID xuid);
144};