Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Scr_BulletTrace fully reversed!
- //Credits to Xx James t xX for the BulletTraceType as it is much easier with it
- //Example on how to use it:
- /*
- BulletTraceType Type;
- float start[3] = { 123, 435, 642 },
- end[3] = { 130, 450, 642 };
- int Client = 3;
- bulletTrace(&Type, start, end, Client, true);
- if(!strcmp(Type.surfaceType, "default"))
- setOrigin(Type.entity, Type.position);
- */
- typedef struct BulletTraceType
- {
- short entityid;
- float position[3];
- TraceHitType hitType;
- char *surfaceFlag;
- int entity;
- };
- typedef enum TraceHitType
- {
- TRACE_HITTYPE_NONE,
- TRACE_HITTYPE_ENTITY,
- TRACE_HITTYPE_DYNENT_MODEL,
- TRACE_HITTYPE_DYNENT_BRUSH,
- TRACE_HITTYPE_UNKNOWN
- };
- typedef struct trace_t
- {
- float fraction;//0x00 - 0x04
- float normal[3];//0x04 - 0x10
- int surfaceFlags;//0x10 - 0x14
- int contents;//0x14 - 0x18
- const char *material;//0x18 - 0x1C
- TraceHitType hitType;//0x1C - 0x20
- unsigned __int16 hitId; //0x20 - 0x22
- unsigned __int16 modelIndex;//0x22 - 0x24
- unsigned __int16 partName;//0x24 - 0x26
- unsigned __int16 partGroup;//0x26 - 0x38
- bool allsolid;//0x28 - 0x29
- bool startsolid;//0x29 - 0x2A
- bool walkable;//0x2A-0x2B
- };
- void bulletTrace(BulletTraceType *Type, float *start, float *end, int hitEntity, int ignoreEnt)
- {
- trace_t result;
- G_LocationalTrace(&result, start, end, !hitEntity ? 0x7FF : hitEntity, !ignoreEnt ? 0x806831 : 0x2806831, 0);
- for(int i = 0;i < 3;i ++)
- Type->position[i] = (((end[i] - start[i]) * result.fraction) + start[i]);
- unsigned short hitid = Trace_GetEntityHitId(&result) & 0xFFFF;
- if(hitid & 0x7FE || hitid & 0x7FF)
- Type->entityid = hitid;
- else
- Type->entityid = gEntity(hitid);
- if(result.fraction >= 1)
- {
- int r10, r11 = result.surfaceFlags;
- __asm srawi r10, r11, 0x14
- Type->surfaceFlag = Com_SurfaceTypeToName(r10 &= 0xF8000000);
- }
- float f12;
- 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 ||
- -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)
- f12 = 1;
- 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)
- 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])))));
- float f9 = ((1 / f12) * (end[0] - start[0]));
- float f7 = ((end[1] - start[1]) * (1 / f12));
- float f6 = ((end[2] - start[2]) * (1 / f12));
- float Normal[3] = { f9, f7, f6 };
- for(int i = 0;i < 3;i++)
- result.normal[i] = Normal[i];
- Type->hitType = result.hitType;
- Type->entity = gEntity(hitid);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement