Skeetendo

’Cause all games were better on the GBC

You are not logged in.

  • Index
  • → Help/Question
  • → [pokecrystal] How do I edit SRAM? Should I be using script commands?

#1 2020-03-13 00:52:46

binomnpx
New member
Registered: 2020-03-13
Post 1/5

[pokecrystal] How do I edit SRAM? Should I be using script commands?

I am trying to repurpose some SRAM for new uses and to have the game automatically save certain things without the player needing to.


Why is it everytime I try the classic:

load BANK(sWhatever)
GetSRAMBank
CopyBytes into sWhatever
CloseSRAM

nothing ever happens?


I have been attempting to include code like the above via new script commands for overworld events. Is there a better way to do this? Also, should script commands be relied on in general for new things that do not already exist?


Some context for a couple of things I am trying to do:

I have a shop that gives you pokemon for game corner coins. I want to make it so that once a sale goes through, there is no restarting your game to undo the sale. This requires the game to save right after the sale.

If you win a battle in the battle tower, you are awarded coins immediately after. I want the game to save your coins in SRAM immediately after you receive them just in case you do not get a chance to manually save.


Thanks in advance.

Offline

#2 2020-03-13 16:54:09

Tauwasser
Member
Registered: 2010-10-16
Post 459/459

Re: [pokecrystal] How do I edit SRAM? Should I be using script commands?

What do you mean by "nothing ever happens"? What does not work in your opinion and what should happen?

Why do you need to use ASM to store this data? There is a dedicated scripting command to save the game.

Offline

#3 2020-03-13 21:35:23

binomnpx
New member
Registered: 2020-03-13
Post 2/5

Re: [pokecrystal] How do I edit SRAM? Should I be using script commands?

Tauwasser wrote:

What do you mean by "nothing ever happens"? What does not work in your opinion and what should happen?

Why do you need to use ASM to store this data? There is a dedicated scripting command to save the game.


Here's what I try to do:

1. Copy some WRAM into SRAM using a new script command

2. Shut the game off without manually saving

3. Expect to see the changes

No changes appear though. I tried searching through the SRAM using the bgb debugger and pokecrystal.map but all I see are FF's. There's a good chance I am looking in the wrong place though.

I am not aware of the dedicated scripting command. I tried using 'special TryQuickSave' found in the battle tower receptionist script (they ask you to save while you are talking to them) but I want the game to just save without being prompted.

I was able to create a new script command that farcall's _SaveGameData (found in engine/menus/save.asm) which doesn't prompt and just saves. I used it and had success but then I found that it was not good enough to save coins in the battle tower battle room because it also saves your location and gets you stuck in there if you shut the game off while in there.

Lately its been giving me bugs like swapping the player gender to a girl when you reload the save so I don't even know anymore.

Offline

#4 2020-03-24 22:51:47

binomnpx
New member
Registered: 2020-03-13
Post 3/5

Re: [pokecrystal] How do I edit SRAM? Should I be using script commands?

OK, I've got some answers.

1. I think my first issue is caused by not saving the Game Corner coins at the right address. So, for right now, I would disregard what I had to say about not being able to edit the SRAM. You probably can, if you write the correct code. Despite not being able to save specific, isolated bytes of WRAM to SRAM, I have even been able to save new WRAM into new SRAM by editing the "true" saving function SaveGameData found in engine/menus/save.asm (and load SRAM into WRAM by editing the load function). It's just that I have to save the new stuff with everything which means I cannot save Game Corner coins without simultaneously saving the player's location (not ideal when saving the game when inside the battle tower, which has been edited to give you coins after winning a battle). This is not a big deal right now but I may go back and attempt to do it.

N.B.: I just want to make it clear that I think it's simply me not saving and loading the correct addresses that is causing my issue. Do not let this discourage you from trying to directly edit the SRAM. The game is capable of doing it. I've seen it in other parts of the code. (Some of the BattleTowerAction commands do it).



2. I was able to create a working "auto-save" script command that doesn't mess with the player's gender like it was before.


Here's a skeleton of a tutorial:

1. Create a new script command in engine/overworld/scripting.asm and macros/scripts/events.asm that farcall's some new label with two colons (e.g. AutoSave::) located in engine/menus/save.asm. (BTW, I've got a tutorial on how to do this part on Pokecommunity under the decomp and disassembly section)

2. Have a look at the TryQuickSave special command. It has nested calls. Follow it until you get to engine/menus/save.asm. You pretty much need to copy what this does but just gut it so that there is none of the yes or no, text, or delay stuff that you normally see when you try to save the game.

3. Copy the gutted code and paste it under the AutoSave:: label

4. Everything should work fine. If you are struggling, just comment below and I'll provide more detail




Edit:

Better yet, here's the gutted code:

(Use at your own risk - hasn't given me any problems yet tho)

```
AutoSave::
ld a, [wSaveFileExists]
and a
jr z, .erase
call CompareLoadedAndSavedPlayerID
jr z, .ok

.erase
call ErasePreviousSave

.ok
and a
call PauseGameLogic
xor a
ldh [hJoypadReleased], a
ldh [hJoypadPressed], a
ldh [hJoypadSum], a
ldh [hJoypadDown], a
call _SaveGameData
call ResumeGameLogic
and a
ret
```

Last edited by binomnpx (2020-03-24 23:05:22)

Offline

  • Index
  • → Help/Question
  • → [pokecrystal] How do I edit SRAM? Should I be using script commands?

Board footer

Powered by FluxBB