2023-11-12 01:59:17 +08:00
|
|
|
|
using System;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CodeWalker.GameFiles
|
|
|
|
|
{
|
|
|
|
|
public abstract class GameFile : Cacheable<GameFileCacheKey>
|
|
|
|
|
{
|
|
|
|
|
public volatile bool Loaded = false;
|
|
|
|
|
public volatile bool LoadQueued = false;
|
2023-11-12 01:59:17 +08:00
|
|
|
|
public DateTime LastLoadTime = DateTime.MinValue;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
public RpfFileEntry RpfFileEntry { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string FilePath { get; set; } //used by the project form.
|
|
|
|
|
public GameFileType Type { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GameFile(RpfFileEntry entry, GameFileType type)
|
|
|
|
|
{
|
|
|
|
|
RpfFileEntry = entry;
|
|
|
|
|
Type = type;
|
2018-01-10 11:17:30 +08:00
|
|
|
|
MemoryUsage = (entry != null) ? entry.GetFileSize() : 0;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
if (entry is RpfResourceFileEntry)
|
|
|
|
|
{
|
|
|
|
|
var resent = entry as RpfResourceFileEntry;
|
|
|
|
|
var newuse = resent.SystemSize + resent.GraphicsSize;
|
|
|
|
|
MemoryUsage = newuse;
|
|
|
|
|
}
|
|
|
|
|
else if (entry is RpfBinaryFileEntry)
|
|
|
|
|
{
|
|
|
|
|
var binent = entry as RpfBinaryFileEntry;
|
|
|
|
|
var newuse = binent.FileUncompressedSize;
|
|
|
|
|
if (newuse > MemoryUsage)
|
|
|
|
|
{
|
|
|
|
|
MemoryUsage = newuse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return (string.IsNullOrEmpty(Name)) ? JenkIndex.GetString(Key.Hash) : Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public enum GameFileType : int
|
|
|
|
|
{
|
|
|
|
|
Ydd = 0,
|
|
|
|
|
Ydr = 1,
|
|
|
|
|
Yft = 2,
|
|
|
|
|
Ymap = 3,
|
|
|
|
|
Ymf = 4,
|
|
|
|
|
Ymt = 5,
|
|
|
|
|
Ytd = 6,
|
|
|
|
|
Ytyp = 7,
|
|
|
|
|
Ybn = 8,
|
|
|
|
|
Ycd = 9,
|
|
|
|
|
Ypt = 10,
|
|
|
|
|
Ynd = 11,
|
|
|
|
|
Ynv = 12,
|
|
|
|
|
Rel = 13,
|
|
|
|
|
Ywr = 14,
|
|
|
|
|
Yvr = 15,
|
2018-01-04 01:29:35 +08:00
|
|
|
|
Gtxd = 16,
|
2019-01-06 02:04:33 +08:00
|
|
|
|
Vehicles = 17,
|
2019-01-11 11:24:50 +08:00
|
|
|
|
CarCols = 18,
|
|
|
|
|
CarModCols = 19,
|
|
|
|
|
CarVariations = 20,
|
|
|
|
|
VehicleLayouts = 21,
|
2019-11-06 01:53:20 +08:00
|
|
|
|
Peds = 22,
|
2019-11-07 00:51:35 +08:00
|
|
|
|
Ped = 23,
|
2019-11-21 21:34:27 +08:00
|
|
|
|
Yed = 24,
|
|
|
|
|
Yld = 25,
|
|
|
|
|
Yfd = 26,
|
2021-04-17 22:30:32 +08:00
|
|
|
|
Heightmap = 27,
|
2021-04-21 04:26:32 +08:00
|
|
|
|
Watermap = 28,
|
2021-06-12 06:23:15 +08:00
|
|
|
|
Mrf = 29,
|
2022-02-02 02:48:18 +08:00
|
|
|
|
DistantLights = 30,
|
2022-02-24 06:28:47 +08:00
|
|
|
|
Ypdb = 31,
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-24 21:59:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-12 01:59:17 +08:00
|
|
|
|
public struct GameFileCacheKey : IEquatable<GameFileCacheKey>
|
2018-02-24 21:59:00 +08:00
|
|
|
|
{
|
|
|
|
|
public uint Hash { get; set; }
|
|
|
|
|
public GameFileType Type { get; set; }
|
|
|
|
|
|
|
|
|
|
public GameFileCacheKey(uint hash, GameFileType type)
|
|
|
|
|
{
|
|
|
|
|
Hash = hash;
|
|
|
|
|
Type = type;
|
|
|
|
|
}
|
2023-10-28 03:31:09 +08:00
|
|
|
|
|
2023-11-12 01:59:17 +08:00
|
|
|
|
public override readonly bool Equals(object obj)
|
2023-10-28 03:31:09 +08:00
|
|
|
|
{
|
2023-11-12 01:59:17 +08:00
|
|
|
|
if (obj == null)
|
|
|
|
|
return false;
|
|
|
|
|
if (obj is not GameFileCacheKey gameFileCacheKey)
|
|
|
|
|
return false;
|
2023-10-28 03:31:09 +08:00
|
|
|
|
return gameFileCacheKey.Hash == Hash && gameFileCacheKey.Type == Type;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-12 01:59:17 +08:00
|
|
|
|
public readonly bool Equals(GameFileCacheKey obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj == null)
|
|
|
|
|
return false;
|
|
|
|
|
return obj.Hash == Hash && obj.Type == Type;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-28 03:31:09 +08:00
|
|
|
|
public static bool operator ==(GameFileCacheKey first, GameFileCacheKey second)
|
|
|
|
|
{
|
|
|
|
|
return first.Equals(second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator !=(GameFileCacheKey first, GameFileCacheKey second)
|
|
|
|
|
{
|
|
|
|
|
return !first.Equals(second);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-12 01:59:17 +08:00
|
|
|
|
public override readonly int GetHashCode()
|
2023-10-28 03:31:09 +08:00
|
|
|
|
{
|
|
|
|
|
return (int)Hash;
|
|
|
|
|
}
|
2018-02-24 21:59:00 +08:00
|
|
|
|
}
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|