Sonic and Sega Retro Message Board: SADX/SA1 Hacking/Modding - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
  • 185 Pages +
  • ◄ First
  • 112
  • 113
  • 114
  • 115
  • 116
  • Last ►
    Locked
    Locked Forum

SADX/SA1 Hacking/Modding Now with more research and development!

#1696 User is offline Aquaslash 

Posted 08 February 2011 - 11:10 PM

  • Emerald Dragoon
  • Posts: 2816
  • Joined: 17-November 04
  • Gender:Male
  • Location:Hampton, VA
  • Project:The S Factor: Sonia and Silver
  • Wiki edits:1,144
Haha, who knew the code was already there, and the files were just missing. Anywho, while I track down the GC version and rip these files myself just to spite that guy, have an alternate set of Metal Sonic sounds ripped from Rivals 2

Just drop them in the relevant folder. Already converted and shiz

#1697 User is offline SANiK 

Posted 20 February 2011 - 02:22 AM

  • Posts: 412
  • Joined: 21-September 04
  • Gender:Male
  • Wiki edits:6
MainMemory sent me the decompress routine that the SADX installer supposedly uses.

So here is a simple program that does the decompression. Rename the input file to in.dll.
CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define __ //For posting on forum. Do a CTRL+F to get rid of it.

void DecompressBuffer(unsigned char *DecompressedBuffer, unsigned char *CompressedBuffer /*Starting at + 20*/, int DecompressedSize)
{
__ unsigned char *CompressedBufferPointer = CompressedBuffer;
__ unsigned char *DecompressedBufferPointer = DecompressedBuffer;

__ //Create sliding dictionary buffer and clear first 4078 bytes of dictionary buffer to 0
__ unsigned char *SlidingDictionary = malloc(4096);
__ memset(SlidingDictionary, 0, 4096);

__ //Set an offset to the dictionary insertion point
__ unsigned int DictionaryInsertionOffset = 4078;

__ //Decompression command
__ unsigned char CommandCounter = 0;
__ unsigned char DecompressCommand = 0;

__ while(DecompressedSize)
__ {
__ __ //Is the decompress counter zero? Load the command
__ __ if(CommandCounter == 0)
__ __ {
__ __ __ CommandCounter = 8; //Each command has 8 sub commands, one bit per command
__ __ __ DecompressCommand = *CompressedBufferPointer++;
__ __ }

__ __ //Each command is a byte and is actually composed of 8 sub commands
__ __ //A bit of 1 means to copy the byte exactly as it is, and add it to the dictionary
__ __ //A bit of 0 means to load a special encoded format describing a repetition.
__ __ if(DecompressCommand & 1)
__ __ {
__ __ __ //Copy the byte exactly over
__ __ __ unsigned char RawByte = *CompressedBufferPointer++;
__ __ __ *DecompressedBufferPointer++ = RawByte;

__ __ __ //Add the byte to the dictionary
__ __ __ SlidingDictionary[DictionaryInsertionOffset] = RawByte;
__ __ __ DictionaryInsertionOffset = (DictionaryInsertionOffset + 1) & 0xFFF; //Slide the dictionary

__ __ __ DecompressedSize--;
__ __ }
__ __ else
__ __ {
__ __ __ //The sub command tells us there is a repetition
__ __ __ //unsigned short RepetitionCode=(CompressedBufferPointer[1] << 8) | CompressedBufferPointer[0];
__ __ __ unsigned char CurrentByte = CompressedBufferPointer[0];
__ __ __ unsigned char NextByte = CompressedBufferPointer[1]; //Lower nibble is the repetition count or RunLength
__ __ __ CompressedBufferPointer+=2;

__ __ __ //Calculate the offset of the byte to use in the sliding dictionary
__ __ __ int DictionaryOffset = ((NextByte & 0xF0) << 4) | CurrentByte;

__ __ __ //It is not really run length compression, but instead it is a dictionary based method
__ __ __ //I just ran out of ideas what to name the variables
__ __ __ int RunCounter = 0;
__ __ __ int RunLength = (NextByte & 0xF) + 3; //Compression defines a repetition to be at minimum three bytes

__ __ __ while ( RunCounter < RunLength)
__ __ __ {
__ __ __ __ unsigned char RawByte = SlidingDictionary[((RunCounter + DictionaryOffset) & 0xFFF)];
__ __ __ __ *DecompressedBufferPointer++ = RawByte;

__ __ __ __ DecompressedSize--;
__ __ __ __ if(DecompressedSize <= 0)
__ __ __ __ {
__ __ __ __ __ free(SlidingDictionary); //Terminate
__ __ __ __ __ return;
__ __ __ __ }

__ __ __ __ //Add the byte to the dictionary
__ __ __ __ SlidingDictionary[DictionaryInsertionOffset] = RawByte;
__ __ __ __ DictionaryInsertionOffset = (DictionaryInsertionOffset + 1) & 0xFFF; //Slide the dictionary

__ __ __ __ RunCounter++;
__ __ __ }
__ __ }

__ __ //Rotate the sub command
__ __ CommandCounter--;
__ __ DecompressCommand >>= 1;
__ }

__ free(SlidingDictionary);
__ return;
}

int isFileCompressed(unsigned char *CompressedBuffer)
{
__ return !strcmp(CompressedBuffer, "compress v1.0");
}

void ProcessBuffer(unsigned char *Name, unsigned char *CompressedBuffer, int CompressedSize)
{
__ if ( CompressedBuffer )
__ {
__ __ if ( isFileCompressed(CompressedBuffer) )
__ __ {
__ __ __ int DecompressedSize = *(unsigned int*)(&CompressedBuffer[16]);
__ __ __ unsigned char *DecompressedBuffer = malloc(DecompressedSize);
__ __ __ if ( DecompressedBuffer )
__ __ __ {
__ __ __ __ //Xor Decrypt the whole buffer
__ __ __ __ unsigned char XorEncryptionValue = CompressedBuffer[15];

__ __ __ __ unsigned int I=0;
__ __ __ __ while(I < CompressedSize)
__ __ __ __ {
__ __ __ __ __ CompressedBuffer[I] ^= XorEncryptionValue;
__ __ __ __ __ I++;
__ __ __ __ }

__ __ __ __ //Decompress the whole buffer
__ __ __ __ DecompressBuffer(DecompressedBuffer, &CompressedBuffer[20], DecompressedSize);

__ __ __ __ //Switch the buffers around so the decompressed one gets saved instead
__ __ __ __ CompressedBuffer=DecompressedBuffer;
__ __ __ __ CompressedSize=DecompressedSize;
__ __ __ }
__ __ }

__ __ //Save file
__ __ FILE *fout=fopen(Name, "wb");
__ __ fwrite(CompressedBuffer, CompressedSize, 1, fout);
__ __ fclose(fout);
__ }
}

int main()
{
__ FILE *fin=fopen("in.dll", "rb");

__ fseek(fin, 0, SEEK_END);
__ int CompressedSize=ftell(fin);

__ fseek(fin, 0, SEEK_SET);

__ void *CompressedBuffer=malloc(CompressedSize);
__ fread(CompressedBuffer, CompressedSize, 1, fin);

__ fclose(fin);

__ ProcessBuffer("out.dll",CompressedBuffer, CompressedSize);

__ return -1;
}


The file format is as so:
At 0, there is a 14 byte null terminated string, "compress v1.0", no quotations.
14 is 0.
15 is a byte that is the xor encryption password.
Like MainMemory said, at 16 there is a dword denoting the decompressed file size.

At 20 is where the data starts.

To read the data you must xor the whole file or at least the data and on portion with the xor encryption password, byte by byte. C xor operator is ^.

The data consists of packets. The first byte of each packet is a byte command.
Each packet, excluding the command byte, can be divided into eight uneven sections. Each bit of the command denotes what operation to do for each of the sections.

The first lower bit of the command byte corresponds to the first section after the command byte.
The second lower bit corresponds to the section after the first section, etc.

If the command bit is 1 for the section, it means the section is only one byte, and so it gets copied to the decompression file.
It also gets put into a sliding dictionary.

If the command bit is a 0 for the section, it means the section is two bytes, and the two bytes describe an address in the sliding dictionary and the number of bytes to copy to the decompressed file from the sliding dictionary. The format of the two bytes is as so: 0xLL 0xHK
Address In Sliding Dictionary where to start copying from = 0xHLL
Number of bytes to copy from sliding dictionary = 3 + 0xK

When copying from the sliding dictionary to the decompressed file, you must do the copy byte by byte because each copy also re-adds the value to the sliding dictionary. So it has a feedback loop that would desynchronize the sliding dictionary if one did a batch copy in one shot.

The sliding table is 4096 bytes in size, and each byte is initialized to 0 at start up.

The sliding table's insertion pointer is at 4078 on startup and for each byte insertion it increments by one. If it is >= 4096, it rolls over to 0. (This is what the & 0xFFF does).
This post has been edited by SANiK: 20 February 2011 - 02:29 AM

#1698 User is offline MainMemory 

Posted 20 February 2011 - 12:14 PM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4148
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
Thanks for that SANiK, now SADXsndSharp can decompress files from system.dat on disc 1. Compressed files show up with blue names, and they're decompressed automatically on extracting. Turns out that everything but the MPG files are compressed.

#1699 User is offline MainMemory 

Posted 08 March 2011 - 01:17 AM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4148
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
I've located the code that sets the checksum for Chao save files, and converted it to C# (source included). If you run this program after editing the file, SADX won't crash. The save file has the same layout as it does in RAM.
This post has been edited by MainMemory: 08 March 2011 - 01:19 AM

#1700 User is offline MainMemory 

Posted 08 March 2011 - 12:06 PM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4148
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
Sorry for the triple post, but I've now got the checksum code for the normal save files, and converted it to C#. So now we can edit the save files. I don't know what's what in the save file yet, but filling it with 00 locks everything, even Sonic.

Edit: SCHG:Sonic Adventure DX: PC/Save Files
This post has been edited by MainMemory: 08 March 2011 - 01:02 PM

#1701 User is offline Overlord 

Posted 08 March 2011 - 03:44 PM

  • Substitute Meerkovo IT Chief
  • Posts: 16871
  • Joined: 12-January 03
  • Gender:Male
  • Location:Berkshire, England
  • Project:VGDB
  • Wiki edits:3,204
There is a "Now you can play as SONIC!" string in SA:DX PC (at the very least) - maybe at some point in development he WAS intended to be unlocked in some form (like just after the initial cutscene, perhaps?)

#1702 User is offline MainMemory 

Posted 07 April 2011 - 08:46 PM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4148
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
Well, it's not much, but I've started work on a rewrite of SADXLVL on the SVN:

I don't know why the UVs are broken, probably some difference between Managed DirectX and SlimDX.

#1703 User is offline SANiK 

Posted 01 May 2011 - 09:25 AM

  • Posts: 412
  • Joined: 21-September 04
  • Gender:Male
  • Wiki edits:6
QUOTE (MainMemory @ Apr 7 2011, 09:46 PM)
Well, it's not much, but I've started work on a rewrite of SADXLVL on the SVN:

I don't know why the UVs are broken, probably some difference between Managed DirectX and SlimDX.


The UV issue makes it look like Katamari Damacy. Pretty neat.

#1704 User is offline MainMemory 

Posted 01 May 2011 - 10:01 AM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4148
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
Since it's been bumped, I might as well give an update:


I've tried comparing the new code to the old code and can't find where the problem is.

If anyone wants to look, you can find the code here.
This post has been edited by MainMemory: 01 May 2011 - 10:05 AM

#1705 User is offline Dude 

Posted 13 June 2011 - 01:11 AM

  • Posts: 3135
  • Joined: 11-September 04
  • Gender:Male
  • Location:Southbridge, MA
  • Project:Random VR/AR trash
  • Wiki edits:43
With the help of FraGag, we were able to force sadx to use a 24 bit zbuffer, fixing most of the problems with draw distance. Here are some comparison pics:

Before:

After:


To do this with your copy of sonic.exe, open it up in hex workshop and go to the following address: 0x34A5D80
You'll be replacing the next 0x28 bytes with 4D 00 00 00.

before:

after:


What's going on here is that SADX, when invoking direct3d loops through all of the z-buffer modes available and settles on the first working one. Since the first one in the list is 16 bit, and 16 bit is ugly as fuck, we're forcing it to only try 24 bit.

If you're going to make vast, expansive levels for SADX then this process is an absolute must. You'll probably also need to expand the sky box, clip and fog distances as well but those are already partially documented.

#1706 User is offline MainMemory 

Posted 16 June 2011 - 10:11 PM

  • Every day's the same old thing... Same place, different day...
  • Posts: 4148
  • Joined: 14-August 09
  • Gender:Not Telling
  • Project:SonLVL
  • Wiki edits:1,339
In other news, I finally fixed the missing polygons and uvs in the SADXLVL rewrite:

But now I have to make it actually do something...
This post has been edited by MainMemory: 16 June 2011 - 10:11 PM

#1707 User is offline n00neimp0rtant 

Posted 19 June 2011 - 08:47 PM

  • EYES ONLY
  • Posts: 262
  • Joined: 24-January 08
  • Gender:Male
  • Location:South Park, PA
  • Project:Creation Kit (Skyrim mods and patches)
  • Wiki edits:1
I have been looking for a way to tweak the fog settings like you can do in the debug mode within the "SADX (Preview)" prototype for GameCube. (Specifically, I'm trying to record a video of a cutscene with intense green fog in the background so I can chroma key the whole background out.) Is there a tool for the PC version that does this?

#1708 User is offline Dude 

Posted 19 June 2011 - 11:06 PM

  • Posts: 3135
  • Joined: 11-September 04
  • Gender:Male
  • Location:Southbridge, MA
  • Project:Random VR/AR trash
  • Wiki edits:43
QUOTE (n00neimp0rtant @ Jun 19 2011, 09:47 PM)
I have been looking for a way to tweak the fog settings like you can do in the debug mode within the "SADX (Preview)" prototype for GameCube. (Specifically, I'm trying to record a video of a cutscene with intense green fog in the background so I can chroma key the whole background out.) Is there a tool for the PC version that does this?


You can use cheat engine and this cheat table: sadx_fog.ct (right-click save as) to mess with the ingame fog and draw distance settings.

#1709 User is offline n00neimp0rtant 

Posted 20 June 2011 - 02:29 AM

  • EYES ONLY
  • Posts: 262
  • Joined: 24-January 08
  • Gender:Male
  • Location:South Park, PA
  • Project:Creation Kit (Skyrim mods and patches)
  • Wiki edits:1
QUOTE (Dude @ Jun 20 2011, 12:06 AM)
You can use cheat engine and this cheat table: sadx_fog.ct (right-click save as) to mess with the ingame fog and draw distance settings.

Thanks a bunch, works great =] I had never heard of Cheat Engine until now, but it seems like a great tool.

Another question: I literally just started playing around with the SADX modding tools, and I feel like I'm getting familiar with them; but when I'm using MainMemory's SADXLVL, I can edit a level just fine within the editor, but no matter what I have tried, I can't get it to actually save my modifications. It appears to save the sonic.exe correctly, and the "Date Modified" field in Explorer updates to the current time, but if I start up sonic.exe or close SADXLVL and open it again, the layouts are the same. No errors or warnings of any sort at any time. Any idea what I might be doing wrong?

(If it makes any difference, I now have to use a "patched" sonic.exe file because regrettably, I found my SADX disc 2 popped out of its little plastic CD holder thing inside the case and got all scratched up from being shook around, so I couldn't run/reinstall it =[ I made sure to change the region in the sonic.exe.ini file to the patched European version, though)

Thanks again for the help.
This post has been edited by n00neimp0rtant: 20 June 2011 - 02:31 AM

#1710 User is offline Morph 

Posted 20 June 2011 - 02:41 AM

  • AKA SonicFreak94.
  • Posts: 765
  • Joined: 01-August 08
  • Gender:Male
  • Location:Utah
  • Project:SA1/2 hax
  • Wiki edits:11
QUOTE (n00neimp0rtant @ Jun 20 2011, 12:29 AM)
Another question: I literally just started playing around with the SADX modding tools, and I feel like I'm getting familiar with them; but when I'm using MainMemory's SADXLVL, I can edit a level just fine within the editor, but no matter what I have tried, I can't get it to actually save my modifications. It appears to save the sonic.exe correctly, and the "Date Modified" field in Explorer updates to the current time, but if I start up sonic.exe or close SADXLVL and open it again, the layouts are the same. No errors or warnings of any sort at any time. Any idea what I might be doing wrong?


Well, are you modifying the geometry of the level, or just the items? If it's just the items, be sure to click the little save button next to the list of characters in the set editor. Otherwise... I dunno.

  • 185 Pages +
  • ◄ First
  • 112
  • 113
  • 114
  • 115
  • 116
  • Last ►
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users