MOD作成方法

Last-modified: 2009-11-25 (水) 14:06:20

このページは以下のサイトを翻訳しています。
http://developer.valvesoftware.com/wiki/Installing_and_Debugging_the_Source_Code
現在作成中です。

概要

ソースコードのインストールとデバッグの一般的な手順は以下のようになっています:

  1. SDKからCreate a Modツールを実行してソースコードをインストール
  2. Microsoft Visual Studio .NET 2003を使用してソースコードをコンパイル
  3. デバッグパラメータの設定
  4. デバッガーの実行

Step By Step

Run the Create a Mod wizard

  1. Source SDKを立ち上げてエンジンバージョンにHarfLife2、もしくはHarfLife2:Episode Oneを、CurrentGameにHarfLife2を選択して、Create a Modをダブルクリックしてください。
  2. Modの種類により二つのタイプを選びます。シングルプレイヤーMODを作成するかマルチプレイヤーMODを作成するかにより選択してください。
  3. 次のダイアログでどこのフォルダにMODを作成するか決定してください。今回はC:\MyMod.で作成します。
  4. 下のテキストボックスには好きなMODの名前を付けてください。この名前が\SteamApps\SourceModsの下のフォルダ名になります。
  5. [次へ]ボタンをクリックしてください。ハードディスク上にソースコードがインストールされます。
  6. wizzardが終わるまでお待ちください。

SourceCodeのコンパイル環境

ソースコードをコンパイルする環境を以下の3つからお選びください。

Note:

It is on debug compile by default. In order to run the mod with a debug dll you must right click the mod in the Steam game browser, click Properties then Set Launch Options... and add -allowdebug to the end of anything that may already be there (separated by spaces). You can change to a release build (for distributing the mod) in the configuration manager.

Currently the code is better compiling on VS2005. You can download it at http://www.microsoft.com/express/2005/

VCE2005 users need to download the Windows SDK (Windows 2000 users: Platform SDK). Visual Studio and VCE2008 users do not.

Debugging

Setup debugging parameters
Note:This will only work if you have installed and launched the Source SDK Base.

  1. In the Solution Explorer window, right-click on the current project (the one in bold) and choose Properties.
  2. In the Property Pages dialog that appears, choose the Debugging item on the left-hand side.
  3. On the right-hand side, in the text control next to Command, enter C:\Steam\SteamApps\Username\source sdk base 2007\hl2.exe (adjusting the folder names given here to reflect your own Steam installation).
  4. Next to Command Arguments, enter -dev -sw -game "C:\Steam\SteamApps\SourceMods\MyMod" (where MyMod is the name of your mod you entered in the Create a Mod dialog).
  5. Next to Working Directory, enter C:\Steam\SteamApps\Username\source sdk base 2007 (adjusting the folder names given here to reflect your own Steam installation).
  6. Click the OK button.

Note:

If you are on the OB code-base and are having trouble with debugging from inside Visual Studio, look at your gameinfo.txt for your mod. If the AppID says 440, you need to change your "Command" and "Working Directory" to point to the "team fortress 2" counterparts. (aka C:\Steam\SteamApps\Username\team fortress 2\hl2.exe and C:\Steam\SteamApps\Username\team fortress 2

Note:

If your paths for the options above have spaces, its a good idea to surround them with quotes. For example, "C:\Steam\SteamApps\Username\team fortress 2\hl2.exe" etc. It MIGHT work without them, but if you are having trouble with debugging, this is something else to try.

Note:

If you get linker errors like fatal error LNK1169: one or more multiply defined symbols found or error LNK2005: __malloc_dbg already defined in memoverride.obj, these can be fixed by adding "/FORCE:MULTIPLE" (without the quotes) into the project properties/configuration properties/linker/command line/additional options. This will most likely have to be added to both the server and client project within the solution.

Run in the debugger

  1. Important: after an SDK update, you must make sure to run whatever game you're editing through Steam once (only one time is necessary) before running in the debugger. If you don't, you may get Steam errors when running through the debugger.
  2. Right-click on the same project you were editing the properties for, and choose Debug->Start New Instance.
  3. If you get a warning that hl2.exe has no debugging information, ignore it.
  4. It should now launch Half-Life 2 and run your code. You can make modifications to the code now, rebuild, and rerun the game with your changes!

Alternative : run-time attachment

  1. Start the mod using Steam
  2. Inside Visual Studio, Main Menu > Debug > Attach to Process...
  3. Select the hl2.exe process with the title of your mod

Tip:

you can start the app in windowed mode for better comfort : add a "-window" option in your run_mod.bat

Links

A good next step after mastering this document is to look at the Your First Entity document, in which you will make changes to some of the source code.

If you plan to integrate code updates from Valve, and if you want code backups and revision history, take a look at the Using Source Control with the Source SDK document.