Improved weapon and turret sync
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using GTA;
|
||||
using GTA.Math;
|
||||
using GTA.Native;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
@ -11,174 +12,80 @@ namespace RageCoop.Client
|
||||
internal class DevTool : Script
|
||||
{
|
||||
public static Vehicle ToMark;
|
||||
public static bool UseSecondary = false;
|
||||
public static int Current = 0;
|
||||
public static int Secondary = 0;
|
||||
public static MuzzleDir Direction = MuzzleDir.Forward;
|
||||
public static Script Instance;
|
||||
public DevTool()
|
||||
{
|
||||
Util.StartUpCheck();
|
||||
Instance = this;
|
||||
Tick += OnTick;
|
||||
KeyDown += OnKeyDown;
|
||||
Pause();
|
||||
}
|
||||
|
||||
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (ToMark == null || (!ToMark.Exists())) { return; }
|
||||
if (DevToolMenu.Menu.SelectedItem == DevToolMenu.boneIndexItem)
|
||||
{
|
||||
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.Right:
|
||||
Current++;
|
||||
break;
|
||||
case Keys.Left:
|
||||
Current--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (DevToolMenu.Menu.SelectedItem == DevToolMenu.secondaryBoneIndexItem)
|
||||
{
|
||||
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.Right:
|
||||
Secondary++;
|
||||
break;
|
||||
case Keys.Left:
|
||||
Secondary--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Update();
|
||||
}
|
||||
private static void Update()
|
||||
{
|
||||
|
||||
if (Current > ToMark.Bones.Count - 1)
|
||||
{
|
||||
Current = 0;
|
||||
}
|
||||
else if (Current < 0)
|
||||
{
|
||||
Current = ToMark.Bones.Count - 1;
|
||||
}
|
||||
DevToolMenu.boneIndexItem.AltTitle = Current.ToString();
|
||||
if (Secondary > ToMark.Bones.Count - 1)
|
||||
{
|
||||
Secondary = 0;
|
||||
}
|
||||
else if (Secondary < 0)
|
||||
{
|
||||
Secondary = ToMark.Bones.Count - 1;
|
||||
}
|
||||
DevToolMenu.secondaryBoneIndexItem.AltTitle = Secondary.ToString();
|
||||
}
|
||||
private void OnTick(object sender, EventArgs e)
|
||||
{
|
||||
if (ToMark == null || !ToMark.Exists()) { return; }
|
||||
Update();
|
||||
Draw(Current);
|
||||
if (UseSecondary)
|
||||
var wb = Game.Player.Character?.Weapons?.CurrentWeaponObject?.Bones["gun_muzzle"];
|
||||
if (wb?.IsValid==true)
|
||||
{
|
||||
Draw(Secondary);
|
||||
World.DrawLine(wb.Position, wb.Position + wb.RightVector, Color.Blue);
|
||||
}
|
||||
|
||||
}
|
||||
private static void Draw(int boneindex)
|
||||
{
|
||||
var bone = ToMark.Bones[boneindex];
|
||||
World.DrawLine(bone.Position, bone.Position + 2 * bone.ForwardVector, Color.Blue);
|
||||
World.DrawLine(bone.Position, bone.Position + 2 * bone.UpVector, Color.Green);
|
||||
World.DrawLine(bone.Position, bone.Position + 2 * bone.RightVector, Color.Yellow);
|
||||
Vector3 todraw = bone.ForwardVector;
|
||||
switch ((byte)Direction)
|
||||
if (ToMark == null) return;
|
||||
if (WeaponUtil.VehicleWeapons.TryGetValue((uint)(int)ToMark.Model, out var info))
|
||||
{
|
||||
case 0:
|
||||
todraw = bone.ForwardVector;
|
||||
break;
|
||||
case 1:
|
||||
todraw = bone.RightVector;
|
||||
break;
|
||||
case 2:
|
||||
todraw = bone.UpVector;
|
||||
break;
|
||||
case 3:
|
||||
todraw = bone.ForwardVector * -1;
|
||||
break;
|
||||
case 4:
|
||||
todraw = bone.RightVector * -1;
|
||||
break;
|
||||
case 5:
|
||||
todraw = bone.UpVector * -1;
|
||||
break;
|
||||
}
|
||||
World.DrawLine(bone.Position, bone.Position + 10 * todraw, Color.Red);
|
||||
}
|
||||
public static void CopyToClipboard(MuzzleDir dir)
|
||||
{
|
||||
|
||||
if (ToMark != null)
|
||||
{
|
||||
string s;
|
||||
if (UseSecondary)
|
||||
foreach (var ws in info.Weapons)
|
||||
{
|
||||
if ((byte)dir < 3)
|
||||
foreach (var w in ws.Value.Bones)
|
||||
{
|
||||
s = $@"
|
||||
// {ToMark.DisplayName}
|
||||
case {ToMark.Model.Hash}:
|
||||
return BulletsShot%2==0 ? {Current} : {Secondary};
|
||||
";
|
||||
}
|
||||
else
|
||||
{
|
||||
s = $@"
|
||||
// {ToMark.DisplayName}
|
||||
case {ToMark.Model.Hash}:
|
||||
return BulletsShot%2==0 ? {Current} : {Secondary};
|
||||
";
|
||||
DrawBone(w.BoneName, ws.Value.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((byte)dir < 3)
|
||||
{
|
||||
s = $@"
|
||||
// {ToMark.DisplayName}
|
||||
case {ToMark.Model.Hash}:
|
||||
return {Current};
|
||||
";
|
||||
}
|
||||
else
|
||||
{
|
||||
s = $@"
|
||||
// {ToMark.DisplayName}
|
||||
case {ToMark.Model.Hash}:
|
||||
return {Current};
|
||||
";
|
||||
}
|
||||
}
|
||||
Thread thread = new Thread(() => Clipboard.SetText(s));
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
GTA.UI.Notification.Show("Copied to clipboard, please paste it on the GitHub issue page!");
|
||||
}
|
||||
}
|
||||
void FindAndDraw()
|
||||
{
|
||||
DrawBone("weapon_1a");
|
||||
DrawBone("weapon_1b");
|
||||
DrawBone("weapon_1c");
|
||||
DrawBone("weapon_1d");
|
||||
DrawBone("weapon_2a");
|
||||
DrawBone("weapon_2b");
|
||||
DrawBone("weapon_2c");
|
||||
DrawBone("weapon_2d");
|
||||
DrawBone("weapon_3a");
|
||||
DrawBone("weapon_3b");
|
||||
DrawBone("weapon_3c");
|
||||
DrawBone("weapon_3d");
|
||||
DrawBone("weapon_4a");
|
||||
DrawBone("weapon_4b");
|
||||
DrawBone("weapon_4c");
|
||||
DrawBone("weapon_4d");
|
||||
DrawBone("weapon_1e");
|
||||
DrawBone("weapon_1f");
|
||||
DrawBone("weapon_1g");
|
||||
DrawBone("weapon_1h");
|
||||
DrawBone("weapon_2e");
|
||||
DrawBone("weapon_2f");
|
||||
DrawBone("weapon_2g");
|
||||
DrawBone("weapon_2h");
|
||||
DrawBone("weapon_3e");
|
||||
DrawBone("weapon_3f");
|
||||
DrawBone("weapon_3g");
|
||||
DrawBone("weapon_3h");
|
||||
DrawBone("weapon_4e");
|
||||
DrawBone("weapon_4f");
|
||||
DrawBone("weapon_4g");
|
||||
DrawBone("weapon_4h");
|
||||
}
|
||||
void DrawBone(string name, string text = null)
|
||||
{
|
||||
text = text ?? name;
|
||||
var b = ToMark.Bones[name];
|
||||
if (b.IsValid)
|
||||
{
|
||||
var start = b.Position;
|
||||
var end = b.Position + b.ForwardVector * 5;
|
||||
World.DrawLine(start, end, Color.AliceBlue);
|
||||
Util.DrawTextFromCoord(end, text, 0.35f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
internal enum MuzzleDir : byte
|
||||
{
|
||||
Forward = 0,
|
||||
Right = 1,
|
||||
Up = 2,
|
||||
Backward = 3,
|
||||
Left = 4,
|
||||
Down = 5,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user