<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Modding &#8211; Saki&#039;s Romhacking Shenanigans</title>
	<atom:link href="https://sakimotor.github.io/category/modding/feed/" rel="self" type="application/rss+xml" />
	<link>https://sakimotor.github.io</link>
	<description>It is what it is!</description>
	<lastBuildDate>Wed, 13 Nov 2024 21:47:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.2</generator>
	<item>
		<title>Modding an Xbox 360 Executable (with Ghidra and a Hex Editor): In the making of an English Patch for Tetris: The Grand Master Ace</title>
		<link>https://sakimotor.github.io/2024/11/13/modding-an-xbox-360-executable-with-ghidra-and-a-hex-editor-in-the-making-of-an-english-patch-for-tetris-the-grand-master-ace/</link>
					<comments>https://sakimotor.github.io/2024/11/13/modding-an-xbox-360-executable-with-ghidra-and-a-hex-editor-in-the-making-of-an-english-patch-for-tetris-the-grand-master-ace/#disqus_thread</comments>
		
		<dc:creator><![CDATA[sakicore]]></dc:creator>
		<pubDate>Wed, 13 Nov 2024 21:24:40 +0000</pubDate>
				<category><![CDATA[Modding]]></category>
		<category><![CDATA[Non classé]]></category>
		<category><![CDATA[Romhacking]]></category>
		<category><![CDATA[ghidra]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[patching]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[translation]]></category>
		<category><![CDATA[wxmedit]]></category>
		<category><![CDATA[xbox360]]></category>
		<category><![CDATA[xextool]]></category>
		<guid isPermaLink="false">https://sakimotor.github.io/?p=168</guid>

					<description><![CDATA[A short summary about how I replaced most japanese text in TGMA with a quick hex editing job.]]></description>
										<content:encoded><![CDATA[
<p>Hello everyone, today I am glad to announce <strong><a href="https://github.com/Sakimotor/tgma_eng">the completion of a patch</a></strong> for the Xbox360-exclusive Arika game <em>Tetris: The Grand Master Ace</em>, as well as an English retranslation of the game&#8217;s <strong><a href="https://sakimotor.github.io/tgma_eng/">promotional website</a></strong> ! The patch can be applied to the retail 1.0 release of the game, and translates most if not all the japanese text in the game (I do not have an Xbox Live Gold subscription, or a region-free console, therefore it is impossible for me to verify how well the XBL-exclusive gamemodes work). Here is a short preview of the patch (Xenia&#8217;s sound emulation is broken for this game so I turned it off):</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Tetris: The Grand Master Ace - English Patch (1.0)" width="500" height="281" src="https://www.youtube.com/embed/YX_kbYU2UHA?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>And here is one for the flash website: </p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="TGM Ace Promotional Website - English Patch (W.I.P)" width="500" height="281" src="https://www.youtube.com/embed/Rw7JoJRj71Y?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>For the most curious: no, I do not speak Japanese, and I did need to use <em>Google Translate </em>and <em>DeepL </em>a lot in spite of how much I despise MTL translations. Nevertheless, I consider knowing enough about the TGM series to have produced a faithful enough translation. I might get in touch with an actual translator who speaks Japanese once I come up with automated tools that would make it easier to insert text into the game/move it around.</p>



<p>The process mainly involved looking at Japanese/Shift-JIS strings inside of <a href="https://wxmedit.github.io/" data-type="URL" data-id="https://wxmedit.github.io/"><strong>wxMEdit</strong></a> and writing Latin/ASCII text instead. I was pretty lucky that the game allowed to use both text encodings interchangeably, or at the same time if I wanted it to be so. Nowadays, there are a few tools that facilitate the romhacking/modding process of an Xbox360 game.</p>



<p class="has-large-font-size"><strong>I &#8211; Unencrypting the executable (xextool)</strong></p>



<p>By default, Xbox360 .xex files will most likely be encrypted, as developers would probably wish to protect their retail games. </p>



<figure class="wp-block-image size-full"><img decoding="async" width="842" height="645" src="https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_1i0stDN3xI.png" alt="" class="wp-image-179" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_1i0stDN3xI.png 842w, https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_1i0stDN3xI-300x230.png 300w, https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_1i0stDN3xI-768x588.png 768w" sizes="(max-width: 842px) 100vw, 842px" /><figcaption class="wp-element-caption"><em>Encrypted .xex file, there is no way you&#8217;d find any string here</em></figcaption></figure>



<p>This is not a problem for us though, as the CLI software <a href="https://digiex.net/threads/xextool-6-3-download.9523/" data-type="URL" data-id="https://digiex.net/threads/xextool-6-3-download.9523/"><strong>xextool</strong></a> can easily decrypt them, and even decompress them in case of compressed games.</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-bash" data-lang="Bash"><code>xextool -c u default.xex #Uncompresses the file
xextool -c c default.xex #Compress modified file
xextool -e u default.xex #Decrypt the file
xextool -e e default.xex #Ecnrypt modified file</code></pre></div>



<p>The resulting decrypted file has text that can be read through. Since the game uses the Shift-JIS encoding, rather than HxD or any other editor that would only have ASCII and a few Latin charsets, we will  use wxMEdit. Make sure you go to <strong>View > Encoding</strong> and select Shift-JIS from there!</p>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_NaoKwDbct4-1.png" alt="" class="wp-image-184" width="840" height="905" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_NaoKwDbct4-1.png 847w, https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_NaoKwDbct4-1-278x300.png 278w, https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_NaoKwDbct4-1-768x828.png 768w" sizes="(max-width: 840px) 100vw, 840px" /><figcaption class="wp-element-caption"><em>English and Japanese text appear directly before us!</em></figcaption></figure>



<p class="has-large-font-size"><strong>II &#8211; Analyzing the executable (Ghidra)</strong></p>



<p>Ghidra is an open-source (and free) reverse engineering tool developed by the NSA. This tool allows to &#8220;decompile&#8221; an executable, and convert its binary data into human-readable pseudocode, as well as many other features. We will use it to locate all of the strings the executable contains, as well as the locations they&#8217;re referenced to/used in the program. Due to the astronomical amount of features it presents, as well as the not-so-friendly interface of the program, I would recommend watching/reading a tutorial that explains how it works before getting your hands on the program by yourself. <strong><a href="https://youtu.be/qCEZC3cPc1s">Hilltop&#8217;s video</a></strong> is a pretty good start in my opinion.  <strong><a href="https://www.youtube.com/watch?v=AOfNzFJ5W7A&amp;pp=ygUTc3RydWN0cyB3aXRoIGdoaWRyYQ%3D%3D">h0x91B</a></strong> is also good, though most of his videos are in Russian and non-subbed.</p>



<p>By default, it couldn&#8217;t do much with a .xex file, as it&#8217;s mostly used on PC-based executables and architectures in order to help with reversing a virus. Fortunately enough, Ghidra features the ability to create and install custom extensions, making possible the analysis of any architecture, console, or device, that would have such extensions developed. </p>



<p>For the Xbox360, <a href="https://github.com/zeroKilo/XEXLoaderWV" data-type="URL" data-id="https://github.com/zeroKilo/XEXLoaderWV"><strong>XexLoaderWV</strong></a> is the go-to solution. After installing the extension, drag-and-dropping a .xex executable unto Ghidra&#8217;s window will allow it to be analyzes. After the analysis is done, Ghidra should point your cursor towards the game&#8217;s entry point. We want to go to <strong>Search &gt; Encoded Strings&#8230;</strong> and look for Shift-JIS encoded text. By default it limits the minimal length to 5 characters, I recommend decreasing it all the way down to 3, or even 2 (though that will recognize some data related to code as SJIS strings so beware).  Press<strong> &#8220;Create All&#8221;</strong> once the strings have been identified. They will now be shown under the section <strong>Window &gt; Defined Strings</strong>, and clicking any string will show where in the executable it is located.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="455" src="https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_M7NzIppr47-1024x455.png" alt="" class="wp-image-188" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_M7NzIppr47-1024x455.png 1024w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_M7NzIppr47-300x133.png 300w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_M7NzIppr47-768x341.png 768w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_M7NzIppr47-1536x682.png 1536w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_M7NzIppr47.png 1628w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption"><em>On the left, the game&#8217;s assembly, with the position of the strings we&#8217;ve identified. &#8220;XREF&#8221; shows the RAM address where the string is referenced (pointer or code). On the right, the list containing all the identified strings so far, their position is also told here.</em></figcaption></figure>



<p class="has-large-font-size"><strong>III &#8211; Modifying the executable (wxMEdit)</strong></p>



<p>Ghidra has the ability of analysing the executable, and even &#8220;Patching Instructions&#8221; in case you want to &#8220;modify&#8221; the game&#8217;s behaviour/data and see how it alters the code&#8217;s flow. Nevertheless, it never touches the actual .xex file. To modify it, if you don&#8217;t make your own scripts, you will need to use a Hex Editor to meet your ends.</p>



<p>As you might have noticed, something is amiss between what Ghidra tells us, and what we&#8217;d see in the actual file. Even though our file is less than 8MB (4MB in TGM Ace&#8217;s case), the starting address of every string here is beyond 0x80000000, which makes it harder to see the association between what we see in Ghidra and what we see in a Hex Editor. In order to solve that, take a random string you&#8217;ve found before, then locate it in both your executable and ghidra. Substract ghidra&#8217;s position from the one you&#8217;ve found in the hex editor, and you get the <strong>offset</strong> you&#8217;ll need to apply when carrying over you analysis knowledge to the actual executable. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="543" src="https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_aqzr5W3inj-1024x543.png" alt="" class="wp-image-191" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_aqzr5W3inj-1024x543.png 1024w, https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_aqzr5W3inj-300x159.png 300w, https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_aqzr5W3inj-768x408.png 768w, https://sakimotor.github.io/wp-content/uploads/2024/11/wxmedit_aqzr5W3inj.png 1208w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://sakimotor.github.io/wp-content/uploads/2024/11/ApplicationFrameHost_TkuY2wHXLg-1.png" alt="" class="wp-image-192" width="397" height="466" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/ApplicationFrameHost_TkuY2wHXLg-1.png 793w, https://sakimotor.github.io/wp-content/uploads/2024/11/ApplicationFrameHost_TkuY2wHXLg-1-255x300.png 255w, https://sakimotor.github.io/wp-content/uploads/2024/11/ApplicationFrameHost_TkuY2wHXLg-1-768x903.png 768w" sizes="(max-width: 397px) 100vw, 397px" /><figcaption class="wp-element-caption"><em>We substracted Ghidra&#8217;s address of the string &#8220;SHOT GUN&#8221; with its actual location in the executable</em></figcaption></figure>



<p>At this point, you will probably ask me why we installed a 500MB tool for cybersec developers when we could just find all of the game&#8217;s strings in our hex editor. The first reason, is comfort. With Ghidra, the chance of missing a string is pretty low, all you have to do is scroll through the Defined Strings list and you will be good to go. By using a hex editor alone, you rely on your reading skills to make sure nothing was skipped, which can make you lose plenty of time on the long term. </p>



<p>The second reason, more serious, is that by using Ghidra&#8217;s analysis tools, you can detect the <strong><a href="https://www.w3schools.com/c/c_pointers.php">pointers</a></strong> (variables that store the address of something) and the chunks of code that refer to a string&#8217;s location. In the case of <em>Tetris: The Grand Master Ace</em> this knowledge is pretty important as the pointers related to the strings will decide where our strings begin. What this means, is that if I expect a string at position 0x10 and another at position 0x20, then unless I modify my second string&#8217;s pointer afterwards, my first string can never be larger than 15 bytes.</p>



<p>Changing the second string&#8217;s pointer so it would expect to find something at position 0x30 instead would allow me to write 16 more bytes into the first one, so it is important to be able to identify, and manipulate those pointers in order to not be limited by the game&#8217;s default behaviour.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="774" height="373" src="https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_5am9uBBHAb.png" alt="" class="wp-image-194" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_5am9uBBHAb.png 774w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_5am9uBBHAb-300x145.png 300w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_5am9uBBHAb-768x370.png 768w" sizes="(max-width: 774px) 100vw, 774px" /><figcaption class="wp-element-caption"><em>All of those values are of type &#8220;addr&#8221;. They store the address of a string, modifying any of them would show a different string.</em></figcaption></figure>



<p>In my case, there was no need to offset values that much, but from time to time, especially when the initial string was made of no more than three kanji, there was a need to move by 4-5 bytes the addresses of some pointers.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="576" src="https://sakimotor.github.io/wp-content/uploads/2024/11/xenia_canary_eF7mTWgKax-1024x576.png" alt="" class="wp-image-196" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/xenia_canary_eF7mTWgKax-1024x576.png 1024w, https://sakimotor.github.io/wp-content/uploads/2024/11/xenia_canary_eF7mTWgKax-300x169.png 300w, https://sakimotor.github.io/wp-content/uploads/2024/11/xenia_canary_eF7mTWgKax-768x432.png 768w, https://sakimotor.github.io/wp-content/uploads/2024/11/xenia_canary_eF7mTWgKax.png 1280w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">O<em>n this screen, all the pointers related to the controller&#8217;s buttons needed to be modified, as &#8220;Button&#8221; and &#8220;Trigger&#8221; took up far more space than the original Kanji. Fun Fact: same applies to the button prompts at the bottom-right!</em></figcaption></figure>



<p>For more advanced romhacks, the game&#8217;s assembly can directly be modified if you know what you&#8217;re doing, the Xbox360 uses a PowerPC architecture so the instruction set is well-documented, and PowerPC compilers exist in case you want to convert C into X360-compatible assembly rather than writing it by hand. <strong><a href="https://godbolt.org/">Compiler Explorer</a></strong> gives a good glimpse at how C could be converted to assembly, feel free to play around with the -O compilation options as well.</p>



<p>Once you&#8217;ve modified all of your strings, saved the custom executable, and tested the game out, it&#8217;s time to distribute the executable. The favoured way of doing so is by grabbing your <strong><a href="https://www.romhacking.net/utilities/704/">Delta Patcher</a></strong> and creating your own Delta Patch by using the original .xex file as a starting point. Make sure you encrypt/compress your modified file if the original was, and you&#8217;re good to go.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="717" height="491" src="https://sakimotor.github.io/wp-content/uploads/2024/11/DeltaPatcher_NB0utQB0Jt-1.png" alt="" class="wp-image-210" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/DeltaPatcher_NB0utQB0Jt-1.png 717w, https://sakimotor.github.io/wp-content/uploads/2024/11/DeltaPatcher_NB0utQB0Jt-1-300x205.png 300w" sizes="(max-width: 717px) 100vw, 717px" /><figcaption class="wp-element-caption"><em>It&#8217;s uncanny how easy it is.</em></figcaption></figure>



<p class="has-large-font-size"><strong>Bonus: Translating the original Flash website (JPEXS + Adobe Flash CS6)</strong></p>



<p>If you ever find some cool flash game or animation that&#8217;s japanese-only, it&#8217;s pretty &#8220;easy&#8221; to modify it to your liking. The <strong><a href="https://github.com/jindrapetrik/jpexs-decompiler">JPEXS Flash Decompiler</a></strong> comes with a tool that allows you to view all the sprites, texts, and scripts of an .swf animation.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="539" src="https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_JGfToAIcGo-1024x539.png" alt="" class="wp-image-211" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_JGfToAIcGo-1024x539.png 1024w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_JGfToAIcGo-300x158.png 300w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_JGfToAIcGo-768x404.png 768w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_JGfToAIcGo.png 1034w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption"><em>Here we can see all the &#8220;shapes&#8221; the game features. Think of it as an .SVG file if you&#8217;re familiar with the format.</em></figcaption></figure>



<p> It also allows you to use custom fonts, and/or extend the charset the original file supported.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="671" height="770" src="https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_gTU6LL4cbn.png" alt="" class="wp-image-212" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_gTU6LL4cbn.png 671w, https://sakimotor.github.io/wp-content/uploads/2024/11/javaw_gTU6LL4cbn-261x300.png 261w" sizes="(max-width: 671px) 100vw, 671px" /><figcaption class="wp-element-caption"><em>The original font lacked most Latin characters. After decompiling its original name,and acquiring the full font, it was possible to reinsert the whole ASCII charset back into the file.</em></figcaption></figure>



<p>At last, it allows you to modify the game&#8217;s texts and behaviour by editing its&#8217; ActionScript logic, and if that is not enough, you can always export the file as an .FLA and edit whatever else you need with Adobe Flash Professionnal CS6. As it is not the main topic of this blogpost, I will not elaborate on it much, but the short tutorials from <strong><a href="https://www.youtube.com/@SupHamster666">Serega </a></strong><a href="http://www.youtube.com/watch?v=HTWEwJ3QHGI"><strong>A.</strong></a> are pretty good, if we omit the disputable game choice that is used as example.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="512" src="https://sakimotor.github.io/wp-content/uploads/2024/11/chrome_LzpPAncc4c-1024x512.png" alt="" class="wp-image-214" srcset="https://sakimotor.github.io/wp-content/uploads/2024/11/chrome_LzpPAncc4c-1024x512.png 1024w, https://sakimotor.github.io/wp-content/uploads/2024/11/chrome_LzpPAncc4c-300x150.png 300w, https://sakimotor.github.io/wp-content/uploads/2024/11/chrome_LzpPAncc4c-768x384.png 768w, https://sakimotor.github.io/wp-content/uploads/2024/11/chrome_LzpPAncc4c-1536x768.png 1536w, https://sakimotor.github.io/wp-content/uploads/2024/11/chrome_LzpPAncc4c.png 1788w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption"><em>Flash games will be flash games amirite ?</em></figcaption></figure>



<p>After applying all of his wise teachings, I was able to (almost) fully translate Arika&#8217;s flash website from 2005 into English, although I would lie if I said my translation is perfect, be it semantically or even visually.</p>



<p class="has-large-font-size"><strong>Conclusion</strong></p>



<p>Thanks to anyone who has read thus far! If you are interested in more writings about romhacking, modding and whatnot, feel free to check the rest of my blog, although my other postings don&#8217;t go into much depth about anything related to actual reverse engineering.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sakimotor.github.io/2024/11/13/modding-an-xbox-360-executable-with-ghidra-and-a-hex-editor-in-the-making-of-an-english-patch-for-tetris-the-grand-master-ace/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Modding The Silver Case (Part 3): Replacing &#038; Distributing the mod</title>
		<link>https://sakimotor.github.io/2023/01/30/modding-the-silver-case-part-3-replacing-distributing-the-mod/</link>
					<comments>https://sakimotor.github.io/2023/01/30/modding-the-silver-case-part-3-replacing-distributing-the-mod/#disqus_thread</comments>
		
		<dc:creator><![CDATA[sakicore]]></dc:creator>
		<pubDate>Mon, 30 Jan 2023 21:11:29 +0000</pubDate>
				<category><![CDATA[Modding]]></category>
		<category><![CDATA[Repacking]]></category>
		<category><![CDATA[afr]]></category>
		<category><![CDATA[modding]]></category>
		<category><![CDATA[patching]]></category>
		<category><![CDATA[ps4]]></category>
		<category><![CDATA[xdelta]]></category>
		<guid isPermaLink="false">https://sakimotor.github.io/?p=67</guid>

					<description><![CDATA[The final step into modding the game: replace the files on the console!]]></description>
										<content:encoded><![CDATA[
<p>Welcome to the final part of my series of post focused on the modding of a <em>PS4 </em>game!</p>



<p>Since we&#8217;re approaching the end, allow me to rant a bit about a detail that would&#8217;ve saved me a fair amount of time if I knew about it beforehand.</p>



<p>As I already noticed in <a href="https://twitter.com/SakiMeguro/status/1342147956343005186" data-type="URL" data-id="https://twitter.com/SakiMeguro/status/1342147956343005186">2020</a>, <em>PS4 </em>games are encrypted inside .<em>PKG </em>files even once they are installed, and the only way to decrypt them is by booting the game up on the console. </p>



<figure class="wp-block-image size-full"><img decoding="async" width="833" height="126" src="https://sakimotor.github.io/wp-content/uploads/2023/01/EqBEVFFXAAA0vib.png" alt="" class="wp-image-69" srcset="https://sakimotor.github.io/wp-content/uploads/2023/01/EqBEVFFXAAA0vib.png 833w, https://sakimotor.github.io/wp-content/uploads/2023/01/EqBEVFFXAAA0vib-300x45.png 300w, https://sakimotor.github.io/wp-content/uploads/2023/01/EqBEVFFXAAA0vib-768x116.png 768w" sizes="(max-width: 833px) 100vw, 833px" /><figcaption class="wp-element-caption"><em>The game&#8217;s folder on the PS4, as seen by connecting through FTP. The whole game is encrypted and gets decrypted only on runtime.</em></figcaption></figure>



<p>As such, one would think that, in order to mod a <em>PS4 </em>game, we would need to repack the whole <em>Fake PKG </em>and reinstall it each time we modify a file. That&#8217;s what I did for my first dozen of tries, and the process was <strong><em>TEDIOUS</em></strong>! Imagine doing the whole process of <a href="https://sakimotor.github.io/2023/01/26/modding-the-silver-case-ps4-part-1-dumping-reinstalling/" data-type="post" data-id="23">Part 1</a> each time a mere file was modified, the waste of time was absolute between the <em>PKG </em>repacking (about 30 minutes), the transfer to USB (5-10 minutes), the actual installation (10 minutes) and finally booting the game up: a whole hour of <strong><em>NOTHING</em></strong>, urgh. </p>



<p>I thought I could finally seek salvation after finding out about <a href="https://www.psxhax.com/threads/ps4-patch-builder-for-building-modded-update-pkgs-by-modded-warfare.7112/page-11" data-type="URL" data-id="https://www.psxhax.com/threads/ps4-patch-builder-for-building-modded-update-pkgs-by-modded-warfare.7112/page-11">PS4 Patch Builder</a> but nope, it was the same, perhaps even worse. In order to use the program I needed a <strong>backup </strong>of the whole game as a <em>PKG</em> and an <em>Image0</em> folder with all my <strong>modded files</strong>, and, for some reason, the program didn&#8217;t function if said folder didn&#8217;t also have all the other files, which means that I know had the equivalent of two backups occupying my space for nothing! After hitting that <em>Build Package</em> button it would take around half an hour to generate the &#8220;Update&#8221; <em>PKG</em> so really there wasn&#8217;t much benefit to using that method, if not to generate a <em>slightly</em> tinier <em>PKG </em>than before, at the expense of having 3 copies of the game lying on my Hard Drive with no benefits.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="901" height="521" src="https://sakimotor.github.io/wp-content/uploads/2023/01/FXdPyzVXgAMq_t4.jpg" alt="" class="wp-image-70" srcset="https://sakimotor.github.io/wp-content/uploads/2023/01/FXdPyzVXgAMq_t4.jpg 901w, https://sakimotor.github.io/wp-content/uploads/2023/01/FXdPyzVXgAMq_t4-300x173.jpg 300w, https://sakimotor.github.io/wp-content/uploads/2023/01/FXdPyzVXgAMq_t4-768x444.jpg 768w" sizes="(max-width: 901px) 100vw, 901px" /><figcaption class="wp-element-caption"><em>A screenshot of the program, provided by its creator, <strong>MODDED WARFARE.</strong></em></figcaption></figure>



<p></p>



<p>Now that this is out of my way, allow me to introduce you to the actual way of modding a <em>PS4</em> game, the Holy Grail of modding, a technique similar to the Switch&#8217;s <em><a href="https://yuzu-emu.org/help/feature/game-modding/" data-type="URL" data-id="https://yuzu-emu.org/help/feature/game-modding/">LayeredFS</a></em> file replacement: <em><strong><a href="https://www.psxhax.com/threads/ps4-frame4-afr-application-file-redirector-tutorial-by-deathrgh.13356/" data-type="URL" data-id="https://www.psxhax.com/threads/ps4-frame4-afr-application-file-redirector-tutorial-by-deathrgh.13356/">AFR</a></strong></em> (<em>Application File Redirector)</em>! I will speak exclusively about <em><strong>GoldHEN</strong></em>&#8216;s implementation of it (as a <em>plugin)</em>, but it was originally made by  <strong><em>theorywrong</em></strong> for the <em><a href="https://github.com/OpenOrbis/mira-project" data-type="URL" data-id="https://github.com/OpenOrbis/mira-project">Mira Project</a></em>.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="573" src="https://sakimotor.github.io/wp-content/uploads/2023/01/ps4-goldhen-v23-avec-ps4-homebrew-enabler-game-patches-et-afr-plugins-1024x573.png" alt="" class="wp-image-72" srcset="https://sakimotor.github.io/wp-content/uploads/2023/01/ps4-goldhen-v23-avec-ps4-homebrew-enabler-game-patches-et-afr-plugins-1024x573.png 1024w, https://sakimotor.github.io/wp-content/uploads/2023/01/ps4-goldhen-v23-avec-ps4-homebrew-enabler-game-patches-et-afr-plugins-300x168.png 300w, https://sakimotor.github.io/wp-content/uploads/2023/01/ps4-goldhen-v23-avec-ps4-homebrew-enabler-game-patches-et-afr-plugins-768x430.png 768w, https://sakimotor.github.io/wp-content/uploads/2023/01/ps4-goldhen-v23-avec-ps4-homebrew-enabler-game-patches-et-afr-plugins.png 1425w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption"><em>GoldHEN&#8217;s plugins usage guide.</em></figcaption></figure>



<p></p>



<p>As its name indicates, while the game is running, <em>AFR </em>replaces the games files with the ones we&#8217;ve put in a custom folder, eliminating all needs from repacking the <em>PKG</em> each time we want to edit a file. This method <strong>works with disc copies and legit PKGs</strong>!</p>



<p>The first thing we need to do is to download the<em> GoldHEN plugins</em> from the <strong><em><a href="https://github.com/GoldHEN/GoldHEN_Plugins_Repository" data-type="URL" data-id="https://github.com/GoldHEN/GoldHEN_Plugins_Repository">GitHub</a></em></strong> repository. Once downloaded, we need to edit the <strong><em>plugins.ini</em> </strong>file to enable the <em>plugins </em>we are going to use, and to tell which games we are going to load the <em>plugins</em> for. As I want to apply the <em>plugins</em> to any game, the file would look like this: </p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-plain"><code>; Note: lines starting with semicolon are for comments.
; Load plugins for any title.

[default]
; Load the AFR plugin 
/data/GoldHEN/plugins/afr.prx

; Load plugins only for Playroom.

[CUSA00001]
/data/GoldHEN/plugins/afr.prx
/data/GoldHEN/plugins/no_share_watermark.prx</code></pre></div>



<p></p>



<p>With the  .ini file modified, it&#8217;s time to put the <em>plugins.ini</em> file and the <em>plugins </em>folder in your<em> PS4</em>, into the <em><code><strong>/data/GoldHEN/plugins/</strong></code>  </em>folder (we can do that by USB or by FTP).</p>



<p>Now, we can run <em>GoldHEN</em> and enable the plugins in the <em>Settings &gt; Debug Settings &gt; Plugins &gt; Enable Plugins Loader </em> section.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="655" height="367" src="https://sakimotor.github.io/wp-content/uploads/2023/01/image-4.png" alt="" class="wp-image-75" srcset="https://sakimotor.github.io/wp-content/uploads/2023/01/image-4.png 655w, https://sakimotor.github.io/wp-content/uploads/2023/01/image-4-300x168.png 300w" sizes="(max-width: 655px) 100vw, 655px" /><figcaption class="wp-element-caption"><em>Enabling the Plugins Loader.</em></figcaption></figure></div>


<p></p>



<p>For each game we want to modify, we simply need to create a folder bearing the game&#8217;s <em><strong>TitleID</strong></em> inside of <em><code><strong>/data/GoldHEN/plugins/AFR</strong></code></em>, and place all of our modified files here.</p>



<p>If everything was done correctly, we  will see the difference each time we boot up the games with <em>AFR </em>enabled.</p>



<p></p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="576" src="https://sakimotor.github.io/wp-content/uploads/2023/01/3-PS4-TheSilverCase-20230126232619-YouTube-0-18-1024x576.jpeg" alt="" class="wp-image-76" srcset="https://sakimotor.github.io/wp-content/uploads/2023/01/3-PS4-TheSilverCase-20230126232619-YouTube-0-18-1024x576.jpeg 1024w, https://sakimotor.github.io/wp-content/uploads/2023/01/3-PS4-TheSilverCase-20230126232619-YouTube-0-18-300x169.jpeg 300w, https://sakimotor.github.io/wp-content/uploads/2023/01/3-PS4-TheSilverCase-20230126232619-YouTube-0-18-768x432.jpeg 768w, https://sakimotor.github.io/wp-content/uploads/2023/01/3-PS4-TheSilverCase-20230126232619-YouTube-0-18.jpeg 1280w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption"><em>The Silver Case&#8217;s intro, replaced with Andrea Bruno&#8217;s </em><a href="https://twitter.com/baronunread/status/1318294022885093378">Sumio Mondo THUG Pro Mod Trailer</a>.</figcaption></figure></div>


<p></p>



<p>There are a few ways of distributing our modded data to the public, each with their pros and cons:</p>



<ul>
<li>The most <em><strong>user-friendly</strong></em> way would be by <strong>repackaging the whole game</strong> and <strong>uploading the PKG</strong> on the internet: anyone with a jailbroken console could install it, but it&#8217;s not only expensive in terms of space usage (we upload the whole game), but also obviously clearly illegal (<em>we upload the whole game</em>). I would not recommend using that as an option, especially if you want your mod project to be publicly available.</li>
</ul>



<ul>
<li>Another way would be by <strong>generating a custom update<em> </em></strong>so we would only need to distribute the files that we modified through a <em>Fake PKG</em>. Unfortunately, this method requires the user to dump their game and reinstall it as a <em>Fake PKG</em>, which isn&#8217;t optimal.</li>
</ul>



<ul>
<li>The best <em><strong>compromise between legality and ease of use</strong></em> would be the <strong>AFR </strong>we mentionted before: we only need to distribute the edited files, which the user can then copy to their console in the <em><code><strong>/data/GoldHEN/plugins/AFR/CUSAXXXX</strong></code></em>folder. </li>
</ul>



<ul>
<li>Even <em><strong>better </strong></em>legally, by using <em>Delta Patching</em> tools, such as <strong><em><a href="https://www.romhacking.net/utilities/598/">xdelta </a></em></strong>or <strong><em><a href="https://github.com/Moodkiller/xdelta3-gui-2.0" data-type="URL" data-id="https://github.com/Moodkiller/xdelta3-gui-2.0">xdelta3</a></em></strong>, instead of distributing the files directly, you can distribute patches that will <strong>modify the original files</strong> with the new data, which means the user would have to own their own dump, and that we don&#8217;t technically upload any (usable as a standalone) illegal content. </li>
</ul>



<ul>
<li>Another advantage is is that by only distributing the patched part of a file, we can drastically reduce the size of the patch we are going to share! Be warned though, this method requires the user to apply the patches <strong>by themselves</strong> before obtaining the modded file, and that an xdelta patch (to my knowledge) is applied to a <strong>single file</strong>, which, in case of a patch that modifies a lot of files,would make us generate the patches <strong>one by one</strong>, and the user would also need to apply them<strong> one by one</strong>!  (<em><strong>these cons could be solved by making Bash/Powershell/Python&#8230; scripts that handle the patching for the user, as xdelta handles CLI with no problem.)</strong></em></li>
</ul>



<p></p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="599" height="47" src="https://sakimotor.github.io/wp-content/uploads/2023/01/image-5.png" alt="" class="wp-image-78" srcset="https://sakimotor.github.io/wp-content/uploads/2023/01/image-5.png 599w, https://sakimotor.github.io/wp-content/uploads/2023/01/image-5-300x24.png 300w" sizes="(max-width: 599px) 100vw, 599px" /><figcaption class="wp-element-caption"><em>The difference speaks for itself</em>!</figcaption></figure></div>


<p></p>



<p>And thus, our long guide finally comes to an end. Now, we are able to jailbreak a ps4 console, dump any game we want, modify its contents (<em>we covered the case of a Unity game)</em> and run the patched contents on the console as easily as possible. Thank you for reading this blog, I will come back for more <em>Sony</em>-oriented romhacking articles soon!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sakimotor.github.io/2023/01/30/modding-the-silver-case-part-3-replacing-distributing-the-mod/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Modding The Silver Case (Part 2): Extracting &#038; Repacking</title>
		<link>https://sakimotor.github.io/2023/01/28/modding-the-silver-case-part-2-extracting-repacking/</link>
					<comments>https://sakimotor.github.io/2023/01/28/modding-the-silver-case-part-2-extracting-repacking/#disqus_thread</comments>
		
		<dc:creator><![CDATA[sakicore]]></dc:creator>
		<pubDate>Sat, 28 Jan 2023 01:28:01 +0000</pubDate>
				<category><![CDATA[Modding]]></category>
		<category><![CDATA[Repacking]]></category>
		<category><![CDATA[archive]]></category>
		<category><![CDATA[ps4]]></category>
		<category><![CDATA[psarc]]></category>
		<category><![CDATA[unity]]></category>
		<guid isPermaLink="false">https://sakimotor.github.io/?p=40</guid>

					<description><![CDATA[In this post, I will explain how to work with the (not so) niche and proprietary .PSARC archive format, as well as the (even less) niche and proprietary Unity .assets archive format.]]></description>
										<content:encoded><![CDATA[
<p>Our <a href="https://sakimotor.github.io/2023/01/26/modding-the-silver-case-ps4-part-1-dumping-reinstalling/" data-type="post" data-id="23">previous </a>post explained how to prepare a game for modding. Today, it&#8217;s about time we do the actual modding part!</p>



<p></p>



<p>The game was made with <strong>Unity</strong>. As such, its mostly comprised of .assets files, just like the PC version, with one particularity: the heaviest (and most important) assets have been compressed within a <strong>.psarc</strong> archive, a proprietary format used by Sony games since the <em>PS3 </em>era.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" src="https://sakimotor.github.io/wp-content/uploads/2023/01/EqA99JfXIAAxS2p.png" alt="" class="wp-image-45" width="686" height="373"/></figure></div>

<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" src="https://sakimotor.github.io/wp-content/uploads/2023/01/EqA-SheXUAQCh0x.png" alt="" class="wp-image-46" width="688" height="433"/><figcaption class="wp-element-caption"><em>General folder layout. The &#8220;Media&#8221; folder contains some .assets files, as well as a &#8220;StreamingAssets&#8221; folder which contains the game&#8217;s videos as .MP4s</em>.</figcaption></figure></div>


<p></p>



<p>In 2020, I used a tool named <strong><a href="https://github.com/IcySon55/Kuriimu/releases" data-type="URL" data-id="https://github.com/IcySon55/Kuriimu/releases">Karameru</a> </strong>to extract the .<em>psarc</em> archives. This time I used <a href="http://richwhitehouse.com/index.php?content=inc_projects.php&amp;showproject=91"><strong>Noesis</strong></a>, a tool widely-used to preview 3D models from different formats, but also for extracting some types of archives, which <em>.psarc</em> is part of.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1428" height="632" src="https://sakimotor.github.io/wp-content/uploads/2023/01/Noesis64_yrB110L5Mw.png" alt="" class="wp-image-48"/><figcaption class="wp-element-caption"><em>Right-clicking on the archive and selecting &#8220;Export&#8221; allows us to extract it wherever we want.</em></figcaption></figure>



<p></p>



<p>Once the archive is extracted, we can treat its contents like a usual <em>Unity </em>game folder. Unfortunately, this means more extracting and repacking but it won&#8217;t be a problem, as this time we have the whole Unity modding community behind our back!</p>



<p> My favorite tool for extracting <em>Unity .assets</em> files is <a href="https://github.com/Perfare/AssetStudio" data-type="URL" data-id="https://github.com/Perfare/AssetStudio"><strong>AssetStudio</strong></a>, a software that has been faithful to me since 2019, when I first used it on the <em>PC </em>version of the game. It&#8217;s very easy of use for previewing and extracting the contents within the archives, but it unfortunately does not support reimporting/repacking.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1920" height="1040" src="https://sakimotor.github.io/wp-content/uploads/2023/01/image.png" alt="" class="wp-image-51"/><figcaption class="wp-element-caption"><em>When we use the &#8220;Load folder&#8221; option on our extracted archive, we can see all the TextAsset (JSON messages) and Texture2D (image textures) we need to replace. We can extract them by using the &#8220;Export&#8221; option</em>.</figcaption></figure>



<p></p>



<p>Once the files we want are extracted, we can edit them to our leisure. I won&#8217;t elaborate much on this part, but one thing I can say is that <em>AssetStudio </em>does its best to convert the assets into commonly-used formats: <em>.txt/.json</em> files for the <em>TextAsset </em>files, <em>.png</em> files for the <em>Texture2D</em> ones,  <em>.wav </em>for the <em>AudioClip</em>&#8230; Surely, we won&#8217;t have much research works to find software able to work with these file formats!</p>



<p>Anyway, after editing the extracted filed to our will, we will reimport them with a russian tool called <strong><a href="https://www.dropbox.com/s/j0dyaqogc7w2gbn/UnityEX_Advanced.rar" data-type="URL" data-id="https://www.dropbox.com/s/j0dyaqogc7w2gbn/UnityEX_Advanced.rar">UnityEX</a> </strong>(<a href="https://disk.yandex.ru/d/C7Vzo44UDXiq-w" data-type="URL" data-id="https://disk.yandex.ru/d/C7Vzo44UDXiq-w">YandexDisk</a> mirror). Just like <em>AssetStudio</em>, it&#8217;s a tool I got familiar with in 2019, when I worked with the <em>PC </em>version. It has been helpful enough for me to donate to its developer in order to get all the features of the program, such as the <em>Unity </em>2020-2021 support (more on that on the official forum <a href="https://forum.zoneofgames.ru/topic/36240-unityex/" data-type="URL" data-id="https://forum.zoneofgames.ru/topic/36240-unityex/">thread</a>), but we can work with the freeware version as well, since the game has been compiled with <em>Unity</em>&#8216;s 2016-2017 SDK!</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="883" height="761" src="https://sakimotor.github.io/wp-content/uploads/2023/01/image-2.png" alt="" class="wp-image-53"/><figcaption class="wp-element-caption"><em>UnityEX in action on the game&#8217;s &#8220;resources.assets&#8221; archive.</em></figcaption></figure></div>


<p>Unlike <em>AssetStudio</em>, <em>UnityEX</em> only opens one file at a time, which doesn&#8217;t matter since all the content we need is stored within the <em>resources.assets</em> file. When we open an archive within UnityEX, we can extract the files by right-clicking them, then by pressing &#8220;Extract with convert or Raw&#8221;: this will convert a file to a more common extension if it&#8217;s known (like <em>AssetStudio</em> does), or leave it as-is. </p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img decoding="async" src="https://sakimotor.github.io/wp-content/uploads/2023/01/image-1.png" alt="" class="wp-image-52" width="665" height="695"/><figcaption class="wp-element-caption"><em>The extracted files go to a new folder named &#8220;<em>Unity_Assets_Files</em>&#8220;, which will contain another folder bearing the same name as our <em>.assets</em> file, in this case <em>resources</em>.</em></figcaption></figure></div>


<p>By hitting the &#8220;<em>Import all files&#8221;</em> button in <em>UnityEX</em>, the program will look all the files from the folder mentioned above, compare the filenames to the ones within the opened <em>.assets </em>archive, then replace each matching occurence. Any <em>.png</em> file is automatically converted into a <em>.tex Texture2D</em> file, then reinserted in the archive. If the program finds a filename that doesn&#8217;t correspond to anything in the archive, it will give a warning and askip if we want to continue anyway. </p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="883" height="761" src="https://sakimotor.github.io/wp-content/uploads/2023/01/image-3.png" alt="" class="wp-image-54"/><figcaption class="wp-element-caption"><em>You might not see the difference, but the green bar being halfway through is a sign of the importing process being in progress.</em></figcaption></figure></div>


<p>Now that the <em>resources.assets</em> has been edited, it&#8217;s time to do the whole process&#8230; Backwards! First, we need to  repack the folder containing the extracted <em>.assets</em> files back to a .psarc file. This time, instead of <em>Karameru</em>,  I used <a href="https://www.ghisler.com/">Total Commander</a>, a freeware file manager which had the benefit of supporting <em>.psarc </em>repacking thanks to a third-party <a href="http://totalcmd.net/plugring/PSARC.html">plugin</a> by <em>BEKETATA</em>.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="569" height="410" src="https://sakimotor.github.io/wp-content/uploads/2023/01/TOTALCMD64_5EmDLZpBdO.png" alt="" class="wp-image-55"/><figcaption class="wp-element-caption"><em>Right-clicking on the folder, then clicking &#8220;File &gt; Pack&#8230;&#8221; does the trick.</em></figcaption></figure>



<p></p>



<p>And&#8230; that&#8217;s it! Now, we have our modded <em>archive.psarc</em> file, ready to get inserted back into the game. As there are multiple ways of doing that, which both take a fair amount of time and dedication, I will document them in a final post, one that will get more focused on the <em>PS4</em>-side manipulation than the <em>PC</em> one.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="603" height="66" src="https://sakimotor.github.io/wp-content/uploads/2023/01/explorer_SMSLQwpTbO.png" alt="" class="wp-image-56"/><figcaption class="wp-element-caption"><em>Our custom videos folder, as well as our modded archive, are ready to go. The archive_og.psarc file is a mere emergency backup.</em></figcaption></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://sakimotor.github.io/2023/01/28/modding-the-silver-case-part-2-extracting-repacking/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
