Author Topic: Python reimplementation of SGS  (Read 17921 times)

Gamen

  • Casual VIPER Fan
  • *
  • Posts: 12
  • Karma: +2/-0
Python reimplementation of SGS
« on: July 02, 2013, 12:07:20 am »
Here's the source code of an almost complete re-implementation of the Sogna Game System in Python. It's mostly based off reverse-engineering RSR and Typing, so other games will probably have quirks. There was one with audio in particular that I noticed with M1, where looping sounds would not be stopped and replaced with other sounds like dialogue if they played too long. That one at least can be fixed by toggling "Play PCM Immediately" under the Audio menu. There's also something funny with fade ins in V16.

I'm not expecting anyone to actually use this, since it is not superior to the original engine except in lower CPU usage (mine uses a timer for the animation thread instead of a spinlock). In addition to Python 2.6 or 2.7, it requires wxPython 2.8 (UI), NumPy (bulk data processing), pyAudio (audio playback, of course), Construct 2.5 (parsing), and optionally Cython (to compile faster versions of the decompression algorithms). All the essential components together take 27MB - a substantial increase over RSR's 104KB SGS.exe. And since SGS.exe is Win32, it's not going to be unplayable on computers for a long time.

In other words, while it works, it's mainly a proof of concept and I expect it will be more useful as a guide than a tool, since the only missing bits that I'm aware of are a lack of support for the i18n opcodes (I have no International versions) and fullscreen. If you have questions I can probably answer them, but be warned I did this in May and then forgot about it until now, so my memory may be a little fuzzy - and that's ignoring the bits that I did in 2011 and earlier, which are even fuzzier.

Oh, and it's public domain - as if it weren't likely an unapproved derivative work as it is.

JG

  • Karin-chan Fan
  • Website Administrator
  • Hardcore VIPER Otaku
  • ********
  • Posts: 3,497
  • Karma: +85/-4
  • 3000 posts of rediculousness and counting
    • Favorite Sogna Game:
      ・Gokuraku VIPER Paradice
    • Now Playing:
      ・Mario & Luigi: Brothership
    • Sogna Digital Museum
Re: Python reimplementation of SGS
« Reply #1 on: July 02, 2013, 08:32:40 pm »
This is fascinating on so many levels.  I've been tinkering with hacking SGS.EXE to make a single version capable of playing any VIPER game and here you go and just completely recreate it from scratch.

Haven't tried it yet but highly impressed that this is a first version.  Most of what you've done I've also done, but in pieces. I can decompress SGS.DAT files (and recompress them) and I can decode (and reencode) ANM files and I can decompile (and recompile) most of the WIN programs with my tools, but nothing that puts them all together into a single usable program.

I definately need to take a look at some of your opcodes in interpreter, as for some of them I haven't been able to figure out exactly what all the arguments do yet.


Boy I hope you could help me figure out the PC98 coding formats - especially BTR.  It's been a dream of mine to finally port BTR to Windows.  (I'd settle for just being able to decode the image files and rip the text out of scenario files.)

Gamen

  • Casual VIPER Fan
  • *
  • Posts: 12
  • Karma: +2/-0
Re: Python reimplementation of SGS
« Reply #2 on: July 02, 2013, 11:07:00 pm »
I've never taken a look at the PC-98 games - I've never gotten a PC-98 emulator to work, for that matter, but even then I don't have any media for them - so I don't know how alike the PC engine is. I was greatly aided by being able to decompile the SGS.exe binary, even though it was a impenetrable mess, but I'd have to settle for merely disassembling the PC-98 engine.

As for trying it out, my memory was apparently quite pessimistic when it came to recalling how well it worked when compiled - I had remembered that it was not compatible, but I just tested it again and it seems to work fine. So here's a compiled version: http://www.sendspace.com/file/uhhh9k (...I love that file id so much). Just drop player.exe and its 3 companions into a game folder and run it.

Edit: If you do try it out, if you get static during the Sogna logo instead of their theme switch the audio to 16-bit. Also you can run a game by drag-and-dropping SGS.DAT onto player.exe, or putting a shortcut to player.exe in your Send To folder and right-clicking on SGS.DAT and choosing Send To -> <shortcut to player.exe>.
« Last Edit: July 02, 2013, 11:13:50 pm by Gamen »

JG

  • Karin-chan Fan
  • Website Administrator
  • Hardcore VIPER Otaku
  • ********
  • Posts: 3,497
  • Karma: +85/-4
  • 3000 posts of rediculousness and counting
    • Favorite Sogna Game:
      ・Gokuraku VIPER Paradice
    • Now Playing:
      ・Mario & Luigi: Brothership
    • Sogna Digital Museum
Re: Python reimplementation of SGS
« Reply #3 on: July 03, 2013, 08:29:02 pm »
Forum attachments > download sites.



This is amazingly well done with only minor glitches in the games I tried.

The only thing I could see missing was language control, unless its so smart that it doesn't show you those controls unless the SGS.DAT has TEXT.xx files.  Didn't appear so but V16 Intl stalled at the first waitforlayer after Akira finishes her prologue so maybe it just didn't get that far.
« Last Edit: July 03, 2013, 08:59:18 pm by JG »

Gamen

  • Casual VIPER Fan
  • *
  • Posts: 12
  • Karma: +2/-0
Re: Python reimplementation of SGS
« Reply #4 on: July 03, 2013, 09:40:17 pm »
Hmm, I tried attaching it... Perhaps it failed because I tried to preview first.

Yeah, I mentioned that I hadn't done anything with the internationalization (i18n) opcodes. I don't have any International versions to test it with, so I didn't implement it. The "next" button on the debug screen can advance past that, but since the implementation is missing anyway, not exactly playable... So not, it's not that smart.

Taking a look at the PC-98 version of CTR... Holey moley. There looks to be nothing shared between the windows and PC-98 versions. Even the DAT file format isn't the same, though it looks deceptively similar. And when I looked through the disassembled SGS.COM, nothing really stood out as familiar. Not promising.

Edit: Solved *cough* the lack of an International version somewhat more quickly than my previous failures prepared me for. I'll see what I can do.
« Last Edit: July 03, 2013, 09:46:12 pm by Gamen »

JG

  • Karin-chan Fan
  • Website Administrator
  • Hardcore VIPER Otaku
  • ********
  • Posts: 3,497
  • Karma: +85/-4
  • 3000 posts of rediculousness and counting
    • Favorite Sogna Game:
      ・Gokuraku VIPER Paradice
    • Now Playing:
      ・Mario & Luigi: Brothership
    • Sogna Digital Museum
Re: Python reimplementation of SGS
« Reply #5 on: July 04, 2013, 07:32:09 am »
Taking a look at the PC-98 version of CTR... Holey moley. There looks to be nothing shared between the windows and PC-98 versions. Even the DAT file format isn't the same, though it looks deceptively similar. And when I looked through the disassembled SGS.COM, nothing really stood out as familiar. Not promising.

Thats the problem I ran into.  There must be some correlation between WIN files and the PC98 format, otherwise it would have taken them twice the development time because they would have coded for two entirely different engines. Likewise there's probably some similarity in the image formats, especially for the frames that aren't animated - there's only so many ways you can store a static image in lossless format.

Gamen

  • Casual VIPER Fan
  • *
  • Posts: 12
  • Karma: +2/-0
Re: Python reimplementation of SGS
« Reply #6 on: July 04, 2013, 01:58:57 pm »
Probably. Can't say for sure though, since I haven't managed to configure anex86 to run CTR or get another PC-98 emu even starting.

I've implemented the multi-language support, so the international versions should work now... at least V-16 does. I've attached source and binaries; the reason there's only player.exe is because the rest of the files are packed into it. There's a few other things I've been thinking of adding: support for translation files that use the international algorithms for printing so you don't need tricks, recording using something like ZMBV, more than 10 saves and being able to label them, and under the hood maybe some refactoring... But except for fullscreen and the fade glitch in older games, I think it's finished.

You mentioned minor glitches... Did you see anything other than the fades glitching?

Edit: I've tried attaching the binary, but it fails with no error. Here's a link: http://www.sendspace.com/file/way9e6 ...it took several minutes to upload that, so maybe the forum isn't patient enough?

JG

  • Karin-chan Fan
  • Website Administrator
  • Hardcore VIPER Otaku
  • ********
  • Posts: 3,497
  • Karma: +85/-4
  • 3000 posts of rediculousness and counting
    • Favorite Sogna Game:
      ・Gokuraku VIPER Paradice
    • Now Playing:
      ・Mario & Luigi: Brothership
    • Sogna Digital Museum
Re: Python reimplementation of SGS
« Reply #7 on: July 04, 2013, 02:02:36 pm »
You mentioned minor glitches... Did you see anything other than the fades glitching?

The fading problems you mentioned, and inconsistencies when rapidly changing the background (might be a framerate slowdown of some kind.)  Saw it happen in V12's Magical Gambler stroy when Sai holds up the wand and the background alternates rapidly.

Gamen

  • Casual VIPER Fan
  • *
  • Posts: 12
  • Karma: +2/-0
Re: Python reimplementation of SGS
« Reply #8 on: July 04, 2013, 02:11:26 pm »
The fading problems you mentioned, and inconsistencies when rapidly changing the background (might be a framerate slowdown of some kind.)  Saw it happen in V12's Magical Gambler stroy when Sai holds up the wand and the background alternates rapidly.

Huh, running them both side-by-side they look the same to me. まあ、いいか…

Anyway, don't miss that I added a link to the compiled version to that previous post.

Edit: I took another look, but I can't see why my engine flickers and the original doesn't - the bytecode quite specifically indicates those frames should be shown. Oh well.
« Last Edit: July 04, 2013, 03:11:52 pm by Gamen »

黒い灯影

  • Mr. Monkey in the moon
  • Forum Administrator
  • Ambassador of VIPER Knowledge
  • *******
  • Posts: 626
  • Karma: +42/-1
  • Unleashing the monkey inside!!
    • Favorite Sogna Game:
      ・VIPER-RSR
    • Now Playing:
      ・Viper RSR
Re: Python reimplementation of SGS
« Reply #9 on: August 29, 2013, 09:03:24 am »
Think you could make a version that doesn't use the SGS.DAT file?  and looks directly for the START.WIN

That's how I'm used to working with Viper games. I modified RSR's SGS.EXE to work with uncompressed files.
BlackShadow

Gamen

  • Casual VIPER Fan
  • *
  • Posts: 12
  • Karma: +2/-0
Re: Python reimplementation of SGS
« Reply #10 on: August 29, 2013, 08:38:09 pm »
Think you could make a version that doesn't use the SGS.DAT file?  and looks directly for the START.WIN

That's how I'm used to working with Viper games. I modified RSR's SGS.EXE to work with uncompressed files.

Sure, sure. Here's a version that can use a directory or a .DAT. Either start it from directory with START.WIN or pass it the path to the directory (or the START.WIN in the directory). Of course, this version also includes all the refactoring I did between my last release and now, but I think I got most of the bugs ironed out... At any rate, any external WAV files have to be in the same directory as START.WIN.

It can load a text-delimited file of translations; under the Other menu is the Export Strings command, which will dump a file of raw, untranslated strings. If you change the filename from *strings_raw.txt to *strings.txt, it will use those strings when possible. The options for a list of choices are space-bar-space delimited... Anyway, it uses the normal dialogue printing instead of the internationalized version, but I might eventually fix that...

There is also a tool in the Other menu that when given two variables can scan for changes to those variables in the code and produce a list of where those are changed. Double-clicking on an entry in the list will change those variables to the indicated values and run the load procedure (though if you can't load a normal save, it can't load either), and if the right variables were selected it should bring you to the scene in the game those values identify. It's pre-filled with a common pair in use, maybe the only pair...

Let me know about bugs, big and small, if you do use it... Especially with the refactoring I did, I know I missed some... The source is attached, and the player.exe is here: http://www.sendspace.com/file/cm8e9n

黒い灯影

  • Mr. Monkey in the moon
  • Forum Administrator
  • Ambassador of VIPER Knowledge
  • *******
  • Posts: 626
  • Karma: +42/-1
  • Unleashing the monkey inside!!
    • Favorite Sogna Game:
      ・VIPER-RSR
    • Now Playing:
      ・Viper RSR
Re: Python reimplementation of SGS
« Reply #11 on: September 03, 2013, 03:23:43 pm »
Thanks for the speedy reply. :D  Much appreciated.
It did stop at one of my WIN scripts, which i use to skip the intros and open directly to the menu.

I attached the said WIN script.. from RSR.
BlackShadow

Gamen

  • Casual VIPER Fan
  • *
  • Posts: 12
  • Karma: +2/-0
Re: Python reimplementation of SGS
« Reply #12 on: September 03, 2013, 08:03:31 pm »
Yeah, it does more than that: it activates internationalization, that is, loading strings from text.jp/us/it/dh/sp and using different fonts. It was failing on your script because text.jp (the default) was not present. I've updated it to be more forgiving. You can get it from http://www.sendspace.com/file/6rfxpk

JG

  • Karin-chan Fan
  • Website Administrator
  • Hardcore VIPER Otaku
  • ********
  • Posts: 3,497
  • Karma: +85/-4
  • 3000 posts of rediculousness and counting
    • Favorite Sogna Game:
      ・Gokuraku VIPER Paradice
    • Now Playing:
      ・Mario & Luigi: Brothership
    • Sogna Digital Museum
Re: Python reimplementation of SGS
« Reply #13 on: September 03, 2013, 10:04:07 pm »
Technically speaking, the real SGS requires TEXT.JP to exist if internationalization is used.  The other TEXT files are optional.  So Gamen had the coding correct, but glad to see he modified to be more flexible.

黒い灯影

  • Mr. Monkey in the moon
  • Forum Administrator
  • Ambassador of VIPER Knowledge
  • *******
  • Posts: 626
  • Karma: +42/-1
  • Unleashing the monkey inside!!
    • Favorite Sogna Game:
      ・VIPER-RSR
    • Now Playing:
      ・Viper RSR
Re: Python reimplementation of SGS
« Reply #14 on: September 04, 2013, 07:20:05 pm »
Yeah, it does more than that: it activates internationalization, that is, loading strings from text.jp/us/it/dh/sp and using different fonts. It was failing on your script because text.jp (the default) was not present. I've updated it to be more forgiving. You can get it from http://www.sendspace.com/file/6rfxpk
Oh. haha... must of forgotten I was trying to mess with that option...  :rattydance
BlackShadow