| 
4 | 4 | 
 
  | 
5 | 5 | using TTMouseClickSimulator.Core.Environment;  | 
6 | 6 | 
 
  | 
7 |  | -namespace TTMouseClickSimulator.Core.Toontown.Environment  | 
 | 7 | +namespace TTMouseClickSimulator.Core.Toontown.Environment;  | 
 | 8 | + | 
 | 9 | +public class ToontownInteractionProvider : InteractionProvider  | 
8 | 10 | {  | 
9 |  | -    public class ToontownInteractionProvider : InteractionProvider  | 
10 |  | -    {  | 
11 |  | -        private const string TTRProcessNameX64 = "TTREngine64";  | 
 | 11 | +    private const string TTRProcessNameX64 = "TTREngine64";  | 
12 | 12 | 
 
  | 
13 |  | -        private const string TTRProcessNameX86 = "TTREngine";  | 
 | 13 | +    private const string TTRProcessNameX86 = "TTREngine";  | 
14 | 14 | 
 
  | 
15 |  | -        private const string CCProcessName = "CorporateClash";  | 
 | 15 | +    private const string CCProcessName = "CorporateClash";  | 
16 | 16 | 
 
  | 
17 |  | -        public ToontownInteractionProvider(  | 
18 |  | -            Simulator simulator,  | 
19 |  | -            ToontownFlavor toontownFlavor,  | 
20 |  | -            WindowsEnvironment environmentInterface,  | 
21 |  | -            bool backgroundMode)  | 
22 |  | -            : base(simulator, environmentInterface, backgroundMode)  | 
23 |  | -        {  | 
24 |  | -            this.ToontownFlavor = toontownFlavor;  | 
25 |  | -        }  | 
 | 17 | +    public ToontownInteractionProvider(  | 
 | 18 | +        Simulator simulator,  | 
 | 19 | +        ToontownFlavor toontownFlavor,  | 
 | 20 | +        WindowsEnvironment environmentInterface,  | 
 | 21 | +        bool backgroundMode)  | 
 | 22 | +        : base(simulator, environmentInterface, backgroundMode)  | 
 | 23 | +    {  | 
 | 24 | +        this.ToontownFlavor = toontownFlavor;  | 
 | 25 | +    }  | 
26 | 26 | 
 
  | 
27 |  | -        public ToontownFlavor ToontownFlavor  | 
28 |  | -        {  | 
29 |  | -            get;  | 
30 |  | -        }  | 
 | 27 | +    public ToontownFlavor ToontownFlavor  | 
 | 28 | +    {  | 
 | 29 | +        get;  | 
 | 30 | +    }  | 
31 | 31 | 
 
  | 
32 |  | -        public bool UseWasdMovement  | 
33 |  | -        {  | 
34 |  | -            get;  | 
35 |  | -            init;  | 
36 |  | -        }  | 
 | 32 | +    public bool UseWasdMovement  | 
 | 33 | +    {  | 
 | 34 | +        get;  | 
 | 35 | +        init;  | 
 | 36 | +    }  | 
37 | 37 | 
 
  | 
38 |  | -        protected override sealed List<Process> FindProcesses()  | 
 | 38 | +    protected override sealed List<Process> FindProcesses()  | 
 | 39 | +    {  | 
 | 40 | +        if (this.ToontownFlavor is ToontownFlavor.ToontownRewritten)  | 
39 | 41 |         {  | 
40 |  | -            if (this.ToontownFlavor is ToontownFlavor.ToontownRewritten)  | 
41 |  | -            {  | 
42 |  | -                var processes = this.environmentInterface.FindProcessesByName(TTRProcessNameX64);  | 
43 |  | -                processes.AddRange(this.environmentInterface.FindProcessesByName(TTRProcessNameX86));  | 
44 |  | - | 
45 |  | -                if (processes.Count is 0)  | 
46 |  | -                {  | 
47 |  | -                    throw new InvalidOperationException(  | 
48 |  | -                        "Could not find Toontown Rewritten. Please make sure " +  | 
49 |  | -                        "TT Rewritten is running before starting the simulator.\n\n" +  | 
50 |  | -                        "If you're running Toontown Rewritten as administrator, you may also " +  | 
51 |  | -                        "need to the simulator as administrator.");  | 
52 |  | -                }  | 
 | 42 | +            var processes = this.environmentInterface.FindProcessesByName(TTRProcessNameX64);  | 
 | 43 | +            processes.AddRange(this.environmentInterface.FindProcessesByName(TTRProcessNameX86));  | 
53 | 44 | 
 
  | 
54 |  | -                return processes;  | 
55 |  | -            }  | 
56 |  | -            else if (this.ToontownFlavor is ToontownFlavor.CorporateClash)  | 
 | 45 | +            if (processes.Count is 0)  | 
57 | 46 |             {  | 
58 |  | -                var processes = this.environmentInterface.FindProcessesByName(CCProcessName);  | 
 | 47 | +                throw new InvalidOperationException(  | 
 | 48 | +                    "Could not find Toontown Rewritten. Please make sure " +  | 
 | 49 | +                    "TT Rewritten is running before starting the simulator.\n\n" +  | 
 | 50 | +                    "If you're running Toontown Rewritten as administrator, you may also " +  | 
 | 51 | +                    "need to the simulator as administrator.");  | 
 | 52 | +            }  | 
59 | 53 | 
 
  | 
60 |  | -                if (processes.Count is 0)  | 
61 |  | -                {  | 
62 |  | -                    throw new InvalidOperationException(  | 
63 |  | -                        "Could not find Corporate Clash. Please make sure " +  | 
64 |  | -                        "Corporate Clash is running before starting the simulator.\n\n" +  | 
65 |  | -                        "If you're running Corporate Clash as administrator, you may also " +  | 
66 |  | -                        "need to the simulator as administrator.");  | 
67 |  | -                }  | 
 | 54 | +            return processes;  | 
 | 55 | +        }  | 
 | 56 | +        else if (this.ToontownFlavor is ToontownFlavor.CorporateClash)  | 
 | 57 | +        {  | 
 | 58 | +            var processes = this.environmentInterface.FindProcessesByName(CCProcessName);  | 
68 | 59 | 
 
  | 
69 |  | -                return processes;  | 
70 |  | -            }  | 
71 |  | -            else  | 
 | 60 | +            if (processes.Count is 0)  | 
72 | 61 |             {  | 
73 |  | -                throw new NotSupportedException("Unsupported Toontown flavor: " + this.ToontownFlavor);  | 
 | 62 | +                throw new InvalidOperationException(  | 
 | 63 | +                    "Could not find Corporate Clash. Please make sure " +  | 
 | 64 | +                    "Corporate Clash is running before starting the simulator.\n\n" +  | 
 | 65 | +                    "If you're running Corporate Clash as administrator, you may also " +  | 
 | 66 | +                    "need to the simulator as administrator.");  | 
74 | 67 |             }  | 
 | 68 | + | 
 | 69 | +            return processes;  | 
 | 70 | +        }  | 
 | 71 | +        else  | 
 | 72 | +        {  | 
 | 73 | +            throw new NotSupportedException("Unsupported Toontown flavor: " + this.ToontownFlavor);  | 
75 | 74 |         }  | 
 | 75 | +    }  | 
 | 76 | + | 
 | 77 | +    protected override void ValidateWindowPositionAndSize(WindowPosition windowPosition)  | 
 | 78 | +    {  | 
 | 79 | +        // Check that the aspect ratio of the window is 4:3 or higher if the window  | 
 | 80 | +        // currently isn't minimized.  | 
 | 81 | +        if (!windowPosition.IsMinimized &&  | 
 | 82 | +            ((double)windowPosition.Size.Width / windowPosition.Size.Height) < 4d / 3d)  | 
 | 83 | +        {  | 
 | 84 | +            throw new ArgumentException(  | 
 | 85 | +                "The Toontown window must have an aspect ratio " +  | 
 | 86 | +                "of 4:3 or higher (e.g. 16:9).");  | 
 | 87 | +        }  | 
 | 88 | +    }  | 
76 | 89 | 
 
  | 
77 |  | -        protected override void TransformVirtualKey(ref WindowsEnvironment.VirtualKey key)  | 
 | 90 | +    protected override void TransformVirtualKey(ref WindowsEnvironment.VirtualKey key)  | 
 | 91 | +    {  | 
 | 92 | +        if (this.UseWasdMovement)  | 
78 | 93 |         {  | 
79 |  | -            if (this.UseWasdMovement)  | 
 | 94 | +            // Replace arrow keys with WASD keys.  | 
 | 95 | +            key = key switch  | 
80 | 96 |             {  | 
81 |  | -                // Replace arrow keys with WASD keys.  | 
82 |  | -                key = key switch  | 
83 |  | -                {  | 
84 |  | -                    WindowsEnvironment.VirtualKey.Up => WindowsEnvironment.VirtualKey.W,  | 
85 |  | -                    WindowsEnvironment.VirtualKey.Down => WindowsEnvironment.VirtualKey.S,  | 
86 |  | -                    WindowsEnvironment.VirtualKey.Left => WindowsEnvironment.VirtualKey.A,  | 
87 |  | -                    WindowsEnvironment.VirtualKey.Right => WindowsEnvironment.VirtualKey.D,  | 
88 |  | -                    var other => other  | 
89 |  | -                };  | 
90 |  | -            }  | 
 | 97 | +                WindowsEnvironment.VirtualKey.Up => WindowsEnvironment.VirtualKey.W,  | 
 | 98 | +                WindowsEnvironment.VirtualKey.Down => WindowsEnvironment.VirtualKey.S,  | 
 | 99 | +                WindowsEnvironment.VirtualKey.Left => WindowsEnvironment.VirtualKey.A,  | 
 | 100 | +                WindowsEnvironment.VirtualKey.Right => WindowsEnvironment.VirtualKey.D,  | 
 | 101 | +                var other => other  | 
 | 102 | +            };  | 
91 | 103 |         }  | 
92 | 104 |     }  | 
93 | 105 | }  | 
0 commit comments