public void Start() { if (_listener != null && _listener.IsListening) { return; } _listener = new HttpListener(); if (!HookRegistry.IsWithinUnity()) { _port += 1; } _listener.Prefixes.Add("http://127.0.0.1:" + _port.ToString() + "/"); _listener.Start(); IsRunning = true; //while (true) //{ // try // { // HttpListenerContext context = _listener.GetContext(); // Process(context); // } // catch (Exception ex) // { // HookRegistry.Panic(ex.Message); // } //} //_listener.BeginGetContext(new AsyncCallback(GetContextCallBack), _listener); System.Threading.ThreadPool.QueueUserWorkItem(Listen); }
private void InitDynamicTypes() { if (HookRegistry.IsWithinUnity()) { _asyncOPModel = typeof(Socket).GetNestedType("SocketAsyncResult", BindingFlags.NonPublic); _asyncModelBuffer = _asyncOPModel.GetField("Buffer", BindingFlags.Instance | BindingFlags.Public); _asyncModelOffset = _asyncOPModel.GetField("Offset", BindingFlags.Instance | BindingFlags.Public); _asyncModelRequestedBytes = _asyncOPModel.GetField("Size", BindingFlags.Instance | BindingFlags.Public); if (_asyncOPModel == null) { HookRegistry.Panic("SocketHook - asyncOPModel == null!"); } if (_asyncModelBuffer == null) { HookRegistry.Panic("SocketHook - asyncModelBuffer == null!"); } if (_asyncModelOffset == null) { HookRegistry.Panic("SocketHook - asyncModelOffset == null!"); } if (_asyncModelRequestedBytes == null) { HookRegistry.Panic("SocketHook - asyncModelRequestedBytes == null!"); } // Hardcode proxy methods, because it's tough to match on methods when you have implementing // types as arguments. Type[] singleArg = new Type[] { typeof(IAsyncResult) }; Type[] doubleArg = new Type[] { typeof(IAsyncResult), typeof(SocketError).MakeByRefType() }; _sendProxy = new MethodInfo[2]; _sendProxy[0] = typeof(Socket).GetMethod("EndSend", BindingFlags.Public | BindingFlags.Instance, null, singleArg, null); if (_sendProxy[0] == null) { HookRegistry.Panic("SocketHook - EP1"); } _sendProxy[1] = typeof(Socket).GetMethod("EndSend", BindingFlags.Public | BindingFlags.Instance, null, doubleArg, null); if (_sendProxy[1] == null) { HookRegistry.Panic("SocketHook - EP2"); } _readProxy = new MethodInfo[2]; _readProxy[0] = typeof(Socket).GetMethod("EndReceive", BindingFlags.Public | BindingFlags.Instance, null, singleArg, null); if (_readProxy[0] == null) { HookRegistry.Panic("SocketHook - EP3"); } _readProxy[1] = typeof(Socket).GetMethod("EndReceive", BindingFlags.Public | BindingFlags.Instance, null, doubleArg, null); if (_readProxy[1] == null) { HookRegistry.Panic("SocketHook - EP4"); } } }
private void InitDynamicTypes() { if (HookRegistry.IsWithinUnity()) { _innerStream = typeof(AuthenticatedStream).GetField("innerStream", BindingFlags.Instance | BindingFlags.NonPublic); if (_innerStream == null) { HookRegistry.Panic("SslStreamHook - innerStream == null"); } _networkSocket = typeof(NetworkStream).GetProperty("Socket", BindingFlags.Instance | BindingFlags.NonPublic)?.GetGetMethod(true); if (_networkSocket == null) { HookRegistry.Panic("SslStreamHook - networkSocket == null"); } _asyncOPModel = typeof(SslStreamBase).GetNestedType("InternalAsyncResult", BindingFlags.NonPublic); _asyncModelBuffer = _asyncOPModel.GetProperty("Buffer")?.GetGetMethod(); _asyncModelOffset = _asyncOPModel.GetProperty("Offset")?.GetGetMethod(); _asyncModelCount = _asyncOPModel.GetProperty("Count")?.GetGetMethod(); if (_asyncOPModel == null) { HookRegistry.Panic("SslStreamHook - asyncOPModel == null!"); } if (_asyncModelBuffer == null) { HookRegistry.Panic("SslStreamHook - asyncModelBuffer == null!"); } if (_asyncModelOffset == null) { HookRegistry.Panic("SslStreamHook - asyncModelOffset == null!"); } if (_asyncModelCount == null) { HookRegistry.Panic("SslStreamHook - asyncModelCount == null!"); } } }
public string DoCmd(IDictionary <string, string> args) { switch (args["cmd"]) { case "AddItem": string numStr; if (!args.TryGetValue("num", out numStr)) { numStr = "1"; } foreach (var idStr in args["ids"].Split(',')) { int id = Convert.ToInt32(idStr.Trim()); int num = Convert.ToInt32(numStr); if (HookRegistry.IsWithinUnity()) { HookRegistry.Debug("AddItem {0}", id); Module <Player> .Self.bag.AddItem(id, num, false, AddItemMode.ForceBag); } else { } } break; case "UnlockAchievement": { int id = Convert.ToInt32(args["id"].Trim()); if (HookRegistry.IsWithinUnity()) { if (Module <AchievementModule> .Self.IsAchievementUnlocked(id)) { return(String.Format("{0} is unlocked", id)); } Module <AchievementModule> .Self.UnlockAchievement(id); } } break; case "MissionAll": { StringBuilder sb = new StringBuilder(); foreach (MissionBaseInfo missionBaseInfo in MissionManager.allMissionBaseInfo.Values) { sb.Append(missionBaseInfo.InstanceID); sb.Append(", "); sb.Append(missionBaseInfo.MissionNO); sb.Append(", "); string name = TextMgr.GetOriginStr(missionBaseInfo.MissionNameId); sb.Append(name); sb.Append(", "); sb.AppendLine(); } return(sb.ToString()); } case "TransportMap": { MessageManager.Instance.Dispatch("TransportMap", new object[] { }, DispatchType.IMME, 2f); } break; case "RefreshPriceIndex": //更新物价指数 Module <StoreManagerV40> .Self.RefreshPriceIndex(); break; case "ItemBar": //修改物品数量 { int index = Convert.ToInt32(args["solt"].Trim()) - 1; int num = Convert.ToInt32(args["num"].Trim()); var item = Module <Player> .Self.bag.itemBar.itemBarItems.ElementAt(index); if (item != null) { num = Mathf.Clamp(num, 1, item.ItemBase.MaxNumber); item.ChangeNumber(num - item.Number); return(String.Format("slot {0} {2}({1}) => {3}", index + 1, item.ItemDataId, item.ItemBase.Name, item.Number)); } else { return("no item on bar"); } } case "Test": return("test"); } return("success"); }