Пример #1
0
        internal static void Init()
        {
            if (initDone)
            {
                return;
            }

            var q1 = from t in Assembly.GetExecutingAssembly().GetTypes()
                     where t.Namespace != null && (t.IsClass && t.Namespace.Contains("LlamaLibrary") && t.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Static).Any(i => i.Name == "Offsets"))
                     select t.GetNestedType("Offsets", BindingFlags.NonPublic | BindingFlags.Static);

            var types = typeof(Offsets).GetFields(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance).Concat(q1.SelectMany(j => j.GetFields(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)));

            using (var pf = new PatternFinder(Core.Memory))
                Parallel.ForEach(types, type =>
                {
                    if (type.FieldType.IsClass)
                    {
                        var instance = Activator.CreateInstance(type.FieldType);


                        foreach (var field in type.FieldType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
                        {
                            var res = ParseField(field, pf);
                            if (field.FieldType == typeof(IntPtr))
                            {
                                field.SetValue(instance, res);
                            }
                            else
                            {
                                field.SetValue(instance, (int)res);
                            }
                        }

                        //set the value
                        type.SetValue(null, instance);
                    }
                    else
                    {
                        var res = ParseField(type, pf);
                        if (type.FieldType == typeof(IntPtr))
                        {
                            type.SetValue(null, res);
                        }
                        else
                        {
                            type.SetValue(null, (int)res);
                        }
                    }
                }
                                 );

            Dictionary <IntPtr, int> vtables = new Dictionary <IntPtr, int>();

            for (var index = 0; index < AgentModule.AgentVtables.Count; index++)
            {
                vtables.Add(AgentModule.AgentVtables[index], index);
            }

            var q = from t in Assembly.GetExecutingAssembly().GetTypes()
                    where t.IsClass && t.Namespace == "LlamaLibrary.RemoteAgents"
                    select t;

            foreach (var MyType in q.Where(i => typeof(IAgent).IsAssignableFrom(i)))
            {
                //Log(MyType.Name);

                var test = (((IAgent)Activator.CreateInstance(MyType,
                                                              BindingFlags.Instance | BindingFlags.NonPublic,
                                                              null,
                                                              new object[]
                {
                    IntPtr.Zero
                },
                                                              null))).RegisteredVtable;
                if (vtables.ContainsKey(test))
                {
                    Log($"\tTrying to add {MyType.Name} {AgentModule.TryAddAgent(vtables[test], MyType)}");
                }
                else
                {
                    Log($"\tFound one {test.ToString("X")} but no agent");
                }
            }
            AddNamespacesToScriptManager(new[] { "LlamaLibrary", "LlamaLibrary.ScriptConditions", "LlamaLibrary.ScriptConditions.Helpers", "LlamaLibrary.ScriptConditions.Extras" });//
            ScriptManager.Init(typeof(ScriptConditions.Helpers));
            initDone = true;
            if (_debug)
            {
                Log($"\n {sb}");
            }
        }
Пример #2
0
        internal static void Init()
        {
            if (initDone)
            {
                return;
            }

            var types = typeof(Offsets).GetFields(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);

            Parallel.ForEach(types, type =>
            {
                var pf = new PatternFinder(Core.Memory);
                if (type.FieldType.IsClass)
                {
                    var instance = Activator.CreateInstance(type.FieldType);


                    foreach (var field in type.FieldType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
                    {
                        var res = ParseField(field, pf);
                        if (field.FieldType == typeof(IntPtr))
                        {
                            field.SetValue(instance, res);
                        }
                        else
                        {
                            field.SetValue(instance, (int)res);
                        }
                    }

                    //set the value
                    type.SetValue(null, instance);
                }
                else
                {
                    var res = ParseField(type, pf);
                    if (type.FieldType == typeof(IntPtr))
                    {
                        type.SetValue(null, res);
                    }
                    else
                    {
                        type.SetValue(null, (int)res);
                    }
                }
            }
                             );

            bool retaineragent     = AgentModule.TryAddAgent(AgentModule.FindAgentIdByVtable(Offsets.AgentRetainerAskVtable), typeof(AgentRetainerVenture));
            bool retainerchar      = AgentModule.TryAddAgent(AgentModule.FindAgentIdByVtable(Offsets.AgentRetainerCharacterVtable), typeof(AgentRetainerCharacter));
            bool dawnAgent         = AgentModule.TryAddAgent(AgentModule.FindAgentIdByVtable(Offsets.DawnVtable), typeof(AgentDawn));
            bool retainerInventory = AgentModule.TryAddAgent(AgentModule.FindAgentIdByVtable(Offsets.AgentRetainerInventoryVtable), typeof(AgentRetainerInventory)); //60
            bool MateriaMelding    = AgentModule.TryAddAgent(AgentModule.FindAgentIdByVtable(Offsets.AgentMeldVtable), typeof(AgentMeld));                           //63
            bool OutOnLimb         = AgentModule.TryAddAgent(AgentModule.FindAgentIdByVtable(Offsets.AgentOutOnLimbVtable), typeof(AgentOutOnLimb));                 //159


            Log($"Added Venture Agent: {retaineragent}");
            Log($"Added RetainerChar Agent: {retainerchar}");
            Log($"Added Dawn(Trust) Agent: {dawnAgent}");
            Log($"Added RetainerInventory Agent: {retainerInventory}");
            Log($"Added MateriaMelding Agent: {MateriaMelding}");
            Log($"Added OutOnLimb Agent: {OutOnLimb} {AgentModule.FindAgentIdByVtable(Offsets.AgentOutOnLimbVtable)}");
            AddNamespacesToScriptManager(new[] { "LlamaLibrary", "LlamaLibrary.ScriptConditions", "LlamaLibrary.ScriptConditions.Helpers" });//
            ScriptManager.Init(typeof(ScriptConditions.Helpers));
            initDone = true;
        }