Created
June 14, 2016 15:05
-
-
Save TinkerWorX/378e6fddcd494e26d9688ea0bccde321 to your computer and use it in GitHub Desktop.
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
using MindWorX.SharpCraft.Modules.WarAPI; | |
using MindWorX.SharpCraft.Modules.WarAPI.Types; | |
using System; | |
using System.Collections.Generic; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using TinkerWorX.SharpCraft; | |
using TinkerWorX.SharpCraft.Utilities; | |
using TinkerWorX.SharpCraft.Windows; | |
namespace MindWorX.SharpCraft.TeamSurvival | |
{ | |
[Requires(typeof(WarAPIPlugin))] | |
public class CustomHeroNamePlugin : IPlugin | |
{ | |
private static Dictionary<CUnit, String> names = new Dictionary<CUnit, String>(); | |
// int __thiscall GetHeroProperName(unit* this, char* name, size_t max_length) @ sub_6F668DD0 | |
[UnmanagedFunctionPointer(CallingConvention.ThisCall)] | |
private delegate Int32 GetHeroProperNamePrototype(CUnit unit, IntPtr name, Int32 maxLength); | |
private static GetHeroProperNamePrototype GetHeroProperName; | |
private static Int32 GetHeroProperNameHook(CUnit unit, IntPtr namePtr, Int32 maxLength) | |
{ | |
String name; | |
if (names.TryGetValue(unit, out name)) | |
{ | |
Marshal.Copy(Encoding.ASCII.GetBytes(name), 0, namePtr, name.Length); | |
Memory.Write(namePtr, name.Length, (Byte)0); | |
return name.Length; | |
} | |
return GetHeroProperName(unit, namePtr, maxLength); | |
} | |
public static Boolean IsInitialized { get; set; } | |
public static void SetName(CUnit unit, String name) | |
{ | |
names[unit] = name; | |
} | |
public static void ClearName(CUnit unit) | |
{ | |
names.Remove(unit); | |
} | |
public void Initialize(PluginContext context) | |
{ | |
} | |
public void OnGameLoad(PluginContext context) | |
{ | |
if (context != PluginContext.Game || IsInitialized) | |
return; | |
var @base = Kernel32.GetModuleHandle("game.dll"); | |
GetHeroProperName = Memory.InstallHook(@base + 0x668DD0, new GetHeroProperNamePrototype(GetHeroProperNameHook), true, false); | |
IsInitialized = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment