예제 #1
0
        private static LuaTable ToValueTable <T>(InjectionType type, List <T> array) where T : Injection
        {
            LuaTable table = LuaMain.LuaEnv.NewTable();

            for (int index = 0, realIndex = 0; index < array.Count; index++)
            {
                T injection = array[index];
                if (injection.Type != InjectionType.Space)
                {
                    object value = injection.Value;
                    if (injection.Type == InjectionType.List || injection.Type == InjectionType.Dict)
                    {
                        value = ToValueTable(injection.Type, injection.Value);
                    }
                    if (type == InjectionType.List)
                    {
                        table.Set(realIndex + 1, value);
                    }
                    else
                    {
                        table.Set(injection.Name, value);
                    }
                    realIndex++;
                }
            }
            return(table);
        }
예제 #2
0
 public MemoryInjectionException(InjectionType injectionType, object injectedObject, DateTimeOffset injectionTime)
     : base($"¨The object is injected by {injectionType}")
 {
     InjectionType  = injectionType;
     InjectedObject = injectedObject;
     DetectionTime  = injectionTime;
 }
예제 #3
0
        private uint GetOffset(InjectionType type)
        {
            var settings = Settings;

            return(type switch
            {
                _ => settings.SysBotPouchOffset,
            });
예제 #4
0
        public SysBotRAMEdit(InjectionType type)
        {
            InitializeComponent();
            Bot            = new SysBotController(type);
            RamOffset.Text = Bot.GetDefaultOffset().ToString("X8");

            TB_IP.Text   = Bot.IP;
            TB_Port.Text = Bot.Port;
            Bot.PopPrompt();
        }
예제 #5
0
 public bool Equals(IInjectionMessage other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     return(InjectionType.Equals(other.InjectionType) &&
            (InjectedObject?.Equals(other.InjectedObject) ?? false) &&
            InjectionDetectionTime.Equals(other.InjectionDetectionTime));
 }
예제 #6
0
        public void InjectionType_Returns_CodeInjection()
        {
            //arrange
            const InjectionType expected = InjectionType.CodeInjection;
            var sut = GetSut();
            //act
            var actual = sut.InjectionType;

            //assert
            Assert.That(actual, Is.EqualTo(expected));
        }
예제 #7
0
        private object Resolve(InjectionType injectionType, ContainerKey key)
        {
            switch (injectionType)
            {
            case InjectionType.Singleton: return(Resolve(key));

            case InjectionType.NewInstance: return(ResolveNewInstance(key));

            default: throw new ArgumentException();
            }
        }
예제 #8
0
        public SysBotRAMEdit(InjectionType type)
        {
            InitializeComponent();
            this.TranslateInterface(GameInfo.CurrentLanguage);
            Bot            = new SysBotController(type);
            RamOffset.Text = Bot.GetDefaultOffset().ToString("X8");

            TB_IP.Text   = Bot.IP;
            TB_Port.Text = Bot.Port;
            Bot.PopPrompt();
        }
예제 #9
0
        public SysBotUI(Action <byte[]> read, Func <byte[]> write, InjectionType type)
        {
            InitializeComponent();
            ByteFetch      = write;
            ByteSet        = read;
            Type           = type;
            RamOffset.Text = GetOffset(type).ToString("X8");

            TB_IP.Text   = Settings.SysBotIP;
            TB_Port.Text = Settings.SysBotPort.ToString();

            PopPrompt();
        }
예제 #10
0
        public SysBotUI(Action <byte[]> read, Func <byte[]> write, InjectionType type)
        {
            InitializeComponent();
            Bot            = new SysBotController(type);
            ByteFetch      = write;
            ByteSet        = read;
            RamOffset.Text = Bot.GetDefaultOffset().ToString("X8");

            TB_IP.Text   = Bot.IP;
            TB_Port.Text = Bot.Port;

            Bot.PopPrompt();
        }
예제 #11
0
        public static string GetCrmProviderDefault(InjectionType type)
        {
            switch (type)
            {
            case InjectionType.CSS:
                return(DnnPageHeaderProvider);

            case InjectionType.JavaScript:
                return(DnnBodyProvider);

            default:
                return(string.Empty);
            }
        }
예제 #12
0
        public static void Inject(string libraryPath, int processID, InjectionType type)
        {
            switch (type)
            {
            case InjectionType.LoadLibrary:
                InjectLoadLibrary(libraryPath, processID);
                break;

            case InjectionType.ManualMap:
                InjectManualMap(libraryPath, processID);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
예제 #13
0
        private void comboBoxEdit2_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBoxEdit2.SelectedIndex)
            {
            case 0:     // normal
                m_viewtype = InjectionType.Normal;
                break;

            case 2:     // knock
                m_viewtype = InjectionType.Knocking;
                break;

            case 1:     // idle
                m_viewtype = InjectionType.Idle;
                break;
            }
            RecalculateValues(m_viewtype);
        }
예제 #14
0
파일: DLLInjector.cs 프로젝트: D3AD-E/DeLLa
        //[DllImport("kernel32.dll", SetLastError = true)]
        //static extern bool GetThreadContext(IntPtr hThread, ref CONTEXT lpContext);

        //// Get context of thread x64, in x64 application
        //[DllImport("kernel32.dll", SetLastError = true)]
        //static extern bool GetThreadContext(IntPtr hThread, ref CONTEXT64 lpContext);

        //[DllImport("kernel32.dll", SetLastError = true)]
        //static extern bool SetThreadContext(IntPtr hThread, ref CONTEXT lpContext);

        //// Get context of thread x64, in x64 application
        //[DllImport("kernel32.dll", SetLastError = true)]
        //static extern bool SetThreadContext(IntPtr hThread, ref CONTEXT64 lpContext);

        //[DllImport("kernel32.dll", SetLastError = true)]
        //static extern uint ResumeThread(IntPtr hThread);

        public void InjectDll(string dllPath, string processName, InjectionType injectionType)
        {
            if (string.IsNullOrWhiteSpace(dllPath) || !File.Exists(dllPath))
            {
                throw new ArgumentException("The provided file path did not point to a valid file");
            }

            Process[] processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(processName));

            if (processes.Length == 0)
            {
                throw new ArgumentException("The provided process could not be found");
            }

            Process process = processes[0];

            if (process is null || process.HasExited || process.Handle.Equals(0))
            {
                throw new ArgumentException("The provided process is not currently running");
            }

            if (process == Process.GetCurrentProcess())
            {
                throw new ArgumentException("Cannot inject DLL to injector");
            }

            ProcessMemoryManager = new MemoryManager(process);

            switch (injectionType)
            {
            case InjectionType.Kernell:
                InjectLoadLibraryDependant(dllPath);
                break;

            case InjectionType.Manual:
                InjectManualMap(dllPath);
                break;

            case InjectionType.NtCreateThread:
                InjectCreateRemoteThreadNt(dllPath);
                break;
            }
        }
예제 #15
0
        public void AlertUnnotifiedChanges_WithOnlyCodeProtection_ForDifferentCodeStamps_alerts()
        {
            //arrange
            const InjectionType expectedInjectionType = InjectionType.CodeInjection;
            var alerterMock = new Mock <IInjectionAlerter>();
            var sut         = GetSut(isStateValid: true, isCodeValid: false,
                                     alerter: alerterMock.Object);
            var obj = new object();

            //act
            sut.NotifyChanges(obj);
            sut.AlertUnnotifiedChanges(obj);
            //assert
            alerterMock.Verify((alerter) =>
                               alerter.Alert(
                                   It.Is <IInjectionMessage>(m => m.InjectionType == expectedInjectionType),
                                   It.IsAny <InjectionAlertChannel>()),
                               Times.Once);
        }
        public void AlertUnnotifiedChanges_WithAllProtections_ForDifferentCodeAndStateStamps_Alerts()
        {
            // Arrange
            const InjectionType expectedInjectionType = InjectionType.CodeAndVariableInjection;
            var alerterMock = new Mock <IInjectionAlerter>();
            var sut         = GetSut(isStateValid: false, isCodeValid: false,
                                     alerter: alerterMock.Object);
            var testObject = new object();

            // Act
            sut.NotifyChanges(testObject);
            sut.AlertUnnotifiedChanges(testObject);

            // Assert
            alerterMock.Verify(alerter =>
                               alerter.Alert(
                                   It.Is <IInjectionMessage>(m => m.InjectionType == expectedInjectionType),
                                   It.IsAny <InjectionAlertChannel>()),
                               Times.Once);
        }
예제 #17
0
 public static LuaTable ToValueTable(InjectionType type, object value)
 {
     if (value is List <Injection4> )
     {
         return(ToValueTable(type, value as List <Injection4>));
     }
     else if (value is List <Injection3> )
     {
         return(ToValueTable(type, value as List <Injection3>));
     }
     else if (value is List <Injection2> )
     {
         return(ToValueTable(type, value as List <Injection2>));
     }
     else if (value is List <Injection1> )
     {
         return(ToValueTable(type, value as List <Injection1>));
     }
     else if (value is List <Injection> )
     {
         return(ToValueTable(type, value as List <Injection>));
     }
     return(null);
 }
예제 #18
0
 public MemoryInjectionException(InjectionType injectionType, string message, Exception inner)
     : base(message, inner)
 {
     InjectionType = injectionType;
 }
 public static string GetCrmProviderDefault(InjectionType type)
 {
     switch (type)
     {
         case InjectionType.CSS:
             return DnnPageHeaderProvider;
         case InjectionType.JavaScript:
             return DnnBodyProvider;
         default:
             return string.Empty;
     }
 }
예제 #20
0
        protected virtual void InjectMethodInternal(MethodDefinition method, CustomAttribute attribute, TypeDefinition type, InjectionType injectionType, PropertyDefinition property = null)
        {
            var il     = method.Body.GetILProcessor();
            var module = method.Module;

            // Generate a cloned method
            var newMethod = GenerateMethod(method, module);

            // Mark the new method as compiler-generated
            if (!newMethod.CustomAttributes.Any(c => c.AttributeType.FullName == typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute).FullName))
            {
                newMethod.CustomAttributes.Add(new CustomAttribute(module.Import(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute).GetConstructor(Type.EmptyTypes))));
            }

            // Add the new method to type
            type.Methods.Add(newMethod);

            // Clear the original method body
            method.Body.Instructions.Clear();
            method.Body.ExceptionHandlers.Clear();
            method.Body.Variables.Clear();
            method.Body.Instructions.Add(il.Create(OpCodes.Nop));

            var varIMethodInject = new VariableDefinition(attribute.AttributeType);

            method.Body.Variables.Add(varIMethodInject);
            var varMethodBase = new VariableDefinition(module.Import(typeof(System.Reflection.MemberInfo)));

            method.Body.Variables.Add(varMethodBase);
            var varthis = new VariableDefinition(module.Import(typeof(System.Object)));

            method.Body.Variables.Add(varthis);
            var varparams = new VariableDefinition(module.Import(typeof(object[])));

            method.Body.Variables.Add(varparams);
            var varparams2 = new VariableDefinition(module.Import(typeof(object[])));

            method.Body.Variables.Add(varparams2);
            var varexception = new VariableDefinition(module.Import(typeof(System.Exception)));

            method.Body.Variables.Add(varexception);
            var varMethodExecutionEventArgs = new VariableDefinition(module.Import(typeof(MethodExecutionEventArgs)));

            method.Body.Variables.Add(varMethodExecutionEventArgs);
            var varflag = new VariableDefinition(module.Import(typeof(bool)));

            method.Body.Variables.Add(varflag);
            var varExceptionStrategy = new VariableDefinition(module.Import(typeof(ExceptionStrategy)));

            method.Body.Variables.Add(varExceptionStrategy);
            var vartypeArray = new VariableDefinition(module.Import(typeof(Type[])));

            method.Body.Variables.Add(vartypeArray);
            method.Body.InitLocals = false;

            var lastNop = new[] { il.Create(OpCodes.Nop),
                                  il.Create(OpCodes.Nop),
                                  il.Create(OpCodes.Nop),
                                  (method.ReturnType.FullName != "System.Void")?il.Create(OpCodes.Ldloc_S, varMethodExecutionEventArgs):il.Create(OpCodes.Nop), };

            var lastLeaves = il.Create(OpCodes.Leave_S, lastNop[1]);

            var case1 = il.Create(OpCodes.Br_S, lastNop[0]);
            var case2 = il.Create(OpCodes.Rethrow);
            var case3 = il.Create(OpCodes.Ldloc_S, varMethodExecutionEventArgs);

            il.Append(new[]
            {
                il.Create(OpCodes.Nop),
            });
            if (injectionType == InjectionType.Method || injectionType == InjectionType.Class)
            {
                il.Append(new[]
                {
                    il.Create(OpCodes.Ldtoken, type),
                    il.Create(OpCodes.Call, module.Import(typeof(System.Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(System.RuntimeTypeHandle) }))),
                    il.Create(OpCodes.Ldstr, method.Name),
                    il.Create(OpCodes.Ldc_I4, method.Parameters.Count),
                    il.Create(OpCodes.Newarr, module.Import(typeof(System.Type))),
                    il.Create(OpCodes.Stloc_S, vartypeArray),
                    il.Create(OpCodes.Ldloc_S, vartypeArray),
                });

                var i = 0;
                method.Parameters.ToList().ForEach(t =>
                {
                    il.Append(new[]
                    {
                        il.Create(OpCodes.Ldc_I4, i++),
                        il.Create(OpCodes.Ldtoken, t.ParameterType),
                        il.Create(OpCodes.Call, module.Import(typeof(System.Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(System.RuntimeTypeHandle) }))),
                        il.Create(OpCodes.Stelem_Ref),
                        il.Create(OpCodes.Ldloc_S, vartypeArray),
                    });
                });

                il.Append(new[]
                {
                    il.Create(OpCodes.Call, module.Import(typeof(System.Type).GetMethod("GetMethod", new Type[] { typeof(string), typeof(Type[]) }))),
                    il.Create(OpCodes.Stloc_S, varMethodBase),
                });
            }
            else if (injectionType == InjectionType.Property)
            {
                il.Append(new[]
                {
                    il.Create(OpCodes.Ldtoken, type),
                    il.Create(OpCodes.Call, module.Import(typeof(System.Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(System.RuntimeTypeHandle) }))),
                    il.Create(OpCodes.Ldstr, property.Name),
                    il.Create(OpCodes.Ldtoken, method.IsGetter?method.ReturnType:method.Parameters[0].ParameterType),
                    il.Create(OpCodes.Call, module.Import(typeof(System.Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(System.RuntimeTypeHandle) }))),
                    il.Create(OpCodes.Call, module.Import(typeof(System.Type).GetMethod("GetProperty", new Type[] { typeof(string), typeof(Type) }))),
                    il.Create(OpCodes.Stloc_S, varMethodBase),
                });
            }

            if (injectionType == InjectionType.Method || injectionType == InjectionType.Property)
            {
                il.Append(il.Create(OpCodes.Ldloc_S, varMethodBase));
            }
            else if (injectionType == InjectionType.Class)
            {
                il.Append(new[]
                {
                    il.Create(OpCodes.Ldtoken, type),
                    il.Create(OpCodes.Call, module.Import(typeof(System.Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(System.RuntimeTypeHandle) }))),
                });
            }

            il.Append(new[]
            {
                il.Create(OpCodes.Ldtoken, attribute.AttributeType),
                il.Create(OpCodes.Call, module.Import(typeof(System.Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(System.RuntimeTypeHandle) }))),
                il.Create(OpCodes.Ldc_I4_0),
                il.Create(OpCodes.Callvirt, module.Import(typeof(System.Reflection.MemberInfo).GetMethod("GetCustomAttributes", new Type[] { typeof(System.Type), typeof(bool) }))),
                il.Create(OpCodes.Ldc_I4_0),
                il.Create(OpCodes.Ldelem_Ref),
                il.Create(OpCodes.Isinst, attribute.AttributeType),
                il.Create(OpCodes.Stloc_S, varIMethodInject),
                il.Create(OpCodes.Nop),
            });

            if (!method.IsStatic)
            {
                il.Append(new[] {
                    il.Create(OpCodes.Ldarg_S, method.Body.ThisParameter),
                });
            }
            else
            {
                il.Append(new[] {
                    il.Create(OpCodes.Ldnull),
                });
            }

            il.Append(new[] {
                il.Create(OpCodes.Stloc_S, varthis),
                il.Create(OpCodes.Ldc_I4, method.Parameters.Count),
                il.Create(OpCodes.Newarr, module.Import(typeof(object))),
                il.Create(OpCodes.Stloc_S, varparams2),
                il.Create(OpCodes.Ldloc_S, varparams2),
            });

            var j = 0;

            method.Parameters.ToList().ForEach(t =>
            {
                il.Append(new[] {
                    il.Create(OpCodes.Ldc_I4, j++),
                    il.Create(OpCodes.Ldarg_S, t),
                    il.Create(OpCodes.Box, t.ParameterType),
                    il.Create(OpCodes.Stelem_Ref),
                    il.Create(OpCodes.Ldloc_S, varparams2)
                });
            });


            il.Append(new[] {
                il.Create(OpCodes.Stloc_S, varparams),
                il.Create(OpCodes.Ldloc_S, varMethodBase),
                il.Create(OpCodes.Ldloc_S, varthis),
                il.Create(OpCodes.Ldloc_S, varparams),
            });

            if (method.ReturnType.IsValueType)
            {
                il.Append(new[] {
                    il.Create(OpCodes.Ldstr, method.ReturnType.FullName),
                });
            }
            else
            {
                il.Append(new[] {
                    il.Create(OpCodes.Ldnull),
                });
            }

            il.Append(new[] {
                il.Create(OpCodes.Newobj, module.Import(typeof(MethodExecutionEventArgs).GetConstructor(
                                                            new Type[] { typeof(System.Reflection.MethodBase), typeof(object), typeof(object[]), typeof(string) }))),
                il.Create(OpCodes.Stloc_S, varMethodExecutionEventArgs),
            });

            //if (method.ReturnType.FullName != "System.Void")
            //{
            //    ILProcessorExsions.Append(il, new[] {
            //      il.Create(OpCodes.Ldloc_S,varMethodExecutionEventArgs),
            //    });

            //    if (method.ReturnType.IsValueType)
            //    {
            //        //method.Body.InitLocals = false;
            //        var varreturnValueDefault = new VariableDefinition(method.ReturnType);
            //        method.Body.Variables.Add(varreturnValueDefault);
            //        ILProcessorExsions.Append(il, new[] {
            //        il.Create(OpCodes.Ldloc_S,varreturnValueDefault),
            //        il.Create(OpCodes.Initobj,method.ReturnType ),
            //        il.Create(OpCodes.Ldloc_S,varreturnValueDefault),
            //        il.Create(OpCodes.Box,method.ReturnType),
            //    });
            //    }
            //    else
            //    {
            //        ILProcessorExsions.Append(il, new[] {
            //            il.Create(OpCodes.Ldnull ),
            //        });

            //    }

            //    ILProcessorExsions.Append(il, new[] {
            //        il.Create(OpCodes.Callvirt,module.Import(typeof(Green.AOP.MethodExecutionEventArgs).GetMethod("set_ReturnValue",new Type[]{typeof(System.Object)}))),
            //    });
            //}



            il.Append(new[] {
                il.Create(OpCodes.Nop),
                il.Create(OpCodes.Ldloc_S, varIMethodInject),
                il.Create(OpCodes.Ldloc_S, varMethodExecutionEventArgs),
                il.Create(OpCodes.Callvirt, module.Import(typeof(IMethodInterceptor).GetMethod("BeforeExecute", new Type[] { typeof(MethodExecutionEventArgs) }))),
                il.Create(OpCodes.Ldc_I4_0),
                il.Create(OpCodes.Ceq),
                il.Create(OpCodes.Stloc_S, varflag),
                il.Create(OpCodes.Ldloc_S, varflag),
                il.Create(OpCodes.Brtrue_S, lastNop[3]),
                il.Create(OpCodes.Nop),
            });
            var trySatrt = il.Create(OpCodes.Nop);

            il.Append(new[] {
                trySatrt,
                il.Create(OpCodes.Ldloc_S, varMethodExecutionEventArgs),
            });

            if (!method.IsStatic)
            {
                method.Body.Instructions.Add(il.Create(OpCodes.Ldarg_0));//Load this;
            }
            method.Parameters.ToList().ForEach(t => { method.Body.Instructions.Add(il.Create(OpCodes.Ldarg_S, t)); });

            method.Body.Instructions.Add(il.Create(OpCodes.Call, newMethod));
            if (method.ReturnType.FullName != "System.Void")
            {
                il.Append(new[]
                {
                    il.Create(OpCodes.Box, method.ReturnType),
                    il.Create(OpCodes.Callvirt, module.Import(typeof(MethodExecutionEventArgs).GetMethod("set_ReturnValue", new Type[] { typeof(System.Object) }))),
                    il.Create(OpCodes.Nop),
                });
            }
            else
            {
                method.Body.Instructions.Add(il.Create(OpCodes.Nop));
            }

            var tryEnd = il.Create(OpCodes.Stloc_S, varexception);

            il.Append(new[]
            {
                il.Create(OpCodes.Ldloc_S, varIMethodInject),
                il.Create(OpCodes.Ldloc_S, varMethodExecutionEventArgs),
                il.Create(OpCodes.Callvirt, module.Import(typeof(IMethodInterceptor).GetMethod("AfterExecute", new Type[] { typeof(MethodExecutionEventArgs) }))),
                il.Create(OpCodes.Nop),
                il.Create(OpCodes.Nop),
                il.Create(OpCodes.Leave_S, lastNop[1]),
                tryEnd,
                il.Create(OpCodes.Nop),
                il.Create(OpCodes.Ldloc_S, varMethodExecutionEventArgs),
                il.Create(OpCodes.Ldloc_S, varexception),
                il.Create(OpCodes.Callvirt, module.Import(typeof(MethodExecutionEventArgs).GetMethod("set_Exception", new Type[] { typeof(System.Exception) }))),
                il.Create(OpCodes.Nop),
                il.Create(OpCodes.Ldloc_S, varIMethodInject),
                il.Create(OpCodes.Ldloc_S, varMethodExecutionEventArgs),
                il.Create(OpCodes.Callvirt, module.Import(typeof(IMethodInterceptor).GetMethod("OnExecption", new Type[] { typeof(MethodExecutionEventArgs) }))),
                il.Create(OpCodes.Stloc_S, varExceptionStrategy),
                il.Create(OpCodes.Ldloc_S, varExceptionStrategy),
                il.Create(OpCodes.Switch, new [] { case1, case2, case3 }),
                il.Create(OpCodes.Br_S, lastNop[0]),
                case1,
                case2,
                case3,
                il.Create(OpCodes.Callvirt, module.Import(typeof(MethodExecutionEventArgs).GetMethod("get_Exception", new Type[] {}))),
                il.Create(OpCodes.Throw),
            });

            il.Append(new[] {
                lastNop[0],
                lastLeaves,
                lastNop[1],
                lastNop[2],
                lastNop[3],
            });
            if (method.ReturnType.FullName != "System.Void")
            {
                var varreturnValue = new VariableDefinition(method.ReturnType);
                method.Body.Variables.Add(varreturnValue);
                var lastreturn = il.Create(OpCodes.Ldloc_S, varreturnValue);
                il.Append(new[] {
                    il.Create(OpCodes.Callvirt, module.Import(typeof(MethodExecutionEventArgs).GetMethod("get_ReturnValue", new Type[] {}))),
                    il.Create(OpCodes.Unbox_Any, method.ReturnType),
                    il.Create(OpCodes.Stloc_S, varreturnValue),
                    il.Create(OpCodes.Br_S, lastreturn),
                    lastreturn,
                });
            }

            method.Body.Instructions.Add(il.Create(OpCodes.Ret));
            method.Body.ExceptionHandlers.Add(new ExceptionHandler(ExceptionHandlerType.Catch)
            {
                HandlerEnd   = lastNop[1],
                HandlerStart = tryEnd,
                TryEnd       = tryEnd,
                TryStart     = trySatrt,
                CatchType    = module.Import(typeof(System.Exception))
            });
        }
예제 #21
0
 public InjectionAttribute(string name = "default", InjectionType injectionType = InjectionType.NewInstance)
 {
     Name          = name;
     InjectionType = injectionType;
 }
예제 #22
0
        public void CalculateInjectionTiming(InjectionType type)
        {
            gridView1.Columns.Clear();
            switch (type)
            {
            case InjectionType.Normal:
                if (fuel_map_x_axis.Length > 0 && fuel_map_y_axis.Length > 0 && insp_mat.Length > 0)
                {
                    // fill table
                    DataTable dt   = new DataTable();
                    object[]  vals = new object[fuel_map_x_axis.Length];
                    int       idx  = 0;
                    foreach (int pressure in fuel_map_x_axis)
                    {
                        dt.Columns.Add(pressure.ToString());
                    }
                    int rpm_index = 0;
                    for (int i = fuel_map_y_axis.Length - 1; i >= 0; i--)
                    //foreach (int rpm in fuel_map_y_axis)
                    {
                        int rpm      = fuel_map_y_axis[i];
                        int mapindex = 0;
                        foreach (int pressureit in fuel_map_x_axis)
                        {
                            int pressure = pressureit;
                            if (m_mapSensor == MapSensorType.MapSensor30)
                            {
                                pressure *= 120;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor35)
                            {
                                pressure *= 140;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor40)
                            {
                                pressure *= 160;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor50)
                            {
                                pressure *= 200;
                                pressure /= 100;
                            }
                            int Lufttemp_faktor = GetLuftTempFactor(m_iat);
                            int P_manifold10    = pressure * 10;
                            int Last            = 0;
                            int Medellast       = 0;
                            if ((((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512) < 255)
                            {
                                Last = ((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512;
                            }
                            else
                            {
                                Last = 255;
                            }
                            Medellast = Last;
                            //Console.WriteLine(pressure.ToString() + " gives medellast: " + Medellast.ToString());
                            int   cellvalue          = (int)Handle_tables(rpm, (byte)Medellast, fuel_map_y_axis.Length, fuel_map_x_axis.Length, insp_mat, fuel_map_y_axis, fuel_map_x_axis);
                            int   injection_duration = CalculateInjectionTime(pressure, m_iat);
                            float inj_dur_ms         = injection_duration * (((float)cellvalue + 128) / 256);


                            if (batt_volt >= 14)
                            {
                                batt_volt = 14;
                            }
                            else if (batt_volt < 5)
                            {
                                batt_volt = 4;
                            }
                            int Batt_korr = Batt_korr_tab[14 - batt_volt];

                            inj_dur_ms += Batt_korr;


                            if (inj_dur_ms >= 32500)
                            {
                                inj_dur_ms = 32500;
                            }

                            if (inj_dur_ms <= min_tid)
                            {
                                inj_dur_ms = min_tid;
                            }
                            float Injection_timems10 = inj_dur_ms / 25;
                            float temp = 6000000 / (float)rpm;
                            //float dutycycle = ((Injection_timems10) / temp) * 100;

                            inj_dur_ms /= 250;
                            float dutycycle = (rpm * inj_dur_ms) / 1200;

                            // for fun, take Fload_tab into account
                            //Console.WriteLine("InjTiming Converting pressure: " + pressure.ToString() + " rpm: " + rpm.ToString() + " dc: " + dutycycle.ToString() + " ms: " + inj_dur_ms.ToString());

                            vals.SetValue(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2"), mapindex);
                            //Console.WriteLine(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2") + " mapidx: " + mapindex.ToString());
                            mapindex++;
                        }
                        dt.Rows.Add(vals);
                        rpm_index++;
                    }
                    gridControl1.DataSource = dt;
                }
                break;

            case InjectionType.Knocking:
                if (fuel_knock_map_x_axis.Length > 0 && fuel_knock_map_y_axis.Length > 0 && fuel_knock_mat.Length > 0)
                {
                    // fill table
                    DataTable dt   = new DataTable();
                    object[]  vals = new object[fuel_knock_map_x_axis.Length];
                    int       idx  = 0;
                    foreach (int pressure in fuel_knock_map_x_axis)
                    {
                        dt.Columns.Add(pressure.ToString());
                    }
                    int rpm_index = 0;
                    for (int i = fuel_knock_map_y_axis.Length - 1; i >= 0; i--)
                    //foreach (int rpm in fuel_map_y_axis)
                    {
                        int rpm      = fuel_knock_map_y_axis[i];
                        int mapindex = 0;
                        foreach (int pressureit in fuel_knock_map_x_axis)
                        {
                            int pressure = pressureit;
                            if (m_mapSensor == MapSensorType.MapSensor30)
                            {
                                pressure *= 120;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor35)
                            {
                                pressure *= 140;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor40)
                            {
                                pressure *= 160;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor50)
                            {
                                pressure *= 200;
                                pressure /= 100;
                            }
                            int Lufttemp_faktor = GetLuftTempFactor(m_iat);
                            int P_manifold10    = pressure * 10;
                            int Last            = 0;
                            int Medellast       = 0;
                            if ((((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512) < 255)
                            {
                                Last = ((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512;
                            }
                            else
                            {
                                Last = 255;
                            }
                            Medellast = Last;
                            int   cellvalue          = (int)Handle_tables(rpm, (byte)Medellast, fuel_knock_map_y_axis.Length, fuel_knock_map_x_axis.Length, fuel_knock_mat, fuel_knock_map_y_axis, fuel_knock_map_x_axis);
                            int   injection_duration = CalculateInjectionTime(pressure, m_iat);
                            float inj_dur_ms         = injection_duration * (((float)cellvalue + 128) / 256);
                            if (batt_volt >= 14)
                            {
                                batt_volt = 14;
                            }
                            else if (batt_volt < 5)
                            {
                                batt_volt = 4;
                            }
                            int Batt_korr = Batt_korr_tab[14 - batt_volt];

                            inj_dur_ms += Batt_korr;

                            if (inj_dur_ms >= 32500)
                            {
                                inj_dur_ms = 32500;
                            }

                            if (inj_dur_ms <= min_tid)
                            {
                                inj_dur_ms = min_tid;
                            }
                            float Injection_timems10 = inj_dur_ms / 25;
                            float temp = 6000000 / (float)rpm;
                            //float dutycycle = ((float)(Injection_timems10) / temp) * 100;

                            inj_dur_ms /= 250;
                            float dutycycle = (rpm * inj_dur_ms) / 1200;
                            vals.SetValue(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2"), mapindex);
                            //Console.WriteLine(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2") + " mapidx: " + mapindex.ToString());

                            mapindex++;
                        }
                        dt.Rows.Add(vals);
                        rpm_index++;
                    }
                    gridControl1.DataSource = dt;
                }

                break;

            case InjectionType.Idle:

                if (idle_fuel_x_axis.Length > 0 && idle_fuel_y_axis.Length > 0 && idle_fuel_map.Length > 0)
                {
                    // fill table
                    DataTable dt   = new DataTable();
                    object[]  vals = new object[idle_fuel_x_axis.Length];
                    int       idx  = 0;
                    foreach (int pressure in idle_fuel_x_axis)
                    {
                        dt.Columns.Add(pressure.ToString());
                    }
                    int rpm_index = 0;
                    for (int i = idle_fuel_y_axis.Length - 1; i >= 0; i--)
                    //foreach (int rpm in fuel_map_y_axis)
                    {
                        int rpm      = idle_fuel_y_axis[i];
                        int mapindex = 0;
                        foreach (int pressureit in idle_fuel_x_axis)
                        {
                            int pressure = pressureit;
                            if (m_mapSensor == MapSensorType.MapSensor30)
                            {
                                pressure *= 120;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor35)
                            {
                                pressure *= 140;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor40)
                            {
                                pressure *= 160;
                                pressure /= 100;
                            }
                            else if (m_mapSensor == MapSensorType.MapSensor50)
                            {
                                pressure *= 200;
                                pressure /= 100;
                            }
                            int Lufttemp_faktor = GetLuftTempFactor(m_iat);
                            int P_manifold10    = pressure * 10;
                            int Last            = 0;
                            int Medellast       = 0;
                            if ((((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512) < 255)
                            {
                                Last = ((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512;
                            }
                            else
                            {
                                Last = 255;
                            }
                            Medellast = Last;
                            int   cellvalue          = (int)Handle_tables(rpm, (byte)Medellast, idle_fuel_y_axis.Length, idle_fuel_x_axis.Length, idle_fuel_map, idle_fuel_y_axis, idle_fuel_x_axis);
                            int   injection_duration = CalculateInjectionTime(pressure, m_iat);
                            float inj_dur_ms         = injection_duration * (((float)cellvalue + 128) / 256);
                            if (batt_volt >= 14)
                            {
                                batt_volt = 14;
                            }
                            else if (batt_volt < 5)
                            {
                                batt_volt = 4;
                            }
                            int Batt_korr = Batt_korr_tab[14 - batt_volt];

                            inj_dur_ms += Batt_korr;

                            if (inj_dur_ms >= 32500)
                            {
                                inj_dur_ms = 32500;
                            }

                            if (inj_dur_ms <= min_tid)
                            {
                                inj_dur_ms = min_tid;
                            }
                            float Injection_timems10 = inj_dur_ms / 25;
                            float temp = 6000000 / (float)rpm;
                            //float dutycycle = ((float)(Injection_timems10) / temp) * 100;

                            inj_dur_ms /= 250;
                            float dutycycle = (rpm * inj_dur_ms) / 1200;
                            vals.SetValue(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2"), mapindex);
                            //Console.WriteLine(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2") + " mapidx: " + mapindex.ToString());

                            mapindex++;
                        }
                        dt.Rows.Add(vals);
                        rpm_index++;
                    }
                    gridControl1.DataSource = dt;
                }
                break;
            }
        }
예제 #23
0
 public SysBotController(InjectionType type) => Type = type;
예제 #24
0
        private void comboBoxEdit2_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBoxEdit2.SelectedIndex)
            {
                case 0: // normal
                    m_viewtype = InjectionType.Normal;
                    break;
                case 2: // knock
                    m_viewtype = InjectionType.Knocking;
                    break;
                case 1: // idle
                    m_viewtype = InjectionType.Idle;
                    break;

            }
            RecalculateValues(m_viewtype);
        }
예제 #25
0
 private void RecalculateValues(InjectionType type)
 {
     CalculateInjectionTiming(type);
 }
예제 #26
0
        public void CalculateInjectionTiming(InjectionType type)
        {
            gridView1.Columns.Clear();
            switch (type)
            {
                case InjectionType.Normal:
                    if (fuel_map_x_axis.Length > 0 && fuel_map_y_axis.Length > 0 && insp_mat.Length > 0)
                    {
                        // fill table
                        DataTable dt = new DataTable();
                        object[] vals = new object[fuel_map_x_axis.Length];
                        int idx = 0;
                        foreach (int pressure in fuel_map_x_axis)
                        {
                            dt.Columns.Add(pressure.ToString());
                        }
                        int rpm_index = 0;
                        for(int i = fuel_map_y_axis.Length -1; i >= 0; i --)
                        //foreach (int rpm in fuel_map_y_axis)
                        {
                            int rpm = fuel_map_y_axis[i];
                            int mapindex = 0;
                            foreach (int pressureit in fuel_map_x_axis)
                            {
                                int pressure = pressureit;
                                if (m_mapSensor == MapSensorType.MapSensor30)
                                {
                                    pressure *= 120;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor35)
                                {
                                    pressure *= 140;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor40)
                                {
                                    pressure *= 160;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor50)
                                {
                                    pressure *= 200;
                                    pressure /= 100;
                                }
                                int Lufttemp_faktor = GetLuftTempFactor(m_iat);
                                int P_manifold10 = pressure * 10;
                                int Last = 0;
                                int Medellast = 0;
                                if ((((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512) < 255)
                                {
                                    Last = ((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512;
                                }
                                else
                                {
                                    Last = 255;
                                }
                                Medellast = Last;
                                //Console.WriteLine(pressure.ToString() + " gives medellast: " + Medellast.ToString());
                                int cellvalue = (int)Handle_tables(rpm, (byte)Medellast, fuel_map_y_axis.Length, fuel_map_x_axis.Length, insp_mat, fuel_map_y_axis, fuel_map_x_axis);
                                int injection_duration = CalculateInjectionTime(pressure, m_iat);
                                float inj_dur_ms = injection_duration * (((float)cellvalue + 128) / 256);

                                if (batt_volt >= 14)
                                {
                                    batt_volt = 14;
                                }
                                else if (batt_volt < 5)
                                {
                                    batt_volt = 4;
                                }
                                int Batt_korr = Batt_korr_tab[14 - batt_volt];

                                inj_dur_ms += Batt_korr;

                                if (inj_dur_ms >= 32500)
                                {
                                    inj_dur_ms = 32500;
                                }

                                if (inj_dur_ms <= min_tid)
                                {
                                    inj_dur_ms = min_tid;
                                }
                                float Injection_timems10 = inj_dur_ms / 25;
                                float temp = 6000000 / (float)rpm;
                                //float dutycycle = ((Injection_timems10) / temp) * 100;

                                inj_dur_ms /= 250;
                                float dutycycle = (rpm * inj_dur_ms) / 1200;

                                // for fun, take Fload_tab into account
                                //Console.WriteLine("InjTiming Converting pressure: " + pressure.ToString() + " rpm: " + rpm.ToString() + " dc: " + dutycycle.ToString() + " ms: " + inj_dur_ms.ToString());

                                vals.SetValue(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2"), mapindex);
                                //Console.WriteLine(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2") + " mapidx: " + mapindex.ToString());
                                mapindex++;
                            }
                            dt.Rows.Add(vals);
                            rpm_index++;
                        }
                        gridControl1.DataSource = dt;
                    }
                    break;
                case InjectionType.Knocking:
                    if (fuel_knock_map_x_axis.Length > 0 && fuel_knock_map_y_axis.Length > 0 && fuel_knock_mat.Length > 0)
                    {
                        // fill table
                        DataTable dt = new DataTable();
                        object[] vals = new object[fuel_knock_map_x_axis.Length];
                        int idx = 0;
                        foreach (int pressure in fuel_knock_map_x_axis)
                        {
                            dt.Columns.Add(pressure.ToString());
                        }
                        int rpm_index = 0;
                        for (int i = fuel_knock_map_y_axis.Length - 1; i >= 0; i--)
                        //foreach (int rpm in fuel_map_y_axis)
                        {
                            int rpm = fuel_knock_map_y_axis[i];
                            int mapindex = 0;
                            foreach (int pressureit in fuel_knock_map_x_axis)
                            {
                                int pressure = pressureit;
                                if (m_mapSensor == MapSensorType.MapSensor30)
                                {
                                    pressure *= 120;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor35)
                                {
                                    pressure *= 140;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor40)
                                {
                                    pressure *= 160;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor50)
                                {
                                    pressure *= 200;
                                    pressure /= 100;
                                }
                                int Lufttemp_faktor = GetLuftTempFactor(m_iat);
                                int P_manifold10 = pressure * 10;
                                int Last = 0;
                                int Medellast = 0;
                                if ((((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512) < 255)
                                {
                                    Last = ((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512;
                                }
                                else
                                {
                                    Last = 255;
                                }
                                Medellast = Last;
                                int cellvalue = (int)Handle_tables(rpm, (byte)Medellast, fuel_knock_map_y_axis.Length, fuel_knock_map_x_axis.Length, fuel_knock_mat, fuel_knock_map_y_axis, fuel_knock_map_x_axis);
                                int injection_duration = CalculateInjectionTime(pressure, m_iat);
                                float inj_dur_ms = injection_duration * (((float)cellvalue + 128) / 256);
                                if (batt_volt >= 14)
                                {
                                    batt_volt = 14;
                                }
                                else if (batt_volt < 5)
                                {
                                    batt_volt = 4;
                                }
                                int Batt_korr = Batt_korr_tab[14 - batt_volt];

                                inj_dur_ms += Batt_korr;

                                if (inj_dur_ms >= 32500)
                                {
                                    inj_dur_ms = 32500;
                                }

                                if (inj_dur_ms <= min_tid)
                                {
                                    inj_dur_ms = min_tid;
                                }
                                float Injection_timems10 = inj_dur_ms / 25;
                                float temp = 6000000 / (float)rpm;
                                //float dutycycle = ((float)(Injection_timems10) / temp) * 100;

                                inj_dur_ms /= 250;
                                float dutycycle = (rpm * inj_dur_ms) / 1200;
                                vals.SetValue(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2"), mapindex);
                                //Console.WriteLine(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2") + " mapidx: " + mapindex.ToString());

                                mapindex++;
                            }
                            dt.Rows.Add(vals);
                            rpm_index++;
                        }
                        gridControl1.DataSource = dt;
                    }

                    break;
                case InjectionType.Idle:

                    if (idle_fuel_x_axis.Length > 0 && idle_fuel_y_axis.Length > 0 && idle_fuel_map.Length > 0)
                    {
                        // fill table
                        DataTable dt = new DataTable();
                        object[] vals = new object[idle_fuel_x_axis.Length];
                        int idx = 0;
                        foreach (int pressure in idle_fuel_x_axis)
                        {
                            dt.Columns.Add(pressure.ToString());
                        }
                        int rpm_index = 0;
                        for (int i = idle_fuel_y_axis.Length - 1; i >= 0; i--)
                        //foreach (int rpm in fuel_map_y_axis)
                        {
                            int rpm = idle_fuel_y_axis[i];
                            int mapindex = 0;
                            foreach (int pressureit in idle_fuel_x_axis)
                            {
                                int pressure = pressureit;
                                if (m_mapSensor == MapSensorType.MapSensor30)
                                {
                                    pressure *= 120;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor35)
                                {
                                    pressure *= 140;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor40)
                                {
                                    pressure *= 160;
                                    pressure /= 100;
                                }
                                else if (m_mapSensor == MapSensorType.MapSensor50)
                                {
                                    pressure *= 200;
                                    pressure /= 100;
                                }
                                int Lufttemp_faktor = GetLuftTempFactor(m_iat);
                                int P_manifold10 = pressure * 10;
                                int Last = 0;
                                int Medellast = 0;
                                if ((((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512) < 255)
                                {
                                    Last = ((Lufttemp_faktor + 384) * (P_manifold10 / 10)) / 512;
                                }
                                else
                                {
                                    Last = 255;
                                }
                                Medellast = Last;
                                int cellvalue = (int)Handle_tables(rpm, (byte)Medellast, idle_fuel_y_axis.Length, idle_fuel_x_axis.Length, idle_fuel_map, idle_fuel_y_axis, idle_fuel_x_axis);
                                int injection_duration = CalculateInjectionTime(pressure, m_iat);
                                float inj_dur_ms = injection_duration * (((float)cellvalue + 128) / 256);
                                if (batt_volt >= 14)
                                {
                                    batt_volt = 14;
                                }
                                else if (batt_volt < 5)
                                {
                                    batt_volt = 4;
                                }
                                int Batt_korr = Batt_korr_tab[14 - batt_volt];

                                inj_dur_ms += Batt_korr;

                                if (inj_dur_ms >= 32500)
                                {
                                    inj_dur_ms = 32500;
                                }

                                if (inj_dur_ms <= min_tid)
                                {
                                    inj_dur_ms = min_tid;
                                }
                                float Injection_timems10 = inj_dur_ms / 25;
                                float temp = 6000000 / (float)rpm;
                                //float dutycycle = ((float)(Injection_timems10) / temp) * 100;

                                inj_dur_ms /= 250;
                                float dutycycle = (rpm * inj_dur_ms) / 1200;
                                vals.SetValue(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2"), mapindex);
                                //Console.WriteLine(inj_dur_ms.ToString("F2") + "/" + dutycycle.ToString("F2") + " mapidx: " + mapindex.ToString());

                                mapindex++;
                            }
                            dt.Rows.Add(vals);
                            rpm_index++;
                        }
                        gridControl1.DataSource = dt;
                    }
                    break;
            }
        }
예제 #27
0
 private void RecalculateValues(InjectionType type)
 {
     CalculateInjectionTiming(type);
 }
    private object DrawValue <T>(InjectionType type, object value) where T : Injection, new()
    {
        switch (type)
        {
        case InjectionType.String:
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.TextArea(JsonParser.ObjectToString(value ?? ""));
            break;

        case InjectionType.Int:
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.IntField(JsonParser.ObjectToInt(value));
            break;

        case InjectionType.Float:
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.FloatField(JsonParser.ObjectToFloat(value));
            break;

        case InjectionType.Boolean:
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.Toggle(JsonParser.ObjectToBool(value));
            break;

        case InjectionType.Curve:
            AnimationCurve curve = value as AnimationCurve;
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.CurveField(curve ?? new AnimationCurve());
            break;

        case InjectionType.Color:
            Color color = (Color)value;
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.ColorField(color);
            break;

        case InjectionType.Vector2:
            Vector2 vector2 = (Vector2)value;
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.Vector2Field("", vector2);
            break;

        case InjectionType.Vector3:
            Vector3 vector3 = (Vector3)value;
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.Vector3Field("", vector3);
            break;

        case InjectionType.Vector4:
            Vector4 vector4 = (Vector4)value;
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.Vector4Field("", vector4);
            break;

        case InjectionType.Object:
            Object obj = value as Object;
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.ObjectField(obj, typeof(Object), true);
            break;

        case InjectionType.GameObject:
            GameObject go = null;
            if (value is GameObject)
            {
                go = value as GameObject;
            }
            else if (value is Component)
            {
                go = (value as Component).gameObject;
            }
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.ObjectField(go, typeof(GameObject), true);
            break;

        case InjectionType.Transform:
            Transform trans = null;
            if (value is Transform)
            {
                trans = value as Transform;
            }
            else if (value is Component)
            {
                trans = (value as Component).transform;
            }
            else if (value is GameObject)
            {
                trans = (value as GameObject).transform;
            }
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            value = EditorGUILayout.ObjectField(trans, typeof(Transform), true);
            break;

        case InjectionType.Behaviour:
            Behaviour behaviour = null;
            if (value is Behaviour)
            {
                behaviour = value as Behaviour;
            }
            else if (value is Component)
            {
                behaviour = (value as Component).GetComponent <Behaviour>();
            }
            else if (value is GameObject)
            {
                behaviour = (value as GameObject).GetComponent <Behaviour>();
            }
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            Behaviour currentBehaviour = EditorGUILayout.ObjectField(behaviour, typeof(Behaviour), true) as Behaviour;
            if (currentBehaviour)
            {
                Behaviour[] behaviours      = currentBehaviour.GetComponents <Behaviour>();
                int         behaviourCount  = behaviours.Length;
                string[]    behaviourNames  = new string[behaviourCount];
                int[]       behaviourIndexs = new int[behaviourCount];
                for (int index = 0; index < behaviourCount; index++)
                {
                    behaviourNames[index]  = index + "." + behaviours[index].GetType().Name;
                    behaviourIndexs[index] = index;
                }

                Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
                int currentIndex   = behaviours.IndexOf(currentBehaviour);
                int behaviourIndex = EditorGUILayout.IntPopup(currentIndex, behaviourNames, behaviourIndexs);
                if (behaviourIndex != currentIndex)
                {
                    currentBehaviour = behaviours[behaviourIndex];
                }
            }
            value = currentBehaviour;
            break;

        case InjectionType.OtherComp:
            Component comp = null;
            if (value is Component)
            {
                comp = value as Component;
            }
            else if (value is GameObject)
            {
                comp = (value as GameObject).GetComponent <Component>();
            }
            GUILayout.Label("Value:", GUILayout.Width(40F));
            Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
            Component currentComp = EditorGUILayout.ObjectField(comp, typeof(Component), true) as Component;
            if (currentComp)
            {
                Component[]      components = currentComp.GetComponents <Component>();
                List <Component> compList   = new List <Component>();
                foreach (Component component in components)
                {
                    if (!(component is Behaviour))
                    {
                        compList.Add(component);
                    }
                }
                int compCount = compList.Count;
                if (compCount > 0)
                {
                    string[] compNames  = new string[compCount];
                    int[]    compIndexs = new int[compCount];
                    for (int index = 0; index < compCount; index++)
                    {
                        compNames[index]  = index + "." + compList[index].GetType().Name;
                        compIndexs[index] = index;
                    }
                    int currentIndex = compList.IndexOf(currentComp);
                    if (currentIndex != -1)
                    {
                        Undo.RecordObject(m_LuaInjectionData, "Injection.Value");
                        int behaviourIndex = EditorGUILayout.IntPopup(currentIndex, compNames, compIndexs);
                        if (behaviourIndex != currentIndex)
                        {
                            currentComp = compList[behaviourIndex];
                        }
                    }
                    else
                    {
                        currentComp = compList[0];
                    }
                }
                else
                {
                    currentComp = null;
                }
            }
            value = currentComp;
            break;
        }
        return(value);
    }
예제 #29
0
 public MemoryInjectionException(Exception inner, InjectionType injectionType) : base(inner)
 {
     InjectionType = injectionType;
 }
예제 #30
0
 /// <summary>
 /// Construtor.
 /// </summary>
 /// <param name="injectionType">Tipo de injeção de dependência.</param>
 public InjectionTypeAttribute(InjectionType injectionType)
 {
     InjectionType = injectionType;
 }