Jump to content
Korean Random

Помогите дописать bat на мод


Recommended Posts

Здравствуйте.

Я совершенно не владею программированием и учиться поздновато, с помощью Гугла делаю мод на загрузочный экран (там две картинки появляются в ходе загрузки) мир танков (РУ-Леста).

Первый загрузочный экран можно поменять в папке \loading\ файл login_bg.

Второй за ним экран имеет поверхностный фон в  папке \ loading\ файл vignette_loading.

Этот фон можно использовать как заставку.

Всё для этого нашел и сделал мод, одни и те же свои картинки появляются на экране загрузки.  

Учитывая, что на форуме танков никто не подсказал и я нигде не нашел, из какой папки берутся картинки - пошел другим путем.

Написал bat, ярлык помещается в автозагрузку, при каждом запуске винды он удаляет старый экран, копирует рандомно новую картинку и переименовывает в нужный файл.

Пути прописаны к моему моду в текущей версии игры и к моему расположению дистрибутива игры.

Скрипт работает, оптимизация не требуется.

Но если у юзеров разное расположение игры и изменится версия игры - работать не будет.

Пожалуйста, помогите. Как сделать путь:  

set "src=C:\Games\Tanki\res_mods\1.33.0.0\gui\maps\loading\Wallpaper_vignette_loading"

set "dest=C:\Games\Tanki\res_mods\1.33.0.0\gui\maps\loading"

так, чтобы не пришлось каждому пользователю переписывать под себя (а также при выходе очередного патча)?

Файл bat находится в папке \loading\.

От С до гуи C:\Games\Tanki\res_mods\1.33.0.0\gui      -    нужно чем-то заменить.

Вот мой скирпт, первая часть  (работает):

@echo off

del *vignette_loading*

set "src=C:\Games\Tanki\res_mods\1.33.0.0\gui\maps\loading\Wallpaper_vignette_loading"

set "dest=C:\Games\Tanki\res_mods\1.33.0.0\gui\maps\loading"

set "ext=.png"

set "number=1"

(

dir/a-d/b "%src%\*%ext%"

)|(

cmd/v/c "for /f "delims=" %%i in ('more' do @echo !random!:%%i"

)|(

sort

)|(

findstr/n .

)|(

cmd/c "for /f "tokens=1,3 delims=:" %%i in ('more' do @copy/y "%src%\%%j" "%dest%"& if %%i equ %number% exit/b"

)

ren vignette*.png vignette_loading.png

echo Login screensaver change completed

timeout 3

exit/b

 

Спасибо.

Link to comment
Short link
Share on other sites

@Puncha22 Here, try this (I haven't tested it).

 

@echo off
setlocal enabledelayedexpansion

REM --- Settings ---
set "target_filename=vignette_loading.png"      REM Target filename
set "source_subdir=Wallpaper_vignette_loading"  REM Name of the subfolder with source wallpapers
set "source_pattern=*.png"                      REM Wallpaper file pattern (can be *.jpg, *.png, etc.)
REM --- End of Settings ---

REM Define paths relative to the location of this bat file
set "dest_dir=%~dp0"
set "src_dir=%~dp0%source_subdir%\"

REM Check if the source wallpaper folder exists
if not exist "%src_dir%" (
    echo ERROR: Source wallpaper folder not found:
    echo %src_dir%
    goto end_script
)

REM --- Random file selection logic ---
REM Count the number of files in the src_dir folder
set "count=0"
for %%f in ("%src_dir%%source_pattern%") do (
    set /a "count+=1"
    set "file[!count!]=%%~nxf" REM Save the filename + extension into an "array"
)

REM Check if any files were found
if !count! equ 0 (
    echo ERROR: No files found in %src_dir% matching the pattern '%source_pattern%'.
    goto end_script
)

REM Select a random index from 1 to count
set /a "random_index=(%RANDOM% %% count) + 1"

REM Get the name of the random file
set "random_file=!file[%random_index!]!"

REM --- Performing operations ---
set "source_file_full=%src_dir%!random_file!"
set "target_file_full=%dest_dir%%target_filename%"

REM Delete the old target file (suppress error if it doesn't exist)
del "%target_file_full%" > nul 2>&1

REM Copy the selected random file with the target name
copy /y "%source_file_full%" "%target_file_full%" > nul

REM Check the copy result
if errorlevel 1 (
    echo ERROR: Failed to copy !random_file! to %target_filename%
    goto end_script
)

echo Loading screen splash successfully changed to: !random_file!
echo Target file: %target_file_full%

:end_script
echo.
REM Pause before closing the window (optional)
timeout /t 5 /nobreak > nul

endlocal
exit /b

 

Edited by Bazooka
Link to comment
Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...