private boolean doDecrypt() throws MapLoadException { if (mapContent == null) { throw new MapLoadException("OriginalMapFile-Warning: Unable to decrypt map file: no data loaded!"); } // - already decrypted if (hasBeenDecrypted || size <= 0) { return true; } // - start of data int pos = offset; // - check if the file has enough data if ((pos + size) >= mapContent.length) { throw new MapLoadException("Error: Unable to decrypt map file: out of data!"); } // - init the key int key = (cryptKey & 0xFF); for (int i = size; i > 0; i--) { // - read one byte and uncrypt it int byt = (mapContent[pos] ^ key); // - calculate next Key key = (key << 1) ^ byt; // - write Byte mapContent[pos] = (byte) byt; pos++; } hasBeenDecrypted = true; return true; }
public MainGrid load(final ObjectInputStream ois) throws MapLoadException { try { LoadRunnable runnable = new LoadRunnable(ois); Thread t = new Thread(null, runnable, "LoadThread", LOAD_STACK_SIZE); t.start(); t.join(); if (runnable.grid != null) { return runnable.grid; } else { throw new MapLoadException("Error loading map.", runnable.exception); } } catch (Throwable t) { throw new MapLoadException(t); } }
public static void loadFrom(ObjectInputStream ois) throws MapLoadException { try { stopAndClear(); uniIns = (RescheduleTimer) ois.readObject(); } catch (Throwable t) { throw new MapLoadException(t); } }
@Override public MapLoader getMap(ReplayStartInformation replayStartInformation) throws MapLoadException { if (map.getMapId().equals(replayStartInformation.getMapId())) { return map; } throw new MapLoadException("No file found for " + replayStartInformation); }
public static MapFileHeader loadHeader(IListedMap file) throws MapLoadException { try (InputStream stream = getMapInputStream(file)) { return MapFileHeader.readFromStream(stream); } catch (IOException e) { throw new MapLoadException("Error during header request for map " + file + " exception: ", e); } }
private MapResourceInfo findAndDecryptFilePartSafe(EOriginalMapFilePartType partType) throws MapLoadException { Optional<MapResourceInfo> filePart = findAndDecryptFilePart(partType); if (filePart.isPresent()) { return filePart.get(); } else { throw new MapLoadException("No " + partType + " information available in mapfile!"); } }
@Override public IMapData getMapData() throws MapLoadException { if (data != null) { return data; } try (InputStream stream = super.getMapDataStream()) { data = new FreshMapData(); FreshMapSerializer.deserialize(data, stream); return data; } catch (IOException ex) { throw new MapLoadException(ex); } }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings, EMapStartResources startResources) throws MapLoadException { try (ObjectInputStream ois = new ObjectInputStream(super.getMapDataStream())) { MatchConstants.deserialize(ois); PlayerState[] playerStates = (PlayerState[]) ois.readObject(); GameSerializer gameSerializer = new GameSerializer(); MainGrid mainGrid = gameSerializer.load(ois); mainGrid.initWithPlayerSettings(playerSettings); RescheduleTimer.loadFrom(ois); ois.close(); return new MainGridWithUiSettings(mainGrid, playerStates); } catch (IOException | ClassNotFoundException ex) { throw new MapLoadException(ex); } }
public static JSettlersGame loadFromReplayFile(ReplayUtils.IReplayStreamProvider loadableReplayFile, INetworkConnector networkConnector, ReplayStartInformation replayStartInformation) throws MapLoadException { try { DataInputStream replayFileInputStream = new DataInputStream(loadableReplayFile.openStream()); replayStartInformation.deserialize(replayFileInputStream); MapLoader mapCreator = loadableReplayFile.getMap(replayStartInformation); return new JSettlersGame(mapCreator, replayStartInformation.getRandomSeed(), networkConnector, (byte) replayStartInformation.getPlayerId(), replayStartInformation.getReplayablePlayerSettings(), true, false, replayFileInputStream); } catch (IOException e) { throw new MapLoadException("Could not deserialize " + loadableReplayFile, e); } }
public OriginalMapLoader(IListedMap listedMap) throws MapLoadException { this.listedMap = listedMap; fileName = listedMap.getFileName(); creationDate = getCreationDateFrom(listedMap); try { mapContent = new OriginalMapFileContentReader(listedMap.getInputStream()); } catch (IOException e) { throw new MapLoadException(e); } if (!CommonConstants.DISABLE_ORIGINAL_MAPS_CHECKSUM && !mapContent.isChecksumValid()) { throw new MapLoadException("Checksum of original map (" + fileName + ") is not valid!"); } // - read all important information from file mapContent.loadMapResources(); mapContent.readBasicMapInformation(MapFileHeader.PREVIEW_IMAGE_SIZE, MapFileHeader.PREVIEW_IMAGE_SIZE); // - free the DataBuffer mapContent.freeBuffer(); isMapOK = true; }
throw new MapLoadException("The version " + fileVersion + " is unknown");
private void readMapInfo() throws MapLoadException { MapResourceInfo filePartOptional = findAndDecryptFilePartSafe(EOriginalMapFilePartType.MAP_INFO); // - file position int pos = filePartOptional.offset; // ---------------------------------- // - read mapType (single / multiplayer map?) int mapType = readBEIntFrom(pos); pos += 4; if (mapType == 1) { isSinglePlayerMap = true; } else if (mapType == 0) { isSinglePlayerMap = false; } else { throw new MapLoadException("wrong value for 'isSinglePlayerMap' " + Integer.toString(mapType) + " in mapfile!"); } // ---------------------------------- // - read Player count int playerCount = readBEIntFrom(pos); pos += 4; mapData.setPlayerCount(playerCount); // ---------------------------------- // - read start resources int startResourcesValue = readBEIntFrom(pos); this.startResources = EMapStartResources.fromMapValue(startResourcesValue); }
public static MapLoader getLoaderForListedMap(IListedMap listedMap) throws MapLoadException { if ((checkExtention(listedMap.getFileName(), MapLoader.MAP_EXTENSION_ORIGINAL)) || (checkExtention(listedMap.getFileName(), MapLoader.MAP_EXTENSION_ORIGINAL_MAP_EDITOR))) { // - original Siedler 3 Map return new OriginalMapLoader(listedMap); } else { // - Siedler 3 Remake Savegame or Map MapFileHeader header = RemakeMapLoader.loadHeader(listedMap); switch (header.getType()) { case NORMAL: return new FreshMapLoader(listedMap, header); case SAVED_SINGLE: return new SavegameLoader(listedMap, header); default: throw new MapLoadException("Unkown EMapType: " + header.getType()); } } }
private void loadMapContent(EMapStartResources startResources, PlayerSetting[] playerSettings) throws MapLoadException { try { // - the map buffer of the class may is closed and need to reopen! mapContent.reOpen(this.listedMap.getInputStream()); } catch (Exception e) { throw new MapLoadException(e); } // - load all common map information mapContent.loadMapResources(); mapContent.readBasicMapInformation(); // - read the landscape mapContent.readMapData(); // - read Stacks mapContent.readStacks(); // - read Settlers mapContent.readSettlers(); // - read the buildings mapContent.readBuildings(); // - add player resources mapContent.addStartTowerMaterialsAndSettlers(startResources, playerSettings); } }
void readSettlers() throws MapLoadException { Optional<MapResourceInfo> filePartOptional = findAndDecryptFilePart(EOriginalMapFilePartType.SETTLERS); if (filePartOptional.isPresent()) { MapResourceInfo filePart = filePartOptional.get(); // - file position int pos = filePart.offset; // - Number of buildings int settlerCount = readBEIntFrom(pos); pos += 4; // - safety check if ((settlerCount * 6 > filePart.size) || (settlerCount < 0)) { throw new MapLoadException("wrong number of settlers in map File: " + settlerCount); } // - read all Stacks for (int i = 0; i < settlerCount; i++) { int party = readByteFrom(pos++); int settlerType = readByteFrom(pos++); int posX = readBEWordFrom(pos); pos += 2; int posY = readBEWordFrom(pos); pos += 2; // ------------- // - update data mapData.setSettler(posX, posY, settlerType, party); } } }
void readStacks() throws MapLoadException { Optional<MapResourceInfo> filePartOptional = findAndDecryptFilePart(EOriginalMapFilePartType.STACKS); if (filePartOptional.isPresent()) { MapResourceInfo filePart = filePartOptional.get(); // - file position int pos = filePart.offset; // - Number of buildings int stackCount = readBEIntFrom(pos); pos += 4; // - safety check if ((stackCount * 8 > filePart.size) || (stackCount < 0)) { throw new MapLoadException("wrong number of stacks in map File: " + stackCount); } // - read all Stacks for (int i = 0; i < stackCount; i++) { int posX = readBEWordFrom(pos); pos += 2; int posY = readBEWordFrom(pos); pos += 2; int stackType = readByteFrom(pos++); int count = readByteFrom(pos++); pos += 2; // not used - maybe: padding to size of 8 (2 INTs) // ------------- // - update data mapData.setStack(posX, posY, stackType, count); } } }
throw new MapLoadException("wrong number of buildings in map File: " + buildingsCount);