Skip to content

Commit

Permalink
core: Make the form loader use Windows-1252 if SWF version <= 5
Browse files Browse the repository at this point in the history
The form loader now loads files using Windows-1252 if the SWF version is
smaller than 6. This roughly matches Flash's behaviour (Flash uses
Windows-1252 on Windows, on macOS a slightly different custom encoding
is used).
Previously, UTF-8 has been (wrongly) used for all SWF files if
System#useCodepage hasn't been set to true, leading to incorrectly
displayed characters.
  • Loading branch information
Korne127 committed Jun 19, 2024
1 parent 6cc434a commit df017bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/src/avm1/globals/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ pub struct SystemProperties {
/// If true then settings should be saved and read from the exact same domain of the player
/// If false then they should be saved to the super domain
pub exact_settings: bool,
/// If true then the system codepage should be used instead of unicode for text files
/// If false then unicode should be used
/// If true, the system codepage should be used for text files
/// If false, UTF-8 should be used for SWF version >= 6 and ISO Latin-1 for SWF version <= 5
pub use_codepage: bool,
/// The capabilities of the player
pub capabilities: SystemCapabilities,
Expand Down
5 changes: 4 additions & 1 deletion core/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::tag_utils::SwfMovie;
use crate::vminterface::Instantiator;
use crate::{avm2_stub_method, avm2_stub_method_context};
use chardetng::EncodingDetector;
use encoding_rs::UTF_8;
use encoding_rs::{UTF_8, WINDOWS_1252};
use gc_arena::{Collect, GcCell};
use indexmap::IndexMap;
use ruffle_render::utils::{determine_jpeg_tag_format, JpegTagFormat};
Expand Down Expand Up @@ -1257,6 +1257,9 @@ impl<'gc> Loader<'gc> {
// Convert the text into UTF-8
utf8_string = encoding.decode(&body).0;
utf8_string.as_bytes()
} else if activation.context.swf.version() <= 5 {
utf8_string = WINDOWS_1252.decode(&body).0;
utf8_string.as_bytes()
} else {
&body
};
Expand Down

0 comments on commit df017bc

Please sign in to comment.