summaryrefslogtreecommitdiff
path: root/cheat/gmod/c_base_weapon.cpp
blob: 94c5ec696cff13cdbd729f3eebeabf8a6e89bc07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "c_base_weapon.hpp"
#include "context.hpp"
#include "base_cheat.hpp"

void* c_base_weapon::get_wpn_data( ) {
	static auto func = pattern::first_code_match< void*( __thiscall* )( void* ) >( g_gmod.m_chl.dll( ), "0F B7 81 ? ? ? ? 50 E8 ? ? ? ? 83 C4 04 C3" );

	if ( func )
		return func( this );

	return nullptr;
}

bool c_base_weapon::is_cw20( ) {
	if( !g_ctx.m_lua )
		return false;

	const auto lua = g_ctx.m_lua;

	this->ce( )->PushEntity( );
	if( !lua->IsType( -1, LUA_TYPE::TYPE_ENTITY ) ) {
		lua->Pop( 2 );
		return false;
	}

	lua->GetField( -1, xors( "CW20Weapon" ) );
	if( !lua->IsType( -1, LUA_TYPE::TYPE_BOOL ) ) {
		lua->Pop( 2 );
		return false;
	}

	bool is_cw20 = lua->GetBool( -1 );

	lua->Pop( 2 );

	return is_cw20;
}

bool c_base_weapon::is_fas2( ) {
	if( !g_ctx.m_lua )
		return false;

	const auto lua = g_ctx.m_lua;

	this->ce( )->PushEntity( );
	if( !lua->IsType( -1, LUA_TYPE::TYPE_ENTITY ) ) {
		lua->Pop( 2 );
		return false;
	}

	lua->GetField( -1, xors( "IsFAS2Weapon" ) );
	if( !lua->IsType( -1, LUA_TYPE::TYPE_BOOL ) ) {
		lua->Pop( 2 );
		return false;
	}

	bool is_fas2 = lua->GetBool( -1 );

	lua->Pop( 2 );

	return is_fas2;
}

float c_base_weapon::get_custom_cone( ) {
	if( !g_ctx.m_lua )
		return 0.f;

	const auto lua = g_ctx.m_lua;

	this->ce( )->PushEntity( ); // thank god for this function.
	if( !lua->IsType( -1, LUA_TYPE::TYPE_ENTITY ) ) {
		lua->Pop( 2 );
		return false;
	}

	lua->GetField( -1, xors( "CurCone" ) );
	if( !lua->IsType( -1, LUA_TYPE::TYPE_NUMBER ) ) {
		lua->Pop( 2 );
		return false;
	}

	float cone = lua->GetNumber( -1 );

	lua->Pop( 2 );

	return cone;
}