Jump to content

[help] Research tree edit.


Recommended Posts

For education purpose.

Game load research tree file (TechTree_Generated.xml) via "Load(TextAsset researchTreeFile)" (in Database.Techs), but I cannot find where set name researchTreeFile (for replace).

 

PS: I understand structure TechTree_Generated.xml.

Link to comment
Share on other sites

Nobody answered? :?

From what I can tell, the TextAsset is set when Db is initialized. It will load the resource Db from a Unity resource file. That's where I lost the track of what is going on.

However I don't think simply replacing the xml file will work. The Techs class contains two dictionaries/lists (TECH_GROUPING and TECH_TIERS), which have to match the xml file. In other words modding techs seems to be more complex than just doing some xml editing.

Link to comment
Share on other sites

On 7/23/2019 at 5:31 PM, Nightinggale said:

However I don't think simply replacing the xml file will work. The Techs class contains two dictionaries/lists (TECH_GROUPING and TECH_TIERS), which have to match the xml file. In other words modding techs seems to be more complex than just doing some xml editing.

Both load data from ResourceTreeLoader<T>/Load() ('simple' XML parser for TechTree_Generated.xml).

Harmony, perhaps, may patch override methods (prefix() with true return). It general issue.

Then need convert plain text in TextAsset and replace original TechTree file (relative simple task).

Spoiler

Need some testing in free time.

 

Link to comment
Share on other sites

26 minutes ago, Cairath said:

Replacing the entire file is incompatible with all mods that'd also edit the research tree though

That's one reason why I would like to get the full source code. The work isn't done yet. What we need is a mod to load xml files, which then expand on the existing file rather than replacing it. In fact making a mod, which can be configured from xml would be interesting on so many levels.

Link to comment
Share on other sites

On 8/11/2019 at 8:03 PM, Cairath said:

Replacing the entire file is incompatible with all mods that'd also edit the research tree though

If keep original tech (only add new and replace exist) all must be compatible (in worst case Harmony allow set mod load order: I first, other second).

Current work (where all edge :confused:)

Spoiler

20190813142340_1.thumb.jpg.5feea9203418d0f9aebdaf1397337e94.jpg

And code (dirty, with some CaiLib code (thanks Cairath) but work):

Spoiler

using Harmony;
using Klei;
using KMod;
using System.IO;
using UnityEngine;
using STRINGS;
public class RTree
{
	private static string WhereI()
	{
		string root = typeof(Initialize_Patch).Assembly.Location;
		return Path.GetDirectoryName(root);
	}

	private static void EditTech()
	{
		Debug.Log("Edit some tech");
		Database.Techs.TECH_GROUPING["FineDining"] = new string[4]
		{
			"DiningTable",
			"CookingStation",
			"EggCracker",
			"Refrigerator"
		};
		Database.Techs.TECH_GROUPING["Agriculture"] = new string[3]
		{
			"FertilizerMaker",
			"FarmStation",
			"FarmTile"
		};
		Database.Techs.TECH_GROUPING["Hydroponics"] = new string[1]
		{
			"HydroponicFarm"
		};
		RTree.AddTech("Hydroponics", "Automated crop irrigation.");
		//Database.Techs.TECH_GROUPING
	}

	private static void AddTech(string name, string desc)
	{
		Debug.Log("Add new tech with name {0} and desc {1}", name,desc);
		Strings.Add(
			"STRINGS.RESEARCH.TECHS." + name.ToUpper() + ".NAME",
			name);
		Strings.Add(
			"STRINGS.RESEARCH.TECHS." + name.ToUpper() + ".DESC",
			desc);
	}

	[HarmonyPatch(typeof(Db))]
	[HarmonyPatch("Initialize")]
	public static class Initialize_Patch
	{
		public static void Prefix(Db __instance)
		{
			// Load TechTree
			string MyTechTreeFile = "MyTechTree.graphml";
			string path = FileSystem.Normalize(Path.Combine(RTree.WhereI(), MyTechTreeFile));
			if (!System.IO.File.Exists(path))
			{
				Debug.Log("No Custom Tech Tree file");
				return;
			}
			Debug.Log("Path is " + path);
			string content = File.ReadAllText(path);
			TextAsset MyTechTree = new TextAsset(content);
			MyTechTree.name = MyTechTreeFile;
			__instance.researchTreeFile = MyTechTree;
			Debug.Log("Research Tree File is " + __instance.researchTreeFile.name);
			if (__instance.researchTreeFile.text.Contains("MyTree"))
			{
				Debug.Log("HackSucces!!!");
			}
			else
			{
				Debug.Log("Fail :-(");
			}
			RTree.EditTech();
		}
	}
}

 

Edit. Edge found (and one half-bug), file issue

Spoiler

20190813152340_1.thumb.jpg.b292edbde85e60c9827dceb99ffa88be.jpg

Quote

What we need is a mod to load xml files, which then expand on the existing file rather than replacing it. In fact making a mod, which can be configured from xml would be interesting on so many levels.

Tree file is graphml with follow structure (general, other just skip):

<?xml version="1.0" encoding="encoding" standalone="no"?>
<graphml>
  <graph>
    <node id="someID">
    <GenericNode> <!-- no checked -->
      <!-- It tech in research screen; one node is one tech -->
      <Geometry height="nodeH" width="nodeW" x="posX" y="posY"/>
      <!-- x and y is important, it position on research screen also, other half important, minimal node size -->
      <NodeLabel>tech_internal_name</NodeLabel>
    </GenericNode>
    </node>
    <!-- now node link in reserch screen -->
    <edge id="someID" source="fromID" target="toID">
          <PolyLineEdge>
          <Path sx="0.0" sy="0.0" tx="0.0" ty="0.0"/>
          </PolyLineEdge>
      <!-- work only edge source/target attributes, other cheked but not work -->
    </edge>
  </graph>
</graphml>

Simple replace all file than edit exist.

Link to comment
Share on other sites

20190830122105_1.thumb.jpg.60a18ca3055a82991fa072a0e9295612.jpg

using Harmony;
using RTreeTools;

public class RTree
{
	[HarmonyPatch(typeof(Db))]
	[HarmonyPatch("Initialize")]
	public static class NewRTree
	{
		public static void Prefix(Db __instance)
		{
			Tree.Create(__instance.researchTreeFile);

			// Create new tech and move exist
			new TNode("AnimalControl").MoveTo(1.3, false);
			new Link("Agriculture", "AnimalControl").Delete();
			new TNode("Fertilizers", "Fertilizers",
				"Boosting crops grown.",
				new string[] {"FertilizerMaker", "FarmStation"},
				new string[] {"Agriculture"},
				new string[] {"FinerDining"}).Create(0.3, false);

			// Move some items
			new TNode("FineDining").AddItems(new string[] {"Refrigerator"});
			new TNode("Agriculture").AddItems(new string[] {"FarmTile"});
			new TNode("AnimalControl").AddItems(new string[] {"FlyingCreatureBait"});

			__instance.researchTreeFile = Tree.Save();
		}
	}
}

Create via hand-made tool set for gentle editing Research Tree (source code (working beta) and binary in link below). Use if need (sorry for lack documentation, little later, OK ;) ).

https://drive.google.com/file/d/1GwBg4Ezpnyeg_qw-uyTR1a3tdxz0O9Yi/view?usp=sharing

Link to comment
Share on other sites

@Guinaro, I little recreate tool-set (while private, I refresh code later). Nothing big, replace new Class via Tree.Class with separate new and exist node constructor (old method also may work, node constructors now internal method), add Delete for nodes (default off, I not like this) and start add documentation.

And yes, node must contain at last one item, name and description is vital need. Label ID must begin with '_' (it mark for engine). AddItems() only move needed items to new place and keep all other, no worry about newly one.

About translation. Place in mod folder 'strings' folder with 'strings.pot' file within.

strings.pot template

msgid ""
msgstr ""
"Application: Oxygen Not Included"
"POT Version: 2.0"

#. STRINGS.BUILDING.DETAILS.USE_COUNT
msgctxt "STRINGS.BUILDING.DETAILS.USE_COUNT"
msgid "Uses: {0}"
msgstr ""

STRINGS.RESEARCH.TREES.TITLE_<Label_id_without_mark_in_uppercase> is label name

STRINGS.RESEARCH.TECH.<tech_id_in_uppercase>.NAME = tech node name

STRINGS.RESEARCH.TECH.<tech_id_in_uppercase>.DESC = tech node description

See Assembly-CSharp.dll/STRINGS/RESEARCH and StreamingAssets/strings for advance.

It allow translate newly added things.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...