Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO.MPQ MapHash.cs GetHashedFileName #59

Open
ghost opened this issue Dec 7, 2024 · 3 comments
Open

IO.MPQ MapHash.cs GetHashedFileName #59

ghost opened this issue Dec 7, 2024 · 3 comments
Labels
Area-Mpq Related to project War3Net.IO.Mpq Question Further information is requested

Comments

@ghost
Copy link

ghost commented Dec 7, 2024

This function reports an error when packaging in MapBuilder. I think it's a problem with the Chinese file name? How to repair it? Please help me.

@Drake53
Copy link
Owner

Drake53 commented Dec 19, 2024

I didn't write the implementation for the hashing algorithm myself and I'm not sure if it's a bug or if the algorithm simply does not support chinese characters. Have you tried different tools to see if they have the same problem? Or if it works in different tools, can you give an example chinese file name and its hashed value?

I could probably fix this by UTF8 encoding the string to a byte array, but I'm not sure if that would give the correct result, so if you can please provide an example so I can test if the solution is correct.

@Drake53 Drake53 added Question Further information is requested Area-Mpq Related to project War3Net.IO.Mpq labels Dec 19, 2024
@ghost
Copy link
Author

ghost commented Feb 8, 2025

 var map = Map.Open("input.w3x", MapFiles.All
      & ~MapFiles.Script
      & ~MapFiles.Triggers
      );
      MapBuilder mapBuilder = new(map);
  
      mapBuilder.Build("out.w3x");

If "test.w3x" file contains any Chinese file name, this code will report an error, for example, if there is a '攻击之爪.blp' file in this' "test. w3x" file

[DllImport("Stormlib.dll")]
    public static extern int SFileAddFileEx(
        uint hMpq,
        [MarshalAs(UnmanagedType.LPWStr)] string szFileName,
        [MarshalAs(UnmanagedType.LPArray)] byte[] szArchivedName,
        uint dwFlags,
        uint dwCompression,
        uint dwCompressionNext
    );
public static byte[] GetArchivedNameBytes(string fileName)
  {
      var bytes = Encoding.UTF8.GetBytes(fileName);
      var result = new byte[bytes.Length + 1];
      Array.Copy(bytes, result, bytes.Length);
      result[bytes.Length] = 0;
      return result;
  }
public bool AddFile(string archivedName, string path)
  {
      if (Handle == 0)
          return false;
      if (ReadOnly)
          throw new ArgumentException("ReadOnly Modeing Not AddFile!!!");
      if (!File.Exists(path))
          throw new FileNotFoundException("File not found.", path);

      lock (_lock)
      {
          return 1 == StormLib.SFileAddFileEx(
                          Handle,
                          path,
                          StormLib.GetArchivedNameBytes(archivedName),
                          StormLib.MPQ_FILE_COMPRESS | StormLib.MPQ_FILE_REPLACEEXISTING,
                          StormLib.MPQ_COMPRESSION_ZLIB,
                          StormLib.MPQ_COMPRESSION_ZLIB
          );
      }
  }

I used 'Stormlib. dll' to solve this problem

@ghost
Copy link
Author

ghost commented Feb 8, 2025

I think you can support UTF8 so that Chinese can be used. Also, external JASS functions are not supported in Triggers. Can we make some changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Mpq Related to project War3Net.IO.Mpq Question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant