PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [RisenSDK] Risen Script Sample project creation/setup



NicoDE
06.10.2011, 14:20
This screenshot tutorial is intended to guide you through the initial creation, setup, and configuration of a new RisenSDK Script Extension project. It is silently assumed that Visual C++ is configured to use the Platform or Windows SDK (you are able to compile and link projects that use the Windows headers and libraries).

Project creation/setup
Create a new Empty Project in $(RisenSDK)/source/Scripts/.
(in this case the SDK has been checked out to D:\Games\Risen)
The project name has to start with Script_ to be loaded by Risen.
The subfolder (project name) will be automatically created by the wizard.
http://upload.worldofplayers.de/files7/script_sample_01.png
http://upload.worldofplayers.de/files7/script_sample_02.png
Add the Script library project (with dependencies) to the solution.
http://upload.worldofplayers.de/files7/script_sample_03.png
http://upload.worldofplayers.de/files7/script_sample_04.png
Remove the DebugCLR/ReleaseCLR configurations from the solution.
http://upload.worldofplayers.de/files7/script_sample_05.png
http://upload.worldofplayers.de/files7/script_sample_06.png
http://upload.worldofplayers.de/files7/script_sample_07.png
http://upload.worldofplayers.de/files7/script_sample_08.png
Add the project dependencies for the main project.
http://upload.worldofplayers.de/files7/script_sample_09.png
http://upload.worldofplayers.de/files7/script_sample_10.png
Add the main C++ file for the DLL and ScriptInit entry points.
(done first to enable the C/C+ Compiler Tool for the project)
http://upload.worldofplayers.de/files7/script_sample_11.png
http://upload.worldofplayers.de/files7/script_sample_12.png
http://upload.worldofplayers.de/files7/script_sample_13.png
http://upload.worldofplayers.de/files7/script_sample_14.pngTemplate for the main C++ file (Script_Sample.cpp):
#include "Script.h"

static gSScriptInit g_ScriptInit;

//NOTE: This manually coded script entry point will be replaced
// with a macro framework in future versions of the RisenSDK...
extern "C" __declspec( dllexport )
gSScriptInit const * GE_STDCALL ScriptInit( void )
{
if( g_ScriptInit.m_arrScripts.IsEmpty() )
{
//TODO: Add your script functions here.
// s_ScriptInit.m_arrScripts.Add( gSScriptInitScript( ... ) );
}
return &g_ScriptInit;
}

BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID )
{
if( DLL_PROCESS_ATTACH == dwReason )
::DisableThreadLibraryCalls( hModule );
return TRUE;
}
Change the type of All Configurations to Dynamic Library
http://upload.worldofplayers.de/files7/script_sample_15.png
http://upload.worldofplayers.de/files7/script_sample_16.png
http://upload.worldofplayers.de/files7/script_sample_17.png
Inherit your project configurations from $(RisenSDK)/source/RisenScripts$(ConfigurationName).vsprops (
..\..\RisenScriptsDebug.vsprops for the Debug configuration and
..\..\RisenScriptsRelease.vsprops for the Release configuration).
http://upload.worldofplayers.de/files7/script_sample_18.png
http://upload.worldofplayers.de/files7/script_sample_19.png
http://upload.worldofplayers.de/files7/script_sample_20.png
http://upload.worldofplayers.de/files7/script_sample_21.png
Reset your configurations to the inherited settings.
http://upload.worldofplayers.de/files7/script_sample_22.png
http://upload.worldofplayers.de/files7/script_sample_23.png
http://upload.worldofplayers.de/files7/script_sample_24.png
http://upload.worldofplayers.de/files7/script_sample_25.png
http://upload.worldofplayers.de/files7/script_sample_26.png
Now all configurations should compile and link.
Additional project tasks
To avoid loosing your Debugging configuration settings
(e.g. by running the $(RisenSDK)/source/clean.cmd batch)
create a $(ProjectFileName).user (reload project if opened).
Template for the generic user file (Script_Sample.vcproj.user):
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="8.00"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="..\..\..\bin\Risen.exe"
DebuggerType="0"
WorkingDirectory="..\..\..\bin"
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="..\..\..\bin\Risen.exe"
DebuggerType="0"
WorkingDirectory="..\..\..\bin"
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>
Published binaries should include (at least) a version information resource.
(script extension users should be able to easily determine author and version)
Template for the resource file (Script_Sample.rc):
LANGUAGE 0x00, 0x00
#pragma code_page( 1252 )

1 VERSIONINFO
FILEVERSION 0, 0, 0, 0
PRODUCTVERSION 1, 0, 95642, 0
FILEOS 0x00000004
FILETYPE 0x00000002
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "CompanyName", "Anonymous"
VALUE "FileDescription", "Risen Script Sample"
VALUE "FileVersion", "0.0"
VALUE "LegalCopyright", "© Anonymous <me@localhost>"
VALUE "InternalName", "Script_Sample"
VALUE "ProductName", "Risen"
VALUE "ProductVersion", "1.0.95642 (Rev. 0)"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0000 0x04B0
END
END

The tutorial (with template files) can be downloaded in HTML format: script_sample.7z (http://upload.worldofplayers.de/files7/script_sample.7z)

Kuchenschlachter
06.10.2011, 17:07
thanks, this helps a lot for us Visual C++ layman.

NicoDE
06.10.2011, 18:08
A "Hello world" console command for testing purposes:
GEInt GE_STDCALL CON_hello( gCScriptProcessingUnit *, GELPVoid, GELPVoid, GEInt a_iIntParameter )
{
gSConScriptArgs & ConArgs = *reinterpret_cast< gSConScriptArgs * >( a_iIntParameter );
switch( ConArgs.m_enumEvent )
{
case gEConScriptEvent_Help:
ConArgs.m_strResult = L"This comand does not require any parameters.";
return GETrue;

case gEConScriptEvent_Complete:
if( ConArgs.m_arrParams.IsEmpty() )
ConArgs.m_arrParams.Add( L"help" );
else
ConArgs.m_arrParams[ 0 ] = L"help";
return GETrue;

case gEConScriptEvent_Execute:
if( (1 == ConArgs.m_arrParams.GetCount()) && (42 == ConArgs.m_arrParams[ 0 ].GetInteger()) )
ConArgs.m_strResult = L"What was the question?";
else
ConArgs.m_strResult = L"Hello, World!";
return GETrue;

default:
ConArgs.m_strResult = L"Unsupported console event.";
return GEFalse;
}
}Don't forget to register it in your ScriptInit:
g_ScriptInit.m_arrScripts.Add( gSScriptInitScript( "CON_hello", __FILE__, CON_hello ) );Note: CON_Xxx is the internal naming convention for console commands.

hasnogaems
22.02.2022, 14:00
Can you give some mods examples that uses c/c++ scripts?

George
22.02.2022, 17:33
Can you give some mods examples that uses c/c++ scripts?
Here you can find the scripts that were developed by Baltram and Kuchenschlachter:
https://svn.nicode.net/risensdk/branches/baltram/source/Scripts/
https://svn.nicode.net/risensdk/branches/kusch/source/Scripts/