Rabadash8820 / UnityAssemblies

Simple, forward-compatible references to any Unity DLL on any platform.
MIT License
109 stars 3 forks source link

Question: Is it worth using this for mod development #9

Closed PhilPJL closed 3 years ago

PhilPJL commented 3 years ago

On the face of it this package seems like a good idea, but for mod development I need to reference Assembly-CSharp.dll from an installed game, so I may as well reference the Unity assemblies in the game folder. So would you recommend this for mod dev or not?

In any case I can't work out how to reference this dll.
image

Rabadash8820 commented 3 years ago

@PhilPJL Interesting use case. I think you are right; for modding, you would probably want to reference the UnityEngine.* DLLs within the built game via a relative path, to be sure you're always working with the same version of the Unity API that the game uses. If you knew you had the same version of Unity as the game's developers installed on your machine, then you could use this package to reference the DLLs in that Unity installation. However, there's probably no way to be sure you've installed the correct Unity version, short of contacting the game's developers.

That said, the structure of built Unity players isn't very well-documented, so I'm not even sure what paths you would use. For standalone builds, it looks like you could reference UnityPlayer.dll, but idk about mobile/console, and if the game uses IL2CPP then you'll be in even more trouble because a lot of the managed and byte code was probably stripped out during build. You might actually be better off trying to install the corresponding Unity version in that case. I'm not very familiar with modding Unity games in general though, clearly 🤷‍♂️.

If you just want to reference TextMesh Pro from a Unity project, not a player, then you can do the following: define a property in your project file called UnityProjectPath set to the root of your Unity project, then add the following reference:

<Reference Include="$(UnityProjectPath)\$(UnityScriptAssembliesPath)\Unity.TextMeshPro.dll" Private="false" />
PhilPJL commented 3 years ago

Thanks for the feedback. Since all required files are in the game's \managed folder, I decided to go with using an environment variable to set the base path.

<Project Sdk="Microsoft.NET.Sdk" InitialTargets="CheckEnvironmentVars">

<!-- etc -->

<Target Name="CheckEnvironmentVars">
    <Error Text="Please set the SolastaInstallDir environment variable." Condition="'$(SolastaInstallDir)' == ''" ContinueOnError="false" />
</Target>

<ItemGroup>
    <Reference Include="Assembly-CSharp">
        <HintPath>$([System.IO.Path]::Combine($(SolastaInstallDir), 'Solasta_Data\Managed\Assembly-CSharp.dll'))</HintPath>
        <Private>false</Private>
    </Reference>
    <Reference Include="Unity.TextMeshPro">
        <HintPath>$([System.IO.Path]::Combine($(SolastaInstallDir), 'Solasta_Data\Managed\Unity.TextMeshPro.dll'))</HintPath>
        <Private>false</Private>
    </Reference>
    <Reference Include="UnityEngine.CoreModule">
        <HintPath>$([System.IO.Path]::Combine($(SolastaInstallDir), 'Solasta_Data\Managed\UnityEngine.CoreModule.dll'))</HintPath>
        <Private>false</Private>
    </Reference>
    <Reference Include="UnityEngine.UI">
        <HintPath>$([System.IO.Path]::Combine($(SolastaInstallDir), 'Solasta_Data\Managed\UnityEngine.UI.dll'))</HintPath>
            <Private>false</Private>
    </Reference>
</ItemGroup>

<!-- etc -->