summaryrefslogtreecommitdiff
path: root/Increase-money-limit.md
blob: 1ab5d01f07beb991248d388cae70e1d27f2c02b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Credit to DizzyEgg for this feature. This feature may also be directly be pulled from DizzyEgg's [money](https://github.com/DizzyEggg/pokeemerald/tree/money) branch.

This tutorial will raise the money limit to 9,999,999.

## Contents
1. [Increase max money amount](#1-increase-max-money-amount)
2. [Fix usages of money](#2-fix-usages-of-money)

## 1. Increase max money amount
The first and most obvious thing we need to do is increase the max money constant. Edit [src/money.c](../blob/master/src/money.c):
```diff
-#define MAX_MONEY 999999
+#define MAX_MONEY 9999999
```
Doing this change alone will have some consequences elsewhere though. A 7 digit number for money won't be processed and displayed correctly.

The position the money amount is at is now incorrect. We can fix this by editing the function to print the amount in the same file:
```diff
 void PrintMoneyAmountInMoneyBox(u8 windowId, int amount, u8 speed)
 {
-    PrintMoneyAmount(windowId, 38, 1, amount, speed);
+    PrintMoneyAmount(windowId, 32, 1, amount, speed);
 }
```
We also need to fix the printing of the money itself, as right now, it only supports a 6 digit number. All we need to do is change 6 to 7 in the same file:
```diff
 void PrintMoneyAmount(u8 windowId, u8 x, u8 y, int amount, u8 speed)
 {
     u8 *txtPtr;
     s32 strLength;
 
-    ConvertIntToDecimalStringN(gStringVar1, amount, STR_CONV_MODE_LEFT_ALIGN, 6);
+    ConvertIntToDecimalStringN(gStringVar1, amount, STR_CONV_MODE_LEFT_ALIGN, 7);
 
-    strLength = 6 - StringLength(gStringVar1);
+    strLength = 7 - StringLength(gStringVar1);
     txtPtr = gStringVar4;
 
     while (strLength-- > 0)
         *(txtPtr++) = CHAR_SPACER;
 
     StringExpandPlaceholders(txtPtr, gText_PokedollarVar1);
     AddTextPrinterParameterized(windowId, FONT_NORMAL, gStringVar4, x, y, speed, NULL);
 }
```
Now that money prints properly, we need to update the places where they are used.

## 2. Fix usages of money
The x value when printing money in shops also needs to be adjusted. Edit [src/shop.c](../blob/master/src/shop.c):
```diff
 static void BuyMenuPrintItemQuantityAndPrice(u8 taskId)
 {
     s16 *data = gTasks[taskId].data;
 
     FillWindowPixelBuffer(4, PIXEL_FILL(1));
-    PrintMoneyAmount(4, 38, 1, gShopDataPtr->totalCost, TEXT_SKIP_DRAW);
+    PrintMoneyAmount(4, 32, 1, gShopDataPtr->totalCost, TEXT_SKIP_DRAW);
     ConvertIntToDecimalStringN(gStringVar1, tItemCount, STR_CONV_MODE_LEADING_ZEROS, BAG_ITEM_CAPACITY_DIGITS);
     StringExpandPlaceholders(gStringVar4, gText_xVar1);
     BuyMenuPrint(4, gStringVar4, 0, 1, 0, 0);
 }
```

We need to adjust the function call in the trainer card. Edit [src/trainer_card.c](../blob/master/src/trainer_card.c):
```diff
 static void PrintMoneyOnCard(void)
 {
     s32 xOffset;
     u8 top;
 
     if (!sData->isHoenn)
         AddTextPrinterParameterized3(1, 1, 20, 56, sTrainerCardTextColors, TEXT_SKIP_DRAW, gText_TrainerCardMoney);
     else
         AddTextPrinterParameterized3(1, 1, 16, 57, sTrainerCardTextColors, TEXT_SKIP_DRAW, gText_TrainerCardMoney);
 
-    ConvertIntToDecimalStringN(gStringVar1, sData->trainerCard.money, STR_CONV_MODE_LEFT_ALIGN, 6);
+    ConvertIntToDecimalStringN(gStringVar1, sData->trainerCard.money, STR_CONV_MODE_LEFT_ALIGN, 7);
     StringExpandPlaceholders(gStringVar4, gText_PokedollarVar1);
     if (!sData->isHoenn)
     {
         xOffset = GetStringRightAlignXOffset(1, gStringVar4, 144);
         top = 56;
     }
     else
     {
         xOffset = GetStringRightAlignXOffset(1, gStringVar4, 128);
         top = 57;
     }
     AddTextPrinterParameterized3(1, FONT_NORMAL, xOffset, top, sTrainerCardTextColors, TEXT_SKIP_DRAW, gStringVar4);
 }
```

Finally, we need to adjust the x value in [src/item_menu.c](../blob/master/src/item_menu.c):
```diff
 static void PrintItemSoldAmount(int windowId, int numSold, int moneyEarned)
 {
     u8 numDigits = (gBagPosition.pocket == BERRIES_POCKET) ? BERRY_CAPACITY_DIGITS : BAG_ITEM_CAPACITY_DIGITS;
     ConvertIntToDecimalStringN(gStringVar1, numSold, STR_CONV_MODE_LEADING_ZEROS, numDigits);
     StringExpandPlaceholders(gStringVar4, gText_xVar1);
     AddTextPrinterParameterized(windowId, FONT_NORMAL, gStringVar4, 0, 1, TEXT_SKIP_DRAW, 0);
-    PrintMoneyAmount(windowId, 38, 1, moneyEarned, 0);
+    PrintMoneyAmount(windowId, 32, 1, moneyEarned, 0);
 }
```

And that's it!

![](https://i.imgur.com/MfLQ3aT.png)
![](https://i.imgur.com/HxZtj9v.png)

Note: if you want 8 digits, use `8` instead of `7` for digit count and `26` instead of `32`. Don't forget to set `MAX_MONEY` appropriately.