From ec236157d5570636449438d7bc47e20be7b34b23 Mon Sep 17 00:00:00 2001 From: Franc1sco Franug Date: Mon, 1 Apr 2024 11:50:42 +0200 Subject: [PATCH] version 1.5 -Fixed a log error. -Fixed model error on console. -ResourcePrecacher is not needed. -Upgraded cssharp version to atleast 179. -Set ParachuteModelEnabled to true by default. -Code optimizations. --- .gitignore | 4 +- README.md | 13 ++--- src/Parachute.cs | 116 ++++++++++++++++++++++++++----------------- src/Parachute.csproj | 2 +- 4 files changed, 78 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index 21471a0..2844c26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ obj -.vs \ No newline at end of file +.vs +src/bin +*.sln \ No newline at end of file diff --git a/README.md b/README.md index 35d0ab8..6426887 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,12 @@ Parachute function when you keep pressed E on the air. ### Requirements -* [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp/) (version 139 or higher) -* [PrecaheResource](https://github.com/KillStr3aK/ResourcePrecacher/) for parachute model. +* [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp/) (version 179 or higher) ### Installation Drag and drop from [releases](https://github.com/Franc1sco/CS2-Parachute/releases) to game/csgo/addons/counterstrikesharp/plugins -If you want to use ParachuteModel you need to precache the parachute model "models/props_survival/parachute/chute.vmdl" using [PrecaheResource](https://github.com/KillStr3aK/ResourcePrecacher/) and set ParachuteModelEnabled to true on the json config. - ### Configuration Configure the file parachute.json generated on addons/counterstrikesharp/configs/plugins/Parachute @@ -23,7 +20,7 @@ Configure the file parachute.json generated on addons/counterstrikesharp/configs "FallSpeed": 100, "AccessFlag": "@css/vip", "TeleportTicks": 300, - "ParachuteModelEnabled": false, + "ParachuteModelEnabled": true, "ConfigVersion": 1 } ``` @@ -32,9 +29,5 @@ Configure the file parachute.json generated on addons/counterstrikesharp/configs * Linear - 0: disables linear fallspeed - 1: enables it * FallSpeed - speed of the fall when you use the parachute * TeleportTicks - 300: ticks until perform a teleport (for prevent console spam). -* ParachuteModelEnabled - false: Add a parachute model while using it. +* ParachuteModelEnabled - true: Add a parachute model while using it. * AccessFlag - access required for can use parachuse, leave blank "" for public access. - -### TODO - -Take ideas from https://forums.alliedmods.net/showthread.php?p=580269 like add option for buy a parachute. diff --git a/src/Parachute.cs b/src/Parachute.cs index 2b91848..f6596ca 100644 --- a/src/Parachute.cs +++ b/src/Parachute.cs @@ -2,7 +2,6 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; using CounterStrikeSharp.API.Modules.Admin; -using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Entities.Constants; using System.Text.Json.Serialization; @@ -16,24 +15,24 @@ public class ConfigGen : BasePluginConfig [JsonPropertyName("FallSpeed")] public float FallSpeed { get; set; } = 100; [JsonPropertyName("AccessFlag")] public string AccessFlag { get; set; } = ""; [JsonPropertyName("TeleportTicks")] public int TeleportTicks { get; set; } = 300; - [JsonPropertyName("ParachuteModelEnabled")] public bool ParachuteModelEnabled { get; set; } = false; + [JsonPropertyName("ParachuteModelEnabled")] public bool ParachuteModelEnabled { get; set; } = true; [JsonPropertyName("ParachuteModel")] public string ParachuteModel { get; set; } = "models/props_survival/parachute/chute.vmdl"; } -[MinimumApiVersion(139)] +[MinimumApiVersion(179)] public class Parachute : BasePlugin, IPluginConfig { public override string ModuleName => "CS2 Parachute"; public override string ModuleAuthor => "Franc1sco Franug"; - public override string ModuleVersion => "1.4"; + public override string ModuleVersion => "1.5"; public ConfigGen Config { get; set; } = null!; public void OnConfigParsed(ConfigGen config) { Config = config; } - private readonly Dictionary bUsingPara = new(); - private readonly Dictionary gParaTicks = new(); - private readonly Dictionary gParaModel = new(); + private readonly Dictionary bUsingPara = new(); + private readonly Dictionary gParaTicks = new(); + private readonly Dictionary gParaModel = new(); public override void Load(bool hotReload) { @@ -47,17 +46,18 @@ public override void Load(bool hotReload) { Utilities.GetPlayers().ForEach(player => { - bUsingPara.Add(player.UserId, false); - gParaTicks.Add(player.UserId, 0); - gParaModel.Add(player.UserId, null); + bUsingPara.Add((int)player.Index, false); + gParaTicks.Add((int)player.Index, 0); + gParaModel.Add((int)player.Index, null); }); } if (Config.ParachuteModelEnabled) { - RegisterListener(map => + RegisterListener((manifest) => { - Server.PrecacheModel(Config.ParachuteModel); + manifest.AddResource(Config.ParachuteModel); + }); } @@ -72,9 +72,9 @@ public override void Load(bool hotReload) } else { - bUsingPara.Add(player.UserId, false); - gParaTicks.Add(player.UserId, 0); - gParaModel.Add(player.UserId, null); + bUsingPara.Add((int)player.Index, false); + gParaTicks.Add((int)player.Index, 0); + gParaModel.Add((int)player.Index, null); return HookResult.Continue; } }); @@ -90,17 +90,17 @@ public override void Load(bool hotReload) } else { - if (bUsingPara.ContainsKey(player.UserId)) + if (bUsingPara.ContainsKey((int)player.Index)) { - bUsingPara.Remove(player.UserId); + bUsingPara.Remove((int)player.Index); } - if (gParaTicks.ContainsKey(player.UserId)) + if (gParaTicks.ContainsKey((int)player.Index)) { - gParaTicks.Remove(player.UserId); + gParaTicks.Remove((int)player.Index); } - if (gParaModel.ContainsKey(player.UserId)) + if (gParaModel.ContainsKey((int)player.Index)) { - gParaModel.Remove(player.UserId); + gParaModel.Remove((int)player.Index); } return HookResult.Continue; } @@ -120,14 +120,14 @@ public override void Load(bool hotReload) && (Config.AccessFlag == "" || AdminManager.PlayerHasPermissions(player, Config.AccessFlag))) { var buttons = player.Buttons; - if ((buttons & PlayerButtons.Use) != 0 && !player.PlayerPawn.Value.OnGroundLastTick) + if ((buttons & PlayerButtons.Use) != 0 && player.PlayerPawn?.Value?.OnGroundLastTick == false) { StartPara(player); } - else if (bUsingPara[player.UserId]) + else if (bUsingPara[(int)player.Index]) { - bUsingPara[player.UserId] = false; + bUsingPara[(int)player.Index] = false; StopPara(player); } } @@ -138,9 +138,9 @@ public override void Load(bool hotReload) { var player = @event.Userid; - if (bUsingPara[player.UserId]) + if (bUsingPara.ContainsKey((int)player.Index) && bUsingPara[(int)player.Index]) { - bUsingPara[player.UserId] = false; + bUsingPara[(int)player.Index] = false; StopPara(player); } return HookResult.Continue; @@ -151,45 +151,52 @@ public override void Load(bool hotReload) private void StopPara(CCSPlayerController player) { player.GravityScale = 1.0f; - gParaTicks[player.UserId] = 0; - if (gParaModel[player.UserId] != null && gParaModel[player.UserId].IsValid) + gParaTicks[(int)player.Index] = 0; + if (gParaModel[(int)player.Index] != null && gParaModel[(int)player.Index]!.IsValid) { - gParaModel[player.UserId].Remove(); - gParaModel[player.UserId] = null; + gParaModel[(int)player.Index]?.Remove(); + gParaModel[(int)player.Index] = null; } } private void StartPara(CCSPlayerController player) { - if (!bUsingPara[player.UserId]) + if (!bUsingPara[(int)player.Index]) { - bUsingPara[player.UserId] = true; + bUsingPara[(int)player.Index] = true; player.GravityScale = 0.1f; if (Config.ParachuteModelEnabled) { - var entity = Utilities.CreateEntityByName("prop_dynamic_override"); + var entity = Utilities.CreateEntityByName("prop_dynamic_override"); if (entity != null && entity.IsValid) { - entity.SetModel(Config.ParachuteModel); entity.MoveType = MoveType_t.MOVETYPE_NOCLIP; entity.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_NONE; entity.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_NONE; + // entity.RenderMode = RenderMode_t.kRenderNormal; // shadows test - dont work entity.DispatchSpawn(); - gParaModel[player.UserId] = entity; + entity.SetModel(Config.ParachuteModel); + //entity.ShadowStrength = 1.0f; // shadows test - dont work + //entity.ShapeType = 0; // shadows test - dont work + //entity.AcceptInput("EnableShadow"); // shadows test - dont work + //entity.AcceptInput("EnableReceivingFlashlight"); // shadows test - dont work + + // CBaseEntity_SetParent(entity, player); // need fix + gParaModel[(int)player.Index] = entity; } } } var fallspeed = Config.FallSpeed * (-1.0f); var isFallSpeed = false; - var velocity = player.PlayerPawn.Value.AbsVelocity; - if (velocity.Z >= fallspeed) + var velocity = player.PlayerPawn.Value?.AbsVelocity; + if (velocity?.Z >= fallspeed) { isFallSpeed = true; } - if (velocity.Z < 0.0f) + if (velocity?.Z < 0.0f) { if (isFallSpeed && Config.Linear || Config.DecreaseVec == 0.0) { @@ -201,22 +208,41 @@ private void StartPara(CCSPlayerController player) velocity.Z = velocity.Z + Config.DecreaseVec; } - var position = player.PlayerPawn.Value.AbsOrigin!; - var angle = player.PlayerPawn.Value.AbsRotation!; + var position = player.PlayerPawn.Value?.AbsOrigin!; + var angle = player.PlayerPawn.Value?.AbsRotation!; - if (gParaTicks[player.UserId] > Config.TeleportTicks) + if (gParaTicks[(int)player.Index] > Config.TeleportTicks) { player.Teleport(position, angle, velocity); - gParaTicks[player.UserId] = 0; + gParaTicks[(int)player.Index] = 0; } - if (gParaModel[player.UserId] != null && gParaModel[player.UserId].IsValid) + if (gParaModel[(int)player.Index] != null && gParaModel[(int)player.Index]!.IsValid) { - gParaModel[player.UserId].Teleport(position, angle, velocity); + gParaModel[(int)player.Index]?.Teleport(position, angle, velocity); } - ++gParaTicks[player.UserId]; + ++gParaTicks[(int)player.Index]; } } + + /* // dont work not sure why + public static string setParentFuncWindowsSig = @"\x4D\x8B\xD9\x48\x85\xD2\x74\x2A"; + public static string setParentFuncLinuxSig = @"\x48\x85\xF6\x74\x2A\x48\x8B\x47\x10\xF6\x40\x31\x02\x75\x2A\x48\x8B\x46\x10\xF6\x40\x31\x02\x75\x2A\xB8\x2A\x2A\x2A\x2A"; + + private static MemoryFunctionVoid CBaseEntity_SetParentFunc + = new(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? setParentFuncLinuxSig : setParentFuncWindowsSig); + + public static void CBaseEntity_SetParent(CBaseEntity childrenEntity, CBaseEntity parentEntity) + { + if (!childrenEntity.IsValid || !parentEntity.IsValid) return; + + var origin = parentEntity.AbsOrigin; + var angle = parentEntity.AbsRotation!; + CBaseEntity_SetParentFunc.Invoke(childrenEntity, parentEntity, null, null); + // If not teleported, the childrenEntity will not follow the parentEntity correctly. + childrenEntity.Teleport(origin, angle, new Vector(IntPtr.Zero)); + Console.WriteLine("CBaseEntity_SetParent() done!"); + }*/ } diff --git a/src/Parachute.csproj b/src/Parachute.csproj index 6b9637f..0c90e14 100644 --- a/src/Parachute.csproj +++ b/src/Parachute.csproj @@ -7,6 +7,6 @@ - +