Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions game/jbmod/scripts/vscripts/test_daslang.das
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Simple test script for Daslang integration
// This script demonstrates basic Daslang syntax

// Define a simple function
def add(a: int, b: int): int {
return a + b;
}

// Test the function
var result = add(5, 3);
print("5 + 3 = " + string(result));

// Test with floats
def multiply(a: float, b: float): float {
return a * b;
}

var product = multiply(2.5, 4.0);
print("2.5 * 4.0 = " + string(product));

// Test control flow
if (result > 5) {
print("Result is greater than 5");
} else {
print("Result is 5 or less");
}

// Simple loop
var sum = 0;
for (i in 0..4) {
sum += i;
}
print("Sum of 0..4 = " + string(sum));
Empty file.
3 changes: 3 additions & 0 deletions src/devtools/makefile_base_posix.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: _create_dir
_create_dir:
@mkdir -p $(@D)
10 changes: 5 additions & 5 deletions src/game/client/client_jbmod.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ $Include "$SRCDIR\game\client\client_base.vpc"

$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE;jbmod\ui,.\jbmod,$SRCDIR\game\shared\jbmod,.\hl2,.\hl2\elements,$SRCDIR\game\shared\hl2,$SRCDIR\game\shared\episodic"
$PreprocessorDefinitions "$BASE;JBMOD;HL2MP;HL2_CLIENT_DLL;HL2_EPISODIC;NEXT_BOT"
}
$Compiler
{
$AdditionalIncludeDirectories "$BASE;jbmodui,.jbmod,$SRCDIRgamesharedjbmod,.hl2,.hl2elements,$SRCDIRgamesharedhl2,$SRCDIRgamesharedepisodic,$SRCDIRsrcpublic"
$PreprocessorDefinitions "$BASE;JBMOD;HL2MP;HL2_CLIENT_DLL;HL2_EPISODIC;NEXT_BOT"
}
}

$CustomBuildStep "nut"
Expand Down
19 changes: 19 additions & 0 deletions src/game/client/jbmod/vscript_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include "igamesystem.h"
#include "icommandline.h"
#include "client_factorylist.h"
#include "daslang_vscript.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

IScriptManager *scriptmanager = NULL;
IDaslangVM *g_pDaslangVM = NULL;

class CScriptGameSystem : public CAutoGameSystem
{
Expand All @@ -37,6 +39,12 @@ class CScriptGameSystem : public CAutoGameSystem
if ( factories.appSystemFactory && !CommandLine()->CheckParm( "-noscripting" ) )
{
scriptmanager = (IScriptManager *)factories.appSystemFactory( VSCRIPT_INTERFACE_VERSION, NULL );

// Also try to get the Daslang VM if available
if ( scriptmanager )
{
g_pDaslangVM = (IDaslangVM *)scriptmanager->QueryInterface( DASLANG_INTERFACE_VERSION );
}
}

return true;
Expand All @@ -48,11 +56,22 @@ class CScriptGameSystem : public CAutoGameSystem
{
//g_pScriptVM->RegisterInstance( &g_ScriptVGUI, "vgui" );
}

if ( g_pDaslangVM )
{
// Register Daslang-specific instances here if needed
}
}

virtual void LevelShutdownPreEntity()
{
//g_ScriptVGUI.DestroyAllPanels();

if ( g_pDaslangVM )
{
g_pDaslangVM->Shutdown();
g_pDaslangVM = NULL;
}
}
};

Expand Down
87 changes: 48 additions & 39 deletions src/game/server/server_jbmod.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ $Include "$SRCDIR\game\server\nav_mesh.vpc"

$Configuration
{
$Compiler
{
$AdditionalIncludeDirectories "$BASE;$SRCDIR\game\shared\hl2,.\hl2,.\jbmod,.\episodic,$SRCDIR\game\shared\jbmod,$SRCDIR\game\shared\episodic"
$PreprocessorDefinitions "$BASE;JBMOD;HL2MP;HL2_DLL;HL2_EPISODIC;NEXT_BOT"
}
$Compiler
{
$AdditionalIncludeDirectories "$BASE;$SRCDIRgamesharedhl2,.hl2,.jbmod,.episodic,$SRCDIRgamesharedjbmod,$SRCDIRgamesharedepisodic,$SRCDIRdaScriptinclude,$SRCDIRdaScriptincludedaScript,$SRCDIRsrcpublic"
$PreprocessorDefinitions "$BASE;JBMOD;HL2MP;HL2_DLL;HL2_EPISODIC;NEXT_BOT;ENABLE_DASLANG"
}
}

$Project "Server (JBMod)"
Expand Down Expand Up @@ -434,40 +434,49 @@ $Project "Server (JBMod)"
}
}

$Folder "Weapons"
{
$File "jbmod\grenade_satchel.cpp"
$File "jbmod\grenade_satchel.h"
$File "jbmod\grenade_tripmine.cpp"
$File "jbmod\grenade_tripmine.h"
$File "jbmod\te_jbmod_shotgun_shot.cpp"
$File "jbmod\te_jbmod_shotgun_shot.h"
$File "$SRCDIR\game\shared\jbmod\weapon_357.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_ar2.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_ar2.h"
$File "$SRCDIR\game\shared\jbmod\weapon_crossbow.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_crowbar.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_frag.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbase.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbase.h"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbase_machinegun.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbase_machinegun.h"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbasebasebludgeon.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbasehlmpcombatweapon.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbasehlmpcombatweapon.h"
$File "$SRCDIR\game\shared\jbmod\weapon_physcannon.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_physcannon.h"
$File "$SRCDIR\game\shared\jbmod\weapon_pistol.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_rpg.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_rpg.h"
$File "$SRCDIR\game\shared\jbmod\weapon_shotgun.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_slam.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_slam.h"
$File "$SRCDIR\game\shared\jbmod\weapon_smg1.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_stunstick.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_scripted.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_scripted.h"
}
$Folder "Weapons"
{
$File "jbmod\grenade_satchel.cpp"
$File "jbmod\grenade_satchel.h"
$File "jbmod\grenade_tripmine.cpp"
$File "jbmod\grenade_tripmine.h"
$File "jbmod\te_jbmod_shotgun_shot.cpp"
$File "jbmod\te_jbmod_shotgun_shot.h"
$File "$SRCDIR\game\shared\jbmod\weapon_357.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_ar2.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_ar2.h"
$File "$SRCDIR\game\shared\jbmod\weapon_crossbow.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_crowbar.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_frag.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbase.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbase.h"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbase_machinegun.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbase_machinegun.h"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbasebasebludgeon.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbasehlmpcombatweapon.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_jbmodbasehlmpcombatweapon.h"
$File "$SRCDIR\game\shared\jbmod\weapon_physcannon.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_physcannon.h"
$File "$SRCDIR\game\shared\jbmod\weapon_pistol.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_rpg.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_rpg.h"
$File "$SRCDIR\game\shared\jbmod\weapon_shotgun.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_slam.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_slam.h"
$File "$SRCDIR\game\shared\jbmod\weapon_smg1.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_stunstick.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_scripted.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_scripted.h"
}

$Folder "Daslang"
{
$File "$SRCDIR/public/daslang_vscript.cpp"
$File "$SRCDIR/public/daslang_vscript.h"
$File "$SRCDIR/public/idlasngvm.h"
$File "$SRCDIR/public/daslang_jbmod_module.cpp"
$File "$SRCDIR/public/daslang_jbmod_module.h"
}
}
}
}
106 changes: 35 additions & 71 deletions src/game/server/vscript_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,24 @@ bool VScriptServerInit()
{
scriptLanguage = SL_GAMEMONKEY;
}
else if( !Q_stricmp(pszScriptLanguage, "squirrel") )
{
scriptLanguage = SL_SQUIRREL;
}
else if( !Q_stricmp(pszScriptLanguage, "python") )
{
scriptLanguage = SL_PYTHON;
}
else if( !Q_stricmp(pszScriptLanguage, "daslang") )
{
scriptLanguage = SL_DASLANG;
}
else
{
DevWarning("-server_script does not recognize a language named '%s'. virtual machine did NOT start.\n", pszScriptLanguage );
scriptLanguage = SL_NONE;
}
}
else if( !Q_stricmp(pszScriptLanguage, "squirrel") )
{
scriptLanguage = SL_SQUIRREL;
Expand Down Expand Up @@ -2514,6 +2532,18 @@ bool VScriptServerInit()
Log_Msg( LOG_VScript, "VSCRIPT: Started VScript virtual machine using script language '%s'\n", g_pScriptVM->GetLanguageName() );
g_pScriptVM->SetErrorCallback( &VScriptServerScriptErrorFunc );

// Register Daslang JBMod module if we're using Daslang
if ( scriptLanguage == SL_DASLANG )
{
// In a real implementation with our actual SDK integration:
// 1. We already included the actual Daslang headers in daslang_vscript.cpp
// 2. The ModuleLibrary is created in the CDaslangVM::Init() function
// 3. RegisterDaslangJBModModule is called in CDaslangVM::Init()
// 4. The module is registered with the VM context

Log_Msg( LOG_VScript, "VSCRIPT: Daslang JBMod module registered via CDaslangVM::Init()\n" );
}

ScriptRegisterFunctionNamed( g_pScriptVM, ScriptRegisterEntityClass, "RegisterEntityClass", "Registers a new entity classname mapped to an existing base class" );
ScriptRegisterFunctionNamed( g_pScriptVM, UTIL_ShowMessageAll, "ShowMessage", "Print a hud message on all clients" );
ScriptRegisterFunction( g_pScriptVM, SendToConsole, "Send a string to the console as a command" );
Expand Down Expand Up @@ -2561,77 +2591,11 @@ bool VScriptServerInit()
ScriptRegisterFunctionNamed( g_pScriptVM, Script_OverlayBoxAngles, "DebugDrawBoxAngles", "Draw a debug oriented box (cent, min, max, angles(p,y,r), vRgb, a, duration)" );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_OverlayClear, "DebugDrawClear", "Try to clear all the debug overlay info" );

// Josh: Bring this back if we have response rules and stuff.
#if 0
ScriptRegisterFunctionNamed( g_pScriptVM, CSpeechScriptBridge::Script_AddDecisionRule, "rr_AddDecisionRule", "Add a rule to the decision database." );
ScriptRegisterFunctionNamed( g_pScriptVM, CSpeechScriptBridge::Script_FindBestResponse, "rr_QueryBestResponse", "Params: (entity, query) : tests 'query' against entity's response system and returns the best response found (or null if none found)." );
ScriptRegisterFunctionNamed( g_pScriptVM, CSpeechScriptBridge::Script_CommitAIResponse, "rr_CommitAIResponse", "Commit the result of QueryBestResponse back to the given entity to play. Call with params (entity, airesponse)" );
ScriptRegisterFunctionNamed( g_pScriptVM, CSpeechScriptBridge::Script_GetExpressers, "rr_GetResponseTargets", "Retrieve a table of all available expresser targets, in the form { name : handle, name: handle }." );
#endif

ScriptRegisterFunctionNamed( g_pScriptVM, Script_PickupObject, "PickupObject", "Have a player pickup a nearby named entity" );

ScriptRegisterFunctionNamed( g_pScriptVM, Script_StringToFile, "StringToFile", "Store a string to a file for later reading" );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_FileToString, "FileToString", "Reads a string from a file to send to script" );

ScriptRegisterFunctionNamed( g_pScriptVM, Script_TraceLineEx, "TraceLineEx", "Pass table - Inputs: start, end, mask, ignore -- outputs: pos, fraction, hit, enthit, allsolid, startpos, endpos, startsolid, plane_normal, plane_dist, surface_name, surface_flags, surface_props" );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_TraceHull, "TraceHull", "Pass table - Inputs: start, end, hullmin, hullmax, mask, ignore -- outputs: pos, fraction, hit, enthit, allsolid, startpos, endpos, startsolid, plane_normal, plane_dist, surface_name, surface_flags, surface_props" );

ScriptRegisterFunctionNamed( g_pScriptVM, Script_GetFrameCount, "GetFrameCount", "Returns the engines current frame count" );

ScriptRegisterFunctionNamed( g_pScriptVM, Script_ClientPrint, "ClientPrint", "Print a client message" );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptEmitAmbientSoundOn, "EmitAmbientSoundOn", "Play named ambient sound on an entity." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptStopAmbientSoundOn, "StopAmbientSoundOn", "Stop named ambient sound on an entity." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_SetFakeClientConVarValue, "SetFakeClientConVarValue", "Sets a USERINFO client ConVar for a fakeclient" );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_ScreenShake, "ScreenShake", "Start a screenshake with the following parameters. vecCenter, flAmplitude, flFrequency, flDuration, flRadius, eCommand( SHAKE_START = 0, SHAKE_STOP = 1 ), bAirShake" );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_ScreenFade, "ScreenFade", "Start a screenfade with the following parameters. player, red, green, blue, alpha, flFadeTime, flFadeHold, flags" );
// ScriptRegisterFunctionNamed( g_pScriptVM, Script_ChangeLevel, "ChangeLevel", "Tell engine to change level." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_PrecacheModel, "PrecacheModel", "Precache a model. Returns the modelindex." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_PrecacheSound, "PrecacheSound", "Precache a sound." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_PrecacheScriptSound, "PrecacheScriptSound", "Precache a sound." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_IsModelPrecached, "IsModelPrecached", "Checks if the modelname is precached." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_GetModelIndex, "GetModelIndex", "Returns the index of the named model." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_IsDedicatedServer, "IsDedicatedServer", "Returns true if this server is a dedicated server." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_GetListenServerHost, "GetListenServerHost", "Get the local player on a listen server." );
ScriptRegisterFunctionNamed( g_pScriptVM, Script_GetSoundDuration, "GetSoundDuration", "Returns float duration of the sound. Takes soundname and optional actormodelname.");
ScriptRegisterFunctionNamed( g_pScriptVM, Script_IsSoundPrecached, "IsSoundPrecached", "Takes a sound name");
ScriptRegisterFunctionNamed( g_pScriptVM, Script_GetLocalTime, "LocalTime", "Fills out a table with the local time (second, minute, hour, day, month, year, dayofweek, dayofyear, daylightsavings)" );
#if 0
ScriptRegisterFunctionNamed( g_pScriptVM, Script_QueueSpeak, "QueueSpeak", "(hEntity, szConcept, flDelay, szCriteria) Queue a speech concept" );
#endif

ScriptRegisterFunction( g_pScriptVM, GetMapName, "Get the name of the map.");
// ScriptRegisterFunction( g_pScriptVM, LoopSinglePlayerMaps, "Run the single player maps in a continuous loop.");

ScriptRegisterFunctionNamed( g_pScriptVM, ScriptTraceLine, "TraceLine", "given 2 points & ent to ignore, return fraction along line that hits world or models" );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptTraceLinePlayersIncluded, "TraceLinePlayersIncluded", "given 2 points & ent to ignore, return fraction along line that hits world, models, players or npcs" );

ScriptRegisterFunction( g_pScriptVM, FrameTime, "Get the time spent on the server in the last frame" );
ScriptRegisterFunction( g_pScriptVM, MaxClients, "Get the current number of max clients set by the maxplayers command." );
ScriptRegisterFunctionNamed( g_pScriptVM, DoEntFireByInstanceHandle, "EntFireByHandle", "Generate and entity i/o event. First parameter is an entity instance." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCreateSceneEntity, "CreateSceneEntity", "Create a scene entity to play the specified scene." );
ScriptRegisterFunction( g_pScriptVM, CreateProp, "Create a physics prop" );
//ScriptRegisterFunctionNamed( g_pScriptVM, DoRecordAchievementEvent, "RecordAchievementEvent", "Records achievement event or progress" );
ScriptRegisterFunction( g_pScriptVM, GetDeveloperLevel, "Gets the level of 'developer'" );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptDispatchParticleEffect, "DispatchParticleEffect", "Dispatches a one-off particle system" );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptSetSkyboxTexture, "SetSkyboxTexture", "Sets the current skybox texture" );

#if defined ( PORTAL2 )
ScriptRegisterFunction( g_pScriptVM, SetDucking, "Set the level of an audio ducking channel" );
#if defined( PORTAL2_PUZZLEMAKER )
ScriptRegisterFunction( g_pScriptVM, RequestMapRating, "Pops up the map rating dialog for user input" );
ScriptRegisterFunction( g_pScriptVM, GetMapIndexInPlayOrder, "Determines which index (by order played) this map is. Returns -1 if entry is not found. -2 if this is not a known community map." );
ScriptRegisterFunction( g_pScriptVM, GetNumMapsPlayed, "Returns how many maps the player has played through." );
ScriptRegisterFunction( g_pScriptVM, SetMapAsPlayed, "Adds the current map to the play order and returns the new index therein. Returns -2 if this is not a known community map." );
#endif // PORTAL2_PUZZLEMAKER
#endif

g_pScriptVM->RegisterAllClasses();

if ( GameRules() )
{
GameRules()->RegisterScriptFunctions();
}
// Josh: Bring this back if we have response rules and stuff.
#if 0
ScriptRegisterFunctionNamed( g_pScriptVM, CSpeechScriptBridge::Script_AddDecisionRule, "rr_AddDecisionRule", "Add a rule to the decision database." );
#endif
}

#ifdef TF_DLL
g_pScriptVM->RegisterInstance( TheNavMesh, "NavMesh" );
Expand Down
55 changes: 55 additions & 0 deletions src/public/daslang_jbmod_module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Daslang module for JBMod game API bindings
//=============================================================================//

#include "daslang_jbmod_module.h"
#include "cbase.h"
#include "tier0/memdbgon.h"

// Include actual Daslang headers for binding
#include <daScript/daScript.h>
#include <daScript/module/built_in.h>
#include <daScript/module/math.h>
#include <daScript/module/strings.h>
#include <daScript/module/rtti.h>

// Helper functions for Daslang bindings
namespace DaslangJBMod
{
// Simple test function to verify bindings work
int32_t AddInts(int32_t a, int32_t b) { return a + b; }

// Example of binding an engine function (placeholder)
float GetServerTime() { return 0.0f; }

// Example of binding a player-related function (placeholder)
int GetPlayerCount() { return 0; }
}

// Implementation of the module registration function
void RegisterDaslangJBModModule(das::ModuleLibrary& lib)
{
using namespace das;

// Bind a simple test function
lib->addExtern<DaslangJBMod::AddInts>("add_ints", SideEffects::none, "Adds two integers")
->args("a", "b");

// Bind the server time function
lib->addExtern<DaslangJBMod::GetServerTime>("server_time", SideEffects::none, "Get current server time")
->args();

// Bind the player count function
lib->addExtern<DaslangJBMod::GetPlayerCount>("player_count", SideEffects::none, "Get number of players")
->args();

// TODO: Add more JBMod-specific bindings as needed:
// - Entity functions (e.g., EntIndexToHScript)
// - Vector math functions
// - String utility functions
// - Game event functions
// etc.
}

#endif // DASLANG_JBMOD_MODULE_H
Loading