Open solomode0001 opened 6 days ago
In v2.1.1 I added potential crash fix, try.
The crash previously encountered when using GetMethods() has been resolved. However, the intended purpose of the GetMethods() function remains unclear.
Currently, the code utilizes GetMethods() on a delegate instance:
void (*_SpawnManager)(void*,float);
void SpawnManager(void* instance, float deltaTime) {
_SpawnManager(instance, deltaTime);
auto OnEnemySpawn = *(Action<void*>**)((uint64_t)instance + 0x40);
if (OnEnemySpawn) {
BNM_LOG_INFO("%s::%s", OnEnemySpawn->delegate.method->klass->name, OnEnemySpawn->delegate.method->name);
auto methods = OnEnemySpawn->GetMethods();
for (const auto& method : methods) {
BNM_LOG_INFO(method.str().c_str());
}
}
}
logs:
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
SpawnDirector::OnEnemySpawn
While GetMethods() seems to be functional, its practical application in this context is not evident.
Suggestion: It would be beneficial to introduce a dedicated function for extracting relevant information about the target method associated with the delegate (in this case, OnEnemySpawn). This function could potentially provide access to details such as:
Having such a function would improve clarity and facilitate easier manipulation and inspection of the delegate's target method. This issue serves to both inquire about the intended use of GetMethods() and propose the implementation of a more specific method information retrieval function for delegates.
In v2.1.2 I fixed issue when only one method exists in Delegate. So your code:
auto methods = OnEnemySpawn->GetMethods();
for (const auto& method : methods) {
BNM_LOG_INFO(method.str().c_str());
}
Will log method SpawnDirector::OnEnemySpawn
.
About suggestion, BNM already has API for getting almost all info that you mentioned using BNM::MethodBase::str()
(that you use in your code).
Example output:
[mscorlib.dll]::[System]::[Int32] [Assembly-CSharp.dll]::[]::[Delegates].(<Start>b__8_2){arguments count: 2}
There is an issue when attempting to retrieve methods using GetMethods on an Action delegate within a MulticastDelegateBase. This consistently leads to a crash.
log:
code: