Author Topic: MBNCSUtil 2.0 beta preview online  (Read 4131 times)

0 Members and 2 Guests are viewing this topic.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
MBNCSUtil 2.0 beta preview online
« on: September 13, 2006, 06:13:49 am »
I did a lot of toying with MBNCSUtil tonight, and I've got some working bits online for you to play with:

http://www.jinxbot.net/mbncsutil/mbncsutil-2.0-beta1.zip

What's new in this release:

MBNCSUtil.Data namespace - contains classes used for working with MPQ archives.
To use MPQs, use code such as:

Code: [Select]
MpqServiceProvider provider = MpqServices.Singleton.Provider;
MpqArchive archive = provider.OpenArchive("IX86Ver1.mpq");
if (archive.ContainsFile("IX86Ver1.dll"))
{
  byte[] verDll = null;
  using (MpqFileStream mfs = archive.OpenFile("IX86Ver1.dll"))
  {
    verDll = new byte[mfs.Length];
    mfs.Read(verDll, 0, (int)mfs.Length];
  }

  if (verDll != null)
  {
    FileStream fs = new FileStream("IX86Ver1.dll", FileMode.OpenOrCreate, FileAccess.Write);
    fs.Write(verDll, 0, verDll.Length);
    fs.Flush();
    fs.Close();
  }
}

The above code sample extracts the IX86Ver1.dll file from IX86Ver1.mpq and writes it to the local path.

I haven't tried using this in Visual Basic 6 yet, but I did wrap it with COM interfaces, so that should also be visible.

I haven't made documentation yet because I'm still trying to figure out how to get the bits of Sandcastle from Microsoft (their internal documentation compiler for .NET 2.0) to work.  However, full code is provided in the download, as is the XML documentation.

Also included, but incomplete, is the MBNCSUtil.BnFtp namespace.  This namespace will provide two classes: BnFtpVersion1Request and BnFtpVersion2Request.  Presently, because I hard-coded in the FILETIME of IX86Ver1.mpq, only BnFtpVersion1Request works and only with IX86Ver1.mpq.  However, if you dink around with those constructors, you should probably be able to get them to work with no problem.

I am posting this to get comments and feedback from the community; if anyone uses MBNCSUtil and would like to try out the new features, please let me know what you think.  Thanks!

I also want to answer the question about why I structured the classes like I did in the MPQ reading namespace.

I use an external library developed by a programmer called ShadowFlare called SFmpq.dll.  I included this DLL as a resource stream in the project, and when the MPQ API is first loaded, the DLL is extracted into a temporary file.  The temporary file is then LoadLibrary'd and I get the addresses of the APIs I used via GetProcAddress.  I defined a series of delegates that match the signatures of these methods.  Finally, I used Marshal.GetDelegateForFunctionPointer (a new API in .NET 2.0) to map the unmanaged function pointer to a managed delegate.  When the application is shut down and the finalizers are being called, I clean up any of the MpqArchive objects I created (HMPQs), then FreeLibrary() the temporary file, then delete the temporary file.

Unfortunately, if there are any exceptions that cause the application to exit without calling the finalizers, the temporary file remains on disk.

Anyway, thanks again for using it and let me know if you have any comments or questions.   :)
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: MBNCSUtil 2.0 beta preview online
« Reply #1 on: September 13, 2006, 07:49:56 am »
If you hardcode the FILETIME to 0, you should be able to download any file. The client sends 0 when it has no recollection of the file whatsoever and the server has no problem with it.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: MBNCSUtil 2.0 beta preview online
« Reply #2 on: September 13, 2006, 02:54:10 pm »
If you hardcode the FILETIME to 0, you should be able to download any file. The client sends 0 when it has no recollection of the file whatsoever and the server has no problem with it.

That worked, except for the IX86VerX.mpq files, because 0x50 sends the filetime as part of the login process.

Come to think of it though, I may have been doing something wrong at that point. 

Hm!
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: MBNCSUtil 2.0 beta preview online
« Reply #3 on: September 13, 2006, 07:22:47 pm »
I've updated the beta (use the same link above).

Included in this release is a test project demonstrating how to use the BnFtpRequestBase (and related classes) as well as some updates to the BnFtp namespace.  BnFtpVersion1Request and BnFtpVersion2Request both require a DateTime parameter representing the FILETIME of the file you're downloading, at least if you're getting a version-check MPQ, and I'll investigate the advertisements scenario in the coming weeks.

As I said, the sample test project prompts you for a CD key for Warcraft III, downloads the version check MPQ via BnFtpVersion2Request, saves it to the local folder, and extracts the version check DLL from the MPQ file.

I plan to include an ExtractFile(string mpqFileName, string destinationPath) method in the MpqArchive class in the future.

Please remember that this is a beta.  Thanks for your feedback.  :)
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline abc

  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: MBNCSUtil 2.0 beta preview online
« Reply #4 on: December 27, 2006, 05:42:36 pm »
Nice.