<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Balzabu | Blog</title>
    <link>https://blog.balzabu.io/tags/bots/</link>
    <description>Recent content on Balzabu | Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Thu, 05 Oct 2023 15:50:11 +0200</lastBuildDate>
    <atom:link href="https://blog.balzabu.io/tags/bots/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Automating PokeMMO For Fun &amp; Profit</title>
      <link>https://blog.balzabu.io/posts/automating-pokemmo/</link>
      <pubDate>Thu, 05 Oct 2023 15:50:11 +0200</pubDate>
      <guid>https://blog.balzabu.io/posts/automating-pokemmo/</guid>
      <description>&lt;hr&gt;
&lt;blockquote&gt;
&lt;p&gt;Updated on 2023-12-07&lt;/p&gt;
&lt;p&gt;A few weeks after this article has been posted, as a strange coincidence, there has been an huge update which changed how the detection works on Android devices.&lt;/p&gt;
&lt;p&gt;It might be bypassable using the same package name as apps that use Accessibility Service by default on some devices, however this should be investigated.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As every nerd I know, during my free time, I love playing videogames and
I&amp;rsquo;ve recently decided to play Pokèmon again, focusing on the old generations. It feels like a real throwback to my childhood!&lt;/p&gt;</description>
      <content:encoded><![CDATA[<hr>
<blockquote>
<p>Updated on 2023-12-07</p>
<p>A few weeks after this article has been posted, as a strange coincidence, there has been an huge update which changed how the detection works on Android devices.</p>
<p>It might be bypassable using the same package name as apps that use Accessibility Service by default on some devices, however this should be investigated.</p>
</blockquote>
<p>As every nerd I know, during my free time, I love playing videogames and
I&rsquo;ve recently decided to play Pokèmon again, focusing on the old generations. It feels like a real throwback to my childhood!</p>
<p>During the setup of the emulators, I&rsquo;ve discovered the existence of PokeMMO.</p>
<h3 id="whats-pokemmo">What&rsquo;s PokeMMO?</h3>
<p>PokeMMO is a cross-platform<sup>[1]</sup>
 <a href="https://en.wikipedia.org/wiki/Massively_multiplayer_online_game"><em>MMO</em></a>, created in August 2012, where it&rsquo;s possible to play most of the Pokèmon games (Red Fire, Emerald, Platinum, Black/White, HG/SS) with thousands of players connected at the same time.
It&rsquo;s possible to trade items and Pokèmon, challenge other players or even sell in-game items through a system created by the developers called <em>GTL</em> ( <a href="https://forums.pokemmo.com/index.php?/topic/59805-pokemmo-gtl-guide-old-trade-chat-guide-trading-in-game/"><em>Global Trade Link</em></a> ); For all intents and purposes, it&rsquo;s an international market based on the In-game currency, the PokeYEN, where all the players can sell or buy everything.</p>
<p>Since it makes use of the original Pokèmon ROMs, the storyline and the NPC interactions are not modified.
The story is the same as the original game, it only implements specific differences such as:</p>
<ul>
   <li>Change of the spawn location of wild Pokèmon</li>
   <li>Legendary Pokèmon can't be caught or kept for long time<sup>[2]</sup>
</li>
   <li>The battles against the NPCs are way harder</li>
</ul>
<p> </p>
<img src="../../images/pokemmo/wow-kid.webp" title="wow" alt="wow">
<p>*<sup>[1]</sup>
 The game is currently supported on Windows, Android, iOS, Mac and Linux.</p>
<p>*<sup>[2]</sup>
 Currently the only legendary Pokèmon that can be caught and kept permanently in the game are: Suicine, Raikou ed Entei.</p>
<h3 id="how-does-it-work">How does it work?</h3>
<p>As already stated, at the beginning the game does not show any substantial difference except for the dialogs speed which is increased to allow a smoother experience.
Once the 4<sup>th</sup> gym has been defeated, it will be possible to use the GTL trading system mentioned in the previous section.</p>
<p>Arrived at this point, it immediately becomes clear that the price of some items listed in the GTL, not only requires to set up a strong team that is able to compete in the PvP aspect of the game but is also really high and requires more and more PokeYENs.</p>
<p>There are different ways to &ldquo;farm&rdquo; the PokeYENs, but all of them are inefficient if we compare them to the selling price of the most useful items and Pokèmon, therefore it was immediately clear to me that I needed to find a method to gain large amounts of PokeYENs with the minimum effort necessary and, above all, for free.
Always keep in mind that the difficulties to face when creating the automation are as many as the interactions in the game.</p>
<p>My research lasted about 1 week, during which I read and studied the various documents and posts available on the official PokeMMO forum.</p>
<p>In the end I found the Holy Graal: <strong>Shiny Hunting</strong>!</p>
<h3 id="shiny">Shiny?!</h3>
<p>Shiny Pokèmon, introduced from the II generation of the game, are just different sprites of the same Pokèmon you would usually catch; generally they are recognized because when they join a battle they are &ldquo;wrapped&rdquo; in flash or stars.</p>
<p>It&rsquo;s good to remember that a normal Pokèmon can&rsquo;t become Shiny, just as a Shiny Pokèmon can never become a normal Pokèmon.</p>
<p>What makes them so special? They are <strong>hard</strong> to obtain.</p>
<p>The spawn rate of these entities is of 1/30000 for each encounter.
Obviously, previous encounters don&rsquo;t influence in any way the spawn rate: the chance that a Pokèmon Shiny appears will always be the same even if you already met the &ldquo;classic&rdquo; version thousands and thousands of times.
In this case players generally aim for the Hordes Pokèmon.</p>
<p>A horde is a group of three or five wild Pokémon battled simultaneously in PokeMMO.</p>
<p>While walking and surfing in locations with hordes, players sometimes encounter a horde instead of a single wild Pokémon. Pokè Balls cannot be used in horde battles until only one member of the horde remains.</p>
<p>It&rsquo;s common, during an &ldquo;hunt&rdquo;, to reach a really high number of encounters; On average, it&rsquo;s estimated that a Shiny occurs between 18000 and 30000 encounters.
Obviously, there is no way to determine the exact number of encounters required; many players have been looking for the Shiny version of their favorite Pokèmon even for <strong>YEARS</strong> , also due to the high cost of the specific methods required to find them such as <a href="https://forums.pokemmo.com/index.php?/topic/49440-the-breeding-guide/">Egg Breeding</a>.</p>
<p>There are items and ranks, such as <em>Shiny Charms</em> (Used in-game, lasts 1 hour) and <em>Donator Rank</em> (Rank obtained for 7/15/31 days after making a donation with IRL money), that are able to decrease the spawn rate and therefore granting more chances to get a Shiny.</p>
<p>Below the affected spawn rates:</p>
<table>
  <thead>
      <tr>
          <th><strong>ITEMS</strong></th>
          <th><strong>RATE</strong></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>No Items</td>
          <td>1/30000</td>
      </tr>
      <tr>
          <td>Donator Status (+10%)</td>
          <td>1/27000</td>
      </tr>
      <tr>
          <td>Shiny Charm (+10%)</td>
          <td>1/27000</td>
      </tr>
      <tr>
          <td>Donator Status + Shiny Charm</td>
          <td>Approx. 1/24300</td>
      </tr>
  </tbody>
</table>
<p>All the items and ranks can be bought paying by IRL money or in-game PokeYENs.
It is obvious that the price in PokeYEN is high and, therefore, unattainable for novices unless you play for dozens and dozens of hours using other farming methods such as <a href="https://forums.pokemmo.com/index.php?/topic/145742-gym-guidebeginner-to-veteran-gym-rerun-teams-and-routes/">Gym Rebattles</a>, <a href="https://forums.pokemmo.com/index.php?/topic/106650-in-depth-money-making-guide-multiple-methods-2nd-edition/&amp;tab=comments#comment-1655417">PayDay</a> or the ever-green Flipping<sub>[1]</sub> of the Items/Pokèmon on the GTL.</p>
<p>*<sup>[1]</sup> &ldquo;Flipping&rdquo; means buying something to resell at an higher price in order to make a profit.</p>
<p>Many people spontaneously decide to &ldquo;hunt&rdquo; these particular Pokèmon because they are the most expensive and sought after in the game economy.</p>
<p>A single Shiny, depending on the IVs (In-game stats such as Attack Speed, Damage, etc.) can be sold from a base price of 800000 up to 1999999999 PokeYENs!
Catching a single Shiny can be game-breaking, because if sold it could yield a return of a large amount of money to the player, who can reinvest.</p>
<p>For additional information: <a href="https://forums.pokemmo.com/index.php?/topic/120706-pokemmo-shiny-hunting-guide-2023-encnespt/">PokeMMO Shiny Hunting Guide</a></p>
<h2 id="automating-the-hunting-process">Automating the hunting process</h2>
<p>Once I&rsquo;ve understood which is the most profitable (and hard) way to get PokeYENs, I&rsquo;ve decided to get my hands dirty.</p>
<p>It&rsquo;s easy to see that many players have tried to study, comprehend and find the best method to automate the process of hunting this kind of Pokèmon, or at least reduce the number of manual interactions required.
Most of the bot implementations I&rsquo;ve seen are aimed towards the Windows version of the game, automating the movements of the characters with specific macros.</p>
<p>What&rsquo;s a macro? A macro is simply a group of procedures that are executed on the system automatically when specific triggers are respected. It&rsquo;s able to interact within the game as a real player would, simulating the clicks of the keyboard and the movement of the mouse.</p>
<p>A macro can be easily written through tools such as <a href="https://www.autohotkey.com/">AutoHotkey</a> or some Python modules: <a href="https://pypi.org/project/PyAutoGUI/">pyautogui</a> and <a href="https://github.com/moses-palmer/pynput">pynput</a>.</p>
<p>However, as found by the user <a href="https://github.com/pnqphong95/">pnqphong95</a> on his GitHub repository <a href="https://github.com/pnqphong95/Pokemon-MMORPG-Bot">Pokemon-MMORPG-Bot</a>, the admins were able to suss him out before he could finish catching the Pokèmon for his team.</p>
<p><strong>His account was perma-banned</strong>.</p>
<p>The game&rsquo;s moderators take the bot issue very seriously, and will promptly reject any un-ban request, as seen from several posts made by other players on their official forum: <a href="/images/pokemmo/pokemmo-ban-notice.jpeg">Ban Notice</a>. Furthermore, while the game is running, there seems to be regular checks on the player to grant it&rsquo;s authenticity.</p>
<p>Actually, during my tests, I&rsquo;ve also noticed some anomalies that could be somehow related to the ban that the previously mentioned player received.
Without any kind of Reverse Engineering, I&rsquo;ve observed:</p>
<ul>
<li>Sudden movements of the player in other positions</li>
<li>Input-lag after a high amount of interactions</li>
</ul>
<p>It is clear that these hypothesis should be studied in depth, in order to determine their relevance in the detection mechanism of the game(if it exists). However, it seems safe to assume that the the Windows version has additional controls in place that effectively prevent/limit the use of these bots or report their anomalous behavior to the administrators, who manually verify everything.</p>
<p>The duration of the game session must also be considered because the game has implemented a mechanism of automatic disconnection from the server: the player will get disconnected if there doesn&rsquo;t seem to be any kind of action for more than 10/15 minutes.
Bots are usually connected for dozens of hours, if not days, so there&rsquo;s probably a system that allows them to &ldquo;list&rdquo; all the sessions and order them by their length, banning on-sight any session that has an unexplained length.</p>
<p>They&rsquo;ve also implemented a reCAPTCHA mechanism that gets suddenly displayed and it could be their latest verification method to establish if a player is &ldquo;botting&rdquo; or not.</p>
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
      <iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/fQbaBGN6g5E?autoplay=0&amp;controls=1&amp;end=0&amp;loop=0&amp;mute=0&amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"></iframe>
    </div>

<p>So what now? Shall we forget about this project and start to waste countless hours of our lives to catch one of these Pokèmon? Absolutely no!</p>
<p>As a wise man said:</p>
<blockquote>
<p>Success is not final; failure is not fatal: it is the courage to continue that counts</p>
<p>&ndash; <cite>Winston Churchill</cite></p>
</blockquote>
<h2 id="what-about-the-android-app">What about the Android APP?</h2>
<p>Excluding Windows, I had no other options except checking the Android port too.
Although it looks virtually identical, I believe that the detection systems work differently for this version.
Usually, when designing a cross-platform application in Java, the application itself is split into as many projects as the supported platforms, with the addition of a Java library for the core functionalities, where most of the work is generally done.
For instance, in order to make our application running on Windows and Android, we should have:</p>
<ol>
   <li> A project for Android-specific features</li>
   <li> A project for Windows-specific functionalities</li> 
   <li> A Java library shared between the first two projects, containing many of the essential features of the application.</li>
</ol>
<p>Therefore, it is easy to assume that in the Android project, although many aspects are the same, the detection mechanisms changes.</p>
<h2 id="implementation-of-macros-on-android">Implementation of macros on Android</h2>
<p>Well, after choosing our platform, it is time to start automating!</p>
<p>After some consideration, I have decided not to share my solution in a step-by-step way.
I am convinced that the massive use of these tools by the players would be able to inflate the economy of the GTL, thus destroying the very meaning of the game.</p>
<p>I will therefore just give general information, and also attach a demonstration video.</p>
<h4 id="image-recognition">Image Recognition</h4>
<p>The technology I&rsquo;ve used is Image Recognition, by which it is possible to search for specific images on the current screen of the device and then run macros.</p>
<p>By searching for items present only at specific times, it is possible to create automatic interactions that are not looped, thus generating many server-side errors, but only when certain conditions are met.</p>
</ol>
<p>An example of the elements I was looking for:</p>
<ol>
   <li> The error message "There's no PP left for this move"
      <ul> <li> Used as a trigger to teleport to a Pokèmon center and then return to the previous spot. </ul>  </li>
   </li>
   <li> The move "Sweet Scent" icon, inserted into the game hotbar.
      <ul> <li> Used as a trigger to start an encounter with a horde </ul>  </li>
   </li>
   <li> NAME+LEVEL+HEALTH BOXES of the single encounter Pokèmon 
      <ul> <li> Used as a trigger to escape from the fight with Pokèmon we do not seek.  </ul>  </li>
   </li>
   <li> NAME+LEVEL+HEALTH BOXES of the horde encounter Pokèmon
      <ul> <li> Used as a trigger to automatically escape from hordes that do not contain the Shiny Pokèmon we are looking for.   </ul>  </li> 
   </li> 
   <li> Player positions in the interested area
      <ul> <li> Used as triggers to take the character to specific places on the map, thus detecting wrong movements and fixing them. </ul> </li>
   </li>
</ol>
<p>An appropriate level of <em>tolerance</em> was found for each image used.
The <em>tolerance</em> allows the image to be recognized and identified in the current screen even if some of the pixels do not match.</p>
<p>In general, any self &ldquo;professional botter&rdquo; should always keep in mind that:</p>
<ul> 
   <li> Being slow is always better! The goal is to always appear as a legit user.</li>
   <li> It is possible for an error to occur in the player's movement, especially when the movement is implemented without any pathfinding or state determination algorithm.</li>
   <li> Manual interaction is likely to be necessary if errors occur; it is not always possible to foresee all of them. </li>
   <li> In most cases, creating bots for specific actions is better than creating generic bots.
   <li> Found a working solution? <b>Don't scale it too much!</b> </li>
</ul>
<br>
That said, I think it is also appropriate to show the results of my "hard" work.
<p>Below you will find a demo showing how the bot works; the screen was recorded in real time using <a href="https://github.com/Genymobile/scrcpy">scrcpy</a>.</p>
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
      <iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/Ki-tdaAxVG0?autoplay=0&amp;controls=1&amp;end=0&amp;loop=0&amp;mute=0&amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"></iframe>
    </div>

<p>In 3 days, after about 32,000 encounters, I managed to capture my Shiny Pokèmon!</p>
<p><img src="/images/pokemmo/shiny_gloom.jpeg" alt="Shiny Gloom"></p>
<p>My solution also includes the <strong>auto increment</strong> on the <strong>Encounters Counter</strong>; other players would literally <strong>kill</strong> just for this functionality!</p>
<p>The APP I used to keep track of the encounters is <a href="https://play.google.com/store/apps/details?id=com.SouthernPacificOceanFisher.FloatCounter&amp;hl=en&amp;gl=US">Floating Counter</a>.</p>
<p>I&rsquo;ve also created a modded version of it to suppress the ads, you can download the modified APK <a href="https://www.4shared.com/s/f9x4h8BF2ge">HERE</a> ( <strong>Password:</strong> <em><a href="https://www.balzabu.io">www.balzabu.io</a></em> ). Remember that no connection is required so you can turn off the &ldquo;Network&rdquo; permission if you want.</p>
<h3 id="extra-an-un-bannable-method">Extra: an un-bannable method?</h3>
<p>Keep in mind that if you decide to use any kind of automation to help your character in the game, it&rsquo;s possible that you get found and banned.
For this reason I&rsquo;ve decided to find other solutions that could simplify the hunting process without risking a ban.</p>
<h4 id="hotkeys">Hotkeys</h4>
<p>Hotkeys are a quick and easy way to associate certain actions in the game with specific keys or buttons.
They are the best method to automate common tasks, such as having to use &ldquo;Scent&rdquo; to initiate an encounter with a horde or run away from a battle if the Pokèmon encountered were not shiny.</p>
<p>On computers, you can use these Hotkeys, simply pressing the corresponding keys while on Android devices you need to click on the visible element in the UI.</p>
<p>Although it is possible to set the hotkeys and order them as you prefer, after an extended period of use I noticed how they are particularly inconvenient on devices with slightly larger screens.</p>
<p>The best solution to this problem is using an external support such as headphones with Volume Up/Down buttons or external controllers.
Using these devices we will have more physical buttons that we can press and then it will be possible to associate them with certain actions through APPs such as <a href="https://play.google.com/store/apps/details?id=com.irishin.buttonsremapper&amp;hl=it&amp;gl=US">Buttons Remapper</a>.</p>
<blockquote>
<p>Pro tip: you can also use an handheld console such as the <a href="https://www.goretroid.com/products/retroid-pocket-3-handheld-retro-gaming-system-1">Retroid Pocket 3+</a>.</p>
</blockquote>
<h2 id="the-end">The end?</h2>
<p>I have to admit that this experience was very addicting, the risk of being banned added that semblance of fear that, to be honest, was very challenging and fun.
After achieving my main goal, which consisted in catching a Pokèmon Shiny by simply looking at the device screen to make sure everything was working, I am enjoying all the other aspects of the game.</p>
<p><strong>I am not going to sell the Shiny to make a profit, I decided to keep it as a memory of this first blog post.</strong></p>
<p>I hope I&rsquo;ve tickled your curiosity and if you made it this far, you&rsquo;ll need to know that&hellip;We&rsquo;ll meet back here soon!
I have lots of things cooking that I think will be of your interest!</p>
<p>For questions or suggestions, contact: <a href="mailto:noc@balzabu.io">noc@balzabu.io</a>.</p>
<p>Bye \O/ !</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
