-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnatives.hpp
108 lines (89 loc) · 1.98 KB
/
natives.hpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* The original code is copyright (c) 2022, open.mp team and contributors.
*/
// Include pawn-natives macros (`SCRIPT_API`) and lookups (`IPlayer&`).
#include <Server/Components/Pawn/pawn_natives.hpp>
// To get the component.
#include "weather-component.hpp"
// Various methods of lookup up a parameter by ID to return a pointer to the native.
namespace pawn_natives
{
template <>
struct ParamLookup<IWeatherRegion>
{
static IWeatherRegion& ValReq(cell ref)
{
if (auto pool = WeatherComponent::getInstance())
{
auto ptr = pool->getWeatherRegion(ref);
if (ptr)
{
return *ptr;
}
}
throw pawn_natives::ParamCastFailure();
}
static IWeatherRegion* Val(cell ref) noexcept
{
if (auto pool = WeatherComponent::getInstance())
{
return pool->getWeatherRegion(ref);
}
return nullptr;
}
};
template <>
class ParamCast<IWeatherRegion*>
{
public:
ParamCast(AMX* amx, cell* params, int idx) noexcept
{
value_ = ParamLookup<IWeatherRegion>::Val(params[idx]);
}
~ParamCast()
{
}
ParamCast(ParamCast<IWeatherRegion*> const&) = delete;
ParamCast(ParamCast<IWeatherRegion*>&&) = delete;
operator IWeatherRegion* ()
{
return value_;
}
static constexpr int Size = 1;
private:
IWeatherRegion* value_;
};
template <>
class ParamCast<IWeatherRegion&>
{
public:
ParamCast(AMX* amx, cell* params, int idx)
: value_(ParamLookup<IWeatherRegion>::ValReq(params[idx]))
{
}
~ParamCast()
{
}
ParamCast(ParamCast<IWeatherRegion&> const&) = delete;
ParamCast(ParamCast<IWeatherRegion&>&&) = delete;
operator IWeatherRegion& ()
{
return value_;
}
static constexpr int Size = 1;
private:
IWeatherRegion& value_;
};
template <>
class ParamCast<const IWeatherRegion&>
{
public:
ParamCast(AMX*, cell*, int) = delete;
ParamCast() = delete;
};
}