Making a Level Select code/mod for Cosmic Smash

Place for discussing homebrew games, development, new releases and emulation.

Moderator: VasiliyRS

3l3tric
noob
Posts: 3

Making a Level Select code/mod for Cosmic Smash

Post#1 » Wed Sep 16, 2020 9:35 pm

Hello!

I'm looking to make either a gs/xploder code or just modify the gdi of Cosmic Smash to create a level select code in the game. It seems like an interesting game for speedrunning, and I'd like to be able to practice individual levels on repeat rather than have to do full game runs for practice.

I don't have any real experience with game modding like this, but so far I've been able to use demul and cheat engine to find a few memory values I'll need for this process. Here's everything I've found so far:

Code: Select all

2C16E7A0 and 2C16E7A4 are level select variables in-game. After some levels are completed, you have a choice for the next one, hence 2 variables. When they're the same the game just takes you to the next level they designate. When they differ the game will give the branching choice, even if the 2 levels wouldn't normally be on a branch anywhere in the normal game. For ongoing repetition of levels, these will almost definitely need to be held at a specific value. I believe these only get updated at the start of a level.

2C16E794 is level select from main menu. Whatever value is here will be the starting level after hitting "game start" on the main menu. This value seems to still get updated at the end of each level transition, even though it doesn't seem to have any influence on future level selects after the first.

2C162F78 seems to be related to level select, as it updates as soon as the results screen of a level appears, but setting it inactive or setting it to strange values doesn't have an effect on the game. I feel like maybe this is used in some visual process, like the lighting of sections of the map or something similar, that needs to update with the levels but won't affect them if it's wrong.

2C17E79C behaves similarly to 2C16E794, as in it updates at the same times, but changing it doesn't seem to have an effect on starting level. Maybe 94 and 9C are a pair in the same way A0 and A4 are, but 94 ends up getting used from the main menu since the game would initialize both variables to 0 at the game over screen anyway. Likely not necessary for level select things.

2C20B320 Index for option screen. Starts at 0 and increases as you scroll down through the list. Maybe this could be used to somehow add more menu options, but likely this won't be necessary for level select.

2C20D2E8 Start Time variable. In the options screen, you can set your start of game timer to any value between 50 and 150 by steps of 5. If you modify the code that adds 5 every time the value is incremented, you can get results by ones without causing issues with the game, and the limits of 50 and 150 can both be bypassed with similar modification. This would probably be the best candidate for modification into a level select function, as you should be able to modify the code to have this variable written to one of the earlier locations instead. I've verified through cheat engine's debugger that these modifications can be made on a per instruction basis and the game still runs. In total you need to modify 4 instructions to remove both the limits and the 5 increment.

2C24072A Start Time variable in-game. This value gets updated right after the previous, and it seems this one is what the game bases its starting time off of, while the other variable is used to update the options menu. When you change the start time, D2E8 gets updated first and then 072A gets updated. If the function that updated this value instead updated 2C16E794 (main menu level select), you'd have the ability to choose any level from the start, and if the value is also pushed to 2C16E7A0 and A4 that level would be repeated indefinitely (at least, as far as my few hours of research thus far have shown). Therefore, I think these memory values should be enough to implement a practice code that allows selecting and repeating any given level from the main menu. One potential stumbling block is that this value (2C24072A) seems to get written to pretty often, even when you haven't changed the start time at all. It doesn't change during these rewrites though, only when the main D2E8 variable changes. Some further messing around with the debugger will likely be necessary to figure out how to adapt this update function for level select.



At this point, I need to figure out how the code I'm interacting with in cheat engine would be modified on the disc itself. Since I'm trying to repurpose existing menus and functions, I would think that some sort of gdi hex mod could probably get the job done, but with my inexperience I'm not sure if that's a path worth pursuing. This could probably be accomplished with a GS/Xploder code too, but in addition to the hassle of swapping a code disc every time I want to play I'd still need to figure out what parts of the GDI need modifying before I'd be able to make a code myself.

If anyone has suggestions on how to proceed, I'd love to hear them. Or, if this thread just goes stagnant and you find this years later on your own journey to modify this game, I hope the info here is at least somewhat helpful.

User avatar
Anthony817
Shark Patrol
Posts: 3118

Re: Making a Level Select code/mod for Cosmic Smash

Post#2 » Wed Sep 16, 2020 10:38 pm

Cool, wishing you the best of luck with this.
Image

fafadou
St.Jimmy
Posts: 398

Re: Making a Level Select code/mod for Cosmic Smash

Post#3 » Thu Sep 17, 2020 4:45 am

The only thing I can suggest to you is to replace a menu in options to select your stage.
For exemple the langage selection if the game have it.
@megavolt85 did it for adding widescreen select in evil twin.

I wish you success.

3l3tric
noob
Posts: 3

Re: Making a Level Select code/mod for Cosmic Smash

Post#4 » Thu Sep 17, 2020 11:28 am

I started thinking about this again today, and I think I have a potential solution using Code Breaker. I'd still prefer hex editing the gdi directly so I wouldn't have to deal with swapping discs, but a code breaker code would still be better than nothing.

I'm thinking you could do 2 codes, a level select and level repeat. These will be activated by either d-pad left and right or trigger left and right. After the activator code, level select would be would be

Code: Select all

03010001
8C16E794


which increments the main menu level select index by 1.

The level repeat code would be

Code: Select all

03020001
8C16E7A0
03020001
8C16E7A4


which decrements the two next level codes by 1. This can be used at any point during a level to repeat it, or even used multiple times to go through stages in reverse order. Changing the 2 in the first and 3rd line to a 1 will make this a level jump code within the game.

I'm not sure how exactly the activator codes work (as in, whether they run only once when the condition is met and wait for an unmet-met cycle before running again, or if they run indefinitely while the condition is met), but if you need to add a delay to a code to make sure it doesn't get activated multiple times on the same button press, you can use 0B0xxxxx for an xxxxx cycle delay. This would go after both the activator code and the incrementing codes.

Now for the roadblock. Apparently Dreamcast games tend to use different memory locations to hold button status across different games. As such, I'd need to find this address in Cosmic Smash in order to make activator codes for the above two functions, which are unfortunately worthless if I can't activate them with a button, and I'm not really sure how to find these addresses. Demul seems to not accept inputs when the window is unfocused, so I can't hold buttons down and perform memory scans with Cheat Engine to isolate these addresses. If I could, the activator codes would be in the format

Code: Select all

0ENNFFBF
00XXXXXX


where NN is the total number of lines after the activator code and XXXXXX is the address (prefix 8c/2c on emu) where the button presses are stored in memory. In this example, D-Pad left would activate the code, since holding only d-left would match with FFBF. Replacing it with FF7F would activate with d-pad right.

So that's where I'm at. If I can figure out either how to have demul read inputs while unfocused or can just find the address through other means, I'll be able to work out a code breaker code for level select. Otherwise, I'll have to figure out how to start sifting through the gdi for a hex replacement (which I'll have to do anyway even if I make a code since swapping discs sucks).


MAJOR EDIT: After some further snooping and a lot of luck, I managed to find the register Cosmic Smash writes button presses to! This address is 8C21B4A8 and contains the button presses as a 2-byte sequence. The next 2 bytes at 2C21B4AA are the right and left triggers respectively.

I've tried writing a codebreaker code, but so far I haven't been successful with anything besides a static level code (which surprisingly only required the main menu level select variable to be set, so you can infinitely repeat any level in the game with a 2 line gamebreaker code! you can just only repeat that one level :/)

Here's the "prototype code"

Code: Select all

0E02FF7F
0021B4A8
03010001
8C16E794

0E04FFEF
0021B4A8
03010001
8C16E7A0
03010001
8C16E7A4

0E04FFDF
0021B4A8
03020001
8C16E7A0
03020001
8C16E7A4


The code is 3 sections. The first causes d-pad left presses to increment the level select used from the main menu, so pressing once causes the game to start one level ahead, twice two levels, so on.

The second and third codes are both needed for level select in-game. The second makes d-up increment the next level select indexes, while the third code decrements them with d-down.

These codes can be altered if you want to use different buttons to activate them. Here are the various single-button codes:

Code: Select all

 A                    FFFB
  B                    FFFD
  X                    FBFF
  Y                    FDFF
 START                 FFF7
 D-UP                  FFEF
 D-DOWN                FFDF
 D-LEFT                FFBF
 D-RIGHT               FF7F


If you want 2 buttons to activate a code, add the 2 hex values together and add any overflow to the end. These values will replace the "FFxF in the first line of each section of the code if you wish to change the button mappings from their default.

I'll update this thread again when I have a working code to share. So far though, I've confirmed on hardware that my level select address and button address are both accurate!

Also, I've seen different answers to this question and I keep second guessing myself, so I'll ask here to be sure once and for all: Should these memory addresses start with 8C or 0C? On Demul they start with 2C but everywhere I've seen online says you need to convert the addresses to work on original hardware, but I've seen some places say one and some the other. For most code breaker codes it doesn't matter, but for the incremental "03" prefix code you need to type the whole exact address.
Last edited by 3l3tric on Thu Sep 17, 2020 5:09 pm, edited 1 time in total.

cloofoofoo
killer
Posts: 276

Re: Making a Level Select code/mod for Cosmic Smash

Post#5 » Thu Sep 17, 2020 3:51 pm

You should also post this in the DC section in obscure games, they seem to do a lot of hex editing and the like over there.

3l3tric
noob
Posts: 3

Re: Making a Level Select code/mod for Cosmic Smash

Post#6 » Thu Sep 17, 2020 7:50 pm

I went ahead and started a thread in OG as well, thanks for the tip.

At the moment progress is close but pretty much halted. The code breaker code is partially working, but I'm not sure how to diagnose the issues I'm having with it. For instance, using just the second code and incrementing the two level select indexes somehow makes them differ, with one leading to level 5 and the other to level 0. And those locations seem static, any time you press d-up between levels those levels come up, no matter how many times you press it. I suspect the increment function doesn't quite work like I think it does. The activator lines (the first two lines of each section) seem fine though, as there is a response to d-pad input. I checked back over my codes and both increment lines are exactly the same, and the addresses point to the exactly correct bytes

  • Similar Topics
    Replies
    Views
    Last post

Return to “New Releases/Homebrew/Emulation”

Who is online

Users browsing this forum: No registered users