Skip to content

Commit 802463d

Browse files
committed
Reflection work put on hold, too messy. Added new workbench plugins
1 parent 5562158 commit 802463d

34 files changed

+1302
-123
lines changed

resourceDatabase.rdb

1.82 KB
Binary file not shown.

scripts/Game/!ESE_CORE.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
#define ESE_INSTALLED // Always keep this enabled to ensure mod compatiblity with additional aliases
22
#define ESE_VERSION_MAJOR_0
3-
#define ESE_MAINFUNC
43

5-
bool ESE_IS_INITIALIZED = ESE.Init();
4+
bool ESE_IS_INITIALIZED = ESE.Init();
5+
6+
// #ESE_ADD_DOCUMENTATION
7+
[__ESE_InitPtrMap()]
8+
void __ESE_InitPtrMap() {ESE_PointerReferenceMap = new map<pointer, Class>();}
9+
ref map<pointer, Class> ESE_PointerReferenceMap;
10+
11+
pointer ptr(Class in)
12+
{
13+
return (int)in;
14+
}
15+
16+
pointer stringf_ptr(Class in)
17+
{
18+
string str = in.ToString();
19+
str = str.Substring(str.Length()-17, 16);
20+
21+
string loBitsStr, hiBitsStr;
22+
hiBitsStr = str.Substring(0, 8);
23+
loBitsStr = str.Substring(8, 8);
24+
int loBits, hiBits;
25+
26+
int j = 0;
27+
for (int i = 7; i >= 0; i--)
28+
{
29+
if (!loBitsStr.IsDigitAt(i)) {loBits += (loBitsStr.ToAscii(i) - 55) * (Math.Pow(16, j));} else {loBits += (loBitsStr.ToAscii(i) - 48) * (Math.Pow(16, j));}
30+
if (!hiBitsStr.IsDigitAt(i)) {hiBits += (hiBitsStr.ToAscii(i) - 55) * (Math.Pow(16, j));} else {hiBits += (hiBitsStr.ToAscii(i) - 48) * (Math.Pow(16, j));}
31+
j++;
32+
}
33+
34+
pointer ptr = EntityID.FromInt(hiBits, loBits);
35+
ESE_PointerReferenceMap.Set(ptr, in);
36+
return ptr;
37+
}
38+
39+
Class deref_ptr(pointer ptr)
40+
{
41+
return ESE_PointerReferenceMap.Get(ptr);
42+
}

scripts/Game/!ESE_Config_EnforceScriptExtensions.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,20 @@
2222
//#define ESE_ALIASES_EQUIPMENT
2323
//#define ESE_ALIASES_VEHICLES
2424
#define ESE_ALIASES_DEBUG
25+
//#define ESE_ENABLE_REFLECTION
2526

2627
#endif
2728

2829
// -------------------- DO NOT MODIFY BEYOND THIS POINT --------------------
2930

31+
#ifdef ESE_ENABLE_REFLECTION
32+
// Include all reflection classes if enabled
33+
#include "$EnforceScriptExtensions:scripts/Game/Additions/Reflection/ESE_Reflection.h"
34+
#include "$EnforceScriptExtensions:scripts/Game/Additions/Reflection/ESE_ReflectionEnums.h"
35+
#include "$EnforceScriptExtensions:scripts/Game/Additions/Reflection/ESE_Type.h"
36+
#include "$EnforceScriptExtensions:scripts/Game/Additions/Reflection/ESE_MemberInfo.h"
37+
#include "$EnforceScriptExtensions:scripts/Game/Additions/Reflection/ESE_ScriptParser.h"
38+
#endif
3039
// Pre-processor enable all other alias defines if ESE_ALIASES_ALL is defined
3140
#ifdef ESE_ALIASES_ALL
3241
#define ESE_ALIASES_MATERIALS
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
\brief Tuple Class Template with seven parameters.
3+
*/
4+
class Tuple7<Class T1, Class T2, Class T3, Class T4, Class T5, Class T6, Class T7> extends Tuple
5+
{
6+
T1 param1;
7+
T2 param2;
8+
T3 param3;
9+
T4 param4;
10+
T5 param5;
11+
T6 param6;
12+
T7 param7;
13+
14+
void Tuple8(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7)
15+
{
16+
param1 = p1;
17+
param2 = p2;
18+
param3 = p3;
19+
param4 = p4;
20+
param5 = p5;
21+
param6 = p6;
22+
param7 = p7;
23+
}
24+
25+
override bool Serialize(Serializer ctx)
26+
{
27+
return ctx.Write(param1) && ctx.Write(param2) && ctx.Write(param3) && ctx.Write(param4) && ctx.Write(param5) && ctx.Write(param6) && ctx.Write(param7);
28+
}
29+
30+
override bool Deserializer(Serializer ctx)
31+
{
32+
return ctx.Read(param1) && ctx.Read(param2) && ctx.Read(param3) && ctx.Read(param4) && ctx.Read(param5) && ctx.Read(param6) && ctx.Read(param7);
33+
}
34+
};
35+
36+
/**
37+
\brief Tuple Class Template with eight parameters.
38+
*/
39+
class Tuple8<Class T1, Class T2, Class T3, Class T4, Class T5, Class T6, Class T7, Class T8> extends Tuple
40+
{
41+
T1 param1;
42+
T2 param2;
43+
T3 param3;
44+
T4 param4;
45+
T5 param5;
46+
T6 param6;
47+
T7 param7;
48+
T8 param8;
49+
50+
void Tuple8(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8)
51+
{
52+
param1 = p1;
53+
param2 = p2;
54+
param3 = p3;
55+
param4 = p4;
56+
param5 = p5;
57+
param6 = p6;
58+
param7 = p7;
59+
param8 = p8;
60+
}
61+
62+
override bool Serialize(Serializer ctx)
63+
{
64+
return ctx.Write(param1) && ctx.Write(param2) && ctx.Write(param3) && ctx.Write(param4) && ctx.Write(param5) && ctx.Write(param6) && ctx.Write(param7) && ctx.Write(param8);
65+
}
66+
67+
override bool Deserializer(Serializer ctx)
68+
{
69+
return ctx.Read(param1) && ctx.Read(param2) && ctx.Read(param3) && ctx.Read(param4) && ctx.Read(param5) && ctx.Read(param6) && ctx.Read(param7) && ctx.Read(param8);
70+
}
71+
};
72+
73+
/**
74+
\brief Tuple Class Template with nine parameters.
75+
*/
76+
class Tuple9<Class T1, Class T2, Class T3, Class T4, Class T5, Class T6, Class T7, Class T8, Class T9> extends Tuple
77+
{
78+
T1 param1;
79+
T2 param2;
80+
T3 param3;
81+
T4 param4;
82+
T5 param5;
83+
T6 param6;
84+
T7 param7;
85+
T8 param8;
86+
T9 param9;
87+
88+
void Tuple9(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8, T9 p9)
89+
{
90+
param1 = p1;
91+
param2 = p2;
92+
param3 = p3;
93+
param4 = p4;
94+
param5 = p5;
95+
param6 = p6;
96+
param7 = p7;
97+
param8 = p8;
98+
param9 = p9;
99+
}
100+
101+
override bool Serialize(Serializer ctx)
102+
{
103+
return ctx.Write(param1) && ctx.Write(param2) && ctx.Write(param3) && ctx.Write(param4) && ctx.Write(param5) && ctx.Write(param6) && ctx.Write(param7) && ctx.Write(param8) && ctx.Write(param9);
104+
}
105+
106+
override bool Deserializer(Serializer ctx)
107+
{
108+
return ctx.Read(param1) && ctx.Read(param2) && ctx.Read(param3) && ctx.Read(param4) && ctx.Read(param5) && ctx.Read(param6) && ctx.Read(param7) && ctx.Read(param8) && ctx.Read(param9);
109+
}
110+
};
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
ESE Additions - ExportAddonScripts
3+
4+
Include path - "$EnforceScriptExtensions:scripts/Game/Additions/ExportModule.h"
5+
6+
Function for making a copy of all script files from a given addon, recreating the complete file structure of the addon.
7+
This is obviously not a function to be used in actual scripts, so call it once via either a temporary global function
8+
or as an attribute, Examples below.
9+
10+
--------------------------------------------------------------------------------------------------------------------------------
11+
Calling in a function:
12+
You can use GameProject.GetAvailableAddons() to get the GUID's of all addons, and check for the right name if you're unsure.
13+
--------------------------------------------------------------------------------------------------------------------------------
14+
15+
int main()
16+
{
17+
array<string> addonGUIDs = {};
18+
GameProject.GetAvailableAddons(addonGUIDs);
19+
20+
foreach (string addon: addonGUIDs)
21+
{
22+
if (GameProject.GetAddonID(addon) == "AddonYouWant")
23+
{
24+
ESE_ExportAddonScripts(addon, "C:\Some\Path\AddonName");
25+
break;
26+
}
27+
}
28+
return 0;
29+
}
30+
int exitcode = main()
31+
32+
--------------------------------------------------------------------------------------------------------------------------------
33+
Calling as an attribute:
34+
Simply call the function like an attribute on a temporary global function or class definition, and manually write in the params.
35+
Note that this will run at compile time not runtime, so just hit F7, let it run, then remove the code again.
36+
--------------------------------------------------------------------------------------------------------------------------------
37+
38+
[ESE_ExportAddonScripts("58D0FB3206B6F859", "C:\Some\Path\AddonName")] // GUID of "$ArmaReforger:" used here
39+
void Temp()
40+
41+
--------------------------------------------------------------------------------------------------------------------------------
42+
**/
43+
44+
// NOTE - As of ESE v0.2.3 this function's behavior with invalid export locations is weird, double check your file paths!
45+
void ESE_ExportAddonScripts(string addonGUID, string exportLocation)
46+
{
47+
if (!exportLocation.EndsWith("/")){
48+
exportLocation += "/";
49+
}
50+
// need to check export location exists, just don't know how :/
51+
52+
string addonRoot = string.Format("$%1:", GameProject.GetAddonID(addonGUID));
53+
Print(addonRoot);
54+
55+
string divider = "\n-------------------------------------------------------------------------------------------------\n";
56+
Debug.Error2("Are you sure?", string.Format("Please Confirm!%3Exporting scripts from addon : '%1' \nTo path : '%2' %3Press debug and close the workbench to cancel before files are created, or ignore to proceed.%3If you're seeing this message when starting the workbench, task manager close the program and launch again with -noGameScriptsOnInit launch parameter", addonRoot, exportLocation, divider));
57+
58+
array<string> paths = {};
59+
System.FindFiles(paths.Insert, addonRoot+"scripts/", ".c");
60+
61+
foreach (string path: paths)
62+
{
63+
string fileName = FilePath.StripPath(path);
64+
65+
string stripped = FilePath.StripFileName(path);
66+
stripped.Replace(addonRoot, string.Empty);
67+
stripped = stripped.Substring(0, stripped.Length() - 1);
68+
69+
array<string> tokens = {};
70+
stripped.Split("/", tokens, true);
71+
72+
string str = exportLocation;
73+
foreach (string token: tokens)
74+
{
75+
str += token + "/";
76+
FileIO.MakeDirectory(str);
77+
}
78+
79+
array<string> allLines = {};
80+
FileHandle readHandle = FileIO.OpenFile(path, FileMode.READ);
81+
string line;
82+
while (readHandle.FGets(line) >= 0)
83+
{
84+
allLines.Insert(line);
85+
}
86+
readHandle.CloseFile();
87+
88+
FileHandle writeHandle = FileIO.OpenFile(str + fileName, FileMode.WRITE);
89+
foreach (string writeLine: allLines)
90+
{
91+
writeHandle.FPrintln(writeLine);
92+
}
93+
writeHandle.CloseFile();
94+
}
95+
}
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ESE_MemberInfo
2+
{
3+
protected ESE_EMemberTypes MemberType;
4+
5+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//#include "$EnforceScriptExtensions:scripts/Game/Additions/Reflection/Old/ESE_Reflection_v1.h"
2+
//#include "$EnforceScriptExtensions:scripts/Game/Additions/Reflection/Old/ESE_Reflection_v2.h"
3+
//#include "$EnforceScriptExtensions:scripts/Game/Additions/Reflection/Old/ESE_Reflection_v3.h"
4+
5+
// ---------------------------------------------------------------------------------------------------------------
6+
7+
8+
9+
// ---------------------------------------------------------------------------------------------------------------
10+
class ESE_Reflection
11+
{
12+
static const ESE_EMemberTypes EMemberTypes;
13+
static const ESE_EBindingFlags EBindingFlags;
14+
15+
static ScriptModule scriptModule = ScriptModule.LoadScript(null, "", true);
16+
17+
// -----------------------------------------------------------------------------------------------------------
18+
// This isn't private in case anyone wants to mess with it, but this should only be called at compile time via attribute call
19+
//[UpdateTypeReferences()]
20+
static void UpdateTypeReferences()
21+
{
22+
auto types = GetAllClasses();
23+
FileHandle classRefFile = FileIO.OpenFile("$EnforceScriptExtensions:scripts/Game/Reflection/ESE_ClassReferences.csv", FileMode.WRITE);
24+
foreach (string type: types)
25+
{
26+
classRefFile.FPrintln(type);
27+
}
28+
classRefFile.CloseFile();
29+
}
30+
31+
// -----------------------------------------------------------------------------------------------------------
32+
static array<string> GetAllClasses()
33+
{
34+
array<string> outArray = {};
35+
// go through all addons so we can find the files in each, like $core, $ArmaReforger, $EnforceScriptExtensions, etc.
36+
array<string> addons = {};
37+
GameProject.GetAvailableAddons(addons);
38+
array<string> duplicates = {};
39+
foreach (string addon: addons)
40+
{
41+
// find all the script files in the addon
42+
string addonID = GameProject.GetAddonID(addon);
43+
array<string> addonFiles = {};
44+
System.FindFiles(addonFiles.Insert, "$"+addonID+":scripts/", ".c");
45+
//addonFiles.Debug();
46+
47+
foreach (string file: addonFiles)
48+
{
49+
string line;
50+
FileHandle fHandle = FileIO.OpenFile(file, FileMode.READ);
51+
bool commentedOff = false;
52+
while (fHandle.FGets(line) >= 0)
53+
{
54+
// handle commented off sections of code
55+
if (line.Contains("/*"))
56+
{
57+
commentedOff = true;
58+
}
59+
if (line.Contains("*/"))
60+
{
61+
commentedOff = false;
62+
}
63+
if (commentedOff || line.Contains("//")) // change to starts with
64+
{
65+
continue;
66+
}
67+
line.Replace(":", "");
68+
if (line.StartsWith("class") || line.StartsWith("sealed") || line.StartsWith("modded"))
69+
{
70+
array<string> tokens = {};
71+
line.Split(" ", tokens, true);
72+
73+
tokens.RemoveItemOrdered("class");
74+
tokens.RemoveItemOrdered("sealed");
75+
tokens.RemoveItemOrdered("modded");
76+
tokens.RemoveItemOrdered("extends");
77+
78+
// to handle template classes, since they have a space in their name like: Something<Class T>
79+
foreach (string element: tokens)
80+
{
81+
if (element.Contains(">") && !element.Contains("<"))
82+
{
83+
tokens[0] = tokens[0] + " " + element;
84+
break;
85+
}
86+
}
87+
88+
tokens.Insert(file);
89+
//Print(tokens);
90+
if (outArray.Contains(tokens[0]))
91+
{
92+
duplicates.Insert(tokens[0] + " : " + file);
93+
}
94+
outArray.Insert(tokens[0] + "," + file);
95+
}
96+
}
97+
fHandle.CloseFile();
98+
}
99+
}
100+
Print(duplicates);
101+
return outArray;
102+
}
103+
104+
// -----------------------------------------------------------------------------------------------------------
105+
106+
// -----------------------------------------------------------------------------------------------------------
107+
}

0 commit comments

Comments
 (0)