Exemplo n.º 1
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (b.con == 1)
     {
         label2.Text = "Twitch connected";
     }
     if (b.text == "")
     {
         if (b.msgs.Count != 0)
         {
             b.text = b.msgs[0];
             b.msgs.RemoveAt(0);
         }
     }
     if (b.text != "")
     {
         if (checkBox1.Checked)
         {
             int r = MemoryRead.SendMsg(b.text);
             if (r == 1)
             {
                 label1.Text = "Message was send to War2 successfully";
                 b.text      = "";
             }
             if (r == 2)
             {
                 label1.Text = "Waiting for War2 to receive message...";
             }
             if (r == 0)
             {
                 label1.Text = "War2 process not found";
             }
             if (r == 3)
             {
                 label1.Text = "War2Twitch plugin not found";
             }
         }
         else
         {
             b.text = "";
         }
     }
     if (b.client.IsConnected)
     {
         if (b.client.JoinedChannels.Count != 0)
         {
             if (checkBox2.Checked)
             {
                 MemoryRead.RecMsg();
                 if (MemoryRead.msgs.Count != 0)
                 {
                     label1.Text = "Received message from War2: " + MemoryRead.msgs[0];
                     //if (checkBox2.Checked)
                     b.client.SendMessage(b.chan, MemoryRead.msgs[0]);
                     MemoryRead.msgs.RemoveAt(0);
                 }
             }
         }
     }
 }
        public static string ReadString(int processHandle, int address, int maxLength)
        {
            byte[] bytes   = new byte[maxLength];
            int    numRead = 0;

            if (!MemoryRead.ReadProcessMemory(processHandle, address, bytes, bytes.Length, ref numRead))
            {
                return("<error>");
            }

            bool encounteredNullByte = false;

            for (int i = 0; i < bytes.Length; i++)
            {
                if (bytes[i] == 0)
                {
                    encounteredNullByte = true;
                }
                if (encounteredNullByte)
                {
                    bytes[i] = 0;
                }
            }

            string result = System.Text.Encoding.Default.GetString(bytes);
            Regex  rgx    = new Regex("[^a-zA-Z0-9_.]+");

            result = rgx.Replace(result, "");

            return(result);
        }
        public static void WriteStructure(int processHandle, int address, object structure, int structSize = 0)
        {
            byte[] arr = getStructureBytes(structure);

            int numWritten = 0;

            MemoryRead.WriteProcessMemory(processHandle, address, arr, arr.Length, ref numWritten);
            Console.WriteLine("Wrote " + numWritten + " bytes to " + address);
        }
        public static int ReadIntFromMemory(int processHandle, int address)
        {
            byte[] buffer    = new byte[4];
            int    readBytes = 0;

            MemoryRead.ReadProcessMemory(processHandle, address, buffer, buffer.Length, ref readBytes);
            if (readBytes != 4)
            {
                return(0);
            }
            return(BitConverter.ToInt32(buffer, 0));
        }
Exemplo n.º 5
0
        protected string ReadMapName(GameProcess gameProcess)
        {
            IntPtr dwClientState = gameProcess.ModuleEngine.Read <IntPtr>(Offsets.dwClientState);

            if (dwClientState != IntPtr.Zero)
            {
                string MapName = MemoryRead.ReadString(gameProcess.ModuleClient, dwClientState, Offsets.dwClientState_Map, 32);
                if (MapName != "")
                {
                    return(MapName);
                }
            }

            if (ConsoleMapName != "")
            {
                return(ConsoleMapName); // Fallback
            }

            return("");
        }
Exemplo n.º 6
0
        public ILabel GenerateClosureCall(
            ILocation result,
            IEnumerable <VirtualRegister> callArguments,
            ILabel onReturn,
            Function.Function callerFunction,
            FunType funType,
            VirtualRegister funPtr)
        {
            var needStackOffset = funType.GetStackArgumentsCount() % 2 == 1 ? 8 : 0;
            var funPtrRead      = new RegisterRead(funPtr);
            var funCodePtr      = new MemoryRead(
                new ArithmeticBinaryOperation(AST.ArithmeticOperationType.Addition, funPtrRead, new IntegerImmediateValue(0)));
            var funClosurePtr = new MemoryRead(
                new ArithmeticBinaryOperation(AST.ArithmeticOperationType.Addition, funPtrRead, new IntegerImmediateValue(16)));
            var preCall = new List <Node>
            {
                new AlignStackPointer(needStackOffset)
            }
            .Append(new Comment("Pass arguments"))
            .Concat(this.PassClosureArguments(callArguments, funClosurePtr))
            .Append(new ClearDF())
            .Append(new Comment($"Call closure function"))
            .Append(
                new UsesDefinesNode(
                    HardwareRegisterUtils.ArgumentRegisters.Take(callArguments.Count() + 1).ToList(),
                    HardwareRegisterUtils.CallerSavedRegisters))
            .Append(new RegisterWrite(HardwareRegister.RAX, funCodePtr));

            var postCall = new List <Node>
            {
                new Comment("Copy function result to variable"),
                this.readWriteGenerator.GenerateWrite(callerFunction, result, new RegisterRead(HardwareRegister.RAX)),
                new Comment("Restore RSP alignment"),
                new AlignStackPointer(-(needStackOffset + (8 * funType.GetStackArgumentsCount()))),
                new Comment("End of call"),
            };

            var controlFlow = new ComputedFunctionCall(postCall.MakeTreeChain(this.labelFactory, onReturn));

            return(preCall.MakeTreeChain(this.labelFactory, controlFlow));
        }
        public static T GetStructure <T>(int processHandle, int address, int structSize = 0)
        {
            if (structSize == 0)
            {
                structSize = Marshal.SizeOf(typeof(T));
            }
            byte[] bytes   = new byte[structSize];
            int    numRead = 0;

            if (!MemoryRead.ReadProcessMemory(processHandle, address, bytes, bytes.Length, ref numRead))
            {
                return(default(T));
            }
            //throw new Exception("ReadProcessMemory failed");
            //if (numRead != bytes.Length)
            //throw new Exception("Number of bytes read does not match structure size");
            GCHandle handle    = GCHandle.Alloc(bytes, GCHandleType.Pinned);
            T        structure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));

            handle.Free();
            return(structure);
        }
        private void retrieveHierarchy(object sender, RoutedEventArgs e)
        {
            expandDong.Clear();
            var items = treeView.Items;

            foreach (TreeViewItem oldItem in items)
            {
                checkExpandedDongs(oldItem);
            }

            items.Clear();

            Process process;

            if (Process.GetProcessesByName("Rayman2").Length > 0)
            {
                process       = Process.GetProcessesByName("Rayman2")[0];
                processHandle = MemoryRead.OpenProcess(MemoryRead.PROCESS_WM_READ | MemoryRead.PROCESS_VM_WRITE | MemoryRead.PROCESS_VM_OPERATION, false, process.Id).ToInt32();

                int dynamicWorldAddress = ReadIntFromMemory(processHandle, 0x500FD0);
                int staticWorldAddress  = ReadIntFromMemory(processHandle, 0x500FC0);

                int mainCharacterObjectAddress = ReadIntFromMemory(processHandle, 0x4FF764);

                SuperObject dynamicWorld = GetStructure <SuperObject>(processHandle, dynamicWorldAddress);
                SuperObject staticWorld  = GetStructure <SuperObject>(processHandle, staticWorldAddress);

                SOTreeNode dynamicTreeRoot = new SOTreeNode();
                dynamicTreeRoot.name        = "Dynamic World Root";
                dynamicTreeRoot.superObject = dynamicWorld;
                retrieveHierarchyRecursive(dynamicTreeRoot, mainCharacterObjectAddress, 0);

                int mainSectorAddress         = ReadIntFromMemory(processHandle, 0x500FB0);
                int previousMainSectorAddress = ReadIntFromMemory(processHandle, 0x500FC8);

                SOTreeNode staticTreeRoot = new SOTreeNode();
                staticTreeRoot.name        = "Static World Root";
                staticTreeRoot.superObject = staticWorld;
                retrieveHierarchyRecursive(staticTreeRoot, mainSectorAddress, previousMainSectorAddress);

                TreeViewItem dynamicTreeViewItemRoot = new TreeViewItem()
                {
                    Header = "Dynamic World"
                };
                dynamicTreeViewItemRoot.ExpandSubtree();

                TreeViewItem staticTreeViewItemRoot = new TreeViewItem()
                {
                    Header = "Static World"
                };
                staticTreeViewItemRoot.ExpandSubtree();

                b = 0;
                fillTree(dynamicTreeRoot, dynamicTreeViewItemRoot);
                fillTree(staticTreeRoot, staticTreeViewItemRoot);

                items.Add(dynamicTreeViewItemRoot);
                items.Add(staticTreeViewItemRoot);

                Console.WriteLine(process);
            }
            else
            {
                Console.WriteLine("Rayman2.exe not found");
            }
        }
Exemplo n.º 9
0
        private async Task ReaderTask()
        {
            while (true)
            {
                if (read)
                {
                    try
                    {
                        var actions = Reader.GetActions();
                        if (actions.ActionContainers.Any())
                        {
                            lock (GameState.Actions)
                            {
                                GameState.Actions.Clear();
                                GameState.Actions.AddRange(actions.ActionContainers.SelectMany(t => t.ActionItems.Select(f => new ActionStructure(f))));
                            }
                        }
                        var player      = Reader.GetCurrentPlayer();
                        var actors      = Reader.GetActors();
                        var playerActor = actors.CurrentPCs.FirstOrDefault(t => t.Value.Name == player.CurrentPlayer.Name).Value;
                        var playerObj   = new PlayerStruct(player, playerActor);
                        if (!Scanner.Instance.IsScanning && playerActor != null)
                        {
                            var characterAddressMap = MemoryHandler.Instance.GetByteArray(Scanner.Instance.Locations[Signatures.CharacterMapKey], 8 * 480);
                            var uniqueAddresses     = new Dictionary <IntPtr, IntPtr>();
                            for (var i = 0; i < 480; i++)
                            {
                                var characterAddress = new IntPtr(TryBitConverter.TryToInt64(characterAddressMap, i * 8));

                                if (characterAddress == IntPtr.Zero)
                                {
                                    continue;
                                }

                                uniqueAddresses[characterAddress] = characterAddress;
                            }
                            foreach (var(key, address) in uniqueAddresses)
                            {
                                try
                                {
                                    var    characterAddress = new IntPtr(address.ToInt64());
                                    byte[] source           = MemoryHandler.Instance.GetByteArray(characterAddress, 9200);
                                    var    ID   = TryBitConverter.TryToUInt32(source, 116);
                                    var    Type = (Actor.Type)source[140];
                                    var    set  = false;
                                    switch (Type)
                                    {
                                    case Actor.Type.PC:
                                        if (playerActor.ID == ID)
                                        {
                                            playerObj = new PlayerStruct(playerObj, source[6366]);
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                    if (set)
                                    {
                                        break;
                                    }
                                }
                                catch (Exception)
                                {
                                    //
                                }
                            }
                        }
                        GameState.Player = playerObj;
                        //TODO add in party when there is a way to sort based on the ingame sort
                        //var party = Reader.GetPartyMembers();
                        //var partyActors = party.PartyMembers.Select(t => actors.CurrentPCs[t.Key]).ToList();
                        //gsiJObject["party"] = JToken.Parse(JsonConvert.SerializeObject(partyActors, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }));
                        MemoryRead?.Invoke();
                    }
                    catch (Exception e)
                    {
                        Global.logger.Error(e, "[FFXIVPlugin] Memory reading failed");
                    }
                    await Task.Delay(TimeSpan.FromMilliseconds(5));
                }
                else
                {
                    await Task.Delay(TimeSpan.FromSeconds(2));
                }
            }
        }
Exemplo n.º 10
0
        public string getPlayerLocation(GameProcess gameProcess)
        {
            string locname = MemoryRead.ReadString(gameProcess.ModuleClient, AddressBase, Offsets.m_szLastPlaceName, 18);

            return(locname);
        }