Beispiel #1
0
    private bool GetKeyDown(KKeyCode key_code)
    {
        bool result = false;

        if (key_code >= KKeyCode.KleiKeys)
        {
            switch (key_code)
            {
            case KKeyCode.MouseScrollUp:
                result = mScrollState[0];
                break;

            case KKeyCode.MouseScrollDown:
                result = mScrollState[1];
                break;
            }
        }
        else
        {
            result = Input.GetKeyDown((KeyCode)key_code);
        }
        return(result);
    }
Beispiel #2
0
 public KeyDef(KKeyCode key_code, Modifier modifier)
 {
     mKeyCode     = key_code;
     mModifier    = modifier;
     mActionFlags = new bool[247];
 }
Beispiel #3
0
 public KeyDefEntry(KKeyCode key_code, Modifier modifier)
 {
     mKeyCode  = key_code;
     mModifier = modifier;
 }
Beispiel #4
0
 public void Bind(KKeyCode key_code, Modifier modifier, Action action)
 {
     mBindings.Add(new KInputBinding(key_code, modifier, action));
     mDirtyBindings = true;
 }
Beispiel #5
0
        private void AddDefaultKeybinding(ModuleDefinition CSharpModule, ModuleDefinition firstPassModule, KKeyCode keyCode, Modifier keyModifier, Action action, string screen = "Root")
        {
            var beforeFieldInit = CecilHelper.GetMethodDefinition(firstPassModule, CecilHelper.GetTypeDefinition(firstPassModule, "GameInputMapping"), ".cctor");

            var lastKeybindingDeclarationEnd = beforeFieldInit.Body.Instructions.Last(instruction => instruction.OpCode == OpCodes.Stobj);
            var stoBindingEntryInstruction   = beforeFieldInit.Body.Instructions.First(instruction => instruction.OpCode == OpCodes.Stobj);
            var newBindingEntryInstruction   = beforeFieldInit.Body.Instructions.First(instruction => instruction.OpCode == OpCodes.Newobj);

            var lastDupInstruction = beforeFieldInit.Body.Instructions.LastOrDefault(instr => instr.OpCode == OpCodes.Dup);

            if (lastDupInstruction != null)
            {
                var lastEntryIndex = Convert.ToInt32(lastDupInstruction.Next.Operand);

                var instructionsToAdd = new List <Instruction>
                {
                    Instruction.Create(OpCodes.Dup),
                    Instruction.Create(OpCodes.Ldc_I4, lastEntryIndex + 1), // index
                    Instruction.Create(OpCodes.Ldelema, (TypeReference)stoBindingEntryInstruction.Operand),
                    Instruction.Create(OpCodes.Ldstr, screen),
                    Instruction.Create(OpCodes.Ldc_I4_S, (sbyte)16), // gamepad button
                    Instruction.Create(OpCodes.Ldc_I4, (int)keyCode),
                    Instruction.Create(OpCodes.Ldc_I4, (int)keyModifier),
                    Instruction.Create(OpCodes.Ldc_I4, (int)action),
                    Instruction.Create(OpCodes.Ldc_I4_1), // rebindable = true
                    Instruction.Create(OpCodes.Ldc_I4_1), // ignore root conflicts = true
                    newBindingEntryInstruction,           // create new object
                    stoBindingEntryInstruction            // store in array
                };

                var ILProcessor = beforeFieldInit.Body.GetILProcessor();

                // increase array size by one
                var arraySizeSetInstruction = beforeFieldInit.Body.Instructions.First();
                ILProcessor.Replace(arraySizeSetInstruction, Instruction.Create(OpCodes.Ldc_I4, (int)arraySizeSetInstruction.Operand + 1));
                //

                new InstructionInserter(ILProcessor).InsertAfter(lastKeybindingDeclarationEnd, instructionsToAdd);
            }
            else
            {
                Logger.Log("Can't find last duplication instruction at GameInputMapping.cctor");

                Failed = true;
            }
        }
 public KInputBinding(KKeyCode key_code, Modifier modifier, Action action)
 {
     mKeyCode  = key_code;
     mAction   = action;
     mModifier = modifier;
 }