fiziologus Posted July 21, 2019 Share Posted July 21, 2019 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 More sharing options...
Nightinggale Posted July 23, 2019 Share Posted July 23, 2019 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 More sharing options...
fiziologus Posted August 5, 2019 Author Share Posted August 5, 2019 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 More sharing options...
fiziologus Posted August 11, 2019 Author Share Posted August 11, 2019 I make it. I just hack Db itself and replace researchTreeFile (and it initialize some where before Db.initialize()). Now only work with tree file and patch tech() if need. Link to comment Share on other sites More sharing options...
Nightinggale Posted August 11, 2019 Share Posted August 11, 2019 Would you please post the entire code you used for this. It's possible it's just the prefix in the screenshot, but the code is cut off. It would be nice if it's visible as text for copy pasting. Link to comment Share on other sites More sharing options...
Cairath Posted August 11, 2019 Share Posted August 11, 2019 Replacing the entire file is incompatible with all mods that'd also edit the research tree though Link to comment Share on other sites More sharing options...
Nightinggale Posted August 11, 2019 Share Posted August 11, 2019 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 More sharing options...
fiziologus Posted August 13, 2019 Author Share Posted August 13, 2019 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 ) Spoiler 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 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 More sharing options...
fiziologus Posted August 30, 2019 Author Share Posted August 30, 2019 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 More sharing options...
Guinaro Posted September 9, 2019 Share Posted September 9, 2019 @fiziologus Just placed my mod Reorganized Research online https://steamcommunity.com/sharedfiles/filedetails/?id=1858538356 Your code was an immense help to kickstart my mod. Learned a lot. I tweaked the code here and there to suit my needs better. So thank you for making this possible. Link to comment Share on other sites More sharing options...
fiziologus Posted September 9, 2019 Author Share Posted September 9, 2019 @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 More sharing options...
Recommended Posts
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.