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 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));
        }
        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);
        }