Advertisement
gopro2027

GTA V PS3 getEntityFromIndex reversed for use in scripts

Apr 26th, 2019
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #define subfc(a,b) (~b + a + 1)
  2. int getAddressOfScriptIndexPoolItem(int pool, int entity) {
  3.     unsigned int r3, r4, r5, r6, r7, r8, r9 = 0;
  4.     r3 = pool;
  5.     r4 = entity;
  6.  
  7.     r8 = r4 >> 8;
  8.     r6 = *(int*)(r3 + 0x4);
  9.     r5 = r4&0xFF;
  10.     r7 = r8;
  11.     r4 = *(int*)r3;
  12.     r6 = *(char*)(r6 + r7);
  13.     if (r6 != r5)
  14.         return 0;
  15.     r6 = *(int*)(r3 + 0x1C);
  16.     if (r6 == 0)
  17.         goto loc_A54DF4;
  18.     r5 = *(int*)(r3 + 0x20);
  19.     if (r7 < r5)//this check might be backwards
  20.                 //would be correct according to https://www.cs.uaf.edu/2011/fall/cs301/lecture/11_21_PowerPC.html
  21.         goto loc_A54DF4;
  22.     r9 = *(int*)(r3 + 0x8);
  23.     if (r7 >= r9)//same as above one, might be backwards
  24.         goto loc_A54DF4;
  25.     r3 = subfc(r7, r5);//this also might be wrong lol
  26.     r3 = r3 >> 2;
  27.     r3 = *(int*)(r6 + r3);
  28.     return r3;
  29.  
  30. loc_A54DF4:
  31.     r3 = *(int*)(r3 + 0xC);
  32.     r3 = r8 * r3;
  33.     r3 = r4 + r3;
  34.     return r3;
  35. }
  36. int getEntityFromIndex(int entityIndex) {
  37.     if (entityIndex == -1)
  38.         return 0;
  39. #define ScriptEntityPool_fwScriptGuid 0x1CC5790
  40.     int v = getAddressOfScriptIndexPoolItem(*(int*)ScriptEntityPool_fwScriptGuid, entityIndex);
  41.     if (v == 0)
  42.         return 0;
  43.     return *(int*)(v + 0x4);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement