don't click here

Sonic Adventure 2: Battle Network

Discussion in 'Engineering & Reverse Engineering' started by SF94, Aug 18, 2013.

  1. flarn2006

    flarn2006

    Member
    280
    3
    18
    SA2 Cheat Table
    I've seen bugs like that before, typically triggered by invalid input, which appears to be the case here. It probably has to do with a while loop that's supposed to ask you to try again if the input is invalid.
     
  2. SF94

    SF94

    Tech Member
    Quick status update!

    I'm currently in the process of restructuring the program to make it easier for me to work with in the long run which may or may not lead to this becoming a "mod" (for MainMemory's SA2 Mod Loader). In fact, once I'm done, I could make this run both stand-alone and as a mod. Running it as a mod will allow me to do more advanced things much more easily though, so that's a thing.

    This will probably take a few days (if I don't procrastinate for like a month again), and I probably won't upload a new build simply because it will effectively function the same as it does now. That is of course, unless I do implement something new, such as synchronized program settings (e.g disable specials). Either way, it'll just make it easier for me to expand later... at which point, I will be uploading new builds =P
     
  3. SF94

    SF94

    Tech Member
    https://www.youtube.com/watch?v=p73Ht0xsIBw

    Edit: And of course JUST AFTER I say something about it, I fix it entirely. That's just like me though, isn't it? :v:

    By the way, swapped spawn points won't function correctly if you're using MainMemory's character select mod. If it bothers you, just disable the mod. Everything else is fine, though.
     
  4. SF94

    SF94

    Tech Member
    Alright, I've uploaded the latest version. It is now version 2. Here's some of the major changes:

    • The update interval has been removed, since I'm no longer waiting 16ms and hoping the timing will work out just right. As a result, it has been replaced with...
    • Frame synchronization. The program synchronizes itself with the framerate to ensure things are applied properly in-game.
    • Input is now significantly more reliable as a result, which means specials now work more reliably. Details on this below--it's not perfect.
    • The 2P main menu and stage selection are now synchronized. Less chance of mishaps, and now you can also use your analog. The battle options menu isn't synchronized, but the settings themselves are. I'll do that later for sure, though.
    • Fixed an annoying bug where if SA2 is started and the program hooks into it too quickly, it would disable the 2P input structure before it exists, locking you out of the 2P menu. (The game doesn't think that player 2's "controller" is "plugged in")
    • The reliable message system has been changed to actually work. I once again question how it even worked at all. Sonickidnextgen, who wrote the socket library, got impatient with me because he just wanted to play SA2, fixed it up. It was pretty simple, I was just procrastinating like I usually do.
    • Probably some other things I forgot about. Obligatory "general stability and performance improvements", etc.

    On the note of the specials, they will work just fine as long as you don't do anything crazy. For example, make sure you're not spazzing out and flinging your analog all over the place, because the result won't be identical on the other client. And if it's not identical, there's a chance that the character wasn't in a state where the special was usable (eg skidding), thus wasting it and desynchronizing things a bit.

    tl;dr: It's best to make sure you're not too close to rings (so the lightdash doesn't trigger and break everything), you're running straight in one direction, or not moving to ensure that the specials go through properly.

    Download here.
     
  5. Retroman

    Retroman

    Member
    732
    2
    18
    This is an awesome thing you are doing, and I support you!
     
  6. Lanzer

    Lanzer

    The saber calls for its master... Member
    6,845
    3
    18
    Glendale, AZ
    Living life.
    Sweet! v2 is out!! can't wait to try. thanks man for all the hard work. :)
     
  7. Shade Vortex

    Shade Vortex

    The Black Vortex Member
    540
    34
    28
    USA, WA.
    Twitch Streams
    When I try to host a server, it just says "Connecting to server at (my ip address) on port (myport) forever, and the same goes for my friend who tries to connect to my IP/port when I try to host the server. Am I doing it wrong or something? I launch SA2BN first, type server, hit enter, enter my port number, hit enter, then launch the game. I've tried having the game launched first, too, but the same thing happened.
     
  8. Hukos

    Hukos

    Member
    527
    2
    18
    All I have to say is that I'm sad that I can't contribute to this great project, but this is a really awesome thing here and I hope it succeeds.
     
  9. SF94

    SF94

    Tech Member
    I could have messed something up. In fact, there's a very high chance I did. Frankly, I rarely test the step-by-step stuff, as I just use command line for debugging.

    Actually, try using command line yourself and see if it helps. The details are on the first post; you can make a .bat file, create a shortcut, or even just open a command prompt and cd to the directory the executable is in.

    Edit: Yup, I broke it. It says "Connecting to server at on port <port>". I'll get right on that. For now, command line should suffice.
    Edit: Aaand fixed. Version 2.1 now.
     
  10. SF94

    SF94

    Tech Member
    Woohoo, update!

    • The program now checks version numbers between server and client to ensure they are the same in order to avoid shenanigans.
    • The program now actively checks if SA2 is running. If it ever crashes, it disconnects you and the client from each other to ensure shenanigans don't occur... if it manages to detect that it crashed, that is. It doesn't always work.
    • Added teleport functionality for testing reasons which teleports you to the other player. Button combo: + - Y + D-Pad Up  
    • Fixed a bug with the reliable packet handler AGAIN where it would only send the first byte of a message and cause the program to be very good at counting IDs. (1, 2, 3, 4, 5, 4294967295, 6, 8?!)
    • Send all menu related variables within the first 5 seconds of connection time in case a connection was re-initialized while deep within the 2P menu. There are some other weird issues to go along with this though, so I don't recommend it.
    • In-game time is now synchronized every second with the client by the server. You can now safely play without disabling the time limit.
    • Battle options menu selection is now synchronized.
    • Always synchronize menu selections when a new menu is entered
    • Re-wrote command line handler. Details below.
    • Fixed Mech HP synchronization, which was evidently broken. Actually trying to play in shooting mode still sucks, though.
    • Properly synchronize upgrades and powerups. (Powerups would always send what you had last, not currently; fixed now)
    • Time Stop is now properly synchronized.
    • Added a keepalive system, so if the other player's client crashed or is exited, yours will disconnect after the default of 15 seconds. This can be overridden with the command line argument --timeout or -t, followed by the timeout in milliseconds (minimum 1000).
    • Pause menu selection synchronized.

    The new command line stuff has been written in such a way that you can actually use it in addition to the console input. This way, you can run the program with, for example, --keep-active, and it will then actually ask you if you're hosting or connecting, for the ip/port, etc. If you use command line primarily and you miss an option, it'll ask you for the missing options in the console as well.

    As a side note, if your console for whatever reason flashes red and beeps at you, pause the game, don't press anything, and try to snap a screenshot of it and post it here. It'll say something about a "SCREWYOU" message. (Annoying bugs)

    Download here. The version number is now 2.5.

    Edit: Small oversight. Running the executable with just --no-specials doesn't actually work because I derped while checking the count of arguments. Just do something like "--no-specials plz", as long as there's more than one argument, and it'll work fine.

    Also behold the power of the money snake.
    Edit: fixed money snake
     
  11. SF94

    SF94

    Tech Member
    Quick bugfix. I fixed the argument count oversight, and now it ACTUALLY WORKS on Windows XP... which was also an oversight. I also did some minor cleanup here and there, but it doesn't really affect anything.

    Download here. The version number is now 2.6.
     
  12. Lanzer

    Lanzer

    The saber calls for its master... Member
    6,845
    3
    18
    Glendale, AZ
    Living life.
    Awesome, thanks for the update Morph. I'll go ahead and crosspost your posts in the SSMB topic too.
     
  13. SF94

    SF94

    Tech Member
    Here's another small polish update:

    • Fixed the random Chao Garden bug. Details below.
    • Fixed an issue with spindashing. The spindash timer is now synchronized. Details on this also below.
    • Attempt to revert changes made to the game's code when disconnecting. The functionality has been there for a while, just not put to use.

    To fix the Chao Garden bug, I changed the way I check for player changes. Before, I was relying on the level number to change so that I could re-initialize the (internal) players only exactly when necessary. The problem here is that it doesn't always change to 0 when exiting a stage to the menu, so I'd have to do a bunch of trickery to change it to 0 so that the player objects would realize they shouldn't be "alive" right now. Every so often, things would get mixed up. And as you may know, stage 0 being the Chao Garden was to fix a bug in the actual game which would allow you to go to the test stage, hence Chao Garden.

    Instead of doing that which was kinda dumb in retrospect, I'm just checking the pointer to each player every loop to see whether or not they're initialized, or if they've been re-initialized (pointer change). No more mixups and no more Chao Garden bug!

    As for the spindash bug: It seems the game would get confused, and sometimes after releasing the spindash button, the receiving end wouldn't always change the timer to 0 like it should (More 0!). So that means next time you pressed B, it would try to spindash, since it always happened to be 24. This would cause desyncs when spinning to gain speed, and then cancelling it, because instead of cancelling on the receiving end, it would just roll up and continue rolling on its merry way. It would also cause the spindash trail left behind to be halfway in the ground. The solution was rather simple, that being to send the spindash timer when you're playing as Sonic/Shadow (and Metalsonic/Amy just in case you use the spindash hack for them =P). I figured it'd be a little more tricky to fix than that, but evidently not.

    This brings the version number to 2.7.

    Edit: typo :v:
     
  14. Lanzer

    Lanzer

    The saber calls for its master... Member
    6,845
    3
    18
    Glendale, AZ
    Living life.
    Thank you for updating the Chao Garden bug and the spindashing <- that right their was alittle annoying to deal with but I wasn't sure if was a legit bug or an after effect of modding the game.
     
  15. SF94

    SF94

    Tech Member
    Man, I say I'll work on one thing, but then I do something totally different...

    http://www.youtube.com/watch?v=iynFt0lkXiw

    EDIT: To be clear, this is the mod loader version. This is why I'm able to do this kind of thing with ease.

    This has pretty been pretty much entirely rewritten for many reasons... although mostly due to everything just falling apart, one bug after another. The networking is now a lot more efficient (by ensuring no duplicate data is sent), and uses both TCP and UDP. Eventually, there will likely be UDP only and TCP only modes. I also send certain bits of player information more efficiently. Before, it effectively sent data every frame (in other words, every 16ms, assuming your game runs at full speed).

    As a result of rewriting it, it made it easier for me to track down the cause of that one game-crashing bug which involves picking up objects, and I've nearly fixed it. It still does crash, but now it's a lot safer. Assuming the player picks up the object carefully (no run-by object-grabbing!), everything works out. Of course, no promises that it'll EVER be fixed, but it's something I'd really like to.

    Aside from that, the highlight here is the smooth-ish gameplay, and the connectivity notification noises. If anyone's interested, the audio used is in SA2 by default (as far as I'm aware) as chao_k_net_*.adx
     
  16. Turbohog

    Turbohog

    Member
    859
    92
    28
    I'm super late to this party, but I just want to thank you for your work on this. You're fulfilling one of my childhood dreams with this project. New video looks great. I can't wait to test this out myself.
     
  17. SF94

    SF94

    Tech Member
    My pleasure. It's a lot of fun, and I'm fulfilling my own childhood dreams as well, of course =P
     
  18. SF94

    SF94

    Tech Member
    The mod loader version is here!

    Before I get to explaining what changed, let me preface this by saying: I need performance feedback. Does it run better or even worse on your system and connection? Are there any bugs present during gameplay that weren't present in the last release build? Please let me know so I can look into it. Also, expect the console to spam a lot of messages. I have this enabled so that in the event of a crash, you can screenshot the console, and I can narrow it down to which packet caused it. Additionally, the connection timeout functionality is gone again. I never took the time to re-implement it after practically re-writing this whole thing.

    This version is generally more stable and uses a totally different networking library (slightly modified SFML - details in OP). As a result, it now uses both TCP and UDP protocols. My friend Sonickidnextgen (ImmutableOctet) plans to eventually implement a UDP-exclusive mode, and on top of that, I'll likely implement TCP-exclusive mode (although likely only for LAN play... but why play via LAN anyway? Whatever... :v: ).

    As for changes, the most major change can be seen in the last progress video a few posts up. Connects and disconnects now occur when entering and exiting the 2P Battle menu, and it plays the Chao Kindergarten networking jingles while waiting for a connection, when a connection has been established, or when a connection has been lost. The networking is also generally more efficient.

    It now also reverts all code changes made after establishing a connection once you disconnect. Although maybe not desirable, I believe this may affect the --keep-active argument. After disconnecting, it will restore the code to its normal behavior. I recommend using the mod version if you want to permanently keep the window active.

    Another nice thing is that you can always have the mod enabled if you please. You just have to enable the console when you want to play online, and then run the game with the command line arguments described in the first post. As for more technical stuff, it now sends less, larger packets as opposed to many small packets. In theory this should speed things up on the receiving end.

    There's also a fun little thing I added. Scale is now synchronized, so you can become giant Shadow if you like. =P

    The new usage and installation instructions are all in the first post.

    Download: Version 3.0 (11/29/2014)

    There's your stinkin' download. Now here's a bit (more) of a monologue =P

    As it stands now, the overall functionality is the same as the last release version, ignoring the general polish. From this point onward, I plan to utilize the mod loader more heavily. I can use it to hijack functions to do specific networking actions. For example, I could hijack the "load level" function (wherever that is!), and tell it to send a "load level pls" request to all the other clients, at which point they would all simply call the function.

    I also plan to rewrite the input handler again. As it stands now, the input handler imposes a 1 to 2 frame delay on every call to the receive function in which a button press was received (which can cause some minor desyncs). The reason for this is that I have to:
    • Synchronize with the framerate if the program doesn't already happen to be in the right place at the right time
    • Take the newly received held buttons, compare to the last received, and write the difference to the "just pressed" buffer.
    • Then I absolutely must wait one whole frame, and immediately after, clear that buffer. Otherwise, the game will think I'm spamming button presses.

    I could get around this by doing a bunch of threading trickery, but I'd honestly rather not. That would be such a hassle. Instead, I plan to hijack the controller update routine to do my bidding. The idea is to just trick it into handling those buffers on its own without constantly wiping them unnecessarily (which it does, by the way--rather annoying!).

    And in the long run, whoever is the client (not hosting) will be handled as a real player 2, even on their instance of SA2. This'll help make way for + - porting to SADX later   .
     
  19. Lanzer

    Lanzer

    The saber calls for its master... Member
    6,845
    3
    18
    Glendale, AZ
    Living life.
    Thanks for your continued work on this Morph, I'll crosspost your post over to SSMB as well to see if I can get any feedback there.
     
  20. Dark Sonic

    Dark Sonic

    Member
    14,257
    1,333
    93
    Working on my art!
    Lol wut. How's that going to work.

    + - Big vs Knuckles in Hot Shelter because fuck everything