| 2263 | constexpr uint8_t StashVersion = 0; |
| 2264 | |
| 2265 | void LoadStash() |
| 2266 | { |
| 2267 | const char *filename; |
| 2268 | if (!gbIsMultiplayer) |
| 2269 | filename = "spstashitems"; |
| 2270 | else |
| 2271 | filename = "mpstashitems"; |
| 2272 | |
| 2273 | Stash = {}; |
| 2274 | |
| 2275 | LoadHelper file(OpenStashArchive(), filename); |
| 2276 | if (!file.IsValid()) |
| 2277 | return; |
| 2278 | |
| 2279 | auto version = file.NextLE<uint8_t>(); |
| 2280 | if (version > StashVersion) { |
| 2281 | EventPlrMsg(_("Stash version invalid. If you attempt to access your stash, data will be overwritten!!"), UiFlags::ColorRed); |
| 2282 | return; |
| 2283 | } |
| 2284 | |
| 2285 | Stash.gold = file.NextLE<uint32_t>(); |
| 2286 | |
| 2287 | auto pages = file.NextLE<uint32_t>(); |
| 2288 | for (unsigned i = 0; i < pages; i++) { |
| 2289 | auto page = file.NextLE<uint32_t>(); |
| 2290 | for (auto &row : Stash.stashGrids[page]) { |
| 2291 | for (uint16_t &cell : row) { |
| 2292 | cell = file.NextLE<uint16_t>(); |
| 2293 | } |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | auto itemCount = file.NextLE<uint32_t>(); |
| 2298 | if (!IsStashSizeValid(file.Size(), pages, itemCount)) { |
| 2299 | Stash = {}; |
| 2300 | EventPlrMsg(_("Stash size invalid. If you attempt to access your stash, data will be overwritten!!"), UiFlags::ColorRed); |
| 2301 | return; |
| 2302 | } |
| 2303 | Stash.stashList.resize(itemCount); |
| 2304 | for (unsigned i = 0; i < itemCount; i++) { |
| 2305 | LoadAndValidateItemData(file, Stash.stashList[i]); |
| 2306 | } |
| 2307 | |
| 2308 | Stash.SetPage(file.NextLE<uint32_t>()); |
| 2309 | } |
| 2310 | |
| 2311 | void RemoveEmptyInventory(Player &player) |
| 2312 | { |
no test coverage detected