Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for nested files itm veh #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Assets/Itm/ItmInfo.Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public virtual bool getRouteRange(out int range)
range = 0;
return false;
}

public virtual List<string> getFilesToLoad()
{
return FilesToLoad;
}
}
}

4 changes: 2 additions & 2 deletions Assets/Itm/ItmInfo.NestedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static NestedItem Load(List<string> values)
item.id = CSVReader.GetInt(values[0]);
item.version = CSVReader.GetInt(values[1].Trim('v'));
item.itemID = CSVReader.GetInt(values[2]);
item.name = CSVReader.GetString(values[3]);
item.location = CSVReader.GetString(values[4]);
item.name = CSVReader.GetQuotedString(values[3]);
item.location = CSVReader.GetQuotedString(values[4]);
return item;
}
}
Expand Down
1 change: 1 addition & 0 deletions Assets/Itm/ItmInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public static List<ItemInfo> Load(string filename)
break;
case "18":
NestedItem nested = NestedItem.Load(values);
nested.itemType = ItemType.Nested;
FilesToLoad.Add(nested.location);
itemInfo.Add(nested);
break;
Expand Down
4 changes: 4 additions & 0 deletions Assets/Shared/CsvFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ private static List<string> ParseTokens(string input)
{
i = end + 1;
}
else
{
i = input.Length;
}
}
else
{
Expand Down
7 changes: 2 additions & 5 deletions Assets/Veh/VehInfo.Nested.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ public abstract partial class VehInfo : ICsvParseable
/// </summary>
public sealed class Nested : VehInfo
{
/*public int Unknown434;
public string Unknown3D4;*/
public string Unknown5C8;
public string VehicleFileName;

public Nested()
{
Expand All @@ -18,11 +16,10 @@ public Nested()

public override void Parse(ICsvParser parser)
{
base.Parse(parser);
this.Version = int.Parse(parser.GetString().Substring(1)); // sets version...?
this.Id = parser.GetInt();
this.Name = parser.GetString();
this.Unknown5C8 = parser.GetString();
this.VehicleFileName = parser.GetString();
}
}
}
Expand Down
89 changes: 83 additions & 6 deletions InfServer/Game/Assets/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Assets;

using InfServer.Protocol;
Expand Down Expand Up @@ -75,14 +74,14 @@ public bool load(CfgInfo zoneConf, string configFilename)
//Add the game config
addAssetData(AssetFileFactory.CreateFromFile<AssetFile>(configFilename));

//Load shit up
ItemFile itms = AssetFileFactory.CreateFromFile<ItemFile>(zoneConf.level.itmFile);
//Load shit up
ItemFile itms = LoadItemFiles(zoneConf);
LioFile lios = AssetFileFactory.CreateFromFile<LioFile>(zoneConf.level.lioFile);
SkillFile rpgs = AssetFileFactory.CreateFromFile<SkillFile>(zoneConf.level.rpgFile);
VehicleFile vehs = AssetFileFactory.CreateFromFile<VehicleFile>(zoneConf.level.vehFile);
VehicleFile vehs = LoadVehicleFiles(zoneConf);
LevelFile lvl = AssetFileFactory.CreateFromFile<LevelFile>(zoneConf.level.lvlFile);

if (itms == null || lios == null || rpgs == null || vehs == null || lvl == null)
if (itms == null || lios == null || rpgs == null || vehs == null || lvl == null)
{ //Missing a core file
foreach (string missing in AssetFileFactory._missingFiles)
Log.write(TLog.Error, "Missing file: {0}", missing);
Expand Down Expand Up @@ -486,5 +485,83 @@ public List<AssetInfo> getAssetList()
{
return _assetList;
}
}

/// <summary>
/// Some vehicle files have nested vehicle files within, this will grab all of them as needed
/// </summary>
private VehicleFile LoadVehicleFiles(CfgInfo zoneConf)
{
VehicleFile mainFile = AssetFileFactory.CreateFromFile<VehicleFile>(zoneConf.level.vehFile);
if (mainFile == null) return null;

var nestedFiles = new List<VehicleFile>();

foreach(var veh in mainFile?.Data)
{
if (veh.Type == VehInfo.Types.Nested)
{
var nestedVeh = (VehInfo.Nested)veh;

if (!string.IsNullOrEmpty(nestedVeh.VehicleFileName))
{
var fileInfo = AssetFileFactory.CreateFromFile<VehicleFile>(nestedVeh.VehicleFileName);

if (fileInfo != null)
{
nestedFiles.Add(fileInfo);
addAssetData(fileInfo);
}
}
}
}

foreach (var nestedFile in nestedFiles)
{
mainFile.Data.AddRange(nestedFile.Data);
}

// remove all nested references to prevent duplicate id issues for no reason
mainFile.Data.RemoveAll(veh => veh.Type == VehInfo.Types.Nested);

return mainFile;
}

/// <summary>
/// Some item files have nested item files within, this will grab all of them as needed
/// </summary>
private ItemFile LoadItemFiles(CfgInfo zoneConf)
{
ItemFile mainFile = AssetFileFactory.CreateFromFile<ItemFile>(zoneConf.level.itmFile);
if (mainFile == null) return null;

var nestedFiles = new List<ItemFile>();

foreach (ItemInfo itemInfo in mainFile.Data)
{
foreach (var fileName in itemInfo.getFilesToLoad())
{
if (!string.IsNullOrEmpty(fileName))
{
var fileInfo = AssetFileFactory.CreateFromFile<ItemFile>(fileName);

if (fileInfo != null)
{
nestedFiles.Add(fileInfo);
addAssetData(fileInfo);
}
}
}
}

foreach (var nestedFile in nestedFiles)
{
mainFile.Data.AddRange(nestedFile.Data);
}

// remove all nested references to prevent duplicate id issues for no reason
mainFile.Data.RemoveAll(item => item.itemType == ItemInfo.ItemType.Nested);

return mainFile;
}
}
}