If you try to mod a static method you will end up with a unwanted behaviour of the code.
If the modded method is called from another class it will call the overwritten method, but if it is called from the original class the original method is called.
In addition to that you can't call the original Method from the modded one, because super is not available on static methods and otherwise you would end up with a stack overflow
Description
Details
- Severity
- Tweak
- Resolution
- Open
- Reproducibility
- Always
- Operating System
- Windows 10 x64
- Category
- General
class TestClassLB {
static void TestMethod() {
TestMethod2();
}
static void TestMethod2() {
Print("Original TestMethod");
}
}
modded class TestClassLB {
static void TestMethod2() {
Print("Modded TestMethod");
}
}
calling "TestClassLB.TestMethod()" will not output "Modded TestMethod" as you would expect, but will output "Original TestMethod"
but calling it directly with "TestClassLB.TestMethod2()" will output "Modded TestMethod" as expected.
it would be great to have a way to call the original method from the modded one with some kind of "SUPER.TestMethod2()" and make the original method invoke the modded one instead of the original one, like it's done everywhere else too
Event Timeline
I just ran into this while going through the steps required to add a new liquid type.
InspectMenuNew.UpdateItemInfoLiquidType() is static and needs to know about every liquid type.
Why do we even have to mod static methods like that one and mess with the UI layer? Every other aspect of adding a new item and a liquid to go with it is pretty straightforward.
This one little widget only needs to know the name (which is already in cfgLiquidDefinitions) and color (which confusingly is not in cfgLiquidDefinitions) of the liquid to do it's thing.
So maybe the real problem isn't that we cannot mod static methods. Maybe the real problem is that we shouldn't have to mess with core game mechanics to do little things.