Browse Source

Fix assembly editing and add more of it

- It breaks the game atm, not sure why exactly but it's probably not a good thing
feature/tb.update
NorbiPeti 2 years ago
parent
commit
e0cd7f6aec
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
9 changed files with 1641 additions and 40 deletions
  1. +0
    -1
      CodeGenerator/CodeGenerator.csproj
  2. +0
    -36
      CodeGenerator/MakeEverythingPublicInGame.cs
  3. +3
    -2
      CodeGenerator/Program.cs
  4. +1574
    -0
      MakeEverythingPublicInGame/MakeEverythingPublicInGame.csproj
  5. +25
    -0
      MakeEverythingPublicInGame/Program.cs
  6. +8
    -0
      TechbloxModdingAPI.sln
  7. +27
    -1
      TechbloxModdingAPI/Utility/NativeApiExtensions.cs
  8. +2
    -0
      TechbloxModdingAPI/Utility/OptionalRef.cs
  9. +2
    -0
      TechbloxModdingAPI/Utility/RefCollection.cs

+ 0
- 1
CodeGenerator/CodeGenerator.csproj View File

@@ -20,7 +20,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.0.4" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
<PackageReference Include="System.CodeDom" Version="7.0.0-preview.2.22152.2" />
</ItemGroup>
<ItemGroup>


+ 0
- 36
CodeGenerator/MakeEverythingPublicInGame.cs View File

@@ -1,36 +0,0 @@
using System;
using System.IO;
using System.Reflection.Metadata;
using System.Text.RegularExpressions;
using Mono.Cecil;
using ModuleDefinition = Mono.Cecil.ModuleDefinition;

namespace CodeGenerator
{
public class MakeEverythingPublicInGame
{
public void Start()
{
Console.WriteLine("Starting assembly editing...");
var fileRegex =
new Regex(".*(Techblox|Gamecraft|RobocraftX|FullGame|RobocraftECS|DataLoader|RCX|GameState)[^/]*(\\.dll)");
foreach (var file in Directory.EnumerateFiles(@"../../../../../ref/Techblox_Data/Managed"))
{
if (!fileRegex.IsMatch(file)) continue;
Console.WriteLine(file);
ProcessAssembly(file);
}
}

public void ProcessAssembly(string path)
{
var mod = ModuleDefinition.ReadModule(path, new(ReadingMode.Immediate) { ReadWrite = true });
foreach (var typeDefinition in mod.Types)
{
typeDefinition.Attributes |= TypeAttributes.Public;
}

mod.Write();
}
}
}

+ 3
- 2
CodeGenerator/Program.cs View File

@@ -1,7 +1,10 @@
using System.Collections.Generic;
using HarmonyLib;
using RobocraftX.Blocks;
using RobocraftX.Common;
using RobocraftX.GroupTags;
using RobocraftX.PilotSeat;
using Svelto.ECS;
using Techblox.EngineBlock;
using Techblox.ServoBlocksServer;
using Techblox.WheelRigBlock;
@@ -13,8 +16,6 @@ namespace CodeGenerator
public static void Main(string[] args)
{
GenerateBlockClasses();
var mepig = new MakeEverythingPublicInGame();
mepig.Start();
}

private static void GenerateBlockClasses()


+ 1574
- 0
MakeEverythingPublicInGame/MakeEverythingPublicInGame.csproj
File diff suppressed because it is too large
View File


+ 25
- 0
MakeEverythingPublicInGame/Program.cs View File

@@ -0,0 +1,25 @@
using System.Text.RegularExpressions;
using Mono.Cecil;

Console.WriteLine("Starting assembly editing...");
var fileRegex =
new Regex(".*(Techblox|Gamecraft|RobocraftX|FullGame|RobocraftECS|DataLoader|RCX|GameState|Svelto\\.ECS)[^/]*(\\.dll)");
foreach (var file in Directory.EnumerateFiles(@"../../../../../ref/Techblox_Data/Managed"))
{
if (!fileRegex.IsMatch(file)) continue;
Console.WriteLine(file);
ProcessAssembly(file);
}

void ProcessAssembly(string path)
{
var mod = ModuleDefinition.ReadModule(path, new(ReadingMode.Immediate) { ReadWrite = true });
foreach (var typeDefinition in mod.Types)
{
typeDefinition.IsPublic = true;
foreach (var method in typeDefinition.Methods) method.IsPublic = true;
foreach (var field in typeDefinition.Fields) field.IsPublic = true;
}

mod.Write();
}

+ 8
- 0
TechbloxModdingAPI.sln View File

@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechbloxModdingAPI", "Techb
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeGenerator", "CodeGenerator\CodeGenerator.csproj", "{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MakeEverythingPublicInGame", "MakeEverythingPublicInGame\MakeEverythingPublicInGame.csproj", "{391A3107-E5C6-4A04-9467-6D868AA9A8B4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -26,6 +28,12 @@ Global
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Release|Any CPU.Build.0 = Release|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{0EBB6400-95A7-4A3D-B2ED-BF31E364CC10}.Test|Any CPU.Build.0 = Debug|Any CPU
{391A3107-E5C6-4A04-9467-6D868AA9A8B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{391A3107-E5C6-4A04-9467-6D868AA9A8B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{391A3107-E5C6-4A04-9467-6D868AA9A8B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{391A3107-E5C6-4A04-9467-6D868AA9A8B4}.Release|Any CPU.Build.0 = Release|Any CPU
{391A3107-E5C6-4A04-9467-6D868AA9A8B4}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{391A3107-E5C6-4A04-9467-6D868AA9A8B4}.Test|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 27
- 1
TechbloxModdingAPI/Utility/NativeApiExtensions.cs View File

@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using Svelto.DataStructures;
using Svelto.ECS;
using Svelto.Tasks;
using Svelto.Tasks.Lean;
@@ -79,7 +82,6 @@ namespace TechbloxModdingAPI.Utility
public static void PublishEntityChangeDelayed<T>(this EntitiesDB entitiesDB, EGID id, int limit = 80)
where T : unmanaged, IEntityComponent
{
//TODO: Doesn't seem to help
if (!ChangesToPublish.ContainsKey(typeof(T)))
ChangesToPublish.Add(typeof(T), (0, new HashSet<EGID>()));
var changes = ChangesToPublish[typeof(T)].Changes;
@@ -94,6 +96,30 @@ namespace TechbloxModdingAPI.Utility
yield return Yield.It;
while (ChangesToPublish[typeof(T)].PublishedCount >= limit)
yield return Yield.It;
if (!entitiesDB._entityStream._streams.TryGetValue(TypeRefWrapper<T>.wrapper, out var result))
yield break; // There is no entity stream for this type
var consumers = (result as EntityStream<T>)?._consumers;
if (consumers == null)
{
Console.WriteLine("Consumers is null");
yield break;
}

bool waitForConsumers;
do
{
waitForConsumers = false;
for (int i = 0; i < consumers.count; i++)
{
var buffer = consumers[i]._ringBuffer;
if (buffer.Count + 1 <= buffer.Capacity) continue;
waitForConsumers = true;
Console.WriteLine($"Gonna have to wait for a consumer (capacity: {buffer.Capacity} count: {buffer.Count}");
break;
}

if (waitForConsumers) yield return Yield.It;
} while (waitForConsumers);
entitiesDB.PublishEntityChange<T>(id);
var (count, changes) = ChangesToPublish[typeof(T)];
changes.Remove(id);


+ 2
- 0
TechbloxModdingAPI/Utility/OptionalRef.cs View File

@@ -21,6 +21,7 @@ namespace TechbloxModdingAPI.Utility
this.index = index;
this.entityId = entityId;
initializer = default;
managedArray = default;
}

public OptionalRef(MB<T> array, uint index, EGID entityId = default)
@@ -53,6 +54,7 @@ namespace TechbloxModdingAPI.Utility
}
array = default;
index = default;
managedArray = default;
}

/// <summary>


+ 2
- 0
TechbloxModdingAPI/Utility/RefCollection.cs View File

@@ -34,6 +34,8 @@ namespace TechbloxModdingAPI.Utility
this.nativeIDs = nativeIDs;
this.group = group;
managed = false;
managedArray = default;
managedIDs = default;
}

public Enumerator GetEnumerator() => new(this);


Loading…
Cancel
Save