add global macro: gCashEncrypted

This commit is contained in:
Ted John 2016-04-23 01:58:54 +01:00
parent 253f411075
commit 11a2ba0133
12 changed files with 28 additions and 22 deletions

View File

@ -3,6 +3,7 @@
#include "game.h"
#include "interface/window.h"
#include "network/network.h"
#include "management/finance.h"
#include "world/climate.h"
#include "world/footpath.h"
#include "world/scenery.h"
@ -196,12 +197,12 @@ static void cheat_increase_money(money32 amount)
{
money32 currentMoney;
currentMoney = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32));
currentMoney = DECRYPT_MONEY(gCashEncrypted);
if (currentMoney < INT_MAX - amount)
currentMoney += amount;
else
currentMoney = INT_MAX;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(currentMoney);
gCashEncrypted = ENCRYPT_MONEY(currentMoney);
window_invalidate_by_class(WC_FINANCES);
window_invalidate_by_class(WC_BOTTOM_TOOLBAR);

View File

@ -409,7 +409,7 @@ static int game_check_affordability(int cost)
{
if (cost <= 0)return cost;
if (RCT2_GLOBAL(0x141F568, uint8) & 0xF0)return cost;
if (cost <= (sint32)(DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32))))return cost;
if (cost <= (sint32)(DECRYPT_MONEY(gCashEncrypted)))return cost;
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint32) = cost;

View File

@ -16,6 +16,7 @@
#include "../object.h"
#include "../world/banner.h"
#include "../world/scenery.h"
#include "../management/finance.h"
#include "../management/research.h"
#include "../util/util.h"
#include "console.h"
@ -470,7 +471,7 @@ static int cc_get(const utf8 **argv, int argc)
console_printf("park_rating %d", gParkRating);
}
else if (strcmp(argv[0], "money") == 0) {
console_printf("money %d.%d0", DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)) / 10, DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)) % 10);
console_printf("money %d.%d0", DECRYPT_MONEY(gCashEncrypted) / 10, DECRYPT_MONEY(gCashEncrypted) % 10);
}
else if (strcmp(argv[0], "current_loan") == 0) {
console_printf("current_loan %d", RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32) / 10);
@ -601,7 +602,7 @@ static int cc_set(const utf8 **argv, int argc)
}
if (strcmp(argv[0], "money") == 0 && invalidArguments(&invalidArgs, double_valid[0])) {
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32) = ENCRYPT_MONEY(MONEY((int)double_val[0], ((int)(double_val[0] * 100)) % 100));
gCashEncrypted = ENCRYPT_MONEY(MONEY((int)double_val[0], ((int)(double_val[0] * 100)) % 100));
console_execute_silent("get money");
}
else if (strcmp(argv[0], "current_loan") == 0 && invalidArguments(&invalidArgs, int_valid[0])) {

View File

@ -58,11 +58,11 @@ money32 *gParkValueHistory = RCT2_ADDRESS(RCT2_ADDRESS_PARK_VALUE_HISTORY, money
*/
void finance_payment(money32 amount, rct_expenditure_type type)
{
money32 cur_money = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32));
money32 cur_money = DECRYPT_MONEY(gCashEncrypted);
money32 new_money = cur_money - amount;
//overflow check
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(new_money);
gCashEncrypted = ENCRYPT_MONEY(new_money);
RCT2_ADDRESS(RCT2_ADDRESS_EXPENDITURE_TABLE, money32)[type] -= amount;
if (dword_988E60[type] & 1)
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_EXPENDITURE, money32) -= amount; // Cumulative amount of money spent this day
@ -177,7 +177,7 @@ void finance_init() {
RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32) = MONEY(10000,00); // Cheat detection
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(MONEY(10000,00));
gCashEncrypted = ENCRYPT_MONEY(MONEY(10000,00));
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32) = MONEY(10000,00);
RCT2_GLOBAL(RCT2_ADDRESS_MAXIMUM_LOAN, money32) = MONEY(20000,00);
@ -282,7 +282,7 @@ money32 finance_get_maximum_loan()
money32 finance_get_current_cash()
{
return DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32));
return DECRYPT_MONEY(gCashEncrypted);
}
/**
@ -295,7 +295,7 @@ void game_command_set_current_loan(int* eax, int* ebx, int* ecx, int* edx, int*
money32 newLoan = *edx;
currentLoan = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32);
money = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32));
money = DECRYPT_MONEY(gCashEncrypted);
loanDifference = currentLoan - newLoan;
RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_INTEREST * 4;
@ -317,7 +317,7 @@ void game_command_set_current_loan(int* eax, int* ebx, int* ecx, int* edx, int*
money -= loanDifference;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32) = newLoan;
RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32) = money;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32) = ENCRYPT_MONEY(money);
gCashEncrypted = ENCRYPT_MONEY(money);
finance_update_loan_hash();
window_invalidate_by_class(WC_FINANCES);
@ -362,5 +362,5 @@ void finance_shift_expenditure_table() {
*/
void finance_reset_cash_to_initial()
{
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32) = ENCRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32));
gCashEncrypted = ENCRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32));
}

View File

@ -46,6 +46,8 @@ enum {
#define EXPENDITURE_TABLE_MONTH_COUNT 16
#define EXPENDITURE_TABLE_TOTAL_COUNT (EXPENDITURE_TABLE_MONTH_COUNT * RCT_EXPENDITURE_TYPE_COUNT)
#define gCashEncrypted RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)
extern const money32 research_cost_table[4];
extern money32 *gCashHistory;

View File

@ -45,6 +45,7 @@ extern "C" {
#include "../interface/keyboard_shortcut.h"
#include "../localisation/date.h"
#include "../localisation/localisation.h"
#include "../management/finance.h"
#include "../network/http.h"
#include "../scenario.h"
#include "../windows/error.h"
@ -1130,7 +1131,7 @@ void Network::AdvertiseHeartbeat()
json_object_set_new(gameInfo, "guests", json_integer(gNumGuestsInPark));
json_object_set_new(gameInfo, "parkValue", json_integer(gParkValue));
if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) {
money32 cash = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32));
money32 cash = DECRYPT_MONEY(gCashEncrypted);
json_object_set_new(gameInfo, "cash", json_integer(cash));
}

View File

@ -656,7 +656,7 @@ void S4Importer::ImportFinance()
gLandPrice = _s4.land_price;
gConstructionRightsPrice = _s4.construction_rights_price;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, uint32) = ENCRYPT_MONEY(_s4.cash);
gCashEncrypted = ENCRYPT_MONEY(_s4.cash);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32) = _s4.loan;
RCT2_GLOBAL(RCT2_ADDRESS_MAXIMUM_LOAN, money32) = _s4.max_loan;
RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32) = _s4.cash;

View File

@ -281,7 +281,7 @@ void scenario_begin()
gParkValue = calculate_park_value();
gCompanyValue = calculate_company_value();
RCT2_GLOBAL(0x013587D0, money32) = RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32) - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32) = ENCRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, sint32));
gCashEncrypted = ENCRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, sint32));
finance_update_loan_hash();

View File

@ -484,7 +484,7 @@ static void window_editor_scenario_options_financial_mousedown(int widgetIndex,
case WIDX_INITIAL_CASH_INCREASE:
if (RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32) < MONEY(1000000,00)) {
RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32) += MONEY(500,00);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32) = ENCRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32));
gCashEncrypted = ENCRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32));
finance_update_loan_hash();
} else {
window_error_open(3248, STR_NONE);
@ -494,7 +494,7 @@ static void window_editor_scenario_options_financial_mousedown(int widgetIndex,
case WIDX_INITIAL_CASH_DECREASE:
if (RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32) > MONEY(0,00)) {
RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32) -= MONEY(500,00);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32) = ENCRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32));
gCashEncrypted = ENCRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_INITIAL_CASH, money32));
finance_update_loan_hash();
} else {
window_error_open(3249, STR_NONE);

View File

@ -738,7 +738,7 @@ static void window_finances_summary_paint(rct_window *w, rct_drawpixelinfo *dpi)
gfx_draw_string_left(dpi, STR_FINANCES_SUMMARY_AT_X_PER_YEAR, (void*)RCT2_ADDRESS_COMMON_FORMAT_ARGS, 0, w->x + 156, w->y + 229);
// Current cash
money32 currentCash = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32));
money32 currentCash = DECRYPT_MONEY(gCashEncrypted);
rct_string_id stringId = currentCash >= 0 ? STR_CASH_LABEL : STR_CASH_NEGATIVE_LABEL;
gfx_draw_string_left(dpi, stringId, &currentCash, 0, w->x + 4, w->y + 244);
@ -824,7 +824,7 @@ static void window_finances_financial_graph_paint(rct_window *w, rct_drawpixelin
// Cash (less loan)
money32 cashLessLoan =
DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)) -
DECRYPT_MONEY(gCashEncrypted) -
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32);
gfx_draw_string_left(

View File

@ -26,6 +26,7 @@
#include "../interface/window.h"
#include "../localisation/date.h"
#include "../localisation/localisation.h"
#include "../management/finance.h"
#include "../management/news_item.h"
#include "../peep/peep.h"
#include "../peep/staff.h"
@ -380,7 +381,7 @@ static void window_game_bottom_toolbar_draw_left_panel(rct_drawpixelinfo *dpi, r
// Draw money
if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) {
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, int) = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32));
RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, int) = DECRYPT_MONEY(gCashEncrypted);
gfx_draw_string_centred(
dpi,
(RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, int) < 0 ? 1391 : 1390),

View File

@ -327,7 +327,7 @@ money32 calculate_park_value()
money32 calculate_company_value()
{
return
DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, sint32)) +
DECRYPT_MONEY(gCashEncrypted) +
gParkValue -
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32);
}
@ -612,7 +612,7 @@ void park_update_histories()
// Update current cash history
for (int i = 127; i > 0; i--)
gCashHistory[i] = gCashHistory[i - 1];
gCashHistory[0] = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)) - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32);
gCashHistory[0] = DECRYPT_MONEY(gCashEncrypted) - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32);
window_invalidate_by_class(WC_FINANCES);
// Update weekly profit history