net-lisias-ksp / KSP-Recall

Recall for KSP blunders, screw ups and borks.
GNU General Public License v2.0
25 stars 2 forks source link

KSP's Monkey Patching is screwing with me. #71

Open Lisias opened 1 year ago

Lisias commented 1 year ago

Oukey. I found a Monkey Patching on KSP, and this freaking thing is screwing with me.

On 2022's Hallowing (more specifically, the weekend following it), my DLLs on A+ got screwed by the following problem:

ERR 12:27:47.935] Exception handling event onGameSceneSwitchRequested in class Startup:System.NullReferenceException: Object reference not set to an instance of an object
  at AirplanePlus.MonkeyPatching.Execute () [0x00000] in <filename unknown>:0
  at AirplanePlus.Startup.OnGameSceneSwitchRequested (FromToAction`2 data) [0x00000] in <filename unknown>:0
  at EventData`1[GameEvents+FromToAction`2[GameScenes,GameScenes]].Fire (FromToAction`2 data) [0x00000] in <filename unknown>:0

[EXC 12:27:47.941] NullReferenceException: Object reference not set to an instance of an object
        AirplanePlus.MonkeyPatching.Execute ()
        AirplanePlus.Startup.OnGameSceneSwitchRequested (FromToAction`2 data)
        EventData`1[GameEvents+FromToAction`2[GameScenes,GameScenes]].Fire (FromToAction`2 data)
        UnityEngine.DebugLogHandler:LogException(Exception, Object)
        KSPe.Util.Log.UnityLogDecorator:UnityEngine.ILogHandler.LogException(Exception, Object)
        ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
        UnityEngine.Debug:LogException(Exception)
        EventData`1:Fire(FromToAction`2)
        HighLogic:SetLoadSceneEventsAndFlags(GameScenes, Boolean)
        HighLogic:LoadScene(GameScenes)
        <SetupSystem>c__Iterator0:MoveNext()
        UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
[LOG 12:27:47.942] [HighLogic]: =========================== Scene Change : From LOADING to MAINMENU =====================

That AirplanePlus.MonkeyPatching thingy? Not mine, don't have the slighest idea from what deepness of Hell this crapness came. I can only say that this prevented me from working on the DLL for the whole weekend.

As long the clock marked midnight of Monday, the problem goes away.

I can only infer this was some kind of Easter Egg that some jerk though it could be a good idea to have hardcoded inside KSP without telling anyone about.

Also on Forum

I'm still thinking if I want to mess with this crap.

Lisias commented 1 year ago

Quoting myself from Forum, just in case:

Well… That was a weird one, and one that got me worried for a couple days (and, so, I screwed up the scheduling).

Right now, A+ needs Firespitter on some of the parts. Yes, I know that there're replacements, but I would need to ask the user to install more than one add'ons to do the FS job - and yet, it will not be good enough (I know what I'm talking, replacing Firespitter on KAX wans't satisfactory). But most people forget to install dependencies anyway, and so I shove on every add'on of mine a WatchDog that barks on you everytime you fire up KSP missing dependencies my add'ons need, and while coding it into A+ I got this weird message on my KSP.log:


[ERR 12:27:47.935] Exception handling event onGameSceneSwitchRequested in class Startup:System.NullReferenceException: Object reference not set to an instance of an object
at AirplanePlus.MonkeyPatching.Execute () [0x00000] in <filename unknown>:0
at AirplanePlus.Startup.OnGameSceneSwitchRequested (FromToAction`2 data) [0x00000] in <filename unknown>:0
at EventData`1[GameEvents+FromToAction`2[GameScenes,GameScenes]].Fire (FromToAction`2 data) [0x00000] in <filename unknown>:0

[EXC 12:27:47.941] NullReferenceException: Object reference not set to an instance of an object AirplanePlus.MonkeyPatching.Execute () AirplanePlus.Startup.OnGameSceneSwitchRequested (FromToAction2 data) EventData1[GameEvents+FromToAction2[GameScenes,GameScenes]].Fire (FromToAction2 data) UnityEngine.DebugLogHandler:LogException(Exception, Object) KSPe.Util.Log.UnityLogDecorator:UnityEngine.ILogHandler.LogException(Exception, Object) ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object) UnityEngine.Debug:LogException(Exception) EventData1:Fire(FromToAction2) HighLogic:SetLoadSceneEventsAndFlags(GameScenes, Boolean) HighLogic:LoadScene(GameScenes)

c__Iterator0:MoveNext() UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) [LOG 12:27:47.942] [HighLogic]: =========================== Scene Change : From LOADING to MAINMENU ===================== ``` > > The Exception **was not raised** from my code, and the testbed I was using was a pretty clean one, nothing but my supporting add'ons (KSPe, my fork of MM, and some utils). And I know all that code I forked or created, I inspected them (or wrote them from scratch), and there's no `MonkeyPatching` class/method/string anywhere on my repositories. > > So this stunt appears to be coming from KSP itself. I reproduced it down to KSP 1.3.1, by the way. Yep, this is lingering with us for a very long time. > > So I had something injecting code into AirplanePlus' WatchDog and causing it to bork. How I would release it this way? So I spent the weekend trying to locate it, understanding it and then trying a workaround for it (without breaking some Forum rules about modding, what's a bit of a challenge). And then the damned thing vanished! > > A bit after 31th Oct 00:00 AM (don't remember if 00:40 or 1:40 or something like that), the problem ceased to happen out of the blue. Right now I'm guessing (and guessing wildly) that this may be related to some Easter Egg code that was never finished and was forgotten on the codebase. But, again, this is a wild guess because I don't really have the slightest clue about why in the Name of the Krakens this krap fell on me on the last weekend.
Lisias commented 11 months ago

AHA!!!! I finally have positive and undeniable evidence that KSP is being Monkey Patched by our backs!! *

I'm not mad about the "feature" implemented, it appears to be good - but, hell, we need to be warned about the changes, damnit!!!. Silently patching things is what malware does, by God's sake!!

https://www.reddit.com/r/KerbalAcademy/comments/16wwkxm/ksp1_saves_are_incompatible_after_reinstalling/

* EDIT: can't affirm that, unfortunately. After thinking on the problem, I concluded I may be biased due that traumatic event that initiated this Report. I can't prove that this is not a feature that I never stomped over yet by pure luck.

Lisias commented 11 months ago

I used KDIFF3 on the affected KSP (1.4.3, by the way - they are Monkey Patching everything) with an old backup to see if the patching is being persisted on disk.

Apparently, they are not - the thing apparently is being downloaded and applied on every KSP boot.

This suggests we can block it using firewalls.

Lisias commented 11 months ago

I transferred this to KSP-Recall, as now I have undeniable evidence this is something related to KSP itself. This doesn't means I will tackle this down on KSP-Recall (or that I ever will try), but KSP-Recall is the place where I'm consolidating KSP (mis)behaviours for future reference.

Lisias commented 11 months ago

NOTE

After thinking about, I concluded that no, this is not a hard evidence of Monkey Patching after all. It may be something on KSP that I never had seen before: Absence of evidence is not evidence of absence, in order to make such bold affirmation I would had to had screwed up an savegame in the exact way I did to check this user's report before, but I don't recall doing it before and, so, I don't have how to know if this is something that was always there or not.

To be more specific, I'm talking about this message:

Screen Shot 2023-10-01 at 19 04 18

Screen Shot 2023-10-01 at 19 04 28

It's happening while trying to open a savegame that by some reason throws up an Exception while being inspected - apparently, it's just it, KSP tries to open the data file, gets an Exception (any one, by any reason) and stupidly concludes "it's not compatible" and shows the message.

The user that reported the problem coming back today telling that his problem just vanished without they knowing how is still an evidence that suggests Monkey Patching, but it's not a positive and undeniable evidence about the message being something new, or even something else being patched on their rig (besides the suggestion being strong enough, see the next paragraph):

On the other hand, this TweakScale issue is:

And now I have evidences that Module Manager (Forum) is not yelling anymore when a Reflection Exception is detected on loading, allowing users to load KSP when TweakScale was prevented from being loaded due the bug on the KSP's Assembly Loader/Resolver that happens when something else borks on loading a dependency.

Hell. This is the KSP.log of a test session made on KSP 1.8.1 with (Forum) Module Manager 4.1.2 on the same circumstances. This was the very first Module Manager to yell (besides diagnosing it incorrectly) about it. KSP.log

There's something smelling here, but there's nothing I can do about it. Past Evidences. Mirror Page 1, Page 2.

https://github.com/TweakScale/TweakScale/issues/312

— — EDIT — —

The TweakScale#312 was finally diagnosed, and it's completely unrelated to this one.

Lisias commented 9 months ago

Note to future readers: on Oct 1, I mentioned:

After thinking about, I concluded that no, this is not a hard evidence of Monkey Patching after all.

This DOES NOT RULES OUT Monkey Patching (look on the damned log, damnit - the words MonkeyPatching is explicitly mentioned on the stack dump!).

This only means that I can't use this evidence as a HARD EVIDENCE (i.e., undeniable evidence or proof) of Monkey Patching because correlation is not causality:

So, this is not a proof - but it's still an evidence that should be used together other evidences that, so, may be used to conclude if we have or not Monkey Patching being downloaded from Kraken knows where by our backs.

See https://github.com/TweakScale/TweakScale/issues/312, in special, https://github.com/TweakScale/TweakScale/issues/312#issuecomment-1828819620 , for the reasons this theory is now slightly stronger than before.

Lisias commented 9 months ago

Monkey Patching was completely ruled out on https://github.com/TweakScale/TweakScale/issues/312 .

See https://github.com/TweakScale/TweakScale/issues/312#issuecomment-1830246915 for details.

Lisias commented 9 months ago

On the other hand, this post on Forum may still be explained by Monkey Patching.