forked from Windower/ResourceExtractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapParser.cs
90 lines (83 loc) · 4.11 KB
/
MapParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// <copyright file="MapParser.cs" company="Windower Team">
// Copyright © 2014-2017 Windower Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// </copyright>
namespace ResourceExtractor
{
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Web.Script.Serialization;
public static class MapParser
{
#region JSON Comments/Posterity
//There are a number of duplicate or unused map DAT's.
//These are values that have been removed from MapDats.json.
//"2": {"0": 5689}, //0 is not used in game.
//"29": {"2": 5729}, //Duplicate of map 1.
//"30": {"2": 5731}, //Duplicate of map 1.
//"44": {"2": 5748}, //Duplicate of map 1.
//"140": {"15": 5341}, //15 is not used in game.
//"142": {"0": 5343}, //Duplicate of map 1.
//"169": {"3": 5633}, //Duplicate of map 2.
//"171": {"0": 5408, //0 is a dummy map.
//"173": {"0": 5410}, //0 is not used in game.
//"174": {"0": 5411}, //0 is not used in game.
//"190": {"1001": 5430}, //Duplicate of map 1.
//"191": {"0": 5431}, //Duplicate of map 1.
//"205": {"1015": 5456, "1016": 5457 //These are maps that never made it to game, different zone name.
//"205": {"18": 5685 //18 is not used in game.
//"226": {"0": 5475}, //0 is a dummy map.
//"242": {"0": 5490}, //0 is a dummy map.
#endregion
public static void Extract()
{
Program.DisplayMessage("Extracting map data...");
var Serializer = new JavaScriptSerializer();
var DatLut = Serializer.Deserialize<IDictionary<string, IDictionary<string, ushort>>>(File.ReadAllText("MapDats.json"));
var Success = false;
try
{
foreach (var ZonePair in DatLut)
{
var Zone = ZonePair.Key;
foreach (var MapPair in ZonePair.Value)
{
var Map = MapPair.Key;
using (var Stream = File.Open(Program.GetPath(MapPair.Value), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var Image = ImageParser.Parse(Stream, true);
using (var OutFile = File.Open(string.Format(CultureInfo.InvariantCulture, "resources/maps/{0}_{1}.png", Zone, Map), FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
{
Image.Save(OutFile, ImageFormat.Png);
}
}
}
}
Success = true;
}
finally
{
Program.DisplayResult(Success);
}
}
}
}