Skip to content

Commit

Permalink
Added action plugin example
Browse files Browse the repository at this point in the history
  • Loading branch information
SillyBits committed Oct 30, 2019
1 parent afde76e commit a5b1d5f
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 1 deletion.
2 changes: 2 additions & 0 deletions App/.gitignore
Expand Up @@ -5,3 +5,5 @@ exports

logs
*.log

plugins
2 changes: 1 addition & 1 deletion App/Actions/Action.cs
Expand Up @@ -156,7 +156,7 @@ protected void _AddToMenu(MenuItem menu, RoutedEventHandler handler)
foreach (var group in groups)
{
MenuItem plugin = add_plugin(menu, group.Key);
foreach (var pair in plugins)
foreach (var pair in group)
add_action(plugin, pair.Key, pair.Value);
}
}
Expand Down
87 changes: 87 additions & 0 deletions Plugins/ActionExamples/ActionExamples.csproj
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F9EC50BC-78D7-4D20-B0FB-E26BBD70BB19}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ActionExamples</RootNamespace>
<AssemblyName>ActionExamples</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExportChildClasses.cs" />
<Compile Include="ExportClassNames.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\App\App.csproj">
<Project>{880c53c6-cdd1-4d17-ad14-b6ece784d9a9}</Project>
<Name>App</Name>
</ProjectReference>
<ProjectReference Include="..\..\CoreLib\CoreLib.csproj">
<Project>{0dede00f-7e56-49f3-8a28-ddbb1f83a8b8}</Project>
<Name>CoreLib</Name>
</ProjectReference>
<ProjectReference Include="..\..\FileHandler\FileHandler.vcxproj">
<Project>{d9c82451-5129-4f70-9d78-f292d3f2b9ab}</Project>
<Name>FileHandler</Name>
</ProjectReference>
<ProjectReference Include="..\..\PakHandler\PakHandler.vcxproj">
<Project>{80df7a33-aaf6-4967-a7fd-35cc1f01a2c4}</Project>
<Name>PakHandler</Name>
</ProjectReference>
<ProjectReference Include="..\..\SavegameHandler\SavegameHandler.vcxproj">
<Project>{096f67ea-d61b-4950-8b21-65dda14ee113}</Project>
<Name>SavegameHandler</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y $(TargetDir)$(TargetName).dll $(SolutionDir)App\plugins
copy /Y $(TargetDir)$(TargetName).pdb $(SolutionDir)App\plugins</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
148 changes: 148 additions & 0 deletions Plugins/ActionExamples/ExportChildClasses.cs
@@ -0,0 +1,148 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows;

using CoreLib;

using FileHandler;

using P = Savegame.Properties;

using SatisfactorySavegameTool.Actions;
using A = SatisfactorySavegameTool.Actions.Attributes;
using SatisfactorySavegameTool.Supplements;


namespace ActionExamples
{
// This example action shows how to run a method on a save to gather some information.
// After completion, the report is being stored to file using a path from the tool's settings.
//
[A.Name("Export child classes"), A.Description("Export all classes found within .Children")]
public class ExportChildClasses : IAction
{
public ExportChildClasses(Savegame.Savegame savegame)
{
_savegame = savegame;
_runner = new HierarchyRunner(savegame, false);
_classes = new Dictionary<string, List<string>>();
}


public void Run()
{
Helper.WaitAsync(RunAsync);
}

public async Task RunAsync()
{
await Task.Run(() => {
Log.Info("Exporting ...");
DateTime start_time = DateTime.Now;
_runner.Run("Exporting ...", _Process);
_WriteFile();
DateTime end_time = DateTime.Now;
TimeSpan ofs = end_time - start_time;
Log.Info("Export took {0}", ofs);
});
}


private void _Process(P.Property prop)
{
//-> [Actor] Persistent_Level:PersistentLevel.Char_Player_C_0
// .ClassName = str:'/Game/FactoryGame/Character/Player/Char_Player.Char_Player_C'
// .PathName = str:'Persistent_Level:PersistentLevel.Char_Player_C_0'
// .EntityObj =
// -> [NamedEntity]
// .Children =
// / List with 5 elements:
// |-> [Name]
// | .LevelName = str:'Persistent_Level'
// | .PathName = str:'Persistent_Level:PersistentLevel.Char_Player_C_0.TrashSlot'
// | ...
// |-> [Name]
// | .LevelName = str:'Persistent_Level'
// | .PathName = str:'Persistent_Level:PersistentLevel.Char_Player_C_0.inventory'
// \ end of list

P.Actor actor = prop as P.Actor;
if (actor == null)
return;

if (str.IsNullOrEmpty(actor.ClassName))
return;
string actor_class = actor.ClassName.ToString();

P.NamedEntity entity = actor.EntityObj as P.NamedEntity;
if (entity == null)
return;

var childs = entity.GetChilds();
if (!childs.ContainsKey("Children"))
return;

P.Properties props = childs["Children"] as P.Properties;
if (props == null || props.Count == 0)
return;

List<P.NamedEntity.Name> names = props.ListOf<P.NamedEntity.Name>();
foreach (P.NamedEntity.Name name in names)
{
string pathname = "";
if (!str.IsNullOrEmpty(name.PathName))
pathname = name.PathName.LastName();

List<string> classes;
if (!_classes.ContainsKey(pathname))
{
classes = new List<string>();
_classes.Add(pathname, classes);
}
else
{
classes = _classes[pathname];
}
if (!classes.Contains(actor_class))
classes.Add(actor_class);
}
}

private void _WriteFile()
{
string filename = Path.Combine(SatisfactorySavegameTool.Settings.EXPORTPATH, Path.GetFileName(_savegame.Filename) + "-childs.export");
using (StreamWriter w = File.CreateText(filename))
{
w.WriteLine("All classes found within .Children:");
w.WriteLine("===================================");
w.WriteLine("");

List<string> keys = _classes.Keys();
keys.Sort();
foreach (string key in keys)
{
w.WriteLine("." + key);
List<string> classes = _classes[key];
classes.Sort();
classes.ForEach(c => w.WriteLine(" - " + c));
w.WriteLine("");
}

w.Flush();
w.Close();
}
}


private Savegame.Savegame _savegame;
private HierarchyRunner _runner;
private Dictionary<string, List<string>> _classes;
}

}

0 comments on commit a5b1d5f

Please sign in to comment.