The following warnings occurred: | |||||||||||||||
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(287) : eval()'d code PHP 8.2.18 (Linux)
|
Logging game events to text file - Printable Version +- Mario Kart Wii Gecko Codes, Cheats, & Hacks (https://mariokartwii.com) +-- Forum: Hacks/Modding (https://mariokartwii.com/forumdisplay.php?fid=14) +--- Forum: Coding & Hacking General Discussion (https://mariokartwii.com/forumdisplay.php?fid=23) +--- Thread: Logging game events to text file (/showthread.php?tid=2110) |
RE: Logging game events to text file - seanmcnally - 03-16-2024 And now, just for fun, the conditional version! C278894C 00000006 83E3008C 3D808000 39600001 2C1F0009 4082001C 807B0000 80630000 88630010 2C030000 41810008 996C165F 00000000 Source: # NOTE this is meant for four player mode, edit the second cmpwi if in another mode # Insertion Address: 8078894C lwz r31, 0x008C (r3) # Default instruction, loads item to r31 lis r12, 0x8000 #Set the upper 16 bits of the EVA li r11, 1 # Get our value ready in case a human uses a star # Find out if a star was used cmpwi r31, 9 bne end_code # If not, skip to the end # Load the slot of player that just used an item lwz r3, 0x0 (r27) # Slot loading code start, load mem address from r27 into r3 lwz r3, 0x0 (r3) # Load new word from a memory address based on the word we just loaded lbz r3, 0x10 (r3) # Load new byte from a memory address based on the word we just loaded cmpwi r3, 3 # EDIT SECOND NUMBER IF IN ANOTHER MODE, use 2 for 3 player, 1 for 2 player, 0 for 1 player. bgt end_code # If the value in r3 is greater than 3, a non-human player used the star, cancel stb r11, 0x165F (r12) #Store a 1 to the EVA at address 8000165F end_code: RE: Logging game events to text file - Vega - 03-16-2024 Good work. You will need some code to be included that will reset the flag (to 0) if the conditions are NOT met. Code: #Default instruction, load item value Some notes:
RE: Logging game events to text file - seanmcnally - 03-16-2024 Thanks! That reset flag may certainly be useful in other cases, but in mine, leaving it at 1 is fine because dolphin will still log every write of that value, even if it's already there. In fact, it may be better to leave it, in case Dolphin logs faster than Chataigne can read. I do have some questions about beq+ and beq-, I came across those in the tutorial but didn't really understand the purpose. I know that they give Broadway a prediction as to what will happen, but how does that affect things in practice? For example, what if you had the wrong type of prediction (plus where there should be a minus?) What would be different? RE: Logging game events to text file - Vega - 03-16-2024 It helps performance (speed) of your code. Having the code handler equipped already slows down the CPU quite a bit, and having "slow" codes on top of it will make it worse. Will this make any "real-time" difference? No, unless we are talking about having multiple codes that all do something intense such as NAND/file editing. Providing the wrong branch hint (+ when you're not suppose to on forward branches and - when you're not suppose to on backwards branches) will do a lot worse though than leaving the branch hint as default (less likely). When you omit a branch hint, it's the same as applying (-) for forward branches and (+) for backwards branches. To give you an idea about what speeds we are talking about. A tick/clock in Broadway under normal conditions is a little over 16 nanoseconds iirc. A missed branch prediction (if said branch is not in the Branch History Table or Branch Target Cache), can cause around.... idk... 10 extra clocks?? (this varies A TON on what code is present and Its been a minute since I've done any instruction timing stuff). So 160+ nanoseconds, lol. RE: Logging game events to text file - seanmcnally - 03-17-2024 Ah, I get it now, I guess I should've figured it was a speed thing. Thanks for explaining! I could see how those seconds could add up. Not to get too off-topic, but now that I have a handle on assembly I've made a few log-specific codes. I made codes to log human player race positions, log which characters players select, and log which players are holding which items (last one isn't working yet but I'm very close). I'm wondering, should I just dump them in this thread, or post them in the Misc section? Working on getting ram dumps for the other regions so I'm able to port them all as well. I want to sincerely thank you for all your help, with your assistance on this thread plus your incredibly detailed tutorials I've completed all of my main objectives AND all of my stretch goals save for one which doesn't have to do with logging. Much appreciated! RE: Logging game events to text file - Vega - 03-18-2024 You could. If you have codes in the future that are meant for public use, you can of course post them in the appropriate sub-forum in the Codes forum. Others post them in their GitHub. RE: Logging game events to text file - seanmcnally - 03-21-2024 Alright folks, my project is complete. For anyone coming across this in the future that needs to do what I did, I'm going to write up a summary of what I did, what I learned, and how you can do this too: After going through these steps, I can now log to a text file:
1) Configuring Dolphin First step, enable the debugging features within Dolphin. Options > Configuration > Interface > Enable Debugging UI. Go to View, make sure Breakpoints, Log, and Log Configuration are checked. Then, in the Log Configuration tab, choose "Info" under verbosity, check "Write to File" under logger outputs, and under Log Types uncheck everything except "Master Log (MASTER)" and "Memory Interface & Memory Map (MI)". At this point you should probably find Dolphin's log file (dolphin.log) and delete it, that way you're starting fresh (on Windows it is found at C:\Users\YourUserName\AppData\Roaming\Dolphin Emulator\Logs). 2) Adding Breakpoints Now, on the Breakpoints tab, we can choose to log when certain events in the game happen. Start up MKWii, then click New, and enter either an instruction address or a memory address. At the bottom, be sure to choose the option that says "Write To Log", you don't want to "break" (or pause) the game when the event happens. Here's a list of breakpoints that I found. Note that the top section of breakpoints won't work until after you've completed section 3, cheat codes. You only need to put in the 8-character address before the #, the info after # denotes the type of breakpoint and my comments on each code. You'll need to pay attention to whether it is an instruction or memory breakpoint, and if memory, whether to choose read or write. Please note that all of these are for the NTSC-U version of the game. Breakpoints are different depending on what version of the game you have. The easiest way to port breakpoints to another version is to download SZS Tools and inside the bin folder, open command prompt and use wstrt.exe to port the code. Full documentation here. The command should look like: Code: wstrt.exe port usa 8078894C Note that the breakpoints that need cheat codes do not need to be ported, but the cheat codes themselves will need to be ported, which involves changing the 6 characters after "C2" in the first line. More on porting codes here. Generated by Cheat Codes (Cheat Codes Required for These To Work!) Character Breakpoints (see list of characters here to decode this value) 800015AF # MEMORY WRITE # P1's Character 800015BF # MEMORY WRITE # P2's Character 800015CF # MEMORY WRITE # P3's Character 800015DF # MEMORY WRITE # P4's Character Position Breakpoints 8000160F # MEMORY WRITE # P1's Position 8000161F # MEMORY WRITE # P2's Position 8000162F # MEMORY WRITE # P3's Position 8000163F # MEMORY WRITE # P4's Position Item Breakpoints 8000165F # MEMORY WRITE # Human Used A Star 8000167F # MEMORY WRITE # Human Has A Star 8000165E # MEMORY WRITE # Someone used a blooper ---- Natural Breakpoints (You can Use These Without Cheat Codes!) 80835D50 # INSTRUCTION # Countdown begins, hits on First num of countdown 8070492C # INSTRUCTION # Lap increase. Put r31 == 3 in conditions and will only log "1. Vars: r31=3" on final lap. 8070a944 # INSTRUCTION # Course Clear, FINISH appears on screen, race complete 80530D9C # INSTRUCTION # Breaks on both course overview and on course start. Condition r24 == 0 for Course Overview, r24 == 1 for Course Start 8088D508 # MEMORY READ/WRITE # Lightning used --- Unused (I didn't wind up needing these, but they are natural, maybe you'll find them useful!) 80531134 # INSTRUCTION # Exact moment GO hits after countdown (can't use, too much nonsense on log) 8058f2a8 # INSTRUCTION # Also hits on GO 808B12F4 # INSTRUCTION # Blooper ink hit (Don't Use, too much on output) 8078894C # INSTRUCTION # Any time any player or CPU uses an item 3) Cheat Codes Now, you might be thinking, why do I need to use cheat codes if I don't want to affect gameplay, just get information? Well, because Dolphin only supports getting information from the RAM, and some pieces of information are stored in other places, or in dynamic parts of the ram whose addresses change on each boot. Because of this, we need to write cheat codes that can write information from those places to the empty parts of the RAM (also known as the EVA, or exception vector area), so Dolphin can log it. So basically, without these codes, all the addresses I provided in the first section are just empty parts of ram. Here's how to add cheat codes to Dolphin if you aren't familiar: 1) Right Click Mario Kart Wii, click Properties 2) Go to Gecko Codes 3) On the bottom, click Add New Code 4) Paste the code (not the source code) into the Code box. Human Has A Star Code: Code: C278EFE8 00000005 Source Code (For Reference): Code: # HUMAN HAS A STAR Blooper or Star Used Code: Code: C278894C 00000008 Source Code: Code: # NOTE this is meant for four player mode, edit the second cmpwi if in another mode Store All Player Positions 4P Mode Code: Code: C278494C 00000011 Source Code: Code: # Store All Player Positions 4P Mode Store All Character Choices 4P Code: Code: C284DAA4 0000000B Source Code: Code: #HERE'S HOW IT WORKS: 4) Dolphin is Logging Stuff, Now What? Well, the reason I needed this was so I could feed it to Chataigne and control RGB lights during game events. You can also use something like Advanced Scene Switcher in OBS to read from a text file and do certain things. But note that the dolphin.log is *additive*, meaning all the previous stuff is kept in a big running log, and it isn't reset to nothing unless you delete the file while dolphin is closed. This also means that each time a program reads it, it reads everything, not just the newest changes. To solve this I made a python script to read from the original log file and just write the newest changes to a new text file. I can then use the new text file in an external program to just read the newest changes of Dolphin's log on each update. You'll need to adjust the path near the end of this script in order to use this. dolphin-log-change-finder.py Code: import time Also, Chataigne cannot natively read text files, so I needed to write my own module for that. And that's everything. Hope this helps someone in the future! Feel free to reach out with any questions, this forum's e-mail notifications don't work so I may not see replies to this thread but I'm also reachable via Discord @SeanMcNally98. Enjoy! |