in0finite / SanAndreasUnity

Open source reimplementation of GTA San Andreas game engine in Unity
https://discord.gg/p6jjud5
MIT License
2.15k stars 353 forks source link

Issues on case-sensitive file systems #31

Closed echozio closed 4 years ago

echozio commented 5 years ago

Running the game on Linux with EXT4 and the Steam version of the game, I encounter a lot of errors with files the game is unable to locate due to the case in the path being different. For instance the "Data" directory has a capital D where as the game looks for "data". I've had to work around this by creating a disk image with FAT32 and copying the game data there. The code should perhaps be updated to ignore case when looking for files.

in0finite commented 5 years ago

That's what I explained in instruction for Linux.

The code should perhaps be updated to ignore case when looking for files.

There is no C# API for opening files case-insensitively (maybe not even a Linux API). But we could enumerate all files in GTA installation, store them in some list, and then search through this list case-insensitively (this is the best solution).

Also, there are some other solutions for this:

echozio commented 5 years ago

I'm sorry, I completely missed those instructions.

There is no C# API for opening files case-insensitively (maybe not even a Linux API).

Yes, I realize you would need additional logic to be able to do this, but at least in the future it should be implemented in the application to eliminate manual steps that need to be taken by less technical users. Certainly not something that matters much in practice right now, I'm sure.

Enumerating the files and comparing case-insensitively like you said definitely seems like the best long-term solution.

I'm on kernel 5.3, so I tried giving this a shot, but it turns out the EXT4 filesystem requires an additional attribute, encoding=utf8, in order to do this. For those who can use it, though, this is by far the easiest solution (in contrast to renaming or using a FAT image).

All you have to do on a compatible system is to go to your San Andreas directory and run

chattr +F .
in0finite commented 5 years ago

in the future it should be implemented in the application to eliminate manual steps that need to be taken by less technical users.

I agree. It should run out of the box with no additional setup. It's just that there hasn't been many Linux users so far, so this wasn't a problem.

it turns out the EXT4 filesystem requires an additional attribute, encoding=utf8, in order to do this

So this attribute is specified at moment of creation of EXT4 partition, or can be changed later ? If it can be changed, than that is the way to go.

echozio commented 5 years ago

So this attribute is specified at moment of creation of EXT4 partition, or can be changed later ? If it can be changed, than that is the way to go.

Unfortunately not. I did give it a shot with tune2fs /dev/sdb1 -E encoding=utf8, however only a subset of extended options are possible to change on an existing filesystem.

slapin commented 5 years ago

I think the best solution (and easiest to implement one) would be to try open all used GTA files to check for proper naming and report user to rename these. For long term solution I think just lowercasing all filenames open from dat files will do. User could use one of lowercase scripts once on their GTA installation. I think lowercasing is very quick to add and that will solve the problem completely and no fancy stuff will be required.

slapin commented 5 years ago

To rename all files, go to gta sa directory and run the following script:

rename -v 'y/A-Z/a-z/' `find .`

if errors are printed, run it again until no output given

To make game work with lowercase files, the small patch is needed:

diff --git a/Assets/Scripts/Importing/Items/Item.cs b/Assets/Scripts/Importing/Items/Item.cs
index 03012128..85009767 100644
--- a/Assets/Scripts/Importing/Items/Item.cs
+++ b/Assets/Scripts/Importing/Items/Item.cs
@@ -40,6 +40,7 @@ namespace SanAndreasUnity.Importing.Items
                     args = args.Replace(".IDE", ".ide");
                     args = args.Replace(".IPL", ".ipl");
                     args = args.Replace('\\', Path.DirectorySeparatorChar);
+                   args = args.ToLower();

                     switch (type.ToLower())
                     {

Thanks for the nice project. Very nice playground. Is it possible to enter cars yet or see peds actually dying (not disappearing)?

in0finite commented 5 years ago

@slapin Thanks for suggesting another solution.

But I don't agree that it is the best long-term solution. The best solution would be to case-insensitively search for files in internal list of all files, like I said before. This will not require any setup from users.

I think I know how to do it. ArchiveManager holds all loaded archives. One of them is LooseArchive, which is actually a directory, and contains files from GTA installation. So what we can do, is to replace arg with the real name, after this line:

https://github.com/GTA-ASM/SanAndreasUnity/blob/7725dfbf7130a061c7adf6f25f3b735192572c84/Assets/Scripts/Importing/Items/Item.cs#L42

The real name will be retreived from ArchiveManager.

Thanks for the nice project. Very nice playground.

Yeah, it's just fun to work on it :grinning:

Is it possible to enter cars yet

Well, did you see gameplay video, or even played the game ? Of course it is.

see peds actually dying (not disappearing)?

Not yet.

echozio commented 5 years ago

I completely agree with @in0finite . This also allows you to use an existing game installation without altering it.

I haven't read enough of the code to have any valuable input on your suggested implementation, but if you implement it I would be happy to test it.

in0finite commented 5 years ago

It shouldn't be difficult. But I'm a little busy these days, so you guys can give it a try in the meantime.

in0finite commented 4 years ago

@chris-echoz can you test it now, from case-sensitivity branch ? It works for my GTA version on NTFS partition.

echozio commented 4 years ago

@in0finite Did not work, failed at loading carrec.img Might work for everything else than carrec.img, though, as when I renamed its parent directory "paths" to "Paths", everything loaded perfectly. Exception:

System.Exception: Archive not found: /home/chris/etc/games/steam/steamapps/common/Grand Theft Auto San Andreas/data/Paths/carrec.img
  at SanAndreasUnity.Behaviours.Loader.StepLoadArchives () [0x0005e] in /home/chris/git/SanAndreasUnity/Assets/Scripts/Behaviours/Loader.cs:280 
  at SanAndreasUnity.Behaviours.Loader+<LoadCoroutine>d__36.MoveNext () [0x001f6] in /home/chris/git/SanAndreasUnity/Assets/Scripts/Behaviours/Loader.cs:186 
in0finite commented 4 years ago

Ok, so archives are not working yet. I can fix this in 1-2 hours.

Can you confirm that you did not rename any other files/folders in your GTA installation ?

in0finite commented 4 years ago

I fixed archives. Try now.

You mentioned that data folder starts with capital D. If that is the case, then some more file types will fail to load. I don't know how you succeeded. Maybe you renamed "Data" to "data".

echozio commented 4 years ago

@in0finite I may have renamed some things from earlier. I'll try deleting and redownloading the game from Steam.

in0finite commented 4 years ago

That would be great. This is the only thing preventing the Linux build release.

Basically, I think that everything is fixed, except maybe for models folder. If it starts with capital M, then there will be 1 more fix to do.

echozio commented 4 years ago

It worked right away with the freshly downloaded game from Steam

in0finite commented 4 years ago

Awesome 😊. Can you try to spawn vehicles and roam around for a little, just to make sure it's all good ?

echozio commented 4 years ago

Yup, I did, everything appears to work as it should. Was able to fly around, spawn and drive vehicles as well as shoot my guns (except the rocket launcher, but this was the case earlier, too).

in0finite commented 4 years ago

Alright then, I guess this issue is fixed. Thanks for testing.

in0finite commented 4 years ago

@chris-echoz I've just been told that sound can not be loaded with Steam version. The reason for this is audio/sfx folder, which is named audio/SFX in other GTA versions. Can you hear sounds with your version ?

echozio commented 4 years ago

@in0finite I did not hear any sounds, but I also don't believe I heard any when I played with the FAT disk image.

in0finite commented 4 years ago

Now I don't get it. How is it possible that you didn't hear sounds with FAT ? By sounds, I mean weapon sounds when you shoot, and startup music.

echozio commented 4 years ago

I tested both just now, and you're right. Audio works with the FAT image, but not with the game from Steam stored on ext4.

in0finite commented 4 years ago

Try it now, from audio-lib branch. It looks for "sfx" folder if "SFX" folder does not exist.

Btw, can you send me the contents of GTA installation, for example, by using tree command ? So that I can test everything without asking you.

echozio commented 4 years ago

audio-lib branch fixed the audio for me. Here's the output of tree: https://gist.github.com/chris-echoz/666b9574baf60c3efc74875586c5f388 And output of find, which might be more useful: https://gist.github.com/chris-echoz/11c57a21076de4502792ff6765531eb6