Here's the encryption code for CV3 that I've written up. DOn't know if it works yet. because I haven't tested.
/*
This script encodes the password. It must be called at the start of the Game Over's
password screen. This script is NOT used in the password entry screen.
Use: pw_encrypt()
Simple enough, huh? The following game variables are used:
ally (the current ally, use -1 or $FF for no ally)
stage (keep in mind some stages actually take up two values)
quest (as in whether the player is on the 2nd Quest hard mode)
The decryption script uses an additional optional variable:
path (no idea, but it is only set for two stages for Grant)
The player name is carried over from the name entry via the global array name[v].
Numerous bitwise operations based on 6502 Assembly are used here. They are located
in the "bitwise" script group. You shouldn't mess with these, just learn how to
use them. You can figure it out by looking through this messy code.
In order to alter this script for your own program, you must change pw_decrypt()
and cryptos() as well, since pw_decrypt checks what this script creates and
cryptos() contains the constants used to modify the variables.
The comment at the top is merely for keeping track of which cells correspond to
which Zero Page byte in the original assembly code. You can ignore them.
Grids are used for the variables and the displayed password because they can be
easily destroyed; this won't prevent hacking, but will make it slightly harder.
Same goes for the password itself, which is stored in a list. Also, grids offer
slightly more flexibility, even if they are more tedious to deal with and take
up more RAM when created, but this is freed up after one step.
This was coded almost straight from the original assembly code, with a few
minor shifts of variables. If it seems convoluted and repetetive, that is
because it is, but in some cases this is necessary. There are certain
functions used in the original code that are not available in GM, so the
bitwise scripts were created to simulate some features, namely the carry bit,
stored in the variable cbit. Understanding how cbit is used is important to
understanding how this script works.
*/
//A=0, X=1, Y=2, 00=3, 01=4, 04=5, 05=6, 88=7, 02=8, 03=9, 89=10, 08/0f=11/18
temp=ds_grid_create(12,1);
ds_grid_clear(temp,0);
pwt=ds_list_create();
ds_list_add(pwt,0);
pw=ds_grid_create(4,4);
var v01a;
v01a=irandom(255);
ally &= $FF;
//This subscript encrypts the player name and sums up the letters. Carry flag cleared.
for(ds_grid_set(temp,1,0,0);ds_grid_get(temp,1,0)<
8;ds_grid_add(temp,1,0,1))
{
ds_grid_set(temp,0,0,name[ds_grid_get(temp,1,0)]
);
adc(0,cryptos(0,ds_grid_get(temp,1,0)));
cbit=0;
adc(0,ds_grid_get(temp,0,0));
sta(3);
}
cbit=1;
amp(0,$7);
sta(3);
ds_grid_set(temp,0,0,stage);
//Change $11 to the highest resumable stage value
cmp(0,$11)
if cbit ds_grid_set(temp,0,0,$11);
stage=ds_grid_get(temp,0,0);
lsr(a); // These
ds_grid_set(temp,0,0,stage); // lines
lsr(0); // simply
rol(3); // shuffle
ds_grid_set(temp,0,0,v01a); // cbit
lsr(0); // around
repeat(3) rol(3); // just for this line
ds_grid_set(temp,0,0,ally);
//This checks if Accumulator is positive. Anything greater than $80 is negative.
if ds_grid_get(temp,0,0)>=$80 or ds_grid_get(temp,0,0)<0 ds_grid_set(temp,0,0,0);
ora(0,0,3);
asl(0);
ora(0,quest);
sta(7);
ds_grid_set(temp,0,0,v01a);
lsr(0);
ds_grid_set(temp,5,0,$50+$50*cbit);
tma(7,8);
amp(8,$F0);
tma(7);
repeat(4) asl(0);
sta(9);
cbit=0;
adc(0,0,8);
sta(4);
tma(5);
eor(0,0,8);
sta(3);
tma(5);
eor(0,0,9);
cbit=0;
adc(0,0,3)
repeat(4) lsr(0);
ora(0,0,4);
cbit=0;
adc(0,stage);
sta(10);
tma(7,3);
for(ds_grid_set(temp,1,0,0);ds_grid_get(temp,1,0)<
8;ds_grid_add(temp,1,0,1))
{
lsr(3);
rol(11+ds_grid_get(temp,1,0));
lsr(4);
rol(11+ds_grid_get(temp,1,0));
}
cbit=1;
ds_grid_set(temp,2,0,stage);
lsr(2);
for(ds_grid_set(temp,1,0,2);ds_grid_get(temp,1,0)>
=0;ds_grid_add(temp,1,0,-1))
{
ds_grid_set(temp,3,0,cryptos(1,ds_grid_get(temp,2,0)));
amp(3,$C);
repeat(2) lsr(3);
ds_grid_set(temp,0,0,cryptos(1,ds_grid_get(temp,2,0)));
amp(0,$30);
ora(0,0,3);
if cmp(0,cryptos(2,ds_grid_get(temp,1,0)))==0 break;
}
tma(1);
repeat(3) asl(0);
adc(0,0,1);
sta(2);
for(ds_grid_set(temp,1,0,0);ds_grid_get(temp,1,0)<
9;ds_grid_add(temp,1,0,1))
{
ds_grid_set(temp,4,0,cryptos(3,ds_grid_get(temp,2,0)+1));
amp(4,$30);
ds_grid_set(temp,0,0,cryptos(3,ds_grid_get(temp,2,0)+1))
amp(0,$3);
repeat(2) asl(0);
ora(0,0,4);
ora(0,0,11+ds_grid_get(temp,1,0));
ds_list_add(pwt,ds_grid_get(temp,0,0));
ds_grid_add(temp,2,0,1);
}
cbit=1;
ds_grid_set(temp,2,0,stage);
lsr(2);
ds_list_replace(pwt,0,cryptos(1,ds_grid_get(temp,2,
0)));
ds_grid_destroy(temp);
It will make more sense once I upload it. ALl that matters is "pwt" stores the actual password. Another script will translate that password into the grid we all know and love from CV3 and CV4; that script is short and sweet and I already finished coding it before I typed out this monstrosity. All the unknown 3-letter scripts are just 6502 Assembly instructions in GML script because I had to incorporate the carry bit ("cbit" in the script) into certain basic functions.
If this exacerbates your senses, then don't even think about looking at the decryption script when I upload it. It's bad enough it'll be coded by me, but the original script was pages and pages of mind-numbing assembly with branches within branches. ... This script here was straightforward by comparison.