just-ero / asl-help

Helper library for LiveSplit's auto splitting language with special features for certain game engines.
GNU General Public License v3.0
5 stars 7 forks source link

[Bug]: Game unable to find a class if the asl is opened before the game, finds after reload #10

Open mitchell-merry opened 1 year ago

mitchell-merry commented 1 year ago

What helper class does this issue occur on?

Unity

Description

Game is Bendy and the Dark Revival.

When the asl is loaded before the game, it repeatedly is unable to find the GameManager class, never - even if you leave it running for a while, if you go into levels, but if the asl is refreshed at any point then it will find it on it's next attempt.

Reproduction Steps

state("Bendy and the Dark Revival") { }

startup
{
  Assembly.Load(File.ReadAllBytes("Components/asl-help")).CreateInstance("Unity");
}

init
{
  vars.Helper.TryLoad = (Func<dynamic, bool>)(mono =>
  {
    var gm = mono["GameManager"];
    return true;
  });
}
// ...

Error Messages

Connected to game: Bendy and the Dark Revival (using default state descriptor)
Initializing
Init completed, running main methods
Searching for module with names: mono.dll, mono-2.0-bdwgc.dll, GameAssembly.dll...
  => No module found yet.
  => Retrying 2 more times in 1000ms...
  => Found mono-2.0-bdwgc.dll.
Retrieving Unity version...
  => Unity 2021.3.6f1.
  => Doesn't look right? You can set the helper's `UnityVersion` manually in 'startup {}':
     `vars.Helper.UnityVersion = new Version(2017, 2);`
Loading Unity mono.v3 structs...
  => Success.

Executing TryLoad...
Searching for image 'Assembly-CSharp'...
  => Found at 0x1FDB06B73E0.
    => class_cache.size is 11.
    => class_cache.table at 0x1FDB07D55F0.
Executing TryLoad...
Searching for image 'Assembly-CSharp'...
  => Found at 0x1FDB06B73E0.
    => class_cache.size is 11.
    => class_cache.table at 0x1FDB07D55F0.
Searching for class 'GameManager'...
  => Not found!
  => Class 'GameManager' could not be found.
TryLoad not successful.
  => Retrying in 3000ms... 
Exception thrown: 'System.ComponentModel.Win32Exception' in 'update' method:
The handle is invalid

   at ASL line 28 in 'update'

   at LiveSplit.ASL.ASLMethod.Call(LiveSplitState timer, ExpandoObject vars, String& version, Double& refreshRate, Object settings, ExpandoObject old, ExpandoObject current, Process game) 
   at LiveSplit.ASL.ASLScript.RunMethod(ASLMethod method, LiveSplitState state, String& version) 
   at LiveSplit.ASL.ASLScript.DoUpdate(LiveSplitState state) 
   at LiveSplit.UI.Components.ASLComponent.UpdateScript()
  => Found at 0x1FDB06B73E0.
    => class_cache.size is 11.
    => class_cache.table at 0x1FDB07D55F0.
Searching for class 'GameManager'...
  => Not found!
  => Class 'GameManager' could not be found.
TryLoad not successful.
  => Retrying in 3000ms...
  => Found at 0x1FDB06B73E0.
    => class_cache.size is 11.
    => class_cache.table at 0x1FDB07D55F0.
Searching for class 'GameManager'...
  => Not found!
  => Class 'GameManager' could not be found.
TryLoad not successful. 
...

Regression?

No response

Potential Causes and Fixes

A way to catch this error or somehow force a complete refresh of asl-help would be a nice option to have if TryLoad fails.