public static void writeMob(ActorSpawnPacket actorSpawnPacket, uint sourceId, int currentZone, string outputFolderName) { if (File.Exists(Path.Combine(outputFolderName, $"{sourceId}.mobdef.xml"))) { return; } if ((actorSpawnPacket.displayFlags & 0x01) > 0) { Console.WriteLine($" -> Mob is active, not writing"); return; } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineOnAttributes = false; using (XmlWriter writer = XmlWriter.Create(Path.Combine(outputFolderName, $"{sourceId}.mobdef.xml"), settings)) { writer.WriteStartDocument(); writer.WriteStartElement("Mob"); writer.WriteElementString("ID", sourceId.ToString()); writer.WriteElementString("ZoneId", currentZone.ToString()); writer.WriteElementString("Type", actorSpawnPacket.type.ToString()); writer.WriteElementString("NameId", actorSpawnPacket.nameId.ToString()); writer.WriteElementString("BnpcBaseId", actorSpawnPacket.bnpcBaseId.ToString()); writer.WriteElementString("ModelId", actorSpawnPacket.model.ToString()); writer.WriteElementString("FateId", actorSpawnPacket.fateId.ToString()); writer.WriteElementString("ClassJob", actorSpawnPacket.classJob.ToString()); writer.WriteElementString("DisplayFlags", actorSpawnPacket.displayFlags.ToString()); writer.WriteElementString("Level", actorSpawnPacket.level.ToString()); writer.WriteElementString("MaxHP", actorSpawnPacket.hPMax.ToString()); writer.WriteElementString("MaxMP", actorSpawnPacket.mPMax.ToString()); writer.WriteElementString("MaxTP", actorSpawnPacket.tPMax.ToString()); writer.WriteElementString("Status", actorSpawnPacket.status.ToString()); writer.WriteElementString("OwnerID", actorSpawnPacket.ownerId.ToString()); writer.WriteElementString("Pos_0_0", actorSpawnPacket.posx.ToString()); writer.WriteElementString("Pos_0_1", actorSpawnPacket.posy.ToString()); writer.WriteElementString("Pos_0_2", actorSpawnPacket.posz.ToString()); writer.WriteElementString("Rotation", actorSpawnPacket.rotation.ToString()); writer.WriteElementString("MobType", actorSpawnPacket.mobType.ToString()); writer.WriteElementString("ModelMainWeapon", actorSpawnPacket.mainWeaponModel.ToString()); writer.WriteElementString("ModelSubWeapon", actorSpawnPacket.secWeaponModel.ToString()); writer.WriteElementString("Look", BitConverter.ToString(actorSpawnPacket.lookdata).Replace("-", " ")); writer.WriteElementString("Models", BitConverter.ToString(actorSpawnPacket.models).Replace("-", " ")); writer.WriteStartElement("EffectPackets"); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); Console.WriteLine($" -> wrote {sourceId}.mobdef.xml"); } }
public static void writeChar(ActorSpawnPacket actorSpawnPacket, uint sourceId, int currentZone, string outputFolderName) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineOnAttributes = false; using (XmlWriter writer = XmlWriter.Create(Path.Combine(outputFolderName, $"{sourceId}.chardef.xml"), settings)) { writer.WriteStartDocument(); writer.WriteStartElement("Char"); writer.WriteElementString("ID", sourceId.ToString()); writer.WriteElementString("ZoneId", currentZone.ToString()); writer.WriteElementString("Type", actorSpawnPacket.type.ToString()); writer.WriteElementString("Name", actorSpawnPacket.name); writer.WriteElementString("Title", actorSpawnPacket.title.ToString()); writer.WriteElementString("Icon", actorSpawnPacket.statusIcon.ToString()); writer.WriteElementString("BnpcBaseId", actorSpawnPacket.bnpcBaseId.ToString()); writer.WriteElementString("ModelId", actorSpawnPacket.model.ToString()); writer.WriteElementString("ClassJob", actorSpawnPacket.classJob.ToString()); writer.WriteElementString("CurrentMount", actorSpawnPacket.currentMount.ToString()); writer.WriteElementString("MountBody", actorSpawnPacket.mountBody.ToString()); writer.WriteElementString("MountColor", actorSpawnPacket.mountColor.ToString()); writer.WriteElementString("MountFeet", actorSpawnPacket.mountFeet.ToString()); writer.WriteElementString("MountHead", actorSpawnPacket.mountHead.ToString()); writer.WriteElementString("DisplayFlags", actorSpawnPacket.displayFlags.ToString()); writer.WriteElementString("Level", actorSpawnPacket.level.ToString()); writer.WriteElementString("MaxHP", actorSpawnPacket.hPMax.ToString()); writer.WriteElementString("MaxMP", actorSpawnPacket.mPMax.ToString()); writer.WriteElementString("MaxTP", actorSpawnPacket.tPMax.ToString()); writer.WriteElementString("Status", actorSpawnPacket.status.ToString()); writer.WriteElementString("OwnerID", actorSpawnPacket.ownerId.ToString()); writer.WriteElementString("TargetID", actorSpawnPacket.targetId.ToString()); writer.WriteElementString("Pos_0_0", actorSpawnPacket.posx.ToString()); writer.WriteElementString("Pos_0_1", actorSpawnPacket.posy.ToString()); writer.WriteElementString("Pos_0_2", actorSpawnPacket.posz.ToString()); writer.WriteElementString("Rotation", actorSpawnPacket.rotation.ToString()); writer.WriteElementString("MobType", actorSpawnPacket.mobType.ToString()); writer.WriteElementString("ModelMainWeapon", actorSpawnPacket.mainWeaponModel.ToString()); writer.WriteElementString("ModelSubWeapon", actorSpawnPacket.secWeaponModel.ToString()); writer.WriteElementString("ModelCraftTool", actorSpawnPacket.craftToolModel.ToString()); writer.WriteElementString("Look", BitConverter.ToString(actorSpawnPacket.lookdata).Replace("-", " ")); writer.WriteElementString("Models", BitConverter.ToString(actorSpawnPacket.models).Replace("-", " ")); writer.WriteEndElement(); writer.WriteEndDocument(); Console.WriteLine($" -> wrote {sourceId}.chardef.xml"); } }
public static void addCSVEntry(ActorSpawnPacket actorSpawnPacket, uint sourceId, int currentZone, string outputFileName) { if ((actorSpawnPacket.displayFlags & 0x01) > 0) { Console.WriteLine($" -> Mob is active, not writing"); return; } StringBuilder csv; if (!File.Exists(outputFileName)) { csv = new StringBuilder(); csv.AppendLine("SourceID,BnpcBaseID,BnpcNameID,ModelID,FateID,Level,MaxHP,MaxMP,MaxTP,Territory,PosX,PosY,PosZ,Rotation,InfoString"); File.WriteAllText(outputFileName, csv.ToString()); } csv = new StringBuilder(File.ReadAllText(outputFileName)); csv.AppendLine($"{sourceId},{actorSpawnPacket.bnpcBaseId},{actorSpawnPacket.nameId},{actorSpawnPacket.model},{actorSpawnPacket.fateId},{actorSpawnPacket.level},{actorSpawnPacket.hPMax},{actorSpawnPacket.mPMax},{actorSpawnPacket.tPMax},{currentZone}," + $"\"{actorSpawnPacket.posx}\",\"{actorSpawnPacket.posy}\",\"{actorSpawnPacket.posz}\",\"{actorSpawnPacket.rotation}\",\"{Globals.exdreader.GetBnpcName(actorSpawnPacket.nameId)} - {Globals.exdreader.GetTerritoryName(currentZone)}\""); File.WriteAllText(outputFileName, csv.ToString()); Console.WriteLine($" -> wrote {outputFileName}"); }
private void HandleRecv(SubPacket subpacket) { //Console.WriteLine("\n-> " + subpacket.gameMessage.opcode.ToString("X")); switch (subpacket.gameMessage.opcode) { /* SERVER OPCODES */ case 0x111: /* ACTOR_SPAWN */ if (Globals.memory) { currentZone = Memory.getZoneId(); } Console.WriteLine("\n-> ACTOR_SPAWN"); ActorSpawnPacket actorSpawnPacket = new ActorSpawnPacket(subpacket.data, currentZone, subpacket.header.sourceId); switch (actorSpawnPacket.type) { case 1: if (actorSpawnPacket.spawnIndex == 0) { Console.WriteLine($" -> OWN CHARACTER: {actorSpawnPacket.name} Zone:{currentZone} EntryLength:{subpacket.data.Length}"); //System.Threading.Thread.Sleep(100); /* replaced with init_zone * currentZone = Memory.ReadZoneId(); * Console.WriteLine($" -> New Zone: {currentZone} - {exdreader.GetTerritoryName(currentZone)}"); */ } else { Console.WriteLine($" -> CHARACTER: {actorSpawnPacket.name} Zone:{currentZone} EntryLength:{subpacket.data.Length}"); if (Globals.xmlOutput & Globals.writeChars & currentZone != 0 & !actorSpawnPacket.invalidPacket) { ActorWriter.writeChar(actorSpawnPacket, subpacket.header.sourceId, currentZone, outputFolderName); } else { if (Globals.writeChars) { Console.WriteLine($" -> currentZone==0(change your zone once to fix) or invalid packet"); } } } break; case 0: Console.WriteLine($" -> EMPTY: {actorSpawnPacket.name} Zone:{currentZone} EntryLength:{subpacket.data.Length}"); break; default: Console.WriteLine($" -> NPC({actorSpawnPacket.nameId}): {Globals.exdreader.GetBnpcName(actorSpawnPacket.nameId)} Zone:{currentZone} EntryLength:{subpacket.data.Length}"); if (actorSpawnPacket.fateId != 0) { Console.WriteLine($" -> FATE NPC: {Globals.exdreader.GetFateName(actorSpawnPacket.fateId)}({actorSpawnPacket.fateId})"); } if (Globals.UI) { Globals.mapviewform.BeginInvoke((MethodInvoker) delegate() { Globals.mapviewform.addActor(actorSpawnPacket); Globals.mapviewform.invalidateMap(); }); } //actorSpawnPacket.debugPrintUnknown(); //File.WriteAllBytes(Path.Combine(outputFolderName, $"{subpacket.header.sourceId}.dat"), subpacket.data); if (Globals.xmlOutput & currentZone != 0 & !actorSpawnPacket.invalidPacket) { ActorWriter.writeMob(actorSpawnPacket, subpacket.header.sourceId, currentZone, outputFolderName); } else { if (Globals.xmlOutput) { Console.WriteLine($" -> currentZone==0(change your zone once to fix) or invalid packet"); } } if (Globals.csvOutput & currentZone != 0 & !actorSpawnPacket.invalidPacket) { try { ActorWriter.addCSVEntry(actorSpawnPacket, subpacket.header.sourceId, currentZone, Path.Combine("output", outputKey + ".csv")); }catch (Exception exc) { Console.WriteLine($" -> " + exc); } } else { if (Globals.csvOutput) { Console.WriteLine($" -> currentZone==0(change your zone once to fix) or invalid packet"); } } if (Globals.DB & currentZone != 0 & !actorSpawnPacket.invalidPacket) { using (MySqlCommand command = new MySqlCommand()) { command.Connection = dbconnection; command.CommandText = "INSERT INTO dbbattlenpc (Id, ZoneId, Type, NameId, SizeId, ModelId, ClassJob, DisplayFlags1, DisplayFlags2, Level, Pos_0_0, Pos_0_1, Pos_0_2, Rotation, MobType, Behaviour, ModelMainWeapon, ModelSubWeapon, Look, Models) VALUES (?Id, ?ZoneId, ?Type, ?NameId, ?SizeId, ?ModelId, ?ClassJob, ?DisplayFlags1, ?DisplayFlags2, ?Level, ?Pos_0_0, ?Pos_0_1, ?Pos_0_2, ?Rotation, ?MobType, ?Behaviour, ?ModelMainWeapon, ?ModelSubWeapon, ?Look, ?Models);"; List <MySqlParameter> parameters = new List <MySqlParameter>(); parameters.Add(new MySqlParameter("?Id", MySqlDbType.Int32, 11)); parameters[0].Value = subpacket.header.sourceId; parameters.Add(new MySqlParameter("?ZoneId", MySqlDbType.Int32, 10)); parameters[1].Value = currentZone; parameters.Add(new MySqlParameter("?Type", MySqlDbType.Int32, 11)); parameters[2].Value = actorSpawnPacket.type; parameters.Add(new MySqlParameter("?NameId", MySqlDbType.Int32, 10)); parameters[3].Value = actorSpawnPacket.nameId; parameters.Add(new MySqlParameter("?BnpcBaseId", MySqlDbType.Int32, 10)); parameters[4].Value = actorSpawnPacket.bnpcBaseId; parameters.Add(new MySqlParameter("?ModelId", MySqlDbType.Int32, 10)); parameters[5].Value = actorSpawnPacket.model; parameters.Add(new MySqlParameter("?ClassJob", MySqlDbType.Int32, 3)); parameters[parameters.Count - 1].Value = actorSpawnPacket.classJob; parameters.Add(new MySqlParameter("?DisplayFlags", MySqlDbType.Int32, 3)); parameters[parameters.Count - 1].Value = actorSpawnPacket.displayFlags; parameters.Add(new MySqlParameter("?Level", MySqlDbType.Int32, 3)); parameters[parameters.Count - 1].Value = actorSpawnPacket.level; parameters.Add(new MySqlParameter("?Pos_0_0", MySqlDbType.Float)); parameters[parameters.Count - 1].Value = actorSpawnPacket.posx; parameters.Add(new MySqlParameter("?Pos_0_1", MySqlDbType.Float)); parameters[parameters.Count - 1].Value = actorSpawnPacket.posy; parameters.Add(new MySqlParameter("?Pos_0_2", MySqlDbType.Float)); parameters[parameters.Count - 1].Value = actorSpawnPacket.posz; parameters.Add(new MySqlParameter("?Rotation", MySqlDbType.Int32, 10)); parameters[parameters.Count - 1].Value = actorSpawnPacket.rotation; parameters.Add(new MySqlParameter("?MobType", MySqlDbType.Int32, 3)); parameters[parameters.Count - 1].Value = actorSpawnPacket.mobType; parameters.Add(new MySqlParameter("?Behaviour", MySqlDbType.Int32, 3)); parameters[parameters.Count - 1].Value = 0; //? parameters.Add(new MySqlParameter("?ModelMainWeapon", MySqlDbType.Int32, 20)); parameters[parameters.Count - 1].Value = actorSpawnPacket.mainWeaponModel; parameters.Add(new MySqlParameter("?ModelSubWeapon", MySqlDbType.Int32, 20)); parameters[parameters.Count - 1].Value = actorSpawnPacket.secWeaponModel; parameters.Add(new MySqlParameter("?Look", MySqlDbType.Blob, actorSpawnPacket.lookdata.Length)); parameters[parameters.Count - 1].Value = actorSpawnPacket.lookdata; parameters.Add(new MySqlParameter("?Models", MySqlDbType.Blob, actorSpawnPacket.models.Length)); parameters[parameters.Count - 1].Value = actorSpawnPacket.models; foreach (MySqlParameter parameter in parameters) { command.Parameters.Add(parameter); } try { command.Prepare(); command.ExecuteNonQuery(); Console.WriteLine(command.CommandText); }catch (Exception exc) { Console.WriteLine($" -> Error writing to DB: " + exc.Message); } } } else { if (Globals.DB) { Console.WriteLine($" -> currentZone==0(change your zone once to fix) or invalid packet"); } } break; } break; case 0x19A: /* INIT_ZONE */ Console.WriteLine("\n-> INIT_ZONE"); InitZonePacket initZonePacket = new InitZonePacket(subpacket.data); currentZone = Convert.ToInt32(initZonePacket.zoneId); if (Globals.UI) { Globals.mapviewform.BeginInvoke((MethodInvoker) delegate() { Globals.mapviewform.SetMapWithId(currentZone, 00); }); } Console.WriteLine($" -> New Zone({initZonePacket.zoneId}): {Globals.exdreader.GetTerritoryName(currentZone)} EntryLength:{subpacket.data.Length}"); break; case 0x146: /* EFFECT */ Console.WriteLine("\n-> EFFECT"); EffectPacket effectPacket = new EffectPacket(subpacket.data); Console.WriteLine($" -> ACTION: {Globals.exdreader.GetActionName((int)effectPacket.actionTextId)} SourceId:{subpacket.header.sourceId} TargetId:{subpacket.header.targetId} Zone:{currentZone} EntryLength:{subpacket.data.Length}"); if (Globals.xmlOutput) { ActorWriter.addEffect(effectPacket, subpacket.header.sourceId, outputFolderName); } break; } }