Advertisement
Guest User

S.T.A.L.K.E.R. FONT INI FILE RESIZE SCRIPT

a guest
Apr 30th, 2021
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.01 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #####################################################################################################
  4. #                                                                                                   #
  5. #                        S.T.A.L.K.E.R. FONT INI FILE RESIZE SCRIPT                                 #
  6. #                                                                                                   #
  7. #                                       by RENΓ‰ KUHS                                               #
  8. #                                                                                                   #
  9. #####################################################################################################
  10.  
  11. use strict;
  12. use warnings;
  13.  
  14. use Path::Tiny;
  15. use autodie; # die if problem reading or writing a file
  16.  
  17. my $dir = path("H:/Games/S.T.A.L.K.E.R. - Anomaly/tools/_unpacked/textures/ui"); # /INSERT PATH TO FONT INI FILES HERE
  18.  
  19. my $file_r = $dir->child("ui_font_letter_25_1600.ini");
  20. my $file_w = $dir->child("ui_font_letter_25_1600.ini_w");
  21.  
  22. # openr_utf8() returns an IO::File object to read from
  23. # with a UTF-8 decoding layer
  24. my $file_handle_r = $file_r->openr_utf8();
  25. # Also open a file for writing
  26. my $file_handle_w = $file_w->openw_utf8();
  27.  
  28. # Indicates whether the following lines are symbol coordinates
  29. my $contains_coords = 0;
  30.  
  31. my $line = "";
  32.  
  33. # This while loop checks to see whether this file contains symbol coordinates
  34. while ( ( $contains_coords == 0 ) && ( $line = $file_handle_r->getline() ) )
  35.     {
  36.     # If the current line contains the appropriate string,
  37.     # we set the appropriate indicator and break the loop
  38.     if ( index( $line, "[symbol_coords]" ) != -1 )
  39.         {
  40.         $contains_coords = 1;
  41.        
  42.         # Continue retrieving lines until the "height" variable is found
  43.         # (this is usually the very next line, but better safe...)
  44.         $file_handle_w->print( $line );
  45.         while ( ( index( $line, "height =" ) == -1 ) && ( $line = $file_handle_r->getline() ) )
  46.             {
  47.             # If "height" is on current line, quadruple it's value
  48.             if ( index( $line, "height =" ) != -1 )
  49.                 {
  50.                 my $height = substr( $line, 8 );
  51.                 $height *= 2;
  52.                 $line = substr( $line, 0, 8 ) . " " . $height . "\n";
  53.                 }
  54.             else # No need to write current line to new file here if current line has "height"
  55.                  # since that will occur outside of this loop below
  56.                 {
  57.                 $file_handle_w->print( $line );
  58.                 }
  59.             }
  60.         }
  61.        
  62.     # Write the current line to the new file
  63.     $file_handle_w->print( $line );
  64.     }
  65.  
  66. # If the file was previously found to contain symbol coordinates,
  67. # the rest of the lines in the file are treated as such
  68. if ( $contains_coords )
  69.     {
  70.     while ( my $line = $file_handle_r->getline() )
  71.         {
  72.         # Split line by comma delimiter
  73.         my @coords = split( ',', substr( $line, 5 ) );
  74.        
  75.         # Variable which holds the processed line,
  76.         # initialised with first 5 chars of original line
  77.         my $line_proc = substr( $line, 0, 5 );
  78.        
  79.         foreach my $coord ( @coords )
  80.             {
  81.             # Quadruple coordinate (this removes spaces but no biggie)
  82.             $coord *= 2;
  83.            
  84.             # Append processed coordinate to line
  85.             $line_proc = $line_proc . " " . $coord . ",";
  86.             }
  87.        
  88.         # Remove extra comma at end of line
  89.         $line_proc = substr( $line_proc, 0 ,-1 );
  90.        
  91.         # Write the current line to the new file
  92.         $file_handle_w->print( $line_proc . "\n" );
  93.         }
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement