{"id":557,"date":"2020-10-29T15:17:58","date_gmt":"2020-10-29T20:17:58","guid":{"rendered":"https:\/\/badecho.com\/?p=557"},"modified":"2020-11-14T21:47:56","modified_gmt":"2020-11-15T02:47:56","slug":"hacking-dragons-dogma-part-1","status":"publish","type":"post","link":"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/","title":{"rendered":"Omnifying (Hacking) Dragon&#8217;s Dogma &#8211; Part 1 (Data Structure Analysis)"},"content":{"rendered":"\n<h2>The Hacking of Dragon&#8217;s Dogma Begins<\/h2>\n\n\n\n<p>Time to make yet another game <a href=\"https:\/\/badecho.com\/index.php\/what-is-omnified\/\" target=\"_blank\" rel=\"noreferrer noopener\">Omnified<\/a>. This time we&#8217;ll be hacking my Omnified systems into that little gem of a game known as <em>Dragon&#8217;s Dogma<\/em>. This, rather strange, little game has always occupied a warm place in my heart. Like many other games, one issue I&#8217;ve had with the game is that it isn&#8217;t brutal enough! We&#8217;re going to get to work on fixing that particular issue right now.<\/p>\n\n\n\n<p>In comparison to the last few games I&#8217;ve Omnified (basically the entire FromSoftware collection), I suspect we&#8217;ll have an easier time Omnifying some parts of this game, and maybe a bit of a harder time Omnifying other parts. The engine used by <em>Dragon&#8217;s Dogma<\/em> is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/MT_Framework\" target=\"_blank\" rel=\"noreferrer noopener\">MT Framework<\/a>, which is used by a number of CAPCOM games, most importantly <em>Monster Hunter World<\/em>. That game had built-in scaling support for characters (something I&#8217;ve not had in a game for a <em>while<\/em> now), which will <strong>greatly<\/strong> simplify Abomnification implementation.<\/p>\n\n\n\n<p>We won&#8217;t be implementing that lovely character-morphing system until near the end of the Omnification of Dragon&#8217;s Dogma. Right now we need to get busy with the basics! That means we need to take a cursory look at important data structures and grab the necessities required by everything Omnified related.<\/p>\n\n\n\n<h2>Getting Busy With the Basics: Finding the Player&#8217;s Health<\/h2>\n\n\n\n<p>The data structure containing the player&#8217;s health is required by a number of Omnified systems, in particular the <a rel=\"noreferrer noopener\" href=\"https:\/\/badecho.com\/index.php\/2020\/10\/19\/apocalypse-system\/\" target=\"_blank\">Apocalypse system<\/a>. It&#8217;s also a nice way to find the <strong>root structure<\/strong> for the player. As always, the health address in memory we find must be the <strong>source of truth<\/strong> for the player&#8217;s health; that is, the health address we end up using needs to be the sole instance in memory that actually determines what the health for the player actually is (there can exist many, many temporary working values for the health in memory in addition to this).<\/p>\n\n\n\n<p>How we find the health depends on whether the game displays the numeric value for the health to the player. Looking at the game, we can easily see that, thankfully, this value is indeed provided to us:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"537\" height=\"280\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthDisplay.png\" alt=\"Shows the in-game health display for the character, including its numeric value, which will be useful during our hacking of Dragon's Dogma.\" class=\"wp-image-562\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthDisplay.png 537w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthDisplay-300x156.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthDisplay-480x250.png 480w\" sizes=\"(max-width: 537px) 100vw, 537px\" \/><figcaption>Here we see the player&#8217;s health value displayed, along with its numeric value!<\/figcaption><\/figure><\/div>\n\n\n\n<p>Sweet. We know that our health, at its maximum, is <strong>450<\/strong>. This allows us to avoid having to search for unknown values; we can go ahead and just start off a search with Cheat Engine for a specific value. What about the data type though? Well, it&#8217;s been my experience that Japanese developers use integer (4 byte) values to store health. Every Japanese game I&#8217;ve Omnified has done this.<\/p>\n\n\n\n<p>Not in this game though. Big surprise there (I&#8217;m serious, <em>every <\/em>Japanese made game I&#8217;ve hacked has stored health values as integers). I did a search for the health assuming it was 4 bytes and ended up with squat. So let&#8217;s assume I did the smart thing right from the get go and did the search the way you really should, by using a <strong>Value Type<\/strong> of <strong>All<\/strong>.<\/p>\n\n\n\n<p>Be advised, the default settings that define what <strong>All<\/strong> encompasses needs to be tweaked! Check out <strong>Edit <\/strong>-&gt; <strong>Scan Settings<\/strong> -&gt; <strong>The all type includes<\/strong>, and make sure we include <strong>Float<\/strong> and <strong>Double<\/strong>. Now, let&#8217;s start the search for our health:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"754\" height=\"749\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/FirstHealthSearch.png\" alt=\"Shows how we start the hacking of Dragon's Dogma by doing an initial search for the player's health, which we know is at 450.\" class=\"wp-image-564\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/FirstHealthSearch.png 754w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/FirstHealthSearch-300x298.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/FirstHealthSearch-150x150.png 150w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/FirstHealthSearch-480x477.png 480w\" sizes=\"(max-width: 754px) 100vw, 754px\" \/><figcaption>We start our search by looking for Exact Values for All types using the known health value of 450.<\/figcaption><\/figure><\/div>\n\n\n\n<p>This gave us 29,701 results. Not bad! Let&#8217;s go get whacked a bit by enemies and then do another <strong>Exact Value<\/strong> search using the updated health value. Hopefully we can tank a few hits. <\/p>\n\n\n\n<p>After I got hit by some goblins, or whatever those things are, we do the next search:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"754\" height=\"749\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/SecondHealthSearch.png\" alt=\"Shows the next search for our health at an updated value of 319, thinning the list of results to just two results.\" class=\"wp-image-565\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/SecondHealthSearch.png 754w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/SecondHealthSearch-300x298.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/SecondHealthSearch-150x150.png 150w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/SecondHealthSearch-480x477.png 480w\" sizes=\"(max-width: 754px) 100vw, 754px\" \/><figcaption>Doing a Next Scan with a value of 319, we (much earlier than normal) find our health&#8217;s source of truth! Right?!<\/figcaption><\/figure><\/div>\n\n\n\n<p>Well that was quick. Already narrowed it down to two results! And yes, as you can see, these are floating point types. We now figure out which health value is the real one by adding them to our address list and then seeing which one, when changed, causes the health to update in the game to the new value.<\/p>\n\n\n\n<p>Except that when we try the above&#8230;we find that <em>neither<\/em> of the returned results update the health in the game. Whoops. That means something strange is going on here. Perhaps there is a rounding issue at hand. We hit the <strong>Undo Scan<\/strong> button to revert to the previous set of results, and then do a search across a range of values instead:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"754\" height=\"749\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/ThirdHealthSearch.png\" alt=\"Shows an updated search across a range of potential updated health values for our player during our hacking of Dragon's Dogma.\" class=\"wp-image-566\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/ThirdHealthSearch.png 754w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/ThirdHealthSearch-300x298.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/ThirdHealthSearch-150x150.png 150w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/ThirdHealthSearch-480x477.png 480w\" sizes=\"(max-width: 754px) 100vw, 754px\" \/><figcaption>Here we performed a search for a range of values that surround the updated health value of 319, giving us some interesting results.<\/figcaption><\/figure><\/div>\n\n\n\n<p>Here we see much more values that are approximately equal to our updated health value of <strong>319<\/strong>. When searching for floats, Cheat Engine doesn&#8217;t require the results to exactly match the queried value &#8212; it will also include results that are close to that value. I&#8217;m not aware of the exact rules Cheat Engine follows, but I assume that it rounds the results to the nearest number before checking for equivalency with the specified value.<\/p>\n\n\n\n<p>As we can see in the image, we see the number <strong>319.5651855<\/strong> pop up many times in the results. Normally we would round this number to <strong>320<\/strong>, however the game must <em>round down<\/em> the internal health value before displaying it to the user. This is odd behavior for sure. <\/p>\n\n\n\n<p>Let&#8217;s now figure out again which one is the source of truth by changing the value of each one and seeing which one updates the health in the game. This time, we are successful in finding the source of truth. Yay! Let&#8217;s now take a look at the data structure the health value resides in by first looking at some of the code accessing it. We right click on the health value and choose <strong>Find out what accesses this address<\/strong>, and the following window appears:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"946\" height=\"533\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthAccesss.png\" alt=\"Shows the code that is reading our discovered health value.\" class=\"wp-image-567\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthAccesss.png 946w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthAccesss-300x169.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthAccesss-768x433.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthAccesss-480x270.png 480w\" sizes=\"(max-width: 946px) 100vw, 946px\" \/><figcaption>Here we see a few instructions reading our health. From this we are able to find the data structure holding it and the offset used to access it.<\/figcaption><\/figure><\/div>\n\n\n\n<p>Looking at the instructions accessing the health, we can see the offset used to access it is <strong>0x8<\/strong>. Looking at the first instruction, we can also see that the address of the struct containing the health value is in the <strong>eax<\/strong> register, with the address being <strong>0x10C666AF0<\/strong>. Let&#8217;s take that address and plug it into a &#8220;Structure dissect&#8221; window so we can get an idea of what the health data structure looks like.<\/p>\n\n\n\n<p>We load the address into the &#8220;Structure dissect&#8221; window. Then, when we attempt to define the structure, we see that the initial, suggested name, for the structure is &#8220;unnamed structure&#8221;. This indicates that there is no <a href=\"https:\/\/en.wikipedia.org\/wiki\/Run-time_type_information\" target=\"_blank\" rel=\"noreferrer noopener\">RTTI<\/a> provided with this game. This shouldn&#8217;t be unexpected I suppose, and it will make some things a bit more difficult in figuring out, but I believe we&#8217;ll survive.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"946\" height=\"533\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthStruct.png\" alt=\"Shows the health data structure we found while hacking Dragon's Dogma.\" class=\"wp-image-568\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthStruct.png 946w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthStruct-300x169.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthStruct-768x433.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthStruct-480x270.png 480w\" sizes=\"(max-width: 946px) 100vw, 946px\" \/><figcaption>Here is our data structure housing the player health, with some fields defined by myself.<\/figcaption><\/figure><\/div>\n\n\n\n<p>Shown above you can see what the struct containing our health looks like. I defined a few of the fields, namely the <strong>Current Health<\/strong> (at offset <strong>0x8<\/strong>) and <strong>Maximum Health<\/strong> (at offset <strong>0xC<\/strong>) fields. This maximum health value, however, is <em>not<\/em> the source of truth for the maximum health! It is read-only and has no effect on your character&#8217;s maximum health. This is strange. <\/p>\n\n\n\n<p>As of now it is unknown to me what any of the other values are in the structure. Perhaps one of them leads to a root structure. <\/p>\n\n\n\n<p>Due to the lack of RTTI information, it is going to be rather difficult to identify any sort of root structure from what we have. We are going to have to first find some other bits of important player data and then see if there are any common structures being pointed to from both of them. Given the difficulty of the exercise I&#8217;ll probably only really try to chart it out if I really need to.<\/p>\n\n\n\n<p>Since I&#8217;m going to, at least for now, operate under the assumption that I&#8217;m not going to be finding the root structure, we will need to create a separate code injection for every player data structure type we&#8217;re interested in. So this means we can and should write up a player health hook right now! We were just looking at the instructions that accessed our health value, so we&#8217;ll just need to choose the right one for hooking into.<\/p>\n\n\n\n<p>Going through that list of instructions, starting at the one with the most calls to it, we open up the code in the disassembler, right click the code in question, and select <strong>Find out what addresses this instruction accesses<\/strong>. We want to find something that ideally only accesses the player&#8217;s health, and nothing else.<\/p>\n\n\n\n<p>A few of the methods access the health of everything on the map, and the majority of the rest seemed to access both the player&#8217;s and the health of the &#8220;pawn&#8221;. Eventually, we come across the instruction at <strong>DDDA.exe+332605<\/strong>, and it seems to only access the player&#8217;s health. So let&#8217;s hook into there baby!<\/p>\n\n\n\n<h2>Player Health Structure Pointer Creation via Injection<\/h2>\n\n\n\n<p>Having a root structure is great, but it isn&#8217;t required to make this thing Omnified. Given the lack of RTTI, the cost vs reward just isn&#8217;t worth it. That&#8217;s fine! It gives us some variety in how we go about Omnifying these things. We&#8217;ll be making separate hooks per data structure for now, and we&#8217;ll start with the grabbing the player&#8217;s health struct.<\/p>\n\n\n\n<p>Since we spent some time finding a good place to inject into (somewhere where no filtering, etc. is required), this will be a very easy hook to write; in fact, here it is:<\/p>\n\n\n\n<h3>Player Health Structure Hook<\/h3>\n\n\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ Gets the player's health struct.\n\/\/ eax: Address of player's health struct.\ndefine(omniPlayerHealthHook, &quot;DDDA.exe&quot; + 332605)\n\nassert(omniPlayerHealthHook, F3 0F 10 40 08)\nalloc(getPlayerHealth,$1000, omniPlayerHealthHook)\nalloc(playerHealth,8)\n\nregistersymbol(omniPlayerHealthHook)\nregistersymbol(playerHealth)\n\ngetPlayerHealth:\n  pushf\n  mov [playerHealth],eax\ngetPlayerHealthOriginalCode:\n  popf\n  movss xmm0,[eax+08]\n  jmp getPlayerHealthReturn\n\n\nomniPlayerHealthHook:\n  jmp getPlayerHealth\ngetPlayerHealthReturn:\n<\/pre>\n\n\n<p>Very simple, we&#8217;re just taking that health struct address stored in the <strong>eax<\/strong> register and throwing it in our <strong>playerHealth<\/strong> struct. This game is actually 32-bit so we don&#8217;t have to follow the typical precautions we have to when hacking 64-bit games, such as when we might deal with memory spaced apart more than 2 gigabytes.<\/p>\n\n\n\n<p>The health structure is one of the big requirements for some Omnified systems, so we can mark that requirement as done. The next piece of data we&#8217;re going to be interested in is the location structure for the player, which will be a bit of a painful affair given the complete lack of relationships established between data types&#8230;but we&#8217;ll be OK!<\/p>\n\n\n\n<h2 id=\"finding-player-coordinates\">Time to Find the Player Coordinates<\/h2>\n\n\n\n<p>Now that health has been taken care of, time to move to the real deal: the location structure for our player, which will contain our player&#8217;s coordinates. It is my hope that it will also contain our scaling parameters. I&#8217;m <em>really<\/em> hoping that this game will be the first game in awhile that has built in easy scaling support. This will make Abomnification implementation so much easier.<\/p>\n\n\n\n<p>We don&#8217;t have a root structure to work from, so we need to find the coordinates the old fashioned way. We do this by manipulating the Y-coordinate of the character, which is (I&#8217;m guessing! It actually depends on the game&#8230;) the vertical axis for the character. It&#8217;s the easiest of the coordinates to isolate from the other ones.<\/p>\n\n\n\n<p>So, to start off our quest to find the player&#8217;s coordinates we first must find&#8230;a rock!<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"1024\" height=\"737\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesRock-1024x737.png\" alt=\"Shows our character standing in front of a rock, which we'll be using to find the Y-coordinate for the player.\" class=\"wp-image-570\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesRock-1024x737.png 1024w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesRock-300x216.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesRock-768x553.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesRock-480x346.png 480w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesRock.png 1079w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Here lies the rock which will aid us in finding the Y-coordinate!<\/figcaption><\/figure><\/div>\n\n\n\n<p>We have found what we need! We will use this holy rock to effectuate changes to our Y-coordinate. We do this like so:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"820\" height=\"529\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesOnRock.png\" alt=\"Shows us standing on the rock, which will raise our Y-coordinate.\" class=\"wp-image-571\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesOnRock.png 820w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesOnRock-300x194.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesOnRock-768x495.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesOnRock-480x310.png 480w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption>By jumping on the rock, we&#8217;ll be increasing our Y-coordinate.<\/figcaption><\/figure><\/div>\n\n\n\n<p>We will create changes to our Y-coordinate by repeatedly jumping on and off the rock and searching for increasing\/decreasing changes for unknown initial valued floats as appropriate. So we start the search by selecting <strong>Float<\/strong> for the <strong>Value Type<\/strong> and <strong>Unknown initial value<\/strong> for the <strong>Scan Type<\/strong>, and then we will choose <strong>Increased Value<\/strong> after jumping up on the rock, and then <strong>Decreased Value<\/strong> after jumping off.<\/p>\n\n\n\n<p>We will repeat the above <em>many<\/em> times, until we get down to a reasonable number. After quite a bit of jumping, I got the following:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"754\" height=\"749\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesSearch.png\" alt=\"Shows the results of us jumping on and off the rock, looking for that Y-coordinate.\" class=\"wp-image-572\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesSearch.png 754w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesSearch-300x298.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesSearch-150x150.png 150w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesSearch-480x477.png 480w\" sizes=\"(max-width: 754px) 100vw, 754px\" \/><figcaption>After lots of jumping on and off the rock, we get the results reduced as much as possible.<\/figcaption><\/figure><\/div>\n\n\n\n<p>I did some additional filtering, such as restricting the results to a range of reasonable values. That said, we&#8217;re still left with 854 possible results. We will narrow this list down by adding them all to the address list, highlighting half of them, pressing spacebar to freeze the value, and then jumping in the game.<\/p>\n\n\n\n<p>If the player is unable to jump up correctly, that means that the source of truth for the Y-coordinate was frozen. We delete the entries in the address list that weren&#8217;t frozen, and then repeat with half of the remaining ones. If the player <em>is<\/em> able to jump up while we have some values frozen, that means that these values are bunk and we toss those away instead.<\/p>\n\n\n\n<p>We repeat this, reducing the results by one half each time, until we get to our source of truth. For me, the address for the Y-coordinate was at <strong>10DF50C4<\/strong>. Excellent. Let&#8217;s now repeat what we did for the health and check out the coordinate&#8217;s data structure using the same process to get struct info into the &#8220;Dissect structure&#8221; window.<\/p>\n\n\n\n<p>After doing that, I played around with some values and named a few of the fields, giving us this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"946\" height=\"533\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesStruct.png\" alt=\"Shows the contents of the location structure for the player, with some fields mapped out by myself already.\" class=\"wp-image-573\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesStruct.png 946w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesStruct-300x169.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesStruct-768x433.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/CoordinatesStruct-480x270.png 480w\" sizes=\"(max-width: 946px) 100vw, 946px\" \/><figcaption>Here is the location structure for the player, with some fields named by myself already.<\/figcaption><\/figure><\/div>\n\n\n\n<p>There&#8217;s our location struct. Got our coordinates. Know what else we got? Scale parameters. Indeed, finally a game with built-in easy scaling support. This will make the Omnification process just <em>loads<\/em> easier. The custom scaling code required by the Abomnification system is <em>by far<\/em> the most complicated piece of hooking we need to do typically. I&#8217;m sure we&#8217;ll run into an equally awful gotcha in its place however (just kidding, knock on wood&#8230;).<\/p>\n\n\n\n<h2>Player Location Structure Pointer Creation via Injection<\/h2>\n\n\n\n<p>Let&#8217;s write a hook for the coordinates then. We first are going to see what instructions are reading the X-coordinate, and try to find one just accessing the player&#8217;s coordinates.<\/p>\n\n\n\n<p>Taking the most frequently executed instruction that accesses our coordinates located at <strong>DDDA.exe+4D316A<\/strong>, I observed that it was only accessing our own player&#8217;s coordinates. Great! Your standard player coordinates polling function. Because there is no filtering required, this too will be a very simple hook, but still a very important one! Let&#8217;s write it.<\/p>\n\n\n\n<h3>Player Location Structure Hook<\/h3>\n\n\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ Gets the player's location structure.\n\/\/ eax: Address of the player's location struct.\ndefine(omniPlayerLocationHook, &quot;DDDA.exe&quot; + 4D316A)\n\nassert(omniPlayerLocationHook, F3 0F 10 40 40)\nalloc(getPlayerLocation,$1000, omniPlayerLocationHook)\nalloc(playerLocation,8)\n\nregistersymbol(omniPlayerLocationHook)\nregistersymbol(playerLocation)\n\ngetPlayerLocation:\n  mov [playerLocation],eax\ngetPlayerLocationOriginalCode:\n  movss xmm0,[eax+40]\n  jmp getPlayerLocationReturn\n\n\nomniPlayerLocationHook:\n  jmp getPlayerLocation\n\ngetPlayerLocationReturn:\n<\/pre>\n\n\n<p>Another very simple hook. After adding that code, we apply the hack, hope that the game doesn&#8217;t crash, and add some entries in the table to display our coordinates. Luckily there was no crash, and we now have a table looking like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"754\" height=\"749\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/TableAfterCoordinates.png\" alt=\"Shows the beginnings of our Omnified Dragon's Dogma table. Here we see the Health and X, Y, and Z coordinates for the player.\" class=\"wp-image-576\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/TableAfterCoordinates.png 754w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/TableAfterCoordinates-300x298.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/TableAfterCoordinates-150x150.png 150w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/TableAfterCoordinates-480x477.png 480w\" sizes=\"(max-width: 754px) 100vw, 754px\" \/><figcaption>Here&#8217;s our table thus far. We have values for the player&#8217;s health and coordinates displayed, sourced from our pointers.<\/figcaption><\/figure><\/div>\n\n\n\n<p>At the time of writing, I&#8217;ve also found another solution that is just as viable, if not a bit more. After exploring the data structures we&#8217;ve mapped already, I found that the location structure for the player can be found at <strong>[playerHealth+1B4]<\/strong>. If we want to instead remove the hook we just wrote and tie the creation of the player location pointer in with the player health, we can update our player health hook to look like the following:<\/p>\n\n\n\n<h3>Player Health and Location Structure Hook<\/h3>\n\n\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ Gets requisite player information.\n\/\/ eax: Address of player's health struct.\ndefine(omniPlayerHook, &quot;DDDA.exe&quot; + 332605)\n\nassert(omniPlayerHook, F3 0F 10 40 08)\nalloc(getPlayer,$1000, omniPlayerHook)\nalloc(playerHealth,8)\nalloc(playerLocation,8)\n\nregistersymbol(omniPlayerHook)\nregistersymbol(playerHealth)\nregistersymbol(playerLocation)\n\ngetPlayer:\n  pushf\n  push ebx\n  mov [playerHealth],eax\n  \/\/ The health structure itself points to the the location structure\n  \/\/ at 0x1B4.\n  mov ebx,[eax+1B4]\n  mov [playerLocation],ebx\n  pop ebx\ngetPlayerOriginalCode:\n  popf\n  movss xmm0,[eax+08]\n  jmp getPlayerReturn\n\n\nomniPlayerHook:\n  jmp getPlayer\ngetPlayerReturn:\n<\/pre>\n\n\n<p>This is actually everything we need at this stage for the main Omnified systems to be implemented. Despite this, I&#8217;d like to get to know the game a little more, and see if we can figure out any of the common data structures that unify all these disparate bits of data. The health structure did not appear to have anything related to the character&#8217;s stamina in it, so let&#8217;s find that next!<\/p>\n\n\n\n<h2>Let&#8217;s Go Get That Stamina<\/h2>\n\n\n\n<p>The numeric value for the player&#8217;s stamina is not displayed on the main game screen, unlike the health, but we can see the numeric value of our stamina at its max if we pause the game and go into <strong>Status<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"508\" height=\"125\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaDisplay.png\" alt=\"Shows the player's stamina bar and the numeric value for stamina at its maximum value in the Status screen.\" class=\"wp-image-577\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaDisplay.png 508w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaDisplay-300x74.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaDisplay-480x118.png 480w\" sizes=\"(max-width: 508px) 100vw, 508px\" \/><figcaption>Here we can see the maximum value for the Stamina, but we cannot see the current value.<\/figcaption><\/figure><\/div>\n\n\n\n<p>So we&#8217;ll be able to start off our search by doing an <strong>Exact Value<\/strong> type search using <strong>540<\/strong> as the value (with the player&#8217;s stamina bar filled up of course), but we&#8217;ll need to do successive <strong>Decreased Value<\/strong> and <strong>Increased Value<\/strong> type searches in order to track changes. Regardless of this, this should be a very easy value to find.<\/p>\n\n\n\n<p>After doing this basic type of search described above, I got the results down to this cast of suspects:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"754\" height=\"749\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaSearch.png\" alt=\"Shows the results of our search for the player's stamina.\" class=\"wp-image-578\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaSearch.png 754w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaSearch-300x298.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaSearch-150x150.png 150w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaSearch-480x477.png 480w\" sizes=\"(max-width: 754px) 100vw, 754px\" \/><figcaption>Here are the values relating to stamina we could narrow down just from successive searching.<\/figcaption><\/figure><\/div>\n\n\n\n<p>Just a tiny list of 9 results that we need to weed down, using the same old tactic of changing their value and seeing what causes an update in the game. We could also just freeze the value by checking its box and seeing if stamina no longer changes value in the game.<\/p>\n\n\n\n<p>After doing that I located the stamina at address <strong>0x0E388198<\/strong>. Let&#8217;s see what the struct it belongs to looks like by right clicking and clicking <strong>Find out what accesses this address<\/strong>. We then look at the base address in the register used when loading the stamina by an instruction in the resulting window from the previous action.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"946\" height=\"533\" src=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaStruct.png\" alt=\"Shows the contents of the structure containing the player's stamina.\" class=\"wp-image-579\" srcset=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaStruct.png 946w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaStruct-300x169.png 300w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaStruct-768x433.png 768w, https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/StaminaStruct-480x270.png 480w\" sizes=\"(max-width: 946px) 100vw, 946px\" \/><figcaption>Here we can see the structure containing the stamina, along with some other values.<\/figcaption><\/figure><\/div>\n\n\n\n<p>The stamina value itself is pretty deep inside this structure at the offset <strong>0x2A8<\/strong>. There really seems to be nothing of substance at the beginning of the struct either. Most interestingly, we see the current and maximum health values for the player in this struct as well. This time, the current health value is read-only (as it should be, there is only one source of truth), but the maximum health here in this struct <em>is<\/em> the source of truth. Very odd.<\/p>\n\n\n\n<h2>Player Stamina Structure Pointer Creation via Injection<\/h2>\n\n\n\n<p>We might as well write a hook that&#8217;ll inject a pointer for our stamina into the code as well. Looking at some of the instructions reading the stamina, it does appear (surprisingly I suppose) that not only the player has stamina, but other creatures do as well! So we&#8217;ll have to go through each one until we hopefully find an instruction that just returns the player&#8217;s stamina.<\/p>\n\n\n\n<p>Luckily for us, the very last of the instructions returned, located at <strong>DDDA.exe+332654<\/strong>, only accesses the player&#8217;s stamina. So let&#8217;s write up a quick, very simple hook for it.<\/p>\n\n\n\n<h3>Player Stamina Structure Hook<\/h3>\n\n\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ Gets the player's stamina struct.\n\/\/ edi: Contains the player's stamina struct.\ndefine(omniPlayerStaminaHook, &quot;DDDA.exe&quot; + 332654)\n\nassert(omniPlayerStaminaHook, F3 0F 10 8F A8 02 00 00)\nalloc(getPlayerStamina,$1000, omniPlayerStaminaHook)\nalloc(playerStamina,8)\n\nregistersymbol(omniPlayerStaminaHook)\nregistersymbol(playerStamina)\n\ngetPlayerStamina:\n  mov [playerStamina],edi\ngetPlayerStaminaOriginalCode:\n  movss xmm1,[edi+000002A8]\n  jmp getPlayerStaminaReturn\n\n\nomniPlayerStaminaHook:\n  jmp getPlayerStamina\n  nop 3\ngetPlayerStaminaReturn:\n<\/pre>\n\n\n<p>Once again, a very simple hook indeed. Well, now we have the player&#8217;s health, location, and stamina all being tracked and accessible from the other bits of code we&#8217;ll be writing in the future. This is really all we need for now, so we can wrap up this cursory look into Dragon Dogma&#8217;s data structures and player data.<\/p>\n\n\n\n<h2>Dragon&#8217;s Dogma Has Strange Data Organization<\/h2>\n\n\n\n<p>There&#8217;s a lot of strange things going on internally with Dragon&#8217;s Dogma. I&#8217;ve never personally been involved with the act of console porting, but I have to wonder if this strangeness is not an artifact of that process. Not incredibly familiar with the PS3 console either, but I do believe it is running on something that is pretty different than your typical x86 architecture.<\/p>\n\n\n\n<p>So what kind of strange &#8220;things&#8221; have we ran into during this initial look into Dragon&#8217;s Dogma? Here are a few of them:<\/p>\n\n\n\n<ul><li>If there&#8217;s a unifying root structure for each entity in the game, I didn&#8217;t stumble on it. I was able to find links to location data structures from the health data structure, but that&#8217;s it. A much deeper look would be required, but it really shouldn&#8217;t be <em>that<\/em> difficult.<\/li><li>The health for creatures is stored as a float, which is <em>not normal<\/em> for Japanese developers. On top of that, it appears that the float is always rounded down prior to displaying it to the user, which is also not normal. We&#8217;ll have to see if it is rounded down when it is evaluating game mechanics such as &#8220;is creature dead&#8221;.<\/li><li>The health and stamina values are not in the same data structure. This is not entirely unorthodox, but more often than not they will be in the same one. What is truly strange is that the maximum health in the health structure is read-only; the true maximum health is in the stamina structure (which has a read-only health value). That just comes off as&#8230;random sloppy data organization.<\/li><\/ul>\n\n\n\n<p>Anyways, nothing is crazy enough here that it will prevent us in Omnifying the game. There&#8217;s a bunch of good things going for us, in particular the availability of easy scaling parameters! Abomnification will be a breeze.<\/p>\n\n\n\n<p>We&#8217;ll be implementing the Apocalypse system next and getting the damage crazy in this game. This will really make the game hard since the ability to dodge isn&#8217;t always available. <\/p>\n\n\n\n<p>Thanks for your interest! Make sure to catch my live streams of my Omnified content at <a href=\"https:\/\/twitch.tv\/omni\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/twitch.tv\/omni<\/a>, and say hello on my Discord at <a href=\"https:\/\/discord.gg\/omni\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/discord.gg\/omni<\/a>. Take care everybody.<\/p>\n\n\n\n<p><em>~Omni<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Hacking of Dragon&#8217;s Dogma Begins Time to make yet another game Omnified. This time we&#8217;ll be hacking my Omnified [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[37,9],"tags":[22],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>Hacking Dragon&#039;s Dogma - Part 1 (Data Analysis) - omni&#039;s hackpad<\/title>\r\n<meta name=\"description\" content=\"The hacking of Dragon&#039;s Dogma starts now. When we&#039;re done, Dragon&#039;s Dogma will be Omnified. We start by looking at its data structures.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Hacking Dragon&#039;s Dogma - Part 1 (Data Analysis) - omni&#039;s hackpad\" \/>\r\n<meta property=\"og:description\" content=\"The hacking of Dragon&#039;s Dogma starts now. When we&#039;re done, Dragon&#039;s Dogma will be Omnified. We start by looking at its data structures.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/\" \/>\r\n<meta property=\"og:site_name\" content=\"omni&#039;s hackpad\" \/>\r\n<meta property=\"article:published_time\" content=\"2020-10-29T20:17:58+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2020-11-15T02:47:56+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthDisplay.png\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/badecho.com\/#website\",\"url\":\"https:\/\/badecho.com\/\",\"name\":\"omni&#039;s hackpad\",\"description\":\"Game Code Disassembly. Omnified Modification. Madness.\",\"publisher\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/badecho.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/badecho.com\/wp-content\/uploads\/2020\/10\/HealthDisplay.png\",\"width\":537,\"height\":280,\"caption\":\"Here we see the player's health value displayed, along with its numeric value!\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/#webpage\",\"url\":\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/\",\"name\":\"Hacking Dragon's Dogma - Part 1 (Data Analysis) - omni&#039;s hackpad\",\"isPartOf\":{\"@id\":\"https:\/\/badecho.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/#primaryimage\"},\"datePublished\":\"2020-10-29T20:17:58+00:00\",\"dateModified\":\"2020-11-15T02:47:56+00:00\",\"description\":\"The hacking of Dragon's Dogma starts now. When we're done, Dragon's Dogma will be Omnified. We start by looking at its data structures.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/\"]}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/#webpage\"},\"author\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"headline\":\"Omnifying (Hacking) Dragon&#8217;s Dogma &#8211; Part 1 (Data Structure Analysis)\",\"datePublished\":\"2020-10-29T20:17:58+00:00\",\"dateModified\":\"2020-11-15T02:47:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/#webpage\"},\"publisher\":{\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\"},\"image\":{\"@id\":\"https:\/\/badecho.com\/index.php\/2020\/10\/29\/hacking-dragons-dogma-part-1\/#primaryimage\"},\"keywords\":\"Omnifying\",\"articleSection\":\"Dragon's Dogma,Games\",\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/badecho.com\/#\/schema\/person\/3de67496328be7ae6e1f52faf582e9d2\",\"name\":\"Matt Weber\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/badecho.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7e345ac2708b3a41c7bd70a4a0440d41?s=96&d=mm&r=g\",\"caption\":\"Matt Weber\"},\"logo\":{\"@id\":\"https:\/\/badecho.com\/#personlogo\"}}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/557"}],"collection":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/comments?post=557"}],"version-history":[{"count":13,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/557\/revisions"}],"predecessor-version":[{"id":682,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/posts\/557\/revisions\/682"}],"wp:attachment":[{"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/media?parent=557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/categories?post=557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badecho.com\/index.php\/wp-json\/wp\/v2\/tags?post=557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}