KosmosisDire / TeammateRevive

A simple Risk of Rain 2 mod that allows teammates to revive their fallen colleagues.
4 stars 9 forks source link

Fix for "Survivors of the Void" DLC update #26

Closed nathanpovo closed 2 years ago

nathanpovo commented 2 years ago

Fixes issue https://github.com/KosmosisDire/TeammateRevive/issues/24

The static methods ArtifactAPI.Add() and BuffAPI.Add were deprecated with https://github.com/risk-of-thunder/R2API/pull/338/ and they had to be replaced with ContentAddition.AddArtifactDef() and ContentAddition.AddBuffDef() respectively.

The BepInEx NuGet package feed was used for assembly references to match the changes in R2API.

nathanpovo commented 2 years ago

I am getting the following error when trying to start the game with the plugin

[Error: Unity Log] TypeLoadException: VTable setup of type TeammateRevive.Skull.SyncSkullMessage failed
Stack trace:
System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) (at <44afb4564e9347cf99a1865351ea8f4a>:IL_001B)
System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at <44afb4564e9347cf99a1865351ea8f4a>:IL_00A8)
System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <44afb4564e9347cf99a1865351ea8f4a>:IL_0009)
System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) (at <44afb4564e9347cf99a1865351ea8f4a>:IL_0027)
System.Activator.CreateInstance[T] () (at <44afb4564e9347cf99a1865351ea8f4a>:IL_0015)
R2API.Networking.NetworkingAPI.RegisterMessageTypeInternal[TMessage] () (at <2ca02759febe4ad8b85b1a9524693cae>:IL_0001)
R2API.Networking.NetworkingAPI.RegisterMessageType[TMessage] () (at <2ca02759febe4ad8b85b1a9524693cae>:IL_0019)
TeammateRevive.MainTeammateRevival.Awake () (at <17b4492572634c7c969743fb5510ea19>:IL_0018)
UnityEngine.GameObject:AddComponent(Type)
BepInEx.Bootstrap.Chainloader:Start()
FlashWindow:.cctor()

System details: Windows 10 Risk of Rain 2 version 1.2.1.0 BepInEx version 5.4.1902 R2API built from commit https://github.com/risk-of-thunder/R2API/commit/200bb6981f07499effc3108502dcfbaf4d190766

nathanpovo commented 2 years ago

Managed to solve the exception by doing a clean install in the thunderstore mod manager. The logs from BepInEx when starting the game are LogOutput.log

Seems to be working fine in singleplayer; I haven't had the chance to try it out in a multiplayer game.

KosmosisDire commented 2 years ago

I can probably play a quick game to test, message me on discord if you want. Username is in the readme

nathanpovo commented 2 years ago

I got somebody to test it out with today.

nathanpovo commented 2 years ago

@EndlessEden how are you building the revive plugin? what version of R2API and BepInEx are you using? I am not seeing any errors in the bepinex log file when loading the plugin.

Log file to compare to - LogOutput.log

@amadare42 about your comment on Unity.Networking, would I not start getting compile errors if that was the case? I was getting some compilation errors that might be related but they were fixed when I updated the packages to the latest versions to match R2API.

nathanpovo commented 2 years ago

The following dependencies will probably need to be updated:

amadare42 commented 2 years ago

@nathanpovo Well, as I said my testing was only preliminary, but swapping UnityEngine.Networking.dll with com.unity.multiplayer-hlapi.Runtime.dll compiled for me, so I assumed it also fixed assembly referencing issue. If just updating references to unity libraries fixed this for you, then it should be fine. Honestly, I'm not sure what developers did with unity binaries, but UnityEngine.Networking.dll is now missing in Managed directory.

nathanpovo commented 2 years ago

@nathanpovo Well, as I said my testing was only preliminary, but swapping UnityEngine.Networking.dll with com.unity.multiplayer-hlapi.Runtime.dll compiled for me, so I assumed it also fixed assembly referencing issue. If just updating references to unity libraries fixed this for you, then it should be fine. Honestly, I'm not sure what developers did with unity binaries, but UnityEngine.Networking.dll is now missing in Managed directory.

To be honest, I don't have any experience with unity; I have no idea where to find those DLLs 😅

I followed the example of R2API and deleted all the unity DLLs and replaced them with a NuGet package and it worked.

nathanpovo commented 2 years ago

Managed to test it a bit.

The plugin works; I could revive my teammate just fine and they could revive me.

However, the area surrounding the dead player is solid magenta colour instead of whatever it usually is (I really thought I took a screenshot but I can't find it anywhere).

Log file of the run - LogOutput.log

Also, when choosing an uncommon item with the artifact of command, the items are a bit cramped. I am not sure if a new item has been added with the DLC update and I don't remember how it used to look.

image

EndlessEden commented 2 years ago

@EndlessEden how are you building the revive plugin? what version of R2API and BepInEx are you using? I am not seeing any errors in the bepinex log file when loading the plugin.

Please ignore my earlier reply, in my haste i stupidly forgot to switch branches and cloned only the main branch.

As far as compiling VS2022, R2API:4.0.11, BepInEX:5.4.1902 - just for reference.

amadare42 commented 2 years ago

@nathanpovo I think command screen looks okay. I don't think we need to address this as part of this mod. There are some ui mods that improve this screen. And yes, revive sphere is properly messed up, I think material failed to load, so customprefabs is probably needed to be change. I don't have unity project to check what's going on there, but probably some names were changed. @KosmosisDire, please take a look at that when you'll have time. image

Here is screenshot from early development iteration on how it should look: image

nathanpovo commented 2 years ago

I am going over the bepinex log file from my run and I couldn't find any relevant errors from the TeammateRevival plugin.

Is the plugin not using the bepinex logger?

amadare42 commented 2 years ago

@nathanpovo I would presume, following code is returning null so no actual exception is thrown: image

KosmosisDire commented 2 years ago

@amadare42 @nathanpovo Yeah, looks like something is wrong with the stubbed shaders. I doubt people have created updated stubbed shaders yet and I don't know how to. It's basically the material from the teleporter area but it only shows the edge along the ground. I suppose the workaround would be to copy that material at runtime (it's probably in the resources folder or something) and tweak the material properties from code to make it show only the edge part. I am pretty busy with school until break starting this weekend. So, I can take a look at it this weekend if it's still a problem.

You should be able to figure out the name of the material by looking at the name of the material it's trying to load there, I think.

If you manage to find the material and make a copy of it in code, the docs (Shaders) and the docs (Materials) would probably be very helpful for actually setting the properties, and figuring out which properties to change.

Also, make sure to copy the material, not the shader.

nathanpovo commented 2 years ago

I updated the method that loads the shaders to the following

static void ReplaceStubbedShaders(AssetBundle bundle)
{
    Log.Debug($"Replacing the stubbed shaders of the {bundle.name} asset bundle");

    var materialsL = bundle.LoadAllAssets<Material>();

    Log.Debug($"Found {materialsL.Length} materials in the asset bundle");

    foreach (Material material in materialsL)
    {
        Log.Debug($"Loading the material {material.name}");

        if (material.shader.name.StartsWith("StubbedShader"))
        {
            Log.Debug($"Loading the stubbed shared for shader {material.shader.name}");

            string shaderPath = $"shaders{material.shader.name.Substring(13)}";
            Shader materialShader = UnityEngine.Resources.Load<Shader>(shaderPath);

            if (materialShader is null)
            {
                Log.Warn($"Could not find the shader for material {material.name} at the path {shaderPath}");
            }
            else
            {
                Log.Debug($"Loaded the stubbed shared {materialShader.name} from the path {shaderPath}");
            }

            material.shader = materialShader;

            Materials.Add(material);
        }
        else
        {
            Log.Debug("The shader was not loaded because it is not a stubbed shader");
        }
    }
}

and I got the following logs

[Debug  :TeammateRevival] Loading assets...
[Debug  :TeammateRevival] [TeammateRevive.Resources.AddedAssets.LoadSkullPrefab:22] called
[Debug  :TeammateRevival] Replacing the stubbed shaders of the customprefabs asset bundle
[Debug  :TeammateRevival] Found 4 materials in the asset bundle
[Debug  :TeammateRevival] Loading the material matDeathMark
[Debug  :TeammateRevival] The shader was not loaded because it is not a stubbed shader
[Debug  :TeammateRevival] Loading the material matDrip
[Debug  :TeammateRevival] The shader was not loaded because it is not a stubbed shader
[Debug  :TeammateRevival] Loading the material matFront
[Debug  :TeammateRevival] The shader was not loaded because it is not a stubbed shader
[Debug  :TeammateRevival] Loading the material matTotemRangeIndicator
[Debug  :TeammateRevival] Loading the stubbed shared for shader StubbedShader/fx/hgintersectioncloudremap
[Warning:TeammateRevival] Could not find the shader for material matTotemRangeIndicator at the path shaders/fx/hgintersectioncloudremap
[Warning: Unity Log] The referenced script (UnityEngine.Networking.NetworkIdentity) on this Behaviour is missing!
[Warning: Unity Log] The referenced script on this Behaviour (Game Object 'PlayerDeathPoint') is missing!
[Debug  :     R2API] Hook added by assembly: R2API.dll for: RoR2.Util.IsPrefab
[Warning: Unity Log] The referenced script (UnityEngine.Networking.NetworkIdentity) on this Behaviour is missing!
[Warning: Unity Log] The referenced script on this Behaviour (Game Object 'PlayerDeathPoint') is missing!
[Warning: Unity Log] The referenced script on this Behaviour (Game Object 'PlayerDeathPoint') is missing!
[Debug  :TeammateRevival] Skull updated! 
[Debug  :TeammateRevival] Replacing the stubbed shaders of the reducehp asset bundle
[Debug  :TeammateRevival] Found 3 materials in the asset bundle
[Debug  :TeammateRevival] Loading the material revive_shrine
[Debug  :TeammateRevival] Loading the stubbed shared for shader StubbedShader/fx/hgcloudremap
[Warning:TeammateRevival] Could not find the shader for material revive_shrine at the path shaders/fx/hgcloudremap
[Debug  :TeammateRevival] Loading the material shrine_material
[Debug  :TeammateRevival] The shader was not loaded because it is not a stubbed shader
[Debug  :TeammateRevival] Loading the material silver_material
[Debug  :TeammateRevival] The shader was not loaded because it is not a stubbed shader

Unfortunately, I have no idea how materials and shaders work so I am now lost 😕

@amadare42 @KosmosisDire where is the method trying to load the shaders from?

amadare42 commented 2 years ago

@nathanpovo It is loaded by unity itself. Stubbed shaders are just empty shaders that are overridden by actual in-game resources. You can check them by ripping game resources using https://github.com/AssetRipper/AssetRipper and checking them out in Unity. If you for some reason cannot/don't want to do this, don't worry - me or @KosmosisDire will have time for that next week (or maybe even in weekend).

amadare42 commented 2 years ago

@nathanpovo @KosmosisDire okay, I found how to fix issue with shaders. Hopoo games did indeed changed place where those shaders are located. But in their infinite wholesomeness, they created LegacyResourcesAPI for mod developers to be able to access resources as usual. This change fixed shader for me: image

I can see another problem though. For some reason Charon's Obol doesn't get displayed on character models. They probably changes something about item display rules. I'll try to looks into it as well.

amadare42 commented 2 years ago

Beforementioned LegacyResourceAPI should be used for ReviveRegen.cs as well. And for all that is holy and unholy and cannot find the reason why Obol doesn't get displayed on character. But I guess this feature isn't that important, I bet a lot of users didn't even notice it is displayed on character. We can release new version without it. Maybe I fix it later.

KosmosisDire commented 2 years ago

We can release new version without it. Maybe I fix it later.

That sounds good to me. Better to get it out sooner I guess since people are just waiting for it to work again

nathanpovo commented 2 years ago

I'll add a commit to use the legacy resources, then.

Are there any other major things that need to be tested before releasing a fix?

KosmosisDire commented 2 years ago

Hey sorry that took me so long, it's been merged. I'll build and upload in a few hours. Has the versioning, manifest, and readme been updated? If not I'll do that.

nathanpovo commented 2 years ago

No, the version, and the manifest were not updated.

amadare42 commented 2 years ago

Btw, @nathanpovo thanks for you work! It helped quite a bit.

nathanpovo commented 2 years ago

Happy to be able to help!

Thank you for creating this awesome mod.