Make codebase tabs
This commit is contained in:
parent
eeb69fe0df
commit
fbe24aa0f8
|
@ -0,0 +1,11 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
# specifically for YAML
|
||||||
|
[{yml, yaml}]
|
||||||
|
indent_style = space
|
|
@ -1,88 +0,0 @@
|
||||||
// Copyright 2023 The LightningBolt Authors
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <bit>
|
|
||||||
#include <base/Types.hpp>
|
|
||||||
#include <type_traits>
|
|
||||||
#include <span>
|
|
||||||
|
|
||||||
namespace lightningbolt {
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template <class NativeT, class OffsetType>
|
|
||||||
constexpr NativeT* CreatePointerFromAddend(void* BasePointer, OffsetType addend) noexcept {
|
|
||||||
return std::bit_cast<NativeT*>(static_cast<char*>(BasePointer) + addend);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
/// An "auto-resolving" semi-sweet (/s) pointer type.
|
|
||||||
/// This is designed to allow resolving offsets in data for
|
|
||||||
/// games written before 64-bit pointers were common/used at all.
|
|
||||||
/// This allows looking up data a lot easier :)
|
|
||||||
///
|
|
||||||
/// [NativeT] is the type of data this would point to
|
|
||||||
/// [OffsetType] is the type of data the "pointer" is repressented as
|
|
||||||
template <class NativeT, class OffsetType = u32>
|
|
||||||
struct OffsetPtr final {
|
|
||||||
using Type = std::remove_cvref_t<NativeT>;
|
|
||||||
using Pointer = Type*;
|
|
||||||
using ConstPointer = const Type*;
|
|
||||||
|
|
||||||
/// Set the offset. Duh!
|
|
||||||
constexpr void Set(OffsetType newOffset) noexcept { rawOffset = newOffset; }
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr OffsetType Raw() const noexcept { return rawOffset; }
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr Pointer operator()(void* baseAddr) const noexcept {
|
|
||||||
// While yucky, it should show problem areas which aren't checking things
|
|
||||||
// immediately rather than read invalid data that might do much worse.
|
|
||||||
if(rawOffset == 0)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return detail::CreatePointerFromAddend<Type>(baseAddr, rawOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class NativeU>
|
|
||||||
constexpr OffsetPtr<NativeU, OffsetType>& PtrCast() {
|
|
||||||
// Safety: The data layout of OffsetPtr<> stays
|
|
||||||
// the exact same regardless of the result type, therefore
|
|
||||||
// even though this is *techinically* UB (? using bit_cast it shouldn't be ?),
|
|
||||||
// this isn't problematic
|
|
||||||
return *std::bit_cast<OffsetPtr<NativeU, OffsetType>*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
OffsetType rawOffset;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Like OffsetPtr<T> but for arrays of data
|
|
||||||
template <class NativeT, class OffsetType = u32>
|
|
||||||
struct OffsetArrayPtr final {
|
|
||||||
using Type = std::remove_cvref_t<NativeT>;
|
|
||||||
using Pointer = Type*;
|
|
||||||
using ConstPointer = const Type*;
|
|
||||||
|
|
||||||
using Span = std::span<NativeT>;
|
|
||||||
|
|
||||||
/// Set the offset. Duh!
|
|
||||||
constexpr void Set(OffsetType newOffset) noexcept { rawOffset = newOffset; }
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr OffsetType Raw() const noexcept { return rawOffset; }
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr Span operator()(void* baseAddr, OffsetType length) const noexcept {
|
|
||||||
// While yucky, it should show problem areas which aren't checking things
|
|
||||||
// immediately rather than read invalid data that might do much worse.
|
|
||||||
if(rawOffset == 0 || length == 0)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
return { detail::CreatePointerFromAddend<Type>(baseAddr, rawOffset), length };
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
OffsetType rawOffset;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ssxtools::core
|
|
|
@ -29,9 +29,7 @@ namespace lightningbolt {
|
||||||
return (address - LoadAddress) + SectionOffset;
|
return (address - LoadAddress) + SectionOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr BoltTableOffsets BoltTableOffsets = {
|
static constexpr BoltTableOffsets BoltTableOffsets = { .usTable = AddressToElfFileOffset(0x0033d400) };
|
||||||
.usTable = AddressToElfFileOffset(0x0033d400)
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace elf
|
} // namespace elf
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue