Skip to content
Merged
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
52 changes: 50 additions & 2 deletions generator/schema_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,41 @@
"SchemaFixedString"
]

dangerous_fields = [
"m_bIsValveDS",
"m_bIsQuestEligible",
"m_iEntityLevel",
"m_iItemIDHigh",
"m_iItemIDLow",
"m_iAccountID",
"m_iEntityQuality",
"m_bInitialized",
"m_szCustomName",
"m_iAttributeDefinitionIndex",
"m_iRawValue32",
"m_iRawInitialValue32",
"m_flValue",
"m_flInitialValue",
"m_bSetBonus",
"m_nRefundableCurrency",
"m_OriginalOwnerXuidLow",
"m_OriginalOwnerXuidHigh",
"m_nFallbackPaintKit",
"m_nFallbackSeed",
"m_flFallbackWear",
"m_nFallbackStatTrak",
"m_iCompetitiveWins",
"m_iCompetitiveRanking",
"m_iCompetitiveRankType",
"m_iCompetitiveRankingPredicted_Win",
"m_iCompetitiveRankingPredicted_Loss",
"m_iCompetitiveRankingPredicted_Tie",
"m_nActiveCoinRank",
"m_nMusicID"
]

found_dangerous_fields = []

def render_template(template, params):
for param, value in params.items():
template = template.replace(f"${param}$", str(value))
Expand Down Expand Up @@ -89,6 +124,12 @@ def write_class(self):
names.append(field_info["NAME"])

field_info["REF_METHOD"] = "Deref" if field_info["KIND"] == "ptr" else "AsRef"
if field["name"] in dangerous_fields:
found_dangerous_fields.append({
"class": self.class_name,
"field": field["name"],
"hash": field_info["HASH"]
})

if field_info["IS_NETWORKED"] == "true":
updators.append(render_template(self.class_updator_template, field_info))
Expand Down Expand Up @@ -199,7 +240,7 @@ def write_enum(self):
for field in self.class_def["fields"]:
value = field["value"] if field["value"] != -1 else f"{type}.MaxValue"
value = value if value != -2 else f"{type}.MaxValue - 1"
fields.append(f" {field["name"]} = {value},")
fields.append(f" {field['name']} = {value},")

params = {
"ENUM_NAME": self.class_name,
Expand Down Expand Up @@ -229,4 +270,11 @@ def write_enum(self):
continue

writer = Writer(enum_def, all_class_names, all_enum_names)
writer.write_enum()
writer.write_enum()

if found_dangerous_fields:
print("\n")
print(" private static readonly HashSet<ulong> dangerousFields = new() {")
for item in found_dangerous_fields:
print(f" {item['hash']}, // {item['class']}.{item['field']}")
print(" };")
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
public $INTERFACE_TYPE$ $NAME$ {
public $INTERFACE_TYPE$ $NAME$ {
get => new $IMPL_TYPE$(_Handle, $HASH$, $ELEMENT_COUNT$, $ELEMENT_SIZE$, $ELEMENT_ALIGNMENT$);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public string $NAME$ {
public string $NAME$ {
get {
var ptr = _Handle + Schema.GetOffset($HASH$);
return Schema.GetString(ptr);
Expand Down
33 changes: 33 additions & 0 deletions managed/src/SwiftlyS2.Core/Modules/CommandLine/CommandLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using SwiftlyS2.Core.Natives;
using SwiftlyS2.Shared.CommandLine;

namespace SwiftlyS2.Core.CommandLine;

internal class CommandLineService : ICommandLine
{
public int ParameterCount => NativeCommandLine.GetParameterCount();

public string CommandLine => NativeCommandLine.GetCommandLine();

public bool HasParameters => NativeCommandLine.HasParameters();

public float GetParameterFloat(string paramName, float defaultValue = 0)
{
return NativeCommandLine.GetParameterValueFloat(paramName, defaultValue);
}

public int GetParameterInt(string paramName, int defaultValue = 0)
{
return NativeCommandLine.GetParameterValueInt(paramName, defaultValue);
}

public string GetParameterString(string paramName, string defaultValue = "")
{
return NativeCommandLine.GetParameterValueString(paramName, defaultValue);
}

public bool HasParameter(string paramName)
{
return NativeCommandLine.HasParameter(paramName);
}
}
12 changes: 8 additions & 4 deletions managed/src/SwiftlyS2.Core/Modules/Engine/EngineService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using SwiftlyS2.Shared;
using SwiftlyS2.Core.Natives;
using SwiftlyS2.Shared.Services;
using SwiftlyS2.Core.Extensions;
using SwiftlyS2.Shared.Natives;

namespace SwiftlyS2.Core.Services;

Expand All @@ -15,13 +17,15 @@ public EngineService(CommandTrackerManager commandTrackedManager)

public string ServerIP => NativeEngineHelpers.GetServerIP();

public string Map => NativeEngineHelpers.GetMap();
public ref CGlobalVars GlobalVars => ref NativeEngineHelpers.GetGlobalVars().AsRef<CGlobalVars>();

public int MaxPlayers => NativeEngineHelpers.GetMaxPlayers();
public string Map => GlobalVars.MapName.ToString() ?? string.Empty;

public float CurrentTime => NativeEngineHelpers.GetServerCurrentTime();
public int MaxPlayers => GlobalVars.MaxClients;

public int TickCount => NativeEngineHelpers.GetServerTickCount();
public float CurrentTime => GlobalVars.CurrentTime;

public int TickCount => GlobalVars.TickCount;

public void ExecuteCommand(string command)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace SwiftlyS2.Core.Events;
internal class OnCommandExecuteHookEvent : IOnCommandExecuteHookEvent
{
public required string OriginalName { get; init; }
public required string[] OriginalArgs { get; init; }
public string CommandName { get; set; } = string.Empty;

public required HookMode HookMode { get; init; }
Expand Down
8 changes: 4 additions & 4 deletions managed/src/SwiftlyS2.Core/Modules/Menus/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void UseSelection(IPlayer player)
buttonOption.OnClick?.Invoke(player);
if (buttonOption.CloseOnSelect)
{
Close(player);
MenuManager.CloseMenuForPlayer(player);
}
break;
}
Expand All @@ -255,7 +255,7 @@ public void UseSelection(IPlayer player)

if (closeAfter && player.IsValid)
{
Close(player);
MenuManager.CloseMenuForPlayer(player);
}
}
});
Expand All @@ -266,7 +266,7 @@ public void UseSelection(IPlayer player)
toggle.Toggle(player);
if (toggle.CloseOnSelect)
{
Close(player);
MenuManager.CloseMenuForPlayer(player);
}
else
{
Expand All @@ -280,7 +280,7 @@ public void UseSelection(IPlayer player)
if (subMenu != null)
{
subMenu.Parent = this;
subMenu.Show(player);
MenuManager.OpenMenu(player, subMenu);
}
break;
}
Expand Down
11 changes: 8 additions & 3 deletions managed/src/SwiftlyS2.Core/Modules/Plugins/SwiftlyCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using SwiftlyS2.Core.GameEvents;
using SwiftlyS2.Core.Misc;
using SwiftlyS2.Core.NetMessages;
using SwiftlyS2.Core.Services;
using SwiftlyS2.Shared;
using SwiftlyS2.Shared.Events;
using SwiftlyS2.Shared.GameEvents;
Expand All @@ -26,9 +25,7 @@
using SwiftlyS2.Core.Memory;
using SwiftlyS2.Shared.Scheduler;
using SwiftlyS2.Core.Scheduler;
using SwiftlyS2.Core.Plugins;
using SwiftlyS2.Core.Database;
using SwiftlyS2.Core.Engine;
using SwiftlyS2.Shared.Database;
using SwiftlyS2.Core.Translations;
using SwiftlyS2.Core.Permissions;
Expand All @@ -38,6 +35,8 @@
using SwiftlyS2.Shared.Players;
using SwiftlyS2.Shared.Translation;
using SwiftlyS2.Core.Players;
using SwiftlyS2.Shared.CommandLine;
using SwiftlyS2.Core.CommandLine;

namespace SwiftlyS2.Core.Services;

Expand Down Expand Up @@ -70,6 +69,7 @@ internal class SwiftlyCore : ISwiftlyCore, IDisposable
public PermissionManager PermissionManager { get; init; }
public RegistratorService RegistratorService { get; init; }
public MenuManager MenuManager { get; init; }
public CommandLineService CommandLineService { get; init; }
public string ContextBasePath { get; init; }
public SwiftlyCore(string contextId, string contextBaseDirectory, PluginMetadata? pluginManifest, Type contextType, IServiceProvider coreProvider)
{
Expand Down Expand Up @@ -102,13 +102,15 @@ public SwiftlyCore(string contextId, string contextBaseDirectory, PluginMetadata
.AddSingleton<ConVarService>()
.AddSingleton<MemoryService>()
.AddSingleton<GameDataService>()
.AddSingleton<PlayerManagerService>()
.AddSingleton<ContextedProfilerService>()
.AddSingleton<SchedulerService>()
.AddSingleton<DatabaseService>()
.AddSingleton<TranslationService>()
.AddSingleton<Localizer>(provider => provider.GetRequiredService<TranslationService>().GetLocalizer())
.AddSingleton<RegistratorService>()
.AddSingleton<MenuManager>()
.AddSingleton<CommandLineService>()
.AddSingleton<IPermissionManager>(provider => provider.GetRequiredService<PermissionManager>())

.AddSingleton<IEventSubscriber>(provider => provider.GetRequiredService<EventSubscriber>())
Expand All @@ -131,6 +133,7 @@ public SwiftlyCore(string contextId, string contextBaseDirectory, PluginMetadata
.AddSingleton<ILocalizer>(provider => provider.GetRequiredService<TranslationService>().GetLocalizer())
.AddSingleton<IRegistratorService>(provider => provider.GetRequiredService<RegistratorService>())
.AddSingleton<IMenuManager>(provider => provider.GetRequiredService<MenuManager>())
.AddSingleton<ICommandLine>(provider => provider.GetRequiredService<CommandLineService>())

.AddLogging(
builder =>
Expand Down Expand Up @@ -164,6 +167,7 @@ public SwiftlyCore(string contextId, string contextBaseDirectory, PluginMetadata
PermissionManager = _ServiceProvider.GetRequiredService<PermissionManager>();
RegistratorService = _ServiceProvider.GetRequiredService<RegistratorService>();
MenuManager = _ServiceProvider.GetRequiredService<MenuManager>();
CommandLineService = _ServiceProvider.GetRequiredService<CommandLineService>();
Logger = LoggerFactory.CreateLogger(contextType);
}

Expand Down Expand Up @@ -206,4 +210,5 @@ public void Dispose()
IRegistratorService ISwiftlyCore.Registrator => RegistratorService;
IMenuManager ISwiftlyCore.Menus => MenuManager;
string ISwiftlyCore.PluginPath => ContextBasePath;
ICommandLine ISwiftlyCore.CommandLine => CommandLineService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SwiftlyS2.Shared.SchemaDefinitions;

public partial interface CAttributeList
{
/// <summary>
/// Sets or adds an attribute to the attribute list.
/// </summary>
public void SetOrAddAttribute(string attributeName, float value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using SwiftlyS2.Core.Natives;
using SwiftlyS2.Shared.SchemaDefinitions;

namespace SwiftlyS2.Core.SchemaDefinitions;

internal partial class CAttributeListImpl : CAttributeList
{
public void SetOrAddAttribute(string attributeName, float value)
{
GameFunctions.SetOrAddAttribute(Address, attributeName, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ public partial interface CBaseModelEntity
/// </summary>
/// <param name="model">The model path to be used.</param>
public void SetModel(string model);

/// <summary>
/// Sets the bodygroup to the entity.
/// </summary>
public void SetBodygroupByName(string group, int value);

/// <summary>
/// Sets the scale of the entity.
/// </summary>
public void SetScale(float scale);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,19 @@ public void SetModel(string model)
{
GameFunctions.SetModel(Address, model);
}

public void SetBodygroupByName(string group, int value)
{
AcceptInput("SetBodygroup", $"{group},{value}");
}

public void SetScale(float scale)
{
var skeletonInstance = CBodyComponent?.SceneNode?.GetSkeletonInstance();
if (skeletonInstance == null) return;

skeletonInstance.Scale = scale;
AcceptInput("SetScale", scale);
CBodyComponentUpdated();
}
}
Loading
Loading