Skip to content

Commit

Permalink
Remove trainer ID check in stats because it kept segfaulting with new…
Browse files Browse the repository at this point in the history
… games
  • Loading branch information
hanzi committed Oct 3, 2024
1 parent 2ca7119 commit 24131e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
8 changes: 6 additions & 2 deletions modules/gui/debug_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,16 @@ def update(self, emulator: "LibmgbaEmulator"):
def get_callback_data(symbol: str, offset: int = 0) -> dict:
pointer = max(0, unpack_uint32(read_symbol(symbol, offset, size=4)))
symbol_name = get_symbol_name_before(pointer, pretty_name=True)
actual_symbol_start, _ = get_symbol(symbol_name)
try:
actual_symbol_start, _ = get_symbol(symbol_name)
offset = hex(pointer - actual_symbol_start)
except RuntimeError:
offset = ""
return {
"__value": symbol_name if pointer > 0 else "0x0",
"pointer": hex(pointer),
"function": symbol_name,
"offset": hex(pointer - actual_symbol_start),
"offset": offset,
}

cb1_symbol = get_callback_data("gMain")
Expand Down
24 changes: 2 additions & 22 deletions modules/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import queue
import sys
from collections import deque
from threading import Thread
from typing import Generator

from modules.console import console
from modules.context import context
from modules.memory import get_game_state
from modules.modes import BotListener, BotMode, BotModeError, FrameInfo, get_bot_listeners, get_bot_mode_by_name
from modules.player import get_player
from modules.modes import BotMode, BotModeError, FrameInfo, get_bot_listeners, get_bot_mode_by_name
from modules.plugins import plugin_profile_loaded
from modules.stats import StatsDatabase, DataKey
from modules.stats import StatsDatabase
from modules.tasks import get_global_script_context, get_tasks

# Contains a queue of tasks that should be run the next time a frame completes.
Expand Down Expand Up @@ -53,7 +51,6 @@ def main_loop() -> None:

context.bot_listeners = get_bot_listeners(context.rom)
previous_frame_info: FrameInfo | None = None
verified_stats_trainer_id = False

while True:
# Process work queue, which can be used to get the main thread to access the emulator
Expand All @@ -65,23 +62,6 @@ def main_loop() -> None:

context.frame += 1

if not verified_stats_trainer_id:
player = get_player()
if player is not None and player.trainer_id > 0:
stats_trainer_id = context.stats.get_data(DataKey.TrainerID)
stats_secret_trainer_id = context.stats.get_data(DataKey.SecretTrainerID)

if stats_trainer_id is None and stats_secret_trainer_id is None:
context.stats.set_data(DataKey.TrainerID, str(player.trainer_id))
context.stats.set_data(DataKey.SecretTrainerID, str(player.secret_id))
elif str(player.trainer_id) != stats_trainer_id or str(player.secret_id) != stats_secret_trainer_id:
console.print(
f"\n[red]The trainer ID in this profile's stats database ({stats_trainer_id}) does not match the current trainer ID ({player.trainer_id}).[/]\n\nDid you start a new game?\nIf so, delete/move `stats.db` in your profile directory."
)
sys.exit(1)

verified_stats_trainer_id = True

game_state = get_game_state()
script_context = get_global_script_context()
script_stack = script_context.stack if script_context is not None and script_context.is_active else []
Expand Down

0 comments on commit 24131e6

Please sign in to comment.