Skip to content

Commit

Permalink
[HaCreator] Load the list of wz files dynamically
Browse files Browse the repository at this point in the history
Better support for future versions of .wz files, as the location of the images, and directories are not static.
  • Loading branch information
lastbattle committed Dec 2, 2022
1 parent b37108a commit cee77e2
Show file tree
Hide file tree
Showing 16 changed files with 839 additions and 1,079 deletions.
21 changes: 8 additions & 13 deletions HaCreator/CustomControls/MapBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public void InitializeMaps(bool special)
{
string imageName = "MapLogin" + (i == 0 ? "" : i.ToString()) + ".img";

WzObject mapLogin;
if (Initialization.isClient64())
{
mapLogin = Program.WzManager["ui_000"]?[imageName];
}
else
WzObject mapLogin = null;

List<string> uiWzFiles = Program.WzManager.GetWzFileNameListFromBase("ui");
foreach (string uiWzFileName in uiWzFiles)
{
mapLogin = Program.WzManager["ui"]?[imageName];
mapLogin = Program.WzManager[uiWzFileName]?[imageName];
if (mapLogin != null)
break;
}

if (mapLogin == null)
Expand Down Expand Up @@ -206,13 +206,8 @@ private void mapNamesBox_SelectedIndexChanged(object sender, EventArgs e)
else
{
string mapid = (selectedName).Substring(0, 9);
string mapcat;
if (Initialization.isClient64())
mapcat = mapid.Substring(0, 1);
else
mapcat = "Map" + mapid.Substring(0, 1);

WzImage mapImage = Program.WzManager.FindMapImage(mapid, mapcat);
WzImage mapImage = Program.WzManager.FindMapImage(mapid);
if (mapImage == null)
{
panel_linkWarning.Visible = false;
Expand Down
221 changes: 90 additions & 131 deletions HaCreator/GUI/Initialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ public partial class Initialization : System.Windows.Forms.Form
{
public HaEditor editor = null;
public static bool client64;
public static string mainWzDirectory;

public Initialization()
public static bool IsClient64()
{
InitializeComponent();
return client64;
}

public static bool isClient64()
/// <summary>
/// Constructor
/// </summary>
public Initialization()
{
return client64;
InitializeComponent();
}

private bool IsPathCommon(string path)
Expand All @@ -54,7 +55,7 @@ private void button_initialise_Click(object sender, EventArgs e)
ApplicationSettings.MapleVersionIndex = versionBox.SelectedIndex;
ApplicationSettings.MapleFolderIndex = pathBox.SelectedIndex;
string wzPath = pathBox.Text;
SetMainWzDirectory(wzPath + "\\Data\\");

DirectoryInfo di = new DirectoryInfo(wzPath + "\\Data");

if (wzPath == "Select MapleStory Folder")
Expand Down Expand Up @@ -134,173 +135,143 @@ private void InitializeWzFiles(string wzPath, WzMapleVersion fileVersion)

Program.WzManager = new WzFileManager(wzPath, fileVersion);

// for old maplestory with only Data.wz
if (Program.WzManager.HasDataFile) //currently always false
{
textBox2.Text = "Initializing Data.wz...";
Application.DoEvents();
UpdateUI_CurrentLoadingWzFile("Data.wz");

Program.WzManager.LoadDataWzFile("data");

Program.WzManager.ExtractStringWzMaps();
//Program.WzManager.ExtractItems();
foreach (string mobWZFile in WzFileManager.MOB_WZ_FILES)
{
}

Program.WzManager.ExtractMobFile();
Program.WzManager.ExtractNpcFile();
Program.WzManager.ExtractReactorFile();
Program.WzManager.ExtractSoundFile("sound");
Program.WzManager.ExtractSoundFile();
Program.WzManager.ExtractMapMarks();
Program.WzManager.ExtractPortals();
Program.WzManager.ExtractTileSets();
Program.WzManager.ExtractObjSets();
Program.WzManager.ExtractBackgroundSets();
}
else
else // for versions beyond v30x
{
textBox2.Text = "Initializing String.wz...";
Application.DoEvents();

if (isClient64())
Program.WzManager.LoadWzFile("string_000");
else
Program.WzManager.LoadWzFile("string");
// String.wz
List<string> stringWzFiles = Program.WzManager.GetWzFileNameListFromBase("string");
foreach (string stringWzFileName in stringWzFiles)
{
UpdateUI_CurrentLoadingWzFile(stringWzFileName);

Program.WzManager.LoadWzFile(stringWzFileName);
}
Program.WzManager.ExtractStringWzMaps();

// Mob WZ
var mobWzFiles = isClient64() ? WzFileManager.MOB_WZ_FILES_64 : WzFileManager.MOB_WZ_FILES;
List<string> mobWzFiles = Program.WzManager.GetWzFileNameListFromBase("mob");
foreach (string mobWZFile in mobWzFiles)
{
textBox2.Text = string.Format("Initializing {0}.wz...", mobWZFile);
Application.DoEvents();
if (Program.WzManager.LoadWzFile(mobWZFile.ToLower()))
{
// mob is a little special... gonna load all 3 wz first
}
}
UpdateUI_CurrentLoadingWzFile(mobWZFile);

Program.WzManager.LoadWzFile(mobWZFile);
}
Program.WzManager.ExtractMobFile();


// Load Npc
textBox2.Text = "Initializing Npc.wz...";
Application.DoEvents();
if (isClient64())
{
foreach (String npc in WzFileManager.NPC_WZ_FILES_64)
{
Program.WzManager.LoadWzFile(npc);
}
}
else
List<string> npcWzFiles = Program.WzManager.GetWzFileNameListFromBase("npc");
foreach (string npc in npcWzFiles)
{
Program.WzManager.LoadWzFile("npc");
UpdateUI_CurrentLoadingWzFile(npc);

Program.WzManager.LoadWzFile(npc);
}
Program.WzManager.ExtractNpcFile();

// Load reactor
textBox2.Text = "Initializing Reactor.wz...";
Application.DoEvents();
if (isClient64())
{
Program.WzManager.LoadWzFile("reactor_000");
Program.WzManager.ExtractReactorFile64();
}
else
List<string> reactorWzFiles = Program.WzManager.GetWzFileNameListFromBase("reactor");
foreach (string reactor in reactorWzFiles)
{
Program.WzManager.LoadWzFile("reactor");
Program.WzManager.ExtractReactorFile();
UpdateUI_CurrentLoadingWzFile(reactor);

Program.WzManager.LoadWzFile(reactor);
}
Program.WzManager.ExtractReactorFile();

// Load sound
var soundWzFiles = isClient64() ? WzFileManager.SOUND_WZ_FILES_64 : WzFileManager.SOUND_WZ_FILES;
foreach (string soundWzFile in soundWzFiles)
List<string> soundWzFiles = Program.WzManager.GetWzFileNameListFromBase("sound");
foreach (string soundWzFileName in soundWzFiles)
{
textBox2.Text = string.Format("Initializing {0}.wz...", soundWzFile);
Application.DoEvents();
Program.WzManager.LoadWzFile(soundWzFile.ToLower());
Program.WzManager.ExtractSoundFile(soundWzFile.ToLower());
UpdateUI_CurrentLoadingWzFile(soundWzFileName);

Program.WzManager.LoadWzFile(soundWzFileName);
Program.WzManager.ExtractSoundFile();
}


textBox2.Text = "Initializing Map.wz...";
Application.DoEvents();
if (isClient64())
// Load maps
List<string> mapWzFiles = Program.WzManager.GetWzFileNameListFromBase("map");
foreach (string mapWzFileName in mapWzFiles)
{
UpdateUI_CurrentLoadingWzFile(mapWzFileName);

Program.WzManager.LoadWzFile(mapWzFileName);
}
for (int i_map = 0; i_map <= 9; i_map++)
{
foreach (String map in WzFileManager.MAP_WZ_FILES_64)
List<string> map_iWzFiles = Program.WzManager.GetWzFileNameListFromBase("map\\map\\map" + i_map);
foreach (string map_iWzFileName in map_iWzFiles)
{
Program.WzManager.LoadWzFile(map);
UpdateUI_CurrentLoadingWzFile(map_iWzFileName);

Program.WzManager.LoadWzFile(map_iWzFileName);
}
Program.WzManager.LoadWzFile("tile_000");
Program.WzManager.LoadWzFile("map0_000");
Program.WzManager.LoadWzFile("map1_000");
Program.WzManager.LoadWzFile("map2_000");
Program.WzManager.LoadWzFile("map3_000");
Program.WzManager.LoadWzFile("map4_000");
Program.WzManager.LoadWzFile("map5_000");
Program.WzManager.LoadWzFile("map6_000");
Program.WzManager.LoadWzFile("map9_000");
Program.WzManager.LoadWzFile("map9_001");
Program.WzManager.ExtractMapMarks64();
Program.WzManager.ExtractPortals64();
Program.WzManager.ExtractTileSets64();
}
else
List<string> tileWzFiles = Program.WzManager.GetWzFileNameListFromBase("map\\tile"); // this doesnt exist before 64-bit client, and is kept in Map.wz
foreach (string tileWzFileNames in tileWzFiles)
{
Program.WzManager.LoadWzFile("map");
Program.WzManager.ExtractMapMarks();
Program.WzManager.ExtractPortals();
Program.WzManager.ExtractTileSets();
}

UpdateUI_CurrentLoadingWzFile(tileWzFileNames);

// Load Obj
if (isClient64())
{
foreach (String obj in WzFileManager.OBJ_WZ_FILES_64)
{
Program.WzManager.LoadWzFile(obj);
}
Program.WzManager.LoadWzFile(tileWzFileNames);
}
Program.WzManager.ExtractObjSets();
List<string> objWzFiles = Program.WzManager.GetWzFileNameListFromBase("map\\obj"); // this doesnt exist before 64-bit client, and is kept in Map.wz
foreach (string objWzFileName in objWzFiles)
{
UpdateUI_CurrentLoadingWzFile(objWzFileName);

// Load Back
if (isClient64())
Program.WzManager.LoadWzFile(objWzFileName);
}
List<string> backWzFiles = Program.WzManager.GetWzFileNameListFromBase("map\\back"); // this doesnt exist before 64-bit client, and is kept in Map.wz
foreach (string backWzFileName in backWzFiles)
{
foreach (String back in WzFileManager.BACK_WZ_FILES_64)
{
Program.WzManager.LoadWzFile(back);
}
UpdateUI_CurrentLoadingWzFile(backWzFileName);

Program.WzManager.LoadWzFile(backWzFileName);
}
Program.WzManager.ExtractMapMarks();
Program.WzManager.ExtractPortals();
Program.WzManager.ExtractTileSets();
Program.WzManager.ExtractObjSets();
Program.WzManager.ExtractBackgroundSets();

var mapWzFiles = isClient64() ? WzFileManager.MAP_WZ_FILES_64 : WzFileManager.MAP_WZ_FILES;
foreach (string mapwzFile in mapWzFiles)
{
if (Program.WzManager.LoadWzFile(mapwzFile.ToLower()))
{
textBox2.Text = string.Format("Initializing {0}.wz...", mapwzFile);
Application.DoEvents();
Program.WzManager.ExtractBackgroundSets();
Program.WzManager.ExtractObjSets();
}
}

textBox2.Text = "Initializing UI.wz...";
Application.DoEvents();
if (isClient64())
// UI.wz
List<string> uiWzFiles = Program.WzManager.GetWzFileNameListFromBase("ui");
foreach (string uiWzFileNames in uiWzFiles)
{
foreach (String ui in WzFileManager.UI_WZ_FILES_64)
{
Program.WzManager.LoadWzFile(ui);
}
}
else
{
Program.WzManager.LoadWzFile("ui");
UpdateUI_CurrentLoadingWzFile(uiWzFileNames);

Program.WzManager.LoadWzFile(uiWzFileNames);
}
}
}

private void UpdateUI_CurrentLoadingWzFile(string fileName)
{
textBox2.Text = string.Format("Initializing {0}.wz...", fileName);
Application.DoEvents();
}

/// <summary>
/// On loading initialization.cs
/// </summary>
Expand Down Expand Up @@ -387,9 +358,7 @@ private void debugButton_Click(object sender, EventArgs e)

foreach (string mapid in Program.InfoManager.Maps.Keys)
{
string mapcat = "Map" + mapid.Substring(0, 1);

WzImage mapImage = Program.WzManager.FindMapImage(mapid, mapcat);
WzImage mapImage = Program.WzManager.FindMapImage(mapid);
if (mapImage == null)
{
continue;
Expand Down Expand Up @@ -441,7 +410,7 @@ private void debugButton_Click(object sender, EventArgs e)
}
catch (Exception exp)
{
string error = string.Format("Exception occured loading {0}{1}{2}{3}{4}", mapcat, Environment.NewLine, mapImage.ToString() /*overrides, see WzImage.ToString*/, Environment.NewLine, exp.ToString());
string error = string.Format("Exception occured loading {1}{2}{3}{4}", Environment.NewLine, mapImage.ToString() /*overrides, see WzImage.ToString*/, Environment.NewLine, exp.ToString());
ErrorLogger.Log(ErrorLevel.Crash, error);
}
finally
Expand Down Expand Up @@ -485,15 +454,5 @@ public static void SetClientSelection64(bool isClient64)
client64 = isClient64;
ApplicationSettings.WzClientSelectionIndex = isClient64 ? 1 : 0;
}

public static string GetMainWzDirectory()
{
return mainWzDirectory;
}

public static void SetMainWzDirectory(string directory)
{
mainWzDirectory = directory;
}
}
}
Loading

0 comments on commit cee77e2

Please sign in to comment.