├── Dependencies
├── NativeUI.dll
├── ScriptHookVDotNet.dll
└── ScriptHookVDotNet.xml
├── PlayerPedAction.cs
├── packages.config
├── Direction.cs
├── TwoPlayerMod.ini
├── DeviceState.cs
├── DeviceButton.cs
├── VehicleAction.cs
├── DpadType.cs
├── PedExtensions.cs
├── TwoPlayerMod.sln
├── README.md
├── Properties
└── AssemblyInfo.cs
├── PlayerSettings.cs
├── TwoPlayerMod.csproj
├── .gitignore
├── InputManager.cs
├── ControllerWizard.cs
├── XInputManager.cs
├── DirectInputManager.cs
├── TwoPlayerMod.cs
├── PlayerPed.cs
└── LICENSE.txt
/Dependencies/NativeUI.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminFaal/TwoPlayerMod/HEAD/Dependencies/NativeUI.dll
--------------------------------------------------------------------------------
/Dependencies/ScriptHookVDotNet.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BenjaminFaal/TwoPlayerMod/HEAD/Dependencies/ScriptHookVDotNet.dll
--------------------------------------------------------------------------------
/PlayerPedAction.cs:
--------------------------------------------------------------------------------
1 | namespace Benjamin94
2 | {
3 | enum PlayerPedAction
4 | {
5 | SelectWeapon, SelectTarget, Shoot, Jump, ThrowTrowable
6 | }
7 | }
--------------------------------------------------------------------------------
/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Direction.cs:
--------------------------------------------------------------------------------
1 | namespace Benjamin94
2 | {
3 | namespace Input
4 | {
5 | ///
6 | /// This enum will be used for determining stick directions
7 | ///
8 | public enum Direction
9 | {
10 | Forward, Left, Right, Backward, ForwardLeft, ForwardRight, BackwardLeft, BackwardRight, None,
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/TwoPlayerMod.ini:
--------------------------------------------------------------------------------
1 | [TWOPLAYERMOD]
2 | TOGGLEMENUKEY = F11
3 | CUSTOMCAMERA = True
4 |
5 | [PLAYERTWO]
6 | ENABLED = True
7 | CHARACTERHASH = Trevor
8 | BLIPSPRITE = Standard
9 | BLIPCOLOR = Green
10 |
11 | [PLAYERTHREE]
12 | ENABLED = True
13 | CHARACTERHASH = Michael
14 | BLIPSPRITE = Standard
15 | BLIPCOLOR = Blue
16 |
17 | [PLAYERFOUR]
18 | ENABLED = False
19 | CHARACTERHASH = LamarDavis
20 | BLIPSPRITE = Standard
21 | BLIPCOLOR = Red
--------------------------------------------------------------------------------
/DeviceState.cs:
--------------------------------------------------------------------------------
1 | using GTA.Math;
2 | using System.Collections.Generic;
3 |
4 | namespace Benjamin94
5 | {
6 | namespace Input
7 | {
8 | public class DeviceState
9 | {
10 | // the X and Y values of the sticks
11 | public Vector2 LeftThumbStick, RightThumbStick;
12 | // the buttons
13 | public List Buttons = new List();
14 |
15 | public override string ToString()
16 | {
17 | return "LeftStick: " + LeftThumbStick + ", RightStick: " + RightThumbStick + ", Buttons: " + string.Join(",", Buttons);
18 | }
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/DeviceButton.cs:
--------------------------------------------------------------------------------
1 | namespace Benjamin94
2 | {
3 | namespace Input
4 | {
5 | ///
6 | /// This enum is used for mapping button indexes to logical naming
7 | ///
8 | public enum DeviceButton
9 | {
10 | DPadUp,
11 | DPadDown,
12 | DPadLeft,
13 | DPadRight,
14 | Back,
15 | BigButton,
16 | Start,
17 | LeftStick,
18 | RightStick,
19 | A,
20 | B,
21 | X,
22 | Y,
23 | LeftShoulder,
24 | LeftTrigger,
25 | RightShoulder,
26 | RightTrigger
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/VehicleAction.cs:
--------------------------------------------------------------------------------
1 | namespace Benjamin94
2 | {
3 | public enum VehicleAction
4 | {
5 | Brake = 1,
6 | ReverseStraight = 3,
7 | HandBrakeLeft = 4,
8 | HandBrakeRight = 5,
9 | HandBrakeStraight = 6,
10 | GoForwardLeft = 7,
11 | GoForwardRight = 8,
12 | GoForwardStraightWeak = 9,
13 | SwerveRight = 10,
14 | SwerveLeft = 11,
15 | ReverseLeft = 13,
16 | ReverseRight = 14,
17 | SwerveAndBrakeLeft = 20,
18 | SwerveAndBrakeRight = 21,
19 | GoForwardWithCustomSteeringAngle = 23,
20 | GoForwardStraightBraking = 24,
21 | BrakeReverseFast = 28,
22 | BurnOut = 30,
23 | RevEngine = 31,
24 | GoForwardStraightFast = 32,
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/DpadType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Benjamin94
8 | {
9 | namespace Input
10 | {
11 | ///
12 | /// To determine what type of dpad a controller has
13 | ///
14 | enum DpadType
15 | {
16 | ///
17 | /// For generic usb gamepads
18 | ///
19 | ButtonsDpad,
20 |
21 | ///
22 | /// For controllers like a PS4 or with digital dpad
23 | ///
24 | DigitalDpad,
25 |
26 | ///
27 | /// For unrecognized controllers
28 | ///
29 | Unknown
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/PedExtensions.cs:
--------------------------------------------------------------------------------
1 | using GTA;
2 |
3 | namespace Benjamin94
4 | {
5 | public static class PedExtensions
6 | {
7 |
8 | ///
9 | /// Helper method to check if the given Ped is a PlayerPed
10 | ///
11 | /// Target Ped to check
12 | /// true or false whether the Ped is a PlayerPed
13 | public static bool IsPlayerPed(this Ped ped)
14 | {
15 | if (TwoPlayerMod.player1 == ped)
16 | {
17 | return true;
18 | }
19 | foreach (PlayerPed playerPed in TwoPlayerMod.playerPeds)
20 | {
21 | if (playerPed.Ped == ped)
22 | {
23 | return true;
24 | }
25 | }
26 | return false;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/TwoPlayerMod.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26228.12
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoPlayerMod", "TwoPlayerMod.csproj", "{2A8BD777-76D5-4EE5-8162-A1B107659D25}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {2A8BD777-76D5-4EE5-8162-A1B107659D25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {2A8BD777-76D5-4EE5-8162-A1B107659D25}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {2A8BD777-76D5-4EE5-8162-A1B107659D25}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {2A8BD777-76D5-4EE5-8162-A1B107659D25}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TwoPlayerMod [.NET]
2 | [](https://ci.appveyor.com/project/BenjaminFaal/twoplayermod)
3 |
4 | This is a ScriptHookV .NET plugin for Grand Theft Auto V, which will enable you to add a secondary player and control it with any USB gamepad.
5 |
6 | The issues page should be primarily used for bug reports and enhancement ideas.
7 |
8 | ## Roadmap / todo
9 | * Fully implement player 2 functions
10 | * ...
11 |
12 | ## Requirements
13 |
14 | * [C++ ScriptHook by Alexander Blade](http://www.dev-c.com/gtav/scripthookv/)
15 | * [Community Script Hook V .NET by crosire](https://github.com/crosire)
16 | * [SharpDX by http://sharpdx.org](http://sharpdx.org)
17 | * [NativeUI by Guadmaz](http://gtaforums.com/topic/809284-net-nativeui/)
18 |
19 | ## Downloads
20 |
21 | Major releases can be found on the mod's [GTA5-Mods.com page](https://www.gta5-mods.com/scripts/twoplayermod-net).
22 |
23 | ## Contributing
24 |
25 | Any contributions to the project are welcomed, it's recommended to use GitHub [pull requests](https://help.github.com/articles/using-pull-requests/).
26 |
27 | ## License
28 |
29 | All the source code is licensed under the conditions of this [license](https://github.com/BenjaminFaal/TwoPlayerMod/blob/master/LICENSE.txt).
30 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("TwoPlayerMod")]
9 | [assembly: AssemblyDescription("This mod spawns up to 3 extra players to the game so you can play together.")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Benjamin94")]
12 | [assembly: AssemblyProduct("TwoPlayerMod")]
13 | [assembly: AssemblyCopyright("Copyright © Benjamin94 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("2a8bd777-76d5-4ee5-8162-a1b107659d25")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("2.2")]
36 | [assembly: AssemblyFileVersion("2.2")]
37 |
--------------------------------------------------------------------------------
/PlayerSettings.cs:
--------------------------------------------------------------------------------
1 | using GTA;
2 | using SharpDX.XInput;
3 | using System;
4 |
5 | namespace Benjamin94
6 | {
7 | class PlayerSettings
8 | {
9 | private static ScriptSettings settings = ScriptSettings.Load("scripts//" + TwoPlayerMod.ScriptName + ".ini");
10 |
11 | private const string PlayerKey = "Player";
12 |
13 | public static void SetValue(UserIndex player, string key, string value)
14 | {
15 | settings.SetValue(PlayerKey + player, key, value);
16 | settings.Save();
17 | settings = ScriptSettings.Load("scripts//" + TwoPlayerMod.ScriptName + ".ini");
18 | }
19 |
20 | public static string GetValue(UserIndex player, string key, string defaultValue)
21 | {
22 | try
23 | {
24 | string value = settings.GetValue(PlayerKey + player, key, defaultValue);
25 | if (string.IsNullOrEmpty(value))
26 | {
27 | value = defaultValue;
28 | }
29 | return value;
30 | }
31 | catch (Exception)
32 | {
33 | }
34 | return defaultValue;
35 | }
36 |
37 | public static TEnum GetEnumValue(UserIndex player, string key, string defaultValue)
38 | {
39 | try
40 | {
41 | string value = GetValue(player, key, defaultValue);
42 | return (TEnum)Enum.Parse(typeof(TEnum), value);
43 | }
44 | catch (Exception)
45 | {
46 | return (TEnum)Enum.Parse(typeof(TEnum), defaultValue);
47 | }
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/TwoPlayerMod.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Release
6 | AnyCPU
7 | {2A8BD777-76D5-4EE5-8162-A1B107659D25}
8 | Library
9 | Properties
10 | TwoPlayerMod
11 | TwoPlayerMod
12 | v4.5.2
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 | Always
38 |
39 |
40 |
41 |
42 | False
43 | Dependencies\NativeUI.dll
44 |
45 |
46 | False
47 | Dependencies\ScriptHookVDotNet.dll
48 | False
49 |
50 |
51 | packages\SharpDX.3.1.1\lib\net45\SharpDX.dll
52 |
53 |
54 | packages\SharpDX.DirectInput.3.1.1\lib\net45\SharpDX.DirectInput.dll
55 |
56 |
57 | packages\SharpDX.XInput.3.1.1\lib\net45\SharpDX.XInput.dll
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | xcopy /S /Y /I "$(SolutionDir)bin\$(ConfigurationName)" "C:\Program Files (x86)\Steam\steamapps\common\Grand Theft Auto V\scripts"
87 |
88 |
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 |
24 | # Visual Studio 2015 cache/options directory
25 | .vs/
26 | # Uncomment if you have tasks that create the project's static files in wwwroot
27 | #wwwroot/
28 |
29 | # MSTest test Results
30 | [Tt]est[Rr]esult*/
31 | [Bb]uild[Ll]og.*
32 |
33 | # NUNIT
34 | *.VisualState.xml
35 | TestResult.xml
36 |
37 | # Build Results of an ATL Project
38 | [Dd]ebugPS/
39 | [Rr]eleasePS/
40 | dlldata.c
41 |
42 | # DNX
43 | project.lock.json
44 | artifacts/
45 |
46 | *_i.c
47 | *_p.c
48 | *_i.h
49 | *.ilk
50 | *.meta
51 | *.obj
52 | *.pch
53 | *.pdb
54 | *.pgc
55 | *.pgd
56 | *.rsp
57 | *.sbr
58 | *.tlb
59 | *.tli
60 | *.tlh
61 | *.tmp
62 | *.tmp_proj
63 | *.log
64 | *.vspscc
65 | *.vssscc
66 | .builds
67 | *.pidb
68 | *.svclog
69 | *.scc
70 |
71 | # Chutzpah Test files
72 | _Chutzpah*
73 |
74 | # Visual C++ cache files
75 | ipch/
76 | *.aps
77 | *.ncb
78 | *.opendb
79 | *.opensdf
80 | *.sdf
81 | *.cachefile
82 |
83 | # Visual Studio profiler
84 | *.psess
85 | *.vsp
86 | *.vspx
87 | *.sap
88 |
89 | # TFS 2012 Local Workspace
90 | $tf/
91 |
92 | # Guidance Automation Toolkit
93 | *.gpState
94 |
95 | # ReSharper is a .NET coding add-in
96 | _ReSharper*/
97 | *.[Rr]e[Ss]harper
98 | *.DotSettings.user
99 |
100 | # JustCode is a .NET coding add-in
101 | .JustCode
102 |
103 | # TeamCity is a build add-in
104 | _TeamCity*
105 |
106 | # DotCover is a Code Coverage Tool
107 | *.dotCover
108 |
109 | # NCrunch
110 | _NCrunch_*
111 | .*crunch*.local.xml
112 | nCrunchTemp_*
113 |
114 | # MightyMoose
115 | *.mm.*
116 | AutoTest.Net/
117 |
118 | # Web workbench (sass)
119 | .sass-cache/
120 |
121 | # Installshield output folder
122 | [Ee]xpress/
123 |
124 | # DocProject is a documentation generator add-in
125 | DocProject/buildhelp/
126 | DocProject/Help/*.HxT
127 | DocProject/Help/*.HxC
128 | DocProject/Help/*.hhc
129 | DocProject/Help/*.hhk
130 | DocProject/Help/*.hhp
131 | DocProject/Help/Html2
132 | DocProject/Help/html
133 |
134 | # Click-Once directory
135 | publish/
136 |
137 | # Publish Web Output
138 | *.[Pp]ublish.xml
139 | *.azurePubxml
140 | # TODO: Comment the next line if you want to checkin your web deploy settings
141 | # but database connection strings (with potential passwords) will be unencrypted
142 | *.pubxml
143 | *.publishproj
144 |
145 | # NuGet Packages
146 | *.nupkg
147 | # The packages folder can be ignored because of Package Restore
148 | **/packages/*
149 | # except build/, which is used as an MSBuild target.
150 | !**/packages/build/
151 | # Uncomment if necessary however generally it will be regenerated when needed
152 | #!**/packages/repositories.config
153 | # NuGet v3's project.json files produces more ignoreable files
154 | *.nuget.props
155 | *.nuget.targets
156 |
157 | # Microsoft Azure Build Output
158 | csx/
159 | *.build.csdef
160 |
161 | # Microsoft Azure Emulator
162 | ecf/
163 | rcf/
164 |
165 | # Microsoft Azure ApplicationInsights config file
166 | ApplicationInsights.config
167 |
168 | # Windows Store app package directory
169 | AppPackages/
170 | BundleArtifacts/
171 |
172 | # Visual Studio cache files
173 | # files ending in .cache can be ignored
174 | *.[Cc]ache
175 | # but keep track of directories ending in .cache
176 | !*.[Cc]ache/
177 |
178 | # Others
179 | ClientBin/
180 | ~$*
181 | *~
182 | *.dbmdl
183 | *.dbproj.schemaview
184 | *.pfx
185 | *.publishsettings
186 | node_modules/
187 | orleans.codegen.cs
188 |
189 | # RIA/Silverlight projects
190 | Generated_Code/
191 |
192 | # Backup & report files from converting an old project file
193 | # to a newer Visual Studio version. Backup files are not needed,
194 | # because we have git ;-)
195 | _UpgradeReport_Files/
196 | Backup*/
197 | UpgradeLog*.XML
198 | UpgradeLog*.htm
199 |
200 | # SQL Server files
201 | *.mdf
202 | *.ldf
203 |
204 | # Business Intelligence projects
205 | *.rdl.data
206 | *.bim.layout
207 | *.bim_*.settings
208 |
209 | # Microsoft Fakes
210 | FakesAssemblies/
211 |
212 | # GhostDoc plugin setting file
213 | *.GhostDoc.xml
214 |
215 | # Node.js Tools for Visual Studio
216 | .ntvs_analysis.dat
217 |
218 | # Visual Studio 6 build log
219 | *.plg
220 |
221 | # Visual Studio 6 workspace options file
222 | *.opt
223 |
224 | # Visual Studio LightSwitch build output
225 | **/*.HTMLClient/GeneratedArtifacts
226 | **/*.DesktopClient/GeneratedArtifacts
227 | **/*.DesktopClient/ModelManifest.xml
228 | **/*.Server/GeneratedArtifacts
229 | **/*.Server/ModelManifest.xml
230 | _Pvt_Extensions
231 |
232 | # Paket dependency manager
233 | .paket/paket.exe
234 |
235 | # FAKE - F# Make
236 | .fake/
237 |
--------------------------------------------------------------------------------
/InputManager.cs:
--------------------------------------------------------------------------------
1 | using SharpDX.DirectInput;
2 | using SharpDX.XInput;
3 | using System.Collections.Generic;
4 |
5 | namespace Benjamin94
6 | {
7 | namespace Input
8 | {
9 | ///
10 | /// Abstract class for managing any type of input device
11 | ///
12 | public abstract class InputManager
13 | {
14 | protected float X_CENTER_L = 0;
15 | protected float Y_CENTER_L = 0;
16 | protected float X_CENTER_R = 0;
17 | protected float Y_CENTER_R = 0;
18 |
19 | ///
20 | /// Getter for user friendly device name
21 | ///
22 | public abstract string DeviceName { get; }
23 |
24 | ///
25 | /// Getter for GUID
26 | ///
27 | public abstract string DeviceGuid { get; }
28 |
29 | ///
30 | /// To determine if one or more DeviceButtons is/are pressed at this moment or not
31 | ///
32 | /// True or false whether all given DeviceButtons need to pressed or just any of the DeviceButtons
33 | /// The DeviceButtons to check
34 | /// true or false whether the DeviceButton is pressed
35 | private bool IsPressed(bool allPressed, params DeviceButton[] btns)
36 | {
37 | DeviceState state = GetState();
38 |
39 | if (allPressed)
40 | {
41 | foreach (DeviceButton btn in btns)
42 | {
43 | allPressed = state.Buttons.Contains(btn);
44 | if (!allPressed)
45 | {
46 | return false;
47 | }
48 | }
49 | return allPressed;
50 | }
51 | else
52 | {
53 | foreach (DeviceButton btn in btns)
54 | {
55 | if (state.Buttons.Contains(btn))
56 | {
57 | return true;
58 | }
59 | }
60 | }
61 | return false;
62 | }
63 |
64 | ///
65 | /// Checks if a single of the given DeviceButtons is pressed
66 | ///
67 | /// The DeviceButton to check
68 | ///
69 | public bool isPressed(DeviceButton btn)
70 | {
71 | return GetState().Buttons.Contains(btn);
72 | }
73 |
74 | ///
75 | /// Checks if all of the given DeviceButtons are pressed
76 | ///
77 | /// The DeviceButtons to check
78 | ///
79 | public bool isAllPressed(params DeviceButton[] btns)
80 | {
81 | return IsPressed(true, btns);
82 | }
83 |
84 | ///
85 | /// Checks if one of the given DeviceButtons is pressed
86 | ///
87 | /// The DeviceButtons to check
88 | ///
89 | public bool isAnyPressed(params DeviceButton[] btns)
90 | {
91 | return IsPressed(false, btns);
92 | }
93 |
94 | ///
95 | /// This method is useful when you want to do more advanced things with the device
96 | ///
97 | /// A DeviceState object which will contain all data
98 | public abstract DeviceState GetState();
99 |
100 | ///
101 | /// Gets the direction that belongs to one of the Sticks
102 | ///
103 | /// The Direction corresponding with the X and Y value
104 | public Direction GetDirection(DeviceButton stick)
105 | {
106 | DeviceState state = GetState();
107 |
108 | if (stick == DeviceButton.LeftStick)
109 | {
110 | return GetDirection(state.LeftThumbStick.X, state.LeftThumbStick.Y, X_CENTER_L, Y_CENTER_L);
111 | }
112 | else if (stick == DeviceButton.RightStick)
113 | {
114 | return GetDirection(state.RightThumbStick.X, state.RightThumbStick.Y, X_CENTER_R, Y_CENTER_R);
115 | }
116 |
117 | return Direction.None;
118 | }
119 |
120 | ///
121 | /// Helper method to check if any given Direction is left
122 | ///
123 | /// The Direction to check
124 | ///
125 | public bool IsDirectionLeft(Direction dir)
126 | {
127 | return dir == Direction.Left || dir == Direction.BackwardLeft || dir == Direction.ForwardLeft;
128 | }
129 | ///
130 | /// Helper method to check if any given Direction is right
131 | ///
132 | /// The Direction to check
133 | ///
134 | public bool IsDirectionRight(Direction dir)
135 | {
136 | return dir == Direction.Right || dir == Direction.BackwardRight || dir == Direction.ForwardRight;
137 | }
138 |
139 | ///
140 | /// Returns both XInput and DirectInput InputManager
141 | ///
142 | /// A List of InputManagers
143 | public static List GetAvailableInputManagers()
144 | {
145 | List managers = new List();
146 | foreach (Controller ctrl in XInputManager.GetDevices())
147 | {
148 | managers.Add(new XInputManager(ctrl));
149 | }
150 |
151 | foreach (Joystick stick in DirectInputManager.GetDevices())
152 | {
153 | managers.Add(new DirectInputManager(stick));
154 | }
155 | return managers;
156 | }
157 |
158 | ///
159 | /// Gets the DirectInput direction from a X and Y value
160 | ///
161 | /// The input X value
162 | /// The input Y value
163 | /// The start value of X
164 | /// The start value of Y
165 | /// The Direction corresponding with the X and Y value
166 | protected abstract Direction GetDirection(float X, float Y, float xCenter, float yCenter);
167 |
168 |
169 | ///
170 | /// Call this method to cleanup this InputManager
171 | ///
172 | public abstract void Cleanup();
173 | }
174 | }
175 | }
--------------------------------------------------------------------------------
/ControllerWizard.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using SharpDX.DirectInput;
3 | using GTA;
4 | using System.Collections.Generic;
5 |
6 | namespace Benjamin94.Input
7 | {
8 | ///
9 | /// This class is useful for letting the user configure their controller
10 | ///
11 | class ControllerWizard
12 | {
13 | private readonly DeviceButton[] dpads = new DeviceButton[] { DeviceButton.DPadUp, DeviceButton.DPadDown, DeviceButton.DPadLeft, DeviceButton.DPadRight };
14 |
15 | private Joystick stick;
16 |
17 | public ControllerWizard(Joystick stick)
18 | {
19 | this.stick = stick;
20 | }
21 |
22 | ///
23 | /// Starts a wizard in which the user gets asked for all buttons one by one
24 | ///
25 | /// The target INI file
26 | ///
27 | public bool StartConfiguration(string iniFile)
28 | {
29 | DirectInputManager input = new DirectInputManager(stick);
30 |
31 | ScriptSettings data = ScriptSettings.Load(iniFile);
32 | string guid = stick.Information.ProductGuid.ToString();
33 |
34 | DpadType dpadType = DetermineDpadType(input);
35 | if (dpadType == (DpadType)3)
36 | {
37 | return false;
38 | }
39 |
40 | if (dpadType == DpadType.Unknown)
41 | {
42 | UI.Notify("Unknown Dpad type, controller configuration stopped.");
43 | return false;
44 | }
45 | data.SetValue(guid, DirectInputManager.DpadTypeKey, dpadType.ToString());
46 |
47 | while (input.GetDpadValue() != -1)
48 | {
49 | UI.ShowSubtitle("Please let go the Dpad button.");
50 | Script.Wait(100);
51 | }
52 |
53 | Script.Wait(1000);
54 |
55 | UI.ShowSubtitle("Determined Dpad type: " + dpadType, 2500);
56 |
57 | Script.Wait(2500);
58 |
59 | foreach (DeviceButton btn in Enum.GetValues(typeof(DeviceButton)))
60 | {
61 | if (Array.Exists(dpads, item => { return item == btn ; }) && dpadType == DpadType.DigitalDpad)
62 | {
63 | bool result = ConfigureDigitalDpadButton(btn, data, input, guid);
64 | if (!result)
65 | {
66 | return false;
67 | }
68 | }
69 | else
70 | {
71 | bool result = Configure(btn, data, input, guid);
72 | if (!result)
73 | {
74 | return false;
75 | }
76 | }
77 |
78 | UI.Notify(GetBtnText(btn) + " button configured.");
79 | }
80 |
81 | data.Save();
82 | return true;
83 | }
84 |
85 | ///
86 | /// Small wizard to determine what kind of Dpad the controller belonging to the InputManager has
87 | ///
88 | /// InputManager which to determine the Dpad of
89 | /// DpadType enum
90 | private DpadType DetermineDpadType(DirectInputManager input)
91 | {
92 | while (input.GetPressedButton() == -1 && input.GetDpadValue() == -1)
93 | {
94 | if (Game.IsKeyPressed(System.Windows.Forms.Keys.Escape)) return (DpadType)3;
95 | UI.ShowSubtitle("Press and hold at least one Dpad button for 1 second. Press the Esc key to cancel.", 120);
96 | Script.Wait(100);
97 | }
98 |
99 | UI.ShowSubtitle("Now keep holding that Dpad button.");
100 | Script.Wait(1000);
101 |
102 | int button = input.GetPressedButton();
103 | int digitalDpadvalue = input.GetDpadValue();
104 |
105 | if (digitalDpadvalue != -1)
106 | {
107 | return DpadType.DigitalDpad;
108 | }
109 | else if (button != -1)
110 | {
111 | return DpadType.ButtonsDpad;
112 | }
113 | return DpadType.Unknown;
114 | }
115 |
116 | ///
117 | /// Helper method to configure a single DeviceButton and add it the configuration
118 | ///
119 | /// The target DeviceButton
120 | /// The ScriptSettings object which it needs to be saved too
121 | /// InputManager object to handle input
122 | /// The GUID of the controller
123 | private bool Configure(DeviceButton btn, ScriptSettings data, DirectInputManager input, string guid)
124 | {
125 | while (input.GetPressedButton() == -1)
126 | {
127 | if (Game.IsKeyPressed(System.Windows.Forms.Keys.Escape)) return false;
128 | UI.ShowSubtitle("Press and hold the " + GetBtnText(btn) + " button on the controller for 1 second. Press the Esc key to cancel.", 120);
129 | Script.Wait(100);
130 | }
131 |
132 | int button = input.GetPressedButton();
133 | UI.ShowSubtitle("Please hold the " + GetBtnText(btn) + " button to confirm it.");
134 | Script.Wait(1000);
135 |
136 | if (button != input.GetPressedButton())
137 | {
138 | UI.ShowSubtitle("Now hold the " + GetBtnText(btn) + " button to confirm.");
139 | Script.Wait(1000);
140 | Configure(btn, data, input, guid);
141 | }
142 | else
143 | {
144 | data.SetValue(guid, btn.ToString(), button);
145 | while (input.GetPressedButton() != -1)
146 | {
147 | UI.ShowSubtitle("Now let go the button to configure the next one.");
148 | Script.Wait(100);
149 | }
150 | Script.Wait(1000);
151 | }
152 |
153 | return true;
154 | }
155 |
156 | ///
157 | /// Helper method to configure a single DeviceButton and add it the configuration
158 | ///
159 | /// The target DeviceButton
160 | /// The ScriptSettings object which it needs to be saved too
161 | /// InputManager object to handle input
162 | /// The GUID of the controller
163 | private bool ConfigureDigitalDpadButton(DeviceButton btn, ScriptSettings data, DirectInputManager input, string guid)
164 | {
165 | while (input.GetDpadValue() == -1)
166 | {
167 | if (Game.IsKeyPressed(System.Windows.Forms.Keys.Escape)) return false;
168 | UI.ShowSubtitle("Press and hold the " + GetBtnText(btn) + " button on the controller for 1 second. Press the Esc key to cancel.", 120);
169 | Script.Wait(100);
170 | }
171 |
172 | int dpadValue = input.GetDpadValue();
173 | UI.ShowSubtitle("Please hold the " + GetBtnText(btn) + " button to confirm it.");
174 | Script.Wait(1000);
175 |
176 | if (dpadValue == -1)
177 | {
178 | UI.ShowSubtitle("Now hold the " + GetBtnText(btn) + " button to confirm.");
179 | Script.Wait(1000);
180 | ConfigureDigitalDpadButton(btn, data, input, guid);
181 | }
182 | else
183 | {
184 | data.SetValue(guid, btn.ToString(), dpadValue);
185 | while (input.GetDpadValue() != -1)
186 | {
187 | UI.ShowSubtitle("Now let go the button to configure the next one.");
188 | Script.Wait(100);
189 | }
190 | Script.Wait(1000);
191 | }
192 |
193 | return true;
194 | }
195 |
196 | ///
197 | /// Helper method which shows the DeviceButon in green text
198 | ///
199 | /// The specific DeviceButton
200 | /// "~g~'Start'~w~" for example
201 | private string GetBtnText(DeviceButton btn)
202 | {
203 | return "~g~'" + btn + "'~w~";
204 | }
205 | }
206 | }
207 |
--------------------------------------------------------------------------------
/XInputManager.cs:
--------------------------------------------------------------------------------
1 | using SharpDX.XInput;
2 | using System;
3 | using System.Collections.Generic;
4 | using GTA.Math;
5 |
6 | namespace Benjamin94
7 | {
8 | namespace Input
9 | {
10 | ///
11 | /// This class will be the InputManager for all XInput devices
12 | ///
13 | class XInputManager : InputManager
14 | {
15 | ///
16 | /// The XInput Controller which will be managed by this InputManager
17 | ///
18 | private Controller device;
19 |
20 | public XInputManager(Controller device)
21 | {
22 | this.device = device;
23 | DeviceState state = GetState();
24 | X_CENTER_L = state.LeftThumbStick.X;
25 | Y_CENTER_L = state.LeftThumbStick.Y;
26 | X_CENTER_R = state.RightThumbStick.X;
27 | Y_CENTER_R = state.RightThumbStick.Y;
28 | }
29 |
30 | public override string DeviceName
31 | {
32 | get
33 | {
34 | return "XInput controller: " + device.UserIndex;
35 | }
36 | }
37 |
38 | public override string DeviceGuid
39 | {
40 | get
41 | {
42 | return DeviceName;
43 | }
44 | }
45 |
46 | ///
47 | /// Helper method to get all connected XInput devices
48 | ///
49 | /// A List with connected Controllers
50 | public static List GetDevices()
51 | {
52 | List controllers = new List();
53 | foreach (UserIndex index in Enum.GetValues(typeof(UserIndex)))
54 | {
55 | if (index != UserIndex.Any)
56 | {
57 | Controller controller = new Controller(index);
58 | if (controller.IsConnected)
59 | {
60 | controllers.Add(controller);
61 | }
62 | }
63 | }
64 | return controllers;
65 | }
66 |
67 | public override DeviceState GetState()
68 | {
69 | try
70 | {
71 | Gamepad pad = device.GetState().Gamepad;
72 |
73 | DeviceState state = new DeviceState();
74 |
75 | state.LeftThumbStick = NormalizeThumbStick(pad.LeftThumbX, pad.LeftThumbY, Gamepad.LeftThumbDeadZone);
76 | state.RightThumbStick = NormalizeThumbStick(pad.RightThumbX, pad.RightThumbY, Gamepad.RightThumbDeadZone);
77 |
78 | if (pad.LeftTrigger > Gamepad.TriggerThreshold)
79 | {
80 | state.Buttons.Add(DeviceButton.LeftTrigger);
81 | }
82 | if (pad.RightTrigger > Gamepad.TriggerThreshold)
83 | {
84 | state.Buttons.Add(DeviceButton.RightTrigger);
85 | }
86 |
87 | if (pad.Buttons != GamepadButtonFlags.None)
88 | {
89 | if ((pad.Buttons & GamepadButtonFlags.DPadUp) != 0)
90 | {
91 | state.Buttons.Add(DeviceButton.DPadUp);
92 | }
93 | if ((pad.Buttons & GamepadButtonFlags.DPadLeft) != 0)
94 | {
95 | state.Buttons.Add(DeviceButton.DPadLeft);
96 | }
97 | if ((pad.Buttons & GamepadButtonFlags.DPadRight) != 0)
98 | {
99 | state.Buttons.Add(DeviceButton.DPadRight);
100 | }
101 | if ((pad.Buttons & GamepadButtonFlags.DPadDown) != 0)
102 | {
103 | state.Buttons.Add(DeviceButton.DPadDown);
104 | }
105 |
106 | if ((pad.Buttons & GamepadButtonFlags.A) != 0)
107 | {
108 | state.Buttons.Add(DeviceButton.A);
109 | }
110 | if ((pad.Buttons & GamepadButtonFlags.B) != 0)
111 | {
112 | state.Buttons.Add(DeviceButton.B);
113 | }
114 | if ((pad.Buttons & GamepadButtonFlags.X) != 0)
115 | {
116 | state.Buttons.Add(DeviceButton.X);
117 | }
118 | if ((pad.Buttons & GamepadButtonFlags.Y) != 0)
119 | {
120 | state.Buttons.Add(DeviceButton.Y);
121 | }
122 |
123 | if ((pad.Buttons & GamepadButtonFlags.Start) != 0)
124 | {
125 | state.Buttons.Add(DeviceButton.Start);
126 | }
127 | if ((pad.Buttons & GamepadButtonFlags.Back) != 0)
128 | {
129 | state.Buttons.Add(DeviceButton.Back);
130 | }
131 |
132 | if ((pad.Buttons & GamepadButtonFlags.LeftShoulder) != 0)
133 | {
134 | state.Buttons.Add(DeviceButton.LeftShoulder);
135 | }
136 | if ((pad.Buttons & GamepadButtonFlags.RightShoulder) != 0)
137 | {
138 | state.Buttons.Add(DeviceButton.RightShoulder);
139 | }
140 |
141 | if ((pad.Buttons & GamepadButtonFlags.LeftThumb) != 0)
142 | {
143 | state.Buttons.Add(DeviceButton.LeftStick);
144 | }
145 | if ((pad.Buttons & GamepadButtonFlags.RightThumb) != 0)
146 | {
147 | state.Buttons.Add(DeviceButton.RightStick);
148 | }
149 | }
150 | return state;
151 | }
152 | catch (Exception)
153 | {
154 | return new DeviceState();
155 | }
156 | }
157 |
158 |
159 | ///
160 | /// Removes deadzone from the input X and Y
161 | ///
162 | /// input X
163 | /// input Y
164 | /// the deadzone to remove
165 | ///
166 | private static Vector2 NormalizeThumbStick(short x, short y, int deadZone)
167 | {
168 | int fx = x;
169 | int fy = y;
170 | if (fx * fx < deadZone * deadZone)
171 | x = 0;
172 | if (fy * fy < deadZone * deadZone)
173 | y = 0;
174 | return new Vector2(x < 0 ? -((float)x / (float)short.MinValue) : (float)x / (float)short.MaxValue,
175 | y < 0 ? -((float)y / (float)short.MinValue) : (float)y / (float)short.MaxValue);
176 | }
177 |
178 | protected override Direction GetDirection(float X, float Y, float xCenter, float yCenter)
179 | {
180 | if (X < xCenter && Y > yCenter)
181 | {
182 | return Direction.ForwardLeft;
183 | }
184 | if (X > xCenter && Y > yCenter)
185 | {
186 | return Direction.ForwardRight;
187 | }
188 | if (X < xCenter && Y == yCenter)
189 | {
190 | return Direction.Left;
191 | }
192 | if (X == xCenter && Y > yCenter)
193 | {
194 | return Direction.Forward;
195 | }
196 | if (X == xCenter && Y < yCenter)
197 | {
198 | return Direction.Backward;
199 | }
200 | if (X < xCenter && Y < yCenter)
201 | {
202 | return Direction.BackwardLeft;
203 | }
204 | if (X > xCenter && Y < yCenter)
205 | {
206 | return Direction.BackwardRight;
207 | }
208 | if (X > xCenter && Y == yCenter)
209 | {
210 | return Direction.Right;
211 | }
212 | return Direction.None;
213 | }
214 |
215 | public override void Cleanup()
216 | {
217 | // nothing to do here
218 | }
219 | }
220 | }
221 | }
222 |
--------------------------------------------------------------------------------
/DirectInputManager.cs:
--------------------------------------------------------------------------------
1 | using GTA;
2 | using SharpDX.DirectInput;
3 | using System;
4 | using System.Collections.Generic;
5 | using GTA.Math;
6 | using System.Linq;
7 | using SharpDX.XInput;
8 |
9 | namespace Benjamin94
10 | {
11 | namespace Input
12 | {
13 |
14 | ///
15 | /// This class will be the InputManager for all DirectInput devices
16 | ///
17 | class DirectInputManager : InputManager
18 | {
19 | public const string DpadTypeKey = "DpadType";
20 |
21 | ///
22 | /// The Joystick which will be managed by this InputManager
23 | ///
24 | public Joystick device;
25 |
26 | ///
27 | /// Here the DeviceButton config from the ini file will be stored
28 | ///
29 | private List> config;
30 |
31 | public override string DeviceName
32 | {
33 | get
34 | {
35 | return device.Information.ProductName;
36 | }
37 | }
38 |
39 | public override string DeviceGuid
40 | {
41 | get
42 | {
43 | return device.Information.ProductGuid.ToString();
44 | }
45 | }
46 |
47 | ///
48 | /// Initializes a default InputManager without config.
49 | /// This means almost none of the methods will work such as IsPressed()
50 | ///
51 | /// The target Joystick which needs to be managed
52 | public DirectInputManager(Joystick device)
53 | {
54 | this.device = device;
55 | if (device != null)
56 | {
57 | device.Acquire();
58 | }
59 | config = new List>(); // for digital dpads
60 |
61 | DeviceState state = GetState();
62 | X_CENTER_L = state.LeftThumbStick.X;
63 | Y_CENTER_L = state.LeftThumbStick.Y;
64 | X_CENTER_R = state.RightThumbStick.X;
65 | Y_CENTER_R = state.RightThumbStick.Y;
66 | }
67 |
68 | ///
69 | /// Helper method to get all connected DirectInput devices
70 | ///
71 | /// A List with connected Joysticks
72 | public static List GetDevices()
73 | {
74 | DirectInput directInput = new DirectInput();
75 | List sticks = new List();
76 | foreach (DeviceInstance dev in directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly))
77 | {
78 | var joystick = new Joystick(directInput, dev.InstanceGuid);
79 |
80 | // dont include Xbox controllers
81 | string name = joystick.Information.ProductName.ToLower();
82 |
83 | if (!name.Contains("xbox") && !name.Contains("360") && !name.Contains("xinput"))
84 | {
85 | sticks.Add(joystick);
86 | }
87 | }
88 | return sticks;
89 | }
90 |
91 | ///
92 | /// Helper method to check if a Joystick is configured correctly
93 | ///
94 | /// The Joystick which needs to be configured
95 | /// The path to the config file
96 | /// true or false whether the config file contains a valid configuration
97 | public static bool IsConfigured(Joystick stick, string file)
98 | {
99 | try
100 | {
101 | LoadConfig(stick, file);
102 | return true;
103 | }
104 | catch (Exception)
105 | {
106 | return false;
107 | }
108 | }
109 |
110 | ///
111 | /// Constructs a new InputManager by reading the config from a file
112 | ///
113 | /// The file must contain something similar to this:
114 | ///
115 | ///[0268054C-0000-0000-0000-504944564944]
116 | ///DPADUP = 5
117 | ///DPADDOWN = 7
118 | ///DPADLEFT = 8
119 | ///DPADRIGHT = 6
120 | ///BACK = 1
121 | ///BIGBUTTON = 17
122 | ///START = 4
123 | ///LEFTSTICK = 2
124 | ///RIGHTSTICK = 3
125 | ///A = 15
126 | ///B = 14
127 | ///X = 16
128 | ///Y = 13
129 | ///LEFTSHOULDER = 11
130 | ///LEFTTRIGGER = 9
131 | ///RIGHTSHOULDER = 12
132 | ///RIGHTTRIGGER = 10
133 | ///
134 | ///
135 | /// The Joystick instance which should be managed by this InputManager
136 | /// Path to the file containing the config
137 | ///
138 | public static DirectInputManager LoadConfig(Joystick stick, string file)
139 | {
140 | DirectInputManager manager = new DirectInputManager(stick);
141 | try
142 | {
143 | string name = stick.Information.ProductGuid.ToString();
144 | ScriptSettings data = ScriptSettings.Load(file);
145 |
146 | DpadType dpadType = DpadType.Unknown;
147 | try
148 | {
149 | dpadType = (DpadType)Enum.Parse(typeof(DpadType), data.GetValue(name, DpadTypeKey, DpadType.Unknown.ToString()));
150 | }
151 | catch (Exception)
152 | {
153 | throw new Exception("Invalid controller config, unknown " + DpadTypeKey + " reconfigure your controller from the menu.");
154 | }
155 |
156 | foreach (DeviceButton btn in Enum.GetValues(typeof(DeviceButton)))
157 | {
158 | int btnIndex = data.GetValue(name, btn.ToString(), -1);
159 |
160 | try
161 | {
162 | manager.config.Add(new Tuple(btnIndex, btn));
163 | }
164 | catch (Exception)
165 | {
166 | throw new Exception("Invalid controller config, please reconfigure your controller from the menu.");
167 | }
168 | }
169 | }
170 | catch (Exception)
171 | {
172 | throw new Exception("Error reading controller config, make sure the file contains a valid controller config.");
173 | }
174 | return manager;
175 | }
176 |
177 | ///
178 | /// Helper method to get dpad value for digital dpads
179 | ///
180 | /// -1 if no dpad button pressed otherwise the value of the button
181 | public int GetDpadValue()
182 | {
183 | try
184 | {
185 | device.Poll();
186 | JoystickState state = device.GetCurrentState();
187 | foreach (int value in device.GetCurrentState().PointOfViewControllers)
188 | {
189 | if (value != -1)
190 | {
191 | return value;
192 | }
193 | }
194 | }
195 | catch (Exception)
196 | {
197 | }
198 | return -1;
199 | }
200 |
201 | ///
202 | /// Determines the first pressed button
203 | ///
204 | /// -1 if no pressed button or the button number if at least one pressed button
205 | public int GetPressedButton()
206 | {
207 | try
208 | {
209 | JoystickState state = device.GetCurrentState();
210 | if (state == null)
211 | {
212 | return -1;
213 | }
214 |
215 | bool[] buttons = state.Buttons;
216 |
217 | for (int i = 0; i < buttons.Length; i++)
218 | {
219 | int button = i + 1;
220 |
221 | if (buttons[i])
222 | {
223 | return button;
224 | }
225 | }
226 | }
227 | catch (Exception)
228 | {
229 | }
230 | return -1;
231 | }
232 |
233 | ///
234 | /// Removes deadzone from the input X and Y
235 | ///
236 | /// input X
237 | /// input Y
238 | ///
239 | private static Vector2 NormalizeThumbStick(float x, float y)
240 | {
241 | Vector2 vector = new Vector2((x - JOY_32767) / JOY_32767, -(y - JOY_32767) / JOY_32767);
242 |
243 | if (Math.Abs(vector.X) < 0.4f)
244 | {
245 | vector.X = 0;
246 | }
247 | if (Math.Abs(vector.Y) < 0.4f)
248 | {
249 | vector.Y = 0;
250 | }
251 | return vector;
252 | }
253 |
254 | public override DeviceState GetState()
255 | {
256 | try
257 | {
258 | device.Poll();
259 | JoystickState state = device.GetCurrentState();
260 |
261 | DeviceState devState = new DeviceState();
262 |
263 | bool[] buttons = state.Buttons;
264 |
265 | for (int i = 0; i < buttons.Length; i++)
266 | {
267 | if (buttons[i])
268 | {
269 | Tuple tuple = config.FirstOrDefault(item => item.Item1 == i + 1);
270 | if (tuple != null)
271 | {
272 | devState.Buttons.Add(tuple.Item2);
273 | }
274 | }
275 | }
276 |
277 | // for ps4 controllers or devices with dpads that are not recognized as buttons
278 | foreach (int pov in state.PointOfViewControllers)
279 | {
280 | Tuple tuple = config.FirstOrDefault(item => item.Item1 == pov);
281 | if (tuple != null)
282 | {
283 | devState.Buttons.Add(tuple.Item2);
284 | }
285 | }
286 |
287 | devState.LeftThumbStick = NormalizeThumbStick(state.X, state.Y);
288 | devState.RightThumbStick = NormalizeThumbStick(state.Z, state.RotationZ);
289 |
290 | return devState;
291 | }
292 | catch (Exception)
293 | {
294 | // most of times this exception occurs when its disconnected unexpectedly
295 | // by calling Acquire() it will always be reconnected as soon as the controller is plugged in again
296 | try
297 | {
298 | device.Acquire();
299 | }
300 | catch (Exception)
301 | {
302 | }
303 | }
304 | return null;
305 | }
306 |
307 | private const int JOY_32767 = 32767;
308 | private const int JOY_0 = 0;
309 | private const int JOY_65535 = 65535;
310 |
311 | protected override Direction GetDirection(float X, float Y, float xCenter, float yCenter)
312 | {
313 | if (X < xCenter && Y > yCenter)
314 | {
315 | return Direction.ForwardLeft;
316 | }
317 | if (X > xCenter && Y > yCenter)
318 | {
319 | return Direction.ForwardRight;
320 | }
321 | if (X < xCenter && Y == yCenter)
322 | {
323 | return Direction.Left;
324 | }
325 | if (X == xCenter && Y > yCenter)
326 | {
327 | return Direction.Forward;
328 | }
329 | if (X == xCenter && Y < yCenter)
330 | {
331 | return Direction.Backward;
332 | }
333 | if (X < xCenter && Y < yCenter)
334 | {
335 | return Direction.BackwardLeft;
336 | }
337 | if (X > xCenter && Y < yCenter)
338 | {
339 | return Direction.BackwardRight;
340 | }
341 | if (X > xCenter && Y == yCenter)
342 | {
343 | return Direction.Right;
344 | }
345 | return Direction.None;
346 | }
347 |
348 | public override void Cleanup()
349 | {
350 | device.Unacquire();
351 | device = null;
352 | config = null;
353 | }
354 | }
355 | }
356 | }
357 |
--------------------------------------------------------------------------------
/TwoPlayerMod.cs:
--------------------------------------------------------------------------------
1 | using GTA;
2 | using GTA.Math;
3 | using GTA.Native;
4 | using SharpDX.DirectInput;
5 | using System;
6 | using NativeUI;
7 | using System.Windows.Forms;
8 | using System.Collections.Generic;
9 | using Benjamin94.Input;
10 | using Benjamin94;
11 | using SharpDX.XInput;
12 | using System.Linq;
13 |
14 | ///
15 | /// The main Script, this will handle all logic
16 | ///
17 | class TwoPlayerMod : Script
18 | {
19 | // for ini keys
20 | public static string ScriptName = "TwoPlayerMod";
21 | private const string ToggleMenuKey = "ToggleMenuKey";
22 | private const string CharacterHashKey = "CharacterHash";
23 | private const string ControllerKey = "Controller";
24 | private const string CustomCameraKey = "CustomCamera";
25 | private const string BlipSpriteKey = "BlipSprite";
26 | private const string BlipColorKey = "BlipColor";
27 | private const string EnabledKey = "Enabled";
28 |
29 | // Player 1
30 | private Player player;
31 | public static Ped player1;
32 |
33 | // PlayerPeds
34 | public static List playerPeds = new List();
35 |
36 | // Menu
37 | private UIMenu menu;
38 | private MenuPool menuPool = new MenuPool();
39 |
40 | // Settings
41 | private Keys toggleMenuKey = Keys.F11;
42 |
43 | // camera
44 | public static bool customCamera = false;
45 | private Camera camera;
46 |
47 | // players
48 | private readonly UserIndex[] userIndices = new UserIndex[] { UserIndex.Two, UserIndex.Three, UserIndex.Four };
49 |
50 | public TwoPlayerMod()
51 | {
52 | ScriptName = Name;
53 | player = Game.Player;
54 | player1 = player.Character;
55 | player1.Task.ClearAll();
56 |
57 | LoadSettings();
58 | SetupMenu();
59 |
60 | KeyDown += TwoPlayerMod_KeyDown;
61 | Tick += TwoPlayerMod_Tick;
62 | }
63 |
64 | ///
65 | /// Loads the mod settings, if there is an error it will revert the file back to default
66 | ///
67 | private void LoadSettings()
68 | {
69 | try
70 | {
71 | toggleMenuKey = (Keys)new KeysConverter().ConvertFromString(Settings.GetValue(Name, ToggleMenuKey, Keys.F11.ToString()));
72 | }
73 | catch (Exception)
74 | {
75 | toggleMenuKey = Keys.F11;
76 | UI.Notify("Failed to read '" + ToggleMenuKey + "', reverting to default " + ToggleMenuKey + " F11");
77 |
78 | Settings.SetValue(Name, ToggleMenuKey, Keys.F11.ToString());
79 | Settings.Save();
80 | }
81 |
82 | try
83 | {
84 | customCamera = bool.Parse(Settings.GetValue(Name, CustomCameraKey, "False"));
85 | }
86 | catch (Exception)
87 | {
88 | customCamera = false;
89 | UI.Notify("Failed to read '" + CustomCameraKey + "', reverting to default " + CustomCameraKey + " False");
90 |
91 | Settings.SetValue(Name, CustomCameraKey, "False");
92 | Settings.Save();
93 | }
94 | }
95 |
96 | ///
97 | /// Determines if the mod is enabled or disabled
98 | ///
99 | /// true or false whether the mod is enabled
100 | private bool Enabled()
101 | {
102 | return playerPeds.Count > 0;
103 | }
104 |
105 | ///
106 | /// Sets up the NativeUI menu
107 | ///
108 | private void SetupMenu()
109 | {
110 | if (menuPool != null)
111 | {
112 | menuPool.ToList().ForEach(menu => { menu.Clear(); });
113 | }
114 |
115 | menu = new UIMenu("Two Player Mod", Enabled() ? "~g~Enabled" : "~r~Disabled");
116 | menuPool.Add(menu);
117 |
118 | UIMenuItem toggleItem = new UIMenuItem("Toggle mod", "Toggle Two Player mode");
119 | toggleItem.Activated += ToggleMod_Activated;
120 | menu.AddItem(toggleItem);
121 |
122 | UIMenu allPlayersMenu = menuPool.AddSubMenu(menu, "Players");
123 | menu.MenuItems.FirstOrDefault(item => { return item.Text.Equals("Players"); }).Description = "Configure players";
124 |
125 | foreach (UserIndex player in userIndices)
126 | {
127 | bool check = bool.Parse(PlayerSettings.GetValue(player, EnabledKey, false.ToString()));
128 |
129 | UIMenu playerMenu = menuPool.AddSubMenu(allPlayersMenu, "Player " + player);
130 | UIMenuItem playerItem = allPlayersMenu.MenuItems.FirstOrDefault(item => { return item.Text.Equals("Player " + player); });
131 |
132 | string controllerGuid = PlayerSettings.GetValue(player, ControllerKey, "");
133 |
134 | playerItem.Description = "Configure player " + player;
135 |
136 | if (!string.IsNullOrEmpty(controllerGuid))
137 | {
138 | playerItem.SetRightBadge(UIMenuItem.BadgeStyle.Star);
139 | }
140 |
141 | UIMenuCheckboxItem togglePlayerItem = new UIMenuCheckboxItem("Toggle player " + player, check, "Enables/disables this player");
142 |
143 | togglePlayerItem.CheckboxEvent += (s, enabled) =>
144 | {
145 | PlayerSettings.SetValue(player, EnabledKey, enabled.ToString());
146 |
147 | RefreshSubItems(togglePlayerItem, playerMenu, enabled);
148 | };
149 |
150 | playerMenu.AddItem(togglePlayerItem);
151 |
152 | playerMenu.AddItem(ConstructSettingsListItem(player, "Character", "Select a character for player " + player, CharacterHashKey, PedHash.Trevor));
153 | playerMenu.AddItem(ConstructSettingsListItem(player, "Blip sprite", "Select a blip sprite for player " + player, BlipSpriteKey, BlipSprite.Standard));
154 | playerMenu.AddItem(ConstructSettingsListItem(player, "Blip color", "Select a blip color for player " + player, BlipColorKey, BlipColor.Green));
155 |
156 | UIMenu controllerMenu = menuPool.AddSubMenu(playerMenu, "Assign controller");
157 | playerMenu.MenuItems.FirstOrDefault(item => { return item.Text.Equals("Assign controller"); }).Description = "Assign controller to player " + player;
158 |
159 | foreach (InputManager manager in InputManager.GetAvailableInputManagers())
160 | {
161 | UIMenuItem controllerItem = new UIMenuItem(manager.DeviceName, "Assign this controller to player " + player);
162 |
163 | string guid = manager.DeviceGuid;
164 |
165 | if (PlayerSettings.GetValue(player, ControllerKey, "").Equals(guid))
166 | {
167 | controllerItem.SetRightBadge(UIMenuItem.BadgeStyle.Star);
168 | }
169 |
170 | if (manager is DirectInputManager)
171 | {
172 | DirectInputManager directManager = (DirectInputManager)manager;
173 | bool configured = DirectInputManager.IsConfigured(directManager.device, GetIniFile());
174 | controllerItem.Enabled = configured;
175 |
176 | if (!configured)
177 | {
178 | controllerItem.Description = "Please configure this controller first from the main menu";
179 | }
180 | }
181 |
182 | controllerItem.Activated += (s, i) =>
183 | {
184 | if (i.Enabled)
185 | {
186 | PlayerSettings.SetValue(player, ControllerKey, guid);
187 |
188 | controllerMenu.MenuItems.ForEach(item =>
189 | {
190 | if (item == controllerItem)
191 | {
192 | item.SetRightBadge(UIMenuItem.BadgeStyle.Star);
193 | }
194 | else
195 | {
196 | item.SetRightBadge(UIMenuItem.BadgeStyle.None);
197 | }
198 | });
199 | }
200 | };
201 |
202 | controllerMenu.AddItem(controllerItem);
203 | }
204 |
205 | RefreshSubItems(togglePlayerItem, playerMenu, check);
206 | }
207 |
208 | UIMenuCheckboxItem cameraItem = new UIMenuCheckboxItem("GTA:SA style camera", customCamera, "Enables/disables the GTA:SA style camera");
209 | cameraItem.CheckboxEvent += (s, i) =>
210 | {
211 | customCamera = !customCamera;
212 | Settings.SetValue(Name, CustomCameraKey, customCamera.ToString());
213 | Settings.Save();
214 | };
215 | menu.AddItem(cameraItem);
216 |
217 | UIMenu controllersMenu = menuPool.AddSubMenu(menu, "Configure controllers");
218 | menu.MenuItems.FirstOrDefault(item => { return item.Text.Equals("Configure controllers"); }).Description = "Configure controllers before assigning them to players";
219 | foreach (Joystick stick in DirectInputManager.GetDevices())
220 | {
221 | UIMenuItem stickItem = new UIMenuItem(stick.Information.ProductName, "Configure " + stick.Information.ProductName);
222 |
223 | controllersMenu.AddItem(stickItem);
224 | stickItem.Activated += (s, i) =>
225 | {
226 | ControllerWizard wizard = new ControllerWizard(stick);
227 | bool success = wizard.StartConfiguration(GetIniFile());
228 | if (success)
229 | {
230 | UI.Notify("Controller successfully configured, you can now assign this controller");
231 | }
232 | else
233 | {
234 | UI.Notify("Controller configuration canceled, please configure your controller before playing");
235 | }
236 | SetupMenu();
237 | };
238 | }
239 |
240 | menu.RefreshIndex();
241 | }
242 |
243 | ///
244 | /// Refreshes all items in the UIMenu except the parentItem
245 | ///
246 | /// The parent UIMenuItem to ignore
247 | /// UIMenu
248 | /// Whether to enable or disable the sub items
249 | private void RefreshSubItems(UIMenuItem parentItem, UIMenu menu, bool enabled)
250 | {
251 | foreach (UIMenuItem item in menu.MenuItems)
252 | {
253 | if (!item.Equals(parentItem))
254 | {
255 | item.Enabled = enabled;
256 | }
257 | }
258 | }
259 |
260 | ///
261 | /// Constructs a new UIMenuListItem with automatic handling of selected value
262 | ///
263 | /// The type of the enum
264 | /// The
265 | /// The menu item text
266 | /// The menu item description
267 | /// The settings key
268 | /// The initial selected value
269 | /// A fully working UIMenuListItem with automatic saving
270 | private UIMenuListItem ConstructSettingsListItem(UserIndex player, string text, string description, string settingsKey, TEnum defaultValue)
271 | {
272 | List items = GetDynamicEnumList();
273 |
274 | TEnum value = PlayerSettings.GetEnumValue(player, settingsKey, defaultValue.ToString());
275 |
276 | UIMenuListItem menuItem = new UIMenuListItem(text, items, items.IndexOf(value.ToString()), description);
277 | menuItem.OnListChanged += (s, i) =>
278 | {
279 | if (s.Enabled)
280 | {
281 | TEnum selectedItem = Enum.Parse(typeof(TEnum), s.IndexToItem(s.Index));
282 | PlayerSettings.SetValue(player, settingsKey, selectedItem.ToString());
283 | }
284 | };
285 | return menuItem;
286 | }
287 |
288 | ///
289 | /// This method will handle entering vehicles
290 | ///
291 | /// Target Ped
292 | public static void HandleEnterVehicle(Ped ped)
293 | {
294 | Vehicle v = World.GetClosestVehicle(ped.Position, 15);
295 | if (v == null)
296 | {
297 | return;
298 | }
299 | Ped driver = v.GetPedOnSeat(VehicleSeat.Driver);
300 |
301 | if (driver != null && driver.IsPlayerPed())
302 | {
303 | ped.Task.EnterVehicle(v, VehicleSeat.Any);
304 | }
305 | else
306 | {
307 | if (driver != null)
308 | {
309 | driver.Delete();
310 | }
311 | ped.Task.EnterVehicle(v, VehicleSeat.Any);
312 | }
313 | }
314 |
315 | ///
316 | /// Helper method to get all values of an Enum for displaying in a menu
317 | ///
318 | /// Type of the Enum
319 | /// Sorted list of all possible given Enum values
320 | private List GetDynamicEnumList()
321 | {
322 | List values = new List();
323 |
324 | foreach (Enum pedHash in Enum.GetValues(typeof(TEnum)))
325 | {
326 | values.Add(pedHash.ToString());
327 | }
328 |
329 | values.Sort();
330 | return values;
331 | }
332 |
333 | ///
334 | /// Helper method to get the INI file
335 | ///
336 | /// "scripts//" + Name + ".ini"
337 | private string GetIniFile()
338 | {
339 | return "scripts//" + Name + ".ini";
340 | }
341 |
342 | ///
343 | /// Gets called by NativeUI when the user selects "Toggle mod" in the menu
344 | ///
345 | private void ToggleMod_Activated(UIMenu sender, UIMenuItem selectedItem)
346 | {
347 | if (!Enabled())
348 | {
349 | UI.ShowSubtitle("Like this mod? Please consider donating!", 10000);
350 | SetupPlayerPeds();
351 |
352 | if (playerPeds.Count == 0)
353 | {
354 | UI.Notify("Please assign a controller to at least one player");
355 | UI.Notify("Also make sure you have configured at least one controller");
356 | return;
357 | }
358 |
359 | SetupCamera();
360 | }
361 | else
362 | {
363 | Clean();
364 | }
365 | menu.Subtitle.Caption = Enabled() ? "~g~Enabled" : "~r~Disabled";
366 | }
367 |
368 | ///
369 | /// Sets up all correctly configured PlayerPed
370 | ///
371 | private void SetupPlayerPeds()
372 | {
373 | foreach (UserIndex player in userIndices)
374 | {
375 | if (bool.Parse(PlayerSettings.GetValue(player, EnabledKey, false.ToString())))
376 | {
377 | string guid = PlayerSettings.GetValue(player, ControllerKey, "");
378 |
379 | foreach (InputManager input in InputManager.GetAvailableInputManagers())
380 | {
381 | if (input.DeviceGuid.Equals(guid))
382 | {
383 | InputManager manager = input;
384 | if (input is DirectInputManager)
385 | {
386 | manager = DirectInputManager.LoadConfig(((DirectInputManager)input).device, GetIniFile());
387 | }
388 |
389 | PedHash characterHash = PlayerSettings.GetEnumValue(player, CharacterHashKey, PedHash.Trevor.ToString());
390 | BlipSprite blipSprite = PlayerSettings.GetEnumValue(player, BlipSpriteKey, BlipSprite.Standard.ToString());
391 | BlipColor blipColor = PlayerSettings.GetEnumValue(player, BlipColorKey, BlipColor.Green.ToString());
392 |
393 | PlayerPed playerPed = new PlayerPed(player, characterHash, blipSprite, blipColor, player1, manager);
394 | playerPeds.Add(playerPed);
395 | break;
396 | }
397 | }
398 | }
399 | }
400 | }
401 |
402 | ///
403 | /// This method will setup the camera system
404 | ///
405 | private void SetupCamera()
406 | {
407 | Function.Call(Hash.LOCK_MINIMAP_ANGLE, 0);
408 | camera = World.CreateCamera(player1.GetOffsetInWorldCoords(new Vector3(0, 10, 10)), Vector3.Zero, GameplayCamera.FieldOfView);
409 | }
410 |
411 | ///
412 | /// This method is overridden so we can cleanup the script
413 | ///
414 | protected override void Dispose(bool A_0)
415 | {
416 | Clean();
417 | base.Dispose(A_0);
418 | }
419 |
420 | ///
421 | /// Toggles the menu
422 | ///
423 | private void TwoPlayerMod_KeyDown(object sender, KeyEventArgs e)
424 | {
425 | if (e.KeyCode == toggleMenuKey)
426 | {
427 | menu.Visible = !menu.Visible;
428 | }
429 | }
430 |
431 |
432 | ///
433 | /// Cleans up the script, deletes Player2 and cleans the InputManager system
434 | ///
435 | private void Clean()
436 | {
437 | Function.Call(Hash.UNLOCK_MINIMAP_ANGLE);
438 |
439 | CleanCamera();
440 | CleanUpPlayerPeds();
441 | }
442 |
443 | ///
444 | /// Cleans up all PlayerPeds
445 | ///
446 | private void CleanUpPlayerPeds()
447 | {
448 | playerPeds.ForEach((playerPed => { playerPed.Clean(); }));
449 | playerPeds.Clear();
450 | if (player1 != null)
451 | {
452 | player1.Task.ClearAllImmediately();
453 | }
454 | }
455 |
456 | ///
457 | /// This method will return the center of given vectors
458 | ///
459 | /// Vector3 A
460 | /// The center Vector3 of the two given Vector3s
461 | public Vector3 CenterOfVectors(params Vector3[] vectors)
462 | {
463 | Vector3 center = Vector3.Zero;
464 | foreach (Vector3 vector in vectors)
465 | {
466 | center += vector;
467 | }
468 |
469 | return center / vectors.Length;
470 | }
471 |
472 | private bool resetWalking = false;
473 |
474 | private void TwoPlayerMod_Tick(object sender, EventArgs e)
475 | {
476 | menuPool.ProcessMenus();
477 |
478 | if (Enabled())
479 | {
480 | if (!Player1Available())
481 | {
482 | CleanCamera();
483 |
484 | while (!Player1Available() || Function.Call(Hash.IS_SCREEN_FADING_IN))
485 | {
486 | Wait(1000);
487 | }
488 |
489 | playerPeds.ForEach(playerPed =>
490 | {
491 | playerPed.Respawn();
492 | Wait(500);
493 | });
494 |
495 | SetupCamera();
496 | }
497 |
498 | playerPeds.ForEach((playerPed => { playerPed.Tick(); }));
499 |
500 | UpdateCamera();
501 |
502 | if (customCamera && player1.IsOnFoot)
503 | {
504 | if (Game.IsControlPressed(0, GTA.Control.Jump))
505 | {
506 | player1.Task.Climb();
507 | }
508 |
509 | Vector2 offset = Vector2.Zero;
510 |
511 | if (Game.IsControlPressed(0, GTA.Control.MoveUpOnly))
512 | {
513 | offset.Y++;
514 | }
515 |
516 | if (Game.IsControlPressed(0, GTA.Control.MoveLeftOnly))
517 | {
518 | offset.X--;
519 | }
520 |
521 | if (Game.IsControlPressed(0, GTA.Control.MoveRightOnly))
522 | {
523 | offset.X++;
524 | }
525 |
526 | if (Game.IsControlPressed(0, GTA.Control.MoveDownOnly))
527 | {
528 | offset.Y--;
529 | }
530 |
531 | if (offset != Vector2.Zero)
532 | {
533 | if (Game.IsControlPressed(0, GTA.Control.Sprint))
534 | {
535 | // needed for running
536 | offset *= 10;
537 | }
538 | Vector3 dest = Vector3.Zero;
539 | dest = player1.Position - new Vector3(offset.X, offset.Y, 0);
540 | player1.Task.RunTo(dest, true, -1);
541 | resetWalking = true;
542 | }
543 | else if (resetWalking)
544 | {
545 | player1.Task.ClearAll();
546 | resetWalking = false;
547 | }
548 | }
549 |
550 | if (Game.IsControlJustReleased(0, GTA.Control.NextCamera))
551 | {
552 | customCamera = !customCamera;
553 | }
554 |
555 | // for letting player get in a vehicle
556 | if (player1.IsOnFoot && Game.IsControlJustReleased(0, GTA.Control.VehicleExit))
557 | {
558 | HandleEnterVehicle(player1);
559 | }
560 | }
561 | }
562 |
563 | ///
564 | /// Cleans the Camera system
565 | ///
566 | private void CleanCamera()
567 | {
568 | World.DestroyAllCameras();
569 | World.RenderingCamera = null;
570 | }
571 |
572 | ///
573 | /// Helper method to check if Player 1 is still normally available
574 | ///
575 | /// True when Player 1 is still normally available to play
576 | private bool Player1Available()
577 | {
578 | return !player1.IsDead && !Function.Call(Hash.IS_PLAYER_BEING_ARRESTED, player, true) && !Function.Call(Hash.IS_PLAYER_BEING_ARRESTED, player, false) && !Function.Call(Hash.IS_SCREEN_FADING_OUT);
579 | }
580 |
581 | ///
582 | /// This will update the camera
583 | ///
584 | private void UpdateCamera()
585 | {
586 | // if all in same vehicle
587 | if (playerPeds.TrueForAll(p => { return p.Ped.CurrentVehicle != null && p.Ped.CurrentVehicle == player1.CurrentVehicle; }))
588 | {
589 | World.RenderingCamera = null;
590 | }
591 | else if (customCamera)
592 | {
593 | PlayerPed furthestPlayer = playerPeds.OrderByDescending(playerPed => { return player1.Position.DistanceTo(playerPed.Ped.Position); }).FirstOrDefault();
594 |
595 | Vector3 center = CenterOfVectors(player1.Position, furthestPlayer.Ped.Position);
596 |
597 | World.RenderingCamera = camera;
598 | camera.PointAt(center);
599 |
600 | float dist = furthestPlayer.Ped.Position.DistanceTo(player1.Position);
601 |
602 | center.Y += 5f + (dist / 1.6f);
603 | center.Z += 2f + (dist / 1.4f);
604 |
605 | camera.Position = center;
606 | }
607 | else
608 | {
609 | World.RenderingCamera = null;
610 | }
611 | }
612 | }
--------------------------------------------------------------------------------
/PlayerPed.cs:
--------------------------------------------------------------------------------
1 | using Benjamin94.Input;
2 | using GTA;
3 | using GTA.Math;
4 | using GTA.Native;
5 | using SharpDX.XInput;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Drawing;
9 | using System.Linq;
10 |
11 | namespace Benjamin94
12 | {
13 | ///
14 | /// This class will wrap around a normal Ped and will have properties like WeaponIndex, TargetIndex, InputManager
15 | ///
16 | class PlayerPed
17 | {
18 | // static properties
19 | private static WeaponHash[] weapons = (WeaponHash[])Enum.GetValues(typeof(WeaponHash));
20 | private static WeaponHash[] meleeWeapons = new WeaponHash[] { WeaponHash.PetrolCan, WeaponHash.Knife, WeaponHash.Nightstick, WeaponHash.Hammer, WeaponHash.Bat, WeaponHash.GolfClub, WeaponHash.Crowbar, WeaponHash.Bottle, WeaponHash.SwitchBlade, WeaponHash.Dagger, WeaponHash.Hatchet, WeaponHash.Unarmed, WeaponHash.KnuckleDuster, WeaponHash.Machete, WeaponHash.Flashlight };
21 | private static WeaponHash[] throwables = new WeaponHash[] { WeaponHash.StickyBomb, WeaponHash.Snowball, WeaponHash.SmokeGrenade, WeaponHash.ProximityMine, WeaponHash.Molotov, WeaponHash.Grenade, WeaponHash.Flare, WeaponHash.BZGas, WeaponHash.Ball };
22 |
23 | // PlayerPed properties
24 | public Ped Ped { get; internal set; }
25 | // private Ped ped = null;
26 | private readonly Ped Player1;
27 | public readonly UserIndex UserIndex = UserIndex.Any;
28 | private VehicleAction LastVehicleAction = VehicleAction.Brake;
29 | private Ped[] Targets = null;
30 |
31 | private int MaxHealth = 100;
32 |
33 | private int weaponIndex = Array.IndexOf(weapons, WeaponHash.Unarmed);
34 |
35 | private int WeaponIndex
36 | {
37 | get
38 | {
39 | if (weaponIndex < 0)
40 | {
41 | weaponIndex = weapons.Length - 1;
42 | }
43 | if (weaponIndex >= weapons.Length)
44 | {
45 | weaponIndex = 0;
46 | }
47 | return weaponIndex;
48 | }
49 | set
50 | {
51 | weaponIndex = value;
52 | }
53 | }
54 |
55 | private int targetIndex = 0;
56 | private int TargetIndex
57 | {
58 | get
59 | {
60 | if (targetIndex < 0)
61 | {
62 | targetIndex = Targets.Length - 1;
63 | }
64 | if (targetIndex >= Targets.Length)
65 | {
66 | targetIndex = 0;
67 | }
68 | return targetIndex;
69 | }
70 | set
71 | {
72 | targetIndex = value;
73 | }
74 | }
75 |
76 | ///
77 | /// This proprty will return information like health, current weapon...
78 | ///
79 | public string Info
80 | {
81 | get
82 | {
83 | string info = "";
84 |
85 | info += "Player " + UserIndex + " Weapon: ~n~" + weapons[WeaponIndex];
86 |
87 | return info;
88 | }
89 | }
90 |
91 | private Dictionary lastActions = new Dictionary();
92 | public readonly InputManager Input;
93 | private readonly PedHash CharacterHash;
94 | private readonly Color MarkerColor;
95 |
96 | ///
97 | /// Constructs a new PlayerPed and sets all required properties
98 | ///
99 | /// The UserIndex of this PlayerPed
100 | /// The PedHash off this PlayerPed
101 | /// Any BlipSprite
102 | /// Any BlipColor
103 | /// The Player 1 Ped
104 | /// InputManager instance
105 | public PlayerPed(UserIndex userIndex, PedHash characterHash, BlipSprite blipSprite, BlipColor blipColor, Ped player1, InputManager input)
106 | {
107 | UserIndex = userIndex;
108 | CharacterHash = characterHash;
109 | Player1 = player1;
110 | Input = input;
111 |
112 | SetupPed();
113 |
114 | foreach (PlayerPedAction action in Enum.GetValues(typeof(PlayerPedAction)))
115 | {
116 | lastActions[action] = Game.GameTime;
117 | }
118 |
119 | switch (blipColor)
120 | {
121 | case BlipColor.White:
122 | MarkerColor = Color.White;
123 | break;
124 | case BlipColor.Red:
125 | MarkerColor = Color.Red;
126 | break;
127 | case BlipColor.Green:
128 | MarkerColor = Color.Green;
129 | break;
130 | case BlipColor.Blue:
131 | MarkerColor = Color.Blue;
132 | break;
133 | case BlipColor.Yellow:
134 | MarkerColor = Color.Yellow;
135 | break;
136 | default:
137 | MarkerColor = Color.OrangeRed;
138 | break;
139 | }
140 |
141 | UpdateBlip(blipSprite, blipColor);
142 | }
143 |
144 | ///
145 | /// This will setup the Ped and set all required properties
146 | ///
147 | private void SetupPed()
148 | {
149 | Ped = World.CreatePed(CharacterHash, Player1.Position.Around(5));
150 | MaxHealth = Ped.Health;
151 |
152 | while (!Ped.Exists())
153 | {
154 | Script.Wait(100);
155 | }
156 |
157 | Ped.Task.ClearAllImmediately();
158 |
159 | Ped.AlwaysKeepTask = true;
160 | Ped.NeverLeavesGroup = true;
161 | Ped.CanBeTargetted = true;
162 | Ped.RelationshipGroup = Player1.RelationshipGroup;
163 | Ped.CanRagdoll = false;
164 | Ped.IsEnemy = false;
165 | Ped.DrownsInWater = false;
166 | Ped.DiesInstantlyInWater = false;
167 | Ped.DropsWeaponsOnDeath = false;
168 |
169 | // dont let the playerped decide what to do when there is combat etc.
170 | Function.Call(Hash.SET_BLOCKING_OF_NON_TEMPORARY_EVENTS, Ped, true);
171 | Function.Call(Hash.SET_PED_FLEE_ATTRIBUTES, Ped, 0, 0);
172 | Function.Call(Hash.SET_PED_COMBAT_ATTRIBUTES, Ped, 46, true);
173 |
174 | foreach (WeaponHash hash in Enum.GetValues(typeof(WeaponHash)))
175 | {
176 | try
177 | {
178 | Weapon weapon = Ped.Weapons.Give(hash, int.MaxValue, true, true);
179 | weapon.InfiniteAmmo = true;
180 | weapon.InfiniteAmmoClip = true;
181 | }
182 | catch (Exception)
183 | {
184 | }
185 | }
186 |
187 | SelectWeapon(Ped, weapons[WeaponIndex]);
188 | }
189 |
190 | ///
191 | /// Gets targets for the given player in combat situations
192 | ///
193 | /// An array of Peds
194 | private Ped[] GetTargets()
195 | {
196 | return World.GetNearbyPeds(Ped, 50).Where(p => IsValidTarget(p)).OrderBy(p => p.Position.DistanceTo(Ped.Position)).ToArray();
197 | }
198 |
199 | ///
200 | /// Helper method to check if a Ped is a valid target for player 2
201 | ///
202 | /// The target Ped to check
203 | private bool IsValidTarget(Ped target)
204 | {
205 | return target != null && !target.IsPlayerPed() && target != Player1 && target.IsAlive && target.IsOnScreen;
206 | }
207 |
208 | ///
209 | /// Method to select another weapon for a Ped
210 | ///
211 | /// target Ped
212 | /// target WeaponHash
213 | private void SelectWeapon(Ped p, WeaponHash weaponHash)
214 | {
215 | WeaponIndex = Array.IndexOf(weapons, weaponHash);
216 |
217 | Function.Call(Hash.SET_CURRENT_PED_WEAPON, p, new InputArgument(weaponHash), true);
218 | UpdateLastAction(PlayerPedAction.SelectWeapon);
219 | }
220 |
221 | ///
222 | /// This method will update this PlayerPed blip sprite and color
223 | ///
224 | /// new BlipSprite
225 | /// new BlipColor
226 | public void UpdateBlip(BlipSprite sprite, BlipColor color)
227 | {
228 | Ped.CurrentBlip.Remove();
229 | Ped.AddBlip().Sprite = sprite;
230 | Ped.CurrentBlip.Color = color;
231 | }
232 |
233 | ///
234 | /// This method will get called by the Script so this PlayerPed can update its state
235 | ///
236 | public void Tick()
237 | {
238 | if (Ped.IsInVehicle())
239 | {
240 | UpdateCombat(() => { return Input.isPressed(DeviceButton.LeftShoulder); }, () => { return Input.isPressed(DeviceButton.RightShoulder); });
241 |
242 | Vehicle v = Ped.CurrentVehicle;
243 |
244 | if (v.GetPedOnSeat(VehicleSeat.Driver) == Ped)
245 | {
246 | VehicleAction action = GetVehicleAction(v);
247 | if (action != LastVehicleAction)
248 | {
249 | LastVehicleAction = action;
250 |
251 | PerformVehicleAction(Ped, v, action);
252 | }
253 | }
254 |
255 | if (Input.isPressed(DeviceButton.X))
256 | {
257 | if (CanDoAction(PlayerPedAction.SelectWeapon, 500))
258 | {
259 | if (UpdateWeaponIndex())
260 | {
261 | SelectWeapon(Ped, weapons[WeaponIndex]);
262 | }
263 | }
264 | NotifyWeapon();
265 | }
266 | }
267 | else
268 | {
269 | UpdateFoot();
270 | }
271 |
272 | // for entering / leaving a vehicle
273 | if (Input.isPressed(DeviceButton.Y))
274 | {
275 | if (Ped.IsInVehicle())
276 | {
277 | Vehicle v = Ped.CurrentVehicle;
278 | if (v.Speed > 7f)
279 | {
280 | //4160 = ped is throwing himself out, even when the vehicle is still (that's what the speed check is for)
281 | Function.Call(Hash.TASK_LEAVE_VEHICLE, Ped, v, 4160);
282 | }
283 | else
284 | {
285 | Ped.Task.LeaveVehicle();
286 | }
287 | }
288 | else
289 | {
290 | TwoPlayerMod.HandleEnterVehicle(Ped);
291 | }
292 | }
293 |
294 | if (Ped.IsDead)
295 | {
296 | UI.Notify("Player " + "~g~" + UserIndex + "~w~ press ~g~" + DeviceButton.Back + "~w~ to respawn~w~.");
297 | if (Input.isPressed(DeviceButton.Back))
298 | {
299 | Respawn();
300 | }
301 | }
302 |
303 | if (!Ped.IsNearEntity(Player1, new Vector3(20, 20, 20)))
304 | {
305 | UI.Notify("Player " + "~g~" + UserIndex + "~w~ press ~g~" + DeviceButton.Back + "~w~ to go back to player ~g~" + UserIndex.One + "~w~.");
306 | if (Input.isPressed(DeviceButton.Back))
307 | {
308 | Ped.Position = Player1.Position.Around(5);
309 | }
310 | }
311 | }
312 |
313 | ///
314 | /// This method will respawn this PlayerPed
315 | ///
316 | public void Respawn()
317 | {
318 | if (Ped != null)
319 | {
320 | Ped.Delete();
321 | }
322 | SetupPed();
323 | }
324 |
325 | ///
326 | /// Determines the needed action corresponding to current controller input, e.g. VehicleAction.RevEngine
327 | ///
328 | /// A VehicleAction enum
329 | private VehicleAction GetVehicleAction(Vehicle v)
330 | {
331 | Direction dir = Input.GetDirection(DeviceButton.LeftStick);
332 | if (Input.isPressed(DeviceButton.A))
333 | {
334 | if (Input.IsDirectionLeft(dir))
335 | {
336 | return VehicleAction.HandBrakeLeft;
337 | }
338 | else if (Input.IsDirectionRight(dir))
339 | {
340 | return VehicleAction.HandBrakeRight;
341 | }
342 | else
343 | {
344 | return VehicleAction.HandBrakeStraight;
345 | }
346 | }
347 |
348 | if (Input.isPressed(DeviceButton.RightTrigger))
349 | {
350 | if (Input.IsDirectionLeft(dir))
351 | {
352 | return VehicleAction.GoForwardLeft;
353 | }
354 | else if (Input.IsDirectionRight(dir))
355 | {
356 | return VehicleAction.GoForwardRight;
357 | }
358 | else
359 | {
360 | return VehicleAction.GoForwardStraightFast;
361 | }
362 | }
363 |
364 | if (Input.isPressed(DeviceButton.LeftTrigger))
365 | {
366 | if (Input.IsDirectionLeft(dir))
367 | {
368 | return VehicleAction.ReverseLeft;
369 | }
370 | else if (Input.IsDirectionRight(dir))
371 | {
372 | return VehicleAction.ReverseRight;
373 | }
374 | else
375 | {
376 | return VehicleAction.ReverseStraight;
377 | }
378 | }
379 |
380 | if (Input.IsDirectionLeft(dir))
381 | {
382 | return VehicleAction.SwerveLeft;
383 | }
384 | else if (Input.IsDirectionRight(dir))
385 | {
386 | return VehicleAction.SwerveRight;
387 | }
388 |
389 | return VehicleAction.RevEngine;
390 | }
391 |
392 | ///
393 | /// Helper method to check if a WeaponHash is a throwable like Grenade or Molotov
394 | ///
395 | /// WeaponHash to check
396 | /// true if the given WeaponHash is throwable, false otherwise
397 | private bool IsThrowable(WeaponHash hash)
398 | {
399 | return throwables.Contains(hash);
400 | }
401 |
402 | ///
403 | /// Helper method to check if a WeaponHash is a melee weapon
404 | ///
405 | /// WeaponHash to check
406 | /// true if the given WeaponHash is melee, false otherwise
407 | private bool IsMelee(WeaponHash hash)
408 | {
409 | return meleeWeapons.Contains(hash);
410 | }
411 |
412 | ///
413 | /// Cleans up this PlayerPed
414 | ///
415 | public void Clean()
416 | {
417 | if (Ped != null)
418 | {
419 | Ped.Delete();
420 | Ped = null;
421 | }
422 | if (Input != null)
423 | {
424 | Input.Cleanup();
425 | }
426 | }
427 |
428 | ///
429 | /// Calls the TASK_VEHICLE_TEMP_ACTION native in order to control a Vehicle
430 | ///
431 | /// The driver
432 | /// The target Vehicle
433 | /// Any of enum VehicleAction
434 | private void PerformVehicleAction(Ped ped, Vehicle vehicle, VehicleAction action)
435 | {
436 | Function.Call(Hash.TASK_VEHICLE_TEMP_ACTION, ped, vehicle, (int)action, -1);
437 | }
438 |
439 | private bool resetWalking = false;
440 |
441 | ///
442 | /// Updates all kind of on foot actions like walking entering exiting vehicles
443 | ///
444 | private void UpdateFoot()
445 | {
446 | UpdateCombat(() => { return Input.isPressed(DeviceButton.LeftTrigger); }, () => { return Input.isPressed(DeviceButton.RightTrigger); });
447 |
448 | Vector2 leftThumb = Input.GetState().LeftThumbStick;
449 |
450 | if (leftThumb != Vector2.Zero)
451 | {
452 | if (Input.isPressed(DeviceButton.A))
453 | {
454 | // needed for running
455 | leftThumb *= 10;
456 | }
457 | Vector3 dest = Vector3.Zero;
458 | if (TwoPlayerMod.customCamera)
459 | {
460 | dest = Ped.Position - new Vector3(leftThumb.X, leftThumb.Y, 0);
461 | }
462 | else
463 | {
464 | dest = Ped.GetOffsetInWorldCoords(new Vector3(leftThumb.X, leftThumb.Y, 0));
465 | }
466 |
467 | Ped.Task.RunTo(dest, true, -1);
468 | resetWalking = true;
469 | }
470 | else if (resetWalking)
471 | {
472 | Ped.Task.ClearAll();
473 | resetWalking = false;
474 | }
475 |
476 | if (Input.isPressed(DeviceButton.X) && CanDoAction(PlayerPedAction.Jump, 850))
477 | {
478 | Ped.Task.Climb();
479 | UpdateLastAction(PlayerPedAction.Jump);
480 | }
481 |
482 | if (Input.isPressed(DeviceButton.LeftShoulder))
483 | {
484 | if (CanDoAction(PlayerPedAction.SelectWeapon, 500))
485 | {
486 | if (UpdateWeaponIndex())
487 | {
488 | SelectWeapon(Ped, weapons[WeaponIndex]);
489 | }
490 | }
491 | NotifyWeapon();
492 | }
493 | }
494 |
495 | ///
496 | /// Helper method to show the current weapon and show the user what to do to change the weapon
497 | ///
498 | private void NotifyWeapon()
499 | {
500 | UI.ShowSubtitle("Player 2 weapon: ~g~" + weapons[WeaponIndex] + "~w~. Use ~g~" + (Ped.IsInVehicle() ? DeviceButton.LeftStick : DeviceButton.RightStick) + "~w~ to select weapons.");
501 | }
502 |
503 | ///
504 | /// This will fire at the targeted ped and will handle changing targets
505 | ///
506 | /// The first (aiming) button which needs to pressed before handling this update
507 | /// The second (firing) button which needs to pressed before the actual shooting
508 | private void UpdateCombat(Func firstButton, Func secondButton)
509 | {
510 | if (Input.isPressed(DeviceButton.DPadLeft))
511 | {
512 | foreach (WeaponHash projectile in throwables)
513 | {
514 | Function.Call(Hash.EXPLODE_PROJECTILES, Ped, new InputArgument(projectile), true);
515 | }
516 | }
517 | if (firstButton.Invoke())
518 | {
519 | if (!secondButton.Invoke())
520 | {
521 | Targets = GetTargets();
522 | }
523 | if (CanDoAction(PlayerPedAction.SelectTarget, 500))
524 | {
525 | Direction dir = Input.GetDirection(DeviceButton.RightStick);
526 | if (Input.IsDirectionLeft(dir))
527 | {
528 | TargetIndex--;
529 | UpdateLastAction(PlayerPedAction.SelectTarget);
530 | }
531 | if (Input.IsDirectionRight(dir))
532 | {
533 | TargetIndex++;
534 | UpdateLastAction(PlayerPedAction.SelectTarget);
535 | }
536 | }
537 |
538 | Ped target = Targets.ElementAtOrDefault(TargetIndex);
539 |
540 | if (target == null)
541 | {
542 | return;
543 | }
544 |
545 | if (!target.IsAlive)
546 | {
547 | Targets = GetTargets();
548 | }
549 |
550 | if (target != null)
551 | {
552 | World.DrawMarker(MarkerType.UpsideDownCone, target.GetBoneCoord(Bone.SKEL_Head) + new Vector3(0, 0, 1), GameplayCamera.Direction, GameplayCamera.Rotation, new Vector3(1, 1, 1), Color.OrangeRed);
553 |
554 | if (secondButton.Invoke())
555 | {
556 | SelectWeapon(Ped, weapons[WeaponIndex]);
557 |
558 | if (IsThrowable(weapons[WeaponIndex]))
559 | {
560 | if (CanDoAction(PlayerPedAction.ThrowTrowable, 1500))
561 | {
562 | Function.Call(Hash.TASK_THROW_PROJECTILE, Ped, target.Position.X, target.Position.Y, target.Position.Z);
563 | UpdateLastAction(PlayerPedAction.ThrowTrowable);
564 | }
565 | }
566 | else if (CanDoAction(PlayerPedAction.Shoot, 750))
567 | {
568 | if (Ped.IsInVehicle())
569 | {
570 | Function.Call(Hash.TASK_DRIVE_BY, Ped, target, 0, 0, 0, 0, 50.0f, 100, 1, (uint)FiringPattern.FullAuto);
571 | }
572 | else if (IsMelee(weapons[WeaponIndex]))
573 | {
574 | // Ped.Task.ShootAt(target, 750, FiringPattern.FullAuto);
575 | // UI.ShowSubtitle("Melee weapons are not supported yet.");
576 | Ped.Task.FightAgainst(target, -1);
577 |
578 | }
579 | else
580 | {
581 | Ped.Task.ShootAt(target, 750, FiringPattern.FullAuto);
582 | }
583 |
584 | UpdateLastAction(PlayerPedAction.Shoot);
585 | }
586 | }
587 | else
588 | {
589 | Ped.Task.AimAt(target, 100);
590 | }
591 | }
592 |
593 | if (Ped.IsOnScreen)
594 | {
595 | Vector3 headPos = Ped.GetBoneCoord(Bone.SKEL_Head);
596 | headPos.Z += 0.3f;
597 | headPos.X += 0.1f;
598 |
599 | UIRectangle rect = new UIRectangle(UI.WorldToScreen(headPos), new Size(MaxHealth / 2, 5), Color.LimeGreen);
600 | rect.Draw();
601 | rect.Size = new Size(Ped.Health / 2, 5);
602 | rect.Color = Color.IndianRed;
603 | rect.Draw();
604 | }
605 | }
606 | else
607 | {
608 | TargetIndex = 0;
609 | }
610 | }
611 |
612 | ///
613 | /// Updates the selection of weapon for Player 2
614 | ///
615 | /// true if weaponIndex changed, false otherwise
616 | private bool UpdateWeaponIndex()
617 | {
618 | Direction dir = Input.GetDirection(Ped.IsInVehicle() ? DeviceButton.LeftStick : DeviceButton.RightStick);
619 |
620 | if (Input.IsDirectionLeft(dir))
621 | {
622 | WeaponIndex--;
623 | return true;
624 | }
625 | if (Input.IsDirectionRight(dir))
626 | {
627 | WeaponIndex++;
628 | return true;
629 | }
630 | return false;
631 | }
632 |
633 | ///
634 | /// Helper method to determine if player 2 is allowed to do the given PlayerPedAction
635 | ///
636 | /// PlayerPedAction to check
637 | /// minimal time that has to be past before true
638 | /// true if time since last PlayerPedAction is more than given time, false otherwise
639 | private bool CanDoAction(PlayerPedAction action, int time)
640 | {
641 | return Game.GameTime - lastActions[action] >= time;
642 | }
643 |
644 | ///
645 | /// Updates the time of the given PlayerPedAction
646 | ///
647 | /// Target PlayerPedAction
648 | private void UpdateLastAction(PlayerPedAction action)
649 | {
650 | lastActions[action] = Game.GameTime;
651 | }
652 | }
653 | }
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | TwoPlayerMod Copyright (C) 2016 BenjaminFaal
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Dependencies/ScriptHookVDotNet.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | "ScriptHookVDotNet"
5 |
6 |
7 |
8 |
9 | Starts an animation.
10 |
11 | The animation dictionary.
12 | The animation name.
13 | Normal value is 8.0.
14 | Normal value is -8.0.
15 | The duration.
16 | The animation flags.
17 | Values are between 0.0 and 1.0.
18 |
19 |
20 |
21 | Starts an animation.
22 |
23 | The animation dictionary.
24 | The animation name.
25 | Normal value is 8.0.
26 | The duration.
27 | The animation flags.
28 |
29 |
30 |
31 | Starts an animation.
32 |
33 | The animation dictionary.
34 | The animation name.
35 |
36 |
37 | Have more than one menu on the screen on the time and transition them
38 |
39 |
40 | The offset each menu in the stack has from the one above it
41 |
42 |
43 | The top left position of the current menu
44 |
45 |
46 | Handles when the user presses the left or right button (e.g. numpad-4 and 6)
47 |
48 |
49 | Handles when the user presses the up or down button (e.g. numpad-2 and 8)
50 |
51 |
52 | Handles when the back button is pressed (e.g. numpad-0)
53 |
54 |
55 | Handles when the activate button is pressed (e.g. numpad-5)
56 |
57 |
58 | Draw all the active UIs
59 |
60 |
61 | Closes all menus
62 |
63 |
64 | Remove the active menu from the stack, this will focus the next highest menu
65 |
66 |
67 | Remove a menu from the stack of active menus
68 |
69 |
70 | Add a menu to the stack of active menus and set it as focused
71 |
72 |
73 | Set by the parent so that the MenuItem can access its properties
74 |
75 |
76 | Called by the Menu to set this item's origin
77 |
78 |
79 | Called when the user changes this item (e.g. numpad-4 and 6)
80 |
81 |
82 | Called when the user activates this item (e.g. numpad-5)
83 |
84 |
85 | Called when the user deselects this item
86 |
87 |
88 | Called when the user selects this item
89 |
90 |
91 | Called when the MenuItem should be drawn with an offset
92 |
93 |
94 | Called when the MenuItem should be drawn
95 |
96 |
97 | Use Ok and Cancel instead of Yes and No
98 |
99 |
100 | Called when the user changes the current element (i.e. left and right)
101 |
102 |
103 | Called when the user changes what element is selected (i.e. up and down)
104 |
105 |
106 | Called when the user hits the activate button
107 |
108 |
109 | Called when the user hits the back button or unfocuses from this menu
110 |
111 |
112 | Called when the menu gains or regains focus
113 |
114 |
115 | Called when the menu is first added to the Viewport
116 |
117 |
118 | Draws the menu with an offset
119 |
120 |
121 | Draws the menu
122 |
123 |
124 |
125 | Determines whether the specified object instances are considered equal.
126 |
127 |
128 |
129 |
130 | true if is the same instance as or
131 | if both are null references or if value1.Equals(value2) returns true; otherwise, false.
132 |
133 |
134 |
135 | Returns a value that indicates whether the current instance is equal to the specified object.
136 |
137 | Object to make the comparison with.
138 |
139 | true if the current instance is equal to the specified object; false otherwise.
140 |
141 |
142 |
143 | Returns a value that indicates whether the current instance is equal to a specified object.
144 |
145 | Object to make the comparison with.
146 |
147 | true if the current instance is equal to the specified object; false otherwise.
148 |
149 |
150 |
151 | Returns the hash code for this instance.
152 |
153 | A 32-bit signed integer hash code.
154 |
155 |
156 |
157 | Converts the value of the object to its equivalent string representation.
158 |
159 | The string representation of the value of this instance.
160 |
161 |
162 |
163 | Converts the matrix to an array of floats.
164 |
165 |
166 |
167 |
168 | Tests for inequality between two objects.
169 |
170 | The first value to compare.
171 | The second value to compare.
172 |
173 | true if has a different value than ; otherwise, false.
174 |
175 |
176 |
177 | Tests for equality between two objects.
178 |
179 | The first value to compare.
180 | The second value to compare.
181 |
182 | true if has the same value as ; otherwise, false.
183 |
184 |
185 |
186 | Scales a matrix by a given value.
187 |
188 | The matrix to scale.
189 | The amount by which to scale.
190 | The scaled matrix.
191 |
192 |
193 |
194 | Scales a matrix by a given value.
195 |
196 | The matrix to scale.
197 | The amount by which to scale.
198 | The scaled matrix.
199 |
200 |
201 |
202 | Multiplies two matricies.
203 |
204 | The first matrix to multiply.
205 | The second matrix to multiply.
206 | The product of the two matricies.
207 |
208 |
209 |
210 | Scales a matrix by a given value.
211 |
212 | The matrix to scale.
213 | The amount by which to scale.
214 | The scaled matrix.
215 |
216 |
217 |
218 | Divides two matricies.
219 |
220 | The first matrix to divide.
221 | The second matrix to divide.
222 | The quotient of the two matricies.
223 |
224 |
225 |
226 | Subtracts two matricies.
227 |
228 | The first matrix to subtract.
229 | The second matrix to subtract.
230 | The difference between the two matricies.
231 |
232 |
233 |
234 | Adds two matricies.
235 |
236 | The first matrix to add.
237 | The second matrix to add.
238 | The sum of the two matricies.
239 |
240 |
241 |
242 | Negates a matrix.
243 |
244 | The matrix to negate.
245 | The negated matrix.
246 |
247 |
248 |
249 | Calculates the transpose of the specified matrix.
250 |
251 | The matrix whose transpose is to be calculated.
252 | The transpose of the specified matrix.
253 |
254 |
255 |
256 | Creates a translation matrix using the specified offsets.
257 |
258 | The offset for all three coordinate planes.
259 | The created translation matrix.
260 |
261 |
262 |
263 | Creates a translation matrix using the specified offsets.
264 |
265 | X-coordinate offset.
266 | Y-coordinate offset.
267 | Z-coordinate offset.
268 | The created translation matrix.
269 |
270 |
271 |
272 | Creates a matrix that scales along the x-axis, y-axis, and y-axis.
273 |
274 | Scaling factor for all three axes.
275 | The created scaling matrix.
276 |
277 |
278 |
279 | Creates a matrix that scales along the x-axis, y-axis, and y-axis.
280 |
281 | Scaling factor that is applied along the x-axis.
282 | Scaling factor that is applied along the y-axis.
283 | Scaling factor that is applied along the z-axis.
284 | The created scaling matrix.
285 |
286 |
287 |
288 | Creates a rotation matrix with a specified yaw, pitch, and roll.
289 |
290 | Yaw around the y-axis, in radians.
291 | Pitch around the x-axis, in radians.
292 | Roll around the z-axis, in radians.
293 | The created rotation matrix.
294 |
295 |
296 |
297 | Creates a rotation matrix from a quaternion.
298 |
299 | The quaternion to use to build the matrix.
300 | The created rotation matrix.
301 |
302 |
303 |
304 | Creates a matrix that rotates around an arbitary axis.
305 |
306 | The axis around which to rotate.
307 | Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.
308 | The created rotation matrix.
309 |
310 |
311 |
312 | Creates a matrix that rotates around the z-axis.
313 |
314 | Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.
315 | The created rotation matrix.
316 |
317 |
318 |
319 | Creates a matrix that rotates around the y-axis.
320 |
321 | Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.
322 | The created rotation matrix.
323 |
324 |
325 |
326 | Creates a matrix that rotates around the x-axis.
327 |
328 | Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.
329 | The created rotation matrix.
330 |
331 |
332 |
333 | Performs a linear interpolation between two matricies.
334 |
335 | Start matrix.
336 | End matrix.
337 | Value between 0 and 1 indicating the weight of .
338 | The linear interpolation of the two matrices.
339 |
340 | This method performs the linear interpolation based on the following formula.
341 | start + (end - start) * amount
342 | Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned.
343 |
344 |
345 |
346 |
347 | Calculates the inverse of a matrix if it exists.
348 |
349 | The inverse of the matrix.
350 |
351 |
352 |
353 | Negates a matrix.
354 |
355 | The matrix to be negated.
356 | The negated matrix.
357 |
358 |
359 |
360 | Scales a matrix by the given value.
361 |
362 | The matrix to scale.
363 | The amount by which to scale.
364 | The scaled matrix.
365 |
366 |
367 |
368 | Determines the quotient of two matrices.
369 |
370 | The first matrix to divide.
371 | The second matrix to divide.
372 | The quotient of the two matrices.
373 |
374 |
375 |
376 | Scales a matrix by the given value.
377 |
378 | The matrix to scale.
379 | The amount by which to scale.
380 | The scaled matrix.
381 |
382 |
383 |
384 | Determines the product of two matrices.
385 |
386 | The first matrix to multiply.
387 | The second matrix to multiply.
388 | The product of the two matrices.
389 |
390 |
391 |
392 | Determines the difference between two matrices.
393 |
394 | The first matrix to subtract.
395 | The second matrix to subtract.
396 | The difference between the two matrices.
397 |
398 |
399 |
400 | Determines the sum of two matrices.
401 |
402 | The first matrix to add.
403 | The second matrix to add.
404 | The sum of the two matrices.
405 |
406 |
407 |
408 | Calculates the inverse of the matrix if it exists.
409 |
410 |
411 |
412 |
413 | Calculates the determinant of the matrix.
414 |
415 | The determinant of the matrix.
416 |
417 |
418 |
419 | Converts the matrix to an array of floats.
420 |
421 |
422 |
423 |
424 | Gets a value indicating whether this instance has an inverse matrix.
425 |
426 |
427 |
428 |
429 | Gets a value indicating whether this instance is an identity matrix.
430 |
431 |
432 |
433 |
434 | Gets a that represents an identity matrix.
435 |
436 |
437 |
438 |
439 | Gets or sets the element of the matrix that exists in the fourth row and fourth column.
440 |
441 |
442 |
443 |
444 | Gets or sets the element of the matrix that exists in the fourth row and third column.
445 |
446 |
447 |
448 |
449 | Gets or sets the element of the matrix that exists in the fourth row and second column.
450 |
451 |
452 |
453 |
454 | Gets or sets the element of the matrix that exists in the fourth row and first column.
455 |
456 |
457 |
458 |
459 | Gets or sets the element of the matrix that exists in the third row and fourth column.
460 |
461 |
462 |
463 |
464 | Gets or sets the element of the matrix that exists in the third row and third column.
465 |
466 |
467 |
468 |
469 | Gets or sets the element of the matrix that exists in the third row and second column.
470 |
471 |
472 |
473 |
474 | Gets or sets the element of the matrix that exists in the third row and first column.
475 |
476 |
477 |
478 |
479 | Gets or sets the element of the matrix that exists in the second row and fourth column.
480 |
481 |
482 |
483 |
484 | Gets or sets the element of the matrix that exists in the second row and third column.
485 |
486 |
487 |
488 |
489 | Gets or sets the element of the matrix that exists in the second row and second column.
490 |
491 |
492 |
493 |
494 | Gets or sets the element of the matrix that exists in the second row and first column.
495 |
496 |
497 |
498 |
499 | Gets or sets the element of the matrix that exists in the first row and fourth column.
500 |
501 |
502 |
503 |
504 | Gets or sets the element of the matrix that exists in the first row and third column.
505 |
506 |
507 |
508 |
509 | Gets or sets the element of the matrix that exists in the first row and second column.
510 |
511 |
512 |
513 |
514 | Gets or sets the element of the matrix that exists in the first row and first column.
515 |
516 |
517 |
518 |
519 | Defines a 4x4 matrix.
520 |
521 | D3DXMATRIX
522 |
523 |
524 | Gets or sets the current transition ratio of the weather.
525 | A Single representing the current time ratio between 0.0f and 1.0f.
526 |
527 |
528 |
529 | Determines whether the specified object instances are considered equal.
530 |
531 | The first value to compare.
532 | The second value to compare.
533 |
534 | true if is the same instance as or
535 | if both are null references or if value1.Equals(value2) returns true; otherwise, false.
536 |
537 |
538 |
539 | Returns a value that indicates whether the current instance is equal to the specified object.
540 |
541 | Object to make the comparison with.
542 |
543 | true if the current instance is equal to the specified object; false otherwise.
544 |
545 |
546 |
547 | Returns a value that indicates whether the current instance is equal to a specified object.
548 |
549 | Object to make the comparison with.
550 |
551 | true if the current instance is equal to the specified object; false otherwise.
552 |
553 |
554 |
555 | Returns the hash code for this instance.
556 |
557 | A 32-bit signed integer hash code.
558 |
559 |
560 |
561 | Converts the value of the object to its equivalent string representation.
562 |
563 | The string representation of the value of this instance.
564 |
565 |
566 |
567 | Tests for inequality between two objects.
568 |
569 | The first value to compare.
570 | The second value to compare.
571 |
572 | true if has a different value than ; otherwise, false.
573 |
574 |
575 |
576 | Tests for equality between two objects.
577 |
578 | The first value to compare.
579 | The second value to compare.
580 |
581 | true if has the same value as ; otherwise, false.
582 |
583 |
584 |
585 | Scales a vector by the given value.
586 |
587 | The vector to scale.
588 | The amount by which to scale the vector.
589 | The scaled vector.
590 |
591 |
592 |
593 | Scales a vector by the given value.
594 |
595 | The vector to scale.
596 | The amount by which to scale the vector.
597 | The scaled vector.
598 |
599 |
600 |
601 | Scales a vector by the given value.
602 |
603 | The vector to scale.
604 | The amount by which to scale the vector.
605 | The scaled vector.
606 |
607 |
608 |
609 | Reverses the direction of a given vector.
610 |
611 | The vector to negate.
612 | A vector facing in the opposite direction.
613 |
614 |
615 |
616 | Subtracts two vectors.
617 |
618 | The first vector to subtract.
619 | The second vector to subtract.
620 | The difference of the two vectors.
621 |
622 |
623 |
624 | Adds two vectors.
625 |
626 | The first vector to add.
627 | The second vector to add.
628 | The sum of the two vectors.
629 |
630 |
631 |
632 | Returns a vector containing the largest components of the specified vectors.
633 |
634 | The first source vector.
635 | The second source vector.
636 | A vector containing the largest components of the source vectors.
637 |
638 |
639 |
640 | Returns a vector containing the smallest components of the specified vectors.
641 |
642 | The first source vector.
643 | The second source vector.
644 | A vector containing the smallest components of the source vectors.
645 |
646 |
647 |
648 | Returns the reflection of a vector off a surface that has the specified normal.
649 |
650 | The source vector.
651 | Normal of the surface.
652 | The reflected vector.
653 | Reflect only gives the direction of a reflection off a surface, it does not determine
654 | whether the original vector was close enough to the surface to hit it.
655 |
656 |
657 |
658 | Calculates the dot product of two vectors.
659 |
660 | First source vector.
661 | Second source vector.
662 | The dot product of the two vectors.
663 |
664 |
665 |
666 | Converts the vector into a unit vector.
667 |
668 | The vector to normalize.
669 | The normalized vector.
670 |
671 |
672 |
673 | Performs a linear interpolation between two vectors.
674 |
675 | Start vector.
676 | End vector.
677 | Value between 0 and 1 indicating the weight of .
678 | The linear interpolation of the two vectors.
679 |
680 | This method performs the linear interpolation based on the following formula.
681 | start + (end - start) * amount
682 | Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned.
683 |
684 |
685 |
686 |
687 | Restricts a value to be within a specified range.
688 |
689 | The value to clamp.
690 | The minimum value.
691 | The maximum value.
692 | The clamped value.
693 |
694 |
695 |
696 | Reverses the direction of a given vector.
697 |
698 | The vector to negate.
699 | A vector facing in the opposite direction.
700 |
701 |
702 |
703 | Scales a vector by the given value.
704 |
705 | The vector to scale.
706 | The amount by which to scale the vector.
707 | The scaled vector.
708 |
709 |
710 |
711 | Modulates a vector by another.
712 |
713 | The first vector to modulate.
714 | The second vector to modulate.
715 | The modulated vector.
716 |
717 |
718 |
719 | Scales a vector by the given value.
720 |
721 | The vector to scale.
722 | The amount by which to scale the vector.
723 | The scaled vector.
724 |
725 |
726 |
727 | Subtracts two vectors.
728 |
729 | The first vector to subtract.
730 | The second vector to subtract.
731 | The difference of the two vectors.
732 |
733 |
734 |
735 | Adds two vectors.
736 |
737 | The first vector to add.
738 | The second vector to add.
739 | The sum of the two vectors.
740 |
741 |
742 |
743 | Returns a new normalized vector with random X and Y components.
744 |
745 |
746 |
747 |
748 | Converts a vector to a heading.
749 |
750 |
751 |
752 |
753 | Returns the signed angle in degrees between from and to.
754 |
755 |
756 |
757 |
758 | Returns the angle in degrees between from and to.
759 | The angle returned is always the acute angle between the two vectors.
760 |
761 |
762 |
763 |
764 | Calculates the squared distance between two vectors.
765 |
766 | The first vector to calculate the squared distance to the second vector.
767 | The second vector to calculate the squared distance to the first vector.
768 | The squared distance between the two vectors.
769 |
770 |
771 |
772 | Calculates the distance between two vectors.
773 |
774 | The first vector to calculate the distance to the second vector.
775 | The second vector to calculate the distance to the first vector.
776 | The distance between the two vectors.
777 |
778 |
779 |
780 | Calculates the squared distance between two vectors.
781 |
782 | The second vector to calculate the squared distance to.
783 | The squared distance to the other vector.
784 |
785 |
786 |
787 | Calculates the distance between two vectors.
788 |
789 | The second vector to calculate the distance to.
790 | The distance to the other vector.
791 |
792 |
793 |
794 | Converts the vector into a unit vector.
795 |
796 |
797 |
798 |
799 | Calculates the squared length of the vector.
800 |
801 | The squared length of the vector.
802 |
803 |
804 |
805 | Calculates the length of the vector.
806 |
807 | The length of the vector.
808 |
809 |
810 |
811 | Returns the left vector. (-1,0)
812 |
813 |
814 |
815 |
816 | Returns the right vector. (1,0)
817 |
818 |
819 |
820 |
821 | Returns the down vector. (0,-1)
822 |
823 |
824 |
825 |
826 | Returns the up vector. (0,1)
827 |
828 |
829 |
830 |
831 | Returns a null vector. (0,0)
832 |
833 |
834 |
835 |
836 | Returns this vector with a magnitude of 1.
837 |
838 |
839 |
840 |
841 | Initializes a new instance of the class.
842 |
843 | Initial value for the X component of the vector.
844 | Initial value for the Y component of the vector.
845 |
846 |
847 |
848 | Gets or sets the Y component of the vector.
849 |
850 | The Y component of the vector.
851 |
852 |
853 |
854 | Gets or sets the X component of the vector.
855 |
856 | The X component of the vector.
857 |
858 |
859 |
860 | Gets or sets the steering scale.
861 |
862 | A single between -1.0f (fully right) and 1.0f (fully left).
863 |
864 |
865 |
866 | Gets or sets the steering angle.
867 |
868 | The steering angle in degrees.
869 |
870 |
871 |
872 | Gets the speed the wheels are spinning at
873 |
874 | The speed in meters per second
875 |
876 |
877 | Can be broken into the car. if the glass is broken, the value will be set to 1.
878 |
879 |
880 | Doesn't allow players to exit the vehicle with the exit vehicle key.
881 |
882 |
883 |
884 | Determines whether the specified object instances are considered equal.
885 |
886 |
887 |
888 |
889 | true if is the same instance as or
890 | if both are null references or if value1.Equals(value2) returns true; otherwise, false.
891 |
892 |
893 |
894 | Returns a value that indicates whether the current instance is equal to the specified object.
895 |
896 | Object to make the comparison with.
897 |
898 | true if the current instance is equal to the specified object; false otherwise.
899 |
900 |
901 |
902 | Returns a value that indicates whether the current instance is equal to a specified object.
903 |
904 | Object to make the comparison with.
905 |
906 | true if the current instance is equal to the specified object; false otherwise.
907 |
908 |
909 |
910 | Returns the hash code for this instance.
911 |
912 | A 32-bit signed integer hash code.
913 |
914 |
915 |
916 | Converts the value of the object to its equivalent string representation.
917 |
918 | The string representation of the value of this instance.
919 |
920 |
921 |
922 | Tests for inequality between two objects.
923 |
924 | The first value to compare.
925 | The second value to compare.
926 |
927 | true if has a different value than ; otherwise, false.
928 |
929 |
930 |
931 | Tests for equality between two objects.
932 |
933 | The first value to compare.
934 | The second value to compare.
935 |
936 | true if has the same value as ; otherwise, false.
937 |
938 |
939 |
940 | Reverses the direction of a given quaternion.
941 |
942 | The quaternion to negate.
943 | A quaternion facing in the opposite direction.
944 |
945 |
946 |
947 | Subtracts two quaternions.
948 |
949 | The first quaternion to subtract.
950 | The second quaternion to subtract.
951 | The difference of the two quaternions.
952 |
953 |
954 |
955 | Adds two quaternions.
956 |
957 | The first quaternion to add.
958 | The second quaternion to add.
959 | The sum of the two quaternions.
960 |
961 |
962 |
963 | Divides a quaternion by another.
964 |
965 | The first quaternion to divide.
966 | The second quaternion to divide.
967 | The divided quaternion.
968 |
969 |
970 |
971 | Scales a quaternion by the given value.
972 |
973 | The quaternion to scale.
974 | The amount by which to scale the quaternion.
975 | The scaled quaternion.
976 |
977 |
978 |
979 | Scales a quaternion by the given value.
980 |
981 | The quaternion to scale.
982 | The amount by which to scale the quaternion.
983 | The scaled quaternion.
984 |
985 |
986 |
987 | Rotates the point with rotation.
988 |
989 | The quaternion to rotate the vector.
990 | The vector to be rotated.
991 | The vector after rotation.
992 |
993 |
994 |
995 | Multiplies a quaternion by another.
996 |
997 | The first quaternion to multiply.
998 | The second quaternion to multiply.
999 | The multiplied quaternion.
1000 |
1001 |
1002 |
1003 | Subtracts two quaternions.
1004 |
1005 | The first quaternion to subtract.
1006 | The second quaternion to subtract.
1007 | The difference of the two quaternions.
1008 |
1009 |
1010 |
1011 | Creates a quaternion given a yaw, pitch, and roll value.
1012 |
1013 | The yaw of rotation.
1014 | The pitch of rotation.
1015 | The roll of rotation.
1016 | The newly created quaternion.
1017 |
1018 |
1019 |
1020 | Creates a quaternion given a rotation matrix.
1021 |
1022 | The rotation matrix.
1023 | The newly created quaternion.
1024 |
1025 |
1026 |
1027 | Creates a quaternion given a rotation and an axis.
1028 |
1029 | The axis of rotation.
1030 | The angle of rotation.
1031 | The newly created quaternion.
1032 |
1033 |
1034 |
1035 | Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).
1036 |
1037 | Euler angles in degrees.
1038 |
1039 |
1040 |
1041 | eturns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).
1042 |
1043 | X degrees.
1044 | Y degrees.
1045 | Z degrees.
1046 |
1047 |
1048 |
1049 | Returns the angle in degrees between two rotations a and b.
1050 |
1051 | The first quaternion to calculate angle.
1052 | The second quaternion to calculate angle.
1053 | The angle in degrees between two rotations a and b.
1054 |
1055 |
1056 |
1057 | Converts the quaternion into a unit quaternion.
1058 |
1059 | The quaternion to normalize.
1060 | The normalized quaternion.
1061 |
1062 |
1063 |
1064 | Reverses the direction of a given quaternion.
1065 |
1066 | The quaternion to negate.
1067 | A quaternion facing in the opposite direction.
1068 |
1069 |
1070 |
1071 | Scales a quaternion by the given value.
1072 |
1073 | The quaternion to scale.
1074 | The amount by which to scale the quaternion.
1075 | The scaled quaternion.
1076 |
1077 |
1078 |
1079 | Modulates a quaternion by another.
1080 |
1081 | The first quaternion to modulate.
1082 | The second quaternion to modulate.
1083 | The modulated quaternion.
1084 |
1085 |
1086 |
1087 | Rotates a rotation from towards to.
1088 |
1089 | From Quaternion.
1090 | To Quaternion.
1091 |
1092 |
1093 |
1094 |
1095 | Creates a rotation which rotates from fromDirection to toDirection.
1096 |
1097 |
1098 |
1099 |
1100 | Interpolates between two quaternions, using spherical linear interpolation. The parameter /t/ is not clamped.
1101 |
1102 |
1103 |
1104 |
1105 |
1106 |
1107 |
1108 | Interpolates between two quaternions, using spherical linear interpolation..
1109 |
1110 | Start quaternion.
1111 | End quaternion.
1112 | Value between 0 and 1 indicating the weight of .
1113 | The spherical linear interpolation of the two quaternions.
1114 |
1115 |
1116 |
1117 | Performs a linear interpolation between two quaternion.
1118 |
1119 | Start quaternion.
1120 | End quaternion.
1121 | Value between 0 and 1 indicating the weight of .
1122 | The linear interpolation of the two quaternions.
1123 |
1124 | This method performs the linear interpolation based on the following formula.
1125 | start + (end - start) * amount
1126 | Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned.
1127 |
1128 |
1129 |
1130 |
1131 | Conjugates and renormalizes the quaternion.
1132 |
1133 | The quaternion to conjugate and renormalize.
1134 | The conjugated and renormalized quaternion.
1135 |
1136 |
1137 |
1138 | Calculates the dot product of two quaternions.
1139 |
1140 | First source quaternion.
1141 | Second source quaternion.
1142 | The dot product of the two quaternions.
1143 |
1144 |
1145 |
1146 | Divides a quaternion by another.
1147 |
1148 | The first quaternion to divide.
1149 | The second quaternion to divide.
1150 | The divided quaternion.
1151 |
1152 |
1153 |
1154 | Adds two quaternions.
1155 |
1156 | The first quaternion to add.
1157 | The second quaternion to add.
1158 | The sum of the two quaternions.
1159 |
1160 |
1161 |
1162 | Conjugates and renormalizes the quaternion.
1163 |
1164 |
1165 |
1166 |
1167 | Conjugates the quaternion.
1168 |
1169 |
1170 |
1171 |
1172 | Converts the quaternion into a unit quaternion.
1173 |
1174 |
1175 |
1176 |
1177 | Calculates the squared length of the quaternion.
1178 |
1179 | The squared length of the quaternion.
1180 |
1181 |
1182 |
1183 | Calculates the length of the quaternion.
1184 |
1185 | The length of the quaternion.
1186 |
1187 |
1188 |
1189 | Gets the angle of the quaternion.
1190 |
1191 |
1192 |
1193 |
1194 | Gets the axis components of the quaternion.
1195 |
1196 |
1197 |
1198 |
1199 | Gets the identity (0, 0, 0, 1).
1200 |
1201 |
1202 |
1203 |
1204 | Initializes a new instance of the structure.
1205 |
1206 | A containing the first three values of the quaternion.
1207 | The W component of the quaternion.
1208 |
1209 |
1210 |
1211 | Initializes a new instance of the structure.
1212 |
1213 | The X component of the quaternion.
1214 | The Y component of the quaternion.
1215 | The Z component of the quaternion.
1216 | The W component of the quaternion.
1217 |
1218 |
1219 |
1220 | Gets or sets the W component of the quaternion.
1221 |
1222 | The W component of the quaternion.
1223 |
1224 |
1225 |
1226 | Gets or sets the Z component of the quaternion.
1227 |
1228 | The Z component of the quaternion.
1229 |
1230 |
1231 |
1232 | Gets or sets the Y component of the quaternion.
1233 |
1234 | The Y component of the quaternion.
1235 |
1236 |
1237 |
1238 | Gets or sets the X component of the quaternion.
1239 |
1240 | The X component of the quaternion.
1241 |
1242 |
1243 |
1244 | Determines whether the specified object instances are considered equal.
1245 |
1246 | The first value to compare.
1247 | The second value to compare.
1248 |
1249 | true if is the same instance as or
1250 | if both are null references or if value1.Equals(value2) returns true; otherwise, false.
1251 |
1252 |
1253 |
1254 | Returns a value that indicates whether the current instance is equal to the specified object.
1255 |
1256 | Object to make the comparison with.
1257 |
1258 | true if the current instance is equal to the specified object; false otherwise.
1259 |
1260 |
1261 |
1262 | Returns a value that indicates whether the current instance is equal to a specified object.
1263 |
1264 | Object to make the comparison with.
1265 |
1266 | true if the current instance is equal to the specified object; false otherwise.
1267 |
1268 |
1269 |
1270 | Returns the hash code for this instance.
1271 |
1272 | A 32-bit signed integer hash code.
1273 |
1274 |
1275 |
1276 | Converts the value of the object to its equivalent string representation.
1277 |
1278 | The string representation of the value of this instance.
1279 |
1280 |
1281 |
1282 | Tests for inequality between two objects.
1283 |
1284 | The first value to compare.
1285 | The second value to compare.
1286 |
1287 | true if has a different value than ; otherwise, false.
1288 |
1289 |
1290 |
1291 | Tests for equality between two objects.
1292 |
1293 | The first value to compare.
1294 | The second value to compare.
1295 |
1296 | true if has the same value as ; otherwise, false.
1297 |
1298 |
1299 |
1300 | Scales a vector by the given value.
1301 |
1302 | The vector to scale.
1303 | The amount by which to scale the vector.
1304 | The scaled vector.
1305 |
1306 |
1307 |
1308 | Scales a vector by the given value.
1309 |
1310 | The vector to scale.
1311 | The amount by which to scale the vector.
1312 | The scaled vector.
1313 |
1314 |
1315 |
1316 | Scales a vector by the given value.
1317 |
1318 | The vector to scale.
1319 | The amount by which to scale the vector.
1320 | The scaled vector.
1321 |
1322 |
1323 |
1324 | Reverses the direction of a given vector.
1325 |
1326 | The vector to negate.
1327 | A vector facing in the opposite direction.
1328 |
1329 |
1330 |
1331 | Subtracts two vectors.
1332 |
1333 | The first vector to subtract.
1334 | The second vector to subtract.
1335 | The difference of the two vectors.
1336 |
1337 |
1338 |
1339 | Adds two vectors.
1340 |
1341 | The first vector to add.
1342 | The second vector to add.
1343 | The sum of the two vectors.
1344 |
1345 |
1346 |
1347 | Returns a vector containing the largest components of the specified vectors.
1348 |
1349 | The first source vector.
1350 | The second source vector.
1351 | A vector containing the largest components of the source vectors.
1352 |
1353 |
1354 |
1355 | Returns a vector containing the smallest components of the specified vectors.
1356 |
1357 | The first source vector.
1358 | The second source vector.
1359 | A vector containing the smallest components of the source vectors.
1360 |
1361 |
1362 |
1363 | Returns the reflection of a vector off a surface that has the specified normal.
1364 |
1365 | The vector to project onto the plane.
1366 | Normal of the surface.
1367 | The reflected vector.
1368 | Reflect only gives the direction of a reflection off a surface, it does not determine
1369 | whether the original vector was close enough to the surface to hit it.
1370 |
1371 |
1372 |
1373 | Projects a vector onto a plane defined by a normal orthogonal to the plane.
1374 |
1375 | The vector to project.
1376 | Normal of the plane, does not assume it is normalized.
1377 | The Projection of vector onto plane.
1378 |
1379 |
1380 |
1381 | Projects a vector onto another vector.
1382 |
1383 | The vector to project.
1384 | Vector to project onto, does not assume it is normalized.
1385 | The projected vector.
1386 |
1387 |
1388 |
1389 | Calculates the cross product of two vectors.
1390 |
1391 | First source vector.
1392 | Second source vector.
1393 | The cross product of the two vectors.
1394 |
1395 |
1396 |
1397 | Calculates the dot product of two vectors.
1398 |
1399 | First source vector.
1400 | Second source vector.
1401 | The dot product of the two vectors.
1402 |
1403 |
1404 |
1405 | Converts the vector into a unit vector.
1406 |
1407 | The vector to normalize.
1408 | The normalized vector.
1409 |
1410 |
1411 |
1412 | Performs a linear interpolation between two vectors.
1413 |
1414 | Start vector.
1415 | End vector.
1416 | Value between 0 and 1 indicating the weight of .
1417 | The linear interpolation of the two vectors.
1418 |
1419 | This method performs the linear interpolation based on the following formula.
1420 | start + (end - start) * amount
1421 | Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned.
1422 |
1423 |
1424 |
1425 |
1426 | Restricts a value to be within a specified range.
1427 |
1428 | The value to clamp.
1429 | The minimum value.
1430 | The maximum value.
1431 | The clamped value.
1432 |
1433 |
1434 |
1435 | Reverses the direction of a given vector.
1436 |
1437 | The vector to negate.
1438 | A vector facing in the opposite direction.
1439 |
1440 |
1441 |
1442 | Scales a vector by the given value.
1443 |
1444 | The vector to scale.
1445 | The amount by which to scale the vector.
1446 | The scaled vector.
1447 |
1448 |
1449 |
1450 | Modulates a vector by another.
1451 |
1452 | The first vector to modulate.
1453 | The second vector to modulate.
1454 | The modulated vector.
1455 |
1456 |
1457 |
1458 | Scales a vector by the given value.
1459 |
1460 | The vector to scale.
1461 | The amount by which to scale the vector.
1462 | The scaled vector.
1463 |
1464 |
1465 |
1466 | Subtracts two vectors.
1467 |
1468 | The first vector to subtract.
1469 | The second vector to subtract.
1470 | The difference of the two vectors.
1471 |
1472 |
1473 |
1474 | Adds two vectors.
1475 |
1476 | The first vector to add.
1477 | The second vector to add.
1478 | The sum of the two vectors.
1479 |
1480 |
1481 |
1482 | Returns a new normalized vector with random X, Y and Z components.
1483 |
1484 |
1485 |
1486 |
1487 | Returns a new normalized vector with random X and Y components.
1488 |
1489 |
1490 |
1491 |
1492 | Creates a random vector inside the circle around this position.
1493 |
1494 |
1495 |
1496 |
1497 | Converts a vector to a heading.
1498 |
1499 |
1500 |
1501 |
1502 | Returns the signed angle in degrees between from and to.
1503 |
1504 |
1505 |
1506 |
1507 | Returns the angle in degrees between from and to.
1508 | The angle returned is always the acute angle between the two vectors.
1509 |
1510 |
1511 |
1512 |
1513 | Calculates the squared distance between two vectors, ignoring the Z-component.
1514 |
1515 | The first vector to calculate the squared distance to the second vector.
1516 | The second vector to calculate the squared distance to the first vector.
1517 | The squared distance between the two vectors.
1518 |
1519 |
1520 |
1521 | Calculates the distance between two vectors, ignoring the Z-component.
1522 |
1523 | The first vector to calculate the distance to the second vector.
1524 | The second vector to calculate the distance to the first vector.
1525 | The distance between the two vectors.
1526 |
1527 |
1528 |
1529 | Calculates the squared distance between two vectors.
1530 |
1531 | The first vector to calculate the squared distance to the second vector.
1532 | The second vector to calculate the squared distance to the first vector.
1533 | The squared distance between the two vectors.
1534 |
1535 |
1536 |
1537 | Calculates the distance between two vectors.
1538 |
1539 | The first vector to calculate the distance to the second vector.
1540 | The second vector to calculate the distance to the first vector.
1541 | The distance between the two vectors.
1542 |
1543 |
1544 |
1545 | Calculates the squared distance between two vectors, ignoring the Z-component.
1546 |
1547 | The second vector to calculate the squared distance to.
1548 | The distance to the other vector.
1549 |
1550 |
1551 |
1552 | Calculates the distance between two vectors, ignoring the Z-component.
1553 |
1554 | The second vector to calculate the distance to.
1555 | The distance to the other vector.
1556 |
1557 |
1558 |
1559 | Calculates the squared distance between two vectors.
1560 |
1561 | The second vector to calculate the distance to.
1562 | The distance to the other vector.
1563 |
1564 |
1565 |
1566 | Calculates the distance between two vectors.
1567 |
1568 | The second vector to calculate the distance to.
1569 | The distance to the other vector.
1570 |
1571 |
1572 |
1573 | Converts the vector into a unit vector.
1574 |
1575 |
1576 |
1577 |
1578 | Calculates the squared length of the vector.
1579 |
1580 | The squared length of the vector.
1581 |
1582 |
1583 |
1584 | Calculates the length of the vector.
1585 |
1586 | The length of the vector.
1587 |
1588 |
1589 |
1590 | Returns the relative Bottom vector as used. (0,0,-1)
1591 |
1592 |
1593 |
1594 |
1595 | Returns the relative Top vector. (0,0,1)
1596 |
1597 |
1598 |
1599 |
1600 | Returns the relative Back vector. (0,-1,0)
1601 |
1602 |
1603 |
1604 |
1605 | Returns the relative Front vector. (0,1,0)
1606 |
1607 |
1608 |
1609 |
1610 | Returns the relative Left vector. (-1,0,0)
1611 |
1612 |
1613 |
1614 |
1615 | Returns the relative Right vector. (1,0,0)
1616 |
1617 |
1618 |
1619 |
1620 | Returns the world West vector. (-1,0,0)
1621 |
1622 |
1623 |
1624 |
1625 | Returns the world East vector. (1,0,0)
1626 |
1627 |
1628 |
1629 |
1630 | Returns the world South vector. (0,-1,0)
1631 |
1632 |
1633 |
1634 |
1635 | Returns the world North vector. (0,1,0)
1636 |
1637 |
1638 |
1639 |
1640 | Returns the world Down vector. (0,0,-1)
1641 |
1642 |
1643 |
1644 |
1645 | Returns the world Up vector. (0,0,1)
1646 |
1647 |
1648 |
1649 |
1650 | Returns a null vector. (0,0,0)
1651 |
1652 |
1653 |
1654 |
1655 | Returns this vector with a magnitude of 1.
1656 |
1657 |
1658 |
1659 |
1660 | Initializes a new instance of the class.
1661 |
1662 | Initial value for the X component of the vector.
1663 | Initial value for the Y component of the vector.
1664 | Initial value for the Z component of the vector.
1665 |
1666 |
1667 |
1668 | Gets or sets the Z component of the vector.
1669 |
1670 | The Z component of the vector.
1671 |
1672 |
1673 |
1674 | Gets or sets the Y component of the vector.
1675 |
1676 | The Y component of the vector.
1677 |
1678 |
1679 |
1680 | Gets or sets the X component of the vector.
1681 |
1682 | The X component of the vector.
1683 |
1684 |
1685 |
--------------------------------------------------------------------------------