public void CreateHero(int player) { if (NewHeroPtr != IntPtr.Zero) { MemoryApi.WriteMemoryPtrBytes(gameProcess, IntPtr.Add(NewHeroPtr, 0x8D), BitConverter.GetBytes(player)); } }
public Item GetItem(int player, int index) { Item i; i.player = player; i.index = index; i.IID = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetItemIDPtr(player, index), 4, out _), 0); i.UID = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetItemHolderPtr(player, index), 4, out _), 0); return(i); }
private IntPtr GetLayeredPointer(IntPtr ptr, int[] offset)//https://stackoverflow.com/questions/47481769/c-sharp-multi-level-pointers-memory-reading { IntPtr output = ptr; for (int i = 0; i < offset.Length - 1; i++) { output = IntPtr.Add(output, offset[i]); output = new IntPtr(BitConverter.ToInt64(MemoryApi.ReadMemoryPtr(gameProcess, output, 8, out _), 0)); } output = IntPtr.Add(output, offset[offset.Length - 1]); return(output); }
private void SetOpCode(IntPtr loc, byte[] code, bool Active) { byte[] check = MemoryApi.ReadMemoryPtr(gameProcess, loc, code.Length, out _); if (MatchingByteArray(check, code) && !Active) { MemoryApi.WriteMemoryPtrBytes(gameProcess, loc, NoOpCode(code.Length)); } else if (MatchingByteArray(check, NoOpCode(code.Length)) && Active) { MemoryApi.WriteMemoryPtrBytes(gameProcess, loc, code); } }
public void SetPlayerLevel(int player, int newLevel) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetPlayerLevelPtr(player), BitConverter.GetBytes(newLevel)); if (newLevel > 10) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetPlayerXPPtr(player), BitConverter.GetBytes(PlayerXpValues[9])); } else { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetPlayerXPPtr(player), BitConverter.GetBytes(PlayerXpValues[newLevel - 1])); } }
private bool IsOpCodeActive(IntPtr loc, int length) { byte[] check = MemoryApi.ReadMemoryPtr(gameProcess, loc, length, out _); if (MatchingByteArray(check, NoOpCode(length))) { return(false); } else { return(true); } }
public void SetBotShop(bool canShop) { if (canShop) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetBotLevelTest(), BitConverter.GetBytes(10)); MemoryApi.WriteMemoryPtrBytes(gameProcess, GetBotTierTest(), BitConverter.GetBytes(99)); } else { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetBotLevelTest(), BitConverter.GetBytes(0)); MemoryApi.WriteMemoryPtrBytes(gameProcess, GetBotTierTest(), BitConverter.GetBytes(0)); } }
public void SetHeroPositionSmart(int player, int index, int xPos, int yPos) { if (player == 0) { yPos = 3 - yPos; } else { xPos = 7 - xPos; yPos -= 1; } MemoryApi.WriteMemoryPtrBytes(gameProcess, GetUnitXPtr(player, index), BitConverter.GetBytes(xPos)); MemoryApi.WriteMemoryPtrBytes(gameProcess, GetUnitYPtr(player, index), BitConverter.GetBytes(yPos)); }
public void SetHeroID(int player, int index, int newID) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetUnitIDPtr(player, index), BitConverter.GetBytes(newID)); SetHeroSupplyCount(player, index, 1); for (int i = 91; i < 95; i++) { if (newID == i) { SetHeroSupplyCount(player, index, 0); break; } } }
public Hero GetHero(int player, int index) { Hero h; h.player = player; h.index = index; h.UID = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetUnitUniqueIDPtr(player, index), 4, out _), 0); h.HID = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetUnitIDPtr(player, index), 4, out _), 0); h.xPos = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetUnitXPtr(player, index), 4, out _), 0); h.yPos = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetUnitYPtr(player, index), 4, out _), 0); h.level = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetUnitLevelPtr(player, index), 4, out _), 0); h.kills = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetUnitKillsPtr(player, index), 4, out _), 0); return(h); }
public bool HeroInjectionActive() { byte[] code = MemoryApi.ReadMemoryPtr(gameProcess, IntPtr.Add(serverAddress, TickOpOffset), 1, out _); if (code[0] == 0xE9) { code = MemoryApi.ReadMemoryPtr(gameProcess, IntPtr.Add(serverAddress, TickOpOffset + 1), 4, out _); int offset = BitConverter.ToInt32(code, 0); IntPtr testPtr = IntPtr.Add(serverAddress, TickOpOffset + 5 + offset); if (NewHeroPtr != testPtr) { NewHeroPtr = testPtr; } return(true); } else { return(false); } }
public bool MatchingOpCodes() { byte[] check = MemoryApi.ReadMemoryPtr(gameProcess, GetOpMovePtr(), MoveOpcodeBytes.Length, out _); if (!MatchingByteArray(check, MoveOpcodeBytes) && !MatchingByteArray(check, NoOpCode(MoveOpcodeBytes.Length))) { return(false); } check = MemoryApi.ReadMemoryPtr(gameProcess, GetOpSwapPtr(), SwapOpcodeBytes.Length, out _); if (!MatchingByteArray(check, SwapOpcodeBytes) && !MatchingByteArray(check, NoOpCode(SwapOpcodeBytes.Length))) { return(false); } check = MemoryApi.ReadMemoryPtr(gameProcess, GetOpBotLogicPtr(), BotOpcodeBytes.Length, out _); if (!MatchingByteArray(check, BotOpcodeBytes) && !MatchingByteArray(check, NoOpCode(BotOpcodeBytes.Length))) { return(false); } check = MemoryApi.ReadMemoryPtr(gameProcess, GetOpItemPtr(), ItemOpcodeBytes.Length, out _); if (!MatchingByteArray(check, ItemOpcodeBytes) && !MatchingByteArray(check, NoOpCode(ItemOpcodeBytes.Length))) { return(false); } return(true); }
public void SetHeroPosition(int player, int index, int xPos, int yPos) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetUnitXPtr(player, index), BitConverter.GetBytes(xPos)); MemoryApi.WriteMemoryPtrBytes(gameProcess, GetUnitYPtr(player, index), BitConverter.GetBytes(yPos)); }
public void SetHeroSupplyCount(int player, int index, int count) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetUnitSupplyCountPtr(player, index), BitConverter.GetBytes(count)); }
public void SetHeroLevel(int player, int index, int newLevel) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetUnitLevelPtr(player, index), BitConverter.GetBytes(newLevel)); }
public int GetPlayerLevel(int player) { return(BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(gameProcess, GetPlayerLevelPtr(player), 4, out _), 0)); }
public void SetPlayerGold(int player, int newGold) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetPlayerGoldPtr(player), BitConverter.GetBytes(newGold)); }
public void SetPlayerLife(int player, int newLife) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetPlayerLifePtr(player), BitConverter.GetBytes(newLife)); }
public void SetHeroKills(int player, int index, int kills) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetUnitKillsPtr(player, index), BitConverter.GetBytes(kills)); }
public void SetItemID(int player, int index, int newID) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetItemIDPtr(player, index), BitConverter.GetBytes(newID)); }
public void SetItemHolder(int player, int index, int HeroUID) { MemoryApi.WriteMemoryPtrBytes(gameProcess, GetItemHolderPtr(player, index), BitConverter.GetBytes(HeroUID)); }
private void NewUpdate() { if (!ad.CheckGameStatus()) { ah.ClearAlliances(); ad = null; } else { int[] UnitCount = new int[2]; UnitCount[0] = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(ad.gameProcess, ad.GetUnitCountPtr(0), 4, out _), 0); UnitCount[1] = BitConverter.ToInt32(MemoryApi.ReadMemoryPtr(ad.gameProcess, ad.GetUnitCountPtr(1), 4, out _), 0); for (int i = 0; i < 2; i++) { #region hero update for (int j = 0; j < UnitCount[i]; j++) { heroLists[i, 1].Add(ad.GetHero(i, j)); } IEnumerable <Hero> removed = heroLists[i, 0].Except(heroLists[i, 1]); IEnumerable <Hero> newHeroes = heroLists[i, 1].Except(heroLists[i, 0]); foreach (Hero h in removed) { PictureBox pb = GetHeroPictureBox(i, h.xPos, h.yPos); pb.Tag = null; pb.BackgroundImage = null; if (h.yPos != -1) { ah.RemoveAlliance(i, h.HID); } HeroUIDtoHID.Remove(h.UID); } foreach (Hero h in newHeroes) { PictureBox pb = GetHeroPictureBox(i, h.xPos, h.yPos); pb.Tag = h; if (ItemUIDtoIID.ContainsKey(h.UID)) //If an item has this hero's uid, { pb.BackgroundImage = IconHelper.CombineImagePair(IconHelper.GetImageByID(h.HID), IconHelper.GetMiniImageByID(ItemUIDtoIID[h.UID])); } else { pb.BackgroundImage = IconHelper.GetImageByID(h.HID); } if (h.yPos != -1) { ah.AddAlliance(i, h.HID); } HeroUIDtoHID.Add(h.UID, h.HID); } if (removed.Count() > 0 || newHeroes.Count() > 0) { tlpArray[i].Invalidate(); if (i == 0) { PlayerAlliancesRTB.Text = ah.GetAlliances(i); } else { BotAlliancesRTB.Text = ah.GetAlliances(i); } } #endregion #region items for (int j = 0; j < 12; j++) { itemLists[i, 1].Add(ad.GetItem(i, j)); if (itemLists[i, 1][j].GetHashCode() != itemLists[i, 0][j].GetHashCode()) { PictureBox pb = GetPBByUID(i, itemLists[i, 0][j].UID); if (pb != null) { pb.BackgroundImage = IconHelper.GetImageByID(((Hero)pb.Tag).HID); } ItemUIDtoIID.Remove(itemLists[i, 0][j].UID); } } for (int j = 0; j < 12; j++) { if (itemLists[i, 1][j].GetHashCode() != itemLists[i, 0][j].GetHashCode()) { if (itemLists[i, 1][j].UID != 0) { ItemUIDtoIID.Add(itemLists[i, 1][j].UID, itemLists[i, 1][j].IID); } PictureBox pb = (PictureBox)tlpArray[2 + i].GetControlFromPosition(j / 6, j % 6); pb.Tag = itemLists[i, 1][j]; if (HeroUIDtoHID.ContainsKey(itemLists[i, 1][j].UID)) { //set item image pair pb.BackgroundImage = IconHelper.CombineImagePair(IconHelper.GetImageByID(itemLists[i, 1][j].IID), IconHelper.GetMiniImageByID(HeroUIDtoHID[itemLists[i, 1][j].UID])); //set hero image pair pb = GetPBByUID(i, itemLists[i, 1][j].UID); pb.BackgroundImage = IconHelper.CombineImagePair(IconHelper.GetImageByID(((Hero)pb.Tag).HID), IconHelper.GetMiniImageByID(ItemUIDtoIID[((Hero)pb.Tag).UID])); //remove old hero image pair pb = GetPBByUID(i, itemLists[i, 0][j].UID); if (pb != null) { pb.BackgroundImage = IconHelper.GetImageByID(((Hero)pb.Tag).HID); } } else { pb.BackgroundImage = IconHelper.GetImageByID(itemLists[i, 1][j].IID); } } } #endregion heroLists[i, 0] = new List <Hero>(heroLists[i, 1]); heroLists[i, 1].Clear(); itemLists[i, 0] = new List <Item>(itemLists[i, 1]); itemLists[i, 1].Clear(); UpdateControls(i); } } }
public bool CreateHeroInjection() { bool ByteCountError = false; Byte[] write; Dictionary <string, IntPtr> Locations = new Dictionary <string, IntPtr>(); Locations.Add("herofunc", IntPtr.Add(serverAddress, 0xF6AA0 - 5)); Locations.Add("returntick", IntPtr.Add(serverAddress, 0xE48A0 + 8 - 5)); Locations.Add("tickfunc", IntPtr.Add(serverAddress, 0xE48A0)); IntPtr target = IntPtr.Subtract(serverAddress, 0x10000); int trycount = 1000; IntPtr newMem = IntPtr.Zero; while (newMem == IntPtr.Zero && trycount > 0) { trycount--; newMem = MemoryApi.MemoryAlloc(gameProcess, target, 0x100); target = IntPtr.Subtract(target, 0x10000); } if (newMem != IntPtr.Zero) { Assembly assembly = Assembly.GetExecutingAssembly(); //https://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file using (Stream stream = assembly.GetManifestResourceStream("UnderlordsTracker.TextFiles.AddHeroInjection.txt")) { using (StreamReader sr = new StreamReader(stream)) { string line; List <byte> code = new List <byte>(); while ((line = sr.ReadLine()) != null && !ByteCountError) { string[] split = line.Split('-'); split[0] = split[0].Replace(" ", ""); split[0] = split[0].Trim(); if (split[0].Contains("%")) { int byteOffset = code.Count; string[] secondSplit = split[0].Split('%'); byte[] jumpDistance = GetByteDistance(IntPtr.Add(newMem, byteOffset), Locations[secondSplit[1]]); code.Add(BitConverter.GetBytes(int.Parse(secondSplit[0], System.Globalization.NumberStyles.HexNumber))[0]); code.AddRange(jumpDistance); } else { if (split[0].Length % 2 != 0) { ByteCountError = true; } else { for (int i = 0; i < split[0].Length / 2; i++) { code.Add(BitConverter.GetBytes(int.Parse(split[0].Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber))[0]); } } } } write = code.ToArray(); } } if (!ByteCountError) { MemoryApi.WriteMemoryPtrBytes(gameProcess, newMem, write); List <byte> code = new List <byte>(); code.Add(0xE9); code.AddRange(GetByteDistance(Locations["tickfunc"], newMem - 5)); for (int i = 0; i < 3; i++) { code.Add(0x90); } MemoryApi.WriteMemoryPtrBytes(gameProcess, Locations["tickfunc"], code.ToArray()); NewHeroPtr = newMem; return(true); } } return(false); }