public static UOResource getLegacyResource(TextureImageInfo tileartTextureInfo) { //FAST search if (legacyTextures.ContainsKey(tileartTextureInfo.textureIDX)) { //TODO: references++ return(legacyTextures[tileartTextureInfo.textureIDX]); } //Get the string from stringDictionary if (tileartTextureInfo.textureIDX >= stringDictionary.count) { UOConsole.Fatal("String {0} not found in dictionary.", tileartTextureInfo.textureIDX); return(null); } string tga = stringDictionary.values[tileartTextureInfo.textureIDX]; //Replace extension int start = (tga.LastIndexOf("\\") == -1) ? 0 : (tga.LastIndexOf("\\") + 1); int end = tga.IndexOf("_"); if (end == -1) { UOConsole.Fatal("no descr in: {0} .. trying with extension", tga); tga = tga.Replace(".tga", ""); end = tga.Length; } //UOConsole.Fatal("{0} {1} {2}", tga, start, end); string toHash = tga.Substring(start, end - start); while (toHash.Length < 8) //Filling the missing zeros { toHash = "0" + toHash; } toHash += ".dds"; toHash = toHash.ToLower(); toHash = "build/tileartlegacy/" + toHash; //Get the file from Texture.uop ulong tehHash = HashDictionary.HashFileName(toHash); if (!uopHashes.legacyTexturesHashes.ContainsKey(tehHash)) { UOConsole.Fatal("string {0} not found in legacyTextureHashes - tga: {1}", toHash, tga); return(null); } uopMapping_t map = uopHashes.legacyTexturesHashes[tehHash]; MythicPackage tex = new MythicPackage(fileDirectory + "LegacyTexture.uop"); byte[] raw = tex.Blocks[map.block].Files[map.file].Unpack(tex.FileInfo.FullName); UOResource res = new UOResource(raw, ShaderTypes.Sprite, true); legacyTextures.Add(tileartTextureInfo.textureIDX, res); return(res); }
//Land tiles does not have tileart TEXTURES section.. we need to extract them from terrain definition public static TextureImageInfo getLandtileTextureID(uint legacyLandtileID) { //Fast search if (landtiles.ContainsKey(legacyLandtileID)) { return(landtiles[legacyLandtileID]); } //Translate the legacy ID to the new pair newID-subtype using legacyterrainMap if (!legacyTerrainMap.ContainsKey(legacyLandtileID)) { UOConsole.Fatal("Cannot find {0} in legacyTerrainMap", legacyLandtileID); return(null); } legacyTerrainMap_t landtileID = legacyTerrainMap[legacyLandtileID]; //Get the file from terrain definition using the newID ulong hash = HashDictionary.HashFileName(string.Format("build/terraindefinition/{0}.bin", landtileID.newID)); if (!uopHashes.terrainHashes.ContainsKey(hash)) { UOConsole.Fatal("Cannot find {0} in terrainHashes", landtileID.newID); return(null); } uopMapping_t pos = uopHashes.terrainHashes[hash]; MythicPackage _uop = new MythicPackage(fileDirectory + "TerrainDefinition.uop"); byte[] raw = _uop.Blocks[pos.block].Files[pos.file].Unpack(_uop.FileInfo.FullName); //Read the loaded terrainDefinition file. TerrainDefinition td; using (MemoryStream ms = new MemoryStream(raw)) { using (BinaryReader r = new BinaryReader(ms)) { td = TerrainDefinition.readTerrainDefinition(r); } } if (td == null) { UOConsole.Fatal("Cannot read terrainDefinition file"); return(null); } landtiles[legacyLandtileID] = td.textures.texturesArray[landtileID.newSubtype]; //Returns the texture according to subtype return(td.textures.texturesArray[landtileID.newSubtype]); }
//Get a tileart given a graphic id public static Tileart getTileart(uint graphic) { //Fast search if (tileartCollection.ContainsKey(graphic)) { return(tileartCollection[graphic]); } //Get the file from tileart using the id ulong hash = HashDictionary.HashFileName(string.Format("build/tileart/{0:D8}.bin", graphic)); if (!uopHashes.tileartHashes.ContainsKey(hash)) { UOConsole.Fatal("Cannot find {0} in tileartHashes", graphic); return(null); } uopMapping_t pos = uopHashes.tileartHashes[hash]; MythicPackage _uop = new MythicPackage(fileDirectory + "tileart.uop"); byte[] raw = _uop.Blocks[pos.block].Files[pos.file].Unpack(_uop.FileInfo.FullName); //Read the loaded tileart file. Tileart t; using (MemoryStream ms = new MemoryStream(raw)) { using (BinaryReader r = new BinaryReader(ms)) { t = Tileart.readTileart(r); } } if (t == null) { UOConsole.Fatal("Cannot read tileart file"); return(t); } tileartCollection[graphic] = t; //Returns the texture according to subtype return(t); }