Skip to content

Commit

Permalink
Merge pull request #311 from daffyyyy/main
Browse files Browse the repository at this point in the history
2.6a
  • Loading branch information
daffyyyy authored Oct 18, 2024
2 parents e9f47e9 + c911415 commit d9adaa4
Show file tree
Hide file tree
Showing 132 changed files with 685 additions and 1,812 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,8 @@ jobs:
${{ env.OUTPUT_PATH }}/McMaster.NETCore.Plugins.dll \
${{ env.OUTPUT_PATH }}/Microsoft.DotNet.PlatformAbstractions.dll \
${{ env.OUTPUT_PATH }}/Microsoft.Extensions.DependencyModel.dll \
- name: Copy skins.json
run: cp website/data/skins.json ${{ env.OUTPUT_PATH }}/skins.json
- name: Copy gloves.json
run: cp website/data/gloves.json ${{ env.OUTPUT_PATH }}/gloves.json
- name: Copy agents.json
run: cp website/data/agents.json ${{ env.OUTPUT_PATH }}/agents.json
- name: Copy music.json
run: cp website/data/music.json ${{ env.OUTPUT_PATH }}/music.json
- name: Copy skins
run: cp -R website/data ${{ env.OUTPUT_PATH }}
- name: Zip
run: zip -r "${{ env.PROJECT_NAME }}.zip" "${{ env.OUTPUT_PATH }}" gamedata/
- name: Clean files Website
Expand Down
Binary file added 3rd_party/MenuManagerApi.dll
Binary file not shown.
412 changes: 223 additions & 189 deletions Commands.cs

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ public class Additional
public bool CommandKillEnabled { get; set; } = true;

[JsonPropertyName("CommandKnife")]
public string CommandKnife { get; set; } = "knife";
public List<string> CommandKnife { get; set; } = ["knife"];

[JsonPropertyName("CommandMusic")]
public string CommandMusic { get; set; } = "music";
public List<string> CommandMusic { get; set; } = ["music"];

[JsonPropertyName("CommandGlove")]
public string CommandGlove { get; set; } = "gloves";
public List<string> CommandGlove { get; set; } = ["gloves"];

[JsonPropertyName("CommandAgent")]
public string CommandAgent { get; set; } = "agents";
public List<string> CommandAgent { get; set; } = ["agents"];

[JsonPropertyName("CommandSkin")]
public string CommandSkin { get; set; } = "ws";
public List<string> CommandSkin { get; set; } = ["ws"];

[JsonPropertyName("CommandSkinSelection")]
public string CommandSkinSelection { get; set; } = "skins";
public List<string> CommandSkinSelection { get; set; } = ["skins"];

[JsonPropertyName("CommandRefresh")]
public string CommandRefresh { get; set; } = "wp";
public List<string> CommandRefresh { get; set; } = ["wp"];

[JsonPropertyName("CommandKill")]
public string CommandKill { get; set; } = "kill";
public List<string> CommandKill { get; set; } = ["kill"];

[JsonPropertyName("GiveRandomKnife")]
public bool GiveRandomKnife { get; set; } = false;
Expand All @@ -62,7 +62,10 @@ public class Additional

public class WeaponPaintsConfig : BasePluginConfig
{
public override int Version { get; set; } = 6;
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 7;

[JsonPropertyName("SkinsLanguage")]
public string SkinsLanguage { get; set; } = "en";

[JsonPropertyName("DatabaseHost")]
public string DatabaseHost { get; set; } = "";
Expand All @@ -80,15 +83,12 @@ public class WeaponPaintsConfig : BasePluginConfig
public string DatabaseName { get; set; } = "";

[JsonPropertyName("CmdRefreshCooldownSeconds")]
public int CmdRefreshCooldownSeconds { get; set; } = 60;

[JsonPropertyName("Prefix")]
public string Prefix { get; set; } = "[WeaponPaints]";
public int CmdRefreshCooldownSeconds { get; set; } = 10;

[JsonPropertyName("Website")]
public string Website { get; set; } = "example.com/skins";

[JsonPropertyName("Additional")]
[JsonPropertyName("Additionalss")]
public Additional Additional { get; set; } = new();
}
}
4 changes: 1 addition & 3 deletions Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ namespace WeaponPaints
{
public class Database(string dbConnectionString)
{
private readonly string _dbConnectionString = dbConnectionString;

public async Task<MySqlConnection> GetConnectionAsync()
{
try
{
var connection = new MySqlConnection(_dbConnectionString);
var connection = new MySqlConnection(dbConnectionString);
await connection.OpenAsync();
return connection;
}
Expand Down
43 changes: 20 additions & 23 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public HookResult OnClientFullConnect(EventPlayerConnectFull @event, GameEventIn
CCSPlayerController? player = @event.Userid;

if (player is null || !player.IsValid || player.IsBot ||
weaponSync == null || _database == null) return HookResult.Continue;
WeaponSync == null || Database == null) return HookResult.Continue;

PlayerInfo playerInfo = new PlayerInfo
var playerInfo = new PlayerInfo
{
UserId = player.UserId,
Slot = player.Slot,
Expand All @@ -30,7 +30,7 @@ public HookResult OnClientFullConnect(EventPlayerConnectFull @event, GameEventIn

try
{
_ = Task.Run(async () => await weaponSync.GetPlayerData(playerInfo));
_ = Task.Run(async () => await WeaponSync.GetPlayerData(playerInfo));
/*
if (Config.Additional.SkinEnabled)
{
Expand Down Expand Up @@ -70,28 +70,28 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo

if (Config.Additional.SkinEnabled)
{
gPlayerWeaponsInfo.TryRemove(player.Slot, out _);
GPlayerWeaponsInfo.TryRemove(player.Slot, out _);
}
if (Config.Additional.KnifeEnabled)
{
g_playersKnife.TryRemove(player.Slot, out _);
GPlayersKnife.TryRemove(player.Slot, out _);
}
if (Config.Additional.GloveEnabled)
{
g_playersGlove.TryRemove(player.Slot, out _);
GPlayersGlove.TryRemove(player.Slot, out _);
}
if (Config.Additional.AgentEnabled)
{
g_playersAgent.TryRemove(player.Slot, out _);
GPlayersAgent.TryRemove(player.Slot, out _);
}
if (Config.Additional.MusicEnabled)
{
g_playersMusic.TryRemove(player.Slot, out _);
GPlayersMusic.TryRemove(player.Slot, out _);
}

temporaryPlayerWeaponWear.TryRemove(player.Slot, out _);
_temporaryPlayerWeaponWear.TryRemove(player.Slot, out _);

commandsCooldown.Remove(player.Slot);
CommandsCooldown.Remove(player.Slot);

return HookResult.Continue;
}
Expand All @@ -100,8 +100,8 @@ private void OnMapStart(string mapName)
{
if (Config.Additional is { KnifeEnabled: false, SkinEnabled: false, GloveEnabled: false }) return;

if (_database != null)
weaponSync = new WeaponSynchronization(_database, Config);
if (Database != null)
WeaponSync = new WeaponSynchronization(Database, Config);
}

private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
Expand All @@ -116,8 +116,6 @@ private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
if (pawn == null || !pawn.IsValid)
return HookResult.Continue;

g_knifePickupCount[player.Slot] = 0;

GivePlayerMusicKit(player);
GivePlayerAgent(player);
GivePlayerGloves(player);
Expand All @@ -127,14 +125,14 @@ private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)

private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
{
g_bCommandsAllowed = false;
_gBCommandsAllowed = false;

return HookResult.Continue;
}

private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
{
g_bCommandsAllowed = true;
_gBCommandsAllowed = true;
return HookResult.Continue;
}

Expand Down Expand Up @@ -169,16 +167,16 @@ public void OnEntityCreated(CEntityInstance entity)

try
{
SteamID? _steamid = null;
SteamID? steamid = null;

if (weapon.OriginalOwnerXuidLow > 0)
_steamid = new(weapon.OriginalOwnerXuidLow);
steamid = new SteamID(weapon.OriginalOwnerXuidLow);

CCSPlayerController? player = null;
CCSPlayerController? player;

if (_steamid != null && _steamid.IsValid())
if (steamid != null && steamid.IsValid())
{
player = Utilities.GetPlayers().FirstOrDefault(p => p.IsValid && p.SteamID == _steamid.SteamId64);
player = Utilities.GetPlayers().FirstOrDefault(p => p.IsValid && p.SteamID == steamid.SteamId64);

if (player == null)
player = Utilities.GetPlayerFromSteamId(weapon.OriginalOwnerXuidLow);
Expand All @@ -196,7 +194,6 @@ public void OnEntityCreated(CEntityInstance entity)
}
catch (Exception)
{
return;
}
});
}
Expand All @@ -213,7 +210,7 @@ private void OnTick()
)
)
{
if (PlayerWeaponImage.TryGetValue(player.Slot, out var value) && !string.IsNullOrEmpty(value))
if (_playerWeaponImage.TryGetValue(player.Slot, out var value) && !string.IsNullOrEmpty(value))
{
player.PrintToCenterHtml("<img src='{PATH}'</img>".Replace("{PATH}", value));
}
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
- Added command **`!agents`** to show menu with agents
- Translations support, submit a PR if you want to share your translation

## ⚙️ Requirements
**Ensure all the following dependencies are installed before proceeding**
- [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp)
- [PlayerSettings](https://github.com/NickFox007/PlayerSettingsCS2) - Required by MenuManagerCS2
- [AnyBaseLibCS2](https://github.com/NickFox007/AnyBaseLibCS2) - Required by PlayerSettings
- [MenuManagerCS2](https://github.com/NickFox007/MenuManagerCS2)
- MySQL database

## CS2 Server
- Have working CounterStrikeSharp (**with RUNTIME!**)
- Download from Release and copy plugin to plugins
Expand Down Expand Up @@ -66,9 +74,7 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
"GiveRandomKnife": false, // Give random knife to players if they didn't choose
"GiveRandomSkins": false // Give random skins to players if they didn't choose
},

"ConfigVersion": 4 // Don't touch
}</pre></code>
</pre></code>
</details>

## Web install
Expand Down
24 changes: 0 additions & 24 deletions SchemaString.cs

This file was deleted.

14 changes: 7 additions & 7 deletions Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ internal static class Utility

internal static async Task CheckDatabaseTables()
{
if (WeaponPaints._database is null) return;
if (WeaponPaints.Database is null) return;

try
{
await using var connection = await WeaponPaints._database.GetConnectionAsync();
await using var connection = await WeaponPaints.Database.GetConnectionAsync();

await using var transaction = await connection.BeginTransactionAsync();

Expand Down Expand Up @@ -91,7 +91,7 @@ internal static async Task CheckDatabaseTables()

internal static bool IsPlayerValid(CCSPlayerController? player)
{
if (player is null || WeaponPaints.weaponSync is null) return false;
if (player is null || WeaponPaints.WeaponSync is null) return false;

return player is { IsValid: true, IsBot: false, IsHLTV: false, UserId: not null };
}
Expand All @@ -102,7 +102,7 @@ internal static void LoadSkinsFromFile(string filePath, ILogger logger)
try
{
var deserializedSkins = JsonConvert.DeserializeObject<List<JObject>>(json);
WeaponPaints.skinsList = deserializedSkins ?? [];
WeaponPaints.SkinsList = deserializedSkins ?? [];
}
catch (FileNotFoundException)
{
Expand All @@ -116,7 +116,7 @@ internal static void LoadGlovesFromFile(string filePath, ILogger logger)
{
var json = File.ReadAllText(filePath);
var deserializedSkins = JsonConvert.DeserializeObject<List<JObject>>(json);
WeaponPaints.glovesList = deserializedSkins ?? [];
WeaponPaints.GlovesList = deserializedSkins ?? [];
}
catch (FileNotFoundException)
{
Expand All @@ -130,7 +130,7 @@ internal static void LoadAgentsFromFile(string filePath, ILogger logger)
{
var json = File.ReadAllText(filePath);
var deserializedSkins = JsonConvert.DeserializeObject<List<JObject>>(json);
WeaponPaints.agentsList = deserializedSkins ?? [];
WeaponPaints.AgentsList = deserializedSkins ?? [];
}
catch (FileNotFoundException)
{
Expand All @@ -144,7 +144,7 @@ internal static void LoadMusicFromFile(string filePath, ILogger logger)
{
var json = File.ReadAllText(filePath);
var deserializedSkins = JsonConvert.DeserializeObject<List<JObject>>(json);
WeaponPaints.musicList = deserializedSkins ?? [];
WeaponPaints.MusicList = deserializedSkins ?? [];
}
catch (FileNotFoundException)
{
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5a
2.6a
Loading

0 comments on commit d9adaa4

Please sign in to comment.