{"id":45,"date":"2025-07-14T15:34:15","date_gmt":"2025-07-14T15:34:15","guid":{"rendered":"https:\/\/blogs.scummvm.org\/superlemon\/?p=45"},"modified":"2025-07-14T16:41:44","modified_gmt":"2025-07-14T16:41:44","slug":"45","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/superlemon\/2025\/07\/14\/45\/","title":{"rendered":"Bringing everything together!"},"content":{"rendered":"<p>This week was the most productive out of all the weeks until now (or maybe it feels like it). This week, I combined everything together. Until now, I was writing the logic of each resource to be written separately, dumping the file in the <code>.\/dumps<\/code> folder and writing only that chunk in that file. So, I was checking the loading of only one resource at once. I wasn&#8217;t even recalculating the offsets.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-51\" src=\"https:\/\/blogs.scummvm.org\/superlemon\/wp-content\/uploads\/sites\/79\/2025\/07\/Screenshot_20250714_203733-300x115.png\" alt=\"\" width=\"300\" height=\"115\" srcset=\"https:\/\/blogs.scummvm.org\/superlemon\/wp-content\/uploads\/sites\/79\/2025\/07\/Screenshot_20250714_203733-300x115.png 300w, https:\/\/blogs.scummvm.org\/superlemon\/wp-content\/uploads\/sites\/79\/2025\/07\/Screenshot_20250714_203733-768x294.png 768w, https:\/\/blogs.scummvm.org\/superlemon\/wp-content\/uploads\/sites\/79\/2025\/07\/Screenshot_20250714_203733.png 837w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>This was good for testing but for the final writing, I needed to recalculate the sizes and the offsets of the resources. Which is what I did this week.<\/p>\n<p>First thing was to remove the STUBbed <code>saveMovie<\/code> lingo command. Then I had to rebuild the <code>RIFXArchive::_reosurces <\/code>array which contains the <code>struct Resource<\/code> (size, offset, flags, index, castId, etc.) of each\u00a0 resource. I added any new cast members to the resource list along with their children. I was under the impression that each cast member has separate children. Which made me think I&#8217;ll have to rebuild the indices of the cast members as well. But that is not the case: one child resource can have multiple parent resources (e.g. one &#8216;BITD&#8217; can be child to multiple &#8216;CASt&#8217; resources). This parent-child relationship also needs to be updated in the <code>RIFXArchive::_keyData<\/code>. My first approach was to rebuild the existing <code>_resource<\/code> array, but I quickly realized that I&#8217;m writing over important data here. So, I switched to building a new resource array and passing that to different functions. The bare bones of the writing of Memory map (&#8216;mmap&#8217;), key data (&#8216;KEY*&#8217;) and Cast data (&#8216;CAS*&#8217;) were already done.<\/p>\n<p>At first, there were a lot of issues with this. The data was being written correctly but the offset was wrong, the size returned by my function: <code>getSCVWResourceSize()<\/code> was off by two bytes. So, the entire loading of filmloop was failing. Also while writing &#8216;BITD&#8217;, &#8216;CLUT&#8217;, &#8216;STXT&#8217; and &#8216;SCVW&#8217; resources, I had to first find their parent cast members, which wasn&#8217;t being handled correctly. I also later realized that &#8216;BITD&#8217; writing for 1\/2\/4bpp was off by one pixel. While reading the cast info in the &#8216;CASt&#8217; resource, the strings: name, filename, directory name and type are all pascal strings. So, their first byte is not read (that byte marks the lengths of the string, which is redundant, we already have their length, so we ignore it). This caused the written cast information to be missing the first byte. The indices of &#8216;CASt&#8217; resources written in the &#8216;CAS*&#8217; were not written in the correct order, causing them to have the wrong CastIds. There was also an issue where if the lingo script goes <code>saveMovie \"filmloop_saved.dir\"<\/code>, at first I was trying to write the file by constructing a path like <code>Common::Path(\"filmloop_saved.dir\");<\/code> but later realized that it also needs a parent directory, so started saving like <code>Common::Path(\".\/\" + \"filmloop_saved.dir\");<\/code><\/p>\n<p>Through all of this (and many more issues), I was finally to sort each issue one by one, and finally write the movies correctly. Now, the <code>saveMovie {argument}<\/code> lingo command saves the exact copy of the currently loaded movie to the path specified by the argument.<\/p>\n<p>After this, I quickly finished writing score (very similar to Filmloop) and Rich Text.\u00a0 This marks writing of all the modifiable resources in Director (that I know of). I have to check a few things before calling this &#8216;Done&#8217;. What happens when I try just <code class=\"inline\">duplicate cast \"Original Cast\"<\/code> and if I call it repeatedly, will it be able to write all the duplicated casts? I also need to play around with <code>puppetSprite<\/code>. Also externally linked bitmaps are something to look into. @sev suggested trying out actual games that use this functionality to make sure it is fully functional.<\/p>\n<p>This task is nearing its end. I hope to complete it soon. After that I want to work on my initial task of loading movie cast members.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week was the most productive out of all the weeks until now (or maybe it feels like it). This week, I combined everything together. Until now, I was writing the logic of each resource to be written separately, dumping the file in the .\/dumps folder and writing only that chunk in that file. So, [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-week-6"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":7,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/posts\/45\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}