Skip to content

Commit

Permalink
Latest fixes for some crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
aebian committed Aug 26, 2020
1 parent 5bbec55 commit 6b67ddc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.0.0")]
[assembly: AssemblyFileVersion("0.5.0.0")]
[assembly: AssemblyVersion("0.6.0.0")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]

36 changes: 17 additions & 19 deletions Utils/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,22 @@ public static void RunPlugin()

{

Global.Dynamics.CurrentPed = Game.LocalPlayer.Character;

Logger.DebugLog("Core Plugin Function Started");

//Game loop
while (true)
{
GameFiber.Yield();

if ((Game.IsKeyDownRightNow(Global.Controls.AttachSilencerModifier) && Game.IsKeyDown(Global.Controls.AttachSilencer) || Global.Controls.AttachSilencerModifier == Keys.None && Game.IsKeyDown(Global.Controls.AttachSilencer) || Game.IsControllerButtonDownRightNow(Global.Controls.AttachSilencerControllerModifier) && Game.IsControllerButtonDown(Global.Controls.AttachSilencerController) || Global.Controls.AttachSilencerControllerModifier == ControllerButtons.None && Game.IsControllerButtonDown(Global.Controls.AttachSilencerController)) && (Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject != null))
if ((Game.IsKeyDownRightNow(Global.Controls.AttachSilencerModifier) && Game.IsKeyDown(Global.Controls.AttachSilencer) || Global.Controls.AttachSilencerModifier == Keys.None && Game.IsKeyDown(Global.Controls.AttachSilencer) || Game.IsControllerButtonDownRightNow(Global.Controls.AttachSilencerControllerModifier) && Game.IsControllerButtonDown(Global.Controls.AttachSilencerController) || Global.Controls.AttachSilencerControllerModifier == ControllerButtons.None && Game.IsControllerButtonDown(Global.Controls.AttachSilencerController)) && (Game.LocalPlayer.Character.Inventory.EquippedWeaponObject != null) && (!(NativeFunction.Natives.IS_PLAYER_FREE_AIMING<bool>(Game.LocalPlayer.Character))))
{
UpdatePlayer();
if (NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0x837445AA) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0xA73D4664) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0xC304849A) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0x65EA7EBB) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0xE608B35E) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0xAC42DF71))
{
Logger.DebugLog("Trying to remove silencer from current selected weapon:");
if (NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0x837445AA) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0xA73D4664) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0xC304849A) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0x65EA7EBB) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0xE608B35E) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0xAC42DF71))
{
Logger.DebugLog("Trying to remove silencer from current selected weapon:");
Logger.DebugLog(Global.Dynamics.EquippedWeaponHash.ToString());
RemoveSilencer();
}
}
else
{
Logger.DebugLog("Trying to attach silencer to current selected weapon:");
Expand All @@ -50,10 +48,10 @@ public static void RunPlugin()

private static void UpdatePlayer()
{
if (Global.Dynamics.CurrentPed)
if (Game.LocalPlayer.Character)
{

Global.Dynamics.EquippedWeaponHash = Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject.Model.Hash;
Global.Dynamics.EquippedWeaponHash = Game.LocalPlayer.Character.Inventory.EquippedWeaponObject.Model.Hash;

}
}
Expand All @@ -73,7 +71,7 @@ private static void AttachSilencer()
case 2583718658: //WEAPON_MARKSMANRIFLE
case 2436666926: //WEAPON_MARKSMANRIFLE_MK2

Global.Dynamics.CurrentPed.Inventory.AddComponentToWeapon(Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_AR_SUPP");
Game.LocalPlayer.Character.Inventory.AddComponentToWeapon(Game.LocalPlayer.Character.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_AR_SUPP");
Logger.DebugLog("Attached silencer to current selected weapon successfully.");
break;

Expand All @@ -88,7 +86,7 @@ private static void AttachSilencer()
case 2549323539: //WEAPON_SPECIALCARBINE:
case 2379721761: //WEAPON_SPECIALCARBINE_MK2:

Global.Dynamics.CurrentPed.Inventory.AddComponentToWeapon(Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_AR_SUPP_02");
Game.LocalPlayer.Character.Inventory.AddComponentToWeapon(Game.LocalPlayer.Character.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_AR_SUPP_02");
Logger.DebugLog("Attached silencer to current selected weapon successfully.");
break;

Expand All @@ -101,7 +99,7 @@ private static void AttachSilencer()
case 2547423399: //WEAPON_SMG_MK2:
case 3170921020: //WEAPON_VINTAGEPISTOL:

Global.Dynamics.CurrentPed.Inventory.AddComponentToWeapon(Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_PI_SUPP");
Game.LocalPlayer.Character.Inventory.AddComponentToWeapon(Game.LocalPlayer.Character.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_PI_SUPP");
Logger.DebugLog("Attached silencer to current selected weapon successfully.");
break;

Expand All @@ -110,29 +108,29 @@ private static void AttachSilencer()
case 995074671: //WEAPON_PISTOL_MK2:
case 4221916961: //WEAPON_SNSPISTOL_MK2:

Global.Dynamics.CurrentPed.Inventory.AddComponentToWeapon(Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_PI_SUPP_02");
Game.LocalPlayer.Character.Inventory.AddComponentToWeapon(Game.LocalPlayer.Character.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_PI_SUPP_02");
Logger.DebugLog("Attached silencer to current selected weapon successfully.");
break;

//COMPONENT_AT_SR_SUPP;
case 689760839: //WEAPON_PUMPSHOTGUN:

Global.Dynamics.CurrentPed.Inventory.AddComponentToWeapon(Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_SR_SUPP");
Game.LocalPlayer.Character.Inventory.AddComponentToWeapon(Game.LocalPlayer.Character.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_SR_SUPP");
Logger.DebugLog("Attached silencer to current selected weapon successfully.");
break;

//COMPONENT_AT_SR_SUPP_02;
case 3238253642: //WEAPON_MICROSMG:

Global.Dynamics.CurrentPed.Inventory.AddComponentToWeapon(Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_SR_SUPP_02");
Game.LocalPlayer.Character.Inventory.AddComponentToWeapon(Game.LocalPlayer.Character.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_SR_SUPP_02");
Logger.DebugLog("Attached silencer to current selected weapon successfully.");
break;

//COMPONENT_AT_SR_SUPP_03;
case 619715967: //WEAPON_HEAVYSNIPER_MK2:
case 3194406291: //WEAPON_PUMPSHOTGUN_MK2:

Global.Dynamics.CurrentPed.Inventory.AddComponentToWeapon(Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_SR_SUPP_03");
Game.LocalPlayer.Character.Inventory.AddComponentToWeapon(Game.LocalPlayer.Character.Inventory.EquippedWeapon.Asset, "COMPONENT_AT_SR_SUPP_03");
Logger.DebugLog("Attached silencer to current selected weapon successfully.");
break;

Expand All @@ -151,16 +149,16 @@ private static void RemoveSilencer()
List<string> silencers = new List<string> { "COMPONENT_AT_AR_SUPP", "COMPONENT_AT_AR_SUPP_02", "COMPONENT_AT_PI_SUPP", "COMPONENT_AT_PI_SUPP_02", "COMPONENT_AT_SR_SUPP", "COMPONENT_AT_SR_SUPP_02", "COMPONENT_AT_SR_SUPP_03" };
foreach (string silencer in silencers)
{
if (NativeFunction.Natives.HAS_PED_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed, (uint)Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Hash, Game.GetHashKey(silencer)))
if (NativeFunction.Natives.HAS_PED_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character, (uint)Game.LocalPlayer.Character.Inventory.EquippedWeapon.Hash, Game.GetHashKey(silencer)))
{
NativeFunction.Natives.REMOVE_WEAPON_COMPONENT_FROM_PED<bool>(Global.Dynamics.CurrentPed, (uint)Global.Dynamics.CurrentPed.Inventory.EquippedWeapon.Hash, Game.GetHashKey(silencer));
NativeFunction.Natives.REMOVE_WEAPON_COMPONENT_FROM_PED<bool>(Game.LocalPlayer.Character, (uint)Game.LocalPlayer.Character.Inventory.EquippedWeapon.Hash, Game.GetHashKey(silencer));
}
}

}
finally
{
if (NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0x837445AA) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0xA73D4664) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0xC304849A) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0x65EA7EBB) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0xE608B35E) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Global.Dynamics.CurrentPed.Inventory.EquippedWeaponObject, 0xAC42DF71))
if (NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0x837445AA) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0xA73D4664) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0xC304849A) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0x65EA7EBB) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0xE608B35E) || NativeFunction.Natives.HAS_WEAPON_GOT_WEAPON_COMPONENT<bool>(Game.LocalPlayer.Character.Inventory.EquippedWeaponObject, 0xAC42DF71))
{
Logger.DebugLog("Warning: Cannot determine if a silencer is attached to equipped weapon.");
}
Expand Down
1 change: 0 additions & 1 deletion Utils/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ internal static class Controls
internal static class Dynamics
{
public static uint EquippedWeaponHash { get; set; }
public static Ped CurrentPed { get; set; }
}
}
}
12 changes: 7 additions & 5 deletions config/SilencerKI.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//This mod supports the typical key member names as most other Rage plugins.
//For a full list go here: https://msdn.microsoft.com/en-us/library/system.windows.forms.keys(v=vs.110).aspx

[General]
DebugLogging = true;
DebugLogging = true

[Keybinds]
//Keyboard Keybinds ; https://msdn.microsoft.com/en-us/library/system.windows.forms.keys(v=vs.110).aspx
AttachSilencer = F10
AttachSilencerModifier = LShiftKey
AttachSilencerModifier = LShiftKey

//Controller Keybinds ; https://docs.ragepluginhook.net/?topic=html/T_Rage_ControllerButtons.htm
AttachSilencerController = DPadRight
AttachSilencerControllerModifier = None

0 comments on commit 6b67ddc

Please sign in to comment.