ruffle-rs / ruffle

A Flash Player emulator written in Rust
https://ruffle.rs
Other
15.64k stars 809 forks source link

Looping intro in Newgrounds version of Bloons TD 4 #11197

Open n0samu opened 1 year ago

n0samu commented 1 year ago

Describe the bug

In the Newgrounds version of Bloons Tower Defense 4, the intro loops and the game cannot be played.

Errors are:

ERROR ruffle_core::timer: Unhandled AVM2 error in timer callback: Error: flash.display.Loader.unload - not yet implemented
        at flash.display::Loader/unload()
        at mochicrypt::Preloader/finish()
        at mochicrypt::Preloader/ad_finished()
        at MethodInfo-48()
ERROR run_frame: ruffle_core::avm2::events: Error dispatching event EventObject(EventObject { type: "addedToStage", class: flash.events::Event, ptr: 0x19d9a95b2f8 }) to handler FunctionObject(FunctionObject { ptr: 0x19d9a44fa88 }) : TypeError: Error #1009: Cannot access a property or method of a null object reference. (accessing field: indexOf)
        at BTD4/addedToStageResult()
ERROR run_frame:run_all_phases_avm2: ruffle_core::display_object::movie_clip: Error occured when running AVM2 frame script: TypeError: Error #1009: Cannot access a property or method of a null object reference. (accessing field: doublecash)
        at bloonstd4_fla::chooseDiffbox_204/updateOptions()
        at bloonstd4_fla::chooseDiffbox_204/frame1()

The problem might just be that Loader.unload is unimplemented.

Expected behavior

The game should work as the Kongregate version does.

Affected platform

Desktop app

Operating system

Windows 10

Browser

No response

Additional information

Mentioned in #11193.

Lord-McSweeney commented 1 year ago

This is because of this code inside the Mochicrypted SWF:

public dynamic class BTD4 extends MovieClip {
    public function BTD4() {
        ...
        addEventListener(Event.ADDED_TO_STAGE,addedToStageResult);
    }
}
      internal function addedToStageResult(param1:Event) : *
      {
         ...
         var _loc2_:* = loaderInfo.url;
         ...
         if(Capabilities.playerType != "External" && false == false)
         {
            trace("fneh");
            if(_loc2_.indexOf("ninjakiwifiles.com") == -1)
            {
            }
         }

The reason LoaderInfo.url isn't being set is because it was loaded with Loader.loadBytes. However, I'm not sure if .url should be set to an empty string or the string of the parent SWF, since this is reliant on the behavior of the FP plugin.

(this is the important error):

Error dispatching event EventObject(EventObject { type: "addedToStage", class: flash.events::Event, ptr: 0x19d9a95b2f8 }) to handler FunctionObject(FunctionObject { ptr: 0x19d9a44fa88 }) : TypeError: Error #1009: Cannot access a property or method of a null object reference. (accessing field: indexOf)
        at BTD4/addedToStageResult()