Skip to content

Commit

Permalink
Oqyh main (#149)
Browse files Browse the repository at this point in the history
Co-authored-by: Gold KingZ <[email protected]>
  • Loading branch information
yonilerner and oqyh authored Apr 29, 2024
1 parent 82198b3 commit 11dc227
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 86 deletions.
Binary file added Resources/ASITE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/BSITE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 15 additions & 27 deletions RetakesAllocator/CustomGameData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using RetakesAllocatorCore;

namespace RetakesAllocator;

Expand All @@ -15,15 +14,15 @@ public class CustomGameData
"CCSPlayer_CanAcquire",
new()
{
{OSPlatform.Windows, @"\x40\x55\x41\x57\x48\x8D\x6C\x24\x2A\x48\x81\xEC\x08\x01\x00\x00"},
{OSPlatform.Windows, @"\x48\x8B\xC4\x44\x89\x40\x18\x48\x89\x48\x08\x55\x56"},
{OSPlatform.Linux, @"\x55\x48\x89\xE5\x41\x57\x41\x56\x48\x8D\x45\xCC"},
}
},
{
"GetCSWeaponDataFromKey",
new()
{
{OSPlatform.Windows, @"\x48\x89\x5C\x24\xCC\x48\x89\x74\x24\xCC\x57\x48\x83\xEC\x20\x48\x8B\xFA\x8B"},
{OSPlatform.Windows, @"\x48\x89\x5C\x24\x08\x48\x89\x74\x24\x10\x57\x48\x83\xEC\x20\x48\x8B\xFA\x8B"},
{OSPlatform.Linux, @"\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x89\xFE\x41\x55\x41\x54\x45"},
}
},
Expand All @@ -33,17 +32,17 @@ public class CustomGameData
{
{
OSPlatform.Windows,
@"\x48\x2B\xD1\xF6\xC1\x07"
@"\x48\x83\xEC\x38\x48\xC7\x44\x24\x28\x00\x00\x00\x00\x45\x33\xC9\x45\x33\xC0\xC6\x44\x24\x20\x00\xE8\x2A\x2A\x2A\x2A\x48\x85"
},
{
OSPlatform.Linux,
@"\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x53\x48\x83\xEC\x18\x48\x89\x7D\xC8\x48\x85\xF6\x74"
}
},
}
}
};

private readonly MemoryFunctionVoid<IntPtr, string, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr>? GiveNamedItem2;
private readonly MemoryFunctionVoid<IntPtr, string, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr> GiveNamedItem2;

public readonly
MemoryFunctionWithReturn<CCSPlayer_ItemServices, CEconItemView, AcquireMethod, NativeObject, AcquireResult>
Expand All @@ -53,21 +52,16 @@ public readonly

public CustomGameData()
{
var giveNamedItemData = GetCustomGameDataKey("GiveNamedItem2");
if (giveNamedItemData is not null)
{
GiveNamedItem2 = new(giveNamedItemData);
}

GiveNamedItem2 = new(GetCustomGameDataKey("GiveNamedItem2"));
CCSPlayer_CanAcquireFunc = new(GetCustomGameDataKey("CCSPlayer_CanAcquire"));
GetCSWeaponDataFromKeyFunc = new(GetCustomGameDataKey("GetCSWeaponDataFromKey"));
}

private string? GetCustomGameDataKey(string key)
private string GetCustomGameDataKey(string key)
{
if (!_customGameData.TryGetValue(key, out var customGameData))
{
return null;
throw new Exception($"Invalid key {key}");
}

OSPlatform platform;
Expand All @@ -84,7 +78,9 @@ public CustomGameData()
throw new Exception("Unsupported platform");
}

return customGameData.TryGetValue(platform, out var customData) ? customData : null;
return customGameData.TryGetValue(platform, out var customData)
? customData
: throw new Exception($"Missing custom data for {key} on {platform}");
}

public void PlayerGiveNamedItem(CCSPlayerController player, string item)
Expand All @@ -94,16 +90,8 @@ public void PlayerGiveNamedItem(CCSPlayerController player, string item)
if (!player.PlayerPawn.Value.IsValid) return;
if (player.PlayerPawn.Value.ItemServices == null) return;

if (GiveNamedItem2 is not null)
{
Log.Debug("Using custom function for GiveNamedItem2");
GiveNamedItem2.Invoke(player.PlayerPawn.Value.ItemServices.Handle, item, 0, 0, 0, 0, 0, 0);
}
else
{
Log.Debug("Using default function for GiveNamedItem2");
player.GiveNamedItem(item);
}
// Log.Debug("Using custom function for GiveNamedItem2");
GiveNamedItem2.Invoke(player.PlayerPawn.Value.ItemServices.Handle, item, 0, 0, 0, 0, 0, 0);
}
}

Expand All @@ -128,4 +116,4 @@ public enum AcquireMethod
{
PickUp = 0,
Buy,
};
};
6 changes: 6 additions & 0 deletions RetakesAllocator/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Runtime.InteropServices;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
Expand Down Expand Up @@ -194,5 +195,10 @@ public static int GetNumPlayersOnTeam()
.Count;
}

public static bool IsWindows()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}

public static bool IsVip(CCSPlayerController player) => AdminManager.PlayerHasPermissions(player, "@css/vip");
}
Loading

0 comments on commit 11dc227

Please sign in to comment.