forked from TES5Edit/TES5Edit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwbInit.pas
938 lines (825 loc) · 28.5 KB
/
wbInit.pas
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
{*******************************************************************************
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
*******************************************************************************}
unit wbInit;
{$I wbDefines.inc}
interface
uses
Classes;
var
wbApplicationTitle : string;
wbScriptToRun : string;
wbPluginsFileName : String;
wbSettingsFileName : string;
wbModGroupFileName : string;
wbPluginToUse : string; // Passed a specific plugin as parameter
wbLogFile : string; // Optional log file for this session
wbMyProfileName : string;
wbMasterUpdateDone : Boolean;
wbDontSave : Boolean;
wbDontCache : Boolean = False;
wbDontCacheLoad : Boolean = False;
wbDontCacheSave : Boolean = False;
wbDontBackup : Boolean = False;
wbRemoveTempPath : Boolean = True;
wbQuickShowConflicts : Boolean;
wbQuickClean : Boolean;
wbParamIndex : integer = 1; // First unused parameter
wbPluginsToUse : TStringList;
function wbFindNextValidCmdLineFileName(var startingIndex : integer; out aValue : string; defaultPath : string = '') : Boolean;
function wbFindNextValidCmdLinePlugin(var startingIndex : integer; out aValue : string; defaultPath : string) : Boolean;
function wbFindCmdLineParam(const aSwitch : string; out aValue : string): Boolean; overload;
function wbLoadMOHookFile: Boolean;
procedure SwitchToCoSave;
implementation
uses
SysUtils,
Windows,
Registry,
ShellApi,
Dialogs,
ShlObj,
IOUtils,
IniFiles,
wbHelpers,
wbInterface,
wbImplementation,
wbDefinitionsFNV,
wbDefinitionsFNVSaves,
wbDefinitionsFO3,
wbDefinitionsFO3Saves,
wbDefinitionsFO4,
wbDefinitionsFO4Saves,
wbDefinitionsTES3,
wbDefinitionsTES4,
wbDefinitionsTES4Saves,
wbDefinitionsTES5,
wbDefinitionsTES5Saves;
function wbFindCmdLineParam(const aSwitch : string;
const aChars : TSysCharSet;
aIgnoreCase : Boolean;
out aValue : string)
: Boolean; overload;
var
i : Integer;
s : string;
begin
Result := False;
aValue := '';
for i := 1 to ParamCount do begin
s := ParamStr(i);
if (aChars = []) or (s[1] in aChars) then
if aIgnoreCase then begin
if AnsiCompareText(Copy(s, 2, Length(aSwitch)), aSwitch) = 0 then begin
if (length(s)>(length(aSwitch)+2)) and (s[Length(aSwitch) + 2] = ':') then begin
aValue := Copy(s, Length(aSwitch) + 3, MaxInt);
Result := True;
end;
Exit;
end;
end else
if AnsiCompareStr(Copy(s, 2, Length(aSwitch)), aSwitch) = 0 then begin
if s[Length(aSwitch) + 2] = ':' then begin
aValue := Copy(s, Length(aSwitch) + 3, MaxInt);
Result := True;
end;
Exit;
end;
end;
end;
function wbFindCmdLineParam(var startingIndex : integer;
const aChars : TSysCharSet;
out aValue : string)
: Boolean; overload;
var
i : integer;
s : string;
begin
Result := False;
aValue := '';
for i := startingIndex to ParamCount do begin
s := ParamStr(i);
if (aChars = []) or (s[1] in aChars) then // skipped
Inc(startingIndex)
else begin
aValue := ParamStr(i);
startingIndex := i+1;
Result := True;
break;
end
end;
end;
function wbFindCmdLineParam(const aSwitch : string;
out aValue : string)
: Boolean; overload;
begin
Result := wbFindCmdLineParam(aSwitch, SwitchChars, True, aValue);
end;
function wbFindCmdLineParam(var startingIndex : integer; out aValue : string) : Boolean; overload;
begin
Result := wbFindCmdLineParam(startingIndex, SwitchChars, aValue);
end;
function wbCheckForValidExtension(aFilePath : string; const anExtension : string): Boolean; overload;
begin
Result := UpperCase(ExtractFileExt(aFilePath)) = UpperCase(anExtension);
end;
function wbCheckForPluginExtension(aFilePath : string): Boolean;
begin
Result := wbCheckForValidExtension(aFilePath, '.esp') or wbCheckForValidExtension(aFilePath, '.esm');
end;
function wbCheckForValidExtension(aFilePath : string): Boolean; overload;
begin
Result := wbCheckForPluginExtension(aFilePath) or
wbCheckForValidExtension(aFilePath, '.fos') or wbCheckForValidExtension(aFilePath, '.ess');
end;
function wbFindNextValidCmdLineFileName(var startingIndex : integer; out aValue : string; defaultPath : string = '') : Boolean;
begin
Result := wbFindCmdLineParam(startingIndex, SwitchChars, aValue);
if Result and not FileExists(aValue) then
if (defaultPath<>'') then
if FileExists(defaultPath+'\'+aValue) then
aValue := ExpandFileName(defaultPath+'\'+aValue)
else
Result := False
else
Result := False;
end;
function wbFindNextValidCmdLinePlugin(var startingIndex : integer; out aValue : string; defaultPath : string) : Boolean;
begin
repeat
Result := wbFindNextValidCmdLineFileName(startingIndex, aValue, defaultPath);
until not Result or wbCheckForPluginExtension(aValue);
if Result then
if (AnsiCompareText(ExtractFilePath(ExpandFileName(aValue)), ExpandFileName(defaultPath)) = 0) then begin
aValue := ExtractFileName(aValue);
if not Assigned(wbPluginsToUse) then wbPluginsToUse := TStringList.Create;
wbPluginsToUse.Add(aValue);
end else
Result := False;
end;
// several ini settings should be read before record definitions
// they may affect definitions like wbSimpleRecords
// and should be overridden by command line parameters
procedure ReadSettings;
var
Settings: TMemIniFile;
begin
try
Settings := TMemIniFile.Create(wbSettingsFileName);
try
wbLoadBSAs := Settings.ReadBool('Options', 'LoadBSAs', wbLoadBSAs);
wbSimpleRecords := Settings.ReadBool('Options', 'SimpleRecords', wbSimpleRecords);
wbShowFlagEnumValue := Settings.ReadBool('Options', 'ShowFlagEnumValue', wbShowFlagEnumValue);
wbTrackAllEditorID := Settings.ReadBool('Options', 'TrackAllEditorID', wbTrackAllEditorID);
finally
Settings.Free;
end;
finally
end;
end;
function GetCSIDLShellFolder(CSIDLFolder: integer): string;
begin
SetLength(Result, MAX_PATH);
SHGetSpecialFolderPath(0, PChar(Result), CSIDLFolder, True);
SetLength(Result, StrLen(PChar(Result)));
if (Result <> '') then
Result := IncludeTrailingBackslash(Result);
end;
function CheckAppPath: string;
const
ExeName : array[TwbGameMode] of string = (
'FalloutNV.exe', // gmFNV
'Fallout3.exe', // gmFO3
'Morrowind.exe', // gmTES3
'Oblivion.exe', // gmTES4
'TESV.exe', // gmTES5
'SkyrimVR.exe', // gmTES5VR
'SkyrimSE.exe', // gmSSE
'Fallout4.exe', // gmFO4
'Fallout4VR.exe' // gmFO4VR
);
var
s: string;
begin
Result := '';
s := ExtractFilePath(ParamStr(0));
while Length(s) > 3 do begin
if FileExists(s + ExeName[wbGameMode]) and DirectoryExists(s + 'Data') then begin
Result := s;
Exit;
end;
s := ExtractFilePath(ExcludeTrailingPathDelimiter(s));
end;
end;
{===SafeLoadLibrary============================================================}
{$IFDEF CPUX86}
function TestAndClearFPUExceptions(AExceptionMask: Word): Boolean;
asm
PUSH ECX
MOV CX, AX
FSTSW AX
TEST AX, CX
JNE @@bad
XOR EAX, EAX
INC EAX
JMP @@exit
@@bad:
XOR EAX, EAX
@@exit:
POP ECX
FCLEX
RET
end;
{------------------------------------------------------------------------------}
function SafeLoadLibrary(const Filename: string; ErrorMode: UINT): HMODULE;
var
OldMode: UINT;
FPUControlWord: Word;
begin
OldMode := SetErrorMode(ErrorMode);
try
FPUControlWord := Get8087CW();
Result := LoadLibrary(PChar(Filename));
TestAndClearFPUExceptions(0);
Set8087CW(FPUControlWord);
finally
SetErrorMode(OldMode);
end;
end;
{==============================================================================}
{$ENDIF CPUX86}
function wbLoadMOHookFile: Boolean;
var
HookDll : HMODULE;
Init : function(logLevel: Integer; profileName: LPCWSTR): BOOL; cdecl;
begin
if not wbShouldLoadMOHookFile then
Exit(True);
Result := False;
if not FileExists(wbMOHookFile) then
Exit;
HookDll := SafeLoadLibrary(wbMOHookFile, SEM_NOOPENFILEERRORBOX);
if HookDll <> 0 then begin
Pointer(@Init) := GetProcAddress(HookDll, 'Init');
if Assigned(Pointer(@Init)) then
Result := Init(0, PWideChar(UnicodeString(wbMOProfile)));
end;
end;
procedure DoInitPath(const ParamIndex: Integer);
const
sBethRegKey = '\SOFTWARE\Bethesda Softworks\';
sBethRegKey64 = '\SOFTWARE\Wow6432Node\Bethesda Softworks\';
var
s: string;
IniFile : TIniFile;
begin
wbModGroupFileName := wbProgramPath + wbAppName + wbToolName + '.modgroups';
if not wbFindCmdLineParam('S', wbScriptsPath) then
wbScriptsPath := wbProgramPath + 'Edit Scripts\';
if not wbFindCmdLineParam('T', wbTempPath) then
wbTempPath := IncludeTrailingPathDelimiter(TPath.GetTempPath + wbAppName + 'Edit')
else
wbRemoveTempPath := not DirectoryExists(wbTempPath);
if not wbFindCmdLineParam('D', wbDataPath) then begin
wbDataPath := CheckAppPath;
if wbDataPath = '' then with TRegistry.Create do try
RootKey := HKEY_LOCAL_MACHINE;
if not OpenKeyReadOnly(sBethRegKey + wbGameNameReg + '\') then
if not OpenKeyReadOnly(sBethRegKey64 + wbGameNameReg + '\') then begin
s := 'Fatal: Could not open registry key: ' + sBethRegKey + wbGameNameReg + '\';
// if wbGameMode = gmTES5 then // All game exists on steam now
ShowMessage(s + #13#10'This can happen after Steam updates, run game''s launcher to restore registry settings');
wbDontSave := True;
Exit;
end;
wbDataPath := ReadString('Installed Path');
if wbDataPath = '' then begin
s := 'Fatal: Could not determine ' + wbGameName2 + ' installation path, no "Installed Path" registry key';
ShowMessage(s + #13#10'This can happen after Steam updates, run game''s launcher to restore registry settings');
wbDontSave := True;
end;
finally
Free;
end;
if wbDataPath <>'' then
wbDataPath := IncludeTrailingPathDelimiter(wbDataPath) + 'Data\';
end else
wbDataPath := IncludeTrailingPathDelimiter(wbDataPath);
wbOutputPath := wbDataPath;
if wbFindCmdLineParam('O', s) and (Length(s) > 0) then
if s[1] = '.' then
//assume relative path
wbOutputPath := IncludeTrailingPathDelimiter(wbOutputPath + s)
else
//assume absolute path
wbOutputPath := IncludeTrailingPathDelimiter(s);
wbMOHookFile := wbDataPath + '..\Mod Organizer\hook.dll';
if not wbFindCmdLineParam('I', wbTheGameIniFileName) then begin
wbMyProfileName := GetCSIDLShellFolder(CSIDL_PERSONAL);
if wbMyProfileName = '' then begin
ShowMessage('Fatal: Could not determine my documents folder');
Exit;
end;
wbMyGamesTheGamePath := wbMyProfileName + 'My Games\' + wbGameName2 + '\';
if wbGameMode in [gmFO3, gmFNV] then
wbTheGameIniFileName := wbMyGamesTheGamePath + 'Fallout.ini'
else if wbGameMode = gmFO4 then
wbTheGameIniFileName := wbMyGamesTheGamePath + 'Fallout4.ini'
else
wbTheGameIniFileName := wbMyGamesTheGamePath + wbGameName + '.ini';
// VR games don't create ini file in My Games by default, use the one in the game folder
if (wbGameMode in [gmTES5VR, gmFO4VR]) and not FileExists(wbTheGameIniFileName) then
wbTheGameIniFileName := ExtractFilePath(ExcludeTrailingPathDelimiter(wbDataPath)) + '\' + ExtractFileName(wbTheGameIniFileName);
end;
if not wbFindCmdLineParam('G', wbSavePath) then begin
if wbMyGamesTheGamePath = '' then
wbMyGamesTheGamePath := ExtractFilePath(wbTheGameIniFileName);
s := 'Saves\';
if FileExists(wbTheGameIniFileName) then begin
IniFile := TIniFile.Create(wbTheGameIniFileName);
try
s := IniFile.ReadString('General', 'SLocalSavePath', s);
finally
FreeAndNil(IniFile);
end;
end;
wbSavePath := wbMyGamesTheGamePath + s;
end;
wbSavePath := IncludeTrailingPathDelimiter(wbSavePath);
wbParamIndex := ParamIndex;
if not wbFindCmdLineParam('P', wbPluginsFileName) then
if not (wbFindNextValidCmdLineFileName(wbParamIndex, wbPluginsFileName) and SameText(ExtractFileExt(wbPluginsFileName), '.txt'))
or wbCheckForValidExtension(wbPluginsFileName)
then begin
wbParamIndex := ParamIndex;
wbPluginsFileName := GetCSIDLShellFolder(CSIDL_LOCAL_APPDATA);
if wbPluginsFileName = '' then begin
ShowMessage('Fatal: Could not determine the local application data folder');
Exit;
end;
wbPluginsFileName := wbPluginsFileName + wbGameName2 + '\Plugins.txt';
end;
// settings in the ini file next to app, or in the same folder with plugins.txt
wbSettingsFileName := wbProgramPath + wbAppName + wbToolName + '.ini';
if not FileExists(wbSettingsFileName) then
wbSettingsFileName := ChangeFileExt(wbPluginsFileName, '.'+LowerCase(wbAppName)+'viewsettings');
wbBackupPath := '';
if not (wbDontSave or wbFindCmdLineParam('B', wbBackupPath)) then
wbBackupPath := wbDataPath + wbAppName + 'Edit Backups\';
wbCachePath := '';
if not (wbDontCache or wbFindCmdLineParam('C', wbCachePath)) then
wbCachePath := wbDataPath + wbAppName + 'Edit Cache\';
if wbCachePath = '' then
wbDontCache := True;
if not wbDontCache then
if not DirectoryExists(wbCachePath) then
if not ForceDirectories(wbCachePath) then
wbDontCache := True;
if wbDontCache then
wbCachePath := '';
wbFindCmdLineParam('R', wbLogFile);
end;
var
wbForcedModes: string;
AppGameMode, AppToolMode, AppSourceMode: string;
procedure DetectAppMode;
const
SourceModes : array [1..2] of string = ('plugins', 'saves');
GameModes: array [1..8] of string = ('tes5vr', 'fo4vr', 'tes4', 'tes5', 'sse', 'fo3', 'fnv', 'fo4');
ToolModes: array [1..12] of string = (
'edit', 'view', 'lodgen', 'script', 'translate',
'setesm', 'clearesm', 'sortandclean', 'sortandcleanmasters',
'checkforerrors', 'checkforitm', 'checkfordr');
var
s, p: string;
begin
// Detecting game mode
// check command line params first for mode overrides
// they should take precendence over application name detection
// AppSourceMode := SourceModes[1];
for s in SourceModes do
if FindCmdLineSwitch(s) or wbFindCmdLineParam(s, p) or (Pos(s, wbForcedModes) <> 0) then begin
AppSourceMode := s;
Break;
end;
// if no overrrides, then check by executable name
if AppSourceMode = '' then
for s in SourceModes do
if (Pos(s, LowerCase(ExtractFileName(ParamStr(0)))) <> 0) or (Pos(s, wbForcedModes) <> 0) then begin
AppSourceMode := s;
Break;
end;
// if still nothing, then default value
if AppSourceMode = '' then
AppSourceMode := 'plugins';
for s in GameModes do
if FindCmdLineSwitch(s) or wbFindCmdLineParam(s, p) or (Pos(s, wbForcedModes) <> 0) then begin
AppGameMode := s;
Break;
end;
// if no overrrides, then check by executable name
if AppGameMode = '' then
for s in GameModes do
if (Pos(s, LowerCase(ExtractFileName(ParamStr(0)))) <> 0) or (Pos(s, wbForcedModes) <> 0) then begin
AppGameMode := s;
Break;
end;
// if still nothing, then default value
if AppGameMode = '' then
AppGameMode := 'fo4';
// the same for tool mode
for s in ToolModes do
if FindCmdLineSwitch(s) or wbFindCmdLineParam(s, p) or (Pos(s, wbForcedModes) <> 0) then begin
AppToolMode := s;
Break;
end;
if AppToolMode = '' then
for s in ToolModes do
if (Pos(s, LowerCase(ExtractFileName(ParamStr(0)))) <> 0) or (Pos(s, wbForcedModes) <> 0) then begin
AppToolMode := s;
Break;
end;
if AppToolMode = '' then
AppToolMode := 'edit';
end;
function isMode(aMode: String): Boolean;
begin
aMode := LowerCase(aMode);
Result := (AppGameMode = aMode) or (AppToolMode = aMode) or (AppSourceMode = aMode);
end;
// Force app modes
function CheckForcedMode: Boolean;
var
s: string;
i: integer;
begin
Result := False;
// there is a game specific script provided to execute
// go into 'script' tool mode and detect game mode by script's extension
i := 1;
if wbFindCmdLineParam('script', s) or wbFindNextValidCmdLineFileName(i, s) then begin
wbScriptToRun := s;
s := ExtractFileExt(s);
i := Pos(UpperCase('pas'), UpperCase(s));
if (i > 0) and (i = Length(s) - 2) then begin
wbForcedModes := Copy(s, 2, Length(s) - 4) + ',script';
Result := True;
end;
end;
end;
procedure wbDoInit;
var
s: string;
ToolModes: TwbSetOfMode;
ToolSources: TwbSetOfSource;
begin
wbReportMode := False;
wbEditAllowed := True;
wbDontSave := False;
CheckForcedMode;
DetectAppMode;
if isMode('Saves') then begin
wbToolSource := tsSaves;
wbSourceName := 'Saves';
wbUseFalsePlugins := True;
end else begin // defaults to plugin
wbToolSource := tsPlugins;
wbSourceName := 'Plugins';
end;
if isMode('View') then begin
wbToolMode := tmView;
wbToolName := 'View';
wbEditAllowed := False;
wbDontSave := True;
end else if isMode('MasterUpdate') then begin
wbToolMode := tmMasterUpdate;
wbToolName := 'MasterUpdate';
end else if isMode('MasterRestore') then begin
wbToolMode := tmMasterRestore;
wbToolName := 'MasterRestore';
end else if isMode('LODGen') then begin
wbToolMode := tmLODgen;
wbToolName := 'LODGen';
wbEditAllowed := False;
wbDontSave := True;
end else if isMode('Script') then begin
wbToolMode := tmScript;
wbToolName := 'Script';
end else if isMode('Translate') then begin
wbToolMode := tmTranslate;
wbToolName := 'Trans';
end else if isMode('setESM') then begin
wbToolMode := tmESMify;
wbToolName := 'SettingESMflag';
end else if isMode('clearESM') then begin
wbToolMode := tmESPify;
wbToolName := 'ClearingESMflag';
end else if isMode('SortAndClean') then begin
wbToolMode := tmSortAndCleanMasters;
wbToolName := 'SortAndCleanMasters';
end else if isMode('CheckForErrors') then begin
wbToolMode := tmCheckForErrors;
wbToolName := 'CheckForErrors';
end else if isMode('CheckForITM') then begin
wbToolMode := tmCheckForITM;
wbToolName := 'CheckForITM';
end else if isMode('CheckForDR') then begin
wbToolMode := tmCheckForDR;
wbToolName := 'CheckForDR';
end else if isMode('Edit') then begin
wbToolMode := tmEdit;
wbToolName := 'Edit';
end else begin
ShowMessage('Application name must contain Edit, View, LODGen, MasterUpdate, MasterRestore, setESM, clearESM, sortAndCleanMasters, CheckForITM, CheckForDR or CheckForErrors to select mode.');
Exit;
end;
if not (wbToolMode in [tmView, tmEdit]) then
wbPrettyFormID := False;
if isMode('FNV') then begin
wbGameMode := gmFNV;
wbAppName := 'FNV';
wbGameName := 'FalloutNV';
ToolModes := wbAlwaysMode + [tmMasterUpdate, tmMasterRestore];
ToolSources := [tsPlugins, tsSaves];
end
else if isMode('FO3') then begin
wbGameMode := gmFO3;
wbAppName := 'FO3';
wbGameName := 'Fallout3';
ToolModes := wbAlwaysMode + [tmMasterUpdate, tmMasterRestore];
ToolSources := [tsPlugins];
end
else if isMode('TES3') then begin
wbGameMode := gmTES3;
wbAppName := 'TES3';
wbGameName := 'Morrowind';
ToolModes := [];
ToolSources := [];
end
else if isMode('TES4') then begin
wbGameMode := gmTES4;
wbAppName := 'TES4';
wbGameName := 'Oblivion';
ToolModes := wbAlwaysMode;
ToolSources := [tsPlugins];
end
else if isMode('TES5') then begin
wbGameMode := gmTES5;
wbAppName := 'TES5';
wbGameName := 'Skyrim';
wbLanguage := 'English';
ToolModes := wbAlwaysMode + [tmTranslate];
ToolSources := [tsPlugins, tsSaves];
end
else if isMode('TES5VR') then begin
wbGameMode := gmTES5VR;
wbAppName := 'TES5VR';
wbGameName := 'Skyrim';
wbGameName2 := 'Skyrim VR';
wbLanguage := 'English';
ToolModes := wbAlwaysMode + [tmTranslate];
ToolSources := [tsPlugins];
end
else if isMode('SSE') then begin
wbGameMode := gmSSE;
wbAppName := 'SSE';
wbGameName := 'Skyrim';
wbGameName2 := 'Skyrim Special Edition';
wbLanguage := 'English';
ToolModes := wbAlwaysMode + [tmTranslate];
ToolSources := [tsPlugins, tsSaves];
end
else if isMode('FO4') then begin
wbGameMode := gmFO4;
wbAppName := 'FO4';
wbGameName := 'Fallout4';
wbArchiveExtension := '.ba2';
wbLanguage := 'En';
ToolModes := wbAlwaysMode + [tmTranslate];
ToolSources := [tsPlugins, tsSaves];
end
else if isMode('FO4VR') then begin
wbGameMode := gmFO4VR;
wbAppName := 'FO4VR';
wbGameName := 'Fallout4';
wbGameName2 := 'Fallout4VR';
wbGameNameReg := 'Fallout 4 VR';
wbLanguage := 'En';
wbArchiveExtension := '.ba2';
ToolModes := wbAlwaysMode + [tmTranslate];
ToolSources := [tsPlugins];
end
else begin
ShowMessage('Application name must contain FNV, FO3, FO4, FO4VR, SSE, TES4, TES5 or TES5VR to select game.');
Exit;
end;
if not (wbToolMode in ToolModes) then begin
ShowMessage('Application ' + wbGameName + ' does not currently support ' + wbToolName);
Exit;
end;
if not (wbToolSource in ToolSources) then begin
ShowMessage('Application ' + wbGameName + ' does not currently support ' + wbSourceName);
Exit;
end;
if (wbToolSource = tsSaves) and (wbToolMode = tmEdit) then begin
ShowMessage('Application ' + wbGameName + ' does not currently support ' + wbSourceName + ' in ' + wbToolName + ' mode.');
Exit;
end;
if wbGameName2 = '' then
wbGameName2 := wbGameName;
if wbGameNameReg = '' then
wbGameNameReg := wbGameName2;
if FindCmdLineSwitch('DontCache') then
wbDontCache := True;
if FindCmdLineSwitch('DontCacheLoad') then
wbDontCacheLoad := True;
if FindCmdLineSwitch('DontCacheSave') then
wbDontCacheSave := True;
if wbDontCacheLoad and wbDontCacheSave then
wbDontCache := True;
DoInitPath(wbParamIndex);
// specific Game settings
if wbGameMode = gmFNV then begin
wbVWDInTemporary := True;
wbLoadBSAs := False;
ReadSettings;
end else if wbGameMode = gmFO3 then begin
wbVWDInTemporary := True;
wbLoadBSAs := False;
ReadSettings;
end else if wbGameMode = gmTES3 then begin
wbLoadBSAs := False;
wbAllowInternalEdit := false;
ReadSettings;
end else if wbGameMode = gmTES4 then begin
wbLoadBSAs := True;
wbAllowInternalEdit := false;
ReadSettings;
end else if wbGameMode in [gmTES5, gmTES5VR, gmSSE] then begin
wbVWDInTemporary := True;
wbLoadBSAs := True; // localization won't work otherwise
wbHideIgnored := False; // to show Form Version
ReadSettings;
end else if wbGameMode in [gmFO4, gmFO4VR] then begin
wbVWDInTemporary := True;
wbVWDAsQuestChildren := True;
wbLoadBSAs := True; // localization won't work otherwise
wbHideIgnored := False; // to show Form Version
ReadSettings;
//wbCreateContainedIn := False;
end else begin
Exit;
end;
// definitions
case wbGameMode of
gmFNV: case wbToolSource of
tsSaves: DefineFNVSaves;
tsPlugins: DefineFNV;
end;
gmFO3: case wbToolSource of
tsSaves: DefineFO3Saves;
tsPlugins: DefineFO3;
end;
gmFO4, gmFO4VR: case wbToolSource of
tsSaves: DefineFO4Saves;
tsPlugins: DefineFO4;
end;
gmTES3: case wbToolSource of
tsPlugins: DefineTES3;
end;
gmTES4: case wbToolSource of
tsSaves: DefineTES4Saves;
tsPlugins: DefineTES4;
end;
gmTES5, gmTES5VR: case wbToolSource of
tsSaves: DefineTES5Saves;
tsPlugins: DefineTES5;
end;
gmSSE: case wbToolSource of
tsSaves: DefineTES5Saves;
tsPlugins: DefineTES5;
end
end;
if wbFindCmdLineParam('l', s) then
wbLanguage := s;
if wbFindCmdLineParam('cp', s) then begin
if SameText(s, 'utf-8') then
wbStringEncoding := seUTF8;
end;
if FindCmdLineSwitch('speed') then
wbSpeedOverMemory := True;
if FindCmdLineSwitch('memory') then
wbSpeedOverMemory := False;
if FindCmdLineSwitch('report') then
wbReportMode := (DebugHook <> 0);
if FindCmdLineSwitch('MoreInfoForIndex') then
wbMoreInfoForIndex := true;
if FindCmdLineSwitch('fixup') then
wbAllowInternalEdit := True
else if FindCmdLineSwitch('nofixup') then
wbAllowInternalEdit := False;
if FindCmdLineSwitch('skipbsa') then
wbLoadBSAs := False
else if FindCmdLineSwitch('forcebsa') then
wbLoadBSAs := True;
if FindCmdLineSwitch('skipInternalEditing') then
wbAllowInternalEdit := False
else if FindCmdLineSwitch('forceInternalEditing') then
wbAllowInternalEdit := True;
if FindCmdLineSwitch('showfixup') then
wbShowInternalEdit := True
else if FindCmdLineSwitch('hidefixup') then
wbShowInternalEdit := False;
if FindCmdLineSwitch('quickshowconflicts') then
wbQuickShowConflicts := True;
if FindCmdLineSwitch('IKnowWhatImDoing') then
wbIKnowWhatImDoing := True;
if FindCmdLineSwitch('quickclean') and (wbToolSource in [tsPlugins]) then
wbQuickClean := wbIKnowWhatImDoing;
if FindCmdLineSwitch('TrackAllEditorID') then
wbTrackAllEditorID := True;
if FindCmdLineSwitch('IgnoreESL') then
wbIgnoreESL := True;
if FindCmdLineSwitch('SimpleFormIDs') then
wbPrettyFormID := False;
if wbToolMode in wbPluginModes then // look for the file name
if not wbFindNextValidCmdLinePlugin(wbParamIndex, wbPluginToUse, wbDataPath) then begin
ShowMessage(wbToolName+' mode requires a valid plugin name!');
Exit;
end;
// specific Tool Mode settings overrides
if wbToolMode = tmLODgen then begin
wbIKnowWhatImDoing := True;
wbAllowInternalEdit := False;
wbShowInternalEdit := False;
wbLoadBSAs := True;
wbBuildRefs := False;
end
else if wbToolMode = tmScript then begin
wbIKnowWhatImDoing := True;
wbLoadBSAs := True;
wbBuildRefs := True;
end
else if wbToolMode in [tmMasterUpdate, tmESMify] then begin
wbIKnowWhatImDoing := True;
wbAllowInternalEdit := False;
wbShowInternalEdit := False;
wbLoadBSAs := False;
wbBuildRefs := False;
wbMasterUpdateFilterONAM := wbToolMode in [tmESMify];
if FindCmdLineSwitch('filteronam') then
wbMasterUpdateFilterONAM := True
else if FindCmdLineSwitch('noFilteronam') then
wbMasterUpdateFilterONAM := True;
if FindCmdLineSwitch('FixPersistence') then
wbMasterUpdateFixPersistence := True
else if FindCmdLineSwitch('NoFixPersistence') then
wbMasterUpdateFixPersistence := False;
end
else if wbToolMode in [tmMasterRestore, tmESPify, tmCheckForDR, tmCheckForITM, tmCheckForErrors] then begin
wbIKnowWhatImDoing := True;
wbAllowInternalEdit := False;
wbShowInternalEdit := False;
wbLoadBSAs := False;
wbBuildRefs := False;
end
else if wbToolMode = tmTranslate then begin
wbTranslationMode := True;
end;
wbApplicationTitle := wbAppName + wbToolName + ' ' + VersionString;
{$IFDEF LiteVersion}
wbApplicationTitle := wbApplicationTitle + ' Lite';
{$ENDIF}
{$IFDEF WIN64}
wbApplicationTitle := wbApplicationTitle + ' x64';
{$ENDIF WIN64}
if FindCmdLineSwitch('nobuildrefs') then
wbBuildRefs := False;
if FindCmdLineSwitch('fixuppgrd') then
wbFixupPGRD := True;
wbShouldLoadMOHookFile := wbFindCmdLineParam('moprofile', wbMOProfile);
try
if (wbToolMode = tmEdit) and not wbIsAssociatedWithExtension('.' + wbAppName + 'pas') then
wbAssociateWithExtension('.' + wbAppName + 'pas', wbAppName + 'Script', wbAppName + wbToolName + ' script');
except end;
end;
procedure SwitchToCoSave;
begin
case wbGameMode of
gmFNV: SwitchToFNVCoSave;
gmFO3: SwitchToFO3CoSave;
gmTES4: SwitchToTES4CoSave;
gmTES5: SwitchToTES5CoSave;
gmSSE: SwitchToTES5CoSave;
end;
end;
initialization
wbDoInit;
end.