Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
implemented basic parser,
Browse files Browse the repository at this point in the history
fixed #196
  • Loading branch information
chucktheripper committed Feb 15, 2016
1 parent 19cc9cd commit 3666ed1
Show file tree
Hide file tree
Showing 20 changed files with 380 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -227,4 +227,7 @@ _Pvt_Extensions
.paket/paket.exe

# FAKE - F# Make
.fake/
.fake/

# Custom
*.dat
34 changes: 34 additions & 0 deletions CodeMaid.config
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SteveCadwallader.CodeMaid.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<userSettings>
<SteveCadwallader.CodeMaid.Properties.Settings>
<setting name="Reorganizing_MemberTypeConstructors" serializeAs="String">
<value>Constructors||2||Instantiation</value>
</setting>
<setting name="Reorganizing_RegionsInsertNewRegions" serializeAs="String">
<value>True</value>
</setting>
<setting name="Reorganizing_RegionsRemoveExistingRegions" serializeAs="String">
<value>True</value>
</setting>
<setting name="Reorganizing_MemberTypeFields" serializeAs="String">
<value>Fields||1||Members</value>
</setting>
<setting name="Reorganizing_RunAtStartOfCleanup" serializeAs="String">
<value>True</value>
</setting>
<setting name="Cleaning_UpdateEndRegionDirectives" serializeAs="String">
<value>False</value>
</setting>
<setting name="Cleaning_InsertBlankLinePaddingBeforePropertiesSingleLine"
serializeAs="String">
<value>True</value>
</setting>
</SteveCadwallader.CodeMaid.Properties.Settings>
</userSettings>
</configuration>
84 changes: 84 additions & 0 deletions OpenNos.Core/Import/DatParser.cs
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;

namespace OpenNos.Core
{
public static class DatParser
{
#region Members

private const string datEntryOffset = "END";

#endregion

#region Methods

public static IEnumerable<TDTO> Parse<TDTO>(string filePath)
{
IList<TDTO> parsedResults = new List<TDTO>();

string[] plainEntries = Regex.Split(File.ReadAllText(filePath).Replace("\r", "\n"), datEntryOffset);

//load all qualified import properties
IEnumerable<PropertyInfo> importProperties = typeof(TDTO).GetProperties()
.Where(prop => prop.IsDefined(typeof(ImportAttribute), false));

//iterate thru all dat entries
foreach (string plainEntry in plainEntries)
{
var parsedEntry = Activator.CreateInstance<TDTO>();

//iterate thru all qualified import properties
foreach (PropertyInfo importProperty in importProperties)
{
ImportAttribute attribute = importProperty.GetCustomAttribute<ImportAttribute>();
var value = ParseLineIndex(plainEntry, attribute);

if(value != null && value != "-1")
{
importProperty.SetValue(parsedEntry, Convert.ChangeType(value, importProperty.PropertyType));
}
}

parsedResults.Add(parsedEntry);
}

return parsedResults;
}

private static string ParseIndex(string line, ImportAttribute attribute)
{
return Regex.Split(line, @"\s")[attribute.Index];
}

private static string ParseLine(string entry, ImportAttribute attribute)
{
return Regex.Match(entry, $"^.*{attribute.Line}.*$", RegexOptions.Multiline).Value;
}

private static string ParseLineIndex(string entry, ImportAttribute attribute)
{
string line = ParseLine(entry, attribute);

//check if line has been found
if (!String.IsNullOrEmpty(line))
{
return ParseIndex(line, attribute);
}
else
{
Console.WriteLine($"{attribute} not found.");
Debug.WriteLine($"{attribute} not found in {entry}");
}

return null;
}

#endregion
}
}
30 changes: 30 additions & 0 deletions OpenNos.Core/Import/ImportAttribute.cs
@@ -0,0 +1,30 @@
using System;

namespace OpenNos.Core
{
public class ImportAttribute : Attribute
{
#region Instantiation

public ImportAttribute(string line, int index)
{
Line = line;
Index = index;
}

#endregion

#region Properties

public int Index { get; set; }

public string Line { get; set; }

public override string ToString()
{
return $"Line: {Line}, Index: {Index}";
}

#endregion
}
}
2 changes: 2 additions & 0 deletions OpenNos.Core/OpenNos.Core.csproj
Expand Up @@ -50,6 +50,8 @@
<ItemGroup>
<Compile Include="Application.cs" />
<Compile Include="Collections\ThreadSafeSortedList.cs" />
<Compile Include="Import\DatParser.cs" />
<Compile Include="Import\ImportAttribute.cs" />
<Compile Include="LoginEncryption.cs" />
<Compile Include="Networking\Communication\ScsServices\Client\IScsServiceClient.cs" />
<Compile Include="Networking\Communication\ScsServices\Client\ScsServiceClient.cs" />
Expand Down
18 changes: 9 additions & 9 deletions OpenNos.DAL.EF.MySQL/DB/OpenNos.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions OpenNos.DAL.EF.MySQL/DB/OpenNos.edmx.sql
Expand Up @@ -44,9 +44,9 @@
-- -----------------------------------------------------------
-- Entity Designer DDL Script for MySQL Server 4.1 and higher
-- -----------------------------------------------------------
-- Date Created: 02/11/2016 00:32:27
-- Date Created: 02/13/2016 11:05:54

-- Generated from EDMX file: C:\Users\ERWAN\Desktop\OpenNos GIT\OpenNos.DAL.EF.MySQL\DB\OpenNos.edmx
-- Generated from EDMX file: C:\Users\Alex\Source\Repos\OpenNos\OpenNos.DAL.EF.MySQL\DB\OpenNos.edmx
-- Target version: 3.0.0.0

-- --------------------------------------------------
Expand Down
18 changes: 14 additions & 4 deletions OpenNos.Data/ItemDTO.cs
@@ -1,23 +1,29 @@
namespace OpenNos.Data
using OpenNos.Core;

namespace OpenNos.Data
{
public class ItemDTO
{
#region Properties

public byte Blocked { get; set; }

public byte Classe { get; set; }
public byte Class { get; set; }

public bool Colored { get; set; }

public short Concentrate { get; set; }

[Import("DATA", 7)]
public short CriticalLuckRate { get; set; }

[Import("DATA", 6)]
public short CriticalRate { get; set; }

[Import("DATA", 5)]
public short DamageMaximum { get; set; }

[Import("DATA", 4)]
public short DamageMinimum { get; set; }

public short DarkElement { get; set; }
Expand All @@ -36,6 +42,7 @@ public class ItemDTO

public short ElementRate { get; set; }

[Import("INDEX", 5)]
public byte EquipmentSlot { get; set; }

public short FairyMaximumLevel { get; set; }
Expand All @@ -50,14 +57,15 @@ public class ItemDTO

public string HpRegeneration { get; set; }

public bool isConsumable { get; set; }
public bool IsConsumable { get; set; }

public byte isWareHouse { get; set; }
public byte IsWareHouse { get; set; }

public byte ItemType { get; set; }

public short LevelJobMinimum { get; set; }

[Import("DATA", 2)]
public short LevelMinimum { get; set; }

public short LightElement { get; set; }
Expand Down Expand Up @@ -86,6 +94,7 @@ public class ItemDTO

public string Name { get; set; }

[Import("VNUM", 3)]
public long Price { get; set; }

public short PvpDefence { get; set; }
Expand All @@ -106,6 +115,7 @@ public class ItemDTO

public byte Type { get; set; }

[Import("VNUM", 2)]
public short VNum { get; set; }

public short WaterElement { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion OpenNos.Data/OpenNos.Data.csproj
Expand Up @@ -54,7 +54,7 @@
<Compile Include="Enums\DeleteResult.cs" />
<Compile Include="Enums\SaveResult.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="User.cs" />
<Compile Include="UserDTO.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenNos.Core\OpenNos.Core.csproj">
Expand Down
2 changes: 1 addition & 1 deletion OpenNos.Data/User.cs → OpenNos.Data/UserDTO.cs
Expand Up @@ -15,7 +15,7 @@

namespace OpenNos.Data
{
public class User
public class UserDTO
{
#region Properties

Expand Down
6 changes: 3 additions & 3 deletions OpenNos.GameObject/Networking/ServerManager.cs
Expand Up @@ -63,7 +63,7 @@ public static void Initialize()
PvpDefence = item.PvpDefence,
Price = item.Price,
Name = item.Name,
Classe = item.Classe,
Class = item.Class,
Blocked = item.Blocked,
Colored = item.Colored,
CriticalLuckRate = item.CriticalLuckRate,
Expand All @@ -86,8 +86,8 @@ public static void Initialize()
HitRate = item.HitRate,
Hp = item.Hp,
HpRegeneration = item.HpRegeneration,
isConsumable = item.isConsumable,
isWareHouse = item.isWareHouse,
IsConsumable = item.IsConsumable,
IsWareHouse = item.IsWareHouse,
ItemType = item.ItemType,
LevelJobMinimum = item.LevelJobMinimum,
ReputationMinimum = item.ReputationMinimum,
Expand Down
2 changes: 1 addition & 1 deletion OpenNos.Handler/LoginPacketHandler.cs
Expand Up @@ -58,7 +58,7 @@ public string BuildServersPacket(int session)
[Packet("NoS0575")]
public void VerifyLogin(string packet)
{
User user = PacketFactory.Deserialize<User>(packet);
UserDTO user = PacketFactory.Deserialize<UserDTO>(packet);
//closed
bool flag = true;
if (flag)
Expand Down
4 changes: 2 additions & 2 deletions OpenNos.Handler/WorldPacketHandler.cs
Expand Up @@ -2305,7 +2305,7 @@ public void UseItem(string packet)
Inventory inv = Session.Character.InventoryList.LoadBySlotAndType(slot, type);
InventoryItem item = inv.InventoryItem;
Item itemInfo = ServerManager.GetItem(item.ItemVNum);
if (itemInfo.isConsumable)
if (itemInfo.IsConsumable)
item.Amount--;
if (itemInfo.Morph != 0)
{
Expand Down Expand Up @@ -2370,7 +2370,7 @@ public void Wear(string packet)
double def = (((TimeSpan)(DateTime.Now - new DateTime(2010, 1, 1, 0, 0, 0))).TotalSeconds) - (Session.Character.LastSp);
if (!(iteminfo.EquipmentSlot == (short)EquipmentType.Sp && def < 30))
{
if ((iteminfo.ItemType == (byte)ItemType.Weapon || iteminfo.ItemType == (byte)ItemType.Armor || iteminfo.ItemType == (byte)ItemType.Fashion || iteminfo.ItemType == (byte)ItemType.Jewelery || iteminfo.ItemType == (byte)ItemType.Specialist) && iteminfo.LevelMinimum <= Session.Character.Level && ((iteminfo.Classe >> Session.Character.Class) & 1) == 1)
if ((iteminfo.ItemType == (byte)ItemType.Weapon || iteminfo.ItemType == (byte)ItemType.Armor || iteminfo.ItemType == (byte)ItemType.Fashion || iteminfo.ItemType == (byte)ItemType.Jewelery || iteminfo.ItemType == (byte)ItemType.Specialist) && iteminfo.LevelMinimum <= Session.Character.Level && ((iteminfo.Class >> Session.Character.Class) & 1) == 1)
{
if (!(Session.Character.UseSp && iteminfo.EquipmentSlot == (short)EquipmentType.Fairy && iteminfo.Element != ServerManager.GetItem(Session.Character.InventoryList.LoadBySlotAndType((short)EquipmentType.Sp, (short)InventoryType.Equipment).InventoryItem.ItemVNum).Element))
{
Expand Down
6 changes: 6 additions & 0 deletions OpenNos.Import.Console/App.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
29 changes: 29 additions & 0 deletions OpenNos.Import.Console/ImportFactory.cs
@@ -0,0 +1,29 @@
using OpenNos.Core;
using OpenNos.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenNos.Import.Console
{
public class ImportFactory
{
private string _folder;

public ImportFactory(string folder)
{
_folder = folder;
}

public void ImportItems()
{
string file = $"{_folder}\\Item.dat";
IEnumerable<ItemDTO> items = DatParser.Parse<ItemDTO>(file);

int i = 0;
}
}
}

0 comments on commit 3666ed1

Please sign in to comment.