-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatman.cpp
More file actions
487 lines (446 loc) · 12.8 KB
/
datman.cpp
File metadata and controls
487 lines (446 loc) · 12.8 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/***********************************************************************
*Copyright (c)2005 , 东莞步步高教育电子分公司
*All rights reserved.
**
文件名称: comOut.c
*文件标识: 步步高电子词典的游戏引擎模块
*摘要: 游戏数据管理模块
**
*移植性声明:
* 1、符合标准:《游戏设计标准V1.0》
* 2、兼容模式:本程序和界面无关,无兼容模式。
*修改历史:
* 版本 日期 作者 改动内容和原因
* ----------------------------------------------------
* 1.0 2005.5.16 高国军 基本的功能完成
***********************************************************************/
#include "stdsys.h"
#include "comm.h"
#include "enghead.h"
U8 libByte[300000+1];
U8 fontByte[163840+1];
U8 rlbByte[50000000+1];
U8 VS_PTR[15360+1];
U8 SHARE_MEM[8000000+1];//2097152+1];
U8 FIGHTERS_IDX[30+1];
U8 FIGHTERS[300+1];
U8 ORDERQUEUE[1200+1];
//全局按键码变量
int g_keyCode;
int g_keyCodeList[100];
int g_keyCodeListMax = 0;
int g_timerTick;
//图片模式
int g_showPicType = 0;//0-原版黑白 1-彩色 2-灰度
int g_stat;//用于选择的值(触屏用)
int libReaded = 0;
int rlbReaded = 0;
/*ng=0//choiceshow
ng=1//新游戏选择历史时期界面
ng=2//读档界面
ng=3//读入存档
nga=1//选择君主界面
ng=10 关于界面
ngb=1 ngsave=0 ngc=0主地图界面
flagwar = 1 战斗
flagshowskill= 1战斗技能菜单
flagmenuhero=1 hero菜单
flagmenushow=1
flagmenuspeed=1
flagmenumov=1
flagmenu=1战斗主菜单
ngc=1 escmenu
ngc=2 ngsecond1=0 citymenu
ngc=3 显示城市状态
ngsave=1 存档界面
ngc=2 ngsecond1=1 ngthird1 == 0 内政菜单
ngc=2 ngsecond1=2 ngthird1 == 0 外交菜单
ngc=2 ngsecond1=3 ngthird1 == 0 军备菜单
ngthird1 >0 武将列表
flagstat 战斗状态显示*/
int ng=0;//用于状态(触屏用)
int nga=0;
int ngb=0;
int ngc=0;
int ngsave=0;
int ngsecond1=0;
int ngthird1=0;
int flagwar=0;
int flagstat=0;
int ngthird2=0;
int ngthird3=0;
int ngthird4=0;
int ngf=0;//flagshowskill;//战斗技能菜单ngf2
int operateflag=0;
//int flagmenuhero;//hero菜单ngf3
//int flagmenushow;//=1ngf4
//int flagmenuspeed;//=1ngf5
//int flagmenumov;//=1ngf6
//int flagmenu;//=1战斗主菜单ngf1
/*本体函数声明*/
int g_ResId;
int g_PicId;
int g_PicStyle;
extern int g_StoredResId[1500];
extern int g_StoredPicId[1500];
extern int g_StoredPicStyle[1500];
extern int g_StoredMax;
/*------------------------------------------*/
U32 GetResStartAddr(U16 id);
U16 GetResItem(U32 addr,U8 idx,RCHEAD *reshead,RIDX *rIdx);
void ExpDataWithKey(U8 *ptr,U8 key,U16 len);
U32 GetResStartAddrRlb(U16 id);
/***********************************************************************
* 说明: 获取指定资源项的数据长度
* 输入参数: ResId-资源id idx-目标在资源队列中的序号
* 返回值 : 资源项的数据长度
* 修改历史:
* 姓名 日期 说明
* ------ ---------- -------------
* 高国军 2005.5.18 完成基本功能
***********************************************************************/
U16 ResGetItemLen(U16 ResId,U8 idx)
{
U32 addr;
RIDX rIdx;
RCHEAD reshead;
addr=GetResStartAddr(ResId);
if(addr==0)
return 0;
return GetResItem(addr,idx,&reshead,&rIdx);
}
/***********************************************************************
* 说明: 将指定的资源载入到内存中
* 输入参数: ResId-资源id idx-目标在资源队列中的序号
* : ptr-内存指针
* 返回值 : 无
* 修改历史:
* 姓名 日期 说明
* ------ ---------- -------------
* 高国军 2005.5.18 完成基本功能
***********************************************************************/
U8 ResLoadToMem(U16 ResId,U8 idx,U8 *ptr)
{
if(g_showPicType == 0)
{
/*if(ResId == IFACE_STRID||ResId == IFACE_CONID)
{
ResStringLoadToMem(ResId,idx,ptr);
}
else*/
{
ResLoadToMemOld(ResId,(U8)idx,ptr);
}
}
else //if(g_showPicType == 1)
{
/*if(ResId == IFACE_STRID||ResId == IFACE_CONID)
{
ResStringLoadToMem(ResId,idx,ptr);
}
else*/
{
ResLoadToMemOld(ResId,(U8)idx,ptr);
}
}
}
/* U8 ResStringLoadToMem(U16 ResId,const U8 *idx,U8 *ptr)
{
memcpy((char *)ptr,(char *)idx,g_tlen);
return 0;
}*/
U8 ResLoadToMemNew(U16 ResId,U8 idx,U8 *ptr)//用于加载qrc图片
{
//char resname[100+1];
//sprintf(resname,"pic_%03d",(int)ResId);
//ptr = (U8*)resname;
U16 plen;
U32 addr;
RIDX rIdx;
RCHEAD reshead;
addr=GetResStartAddr(ResId);
if(addr==0)
return 1;
GetResItem(addr,idx,&reshead,&rIdx);
addr+=rIdx.offset;
plen = rIdx.rlen;
gam_fseek(g_LibFp,addr,SEEK_SET);
gam_fread(ptr,1,plen,g_LibFp);
ptr[plen] = 0;
if(reshead.ResKey)
ExpDataWithKey(ptr,reshead.ResKey,plen);
return 0;
}
U8 ResLoadToMemOld(U16 ResId,U8 idx,U8 *ptr)
{
U16 plen;
U32 addr;
RIDX rIdx;
RCHEAD reshead;
addr=GetResStartAddr(ResId);
if(addr==0)
return 1;
GetResItem(addr,idx,&reshead,&rIdx);
addr+=rIdx.offset;
plen = rIdx.rlen;
gam_fseek(g_LibFp,addr,SEEK_SET);
gam_fread(ptr,1,plen,g_LibFp);
ptr[plen] = 0;
if(reshead.ResKey)
ExpDataWithKey(ptr,reshead.ResKey,plen);
return 0;
}
/***********************************************************************
* 说明: 将指定的资源载入到常量页面(没有常量页的系统用堆来模拟)
* 输入参数: ResId-资源id idx-目标在资源队列中的序号
* 返回值 : 资源被载入后的指针(NULL为载入失败)
* 修改历史:
* 姓名 日期 说明
* ------ ---------- -------------
* 高国军 2005.5.18 完成基本功能
***********************************************************************/
U8 *ResLoadToCon(U16 ResId,U8 idx,U8 *cbnk)
{
if(g_showPicType == 0)
{
/*if(ResId == IFACE_STRID||ResId == IFACE_CONID)
{
return ResLoadToCon(ResId,idx,cbnk);
}
else*/
{
return ResLoadToConOld(ResId,(U8)idx,cbnk);
}
}
else //if(g_showPicType == 1)
{
/*if(ResId == IFACE_STRID||ResId == IFACE_CONID)
{
return ResLoadToCon(ResId,idx,cbnk);
}
else*/
{
//61 /* 武将资源 */
//62 /* 武将名称一 */
//70 /* 武将名称二 */
//71 /* 武将名称三 */
//72 /* 武将名称四 */
//57 /* 城市资源 */
//58 /* 城市名称 */
//73 /* 道具名称 */
//66 /* 道具资源 */
//GENERAL_CON 63 /* 武将出现条件 */
//GOODS_CON 67 /* 道具出现条件 */
if(ResId == 1 ||ResId == 2 ||ResId == 10 ||ResId == 11 ||ResId == 12
||ResId == 13 ||ResId == 14 ||ResId == 57 ||ResId == 58 ||ResId == 59
||ResId == 60 ||ResId == 61 ||ResId == 62 ||ResId == 63 ||ResId == 64
||ResId == 65 ||ResId == 66 ||ResId == 67 ||ResId == 68 ||ResId == 70
||ResId == 71 ||ResId == 72 ||ResId == 73 ||ResId == 74 ||ResId == 80
||ResId == 110 ||ResId == 111 ||ResId == 112 ||ResId == 113
||ResId == 114 ||ResId == 115 ||ResId == 116 )
{
return ResLoadToConOld(ResId,(U8)idx,cbnk);
}
else
{
return ResLoadToConNew(ResId,(U8)idx,g_CBnkPtr2);//cbnk);
}
}
}
}
/*U8 *ResConstLoadToCon(U16 ResId,const U8 *idx,U8 *cbnk)
{
//strcpy((char *)cbnk,(char *)idx);
return (U8 *)idx;
}*/
U8 *ResLoadToConNew(U16 ResId,U8 idx,U8 *cbnk)//用于加载qrc图片
{
// resname[100+1];
//sprintf(resname,"pic_%03d",(int)ResId);
//return (U8*)resname;
U8 * ptr;
U16 tmp;
U32 addr;
RCHEAD *reshead;
if(!idx)
return (U8 *) NULL;
idx-=1;
//DebugTime(41);
addr=GetResStartAddrRlb(ResId);
if(addr==0)
return (U8 *) NULL;
//DebugTime(42);
//20180226记录资源序号
g_ResId = ResId;
g_PicId = idx;
if(rlbReaded == 0)
{
ptr=gam_fload(cbnk,addr,g_RlbFp);
rlbReaded = 1;
}
else
{
ptr=gam_fload_mem(cbnk,addr,g_RlbFp);
}
//DebugTime(43);
reshead=(RCHEAD *)ptr;
if(reshead->ItmCnt<idx || reshead->ResKey!=0)
return (U8 *) NULL;
if(reshead->ItmLen!=0)
{
ptr+=sizeof(RCHEAD);
ptr+=idx*reshead->ItmLen;
}
else
{
if(reshead->ItmCnt==1)
ptr+=sizeof(RCHEAD);
else
{
tmp=idx;
tmp<<=2;
tmp+=sizeof(RCHEAD);
ptr+=(U16) *((U16*)(ptr+tmp));
}
}
//DebugTime(44);
return ptr;
}
U8 *ResLoadToConOld(U16 ResId,U8 idx,U8 *cbnk)
{
U8 * ptr;
U16 tmp;
U32 addr;
RCHEAD *reshead;
if(!idx)
return (U8 *) NULL;
idx-=1;
addr=GetResStartAddr(ResId);
if(addr==0)
return (U8 *) NULL;
//20180226记录资源序号
g_ResId = ResId;
g_PicId = idx;
//20180316检测是否存在资源,如果已经存在,不再进行重复load
/*int picStored = 0;
for(int t_i = 0; t_i < g_StoredMax ; t_i ++)
{
if(g_ResId == g_StoredResId[t_i] && g_PicId == g_StoredPicId[t_i] && g_PicStyle == g_StoredPicStyle[t_i])
{
picStored = t_i;
break;
}
}
if(picStored>0)
{
return NULL;
}*/
if(libReaded == 0)
{
ptr=gam_fload(cbnk,addr,g_LibFp);
libReaded = 1;
}
else
{
ptr=gam_fload_mem(cbnk,addr,g_LibFp);
}
reshead=(RCHEAD *)ptr;
if(reshead->ItmCnt<idx || reshead->ResKey!=0)
return (U8 *) NULL;
if(reshead->ItmLen!=0)
{
ptr+=sizeof(RCHEAD);
ptr+=idx*reshead->ItmLen;
}
else
{
if(reshead->ItmCnt==1)
ptr+=sizeof(RCHEAD);
else
{
tmp=idx;
tmp<<=2;
tmp+=sizeof(RCHEAD);
ptr+=(U16) *((U16*)(ptr+tmp));
}
}
return ptr;
}
/***********************************************************************
* 说明: 将被加密的数据解密
* 输入参数: id-资源id
* 返回值 : 无
* 修改历史:
* 姓名 日期 说明
* ------ ---------- -------------
* 高国军 2005.5.18 完成基本功能
***********************************************************************/
void ExpDataWithKey(U8 *ptr,U8 key,U16 len)
{
U16 i;
for(i=0;i<len;i++)
ptr[i]-=key;
}
/***********************************************************************
* 说明: 获取指定的资源项
* 输入参数: addr-资源起始地址 idx-目标在资源队列中的序号
* : reshead-资源头 rIdx-资源项索引
* 返回值 : 资源项数据长度
* 修改历史:
* 姓名 日期 说明
* ------ ---------- -------------
* 高国军 2005.5.18 完成基本功能
***********************************************************************/
U16 GetResItem(U32 addr,U8 idx,RCHEAD *reshead,RIDX *rIdx)
{
gam_fseek(g_LibFp,addr,SEEK_SET);
gam_fread((U8*)reshead,sizeof(RCHEAD),1,g_LibFp);
if(reshead->ItmLen!=0)
{
rIdx->offset = idx - 1;
rIdx->offset *= reshead->ItmLen;
rIdx->offset += sizeof(RCHEAD);
rIdx->rlen=(U16)(reshead->ItmLen);
}
else
{
addr=idx-1;
addr<<=2;
gam_fseek(g_LibFp,addr,SEEK_CUR);
gam_fread((U8 *)rIdx,sizeof(RIDX),1,g_LibFp);
}
return rIdx->rlen;
}
/***********************************************************************
* 说明: 获取指定资源的数据起始地址
* 输入参数: id-资源id
* 返回值 : 资源地址
* 修改历史:
* 姓名 日期 说明
* ------ ---------- -------------
* 高国军 2005.5.18 完成基本功能
***********************************************************************/
U32 GetResStartAddr(U16 id)
{
U32 addr;
if(id==0) return (U32)0;
/* 获取资源的索引地址 addr=(id-1)*4 */
addr=id-1;
addr<<=2;
/* 获取资源索引(实际就是资源存储的数据地址)*/
gam_fseek(g_LibFp,addr,SEEK_SET);
gam_fread((U8*)&addr,4,1,g_LibFp);
return addr;
}
U32 GetResStartAddrRlb(U16 id)
{
U32 addr;
if(id==0) return (U32)0;
/* 获取资源的索引地址 addr=(id-1)*4 */
addr=id-1;
addr<<=2;
/* 获取资源索引(实际就是资源存储的数据地址)*/
gam_fseek(g_RlbFp,addr,SEEK_SET);
gam_fread((U8*)&addr,4,1,g_RlbFp);
return addr;
}