Skip to content

Commit

Permalink
Merge pull request #6 from ClonkAndre/dev
Browse files Browse the repository at this point in the history
Move dev into main
  • Loading branch information
ClonkAndre authored Oct 18, 2024
2 parents 8571f42 + 17cce0d commit 49263b1
Show file tree
Hide file tree
Showing 13 changed files with 2,887 additions and 426 deletions.
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
A simple traffic loader for GTA IV.
# Simple Traffic Loader
This is a simple traffic loader for GTA IV which aims to eliminate the famous taxi bug while also delivering some extra features.

[Download Version 1.1 here](https://www.gtainside.com/gta4/mods/157022-simple-traffic-loader/)
## Features
- Custom vehicle loading groups.
- Manual and automatic vehicle budget overrider.

Feel free to contribute to this traffic loader.
## Requirements
- [IV-SDK .NET](https://github.com/ClonkAndre/IV-SDK-DotNet)
- [ClonksCodingLib.GTAIV](https://github.com/ClonkAndre/ClonksCodingLib.GTAIV)

## Other Links
GTAForums: TODO
GTAInside (ONLY OLD VERSION FOR NOW): TODO
LCPDFR.com (ONLY OLD VERSION FOR NOW): TODO

## How to Contribute
This project was built using a private SDK.
If you want to contribute on this project, it is recommended to use the Open-Source [IV-SDK](https://github.com/Zolika1351/iv-sdk).
The 1.0 and 1.1 versions were built using a private SDK.
If you want to work on those versions, it is recommended to use the Open-Source [IV-SDK](https://github.com/Zolika1351/iv-sdk).

Do you have an idea to improve this mod, or did you happen to run into a bug? Please share your idea or the bug you found in the [issues](https://github.com/ClonkAndre/Simple-Traffic-Loader/issues) page, or even better: feel free to fork and contribute to this project with a [Pull Request](https://github.com/ClonkAndre/Simple-Traffic-Loader/pulls).

25 changes: 25 additions & 0 deletions SimpleTrafficLoader/SimpleTrafficLoader.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleTrafficLoader", "SimpleTrafficLoader\SimpleTrafficLoader.csproj", "{21A832B6-31FF-4483-9727-6C26632097F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{21A832B6-31FF-4483-9727-6C26632097F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21A832B6-31FF-4483-9727-6C26632097F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21A832B6-31FF-4483-9727-6C26632097F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21A832B6-31FF-4483-9727-6C26632097F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {549C0F41-A248-49CF-B404-F7E33E940461}
EndGlobalSection
EndGlobal
36 changes: 36 additions & 0 deletions SimpleTrafficLoader/SimpleTrafficLoader/Classes/Logging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using IVSDKDotNet;

namespace SimpleTrafficLoader.Classes
{
internal class Logging
{

#if DEBUG
public static bool EnableDebugLogging = true;
#else
public static bool EnableDebugLogging = false;
#endif

public static void Log(string str, params object[] args)
{
IVGame.Console.Print(string.Format("[SimpleTrafficLoader] {0}", string.Format(str, args)));
}
public static void LogWarning(string str, params object[] args)
{
IVGame.Console.PrintWarning(string.Format("[SimpleTrafficLoader] {0}", string.Format(str, args)));
}
public static void LogError(string str, params object[] args)
{
IVGame.Console.PrintError(string.Format("[SimpleTrafficLoader] {0}", string.Format(str, args)));
}

public static void LogDebug(string str, params object[] args)
{
#if DEBUG
if (EnableDebugLogging)
IVGame.Console.Print(string.Format("[SimpleTrafficLoader] [DEBUG] {0}", string.Format(str, args)));
#endif
}

}
}
36 changes: 36 additions & 0 deletions SimpleTrafficLoader/SimpleTrafficLoader/Classes/ModSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using IVSDKDotNet;
using IVSDKDotNet.Attributes;

namespace SimpleTrafficLoader
{
[ShowStaticFieldsInInspector()]
internal class ModSettings
{

#region Variables
// General
public static bool UnloadAllGroupsWhenModUnloads;
public static int MaxLoadedGroups;
public static string LoadGroupByDefault;
public static bool ForceLoadModels;

// Budget
public static bool AutomaticallyDetermineVehicleBudget;
public static uint VehicleBudgetOverride;
#endregion

public static void Load(SettingsFile settings)
{
// General
UnloadAllGroupsWhenModUnloads = settings.GetBoolean("General", "UnloadAllGroupsWhenModUnloads", true);
MaxLoadedGroups = settings.GetInteger("General", "MaxLoadedGroups", 5);
LoadGroupByDefault = settings.GetValue("General", "LoadGroup", "Default.json");
ForceLoadModels = settings.GetBoolean("General", "ForceLoadModels", false);

// Budget
AutomaticallyDetermineVehicleBudget = settings.GetBoolean("Budget", "AutomaticallyDetermineVehicleBudget", true);
uint.TryParse(settings.GetValue("Budget", "VehicleBudgetOverride", "0"), out VehicleBudgetOverride);
}

}
}
176 changes: 176 additions & 0 deletions SimpleTrafficLoader/SimpleTrafficLoader/Classes/SpawnGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using System;
using System.Collections.Generic;
using System.Linq;

using CCL.GTAIV;

using IVSDKDotNet;
using IVSDKDotNet.Attributes;
using static IVSDKDotNet.Native.Natives;

namespace SimpleTrafficLoader.Classes
{
internal class SpawnGroup
{

#region Variables
// Details
[ExcludeFromJsonSerialization()] internal Guid ID;
public string GroupName;
[ExcludeFromJsonSerialization()] internal string GroupNameEdit;

// Control
public bool Disabled;
[ExcludeFromJsonSerialization()] internal bool IsGroupActive;
[ExcludeFromJsonSerialization()] internal bool WasUnloadRequested;

// Lists
public List<string> TargetIslands;
public List<string> TargetNeighborhoods;
public List<string> ModelsToLoad;
public List<string> LoadPolicies;
[ExcludeFromJsonSerialization()] private List<NativeModel> theNativeModels;
#endregion

#region Constructor
public SpawnGroup()
{
// Generate random ID for this group
ID = Guid.NewGuid();

// Lists
theNativeModels = new List<NativeModel>();
}
#endregion

#region Methods
public void Prepare()
{
// Generate random ID for this group
if (ID == Guid.Empty)
ID = Guid.NewGuid();

GroupNameEdit = GroupName;

// Check and add models that should be loaded in a seperate list
theNativeModels.Clear();

for (int i = 0; i < ModelsToLoad.Count; i++)
{
string model = ModelsToLoad[i];

int modelHash = 0;

// Check if model name was given or the model hash
if (!int.TryParse(model, out modelHash))
{
modelHash = (int)RAGE.AtStringHash(model);
}

// Check stuff
if (modelHash == 0)
continue;
if (!IS_MODEL_IN_CDIMAGE(modelHash))
continue;

// Add model to list
theNativeModels.Add(new NativeModel(modelHash));
}
}

public void LoadModels()
{
if (!CanDoStuff())
return;

// If group is unloading then prevent any models of this group from loading
if (WasUnloadRequested)
return;

// If models are already loaded then return
if (AreAllModelsLoaded())
return;

Logging.LogDebug("- - - About to LOAD models of group '{0}'! - - -", GroupName);

// Load models
for (int i = 0; i < theNativeModels.Count; i++)
{
NativeModel model = theNativeModels[i];

// If model is already loaded then skip
if (model.IsInMemory)
continue;

// Get model hash
int modelHash = (int)model.Hash;

// Request/Load this model
if (!ModSettings.ForceLoadModels)
{
// Load models one-by-one
IVStreaming.ScriptRequestModel(modelHash);
IVStreaming.LoadAllRequestedModels(false);
return;
}
else
{
// Request model to be loaded instantly
IVStreaming.ScriptRequestModel(modelHash);
}
}

// Load all requested models instantly
IVStreaming.LoadAllRequestedModels(false);
}
public void UnloadModels()
{
if (!CanDoStuff())
return;

// If models are already unloaded then return
if (!AreAllModelsLoaded())
return;

// If unload was already requested then return
if (WasUnloadRequested)
return;

WasUnloadRequested = true;

Logging.LogDebug("- - - About to UNLOAD group '{0}'! - - -", GroupName);

// Mark loaded models as no longer needed
// This might take a few seconds for them to actually get unloaded
for (int i = 0; i < theNativeModels.Count; i++)
{
NativeModel model = theNativeModels[i];

// If model is already unloaded then skip
if (!model.IsInMemory)
continue;

model.MarkAsNoLongerNeeded();
}

IsGroupActive = false;
WasUnloadRequested = false;
}
#endregion

#region Functions
public bool AreAllModelsLoaded()
{
if (theNativeModels.Count == 0)
return false;

return theNativeModels.All(x => x.IsInMemory);
}
public bool CanDoStuff()
{
return IsGroupActive && theNativeModels.Count != 0;
}
#endregion

}
}
14 changes: 14 additions & 0 deletions SimpleTrafficLoader/SimpleTrafficLoader/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace SimpleTrafficLoader
{

public enum Island
{
Unknown,
Alderney,
Algonquin,
Bohan,
Dukes,
Broker
}

}
Loading

0 comments on commit 49263b1

Please sign in to comment.