Skip to content

Commit

Permalink
Allow editing the turn-to-stone conditions.
Browse files Browse the repository at this point in the history
There is a coding error in the original game.  The error is never
triggered because the palace items numbers are self-same to the
palace number which they are found in.

1. Detect and preserve original game behavior.
2. Provide a fixed version.
3. Provide a turn-to-stone disabled option.
  • Loading branch information
Chris Frantz committed Apr 6, 2020
1 parent 63c3000 commit 73bea56
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
20 changes: 15 additions & 5 deletions content/palace_continue.textpb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,26 @@ palace_continue {
}

palace_to_stone {
name: "Vanilla (palaces turn to stone)"
name: "Vanilla (turn to stone w/ original coding error)"
hack: [
{address { bank:1 address:0x8797 } data: [0x00, 0x01, 0x02, 0x03]},
{address { bank:2 address:0x8797 } data: [0x04, 0x05, 0xFF, 0x03]}
{address { bank:1 address:0x87aa } data: [0xb9, 0x8d, 0x07]},
{address { bank:2 address:0x87b3 } data: [0xb9, 0x8d, 0x07]},
{address { bank:-1 address:0xe01e } data: [0x20, 0x9b, 0x87]}
]
}
palace_to_stone {
name: "Palaces turn to stone (error fixed)"
hack: [
{address { bank:1 address:0x87aa } data: [0xbd, 0x8d, 0x07]},
{address { bank:2 address:0x87b3 } data: [0xbd, 0x8d, 0x07]},
{address { bank:-1 address:0xe01e } data: [0x20, 0x9b, 0x87]}
]
}
palace_to_stone {
name: "Disable turning to stone"
hack: [
{address { bank:1 address:0x8797 } data: [0xFF, 0xFF, 0xFF, 0xFF]},
{address { bank:2 address:0x8797 } data: [0xFF, 0xFF, 0xFF, 0xFF]}
{address { bank:1 address:0x87aa } data: [0xea, 0xea, 0xea]},
{address { bank:2 address:0x87b3 } data: [0xea, 0xea, 0xea]},
{address { bank:-1 address:0xe01e } data: [0xea, 0xea, 0xea]}
]
}
51 changes: 51 additions & 0 deletions imwidget/misc_hacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@

namespace z2util {

const char* MiscellaneousHacks::collectable_names_[MAX_COLLECTABLE];

void MiscellaneousHacks::Init() {
static char collectable[MAX_COLLECTABLE][32];
const auto& ri = ConfigLoader<RomInfo>::GetConfig();
for(int i=0; i<MAX_COLLECTABLE; i++) {
const auto& c = ri.items().info().find(i);
if (c == ri.items().info().end()) {
snprintf(collectable[i], 31, "%02x: ???", i);
} else {
snprintf(collectable[i], 31, "%02x: %s", i, c->second.name().c_str());
}
collectable_names_[i] = collectable[i];
}
}

bool MiscellaneousHacks::Draw() {
if (!visible_)
return false;
Expand Down Expand Up @@ -36,6 +52,37 @@ bool MiscellaneousHacks::Draw() {
return changed;
}


bool MiscellaneousHacks::DrawPalaceCompletionItems() {
const auto& ri = ConfigLoader<RomInfo>::GetConfig();
const auto& misc = ri.misc();
char palace[4];
int item;
bool changed = false;
ImGui::Text("Palace Completion Items:");
ImGui::Text(" ");
ImGui::PushItemWidth(90);
for(int i=0; i<6; ++i) {
// Palace four has a special configuration in overworld_palace_ram,
// but the offsets for completion items don't care about that.
const auto& addr = (i<4) ? misc.overworld_palace_ram(0)
: misc.overworld_palace_ram(2);
int offset = (i<4) ? i : i-4;
item = mapper_->Read(addr, 8+offset);
snprintf(palace, sizeof(palace), "P%d", i+1);
ImGui::SameLine();
if (ImGui::Combo(palace, &item, collectable_names_, MAX_COLLECTABLE)) {
mapper_->Write(addr, 8+offset, item);
if (i==3) {
// Palace 4 gets to be in both banks.
mapper_->Write(misc.overworld_palace_ram(2), 8+offset, item);
}
}
}
ImGui::PopItemWidth();
return changed;
}

bool MiscellaneousHacks::DrawMiscHacks() {
const auto& ri = ConfigLoader<RomInfo>::GetConfig();
const auto& misc = ri.misc();
Expand Down Expand Up @@ -122,6 +169,10 @@ bool MiscellaneousHacks::DrawMiscHacks() {
Hack("Completed Places", ri.palace_to_stone_size(),
[&]() { return ri.palace_to_stone(); },
[&](int n) { return ri.palace_to_stone(n); });
if (EnabledIndex([&]() { return ri.palace_to_stone(); }) == 1) {
// If its the fixed version, let the user edit the table.
DrawPalaceCompletionItems();
}

Hack("Overworld BreakBlocks", ri.overworld_breakblocks_size(),
[&]() { return ri.overworld_breakblocks(); },
Expand Down
6 changes: 5 additions & 1 deletion imwidget/misc_hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@ namespace z2util {

class MiscellaneousHacks: public ImWindowBase {
public:
MiscellaneousHacks(): ImWindowBase(false), tab_(0) {};
MiscellaneousHacks(): ImWindowBase(false), tab_(0) { Init(); }

void Init();
void Refresh() override { CheckConfig(); }
bool Draw() override;
bool DrawMiscHacks();
bool DrawDynamicBanks();
void CheckConfig();
inline void set_mapper(Mapper* m) { mapper_ = m; };

const static int MAX_COLLECTABLE = 36;
private:
template<class GETALL, class GET>
int Hack(const char* hackname, int n, GETALL getall, GET get);
template<class GETALL>
int EnabledIndex(GETALL getall);

bool DrawPalaceCompletionItems();
bool MemcmpHack(const PokeData& data);
void PutPokeData(const PokeData& data);
void PutGameHack(const GameHack& hack);

int tab_;
Mapper* mapper_;
static const char *collectable_names_[MAX_COLLECTABLE];
};

} // namespace
Expand Down

0 comments on commit 73bea56

Please sign in to comment.