Advertisement
XeSao

MW2 TU8 - BulletTrace fully reversed! - By XeSao

Nov 28th, 2014
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. //Scr_BulletTrace fully reversed!
  2. //Credits to Xx James t xX for the BulletTraceType as it is much easier with it
  3. //Example on how to use it:
  4.  
  5. /*
  6. BulletTraceType Type;
  7. float start[3] = { 123, 435, 642 },
  8.     end[3] = { 130, 450, 642 };
  9. int Client = 3;
  10. bulletTrace(&Type, start, end, Client, true);
  11.  
  12. if(!strcmp(Type.surfaceType, "default"))
  13.     setOrigin(Type.entity, Type.position);
  14. */
  15.  
  16.  
  17. typedef struct BulletTraceType
  18. {
  19.     short entityid;
  20.     float position[3];
  21.     TraceHitType hitType;
  22.     char *surfaceFlag;
  23.     int entity;
  24. };
  25.  
  26. typedef enum TraceHitType
  27. {
  28.     TRACE_HITTYPE_NONE,
  29.     TRACE_HITTYPE_ENTITY,
  30.     TRACE_HITTYPE_DYNENT_MODEL,
  31.     TRACE_HITTYPE_DYNENT_BRUSH,
  32.     TRACE_HITTYPE_UNKNOWN
  33. };
  34.  
  35. typedef struct trace_t
  36. {
  37.     float fraction;//0x00 - 0x04
  38.     float normal[3];//0x04 - 0x10
  39.     int surfaceFlags;//0x10 - 0x14
  40.     int contents;//0x14 - 0x18
  41.     const char *material;//0x18 - 0x1C
  42.     TraceHitType hitType;//0x1C - 0x20
  43.     unsigned __int16 hitId; //0x20 - 0x22
  44.     unsigned __int16 modelIndex;//0x22 - 0x24
  45.     unsigned __int16 partName;//0x24 - 0x26
  46.     unsigned __int16 partGroup;//0x26 - 0x38
  47.     bool allsolid;//0x28 - 0x29
  48.     bool startsolid;//0x29 - 0x2A
  49.     bool walkable;//0x2A-0x2B
  50. };
  51.  
  52. void bulletTrace(BulletTraceType *Type, float *start, float *end, int hitEntity, int ignoreEnt)
  53. {
  54.     trace_t result;
  55.     G_LocationalTrace(&result, start, end, !hitEntity ? 0x7FF : hitEntity, !ignoreEnt ? 0x806831 : 0x2806831, 0);
  56.     for(int i = 0;i < 3;i ++)
  57.         Type->position[i] = (((end[i] - start[i]) * result.fraction) + start[i]);
  58.     unsigned short hitid = Trace_GetEntityHitId(&result) & 0xFFFF;
  59.     if(hitid & 0x7FE || hitid & 0x7FF)
  60.         Type->entityid = hitid;
  61.     else
  62.         Type->entityid = gEntity(hitid);
  63.     if(result.fraction >= 1)
  64.     {
  65.         int r10, r11 = result.surfaceFlags;
  66.         __asm srawi     r10, r11, 0x14
  67.         Type->surfaceFlag = Com_SurfaceTypeToName(r10 &= 0xF8000000);
  68.     }
  69.     float f12;
  70.     if(-sqrt((((end[0] - start[0]) * (end[0] - start[0])) + (((end[2] - start[2]) * (end[2] - start[2])) + ((end[1] - start[1]) * (end[1] - start[1]))))) >= 0 ||
  71.     -sqrt((((end[0] - start[0]) * (end[0] - start[0])) + (((end[2] - start[2]) * (end[2] - start[2])) + ((end[1] - start[1]) * (end[1] - start[1]))))) == 0)
  72.         f12 = 1;
  73.     else if(-sqrt((((end[0] - start[0]) * (end[0] - start[0])) + (((end[2] - start[2]) * (end[2] - start[2])) + ((end[1] - start[1]) * (end[1] - start[1]))))) <= 0)
  74.         f12 = sqrt((((end[0] - start[0]) * (end[0] - start[0])) + (((end[2] - start[2]) * (end[2] - start[2])) + ((end[1] - start[1]) * (end[1] - start[1])))));
  75.     float f9 = ((1 / f12) * (end[0] - start[0]));
  76.     float f7 = ((end[1] - start[1]) * (1 / f12));
  77.     float f6 = ((end[2] - start[2]) * (1 / f12));
  78.     float Normal[3] = { f9, f7, f6 };
  79.     for(int i = 0;i < 3;i++)
  80.         result.normal[i] = Normal[i];
  81.     Type->hitType = result.hitType;
  82.     Type->entity = gEntity(hitid);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement