          -=========================================================-
                        Toc Fixer for PC-Engine CD-ROMs
                    http://rigg.servegame.com/software.htm
          -=========================================================-

                                 Version 1.01
                         ReadMe updated on 12/25/2005

   Copyright  2005 by NightWolve under GNU General Public License. This
   software may not be distributed unless accompanied by this documentation.
   See the Legal section for details.

+==============================================================================-
|  Table of Contents
+==============================================================================-

   1.  Introduction
   2.  Requirements
   3.  Usage
   4.  Version History
   5.  Project History
   6.  Credits & Greetings
   7.  Legal / Disclaimer
   8.  Contacting us
   9.  Miscellaneous Links and Goodies


+==============================================================================-
|  1.  Introduction
+==============================================================================-

   OK, so you've downloaded that crappy ISO/MP3/CUE archive from some site, IRC
   channel, or newsgroup, but after decoding the MP3s to waves, then mounting
   or burning the image thereafter to play it, you find it's unstable... It
   crashes, and/or there are lip-syncing issues during the cinemas, etc. So why
   is that? Well, it's quite simple. Early in the PC-Engine pirating scene, the
   idea of using lossy encoders such as MP3 for the redbook audio tracks took
   off like wildfire because of the huge compression ratios one was able to
   achieve. This allowed for easy distribution over the Internet obviously. The
   problem, however, is that when a MP3 decoder decodes the wave back, it
   doesn't restore the wave file's original size. That is, the size in bytes
   the wave originally had before it underwent MP3 encoding. So what happens
   when you've decoded your MP3s to waves and now you've got your ISO/WAV/CUE
   image file set mounted with daemon tools or you try to burn it? Well, the
   offset of where every audio track begins will be different, again, since the
   waves don't have their original file size. Never mind the lossiness of the
   encoding process. That's not the issue! The issue is that most game code has
   the LBA offset hard-coded, which is what's used when it wants to play an
   audio track. However, there are some games that will dynamically examine
   their own TOC at runtime when it's time to play the next audio track, but
   they're few and far in between such as "Ys IV: The Dawn of Ys." Such images
   would have none of the above aformentioned problems discussed so far. But
   anyhow, there's your background information on why the vast majority of
   ISO/MP3/CUE archives suck as a means for archiving PC-Engine CD-ROMs.

   Now, how does TocFixer address this problem? Well, it's compiled with a TOC
   database of PC-Engine CD-ROMs collected by Squaresoft74 from original silver
   owners. With this data, I know exactly how many bytes in size each of your
   track files should be, both for wave and ISO. So, with that info, this
   application will check your ISO and wave files in the folder you select
   against the verified TOC data and resize the files if necessary. Resizing
   ISO files is no sweat, but wave files are given extra special attention.
   The header will be checked to ensure you decoded it correctly. Trailing
   bytes, should they be present, will be removed before the final resizing
   attempt. And finally, it will not resize the file such that by default,
   no more than 3 seconds of audio will be lost, which equals 529,200 bytes.
   That's pushing the limits, but if that much audio needs to be cut off,
   there's likely something very wrong with the wave to begin with. Same goes
   if the file has to be enlarged by more than 529,200 bytes.
   
   So, while I hope this tool will decrease all the tech support problems I and
   others have had to deal with over the years with those unfortunate enough to
   have obtained crap ISO/MP3/CUE archives, I am conflicted in offering this
   tool to the public. I've been strongly advocating the image storage scene
   adopt, at the very least, lossy encoders such as OGG that restore the wave
   to its original file size. As a result, they work perfectly, with none of
   the issues of ISO/MP3/CUE archives. By releasing this tool, I'm objectively
   supporting the continued usage of ISO/MP3/CUE archives and I'd like to make
   it clear, that is far from my willful intention. I still wanna see them all
   nuked, of course. This tool is intended to fix existing archives, not hinder
   progress towards using OGG and the like. So please, while you may be stuck
   with an ISO/MP3/CUE archive for now, if you're gonna create new archives,
   please use OGG at the very least. It achieves just as good lossy compression
   as MP3, minus all the headaches...

   Finally, this tool, while created with ISO/MP3/CUE archives in mind, doesn't
   have to be limited to just that purpose. This tools lends itself as an
   overall ISO/WAV/CUE image file set verifier. You can use it to check your
   existing PC-Engine CD-ROM images in general, regardless of what original
   lossy audio encoder was used. If you're using the latest MagicEngine 1.X
   emulator, you'll notice that when you click PCECD in the boot CD menu, at
   the bottom status bar, a full title of the game will appear if the CD can be
   correctly identified. If a title does appear, that means your CD's TOC is
   just fine. But if NO title is shown, that means your TOC has been damaged by
   the MP3 decoding process and you should run this tool to attempt to fix it.
   Hope that helps.

   Well, good luck,

     - NightWolve, Squaresoft74

+==============================================================================-
|  2.  Requirements
+==============================================================================-

   Operating System:	Any 32-bit version of Microsoft Windows will suffice

+==============================================================================-
|  3.  Usage
+==============================================================================-

   1. Run TocFixer by double clicking it.
   2. Select the game title from the dropdown combobox that you wish to repair.
   3. Click the Browse button to then find the folder that contains the ISO and
      wave files that you wish to repair (The files that match the game title
      you selected in step 2). Next, simply select any one of the files and
      click Open.
   4. Check the status output. If it informs you the image is unstable, click
      the Repair button to begin the process.
   5. Monitor the status output for any other errors that might turn up. If the
      process is successful, a new CUE file will be opened up for you in
      notepad. You're now ready to mount that CUE file and/or use it to burn
      the image for testing. Good luck, ya heathen.

   Note: If you get a wave format error, you will need to either obtain better
   copies of the audio files or ensure you're decoding them properly to be
   44,100 Hz 16-bit stereo waves. I recommend dBpowerAMP for decoding MP3s back
   into waves if you run into trouble like this.

+==============================================================================-
|  4.  Version History
+==============================================================================-

 Version 1.01 (12/31/2005):

 + Fixed a critical issue where if the file is being enlarged, the contents of
   the file between the old EOF (End-Of-File) position and the new position
   are undefined. Basically, all bytes appended to a file - to grow it - will
   definitely be 0x00, rather than undefined. Using the prior method, the file
   could be grown quickly, gigabytes in a matter of seconds, but whatever data
   is on the harddrive at the time is what's allocated to the file as is. For
   an audio file, when enlarged, such a method would produce static at the end.
 + Added support for saving the last folder that track files were loaded from.
 + Edited instructions slightly on main screen.

 Version 1.00 (8/13/2005):

 + Generates a default reliable CUE file for use with daemon tools or any CDRW
   burning software that supports CDRWIN's CUE format.
 + Added full wave header verification. The tool will not blindly resize your
   wave. It will check if the 44 byte header is proper for what's expected for
   a CD. If it's not a 44,100 Hz 16-bit stereo wave, it will abort the resizing
   attempt and warn you. You'll have to properly convert your waves or obtain
   them from a better source in such an event.
 + Added a basic failsafe where if the number of track files in your selected
   folder found is not equal to the expected track files of the game title you
   selected, the program will abort and warn you of the mismatch/error.
 + Any trailing bytes found present in a wave will automatically be removed.
 + Added a wave resize limit. Basically, if the tool finds that you must resize
   a wave beyond the default setting of 3 seconds of audio, it will abort the
   resize attempt and warn you that you need to find a better quality source.
   In other words, something is really wrong with the wave file if you need to
   resize it by that much. (For a CD-quality, 44.1KHz 16-bit stereo wave, three
   seconds of audio equals 529,200 bytes.)
 + Improved the scrolling for the status text box.
 + Fixed a bug where a WINAPI didn't work as expected in Win98SE, so it should
   now work reliably on all Windows platforms (9X/NT/2K/XP).
 + Fixed a bad character used in a game title for Square's TOC database.
   "Linda  (J)" will now show up properly.
 + Added an About box.
 + Code is highly optimized. The default VC++ runtime engine is not used.
   Instead, I use a small custom runtime engine I prefer to compile with that
   results in a much smaller and quicker executable, along with the fact that I
   sacrifice ANSI portability by calling Windows APIs directly for speed gains.

+==============================================================================-
|  5.  Project History
+==============================================================================-

   I started this project on Friday, July 29, 2005 after getting into an
   argument with bastaad525 and one of the most argumentative douche bags
   you'll ever run into, Ozzy_98, on the MagicEngine forums. The thread is
   right here if you're curious:

   http://www.magicenginefx.com/forums/viewtopic.php?t=1243

   Basically, bastaad525 made the proposal of fixing shitty ISO/MP3/CUE archives
   by generating an altered CUE file filled with POSTGAP compensations and after
   I proposed the correct and FINAL solution to properly repair them once and
   for all, to end the reign of terror they've brought upon the pce community,
   this complete and utter douche bag known as Ozzy_98 came in to defend the
   original flawed idea. Not to mention he dragged with him some history
   between us from at least ~3 years ago. Details can be found in the thread.

   Now, to be clear, I really really HATE ISO/MP3/CUE archives. I really do,
   but the second thing I've hated over the years was seeing these compensating
   CUE files with one POSTGAP line after the other for every audio track. Same
   goes for the others that use PREGAP everywhere. I couldn't stand by and let
   a solution such as this take off to spread even more of them, so I felt
   compelled to take action to oppose this douche baggery, despite my
   opposition to helping further the cause of ISO/MP3/CUE archives. So... that
   was basically one significant motivator in my creating this application.

   Enter Squaresoft74 who used to spread ISO/MP3/CUE archives himself before
   better alternative lossy encoders such as OGG became available. To redeem
   himself for having spread such archives in the past (Just taking a friendly
   jab at him for that), he embarked on the TOC Database project. Basically, he
   gives a TocReader tool to someone he trusts that owns an original PC-Engine
   CD-ROM. That person runs the tool to collect the Table of Contents (TOC)
   data from that disc. Squaresoft74 takes this data and then stores it at his
   website so that others can use it to verify their images. Now, I originally
   dismissed his whole idea way back, but then I saw emulator writers were
   using his database as a means to verify a disc's validity. So by having the
   emulator check a disc's TOC data before trying to play it, this would ensure
   that there would be less problems, as well as inform the user that he/she
   has a bad image. Purty clever I thought. Turned out Squaresoft74 was serious
   about collecting as much TOC data as possible, so we have his dedication to
   thank for making this tool possible. No TOC data, no TocFixer!

   So anyway, to get to the crux of the matter, it occurred to me since
   Squaresoft74 had this database and all these ISO/MP3/CUE archives were out
   there, still generating tech support questions, crashing, suffering from
   lip-syncing issues, etc. why not use his collected data to fix the images
   themselves? Thus, TocFixer was born and yet another great use for his TOC
   database revealed itself. Voila! So yeah, I banged this application out in
   a few days thereafter, having worked with Squaresoft74 and prepared his TOC
   data in an useable form. Well, I think it's a purty nifty little application
   that'll surely solve a lot of headaches. Good luck!

                                                              -NightWolve

+==============================================================================-
|  6.  Credits & Greetings
+==============================================================================-

 - Concept/Programming/Development

     NightWolve (Nicholas Livaditis)

 - TOC Database Concept/Management

     Squaresoft74

 Greetings and thanks to:

 - Dave Shadoff, for some technical help/ideas to make this a better tool.
 - KI, for his TocReader VC++ source code that I used as a starting base to
   write this tool.

+==============================================================================-
|  7.  Legal / Disclaimer
+==============================================================================-

   This software is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
   more details. Anyone using it does so at their own risk! Neither NightWolve,
   nor any of the other individuals mentioned in this documentation will be
   held liable for any loss or damage arising from its use.

+==============================================================================-
|  8.  Contacting us
+==============================================================================-

   Suggestions for improvements are welcome and please report any bugs.

   NightWolve:
	Email:	nlivadit@yahoo.com
	WWW:	http://rigg.servegame.com/

   Squaresoft74:
	Email:	squaresoft74@hotmail.com
	WWW:	http://necstasy.emunova.net/

+==============================================================================-
|  9.  Miscellaneous Links and Goodies
+==============================================================================-

 - Retro ISO Gaming Guild (aka RIGG)

     Detail:	Our PC-Engine/Turbo Duo preservation group - Offering quality
		archives, as well as BOLD (there, I said it, BOOOOLDD BABY!!)
		translation projects for both PC-Engine & PC games...
		Come join us!!

     WWW:	http://rigg.servegame.com/

 - "Xak III: The Eternal Recurrence" Translation Project

     Detail:	My first PC-Engine translation project! It's a fine action-RPG.

     WWW:	http://home.earthlink.net/~nlivaditis/xakiii/

 - "Ys IV: The Dawn of Ys" Translation Project

     Detail:	That's right! Ys IV for the PC-Engine has an English patch!!!

     WWW:	http://rigg.servegame.com/translations/ys4/

 - Squaresoft74's Snk-Nec TOC Database

     WWW:	http://necstasy.emunova.net/

 - MagicEngine PC-Engine Emulator

     Detail:	The best emulator for PC-Engine out there, but shareware.

     WWW:	http://www.magicengine.com/uk_index.html

 - Daemon Tools

     Detail:	The best freeware virtual CD/DVD-ROM emulator that I know of.
		Use this for all your disc image mounting needs. This allows
		you to play PC-Engine images directly from your hard drive
		with the MagicEngine emulator, rather than having to play it
		through a slower physical CD-ROM disc in the drive. Saves you
		the trouble of having to burn CD-Rs for every image you find.

     WWW:	http://www.daemon-tools.cc/dtcc/download.php

 - dBpowerAMP

     Detail:	A great freeware audio file conversion tool. I recommend you
		use this to convert your MP3 files to waves.

     WWW:	http://www.dbpoweramp.com/


