Post Pacific  

Go Back   Post Pacific > Lineage 2 > Lineage 2 Client Modifications ONLY!
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 28.10.2005, 18:38   #3
Sivera
Архивный участник
 
Join Date: Oct 2005
Posts: 11
Default


Program code for convert decoded skillname-*.dat to txt file or something else if you prefere C# ( converted from PHP with some changes )

If you know .Net, you can use it as example for all decoded *.dat files.

Code:
using System;
using System.IO;
using System.Text;

namespace EncDecLib.Dump
{
	public class DumpSkillName
	{
		public DumpSkillName()
		{
		}

		private static uint m__StartByte = 4;
		private static string Delimiter = "\t";
		
		public static string[] DumpFile(string m_FilePath, string m_Delimiter)
		{
			if(m_Delimiter != null)
				Delimiter = m_Delimiter;
			uint m_DataLength = Re(m_FilePath, 4, 0);
			if(m__StartByte != 0)
			{
				string[] data = new string[m_DataLength];
				for(int i=0; i < m_DataLength ; i++)
					data[i] = GetString(m_FilePath, m__StartByte);
				return data;
			}
			else return new string[]{"Unable to read decrypted file."};
		}
		
		private static string GetString(string m_FileName, uint m_StartByte)
		{
			using(FileStream fs = File.OpenRead(m_FileName))
			{
				string m_SkillName = null;
				string m_SkillDescr = null;
	
				string m_SkillID = Re(m_FileName, 4, m_StartByte).ToString();
				m_StartByte += 4;
				string m_SkillLevel = Re(m_FileName, 4, m_StartByte).ToString(); 
				m_StartByte += 4;
				
				uint m_SkillNameLength = GetStringLength(m_FileName, 1, m_StartByte);
				m_StartByte++;
				
				byte[] tmp = new byte[m_SkillNameLength];
				fs.Position = m_StartByte;
				fs.Read(tmp,0,tmp.Length);
				m_SkillName = Encoding.ASCII.GetString(tmp);

				m_StartByte += m_SkillNameLength;
				uint m_SkillDescrLength = GetStringLength(m_FileName, 1, m_StartByte);
				tmp = new byte[m_SkillDescrLength];
				
				byte[] check = new byte[1];
				fs.Position = m_StartByte + 1;
				fs.Read(check,0,check.Length);
				
				uint add_counter = 0;
				
				else if(check[0] >= 1 || check[0] <= 9)
				{
					m_StartByte += 2;
					fs.Position = m_StartByte;
					byte[] unknown = new byte[1024];
					fs.Read(unknown,0,unknown.Length);
					
					while(unknown[add_counter] != 0)
					{
						add_counter++;
					}
					add_counter++;
				}
				else
					m_StartByte += 1;
				
				if(add_counter != 0)
					tmp = new byte[add_counter];
				fs.Position = m_StartByte;
				fs.Read(tmp, 0, tmp.Length);

				m_SkillDescr = Encoding.ASCII.GetString(tmp);
				m_StartByte += (uint)tmp.Length;
				m__StartByte = m_StartByte;

				int m_length = m_SkillName.Length;
				m_SkillName = m_SkillName.Substring(0,m_length--);
				m_length = m_SkillDescr.Length;
				m_SkillDescr = m_SkillDescr.Substring(0,m_length--);

				return String.Format("{0}{4}{1}{4}{2}{4}{3}", m_SkillID, m_SkillLevel, m_SkillName, m_SkillDescr, Delimiter); //You may chanche output format as you wish
			}			
		}
				
		private static uint GetStringLength(string m_FileName, uint m_BytesToRead, uint m_StartReadingByte)
		{
			if(File.Exists(m_FileName))
			{
				FileStream m_FileStream = File.OpenRead(m_FileName);
				BinaryReader m_BinaryReader = new BinaryReader(m_FileStream);
				byte[] m_BinaryData = m_BinaryReader.ReadBytes(Convert.ToInt32(m_FileStream.Length));
				byte[] m_Bytes = new byte[m_BytesToRead];
				uint m_Tmp = m_StartReadingByte;
				uint m_MaxToRead = m_StartReadingByte + m_BytesToRead;
				int _c = 0;
				for(uint i = m_StartReadingByte; i < m_MaxToRead; i++)
				{
					m_Bytes[_c] = m_BinaryData[m_Tmp];
					m_Tmp++;
					_c++;
				}
				 
				return Convert.ToUInt32(Dump.HexEncoding.ToString(m_Bytes), 16);
			}
			else
				return 0;		
		}

		private static uint Re(string m_FileName, uint m_BytesToRead, uint m_StartReadingByte)
		{
			if(File.Exists(m_FileName))
			{
				FileStream m_FileStream = File.OpenRead(m_FileName);
				BinaryReader m_BinaryReader = new BinaryReader(m_FileStream);
				byte[] m_BinaryData = m_BinaryReader.ReadBytes(Convert.ToInt32(m_FileStream.Length));
				byte[] m_Bytes = new byte[m_BytesToRead];
				uint m_Tmp = m_BytesToRead + m_StartReadingByte - 1;
				uint m_MaxToRead = m_StartReadingByte + m_BytesToRead;
				int _c = 0;
				for(uint i = m_StartReadingByte; i < m_MaxToRead; i++)
				{
					m_Bytes[_c] = m_BinaryData[m_Tmp];
					m_Tmp--;
					_c++;
				}
				
				return Convert.ToUInt32(Dump.HexEncoding.ToString(m_Bytes), 16);
			}
			else
				return 0;
		}	
	}
}
And class that's used for hex calculations

Code:
using System;
using System.Text;

namespace EncDecLib.Dump
{
	public class HexEncoding
	{
		public HexEncoding()
		{
		}
		public static int GetByteCount(string hexString)
		{
			int numHexChars = 0;
			char c;
			for (int i=0; i<hexString.Length; i++)
			{
				c = hexString[i];
				if (IsHexDigit(c))
					numHexChars++;
			}
			if (numHexChars % 2 != 0)
			{
				numHexChars--;
			}
			return numHexChars / 2; 
		}
		public static byte[] GetBytes(string hexString, out int discarded)
		{
			discarded = 0;
			string newString = "";
			char c;
			for (int i=0; i<hexString.Length; i++)
			{
				c = hexString[i];
				if (IsHexDigit(c))
					newString += c;
				else
					discarded++;
			}
			if (newString.Length % 2 != 0)
			{
				discarded++;
				newString = newString.Substring(0, newString.Length-1);
			}

			int byteLength = newString.Length / 2;
			byte[] bytes = new byte[byteLength];
			string hex;
			int j = 0;
			for (int i=0; i<bytes.Length; i++)
			{
				hex = new String(new Char[] {newString[j], newString[j+1]});
				bytes[i] = HexToByte(hex);
				j = j+2;
			}
			return bytes;
		}
		
		public static string ToString(byte[] bytes)
		{
			string hexString = "";
			for (int i=0; i<bytes.Length; i++)
			{
				hexString += bytes[i].ToString("X2");
			}
			return hexString;
		}

		public static bool InHexFormat(string hexString)
		{
			bool hexFormat = true;

			foreach (char digit in hexString)
			{
				if (!IsHexDigit(digit))
				{
					hexFormat = false;
					break;
				}
			}
			return hexFormat;
		}
		
		public static bool IsHexDigit(Char c)
		{
			int numChar;
			int numA = Convert.ToInt32('A');
			int num1 = Convert.ToInt32('0');
			c = Char.ToUpper(c);
			numChar = Convert.ToInt32(c);
			if (numChar >= numA && numChar < (numA + 6))
				return true;
			if (numChar >= num1 && numChar < (num1 + 10))
				return true;
			return false;
		}
		
		private static byte HexToByte(string hex)
		{
			if (hex.Length > 2 || hex.Length <= 0)
				throw new ArgumentException("hex must be 1 or 2 characters in length");
			byte newByte = byte.Parse(hex, System.Globalization.NumberStyles.HexNumber);
			return newByte;
		}
	}
}
Using formatting (what you'll empliment) you'll be able to get array from strings like this (it's easy way to make file you want):

Code:
skill_begin	skill_id = 3	skill_level = 1	name = [Power Strike]	desc = [Gathers power for a fierce strike. Usable when a sword or blunt weapon is equipped. Power 25. Over-hit available.]	skill_end
skill_begin	skill_id = 3	skill_level = 2	name = [Power Strike]	desc = [Gathers power for a fierce strike. Usable when a sword or blunt weapon is equipped. Power 27. Over-hit available.]	skill_end
skill_begin	skill_id = 3	skill_level = 3	name = [Power Strike]	desc = [Gathers power for a fierce strike. Usable when a sword or blunt weapon is equipped. Power 30. Over-hit available.]	skill_end
skill_begin	skill_id = 3	skill_level = 4	name = [Power Strike]	desc = [Gathers power for a fierce strike. Usable when a sword or blunt weapon is equipped. Power 39. Over-hit available.]	skill_end
etc
etc
etc...
But..
Can anyone explane how l2encdec works?
What algorithm is used?

Thx for any information.
Sivera is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 22:56.