-
Notifications
You must be signed in to change notification settings - Fork 21
Running Code on Files
Synthlight edited this page Jan 9, 2026
·
2 revisions
A minimal example of just the function contents without the boilerplate around it:
var entryObject = file.rsz.GetEntryObject<App_user_data_ItemData>();
var entries = entryObject.Values.Cast<App_user_data_ItemData_cData>(); // Because these files always wind up with lists of the base class `Ace_user_data_ExcelUserData_cData`.
foreach (var item in entries) {
item.SellPrice = 0;
}And the full file if you wanted to run it like this instead:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using RE_Editor.Common;
using RE_Editor.Common.Data;
using RE_Editor.Common.Models;
using RE_Editor.Constants;
using RE_Editor.Models;
using RE_Editor.Models.Enums;
using RE_Editor.Models.Structs;
using RE_Editor.Util;
using RE_Editor.Windows;
namespace RE_Editor.Mods;
public static class RuntimeEdits {
public static void DoStuff(ReDataFile file) {
var entryObject = file.rsz.GetEntryObject<App_user_data_ItemData>();
var entries = entryObject.Values.Cast<App_user_data_ItemData_cData>(); // Because these files always wind up with lists of the base class `Ace_user_data_ExcelUserData_cData`.
foreach (var item in entries) {
item.SellPrice = 0;
}
}
}Both do the exact same thing.
And here's an example of adding entries to the shop list:
using RE_Editor.Common.Models;
using RE_Editor.Constants;
using RE_Editor.Models.Enums;
using RE_Editor.Models.Structs;
namespace RE_Editor.Mods;
public static class RuntimeEdits {
public static void DoStuff(ReDataFile file) {
var entryObject = file.rsz.GetEntryObject<App_user_data_ItemShopData>();
entryObject.Values.Add(CreateItem(file.rsz, (int) ItemConstants.MAX_POTION));
entryObject.Values.Add(CreateItem(file.rsz, (int) ItemConstants.ARKVELD_GEM));
for (var i = 0; i < entryObject.Values.Count; i++) {
var shopItem = (App_user_data_ItemShopData_cData) entryObject.Values[i];
shopItem._Index = i; // Fix indexes so they're all sequential.
}
}
public static App_user_data_ItemShopData_cData CreateItem(RSZ rsz, int itemId) {
var shopEntry = App_user_data_ItemShopData_cData.Create(rsz);
shopEntry.ItemId = itemId;
shopEntry.StoryPackage = App_StoryPackageFlag_TYPE_Fixed.INVALID;
shopEntry.IsSaleTarget = true;
shopEntry._Index = 0; // Fix later. (0 is also the default so this line isn't even needed.)
return shopEntry;
}
}Instancing objects is kinda cursed. You have to call {the type}.Create(rsz) and should never instance it directly.
(Where you get the rsz instance from doesn't matter so much, it's the same reference for pretty much all objects in the ReDataFile file.)
So long as your code doesn't start with using or namespace, it will be wrapped in boilerplate like so before it is run:
var fullCode = $$"""
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using RE_Editor.Common;
using RE_Editor.Common.Data;
using RE_Editor.Common.Models;
using RE_Editor.Constants;
using RE_Editor.Models;
using RE_Editor.Models.Enums;
using RE_Editor.Models.Structs;
using RE_Editor.Util;
using RE_Editor.Windows;
namespace RE_Editor.Mods;
public static class RuntimeEdits {
public static void DoStuff(ReDataFile file) {
{{codeFragment}}
}
}
""";You can add whatever methods you want, but the entry point will always be the static DoStuff method on the class RE_Editor.Mods.RuntimeEdits.