Skip to content

Commit

Permalink
Cleanup naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
danwilkins committed Jan 15, 2024
1 parent 0f051c6 commit 44fa531
Show file tree
Hide file tree
Showing 40 changed files with 569 additions and 573 deletions.
26 changes: 13 additions & 13 deletions LanternExtractor/EQ/Archive/ArchiveBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,60 @@ public abstract class ArchiveBase
{
public string FilePath { get; }
public string FileName { get; }
protected List<ArchiveFile> _files = new List<ArchiveFile>();
protected Dictionary<string, ArchiveFile> _fileNameReference = new Dictionary<string, ArchiveFile>();
protected ILogger _logger;
protected List<ArchiveFile> Files = new List<ArchiveFile>();
protected Dictionary<string, ArchiveFile> FileNameReference = new Dictionary<string, ArchiveFile>();
protected ILogger Logger;
public bool IsWldArchive { get; set; }
public Dictionary<string, string> FilenameChanges = new Dictionary<string, string>();

protected ArchiveBase(string filePath, ILogger logger)
{
FilePath = filePath;
FileName = Path.GetFileName(filePath);
_logger = logger;
Logger = logger;
}

public abstract bool Initialize();

public ArchiveFile GetFile(string fileName)
{
return !_fileNameReference.ContainsKey(fileName) ? null : _fileNameReference[fileName];
return !FileNameReference.ContainsKey(fileName) ? null : FileNameReference[fileName];
}

public ArchiveFile GetFile(int index)
{
if (index < 0 || index >= _files.Count)
if (index < 0 || index >= Files.Count)
{
return null;
}

return _files[index];
return Files[index];
}

public ArchiveFile[] GetAllFiles()
{
return _files.ToArray();
return Files.ToArray();
}

public void WriteAllFiles(string folder)
{
foreach (var file in _files)
foreach (var file in Files)
{
FileWriter.WriteBytesToDisk(file.Bytes, folder, file.Name);
}
}

public void RenameFile(string originalName, string newName)
{
if (!_fileNameReference.ContainsKey(originalName))
if (!FileNameReference.ContainsKey(originalName))
{
return;
}

var file = _fileNameReference[originalName];
_fileNameReference.Remove(originalName);
var file = FileNameReference[originalName];
FileNameReference.Remove(originalName);
file.Name = newName;
_fileNameReference[newName] = file;
FileNameReference[newName] = file;
}
}
}
28 changes: 14 additions & 14 deletions LanternExtractor/EQ/Archive/PfsArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public PfsArchive(string filePath, ILogger logger) : base(filePath, logger)

public override bool Initialize()
{
_logger.LogInfo("PfsArchive: Started initialization of archive: " + FileName);
Logger.LogInfo("PfsArchive: Started initialization of archive: " + FileName);

if (!File.Exists(FilePath))
{
_logger.LogError("PfsArchive: File does not exist at: " + FilePath);
Logger.LogError("PfsArchive: File does not exist at: " + FilePath);
return false;
}

Expand All @@ -44,7 +44,7 @@ public override bool Initialize()

if (offset > reader.BaseStream.Length)
{
_logger.LogError("PfsArchive: Corrupted PFS length detected!");
Logger.LogError("PfsArchive: Corrupted PFS length detected!");
return false;
}

Expand All @@ -62,16 +62,16 @@ public override bool Initialize()

if (deflatedLength >= reader.BaseStream.Length)
{
_logger.LogError("PfsArchive: Corrupted file length detected!");
Logger.LogError("PfsArchive: Corrupted file length detected!");
return false;
}

byte[] compressedBytes = reader.ReadBytes((int)deflatedLength);
byte[] inflatedBytes;

if (!InflateBlock(compressedBytes, (int)inflatedLength, out inflatedBytes, _logger))
if (!InflateBlock(compressedBytes, (int)inflatedLength, out inflatedBytes, Logger))
{
_logger.LogError("PfsArchive: Error occured inflating data");
Logger.LogError("PfsArchive: Error occured inflating data");
return false;
}

Expand Down Expand Up @@ -99,42 +99,42 @@ public override bool Initialize()
continue;
}

_files.Add(new PfsFile(crc, size, offset, fileBytes));
Files.Add(new PfsFile(crc, size, offset, fileBytes));

reader.BaseStream.Position = cachedOffset;
}

// Sort files by offset so we can assign names
_files.Sort((x, y) => x.Offset.CompareTo(y.Offset));
Files.Sort((x, y) => x.Offset.CompareTo(y.Offset));

// Assign file names
for (int i = 0; i < _files.Count; ++i)
for (int i = 0; i < Files.Count; ++i)
{
switch(pfsVersion)
{
case 0x10000:
// PFS version 1 files do not appear to contain the filenames
if (_files[i] is PfsFile pfsFile)
if (Files[i] is PfsFile pfsFile)
{
pfsFile.Name = $"{pfsFile.Crc:X8}.bin";
}
break;
case 0x20000:
_files[i].Name = fileNames[i];
_fileNameReference[fileNames[i]] = _files[i];
Files[i].Name = fileNames[i];
FileNameReference[fileNames[i]] = Files[i];

if (!IsWldArchive && fileNames[i].EndsWith(LanternStrings.WldFormatExtension))
{
IsWldArchive = true;
}
break;
default:
_logger.LogError("PfsArchive: Unexpected pfs version: " + FileName);
Logger.LogError("PfsArchive: Unexpected pfs version: " + FileName);
break;
}
}

_logger.LogInfo("PfsArchive: Finished initialization of archive: " + FileName);
Logger.LogInfo("PfsArchive: Finished initialization of archive: " + FileName);
}

return true;
Expand Down
12 changes: 6 additions & 6 deletions LanternExtractor/EQ/Archive/T3dArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public T3dArchive(string filePath, ILogger logger) : base(filePath, logger)

public override bool Initialize()
{
_logger.LogInfo("T3dArchive: Started initialization of archive: " + FileName);
Logger.LogInfo("T3dArchive: Started initialization of archive: " + FileName);

if (!File.Exists(FilePath))
{
_logger.LogError("T3dArchive: File does not exist at: " + FilePath);
Logger.LogError("T3dArchive: File does not exist at: " + FilePath);
return false;
}

Expand All @@ -35,14 +35,14 @@ public override bool Initialize()
var magic = reader.ReadBytes(4);
if (!magic.SequenceEqual(T3dMagic))
{
_logger.LogError("T3dArchive: Incorrect file magic");
Logger.LogError("T3dArchive: Incorrect file magic");
return false;
}

var version = reader.ReadBytes(4);
if (!version.SequenceEqual(T3dVersion))
{
_logger.LogError("T3dArchive: Incorrect file version");
Logger.LogError("T3dArchive: Incorrect file version");
return false;
}

Expand Down Expand Up @@ -79,8 +79,8 @@ public override bool Initialize()
IsWldArchive = true;
}

_files.Add(file);
_fileNameReference[file.Name] = file;
Files.Add(file);
FileNameReference[file.Name] = file;
}
}

Expand Down
3 changes: 1 addition & 2 deletions LanternExtractor/EQ/Sound/EnvAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace LanternExtractor.EQ.Sound
{
public class EnvAudio
{
public static EnvAudio Instance => _instance;
private static readonly EnvAudio _instance = new EnvAudio();
public static EnvAudio Instance { get; } = new EnvAudio();

public EalData Data { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion LanternExtractor/EQ/Wld/DataTypes/RegionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public enum RegionType
Lava = 2,
Pvp = 3,
Zoneline = 4,
WaterBlockLOS = 5,
WaterBlockLos = 5,
FreezingWater = 6,
Slippery = 7,
Unknown = 8,
Expand Down
20 changes: 10 additions & 10 deletions LanternExtractor/EQ/Wld/DataTypes/RenderInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class RenderInfo
public float Brightness { get; set; }
public float ScaledAmbient { get; set; }
public BitmapInfoReference SimpleSpriteReference { get; set; }
public UVInfo UVInfo { get; set; }
public List<vec2> UVMap { get; set; }
public UvInfo UvInfo { get; set; }
public List<vec2> UvMap { get; set; }

public static RenderInfo Parse(BinaryReader reader, List<WldFragment> fragments)
{
Expand All @@ -29,8 +29,8 @@ public static RenderInfo Parse(BinaryReader reader, List<WldFragment> fragments)
var hasBrightness = ba.IsBitSet(1);
var hasScaledAmbient = ba.IsBitSet(2);
var hasSimpleSprite = ba.IsBitSet(3);
var hasUVInfo = ba.IsBitSet(4);
var hasUVMap = ba.IsBitSet(5);
var hasUvInfo = ba.IsBitSet(4);
var hasUvMap = ba.IsBitSet(5);
var isTwoSided = ba.IsBitSet(6);

if (hasPen)
Expand All @@ -54,23 +54,23 @@ public static RenderInfo Parse(BinaryReader reader, List<WldFragment> fragments)
renderInfo.SimpleSpriteReference = fragments[fragmentRef - 1] as BitmapInfoReference;
}

if (hasUVInfo)
if (hasUvInfo)
{
renderInfo.UVInfo = new UVInfo
renderInfo.UvInfo = new UvInfo
{
UVOrigin = new vec3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()),
UvOrigin = new vec3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()),
UAxis = new vec3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()),
VAxis = new vec3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())
};
}

if (hasUVMap)
if (hasUvMap)
{
var uvMapCount = reader.ReadInt32();
renderInfo.UVMap = new List<vec2>();
renderInfo.UvMap = new List<vec2>();
for (var i = 0; i < uvMapCount; i++)
{
renderInfo.UVMap.Add(new vec2(reader.ReadSingle(), reader.ReadSingle()));
renderInfo.UvMap.Add(new vec2(reader.ReadSingle(), reader.ReadSingle()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions LanternExtractor/EQ/Wld/DataTypes/UVInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace LanternExtractor.EQ.Wld.DataTypes
{
public class UVInfo
public class UvInfo
{
public vec3 UVOrigin { get; set; }
public vec3 UvOrigin { get; set; }
public vec3 UAxis { get; set; }
public vec3 VAxis { get; set; }
}
Expand Down
8 changes: 4 additions & 4 deletions LanternExtractor/EQ/Wld/Exporters/ActorObjExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace LanternExtractor.EQ.Wld.Exporters
{
public static class ActorObjExporter
{
public static Dictionary<Mesh, List<vec3>> _backupVertices = new Dictionary<Mesh, List<vec3>>();
public static Dictionary<Mesh, List<vec3>> BackupVertices = new Dictionary<Mesh, List<vec3>>();

public static void ExportActors(WldFile wldFile, Settings settings, ILogger logger)
{
Expand Down Expand Up @@ -254,7 +254,7 @@ private static void WriteAnimationFrame(SkeletonHierarchy skeleton, string anima
{
foreach (var mesh in skeleton.Meshes)
{
_backupVertices[mesh] = MeshExportHelper.ShiftMeshVertices(mesh, skeleton,
BackupVertices[mesh] = MeshExportHelper.ShiftMeshVertices(mesh, skeleton,
wldFile.WldType == WldType.Characters, animation, frameIndex);
meshWriter.AddFragmentData(mesh);
}
Expand All @@ -266,7 +266,7 @@ private static void WriteAnimationFrame(SkeletonHierarchy skeleton, string anima
settings.ExportZoneMeshGroups, wldFile.ZoneShortname);
meshWriter2.SetIsCharacterModel(true);
meshWriter2.AddFragmentData(skeleton.Meshes[0]);
_backupVertices[m2] = MeshExportHelper.ShiftMeshVertices(m2, skeleton,
BackupVertices[m2] = MeshExportHelper.ShiftMeshVertices(m2, skeleton,
wldFile.WldType == WldType.Characters, animation, frameIndex);
meshWriter2.AddFragmentData(m2);
meshWriter2.WriteAssetToFile(GetMeshPath(wldFile, FragmentNameCleaner.CleanName(skeleton), i + 1));
Expand All @@ -290,7 +290,7 @@ private static void WriteAnimationFrame(SkeletonHierarchy skeleton, string anima

private static void RestoreVertices()
{
foreach (var shiftedMesh in _backupVertices)
foreach (var shiftedMesh in BackupVertices)
{
shiftedMesh.Key.Vertices = shiftedMesh.Value;
}
Expand Down
24 changes: 12 additions & 12 deletions LanternExtractor/EQ/Wld/Exporters/ActorWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,38 @@ public override void AddFragmentData(WldFragment data)

if (_actorType == ActorType.Skeletal)
{
_export.Append(FragmentNameCleaner.CleanName(actor));
_export.Append(",");
_export.Append(FragmentNameCleaner.CleanName(actor.SkeletonReference.SkeletonHierarchy));
_export.AppendLine();
Export.Append(FragmentNameCleaner.CleanName(actor));
Export.Append(",");
Export.Append(FragmentNameCleaner.CleanName(actor.SkeletonReference.SkeletonHierarchy));
Export.AppendLine();
}
else if (_actorType == ActorType.Static)
{
_export.Append(FragmentNameCleaner.CleanName(actor));
_export.Append(",");
Export.Append(FragmentNameCleaner.CleanName(actor));
Export.Append(",");

if (actor.MeshReference.Mesh != null)
{
_export.Append(FragmentNameCleaner.CleanName(actor.MeshReference.Mesh));
Export.Append(FragmentNameCleaner.CleanName(actor.MeshReference.Mesh));
}
else if (actor.MeshReference.LegacyMesh != null)
{
_export.Append(FragmentNameCleaner.CleanName(actor.MeshReference.LegacyMesh));
Export.Append(FragmentNameCleaner.CleanName(actor.MeshReference.LegacyMesh));
}

_export.AppendLine();
Export.AppendLine();
}
else
{
_export.AppendLine(FragmentNameCleaner.CleanName(actor));
Export.AppendLine(FragmentNameCleaner.CleanName(actor));
}

_actorCount++;
}

public override void WriteAssetToFile(string fileName)
{
if (_export.Length == 0)
if (Export.Length == 0)
{
return;
}
Expand All @@ -70,7 +70,7 @@ public override void WriteAssetToFile(string fileName)
headerBuilder.AppendLine(LanternStrings.ExportHeaderTitle +
"Actor List");
headerBuilder.AppendLine("# Total models: " + _actorCount);
_export.Insert(0, headerBuilder.ToString());
Export.Insert(0, headerBuilder.ToString());

base.WriteAssetToFile(fileName);
}
Expand Down
Loading

0 comments on commit 44fa531

Please sign in to comment.