Skip to content

Commit

Permalink
Merge branch 'citizenfx:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniGP17 committed Aug 21, 2024
2 parents 962be88 + fbef73f commit 2c9cf2e
Show file tree
Hide file tree
Showing 192 changed files with 7,064 additions and 2,606 deletions.
33 changes: 31 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ build_proot_linux:
stage: build
tags:
- linux
image: mcr.microsoft.com/dotnet/sdk:6.0-alpine3.15
image: registry-internal.fivem.net/cfx/fivem/fivem-builder-linux-alpine:latest
variables:
GIT_SUBMODULE_STRATEGY: normal
GIT_SUBMODULE_DEPTH: 3
# workaround gitlab-ci-multi-runner#2148
GIT_SSL_CAPATH: /etc/ssl/certs/
DOCKER_TLS_CERTDIR: ""
script:
- sh code/tools/ci/build_server_proot.sh
- sh code/tools/ci/build_server_docker_alpine.sh
artifacts:
paths:
- fx.tar.xz
Expand Down Expand Up @@ -371,3 +371,32 @@ redm_upload_review:
needs:
- job: build_client_rdr3
artifacts: true

prebuild_linux_docker_container:
image: docker:24.0
stage: build
tags:
- linux
services:
- docker:24.0-dind
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
GIT_SUBMODULE_STRATEGY: none
DOCKER_IMAGE_NAME: "$CI_REGISTRY_IMAGE/fivem-builder-linux-alpine:latest"
DOCKER_COMMIT_TAG: "$CI_REGISTRY_IMAGE/fivem-builder-linux-alpine:$CI_COMMIT_SHORT_SHA"
before_script:
- docker info
script:
- echo "Building Docker image..."
- docker build -t $DOCKER_IMAGE_NAME -t $DOCKER_COMMIT_TAG -f code/tools/ci/docker-builder/Dockerfile .
- echo "Logging into GitLab Container Registry..."
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- echo "Pushing Docker image to registry with latest tag..."
- docker push $DOCKER_IMAGE_NAME
- echo "Pushing Docker image to registry with commit tag..."
- docker push $DOCKER_COMMIT_TAG
rules:
- when: manual
allow_failure: true

29 changes: 18 additions & 11 deletions code/client/citicore/PatternCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@ static uintptr_t g_currentStub = hook::exe_end();

extern "C"
{
DLL_EXPORT void* AllocateFunctionStubImpl(void* function, int type)
DLL_EXPORT void* AllocateStubMemoryImpl(size_t size)
{
// Try and pick a sensible alignment
size_t alignMask = ((size > 64) ? 16 : 8) - 1;

g_currentStub = (g_currentStub + alignMask) & ~alignMask;

char* code = (char*)g_currentStub + hook::baseAddressDifference;

DWORD oldProtect;
VirtualProtect(code, size, PAGE_EXECUTE_READWRITE, &oldProtect);

g_currentStub += size;

return code;
}

DLL_EXPORT void* AllocateFunctionStubImpl(void* function, int type)
{
char* code = (char*) AllocateStubMemoryImpl(20);

DWORD oldProtect;
VirtualProtect(code, 15, PAGE_EXECUTE_READWRITE, &oldProtect);

Expand All @@ -35,17 +52,7 @@ extern "C"
return code;
}

DLL_EXPORT void* AllocateStubMemoryImpl(size_t size)
{
char* code = (char*)g_currentStub + hook::baseAddressDifference;

DWORD oldProtect;
VirtualProtect(code, size, PAGE_EXECUTE_READWRITE, &oldProtect);

g_currentStub += size;

return code;
}
}
#endif

Expand Down
25 changes: 0 additions & 25 deletions code/client/clrcore-v2/Client/FiveM/Object.cs

This file was deleted.

11 changes: 11 additions & 0 deletions code/client/clrcore-v2/Client/RedM/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Reflection;
using System.Runtime.Versioning;

[assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]
[assembly: AssemblyTitle("CitizenFX.RedM")]

[assembly: AssemblyCompany("The CitizenFX Collective")]
[assembly: AssemblyCopyright("Copyright CitizenFX and contributors, licensed under the FiveM Platform Agreement")]

[assembly: AssemblyVersion("0.0.0.1")]
[assembly: AssemblyFileVersion("0.0.0.1")]
193 changes: 193 additions & 0 deletions code/client/clrcore-v2/Client/RedM/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
using System;
using CitizenFX.Core;
using CitizenFX.Shared;
using CitizenFX.RedM.Native;

namespace CitizenFX.RedM
{
public abstract class Entity : PoolObject , ISpatial , IEquatable<Entity> , IEntity
{
public Entity(int handle) : base(handle)
{
}

/// <summary>
/// Checks if the entity handle is still valid, will only return false after calling Delete on the entity
/// </summary>
/// <value>
/// True if the handle is a non-zero number
/// </value>
public bool IsHandleValid() => Handle != 0;

/// <summary>
/// Gets or sets the health of this <see cref="Entity"/>
/// </summary>
/// <value>
/// The health from 0 - 500 as an integer.
/// </value>
public int Health
{
get => Natives.GetEntityHealth(Handle) - 100;
set => Natives.SetEntityHealth(Handle, value + 100, 0);
}

/// <summary>
/// Gets or sets the position of this <see cref="Entity"/>.
/// </summary>
/// <value>
/// The position in world space.
/// </value>
public Vector3 Position
{
get => Natives.GetEntityCoords(Handle, true, false);
set => Natives.SetEntityCoords(Handle, value.X, value.Y, value.Z, false, false, false, false);
}

/// <summary>
/// Gets or sets the rotation of this <see cref="Entity"/>.
/// </summary>
/// <value>
/// The yaw, pitch, roll rotation values.
/// </value>
public Vector3 Rotation
{
get => Natives.GetEntityRotation(Handle, 2);
set => Natives.SetEntityRotation(Handle, value.X, value.Y, value.Z, 2, true);
}

/// <summary>
/// Gets or sets the heading of this <see cref="Entity"/>.
/// </summary>
/// <value>
/// The heading in degrees.
/// </value>
public float Heading
{
get => Natives.GetEntityHeading(Handle);
set => Natives.SetEntityHeading(Handle, value);
}

/// <summary>
/// Gets or sets a value indicating whether this <see cref="Entity"/> is frozen.
/// </summary>
/// <value>
/// Returns <c>true</c> if this <see cref="Entity"/> is position frozen; otherwise, <c>false</c>.
/// </value>
public bool IsPositionFrozen
{
// TODO: Change this back to the native call whenever `IS_ENTITY_FROZEN` returns a bool instead of a long
get => Natives.Call<bool>(Hash._IS_ENTITY_FROZEN, Handle);
set => Natives.FreezeEntityPosition(Handle, value);
}


/// <summary>
/// Gets or sets the velocity of this <see cref="Entity"/>.
/// </summary>
public Vector3 Velocity
{
get => Natives.GetEntityVelocity(Handle, 0);
set => Natives.SetEntityVelocity(Handle, value.X, value.Y, value.Z);
}

/// <summary>
/// Gets the current model of this entity
/// </summary>
public Model Model => new Model(Natives.GetEntityModel(Handle));

uint Shared.IEntity.Model => Natives.GetEntityModel(Handle);

/// <summary>
/// Gets the current network owner of this entity
/// </summary>
public Shared.Player Owner => new Player(Natives.NetworkGetEntityOwner(Handle));

/// <summary>
/// Gets the network id of this <see cref="Entity" />
/// </summary>
public int NetworkId => Natives.NetworkGetNetworkIdFromEntity(Handle);

/// <summary>
/// Gets if the current <see cref="Entity" /> is networked.
/// </summary>
public bool IsNetworked => Natives.NetworkGetEntityIsNetworked(Handle);

public EntityType Type => (EntityType)Natives.GetEntityType(Handle);

// allow conversion from entity -> int so we can pass to natives
public static implicit operator int(Entity e) => e.Handle;

/// <summary>
/// Determines whether this <see cref="Entity"/> exists.
/// </summary>
/// <returns>Returns <c>true</c> if this <see cref="Entity"/> exists; otherwise, <c>false</c></returns>
public override bool Exists()
{
return IsHandleValid() && Natives.DoesEntityExist(Handle);
}

/// <summary>
/// Gets or sets whether this <see cref="Entity"/> is a persistent entity
/// </summary>
public bool IsMissionEntity
{
get => Natives.IsEntityAMissionEntity(Handle);
set => Natives.SetEntityAsMissionEntity(Handle, false, true);
}

/// <summary>
/// Deletes this <see cref="Entity"/>
/// </summary>
public override void Delete()
{
IsMissionEntity = true;
int handle = Handle;
Natives.DeleteEntity(ref handle);
Handle = handle;
}

/// <summary>
/// Gets the <see cref="StateBag"/> of this <see cref="Entity"/>
/// </summary>
public StateBag State
{
get
{
if (!Natives.NetworkGetEntityIsNetworked(Handle))
{
Natives.EnsureEntityStateBag(Handle);

return new StateBag($"localEntity:{Handle}");
}

return new StateBag("entity:" + NetworkId);
}
}


public override int GetHashCode()
{
return Handle.GetHashCode();
}

public static bool operator ==(Entity left, Entity right)
{
return left?.Equals(right) ?? right is null;
}

public static bool operator !=(Entity left, Entity right)
{
return !(left == right);
}

public bool Equals(Entity entity)
{
return !(entity is null) && Handle == entity.Handle;
}

public override bool Equals(object obj)
{
return !(obj is null) && obj.GetType() == GetType() && Equals((Entity) obj);
}
}
}
38 changes: 38 additions & 0 deletions code/client/clrcore-v2/Client/RedM/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

namespace CitizenFX.RedM
{
public static partial class Game
{
/// <summary>
/// Calculates a Jenkins One At A Time hash from the given <see cref="string"/> which can then be used by any native function that takes a hash
/// </summary>
/// <param name="input">The input <see cref="string"/> to hash.</param>
/// <returns>The Jenkins hash of the <see cref="string"/></returns>
public static uint GenerateHash(string input)
{
uint hash = 0;
// If reorganization is needed then this encryption is better off in separate type, e.g.: `Encryption`
if (!string.IsNullOrEmpty(input))
{
var len = input.Length;

input = input.ToLowerInvariant();

for (var i = 0; i < len; i++)
{
hash += input[i];
hash += hash << 10;
hash ^= hash >> 6;
}

hash += hash << 3;
hash ^= hash >> 11;
hash += hash << 15;

}

return hash;
}

}
}
Loading

0 comments on commit 2c9cf2e

Please sign in to comment.