Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Script for dealing with underscores in cellnames, which breaks savegames in SSE.
- Details on bug: https://redd.it/5fvul2
- Has two modes, one for just filtering the cells, and another to fix the namnes by removing the underscore.
- Author Aezay
- Created 2018.05.31
- Modificed 2018.06.01
- }
- unit CellNamesWithUnderscoresFix;
- const
- { method IDs }
- ID_NONE = 0;
- ID_FILTER = 1;
- ID_FIX = 2;
- var
- methodID: Integer;
- log: TStringList;
- editorID, fullName: string; // used in Process, Filter
- fid: DWORD; // used in Process, Filter
- // add found cell to our log and xEdit log
- procedure LogMatch(e: IInterface; const EditorID: string);
- begin
- fullName := GetElementNativeValues(e,'FULL');
- //fid := GetLoadOrderFormID(e);
- fid := FormID(e);
- AddMessage(Format('* [%.8x] %s (%s)',[fid,EditorID,fullName]));
- log.Add(Format('[%.8x] %-40s %s',[fid,EditorID,fullName]));
- end;
- // regular processing
- function Process(e: IInterface):Integer;
- begin
- if (Signature(e) <> 'CELL') then begin
- Result := 0;
- Exit;
- end;
- editorID := GetElementNativeValues(e,'EDID');
- if (editorID = '') or (Pos('_',editorID) = 0) then begin
- Result := 0;
- Exit;
- end;
- LogMatch(e,editorID);
- editorID := StringReplace(editorID,'_','',[rfReplaceAll]);
- SetElementNativeValues(e,'EDID',editorID);
- end;
- // filter processing
- function Filter(e: IInterface):Boolean;
- begin
- if (Signature(e) <> 'CELL') then begin
- Result := false;
- Exit;
- end;
- editorID := GetElementNativeValues(e,'EDID');
- if (editorID = '') or (Pos('_',editorID) = 0) then begin
- Result := false;
- Exit;
- end;
- LogMatch(e,editorID);
- Result := true;
- end;
- // method button
- procedure Method_Button_Click(Sender: TObject);
- begin
- methodID := TButton(Sender).Tag;
- end;
- function _CreateMethodButton(Owner: TWinControl; MethodID: Integer; const Caption: string):TButton;
- begin
- Result := TButton.Create(Owner);
- Result.Parent := Owner;
- Result.Caption := Caption;
- Result.Tag := MethodID;
- Result.ModalResult := mrOk;
- Result.OnClick := Method_Button_Click;
- end;
- // prompts for method to use
- function MethodPrompt():Integer;
- const
- MARGIN = 8;
- BTN_HEIGHT = 32;
- var
- form: TForm;
- btn1, btn2: TButton;
- begin
- { form }
- form := TForm.Create(nil);
- form.Caption := 'Underscore cell script';
- form.SetBounds(0,0,440,120);
- form.Position := poScreenCenter;
- form.BorderWidth := MARGIN;
- { btn }
- btn1 := _CreateMethodButton(form,ID_FILTER,'<INFO> &Apply global filter to show cells including underscores...');
- btn1.SetBounds(0,0,form.ClientWidth,BTN_HEIGHT);
- btn2 := _CreateMethodButton(form,ID_FIX,'<FIX> &Remove underscores from cells in selected elements...');
- btn2.SetBounds(0,BTN_HEIGHT + MARGIN,form.ClientWidth,BTN_HEIGHT);
- form.ClientHeight := btn2.BoundsRect.Bottom;
- { display }
- if (form.ShowModal() = mrOk) then
- Result := methodID
- else
- Result := ID_NONE;
- form.Free();
- end;
- // displays the content of the log strings
- procedure DisplayReport();
- var
- form: TForm;
- memo: TMemo;
- begin
- if (log.Count = 0) then begin
- Exit;
- end;
- { form }
- form := TForm.Create(nil);
- form.Caption := Format('Report of cells with underscores (%d cells)',[log.Count]);
- form.SetBounds(0,0,680,680);
- form.Position := poScreenCenter;
- form.BorderWidth := 0;
- { memo }
- memo := TMemo.Create(form);
- memo.Parent := form;
- memo.Align := alClient;
- memo.ReadOnly := true;
- memo.ScrollBars := ssBoth;
- memo.Font.Name := 'Courier New';
- memo.Font.Size := 8;
- memo.Lines.Text := log.Text;
- { display }
- form.ShowModal();
- form.Free();
- end;
- // init for filter method
- function InitFilter():Integer;
- begin
- FilterConflictAll := False;
- FilterConflictThis := False;
- FilterByInjectStatus := False;
- FilterInjectStatus := False;
- FilterByNotReachableStatus := False;
- FilterNotReachableStatus := False;
- FilterByReferencesInjectedStatus := False;
- FilterReferencesInjectedStatus := False;
- FilterByEditorID := False;
- FilterEditorID := '';
- FilterByName := False;
- FilterName := '';
- FilterByBaseEditorID := False;
- FilterBaseEditorID := '';
- FilterByBaseName := False;
- FilterBaseName := '';
- FilterScaledActors := False;
- FilterByPersistent := False;
- FilterPersistent := False;
- FilterUnnecessaryPersistent := False;
- FilterMasterIsTemporary := False;
- FilterIsMaster := False;
- FilterPersistentPosChanged := False;
- FilterDeleted := False;
- FilterByVWD := False;
- FilterVWD := False;
- FilterByHasVWDMesh := False;
- FilterHasVWDMesh := False;
- FilterBySignature := False;
- FilterSignatures := '';
- FilterByBaseSignature := False;
- FilterBaseSignatures := '';
- FlattenBlocks := False;
- FlattenCellChilds := False;
- AssignPersWrldChild := False;
- InheritConflictByParent := True; // color conflicts
- FilterScripted := True; // use custom Filter() function
- ApplyFilter();
- Finalize(); // we have to call this manually here, since we return 1
- Result := 1;
- end;
- // init for fix method
- function InitFix():Integer;
- begin
- Result := 0;
- end;
- // main init
- function Initialize():Integer;
- begin
- log := TStringList.Create();
- case MethodPrompt() of
- ID_FILTER: Result := InitFilter();
- ID_FIX: Result := InitFix();
- else
- Result := 1;
- end
- end;
- // main finalize
- function Finalize():Integer;
- begin
- AddMessage(Format('Found %d cells containing underscores!',[log.Count]));
- DisplayReport();
- log.Free();
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement