forked from the4chancup/4ccEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
5839 lines (5014 loc) · 189 KB
/
main.cpp
File metadata and controls
5839 lines (5014 loc) · 189 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
/*Header files and preprocessor directives*/
#include "resource.h"
#include "editor.h"
#include "window.h"
#include "aatf.h"
#include <string>
#include <Windows.h>
#pragma comment(lib, "Winmm.lib")
#include <mmsystem.h>
//----------------------------------------------------------------------
/*Function prototypes*/
/*
//Dialog procedures: (Now in window.h)
LRESULT CALLBACK wnd_proc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK aatf_sing_dlg_proc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK aatf_mult_dlg_proc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK aatf_sel_dlg_proc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK aatf_comp_dlg_proc(HWND, UINT, WPARAM, LPARAM);
//BOOL CALLBACK tab_two_dlg_proc(HWND, UINT, WPARAM, LPARAM);
//Control procedures: (Now in window.h)
LRESULT CALLBACK lv_cntl_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
LRESULT CALLBACK cb_cntl_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
LRESULT CALLBACK cb2_cntl_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
LRESULT CALLBACK scale_cntl_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
LRESULT CALLBACK scale_static_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
LRESULT CALLBACK onto_tab_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
LRESULT CALLBACK from_tab_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
LRESULT CALLBACK tab_two_dlg_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
LRESULT CALLBACK tab_three_dlg_proc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
BOOL CALLBACK statDlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK bumpDlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK scale_children(HWND,LPARAM);
BOOL CALLBACK draw_children(HWND,LPARAM);
*/
int loadDLL();
int DoFileOpen(HWND, int, TCHAR* = NULL);
void DoFileSave(HWND);
void data_handler(const TCHAR *, int);
void save_handler(const TCHAR *);
void player_names_to_positions();
void export_squad(HWND);
void import_squad(HWND);
void extract_player_entry(player_entry, int &);
void extract_team_info(team_entry, int &);
void extract_teamplayer_info(team_entry, int &);
void show_player_info(int);
player_entry get_form_player_info(int);
bool get_form_team_info(int, team_entry &);
void fill_list_all_players();
void make_pony_phys();
void trim_team();
void team_vis_clear();
void team_created_set();
void team_fpc_on();
void team_fpc_off();
void fpc_toggle();
void toggle_hid();
void set_stats();
void bump_stats();
void copy_stats();
void set_boot_glove_ids();
void swap_stats();
//void setup_control(HWND,HFONT,SUBCLASSPROC); (Now in window.h)
//void setup_combo(HWND,HFONT,SUBCLASSPROC);
void common_shortcuts(WPARAM);
void roster_data_output();
void fix_database();
void scroll_player_up();
void scroll_player_down();
void update_tables();
void SD_OnHVScroll(HWND hwnd, int bar, UINT code);
void SD_ScrollClient(HWND hwnd, int bar, int pos);
int SD_GetScrollPos(HWND hwnd, int bar, UINT code);
//----------------------------------------------------------------------
/*Global variables*/
char gc_ver4ccs[] = "20a";
HINSTANCE ghinst; //Main window instance
HINSTANCE hPesDecryptDLL; //Handle to libpesXcrypter.dll
HINSTANCE hPes15DecryptDLL; //Handle to libpes15crypter.dll
HWND ghw_main; //Handle to main window
HWND ghw_tabcon, ghw_tab1, ghw_tab2, ghw_tab3;
HFONT ghFont;
HWND ghw_stat=NULL, ghw_bump=NULL, ghw_copy=NULL, ghw_import=NULL, ghw_swap = NULL, ghw_boglo=NULL;
HWND ghw_DlgCurrent = NULL;
HWND ghAatfbox=NULL;
void* ghdescriptor = NULL; //void, cast as FileDescriptorOld, FileDescriptorNew, or FileDescriptor15 depending on version
player_entry* gplayers = NULL;
int* gn_playind = NULL; //positions in gplayers array of each item in player listbox
team_entry* gteams = NULL;
int* gn_teamCbIndToArray = NULL; //positions in gteams array of each item in team combobox
int* gn_teamArrayIndToCb = NULL; //vice versa
int gnum_players, gnum_teams, gn_listsel=-1, gn_teamsel=-1, gn_forceupdate=-1;
bool gb_forceupdate = false;
bool gb_firstsave = true;
bool gb_importStats = true, gb_importAes = true; //Squad import options
int gn_oldysize = 642;
int g_prevx=0;
int giPesVersion = 0;
int g_bumpAmount = 0;
const uint8_t* gpMasterKey;
appearance_map g_umap_pid_to_startByte; //Map from player ID to start byte of appearance entry
int gi_lastAbility = IDC_ABIL_AGGR; //Final control ID in list of Player Ability, for looping over them
//Brushes
HBRUSH gTeamColor1 = NULL;
HBRUSH gTeamColor2 = NULL;
HBRUSH g_hbr = NULL;
pf_createFileDescriptorOld createFileDescriptorOld;
pf_createFileDescriptorNew createFileDescriptorNew;
pf_destroyFileDescriptorOld destroyFileDescriptorOld;
pf_destroyFileDescriptorNew destroyFileDescriptorNew;
pf_decryptWithKeyOld decryptWithKeyOld;
pf_decryptWithKeyNew decryptWithKeyNew;
pf_encryptWithKeyOld encryptWithKeyOld;
pf_encryptWithKeyNew encryptWithKeyNew;
pf_createFileDescriptor15 createFileDescriptor15;
pf_destroyFileDescriptor15 destroyFileDescriptor15;
pf_decryptFile15 decryptFile15;
pf_encryptFile15 encryptFile15;
//The TCHAR-version of a user-provided entry point for a graphical
// Windows-based application.
// I [in] A handle to the current instance of the application
// PI [in] A handle to the previous instance of the application. This
// parameter is always NULL
// CL [in] The command line for the program, excluding the program name
// SC [in] Controls how the window is to be shown
int APIENTRY _tWinMain(HINSTANCE I, HINSTANCE PI, LPTSTR CL, int SC)
{
ghinst = I; //Global handle to the program instance
WNDCLASSEX wc;
MSG msg;
//Create brush for painting main window background so it will match the bg color of the tabs and dialog boxes on all systems
COLORREF bkColor = (COLORREF)GetSysColor(COLOR_3DFACE);
g_hbr = (HBRUSH)CreateSolidBrush(bkColor);
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = wnd_proc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = I;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = g_hbr;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
wc.lpszClassName = _T("4cc_app");
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"),
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
//Load libpesXcrypter.dll and its functions
int retval = loadDLL();
if(retval) return retval;
ghw_main = CreateWindowEx(
0,
wc.lpszClassName,
_T("4ccEditor Autumn 25 Edition (Version B)"),
WS_OVERLAPPEDWINDOW,
20, 20, 1120+144, 700,
NULL, NULL, ghinst, NULL);
if(ghw_main == NULL)
{
MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
srand(time(NULL));
ShowWindow(ghw_main, SC);
UpdateWindow(ghw_main);
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
if( !IsDialogMessage(ghw_main, &msg) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//Message loop for the main window
LRESULT CALLBACK wnd_proc(HWND H, UINT M, WPARAM W, LPARAM L)
{
switch(M)
{
case WM_CREATE:
{
int ii;
//Initialize common controls so we can use tabbed page,
// tooltip, and progress bar controls
INITCOMMONCONTROLSEX ix;
ix.dwSize = sizeof(INITCOMMONCONTROLSEX);
ix.dwICC = ICC_TAB_CLASSES | ICC_PROGRESS_CLASS;
InitCommonControlsEx(&ix);
//AATF Dialog box
ghAatfbox = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_AATF), H, aatf_sing_dlg_proc);
HICON hi_big = (HICON)LoadImage(ghinst, MAKEINTRESOURCE(IDI_4CC_MED), IMAGE_ICON, 48, 48, NULL);
HICON hi_sml = (HICON)LoadImage(ghinst, MAKEINTRESOURCE(IDI_4CC), IMAGE_ICON, 16, 16, NULL);
SendMessage(H, WM_SETICON, ICON_BIG, (LPARAM)hi_big);
SendMessage(H, WM_SETICON, ICON_SMALL, (LPARAM)hi_sml);
HFONT hfDefault;
HWND hw_new;
HWND hw_bud;
RECT *chd_rect;
hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
ghFont = CreateFont(15,0,0,0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Segoe UI"));
hw_new = CreateWindowEx(0,_T("SCROLLBAR"),(PTSTR) NULL, WS_CHILD | SBS_HORZ,
0, 642-18, 1102, 18, H, (HMENU)IDC_HSCROLL, GetModuleHandle(NULL), (PVOID) NULL);
RECT rc = {};
GetClientRect(H, &rc);
const SIZE sz = { rc.right - rc.left, rc.bottom - rc.top };
SCROLLINFO si = {};
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
si.nPos = si.nMin = 1;
si.nMax = sz.cx;
si.nPage = sz.cx;
SetScrollInfo(hw_new, SB_HORZ, &si, FALSE);
//In window.cpp:
setup_main(H);
setup_tab1(H);
setup_tab2(H);
setup_tab3(H);
int x1, x2, y1;
x1 = GetSystemMetrics(SM_CXSCREEN);
y1 = GetSystemMetrics(SM_CYSCREEN); //1120, 700
if(y1<700)
{
x2 = y1/700*1120;
if(x2>x1) x2=x1;
SetWindowPos(H,0,0,0,x2,y1,SWP_NOZORDER);
}
SetFocus(GetDlgItem(H, IDC_TEAM_LIST));
}
break;
case WM_SIZE:
{
RECT rcClient;
resize_info ri;
GetClientRect(H, &rcClient);
//GetWindowRect(H, &rcClient);
//MapWindowPoints(HWND_DESKTOP, GetParent(H), (LPPOINT)&rcClient, 2);
//hEdit = GetDlgItem(H, IDC_MAIN_EDIT);
//SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
//float scale = (float)(rcClient.bottom-rcClient.top)/700.0;
ri.scale = (float)(rcClient.bottom-rcClient.top)/642.0;
int font_height = ceil(ri.scale*15.0);
DeleteObject((HGDIOBJ)ghFont);
ghFont = CreateFont(font_height,0,0,0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Segoe UI"));
HWND hscroll = GetDlgItem(H, IDC_HSCROLL);
SetWindowPos(hscroll, 0, rcClient.left, rcClient.bottom - 18, rcClient.right, 18,
SWP_NOOWNERZORDER|SWP_NOACTIVATE|SWP_NOZORDER);
const SIZE sz = { rcClient.right - rcClient.left, rcClient.bottom - rcClient.top };
if( !(W != SIZE_RESTORED && W != SIZE_MAXIMIZED) )
{
//----------------
SCROLLINFO si = {};
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_PAGE | SIF_RANGE;
si.nPage = sz.cx;
si.nMax = 1104*ri.scale;
SetScrollInfo(hscroll, SB_CTL, &si, TRUE);
si.fMask = SIF_RANGE | SIF_POS;
GetScrollInfo(hscroll, SB_CTL, &si);
const int maxScrollPos = si.nMax - (sz.cx - 1);
// Scroll client only if scroll bar is visible and window's
// content is fully scrolled toward right and/or bottom side.
// Also, update window's content on maximize.
const bool needToScroll =
(si.nPos != si.nMin && si.nPos == maxScrollPos) ||
(W == SIZE_MAXIMIZED);
if(needToScroll)
{
SD_ScrollClient(hscroll, SB_CTL, si.nPos);
}
//---------------------
if( (float)sz.cx/(float)sz.cy< 1.718 ) ShowWindow(hscroll, SW_SHOW);
else ShowWindow(hscroll, SW_HIDE);
//ri.hdefer = BeginDeferWindowPos(500);
EnumChildWindows(H, scale_children, (LPARAM)&ri);
//EndDeferWindowPos(ri.hdefer);
EnumChildWindows(H, draw_children, (LPARAM)0);
InvalidateRect(H,NULL,true);
}
}
break;
case WM_HSCROLL:
{
SD_OnHVScroll(GetDlgItem(H, IDC_HSCROLL), SB_CTL, LOWORD(W));
}
break;
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)L; // item drawing information
HWND hTabCtrl = GetDlgItem(H, IDC_TAB_MAIN);
TCITEM tci;
TCHAR szTabText[30];
HBRUSH hbr;
COLORREF bkColor;
if (hTabCtrl == lpdis->hwndItem) // is this the tab control?
{
bkColor = (COLORREF)GetSysColor(COLOR_3DFACE);
hbr = (HBRUSH)CreateSolidBrush(bkColor);
memset(szTabText, '\0', sizeof(szTabText));
tci.mask = TCIF_TEXT;
tci.pszText = szTabText;
tci.cchTextMax = 29;
TabCtrl_GetItem(hTabCtrl, lpdis->itemID, &tci);
FillRect(lpdis->hDC, &lpdis->rcItem, hbr);
SetBkColor(lpdis->hDC, bkColor);
//RECT rctext = lpdis->rcItem;
//rctext.top -= GetSystemMetrics(SM_CYEDGE);
//rctext.left += GetSystemMetrics(SM_CXEDGE);
//int test = TabCtrl_GetCurSel(hTabCtrl);
//TextOut(lpdis->hDC,rctext.left,rctext.top,tci.pszText,lstrlen(tci.pszText));
if( lpdis->itemID == TabCtrl_GetCurSel(hTabCtrl) )
DrawText(lpdis->hDC, tci.pszText, lstrlen(tci.pszText), &lpdis->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
else
DrawText(lpdis->hDC, tci.pszText, lstrlen(tci.pszText), &lpdis->rcItem, DT_SINGLELINE|DT_BOTTOM|DT_CENTER);
DeleteObject(hbr);
}
}
break;
case WM_KEYDOWN:
{
//When P key is pressed
if( W == 0x50 && (GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_SHIFT) & 0x8000) )
{
make_pony_phys();
}
}
break;
case WM_NOTIFY:
{
switch( ((LPNMHDR)L)->code )
{
//Message sent because user changed the tab selection
// (clicked on another tab)
case TCN_SELCHANGING:
{
//Hide the old tab from view
if( TabCtrl_GetCurSel(GetDlgItem(ghw_main, IDC_TAB_MAIN)) == 0 )
{
ShowWindow(ghw_tab1, SW_HIDE);
}
else if( TabCtrl_GetCurSel(GetDlgItem(ghw_main, IDC_TAB_MAIN)) == 1 )
{
ShowWindow(ghw_tab2, SW_HIDE);
}
else if( TabCtrl_GetCurSel(GetDlgItem(ghw_main, IDC_TAB_MAIN)) == 2 )
{
ShowWindow(ghw_tab3, SW_HIDE);
}
}
break;
//Message sent when new tab gains focus
case TCN_SELCHANGE:
{
//Make the new tab visible
if( TabCtrl_GetCurSel(GetDlgItem(ghw_main, IDC_TAB_MAIN)) == 0 )
{
ShowWindow(ghw_tab1, SW_SHOW);
}
else if( TabCtrl_GetCurSel(GetDlgItem(ghw_main, IDC_TAB_MAIN)) == 1 )
{
ShowWindow(ghw_tab2, SW_SHOW);
}
else if( TabCtrl_GetCurSel(GetDlgItem(ghw_main, IDC_TAB_MAIN)) == 2 )
{
ShowWindow(ghw_tab3, SW_SHOW);
}
}
break;
case LVN_ITEMCHANGED:
{
if(gb_forceupdate)
{
player_entry pe_current = get_form_player_info(gn_forceupdate);
if( !(gplayers[gn_forceupdate] == pe_current) )
{
if( wcscmp(gplayers[gn_forceupdate].name, pe_current.name) )
pe_current.b_edit_player = true;
gplayers[gn_forceupdate] = pe_current;
//Check if name is still in ListView
int list_size,ii;
bool b_upd = false;
list_size = SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_GETITEMCOUNT, 0, 0);
for(ii=0;ii<list_size;ii++)
{
if(gplayers[gn_playind[ii]].id==pe_current.id)
{
b_upd = true;
break;
}
}
if(b_upd)
{
//Update displayed name
LVITEM lvI;
memset(&lvI,0,sizeof(lvI)); //Zero out struct members
lvI.mask = LVIF_TEXT;
lvI.pszText = pe_current.name;
lvI.iItem = ii;
SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_SETITEM, 0, (LPARAM)&lvI);
}
}
//Check and update team tables
team_entry te_current;
if( get_form_team_info(gn_forceupdate, te_current) )
{
int ti = gplayers[gn_forceupdate].team_ind;
if( !(gteams[ti] == te_current) )
{
gteams[ti] = te_current;
//Update combobox
int csel = SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_GETCURSEL, 0, 0);
SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_DELETESTRING, gn_teamArrayIndToCb[ti]+1, 0);
SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_INSERTSTRING, gn_teamArrayIndToCb[ti]+1, (LPARAM)te_current.name);
SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_SETCURSEL, csel, 0);
}
}
gn_listsel = ((LPNMLISTVIEW)L)->iItem;
show_player_info(gn_playind[gn_listsel]);
gb_forceupdate = false;
}
else if(((LPNMLISTVIEW)L)->iItem != gn_listsel)
{
if(gn_listsel > -1)
{
player_entry pe_current = get_form_player_info(gn_playind[gn_listsel]);
if( !(gplayers[gn_playind[gn_listsel]] == pe_current) )
{
if( wcscmp(gplayers[gn_playind[gn_listsel]].name, pe_current.name) )
pe_current.b_edit_player = true;
gplayers[gn_playind[gn_listsel]] = pe_current;
//Update displayed name
LVITEM lvI;
memset(&lvI,0,sizeof(lvI)); //Zero out struct members
lvI.mask = LVIF_TEXT;
lvI.pszText = pe_current.name;
lvI.iItem = gn_listsel;
SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_SETITEM, 0, (LPARAM)&lvI);
}
//Check and update team tables
team_entry te_current;
if( get_form_team_info(gn_playind[gn_listsel], te_current) )
{
int ti = gplayers[gn_playind[gn_listsel]].team_ind;
if( !(gteams[ti] == te_current) )
{
gteams[ti] = te_current;
//Update combobox
int csel = SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_GETCURSEL, 0, 0);
SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_DELETESTRING, gn_teamArrayIndToCb[ti]+1, 0);
SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_INSERTSTRING, gn_teamArrayIndToCb[ti]+1, (LPARAM)te_current.name);
SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_SETCURSEL, csel, 0);
}
}
}
gn_listsel = ((LPNMLISTVIEW)L)->iItem;
show_player_info(gn_playind[gn_listsel]);
}
}
break;
case UDN_DELTAPOS:
{
LPNMUPDOWN lpnmud = (LPNMUPDOWN)L;
if(LOWORD(W)==IDB_MOVE_PLYR)
{
if(lpnmud->iDelta<0 && gn_listsel > 0) //Ensure can't move up if at top of list
{
//Get team of player in prev position on list, check if equal to current player team
if(gplayers[gn_playind[gn_listsel-1]].team_ind == gplayers[gn_playind[gn_listsel]].team_ind)
{
//Update current player entry
player_entry pe_current = get_form_player_info(gn_playind[gn_listsel]);
if( !(gplayers[gn_playind[gn_listsel]] == pe_current) )
{
if( wcscmp(gplayers[gn_playind[gn_listsel]].name, pe_current.name) )
pe_current.b_edit_player = true;
gplayers[gn_playind[gn_listsel]] = pe_current;
}
//export settings for current player into temp struct 1
player_export currPlyrExport = gplayers[gn_playind[gn_listsel]].PlayerExport();
//export settings for prev player into temp struct 2
player_export prevPlyrExport = gplayers[gn_playind[gn_listsel-1]].PlayerExport();
//Have player copy ids match new slot
unsigned long tmp_id = currPlyrExport.copy_id;
currPlyrExport.copy_id = prevPlyrExport.copy_id;
prevPlyrExport.copy_id = tmp_id;
//swap temp struct 2 into (old) current player, set b_changed flag
gplayers[gn_playind[gn_listsel]].PlayerImport(prevPlyrExport);
gplayers[gn_playind[gn_listsel]].b_changed = true;
//import temp struct 1 into (old) prev player, set b_changed flag
gplayers[gn_playind[gn_listsel-1]].PlayerImport(currPlyrExport);
gplayers[gn_playind[gn_listsel-1]].b_changed = true;
show_player_info(gn_playind[gn_listsel]);
//Update displayed names
LVITEM lvI;
memset(&lvI,0,sizeof(lvI)); //Zero out struct members
lvI.mask = LVIF_TEXT;
lvI.pszText = gplayers[gn_playind[gn_listsel]].name;
lvI.iItem = gn_listsel;
SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_SETITEM, 0, (LPARAM)&lvI);
lvI.pszText = gplayers[gn_playind[gn_listsel-1]].name;
lvI.iItem = gn_listsel-1;
//Note this will set the current selection to gn_listsel-1, the prev player
SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_SETITEM, 0, (LPARAM)&lvI);
//As gn_listsel has changed, make the selection visible and highlighted
ListView_EnsureVisible(GetDlgItem(ghw_main, IDC_NAME_LIST), gn_listsel, false);
ListView_SetItemState(GetDlgItem(ghw_main, IDC_NAME_LIST), gn_listsel, LVIS_SELECTED, LVIS_SELECTED);
}
}
else if(lpnmud->iDelta>0 &&
gn_listsel != ListView_GetItemCount(GetDlgItem(ghw_main, IDC_NAME_LIST))-1 &&
gn_listsel > -1) //Ensure can't move down if at bottom of list
{
//Get team of player in next position on list, check if equal to current player team
if(gplayers[gn_playind[gn_listsel+1]].team_ind == gplayers[gn_playind[gn_listsel]].team_ind)
{
//Update current player entry
player_entry pe_current = get_form_player_info(gn_playind[gn_listsel]);
if( !(gplayers[gn_playind[gn_listsel]] == pe_current) )
{
if( wcscmp(gplayers[gn_playind[gn_listsel]].name, pe_current.name) )
pe_current.b_edit_player = true;
gplayers[gn_playind[gn_listsel]] = pe_current;
}
//export settings for current player into temp struct 1
player_export currPlyrExport = gplayers[gn_playind[gn_listsel]].PlayerExport();
//export settings for next player into temp struct 2
player_export nextPlyrExport = gplayers[gn_playind[gn_listsel+1]].PlayerExport();
//Have player copy ids match new slot
unsigned long tmp_id = currPlyrExport.copy_id;
currPlyrExport.copy_id = nextPlyrExport.copy_id;
nextPlyrExport.copy_id = tmp_id;
//swap temp struct 2 into (old) current player, set b_changed flag
gplayers[gn_playind[gn_listsel]].PlayerImport(nextPlyrExport);
gplayers[gn_playind[gn_listsel]].b_changed = true;
//import temp struct 1 into (old) next player, set b_changed flag
gplayers[gn_playind[gn_listsel+1]].PlayerImport(currPlyrExport);
gplayers[gn_playind[gn_listsel+1]].b_changed = true;
show_player_info(gn_playind[gn_listsel]);
//Update displayed names
LVITEM lvI;
memset(&lvI,0,sizeof(lvI)); //Zero out struct members
lvI.mask = LVIF_TEXT;
lvI.pszText = gplayers[gn_playind[gn_listsel]].name;
lvI.iItem = gn_listsel;
SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_SETITEM, 0, (LPARAM)&lvI);
lvI.pszText = gplayers[gn_playind[gn_listsel+1]].name;
lvI.iItem = gn_listsel+1;
//Note this will set the current selection to gn_listsel+1, the next player
SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_SETITEM, 0, (LPARAM)&lvI);
//As gn_listsel has changed, make the selection visible and highlighted
ListView_EnsureVisible(GetDlgItem(ghw_main, IDC_NAME_LIST), gn_listsel, false);
ListView_SetItemState(GetDlgItem(ghw_main, IDC_NAME_LIST), gn_listsel, LVIS_SELECTED, LVIS_SELECTED);
}
}
}
}
break;
}
}
break;
case WM_CLOSE:
if(ghdescriptor)
{
if(giPesVersion >= 18)
destroyFileDescriptorNew((FileDescriptorNew*)ghdescriptor);
else if(giPesVersion >= 16)
destroyFileDescriptorOld((FileDescriptorOld*)ghdescriptor);
else
destroyFileDescriptor15((FileDescriptor15*)ghdescriptor);
ghdescriptor = NULL;
}
if(gplayers)
{
delete[] gplayers;
gplayers = NULL;
}
if(gn_playind)
{
delete[] gn_playind;
gn_playind = NULL;
}
if(gteams)
{
delete[] gteams;
gteams = NULL;
}
//Delete icons, fonts and bitmaps
DeleteObject((HGDIOBJ)ghFont);
FreeLibrary(hPesDecryptDLL);
FreeLibrary(hPes15DecryptDLL);
DeleteObject(g_hbr);
DestroyWindow(H);
break;
case WM_DESTROY:
DestroyWindow(ghAatfbox);
PostQuitMessage(0);
break;
case WM_COMMAND:
wchar_t buffer[4];
int ret;
int prevPesVersion;
memset(buffer, 0, sizeof(buffer));
switch(LOWORD(W))
{
case ID_FILE_EXIT:
PostMessage(H, WM_CLOSE, 0, 0);
break;
case ID_FILE_OPEN_15_EN:
prevPesVersion = giPesVersion;
ret = DoFileOpen(H, 15, _T("Open PES15 EDIT file"));
if (ret) giPesVersion = prevPesVersion;
break;
case ID_FILE_OPEN_16_EN:
prevPesVersion = giPesVersion;
ret = DoFileOpen(H, 16, _T("Open PES16 EDIT file"));
if(ret) giPesVersion = prevPesVersion;
break;
case ID_FILE_OPEN_17_EN:
prevPesVersion = giPesVersion;
ret = DoFileOpen(H, 17, _T("Open PES17 EDIT file"));
if (ret) giPesVersion = prevPesVersion;
break;
case ID_FILE_OPEN_18_EN:
prevPesVersion = giPesVersion;
ret = DoFileOpen(H, 18, _T("Open PES18 EDIT file"));
if (ret) giPesVersion = prevPesVersion;
break;
case ID_FILE_OPEN_19_EN:
prevPesVersion = giPesVersion;
ret = DoFileOpen(H, 19, _T("Open PES19 EDIT file"));
if (ret) giPesVersion = prevPesVersion;
break;
case ID_FILE_OPEN_20_EN:
prevPesVersion = giPesVersion;
ret = DoFileOpen(H, 20, _T("Open PES20 EDIT file"));
if (ret) giPesVersion = prevPesVersion;
break;
case ID_FILE_OPEN_EN:
case ID_FILE_OPEN_21_EN:
prevPesVersion = giPesVersion;
ret = DoFileOpen(H, 21, _T("Open PES21 EDIT file"));
if (ret) giPesVersion = prevPesVersion;
break;
case ID_FILE_SAVE_EN:
if(ghdescriptor)
{
DoFileSave(H);
}
break;
case IDM_PLAY_STAT:
set_stats();
break;
case IDM_PLAY_BUMP:
bump_stats();
break;
case IDM_PLAY_COPY:
copy_stats();
break;
case IDM_PLAY_SWAP:
swap_stats();
break;
case IDM_PLAY_FTOG:
fpc_toggle();
break;
case IDM_TEAM_CLEAR:
if(gplayers) team_vis_clear();
break;
case IDM_TEAM_CREAT:
if(gplayers) team_created_set();
break;
case IDM_TEAM_FPCON:
if(gplayers) team_fpc_on();
break;
case IDM_TEAM_FPOFF:
if(gplayers) team_fpc_off();
break;
case IDM_TEAM_BOGLO:
if (gplayers) set_boot_glove_ids();
break;
case IDM_TEAM_NAMEPOS:
if (gn_teamsel > -1) player_names_to_positions();
else MessageBox(H, _T("Please select a team."), NULL, MB_ICONWARNING);
break;
case IDM_TEAM_SAVES:
if(gn_teamsel > -1) export_squad(H);
else MessageBox(H,_T("Please select a team to be saved."),NULL,MB_ICONWARNING);
break;
case IDM_TEAM_LOADS:
if(gn_teamsel > -1) import_squad(H);
else MessageBox(H,_T("Please select a team to overwrite."),NULL,MB_ICONWARNING);
break;
case IDM_DATA_OUTPUT:
if(gplayers) roster_data_output();
break;
case IDM_DATA_FIX:
if(gplayers) fix_database();
break;
case IDC_TEAM_LIST:
{
if(HIWORD(W)==CBN_SELCHANGE)
{
//fill player, text lists in window
int ii, jj, num_on_team, csel;
csel = SendDlgItemMessage(ghw_main, IDC_TEAM_LIST, CB_GETCURSEL, 0, 0) - 1;
if(gn_teamCbIndToArray[csel]!=gn_teamsel)
{
if(csel>-1)
{
if(gn_listsel > -1)
{
gb_forceupdate = true;
gn_forceupdate = gn_playind[gn_listsel];
}
else gb_forceupdate = false;
if(gn_forceupdate < 0) gb_forceupdate = false;
for(num_on_team=0;num_on_team < gteams->team_max; num_on_team++)
{
if(!gteams[gn_teamCbIndToArray[csel]].players[num_on_team]) break;
}
if(gn_playind != NULL) delete[] gn_playind;
gn_playind = new int[num_on_team];
for (int ii=0; ii<num_on_team; ii++) gn_playind[ii] = -1;
SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_DELETEALLITEMS, 0, 0);
LVITEM lvI;
memset(&lvI,0,sizeof(lvI)); //Zero out struct members
lvI.mask = LVIF_TEXT;
int kk=0;
for(ii=0;ii<gnum_players;ii++)
{
for(jj=0;jj<num_on_team;jj++)
{
if(gplayers[ii].id == gteams[gn_teamCbIndToArray[csel]].players[jj])
{
gn_playind[kk] = ii;
lvI.pszText = gplayers[ii].name;
lvI.iItem = kk;
SendDlgItemMessage(ghw_main, IDC_NAME_LIST, LVM_INSERTITEM, 0, (LPARAM)&lvI);
kk++;
break;
}
}
if(kk==num_on_team) break;
}
gn_teamsel = gn_teamCbIndToArray[csel]; //Update ID of currently selected team
if(gplayers && (gn_playind[0] > -1))
{
ListView_SetItemState(GetDlgItem(ghw_main, IDC_NAME_LIST), 0, LVIS_SELECTED, LVIS_SELECTED);
gn_listsel = 0;
}
else
{
gn_listsel = -1;
show_player_info(-1);
}
}
else
{
if(gn_listsel > -1)
{
gb_forceupdate = true;
gn_forceupdate = gn_playind[gn_listsel];
}
else gb_forceupdate = false;
fill_list_all_players();
gn_teamsel = -1;
}
}
}
}
break;
case IDB_CAPTAIN:
{
if(HIWORD(W)==BN_CLICKED)
{
if(ghdescriptor && (gn_listsel > -1))
{
SendDlgItemMessage(H, IDB_CAPTAIN, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
if(gteams[gplayers[gn_playind[gn_listsel]].team_ind].captain_ind !=
gplayers[gn_playind[gn_listsel]].team_lineup_ind)
{
gteams[gplayers[gn_playind[gn_listsel]].team_ind].captain_ind =
gplayers[gn_playind[gn_listsel]].team_lineup_ind;
gteams[gplayers[gn_playind[gn_listsel]].team_ind].b_changed = true;
}
}
}
}
break;
case IDB_MAKE_GOLD:
{
if(HIWORD(W)==BN_CLICKED)
{
_itow_s(goldRate, buffer, 3, 10);
for(int ii=IDT_ABIL_ATKP;ii<gi_lastAbility;ii+=2)
SendDlgItemMessage(ghw_tab1, ii, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(goldForm, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_FORM, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(goldIR, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_INJU, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(goldWeakFootUse, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_WKUS, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(goldWeakFootAcc, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_WKAC, WM_SETTEXT, 0, (LPARAM)buffer);
}
}
break;
case IDB_MAKE_SILV:
{
if(HIWORD(W)==BN_CLICKED)
{
_itow_s(silverRate, buffer, 3, 10);
for (int ii = IDT_ABIL_ATKP; ii < gi_lastAbility; ii += 2)
SendDlgItemMessage(ghw_tab1, ii, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(silverForm, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_FORM, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(silverIR, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_INJU, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(silverWeakFootUse, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_WKUS, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(silverWeakFootAcc, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_WKAC, WM_SETTEXT, 0, (LPARAM)buffer);
}
}
break;
case IDB_MAKE_REGU:
{
if(HIWORD(W)==BN_CLICKED)
{
//if(ii==IDT_ABIL_DEFP || ii==IDT_ABIL_BWIN || ii==IDT_ABIL_EXPL) //Nerf Defensive Prowess, Ball winning and Explosive power to 72
// SendDlgItemMessage(ghw_tab1, ii, WM_SETTEXT, 0, (LPARAM)_T("77"));
_itow_s(regRate, buffer, 3, 10);
for (int ii = IDT_ABIL_ATKP; ii < gi_lastAbility; ii += 2)
SendDlgItemMessage(ghw_tab1, ii, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(regForm, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_FORM, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(regIR, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_INJU, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(regWeakFootUse, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_WKUS, WM_SETTEXT, 0, (LPARAM)buffer);
_itow_s(regWeakFootAcc, buffer, 3, 10);
SendDlgItemMessage(ghw_tab1, IDT_ABIL_WKAC, WM_SETTEXT, 0, (LPARAM)buffer);
}
}
break;
case IDB_SET_STATS:
{
if(HIWORD(W)==BN_CLICKED)
{
int ii;
TCHAR buffer[3];
GetDlgItemText(H, IDT_SET_STATS, buffer, 3);
for(ii=IDT_ABIL_ATKP;ii<gi_lastAbility;ii+=2)
{
SetDlgItemText(ghw_tab1, ii, buffer);
}
}
}
break;
case IDM_DATA_AATFC: //Run AATF on currently-selected team and show results in a dialog box
{
if(gn_teamsel > -1)
{
update_tables();
ShowWindow(ghAatfbox, SW_SHOW);
aatf_single(ghAatfbox, giPesVersion, gn_teamsel, gplayers, gteams, gnum_players);
}
else MessageBox(H,_T("Please select a team to check."),NULL,MB_ICONWARNING);
}
break;
case IDM_DATA_AATFS: //Run AATF on teams selected from a list
{
if(ghdescriptor)
{
update_tables();
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_AATF_SEL), H, aatf_sel_dlg_proc);
}
}
break;
case IDM_DATA_COMPE: //Compare this save to another and report any changes
{
if(ghdescriptor)
{
update_tables();
//Open dialog box to get file path
OPENFILENAME ofn;
TCHAR cs_file_name[MAX_PATH] = _T("");
TCHAR cs_open_title[40];