Skip to content

Commit

Permalink
Fix errors in EOLib/EndlessClient due to refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Mar 16, 2022
1 parent e682dcf commit fd738a8
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 53 deletions.
2 changes: 1 addition & 1 deletion EOLib/Domain/Character/CharacterActions.cs
Expand Up @@ -100,7 +100,7 @@ public void PrepareCastSpell(int spellId)

public void CastSpell(int spellId, ISpellTargetable target)
{
var data = _spellFileProvider.ESFFile.Data.Single(x => x.ID == spellId);
var data = _spellFileProvider.ESFFile.Single(x => x.ID == spellId);

var action = data.Target == IO.SpellTarget.Self
? PacketAction.TargetSelf
Expand Down
8 changes: 4 additions & 4 deletions EOLib/Net/FileTransfer/FileRequestActions.cs
Expand Up @@ -72,28 +72,28 @@ public async Task GetMapForWarp(short mapID)

public async Task GetItemFileFromServer()
{
var itemFile = await _fileRequestService.RequestFile(InitFileType.Item, _playerInfoProvider.PlayerID);
var itemFile = await _fileRequestService.RequestFile<EIFRecord>(InitFileType.Item, _playerInfoProvider.PlayerID);
_pubFileSaveService.SaveFile(PubFileNameConstants.PathToEIFFile, itemFile, rewriteChecksum: false);
_pubFileRepository.EIFFile = (EIFFile)itemFile;
}

public async Task GetNPCFileFromServer()
{
var npcFile = await _fileRequestService.RequestFile(InitFileType.Npc, _playerInfoProvider.PlayerID);
var npcFile = await _fileRequestService.RequestFile<ENFRecord>(InitFileType.Npc, _playerInfoProvider.PlayerID);
_pubFileSaveService.SaveFile(PubFileNameConstants.PathToENFFile, npcFile, rewriteChecksum: false);
_pubFileRepository.ENFFile = (ENFFile)npcFile;
}

public async Task GetSpellFileFromServer()
{
var spellFile = await _fileRequestService.RequestFile(InitFileType.Spell, _playerInfoProvider.PlayerID);
var spellFile = await _fileRequestService.RequestFile<ESFRecord>(InitFileType.Spell, _playerInfoProvider.PlayerID);
_pubFileSaveService.SaveFile(PubFileNameConstants.PathToESFFile, spellFile, rewriteChecksum: false);
_pubFileRepository.ESFFile = (ESFFile)spellFile;
}

public async Task GetClassFileFromServer()
{
var classFile = await _fileRequestService.RequestFile(InitFileType.Class, _playerInfoProvider.PlayerID);
var classFile = await _fileRequestService.RequestFile<ECFRecord>(InitFileType.Class, _playerInfoProvider.PlayerID);
_pubFileSaveService.SaveFile(PubFileNameConstants.PathToECFFile, classFile, rewriteChecksum: false);
_pubFileRepository.ECFFile = (ECFFile)classFile;
}
Expand Down
35 changes: 19 additions & 16 deletions EOLib/Net/FileTransfer/FileRequestService.cs
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using AutomaticTypeMapper;
using EOLib.Domain.Protocol;
Expand All @@ -14,16 +15,16 @@ namespace EOLib.Net.FileTransfer
public class FileRequestService : IFileRequestService
{
private readonly IPacketSendService _packetSendService;
private readonly INumberEncoderService _numberEncoderService;
private readonly IMapDeserializer<IMapFile> _mapFileSerializer;
private readonly IPubFileDeserializer _pubFileDeserializer;

public FileRequestService(IPacketSendService packetSendService,
INumberEncoderService numberEncoderService,
IMapDeserializer<IMapFile> mapFileSerializer)
IMapDeserializer<IMapFile> mapFileSerializer,
IPubFileDeserializer pubFileDeserializer)
{
_packetSendService = packetSendService;
_numberEncoderService = numberEncoderService;
_mapFileSerializer = mapFileSerializer;
_pubFileDeserializer = pubFileDeserializer;
}

public async Task<IMapFile> RequestMapFile(short mapID, short playerID)
Expand All @@ -43,7 +44,8 @@ public async Task<IMapFile> RequestMapFileForWarp(short mapID)
return await GetMapFile(request, mapID, true);
}

public async Task<IPubFile> RequestFile(InitFileType fileType, short playerID)
public async Task<IPubFile<TRecord>> RequestFile<TRecord>(InitFileType fileType, short playerID)
where TRecord : class, IPubRecord, new()
{
var request = new PacketBuilder(PacketFamily.Welcome, PacketAction.Agree)
.AddChar((byte)fileType)
Expand All @@ -61,21 +63,21 @@ public async Task<IPubFile> RequestFile(InitFileType fileType, short playerID)
if (extraByte != 1)
throw new MalformedPacketException("Missing extra single byte in file transfer packet", response);

IPubFile retFile;
Func<IPubFile<TRecord>> factory;
switch (responseFileType)
{
case InitReply.ItemFile: retFile = new EIFFile(); break;
case InitReply.NpcFile: retFile = new ENFFile(); break;
case InitReply.SpellFile: retFile = new ESFFile(); break;
case InitReply.ClassFile: retFile = new ECFFile(); break;
case InitReply.ItemFile: factory = () => (IPubFile<TRecord>)new EIFFile(); break;
case InitReply.NpcFile: factory = () => (IPubFile<TRecord>)new ENFFile(); break;
case InitReply.SpellFile: factory = () => (IPubFile<TRecord>)new ESFFile(); break;
case InitReply.ClassFile: factory = () => (IPubFile<TRecord>)new ECFFile(); break;
default: throw new EmptyPacketReceivedException();
}

var responseBytes = response.ReadBytes(response.Length - response.ReadPosition)
.ToArray();
retFile.DeserializeFromByteArray(responseBytes, _numberEncoderService);
var responseBytes = response
.ReadBytes(response.Length - response.ReadPosition)
.ToArray();

return retFile;
return _pubFileDeserializer.DeserializeFromByteArray(responseBytes, factory);
}

private async Task<IMapFile> GetMapFile(IPacket request, int mapID, bool isWarp)
Expand Down Expand Up @@ -109,6 +111,7 @@ public interface IFileRequestService

Task<IMapFile> RequestMapFileForWarp(short mapID);

Task<IPubFile> RequestFile(InitFileType fileType, short playerID);
Task<IPubFile<TRecord>> RequestFile<TRecord>(InitFileType fileType, short playerID)
where TRecord : class, IPubRecord, new();
}
}
2 changes: 1 addition & 1 deletion EOLib/PacketHandlers/Items/UseItemHandler.cs
Expand Up @@ -107,7 +107,7 @@ public override bool HandlePacket(IPacket packet)
var cureCurseEvade = packet.ReadShort();
var cureCurseArmor = packet.ReadShort();

var cursedItems = _itemFileProvider.EIFFile.Data.Where(x => x.Special == ItemSpecial.Cursed).ToList();
var cursedItems = _itemFileProvider.EIFFile.Where(x => x.Special == ItemSpecial.Cursed).ToList();
if (cursedItems.Any(x => x.Graphic == renderProps.BootsGraphic && x.Type == ItemType.Boots))
renderProps = renderProps.WithBootsGraphic(0);
if (cursedItems.Any(x => x.Graphic == renderProps.ArmorGraphic && x.Type == ItemType.Armor))
Expand Down
18 changes: 9 additions & 9 deletions EndlessClient/Dialogs/SkillmasterDialog.cs
Expand Up @@ -169,7 +169,7 @@ private void _setState(SkillState newState)
continue;
int localI = i;

var spellData = OldWorld.Instance.ESF.Data[m_skills[localI].ID];
var spellData = OldWorld.Instance.ESF[m_skills[localI].ID];

ListDialogItem nextListItem = new ListDialogItem(this, ListDialogItem.ListItemStyle.Large, index++)
{
Expand Down Expand Up @@ -200,7 +200,7 @@ private void _setState(SkillState newState)
if (args.Result == XNADialogResult.Cancel) return;
bool found =
OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.Any(
_spell => OldWorld.Instance.ESF.Data[_spell.ID].Name.ToLower() == input.ResponseText.ToLower());
_spell => OldWorld.Instance.ESF[_spell.ID].Name.ToLower() == input.ResponseText.ToLower());
if (!found)
{
Expand All @@ -211,7 +211,7 @@ private void _setState(SkillState newState)
if (!m_api.ForgetSpell(
OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.Find(
_spell => OldWorld.Instance.ESF.Data[_spell.ID].Name.ToLower() == input.ResponseText.ToLower()).ID))
_spell => OldWorld.Instance.ESF[_spell.ID].Name.ToLower() == input.ResponseText.ToLower()).ID))
{
Close();
((EOGame)Game).DoShowLostConnectionDialogAndReturnToMainMenu();
Expand Down Expand Up @@ -254,11 +254,11 @@ private void _learn(Skill skill)

if (skill.ClassReq > 0 && c.Class != skill.ClassReq)
{
EOMessageBox.Show(DialogResourceID.SKILL_LEARN_WRONG_CLASS, " " + OldWorld.Instance.ECF.Data[skill.ClassReq].Name + "!", EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
EOMessageBox.Show(DialogResourceID.SKILL_LEARN_WRONG_CLASS, " " + OldWorld.Instance.ECF[skill.ClassReq].Name + "!", EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
return;
}

EOMessageBox.Show(DialogResourceID.SKILL_LEARN_CONFIRMATION, " " + OldWorld.Instance.ESF.Data[skill.ID].Name + "?", EODialogButtons.OkCancel, EOMessageBoxStyle.SmallDialogSmallHeader,
EOMessageBox.Show(DialogResourceID.SKILL_LEARN_CONFIRMATION, " " + OldWorld.Instance.ESF[skill.ID].Name + "?", EODialogButtons.OkCancel, EOMessageBoxStyle.SmallDialogSmallHeader,
(o, e) =>
{
if (e.Result != XNADialogResult.OK)
Expand Down Expand Up @@ -294,12 +294,12 @@ private void _showRequirements(Skill skill)

List<string> drawStrings = new List<string>(15)
{
OldWorld.Instance.ESF.Data[skill.ID].Name + (skill.ClassReq > 0 ? " [" + OldWorld.Instance.ECF.Data[skill.ClassReq].Name + "]" : ""),
OldWorld.Instance.ESF[skill.ID].Name + (skill.ClassReq > 0 ? " [" + OldWorld.Instance.ECF[skill.ClassReq].Name + "]" : ""),
" "
};
if (skill.SkillReq.Any(x => x != 0))
{
drawStrings.AddRange(from req in skill.SkillReq where req != 0 select OldWorld.GetString(EOResourceID.SKILLMASTER_WORD_SKILL) + ": " + OldWorld.Instance.ESF.Data[req].Name);
drawStrings.AddRange(from req in skill.SkillReq where req != 0 select OldWorld.GetString(EOResourceID.SKILLMASTER_WORD_SKILL) + ": " + OldWorld.Instance.ESF[req].Name);
drawStrings.Add(" ");
}

Expand Down Expand Up @@ -329,7 +329,7 @@ private void _showRequirements(Skill skill)

private void _showRequirementsLabel(Skill skill)
{
string full = $"{OldWorld.Instance.ESF.Data[skill.ID].Name} {skill.LevelReq} LVL, ";
string full = $"{OldWorld.Instance.ESF[skill.ID].Name} {skill.LevelReq} LVL, ";
if (skill.StrReq > 0)
full += $"{skill.StrReq} STR, ";
if (skill.IntReq > 0)
Expand All @@ -345,7 +345,7 @@ private void _showRequirementsLabel(Skill skill)
if (skill.GoldReq > 0)
full += $"{skill.GoldReq} Gold";
if (skill.ClassReq > 0)
full += $", {OldWorld.Instance.ECF.Data[skill.ClassReq].Name}";
full += $", {OldWorld.Instance.ECF[skill.ClassReq].Name}";

((EOGame)Game).Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_INFORMATION, full);
}
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/HUD/Panels/Old/OldOnlineListPanel.cs
Expand Up @@ -24,7 +24,7 @@ public class ClientOnlineEntry : OnlineEntry
public ClientOnlineEntry(string name, string title, string guild, int @class, PaperdollIconType icon)
: base(name, title, guild, @class, icon)
{
var record = OldWorld.Instance.ECF[@class] ?? new ECFRecord {Name = ""};
var record = OldWorld.Instance.ECF[@class] ?? new ECFRecord().WithNames(new[] { string.Empty });
ClassString = record.ID == 0 ? "-" : record.Name;
}

Expand Down
18 changes: 9 additions & 9 deletions EndlessClient/Old/OldCharacter.cs
Expand Up @@ -509,11 +509,11 @@ public void UpdateInventoryItem(short id, int characterAmount, byte characterWei

public void SetDisplayItemsFromRenderData(CharRenderData newRenderData)
{
EquipItem(ItemType.Boots, (short)(OldWorld.Instance.EIF.Data.SingleOrDefault(x => x.Type == ItemType.Boots && x.DollGraphic == newRenderData.boots) ?? new EIFRecord()).ID, newRenderData.boots, true);
EquipItem(ItemType.Armor, (short)(OldWorld.Instance.EIF.Data.SingleOrDefault(x => x.Type == ItemType.Armor && x.DollGraphic == newRenderData.armor) ?? new EIFRecord()).ID, newRenderData.armor, true);
EquipItem(ItemType.Hat, (short)(OldWorld.Instance.EIF.Data.SingleOrDefault(x => x.Type == ItemType.Hat && x.DollGraphic == newRenderData.hat) ?? new EIFRecord()).ID, newRenderData.hat, true);
EquipItem(ItemType.Shield, (short)(OldWorld.Instance.EIF.Data.SingleOrDefault(x => x.Type == ItemType.Shield && x.DollGraphic == newRenderData.shield) ?? new EIFRecord()).ID, newRenderData.shield, true);
EquipItem(ItemType.Weapon, (short)(OldWorld.Instance.EIF.Data.SingleOrDefault(x => x.Type == ItemType.Weapon && x.DollGraphic == newRenderData.weapon) ?? new EIFRecord()).ID, newRenderData.weapon, true);
EquipItem(ItemType.Boots, (short)(OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Boots && x.DollGraphic == newRenderData.boots) ?? new EIFRecord()).ID, newRenderData.boots, true);
EquipItem(ItemType.Armor, (short)(OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Armor && x.DollGraphic == newRenderData.armor) ?? new EIFRecord()).ID, newRenderData.armor, true);
EquipItem(ItemType.Hat, (short)(OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Hat && x.DollGraphic == newRenderData.hat) ?? new EIFRecord()).ID, newRenderData.hat, true);
EquipItem(ItemType.Shield, (short)(OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Shield && x.DollGraphic == newRenderData.shield) ?? new EIFRecord()).ID, newRenderData.shield, true);
EquipItem(ItemType.Weapon, (short)(OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Weapon && x.DollGraphic == newRenderData.weapon) ?? new EIFRecord()).ID, newRenderData.weapon, true);
}

public void UpdateStatsAfterEquip(PaperdollEquipData data)
Expand Down Expand Up @@ -543,16 +543,16 @@ public ChestKey CanOpenChest(ChestSpawnMapEntity chest)
switch (permission) //note - it would be nice to be able to send the Item IDs of the keys in the welcome packet or something
{
case ChestKey.Normal:
rec = OldWorld.Instance.EIF.Data.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "normal key");
rec = OldWorld.Instance.EIF.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "normal key");
break;
case ChestKey.Crystal:
rec = OldWorld.Instance.EIF.Data.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "crystal key");
rec = OldWorld.Instance.EIF.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "crystal key");
break;
case ChestKey.Silver:
rec = OldWorld.Instance.EIF.Data.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "silver key");
rec = OldWorld.Instance.EIF.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "silver key");
break;
case ChestKey.Wraith:
rec = OldWorld.Instance.EIF.Data.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "wraith key");
rec = OldWorld.Instance.EIF.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "wraith key");
break;
default:
return permission;
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Old/PacketAPICallbackManager.cs
Expand Up @@ -437,7 +437,7 @@ private void _statskillLearnError(SkillMasterReply reply, short id)
{
//not sure if this will ever actually be sent because client validates data before trying to learn a skill
case SkillMasterReply.ErrorWrongClass:
EOMessageBox.Show(DialogResourceID.SKILL_LEARN_WRONG_CLASS, " " + OldWorld.Instance.ECF.Data[id].Name + "!", EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
EOMessageBox.Show(DialogResourceID.SKILL_LEARN_WRONG_CLASS, " " + OldWorld.Instance.ECF[id].Name + "!", EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
break;
case SkillMasterReply.ErrorRemoveItems:
EOMessageBox.Show(DialogResourceID.SKILL_RESET_CHARACTER_CLEAR_PAPERDOLL, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
Expand Down
Expand Up @@ -72,7 +72,7 @@ private bool IsShieldBehindCharacter(ICharacterRenderProperties renderProperties

private bool IsWeaponBehindCharacter(ICharacterRenderProperties renderProperties)
{
var weaponInfo = EIFFile.Data.FirstOrDefault(
var weaponInfo = EIFFile.FirstOrDefault(
x => x.Type == ItemType.Weapon &&
x.DollGraphic == renderProperties.WeaponGraphic);

Expand All @@ -85,7 +85,7 @@ private bool IsWeaponBehindCharacter(ICharacterRenderProperties renderProperties

private HatMaskType GetHatMaskType(ICharacterRenderProperties renderProperties)
{
var hatInfo = EIFFile.Data.FirstOrDefault(
var hatInfo = EIFFile.FirstOrDefault(
x => x.Type == ItemType.Hat &&
x.DollGraphic == renderProperties.HatGraphic);

Expand Down
6 changes: 3 additions & 3 deletions EndlessClient/Rendering/OldCharacterRenderer.cs
Expand Up @@ -284,7 +284,7 @@ private void _updateDisplayDataSprites()
{
if (OldWorld.Instance.EIF != null)
{
shieldInfo = OldWorld.Instance.EIF.Data.SingleOrDefault(x => x.Type == ItemType.Shield && x.DollGraphic == Data.shield);
shieldInfo = OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Shield && x.DollGraphic == Data.shield);
if(shieldInfo != null)
shield = spriteSheet.GetShield(shieldInfo.Name == "Bag" || shieldInfo.SubType == ItemSubType.Arrows || shieldInfo.SubType == ItemSubType.Wings);
}
Expand All @@ -299,7 +299,7 @@ private void _updateDisplayDataSprites()
{
if (OldWorld.Instance.EIF != null)
{
weaponInfo = OldWorld.Instance.EIF.Data.SingleOrDefault(x => x.Type == ItemType.Weapon && x.DollGraphic == Data.weapon);
weaponInfo = OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Weapon && x.DollGraphic == Data.weapon);
if(weaponInfo != null)
weapon = spriteSheet.GetWeapon(weaponInfo.SubType == ItemSubType.Ranged);
}
Expand All @@ -321,7 +321,7 @@ private void _updateDisplayDataSprites()
lock (hatHairLock)
hat = spriteSheet.GetHat();
if (OldWorld.Instance.EIF != null)
hatInfo = OldWorld.Instance.EIF.Data.SingleOrDefault(x => x.Type == ItemType.Hat && x.DollGraphic == Data.hat);
hatInfo = OldWorld.Instance.EIF.SingleOrDefault(x => x.Type == ItemType.Hat && x.DollGraphic == Data.hat);
}
else
{
Expand Down

0 comments on commit fd738a8

Please sign in to comment.