-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 46e42b4
Showing
7 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
bin/ | ||
obj/ | ||
.vs/ | ||
.git | ||
.vscode/ | ||
CSS-Panel |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
using System.Text.Json; | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Core.Capabilities; | ||
using CounterStrikeSharp.API.Modules.Admin; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using LevelsRanks.API; | ||
using MySqlConnector; | ||
using Dapper; | ||
|
||
|
||
namespace LevelRanks_FakeRanks; | ||
|
||
public class Config | ||
{ | ||
public int Type { get; set; } = 2; | ||
} | ||
|
||
public class LevelRanks_FakeRanks : BasePlugin | ||
{ | ||
public override string ModuleName => "[LR] Fake Ranks"; | ||
public override string ModuleVersion => "1.0.0"; | ||
public override string ModuleAuthor => "Ravid"; | ||
public override string ModuleDescription => "Fake Ranks in scoreboard for LevelRanks plugin."; | ||
|
||
private readonly PluginCapability<IPointsManager> _pointsManagerCapability = new("levelsranks"); | ||
private IPointsManager? _pointsManager; | ||
|
||
private bool AllowUpdate = false; | ||
|
||
private Config config = new(); | ||
|
||
public override void Load(bool hotReload) | ||
{ | ||
base.Load(hotReload); | ||
|
||
_pointsManager = _pointsManagerCapability.Get(); | ||
|
||
if (_pointsManager == null) | ||
{ | ||
Server.PrintToConsole("Points management system is currently unavailable."); | ||
return; | ||
} | ||
|
||
config = LoadConfig(); | ||
|
||
RegisterEventHandler((EventRoundPrestart @event, GameEventInfo info) => { AllowUpdate = true; return HookResult.Continue; }); | ||
RegisterEventHandler((EventCsWinPanelMatch @event, GameEventInfo info) => { AllowUpdate = false; return HookResult.Continue; }); | ||
|
||
AddCommand("css_fakeranks_reload", "Reloads the plugin configuration.", OnReloadCommand); | ||
|
||
RegisterListener<Listeners.OnTick>(() => | ||
{ | ||
if (config.Type == 0 || !AllowUpdate) | ||
{ | ||
return; | ||
} | ||
|
||
Utilities.GetPlayers().ForEach(p => | ||
{ | ||
if (p.IsValid && !p.IsBot) | ||
{ | ||
if(config.Type == 1) | ||
{ | ||
GetDataFromDB(p); | ||
} else{ | ||
var rankid = _pointsManager.GetCurrentRank(p.SteamID.ToString()); | ||
|
||
p.CompetitiveWins = 10; | ||
p.CompetitiveRankType = 12; | ||
p.CompetitiveRanking = rankid!.Id; | ||
Utilities.SetStateChanged(p, "CCSPlayerController", "m_iCompetitiveRankType"); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
private void GetDataFromDB(CCSPlayerController player) | ||
{ | ||
var connectionString = _pointsManager!.GetConnectionString(); | ||
var databaseConfig = _pointsManager.GetDatabaseConfig(); | ||
|
||
using var connection = new MySqlConnection(connectionString); | ||
connection.Open(); | ||
|
||
var pointsQuery = $"SELECT `value` FROM {databaseConfig.Name} WHERE steam = @SteamID"; | ||
var points = connection.QueryFirstOrDefault<int>(pointsQuery, new { SteamID = ConvertSteamID64ToSteamID(player.SteamID.ToString()) }); | ||
|
||
if(points < 0) | ||
{ | ||
points = 0; | ||
} | ||
|
||
player.CompetitiveWins = 10; | ||
player.CompetitiveRankType = 11; | ||
player.CompetitiveRanking = points; | ||
Utilities.SetStateChanged(player, "CCSPlayerController", "m_iCompetitiveRankType"); | ||
} | ||
|
||
//Reload command | ||
// need @css/root permission | ||
[RequiresPermissions(new string[] { "@css/root" })] | ||
public void OnReloadCommand(CCSPlayerController? player, CommandInfo info) | ||
{ | ||
if(player == null) | ||
{ | ||
info.ReplyToCommand(" \x04[FakeRanks]\x01 You must be a player to use this command."); | ||
return; | ||
} | ||
|
||
if(!player.IsValid || player.IsBot) | ||
{ | ||
info.ReplyToCommand(" \x04[FakeRanks]\x01 You must be a player to use this command."); | ||
return; | ||
} | ||
|
||
config = LoadConfig(); | ||
info.ReplyToCommand(" \x04[FakeRanks]\x01 Configuration reloaded."); | ||
} | ||
|
||
public Config LoadConfig() | ||
{ | ||
var configPath = Path.Combine(ModuleDirectory, "config.json"); | ||
if (!File.Exists(configPath)) | ||
{ | ||
return CreateConfig(configPath); | ||
} | ||
|
||
var config = JsonSerializer.Deserialize<Config>(File.ReadAllText(configPath))!; | ||
|
||
return config; | ||
} | ||
|
||
private static Config CreateConfig(string configPath) | ||
{ | ||
var config = new Config(); | ||
|
||
File.WriteAllText(configPath, | ||
JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true })); | ||
return config; | ||
} | ||
|
||
public static string ConvertSteamID64ToSteamID(string steamId64) | ||
{ | ||
if (ulong.TryParse(steamId64, out var communityId) && communityId > 76561197960265728) | ||
{ | ||
var authServer = (communityId - 76561197960265728) % 2; | ||
var authId = (communityId - 76561197960265728 - authServer) / 2; | ||
return $"STEAM_1:{authServer}:{authId}"; | ||
} | ||
return string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>[LR] Fake Ranks</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.234" /> | ||
<PackageReference Include="Dapper" Version="2.1.35" /> | ||
<Reference Include="LevelsRanks.API.dll"> | ||
<HintPath>LevelsRanks.API.dll</HintPath> | ||
</Reference> | ||
<Reference Include="MySqlConnector"> | ||
<HintPath>MySqlConnector.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# LevelRanks_FakeRanks | ||
|
||
> [!CAUTION] | ||
> This plugin does not reveal actual MM Ranks of players. | ||
## A plugin that reveals ranks of all players in server for player who presses "tab" | ||
|
||
Using [LevelRanks API](https://github.com/ABKAM2023/CS2-LevelsRanks-Core) for data | ||
|
||
## Dependencies | ||
|
||
- [LevelRanks Core](https://github.com/ABKAM2023/CS2-LevelsRanks-Core) | ||
- [FakeRanks](https://github.com/Cruze03/FakeRanks-RevealAll) |