Skip to content

Commit

Permalink
最新版で動かなくなっていたのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
TORISOUP committed Aug 17, 2024
1 parent ef70a61 commit 71d02e7
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Inferno/ChaosMode/ChaosMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected override void Setup()
private void CitizenChaos()
{
if (!PlayerPed.IsSafeExist()) return;

//まだ処理をしていない市民に対してコルーチンを回す
var nearPeds =
CachedPeds.Where(x => x.IsSafeExist() && x.IsInRangeOf(PlayerPed.Position, chaosModeSetting.Radius));
Expand Down
10 changes: 2 additions & 8 deletions Inferno/Inferno.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="ScriptHookVDotNet2, Version=2.10.3.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>X:\Project2\GTA\InfernoProject\Inferno\Inferno\ScriptHookVDotNet2.dll</HintPath>
<Reference Include="ScriptHookVDotNet2, Version=2.11.6.0, Culture=neutral, processorArchitecture=Amd64">
<HintPath>..\packages\ScriptHookVDotNet2.2.11.6\lib\net48\ScriptHookVDotNet2.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand All @@ -72,10 +71,6 @@
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\ReactiveProperty.0.3.2.0\lib\NET40\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="System.XML" />
<Reference Include="UniRx, Version=5.4.1.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -222,7 +217,6 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 2 additions & 2 deletions Inferno/InfernoScripts/InfernoCore/Debug/DebugLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DebugLogger
public DebugLogger(string logPath)
{
this._logPath = logPath;
_encoding = Encoding.GetEncoding("Shift_JIS");
_encoding = Encoding.GetEncoding("UTF-8");
}

/// <summary>
Expand All @@ -35,7 +35,7 @@ private void WriteToText(string message)

public void Log(string message)
{
var sendMessage = String.Format("[{0}] {1}", DateTime.Now, message);
var sendMessage = $"[{DateTime.Now}] {message}";
WriteToText(sendMessage);
}
}
Expand Down
45 changes: 31 additions & 14 deletions Inferno/InfernoScripts/InfernoCore/InfernoCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public sealed class InfernoCore : Script
private static readonly Subject<KeyEventArgs> OnKeyDownSubject = new Subject<KeyEventArgs>();
private static readonly Subject<IEventMessage> EventMessageSubject = new Subject<IEventMessage>();

private DateTimeOffset _lastUpdate;

/// <summary>
/// イベントメッセージを発行する
/// </summary>
Expand All @@ -36,22 +38,32 @@ public static void Publish(IEventMessage message)
/// <summary>
/// 周辺市民
/// </summary>
public ReactiveProperty<Ped[]> PedsNearPlayer = new ReactiveProperty<Ped[]>();
public IReadOnlyReactiveProperty<Ped[]> PedsNearPlayer => _nearPeds;

private readonly ReactiveProperty<Ped[]> _nearPeds = new ReactiveProperty<Ped[]>();

/// <summary>
/// 周辺車両
/// </summary>
public ReactiveProperty<Vehicle[]> VehicleNearPlayer = new ReactiveProperty<Vehicle[]>();
public IReadOnlyReactiveProperty<Vehicle[]> VehicleNearPlayer => _nearVehicle;

private readonly ReactiveProperty<Vehicle[]> _nearVehicle = new ReactiveProperty<Vehicle[]>();


/// <summary>
/// プレイヤ
/// </summary>
public ReactiveProperty<Ped> PlayerPed = new ReactiveProperty<Ped>();
public IReadOnlyReactiveProperty<Ped> PlayerPed => _playerPed;

private readonly ReactiveProperty<Ped> _playerPed = new ReactiveProperty<Ped>();


/// <summary>
/// プレイヤの乗ってる車両
/// </summary>
public ReactiveProperty<Vehicle> PlayerVehicle = new ReactiveProperty<Vehicle>();
public IReadOnlyReactiveProperty<Vehicle> PlayerVehicle => _playerVehicle;

private readonly ReactiveProperty<Vehicle> _playerVehicle = new ReactiveProperty<Vehicle>();

/// <summary>
/// 25ms周期のTick
Expand All @@ -69,16 +81,19 @@ public InfernoCore()

_debugLogger = new DebugLogger(@"InfernoScript.log");

_lastUpdate = DateTimeOffset.Now;

//100ms周期でイベントを飛ばす
Interval = 100;
Observable.FromEventPattern<EventHandler, EventArgs>(h => h.Invoke, h => Tick += h, h => Tick -= h)
Observable
.FromEventPattern<EventHandler, EventArgs>(h => h.Invoke, h => Tick += h, h => Tick -= h)
.Select(_ => Unit.Default)
.Multicast(OnTickSubject)
.Connect();

//キー入力
Observable.FromEventPattern<KeyEventHandler, KeyEventArgs>(h => h.Invoke, h => KeyDown += h,
h => KeyDown -= h)
h => KeyDown -= h)
.Select(e => e.EventArgs)
.Multicast(OnKeyDownSubject)
.Connect();
Expand All @@ -93,27 +108,29 @@ public InfernoCore()
/// </summary>
private void UpdatePedsAndVehiclesList()
{
// 1秒おきにキャッシュ更新
if (DateTimeOffset.Now - _lastUpdate < TimeSpan.FromMilliseconds(1000)) return;
_lastUpdate = DateTimeOffset.Now;

try
{
var player = Game.Player;
var ped = player?.Character;
if (!ped.IsSafeExist()) return;
PlayerPed.Value = ped;
PedsNearPlayer.Value = World.GetNearbyPeds(ped, 500);
VehicleNearPlayer.Value = World.GetNearbyVehicles(ped, 500);
PlayerVehicle.Value = ped?.CurrentVehicle;
_playerPed.Value = ped;
_nearPeds.Value = World.GetNearbyPeds(ped, 500) ?? Array.Empty<Ped>();
_nearVehicle.Value = World.GetNearbyVehicles(ped, 500) ?? Array.Empty<Vehicle>();
_playerVehicle.Value = ped?.CurrentVehicle;
}
catch (Exception e)
{
LogWrite(e.StackTrace);
LogWrite(e.Message + "\n" + e.StackTrace);
}
}

public void LogWrite(string message)
{
_debugLogger.Log(message);
}


}
}
}
40 changes: 21 additions & 19 deletions Inferno/InfernoScripts/InfernoCore/InfernoScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Inferno
/// </summary>
public abstract class InfernoScript : Script
{

protected Random Random = new Random();

private readonly ReactiveProperty<bool> _isActiveReactiveProperty = new ReactiveProperty<bool>(false);
Expand All @@ -44,6 +43,7 @@ protected IScheduler InfernoScriptScheduler
{
throw new Exception("設定ファイル名が設定されていません");
}

var loader = new InfernoConfigLoader<T>();
var dto = loader.LoadSettingFile(ConfigFileName);
//バリデーションに引っかかったらデフォルト値を返す
Expand All @@ -62,7 +62,8 @@ protected bool IsActive
/// <summary>
/// IsActiveが変化したことを通知する
/// </summary>
protected UniRx.IObservable<bool> IsActiveAsObservable => _isActiveReactiveProperty.AsObservable().DistinctUntilChanged();
protected UniRx.IObservable<bool> IsActiveAsObservable =>
_isActiveReactiveProperty.AsObservable().DistinctUntilChanged();

#region Chace

Expand All @@ -72,21 +73,18 @@ protected bool IsActive
public Ped PlayerPed => cahcedPlayerPed ?? Game.Player.Character;

private Ped cahcedPlayerPed;
public ReactiveProperty<Vehicle> PlayerVehicle = new ReactiveProperty<Vehicle>();
public readonly ReactiveProperty<Vehicle> PlayerVehicle = new ReactiveProperty<Vehicle>();

private Ped[] _cachedPeds = new Ped[0];

/// <summary>
/// キャッシュされたプレイヤ周辺の市民
/// </summary>
public Ped[] CachedPeds => _cachedPeds;

private Vehicle[] _cachedVehicles = new Vehicle[0];

public Ped[] CachedPeds => InfernoCore.Instance.PedsNearPlayer.Value;

/// <summary>
/// キャッシュされたプレイヤ周辺の車両
/// </summary>
public ReadOnlyCollection<Vehicle> CachedVehicles => Array.AsReadOnly(_cachedVehicles ?? new Vehicle[0]);
public Vehicle[] CachedVehicles => InfernoCore.Instance.VehicleNearPlayer.Value;

#endregion Chace

Expand Down Expand Up @@ -116,9 +114,10 @@ public UniRx.IObservable<KeyEventArgs> OnKeyDownAsObservable
if (_onKeyDownAsObservable != null) return _onKeyDownAsObservable;
_onKeyDownAsObservable =
Observable.FromEventPattern<KeyEventHandler, KeyEventArgs>(h => h.Invoke, h => KeyDown += h,
h => KeyDown -= h)
h => KeyDown -= h)
.Select(e => e.EventArgs)
.Publish().RefCount();
.Publish()
.RefCount();
return _onKeyDownAsObservable;
}
}
Expand Down Expand Up @@ -149,7 +148,8 @@ protected UniRx.IObservable<Unit> CreateInputKeywordAsObservable(string keyword)
.Select(x => x.Aggregate((p, c) => p + c))
.Where(x => x == keyword.ToUpper()) //入力文字列を比較
.Select(_ => Unit.Default)
.First().Repeat() //1回動作したらBufferをクリア
.First()
.Repeat() //1回動作したらBufferをクリア
.Publish()
.RefCount();
}
Expand All @@ -161,6 +161,7 @@ protected UniRx.IObservable<Unit> CreateTickAsObservable(TimeSpan timeSpan)
{
return OnTickAsObservable.ThrottleFirst(timeSpan, InfernoScriptScheduler).Share();
}

#endregion forEvents

#region forAbort
Expand Down Expand Up @@ -192,11 +193,11 @@ protected UniRx.IObservable<Unit> OnAbortAsync
return _onAbortObservable ??
(_onAbortObservable =
Observable.FromEventPattern<EventHandler, EventArgs>(h => h.Invoke, h => Aborted += h,
h => Aborted -= h).AsUnitObservable());
h => Aborted -= h)
.AsUnitObservable());
}
}


#endregion

#region forCoroutine
Expand All @@ -219,7 +220,6 @@ protected void StopAllCoroutine()
}



/// <summary>
/// 指定秒数待機するIEnumerable
/// </summary>
Expand Down Expand Up @@ -295,15 +295,14 @@ protected InfernoScript()
.First()
.Subscribe(_ =>
{
InfernoCore.Instance.PedsNearPlayer.Subscribe(x => _cachedPeds = x);
InfernoCore.Instance.VehicleNearPlayer.Subscribe(x => _cachedVehicles = x);
InfernoCore.Instance.PlayerPed.Subscribe(x => cahcedPlayerPed = x);
InfernoCore.Instance.PlayerVehicle.Subscribe(x => PlayerVehicle.Value = x);
});

OnTickAsObservable =
Observable.FromEventPattern<EventHandler, EventArgs>(h => h.Invoke, h => Tick += h, h => Tick -= h)
.Select(_ => Unit.Default).Share(); //Subscribeされたらイベントハンドラを登録する
.Select(_ => Unit.Default)
.Share(); //Subscribeされたらイベントハンドラを登録する

OnThinnedTickAsObservable =
OnTickAsObservable.ThrottleFirst(TimeSpan.FromMilliseconds(100), InfernoScriptScheduler)
Expand All @@ -324,6 +323,7 @@ protected InfernoScript()
{
SynchronizationContext.SetSynchronizationContext(InfernoSynchronizationContext);
}

InfernoSynchronizationContext.Update();
});

Expand All @@ -336,6 +336,7 @@ protected InfernoScript()
{
c.Update(100);
}

//完了状態にあるタイマを全て削除
_counterList.RemoveAll(x => x.IsCompleted);
});
Expand All @@ -354,6 +355,7 @@ protected InfernoScript()
{
e.MarkAsNoLongerNeeded();
}

_autoReleaseEntities.Clear();
});

Expand Down Expand Up @@ -385,4 +387,4 @@ public void LogWrite(string message)

#endregion Debug
}
}
}
1 change: 1 addition & 0 deletions Inferno/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<packages>
<package id="Moq" version="4.2.1502.0911" targetFramework="net45" userInstalled="true" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="ScriptHookVDotNet2" version="2.11.6" targetFramework="net48" />
<package id="UniRx" version="5.4.1.0" targetFramework="net452" />
</packages>

0 comments on commit 71d02e7

Please sign in to comment.