暂存7
This commit is contained in:
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -14,16 +14,19 @@ namespace WulaFallenEmpire
|
||||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
var codes = new List<CodeInstruction>(instructions);
|
||||
// 找到 MapPortal.Map 属性的 getter 方法
|
||||
var mapPropertyGetter = AccessTools.PropertyGetter(typeof(MapPortal), "Map");
|
||||
// 找到 Thing.Map 属性的 getter 方法 (MapPortal 继承自 Thing)
|
||||
var mapPropertyGetter = AccessTools.PropertyGetter(typeof(Verse.Thing), "Map");
|
||||
// 找到我们自定义的静态方法,它将返回正确的 Map
|
||||
var getShuttleMapMethod = AccessTools.Method(typeof(DialogEnterPortal_CalculateAndRecacheTransferables_Patch), nameof(GetShuttleMap));
|
||||
|
||||
Log.Message("[WULA-DEBUG] Transpiler for CalculateAndRecacheTransferables started.");
|
||||
|
||||
for (int i = 0; i < codes.Count; i++)
|
||||
{
|
||||
// 查找对 MapPortal.Map 的 get 访问
|
||||
if (codes[i].opcode == OpCodes.Callvirt && codes[i].operand is MethodInfo method && method == mapPropertyGetter)
|
||||
// 查找对 Thing.Map 的 get 访问
|
||||
if (codes[i].opcode == OpCodes.Call && codes[i].operand is MethodInfo method && method == mapPropertyGetter)
|
||||
{
|
||||
Log.Message($"[WULA-DEBUG] Transpiler found Thing.Map getter at index {i}.");
|
||||
// 替换为调用我们的静态方法
|
||||
yield return new CodeInstruction(OpCodes.Call, getShuttleMapMethod);
|
||||
}
|
||||
@@ -32,20 +35,60 @@ namespace WulaFallenEmpire
|
||||
yield return codes[i];
|
||||
}
|
||||
}
|
||||
Log.Message("[WULA-DEBUG] Transpiler for CalculateAndRecacheTransferables finished.");
|
||||
}
|
||||
|
||||
// 这个静态方法将由 Transpiler 注入,用于返回正确的 Map
|
||||
// 参数 portalInstance 是原始方法中对 MapPortal 实例的引用
|
||||
public static Map GetShuttleMap(MapPortal portalInstance)
|
||||
{
|
||||
if (portalInstance is ShuttlePortalAdapter adapter && adapter.shuttle != null)
|
||||
if (portalInstance is ShuttlePortalAdapter adapter)
|
||||
{
|
||||
return adapter.shuttle.Map;
|
||||
Log.Message($"[WULA-DEBUG] portalInstance is ShuttlePortalAdapter. adapter.shuttle: {adapter.shuttle?.def.defName ?? "null"}");
|
||||
if (adapter.shuttle != null)
|
||||
{
|
||||
// 确保 adapter.shuttle.Map 不为 null
|
||||
if (adapter.shuttle.Map != null)
|
||||
{
|
||||
return adapter.shuttle.Map;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"[WULA] Shuttle {adapter.shuttle.def.defName} is not spawned on any map when trying to get its map.");
|
||||
return null; // 返回 null,让后续代码处理
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果不是我们的适配器或者 shuttle 为空,则返回原始 MapPortal 的 Map
|
||||
// 我们需要直接访问 Thing 类的 Map 属性,这是 MapPortal 继承的
|
||||
|
||||
// 如果不是我们的适配器,或者适配器中的 shuttle 为空,
|
||||
// 则尝试获取原始 MapPortal 的 Map。
|
||||
// 这里需要非常小心,因为 portalInstance 本身也可能是 null,
|
||||
// 或者它继承自 Thing 的 Map 属性是 null。
|
||||
if (portalInstance == null)
|
||||
{
|
||||
Log.Error("[WULA] GetShuttleMap received a null portalInstance.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var originalMapGetter = AccessTools.PropertyGetter(typeof(Thing), "Map");
|
||||
return (Map)originalMapGetter.Invoke(portalInstance, null);
|
||||
if (originalMapGetter == null)
|
||||
{
|
||||
Log.Error("[WULA] Could not get Thing.Map getter via AccessTools.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Map result = null;
|
||||
try
|
||||
{
|
||||
result = (Map)originalMapGetter.Invoke(portalInstance, null);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log.Error($"[WULA] Error invoking original Thing.Map getter: {ex.Message}");
|
||||
}
|
||||
|
||||
Log.Message($"[WULA-DEBUG] GetShuttleMap returning original Map. Result: {result?.ToString() ?? "null"}");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,22 +24,22 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
base.PostSpawnSetup(respawningAfterLoad);
|
||||
|
||||
Log.Message($"[WULA-DEBUG] CompPocketMapPortal.PostSpawnSetup called. Parent: {parent?.def?.defName ?? "null"}");
|
||||
|
||||
// 检查父对象是否是穿梭机
|
||||
if (ParentShuttle == null)
|
||||
{
|
||||
Log.Error($"[WULA] CompPocketMapPortal attached to non-shuttle building: {parent?.def?.defName}");
|
||||
return; // Early exit if parent is not a shuttle
|
||||
}
|
||||
else
|
||||
|
||||
// 创建MapPortal适配器,并设置其地图和位置信息
|
||||
portalAdapter = new ShuttlePortalAdapter(ParentShuttle);
|
||||
// 确保 portalAdapter 的 shuttle 引用被正确设置
|
||||
if (portalAdapter != null)
|
||||
{
|
||||
// 创建MapPortal适配器,并设置其地图和位置信息
|
||||
portalAdapter = new ShuttlePortalAdapter(ParentShuttle);
|
||||
// 确保 portalAdapter 的 shuttle 引用被正确设置
|
||||
// 并在 PostSpawnSetup 中设置 MapPortal 基类的地图和位置信息
|
||||
// 确保 portalAdapter 的 shuttle 引用被正确设置
|
||||
if (portalAdapter != null)
|
||||
{
|
||||
portalAdapter.shuttle = ParentShuttle;
|
||||
}
|
||||
portalAdapter.shuttle = ParentShuttle;
|
||||
Log.Message($"[WULA-DEBUG] portalAdapter.shuttle set in PostSpawnSetup: {portalAdapter.shuttle?.def.defName ?? "null"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,7 @@ namespace WulaFallenEmpire
|
||||
|
||||
if (portalAdapter != null)
|
||||
{
|
||||
Log.Message($"[WULA-DEBUG] Opening Dialog_EnterPortal with portalAdapter. Type: {portalAdapter.GetType().Name}. Shuttle: {portalAdapter.shuttle?.def.defName ?? "null"}");
|
||||
var dialog = new Dialog_EnterPortal(portalAdapter);
|
||||
Find.WindowStack.Add(dialog);
|
||||
}
|
||||
@@ -349,8 +350,6 @@ namespace WulaFallenEmpire
|
||||
// def.portal?.traverseSound?.PlayOneShot(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写进入按钮文本
|
||||
/// </summary>
|
||||
public override string EnterString => "WULA.PocketSpace.Enter".Translate();
|
||||
|
||||
Reference in New Issue
Block a user