ChuckHearthstone / SilverFish

Hearthstone AI derived from https://github.com/noHero123/silverfish
53 stars 16 forks source link

Only part of a ReadProcessMemory or WriteProcessMemory request was completed #45

Open chucklu opened 4 years ago

chucklu commented 4 years ago

2020-05-13 21:17:34.538+08:00 [15] ERROR Triton.Common.LogUtilities.Logger - [Tick] Exception during execution: Buddy.Coroutines.CoroutineUnhandledException: Exception was thrown by coroutine ---> System.Exception: Only part of a ReadProcessMemory or WriteProcessMemory request was completed, at addr: F37438A4, Size: 12 at GreyMagic.ExternalProcessMemory.ReadByteBuffer(IntPtr addr, Void* buffer, Int32 count) at GreyMagic.MemoryBase.Read[T](IntPtr addr) at ns27.Class276.method_31(IntPtr intptr_37) at ns27.Class276.method_33(IntPtr intptr_37, String string_0, Enum20[] enum20_0) at Triton.Game.Mono.MonoClass.smethod_4(IntPtr intptr_1, String string_4, Enum20[] enum20_0) at Triton.Game.Mono.MonoClass.method_0(String string_4, Enum20[] enum20_0) at Triton.Game.Mono.MonoClass.method_7(String string_4, Enum20[] enum20_0, Object[] object_0) at Triton.Game.Mono.MonoClass.method_15[T](String string_4, Enum20[] enum20_0, Object[] object_0) at ns26.Class271`1.method_24(Int32 int_1)

at ns26.Class271`1.method_25() at Triton.Game.Mapping.QuestLog.get_m_currentQuests() at Triton.Bot.Logic.Bots.DefaultBot.DefaultBot.Struct84.MoveNext() // End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Triton.Bot.Logic.Bots.DefaultBot.DefaultBot.Struct60.MoveNext() // End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Buddy.Coroutines.Coroutine.Class66.Struct18.MoveNext() //End of inner exception stack trace --- at Buddy.Coroutines.Coroutine.method_2(Boolean bool_2) at Buddy.Coroutines.Coroutine.method_0(Boolean bool_2) at Buddy.Coroutines.Coroutine.Resume() at Triton.Bot.Logic.Bots.DefaultBot.DefaultBot.Tick() at Triton.Bot.BotManager.smethod_1(IBot ibot_1)

chucklu commented 4 years ago
// Triton.Game.Mapping.QuestLog
// Token: 0x17002BD0 RID: 11216
// (get) Token: 0x0600793A RID: 31034 RVA: 0x000E8EA8 File Offset: 0x000E70A8
public List<QuestTile> m_currentQuests
{
    get
    {
        Class271<QuestTile> @class = base.method_3<Class271<QuestTile>>("m_currentQuests");
        if (@class != null)
        {
            return @class.method_25();
        }
        return null;
    }
}
chucklu commented 4 years ago
// ns26.Class271<T>
// Token: 0x06001AF2 RID: 6898 RVA: 0x000DEAE0 File Offset: 0x000DCCE0
public List<T> method_25()
{
    List<T> list = new List<T>();
    int int32_ = this.Int32_0;
    for (int i = 0; i < int32_; i++)
    {
        list.Add(this.method_24(i));
    }
    return list;
}

// ns26.Class271<T>
// Token: 0x06001AF1 RID: 6897 RVA: 0x00013280 File Offset: 0x00011480
public T method_24(int int_1)
{
    return base.method_15<T>("get_Item", new Class276.Enum20[]
    {
        Class276.Enum20.I4
    }, new object[]
    {
        int_1
    });
}
chucklu commented 4 years ago
// Triton.Game.Mono.MonoClass
// Token: 0x060019F8 RID: 6648 RVA: 0x000DCB0C File Offset: 0x000DAD0C
internal T method_15<T>(string string_4, Class276.Enum20[] enum20_0, params object[] object_0) where T : class
{
    if (!typeof(T).IsClass)
    {
        throw new InvalidOperationException(string.Concat(new object[]
        {
            typeof(T),
            " is not a class type. Please fix the method invocation for ",
            this.ClassName,
            ".",
            string_4,
            " to use Get<T> or GetString instead."
        }));
    }
    IntPtr intPtr = this.method_7(string_4, enum20_0, object_0);
    if (intPtr == IntPtr.Zero)
    {
        return default(T);
    }
    return FastObjectFactory.CreateObjectInstance<T>(intPtr);
}

// Triton.Game.Mono.MonoClass
// Token: 0x060019F0 RID: 6640 RVA: 0x000DC9F8 File Offset: 0x000DABF8
internal IntPtr method_7(string string_4, Class276.Enum20[] enum20_0, params object[] object_0)
{
    IntPtr classInstance = this.GetClassInstance();
    if (classInstance == IntPtr.Zero)
    {
        throw new Exception("Cannot call a method on an object instance that has no address!");
    }
    IntPtr intPtr = this.method_0(string_4, enum20_0);
    if (intPtr == IntPtr.Zero)
    {
        throw new MissingMethodException(this.ClassName, string_4);
    }
    return MonoClass.Class276_0.method_43(intPtr, classInstance, object_0);
}

// Triton.Game.Mono.MonoClass
// Token: 0x060019D9 RID: 6617 RVA: 0x00012694 File Offset: 0x00010894
internal IntPtr method_0(string string_4, Class276.Enum20[] enum20_0)
{
    if (this.IntPtr_0 == IntPtr.Zero)
    {
        throw new InvalidOperationException("Cannot get a method pointer on an object that has no MonoClass pointer.");
    }
    return MonoClass.smethod_4(this.IntPtr_0, string_4, enum20_0);
}

// Triton.Game.Mono.MonoClass
// Token: 0x060019DA RID: 6618 RVA: 0x000DC4A8 File Offset: 0x000DA6A8
private static IntPtr smethod_4(IntPtr intptr_1, string string_4, Class276.Enum20[] enum20_0)
{
    MonoClass.Class274 @class = new MonoClass.Class274();
    @class.string_0 = string_4;
    @class.enum20_0 = enum20_0;
    Dictionary<string, List<MonoClass.Class273>> dictionary;
    if (!MonoClass.dictionary_3.TryGetValue(intptr_1, out dictionary))
    {
        MonoClass.dictionary_3.Add(intptr_1, new Dictionary<string, List<MonoClass.Class273>>());
        dictionary = MonoClass.dictionary_3[intptr_1];
    }
    List<MonoClass.Class273> list;
    if (!dictionary.TryGetValue(@class.string_0, out list))
    {
        dictionary.Add(@class.string_0, new List<MonoClass.Class273>());
        list = dictionary[@class.string_0];
    }
    MonoClass.Class273 class2 = list.FirstOrDefault(new Func<MonoClass.Class273, bool>(@class.method_0));
    if (class2 == null)
    {
        IntPtr intPtr = MonoClass.Class276_0.method_33(intptr_1, @class.string_0, @class.enum20_0);
        if (intPtr != IntPtr.Zero)
        {
            class2 = new MonoClass.Class273(@class.string_0, intPtr, @class.enum20_0);
            list.Add(class2);
        }
    }
    if (class2 == null)
    {
        return IntPtr.Zero;
    }
    return class2.IntPtr_0;
}
chucklu commented 4 years ago
// ns27.Class276
// Token: 0x06001A90 RID: 6800 RVA: 0x000DE024 File Offset: 0x000DC224
internal IntPtr method_33(IntPtr intptr_37, string string_0, params Class276.Enum20[] enum20_0)
{
    while (intptr_37 != IntPtr.Zero)
    {
        using (AllocatedMemory allocatedMemory = this.externalProcessMemory_0.CreateAllocatedMemory(256))
        {
            allocatedMemory.AllocateOfChunk<IntPtr>("Itr");
            IntPtr intPtr;
            while ((intPtr = this.method_35(intptr_37, allocatedMemory["Itr"])) != IntPtr.Zero)
            {
                IntPtr address = this.method_37(intPtr);
                if (this.externalProcessMemory_0.ReadStringA(address) == string_0)
                {
                    if (enum20_0 != null)
                    {
                        Class276.Enum20[] array = this.method_31(intPtr);
                        if (array.Length != enum20_0.Length || !array.SequenceEqual(enum20_0))
                        {
                            continue;
                        }
                    }
                    return intPtr;
                }
            }
            intptr_37 = this.method_25(intptr_37);
        }
    }
    return IntPtr.Zero;
}

// ns27.Class276
// Token: 0x06001A8E RID: 6798 RVA: 0x000DDDE4 File Offset: 0x000DBFE4
internal Class276.Enum20[] method_31(IntPtr intptr_37)
{
    List<Class276.Enum20> list = new List<Class276.Enum20>();
    IntPtr intPtr = this.method_13(intptr_37);
    Class276.Struct109 @struct = this.externalProcessMemory_0.Read<Class276.Struct109>(intPtr);
    IntPtr pointer = intPtr + 12;
    for (int i = 1; i < (int)(@struct.ushort_0 + 1); i++)
    {
        IntPtr addr = this.externalProcessMemory_0.Read<IntPtr>(pointer + i * 4);
        Class276.Enum20 uint32_ = (Class276.Enum20)this.externalProcessMemory_0.Read<Class276.Struct110>(addr).UInt32_1;
        list.Add(uint32_);
    }
    return list.ToArray();
}
chucklu commented 4 years ago

might need to check Class276.Struct110 and its property UInt32_1

// ns27.Class276.Struct110
// Token: 0x17000509 RID: 1289
// (get) Token: 0x06001ABF RID: 6847 RVA: 0x00012FC2 File Offset: 0x000111C2
internal uint UInt32_1
{
    get
    {
        return (this.uint_0 & 16711680U) / 65536U;
    }
}
chucklu commented 4 years ago

check the HearthMirror project of HearthSim

zfz12345 commented 4 years ago

new

using System;

namespace HearthMirror
{
    // Token: 0x0200000B RID: 11
    internal static class Offsets
    {
        // Token: 0x04000033 RID: 51
        public static uint ImageDosHeader_e_lfanew = 60u;

        // Token: 0x04000034 RID: 52
        public static uint ImageNTHeaders_Signature = 0u;

        // Token: 0x04000035 RID: 53
        public static uint ImageNTHeaders_Machine = 4u;

        // Token: 0x04000036 RID: 54
        public static uint ImageNTHeaders_ExportDirectoryAddress = 120u;

        // Token: 0x04000037 RID: 55
        public static uint ImageExportDirectory_NumberOfFunctions = 20u;

        // Token: 0x04000038 RID: 56
        public static uint ImageExportDirectory_AddressOfFunctions = 28u;

        // Token: 0x04000039 RID: 57
        public static uint ImageExportDirectory_AddressOfNames = 32u;

        // Token: 0x0400003A RID: 58
        public static uint MonoDomain_domain_assemblies = 108u;

        // Token: 0x0400003B RID: 59
        public static uint MonoAssembly_name = 8u;

        // Token: 0x0400003C RID: 60
        public static uint MonoAssembly_image = 68u;

        // Token: 0x0400003D RID: 61
        public static uint MonoImage_class_cache = 852u;

        // Token: 0x0400003E RID: 62
        public static uint MonoInternalHashTable_size = 12u;

        // Token: 0x0400003F RID: 63
        public static uint MonoInternalHashTable_table = 20u;

        // Token: 0x04000040 RID: 64
        public static uint MonoClass_parent = 32u;

        // Token: 0x04000041 RID: 65
        public static uint MonoClass_nested_in = 36u;

        // Token: 0x04000042 RID: 66
        public static uint MonoClass_runtime_info = 132u;

        // Token: 0x04000043 RID: 67
        public static uint MonoClass_name = 44u;

        // Token: 0x04000044 RID: 68
        public static uint MonoClass_name_space = 48u;

        // Token: 0x04000045 RID: 69
        public static uint MonoClass_vtable_size = 56u;

        // Token: 0x04000046 RID: 70
        public static uint MonoClass_next_class_cache = 168u;

        // Token: 0x04000047 RID: 71
        public static uint MonoClass_fields = 96u;

        // Token: 0x04000048 RID: 72
        public static uint MonoClass_sizes = 92u;

        // Token: 0x04000049 RID: 73
        public static uint MonoClass_byval_arg = 116u;

        // Token: 0x0400004A RID: 74
        public static uint MonoClass_bitfields = 20u;

        // Token: 0x0400004B RID: 75
        public static uint MonoClass_bitfields_classkind = 30u;

        // Token: 0x0400004C RID: 76
        public static uint MonoClass_field_count = 164u;

        // Token: 0x0400004D RID: 77
        public static uint MonoClass_sizeof = 148u;

        // Token: 0x0400004E RID: 78
        public static uint MonoClassField_sizeof = 16u;

        // Token: 0x0400004F RID: 79
        public static uint MonoClassField_type = 0u;

        // Token: 0x04000050 RID: 80
        public static uint MonoClassField_name = 4u;

        // Token: 0x04000051 RID: 81
        public static uint MonoClassField_parent = 8u;

        // Token: 0x04000052 RID: 82
        public static uint MonoClassField_offset = 12u;

        // Token: 0x04000053 RID: 83
        public static uint MonoType_attrs = 4u;

        // Token: 0x04000054 RID: 84
        public static uint MonoType_type = 6u;

        // Token: 0x04000055 RID: 85
        public static uint MonoClassRuntimeInfo_domain_vtables = 4u;

        // Token: 0x04000056 RID: 86
        public static uint MonoVTable_vtable = 40u;

        // Token: 0x04000057 RID: 87
        public static uint MonoVTable_bitfield = 28u;
    }
}

old

using System;

namespace HearthMirror
{
    // Token: 0x0200000B RID: 11
    internal static class Offsets
    {
        // Token: 0x04000033 RID: 51
        public static uint ImageDosHeader_e_lfanew = 60u;

        // Token: 0x04000034 RID: 52
        public static uint ImageNTHeaders_Signature = 0u;

        // Token: 0x04000035 RID: 53
        public static uint ImageNTHeaders_Machine = 4u;

        // Token: 0x04000036 RID: 54
        public static uint ImageNTHeaders_ExportDirectoryAddress = 120u;

        // Token: 0x04000037 RID: 55
        public static uint ImageExportDirectory_NumberOfFunctions = 20u;

        // Token: 0x04000038 RID: 56
        public static uint ImageExportDirectory_AddressOfFunctions = 28u;

        // Token: 0x04000039 RID: 57
        public static uint ImageExportDirectory_AddressOfNames = 32u;

        // Token: 0x0400003A RID: 58
        public static uint MonoDomain_sizeof = 324u;

        // Token: 0x0400003B RID: 59
        public static uint MonoDomain_domain_assemblies = 112u;

        // Token: 0x0400003C RID: 60
        public static uint MonoAssembly_sizeof = 84u;

        // Token: 0x0400003D RID: 61
        public static uint MonoAssembly_name = 8u;

        // Token: 0x0400003E RID: 62
        public static uint MonoAssembly_image = 64u;

        // Token: 0x0400003F RID: 63
        public static uint MonoImage_class_cache = 672u;

        // Token: 0x04000040 RID: 64
        public static uint MonoInternalHashTable_size = 12u;

        // Token: 0x04000041 RID: 65
        public static uint MonoInternalHashTable_table = 20u;

        // Token: 0x04000042 RID: 66
        public static uint MonoClass_parent = 36u;

        // Token: 0x04000043 RID: 67
        public static uint MonoClass_nested_in = 40u;

        // Token: 0x04000044 RID: 68
        public static uint MonoClass_runtime_info = 168u;

        // Token: 0x04000045 RID: 69
        public static uint MonoClass_name = 52u;

        // Token: 0x04000046 RID: 70
        public static uint MonoClass_name_space = 56u;

        // Token: 0x04000047 RID: 71
        public static uint MonoClass_next_class_cache = 172u;

        // Token: 0x04000048 RID: 72
        public static uint MonoClass_fields = 120u;

        // Token: 0x04000049 RID: 73
        public static uint MonoClass_sizes = 92u;

        // Token: 0x0400004A RID: 74
        public static uint MonoClass_byval_arg = 140u;

        // Token: 0x0400004B RID: 75
        public static uint MonoClass_bitfields = 20u;

        // Token: 0x0400004C RID: 76
        public static uint MonoClass_field_count = 104u;

        // Token: 0x0400004D RID: 77
        public static uint MonoClassField_sizeof = 16u;

        // Token: 0x0400004E RID: 78
        public static uint MonoClassField_type = 0u;

        // Token: 0x0400004F RID: 79
        public static uint MonoClassField_name = 4u;

        // Token: 0x04000050 RID: 80
        public static uint MonoClassField_parent = 8u;

        // Token: 0x04000051 RID: 81
        public static uint MonoClassField_offset = 12u;

        // Token: 0x04000052 RID: 82
        public static uint MonoType_attrs = 4u;

        // Token: 0x04000053 RID: 83
        public static uint MonoType_sizeof = 8u;

        // Token: 0x04000054 RID: 84
        public static uint MonoClassRuntimeInfo_domain_vtables = 4u;

        // Token: 0x04000055 RID: 85
        public static uint MonoVTable_data = 12u;
    }
}

Any Ideas?

ghotm commented 4 years ago

这个问题我也搞不懂,有没有能人异士透露个思路