From bf8a51fbc576344759ede86cd4667047cb1b29db Mon Sep 17 00:00:00 2001 From: DiFFoZ <48765566+DiFFoZ@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:49:50 +0700 Subject: [PATCH] Add patch PlayerTool to find dummy by name. --- Dummy/Patches/Patch_PlayerTool.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Dummy/Patches/Patch_PlayerTool.cs b/Dummy/Patches/Patch_PlayerTool.cs index 004f318..10083d6 100644 --- a/Dummy/Patches/Patch_PlayerTool.cs +++ b/Dummy/Patches/Patch_PlayerTool.cs @@ -16,7 +16,7 @@ public static class Patch_PlayerTool public static void getSteamPlayerBySteamId(CSteamID steamID, ref SteamPlayer __result) { if (__result != null || OnNeedDummyProvider == null) return; - var dummy = OnNeedDummyProvider.Invoke().Dummies.FirstOrDefault(x => x.SteamID == steamID); + var dummy = OnNeedDummyProvider().Dummies.FirstOrDefault(x => x.SteamID == steamID); if (dummy != null) { __result = dummy.SteamPlayer; @@ -29,12 +29,26 @@ public static void getSteamPlayerByUlong(ulong steamID, ref SteamPlayer __result { if (__result != null || OnNeedDummyProvider == null) return; - var dummy = OnNeedDummyProvider.Invoke().Dummies.FirstOrDefault(x => x.SteamID == (CSteamID)steamID); + var dummy = OnNeedDummyProvider().Dummies.FirstOrDefault(x => x.SteamID == (CSteamID)steamID); + if (dummy != null) + { + __result = dummy.SteamPlayer; + } + } + + [HarmonyPatch("getSteamPlayer", new Type[] { typeof(string) })] + [HarmonyPostfix] + public static void getSteamPlayerByString(string name, ref SteamPlayer __result) + { + if (__result != null || OnNeedDummyProvider == null) return; + + var dummy = OnNeedDummyProvider().Dummies + .FirstOrDefault(x => NameTool.checkNames(name, x.DisplayName) + || NameTool.checkNames(name, x.SteamPlayer.playerID.playerName)); if (dummy != null) { __result = dummy.SteamPlayer; } } - // todo: add patch to get by name } }