2016-06-12 20:12:59 +01:00
|
|
|
|
using FFXIVClassic.Common;
|
2016-01-02 14:04:45 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-01-28 23:24:20 -05:00
|
|
|
|
using System.IO;
|
2016-01-02 14:04:45 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2016-01-20 23:18:10 -05:00
|
|
|
|
namespace FFXIVClassic_Map_Server.Actors
|
2016-01-02 14:04:45 -05:00
|
|
|
|
{
|
|
|
|
|
class StaticActors
|
|
|
|
|
{
|
2016-01-25 01:10:43 -05:00
|
|
|
|
private Dictionary<uint, Actor> mStaticActors = new Dictionary<uint, Actor>();
|
2016-01-02 14:04:45 -05:00
|
|
|
|
|
2016-01-28 23:24:20 -05:00
|
|
|
|
public StaticActors(string path)
|
2016-01-02 14:04:45 -05:00
|
|
|
|
{
|
2016-03-28 23:05:19 -04:00
|
|
|
|
byte[] data = File.ReadAllBytes(path);
|
|
|
|
|
|
|
|
|
|
if (data[0] == 's' && data[1] == 'a' && data[2] == 'n' && data[3] == 'e')
|
|
|
|
|
data = DecryptStaticActorsFile(data);
|
|
|
|
|
|
|
|
|
|
loadStaticActors(data);
|
2016-01-28 23:24:20 -05:00
|
|
|
|
}
|
2016-03-28 23:05:19 -04:00
|
|
|
|
|
|
|
|
|
private byte[] DecryptStaticActorsFile(byte[] encoded)
|
|
|
|
|
{
|
|
|
|
|
byte[] decoded = new byte[encoded.Length - 13];
|
|
|
|
|
|
|
|
|
|
MemoryStream sIn = new MemoryStream(encoded);
|
|
|
|
|
MemoryStream sOut = new MemoryStream(decoded);
|
|
|
|
|
|
|
|
|
|
BinaryReader binReader = new BinaryReader(sIn);
|
|
|
|
|
BinaryWriter binWriter = new BinaryWriter(sOut);
|
|
|
|
|
|
|
|
|
|
binReader.BaseStream.Seek(13, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
byte byteIn = binReader.ReadByte();
|
|
|
|
|
byte byteOut = (Byte)(byteIn ^ 0x73);
|
|
|
|
|
binWriter.Write((Byte)byteOut);
|
|
|
|
|
}
|
|
|
|
|
catch (EndOfStreamException e) { break; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
binReader.Close();
|
|
|
|
|
binWriter.Close();
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool loadStaticActors(byte[] data)
|
2016-01-28 23:24:20 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-03-28 23:05:19 -04:00
|
|
|
|
using (MemoryStream s = new MemoryStream(data))
|
2016-01-28 23:24:20 -05:00
|
|
|
|
{
|
|
|
|
|
using (BinaryReader binReader = new BinaryReader(s))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
while (binReader.BaseStream.Position != binReader.BaseStream.Length)
|
|
|
|
|
{
|
|
|
|
|
uint id = Utils.swapEndian(binReader.ReadUInt32()) | 0xA0F00000;
|
|
|
|
|
|
|
|
|
|
List<byte> list = new List<byte>();
|
|
|
|
|
byte readByte;
|
|
|
|
|
|
|
|
|
|
while ((readByte = binReader.ReadByte()) != 0)
|
|
|
|
|
list.Add(readByte);
|
|
|
|
|
|
|
|
|
|
string output = Encoding.UTF8.GetString(list.ToArray());
|
|
|
|
|
string actorType = output.Split('/')[1];
|
|
|
|
|
string actorName = output.Substring(1 + output.LastIndexOf("/"));
|
|
|
|
|
|
|
|
|
|
if (actorType.Equals("Command"))
|
|
|
|
|
mStaticActors.Add(id, new Command(id, actorName));
|
|
|
|
|
else if (actorType.Equals("Quest"))
|
|
|
|
|
mStaticActors.Add(id, new Quest(id, actorName));
|
|
|
|
|
//else if (actorType.Equals("Status"))
|
|
|
|
|
//mStaticActors.Add(id, new Status(id, actorName));
|
|
|
|
|
else if (actorType.Equals("Judge"))
|
|
|
|
|
mStaticActors.Add(id, new Judge(id, actorName));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(FileNotFoundException e)
|
2016-06-12 20:12:59 +01:00
|
|
|
|
{ Program.Log.Error("Could not find staticactors file."); return false; }
|
2016-01-25 01:10:43 -05:00
|
|
|
|
|
2016-06-12 20:12:59 +01:00
|
|
|
|
Program.Log.Info(String.Format("Loaded {0} static actors.", mStaticActors.Count()));
|
2016-01-25 01:10:43 -05:00
|
|
|
|
|
2016-01-28 23:24:20 -05:00
|
|
|
|
return true;
|
2016-01-02 14:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool exists(uint actorId)
|
|
|
|
|
{
|
|
|
|
|
return mStaticActors[actorId] != null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 01:10:43 -05:00
|
|
|
|
public Actor findStaticActor(string name)
|
|
|
|
|
{
|
|
|
|
|
foreach (Actor a in mStaticActors.Values)
|
|
|
|
|
{
|
|
|
|
|
if (a.actorName.Equals(name))
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-02 14:04:45 -05:00
|
|
|
|
public Actor getActor(uint actorId)
|
|
|
|
|
{
|
2016-01-28 23:24:20 -05:00
|
|
|
|
if (mStaticActors.ContainsKey(actorId))
|
|
|
|
|
return mStaticActors[actorId];
|
|
|
|
|
else
|
|
|
|
|
return null;
|
2016-01-02 14:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|