public static async Task AnalyseAsync(string path) { foreach (var file in Directory.GetFiles(path, "*.raw", SearchOption.AllDirectories)) { var editor = await TerrainEditor.OpenAsync(file); foreach (var chunk in editor.Source.Chunks) { { var data = chunk.ShortMap.Data; Console.WriteLine($"MAX = {data.Max()}\tMIN = {data.Min()}\tLEN = {data.Length}"); } { var data = chunk.UnknownByteArray1; Console.WriteLine($"MAX = {data.Max()}\tMIN = {data.Min()}\tLEN = {data.Length}\n"); } { foreach (var array in chunk.UnknownShortArray) { var data = array; Console.WriteLine($"MAX = {data.Max()}\tMIN = {data.Min()}\tLEN = {data.Length}"); } Console.WriteLine(); } Console.ReadKey(); } } }
public static async Task InsertAsync(string path) { LuzFile luz; await using (var stream = File.OpenRead(path)) { using var reader = new BitReader(stream); luz = new LuzFile(); luz.Deserialize(reader); } var worlds = Interface.Database["ZoneTable"]; if (luz.WorldId == 0) { var attributes = File.GetAttributes(path); attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(path, attributes); luz.WorldId = (uint)worlds.ClaimKey(100); await using var stream = File.Create(path); using var writer = new BitWriter(stream); luz.Serialize(writer); } var entry = worlds.FirstOrDefault(w => w.Key == luz.WorldId); if (entry != default) { if (entry.Value <string>("zoneName").StartsWith("ZoneTable")) { worlds.Remove(entry); } else { return; } } var rootPath = Path.GetDirectoryName(path); var terrain = await TerrainEditor.OpenAsync(Path.Combine(rootPath, luz.TerrainFileName)); entry = worlds.Create(luz.WorldId); var root = new Uri(Path.Combine(Interface.Configuration.Output, "./maps/")); var map = new Uri(path); var relative = root.MakeRelativeUri(map).ToString(); Console.WriteLine($"Inserting: [{luz.WorldId}] {Path.GetFileName(path)} into {relative}"); var _ = new ZoneTableTable(entry) { zoneName = relative, ghostdistance = 5000, zoneID = (int)luz.WorldId, scriptID = -1, ghostdistance_min = 150, heightInChunks = terrain.Source.Height, widthInChunks = terrain.Source.Weight, localize = false, petsAllowed = true, mountsAllowed = true }; }
public static async Task UpgradeZone(string path) { var origin = path; var id = Interface.Database["ZoneTable"].ClaimKey(100); path = Path.Combine(Interface.Configuration.Output, "maps", path); LuzFile luz; var root = Path.GetDirectoryName(path); await using (var stream = File.OpenRead(path)) { using var reader = new BitReader(stream); luz = new LuzFile(); luz.Deserialize(reader); } foreach (var scene in luz.Scenes) { LvlFile lvl; var scenePath = Path.Combine(root, scene.FileName); await using (var stream = File.OpenRead(scenePath)) { using var reader = new BitReader(stream); lvl = new LvlFile(); lvl.Deserialize(reader); } if (lvl.IsOld) { Console.WriteLine($"Converting {scene.SceneName} to new."); lvl.ConvertToNew(); await using (var stream = File.Create(scenePath)) { using var writer = new BitWriter(stream); lvl.Serialize(writer); } } var spawnPoint = lvl.LevelObjects?.Templates?.FirstOrDefault(l => l.Lot == 4945); if (spawnPoint == null) { continue; } luz.SpawnPoint = spawnPoint.Position; luz.SpawnRotation = spawnPoint.Rotation; } if (luz.Version < 0x26) { Console.WriteLine($"Converting {Path.GetFileName(path)} to new."); luz.Version = 0x26; luz.WorldId = (uint)id; await using (var stream = File.Create(path)) { using var writer = new BitWriter(stream); luz.Serialize(writer); } } Console.WriteLine("Updating terrain."); var terrainPath = Path.Combine(root, luz.TerrainFileName); var terrain = await TerrainEditor.OpenAsync(terrainPath); foreach (var chunk in terrain.Source.Chunks) { for (var i = 0; i < chunk.ColorRelatedArray.Length; i++) { chunk.ColorRelatedArray[i] = 1; } } await terrain.SaveAsync(terrainPath); Console.WriteLine($"Adding [{id}] {Path.GetFileName(path)} to database."); var zones = Interface.Database["ZoneTable"]; var row = zones.Create(id); var _ = new ZoneTableTable(row) { zoneName = origin, zoneID = (int)luz.WorldId, ghostdistance = 500, scriptID = -1, locStatus = 0 }; }