TGE/Code/How to make torque a plugin

From TDN

Contents

Disclaimer


Making secure web plug-ins are difficult and may create many different security risks. If you make use of this project, make sure comprehensive testing takes place before releasing projects to the public. This project is an unofficial project.

Introduction


This is currently a work in progress and I hope that people will join in and help make this a reality. This page is an attempt to turn the TGE into a plugin which is usable in the majority of browsers on the market.

Image:TGEPlugin.jpg





Starting Off


Download

Before we start you will need a clean version of TGE 1.4 or 1.5 installed in a directory. The directory that the files reference will be C:\projects\tge14\TGE14Plugin and you will have to change them to match your setup. Next extract [this zip] into the main TGE 1.4 or TGE 1.5 folder. This zip contains all the files nessessary to start compiling the browser plugins.

The code






What's Included

The Visual Studio 2003.net project that you download will include a number of Sub-Projects beyond the default Torque projects.

Project         Status       Description

np3DPlugin      Compiles    Dual Plugin that contains both ActiveX and npPlugin interfaces.  
np3DPluginFF    Broken      Plugin that only works in np capable browsers (FireFox)
np3DPluginPS    Unknown     Autogenerated by the ActiveX wizard while making the Dual Plugin

** Hasn't been tested in a while.  Will be once the Dual plugin is working better.  It's not needed for windows systems.



Here are some tips to getting this to work in Visual Studio 2005:

  • 1) Get a copy of VS2005 Standard, Express is no good as it doesn't have the proper ATL libraries.
  • 2) Extract the files and use Beyond Compare to integrate them into your project.
  • 3) Add the np3DPlugin project to your Solution.
  • 4) Copy into the np3DPlugin project any extra files your game may be using that you have added to the engine (To avoid loads of linker errors!)
  • 5) A number of the functions have changed 2003 -> 2005. Generally these relate to UTF16 being replaced by wchar_t. Castings in the relevant places sorted this out.




News


  • December 25, 2006 - Added brief instructions on how to get it to work in VS 2005.
  • August 22, 2006 - Reuploaded the code with minor fixes. .sln file now fixed. Called it v1.0
  • July 19, 2006 - Uploaded version with working mission downloader and install files.
  • July 10, 2006 - Started to add information about the downloading of files.
  • May 29, 2006 - Major problems in IE now eliminated.
  • May 19, 2006 - Reload now works in IE and Firefox.
  • May 02, 2006 - You can now reload. Still buggy though.
  • April 26, 2006 - Fixed compiler problems.
  • April 21, 2006 - Made and uploaded the first compiled version of the plugin. Fixed some IE bugs. Got it working in Firefox again.
  • April 11, 2006 - Fixed crash on close and you can now resize the browser in ActiveX. FireFox is probably broken now.
  • March 24, 2006 - Got the ActiveX control to display in the browser.
  • March 10, 2006 - Got the ActiveX version to compile. Still doesn't display anything useful but it loads.
  • March 07, 2006 - Updated the code. Now launches TGE and allows you to play a game.
  • March 03, 2006 - Updated the code. It now finds the data directories, but the ASM which detects the processor is still broken.
  • March 02, 2006 - Updated the site again with a version of the plugin which actually shows you something in Firefox. Only the debug version works because it's looking for the main.cs and data files in the working directory. If it can't find them, the browser will exit.
  • Feburary 2006 - First version of the plugin uploaded.




Compiling


Setup


Before the program will compile, you first need to add some of the npPlugin tools to your path. Press Windows + Break to open the system control panel. Go to the Advanced tab and click the Environment Variables button. In the lower section you should see a Path variable. Double click on that. We need to add the Gecko tools to the path. You will have to adjust these 2 paths to point to the directory where you extracted the zip file to.

;C:\projects\tge14\TGE14Plugin\bin\moztools\wintools\buildtools\windows\bin\x86;C:\projects\tge14\TGE14Plugin\bin\gecko-sdk\xpcom\bin;

Now Visual Studio should be able to find the xpcom files nessessary to compile.

You also need to create one Windows Registry entry due to the fact that no information can be supplied on the command line. It will point to the Torque folder. This will typically be done in the Install program. Click Start -> Run and type in "regedt32" without the quotes. Open up HKEY_LOCAL_MACHINE\Software and right click to create a New Key. Type "TGEBrowser" without the quotes.

Inside of the TGEBrowser folder, create a new String value and call it main.cs. Set its value to wherever you are storing the main.cs, client, server, and data folders. For example:

c:\projects\tge14\tge14plugin\example\

Now the plugin will be able to find the main.cs file (and accompanying data files) wherever it is located on the hard drive.

Compiling the Dual Plugin

Navigate into the \vc7\ folder and double click on the tge14.sln file which was extracted from the zip. Make sure that the np3DPlugin project is selected and go into the properties page for it.

In the Debugging section change the working directory to where your example folder is (The same path that you entered into the registry) and set the command to either your Firefox or Internet Explorer executable. Don't select the IE from the list, navigate to the executable on your hard drive.

Next go down to the Custom Build Step and adjust the Command Line function to point the DLL to the firefox plugin directory and the .xpt to the Firefox components directory. The .xpt is required in order to allow JavaScript to call the function.

The setup for registering Internet Explorer is automatically done in the Build Events->Post-Build Event page with the regsvr32 command. You shouldn't need to change anything there.

Now do a full clean build of np3DPlugin and it should launch your web browser when done. Load up the dual.html file and if everything went right, it should load the plugin.





Compiling the npPluginFF (FireFox only)

  • Currently Out of Date*

This project is for a Firefox only version of the plugin on windows. It will only be useful if you are interested in porting the plugin to Linux, the Mac or aren't interested in the ActiveX portion of the code and want a simplified version.

Navigate into the \vc7\ folder and double click on the tge14.sln file which was extracted from the zip. Make sure that the np3DPluginFF project is selected and rebuild it.

  • If FireFox isn't located in c:\Program Files\FireFox then you may get some compile errors. To fix them go into Project -> Properties -> Custom Build Step->General -> Command Line. Click the 3 dots and adjust the folders to point to your actual FireFox directory. "C:\Program Files\Mozilla FireFox" is the default directory that FireFox installs to.

  • End Out Of Date Section *




Plugin Paramaters


  • <param name="mission" value="stronghold.mis">
    - This paramater specifies the mission file which TGE is supposed to load. If you have compiled in the Download code then the mission file will be downloaded from the specified server.

  • <param name="downloadURL" value="http://www.example.com/subfolder/">
    - This paramater specifies where on the server the mission files that will need to be downloaded are located. In this directory you place all of your .upd files and, if you're using the demo game for TGE, "/starter.fps".



Signing the Install


In order for users to be able to download your version of the browser plugin from a web site they either have to reduce their security to a low level, or you need to purchase a code signing certificate from any number of companies (eg [GeoTrust]). Once you purchase it you should have two files and a password.

  • C:\code_signing.pvk
  • C:\code_signing.spc

The next step is to download the [CAB SDK from Microsoft's web site]. Extract that package somewhere on your hard drive.

In order to package up a .cab file properly you will need to create a .inf file so that IE will know what to do with the files that it extracts. Create a file called my3dplugin.inf and open it in a text editor. Put the following code inside:

[Add.Code]

[Setup Hooks]
hook1=hook1

[hook1]
run=%EXTRACT_DIR%\stub_setup.exe 

[Version]
; This section is required for compatibility on both Windows 95 and Windows NT.
Signature="$CHICAGO$"
AdvancedInf=2.0

If you are including the plugins dll in the .cab file you may want to add an extra bit, but it is in no way required (It adds the plugin to a section in the IE options). Make sure to adjust the clsid to reflect your plugin.

[np3DPlugin.dll]
file=http://www.example.com/subdir/np3DPlugin.dll
clsid={00000000-0000-0000-0000-000000000000}
FileVersion=1,0,0,1



Next, create a new text file called createCAB.bat and open it up in a text editor. Add these 3 lines of code and adjust the file paths to match those on your system.

C:\cabsdk\BIN\cabarc  -s 6144 n my3dplugin.cab setup.exe my3dplugin.inf
"C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\signcode" -v c:\code_signing.pvk -spc c:\code_signing.spc -a sha1 my3dplugin.cab
pause

If everything is entered in correctly, when you run it you should see cabarc create the .cab file and then signcode will popup a password dialog box. Enter in your code signing password and the .cab file should be signed. Right click on the .cab file and select properties. If you see a Digital Signature tab there then everything worked. If not look through your .bat file and check to make sure that everyting is setup properly.

Upload the .cab to your server and load your testing web page which refers to the .cab in the <object> tag and it should now download on an end users machine.

The whitelist


The whitelist was put into the plugin to help prevent sites which you don't trust from running the plugin. It is simply a text file with a list of domain names which every user has on their local machine which lists which domain names are allowed to send mission/data files to the user. If their name isn't on the list, then the plugin will not ask for the files.

The format for the file is very simple. Simply place each unique domain name on its own line like this:

garagegames.com
example.com
www.example.com



Creating a .upd file


.upd files are used to tell the plugin what files need to be downloaded from the server. They include a crc check to make sure that it isn't downloading files which already exist on the end users machine. To generate a .upd file you need to load up a version of TGE which includes all the files you are going to use, then in the console type:

createFileList("stronghold.mis.upd");

This will place a file in your games directory (eg starter.fps) called stronghold.mis.upd. Next open that file in a text editor and remove all of the files from the list which you don't want to be included with your mission. Typically the client and server directories as well as any data files which aren't used in the level. Right now it isn't smart enough to only populate the list with the items which are actually used.

Once you have that file created you can place it on your web server and the plugin will try to download it when you specify stronghold.mis as a paramater.



Contributers


These people helped out in some way (whether they knew it or not).

  • Ed Zavada - TGE 1.5 integration
  • Gordon Marsh - Figured out how to get it working in VS2005
  • ThothraMerkaba on IRC - Beta testing a new crash.
  • Ricky26 on IRC - Contributed the file download code
  • Pauliver on IRC - Tested the installation instructions to verify that it works on other people machines.
  • Jeff White - Contributed this [helpful answer]
  • JamesU on IRC - Contributed the reload code.
  • Blikstad on IRC - Helped out with some random programming problems.
  • Neil Marshall [email protected] - Started the project




Tasks that need to be worked on


If you want to work on any of these, feel free to pick up the ball and add it. It's not hard.

  • Fix the crash on exit in Firefox
  • Read in the url of the page that is running the plugin in Firefox.
  • Get WM_MOUSEWHEEL to work with Firefox code.
  • Improve the registry entry code/Object tag parsing so that multiple apps will be possible with one plugin.
  • Implement the ability to script the plugin (Watch out for security holes).
  • Get fullscreen to work.
  • Fix up this document so that it's easier to follow.