-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGameFunc.cpp
More file actions
1494 lines (1380 loc) · 43.7 KB
/
GameFunc.cpp
File metadata and controls
1494 lines (1380 loc) · 43.7 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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "ext.h"
#include "Game.h"
// parts
// CGame::xxx > Funcsions
void CGame::GenerateDatMsg(WCHAR* msglog, BYTE* data, WORD size)
{
int nMsgIndex = 0;
int nBuf = MAX_MSG_BUFFER;
for (int i=0;i<size;i++)
{
_itow_s((int)data[i], &msglog[nMsgIndex], nBuf, 16);
if (data[i] < 16)
msglog[nMsgIndex+1] = L' ';
msglog[nMsgIndex+2] = L' ';
nMsgIndex+=3;
nBuf-=3;
if (size > 1 && nBuf <= 4)
{
msglog[nMsgIndex] = L'.';
msglog[nMsgIndex+1] = L'.';
msglog[nMsgIndex+2] = L'\n';
msglog[nMsgIndex+3] = NULL;
return;
}
}
msglog[nMsgIndex] = '\n';
msglog[nMsgIndex+1] = NULL;
}
//> セッションへ送るパケット作成
BOOL CGame::AddPacket(BYTE* data, WORD size)
{
if (!m_nTcpSock || !data || size > MAX_PACKET_SIZE)
return FALSE;
ptype_packet ppkt = NewPacket();
if (!ppkt) return FALSE;
ppkt->cli_sock = m_nTcpSock;
ppkt->session = NULL;
ppkt->size = size;
ZeroMemory(ppkt->data,sizeof(char)*MAX_PACKET_SIZE);
CopyMemory(ppkt->data,data,size);
g_pCriticalSection->EnterCriticalSection_Packet(L'2');
#ifdef _DEBUG
//#if ADD_LOG_PACKET_INFO
if (!g_pPacketQueue->EnqueueRaw(ppkt))
{
AddMessageLog(L"パケットキュー追加失敗");
switch (data[2])
{
case PK_SYN:
AddMessageLog(L"PK_SYN"); break;
case PK_ACK:
AddMessageLog(L"PK_ACK"); break;
case PK_NOOP:
AddMessageLog(L"PK_NOOP"); break;
case PK_USER_AUTH:
AddMessageLog(L"PK_USER_AUTH"); break;
case PK_USER_CHAT:
AddMessageLog(L"PK_USER_CHAT"); break;
case PK_USER_ROOMINFO:
AddMessageLog(L"PK_USER_ROOMINFO"); break;
case PK_USER_LOAD:
AddMessageLog(L"PK_USER_LOAD"); break;
case PK_USER_MAININFO:
AddMessageLog(L"LOG_PK_USER_MAININFO"); break;
case PK_REQ_LOC:
AddMessageLog(L"PK_REQ_LOC"); break;
case PK_CMD_MV:
AddMessageLog(L"PK_CMD_MV"); break;
case PK_CMD_ROOM_CHARA_SEL:
AddMessageLog(L"PK_CMD_ROOM_CHARA_SEL"); break;
case PK_CMD_ROOM_READY:
AddMessageLog(L"PK_CMD_ROOM_READY"); break;
case PK_CMD_ROOM_RULE:
AddMessageLog(L"PK_CMD_ROOM_RULE"); break;
case PK_CMD_ROOM_MV:
AddMessageLog(L"PK_CMD_ROOM_MV"); break;
case PK_CMD_ROOM_ITEM_SEL:
AddMessageLog(L"PK_CMD_ROOM_ITEM_SEL"); break;
case PK_CMD_ROOM_TEAM_COUNT:
AddMessageLog(L"PK_CMD_ROOM_TEAM_COUNT"); break;
case PK_CMD_ROOM_STAGE_SEL:
AddMessageLog(L"PK_CMD_ROOM_STAGE_SEL"); break;
case PK_CMD_LOAD_COMPLETE:
AddMessageLog(L"PK_CMD_LOAD_COMPLETE"); break;
case PK_CMD_MAIN_MV:
AddMessageLog(L"PK_CMD_MAIN_MV\n"); break;
case PK_OBJ_UPDATE_ACT:
AddMessageLog(L"PK_OBJ_UPDATE_ACT"); break;
case PK_OBJ_REMOVE:
AddMessageLog(L"PK_OBJ_REMOVE"); break;
case PK_USER_DISCON:
AddMessageLog(L"PK_USER_DISCON"); break;
}
WCHAR msglog[MAX_MSG_BUFFER*4+1];
GenerateDatMsg(msglog, data, size);
AddMessageLog(msglog);
}
//#endif
#else
g_pPacketQueue->EnqueueRaw(ppkt);
#endif
g_pCriticalSection->LeaveCriticalSection_Packet();
// EnqueuePacket(&m_tQueue, ppkt);
return TRUE;
}
//< セッションへ送るパケット作成
// チャットにメッセージ追加
void CGame::AddChatMessage(WCHAR *msg, E_TYPE_PACKET_CHAT_HEADER chat)
{
HRESULT hr;
if (!p_pUI || !msg) return;
CDXUTColorListBox *pColorListBox = (CDXUTColorListBox*)p_pUI->GetControl(IDC_ROOM_LB_CHATLOG);
if (!pColorListBox) return;
BYTE bytColorElement = 1;
switch (chat)
{
case PK_USER_CHAT_TEAM: // チームへ
bytColorElement = 3;
break;
case PK_USER_CHAT_SERVER_INFO: // サーバから情報
bytColorElement = 4;
AddMessageLog(msg);
break;
case PK_USER_CHAT_SERVER_WARNING: // サーバから注意
bytColorElement = 5;
AddMessageLog(msg);
break;
case PK_USER_CHAT_ALL: // 全員へ
bytColorElement = 2;
break;
case PK_USER_CHAT_WIS:
default:
bytColorElement = 6; // 個人
break;
}
V(pColorListBox->AddItem(msg, NULL, bytColorElement));
(pColorListBox->GetScrollBar())->SetTrackPos(pColorListBox->GetSize());
}
int CGame::AddResourceTexture(WCHAR* path)
{
LPDIRECT3DTEXTURE9 pTex = NULL;
int nImageWidth,nImageHeight;
// リソースマネージャとダイアログにテクスチャを追加
int nNewTextureNodeIndex = g_DialogResourceManager.AddTexture(L"");
p_pUI->SetTexture(nNewTextureNodeIndex, L"");
if (FAILED(LoadTextureFromFiler(path, &pTex, &nImageWidth, &nImageHeight)))
{
return -1;
}
DXUTTextureNode* pTextureNode = g_DialogResourceManager.GetTextureNode(nNewTextureNodeIndex);
SafeRelease(pTextureNode->pTexture);
pTextureNode->pTexture = pTex;
pTextureNode->dwWidth = nImageWidth;
pTextureNode->dwHeight = nImageHeight;
wcscpy_s(pTextureNode->strFilename, MAX_PATH, path);
return nNewTextureNodeIndex;
}
// Login
void CGame::SuccessAuth(BYTE* data)
{
SetUserIndex(data[4]);
SetConnState(CONN_STATE_AUTHED);
SetUserState(OBJ_STATE_ROOM_READY);
m_SessionArray[m_nUserIndex].master = data[9];
m_SessionArray[m_nUserIndex].team_no = data[10];
SetMaxLoginNum(data[11]);
g_nMaxLoginNum = data[11];
memcpy(&m_SessionArray[m_nUserIndex].obj_state, &data[5], sizeof(DWORD));
CreateCharacters();
}
// chat
BYTE CGame::GetChatMessageRange()
{
DXUTComboBoxItem *pItem = ((CDXUTComboBox*)p_pUI->GetControl(IDC_ROOM_CMB_CHAT))->GetSelectedItem();
if (!pItem) return (BYTE)PK_USER_CHAT_NONE;
DWORD pb = (DWORD)pItem->pData;
// CTRLキー押下しているならチームチャットにする
if (GetAsyncKeyState(VK_CONTROL)&0x8000)
return (BYTE)PK_USER_CHAT_TEAM;
// ALTキー押下しているなら全体チャットにする
if (GetAsyncKeyState(VK_MENU)&0x8000)
return (BYTE)PK_USER_CHAT_ALL;
// 発言範囲コンボボックスの選択
switch ((E_TYPE_PACKET_CHAT_HEADER)pb )
{
case PK_USER_CHAT_ALL:
return (BYTE)PK_USER_CHAT_ALL;
case PK_USER_CHAT_TEAM:
return (BYTE)PK_USER_CHAT_TEAM;
default:
return (BYTE)pb; // pDataのユーザIDを返す
// break;
}
return (BYTE)PK_USER_CHAT_NONE;
}
// 切断通知
void CGame::OnDisconnectUser(int nCharaIndex)
{
WCHAR wsName[MAX_USER_NAME+1];
WCHAR wsMessage[MAX_CHAT_MSG+1];
//> チャットログに切断メッセージ追加
common::session::GetSessionName(&m_SessionArray[nCharaIndex], wsName);
SafePrintf(wsMessage, MAX_CHAT_MSG, L"%sさんが切断しました", wsName);
CDXUTListBox* pListBox = (CDXUTListBox*)p_pUI->GetControl(IDC_ROOM_LB_CHATLOG);
AddChatMessage(wsMessage, PK_USER_CHAT_SERVER_WARNING);
AddMessageLog(wsMessage);
//< チャットログに切断メッセージ追加
////////////////////////////
m_SessionArray[nCharaIndex].connect_state = CONN_STATE_EMPTY;
m_nAuthedCount = CalcAuthedUserCount();
switch (m_eGameState)
{
case eGameRoomInit:
case eGameRoom:
case eGameRoomRelease:
m_SessionArray[nCharaIndex].entity = 0;
m_SessionArray[nCharaIndex].game_ready = 0;
m_SessionArray[nCharaIndex].frame_count = 0;
m_SessionArray[nCharaIndex].live_count = 0;
// アバターキャラ削除
m_pRoomCharacters[nCharaIndex]->Destroy();
// ユーザーリスト更新
UpdateUserList(nCharaIndex);
// 個人チャットコンボボックス更新
UpdateWisperList(nCharaIndex);
m_pTeamRulePropertyManager->Update((GetMySessionInfo()->master!=0), m_nTeamCount);
UpdateReadyButtonState();
break;
case eGameLoad:
case eGameLoadInit:
case eGameLoadRelease:
// 既に死んでいる場合は設定しないようにチェック
if (!(m_SessionArray[nCharaIndex].obj_state & OBJ_STATE_MAIN_NOLIVE_FLG))
{
m_SessionArray[nCharaIndex].obj_state = OBJ_STATE_EMPTY;
OnCharaDisconnect(nCharaIndex); // キャラを横たわらせる
}
//> 20110201 部屋に切断したユーザの何かが残っている
// アバターキャラ削除
m_pRoomCharacters[nCharaIndex]->Destroy();
//< 20110201 部屋に切断したユーザの何かが残っている
// ユーザーリスト更新
UpdateUserList(nCharaIndex);
// 個人チャットコンボボックス更新
UpdateWisperList(nCharaIndex);
EraseDisconnectCharacter(nCharaIndex);
break;
case eGameMainInit:
case eGameMain:
case eGameMainRelease:
// 既に死んでいる場合は設定しないようにチェック
if (!(m_SessionArray[nCharaIndex].obj_state & OBJ_STATE_MAIN_NOLIVE_FLG))
{
m_SessionArray[nCharaIndex].obj_state = OBJ_STATE_MAIN_DEAD;
OnCharaDisconnect(nCharaIndex); // キャラを横たわらせる
}
//> 20110201 部屋に切断したユーザの何かが残っている
// アバターキャラ削除
m_pRoomCharacters[nCharaIndex]->Destroy();
//< 20110201 部屋に切断したユーザの何かが残っている
// ユーザーリスト更新
UpdateUserList(nCharaIndex);
// 個人チャットコンボボックス更新
UpdateWisperList(nCharaIndex);
EraseDisconnectCharacter(nCharaIndex);
break;
case eGameResult:
case eGameResultRelease:
//> 20110201 部屋に切断したユーザの何かが残っている
// アバターキャラ削除
m_pRoomCharacters[nCharaIndex]->Destroy();
//< 20110201 部屋に切断したユーザの何かが残っている
m_SessionArray[nCharaIndex].entity = 0;
m_SessionArray[nCharaIndex].game_ready = 0;
m_SessionArray[nCharaIndex].frame_count = 0;
m_SessionArray[nCharaIndex].live_count = 0;
// 個人チャットコンボボックス更新
UpdateWisperList(nCharaIndex);
// ユーザーリスト更新
UpdateUserList(nCharaIndex);
break;
case eGameResultInit:
default:
//> 20110201 部屋に切断したユーザの何かが残っている
// アバターキャラ削除
m_pRoomCharacters[nCharaIndex]->Destroy();
//< 20110201 部屋に切断したユーザの何かが残っている
// 個人チャットコンボボックス更新
UpdateWisperList(nCharaIndex);
// ユーザーリスト更新
UpdateUserList(nCharaIndex);
break;
}
}
BOOL CGame::LoadStageCharacter()
{
m_vecCharacters.clear();
WCHAR loadlog[64];
g_pCriticalSection->EnterCriticalSection_StageTexture(L'\\');
for (int i=0;i<GetMaxLoginNum();i++)
{
if (m_SessionArray[i].obj_state != OBJ_STATE_LOADING)
continue;
// スクリプト関連付け再設定
m_pRoomCharacters[i]->Hide();
// if (!m_pStageCharacters[i]->Create(&m_mapCharaScrInfo, m_nDefaultGUIResourceIndex, p_pUI, &m_SessionArray[i]))
// return FALSE;
if (m_SessionArray[i].team_no != GALLERY_TEAM_NO)
{
m_SessionArray[i].scrinfo = common::scr::FindCharaScrInfoFromCharaType(m_SessionArray[i].chara_type, &m_mapCharaScrInfo);
if (m_pStageCharacters[i]->Create(&m_mapCharaScrInfo, m_nDefaultGUIResourceIndex, p_pUI, &m_SessionArray[i], m_pSelectedStageScrInfo->stage.size.cx, m_pSelectedStageScrInfo->stage.size.cy))
SafePrintf(loadlog, 64, L"stg_chr_load(obj/id):%d/%d", m_SessionArray[i].obj_no, m_SessionArray[i].scrinfo->ID);
else
SafePrintf(loadlog, 64, L"stg_chr_fail(obj/id):%d/%d", m_SessionArray[i].obj_no, m_SessionArray[i].scrinfo->ID);
AddMessageLog(loadlog);
m_vecCharacters.push_back(&m_SessionArray[i]);
}
else
{
if (m_SessionArray[i].chara_type == ROOM_CHARA_RANDOM_ID)
m_SessionArray[i].scrinfo = common::scr::FindCharaScrInfoFromCharaType(m_mapCharaScrInfo[genrand_int32()%m_mapCharaScrInfo.size()].ID, &m_mapCharaScrInfo);
else
m_SessionArray[i].scrinfo = common::scr::FindCharaScrInfoFromCharaType(m_SessionArray[i].chara_type, &m_mapCharaScrInfo);
AddMessageLog(loadlog);
m_SessionArray[i].entity = 0;
}
}
g_pCriticalSection->LeaveCriticalSection_StageTexture();
return TRUE;
}
void CGame::ClearStageObjects()
{
OutputDebugStr(L"ClearStageObjects");
for ( std::map < int, type_obj* >::iterator it = m_mapObjects.begin();
it != m_mapObjects.end();
it++)
{
switch ((*it).second->obj_type)
{
default:
case OBJ_TYPE_CHARA:
{
type_session* sess = (type_session*)((*it).second);
SafeDelete(sess);
break;
}
case OBJ_TYPE_BLT_LIQUID:
case OBJ_TYPE_BLT_SOLID:
case OBJ_TYPE_BLT_GAS:
{
type_blt* blt = (type_blt*)((*it).second);
DEBUG_DELETE(blt, L"ClearStageObjects");
break;
}
case OBJ_TYPE_ITEM_GAS:
case OBJ_TYPE_ITEM_SOLID:
case OBJ_TYPE_ITEM_LIQUID:
{
type_obj* obj = (type_obj*)((*it).second);
DEBUG_DELETE(obj, L"ClearStageObjects");
break;
}
}
}
m_pFocusObject = NULL;
m_mapObjects.clear();
UpdateObjectNo();
}
void CGame::OnLostCharacterScriptTexture()
{
for (std::map<int, TCHARA_SCR_INFO>::iterator it = m_mapCharaScrInfo.begin();
it != m_mapCharaScrInfo.end();
it++)
{
(*it).second.pTexture = NULL;
}
for (int i=0;i<GetMaxLoginNum();i++)
{
if (m_SessionArray[i].entity)
((TCHARA_SCR_INFO*)m_SessionArray[i].scrinfo)->pTexture = NULL;
if (m_pRoomCharacters[i]->IsCreated())
m_pRoomCharacters[i]->OnLost();
if (m_pStageCharacters[i]->IsCreated())
m_pStageCharacters[i]->OnLost();
}
}
void CGame::OnResetCharacterScriptTexture()
{
for (std::map<int, TCHARA_SCR_INFO>::iterator it = m_mapCharaScrInfo.begin();
it != m_mapCharaScrInfo.end();
it++)
{
/*
// テクスチャをリソースに登録
int nScrTextureNodeIndex = AddResourceTexture((*it).second.tex_path);
if (nScrTextureNodeIndex == -1)
{
MessageBox(NULL, L"スクリプトに定義された画像のリセットに失敗しました", L"script or image error", MB_OK);
return;
}
(*it).second.res_index = nScrTextureNodeIndex;
*/
(*it).second.pTexture = g_DialogResourceManager.GetTextureNode((*it).second.res_index)->pTexture;
}
for (int i=0;i<GetMaxLoginNum();i++)
{
if (m_SessionArray[i].entity)
{
TCHARA_SCR_INFO* pCharaScrInfo = common::scr::FindCharaScrInfoFromCharaType(m_SessionArray[i].chara_type, &m_mapCharaScrInfo);
m_SessionArray[i].scrinfo = pCharaScrInfo;
}
if (m_pRoomCharacters[i]->IsCreated())
m_pRoomCharacters[i]->OnReset();
if (m_pStageCharacters[i]->IsCreated())
m_pStageCharacters[i]->OnReset();
}
}
void CGame::OnResetCharacterScriptSound()
{
std::map<int, TBASE_SCR_INFO*> mapLoadedCharacters;
for (std::vector< type_session* >::iterator it = m_vecCharacters.begin();
it != m_vecCharacters.end();
it++)
{
// スクリプトの音声読込み済み確認
if (mapLoadedCharacters.find((*it)->scrinfo->scr_index) != mapLoadedCharacters.end())
continue;
int nScrIndex = (*it)->scrinfo->scr_index;
LuaFuncParam luaParams,luaResults;
luaParams.Number(nScrIndex);
common::scr::CallLuaFunc(g_pLuah, "getChara_SEFilesCount", &luaResults, 1, &luaParams, g_pCriticalSection);
int nSECount = (int)luaResults.GetNumber(0);
WCHAR* wsSEPath;
int wsSEPathLen = 0;
for (int i=0;i<nSECount;i++)
{
luaParams.Clear();
luaResults.Clear();
luaParams.Number(nScrIndex).Number(i);
common::scr::CallLuaFunc(g_pLuah, "getChara_SEFile", &luaResults, 1, &luaParams, g_pCriticalSection);
char csSEPath[_MAX_PATH*2+1];
SafePrintfA(csSEPath, _MAX_PATH*2, luaResults.GetString(0));
if ( !luaResults.GetWString(0, &wsSEPath, &wsSEPathLen) )
{
MessageBox(g_hWnd, wsSEPath, L"lua", MB_OK);
SafeDeleteArray(wsSEPath);
continue;;
}
int nResID = 0;
if ((nResID = m_pScrSoundLibs->AddFromFile(wsSEPath)) == -1)
MessageBox(g_hWnd, wsSEPath, L"Script Sound Load Error", MB_OK);
else
m_mapScrSoundIDHash.insert(std::map<std::string, int>::value_type(csSEPath, nResID));
SafeDeleteArray(wsSEPath);
}
mapLoadedCharacters.insert(std::map<int, TBASE_SCR_INFO* >::value_type( (*it)->scrinfo->scr_index, (*it)->scrinfo ));
}
}
// ステージロードスレッド
DWORD __stdcall CGame::Thread_Loading(LPVOID param)
{
TLoadingParam* pParam = (TLoadingParam*)param;
g_pCriticalSection->EnterCriticalSection_StageTexture(L'!');
BYTE *pStageBuf = NULL;
UINT nStageBufSize;
BYTE *pBGBuf = NULL;
UINT nBGBufSize;
g_pFiler->GetFileMemory(pParam->pStageScrInfo->stage.path, &pStageBuf, &nStageBufSize);
if (!pStageBuf)
{
g_pCriticalSection->LeaveCriticalSection_StageTexture();
MessageBox(g_hWnd, L"ステージ用ファイルロード失敗", L"error", MB_OK);
g_bCloseSocket = TRUE;
return 0;
}
if (g_bKillLoadingThread)
{
SafeDeleteArray(pStageBuf);
g_pCriticalSection->LeaveCriticalSection_StageTexture();
AddMessageLog(L"!ステージ用画像ロード前にDeviceLost");
return 0;
}
if (!pParam->pMainStage->Init(pStageBuf, nStageBufSize, &pParam->pStageScrInfo->stage.size))
{
SafeDeleteArray(pStageBuf);
g_pCriticalSection->LeaveCriticalSection_StageTexture();
MessageBox(g_hWnd, L"ステージ用画像ロード失敗", L"error", MB_OK);
g_bCloseSocket = TRUE;
return 0;
}
SafeDeleteArray(pStageBuf);
if (g_bKillLoadingThread)
{
SafeDeleteArray(pBGBuf);
g_pCriticalSection->LeaveCriticalSection_StageTexture();
AddMessageLog(L"!ステージ用ファイルロード前にDeviceLost");
return 0;
}
g_pFiler->GetFileMemory(pParam->pStageScrInfo->bg.path, &pBGBuf, &nBGBufSize);
if (!pBGBuf)
{
SafeDeleteArray(pStageBuf);
g_pCriticalSection->LeaveCriticalSection_StageTexture();
MessageBox(g_hWnd, L"ステージ用ファイルロード失敗", L"error", MB_OK);
DestroyWindow(g_hWnd);
return 0;
}
if (g_bKillLoadingThread)
{
SafeDeleteArray(pBGBuf);
AddMessageLog(L"!背景ファイルロード後にDeviceLost");
g_pCriticalSection->LeaveCriticalSection_StageTexture();
return 0;
}
AddMessageLog(L">ステージロード");
if (g_nStageLoadType == 1)
{
if (FAILED(D3DXCreateTextureFromFileEx(g_pDevice, pParam->pStageScrInfo->stage.path, 0,0, 1, 0, D3DDEFAULT_FORMAT, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, pParam->ppStageTexture)))
{
MessageBox(NULL, L"ステージテクスチャ作成失敗",L"ステージテクスチャ作成", MB_OK);
Sleep(1);
if (g_bKillLoadingThread)
{
AddMessageLog(L"!ステージロード中にDeviceLost");
g_pCriticalSection->LeaveCriticalSection_StageTexture();
return 0;
}
else
AddMessageLog(L"!ステージテクスチャ作成失敗");
}
}
else
{
if (!(*pParam->ppStageTexture))
{
// while (!TextureLoader::LoadTextureFromFileInMemory(pParam->ppStageTexture, g_pDevice, pBuf, nBufSize, NULL, NULL, 0, D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT))
while (!pParam->pMainStage->CreateTexture(g_pDevice, pParam->ppStageTexture))
{
AddMessageLog(L"(ステージテクスチャ作成失敗)");
Sleep(1);
if (g_bKillLoadingThread)
{
AddMessageLog(L"!ステージロード中にDeviceLost");
g_pCriticalSection->LeaveCriticalSection_StageTexture();
return 0;
}
else
AddMessageLog(L"!ステージテクスチャ作成失敗");
}
}
}
AddMessageLog(L"<ステージロード");
if (g_bKillLoadingThread)
{
SafeDeleteArray(pStageBuf);
SafeDeleteArray(pBGBuf);
AddMessageLog(L"!背景ロード前にDeviceLost");
g_pCriticalSection->LeaveCriticalSection_StageTexture();
return 0;
}
// ステージ背景ロード
// ステージロード
if (!(*pParam->ppStageBGTexture))
{
AddMessageLog(L">背景ロード");
BOOL ret = FALSE;
while (!TextureLoader::LoadTextureFromFileInMemory(pParam->ppStageBGTexture, g_pDevice, pBGBuf, nBGBufSize, NULL, NULL, 0, 1))
// while (!PngLoader::CreateTextureFromFileInMemory(g_pDevice, pBGBuf, nBGBufSize, NULL, NULL, pParam->ppStageBGTexture, D3DPOOL_DEFAULT))
{
AddMessageLog(L">背景ロード失敗");
Sleep(1);
if (g_bKillLoadingThread)
break;
}
SafeDeleteArray(pBGBuf);
}
g_pCriticalSection->LeaveCriticalSection_StageTexture();
AddMessageLog(L"<背景ロード");
g_pCriticalSection->EnterCriticalSection_Session(L'7');
g_pCriticalSection->EnterCriticalSection_Sound(L'4');
AddMessageLog(L">キャラスクリプト音声ロード");
if (pParam->pVecCharacters->empty())
AddMessageLog(L"!Empty:LoadChara");
std::map<int, TBASE_SCR_INFO*> mapLoadedCharacters;
for (std::vector< type_session* >::iterator it = pParam->pVecCharacters->begin();
it != pParam->pVecCharacters->end();
it++)
{
if (g_bKillLoadingThread)
{
AddMessageLog(L"!キャラスクリプト音声ロード中1:DeviceLost");
g_pCriticalSection->LeaveCriticalSection_Sound();
g_pCriticalSection->LeaveCriticalSection_Session();
return 0;
}
// スクリプトの音声読込み済み確認
if (mapLoadedCharacters.find((*it)->scrinfo->ID) != mapLoadedCharacters.end())
continue;
int nScrIndex = (*it)->scrinfo->scr_index;
LuaFuncParam luaParams,luaResults;
luaParams.Number(nScrIndex);
common::scr::CallLuaFunc(g_pLuah, "getChara_SEFilesCount", &luaResults, 1, &luaParams, g_pCriticalSection);
int nSECount = (int)luaResults.GetNumber(0);
WCHAR log[48];
SafePrintf(log, 48, L"scr(%d,%d)_CharaSECount:%d",(*it)->scrinfo->ID, nScrIndex, nSECount);
AddMessageLog(log);
WCHAR* wsSEPath;
int wsSEPathLen = 0;
for (int i=0;i<nSECount;i++)
{
if (g_bKillLoadingThread)
{
AddMessageLog(L"!キャラスクリプト音声ロード中2:DeviceLost");
g_pCriticalSection->LeaveCriticalSection_Sound();
g_pCriticalSection->LeaveCriticalSection_Session();
return 0;
}
luaParams.Clear();
luaResults.Clear();
luaParams.Number(nScrIndex).Number(i);
common::scr::CallLuaFunc(g_pLuah, "getChara_SEFile", &luaResults, 1, &luaParams, g_pCriticalSection);
char csSEPath[MAX_PATH*2+1];
SafePrintfA(csSEPath, MAX_PATH*2, luaResults.GetString(0));
if ( !luaResults.GetWString(0, &wsSEPath, &wsSEPathLen) )
{
AddMessageLog(wsSEPath);
MessageBox(g_hWnd, wsSEPath, L"lua", MB_OK);
SafeDeleteArray(wsSEPath);
continue;
}
int nResID = pParam->pSoundLibs->AddFromFile(wsSEPath);
if (nResID == -1)
{
WCHAR log[64];
SafePrintf(log, 64, L"Script Sound Load Error:%s", wsSEPath);
AddMessageLog(log);
MessageBox(g_hWnd, wsSEPath, L"Script Sound Load Error", MB_OK);
}
else
{
std::string stemp(csSEPath);
pParam->pSoundIDHash->insert(std::map<std::string, int>::value_type(csSEPath, nResID));
}
SafeDeleteArray(wsSEPath);
}
mapLoadedCharacters.insert(std::map<int, TBASE_SCR_INFO* >::value_type( (*it)->scrinfo->ID, (*it)->scrinfo ));
}
AddMessageLog(L"<キャラスクリプト音声ロード>ステージ");
{
int nScrIndex = pParam->pStageScrInfo->scr_index;
LuaFuncParam luaParams,luaResults;
luaParams.Number(nScrIndex);
common::scr::CallLuaFunc(g_pLuah, "getStage_SEFilesCount", &luaResults, 1, &luaParams, g_pCriticalSection);
int nSECount = (int)luaResults.GetNumber(0);
WCHAR log[48];
SafePrintf(log, 48, L"scr_index(%d)_StageSECount:%d", nScrIndex, nSECount);
AddMessageLog(log);
WCHAR* wsSEPath;
int wsSEPathLen = 0;
for (int i=0;i<nSECount;i++)
{
if (g_bKillLoadingThread)
{
AddMessageLog(L"!ステージスクリプト音声ロード中2:DeviceLost");
g_pCriticalSection->LeaveCriticalSection_Sound();
g_pCriticalSection->LeaveCriticalSection_Session();
return 0;
}
luaParams.Clear();
luaResults.Clear();
luaParams.Number(nScrIndex).Number(i);
common::scr::CallLuaFunc(g_pLuah, "getStage_SEFile", &luaResults, 1, &luaParams, g_pCriticalSection);
char csSEPath[MAX_PATH*2+1];
SafePrintfA(csSEPath, MAX_PATH*2, luaResults.GetString(0));
if ( !luaResults.GetWString(0, &wsSEPath, &wsSEPathLen) )
{
AddMessageLog(wsSEPath);
MessageBox(g_hWnd, wsSEPath, L"lua", MB_OK);
SafeDeleteArray(wsSEPath);
continue;
}
int nResID = pParam->pSoundLibs->AddFromFile(wsSEPath);
if (nResID == -1)
{
WCHAR log[64];
SafePrintf(log, 64, L"Script Sound Load Error:%s", wsSEPath);
AddMessageLog(log);
MessageBox(g_hWnd, wsSEPath, L"Script Sound Load Error", MB_OK);
}
else
{
std::string stemp(csSEPath);
pParam->pSoundIDHash->insert(std::map<std::string, int>::value_type(csSEPath, nResID));
}
SafeDeleteArray(wsSEPath);
}
}
AddMessageLog(L"<ステージスクリプト音声ロード>BGMロード");
// BGM
*pParam->pBgmSoundID = pParam->pSoundLibs->AddFromFile(pParam->pStageScrInfo->bgm);
if (*pParam->pBgmSoundID == -1)
{
WCHAR log[64];
SafePrintf(log, 64, L"ステージBGMロードエラー:%s", pParam->pStageScrInfo->bgm);
AddMessageLog(log);
}
g_pCriticalSection->LeaveCriticalSection_Sound();
g_pCriticalSection->LeaveCriticalSection_Session();
AddMessageLog(L"<ロード完了");
return 0;
}
void CGame::UpdateRankView()
{
CDXUTScrollBar* pScrollBar = p_pUI->GetScrollBar(IDC_RESULT_SB_RANK);
// pScrollBar->SetTrackRange(0, (int)m_vecCharacters.size()-1);
int nNo = pScrollBar->GetTrackPos();
CDXUTControl* pNoControl = NULL;
CDXUTControl* pIconControl = NULL;
CDXUTControl* pNameControl = NULL;
CDXUTControl* pTeamControl = NULL;
bool bVisible = false;
for (int i=0;i<m_nRankItemCount;i++)
{
// if (i+nNo > m_nRankItemCount-1) break;
bVisible = (i>=nNo) && (i-nNo<=RESULT_RANK_VIEW_RANGE-1);
pNoControl = p_pUI->GetControl(IDC_RESULT_SPRITE_NO_BASE+i);
pIconControl = p_pUI->GetControl(IDC_RESULT_SPRITE_ICON_BASE+i);
pNameControl = p_pUI->GetControl(IDC_RESULT_STATIC_NAME_BASE+i);
if (m_nTeamCount > 1)
pTeamControl = p_pUI->GetControl(IDC_RESULT_STATIC_TEAM_BASE+i);
if (pNoControl->GetVisible() != bVisible)
{
pNoControl->SetVisible(bVisible);
pNoControl->Refresh();
pIconControl->SetVisible(bVisible);
pIconControl->Refresh();
pNameControl->SetVisible(bVisible);
pNameControl->Refresh();
// チーム番号
if (pTeamControl)
{
pNameControl->SetVisible(bVisible);
pNameControl->Refresh();
}
}
int nOffsetX = 0;
if (pTeamControl)
nOffsetX = RESULT_STATIC_TEAM_CNT_W;
if (bVisible)
{
int nY = RESULT_SPRITE_RANK_NO_CNT_Y_BASE+((RESULT_SPRITE_RANK_NO_CNT_Y_OFFSET)*i);
pNoControl->SetLocation(
RESULT_SPRITE_RANK_NO_CNT_X_BASE,
RESULT_SPRITE_RANK_NO_CNT_Y_BASE+((RESULT_SPRITE_RANK_NO_CNT_Y_OFFSET+RESULT_SPRITE_LINE_CNT_H)*(i-nNo)) );
pIconControl->SetLocation(
RESULT_SPRITE_ICON_CNT_X_BASE,
RESULT_SPRITE_ICON_CNT_Y_BASE+((RESULT_SPRITE_ICON_CNT_Y_OFFSET+RESULT_SPRITE_LINE_CNT_H)*(i-nNo)) );
if (pTeamControl)
pTeamControl->SetLocation(
RESULT_STATIC_TEAM_CNT_X_BASE,
RESULT_STATIC_TEAM_CNT_Y_BASE+((RESULT_STATIC_TEAM_CNT_Y_OFFSET+RESULT_SPRITE_LINE_CNT_H)*(i-nNo)) );
pNameControl->SetLocation(
RESULT_STATIC_NAME_CNT_X_BASE+nOffsetX,
RESULT_STATIC_NAME_CNT_Y_BASE+((RESULT_STATIC_NAME_CNT_Y_OFFSET+RESULT_SPRITE_LINE_CNT_H)*(i-nNo)) );
pNameControl->SetSize(
RESULT_STATIC_NAME_CNT_W-nOffsetX,
RESULT_STATIC_NAME_CNT_H);
}
}
}
void CGame::LoadSound(WCHAR* pPath, CSoundLibraries* pSoundLibs, std::map<std::wstring, int>* pMapSoundIDHash)
{
int nResID = 0;
if ((nResID = pSoundLibs->AddFromFile(pPath)) == -1)
MessageBox(g_hWnd, pPath, L"Sound Load Error", MB_OK);
else
pMapSoundIDHash->insert(std::map<std::wstring, int>::value_type(pPath, nResID));
}
void CGame::PlaySysSoundSE(std::wstring wsResouce, int fade)
{
if (wsResouce.empty()) return;
if (!m_bytSEVolume) return;
g_pCriticalSection->EnterCriticalSection_Sound(L'5');
std::map<std::wstring, int>::iterator itfind = m_mapSysSoundIDHash.find(wsResouce);
if (itfind == m_mapSysSoundIDHash.end())
{
g_pCriticalSection->LeaveCriticalSection_Sound();
WCHAR log[64];
SafePrintf(log, 64, L"NotFound,SysSoundIDHash:%s", wsResouce.c_str());
AddMessageLog(log);
return;
}
CSoundBuffer* pSoundBuffer = m_pSysSoundLibs->GetDuplicatedFromID((*itfind).second);
if (!pSoundBuffer)
{
g_pCriticalSection->LeaveCriticalSection_Sound();
WCHAR log[64];
SafePrintf(log, 64, L"NoGet,SysSoundBuffer:%s", wsResouce.c_str());
AddMessageLog(log);
}
else
m_pSoundPlayer->PlaySoundBuffer(pSoundBuffer, m_bytSEVolume, 0, fade);
g_pCriticalSection->LeaveCriticalSection_Sound();
}
void CGame::SaveConfig()
{
// BGM VOLUME
m_pIniConfig->WriteInt(L"CONFIG", L"BGM", m_bytBGMVolume = p_pConfig->GetSlider(IDC_CONFIG_SLIDER_BGM)->GetValue());
// SE VOLUME
m_pIniConfig->WriteInt(L"CONFIG", L"SE", m_bytSEVolume = p_pConfig->GetSlider(IDC_CONFIG_SLIDER_SE)->GetValue());
// EFFECT ON/OFF
m_pIniConfig->WriteBool(L"CONFIG", L"EFFECT", m_bEffectEnable = p_pConfig->GetCheckBox(IDC_CONFIG_CHK_EFFECT)->GetChecked());
// BLT_FOCUS ON/OFF
m_pIniConfig->WriteBool(L"CONFIG", L"BLT_FOCUS", m_bBulletFocus = p_pConfig->GetCheckBox(IDC_CONFIG_CHK_BLT_FOCUS)->GetChecked());
// ACT_FOCUS ON/OFF
m_pIniConfig->WriteBool(L"CONFIG", L"ACT_FOCUS", m_bActChrFocus = p_pConfig->GetCheckBox(IDC_CONFIG_CHK_ACT_FOCUS)->GetChecked());
}
BOOL CGame::ReqLoadComplete()
{
if (m_bReqLoadComplete)
return FALSE;
AddMessageLog(L"ReqLoadComplete");
m_bReqLoadComplete = TRUE;
return TRUE;
}
void CGame::ShowItemDetail(int nControlID)
{
CDXUTButton* pBtn = p_pUI->GetButton(nControlID);
if (!pBtn) return;
CDXUTButton* pBtnDetail = p_pUI->GetButton(IDC_ROOM_BTN_ITEM_DETAIL);
DWORD dwItemFlg = (DWORD)pBtn->GetUserData();
if (!dwItemFlg) return;
int i=0;
for (;i<GAME_ITEM_COUNT;i++)
{
if (dwItemFlg == c_tItemResouceInfoTable[i].flg)
break;
}
if (i >= GAME_ITEM_COUNT) return;
const WCHAR* wsText = c_tItemResouceInfoTable[i].text;
pBtnDetail->SetText(wsText);
pBtnDetail->SetLocation(min(WIN_WIDTH-m_rcItemDetailControlSize[i].right,m_nMousePosX-4),m_nMousePosY-m_rcItemDetailControlSize[i].bottom+4);
pBtnDetail->SetSize(m_rcItemDetailControlSize[i].right, m_rcItemDetailControlSize[i].bottom);
if (!pBtnDetail->GetVisible())
pBtnDetail->SetVisible(true);
}
BOOL CGame::ReqPacketHash(BYTE* data)
{
BYTE pkt[MAX_PACKET_SIZE];
// INT pktsize = PacketMaker::MakePacketData_AuthRetHash(hash_group, hash_id, hashcode.c_str(), hashcode.length(), pkt);
int index = 3;
WORD wCount = 0;
memcpy(&wCount, &data[index], sizeof(WORD));
index += sizeof(WORD);
for (int i=0;i<wCount;++i)
{
WORD wID = 0;
memcpy(&wID, &data[index], sizeof(WORD));
index += sizeof(WORD);
std::map <int, TCHARA_SCR_INFO>::iterator itfind = m_mapCharaScrInfo.find(wID);
if (itfind == m_mapCharaScrInfo.end())
{
WCHAR alog[128];
SafePrintf(alog, 128, L"キャラデータ不足しています。\nキャラスクリプトID[%d]が見つかりませんでした。", wID);
g_pGame->PlaySysSoundSE(SE_sai_SrvInfo);
AddMessageLog(alog);
MessageBox(g_hWnd, alog, L"認証結果", MB_OK);
if (g_bCloseSocket) return FALSE;
SafePrintf(alog, 128, L"サーバが使用しているキャラスクリプトID[%d]を要求しますか?\n(「はい」を押すと受信完了まで応答が無くなります)", wID);
if (MessageBox(g_hWnd, alog, L"データ不足", MB_YESNO) == IDYES)
{
if (g_bCloseSocket) return FALSE;
BYTE pkt[MAX_PACKET_SIZE];
INT pktsize = PacketMaker::MakePacketData_ReqFileHash(FALSE, wID, 0, pkt);
return AddPacket(pkt, pktsize);
}
else
g_bCloseSocket = TRUE;
return FALSE;
}
else
(*itfind).second.flg = TRUE;
}
memcpy(&wCount, &data[index], sizeof(WORD));
index += sizeof(WORD);
for (int i=0;i<wCount;++i)
{
WORD wID = 0;
memcpy(&wID, &data[index], sizeof(WORD));
index += sizeof(WORD);
std::map <int, TSTAGE_SCR_INFO>::iterator itfind = m_mapStageScrInfo.find(wID);
if (itfind == m_mapStageScrInfo.end())
{
WCHAR alog[128];
SafePrintf(alog, 128, L"ステージデータ不足しています。\nステージスクリプトID[%d]が見つかりませんでした。", wID);
g_pGame->PlaySysSoundSE(SE_sai_SrvInfo);
AddMessageLog(alog);
MessageBox(g_hWnd, alog, L"認証結果", MB_OK);
if (g_bCloseSocket) return FALSE;
SafePrintf(alog, 128, L"サーバが使用しているステージスクリプトID[%d]を要求しますか?\n(「はい」を押すと受信完了まで応答が無くなります)", wID);
if (MessageBox(g_hWnd, alog, L"データ不足", MB_YESNO) == IDYES)
{
if (g_bCloseSocket) return FALSE;
BYTE pkt[MAX_PACKET_SIZE];
INT pktsize = PacketMaker::MakePacketData_ReqFileHash(FALSE, wID, 0, pkt);
return AddPacket(pkt, pktsize);
}
else
g_bCloseSocket = TRUE;
return FALSE;
}
else
(*itfind).second.flg = TRUE;
}
INT pktsize = PacketMaker::MakePacketData_FileHash(FALSE, &m_mapCharaScrInfo, &m_mapStageScrInfo, pkt);
return AddPacket(pkt, pktsize);
int hash_group = data[3];
WORD hash_id=0;
memcpy(&hash_id, &data[4], sizeof(WORD));
std::string hashcode;
if (hash_group == 0)
{
std::map <int, TSTAGE_SCR_INFO>::iterator itfind = m_mapStageScrInfo.find(hash_id);
if (itfind == m_mapStageScrInfo.end())
{
WCHAR alog[128];
SafePrintf(alog, 128, L"スクリプトデータ不足しています。\nステージスクリプトID[%d]が見つかりませんでした。", hash_id);