Esempio n. 1
0
        private bool setupConfigBorCfg(string path)
        {
            savedata conf = new savedata();

            conf.init();

            Directory.CreateDirectory(Path.Combine(path, "Saves"));
            foreach (var file in Directory.GetFiles(Path.Combine(path, "Saves"), "*.cfg"))
            {
                if (Path.GetFileName(file).ToLower() != "default.cfg")
                {
                    File.Delete(file);
                }
            }

            string cfg = Path.Combine(path, "Saves", "default.cfg");

            if (File.Exists(cfg))
            {
                try
                {
                    byte[] bytes = File.ReadAllBytes(cfg);
                    if (bytes.Length >= 320 && bytes[0] == 0x48 && bytes[1] == 0x37 && bytes[2] == 0x03 && bytes[3] == 0x00)
                    {
                        GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                        conf = (savedata)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(savedata));
                        handle.Free();
                    }
                }
                catch
                {
                    return(false);
                }
            }

            setupControllersCfg(conf);

            conf.fullscreen = 1;
            conf.vsync      = 1;
            conf.usegl      = 1;
            conf.stretch    = SystemConfig.isOptSet("ratio") && SystemConfig["ratio"] == "1" ? 1 : 0;

            try
            {
                int    size = Marshal.SizeOf(conf);
                byte[] arr  = new byte[size];

                IntPtr ptr = Marshal.AllocHGlobal(size);
                Marshal.StructureToPtr(conf, ptr, true);
                Marshal.Copy(ptr, arr, 0, size);
                Marshal.FreeHGlobal(ptr);

                File.WriteAllBytes(cfg, arr);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        private void setupControllersCfg(savedata conf)
        {
            if (Program.SystemConfig.isOptSet("disableautocontrollers") && Program.SystemConfig["disableautocontrollers"] == "1")
            {
                return;
            }

            if (!Controllers.Any())
            {
                return;
            }

            bool hasKeyb = false;

            for (int idx = 0; idx < 4; idx++)
            {
                var c = Controllers.FirstOrDefault(j => j.Index == idx + 1);
                if (c == null || c.Input == null)
                {
                    if (hasKeyb)
                    {
                        conf.keys[idx].up         = 0;
                        conf.keys[idx].down       = 0;
                        conf.keys[idx].left       = 0;
                        conf.keys[idx].right      = 0;
                        conf.keys[idx].attack1    = 0;
                        conf.keys[idx].attack2    = 0;
                        conf.keys[idx].attack3    = 0;
                        conf.keys[idx].attack4    = 0;
                        conf.keys[idx].jump       = 0;
                        conf.keys[idx].special    = 0;
                        conf.keys[idx].start      = 0;
                        conf.keys[idx].screenshot = 0;
                        conf.keys[idx].esc        = 0;
                    }
                    else
                    {
                        conf.keys[idx].up         = 82;
                        conf.keys[idx].down       = 81;
                        conf.keys[idx].left       = 80;
                        conf.keys[idx].right      = 79;
                        conf.keys[idx].attack1    = 4;
                        conf.keys[idx].attack2    = 22;
                        conf.keys[idx].attack3    = 29;
                        conf.keys[idx].attack4    = 27;
                        conf.keys[idx].jump       = 7;
                        conf.keys[idx].special    = 9;
                        conf.keys[idx].start      = 40;
                        conf.keys[idx].screenshot = 69;
                        conf.keys[idx].esc        = 41;
                        hasKeyb = true;
                    }

                    continue;
                }

                if (c.Input.Type == "keyboard")
                {
                    hasKeyb                   = true;
                    conf.keys[idx].up         = KeyboardValue(InputKey.up, c);
                    conf.keys[idx].down       = KeyboardValue(InputKey.down, c);
                    conf.keys[idx].left       = KeyboardValue(InputKey.left, c);
                    conf.keys[idx].right      = KeyboardValue(InputKey.right, c);
                    conf.keys[idx].attack1    = KeyboardValue(InputKey.a, c); // ATTACK
                    conf.keys[idx].attack2    = KeyboardValue(InputKey.x, c);
                    conf.keys[idx].attack3    = KeyboardValue(InputKey.y, c);
                    conf.keys[idx].attack4    = KeyboardValue(InputKey.rightshoulder, c); // ATTACK4
                    conf.keys[idx].jump       = KeyboardValue(InputKey.b, c);             // JUMP
                    conf.keys[idx].special    = KeyboardValue(InputKey.select, c);
                    conf.keys[idx].start      = KeyboardValue(InputKey.start, c);
                    conf.keys[idx].screenshot = 69; // F12
                    conf.keys[idx].esc        = 41; // Esc
                    continue;
                }

                conf.keys[idx].up         = JoystickValue(InputKey.up, c);
                conf.keys[idx].down       = JoystickValue(InputKey.down, c);
                conf.keys[idx].left       = JoystickValue(InputKey.left, c);
                conf.keys[idx].right      = JoystickValue(InputKey.right, c);
                conf.keys[idx].attack1    = JoystickValue(InputKey.a, c); // ATTACK
                conf.keys[idx].attack2    = JoystickValue(InputKey.x, c);
                conf.keys[idx].attack3    = JoystickValue(InputKey.y, c);
                conf.keys[idx].attack4    = JoystickValue(InputKey.rightshoulder, c); // ATTACK4
                conf.keys[idx].jump       = JoystickValue(InputKey.b, c);             // JUMP
                conf.keys[idx].special    = JoystickValue(InputKey.select, c);
                conf.keys[idx].start      = JoystickValue(InputKey.start, c);
                conf.keys[idx].screenshot = 0;

                if (Program.EnableHotKeyStart)
                {
                    conf.keys[idx].esc = JoystickValue(InputKey.hotkey, c); // esc
                }
                else
                {
                    conf.keys[idx].esc = 0;
                }
            }
        }