Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions YAFC/Data/Mod-fixes/pyalternativeenergy.data.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Remove the placer entities that pyanodon uses for some runtime scripting trickery.
for _, item in pairs(data.raw.item) do
if item.place_result then
item.place_result = item.place_result:gsub("%-placer$", ""):gsub("%-placer%-", "-")
end
if item.next_upgrade then
item.next_upgrade = item.next_upgrade:gsub("%-placer$", ""):gsub("%-placer%-", "-")
end
end

for _, type in pairs(data.raw) do
for name, _ in pairs(type) do
if name:match("%-placer$") or name:match("%-placer%-") then
type[name] = nil
end
end
end
20 changes: 14 additions & 6 deletions YAFCparser/LuaContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,7 @@ private int Require(IntPtr lua)
if (bytes != null)
{
var result = Exec(bytes, requiredFile.mod, requiredFile.path);
if (modFixes.TryGetValue(requiredFile, out var fix))
{
var modFixName = "mod-fix-" + requiredFile.mod + "." + requiredFile.path;
Console.WriteLine("Running mod-fix "+modFixName);
result = Exec(fix, "*", modFixName, result);
}
result = RunModFix(requiredFile.mod, requiredFile.path, result);
required[requiredFile] = result;
GetReg(result);
}
Expand All @@ -368,6 +363,18 @@ private int Require(IntPtr lua)
return 1;
}

private int RunModFix(string mod, string path, int result = 0)
{
if (modFixes.TryGetValue((mod, path), out var fix))
{
var modFixName = "mod-fix-" + mod + "." + path;
Console.WriteLine("Running mod-fix " + modFixName);
result = Exec(fix, "*", modFixName, result);
}

return result;
}

protected readonly List<object> neverCollect = new List<object>(); // references callbacks that could be called from native code to not be garbage collected
private void RegisterApi(LuaCFunction callback, string name)
{
Expand Down Expand Up @@ -434,6 +441,7 @@ public void DoModFiles(string[] modorder, string fileName, IProgress<(string, st
continue;
Console.WriteLine("Executing " + mod + "/" + fileName);
Exec(bytes, mod, fileName);
RunModFix(mod, fileName);
}
}

Expand Down