Author Topic: Editing CC's script?  (Read 2918 times)

Serge50

  • Iokan (+1)
  • *
  • Posts: 3
    • View Profile
Editing CC's script?
« on: October 16, 2015, 10:23:03 am »
Hello :D
I've been trying to find a way to edit Chrono Cross's dialogue text since a while but always counter dead-ends.
All I've reached is dump the game files using Yazoo's cctools. Problem is the files extracted were all in .out format which I have no idea how to decompress/convert.The rest of Yazoo's c++ files didn't want to compile due to errors in  the code(or I'm doing it wrong?) :? .

I just want to edit the text for fun purpose  :)  I hope I can get some help.

Danetta

  • Guru of Time Emeritus
  • Porrean (+50)
  • *
  • Posts: 51
  • So where is it going?
    • View Profile
Re: Editing CC's script?
« Reply #1 on: November 20, 2015, 06:24:03 pm »
Well, editing dialogs can be easily done with Terminus Tradiction Tools. It's not neccesary to use them for this purpose, but it's what it's designed for, so it's the easiest way.

Serge50

  • Iokan (+1)
  • *
  • Posts: 3
    • View Profile
Re: Editing CC's script?
« Reply #2 on: January 01, 2016, 10:29:48 am »
My thanks for your reply.
I tried the terminus traduction tools on a windows xp laptop and it worked fine.But on another one with win7 it didnt work and i get unusual errors when running the rein execs.I ran them on windows xp sp3 compatibility,gives fewer errors but still doesn't work when applying the patch on the iso.
It's not a big deal but I'm just curious what the problem is  :D .
Thanks again!

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2127
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: Editing CC's script?
« Reply #3 on: January 26, 2016, 03:54:05 am »
Just out of sheer interest, I've been trying to make my own Square LZSS de/compressor library in C11, but I've been stumped on the compression function as to what the 4 byte value at offset 8 is in the file header. My best guess is that it is a checksum of some sort. I've been trying to reverse-CRC it in hopes of finding a magic value that would confirm this, but re-CRCing with the magic value does not yield the same value as is in the file header. My gut still says that 4 byte value is used as an integrity checksum though.

I tried the CRC validation with some of FaustWolf's test files: Script.lzs (at offset 12 til EOF) and the extracted Script.txt as well as 2540.out (at offs 12 til EOF) on CD1
« Last Edit: January 26, 2016, 08:24:38 pm by Schala Zeal »

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2127
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: Editing CC's script?
« Reply #4 on: February 09, 2016, 11:41:12 pm »
Think I may be doing something wrong here, but... give it a try

Code: [Select]
#include <cstring>
#include <fstream>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

int main(int argc, char **argv)
{
std::ifstream inf;
std::ofstream outf;
char *buf = new char[4096];
char c;
unsigned inlen = 0, outlen = 0;
std::vector<bool> data;
auto p = data.begin();

inf.open(argv[1], std::ifstream::binary);
inf.seekg(0, inf.end);
inlen = inf.tellg();
inf.seekg(0, inf.beg);
inf.read(buf, 4);
if (std::strncmp(buf, "sszl", 4) != 0) return 1;
std::memset(buf, 0, 4);
inf.read((char*)&outlen, 4);
std::cout << inlen << " / " << outlen << '\n';
inf.seekg(4, inf.cur);

while (inf.get(c))
for (int i = 0; i < 8; i++)
data.push_back((bool)((c >> i) & 1));
inf.close();
unsigned j = 0;
unsigned o = 0;
outf.open(std::string(argv[1])+".uncompressed", std::ofstream::binary);
for (int i = 0; i < data.size();)
{
if ((bool)data[i++])
{
char k = std::accumulate(data.begin()+i, data.begin()+(i+8), 0,
[](char x, char y)
{
return (x<<1)+y;
});
std::memmove(buf+(j%4096), &k, 1);
outf.put(k);
i+=8;
j++;
}
else
{
o = std::accumulate(data.begin()+i, data.begin()+(i+12), 0,
[](unsigned x, unsigned y)
{
return (x<<1)+y;
})-1;
unsigned k = std::accumulate(data.begin()+i, data.begin()+(i+4), 0,
[](unsigned x, unsigned y)
{
return (x<<1)+y;
})+2;
o %= 4096;

for (int m = 0; m < k; m++)
{
buf[(j+m)%4096]=buf[o];
outf.put(buf[o]);
o=(o+1)%4096;
i+=16;
j+=o;
}
}
}
outf.close();

/*for (auto i: data) std::cout << (i ? 1 : 0);
std::cout << '\n';*/
return 0;
}

EgyLynx

  • Enlightened One (+200)
  • *
  • Posts: 298
    • View Profile
Re: Editing CC's script?
« Reply #5 on: February 12, 2016, 11:07:46 am »
It is little surpised that iostream think need if something (only hello world) text are put screen... or ...

Well... i dont begin comments what include what...
If there are someone who are more exp these c family langugues...

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2127
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: Editing CC's script?
« Reply #6 on: February 15, 2016, 12:17:20 am »
I used iostream for verbose purposes.

Lynxos

  • Iokan (+1)
  • *
  • Posts: 1
    • View Profile
Re: Editing CC's script?
« Reply #7 on: April 13, 2016, 05:40:25 pm »
Think I may be doing something wrong here, but... give it a try

Code: [Select]
#include <cstring>
#include <fstream>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

int main(int argc, char **argv)
{
std::ifstream inf;
std::ofstream outf;
char *buf = new char[4096];
char c;
unsigned inlen = 0, outlen = 0;
std::vector<bool> data;
auto p = data.begin();

inf.open(argv[1], std::ifstream::binary);
inf.seekg(0, inf.end);
inlen = inf.tellg();
inf.seekg(0, inf.beg);
inf.read(buf, 4);
if (std::strncmp(buf, "sszl", 4) != 0) return 1;
std::memset(buf, 0, 4);
inf.read((char*)&outlen, 4);
std::cout << inlen << " / " << outlen << '\n';
inf.seekg(4, inf.cur);

while (inf.get(c))
for (int i = 0; i < 8; i++)
data.push_back((bool)((c >> i) & 1));
inf.close();
unsigned j = 0;
unsigned o = 0;
outf.open(std::string(argv[1])+".uncompressed", std::ofstream::binary);
for (int i = 0; i < data.size();)
{
if ((bool)data[i++])
{
char k = std::accumulate(data.begin()+i, data.begin()+(i+8), 0,
[](char x, char y)
{
return (x<<1)+y;
});
std::memmove(buf+(j%4096), &k, 1);
outf.put(k);
i+=8;
j++;
}
else
{
o = std::accumulate(data.begin()+i, data.begin()+(i+12), 0,
[](unsigned x, unsigned y)
{
return (x<<1)+y;
})-1;
unsigned k = std::accumulate(data.begin()+i, data.begin()+(i+4), 0,
[](unsigned x, unsigned y)
{
return (x<<1)+y;
})+2;
o %= 4096;

for (int m = 0; m < k; m++)
{
buf[(j+m)%4096]=buf[o];
outf.put(buf[o]);
o=(o+1)%4096;
i+=16;
j+=o;
}
}
}
outf.close();

/*for (auto i: data) std::cout << (i ? 1 : 0);
std::cout << '\n';*/
return 0;
}

Care to share info on what this code does?

alfadorredux

  • Entity
  • Mystical Knight (+700)
  • *
  • Posts: 746
  • Just a purple cat
    • View Profile
Re: Editing CC's script?
« Reply #8 on: June 25, 2016, 03:32:39 pm »
Slight necro here, but the decompression algorithm goes approximately like this (stripping my comments from an implementation that at least somewhat works):

#create a 4K buffer filled with zeroes

#read 4 bytes ("sszl")

#read the decompressed size (4-byte little-endian)

#read the four mystery bytes

#while the input file isn't empty, read 512 bytes, or whatever's left

#unpack into a bit string, split, and reverse to produce an array of "bits" (that corresponds to the line "my @bits = reverse(split("", unpack("B4096", $buf)));" in Perl, you might need to read "man perlpacktut" if you can't figure out what's going on)

#(if there's slopover from an old read, push it onto the end)

#while there are at least 17 bits left (or we're processing the last few bits in the file), do
    #if the next bit is a 1
        #output an 8-bit literal byte to the output file and the buffer
    #if the next bit is a 0
        #create a pointer into the buffer from the next 12 bits
        #create a length from the next 4 bits
        #starting from the indicated position in the buffer, read length bytes and
         write them into the buffer and the output file

That's about it.  Good luck.

froodo

  • Porrean (+50)
  • *
  • Posts: 75
    • View Profile
    • About Me
Re: Editing CC's script?
« Reply #9 on: June 25, 2016, 05:40:55 pm »
A good thing for Schala (she's making a open-source reimplementation of CC engine)

Schala Zeal

  • Radical Dreamer (+2000)
  • *
  • Posts: 2127
  • 7th Elemental Innate, and vtuber
    • View Profile
Re: Editing CC's script?
« Reply #10 on: June 25, 2016, 09:59:27 pm »
Indeed, and an Assimp extension to read CC mdl files (and .mesh files maybe) as part of it.