Skip to content
LOuroboros edited this page Aug 20, 2023 · 24 revisions

Credit to paccy for this tutorial in the Simple Modifications Pokecommunity thread. The tutorial was modified by ExpoSeed, surskitty, FieryMewtwo and Lunos.

This tutorial will make all TMs infinitely reusable, unholdable by Pokemon, unsellable to shops, and also removes the number from appearing in the Bag.

Contents

  1. Don't consume TMs on use
  2. Treat TMs as HMs in the bag
  3. Don't allow TM selling and rebuying
  4. Don't replenish PP when TMs are used
  5. Correct the in-game references to the old TM behavior

1. Don't consume TMs on use

Normally, the game checks if the item used was a TM or an HM, and consumes the item if it was a TM. We can just simply remove this check.

Edit src/party_menu.c:

static void Task_LearnedMove(u8 taskId)
{
    struct Pokemon *mon = &gPlayerParty[gPartyMenu.slotId];
    s16 *move = &gPartyMenu.data1;
    u16 item = gSpecialVar_ItemId;

    if (move[1] == 0)
    {
        AdjustFriendship(mon, FRIENDSHIP_EVENT_LEARN_TMHM);
-       if (item < ITEM_HM01_CUT)
-           RemoveBagItem(item, 1);
    }
    GetMonNickname(mon, gStringVar1);
    StringCopy(gStringVar2, gMoveNames[move[0]]);
    StringExpandPlaceholders(gStringVar4, gText_PkmnLearnedMove3);
    DisplayPartyMenuMessage(gStringVar4, TRUE);
    ScheduleBgCopyTilemapToVram(2);
    gTasks[taskId].func = Task_DoLearnedMoveFanfareAfterText;
}

If you were to stop here, TMs can still be given to Pokemon and you can still see the number in the bag. The next step will address this.

2. Treat TMs as HMs in the bag

struct Item has a field importance. If this field has a nonzero value, then the item is treated like a key item, and cannot be held, tossed, or deposited in the PC, and it will not display an item count in the bag.

Edit src/data/items.h:

    [ITEM_TM01_FOCUS_PUNCH] =
    {
        .name = _("TM01"),
        .itemId = ITEM_TM01_FOCUS_PUNCH,
        .price = 3000,
        .description = sTM01Desc,
+       .importance = 1,
        .pocket = POCKET_TM_HM,
        .type = 1,
        .fieldUseFunc = ItemUseOutOfBattle_TMHM,
        .secondaryId = 0,
    },

You will need to repeat the above for every TM.

But there is still an issue: TMs can still be sold. This will be addressed in the next step.

3. Don't allow TM selling and rebuying

If you were to see what determines if an item can be sold, you will find that any item with a price of 0 cannot be sold. So it's as simple as setting the TM prices to 0, right? Wrong. Setting the item price to 0 also means that the buying price will also be 0!

In order to avoid this, we will need to modify the logic that checks for whether an item can be sold. All we need to do is check if the item ID is a TM. Edit the Task_ItemContext_Sell function of src/item_menu.c:

-    if (ItemId_GetPrice(gSpecialVar_ItemId) == 0)
+    if (ItemId_GetPrice(gSpecialVar_ItemId) == 0 || ItemId_GetPocket(gSpecialVar_ItemId) == POCKET_TM_HM)
     {
         CopyItemName(gSpecialVar_ItemId, gStringVar2);
         StringExpandPlaceholders(gStringVar4, gText_CantBuyKeyItem);
         DisplayItemMessage(taskId, 1, gStringVar4, BagMenu_InitListsMenu);
     }

The last issue to take care of is that TMs that the player already has can be bought again for no effect. This step is technically optional, but it is nice to have that bit of polish.

We will first need to add a new string. Edit include/strings.h:

 extern const u8 gText_InBagVar1[];
 extern const u8 gText_Var1AndYouWantedVar2[];
 extern const u8 gText_HereYouGoThankYou[];
 extern const u8 gText_NoMoreRoomForThis[];
+extern const u8 gText_YouAlreadyHaveThis[];
 extern const u8 gText_ThankYouIllSendItHome[];
 extern const u8 gText_ThanksIllSendItHome[];
 extern const u8 gText_SpaceForVar1Full[];
 extern const u8 gText_ThrowInPremierBall[];

Edit src/strings.c:

 const u8 gText_ThanksIllSendItHome[] = _("Thanks!\nI'll send it to your PC at home.");
 const u8 gText_YouDontHaveMoney[] = _("You don't have enough money.{PAUSE_UNTIL_PRESS}");
 const u8 gText_NoMoreRoomForThis[] = _("You have no more room for this\nitem.{PAUSE_UNTIL_PRESS}");
+const u8 gText_YouAlreadyHaveThis[] = _("You already have this item.{PAUSE_UNTIL_PRESS}");
 const u8 gText_SpaceForVar1Full[] = _("The space for {STR_VAR_1} is full.{PAUSE_UNTIL_PRESS}");
 const u8 gText_AnythingElseICanHelp[] = _("Is there anything else I can help\nyou with?");
 const u8 gText_CanIHelpWithAnythingElse[] = _("Can I help you with anything else?");

Now to add the code that prevents the rebuying. Edit the Task_BuyMenu function of src/shop.c:

             if (!IsEnoughMoney(&gSaveBlock1Ptr->money, gShopDataPtr->totalCost))
             {
                 BuyMenuDisplayMessage(taskId, gText_YouDontHaveMoney, BuyMenuReturnToItemList);
             }
+            else if (ItemId_GetPocket(itemId) == POCKET_TM_HM && CheckBagHasItem(itemId, 1))
+            {
+                BuyMenuDisplayMessage(taskId, gText_YouAlreadyHaveThis, BuyMenuReturnToItemList);
+            }
             else
             {

This prevents rebuying from shops, but there's still the Mauville Game Corner. Let's go to data/maps/MauvilleCity_GameCorner/scripts.inc.

First, let's replace the MauvilleCity_GameCorner_EventScript_NoRoomForTM function with MauvilleCity_GameCorner_EventScript_YouAlreadyHaveThis. The bag will no longer be full, so let's instead use the same string we used for the shops.

        goto MauvilleCity_GameCorner_EventScript_ReturnToChooseTMPrize
        end
 
-MauvilleCity_GameCorner_EventScript_NoRoomForTM::
-       call Common_EventScript_BagIsFull
+MauvilleCity_GameCorner_EventScript_YouAlreadyHaveThis::
+       msgbox gText_YouAlreadyHaveThis, MSGBOX_DEFAULT
        goto MauvilleCity_GameCorner_EventScript_ReturnToChooseTMPrize
        end

Next, we need to replace all of the checks to see if there is room with checks for if you have the item. These currently use checkitemspace. We can replace them with checkitem and exiting the function if the result is true.

        compare VAR_TEMP_2, TM13_COINS
        goto_if_lt MauvilleCity_GameCorner_EventScript_NotEnoughCoinsForTM
-       checkitemspace ITEM_TM13, 1
-       goto_if_eq VAR_RESULT, FALSE, MauvilleCity_GameCorner_EventScript_NoRoomForTM
+       checkitem ITEM_TM13, 1
+       goto_if_eq VAR_RESULT, TRUE, MauvilleCity_GameCorner_EventScript_YouAlreadyHaveThis
        removecoins TM13_COINS
        additem ITEM_TM13
        updatecoinsbox 1, 1

Repeat for each TM.

We are almost done, but there is one final issue to deal with: TMs will replenish PP. It is time to address that.

4. Don't replenish PP when TMs are used

This step is also technically optional (and accurate to Gen 6+ behavior!), but right now, if you overwrite a TM move with another TM and then reteach the old TM, the move will get all its PP back! This is an exploit that can be used to retain infinite PP on that move. Gen 5's solution was to assign the lower of the new PP or the old PP, meaning that TMs cannot be used to gain PP.

To replicate this, open up Task_PartyMenuReplaceMove of src/party_menu.c:

 static void Task_PartyMenuReplaceMove(u8 taskId)
 {
     struct Pokemon *mon;
     u16 move;
+    u8 oldPP;
 
     if (IsPartyMenuTextPrinterActive() != TRUE)
     {
         mon = &gPlayerParty[gPartyMenu.slotId];
         RemoveMonPPBonus(mon, GetMoveSlotToReplace());
+        oldPP = GetMonData(mon, MON_DATA_PP1 + GetMoveSlotToReplace(), NULL);
         move = gPartyMenu.data1;
         SetMonMoveSlot(mon, move, GetMoveSlotToReplace());
+        if (GetMonData(mon, MON_DATA_PP1 + GetMoveSlotToReplace(), NULL) > oldPP)
+            SetMonData(mon, MON_DATA_PP1 + GetMoveSlotToReplace(), &oldPP);
         Task_LearnedMove(taskId);
     }
 }

We remember the PP before replacing the move, and if it's lower than the new PP, we put the old PP back in the move slot.

5. Correct the in-game references to the old TM behavior

One more change can be made; the text in-game still references the way in which TMs used to work!

Let's fix that.

In data/maps/Route104/scripts.inc:

Route104_EventScript_ReceivedBulletSeed::
-	msgbox Route104_Text_TMsAreOneTimeUse, MSGBOX_DEFAULT
+	msgbox Route104_Text_TMsCanBeReused, MSGBOX_DEFAULT
	release
	end
-Route104_Text_TMsAreOneTimeUse:
-	.string "A word of advice!\p"
-	.string "A TM, TECHNICAL MACHINE, is good only\n"
-	.string "for one-time use.\p"
-	.string "Once you use it, it's gone.\n"
-	.string "Think twice before using it!$"
+Route104_Text_TMsCanBeReused:
+	.string "By the way, a TM, TECHNICAL MACHINE,\n"
+	.string "can be used as many times as you want!$"

In data/maps/RustboroCity_Gym/scripts.inc:

RustboroCity_Gym_Text_ExplainRockTomb:
	.string "That TECHNICAL MACHINE, TM39,\n"
	.string "contains ROCK TOMB.\p"
	.string "It not only inflicts damage by dropping\n"
	.string "rocks, it also lowers SPEED.\p"
	.string "If you use a TM, it instantly teaches\n"
	.string "the move to a POKéMON.\p"
-	.string "Remember, a TM can be used only once,\n"
-	.string "so think before you use it.$"
+	.string "A TM can be used as many times as you'd\n"
+	.string "like, so please enjoy it.$"

In data/maps/RustboroCity_CuttersHouse/scripts.inc:

RustboroCity_CuttersHouse_Text_ExplainCut:
	.string "That HIDDEN MACHINE, or HM for\n"
	.string "short, is CUT.\p"
	.string "An HM move is one that can be used\n"
	.string "by POKéMON outside of battle.\p"
	.string "Any POKéMON that's learned CUT can\n"
	.string "chop down thin trees if the TRAINER\l"
	.string "has earned the STONE BADGE.\p"
-	.string "And, unlike a TM, an HM can be used\n"
+	.string "And, like a TM, an HM can be used\n"
	.string "more than once.$"

And that's it! TMs are now reusable just like in Gen 5!

Optionally, now that your TMs are reusable, you can see this code diff for an implementation by SBird/Karathan that turns TMs and HMs into a bitfield, freeing up a good amount of space in the SaveBlock1.

Clone this wiki locally