Skip to content

Commit 3a86f11

Browse files
committed
Enabled publicize feature for compiler output
- Implemented a config check to enable publicizing in the compiler. - Added logic to write the publicized assembly to a specified output path. - Included error handling for directory existence and writing failures. - Updated patching process to call the new finish method after patching.
1 parent 01a225b commit 3a86f11

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/CompilerService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public CompilerService(Extension extension)
7373
EnvironmentHelper.SetVariable("Path:Configuration", Interface.Oxide.ConfigDirectory);
7474
EnvironmentHelper.SetVariable("Path:Data", Interface.Oxide.DataDirectory);
7575
EnvironmentHelper.SetVariable("Path:Libraries", Interface.Oxide.ExtensionDirectory);
76+
77+
if (Interface.Oxide.Config.Compiler.Publicize)
78+
{
79+
EnvironmentHelper.SetVariable("AllowPublicize", "true", force: true);
80+
}
7681
}
7782

7883
private void ExpireFileCache()
@@ -136,6 +141,12 @@ internal bool Precheck()
136141
preprocessorList.AddRange(Interface.Oxide.Config.Compiler.PreprocessorDirectives);
137142
}
138143

144+
if (Interface.Oxide.Config.Compiler.Publicize)
145+
{
146+
EnvironmentHelper.SetVariable("AllowPublicize", "true", force: true);
147+
preprocessorList.Add("OXIDE_PUBLICIZED");
148+
}
149+
139150
preprocessor = preprocessorList.Distinct().ToArray();
140151

141152
#if DEBUG

src/Patching/Publicizer.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
using Oxide.CSharp.Patching.Validation;
44
using References::Mono.Cecil;
5+
using System;
6+
using System.IO;
57

68
namespace Oxide.CSharp.Patching
79
{
@@ -72,5 +74,31 @@ protected override bool OnMethodDefinition(MethodDefinition method)
7274
method.IsPublic = true;
7375
return true;
7476
}
77+
78+
protected override void OnPatchFinished(PatchContext context)
79+
{
80+
string writePath = EnvironmentHelper.GetVariable("PublicizerOutput");
81+
82+
if (!string.IsNullOrEmpty(writePath))
83+
{
84+
string name = context.Assembly.Name.Name;
85+
if (!Directory.Exists(writePath))
86+
{
87+
Log($"Failed to write {name} because PublicizeOutput {writePath} doesn't exist", Core.Logging.LogType.Error);
88+
return;
89+
}
90+
91+
try
92+
{
93+
name = Path.Combine(writePath, name + ".dll");
94+
context.Assembly.Write(name);
95+
Log($"Wrote publicized assembly to {writePath}");
96+
}
97+
catch (Exception e)
98+
{
99+
Log($"Failed to write publicized assembly to {writePath}", Core.Logging.LogType.Error, e);
100+
}
101+
}
102+
}
75103
}
76104
}

src/Patching/TraversePatch.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public void Patch(PatchContext context)
4848
TypeDefinition type = types[t];
4949
RecurseType(type, context);
5050
}
51+
52+
OnPatchFinished(context);
5153
}
5254

5355
private void RecurseType(TypeDefinition type, PatchContext context)
@@ -201,6 +203,10 @@ protected virtual bool OnEventDefinition(EventDefinition @event)
201203
return false;
202204
}
203205

206+
protected virtual void OnPatchFinished(PatchContext context)
207+
{
208+
}
209+
204210
protected bool RunValidation(IMemberDefinition member, IEnumerable<PatchValidationAttribute> validations)
205211
{
206212
if (member == null)

0 commit comments

Comments
 (0)