private static int GetUnitReaction(IntPtr hProcess, uint unit1, uint unit2)
{
if (unit1 == 0 || unit2 == 0)
return -1;
int hash1, hash2;
int factionIndex = Memory.ReadInt(hProcess, 0x93E80C);
int factionPointer = Memory.ReadInt(hProcess, 0x93E818);
int totalFactions = Memory.ReadInt(hProcess, 0x93E808);
int unit1Faction = Memory.ReadInt(hProcess, (Memory.ReadUInt(hProcess, (unit1 + 0x120)) + 0x74));
int unit2Faction = Memory.ReadInt(hProcess, (Memory.ReadUInt(hProcess, (unit2 + 0x120)) + 0x74));
if (unit1Faction >= factionIndex && unit2Faction >= factionIndex &&
unit1Faction < totalFactions && unit2Faction < totalFactions)
{
hash1 = Memory.ReadInt(hProcess, (factionPointer + ((unit1Faction - factionIndex) * 4)));
hash2 = Memory.ReadInt(hProcess, (factionPointer + ((unit2Faction - factionIndex) * 4)));
return CompareFactionHash(hProcess, hash1, hash2);
}
return -2;
}
private static int CompareFactionHash(IntPtr hProcess, int hash1, int hash2)
{
if (hash1 == 0 || hash2 == 0)
return -1;
int hashCheck1 = 0, hashCheck2 = 0;
int hashCompare = 0;
int hashIndex = 0;
byte[] bHash1 = new byte[0x40];
byte[] bHash2 = new byte[0x40];
Memory.ReadMemory(hProcess, hash1, ref bHash1);
Memory.ReadMemory(hProcess, hash2, ref bHash2);
hashCheck1 = BitConverter.ToInt32(bHash1, 0x04);
hashCheck2 = BitConverter.ToInt32(bHash2, 0x04);
//bitwise compare of [bHash1+0x14] and [bHash2+0x0C]
if ((BitConverter.ToInt32(bHash1, 0x14) & BitConverter.ToInt32(bHash2, 0x0C)) != 0)
return 1; //hostile
hashIndex = 0x18;
hashCompare = BitConverter.ToInt32(bHash1, hashIndex);
if (hashCompare != 0)
{
for (int i = 0; i < 4; i++)
{
if (hashCompare == hashCheck2)
return 1; //hostile
hashIndex += 4;
hashCompare = BitConverter.ToInt32(bHash1, hashIndex);
if (hashCompare == 0)
break;
}
}
//bitwise compare of [bHash1+0x10] and [bHash2+0x0C]
if ((BitConverter.ToInt32(bHash1, 0x10) & BitConverter.ToInt32(bHash2, 0x0C)) != 0)
return 4; //friendly
hashIndex = 0x28;
hashCompare = BitConverter.ToInt32(bHash1, hashIndex);
if (hashCompare != 0)
{
for (int i = 0; i < 4; i++)
{
if (hashCompare == hashCheck2)
return 4; //friendly
hashIndex += 4;
hashCompare = BitConverter.ToInt32(bHash1, hashIndex);
if (hashCompare == 0)
break;
}
}
//bitwise compare of [bHash2+0x10] and [bHash1+0x0C]
if ((BitConverter.ToInt32(bHash2, 0x10) & BitConverter.ToInt32(bHash1, 0x0C)) != 0)
return 4; //friendly
hashIndex = 0x28;
hashCompare = BitConverter.ToInt32(bHash2, hashIndex);
if (hashCompare != 0)
{
for (int i = 0; i < 4; i++)
{
if (hashCompare == hashCheck1)
return 4; //friendly
hashIndex += 4;
hashCompare = BitConverter.ToInt32(bHash2, hashIndex);
if (hashCompare == 0)
break;
}
}
return 3; //neutral
}
private static string UnitReaction(int reaction)
{
switch (reaction)
{
case 1:
return "Hostile";
case 3:
return "Neutral";
case 4:
return "Friendly";
default:
return "Not Used";
}
}