mirror of
https://github.com/HypoxiE/rimworld-add-my-music-mod.git
synced 2025-12-06 05:45:58 +00:00
changing the initialization algorithms of the mod
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -0,0 +1,5 @@
|
|||||||
|
.vdf
|
||||||
|
DLLSourceCode/**/*.dll
|
||||||
|
DLLSourceCode/bin/*
|
||||||
|
DLLSourceCode/obj/*
|
||||||
|
DLLSourceCode/References/*
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
<li>1.5</li>
|
<li>1.5</li>
|
||||||
<li>1.6</li>
|
<li>1.6</li>
|
||||||
</supportedVersions>
|
</supportedVersions>
|
||||||
|
<dependencies>
|
||||||
|
<li>ludeon.rimworld</li>
|
||||||
|
<li>brrainz.harmony</li>
|
||||||
|
</dependencies>
|
||||||
<description>
|
<description>
|
||||||
[EN]
|
[EN]
|
||||||
This mod adds the ability to put your own music in the game.
|
This mod adds the ability to put your own music in the game.
|
||||||
|
|||||||
BIN
Assemblies/AddMyMusicMod.dll
Normal file
BIN
Assemblies/AddMyMusicMod.dll
Normal file
Binary file not shown.
24
DLLSourceCode/AddMyMusicMod.csproj
Normal file
24
DLLSourceCode/AddMyMusicMod.csproj
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="0Harmony">
|
||||||
|
<HintPath>References/0Harmony.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Assembly-CSharp">
|
||||||
|
<HintPath>References/Assembly-CSharp.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine">
|
||||||
|
<HintPath>References/UnityEngine.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="UnityEngine.CoreModule">
|
||||||
|
<HintPath>References/UnityEngine.CoreModule.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
<Copy SourceFiles="$(TargetPath)" DestinationFolder="K:\SteamLibrary\steamapps\common\RimWorld\Mods\custom_music\Assemblies\" />
|
||||||
|
</Target>
|
||||||
|
</Project>
|
||||||
88
DLLSourceCode/test.cs
Normal file
88
DLLSourceCode/test.cs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
|
[StaticConstructorOnStartup]
|
||||||
|
public static class CopyDefsAtStartup
|
||||||
|
{
|
||||||
|
static CopyDefsAtStartup()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
string localPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||||
|
string localLowPath = Path.Combine(Path.GetDirectoryName(localPath), "LocalLow");
|
||||||
|
|
||||||
|
string songsGameplayXMLSourcePath = Path.Combine(localLowPath, @"Ludeon Studios\RimWorld by Ludeon Studios\AddMyMusic_data\Songs_Gameplay.xml");
|
||||||
|
string songsDBSourcePath = Path.Combine(localLowPath, @"Ludeon Studios\RimWorld by Ludeon Studios\AddMyMusic_data\music_is_here");
|
||||||
|
|
||||||
|
string modDefsDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods", "custom_music", "Defs", "SongDefs");
|
||||||
|
string modSoundsDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods", "custom_music", "Sounds", "Gameplay");
|
||||||
|
|
||||||
|
if (!Directory.Exists(modDefsDir))
|
||||||
|
Directory.CreateDirectory(modDefsDir);
|
||||||
|
|
||||||
|
string modDefsPath = Path.Combine(modDefsDir, "Songs_Gameplay.xml");
|
||||||
|
|
||||||
|
|
||||||
|
if (File.Exists(songsGameplayXMLSourcePath))
|
||||||
|
{
|
||||||
|
bool symlinkCreated = SymlinkHelper.CreateDirectorySymlink(modSoundsDir, songsDBSourcePath);
|
||||||
|
File.Copy(songsGameplayXMLSourcePath, modDefsPath, true);
|
||||||
|
Log.Message("[MyMod] Songs_Gameplay.xml скопирован в папку мода.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warning("[MyMod] Исходный файл Songs_Gameplay.xml не найден.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error("[MyMod] Ошибка при копировании Songs_Gameplay.xml: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SymlinkHelper
|
||||||
|
{
|
||||||
|
public static bool CreateDirectorySymlink(string linkPath, string targetPath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var psi = new ProcessStartInfo("cmd.exe", $"mklink /D \"{linkPath}\" \"{targetPath}\"")
|
||||||
|
{
|
||||||
|
FileName = "cmd.exe",
|
||||||
|
Arguments = $"/c mklink /D \"{linkPath}\" \"{targetPath}\"",
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
Verb = "runas"
|
||||||
|
};
|
||||||
|
|
||||||
|
using var process = Process.Start(psi);
|
||||||
|
process.WaitForExit();
|
||||||
|
|
||||||
|
string output = process.StandardOutput.ReadToEnd();
|
||||||
|
string error = process.StandardError.ReadToEnd();
|
||||||
|
|
||||||
|
if (process.ExitCode == 0)
|
||||||
|
{
|
||||||
|
Log.Message($"Symlink создан: {output}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Error($"Ошибка создания symlink: {error}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error($"Exception: {e}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<Defs>
|
|
||||||
<SongDef>
|
|
||||||
<defName>test_music_1</defName>
|
|
||||||
<clipPath>Gameplay/test_music_1</clipPath>
|
|
||||||
|
|
||||||
<!--The probability of music appearing in the game-->
|
|
||||||
<commonality>1.0</commonality>
|
|
||||||
|
|
||||||
<!--Music volume-->
|
|
||||||
<volume>1.0</volume>
|
|
||||||
|
|
||||||
<!--If true, it only plays in a combat situation-->
|
|
||||||
<tense>false</tense>
|
|
||||||
|
|
||||||
<!--If true, it only plays in a combat situation-->
|
|
||||||
<tense>false</tense>
|
|
||||||
|
|
||||||
<!--If you want to limit the time of day, delete '<!- -' and '- ->' of the desired option-->
|
|
||||||
<!--<allowedTimeOfDay>Day</allowedTimeOfDay>-->
|
|
||||||
<!--<allowedTimeOfDay>Night</allowedTimeOfDay>-->
|
|
||||||
|
|
||||||
<!--Listing the seasons in which this song is played-->
|
|
||||||
<allowedSeasons> <li>Winter</li><li>Spring</li><li>Summer</li><li>Fall</li> </allowedSeasons>
|
|
||||||
</SongDef>
|
|
||||||
<SongDef>
|
|
||||||
<defName>test_music_2</defName>
|
|
||||||
<clipPath>Gameplay/test_music_2</clipPath>
|
|
||||||
|
|
||||||
<!--The probability of music appearing in the game-->
|
|
||||||
<commonality>1.0</commonality>
|
|
||||||
|
|
||||||
<!--Music volume-->
|
|
||||||
<volume>1.0</volume>
|
|
||||||
|
|
||||||
<!--If true, it only plays in a combat situation-->
|
|
||||||
<tense>false</tense>
|
|
||||||
|
|
||||||
<!--If true, it only plays in a combat situation-->
|
|
||||||
<tense>false</tense>
|
|
||||||
|
|
||||||
<!--If you want to limit the time of day, delete '<!- -' and '- ->' of the desired option-->
|
|
||||||
<!--<allowedTimeOfDay>Day</allowedTimeOfDay>-->
|
|
||||||
<!--<allowedTimeOfDay>Night</allowedTimeOfDay>-->
|
|
||||||
|
|
||||||
<!--Listing the seasons in which this song is played-->
|
|
||||||
<allowedSeasons> <li>Winter</li><li>Spring</li><li>Summer</li><li>Fall</li> </allowedSeasons>
|
|
||||||
</SongDef>
|
|
||||||
</Defs>
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -3,37 +3,47 @@ echo This command will completely overwrite the Songs_Gameplay.xml file of this
|
|||||||
pause
|
pause
|
||||||
|
|
||||||
setlocal enabledelayedexpansion
|
setlocal enabledelayedexpansion
|
||||||
chcp 65001
|
|
||||||
echo ^<?xml version="1.0" encoding="utf-8" ?^> > Defs\SongDefs\Songs_Gameplay.xml
|
|
||||||
echo ^<Defs^> >> Defs\SongDefs\Songs_Gameplay.xml
|
|
||||||
|
|
||||||
for %%f in (Sounds\Gameplay\*) do (
|
set "localappdata=%USERPROFILE%\AppData\LocalLow"
|
||||||
|
set "mod_user_dir=%localappdata%\Ludeon Studios\RimWorld by Ludeon Studios\AddMyMusic_data"
|
||||||
|
if not exist "%mod_user_dir%" mkdir "%mod_user_dir%"
|
||||||
|
|
||||||
|
set "music_database=%mod_user_dir%\music_is_here"
|
||||||
|
if not exist "%music_database%" mkdir "%music_database%"
|
||||||
|
|
||||||
|
|
||||||
|
chcp 65001
|
||||||
|
echo ^<?xml version="1.0" encoding="utf-8" ?^> > "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
|
echo ^<Defs^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
|
|
||||||
|
for %%f in ("%music_database%\*") do (
|
||||||
set sound_name=%%~nf
|
set sound_name=%%~nf
|
||||||
|
|
||||||
echo ^<SongDef^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<SongDef^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<defName^>!sound_name!^</defName^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<defName^>!sound_name!^</defName^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<clipPath^>Gameplay/!sound_name!^</clipPath^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<clipPath^>Gameplay/!sound_name!^</clipPath^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo. >> Defs\SongDefs\Songs_Gameplay.xml
|
echo. >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<^^!--The probability of music appearing in the game--^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<^^!--The probability of music appearing in the game--^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<commonality^>1.0^</commonality^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<commonality^>1.0^</commonality^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo. >> Defs\SongDefs\Songs_Gameplay.xml
|
echo. >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<^^!--Music volume--^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<^^!--Music volume--^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<volume^>1.0^</volume^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<volume^>1.0^</volume^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo. >> Defs\SongDefs\Songs_Gameplay.xml
|
echo. >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<^^!--If true, it only plays in a combat situation--^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<^^!--If true, it only plays in a combat situation--^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<tense^>false^</tense^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<tense^>false^</tense^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo. >> Defs\SongDefs\Songs_Gameplay.xml
|
echo. >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<^^!--If you want to limit the time of day, delete '^<^^!- -' and '- -^>' of the desired option--^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<^^!--If you want to limit the time of day, delete '^<^^!- -' and '- -^>' of the desired option--^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<^^!--^<allowedTimeOfDay^>Day^</allowedTimeOfDay^>--^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<^^!--^<allowedTimeOfDay^>Day^</allowedTimeOfDay^>--^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<^^!--^<allowedTimeOfDay^>Night^</allowedTimeOfDay^>--^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<^^!--^<allowedTimeOfDay^>Night^</allowedTimeOfDay^>--^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo. >> Defs\SongDefs\Songs_Gameplay.xml
|
echo. >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<^^!--Listing the seasons in which this song is played--^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<^^!--Listing the seasons in which this song is played--^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
echo ^<allowedSeasons^> ^<li^>Winter^</li^>^<li^>Spring^</li^>^<li^>Summer^</li^>^<li^>Fall^</li^> ^</allowedSeasons^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^<allowedSeasons^> ^<li^>Winter^</li^>^<li^>Spring^</li^>^<li^>Summer^</li^>^<li^>Fall^</li^> ^</allowedSeasons^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
|
|
||||||
echo ^</SongDef^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^</SongDef^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
|
echo. >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
)
|
)
|
||||||
|
|
||||||
echo ^</Defs^> >> Defs\SongDefs\Songs_Gameplay.xml
|
echo ^</Defs^> >> "%mod_user_dir%\Songs_Gameplay.xml"
|
||||||
|
|
||||||
echo Songs_Gameplay.xml overwritten. After restarting the game, music will be added.
|
echo Songs_Gameplay.xml overwritten. After restarting the game, music will be added.
|
||||||
pause
|
pause
|
||||||
Reference in New Issue
Block a user