Fixing CusPop

Discussions about all other tools (CusPop, SAV/HOF editors) and hex editing.
Post Reply
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Fixing CusPop

Post by David »

A few days ago I tried to run CusPoP (that was written in PHP).
I used the source that can be found here: http://www.popot.org/other_useful_tools ... and_CusAsm.
Only a few fixes were needed to make it work:
- change extensions from .phps to .php
- change <? to <?php at the beginning of the files
- in cuspopgenerator.php, change action='prince.exe' to action='gethack.php'
- in gethack.php, before echo $out;, add header('Content-Disposition: attachment; filename=prince.exe');
You need to start cuspopgenerator.php .

I know that Poirot is working on a new version (see here), but until it's finished, the older version could be put up.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Fixing CusPop

Post by Norbert »

David wrote:Only a few fixes were needed to make it work: [...]
And non of these changes appear to be related to WordPress, which surprises me.
It makes me a little sad that poirot, despite receiving many requests from me to fix CusPop, didn't help us out a bit more.

Anyways, I've applied the changes you mentioned.
http://www.popot.org/other_useful_tools.php?tool=CusPop
It serves a PRINCE.EXE file (the correct file, packed/unpacked), but it's not a modified file...

By the way, do you know which files are necessary for CusPop to work?
Right now, popot.org/cuspop/ contains:
cusasm.php
cached/form.htm
cached/-z
cached/cachedtree.php
princehack.xml
cuspop.php
gethack/cusasm.php
gethack/gethack.php
gethack/-z
gethack/backup/gethack.php
gethack/backup/customexe.php
gethack/backup/parsecommands.php
gethack/parsecommands.php
gethack.php
options.php
vers/bin.p0
vers/bin.u3
vers/bin.u4
vers/bin.p3
vers/bin.u0
vers/bin.p4
parsecommands.php
cuspopgenerator.php
I can probably remove at least the gethack/ and cached/ directories?
Probably also cuspopgenerator.php, since it's no longer being used.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Fixing CusPop

Post by David »

Norbert wrote:It serves a PRINCE.EXE file (the correct file, packed/unpacked), but it's not a modified file...
Ah, yes, I didn't check the generated files.
It seems that only strings are not handled correctly.
gethack.php expects a "size" attribute for strings. It gets the list of hacks through a hidden form field * ; the form is generated by cuspopgenerator.php .
* Its contents are ~100 kB! Perhaps this wasn't the best design decision...
However, cuspopgenerator.php doesn't copy the size from princehack.xml to the hidden field.

In cuspopgenerator.php, find this line:

Code: Select all

				$binary[]=array('action'=>'read','type'=>$item['attributes']['type'],'reference'=>create_ref($item['attributes']['name'].$refid),'wop'=>@$item['attributes']['writeoperation']);
And replace it with this:

Code: Select all

				$binary[]=array('action'=>'read','type'=>$item['attributes']['type'],'reference'=>create_ref($item['attributes']['name'].$refid),'wop'=>@$item['attributes']['writeoperation'],'size'=>@$item['attributes']['size']);
And... the http://www.popot.org/other_useful_tools.php?tool=CusPop page has maxlength attributes on the text fields, which seems to be missing from the source.
Is that page generated by the CusPoP source, or is it just a static page saved from the time CusPoP was working?
(Perhaps the source is not the newest version? - Or, judging from the bug above, different files are from different versions?)
To add them, add this to cuspopgenerator.php, in the print_input function, before the if ($use=='checkbox') line:

Code: Select all

 	$size=@$read['size'];
 	$maxlength=$size?" maxlength='$size'":'';//
 	$def.=$maxlength;//
Now it should work.
I tried changing the remaining time (both minutes and seconds), level type, guard HP, filenames, cheat code, tile incompatibilities.
This covers all types: integer, float, string, boolean (checkbox) and drop-down list.

Just one more bugfix: (this also seems to be fixed on the PoPOT page)
Occurences of value="0" are ignored.
change this: (in cuspopgenerator.php)

Code: Select all

			$v=$value?" value='$value'":'';
to this:

Code: Select all

			$v=!is_null($value)?" value='$value'":'';
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Fixing CusPop

Post by Norbert »

Thanks for looking into all this.

The version at popot.org is a "static page saved from the time CusPoP was working".

I'm looking into the differences between both versions.
One thing the popot.org version seems to have fixed is that 'f36' isn't used twice.
I haven't looked at everything yet, but other changes appear to be related to aesthetics only.

[Edit: The JavaScript "l" variable appears to have some possibly important differences between the two versions: image/mirror. Also, everything the /* draw hidden */ section generates isn't on popot.org, nor is the large "all" JavaScript array.]
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Fixing CusPop

Post by Norbert »

Okay, I've looked through everything. In addition to what I've already posted, here are all other differences:

1. Some (non-crucial) text changes, like starting sentences with capitals.

2. An extra helptip under Game Messages:

Code: Select all

<p class='helptip'>The character % is used as an escape character used to replace some needed placeholders. We are using the printf syntax. So a % must be written as %%, a decimal as %d (%5d is a decimal of 5 spaces, %05d a decimal completed with zeros to fit the 5 spaces), a character as %c, a text string as %s. If you want more complicated replacements read the referred documentation.
</p>
3. It says value='off' instead of value='0'.

3. Labels have a for=''.

4. Ids have been added here and there.

5. All the resources are on by default. (I made that change myself.)

Based on these last two posts of mine, should any additional changes be made to any of the PHP files?
(I did not yet upload files that include the changes you've already suggested. I'll do that soon.)
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Fixing CusPop

Post by David »

2. An extra helptip under Game Messages:
That message is on a <folder> tag, the others are on <read> or <hack> tags. The print_form() function is responsible for the help text, but it does not print a help text for <folder> tags.

Some more differences:
- "Section", "Customize" (on PoPOT) are "Folder", "Set up" in the source. (print_form())
- On PoPOT there is an introduction text. In the source it is commented out in print_page().
Norbert wrote:One thing the popot.org version seems to have fixed is that 'f36' isn't used twice.
That should be fixed.
These IDs are generated by create_ref().
It generates an unique ID from the combination of the item name and the index of the group.
The problem is that the "combination" is a concatenation.
Therefore, "level 11" "7" (in "guard information") and "level 1" "17" (in "level color variations") will get the same ID, 'f36'.
(I got these by adding print"[$ref]"; into create_ref().)
Some separator would fix this. Perhaps change create_ref() to accept two parameters (and replace "." with "," in the calls), and concatenate them in create_ref() - with a separator in between.
Note: It would be incorrect if create_ref() returned a different ID each time (like get_free_id()), because, in case of duplicates, it is called with the same argument multiple times, and then should return the same ID. These IDs are used not only in the <input> tags, but also in the hidden form field, to connect input fields to offsets. Duplicates mean that the same field is bound to multiple offsets.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Fixing CusPop

Post by Norbert »

David wrote:Some more differences:
- "Section", "Customize" (on PoPOT) are "Folder", "Set up" in the source. (print_form())
- On PoPOT there is an introduction text. In the source it is commented out in print_page().
In my overview I grouped those under:
Norbert wrote:1. Some (non-crucial) text changes, like starting sentences with capitals.
I'll study your text about IDs tomorrow, I hope I'll figure out what are the proper changes to make...

By the way, what about this...
Norbert wrote:[Edit: The JavaScript "l" variable appears to have some possibly important differences between the two versions: image/mirror. Also, everything the /* draw hidden */ section generates isn't on popot.org, nor is the large "all" JavaScript array.]
...is any of that going to be a problem, you think?
To me it looks like maybe some changes can or cannot, or should or shouldn't, be applied to certain PRINCE.EXE versions.
What the password string was used/meant for, I do not yet know either.

Thanks again for throwing time and energy at this.
Tomorrow, I'll make sure the updated version becomes available at popot.org and here on princed.org, and I'll also publish a package of the updated version as CusPop 2.1.
I'll update a doc in the package or I'll add an AUTHORS file or something - that'll also mention Enrique - to give some credits to you ("David from the Princed Forum") and I'm also going to make sure the script enables all resources by default.
I doubt the latter is a controversial change, and it'll prevent lots of people from running into 'distorted' images when playtesting mods.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Fixing CusPop

Post by David »

Norbert wrote: By the way, what about this...
Norbert wrote:[Edit: The JavaScript "l" variable appears to have some possibly important differences between the two versions: image/mirror. Also, everything the /* draw hidden */ section generates isn't on popot.org, nor is the large "all" JavaScript array.]
...is any of that going to be a problem, you think?
To me it looks like maybe some changes can or cannot, or should or shouldn't, be applied to certain PRINCE.EXE versions.
Yes, there are certain hacks that have no offsets in certain versions. These are disabled by the JavaScript when you select a version.
For example, level color variations don't exist in 1.0. Or, certain tables (like the guard types/skill, cutscenes, allowed tiles) have their parts compressed in the packed versions.
However, some items of this array are the empty string. I guess that the problem is that in cuspopgenerator.phps, an array with holes (non-contigous indexes - see the unset() in add_field()) is walked with a for (in print_script()), instead of a foreach.
Replace for ($j=0;$j<@count($val);$j++) { with foreach($val as $j=>$l3){.
After this fix there still are differences: for example, selecting 1.0 disables the "Newer versions cheat code" in the PoPOT version, but not in the source version. Selecting 1.3 or 1.4, however, disables "Older version cheat code" in both versions.

The "all" array is just a list of all fields for the above function. The PoPOT version selects fields by their ID.

The /* draw hidden */ section generates the 'pass' field, see below.
Norbert wrote: What the password string was used/meant for, I do not yet know either.
That is the hidden field that passes the hacks from cuspopgenerator.php to gethack.php.
It was removed from the PoPOT version. Instead, it is written to cached/cachedtree.php . (According to the version on github, see link below.)
Norbert wrote: [...] and I'm also going to make sure the script enables all resources by default.
I doubt the latter is a controversial change, and it'll prevent lots of people from running into 'distorted' images when playtesting mods.
I wanted to this post, but then I realized that people who make a custom prince.exe will distribute it with their levels...
However, it works only in the unpacked versions.

By the way, I found this: https://github.com/ecalot/cuspop
Judging from princehack.xml, which has <enum> tags, widget="color" attributes, this is probably the upcoming version - at least what is already ready from it.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Fixing CusPop

Post by Norbert »

All right, cool.
Norbert wrote:Tomorrow, I'll [...]
On Saturday, I'll [...]. :)
(Creating the sword fighting video took longer than I thought.)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Fixing CusPop

Post by Norbert »

Enrique's code is full of "if ($variable=@$variable), and I have no idea what that means.
Even if @ is used to suppress errors or whatever or it refers to a special kind of variable, how could that code possibly work?
Shouldn't it be either == or !=, or is the @ somehow changing the whole thing?
Super annoying that it's impossible to search for =@ via Google (even with verbatim and +), and on IRC nobody seems to know what such code does.
I'm going to e-mail Enrique about it.
poirot
Developer
Developer
Posts: 394
Joined: March 24th, 2003, 8:52 pm
Location: Australia
Contact:

Re: Fixing CusPop

Post by poirot »

Sorry, did you know I wrote the code in about two days?

Code: Select all

if ($some_defined_variable=@$some_may_be_defined_variable)
this code defines $some_defined_variable to be used inside the if or ignores the if in case $some_may_be_defined_variable is null or not defined. In my case there was no way this variable could be null, so the if works only for defined variables. This is very useful while using arrays. An example:

Code: Select all

if ($key=@$array['key']) {
     something_with($key)
}
in python would be

Code: Select all

if ('key' in array):
     key=array['key']
     something_with(key)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Fixing CusPop

Post by Norbert »

Post Reply