Skip to content

Commit f05dabd

Browse files
committed
Adding support for other mods to add their own ESE Aliases using #ifdef ESE_INSTALLED
1 parent cdc3aef commit f05dabd

File tree

9 files changed

+93
-15
lines changed

9 files changed

+93
-15
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
# Enforce-Script-Extensions
2-
A collection of new types and methods for Arma Reforger to help streamline the scripting experience
2+
A collection of new data types, methods, aliases etc. for Arma Reforger to help streamline the scripting experience.
3+
# Installation
4+
ESE will be released on the workshop at a date TBA. If you want to use it now however, clone this repo and add it as an existing project in the enfusion workbench, BUT BE CAREFUL! Things are changing a lot still, and using these pre-release versions may cause compatibility issues when it releases. I would hightly recommend renaming all the files and classes to "OLD_ESE..." so they remain seperate from release versions.
5+
# Contributing & Suggestions
6+
If you have any code you'd like me to add, or more vague suggestions for functionality to add, feel free to create a discussion and let me know!

addon.gproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,25 @@ GameProject {
55
Dependencies {
66
"58D0FB3206B6F859" "5614BBCCBB55ED1C"
77
}
8+
Configurations {
9+
GameProjectConfig PC {
10+
ScriptProjectManagerSettings ScriptProjectManagerSettings "{AC4BE58770485E4B}" {
11+
Configurations {
12+
ScriptConfigurationClass workbench {
13+
Defines + {
14+
"ESE_ALIASES_ALL"
15+
}
16+
}
17+
}
18+
}
19+
}
20+
GameProjectConfig XBOX_ONE {
21+
}
22+
GameProjectConfig XBOX_SERIES {
23+
}
24+
GameProjectConfig PS4 {
25+
}
26+
GameProjectConfig HEADLESS {
27+
}
28+
}
829
}

resourceDatabase.rdb

65 Bytes
Binary file not shown.

scripts/Core/proto/ESE_Types.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ESE_array<Class T> : array<T>
2121
}
2222
str = temp;
2323
}
24-
24+
// -----------------------------------------------------------------------------------------------------------
2525
// Converts contents of array to string if array type is string, will return false if not array<string>
2626
bool ToStringTextOnly(out string str)
2727
{
@@ -36,13 +36,13 @@ class ESE_array<Class T> : array<T>
3636
str = temp;
3737
return true;
3838
}
39-
39+
// -----------------------------------------------------------------------------------------------------------
4040
// Returns data type of array
4141
typename GetType()
4242
{
4343
return T;
4444
}
45-
45+
// -----------------------------------------------------------------------------------------------------------
4646
// Casts contents of array to template type of the new array and copies the contents to it
4747
bool CastToNewArray(inout ESE_array newArray)
4848
{

scripts/Game/!ESE_Config.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Message me @narcoleptic marshmallow #1188 on discord to give feedback or go to https://github.com/NarcoMarshDev
55
// -----------------------------------------------------------------------------------------------------------
66

7+
// REMEMBER TO CHANGE THIS TO USING THE DEFINES IN THE PROJECT OPTIONS MENU OR PEOPLE WILL RIOT!!!
78

89
/** -------------------------------------------------------- READ THIS --------------------------------------------------------
910
@@ -33,16 +34,18 @@
3334
#define ESE_ALIASES_WEAPONS - All base game weapon ResourceNames
3435
#define ESE_ALIASES_ATTACHMENTS - All base game attachment ResourceNames
3536
#define ESE_ALIASES_MAGAZINES - All base game magazine ResourceNames
37+
#define ESE_ALIASES_VEHICLES - All base game vehicle ResourceNames (almost, missing some odd variats)
3638
#define ESE_ALIASES_MATH - Useful mathematical constants and such like
3739
3840
@endcode
3941
*/
42+
#define ESE_INSTALLED // Always keep this enabled to ensure mod compatiblity with aliases
4043

41-
#define ESE_VERBOSE
44+
//#define ESE_VERBOSE
4245
//#define ESE_ENABLE_WIP
4346
//#define ESE_EXPERIMENTAL
4447
//#define ESE_OBSOLETE
45-
#define ESE_ALIASES_ALL
48+
//#define ESE_ALIASES_ALL
4649
//#define ESE_ALIASES_MATERIALS
4750
//#define ESE_ALIASES_WEAPONS
4851
//#define ESE_ALIASES_ATTACHMENTS

scripts/Game/ESE.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ESE
3838
}
3939
return allChildren;
4040
}
41+
// -----------------------------------------------------------------------------------------------------------
4142
// See ESE.GetAllChildren - Returns only entities of given type
4243
static array<IEntity> GetAllChildrenByType(IEntity parent, typename childClass)
4344
{
@@ -60,6 +61,7 @@ class ESE
6061
}
6162
return allChildren;
6263
}
64+
// -----------------------------------------------------------------------------------------------------------
6365
// Deletes entity on server side
6466
static void DeleteEntity(IEntity ent)
6567
{
@@ -74,30 +76,31 @@ class ESE
7476
{
7577
return ChimeraCharacter.Cast( GetGame().GetPlayerManager().GetPlayerControlledEntity(playerId) );
7678
}
77-
79+
// -----------------------------------------------------------------------------------------------------------
7880
// Returns player controlled entity of local machine
7981
static ChimeraCharacter GetLocalPlayerEntity()
8082
{
8183
return ChimeraCharacter.Cast( GetGame().GetPlayerController().GetControlledEntity() );
8284
}
83-
85+
// -----------------------------------------------------------------------------------------------------------
8486
// Returns player id of given entity, returns 0 if not controlled by player
8587
static int GetPlayerId(IEntity ent)
8688
{
8789
return GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(ent);
8890
}
89-
91+
// -----------------------------------------------------------------------------------------------------------
9092
// Returns currently equipped weapon of given player character, returns null if weapon is holstered
9193
static BaseWeaponComponent GetCurrentWeapon(ChimeraCharacter player)
9294
{
9395
return player.GetCharacterController().GetWeaponManagerComponent().GetCurrentWeapon();
9496
}
95-
97+
// -----------------------------------------------------------------------------------------------------------
98+
// Pretty obvious
9699
static void HolsterCurrentWeapon(ChimeraCharacter player)
97100
{
98101
player.GetCharacterController().SelectWeapon(null);
99102
}
100-
103+
// -----------------------------------------------------------------------------------------------------------
101104
// Returns alive state of given entity
102105
static bool IsEntityAlive(IEntity entity)
103106
{
@@ -107,7 +110,7 @@ class ESE
107110
else
108111
return true;
109112
}
110-
113+
// -----------------------------------------------------------------------------------------------------------
111114
#ifdef ESE_ENABLE_WIP
112115
/**
113116
TODO - MAKE SURE THIS WORKS AS INTENDED ON LOCAL PLAYERS WHEN CALLED
@@ -129,6 +132,7 @@ class ESE
129132
return screenPos[2] > 0 && screenPos[0] > 0 && screenPos[0] < width && screenPos[1] > 0 && screenPos[1] < height);
130133
}
131134
#endif
135+
// -----------------------------------------------------------------------------------------------------------
132136
/**
133137
Outputs all available magazines for a given weapon and character into a MagazineComponent array
134138
@code

scripts/Game/ESE_Entities.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ESE_Entities
3939

4040
return GetGame().SpawnEntityPrefab(prefab, GetGame().GetWorld(), spawnParams);
4141
}
42+
// -----------------------------------------------------------------------------------------------------------
4243
/**
4344
Creates new entity from prefab at a players position
4445
@code
@@ -62,11 +63,13 @@ class ESE_Entities
6263

6364
return GetGame().SpawnEntityPrefab(prefab, player.GetWorld(), spawnParams);
6465
}
66+
// -----------------------------------------------------------------------------------------------------------
6567
// Deletes entity on server side
6668
static void DeleteEntity(IEntity ent)
6769
{
6870
RplComponent.DeleteRplEntity(ent, false);
6971
}
72+
// -----------------------------------------------------------------------------------------------------------
7073
static void DeleteEntityByRplId(RplId id)
7174
{
7275
IEntity ent = IEntity.Cast(Replication.FindItem(id));
@@ -100,7 +103,7 @@ class ESE_Entities
100103
child = child.GetSibling();
101104
}
102105
}
103-
106+
// -----------------------------------------------------------------------------------------------------------
104107
static void EnableCollisions(IEntity ent, int layerMask = 0xffffffff)
105108
{
106109
Physics.CreateStatic(ent, layerMask);
@@ -142,7 +145,7 @@ class ESE_Entities
142145
}
143146
}
144147
}
145-
148+
// -----------------------------------------------------------------------------------------------------------
146149
/**
147150
Restores materials of entity and optionally it's children back to its original state
148151
\param entity - entity to have materials reset
@@ -207,7 +210,7 @@ class ESE_Entities
207210
vector screenPos = workspace.ProjWorldToScreenNative(worldPos, GetGame().GetWorld());
208211
return screenPos[2] > 0 && screenPos[0] > 0 && screenPos[0] < width && screenPos[1] > 0 && screenPos[1] < height);
209212
}
210-
213+
// -----------------------------------------------------------------------------------------------------------
211214
//TODO - Not sure why it's not working but don't use it for now, may have to go back to the GetParent() -> GetAllChildren() type system
212215
static void GetAllSiblings(IEntity ent, notnull inout array<IEntity> allSiblings)
213216
{

scripts/Game/ESE_IO.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,47 @@
55
// -----------------------------------------------------------------------------------------------------------
66
class ESE_IO
77
{
8+
static int ReadFileAsArray(string path, inout array<string> arr, int length)
9+
{
10+
FileHandle f = FileIO.OpenFile(path, FileMode.READ);
11+
int readLen = f.ReadFile(arr, length);
12+
return readLen;
13+
}
14+
// -----------------------------------------------------------------------------------------------------------
15+
#ifdef ESE_ENABLE_WIP
16+
static string ReadFileAsString(string path)
17+
{
18+
// TODO
19+
}
20+
#endif
21+
// -----------------------------------------------------------------------------------------------------------
22+
/**
23+
Generate globally unique id, returns a string that can be used as a token
24+
This code comes from armazac's Overthrow mod, credit:
25+
https://github.com/ArmaOverthrow/Overthrow.Arma4/blob/main/Scripts/Game/Components/Player/OVT_PlayerIdentityComponent.c
26+
*/
27+
static string GenerateGUID()
28+
{
29+
30+
int year = 0;
31+
int month = 0;
32+
int day = 0;
33+
System.GetYearMonthDayUTC(year, month, day);
834

35+
int hour = 0;
36+
int minute = 0;
37+
int second = 0;
38+
System.GetHourMinuteSecondUTC(hour, minute, second);
39+
40+
string s = ""+year+month+day+hour+minute+second;
41+
42+
//Add some random numbers (Reference: https://eager.io/blog/how-long-does-an-id-need-to-be/)
43+
int i = s_AIRandomGenerator.RandFloatXY(0, 16777215);
44+
s += i.ToString();
45+
46+
i = s_AIRandomGenerator.RandFloatXY(0, 16777215);
47+
s += i.ToString();
48+
49+
return s;
50+
}
951
}

scripts/Game/ESE_Math.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ESE_Math
4444
}
4545
return vec;
4646
}
47+
// -----------------------------------------------------------------------------------------------------------
4748

4849

4950

0 commit comments

Comments
 (0)