Skip to content

Commit

Permalink
Complete devtool, added support for vehicle weapon sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sardelka9515 committed May 27, 2022
1 parent b509645 commit 93db7d3
Show file tree
Hide file tree
Showing 13 changed files with 527 additions and 226 deletions.
167 changes: 150 additions & 17 deletions Client/DevTools/DevTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,178 @@
using GTA.Math;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;

namespace RageCoop.Client
{
internal class DevTool:Script
{
public static Entity ToMark;
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 DevTool()
{
Tick+=OnTick;
KeyUp+=OnKeyUp;
KeyDown+=OnKeyDown;
}

private void OnKeyUp(object sender, KeyEventArgs e)
private void OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
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)
{
case Keys.Right:
Current++;
DebugMenu.boneIndexItem.AltTitle= Current.ToString();
break;
case Keys.Left:
Current--;
DebugMenu.boneIndexItem.AltTitle= Current.ToString();
break;

switch (e.KeyCode)
{
case Keys.Right:
Secondary++;
break;
case Keys.Left:
Secondary--;
break;
}
}
Update();
}
private static void Update()
{

private void OnTick(object sender, EventArgs e)
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 static void OnTick(object sender, EventArgs e)
{
if(ToMark == null || !ToMark.Exists()){ return;}
if ((Current< 0)||(Current>ToMark.Bones.Count-1)) {
Current=0;
DebugMenu.boneIndexItem.AltTitle= Current.ToString();
Update();
Draw(Current);
if (UseSecondary)
{
Draw(Secondary);
}
var bone = ToMark.Bones[Current];

}
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)
{
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)
{
if ((byte)dir<3)
{
s=$@"
// {ToMark.DisplayName}
case {ToMark.Model.Hash}:
i=Main.Ticked%2==0 ? {Current} : {Secondary};
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].{dir}Vector);
";
}
else
{
s=$@"
// {ToMark.DisplayName}
case {ToMark.Model.Hash}:
i=Main.Ticked%2==0 ? {Current} : {Secondary};
return new MuzzleInfo(v.Bones[i].Position, v.Bones[i].{((MuzzleDir)(dir-3)).ToString()}Vector*-1);
";
}
}
else
{
if ((byte)dir<3)
{
s=$@"
// {ToMark.DisplayName}
case {ToMark.Model.Hash}:
return new MuzzleInfo(v.Bones[{Current}].Position, v.Bones[{Current}].{dir}Vector);
";
}
else
{
s=$@"
// {ToMark.DisplayName}
case {ToMark.Model.Hash}:
return new MuzzleInfo(v.Bones[{Current}].Position, v.Bones[{Current}].{((MuzzleDir)(dir-3)).ToString()}Vector*-1);
";
}
}
Thread thread = new Thread(() => Clipboard.SetText(s));
thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA
thread.Start();
thread.Join();
GTA.UI.Notification.Show("Copied to clipboard, please paste it on the GitHub issue page!");
}
}

}
public enum MuzzleDir:byte
{
Forward=0,
Right = 1,
Up=2,
Backward=3,
Left = 4,
Down=5,
}
}
2 changes: 1 addition & 1 deletion Client/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void OnKeyDown(object sender, KeyEventArgs e)
if (MainMenu.MenuPool.AreAnyVisible)
{
MainMenu.MainMenu.Visible = false;
MainMenu.SubSettings.MainMenu.Visible = false;
MainMenu.SubSettings.Menu.Visible = false;
}
else
{
Expand Down
15 changes: 9 additions & 6 deletions Client/Menus/RageCoopMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ public RageCoopMenu()
MainMenu.Add(_usernameItem);
MainMenu.Add(ServerIpItem);
MainMenu.Add(_serverConnectItem);

MainMenu.AddSubMenu(SubSettings.MainMenu);
MainMenu.AddSubMenu(DebugMenu.MainMenu);
MainMenu.Add(_aboutItem);

MainMenu.AddSubMenu(SubSettings.Menu);
MainMenu.AddSubMenu(DevToolMenu.Menu);
MainMenu.AddSubMenu(DebugMenu.Menu);


MenuPool.Add(MainMenu);
MenuPool.Add(SubSettings.MainMenu);
MenuPool.Add(DebugMenu.MainMenu);
MenuPool.Add(SubSettings.Menu);
MenuPool.Add(DevToolMenu.Menu);
MenuPool.Add(DebugMenu.Menu);
MenuPool.Add(DebugMenu.DiagnosticMenu);
}

Expand Down Expand Up @@ -106,7 +109,7 @@ public void DisconnectedMenuSetting()
MainMenu.Items[1].Enabled = true;
MainMenu.Items[2].Enabled = true;
MainMenu.Items[2].Title = "Connect";
SubSettings.MainMenu.Items[1].Enabled = false;
SubSettings.Menu.Items[1].Enabled = false;
}
}
}
31 changes: 10 additions & 21 deletions Client/Menus/Sub/DebugMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
using LemonUI;
using LemonUI.Menus;
using GTA;
using System.Drawing;

namespace RageCoop.Client
{
internal static class DebugMenu
{
public static NativeMenu MainMenu = new NativeMenu("RAGECOOP", "Debug", "Debug settings") {
public static NativeMenu Menu = new NativeMenu("RAGECOOP", "Debug", "Debug settings") {
UseMouse = false,
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
Expand All @@ -21,24 +22,22 @@ internal static class DebugMenu
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
private static NativeItem d1=new NativeItem("PositionPrediction");
private static NativeCheckboxItem devToolItem=new NativeCheckboxItem("DevTool");
public static NativeItem boneIndexItem = new NativeItem("Current bone index");
static DebugMenu()
{
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
Menu.Title.Color = Color.FromArgb(255, 165, 0);

d1.Activated+=(sender,e) =>
{
try{ SyncParameters.PositioinPrediction =float.Parse(Game.GetUserInput(WindowTitle.EnterMessage20, SyncParameters.PositioinPrediction.ToString(), 20));}
catch { }
Update();
};
devToolItem.Activated+=DevToolItem_Activated;
devToolItem.Checked=false;


MainMenu.Add(d1);
MainMenu.Add(devToolItem);
MainMenu.Add(boneIndexItem);
MainMenu.AddSubMenu(DiagnosticMenu);
MainMenu.Opening+=(sender, e) =>Update();
Menu.Add(d1);
Menu.AddSubMenu(DiagnosticMenu);
Menu.Opening+=(sender, e) =>Update();
DiagnosticMenu.Opening+=(sender, e) =>
{
DiagnosticMenu.Clear();
Expand All @@ -52,17 +51,7 @@ static DebugMenu()
Update();
}

private static void DevToolItem_Activated(object sender, EventArgs e)
{
if (devToolItem.Checked)
{
DevTool.ToMark=Game.Player.Character.CurrentVehicle;
}
else
{
DevTool.ToMark=null;
}
}


private static void Update()
{
Expand Down
88 changes: 88 additions & 0 deletions Client/Menus/Sub/DevToolMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LemonUI.Menus;
using GTA;
using System.Drawing;

namespace RageCoop.Client
{
internal class DevToolMenu
{
public static NativeMenu Menu = new NativeMenu("RAGECOOP", "DevTool", "Help with the development")
{
UseMouse = false,
Alignment = Main.Settings.FlipMenu ? GTA.UI.Alignment.Right : GTA.UI.Alignment.Left
};
private static NativeCheckboxItem enableItem = new NativeCheckboxItem("Enable");

private static NativeCheckboxItem enableSecondaryItem = new NativeCheckboxItem("Secondary","Enable if this vehicle have two muzzles");
public static NativeItem boneIndexItem = new NativeItem("Current bone index");
public static NativeItem secondaryBoneIndexItem = new NativeItem("Secondary bone index");
public static NativeItem clipboardItem = new NativeItem("Copy to clipboard");
public static NativeListItem<MuzzleDir> dirItem = new NativeListItem<MuzzleDir>("Direction");
static DevToolMenu()
{
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
Menu.Title.Color = Color.FromArgb(255, 165, 0);

enableItem.Activated+=enableItem_Activated;
enableItem.Checked=false;
enableSecondaryItem.CheckboxChanged+=EnableSecondaryItem_Changed;

secondaryBoneIndexItem.Enabled=false;
clipboardItem.Activated+=ClipboardItem_Activated;
dirItem.ItemChanged+=DirItem_ItemChanged;
foreach (var d in Enum.GetValues(typeof(MuzzleDir)))
{
dirItem.Items.Add((MuzzleDir)d);
}
dirItem.SelectedIndex=0;

Menu.Add(enableItem);
Menu.Add(boneIndexItem);
Menu.Add(enableSecondaryItem);
Menu.Add(secondaryBoneIndexItem);
Menu.Add(dirItem);
Menu.Add(clipboardItem);
}

private static void EnableSecondaryItem_Changed(object sender, EventArgs e)
{
if (enableSecondaryItem.Checked)
{
DevTool.UseSecondary=true;
secondaryBoneIndexItem.Enabled=true;
}
else
{
DevTool.UseSecondary=false;
secondaryBoneIndexItem.Enabled=false;
}
}

private static void DirItem_ItemChanged(object sender, ItemChangedEventArgs<MuzzleDir> e)
{
DevTool.Direction=dirItem.SelectedItem;
}

private static void ClipboardItem_Activated(object sender, EventArgs e)
{
DevTool.CopyToClipboard(dirItem.SelectedItem);
}

private static void enableItem_Activated(object sender, EventArgs e)
{
if (enableItem.Checked)
{
DevTool.ToMark=Game.Player.Character.CurrentVehicle;
}
else
{
DevTool.ToMark=null;
}
}
}
}
Loading

0 comments on commit 93db7d3

Please sign in to comment.