-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Project-Hatchet/main-legacy
Update main with the code currently on the steam stable build
- Loading branch information
Showing
69 changed files
with
1,809 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
from SCons.Script import * | ||
|
||
import os.path | ||
import glob | ||
import winreg | ||
import urllib.request | ||
import os | ||
import zipfile | ||
import json | ||
import subprocess | ||
|
||
env = Environment(tools=[]) | ||
|
||
# Utility functions | ||
|
||
def allFilesIn(path): | ||
return [s.replace("$", "$$") for s in glob.glob(path + '/**/*', recursive=True) if os.path.isfile(s)] | ||
|
||
def getSettings(): | ||
with open("build.json") as file: | ||
return json.load(file) | ||
|
||
def targetDefinition(target, description): | ||
return env.Help(f"\n{target.ljust(20)}\t - {description}") | ||
|
||
def isJunction(path): | ||
process = subprocess.run(["fsutil", "reparsepoint", "query", path], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | ||
return process.returncode == 0 | ||
|
||
# Useful paths | ||
def a3toolsPath(): | ||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"SOFTWARE\Bohemia Interactive\Arma 3 Tools") as key: | ||
return winreg.QueryValueEx(key, "path")[0] | ||
|
||
def arma3Path(): | ||
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) | ||
with winreg.OpenKey(reg, r"SOFTWARE\Wow6432Node\bohemia interactive\arma 3") as key: | ||
return winreg.EnumValue(key,1)[1] | ||
|
||
def addonBuilderPath(): | ||
return os.path.join(a3toolsPath(), "AddonBuilder", "AddonBuilder.exe") | ||
|
||
class Object(object): | ||
pass | ||
|
||
def getPboInfo(settings): | ||
def addInfo(name): | ||
pboInfo = Object() | ||
pboInfo.name = name | ||
pboInfo.folder = os.path.join(settings["addonsFolder"], name) | ||
pboInfo.outputPath = pboInfo.folder + ".pbo" | ||
with open(os.path.join(pboInfo.folder,"$PBOPREFIX$"), "r") as file: | ||
pboInfo.pboPrefix = file.readline().strip() | ||
try: | ||
pboInfo.a3symlink = os.path.join(arma3Path(),pboInfo.pboPrefix) | ||
except: | ||
pboInfo.a3symlink = None | ||
|
||
if (name in settings["excludePboSymlinks"]): | ||
pboInfo.a3symlink = None | ||
return pboInfo | ||
return list(map(addInfo,filter(lambda x: os.path.isdir(os.path.join(settings["addonsFolder"], x)), os.listdir(settings["addonsFolder"])))) | ||
|
||
# Build target functions | ||
def commandsToRemoveSymlink(pbo): | ||
if pbo.a3symlink is None: | ||
return [] | ||
commands = [] | ||
if isJunction(pbo.a3symlink): | ||
commands.append(f'fsutil reparsepoint delete \"{pbo.a3symlink}\"') | ||
if os.path.isdir(pbo.a3symlink): | ||
commands.append(Delete(pbo.a3symlink)) | ||
return commands | ||
|
||
def commandsToCreateSymlink(pbo): | ||
if pbo.a3symlink is None: | ||
return [] | ||
commands = commandsToRemoveSymlink(pbo) | ||
if not os.path.isdir(os.path.dirname(pbo.a3symlink)): | ||
commands.append(Mkdir(os.path.dirname(pbo.a3symlink))) | ||
commands.append(f'mklink /J "{pbo.a3symlink}" "{pbo.folder}"') | ||
return commands | ||
|
||
def buildPbo(settings,env, pbo): | ||
env.Command(pbo.outputPath, allFilesIn(pbo.folder), | ||
f'"{addonBuilderPath()}" "{os.path.abspath(pbo.folder)}" "{os.path.abspath(settings["addonsFolder"])}" -clear -include=buildExtIncludes.txt') | ||
targetDefinition(pbo.name, f"Build the {pbo.name} pbo.") | ||
return env.Alias(pbo.name, pbo.outputPath) | ||
|
||
def downloadNaturaldocs(target, source, env): | ||
url = "https://www.naturaldocs.org/download/natural_docs/2.1.1/Natural_Docs_2.1.1.zip" | ||
zipFilePath = r"buildTools\NaturalDocs.zip" | ||
urllib.request.urlretrieve(url, zipFilePath) | ||
with zipfile.ZipFile(zipFilePath, 'r') as zip_ref: | ||
zip_ref.extractall(r"buildTools") | ||
|
||
settings = getSettings() | ||
pbos = getPboInfo(settings) | ||
|
||
pboAliases = [buildPbo(settings,env, pbo) for pbo in pbos] | ||
|
||
env.Command("buildTools", [], Mkdir("buildTools")) | ||
|
||
env.Command(r"buildTools\Natural Docs", [], [downloadNaturaldocs, Delete(r"buildTools\NaturalDocs.zip")]) | ||
|
||
allPbos = env.Alias("all", pboAliases) | ||
targetDefinition("all", "Build all pbos.") | ||
|
||
buildDocs = env.Command(r"docs\index.html", | ||
[s for s in allFilesIn(settings["addonsFolder"]) if s.endswith(".sqf")] + [r"buildTools\Natural Docs"], | ||
[Mkdir("docs"), r'"buildTools\Natural Docs\NaturalDocs.exe" naturaldocs']) | ||
env.AlwaysBuild(buildDocs) | ||
|
||
env.Alias("docs", r"docs\index.html") | ||
targetDefinition("docs", "Generate naturaldocs documentation") | ||
env.Help("\n") | ||
|
||
env.Clean(["buildTools", "all"], r"buildTools") | ||
env.Clean(["docs", "all"], ["docs", r"naturaldocs\Working Data"]) | ||
|
||
try: | ||
settings = getSettings() | ||
a3dir = arma3Path() | ||
symlinks = env.Alias("symlinks", [], sum(map(commandsToCreateSymlink, pbos),[])) | ||
env.AlwaysBuild(symlinks) | ||
|
||
removeSymlinks = env.Alias("rmsymlinks", [], sum(map(commandsToRemoveSymlink, pbos),[])) | ||
env.AlwaysBuild(removeSymlinks) | ||
except Exception as e: | ||
print(e) | ||
print("Error: Couldn't find arma 3, cannot make or remove symlinks") | ||
|
||
env.Default("all") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
z/htf/hatchet_vxf_core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CfgPatches { | ||
class vxf_core { | ||
name = "Vortex Vehicle Framework"; | ||
author = "Vortex Vehicles"; | ||
units[] = {}; | ||
weapons[] = {}; | ||
requiredVersion = 1.0; | ||
requiredAddons[] = {}; | ||
}; | ||
}; | ||
|
||
#include "config\cfgFunctions.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// #include "\vxf_core\includes\configMacros.hpp" | ||
|
||
class cfgFunctions { | ||
class vxf_core { | ||
class functions { | ||
//startup | ||
class init { | ||
postInit = 1; | ||
file = "hatchet_vxf_core\functions\init.sqf"; | ||
}; | ||
class getVehicleConfig { | ||
file = "hatchet_vxf_core\functions\getVehicleConfig.sqf"; | ||
}; | ||
class startLoops { | ||
file = "hatchet_vxf_core\functions\startLoops.sqf"; | ||
}; | ||
|
||
//events | ||
class vehicleChanged { | ||
file = "hatchet_vxf_core\functions\events\vehicleChanged.sqf"; | ||
}; | ||
class perFrame { | ||
file = "hatchet_vxf_core\functions\events\perFrame.sqf"; | ||
}; | ||
class perSecond { | ||
file = "hatchet_vxf_core\functions\events\perSecond.sqf"; | ||
}; | ||
|
||
//module handling | ||
class load { | ||
file = "hatchet_vxf_core\functions\modules\load.sqf"; | ||
}; | ||
class loadAll { | ||
file = "hatchet_vxf_core\functions\modules\loadAll.sqf"; | ||
}; | ||
class start { | ||
file = "hatchet_vxf_core\functions\modules\start.sqf"; | ||
}; | ||
class hasModule { | ||
file = "hatchet_vxf_core\functions\modules\hasModule.sqf"; | ||
}; | ||
class shutDownAll { | ||
file = "hatchet_vxf_core\functions\modules\shutDownAll.sqf"; | ||
}; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* vxf_core_fnc_perFrame | ||
* | ||
* Function will run relevante modules' per frame functions | ||
* | ||
* Params: array[array[(object) vehicle, (scalar) last frame time], (scalar)pfhId] | ||
* Returns: nothing | ||
* | ||
* Author: Yax | ||
*/ | ||
params ["_args", "_pfhId"]; | ||
_args params ["_vehicle", "_lastFrameTime"]; | ||
|
||
//shutdown conditions | ||
if ( | ||
(vehicle player != _vehicle) || | ||
(!alive player) || | ||
(!alive _vehicle) | ||
) exitWith { | ||
[vxf_vehicle] call vxf_core_fnc_shutDownAll; | ||
[_pfhId] call CBA_fnc_removePerFrameHandler; | ||
vxf_perFrameHandler = nil; | ||
if (!isNil {vxf_drawHandler}) then { | ||
removeMissionEventHandler ["Draw3d",vxf_drawHandler]; | ||
vxf_drawHandler = nil; | ||
}; | ||
}; | ||
|
||
if (cba_missionTime == _lastFrameTime) exitWith {vxf_paused = true;}; | ||
_args set [1, cba_missionTime]; | ||
if (vxf_paused) then { | ||
// unpause | ||
["vxf_unPause", []] call CBA_fnc_localEvent; | ||
}; | ||
vxf_paused = false; | ||
|
||
//frame time will be passed on to modules | ||
private _frameTime = (cba_missionTime - _lastFrameTime); | ||
//skip a frame when unpausing so time between frames stays normal | ||
if (_frameTime > 1) exitWith {}; | ||
|
||
private ["_func"]; | ||
{ //forEach vehicle vxf_modules | ||
if (_x # 1) then { | ||
_func = missionNameSpace getVariable (_x # 3); | ||
if (!isNil {_func}) then {[_vehicle, _frameTime] call _func;}; | ||
}; | ||
} forEach (_vehicle getVariable ["vxf_modules", []]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* vxf_core_fnc_perSecond | ||
* | ||
* Function will run relevante modules' per second functions | ||
* | ||
* Params: array[array[(object) vehicle], (scalar)pfhId] | ||
* Returns: nothing | ||
* | ||
* Author: Yax | ||
*/ | ||
params ["_args", "_pfhId"]; | ||
_args params ["_vehicle"]; | ||
|
||
//shutdown conditions | ||
if ( | ||
(vehicle player != _vehicle) || | ||
(!alive player) || | ||
(!alive _vehicle) | ||
) exitWith { | ||
[_pfhId] call CBA_fnc_removePerFrameHandler; | ||
vxf_perSecondHandler = nil; | ||
}; | ||
|
||
if (vxf_paused) exitWith {}; | ||
|
||
private _modules = (_vehicle getVariable ["vxf_modules", []]); | ||
[_vehicle, _modules] spawn { | ||
params ["_vehicle", "_modules"]; | ||
private _moduleDelay = 1 / ((count _modules) + 1); | ||
private ["_func"]; | ||
{ //forEach vehicle vxf_modules | ||
sleep _moduleDelay; | ||
if (_x # 1) then { | ||
_func = missionNameSpace getVariable (_x # 4); | ||
if (!isNil {_func}) then {[_vehicle] call _func;}; | ||
}; | ||
} forEach _modules; | ||
}; |
33 changes: 33 additions & 0 deletions
33
addons/hatchet_vxf_core/functions/events/vehicleChanged.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* vxf_core_fnc_vehicleChanged | ||
* | ||
* Function is triggered by cba vehicleChanged eventhandler | ||
* when called, it will check if the vehicle has any vxf config, | ||
* and if relevant, set up the functions for it | ||
* | ||
* Params: Array[(object) caller, (object) newVehicle] | ||
* Returns: nil | ||
* | ||
* Author: Yax | ||
*/ | ||
|
||
params ["_caller", "_newVehicle"]; | ||
|
||
if (isNil "_caller" || isNil "_newVehicle") exitWith {}; | ||
if (_caller !=player) exitWith {}; | ||
if (!(isNil "vxf_vehicle")) then {[vxf_vehicle] call vxf_core_fnc_shutDownAll;}; | ||
|
||
private _isVxfSetup = [_newVehicle] call vxf_core_fnc_getVehicleConfig; | ||
|
||
//end the function if the vehicle isn't compatible | ||
if (!_isVxfSetup) exitWith { | ||
_newVehicle setVariable ["vxf_modules", nil]; | ||
}; | ||
|
||
[_newVehicle] call vxf_core_fnc_loadAll; | ||
[_newVehicle] call vxf_core_fnc_startLoops; | ||
vxf_vehicle = _newVehicle; | ||
|
||
vxf_interaction_vehicleSwitchedEH = _newVehicle addEventHandler ["SeatSwitched", { | ||
if (_this # 1 == player) then {[player, vehicle player] call vxf_core_fnc_vehicleChanged;}; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* vxf_core_fnc_getVehicleConfig | ||
* | ||
* Function will look through the cfgVehicles for the vehicle | ||
* and look for relevant vxf config subclasses, when it finds them | ||
* the most relevant one will be assigned to the vehicle's vxf_config variable | ||
* | ||
* Params: (object) vehicle | ||
* Returns: (bool) success | ||
* | ||
* Author: Yax | ||
*/ | ||
|
||
params ["_vehicle"]; | ||
|
||
private _configFound = false; | ||
private _configSources = []; | ||
|
||
_vehicle setVariable ["vxf_config", nil]; | ||
private _turretIndex = [player] call ace_common_fnc_getTurretIndex; | ||
|
||
if(player == driver _vehicle) then { | ||
_configSources pushBack "vxf_driver"; | ||
}; | ||
|
||
private _copilotTurretIndex = [_vehicle] call ace_common_fnc_getTurretCopilot; | ||
if((count _copilotTurretIndex) > 0 && (count _turretIndex) > 0 && {(_turretIndex # 0) == (_copilotTurretIndex # 0)}) then { | ||
_configSources pushBack "vxf_copilot"; | ||
}; | ||
|
||
if(count _turretIndex > 0) then { | ||
_configSources pushBack format["vxf_turret_%1",(_turretIndex # 0)]; | ||
}; | ||
|
||
if(player == gunner _vehicle) then { | ||
_configSources pushBack "vxf_gunner"; | ||
}; | ||
|
||
if(_vehicle getCargoIndex player > -1) then { | ||
_configSources pushBack "vxf_cargo"; | ||
}; | ||
|
||
_configSources pushBack "vxf"; | ||
|
||
{ | ||
private _config = (configFile >> "cfgVehicles" >> (typeOf _vehicle) >> _x); | ||
if(isClass _config) exitWith { | ||
_configFound = true; | ||
//if there was already a config present, a seat change happened, so do a shutdown of old systems | ||
//if (!isNil {_vehicle getVariable "vxf_config"}) then { | ||
// [_vehicle] call vxf_core_fnc_shutDown; | ||
//}; | ||
_vehicle setVariable ["vxf_config", _config]; | ||
_vehicle setVariable ["vxf_projectPrefix", getText (_config >> "projectPrefix")]; | ||
}; | ||
}forEach _configSources; | ||
|
||
_configFound |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
["vehicle", vxf_core_fnc_vehicleChanged, true] call CBA_fnc_addPlayerEventHandler; | ||
vxf_paused = false; |
Oops, something went wrong.