-
Notifications
You must be signed in to change notification settings - Fork 3
/
polygon.cpp
110 lines (92 loc) · 2.61 KB
/
polygon.cpp
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
108
109
110
#include "stdafx.h"
polygon_s *(__cdecl *noxPolygonGetByIdx) (int Idx);
polygonAngle_s *(__cdecl *noxPolygonAngleGetByNum) (int Idx);
int *noxNextPolygonIdx;
int *noxNextPolygonAngleNum;
namespace
{
int polygonGetByIdxL(lua_State *L)
{
if (lua_type(L,1)!=LUA_TNUMBER)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
int idx=lua_tointeger(L,1);
if (idx>*noxNextPolygonIdx-1)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
lua_pushlightuserdata(L,(void*)noxPolygonGetByIdx(idx));
return 1;
}
int polygonInfoL(lua_State *L)
{
if (lua_type(L,1)!=LUA_TLIGHTUSERDATA)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
polygon_s *P=(polygon_s*)lua_touserdata(L,1);
lua_newtable(L);
lua_pushinteger(L,P->polygonIdx);
lua_setfield(L,-2,"idx");
lua_pushinteger(L,P->posX1);
lua_setfield(L,-2,"posX1");
lua_pushinteger(L,P->posX2);
lua_setfield(L,-2,"posX2");
lua_pushinteger(L,P->posY1);
lua_setfield(L,-2,"posY1");
lua_pushinteger(L,P->posY2);
lua_setfield(L,-2,"posY2");
lua_pushstring(L,P->Name);
lua_setfield(L,-2,"name");
lua_pushinteger(L,P->color);
lua_setfield(L,-2,"color");
lua_pushinteger(L,P->kolvoUglov);
lua_setfield(L,-2,"kolvoUglov");
lua_pushinteger(L,P->minimapGroup);
lua_setfield(L,-2,"minimapGroup");
BYTE *A=(BYTE*)P->strucCoordinat;
lua_newtable(L);
int i=0;
for (;i<P->kolvoUglov;i++)
{
lua_newtable(L);
polygonAngle_s *Ang=noxPolygonAngleGetByNum(*(A+i*4));
lua_pushinteger(L,Ang->numAngle);
lua_rawseti(L,-2,1);
lua_pushinteger(L,Ang->posX);
lua_rawseti(L,-2,2);
lua_pushinteger(L,Ang->posY);
lua_rawseti(L,-2,3);
lua_rawseti(L,-2,(P->kolvoUglov)-i);
}
lua_setfield(L,-2,"tCord");
return 1;
}
int polygonSetAttrL(lua_State*L)
{
if (lua_type(L,1)!=LUA_TLIGHTUSERDATA || lua_type(L,2)!=LUA_TTABLE)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
polygon_s *P=(polygon_s *) lua_touserdata(L,1);
lua_getfield(L,2,"name");
if (lua_type(L,-1)==LUA_TSTRING)
conPrintI(lua_tostring(L,-1));
return 0;
}
}
void polygonInit()
{
ASSIGN(noxPolygonGetByIdx,0x004214A0); // ôóíêöèè
ASSIGN(noxPolygonAngleGetByNum,0x00421030);
ASSIGN(noxNextPolygonIdx,0x00595BC0); // ïåðåìåííûå // ñîäåðæèò èäêñ ñëåäóþùåãî (åùå íå ñóùåñòâóþùåãî ïîëèãîíà)
ASSIGN(noxNextPolygonAngleNum,0x00595BC4); // íîìåð ñëåäóþùåãî óãëà
registerserver("polygonInfo",&polygonInfoL);
registerserver("polygonGetByIdx",&polygonGetByIdxL);
registerserver("polygonSetAttr",&polygonSetAttrL);
}