-
Notifications
You must be signed in to change notification settings - Fork 3
/
mapUtil.cpp
179 lines (169 loc) · 3.66 KB
/
mapUtil.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "stdafx.h"
#include "direct.h"
extern "C" void mapUtilInit(lua_State*L);
/*
Mode
0=wb
1=rb
2=r+b
CodeType
0x13=MapEncoding
*/
bool (__cdecl *cryptOpen)(const char *Filename,int Mode,int CodeType);
void (__cdecl *cryptClose)();
int (__cdecl *fileReadWrite)(void *DstBuf, size_t DstSize);
int (__cdecl *genWriteMapMB)(char *Path,int Type);
char *(__cdecl *getGameFolder)();
void **noxWallGlobalList=(void**)0x0075396C;
/*
Ôîðìàò ôàéëà:
DWORD Sign;//FADEFACE
DWORD Crc;
DWORD Var1;
DWORD Var2;
çàòåì ðàçäåëû
Section
{
byte NameLen;
byte Name[];
DWORD SectionCrcORSize;
}
*/
namespace
{
/*
Òåñòîâûå ôóíêöèè äëÿ øèôðîâàíèÿ ôàéëîâ
int mapDecode(lua_State*L)
{
lua_settop(L,2);
if (
lua_type(L,1)!=LUA_TSTRING ||
(lua_type(L,2)!=LUA_TSTRING)
)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
FILE *G=fopen(lua_tostring(L,1),"rb");
if (G==NULL)
{
lua_pushstring(L,"mapDecode: unable to open src file!");
lua_error_(L);
}
fseek(G,0,SEEK_END);
int FileSize=ftell(G);
fclose(G);
if (!cryptOpen(lua_tostring(L,1),1,0x13))
{
lua_pushstring(L,"mapDecode: unable to open src file!");
lua_error_(L);
}
FILE *F=fopen(lua_tostring(L,2),"wb");
if (F==NULL)
{
lua_pushstring(L,"mapDecode: unable to open src file!");
lua_error_(L);
}
int Remain=FileSize;
int X;
const int BufSize=1024;
char Buf[BufSize]={0};
while(Remain>0)
{
int BlockSize=Remain>BufSize?BufSize:Remain;
if (0==fileReadWrite(Buf,BlockSize))
{
lua_pushstring(L,"mapDecode: read error!");
lua_error_(L);
}
fwrite(Buf,BlockSize,1,F);
Remain-=BlockSize;
}
fclose(F);
cryptClose();
return 0;
}
int mapEncode(lua_State*L)
{
lua_settop(L,2);
if (
lua_type(L,1)!=LUA_TSTRING ||
(lua_type(L,2)!=LUA_TSTRING)
)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
FILE *F=fopen(lua_tostring(L,1),"rb");
if (F==NULL)
{
lua_pushstring(L,"mapEncode: unable to open src file!");
lua_error_(L);
}
if (!cryptOpen(lua_tostring(L,2),0,0x13))
{
lua_pushstring(L,"mapEncode: unable to open dst file!");
lua_error_(L);
}
fseek(F,0,SEEK_END);
int FileSize=ftell(F);
fseek(F,0,SEEK_SET);
int Remain=FileSize;
int X;
const int BufSize=1024;
char Buf[BufSize]={0};
while(Remain>0)
{
int BlockSize=Remain>BufSize?BufSize:Remain;
if (1!=fread(Buf,BlockSize,1,F))
{
lua_pushstring(L,"mapEncode: write error!");
lua_error_(L);
}
if (0==fileReadWrite(Buf,BlockSize))
{
lua_pushstring(L,"mapEncode: write error!");
lua_error_(L);
}
Remain-=BlockSize;
}
fclose(F);
cryptClose();
return 0;
}
*/
int mapSave(lua_State*L)
{
lua_settop(L,1);
if (
lua_type(L,1)!=LUA_TSTRING
)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
char Buf[60];
sprintf(Buf,"%s\\Maps\\%s",getGameFolder(),lua_tostring(L,1));
_mkdir(Buf);
sprintf(Buf,"%s\\Maps\\%s\\%s.map",getGameFolder(),lua_tostring(L,1),lua_tostring(L,1));
wallRec *Wall=*((wallRec**)(noxWallGlobalList));
*noxWallGlobalList=(void*)0;
lua_pushboolean(L,genWriteMapMB(Buf,1));
*noxWallGlobalList=(wallRec*)Wall;
return 1;
}
}
void mapUtilInit(lua_State*L)
{
ASSIGN(cryptOpen,0x00426910);
ASSIGN(cryptClose,0x004269F0);
ASSIGN(fileReadWrite,0x00426AC0);
ASSIGN(genWriteMapMB,0x0051E010);
ASSIGN(getGameFolder,0x00409E10);
/* lua_pushcfunction(L,&mapDecode);
lua_setglobal(L,"mapDecode");
lua_pushcfunction(L,&mapEncode);
lua_setglobal(L,"mapEncode");
*/
registerserver("mapSave",&mapSave);
}