public override void InitBuild(MemoryStream stream) { MessageBuffer informations = Informations as MessageBuffer; if (stream.Length > 0) { Reader.Add(stream.ToArray(), 0, (int)stream.Length); } if (informations.Build(Reader, ClientSide)) { if (BotofuProtocolManager.Protocol[ProtocolKeyEnum.Messages, x => x.protocolID == informations.MessageId] is NetworkElement message) { IDataReader reader = new BigEndianReader(informations.Data); ProtocolJsonContent content = FromByte(null, message, reader); reader.Dispose(); OnMessageParsed?.Invoke(message, content); } Informations = null; Informations = new MessageBuffer(); stream.Close(); stream = new MemoryStream(Reader.ReadBytes((int)Reader.BytesAvailable)); Reader.Dispose(); Reader = null; Reader = new BigEndianReader(); InitBuild(stream); } }
private void ClientTreatment_OnMessageParsed(NetworkElement arg1, ProtocolJsonContent arg2) { var hooker = HookManager <T> .Instance[LocalClient.localIp.Port]; if (hooker is null) { logger.Error("no proxy found"); return; } if (ClientTreatment.Informations is MessageBuffer informations) { hooker.Proxy.LAST_GLOBAL_INSTANCE_ID = informations.InstanceId; } uint instance_id = hooker.Proxy.LAST_GLOBAL_INSTANCE_ID + hooker.Proxy.FAKE_MESSAGE_SENT; StartupConfiguration configuration = Configurations.ConfigurationManager.Instance.Startup; if (configuration.show_message) { logger.Info($"[client {RemoteClient.remoteIp}] {arg1.BasicString()}"); if (configuration.show_message_content) { logger.Info($"{arg2}"); } } HandlerManager.Instance.Handle(arg1.protocolID, LocalClient, RemoteClient, arg2); RemoteClient.Send(ClientTreatment.Informations.ReWriteInstanceId(instance_id)); }
public async void Test(Hooker <MessageInformation> hook, CustomClientPage page) { if (page is null) { return; } await Task.Run(() => { page.Dispatcher.Invoke(() => { ProtocolJsonContent content = Content["infos"]["entityLook"]; Bitmap image = content.FromWeb(); SetModel(page.CharacterInformation, hook.Player, image); if (UIManager.Instance.UI.Container[hook.Proxy.ProcessId] is CustomButton btn) { btn.ButtonText = $"{hook.Player.Name}"; UIManager.Instance.UI.Container[hook.Proxy.ProcessId, true] = btn; } if (UIManager.Instance.UI.SelectedId == hook.Proxy.ProcessId) { UIManager.Instance.UI.Navigate(page, hook.Proxy.ProcessId); } }); }); }
public static SubEntity FromSubEntity(this ProtocolJsonContent content) { return(new SubEntity() { BindingPointCategory = content["bindingPointCategory"], BindingPointIndex = content["bindingPointIndex"], SubEntityLook = content["subEntityLook"].FromEntityLook() }); }
public void Handle(Type type, CustomClient local, CustomClient remote, ProtocolJsonContent content) { if (type is null) { return; } MessageHandler handler = (MessageHandler)Activator.CreateInstance(type, new object[] { local, remote, content }); new Action(handler.Handle).Run(handler.EndHandle, handler.Error); }
private void Handle(MethodInfo method, ProxyElement proxy, ProtocolJsonContent content) { if (method is null) { return; } object obj = Activator.CreateInstance(method.DeclaringType); method.Invoke(obj, new object[] { proxy, method.GetCustomAttribute <HandlerAttribute>().Message, content }); }
public void Send(NetworkElement message, ProtocolJsonContent content, bool clientSide) { if (message is null) { return; } using (BigEndianWriter writer = new BigEndianWriter()) { byte[] data = ProtocolTreatmentExtension.FromContent(content, message); int cmpLen = _cmpLen(data.Length); writer.WriteShort((short)((message.protocolID << 2) | cmpLen)); if (clientSide) { writer.WriteUnsignedInt(GetCustomInstanceId()); } switch (cmpLen) { case 0: break; case 1: writer.WriteByte((byte)data.Length); break; case 2: writer.WriteShort((short)data.Length); break; case 3: writer.WriteByte((byte)((data.Length >> 16) & 255)); writer.WriteShort((short)(data.Length & 65535)); break; } writer.WriteBytes(data); Send(writer.Data); OnCustomMessageSent?.Invoke(message, content); StartupConfiguration configuration = Configurations.ConfigurationManager.Instance.Startup; if (configuration.show_fake_message) { logger.Info($"fake message sent to {remoteIp} |{message.BasicString()}]"); if (configuration.show_fake_message_content) { logger.Info($"{content}"); } } } }
public static PlayerModel FromBaseInformations(this ProtocolJsonContent content) { return(new PlayerModel() { Id = content["infos"]["id"], Name = content["infos"]["name"], Level = content["infos"]["level"], IsMerchant = false, Sex = content["infos"]["sex"], BreedId = content["infos"]["breed"], //Look = content["infos"]["look"].FromEntityLook() }); }
public void Send(int processId, NetworkElementField message, ProtocolJsonContent content, bool clientSide) { if (message is null) { return; } using (BigEndianWriter writer = new BigEndianWriter()) { byte[] data = message.ToByte(content); int cmpLen = _cmpLen(data.Length); writer.WriteShort((short)((message.protocolID << 2) | cmpLen)); ProxyManager.Instance[processId].FAKE_MESSAGE_SENT++; if (clientSide) { writer.WriteUnsignedInt(ProxyManager.Instance[processId].FAKE_MSG_INSTANCE_ID); } switch (cmpLen) { case 0: break; case 1: writer.WriteByte((byte)data.Length); break; case 2: writer.WriteShort((short)data.Length); break; case 3: writer.WriteByte((byte)((data.Length >> 16) & 255)); writer.WriteShort((short)(data.Length & 65535)); break; } writer.WriteBytes(data); Send(writer.Data); if (ConfigurationManager.Instance.Startup.show_fake_message_sent) { Console.WriteLine($"Fake Message sent to ({RemoteIP}) : (n°{ProxyManager.Instance[processId].FAKE_MSG_INSTANCE_ID}) [{message.name} ({message.protocolID})]"); if (ConfigurationManager.Instance.Startup.show_message_content) { Console.WriteLine($"{content}"); } } } }
public static byte[] FromContent(ProtocolJsonContent content, NetworkElement field) { if (content is null) { return(new byte[0]); } if (field is null) { throw new Exception("field cannot be null"); } try { using (BigEndianWriter writer = new BigEndianWriter()) { if (field.super_serialize) { NetworkElement super = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.MessagesAndTypes, x => x.name == field.super]; byte[] super_data = FromContent(content, super); writer.WriteBytes(super_data); } IEnumerable <ClassField> boolWrapper = field.fields.Where(x => x.use_boolean_byte_wrapper).OrderBy(x => x.boolean_byte_wrapper_position); IEnumerable <ClassField> vars = field.fields.Where(x => !boolWrapper.Contains(x)).OrderBy(x => x.position); if (boolWrapper.Count() > 0) { byte[] flags = new byte[boolWrapper.LastOrDefault().position.Value + 1]; foreach (ClassField _bool in boolWrapper) { flags[_bool.position.Value] = BooleanByteWrapper.SetFlag(flags[_bool.position.Value], (byte)((_bool.boolean_byte_wrapper_position.Value - 1) % 8), content[_bool.name]); } } foreach (ClassField _var in vars) { Parse(_var, content[_var.name], writer); } return(writer.Data); } } catch (Exception e) { logger.Error(e); return(new byte[0]); } }
private void ServerTreatment_OnMessageParsed(NetworkElement arg1, ProtocolJsonContent arg2) { StartupConfiguration configuration = Configurations.ConfigurationManager.Instance.Startup; if (configuration.show_message) { logger.Info($"[server {RemoteClient.remoteIp}] {arg1.BasicString()}"); if (configuration.show_message_content) { logger.Info($"{arg2}"); } } HandlerManager.Instance.Handle(arg1.protocolID, LocalClient, RemoteClient, arg2); }
public static ProtocolJsonContent FromBytes(ProtocolJsonContent content, NetworkElement field, IDataReader reader) { if (content is null) { content = new ProtocolJsonContent(); } if (field is null) { return(content); } try { if (field.super_serialize) { NetworkElement super = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.MessagesAndTypes, x => x.name == field.super]; content = FromBytes(content, super, reader); } IEnumerable <ClassField> boolWrapper = field.fields.Where(x => x.use_boolean_byte_wrapper).OrderBy(x => x.boolean_byte_wrapper_position); IEnumerable <ClassField> vars = field.fields.Where(x => !boolWrapper.Contains(x)).OrderBy(x => x.position); byte flag = 0; for (byte i = 0; i < boolWrapper.Count(); i++) { ClassField _bool = boolWrapper.ElementAt(i); if (i % 8 == 0) { flag = reader.ReadByte(); } content[_bool.name] = BooleanByteWrapper.GetFlag(flag, i); } foreach (ClassField _var in vars) { content[_var.name] = _var.Parse(ref reader); } } catch (Exception e) { Console.WriteLine($"{e}"); } return(content); }
public static EntityLook FromEntityLook(this ProtocolJsonContent content) { EntityLook look = new EntityLook() { BonesId = content["bonesId"], Skins = content["skins"], IndexedColors = content["indexedColors"], Scales = content["scales"], SubEntityLook = new SubEntity[content["subEntityLook"].Length] }; for (int i = 0; i < look.SubEntityLook.Length; i++) { look.SubEntityLook[i] = content["subEntityLook"][i].FromSubEntity(); } return(look); }
public static string EntityLookToString(this ProtocolJsonContent content) { string bonesId = $"{content["bonesId"]}"; string skins = ""; for (int i = 0; i < content["skins"].Length; i++) { skins += $"{content["skins"][i]}{(i < content["skins"].Length - 1 ? "," : "")}"; } string indexedColors; try { indexedColors = $"1={content["indexedColors"][0]},2={content["indexedColors"][1]},3={content["indexedColors"][2]},4={content["indexedColors"][3]},5={content["indexedColors"][4]}"; } catch { indexedColors = ""; } string scales = ""; for (int i = 0; i < content["scales"].Length; i++) { scales += $"{content["scales"][i]}{(i < content["scales"].Length - 1 ? "," : "")}"; } string result = "{" + bonesId; if (skins != "") { result += $"|{skins}"; } if (indexedColors != "") { result += $"|{indexedColors}"; } if (scales != "") { result += $"|{scales}"; } return(result + "}"); }
private static dynamic _readElement(this ClassField field, ref IDataReader reader) { if (IsPrimitiv(field.type)) { string read_method = $"Read{field.write_method.Replace("write", "")}"; return(read_method._readMethod(ref reader)); } else { NetworkElement network_element = null; ProtocolJsonContent content = null; bool is_null = false; if (field.write_false_if_null_method != null && field.write_false_if_null_method != "") { string check_null_method = $"Read{field.write_false_if_null_method.Replace("write", "")}"; is_null = check_null_method._readMethod(ref reader) == 0; } if (is_null) { return(null); } if (!field.prefixed_by_type_id) { network_element = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.Types, x => x.name == field.type]; } else { string read_id_method = $"Read{field.write_type_id_method.Replace("write", "")}"; dynamic protocol_id = read_id_method._readMethod(ref reader); content = new ProtocolJsonContent(); content["protocol_id"] = protocol_id; network_element = ProtocolManager.Instance.Protocol[ProtocolKeyEnum.Types, x => x.protocolID == protocol_id]; } return(FromBytes(content, network_element, reader)); } }
public static Bitmap FromWeb(this ProtocolJsonContent content) { byte[] data = Encoding.ASCII.GetBytes(content.EntityLookToString()); string data_str = data.ToHexString(false).ToLower(); string url = $"https://static.ankama.com/dofus/renderer/look/{data_str}/full/1/150_220-10.png"; using (WebClient client = new WebClient()) { client.Headers.Set(HttpRequestHeader.Host, "static.ankama.com"); client.Headers.Set(HttpRequestHeader.Accept, "image/webp,image/apng,image/*,*/*;q=0.8"); try { Stream stream = client.OpenRead(new Uri(url)); return(new Bitmap(stream)); } catch { return(null); } } }
private ActorModel Parse(ProtocolJsonContent content, double mapId) { // GameRolePlayCharacterInformations or // GameRolePlayMerchantInformations if (content["protocol_id"] == 36 || content["protocol_id"] == 129) { ProtocolJsonContent humanoidInfo = content["humanoidInfo"]; ProtocolJsonContent alignmentInfos = content["alignmentInfos"]; short level = (short)(alignmentInfos is null ? 0 : (alignmentInfos["characterPower"] - content["contextualId"])); return(new PlayerModel() { Id = content["contextualId"], Level = level, Name = content["name"], IsMerchant = content["protocol_id"] == 129, MapId = mapId }); } return(null); }
public static ActorModel FromActorRolePlayInformation(this ProtocolJsonContent content) { if (content["protocol_id"] == 36 || content["protocol_id"] == 129) { ProtocolJsonContent alignmentInfos = content["alignmentInfos"]; ProtocolJsonContent humanoidInfos = content["humanoidInfo"]; short level = (short)(alignmentInfos is null ? 0 : (alignmentInfos["characterPower"] - content["contextualId"])); return(new PlayerModel() { Id = content["contextualId"], Level = level, Name = content["name"], IsMerchant = content["protocol_id"] == 129, Sex = humanoidInfos["sex"], BreedId = 0, Look = content["look"] }); } return(null); }
private void ClientMessageInformation_OnMessageParsed(NetworkElementField obj, ProtocolJsonContent con) { ProxyManager.Instance[ProcessId].LAST_GLOBAL_INSTANCE_ID = ClientMessageInformation.Information.InstanceId; ProxyManager.Instance[ProcessId].SERVER_MESSAGE_RCV = 0; uint instance_id = ClientMessageInformation.Information.InstanceId + ProxyManager.Instance[ProcessId].FAKE_MESSAGE_SENT; if (ConfigurationManager.Instance.Startup.show_message) { Console.WriteLine($"[Client({FakeClient.RemoteIP})] (n°{instance_id} | ({ClientMessageInformation.Information.InstanceId} + {ProxyManager.Instance[ProcessId].FAKE_MESSAGE_SENT})) {obj.name} ({obj.protocolID})"); if (ConfigurationManager.Instance.Startup.show_message_content) { Console.WriteLine($"{con}"); } } FakeClient.Send(ClientMessageInformation.Information.ReWriteInstanceId(instance_id)); HandlerManager.Instance.Handle((uint)obj.protocolID, this, con); }
private void RemoteClient_OnCustomMessageSent(NetworkElement arg1, ProtocolJsonContent arg2) { FAKE_MESSAGE_SENT++; }
public void Handle(string protocolName, ProxyElement proxy, ProtocolJsonContent content) { MethodInfo method = _handlers.FirstOrDefault(x => x.GetCustomAttribute <HandlerAttribute>().ProtocolName == protocolName); Handle(method, proxy, content); }
public void HandleCharacterSelectedSuccessMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content) { PlayerModel model = new PlayerModel() { Id = content["infos"]["id"], Name = content["infos"]["name"], Level = content["infos"]["level"], IsMerchant = false }; ProxyManager.Instance[proxy.ProcessId].CharacterSelected = model; FastEventManager.Instance.Handle(FastEventEnum.PlayerSelected, model); }
public void Handle(string protocolName, CustomClient local, CustomClient remote, ProtocolJsonContent content) { Type type = handlersType.FirstOrDefault(x => x.GetCustomAttribute <HandlerAttribute>().ProtocolName.ToLower() == protocolName.ToLower()); Handle(type, local, remote, content); }
public void Handle(int protocolId, CustomClient local, CustomClient remote, ProtocolJsonContent content) { Type type = handlersType.FirstOrDefault(x => x.GetCustomAttribute <HandlerAttribute>().ProtocolId == protocolId); Handle(type, local, remote, content); }
public void HandleGameContextRemoveElementMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content) { double mapId = ProxyManager.Instance[proxy.ProcessId].CharacterSelected.MapId; FastEventManager.Instance.Handle(FastEventEnum.ElementRemovedMap, content["id"], mapId); }
public void HandleGameRolePlayShowActorMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content) { double mapId = ProxyManager.Instance[proxy.ProcessId].CharacterSelected.MapId; ActorModel model = Parse(content["informations"], mapId); if (model != null) { FastEventManager.Instance.Handle(FastEventEnum.PlayerEnterMap, model); } }
public void HandleMapComplementaryInformationsDataMessage(ProxyElement proxy, NetworkElementField message, ProtocolJsonContent content) { MapModel map = new MapModel() { MapId = content["mapId"] }; ProxyManager.Instance[proxy.ProcessId].CharacterSelected.MapId = map.MapId; foreach (ProtocolJsonContent actor in content["actors"]) { ActorModel model = Parse(actor, content["mapId"]); if (model != null) { map.Actors.Add(model); } } FastEventManager.Instance.Handle(FastEventEnum.PlayerSelectedEnterMap, map); }
public void SendClient(dynamic value, ProtocolJsonContent content) { Client.Send(ProcessId, value, content, false); }
public void SendServer(dynamic value, ProtocolJsonContent content) { FakeClient.Send(ProcessId, value, content); }
private void ServerMessageInformation_OnMessageParsed(NetworkElementField obj, ProtocolJsonContent con) { ProxyManager.Instance[ProcessId].SERVER_MESSAGE_RCV++; if (ConfigurationManager.Instance.Startup.show_message) { Console.WriteLine($"[Server({FakeClient.RemoteIP})] {obj.name} ({obj.protocolID})"); if (ConfigurationManager.Instance.Startup.show_message_content) { Console.WriteLine($"{con}"); } } HandlerManager.Instance.Handle((uint)obj.protocolID, this, con); }